UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines • 4.2 kB
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{k as tryResolveConfiguredAgentWorkspaceDir}from"./agent-scope-config-CG9CFpGX.mjs";import{t as resolveDefaultAgentWorkspaceDir}from"./workspace-default-path-ULYbn-EL.mjs";import"./workspace-default-Cb7cQoAN.mjs";import{r as selectDatabaseEngine}from"./registry-ByN-O5dB.mjs";import{a as resolveUpdateRehearsalRoot,r as isUpdateRehearsalReadOnlyPath}from"./update-rehearsal-paths-C4qLj9oD.mjs";import{t as loadBundledPluginPublicArtifactModuleFromCandidatesSync}from"./public-surface-loader-BNZQgUD9.mjs";import path from"node:path"; //!src/plugins/doctor-migration-applicability.ts function sqliteOnlyMigrationNotice(e,t){const n=e.sqliteOnly;if(!n||selectDatabaseEngine({id:n.family,postgres:true},t)!==`postgres`)return;return`${e.label}: legacy SQLite migration not applicable on PostgreSQL; legacy data is migrated before port.${n.postgresNote?` ${n.postgresNote}`:``}`} //!src/plugins/doctor-migration-resources.ts async function preparePluginDoctorMigrationResources(e,t,n){const r=resolveUpdateRehearsalRoot(t.env);const i=/* @__PURE__ */ new Map;const a=[];const o=/* @__PURE__ */ new Map;for(const{pluginId:r,migration:s}of e){t.signal?.throwIfAborted();t.assertCurrent?.();n?.();const e=sqliteOnlyMigrationNotice(s,t.config);if(e){a.push(e);continue}if(s.collectBackupResources===void 0){if(!t.warnings.some(e=>e.pluginId===r))t.warnings.push({kind:`undeclared-migration-resources`,pluginId:r,message:`${r} migration recovery coverage is unknown: no backup inventory was declared. Update the plugin to a version with migration backup support. Until then, keep a separate backup of its configured data before relying on rollback; ask its maintainer to add backup support. See https://docs.openclaw.ai/cli/doctor/state-migrations#plugin-migration-recovery-coverage`});continue}const c=await s.collectBackupResources({config:t.config,env:t.env,stateDir:t.stateDir,serviceWorkspaceDir:tryResolveConfiguredAgentWorkspaceDir(t.config,t.env)??resolveDefaultAgentWorkspaceDir(t.env),...t.requireLocalResources?{requireLocalResources:true}:{}});t.signal?.throwIfAborted();t.assertCurrent?.();n?.();if(!Array.isArray(c))throw new Error(`Invalid migration backup inventory from ${r}/${s.id}`);const l=c;for(const e of l){if(!isMigrationBackupResource(e))throw new Error(`Invalid migration backup resource from ${r}/${s.id}`);const t=e.path;const n=i.get(t);if(n&&n.kind!==e.kind)throw new Error(`Conflicting migration backup resource kinds for ${t}`);i.set(t,{path:t,kind:e.kind});const a=o.get(r)??/* @__PURE__ */ new Set;a.add(t);o.set(r,a)}}const s=new Set(r?[...o].flatMap(([e,n])=>[...n].some(e=>isUpdateRehearsalReadOnlyPath(e,t.env))?[e]:[]):[]);const c=/* @__PURE__ */ new Set;for(const[e,t]of o)if(!s.has(e))for(const e of t)c.add(e);const l=[...i.values()].filter(e=>c.has(e.path)).toSorted((e,t)=>e.path.localeCompare(t.path));const assertCurrent=()=>{t.signal?.throwIfAborted();t.assertCurrent?.();if(!r)return;if(resolveUpdateRehearsalRoot(t.env)!==r)throw new Error(`Plugin migration rehearsal scope changed during preparation`);for(const e of l)if(isUpdateRehearsalReadOnlyPath(e.path,t.env))throw new Error(`Plugin migration data escaped the rehearsal root: ${e.path}`)};assertCurrent();return{resources:l,deferredPluginIds:s,notices:[...a,...[...s].map(e=>`rehearsal: ${e} state migrations deferred; declared data outside the rehearsal root left untouched`)],assertCurrent}}async function assertPluginStateRetention(e,t){for(const n of e){const e=n.doctorContract?.stateMigrations;if(!Array.isArray(e))continue;const r=loadBundledPluginPublicArtifactModuleFromCandidatesSync({dirName:n.id,artifactCandidates:[`state-retention-api.js`],retainedAt:t.candidateRoot});if(!r||r.packageName!==n.packageName)continue;for(const n of r.stateMigrations)if(e.some(({id:e})=>e===n.id))await n.assertSupportedState(t)}}function isMigrationBackupResource(e){return isRecord(e)&&typeof e.path===`string`&&path.isAbsolute(e.path)&&path.normalize(e.path)===e.path&&(e.kind===`sqlite`||e.kind===`file`||e.kind===`directory`)}export{preparePluginDoctorMigrationResources as n,sqliteOnlyMigrationNotice as r,assertPluginStateRetention as t};