openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
122 lines (121 loc) • 6.07 kB
JavaScript
import { a as resolveRequiredHomeDir, c as resolveUserPath } from "./home-dir-EKmgmdPG.mjs";
import "./src-H3RMXyFL.mjs";
import { t as expectDefined } from "./expect-DDakjvvQ.mjs";
import { r as resolveStateDir } from "./state-dir-DiG0gXzD.mjs";
import { o as getPluginRuntimeGatewayRequestScope } from "./gateway-request-scope-BvvDhs5D.mjs";
import { r as isDeeplyFrozenPlainData } from "./immutable-data-Y7xVjZoy.mjs";
import { n as createOpenClawAgentDatabasePathMatcher } from "./openclaw-agent-db.paths-DJxv80ws.mjs";
import { a as resolveUnsuffixedSqliteTargetFromSessionStorePath } from "./session-sqlite-target-paths-Dw0pT36E.mjs";
import { l as resolveSessionStorePathCore } from "./paths-DvQ5AJvD.mjs";
import { R as resolvePersistedSessionStoreOwner } from "./agent-scope-config-DmXgFGKP.mjs";
import { t as OPENCLAW_AGENT_SCHEMA_VERSION } from "./openclaw-schema-versions-E_10NoI6.mjs";
import { s as resolveOpenClawStateSqlitePath } from "./openclaw-state-db.paths-R3ArRCcz.mjs";
import "./openclaw-agent-db-contract-aCH9b8Uc.mjs";
import { n as resolveSessionStoreCompatibilityAgentId } from "./legacy.default-agent-owner-DpmHgK0A.mjs";
import { i as getPreparedAgentDeletionDiscovery } from "./agent-deletion-journal-status-CZ5XyH3P.mjs";
import { c as listOpenClawRegisteredAgentDatabases, f as readOpenClawAgentDatabaseRegistryToken } from "./openclaw-agent-db-registry-listing-CbXBL50a.mjs";
import "./openclaw-agent-db-CwXW4hGa.mjs";
import { n as getAgentDatabaseStartupAdmission } from "./agent-database-startup-C_V1xkCB.mjs";
import { o as resolveConfiguredAgentDatabaseCandidatePaths, s as resolveConfiguredAgentDatabaseTargets } from "./targets-BVE0__Jb.mjs";
import { n as createRetainedAgentDatabaseMatcher, r as createRetainedAgentDatabaseMatcherFromSnapshot } from "./agent-deletion-discovery-BUESMyCH.mjs";
import fs from "node:fs";
//#region src/config/sessions/combined-store-paths.ts
const configuredAdmissionPaths = /* @__PURE__ */ new WeakMap();
function createGatewayConfiguredDatabaseMatcher(e, t) {
const n = getAgentDatabaseStartupAdmission();
const r = readOpenClawAgentDatabaseRegistryToken({ env: t });
const i = JSON.stringify([
resolveStateDir(t),
resolveRequiredHomeDir(t),
resolveUserPath(".")
]);
const a = isDeeplyFrozenPlainData(e) ? configuredAdmissionPaths.get(e) : void 0;
const o = a && a.admission === n && a.registryToken === r && a.context === i ? a.paths : new Set(resolveConfiguredAgentDatabaseCandidatePaths(e, { env: t }));
if (o !== a?.paths && isDeeplyFrozenPlainData(e)) configuredAdmissionPaths.set(e, {
admission: n,
registryToken: r,
context: i,
paths: o
});
let s;
const c = o.values();
return (e) => {
if (o.has(e)) return true;
if (!fs.statSync(e, { throwIfNoEntry: false })) return false;
s ??= {
key: createOpenClawAgentDatabasePathMatcher().createIndex(),
paths: /* @__PURE__ */ new Set()
};
const t = s.key(e);
if (s.paths.has(t)) return true;
for (const e of c) try {
if (!fs.statSync(e, { throwIfNoEntry: false })) continue;
const n = s.key(e);
s.paths.add(n);
if (n === t) return true;
} catch {}
return false;
};
}
function storeTargetKey(e) {
return `${e.agentId}\0${e.storePath}`;
}
function isStorePathTemplate(e) {
return typeof e === "string" && e.includes("{agentId}");
}
function resolveCombinedStorePath(e, t) {
return e.length === 1 ? expectDefined(e[0], "store path at 0") : typeof t === "string" && t.trim() ? t.trim() : "(multiple)";
}
function resolveCombinedDatabasePath(e, t) {
const n = [...new Set(e.map((e) => expectDefined(t.get(storeTargetKey(e)), "physical store").storePath))];
return n.length === 1 ? expectDefined(n[0], "database path at 0") : "(multiple)";
}
function discoveryReadOptions(e) {
return e ? {
env: e.env,
readCandidates: e.readCandidates,
registeredDatabases: (e.snapshot?.registeredAgentDatabases ?? []).filter((e) => e.schemaVersion === 38)
} : {};
}
/** Exclude retired discovery targets before resolution can open their databases. */
function gatewayDiscoveryReadOptions(e, t) {
const n = createGatewayRetainedStoreMatcher(e, t);
const r = t?.recoveryExclusions;
return {
...discoveryReadOptions(t),
excludeTarget: (e) => {
const t = resolveUnsuffixedSqliteTargetFromSessionStorePath(e.storePath).path;
return r?.agentIds.includes(e.agentId) === true || r?.storePaths.includes(e.storePath) === true || r?.databasePaths.includes(t) === true || Boolean(n(t, e.agentId));
}
};
}
function resolveSharedStoreRowOwner(e, t, n, r) {
const i = resolveSessionStorePathCore(e.session?.store, {
agentId: resolveSessionStoreCompatibilityAgentId(e),
env: r
});
if (!n.has(i)) return;
const a = resolvePersistedSessionStoreOwner(e);
return a.kind === "configured" ? {
agentId: a.agentId,
target: t
} : void 0;
}
function createGatewayRetainedStoreMatcher(e, t) {
const n = discoveryReadOptions(t);
const r = n.env ?? process.env;
const readConfiguredTargets = (t) => resolveConfiguredAgentDatabaseTargets(e, {
env: r,
...n,
excludeTarget: (e) => t(resolveUnsuffixedSqliteTargetFromSessionStorePath(e.storePath).path, e.agentId)
});
const i = t ? void 0 : getPreparedAgentDeletionDiscovery(resolveOpenClawStateSqlitePath(r));
const a = t?.snapshot ?? (i && {
retainedDeletions: i,
registeredAgentDatabases: listOpenClawRegisteredAgentDatabases({ env: r })
});
if (!t && !a && getPluginRuntimeGatewayRequestScope()) throw new Error("Session discovery requires worker preparation; await the asynchronous session store loader.");
return t || a ? createRetainedAgentDatabaseMatcherFromSnapshot(r, readConfiguredTargets, a, "database", "runtime-discovery") : createRetainedAgentDatabaseMatcher(r, readConfiguredTargets, "database", "runtime-discovery");
}
//#endregion
export { resolveCombinedDatabasePath as a, storeTargetKey as c, isStorePathTemplate as i, createGatewayRetainedStoreMatcher as n, resolveCombinedStorePath as o, gatewayDiscoveryReadOptions as r, resolveSharedStoreRowOwner as s, createGatewayConfiguredDatabaseMatcher as t };