UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

79 lines (78 loc) • 3.06 kB
import { r as validateConfigObjectRawWithPlugins } from "./validation-DSwgLhC7.mjs"; import { s as readConfigFileSnapshot } from "./io.runtime-DsJ2dLCQ.mjs"; import { i as resolveConfigIncludeWriteBoundary, r as replaceConfigFile } from "./mutate-DhAOi0-2.mjs"; import "./config-CMA-J084.mjs"; import { a as migrateLegacyConfig, i as restoreDoctorConfigEnvRefs, r as prepareDoctorConfigReferenceSource } from "./config-flow-steps-ETwvCUK9.mjs"; import { n as containsAuthoredInclude } from "./include-migration-ownership-CWJZ0wk-.mjs"; //#region src/commands/doctor/legacy-config-repair.ts /** Plan without replacing the source: update checkpoints must retain the authored bytes. */ function planLegacyConfigForUpdateChannel(e, t = {}) { const n = containsAuthoredInclude(e.parsed); const r = migrateLegacyConfig(e.sourceConfig, { sourceConfigBeforeMigrations: e.sourceConfigBeforeMigrations, context: { authoredRaw: e.parsed, resolvedRaw: e.sourceConfig } }); if (!r.config && !r.warnings?.length) return; const i = r.sourceConfig ?? r.config ?? e.sourceConfig; const a = validateConfigObjectRawWithPlugins(r.config ?? i); if (!a.ok) return; if (n && !resolveConfigIncludeWriteBoundary({ snapshot: e, nextConfig: i })) return; return { snapshot: e, config: a.config, nextConfig: i, changes: r.changes, ...r.warnings?.length ? { warnings: r.warnings } : {}, includeIdentity: { includeFileHashesForWrite: { ...t.includeFileHashesForWrite }, includeFileTargetsForWrite: { ...t.includeFileTargetsForWrite } } }; } /** * Persist the prepared migration without rebasing it onto later source edits. * Deferred callers seal/bind their checkpoint before invoking this writer; * the plan itself is source data, not proof of exclusion or write authority. */ async function repairLegacyConfigForUpdateChannel(e) { const t = e.plan ?? planLegacyConfigForUpdateChannel(e.configSnapshot); if (!t) return { snapshot: e.configSnapshot, repaired: false }; const n = t.warnings?.length ? { warnings: t.warnings } : {}; if (t.changes.length === 0) return { snapshot: e.configSnapshot, repaired: false, ...n }; if (e.plan && containsAuthoredInclude(t.snapshot.parsed)) { const e = t.snapshot.includedPaths ?? []; if (e.length === 0 || e.some((e) => !t.includeIdentity.includeFileHashesForWrite?.[e] || !t.includeIdentity.includeFileTargetsForWrite?.[e])) throw new Error("Legacy config plan is missing include write identities."); } await replaceConfigFile({ sourceConfig: restoreDoctorConfigEnvRefs(t.nextConfig, prepareDoctorConfigReferenceSource(t.snapshot)), baseHash: t.snapshot.hash, writeOptions: { ...e.plan ? t.includeIdentity : e.configWriteOptions, expectedConfigPath: t.snapshot.path, auditOrigin: "doctor", allowConfigSizeDrop: true, skipOutputLogs: e.jsonMode } }); const r = await readConfigFileSnapshot(); return { snapshot: r, repaired: r.valid, ...n }; } //#endregion export { repairLegacyConfigForUpdateChannel as n, planLegacyConfigForUpdateChannel as t };