UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

39 lines (38 loc) • 1.86 kB
import { a as composeSessionSourceAssertion } from "./session-source-authority-h1UO3u0I.mjs"; import { t as ErrorCodes } from "./gateway-error-details-gTekQWj2.mjs"; import { d as errorShape } from "./error-codes-D0WRV4Bq.mjs"; //#region src/gateway/server-methods/agent-runtime-authority.ts function hasActiveAgentRuntimeAuthority(client, context, assertCallerCurrent) { try { assertCallerCurrent?.(); } catch { return false; } const identity = client?.internal?.agentRuntimeIdentity; const validate = context.validateAgentRuntimeApprovalAuthority; return !identity || !validate || validate(identity); } function assertActiveAgentRuntimeAuthority(client, context, assertCallerCurrent) { if (!hasActiveAgentRuntimeAuthority(client, context, assertCallerCurrent)) throw new TypeError("agent runtime authority is no longer active"); } function createAgentRuntimeAuthorityGuard(client, context, respond, assertCallerCurrent) { const hasActive = () => hasActiveAgentRuntimeAuthority(client, context, assertCallerCurrent); return { commitGuard: assertCallerCurrent || client?.internal?.agentRuntimeIdentity && context.validateAgentRuntimeApprovalAuthority ? composeSessionSourceAssertion([assertCallerCurrent], (assertCaller) => assertActiveAgentRuntimeAuthority(client, context, assertCaller)) : void 0, ensureActive() { if (hasActive()) return true; respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, "agent runtime authority is no longer active")); return false; }, handleClosedError(error) { if (error instanceof TypeError && !hasActive()) { respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, error.message)); return; } throw error; }, hasActive }; } //#endregion export { createAgentRuntimeAuthorityGuard as n, hasActiveAgentRuntimeAuthority as r, assertActiveAgentRuntimeAuthority as t };