UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

57 lines (56 loc) • 3.51 kB
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { n as normalizeAgentId } from "./agent-id-CQjtp2ft.mjs"; import "./session-key-CqAyZeVk.mjs"; import { a as resolveOpenClawRegisteredAgentDatabasePath } from "./openclaw-state-db.paths-R3ArRCcz.mjs"; import { y as DuplicateAgentError } from "./openclaw-state-worker-error-C8y1JGQN.mjs"; import { i as readLegacyMigrationReceiptFromDatabase } from "./state-migrations.receipts-CXYpigJ-.mjs"; //#region src/state/agent-deletion-journal-recovery.kernel.ts const AGENT_DELETION_RECOVERY_SOURCE_KEY = "agent-deletion-journal-reconstruction"; const AGENT_DELETION_RECONSTRUCTION_DESCRIPTION = "Reconstructed the missing agent deletion journal; held databases require explicit agent restore or delete."; function parseHolds(e) { return e.map((e) => { if (!isRecord(e) || typeof e.agentId !== "string" || e.agentId !== normalizeAgentId(e.agentId) || typeof e.path !== "string" || !e.path.trim()) throw new Error("Invalid agent database hold in deletion journal reconstruction receipt."); return { agentId: e.agentId, path: e.path }; }); } function readReport(e) { const t = readLegacyMigrationReceiptFromDatabase(e.db, AGENT_DELETION_RECOVERY_SOURCE_KEY); if (!t) return; const n = JSON.parse(t.reportJson); if (!isRecord(n) || typeof n.description !== "string" || !Array.isArray(n.held)) throw new Error("Invalid agent deletion journal reconstruction receipt."); const r = parseHolds(n.held); if (n.missingJournal !== void 0 && !Array.isArray(n.missingJournal)) throw new Error("Invalid missing-journal provenance in deletion journal reconstruction receipt."); const i = Array.isArray(n.missingJournal) ? parseHolds(n.missingJournal) : n.description === "Reconstructed the missing agent deletion journal; held databases require explicit agent restore or delete." ? r : []; if (i.some((e) => !r.some((t) => t.agentId === e.agentId && t.path === e.path))) throw new Error("Missing-journal provenance refers to an unheld agent database."); return { ...n, description: n.description, held: r, missingJournal: i }; } function decodeHolds(e, t) { return t.map((t) => ({ agentId: t.agentId, path: resolveOpenClawRegisteredAgentDatabasePath(e.path, t.path) })); } /** Read recovery facts from this exact shared-state generation without opening another database. */ function readAgentDeletionRecoveryHolds(e) { return decodeHolds(e, readReport(e)?.held ?? []); } /** Only table-absence reconstruction can grant this provenance; quarantine cannot. */ function readAgentDeletionMissingJournalHolds(e) { return decodeHolds(e, readReport(e)?.missingJournal ?? []); } function assertAgentDeletionRecoveryHoldPredicate(e, t) { if (t?.applies) assertAgentDeletionRecoveryHoldsMatch(readAgentDeletionRecoveryHolds(e), t); } function assertAgentDeletionRecoveryHoldsMatch(e, t) { if (t.applies && e.some((e) => e.agentId === t.agentId && !t.held.some((t) => t.agentId === e.agentId && t.path === e.path))) throw new DuplicateAgentError(`Agent ${t.agentId} has held databases. Restore its original agentDir and session.store configuration, then run agents add explicitly to restore the preserved store.`); } //#endregion export { decodeHolds as a, readReport as c, assertAgentDeletionRecoveryHoldsMatch as i, AGENT_DELETION_RECOVERY_SOURCE_KEY as n, readAgentDeletionMissingJournalHolds as o, assertAgentDeletionRecoveryHoldPredicate as r, readAgentDeletionRecoveryHolds as s, AGENT_DELETION_RECONSTRUCTION_DESCRIPTION as t };