import type { Pool, ResolvedModel } from "./router-core.ts"; export interface RateLimitSnapshot { remaining?: number; limit?: number; resetAt?: number; } export type PlanStatus = "ok" | "cooldown"; export interface PlanState { planKey: string; status: PlanStatus; cooldownUntil?: number; reason?: string; lastSnapshot?: RateLimitSnapshot; updatedAt: number; } export interface QuotaConfig { enabled: boolean; reserveRatio: number; inTurnRetry: boolean; maxRetries: number; defaultCooldownMs: number; } export interface PlanIdentity { provider: string; baseUrl: string; apiKey?: string; headers?: Record; env?: Record; } export declare const DEFAULT_QUOTA_CONFIG: QuotaConfig; export declare class QuotaState { readonly config: QuotaConfig; private readonly plans; constructor(config?: QuotaConfig | Partial); isAvailable(planKey: string, now: number): boolean; recordResponse(planKey: string, status: number, headers: Record, provider: string, now: number): PlanState; recordRateLimited(planKey: string, retryAfterMs: number | undefined, resetAt: number | undefined, now: number): PlanState; snapshot(planKey: string): PlanState | undefined; snapshots(): PlanState[]; /** Returns true when no matching plan is known or at least one matching auth plan is usable. */ isAnyAvailableMatching(planKeyPrefix: string, now: number): boolean; load(file: string): void; persist(file: string): void; private get; } export declare function buildPlanKey(identity: PlanIdentity): string; export declare function filterPoolByQuota(pool: Pool, quota: QuotaState | undefined, now: number, excluded?: Set, planKeyFor?: (item: ResolvedModel) => string): Pool; /** Filters models when every persisted auth plan for the same provider endpoint is cooling down. */ export declare function filterPoolByQuotaPlanPrefix(pool: Pool, quota: QuotaState | undefined, now: number): Pool; export declare function quotaPlanPrefix(provider: string, baseUrl: string): string; export declare function parseRateLimitHeaders(_provider: string, headers: Record, now: number): RateLimitSnapshot; export declare function parseRfc3339(value: string | undefined): number | undefined; export declare function parseDuration(value: string | undefined): number | undefined; export declare function parseRetryAfter(value: string | undefined, now: number): number | undefined;