From c5009a03331d4803ac6cfe7917b2d2764932ea43 Mon Sep 17 00:00:00 2001 From: Shirone Date: Sat, 10 Jan 2026 14:43:57 +0100 Subject: [PATCH] refactor: remove Codex credits handling from services and UI components - Eliminated CodexCreditsSnapshot interface and related logic from CodexUsageService and UI components. - Updated CodexUsageSection to display only plan type, removing credits information for a cleaner interface. - Streamlined Codex usage formatting functions by removing unused credit formatting logic. These changes simplify the Codex usage management by focusing on plan types, enhancing clarity and maintainability. --- .../src/services/codex-usage-service.ts | 20 ------------------- .../codex/codex-usage-section.tsx | 20 ++++--------------- apps/ui/src/lib/codex-usage-format.ts | 13 +----------- apps/ui/src/store/app-store.ts | 7 ------- libs/types/src/codex-app-server.ts | 7 ------- libs/types/src/index.ts | 1 - 6 files changed, 5 insertions(+), 63 deletions(-) diff --git a/apps/server/src/services/codex-usage-service.ts b/apps/server/src/services/codex-usage-service.ts index e9420266..c10e8df3 100644 --- a/apps/server/src/services/codex-usage-service.ts +++ b/apps/server/src/services/codex-usage-service.ts @@ -18,19 +18,12 @@ export interface CodexRateLimitWindow { resetsAt: number; } -export interface CodexCreditsSnapshot { - balance?: string; - unlimited?: boolean; - hasCredits?: boolean; -} - export type CodexPlanType = 'free' | 'plus' | 'pro' | 'team' | 'enterprise' | 'edu' | 'unknown'; export interface CodexUsageData { rateLimits: { primary?: CodexRateLimitWindow; secondary?: CodexRateLimitWindow; - credits?: CodexCreditsSnapshot; planType?: CodexPlanType; } | null; lastUpdated: string; @@ -106,9 +99,6 @@ export class CodexUsageService { return { rateLimits: { planType: 'unknown', - credits: { - hasCredits: true, - }, }, lastUpdated: new Date().toISOString(), }; @@ -159,10 +149,6 @@ export class CodexUsageService { const result: CodexUsageData = { rateLimits: { planType, - credits: { - hasCredits: true, - unlimited: planType !== 'free' && planType !== 'unknown', - }, }, lastUpdated: new Date().toISOString(), }; @@ -321,15 +307,9 @@ export class CodexUsageService { return null; } - const isFreePlan = planType === 'free'; - const result: CodexUsageData = { rateLimits: { planType, - credits: { - hasCredits: true, - unlimited: !isFreePlan, - }, }, lastUpdated: new Date().toISOString(), }; diff --git a/apps/ui/src/components/views/settings-view/codex/codex-usage-section.tsx b/apps/ui/src/components/views/settings-view/codex/codex-usage-section.tsx index 1e927777..b879df4a 100644 --- a/apps/ui/src/components/views/settings-view/codex/codex-usage-section.tsx +++ b/apps/ui/src/components/views/settings-view/codex/codex-usage-section.tsx @@ -6,7 +6,6 @@ import { OpenAIIcon } from '@/components/ui/provider-icon'; import { cn } from '@/lib/utils'; import { getElectronAPI } from '@/lib/electron'; import { - formatCodexCredits, formatCodexPlanType, formatCodexResetTime, getCodexWindowLabel, @@ -25,7 +24,6 @@ const UPDATED_LABEL = 'Updated'; const CODEX_FETCH_ERROR = 'Failed to fetch usage'; const CODEX_REFRESH_LABEL = 'Refresh Codex usage'; const PLAN_LABEL = 'Plan'; -const CREDITS_LABEL = 'Credits'; const WARNING_THRESHOLD = 75; const CAUTION_THRESHOLD = 50; const MAX_PERCENTAGE = 100; @@ -49,7 +47,6 @@ export function CodexUsageSection() { const rateLimits = codexUsage?.rateLimits ?? null; const primary = rateLimits?.primary ?? null; const secondary = rateLimits?.secondary ?? null; - const credits = rateLimits?.credits ?? null; const planType = rateLimits?.planType ?? null; const rateLimitWindows = [primary, secondary].filter(isRateLimitWindow); const hasMetrics = rateLimitWindows.length > 0; @@ -206,20 +203,11 @@ export function CodexUsageSection() { })} )} - {(planType || credits) && ( + {planType && (
- {planType && ( -
- {PLAN_LABEL}:{' '} - {formatCodexPlanType(planType)} -
- )} - {credits && ( -
- {CREDITS_LABEL}:{' '} - {formatCodexCredits(credits)} -
- )} +
+ {PLAN_LABEL}: {formatCodexPlanType(planType)} +
)} {!hasMetrics && !error && canFetchUsage && !isLoading && ( diff --git a/apps/ui/src/lib/codex-usage-format.ts b/apps/ui/src/lib/codex-usage-format.ts index 288898b2..25114a57 100644 --- a/apps/ui/src/lib/codex-usage-format.ts +++ b/apps/ui/src/lib/codex-usage-format.ts @@ -1,12 +1,8 @@ -import { type CodexCreditsSnapshot, type CodexPlanType } from '@/store/app-store'; +import { type CodexPlanType } from '@/store/app-store'; const WINDOW_DEFAULT_LABEL = 'Usage window'; const RESET_LABEL = 'Resets'; const UNKNOWN_LABEL = 'Unknown'; -const UNAVAILABLE_LABEL = 'Unavailable'; -const UNLIMITED_LABEL = 'Unlimited'; -const AVAILABLE_LABEL = 'Available'; -const NONE_LABEL = 'None'; const DAY_UNIT = 'day'; const HOUR_UNIT = 'hour'; const MINUTE_UNIT = 'min'; @@ -77,10 +73,3 @@ export function formatCodexPlanType(plan: CodexPlanType | null): string { if (!plan) return UNKNOWN_LABEL; return PLAN_TYPE_LABELS[plan] ?? plan; } - -export function formatCodexCredits(snapshot: CodexCreditsSnapshot | null): string { - if (!snapshot) return UNAVAILABLE_LABEL; - if (snapshot.unlimited) return UNLIMITED_LABEL; - if (snapshot.balance) return snapshot.balance; - return snapshot.hasCredits ? AVAILABLE_LABEL : NONE_LABEL; -} diff --git a/apps/ui/src/store/app-store.ts b/apps/ui/src/store/app-store.ts index b6de532b..2a2b1224 100644 --- a/apps/ui/src/store/app-store.ts +++ b/apps/ui/src/store/app-store.ts @@ -719,12 +719,6 @@ export type CodexPlanType = | 'edu' | 'unknown'; -export interface CodexCreditsSnapshot { - balance?: string; - unlimited?: boolean; - hasCredits?: boolean; -} - export interface CodexRateLimitWindow { limit: number; used: number; @@ -738,7 +732,6 @@ export interface CodexUsage { rateLimits: { primary?: CodexRateLimitWindow; secondary?: CodexRateLimitWindow; - credits?: CodexCreditsSnapshot; planType?: CodexPlanType; } | null; lastUpdated: string; diff --git a/libs/types/src/codex-app-server.ts b/libs/types/src/codex-app-server.ts index f255eac9..454a77b2 100644 --- a/libs/types/src/codex-app-server.ts +++ b/libs/types/src/codex-app-server.ts @@ -55,7 +55,6 @@ export interface AppServerRateLimitsResponse { export interface AppServerRateLimits { primary: AppServerRateLimitWindow | null; secondary: AppServerRateLimitWindow | null; - credits?: AppServerCredits; planType?: string; } @@ -65,12 +64,6 @@ export interface AppServerRateLimitWindow { resetsAt: number; } -export interface AppServerCredits { - hasCredits: boolean; - unlimited: boolean; - balance: string; -} - /** * Generic JSON-RPC request structure */ diff --git a/libs/types/src/index.ts b/libs/types/src/index.ts index a28cfc69..f02df113 100644 --- a/libs/types/src/index.ts +++ b/libs/types/src/index.ts @@ -40,7 +40,6 @@ export type { AppServerRateLimitsResponse, AppServerRateLimits, AppServerRateLimitWindow, - AppServerCredits, JsonRpcRequest, JsonRpcResponse, } from './codex-app-server.js';