refactor(cli): lazy-load models runtime

This commit is contained in:
Vincent Koc
2026-05-14 15:47:43 +08:00
parent bfc798bd0b
commit babd25c6b7
4 changed files with 159 additions and 61 deletions

View File

@@ -0,0 +1,33 @@
import type { Command } from "commander";
import { defaultRuntime } from "../runtime.js";
import { resolveOptionFromCommand, runCommandWithRuntime } from "./cli-utils.js";
import { formatCliCommand } from "./command-format.js";
export { defaultRuntime };
export function runModelsCommand(action: () => Promise<void>) {
return runCommandWithRuntime(defaultRuntime, action);
}
export function resolveModelAgentOption(
command: Command | undefined,
opts?: { agent?: unknown },
): string | undefined {
return (
resolveOptionFromCommand<string>(command, "agent") ??
(typeof opts?.agent === "string" ? opts.agent : undefined)
);
}
export function rejectAgentScopedModelWrite(
command: Command,
commandName: "set" | "set-image",
): void {
const agent = resolveOptionFromCommand<string>(command, "agent");
if (!agent) {
return;
}
throw new Error(
`openclaw models ${commandName} does not support --agent; it only updates global model defaults. Remove --agent, or run ${formatCliCommand("openclaw agents list")} and set the per-agent model in agent config.`,
);
}