mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 22:04:45 +00:00
fix(codex): show api key profile handles
This commit is contained in:
committed by
Peter Steinberger
parent
ac618c6d9d
commit
e15f99e34e
@@ -348,23 +348,28 @@ function formatProfileLabel(
|
||||
profileId: string,
|
||||
credential: AuthProfileCredential | undefined,
|
||||
): string {
|
||||
const tail = profileId.includes(":") ? profileId.slice(profileId.indexOf(":") + 1) : profileId;
|
||||
const displayName = credential?.displayName?.trim();
|
||||
if (displayName) {
|
||||
return credential?.type === "api_key" ? simplifyApiKeyDisplayName(displayName) : displayName;
|
||||
return credential?.type === "api_key"
|
||||
? simplifyApiKeyDisplayName(displayName, tail)
|
||||
: displayName;
|
||||
}
|
||||
const email = credential?.email?.trim() ?? extractEmailFromProfileId(profileId);
|
||||
if (email) {
|
||||
return email;
|
||||
}
|
||||
const tail = profileId.includes(":") ? profileId.slice(profileId.indexOf(":") + 1) : profileId;
|
||||
if (credential?.type === "api_key") {
|
||||
return humanizeApiKeyProfileTail(tail);
|
||||
return tail || "API key";
|
||||
}
|
||||
return humanizeProfileTail(tail);
|
||||
}
|
||||
|
||||
function simplifyApiKeyDisplayName(value: string): string {
|
||||
function simplifyApiKeyDisplayName(value: string, tail: string): string {
|
||||
const stripped = value.replace(/^OpenAI\s+/iu, "").trim();
|
||||
if (tail && stripped.toLowerCase() === humanizeApiKeyProfileTail(tail).toLowerCase()) {
|
||||
return tail;
|
||||
}
|
||||
return stripped || value;
|
||||
}
|
||||
|
||||
|
||||
@@ -747,7 +747,7 @@ describe("codex command", () => {
|
||||
expect(result.text).toContain(
|
||||
"\n 1. personal-email@gmail.com ChatGPT subscription — active now",
|
||||
);
|
||||
expect(result.text).toContain("\n 2. API key backup API key — available if needed");
|
||||
expect(result.text).toContain("\n 2. api-key-backup API key — available if needed");
|
||||
expect(result.text).not.toContain("Now using:");
|
||||
expect(result.text).not.toContain("openai:api-key-backup");
|
||||
expect(result.text).not.toContain("primary");
|
||||
@@ -830,7 +830,7 @@ describe("codex command", () => {
|
||||
deps: createDeps({ safeCodexControlRequest }),
|
||||
});
|
||||
|
||||
expect(result.text).toContain("Now using: API key backup");
|
||||
expect(result.text).toContain("Now using: api-key-backup");
|
||||
expect(result.text).toContain("subscription rate-limited \u00b7 switches back in");
|
||||
expect(result.text).toContain("Subscription personal-email@gmail.com");
|
||||
expect(result.text).toContain("\n Weekly 100% \u00b7 Short-term 0% \u00b7 Resets in");
|
||||
@@ -838,12 +838,12 @@ describe("codex command", () => {
|
||||
"\n 1. personal-email@gmail.com ChatGPT subscription — rate-limited",
|
||||
);
|
||||
expect(result.text).toContain(
|
||||
"\n 2. API key backup API key — active now \u00b7 billed per token",
|
||||
"\n 2. api-key-backup API key — active now \u00b7 billed per token",
|
||||
);
|
||||
expect(result.text).toContain(
|
||||
"\n 3. work-email@gmail.com ChatGPT subscription — available if needed",
|
||||
);
|
||||
expect(result.text).toContain("\n 4. Work API key backup API key — available if needed");
|
||||
expect(result.text).toContain("\n 4. work-api-key-backup API key — available if needed");
|
||||
expect(result.text).not.toContain("Reason:");
|
||||
expect(result.text).not.toContain("fallback active");
|
||||
expect(result.text).not.toContain("not tracked");
|
||||
|
||||
Reference in New Issue
Block a user