openclaw/src/commands/onboard-non-interactive.ts

38 lines
1.3 KiB
TypeScript
Raw Normal View History

2026-01-30 03:15:10 +01:00
import type { OpenClawConfig } from "../config/config.js";
2026-01-01 18:23:16 +01:00
import type { RuntimeEnv } from "../runtime.js";
import type { OnboardOptions } from "./onboard-types.js";
import { formatCliCommand } from "../cli/command-format.js";
import { readConfigFileSnapshot } from "../config/config.js";
2026-01-01 18:23:16 +01:00
import { defaultRuntime } from "../runtime.js";
2026-01-14 05:39:47 +00:00
import { runNonInteractiveOnboardingLocal } from "./onboard-non-interactive/local.js";
import { runNonInteractiveOnboardingRemote } from "./onboard-non-interactive/remote.js";
2026-01-01 18:23:16 +01:00
export async function runNonInteractiveOnboarding(
opts: OnboardOptions,
runtime: RuntimeEnv = defaultRuntime,
) {
const snapshot = await readConfigFileSnapshot();
if (snapshot.exists && !snapshot.valid) {
2026-01-20 07:42:21 +00:00
runtime.error(
2026-01-30 03:15:10 +01:00
`Config invalid. Run \`${formatCliCommand("openclaw doctor")}\` to repair it, then re-run onboarding.`,
2026-01-20 07:42:21 +00:00
);
runtime.exit(1);
return;
}
2026-01-14 05:39:47 +00:00
2026-01-30 03:15:10 +01:00
const baseConfig: OpenClawConfig = snapshot.valid ? snapshot.config : {};
2026-01-07 09:58:54 +01:00
const mode = opts.mode ?? "local";
if (mode !== "local" && mode !== "remote") {
runtime.error(`Invalid --mode "${String(mode)}" (use local|remote).`);
runtime.exit(1);
return;
}
2026-01-01 18:23:16 +01:00
if (mode === "remote") {
2026-01-14 05:39:47 +00:00
await runNonInteractiveOnboardingRemote({ opts, runtime, baseConfig });
2026-01-01 18:23:16 +01:00
return;
}
2026-01-14 05:39:47 +00:00
await runNonInteractiveOnboardingLocal({ opts, runtime, baseConfig });
2026-01-01 18:23:16 +01:00
}