export type FailoverReason = 'rate_limit' | 'auth' | 'timeout' | 'connection' | 'billing' | 'format' | 'unknown'; /** * Unified error response from providers. * Providers return this instead of throwing, enabling centralized error handling. */ export interface ProviderErrorResponse { /** HTTP status code if available (e.g., 401, 429, 500) */ status?: number; /** Machine-readable error code (e.g., 'invalid_api_key', 'context_length_exceeded') */ code?: string; /** Human-readable error message */ message: string; /** Which provider generated this error */ provider: 'anthropic' | 'openai' | 'pi-ai'; /** Original error object for debugging */ originalError?: unknown; /** Whether this error is transient and worth retrying */ retryable: boolean; /** Optional retry-after hint in milliseconds */ retryAfterMs?: number; } export declare class FailoverError extends Error { readonly reason: FailoverReason; readonly provider?: string; readonly model?: string; readonly status?: number; constructor(message: string, params: { reason: FailoverReason; provider?: string; model?: string; status?: number; cause?: unknown; }); } export declare function isFailoverError(err: unknown): err is FailoverError; export declare function isProviderErrorResponse(err: unknown): err is ProviderErrorResponse; /** * Helper to create a provider error response from HTTP response metadata. * Used by providers to classify HTTP errors before throwing. */ export declare function createProviderErrorResponse(provider: 'anthropic' | 'openai' | 'pi-ai', message: string, { status, code, originalError, retryAfterMs, }?: { status?: number; code?: string; originalError?: unknown; retryAfterMs?: number; }): ProviderErrorResponse; /** * Convert a provider error response into a throwable MossError. * This bridges the new error response system with legacy error handling. */ export declare function throwProviderErrorResponse(response: ProviderErrorResponse): never; export declare function isContextOverflowError(message?: string): boolean; export declare function isRateLimitError(message?: string): boolean; export declare function isQuotaExceededError(message?: string): boolean; export declare function isTimeoutError(message?: string): boolean; export declare function isConnectionError(message?: string): boolean; export declare function isServerError(message?: string): boolean; export declare function isTransientError(message?: string): boolean; export declare function isAuthError(message?: string): boolean; export declare function classifyFailoverReason(message: string): FailoverReason | null; export declare function isFailoverErrorMessage(message?: string): boolean; export interface RetryOptions { attempts?: number; minDelayMs?: number; maxDelayMs?: number; jitter?: number; label?: string; shouldRetry?: (err: unknown, attempt: number) => boolean; retryDelayMs?: (err: unknown, attempt: number, computedDelayMs: number) => number | undefined; onRetry?: (info: { attempt: number; delay: number; error: unknown; }) => void; } export declare function retryAsync(fn: () => Promise, options?: RetryOptions): Promise; export declare function describeError(err: unknown): string; //# sourceMappingURL=errors.d.ts.map