UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

159 lines (158 loc) • 8.06 kB
import { i as collectNestedErrorCandidates } from "./error-coercion-hDrHOSGy.mjs"; import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs"; import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs"; import { n as StartupMaintenanceRequiredError } from "./startup-maintenance-required-DEn4Krys.mjs"; import { r as withArtifactPreservingStateReads } from "./artifact-preserving-state-reads-BfhmBr-V.mjs"; import { s as resolveOpenClawStateSqlitePath } from "./openclaw-state-db.paths-R3ArRCcz.mjs"; import "./gateway-state-owner-Bnv5owvG.mjs"; import { t as GatewayStateOwnerContentionError } from "./gateway-state-owner-errors-DI3mhN4z.mjs"; import { i as hasCommandProcessCleanupError } from "./exec-result-DJMhztYN.mjs"; import { n as executeExistingOpenClawStateRead } from "./openclaw-state-db-readonly-B6YHb1oF.mjs"; import { k as readStateLeaseProcessOwnerStatus } from "./openclaw-state-db-existing-schema-C1h5v6Xh.mjs"; import { t as UpdateSchemaRefusalError } from "./openclaw-update-schema-refusal-DQDN1MLl.mjs"; import { d as hasGatewayServiceStopUnsafeError } from "./service-inspection-error-BKgh5HDJ.mjs"; import { t as DoctorMaintenanceRefusalError } from "./update-doctor-result-DwaI51On.mjs"; import { t as ConfigWritePostCommitError } from "./io.write-errors-CuPAqPbq.mjs"; import { t as DoctorUnreadableStateDatabaseError } from "./state-repair-message-CG0JUAZp.mjs"; import { t as ExecApprovalsMigrationRequiredError } from "./exec-approvals-migration-gate-B5wo0WQB.mjs"; import { n as GatewayLockError } from "./gateway-lock-IYOwJQai.mjs"; import { t as DoctorStateMigrationRefusalError } from "./state-migrations.messages-CNB52OxC.mjs"; //#region src/commands/doctor-maintenance-inspection.ts /** An app's package-update authority does not own repair of its already offline state. */ async function readOfflineAppOwnedDoctorInspection(e, t) { const { GatewayServiceUpdateOwnershipError: n } = await import("./update-command-service-plan-Bc8xWWoh.mjs"); if (hasCommandProcessCleanupError(e) || !(e instanceof n) || !e.failureFacts.some((e) => e.check === "managed-service" && e.code === "service-mutation-refused")) return; const { readGatewayServiceState: r, resolveGatewayService: i } = await import("./service-D5ZNJZsc.mjs"); const { assertDoctorServiceSelection: a } = await import("./doctor-service-repair-policy-Yhj-PuNX.mjs"); const o = await r(i(), { env: t, requireEffective: true, validateEnvBeforeStatusRead: (e) => a(t, e) }); if (!o.command) return; const { summarizeGatewayServiceLayout: s } = await import("./service-layout-Cc8-naBU.mjs"); const { readInstallOwner: c, formatInstallOwnerMessage: l } = await import("./install-owner-HbpTWvNb.mjs"); const u = await c((await s(o.command))?.packageRootReal ?? null); const { isManagedGatewayServiceOffline: d } = await import("./update-command-service-publication-D9gg7bDM.mjs"); if (!u || !await d(o)) return; const f = `${l(u)} Doctor can repair offline state; Gateway service installation and activation remain with the app.`; return { stopped: false, inspected: true, runtimeInspected: true, running: false, offline: true, serviceEnv: o.env, serviceMutationAllowed: false, serviceUpdateVerdict: { kind: "unavailable", message: f }, serviceMutationSkipMessage: f }; } /** Observe the selected installation without bootstrapping it or inheriting a discovery view. */ async function readDoctorGatewayOwnerLease(e, t) { const n = { env: { ...e }, path: resolveOpenClawStateSqlitePath(e) }; const r = await withArtifactPreservingStateReads(() => executeExistingOpenClawStateRead(n, { type: "gatewayOwnerLease.read", schemaMaintenance: true }, { current: true, signal: t })); t.throwIfAborted(); if (!r) return; return r.lease ? { ...r.lease, state: readStateLeaseProcessOwnerStatus(r.lease, r.lease.heartbeatAt) } : void 0; } /** Admission has not opened repair writers; deferral cannot authorize any later work. */ function classifyDoctorMaintenanceRefusal(e) { const t = collectNestedErrorCandidates(e); const n = t.find((e) => e instanceof DoctorMaintenanceRefusalError && e.refusal.kind === "data-at-risk"); if (n) return n.refusal; if (hasGatewayServiceStopUnsafeError(e) || hasCommandProcessCleanupError(e)) return { kind: "data-at-risk", reason: "active-mutation" }; if (t.some((e) => e instanceof DoctorUnreadableStateDatabaseError)) return { kind: "data-at-risk", reason: "unreadable-state" }; if (t.some((e) => e instanceof DoctorStateMigrationRefusalError || e instanceof StartupMaintenanceRequiredError || e instanceof ExecApprovalsMigrationRequiredError || e instanceof UpdateSchemaRefusalError)) return { kind: "data-at-risk", reason: "incomplete-migration" }; if (t.some((e) => e instanceof GatewayLockError || e instanceof ConfigWritePostCommitError && e.rollbackStatus !== "restored")) return { kind: "data-at-risk", reason: "gateway-state-unverified" }; return { kind: "deferred", reason: t.some((e) => e instanceof GatewayStateOwnerContentionError) ? "coordinator-contention" : "admission-unavailable" }; } /** The same persisted-state admission protects completion and exceptional restoration. */ async function assertDoctorMaintenanceReady(e, t, n, r) { let i = false; let a = []; const { assertSessionStoreMigrationComplete: o } = await import("./startup-migration-G4xLSSxu.mjs"); o({ cfg: e, env: t, operation: "doctor" }); const { assertOpenClawDatabasesReady: s } = await import("./openclaw-database-preflight-BB0y4HYJ.mjs"); const { resolveConfiguredAgentDatabaseTargets: c } = await import("./targets-cXkr4Sqy.mjs"); try { await s({ env: t, config: e, operation: "doctor", onDeferredSchemaPublication: (e) => { i = true; n(e.message); }, onVerified: (e) => { a = e.agentRefusals?.flatMap((e) => e.paths) ?? []; }, configuredAgentDatabaseTargets: c(e, { env: t }) }); } catch (e) { throw new DoctorMaintenanceRefusalError(formatErrorMessage(e), { kind: "data-at-risk", reason: "incomplete-migration" }, { cause: e }); } const { assertConfiguredWorkspaceStateReady: l } = await import("./workspace-state-dirs-H0UukwV6.mjs"); await l({ cfg: e, operation: "doctor" }); if (!i && r) { const { completeDoctorMigrationBackups: e } = await import("./doctor-migration-backup-artifacts-iqehb2Km.mjs"); try { e(t, r.filter((e) => !a.some((t) => t === e.path || t === e.realPath)).map((e) => e.path)); } catch (e) { n(`Migration backups remain protected; completion registration failed: ${String(e)}`); } } return { schemaPublicationDeferred: i }; } function assertDoctorMaintenanceInspection(e, t) { const n = e.serviceUpdateVerdict?.kind; if (!e.blockMessage && (n === "unavailable" || e.inspected && (n === "owned" || n === "absent" || e.offline === true))) return; const r = e.blockMessage ?? e.serviceMutationSkipMessage ?? `Gateway service ownership or shutdown could not be verified. Run ${formatCliCommand("openclaw gateway status --deep", t)} and stop it through its service owner before retrying.`; const i = n === "foreign" ? `Run ${formatCliCommand("openclaw gateway status --deep", t)} to find the Gateway installation. If an operator-owned launcher override points there, update or remove that override; reinstalling alone will not fix it. Inspect systemd overrides with systemctl cat (--user for user services). The service was left unchanged.` : `Stop the Gateway service and other OpenClaw processes using this state, then run ${formatCliCommand("openclaw doctor --fix", t)} from an independent shell.`; throw new DoctorMaintenanceRefusalError(`Doctor could not enter maintenance. Error: ${r} ${i}`, { kind: "data-at-risk", reason: "gateway-state-unverified" }, { failureFacts: e.blockFailureFacts }); } //#endregion export { readOfflineAppOwnedDoctorInspection as a, readDoctorGatewayOwnerLease as i, assertDoctorMaintenanceReady as n, classifyDoctorMaintenanceRefusal as r, assertDoctorMaintenanceInspection as t };