UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.53 kB
import{s as composeSessionSourceAssertion}from"./session-source-authority-Cun3s-rH.mjs";import{i as ErrorCodes}from"./missing-scope-error-CkgBgh6d.mjs";import{p as errorShape}from"./error-codes-CQNGhXT-.mjs";import{n as SessionMutationAuthorizationChangedError}from"./session-mutation-authorization-error-D4Cgq_Qr.mjs"; //!src/gateway/server-methods/agent-runtime-authority.ts function hasActiveAgentRuntimeAuthority(e,t,n){try{n?.()}catch(e){if(e instanceof SessionMutationAuthorizationChangedError)throw e;return false}const r=e?.internal?.agentRuntimeIdentity;const i=t.validateAgentRuntimeApprovalAuthority;return!r||!i||i(r)}function assertActiveAgentRuntimeAuthority(e,t,n){if(!hasActiveAgentRuntimeAuthority(e,t,n))throw new TypeError(`The message turn has ended. Start a new turn to retry.`)}function createAgentRuntimeAuthorityGuard(e,t,n,r){const hasActive=()=>hasActiveAgentRuntimeAuthority(e,t,r);return{commitGuard:r||e?.internal?.agentRuntimeIdentity&&t.validateAgentRuntimeApprovalAuthority?composeSessionSourceAssertion([r],n=>assertActiveAgentRuntimeAuthority(e,t,n)):void 0,ensureActive(){if(hasActive())return true;n(false,void 0,errorShape(ErrorCodes.INVALID_REQUEST,`The message turn has ended. Start a new turn to retry.`));return false},handleClosedError(e){if(e instanceof TypeError&&!hasActive()){n(false,void 0,errorShape(ErrorCodes.INVALID_REQUEST,e.message));return}throw e},hasActive}}export{createAgentRuntimeAuthorityGuard as n,hasActiveAgentRuntimeAuthority as r,assertActiveAgentRuntimeAuthority as t};