openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
38 lines (37 loc) • 1.57 kB
JavaScript
import { a as resolveGlobalSingleton } from "./global-singleton-D7yf05nR.mjs";
import { t as isPromiseLike } from "./promise-like-aMoWEh5w.mjs";
import { u as throwSqliteLifecycleErrors } from "./sqlite-lifecycle-errors-D8BU4VLa.mjs";
import { AsyncLocalStorage } from "node:async_hooks";
import { isPathInside } from "@openclaw/fs-safe/path";
//#region src/state/artifact-preserving-state-reads.ts
const artifactPreservingReads = resolveGlobalSingleton(Symbol.for("openclaw.artifactPreservingStateReads"), () => new AsyncLocalStorage());
function withArtifactPreservingStateReads(e, t = {}) {
if (isArtifactPreservingStateRead("agent")) return e();
const n = {
agentDatabases: t.agentDatabases === true,
readers: /* @__PURE__ */ new Set(),
privateRoots: /* @__PURE__ */ new Set()
};
const finish = (e, t = []) => {
for (const e of n.readers) try {
e();
} catch (e) {
t.push(e);
}
throwSqliteLifecycleErrors(t, "Artifact-preserving inspection and cleanup failed.");
return e;
};
let r;
try {
r = artifactPreservingReads.run(n, e);
} catch (e) {
return finish(void 0, [e]);
}
return isPromiseLike(r) ? Promise.resolve(r).then(finish, (e) => finish(void 0, [e])) : finish(r);
}
function isArtifactPreservingStateRead(e = "shared", t) {
const n = artifactPreservingReads.getStore();
return Boolean(n && (e === "shared" || n.agentDatabases) && (!t || ![...n.privateRoots].some((e) => isPathInside(e, t))));
}
//#endregion
export { isArtifactPreservingStateRead as n, withArtifactPreservingStateReads as r, artifactPreservingReads as t };