openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 4.91 kB
JavaScript
import{r as e}from"./openclaw-state-read-semver-CqfGj9gv.mjs";import{Y as t}from"./openclaw-state-read-sqlite-database-admission-Ck6VG7rE.mjs";import"./openclaw-state-read-tmp-openclaw-dir-C3Ynn93H.mjs";import"./openclaw-state-read-openclaw-state-db-cache-BVY8IYkn.mjs";import"./openclaw-state-read-openclaw-state-db.paths-CFemYLpA.mjs";import{o as n}from"./openclaw-state-read-record-coerce-D1s3ReAs.mjs";import{a as r,i,m as a,r as o}from"./openclaw-state-read-kysely-sync-DQyYiAw5.mjs";import{t as s}from"./openclaw-state-read-errors-D_saNBXy.mjs";import{a as c}from"./openclaw-state-read-sqlite-transaction-V1rK3HH2.mjs";import{o as l,s as u}from"./openclaw-state-read-openclaw-state-db-schema-helpers-BkqUYEFY.mjs";import{a as d}from"./openclaw-state-read-openclaw-state-db-DnrW7QY9.mjs";import{n as f}from"./openclaw-state-read-agent-id-DmscQLD6.mjs";import{i as p}from"./openclaw-state-read-openclaw-state-db-readonly-CDG18cNK.mjs";import"./openclaw-state-read-session-key-DaKMXMbu.mjs";import"./openclaw-state-read-openclaw-state-worker-context-Cvog3s4V.mjs";import"./openclaw-state-read-session-row-changes-C0Qzq-vO.mjs";import{i as m}from"./openclaw-state-read-openclaw-agent-db-registry.read-D1CTFqiu.mjs";import"./openclaw-state-read-openclaw-agent-db-registry-listing-0iIGDbl2.mjs";import"./openclaw-state-read-openclaw-state-db-schema-additive-DRfDFLLT.mjs";import{t as h}from"./openclaw-state-read-agent-deletion-journal-status-hTodcgwC.mjs";import{t as g}from"./openclaw-state-read-agent-deletion-journal-recovery.kernel-DxhVBGkd.mjs";import _ from"node:path";const v=[`template_package_refs`,`template_mcp_server_refs`,`template_cron_refs`];function readTemplateSecondaryReferenceTables(e,t){return v.filter(n=>l(e,n)?!!e.prepare(`SELECT 1 FROM ${n} WHERE agent_id = ? LIMIT 1`).get(t):!1)}function hasTemplateDeletionOwnership(e,t){let n=r(e.db);return[`template_installs`,`template_workspace_files`].some(r=>l(e.db,r)&&i(e.db,n.selectFrom(r).select(`agent_id`).where(`agent_id`,`=`,t).limit(1))!==void 0)||readTemplateSecondaryReferenceTables(e.db,t).length>0}var y=/* @__PURE__ */ e({parseAgentDeletionDatabasePaths:()=>parseAgentDeletionDatabasePaths,readAgentDatabaseDeletionSnapshot:()=>readAgentDatabaseDeletionSnapshot,readAgentDeletionJournalStatusInDatabase:()=>readAgentDeletionJournalStatusInDatabase,readRetainedAgentDeletionsFromDatabase:()=>readRetainedAgentDeletionsFromDatabase});function readAgentDeletionJournalStatusInDatabase(e,t){let n=h(e,t);if(n)return n;if(!l(e,`agent_deletion_journal`))return`absent`;let a=i(e,r(e).selectFrom(`agent_deletion_journal`).select(`cleanup_completed`).where(`agent_id`,`=`,f(t)));return a?a.cleanup_completed===1?`complete`:`pending`:`absent`}function parseAgentDeletionDatabasePaths(e){let t=JSON.parse(e);if(n(t))return t;throw Error(`Invalid agent deletion database path journal.`)}function readRetainedAgentDeletionsFromDatabase(e,n,i=`maintenance`,c){let f=[],p=!1,m;try{if(p=!l(e,`agent_deletion_journal`),!p){let t=a(),n=t.and([t(`cleanup_completed`,`=`,1),t(`delete_files`,`=`,0)]),l=i===`runtime`?n:t.or([n,t(`cleanup_completed`,`=`,0)]);f=o(e,r(e).selectFrom(`agent_deletion_journal`).select([`agent_id`,`cleanup_completed`]).select(u(e,`agent_deletion_journal`,`phase`)?`phase`:t.lit(null).as(`phase`)).select([t.case().when(l).then(t.ref(`agent_dir`)).else(null).end().as(`agent_dir`),t.case().when(l).then(t.ref(`database_paths_json`)).else(`[]`).end().as(`database_paths_json`)]).$if(!c,e=>e.where(l)).orderBy(`agent_id`,`asc`)).rows.flatMap(t=>{if(c?.push({agentId:t.agent_id,status:t.cleanup_completed===1?`complete`:`pending`}),t.agent_dir===null)return[];let n=[];try{n=parseAgentDeletionDatabasePaths(t.database_paths_json)}catch(e){i===`maintenance`&&(m??=s(e))}let r={agentId:t.agent_id,agentDir:t.agent_dir,databasePaths:[_.join(t.agent_dir,`openclaw-agent.sqlite`),...n],cleanupCompleted:t.cleanup_completed===1};return t.cleanup_completed===0&&t.phase==null&&hasTemplateDeletionOwnership({db:e},t.agent_id)&&(r.manualTemplateRemoval=!0),r})}}catch(e){if(t(e))throw e;m=s(e)}let h=[];try{l(e,`migration_sources`)&&(h=g({db:e,path:n}))}catch(e){if(i===`maintenance`||t(e))throw e}return p&&h.length===0&&d(e)?{status:`empty`}:p||m!==void 0?{status:`unavailable`,cause:p?`missing`:`unreadable`,reason:p?`deletion journal missing`:`deletion journal unreadable: ${m}`,...f.length||h.length?{known:{entries:f,held:h}}:{}}:f.length||h.length?{status:`present`,entries:f,held:h}:{status:`empty`}}function readAgentDatabaseDeletionSnapshot(e,t=`maintenance`){return p(({db:e,path:n})=>c(e,()=>({retainedDeletions:readRetainedAgentDeletionsFromDatabase(e,n,t),registeredAgentDatabases:m(e,n,!1)}),{operationLabel:`agentDeletionJournal.snapshot`}),{env:e})}export{hasTemplateDeletionOwnership as a,readRetainedAgentDeletionsFromDatabase as i,parseAgentDeletionDatabasePaths as n,readAgentDatabaseDeletionSnapshot as r,y as t};