openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
133 lines (132 loc) • 5.76 kB
JavaScript
import { _ as resolveGlobalSingleton } from "./runtime-doctor-migrations-JGL9tD-z.js";
import "./account-core-u1qUW4Od.js";
import "./subsystem-DLheYoE0.js";
import { n as resolveIdentityPathViaExistingAncestorSync } from "./boundary-path-BJflOsrm.js";
import "./boundary-file-read-D04C1gj5.js";
import "./cli-invocation-Df8-W3Wc.js";
import "./runtime-process-manifest-B0mzdXd2.js";
import { a as runtimeProcessEntrypoints } from "./runtime-binary-DrN_tBF0.js";
import { r as resolveRuntimeWorkerUrl } from "./runtime-worker-url-BSKz18fr.js";
import path from "node:path";
import fs, { realpathSync, statSync } from "node:fs";
import { isDeepStrictEqual } from "node:util";
import "@openclaw/fs-safe/advanced";
import { createHash } from "node:crypto";
import { fileURLToPath, pathToFileURL } from "node:url";
import { AsyncLocalStorage } from "node:async_hooks";
//#region src/state/openclaw-agent-db.paths.ts
const INCOGNITO_AGENT_SQLITE_BASENAME = "incognito-openclaw-agent.sqlite";
const agentSqlitePaths = /* @__PURE__ */ new Map();
const agentSqlitePathKeys = agentSqlitePaths.keys();
//#endregion
//#region src/infra/runtime-process-url.ts
const sealedEntrypoints = /* @__PURE__ */ new Map();
function resolveRuntimeProcessEntrypointUrl(e) {
return sealedEntrypoints.get(e) ?? resolveRuntimeWorkerUrl(runtimeProcessEntrypoints[e]);
}
//#endregion
//#region src/state/openclaw-state-maintenance-context.ts
const liveAuthorityReads = resolveGlobalSingleton(Symbol.for("openclaw.maintenanceLiveAuthorityReads"), () => /* @__PURE__ */ new WeakMap());
function allowsMaintenanceLiveAuthorityReads(e, t) {
const n = resolveIdentityPathViaExistingAncestorSync(t);
for (let t = e; t; t = maintenanceResources.parents.get(t)) if (liveAuthorityReads.get(t)?.has(n)) return true;
return false;
}
/** Raw source descriptor closes are safe only before maintenance admits native source reads. */
function maintenanceOwnerHasSourceCustody(e, t) {
if (!e?.ownsSchemaMaintenance) return false;
e.assertReadAdmission();
return !allowsMaintenanceLiveAuthorityReads(e, t);
}
const maintenanceResources = resolveGlobalSingleton(Symbol.for("openclaw.databaseMaintenanceResources"), () => ({
current: new AsyncLocalStorage(),
claims: /* @__PURE__ */ new WeakMap(),
parents: /* @__PURE__ */ new WeakMap()
}));
function getOpenClawDatabaseMaintenanceScope() {
return maintenanceResources.current.getStore()?.scope;
}
/** Background work retains command custody without borrowing its native execution path. */
function isOpenClawDatabaseMaintenanceWorkerAccess() {
return maintenanceResources.current.getStore()?.workerAccess === true;
}
function isOpenClawDatabaseMaintenanceResourceOwned(e, t) {
return maintenanceResources.claims.get(e)?.scope === t;
}
function getOpenClawDatabaseMaintenanceResourceScope(e) {
return maintenanceResources.claims.get(e)?.scope;
}
function runMaintenance(e, t, n = isOpenClawDatabaseMaintenanceWorkerAccess()) {
const r = {
scope: e,
active: true,
workerAccess: n
};
try {
const n = maintenanceResources.current.run(r, t);
if (n instanceof Promise) {
const settled = () => {
r.active = false;
};
n.then(settled, settled);
e.track(n);
} else r.active = false;
return n;
} catch (e) {
r.active = false;
throw e;
}
}
/** Retain one exact resource claim for finite commands while its maintenance scope drains. */
function captureOpenClawDatabaseMaintenanceResource(e, t) {
const n = maintenanceResources.claims.get(e);
const assertCurrent = () => {
t.assertOwnerCurrent();
if (n?.scope !== t || maintenanceResources.claims.get(e) !== n) throw new Error("Database maintenance resource owner changed");
};
assertCurrent();
return {
assertCurrent,
async run(e) {
assertCurrent();
return runMaintenance(t, e);
},
async runWorker(e) {
assertCurrent();
return runMaintenance(t, e, true);
}
};
}
/** A cached handle used by an independent caller remains with the ordinary cache owner. */
function observeOpenClawDatabaseMaintenanceResource(e) {
if (!e) return;
const t = maintenanceResources.claims.get(e);
const n = getOpenClawDatabaseMaintenanceScope();
if (!t) return;
const r = commonMaintenanceAncestor(t.scope, n);
if (r === t.scope) return;
t.scope.assertAdmission();
t.release();
maintenanceResources.claims.delete(e);
if (r) r.own(e, t.phase, t.close);
}
function commonMaintenanceAncestor(e, t) {
const n = /* @__PURE__ */ new Set();
for (let t = e; t; t = maintenanceResources.parents.get(t)) n.add(t);
for (let e = t; e; e = maintenanceResources.parents.get(e)) if (n.has(e)) return e;
}
//#endregion
//#region src/agents/workspace-state-identity.ts
const WORKSPACE_ALIAS_REPOINTED_ERROR_CODE = "WORKSPACE_ALIAS_REPOINTED";
var WorkspaceAliasRepointedError = class extends Error {
constructor(e) {
super(`workspace path alias points to a different current target: ${e.aliasPath} now resolves to ${e.currentWorkspacePath}, but its stored workspace state belongs to ${e.storedWorkspacePath}. Run \`openclaw doctor --fix\` and confirm the move, or use \`openclaw doctor --fix --force\`.`);
this.code = WORKSPACE_ALIAS_REPOINTED_ERROR_CODE;
this.name = "WorkspaceAliasRepointedError";
this.aliasPath = e.aliasPath;
this.storedWorkspacePath = e.storedWorkspacePath;
this.currentWorkspacePath = e.currentWorkspacePath;
}
};
//#endregion
export { isOpenClawDatabaseMaintenanceResourceOwned as a, resolveRuntimeProcessEntrypointUrl as c, getOpenClawDatabaseMaintenanceScope as i, INCOGNITO_AGENT_SQLITE_BASENAME as l, captureOpenClawDatabaseMaintenanceResource as n, maintenanceOwnerHasSourceCustody as o, getOpenClawDatabaseMaintenanceResourceScope as r, observeOpenClawDatabaseMaintenanceResource as s, WorkspaceAliasRepointedError as t };