UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

89 lines (88 loc) • 2.8 kB
//#region src/agents/bash-process-scope.ts /** Resolve the process-tool isolation key for exec/process session state. */ function resolveProcessToolScopeKey(e) { const t = e.scopeKey?.trim() || e.sessionKey?.trim() || e.sessionId?.trim(); if (t) return t; const n = e.agentId?.trim(); return n ? `agent:${n}` : void 0; } /** Resolve ancestor visibility only when needed, retaining its live authority. */ function createProcessToolScope(e, t) { const { scopeKey: n, agentId: r, sessionKey: i, sessionStore: a } = e; const o = /* @__PURE__ */ new Set(); const s = []; const assertCurrent = () => { t(); for (const e of s) e.assertCurrent(); }; const release = async () => { if (s.length === 0) return; const { releaseSessionSourceAuthorities: e } = await import("./session-source-authority-t8n2-dOC.mjs"); await e(s); }; return { isInScope: (e) => { assertCurrent(); if (!n) return true; if (e?.scopeKey === n) return !r || !e.agentId || e.agentId === r; return Boolean(r && e?.agentId === r && e.scopeKey && o.has(e.scopeKey)); }, assertCurrent, [Symbol.asyncDispose]: release, resolveAncestorScopes: async () => { if (!r || !i || n !== i) return; assertCurrent(); const [{ resolveSessionStorePathCore: e }, { withSessionEntryReadOnlyInWorker: c }, { captureSessionEntrySourceAssertion: l }, { parseAgentSessionKey: u }] = await Promise.all([ import("./paths-vnGHlSXy.mjs"), import("./session-entry-read-runtime-24no1ay9.mjs"), import("./session-entry-source-authority-BdB-rP84.mjs"), import("./session-key-Dy5IGO7x.mjs") ]); assertCurrent(); const d = e(a, { agentId: r }); let f = i; while (f && (u(f)?.agentId ?? r) === r) { if (o.has(f) || o.size >= 32) throw new Error("Process session ancestry is invalid."); const e = f; const n = await c({ agentId: r, sessionKey: e, storePath: d, hydrateSkillPromptRefs: false }, assertCurrent, async (n, i) => { if (!n.ok) throw n.error; if (!n.value) return; const a = l({ scope: { agentId: r, sessionKey: e, storePath: i.source?.path ?? d }, readSource: i.source, expected: n.value, fields: [ "sessionId", "lifecycleRevision", "parentSessionKey", "spawnedBy" ], assertCurrent: t, assertHostCurrent: t, refuse: () => { throw new Error("Process session ancestry changed; retry the process action."); } }); s.push(await a.prepareSessionSource()); assertCurrent(); return n.value; }); assertCurrent(); if (!n) break; o.add(e); f = n.parentSessionKey ?? n.spawnedBy; } } }; } //#endregion export { resolveProcessToolScopeKey as n, createProcessToolScope as t };