openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.97 kB
JavaScript
import{i as hasRetainedPluginRuntimeCloseError}from"./runtime-close-error-Ct99vNsO.mjs";import{k as tryResolveConfiguredAgentWorkspaceDir}from"./agent-scope-config-CG9CFpGX.mjs";import{a as getOpenClawDatabaseMaintenanceScope}from"./openclaw-state-maintenance-context-D-pYfco8.mjs";import"./openclaw-state-db-async-lifecycle-DlV0ztcV.mjs";import"./agent-scope-Dw5XRSEh.mjs";import{c as OUTBOUND_LEGACY_PREPARATION_QUEUE_NAME,i as OUTBOUND_DELIVERY_MIGRATION_QUEUE_NAME,r as LEGACY_OUTBOUND_DELIVERY_QUEUE_NAME}from"./delivery-queue-namespaces-BNCoN9F0.mjs";import{i as countPendingDeliveryQueueEntriesReadOnly}from"./delivery-queue-sqlite-BtAn8uTD.mjs";import{t as withLegacyMigrationStateLock}from"./state-migrations.lock-CvJDF0aU.mjs";
//!src/commands/doctor-outbound-delivery.ts
async function migrateDoctorDeliveryQueues(e){const t={...e.env,OPENCLAW_STATE_DIR:e.stateDir};const{repairRetiredDoctorState:n}=await import(`./doctor-retired-state-repair-DX76Wike.mjs`);const r=await n(t);if(await countPendingDeliveryQueueEntriesReadOnly([`outbound`,`outbound-legacy-preparing-v1`,`outbound-prepared-migration-v1`],t)===0)return r;const i=await withLegacyMigrationStateLock({stateDir:e.stateDir,env:e.env,label:`legacy delivery queues`,releaseLabel:`Delivery queue`,run:async t=>{const{loadLegacyPendingDeliveries:n,loadPendingLegacyDeliveryPreparations:r,loadPendingDeliveryMigrations:i}=await import(`./delivery-queue-storage-MioRX0P-.mjs`);const a=n(e.stateDir);const o=r(e.stateDir);if(a.length===0&&o.length===0&&i(e.stateDir).length===0)return{changes:[],warnings:[]};const{migrateLegacyPendingOutboundDeliveries:s}=await import(`./delivery-queue-migration-D9n--AFv.mjs`);const c=[];const l={info:e=>{},warn:e=>c.push(e),error:e=>c.push(e)};const u={cfg:e.cfg,stateDir:e.stateDir,log:l};const d=a.length>0||o.some(e=>e.legacyPreparationState===`claimed`);let f;if(d){const{loadGatewayStartupPluginPlanWithMetadata:n}=await import(`./gateway-startup-plugin-loader-CrMWPwQD.mjs`);const{acquirePluginRegistryForInspection:r}=await import(`./plugins/loader.js`);const{createHookRunner:i}=await import(`./hooks-388WnVU-.mjs`);const{withPluginRegistryPreparationScope:a}=await import(`./registry-lifecycle-DtPg8Lne.mjs`);const{withPluginRuntimeRegistryScope:o}=await import(`./gateway-request-scope-BS6Ldhu6.mjs`);const d=tryResolveConfiguredAgentWorkspaceDir(e.cfg);const{plan:p,metadataSnapshot:m}=n({config:e.cfg,workspaceDir:d,env:t});const h=getOpenClawDatabaseMaintenanceScope();if(!h)throw new Error(`Outbound migration requires its maintenance resource owner`);let g;let _;h.own({},`agent-resources`,async()=>{if(g)try{await g.release()}catch(e){if(hasRetainedPluginRuntimeCloseError(e))throw e}else if(hasRetainedPluginRuntimeCloseError(_))throw _});try{g=await r({config:e.cfg,activationSourceConfig:e.cfg,env:t,workspaceDir:d,onlyPluginIds:[...p.pluginIds],manifestRegistry:m.manifestRegistry,discovery:m.discovery,channelPluginLoadIntent:`full`,runtimeSideEffects:true,throwOnLoadError:true})}catch(e){_=e;if(hasRetainedPluginRuntimeCloseError(e))throw e;return{changes:[],warnings:[...c,`Legacy outbound delivery preparation deferred: ${String(e)}. Run openclaw doctor --fix after repairing the plugin.`],warningDisposition:`recoverable`}}const v=g.registry;try{f=await a(v,()=>o(v,()=>s({...u,hookRunner:i(v,{logger:l,catchErrors:true})})))}catch(e){const t=[e];try{await g.release()}catch(e){t.push(e)}if(t.length>1)throw new AggregateError(t,`Outbound migration and plugin disposal failed`,{cause:e});throw e}await g.release()}else f=await s(u);if(f.remaining>0)c.push(`${f.remaining} legacy outbound deliveries still require preparation. Run openclaw doctor --fix to retry.`);return{changes:f.moved>0?[`Prepared ${f.moved} legacy outbound deliveries for current queue recovery`]:[],warnings:c,warningDisposition:`recoverable`}}});return{...i,changes:[...r.changes,...i.changes],warnings:[...r.warnings,...i.warnings]}}export{migrateDoctorDeliveryQueues};