openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
60 lines (59 loc) • 2.55 kB
JavaScript
import { i as resolveRequiredHomeDir, o as resolveUserPath, t as expandHomePrefix } from "./home-dir-Dc6nN6HB.mjs";
import { d as readDatabasePathIdentitySync } from "./sqlite-worker-identity-BRNRpRyc.mjs";
import { n as normalizeAgentId } from "./agent-id-D1-Q6vR4.mjs";
import "./session-key-DY3MOX4N.mjs";
import { i as listAgentIds } from "./agent-roster-DH6r_8f4.mjs";
import { c as resolveSessionStorePathCore, p as listSqliteTargetCandidatePathsForSessionStorePath } from "./paths-Bonddxfk.mjs";
import "./agent-scope-config-BEk6-ThS.mjs";
import { r as cloneEnvWithPlatformSemantics } from "./config-env-vars-BzUE_dOh.mjs";
import { n as resolveSessionStoreCompatibilityAgentId } from "./legacy.default-agent-owner-CMzbXvh6.mjs";
import path from "node:path";
import { isDeepStrictEqual } from "node:util";
//#region src/agents/agent-delete-session-store-safety.targets.ts
function captureCandidates(stores) {
return [...new Set(stores.flatMap((store) => listSqliteTargetCandidatePathsForSessionStorePath(store)))].toSorted().map((pathname) => ({
path: pathname,
identity: readDatabasePathIdentitySync(pathname)
}));
}
/** Retain lexical families, physical aliases, and absences before discovery yields. */
function prepareAgentSessionStoreDeletionSafety(cfg, agentId, environment) {
const id = normalizeAgentId(agentId);
const env = cloneEnvWithPlatformSemantics(environment);
const config = structuredClone(cfg);
const store = cfg.session?.store;
if (store?.trim()) {
config.agents = {
...config.agents,
defaults: {
...config.agents?.defaults,
sessionStore: { agentId: resolveSessionStoreCompatibilityAgentId(cfg) }
}
};
config.session = {
...config.session,
store: path.resolve(resolveUserPath("."), store.startsWith("~") ? expandHomePrefix(store, {
home: resolveRequiredHomeDir(env),
env
}) : store)
};
}
const stores = store?.trim() ? listAgentIds(config).filter((survivor) => normalizeAgentId(survivor) !== id).map((survivor) => resolveSessionStorePathCore(config.session?.store, {
agentId: survivor,
env
})) : [];
return {
config,
agentId: id,
env,
targets: {
stores,
candidates: captureCandidates(stores)
}
};
}
function assertAgentSessionStoreDeletionTargetsCurrent(targets) {
if (!isDeepStrictEqual(captureCandidates(targets.stores), targets.candidates)) throw new Error("Agent session database changed during deletion planning.");
}
//#endregion
export { prepareAgentSessionStoreDeletionSafety as n, assertAgentSessionStoreDeletionTargetsCurrent as t };