openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.12 kB
JavaScript
import{n as normalizeAgentId}from"./agent-id-cOfqmfln.mjs";import"./session-key-BPgKfU2m.mjs";import{i as isIncognitoOpenClawAgentSqlitePath}from"./openclaw-agent-db.paths-SkzMsgQ0.mjs";import{m as readDatabasePathIdentitySync}from"./sqlite-worker-identity-CikEUuqF.mjs";import{l as registerOpenClawAgentDatabaseSyncResource}from"./openclaw-agent-db-resources-KCMTIo4b.mjs";import{r as captureSessionStoreReadCandidate}from"./session-store-read-candidates-CcJ9PtLw.mjs";import{n as getSessionActorStorageBinding,t as captureSessionActorStorageOwner}from"./session-actor-storage-binding-Bq_IHhu0.mjs";import path from"node:path";
//!src/gateway/control-ui-session-pr-source.ts
async function withControlUiSessionPrSource(e,t){const n={agentId:normalizeAgentId(e.agentId),path:path.resolve(e.path)};const r=getSessionActorStorageBinding({agentId:n.agentId,storePath:n.path});if(r){const assertCurrent=()=>{r.authority.assertCurrent();r.actor.assertReadable()};return t(assertCurrent,JSON.stringify(r.actor.target.database))}const i=[];let a=true;const changed=()=>/* @__PURE__ */ new Error(`Session PR source changed or closed. Retry the request.`);try{if(isIncognitoOpenClawAgentSqlitePath(n.path,n)){const assertActive=()=>{if(!a)throw changed()};const e=captureSessionActorStorageOwner({agentId:n.agentId,storePath:n.path},{assertCurrent:assertActive,authorize:assertActive});const r=e?.owner;if(!e||!r)throw changed();const assertCurrent=()=>{e.authority.assertCurrent();r.assertCurrent()};assertCurrent();return await t(assertCurrent,JSON.stringify(r.identity))}const e=captureSessionStoreReadCandidate(n.path);const r=readDatabasePathIdentitySync(e.path);if(!r.key.startsWith(`file:`)||r.canonicalPath!==e.physicalPath)throw changed();const o=r.key;const s=[.../* @__PURE__ */ new Set([e.path,e.physicalPath])];for(const e of s)i.push(registerOpenClawAgentDatabaseSyncResource({agentId:n.agentId,path:e,revoke:()=>{a=false},close:()=>{a=false}}));const assertCurrent=()=>{if(!a)throw changed()};return await t(assertCurrent,o)}finally{a=false;for(const e of i.toReversed())e()}}export{withControlUiSessionPrSource as t};