UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

133 lines (132 loc) • 4.97 kB
import { i as hasRetainedPluginRuntimeCloseError } from "./runtime-close-error-Ak-r7PLO.mjs"; import { k as tryResolveConfiguredAgentWorkspaceDir } from "./agent-scope-config-DmXgFGKP.mjs"; import { a as getOpenClawDatabaseMaintenanceScope } from "./openclaw-state-maintenance-context-D6i7Zdhn.mjs"; import "./openclaw-state-db-async-lifecycle-CH8q4Sdl.mjs"; import "./agent-scope-BwB8YH6y.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-HQn65gG8.mjs"; import { i as countPendingDeliveryQueueEntriesReadOnly } from "./delivery-queue-sqlite-lyIJZlO0.mjs"; import { t as withLegacyMigrationStateLock } from "./state-migrations.lock-DKVTkbR4.mjs"; //#region src/commands/doctor-outbound-delivery.ts /** Doctor owns the retired raw queue; current delivery recovery never prepares old payloads. */ async function migrateDoctorDeliveryQueues(e) { const t = { ...e.env, OPENCLAW_STATE_DIR: e.stateDir }; const { repairRetiredDoctorState: n } = await import("./doctor-retired-state-repair-DuxmGBr8.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-DNsguS0r.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-BWn8RyLg.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-DVYUgAD_.mjs"); const { acquirePluginRegistryForInspection: r } = await import("./plugins/loader.js"); const { createHookRunner: i } = await import("./hooks-C5niPW1e.mjs"); const { withPluginRegistryPreparationScope: a } = await import("./registry-lifecycle-C5nApG8p.mjs"); const { withPluginRuntimeRegistryScope: o } = await import("./gateway-request-scope-CF7UIf6R.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] }; } //#endregion export { migrateDoctorDeliveryQueues };