openclaw/src/cli/models-cli.runtime.ts
2026-05-14 15:48:11 +08:00

33 lines
1.1 KiB
TypeScript

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.`,
);
}