openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 1.8 kB
JavaScript
import{i as e}from"./transcript-global-singleton-DIJgobpU.mjs";import{a as t}from"./transcript-sql-connection-CRz-dHXM.mjs";import{b as n,h as r}from"./transcript-sqlite-post-commit-BDZjIt2B.mjs";import{AsyncLocalStorage as i}from"node:async_hooks";import{isPathInside as a}from"@openclaw/fs-safe/path";const o=e(Symbol.for(`openclaw.artifactPreservingStateReads`),()=>new i),s=e(Symbol.for(`openclaw.liveStateReads`),()=>new i);function isLiveStateRead(){return s.getStore()!==void 0}function isStartupConfigStateRead(){return s.getStore()===`startup-config`}function withArtifactPreservingStateReads(e,i={}){if(isArtifactPreservingStateRead(`agent`))return e();let a={agentDatabases:i.agentDatabases===!0,readers:/* @__PURE__ */ new Set,privateRoots:/* @__PURE__ */ new Set,snapshots:/* @__PURE__ */ new Map},closeReaders=e=>{for(let t of a.readers)try{t()}catch(t){e.push(t)}},finish=(e,t=[])=>{closeReaders(t);for(let e of a.snapshots.values())try{if(!e.cleanup())throw new r(`SQLite inspection snapshot cleanup failed.`)}catch(e){t.push(e)}return n(t,`Artifact-preserving inspection and cleanup failed.`),e},finishAsync=async(e,t=[])=>{closeReaders(t);for(let e of a.snapshots.values())try{if(!await e.cleanupAsync())throw new r(`SQLite inspection snapshot cleanup failed.`)}catch(e){t.push(e)}return n(t,`Artifact-preserving inspection and cleanup failed.`),e},s;try{s=o.run(a,e)}catch(e){return finish(void 0,[e])}return t(s)?Promise.resolve(s).then(finishAsync,e=>finishAsync(void 0,[e])):finish(s)}function isArtifactPreservingStateRead(e=`shared`,t){let n=o.getStore();return!(!n||e!==`shared`&&!n.agentDatabases||t&&[...n.privateRoots].some(e=>a(e,t)))}export{withArtifactPreservingStateReads as a,isStartupConfigStateRead as i,isArtifactPreservingStateRead as n,isLiveStateRead as r,o as t};