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;
}
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(),
};

View File

@@ -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() {
})}
</div>
)}
{(planType || credits) && (
{planType && (
<div className="rounded-xl border border-border/60 bg-secondary/20 p-4 text-xs text-muted-foreground">
{planType && (
<div>
{PLAN_LABEL}:{' '}
<span className="text-foreground">{formatCodexPlanType(planType)}</span>
</div>
)}
{credits && (
<div>
{CREDITS_LABEL}:{' '}
<span className="text-foreground">{formatCodexCredits(credits)}</span>
</div>
)}
<div>
{PLAN_LABEL}: <span className="text-foreground">{formatCodexPlanType(planType)}</span>
</div>
</div>
)}
{!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 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;
}

View File

@@ -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;

View File

@@ -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
*/

View File

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