mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 16:28:26 +00:00
fix: normalize status auth cost handling and models header tests
This commit is contained in:
@@ -90,6 +90,34 @@ type StatusArgs = {
|
||||
now?: number;
|
||||
};
|
||||
|
||||
type NormalizedAuthMode = "api-key" | "oauth" | "token" | "aws-sdk" | "mixed" | "unknown";
|
||||
|
||||
function normalizeAuthMode(value?: string): NormalizedAuthMode | undefined {
|
||||
const normalized = value?.trim().toLowerCase();
|
||||
if (!normalized) {
|
||||
return undefined;
|
||||
}
|
||||
if (normalized === "api-key" || normalized.startsWith("api-key ")) {
|
||||
return "api-key";
|
||||
}
|
||||
if (normalized === "oauth" || normalized.startsWith("oauth ")) {
|
||||
return "oauth";
|
||||
}
|
||||
if (normalized === "token" || normalized.startsWith("token ")) {
|
||||
return "token";
|
||||
}
|
||||
if (normalized === "aws-sdk" || normalized.startsWith("aws-sdk ")) {
|
||||
return "aws-sdk";
|
||||
}
|
||||
if (normalized === "mixed" || normalized.startsWith("mixed ")) {
|
||||
return "mixed";
|
||||
}
|
||||
if (normalized === "unknown") {
|
||||
return "unknown";
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function resolveRuntimeLabel(
|
||||
args: Pick<StatusArgs, "config" | "agent" | "sessionKey" | "sessionScope">,
|
||||
): string {
|
||||
@@ -498,17 +526,27 @@ export function buildStatusMessage(args: StatusArgs): string {
|
||||
];
|
||||
const activationLine = activationParts.filter(Boolean).join(" · ");
|
||||
|
||||
const activeAuthMode = resolveModelAuthMode(activeProvider, args.config);
|
||||
const selectedAuthMode =
|
||||
normalizeAuthMode(args.modelAuth) ?? resolveModelAuthMode(selectedProvider, args.config);
|
||||
const selectedAuthLabelValue =
|
||||
args.modelAuth ??
|
||||
(() => {
|
||||
const selectedAuthMode = resolveModelAuthMode(selectedProvider, args.config);
|
||||
return selectedAuthMode && selectedAuthMode !== "unknown" ? selectedAuthMode : undefined;
|
||||
})();
|
||||
(selectedAuthMode && selectedAuthMode !== "unknown" ? selectedAuthMode : undefined);
|
||||
const activeAuthMode =
|
||||
normalizeAuthMode(args.activeModelAuth) ?? resolveModelAuthMode(activeProvider, args.config);
|
||||
const activeAuthLabelValue =
|
||||
args.activeModelAuth ??
|
||||
(activeAuthMode && activeAuthMode !== "unknown" ? activeAuthMode : undefined);
|
||||
const showCost = activeAuthLabelValue === "api-key" || activeAuthLabelValue === "mixed";
|
||||
const selectedModelLabel = modelRefs.selected.label || "unknown";
|
||||
const activeModelLabel = formatProviderModelRef(activeProvider, activeModel) || "unknown";
|
||||
const fallbackState = resolveActiveFallbackState({
|
||||
selectedModelRef: selectedModelLabel,
|
||||
activeModelRef: activeModelLabel,
|
||||
state: entry,
|
||||
});
|
||||
const effectiveCostAuthMode = fallbackState.active
|
||||
? activeAuthMode
|
||||
: (selectedAuthMode ?? activeAuthMode);
|
||||
const showCost = effectiveCostAuthMode === "api-key" || effectiveCostAuthMode === "mixed";
|
||||
const costConfig = showCost
|
||||
? resolveModelCostConfig({
|
||||
provider: activeProvider,
|
||||
@@ -529,13 +567,6 @@ export function buildStatusMessage(args: StatusArgs): string {
|
||||
: undefined;
|
||||
const costLabel = showCost && hasUsage ? formatUsd(cost) : undefined;
|
||||
|
||||
const selectedModelLabel = modelRefs.selected.label || "unknown";
|
||||
const activeModelLabel = formatProviderModelRef(activeProvider, activeModel) || "unknown";
|
||||
const fallbackState = resolveActiveFallbackState({
|
||||
selectedModelRef: selectedModelLabel,
|
||||
activeModelRef: activeModelLabel,
|
||||
state: entry,
|
||||
});
|
||||
const selectedAuthLabel = selectedAuthLabelValue ? ` · 🔑 ${selectedAuthLabelValue}` : "";
|
||||
const channelModelNote = (() => {
|
||||
if (!args.config || !entry) {
|
||||
|
||||
Reference in New Issue
Block a user