mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
fix(cli): clarify auth profile order output (#112203)
* fix(cli): clarify auth profile order output * fix(cli): report auth order fallback source * test(cli): trim auth order wording coverage
This commit is contained in:
@@ -467,7 +467,7 @@ export function registerModelsCli(program: Command) {
|
||||
|
||||
order
|
||||
.command("get")
|
||||
.description("Show per-agent auth order override (from auth-state.json)")
|
||||
.description("Show per-agent auth profile order override")
|
||||
.requiredOption("--provider <name>", "Provider id (e.g. anthropic)")
|
||||
.option("--agent <id>", "Agent id (default: configured default agent)")
|
||||
.option("--json", "Output JSON", false)
|
||||
@@ -488,7 +488,7 @@ export function registerModelsCli(program: Command) {
|
||||
|
||||
order
|
||||
.command("set")
|
||||
.description("Set per-agent auth order override (writes auth-state.json)")
|
||||
.description("Set per-agent auth profile order override")
|
||||
.requiredOption("--provider <name>", "Provider id (e.g. anthropic)")
|
||||
.option("--agent <id>", "Agent id (default: configured default agent)")
|
||||
.argument("<profileIds...>", "Auth profile ids (e.g. anthropic:default)")
|
||||
@@ -509,7 +509,7 @@ export function registerModelsCli(program: Command) {
|
||||
|
||||
order
|
||||
.command("clear")
|
||||
.description("Clear per-agent auth order override (fall back to config/round-robin)")
|
||||
.description("Clear per-agent auth profile order override")
|
||||
.requiredOption("--provider <name>", "Provider id (e.g. anthropic)")
|
||||
.option("--agent <id>", "Agent id (default: configured default agent)")
|
||||
.action(async (opts, command) => {
|
||||
|
||||
@@ -7,8 +7,10 @@ import {
|
||||
resolveAuthStatePathForDisplay,
|
||||
setAuthProfileOrder,
|
||||
} from "../../agents/auth-profiles.js";
|
||||
import { normalizeProviderId } from "../../agents/model-selection.js";
|
||||
import { findNormalizedProviderValue, normalizeProviderId } from "../../agents/model-selection.js";
|
||||
import { resolveProviderIdForAuth } from "../../agents/provider-auth-aliases.js";
|
||||
import { formatCliCommand } from "../../cli/command-format.js";
|
||||
import type { OpenClawConfig } from "../../config/types.openclaw.js";
|
||||
import { type RuntimeEnv, writeRuntimeJson } from "../../runtime.js";
|
||||
import { shortenHomePath } from "../../utils.js";
|
||||
import { loadModelsConfig } from "./load-config.js";
|
||||
@@ -20,6 +22,19 @@ function describeOrder(store: AuthProfileStore, provider: string): string[] {
|
||||
return Array.isArray(order) ? order : [];
|
||||
}
|
||||
|
||||
function describeOrderFallback(cfg: OpenClawConfig, provider: string): string {
|
||||
const authProvider = resolveProviderIdForAuth(provider, { config: cfg });
|
||||
const configuredOrder =
|
||||
findNormalizedProviderValue(cfg.auth?.order, authProvider) ??
|
||||
findNormalizedProviderValue(cfg.auth?.order, provider);
|
||||
if (configuredOrder === undefined) {
|
||||
return "selecting automatically";
|
||||
}
|
||||
return configuredOrder.length > 0
|
||||
? `using order from config: ${configuredOrder.join(", ")}`
|
||||
: "config selects no profiles";
|
||||
}
|
||||
|
||||
async function resolveAuthOrderContext(
|
||||
opts: { provider: string; agent?: string },
|
||||
runtime: RuntimeEnv,
|
||||
@@ -61,7 +76,11 @@ export async function modelsAuthOrderGetCommand(
|
||||
runtime.log(`Agent: ${agentId}`);
|
||||
runtime.log(`Provider: ${provider}`);
|
||||
runtime.log(`Auth state store: ${shortenHomePath(resolveAuthStatePathForDisplay(agentDir))}`);
|
||||
runtime.log(order.length > 0 ? `Order override: ${order.join(", ")}` : "Order override: (none)");
|
||||
runtime.log(
|
||||
order.length > 0
|
||||
? `Auth profile order override: ${order.join(", ")}`
|
||||
: `Auth profile order override: none (${describeOrderFallback(cfg, provider)})`,
|
||||
);
|
||||
}
|
||||
|
||||
/** Clears the configured auth profile priority order for a provider. */
|
||||
@@ -69,7 +88,7 @@ export async function modelsAuthOrderClearCommand(
|
||||
opts: { provider: string; agent?: string },
|
||||
runtime: RuntimeEnv,
|
||||
) {
|
||||
const { agentId, agentDir, provider } = await resolveAuthOrderContext(opts, runtime);
|
||||
const { cfg, agentId, agentDir, provider } = await resolveAuthOrderContext(opts, runtime);
|
||||
const updated = await setAuthProfileOrder({
|
||||
agentDir,
|
||||
provider,
|
||||
@@ -83,7 +102,7 @@ export async function modelsAuthOrderClearCommand(
|
||||
|
||||
runtime.log(`Agent: ${agentId}`);
|
||||
runtime.log(`Provider: ${provider}`);
|
||||
runtime.log("Cleared per-agent order override.");
|
||||
runtime.log(`Auth profile order override cleared; ${describeOrderFallback(cfg, provider)}.`);
|
||||
}
|
||||
|
||||
/** Sets the provider auth profile priority order after validating each profile id. */
|
||||
@@ -129,5 +148,5 @@ export async function modelsAuthOrderSetCommand(
|
||||
|
||||
runtime.log(`Agent: ${agentId}`);
|
||||
runtime.log(`Provider: ${provider}`);
|
||||
runtime.log(`Order override: ${describeOrder(updated, provider).join(", ")}`);
|
||||
runtime.log(`Auth profile order override: ${describeOrder(updated, provider).join(", ")}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user