mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-27 05:17:48 +00:00
refactor(cli): lazy-load models runtime
This commit is contained in:
33
src/cli/models-cli.runtime.ts
Normal file
33
src/cli/models-cli.runtime.ts
Normal 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.`,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user