UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

127 lines (126 loc) • 5.05 kB
import { N as shouldMigrateStateFromPath } from "./logger-kwZIqwuw.js"; import "./paths-ViKUYWUK.js"; import "./tmp-openclaw-dir-idKIOMmb.js"; import "./theme-CdOoMzRk.js"; import "./globals-DBUMOBZ8.js"; import "./subsystem-DISldKSB.js"; import "./ansi-BEJF8NKS.js"; import "./boolean-C3GkJetE.js"; import "./env-Dnra1IpT.js"; import "./utils-CS0Ikux6.js"; import "./agent-scope-bjWqU22i.js"; import "./boundary-path-Dm0QJ7-y.js"; import "./boundary-file-read-DcZxlWD8.js"; import "./logger-BmpSCz93.js"; import "./exec-B5_AYfQG.js"; import "./workspace-D4K6QX9X.js"; import "./model-selection-BnFtDmP7.js"; import { d as readConfigFileSnapshot } from "./io-y3Az_Onx.js"; import "./shell-env-BOu7XeT_.js"; import "./safe-text-yavot2qw.js"; import "./version-CD3oP1-d.js"; import "./env-substitution-O6uabUmO.js"; import "./includes-Bj3eLUWH.js"; import "./zod-schema.providers-core-COy5nBQ0.js"; import "./legacy-web-search-BB-ZHEhz.js"; import "./registry-C5UkPpaO.js"; import "./config-state-Br0ucqMb.js"; import "./min-host-version-RMBWtIAR.js"; import "./manifest-registry-B5JNQdOM.js"; import "./runtime-guard-PhQ6PwQa.js"; import "./avatar-policy-B5nOfso_.js"; import "./ip-Ce8EDTBZ.js"; import "./zod-schema.agent-runtime-Dtg4Jy6G.js"; import "./zod-schema.core-BuVz8Rk7.js"; import "./config-D4zN4BRl.js"; //#region src/cli/program/config-guard.ts const ALLOWED_INVALID_COMMANDS = new Set([ "doctor", "logs", "health", "help", "status" ]); const ALLOWED_INVALID_GATEWAY_SUBCOMMANDS = new Set([ "status", "probe", "health", "discover", "call", "install", "uninstall", "start", "stop", "restart" ]); let didRunDoctorConfigFlow = false; let configSnapshotPromise = null; function resetConfigGuardStateForTests() { didRunDoctorConfigFlow = false; configSnapshotPromise = null; } async function getConfigSnapshot() { if (process.env.VITEST === "true") return readConfigFileSnapshot(); configSnapshotPromise ??= readConfigFileSnapshot(); return configSnapshotPromise; } async function ensureConfigReady(params) { const commandPath = params.commandPath ?? []; let preflightSnapshot = null; if (!didRunDoctorConfigFlow && shouldMigrateStateFromPath(commandPath)) { didRunDoctorConfigFlow = true; const runDoctorConfigPreflight = async () => (await import("./doctor-config-preflight-DIPBgMe6.js")).runDoctorConfigPreflight({ migrateState: false, migrateLegacyConfig: false, invalidConfigNote: false }); if (!params.suppressDoctorStdout) preflightSnapshot = (await runDoctorConfigPreflight()).snapshot; else { const originalStdoutWrite = process.stdout.write.bind(process.stdout); const originalSuppressNotes = process.env.OPENCLAW_SUPPRESS_NOTES; process.stdout.write = (() => true); process.env.OPENCLAW_SUPPRESS_NOTES = "1"; try { preflightSnapshot = (await runDoctorConfigPreflight()).snapshot; } finally { process.stdout.write = originalStdoutWrite; if (originalSuppressNotes === void 0) delete process.env.OPENCLAW_SUPPRESS_NOTES; else process.env.OPENCLAW_SUPPRESS_NOTES = originalSuppressNotes; } } } const snapshot = preflightSnapshot ?? await getConfigSnapshot(); const commandName = commandPath[0]; const subcommandName = commandPath[1]; const allowInvalid = commandName ? ALLOWED_INVALID_COMMANDS.has(commandName) || commandName === "gateway" && subcommandName && ALLOWED_INVALID_GATEWAY_SUBCOMMANDS.has(subcommandName) : false; const { formatConfigIssueLines } = await import("./issue-format-BB_Prw9W.js"); const issues = snapshot.exists && !snapshot.valid ? formatConfigIssueLines(snapshot.issues, "-", { normalizeRoot: true }) : []; const legacyIssues = snapshot.legacyIssues.length > 0 ? formatConfigIssueLines(snapshot.legacyIssues, "-") : []; if (!(snapshot.exists && !snapshot.valid)) return; const [{ colorize, isRich, theme }, { shortenHomePath }, { formatCliCommand }] = await Promise.all([ import("./theme-B5HDbQfl.js"), import("./utils-ChODAevd.js"), import("./command-format-Curl_YVg.js") ]); const rich = isRich(); const muted = (value) => colorize(rich, theme.muted, value); const error = (value) => colorize(rich, theme.error, value); const heading = (value) => colorize(rich, theme.heading, value); const commandText = (value) => colorize(rich, theme.command, value); params.runtime.error(heading("Config invalid")); params.runtime.error(`${muted("File:")} ${muted(shortenHomePath(snapshot.path))}`); if (issues.length > 0) { params.runtime.error(muted("Problem:")); params.runtime.error(issues.map((issue) => ` ${error(issue)}`).join("\n")); } if (legacyIssues.length > 0) { params.runtime.error(muted("Legacy config keys detected:")); params.runtime.error(legacyIssues.map((issue) => ` ${error(issue)}`).join("\n")); } params.runtime.error(""); params.runtime.error(`${muted("Run:")} ${commandText(formatCliCommand("openclaw doctor --fix"))}`); if (!allowInvalid) params.runtime.exit(1); } const __test__ = { resetConfigGuardStateForTests }; //#endregion export { __test__, ensureConfigReady };