openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
187 lines (186 loc) • 6.27 kB
JavaScript
import { o as getCommandPositionalsWithRootOptions } from "./cli-root-options-xlQx6o4R.mjs";
import { r as getFlagValue, s as hasFlag } from "./argv-CbnKpH-r.mjs";
import { t as resolveCliArgvInvocation } from "./argv-invocation-C9SmXUsh.mjs";
import { t as resolveCliDatabaseProcessRole } from "./database-process-role-MptgTPr9.mjs";
//#region src/cli/database-engine-selection.ts
const OWNED_DATABASE_SELECTION = /* @__PURE__ */ new Set([
"",
"gateway",
"help",
"completion *",
"docs *",
"logs *",
"channels logs",
"config file",
"config validate",
"gateway call",
"gateway health",
"gateway suspend",
"gateway resume",
"gateway usage-cost",
"gateway stability",
"channels status",
"agent remote",
"cron *",
"automations *",
"devices *",
"nodes status",
"nodes list",
"nodes describe",
"nodes pending",
"nodes approve",
"nodes reject",
"nodes remove",
"nodes rename",
"nodes invoke",
"nodes notify",
"nodes push",
"nodes camera",
"nodes screen",
"nodes location",
"secrets reload",
"approvals pending",
"exec-approvals pending",
"memory",
"memory status",
"memory index",
"memory reset",
"memory search",
"memory forget",
"memory promote",
"memory promote-explain",
"memory rem-harness",
"memory rem-backfill",
"memory session-backfill",
"gateway restart",
"daemon restart",
"node restart",
"gateway stop",
"daemon stop",
"gateway uninstall",
"daemon uninstall",
"node stop",
"node uninstall",
"node status",
"gateway discover",
"gateway runtime-intent",
"daemon runtime-intent",
"qa *",
"database *",
"agent exec",
"plugins build",
"plugins validate",
"plugins lint",
"plugins init",
"templates create",
"templates validate",
"templates build",
"templates dev",
"config set",
"config patch",
"config unset",
"reset config",
"uninstall service",
"doctor explicit-store",
"doctor update",
"doctor post-upgrade",
"update *"
]);
/** Select storage before stateful startup; true means Doctor completed a no-database report. */
async function prepareCliDatabaseEngine(e) {
const t = resolveCliArgvInvocation(e);
const n = t.primary === "onboard" ? getCommandPositionalsWithRootOptions(e, {
commandPath: ["onboard"],
booleanFlags: ["--json"],
maxPositionals: 1,
mode: "command-path"
})?.[0] : void 0;
const r = ["setup", "crestodian"].includes(t.primary ?? "") || t.primary === "onboard" && n !== "recommendations";
let i = t.hasHelpOrVersion ? "help" : resolveCliDatabaseProcessRole(e) === "gateway" ? "gateway" : t.commandPath.slice(0, 2).join(" ");
if (t.primary === "agent" && t.commandPath[1] !== "exec" && !hasFlag(e, "--local")) i = "agent remote";
if (["gateway status", "daemon status"].includes(i) && hasFlag(e, "--runtime-intent-only")) i = `${t.primary} runtime-intent`;
if (t.primary === "reset" && getFlagValue(e, "--scope") === "config") i = "reset config";
if (t.primary === "uninstall" && hasFlag(e, "--service") && ![
"--all",
"--state",
"--workspace"
].some((t) => hasFlag(e, t))) i = "uninstall service";
if (t.primary === "doctor" && !t.hasHelpOrVersion) {
if (hasFlag(e, "--session-sqlite-store") || hasFlag(e, "--client-credentials")) i = "doctor explicit-store";
else if (process.env.OPENCLAW_UPDATE_POST_INSTALL_DOCTOR_RESULT_PATH?.trim()) i = "doctor update";
else if (hasFlag(e, "--post-upgrade")) i = "doctor post-upgrade";
}
if (OWNED_DATABASE_SELECTION.has(i) || OWNED_DATABASE_SELECTION.has(`${t.primary} *`)) return false;
const { readConfigSnapshotBeforeEngineSelection: a } = await import("./config-preflight-snapshot-DXY8QhxC.mjs");
const readSnapshot = () => a(process.env, { isolateEnv: false });
let o = await readSnapshot();
if (r && hasFlag(e, "--reset")) return false;
if (r && o.issues.some((e) => e.errorCode === "CONFIG_SOURCE_INVALID") && (await import("./paths-C9ebzH5f.mjs")).resolveIsConfigReadOnly()) {
const { createConfigMutationError: e } = await import("./config-write-guard-C8xOz4HA.mjs");
throw e({ configPath: o.path });
}
let s = false;
const { createConfigReadError: c, createInvalidConfigError: l, formatInvalidConfigDetails: u, isConfigReadFailure: d } = await import("./io.invalid-config-DHUoEji6.mjs");
if (r && !hasFlag(e, "--non-interactive") && !hasFlag(e, "--json") && !d(o) && o.issues.some((e) => e.errorCode === "CONFIG_SOURCE_INVALID")) {
const [{ offerInvalidConfigRecovery: e }, { prepareDoctorEngineSelection: t }, { defaultRuntime: n }] = await Promise.all([
import("./invalid-config-recovery-ExdYI41x.mjs"),
import("./doctor-engine-selection-DxSd2kyC.mjs"),
import("./runtime-PcIG_sHE.mjs")
]);
n.error(l(o.path, u(o.issues)).message);
if (!await e({
runtime: n,
runDoctor: async () => {
o = await t({
argv: [
"node",
"openclaw",
"doctor",
"--fix"
],
snapshot: o,
readSnapshot
});
},
retry: async () => {
if (d(o)) throw c(o);
if (o.issues.some((e) => e.errorCode === "CONFIG_SOURCE_INVALID")) throw l(o.path, u(o.issues));
}
})) n.exit(1);
}
if (t.primary === "doctor" && o.issues.some((e) => e.errorCode === "CONFIG_SOURCE_INVALID")) {
s = true;
const { prepareDoctorEngineSelection: t, reportDoctorUnresolvedEngine: n } = await import("./doctor-engine-selection-DxSd2kyC.mjs");
try {
o = await t({
argv: e,
snapshot: o,
readSnapshot
});
} catch (t) {
n(o, e, t);
return true;
}
if (d(o) || o.issues.some((e) => e.errorCode === "CONFIG_SOURCE_INVALID")) {
n(o, e);
return true;
}
}
if (d(o)) throw c(o);
if (o.issues.some((e) => e.errorCode === "CONFIG_SOURCE_INVALID")) throw l(o.path, u(o.issues));
const [{ resolveDatabaseEngineSelection: f }, { installDatabaseEngineSelection: p }] = await Promise.all([import("./config-eNRW_vew.mjs"), import("./context-Dz_LKKUd.mjs")]);
try {
p(await f(o.config, process.env));
} catch (t) {
if (!s) throw t;
const { reportDoctorUnresolvedEngine: n } = await import("./doctor-engine-selection-DxSd2kyC.mjs");
n(o, e, t);
return true;
}
const [{ pinRuntimePaths: m }, { pinConfigDir: h }] = await Promise.all([import("./paths-C9ebzH5f.mjs"), import("./utils-C6VO5Omq.mjs")]);
m(process.env);
h(process.env);
return false;
}
//#endregion
export { prepareCliDatabaseEngine };