Auth labels: handle token refs and share Pi credential conversion

This commit is contained in:
joshavant
2026-02-22 14:40:16 -08:00
committed by Peter Steinberger
parent e1301c31e7
commit cec404225d
7 changed files with 226 additions and 172 deletions

View File

@@ -19,6 +19,20 @@ function formatApiKeySnippet(apiKey: string): string {
return `${head}${tail}`;
}
function formatCredentialSnippet(params: {
value: string | undefined;
ref: { source: string; id: string } | undefined;
}): string {
const value = typeof params.value === "string" ? params.value.trim() : "";
if (value) {
return formatApiKeySnippet(value);
}
if (params.ref) {
return `ref(${params.ref.source}:${params.ref.id})`;
}
return "unknown";
}
export function resolveModelAuthLabel(params: {
provider?: string;
cfg?: OpenClawConfig;
@@ -57,9 +71,13 @@ export function resolveModelAuthLabel(params: {
return `oauth${label ? ` (${label})` : ""}`;
}
if (profile.type === "token") {
return `token ${formatApiKeySnippet(profile.token)}${label ? ` (${label})` : ""}`;
return `token ${formatCredentialSnippet({ value: profile.token, ref: profile.tokenRef })}${
label ? ` (${label})` : ""
}`;
}
return `api-key ${formatApiKeySnippet(profile.key ?? "")}${label ? ` (${label})` : ""}`;
return `api-key ${formatCredentialSnippet({ value: profile.key, ref: profile.keyRef })}${
label ? ` (${label})` : ""
}`;
}
const envKey = resolveEnvApiKey(providerKey);