UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

55 lines (54 loc) • 3.26 kB
import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs"; import { a as isConfigReadFailure, t as configFailureHeading } from "./io.invalid-config-DK-BYZ4Y.mjs"; import { r as isPluginPackagingRuntimeOutputInvalidConfigSnapshot } from "./recovery-policy-CixJJb9O.mjs"; import { l as readConfigFileSnapshotForWrite, s as readConfigFileSnapshot } from "./io.runtime-DsJ2dLCQ.mjs"; import "./config-CMA-J084.mjs"; import { r as isJsonOutputModeActive } from "./json-output-mode-DSme4Xvd.mjs"; import { t as exitCliAfterOutput } from "./one-shot-exit-DkbGSQD5.mjs"; import { r as formatPluginPackagingRuntimeOutputRecoveryHint } from "./config-recovery-hints-DL4KuQ2q.mjs"; import { t as renderConfigValidationIssueLines } from "./issue-location-B-4mXR06.mjs"; //#region src/commands/config-validation.ts /** Read the config file and exit through the runtime when validation fails. */ async function requireValidConfigFileSnapshot(e, t) { const n = { ...t?.observe === false ? { observe: false } : {}, ...t?.skipPluginValidation ? { skipPluginValidation: true } : {} }; return validateConfigFileSnapshot(t?.adoptPluginMetadata ? (await (await import("./command-config-snapshot-Dq3IWUD7.mjs")).readCommandConfigSnapshot(n)).snapshot : await readConfigFileSnapshot(Object.keys(n).length > 0 ? n : void 0), e); } /** Preserve native read-time ownership through commands that can write after awaits. */ async function requireValidConfigForWrite(e) { const t = await readConfigFileSnapshotForWrite(); if (!await validateConfigFileSnapshot(t.snapshot, e)) return null; return t; } /** Each command phase owns prepared facts; installation ends the preceding metadata scope. */ async function withCommandPluginMetadata(e, t) { const [{ completePluginMetadataSnapshot: n, resolvePluginMetadataSnapshot: r }, { withPluginMetadataSnapshotScope: i }] = await Promise.all([import("./plugin-metadata-snapshot-PjL6_oGE.mjs"), import("./current-plugin-metadata-snapshot-wZiay48X.mjs")]); return await i(n(e) ?? r(e), t, { config: e.config, workspaceDir: e.workspaceDir }); } async function validateConfigFileSnapshot(e, t) { if (e.exists && !e.valid) { if (isJsonOutputModeActive(process.argv)) { const { writeInvalidConfigCliJson: n } = await import("./config-validation-output-BWmyUQ4V.mjs"); n(t, e); exitCliAfterOutput(t, 1); } const n = e.issues.length > 0 ? renderConfigValidationIssueLines(e).join("\n") : "Unknown validation issue."; t.error(`${configFailureHeading(e)}: ${e.path}\n${n}`); t.error(isConfigReadFailure(e) ? "Resolve the read error shown above, then retry." : isPluginPackagingRuntimeOutputInvalidConfigSnapshot(e) ? `Fix: ${formatPluginPackagingRuntimeOutputRecoveryHint()}` : `Fix: ${formatCliCommand("openclaw doctor --fix")}`); t.error(`Inspect: ${formatCliCommand("openclaw config validate")}`); t.exit(1); return null; } return e; } /** Read and return a valid OpenClaw config, or null after reporting validation errors. */ async function requireValidConfig(e, t) { return (await requireValidConfigFileSnapshot(e, t))?.config ?? null; } //#endregion export { withCommandPluginMetadata as i, requireValidConfigFileSnapshot as n, requireValidConfigForWrite as r, requireValidConfig as t };