UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

78 lines (77 loc) • 3.1 kB
import { n as normalizeAgentId } from "./agent-id-CQjtp2ft.mjs"; import "./session-key-CqAyZeVk.mjs"; import { i as listAgentIds, n as listAgentEntries } from "./agent-roster-t1ooUdXp.mjs"; import { l as resolveSessionStorePathCore } from "./paths-DvQ5AJvD.mjs"; import { E as toAgentEntriesRecord, f as resolveAgentWorkspaceDir, v as resolveEffectiveAgentDir } from "./agent-scope-config-DmXgFGKP.mjs"; import { s as readAgentDeletionJournalStatusInWorker } from "./agent-deletion-journal.read-DjOO2RZM.mjs"; //#region src/config/agent-workspace-roster-transition.ts var AgentDeletionTargetsPendingError = class extends Error {}; /** Gateway deletion captures its targets under the same lock as config writers. */ async function assertAgentDeletionTargetsUnchanged(e, t, n = process.env) { const r = new Set(listAgentIds(e)); const i = new Set(listAgentIds(t)); if (e.session?.store !== t.session?.store) { const { listPendingAgentDeletionJournalsAsync: r } = await import("./agent-deletion-journal-DuW0PNFF.mjs"); const { entries: a, manualTemplateAgentIds: o } = await r({ env: n }); for (const r of [...a.map((e) => e.agentId), ...o]) if (resolveSessionStorePathCore(e.session?.store, { agentId: r, env: n }) !== resolveSessionStorePathCore(t.session?.store, { agentId: r, env: n })) i.add(r); } for (const a of i) { if (r.has(a) && resolveAgentWorkspaceDir(e, a, n) === resolveAgentWorkspaceDir(t, a, n) && resolveEffectiveAgentDir(e, a, { env: n }) === resolveEffectiveAgentDir(t, a, { env: n }) && resolveSessionStorePathCore(e.session?.store, { agentId: a, env: n }) === resolveSessionStorePathCore(t.session?.store, { agentId: a, env: n })) continue; if (await readAgentDeletionJournalStatusInWorker(a, { env: n }) === "pending") throw new AgentDeletionTargetsPendingError(`Agent "${a}" deletion cleanup is still pending; finish or retry its deletion before changing its workspace, agent directory, or session store.`); } } function pinSurvivorWorkspaceForRosterCollapse(e, t, n = process.env) { const r = listAgentEntries(e); const i = listAgentEntries(t); if (r.length <= 1 || i.length !== 1) return { config: t, insertedPaths: [] }; const a = normalizeAgentId(i[0].id); if (!r.some((e) => normalizeAgentId(e.id) === a)) return { config: t, insertedPaths: [] }; const o = t.agents ?? {}; const s = o.entries ? { ...o.entries } : toAgentEntriesRecord(i); const c = Object.keys(s).find((e) => normalizeAgentId(e) === a); const l = c ? s[c] : void 0; const u = l !== void 0 && (!Object.hasOwn(l, "workspace") || typeof l.workspace === "string" && l.workspace.trim().length === 0); if (!c || !l || !u) return { config: t, insertedPaths: [] }; s[c] = { ...l, workspace: resolveAgentWorkspaceDir(e, a, n) }; return { config: { ...t, agents: { ...o, entries: s } }, insertedPaths: [[ "agents", "entries", c, "workspace" ]] }; } //#endregion export { assertAgentDeletionTargetsUnchanged as n, pinSurvivorWorkspaceForRosterCollapse as r, AgentDeletionTargetsPendingError as t };