UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

106 lines (105 loc) • 4.97 kB
import { n as createNonExitingRuntime, r as defaultRuntime } from "./runtime-BRg2NubB.mjs"; import { r as resolveStateDir } from "./state-dir-CYkBUd_G.mjs"; import { C as resolveIsNixMode } from "./paths-BP0DYpE8.mjs"; import { t as exitCliAfterOutput } from "./one-shot-exit-Cp7k2m-c.mjs"; import { n as resolveDoctorRepairMode } from "./doctor-repair-mode-p8fxj8I_.mjs"; import fs from "node:fs"; //#region src/flows/doctor-health-startup.ts function exitDoctorHealthFlow(runtime, code) { if (runtime === defaultRuntime) exitCliAfterOutput(runtime, code); runtime.exit(code); } function stateDirectoryExistsAtDoctorStart() { try { return fs.statSync(resolveStateDir()).isDirectory(); } catch { return false; } } async function prepareDoctorHealthFlow(runtime, options, intro) { const effectiveRuntime = runtime ?? (await import("./runtime-C8KQWZf7.mjs")).defaultRuntime; const repairRuntime = { ...effectiveRuntime, exit: createNonExitingRuntime().exit }; const stateDirExistedAtStart = stateDirectoryExistsAtDoctorStart(); intro("OpenClaw doctor"); const { resolveOpenClawPackageRoot } = await import("./openclaw-root-BJJK7daK.mjs"); const root = await resolveOpenClawPackageRoot({ moduleUrl: import.meta.url, argv1: process.argv[1], cwd: process.cwd() }); if (resolveIsNixMode() && (options.repair === true || options.yes === true || options.generateGatewayToken === true)) { const { assertConfigWriteAllowedInCurrentMode } = await import("./config-write-guard-DC0DpvIi.mjs"); assertConfigWriteAllowedInCurrentMode(); } if (!resolveDoctorRepairMode(options).updateInProgress) { const [{ readSourceConfigBestEffort }, { inspectDoctorTailscalePrerequisite }] = await Promise.all([import("./io.runtime.js"), import("./doctor-tailscale-D98wNau_.mjs")]); const prerequisite = await inspectDoctorTailscalePrerequisite(await readSourceConfigBestEffort()); if (prerequisite) { const { note } = await import("./terminal-core/note.js"); note(prerequisite, "Gateway startup prerequisite"); } } return { effectiveRuntime, repairRuntime, stateDirExistedAtStart, root }; } async function prepareDoctorInteractiveMaintenance(params) { const { createDoctorPrompter } = await import("./doctor-prompter-DfExfSVV.mjs"); const { prepareDoctorDatabasePreflight } = await import("./doctor-database-preflight-Boy2l09m.mjs"); const prompter = createDoctorPrompter({ runtime: params.runtime, options: params.options }); if (!params.databasePreflight) await prepareDoctorDatabasePreflight({ scope: "state" }); const { maybeOfferUpdateBeforeDoctor } = await import("./doctor-update-0LFi29rj.mjs"); if ((await maybeOfferUpdateBeforeDoctor({ options: params.options, root: params.root, confirm: (p) => prompter.confirm(p), outro: params.outro })).handled) return "handled"; if (!params.databasePreflight) await prepareDoctorDatabasePreflight(); if (await prompter.confirmRuntimeRepair({ message: "Pause the managed Gateway while you review repairs? Doctor restores its prior service state when finished.", initialValue: true, requiresInteractiveConfirmation: true })) return "accepted"; params.runtime.log("Doctor repairs skipped. Continuing read-only diagnosis."); const { runDoctorLintCli } = await import("./doctor-lint-BIfrH_rT.mjs"); return { diagnosticExitCode: await runDoctorLintCli(params.runtime, { allowExec: params.options.allowExec, deep: params.options.deep }) }; } async function prepareDoctorMaintenanceArchives(databasePreflight, runtime, preflightOptions = {}) { let discovery; try { const { prepareDoctorDatabasePreflight } = await import("./doctor-database-preflight-Boy2l09m.mjs"); discovery = (databasePreflight ?? await prepareDoctorDatabasePreflight(preflightOptions)).agentDatabaseMigrationDiscovery; if (discovery) { const { prepareCanonicalTranscriptArchiveMigrations } = await import("./state-migrations.transcript-directives-archives-CEhU9Jyg.mjs"); await prepareCanonicalTranscriptArchiveMigrations(discovery); } } catch (error) { runtime.log(`Archive verification preparation deferred: ${String(error)}`); } const { waitForCliSignalExit } = await import("./signal-exit-barrier-DSvUqIYX.mjs"); await waitForCliSignalExit(); return discovery; } async function prepareDoctorStateSchema(schemas, shouldRepair) { if (!shouldRepair || !schemas.pendingMigrations?.some((entry) => entry.kind === "state")) return; const { prepareLegacyStateDatabaseSchema } = await import("./state-migrations.doctor-DD1CDbaH.mjs"); const { throwIfDoctorStateMigrationRefused } = await import("./state-migrations.messages-JeVUPL7d.mjs"); const receipt = await prepareLegacyStateDatabaseSchema(process.env); throwIfDoctorStateMigrationRefused([receipt]); return receipt; } //#endregion export { prepareDoctorStateSchema as a, prepareDoctorMaintenanceArchives as i, prepareDoctorHealthFlow as n, prepareDoctorInteractiveMaintenance as r, exitDoctorHealthFlow as t };