export type Provider = "openai-codex" | "zai" | "anthropic"; export type UsageUnit = "percent" | "tokens" | "requests" | "usd" | "minutes" | "bytes" | "unknown"; export type UsageStatus = "ok" | "warning" | "exhausted" | "unknown"; export interface UsageWindow { id: string; label: string; durationMs?: number; resetsAt?: number; } export interface UsageAmount { used?: number; limit?: number; remaining?: number; usedFraction?: number; remainingFraction?: number; unit: UsageUnit; } export interface UsageScope { provider: Provider; accountId?: string; projectId?: string; orgId?: string; modelId?: string; tier?: string; windowId?: string; shared?: boolean; } export interface UsageLimit { id: string; label: string; scope: UsageScope; window?: UsageWindow; amount: UsageAmount; status?: UsageStatus; notes?: string[]; } export interface UsageReport { provider: Provider; fetchedAt: number; limits: UsageLimit[]; metadata?: Record; raw?: unknown; } export interface UsageLogger { debug(message: string, meta?: Record): void; warn(message: string, meta?: Record): void; } export interface UsageCredential { type: "api_key" | "oauth"; apiKey?: string; accessToken?: string; refreshToken?: string; expiresAt?: number; accountId?: string; projectId?: string; email?: string; enterpriseUrl?: string; metadata?: Record; } export interface UsageFetchParams { provider: Provider; credential: UsageCredential; baseUrl?: string; signal?: AbortSignal; } export interface UsageFetchContext { fetch: typeof fetch; logger?: UsageLogger; } export interface UsageProvider { id: Provider; fetchUsage(params: UsageFetchParams, ctx: UsageFetchContext): Promise; supports?(params: UsageFetchParams): boolean; } export interface CredentialRankingStrategy { findWindowLimits(report: UsageReport): { primary?: UsageLimit; secondary?: UsageLimit; }; windowDefaults: { primaryMs: number; secondaryMs: number; }; hasPriorityBoost?(primary: UsageLimit | undefined): boolean; }