UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

2 lines • 2.05 kB
//!src/agents/bash-process-scope.ts 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}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-D0S7WMfL.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-Dp5zGHA2.mjs`),import(`./session-entry-read-runtime-DneR6aFS.mjs`),import(`./session-entry-source-authority-DhLZHw_p.mjs`),import(`./session-key-ClrPzTqw.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}}}}export{resolveProcessToolScopeKey as n,createProcessToolScope as t};