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.
This commit is contained in:
Shirone
2026-01-10 14:43:57 +01:00
parent 99b05d35a2
commit c5009a0333
6 changed files with 5 additions and 63 deletions

View File

@@ -18,19 +18,12 @@ export interface CodexRateLimitWindow {
resetsAt: number; resetsAt: number;
} }
export interface CodexCreditsSnapshot {
balance?: string;
unlimited?: boolean;
hasCredits?: boolean;
}
export type CodexPlanType = 'free' | 'plus' | 'pro' | 'team' | 'enterprise' | 'edu' | 'unknown'; export type CodexPlanType = 'free' | 'plus' | 'pro' | 'team' | 'enterprise' | 'edu' | 'unknown';
export interface CodexUsageData { export interface CodexUsageData {
rateLimits: { rateLimits: {
primary?: CodexRateLimitWindow; primary?: CodexRateLimitWindow;
secondary?: CodexRateLimitWindow; secondary?: CodexRateLimitWindow;
credits?: CodexCreditsSnapshot;
planType?: CodexPlanType; planType?: CodexPlanType;
} | null; } | null;
lastUpdated: string; lastUpdated: string;
@@ -106,9 +99,6 @@ export class CodexUsageService {
return { return {
rateLimits: { rateLimits: {
planType: 'unknown', planType: 'unknown',
credits: {
hasCredits: true,
},
}, },
lastUpdated: new Date().toISOString(), lastUpdated: new Date().toISOString(),
}; };
@@ -159,10 +149,6 @@ export class CodexUsageService {
const result: CodexUsageData = { const result: CodexUsageData = {
rateLimits: { rateLimits: {
planType, planType,
credits: {
hasCredits: true,
unlimited: planType !== 'free' && planType !== 'unknown',
},
}, },
lastUpdated: new Date().toISOString(), lastUpdated: new Date().toISOString(),
}; };
@@ -321,15 +307,9 @@ export class CodexUsageService {
return null; return null;
} }
const isFreePlan = planType === 'free';
const result: CodexUsageData = { const result: CodexUsageData = {
rateLimits: { rateLimits: {
planType, planType,
credits: {
hasCredits: true,
unlimited: !isFreePlan,
},
}, },
lastUpdated: new Date().toISOString(), lastUpdated: new Date().toISOString(),
}; };

View File

@@ -6,7 +6,6 @@ import { OpenAIIcon } from '@/components/ui/provider-icon';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
import { getElectronAPI } from '@/lib/electron'; import { getElectronAPI } from '@/lib/electron';
import { import {
formatCodexCredits,
formatCodexPlanType, formatCodexPlanType,
formatCodexResetTime, formatCodexResetTime,
getCodexWindowLabel, getCodexWindowLabel,
@@ -25,7 +24,6 @@ const UPDATED_LABEL = 'Updated';
const CODEX_FETCH_ERROR = 'Failed to fetch usage'; const CODEX_FETCH_ERROR = 'Failed to fetch usage';
const CODEX_REFRESH_LABEL = 'Refresh Codex usage'; const CODEX_REFRESH_LABEL = 'Refresh Codex usage';
const PLAN_LABEL = 'Plan'; const PLAN_LABEL = 'Plan';
const CREDITS_LABEL = 'Credits';
const WARNING_THRESHOLD = 75; const WARNING_THRESHOLD = 75;
const CAUTION_THRESHOLD = 50; const CAUTION_THRESHOLD = 50;
const MAX_PERCENTAGE = 100; const MAX_PERCENTAGE = 100;
@@ -49,7 +47,6 @@ export function CodexUsageSection() {
const rateLimits = codexUsage?.rateLimits ?? null; const rateLimits = codexUsage?.rateLimits ?? null;
const primary = rateLimits?.primary ?? null; const primary = rateLimits?.primary ?? null;
const secondary = rateLimits?.secondary ?? null; const secondary = rateLimits?.secondary ?? null;
const credits = rateLimits?.credits ?? null;
const planType = rateLimits?.planType ?? null; const planType = rateLimits?.planType ?? null;
const rateLimitWindows = [primary, secondary].filter(isRateLimitWindow); const rateLimitWindows = [primary, secondary].filter(isRateLimitWindow);
const hasMetrics = rateLimitWindows.length > 0; const hasMetrics = rateLimitWindows.length > 0;
@@ -206,20 +203,11 @@ export function CodexUsageSection() {
})} })}
</div> </div>
)} )}
{(planType || credits) && ( {planType && (
<div className="rounded-xl border border-border/60 bg-secondary/20 p-4 text-xs text-muted-foreground"> <div className="rounded-xl border border-border/60 bg-secondary/20 p-4 text-xs text-muted-foreground">
{planType && ( <div>
<div> {PLAN_LABEL}: <span className="text-foreground">{formatCodexPlanType(planType)}</span>
{PLAN_LABEL}:{' '} </div>
<span className="text-foreground">{formatCodexPlanType(planType)}</span>
</div>
)}
{credits && (
<div>
{CREDITS_LABEL}:{' '}
<span className="text-foreground">{formatCodexCredits(credits)}</span>
</div>
)}
</div> </div>
)} )}
{!hasMetrics && !error && canFetchUsage && !isLoading && ( {!hasMetrics && !error && canFetchUsage && !isLoading && (

View File

@@ -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 WINDOW_DEFAULT_LABEL = 'Usage window';
const RESET_LABEL = 'Resets'; const RESET_LABEL = 'Resets';
const UNKNOWN_LABEL = 'Unknown'; 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 DAY_UNIT = 'day';
const HOUR_UNIT = 'hour'; const HOUR_UNIT = 'hour';
const MINUTE_UNIT = 'min'; const MINUTE_UNIT = 'min';
@@ -77,10 +73,3 @@ export function formatCodexPlanType(plan: CodexPlanType | null): string {
if (!plan) return UNKNOWN_LABEL; if (!plan) return UNKNOWN_LABEL;
return PLAN_TYPE_LABELS[plan] ?? plan; 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;
}

View File

@@ -719,12 +719,6 @@ export type CodexPlanType =
| 'edu' | 'edu'
| 'unknown'; | 'unknown';
export interface CodexCreditsSnapshot {
balance?: string;
unlimited?: boolean;
hasCredits?: boolean;
}
export interface CodexRateLimitWindow { export interface CodexRateLimitWindow {
limit: number; limit: number;
used: number; used: number;
@@ -738,7 +732,6 @@ export interface CodexUsage {
rateLimits: { rateLimits: {
primary?: CodexRateLimitWindow; primary?: CodexRateLimitWindow;
secondary?: CodexRateLimitWindow; secondary?: CodexRateLimitWindow;
credits?: CodexCreditsSnapshot;
planType?: CodexPlanType; planType?: CodexPlanType;
} | null; } | null;
lastUpdated: string; lastUpdated: string;

View File

@@ -55,7 +55,6 @@ export interface AppServerRateLimitsResponse {
export interface AppServerRateLimits { export interface AppServerRateLimits {
primary: AppServerRateLimitWindow | null; primary: AppServerRateLimitWindow | null;
secondary: AppServerRateLimitWindow | null; secondary: AppServerRateLimitWindow | null;
credits?: AppServerCredits;
planType?: string; planType?: string;
} }
@@ -65,12 +64,6 @@ export interface AppServerRateLimitWindow {
resetsAt: number; resetsAt: number;
} }
export interface AppServerCredits {
hasCredits: boolean;
unlimited: boolean;
balance: string;
}
/** /**
* Generic JSON-RPC request structure * Generic JSON-RPC request structure
*/ */

View File

@@ -40,7 +40,6 @@ export type {
AppServerRateLimitsResponse, AppServerRateLimitsResponse,
AppServerRateLimits, AppServerRateLimits,
AppServerRateLimitWindow, AppServerRateLimitWindow,
AppServerCredits,
JsonRpcRequest, JsonRpcRequest,
JsonRpcResponse, JsonRpcResponse,
} from './codex-app-server.js'; } from './codex-app-server.js';