UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

47 lines (46 loc) • 2.04 kB
//#region src/auto-reply/command-owner-authority.ts const COMMAND_OWNER_AUTHORITY = Symbol("openclaw.commandOwnerAuthority"); var CommandOwnerRevokedError = class extends Error {}; const capabilities = /* @__PURE__ */ new WeakMap(); /** Host ingress binds a live check; ordinary context copies retain it, wire data cannot. */ function bindCommandOwnerAuthority(e, t) { const n = t.isCurrent.bind(t); const r = t.operatorAuthority; const i = { recoveryReference: t.recoveryReference && Object.freeze({ ...t.recoveryReference }), channelPrincipal: t.channelPrincipal && Object.freeze({ ...t.channelPrincipal }), operatorAuthority: r, successor: t.successor, isCurrent: n }; Object.setPrototypeOf(i, null); Object.freeze(i); capabilities.set(i, i); Object.assign(e, { [COMMAND_OWNER_AUTHORITY]: i }); } function getCommandOwnerAuthority(e) { const t = Reflect.get(e, COMMAND_OWNER_AUTHORITY); return typeof t === "object" && t !== null ? capabilities.get(t) : void 0; } /** * Moves inherited owner authority into a successor that outlives its source occurrence. * Only a source-provided requester check transfers; otherwise the successor holds none. */ function transferCommandOwnerAuthorityToSuccessor(e) { const t = getCommandOwnerAuthority(e); if (!t) return "none"; Reflect.deleteProperty(e, COMMAND_OWNER_AUTHORITY); if (!t.successor) return "removed"; bindCommandOwnerAuthority(e, t.successor); return "transferred"; } /** Fence a turn that admitted owner tools against later identity or role revocation. */ function captureCommandOwnerAssertion(e) { const t = getCommandOwnerAuthority(e); if (!t) return; return Object.assign(() => { if (!t.isCurrent()) throw new CommandOwnerRevokedError("Channel operator authority changed; send a new request."); }, { recoveryReference: t.recoveryReference ?? null }); } //#endregion export { transferCommandOwnerAuthorityToSuccessor as a, getCommandOwnerAuthority as i, bindCommandOwnerAuthority as n, captureCommandOwnerAssertion as r, CommandOwnerRevokedError as t };