UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

77 lines (76 loc) • 2.59 kB
import { n as normalizeAgentId } from "./agent-id-CQjtp2ft.mjs"; import "./session-key-CqAyZeVk.mjs"; import { r as isIncognitoOpenClawAgentSqlitePath } from "./openclaw-agent-db.paths-DJxv80ws.mjs"; import { m as readDatabasePathIdentitySync } from "./sqlite-worker-identity-BH8ZkJU9.mjs"; import { c as registerOpenClawAgentDatabaseSyncResource } from "./openclaw-agent-db-resources-Dp8HvLsg.mjs"; import { r as captureSessionStoreReadCandidate } from "./session-store-read-candidates-BjEE1iTg.mjs"; import { n as getSessionActorStorageBinding, t as captureSessionActorStorageOwner } from "./session-actor-storage-binding-DMwpDsij.mjs"; import path from "node:path"; //#region src/gateway/control-ui-session-pr-source.ts /** Retain source lifetime through the caller's last assertion and publication. */ 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(); } } //#endregion export { withControlUiSessionPrSource as t };