UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

92 lines (91 loc) • 2.81 kB
import { b as uniqueStrings } from "./string-normalization-DLmfYZXI.mjs"; import { t as scrubDoctorErrorMessage } from "./doctor-error-message-BWgd1c6H.mjs"; import { r as listHealthChecks } from "./health-check-registry-Cl2vTx8K.mjs"; import { f as withDoctorProgress } from "./doctor-health-startup-KiSUu3WC.mjs"; //#region src/flows/doctor-repair-flow.ts async function runDoctorHealthRepairs(e, t = {}) { const n = t.checks ?? listHealthChecks(); const r = { config: e.cfg, findings: [], remainingFindings: [], changes: [], warnings: [], diffs: [], effects: [] }; for (const i of n) { const phase = (e, n) => withDoctorProgress(`${i.id}: ${e}`, n, t.progress === true); const n = { ...e, cfg: r.config }; let a; try { a = await phase("check", () => i.detect(n)); } catch (e) { const t = scrubDoctorErrorMessage(e); r.warnings.push(`${i.id} detect failed: ${t}`); const n = { checkId: i.id, severity: "warning", category: "fix-now", message: `Doctor could not complete ${i.description}: ${t}`, fixHint: "Inspect the reported cause and correct the failed prerequisite, then rerun openclaw doctor. This check has not established its health.", docsUrl: "https://docs.openclaw.ai/cli/doctor/running#understanding-findings" }; r.findings.push(n); r.remainingFindings.push(n); continue; } r.findings.push(...a); if (a.length === 0 || i.repair === void 0) { r.remainingFindings.push(...a); continue; } let o = a; try { const e = i.repair.bind(i); const s = await phase("repair", () => e({ ...n, dryRun: t.dryRun === true, diff: t.diff === true }, a)); r.warnings.push(...s.warnings ?? []); r.diffs.push(...s.diffs ?? []); r.effects.push(...s.effects ?? []); r.changes.push(...s.changes); const c = s.status ?? "repaired"; if (c !== "repaired") { r.warnings.push(`${i.id} repair ${c}${s.reason ? `: ${s.reason}` : ""}`); continue; } if (s.config !== void 0 && t.dryRun !== true) r.config = s.config; if (t.dryRun === true) continue; try { const e = await phase("validation", () => i.detect({ ...n, cfg: r.config }, { findings: o, paths: uniqueDefined(o.map((e) => e.path)), ocPaths: uniqueDefined(o.map((e) => e.ocPath)) })); o = e; if (e.length > 0) r.warnings.push(`${i.id} repair left ${e.length} finding(s)`); } catch (e) { r.warnings.push(`${i.id} validation failed: ${scrubDoctorErrorMessage(e)}`); } } catch (e) { r.warnings.push(`${i.id} repair failed: ${scrubDoctorErrorMessage(e)}`); } finally { r.remainingFindings.push(...o); } } return r; } function uniqueDefined(e) { return uniqueStrings(e.filter((e) => e !== void 0)); } //#endregion export { runDoctorHealthRepairs };