openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.04 kB
JavaScript
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{n as normalizeAgentId}from"./agent-id-cOfqmfln.mjs";import"./session-key-BPgKfU2m.mjs";import{a as resolveOpenClawRegisteredAgentDatabasePath}from"./openclaw-state-db.paths-CbgXfEg1.mjs";import{y as DuplicateAgentError}from"./openclaw-state-worker-error-Ca5E4dEV.mjs";import{i as readLegacyMigrationReceiptFromDatabase}from"./state-migrations.receipts-DhYgpkdJ.mjs";
//!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)}))}function readAgentDeletionRecoveryHolds(e){return decodeHolds(e,readReport(e)?.held??[])}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.`)}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};