Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions apps/server/src/provider/CodexProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,17 @@ function reasoningEffortLabel(reasoningEffort: string): string {
return REASONING_EFFORT_LABELS[reasoningEffort] ?? reasoningEffort;
}

function codexAccountAuthLabel(account: CodexSchema.V2GetAccountResponse["account"]) {
function codexAccountAuthLabel(
account: CodexSchema.V2GetAccountResponse["account"],
usagePlanType: string | null | undefined,
) {
if (!account) return undefined;
if (account.type === "apiKey") return "OpenAI API Key";
if (account.type === "amazonBedrock") return "Amazon Bedrock";
if (account.type !== "chatgpt") return undefined;
return codexPlanLabel(account.planType);
// account/read takes the plan from the cached login token; the usage read asks the backend.
const usageLabel = usagePlanType === "unknown" ? undefined : codexPlanLabel(usagePlanType);
return usageLabel ?? codexPlanLabel(account.planType);
}

export function codexPlanLabel(planType: string | null | undefined): string | undefined {
Expand Down Expand Up @@ -651,7 +656,10 @@ function accountProbeStatus({ account, rateLimits }: CodexAppServerProviderSnaps
readonly auth: ServerProvider["auth"];
readonly message?: string;
} {
const authLabel = codexAccountAuthLabel(account.account);
const authLabel = codexAccountAuthLabel(
account.account,
rateLimits && "snapshot" in rateLimits ? rateLimits.snapshot.planType : undefined,
);
const authEmail = codexAccountEmail(account.account);
const workspaceId =
rateLimits && "accountId" in rateLimits ? rateLimits.accountId?.trim() : undefined;
Expand Down
22 changes: 22 additions & 0 deletions apps/server/src/provider/ProviderRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,28 @@ it.layer(
}),
);

it.effect("labels the plan the usage read reports over the cached login plan", () =>
Effect.gen(function* () {
const statusWithUsagePlan = (planType: string | null) =>
checkCodexProviderStatus(defaultCodexSettings, () =>
Effect.succeed(
makeCodexProbeSnapshot({
rateLimits: { snapshot: { planType }, resetCredits: null },
}),
),
);

const downgraded = yield* statusWithUsagePlan("free");
assert.strictEqual(downgraded.auth.label, "ChatGPT Free Subscription");

const unreported = yield* statusWithUsagePlan(null);
assert.strictEqual(unreported.auth.label, "ChatGPT Pro 200 Subscription");

const unknown = yield* statusWithUsagePlan("unknown");
assert.strictEqual(unknown.auth.label, "ChatGPT Pro 200 Subscription");
}),
);

it.effect("returns unauthenticated when app-server requires OpenAI auth", () =>
Effect.gen(function* () {
const status = yield* checkCodexProviderStatus(defaultCodexSettings, () =>
Expand Down
Loading