/** * FNXC:CodeOrganization 2026-07-20-14:00: * Models registry and usage client API peeled from legacy.ts. */ import { api } from "./client.js"; // --- Models API --- /** Available AI model info returned by the models endpoint */ export interface ModelInfo { provider: string; id: string; name: string; reasoning: boolean; contextWindow: number; } /** Response from the models endpoint */ export interface ModelsResponse { models: ModelInfo[]; favoriteProviders: string[]; favoriteModels: string[]; defaultProvider?: string; defaultModelId?: string; resolvedPlanningProvider?: string; resolvedPlanningModelId?: string; } /** Fetch available AI models from the model registry along with favoriteProviders */ export function fetchModels(): Promise { return api("/models"); } // --- Usage API --- /** Pace information for weekly usage windows */ export interface UsagePace { status: "ahead" | "on-track" | "behind"; percentElapsed: number; // 0-100, how much of the window time has passed message: string; // e.g., "Using 15% over your limit pace" } /** Usage window for a provider (e.g., "Session (5h)", "Weekly") */ export interface UsageWindow { label: string; percentUsed: number; // 0-100 percentLeft: number; // 0-100 resetText: string | null; // e.g., "resets in 2h" resetMs?: number; // ms until reset resetAt?: string; // ISO 8601 timestamp of when the window resets (machine-readable) windowDurationMs?: number; // total window length pace?: UsagePace; // pace indicator for weekly windows } /** Provider usage data */ export interface ProviderUsage { name: string; icon: string; // emoji status: "ok" | "error" | "no-auth"; error?: string; plan?: string | null; email?: string | null; windows: UsageWindow[]; } /** Fetch usage data from all configured AI providers */ export function fetchUsageData(): Promise<{ providers: ProviderUsage[] }> { return api<{ providers: ProviderUsage[] }>("/usage"); }