export type FallbackTriggerClass = "rate_limit" | "quota" | "auth" | "server" | "unknown" | "other"; export interface FallbackTrigger { class: FallbackTriggerClass; retryAfterMs?: number; } export type TransportHeaders = Headers | Record; /** * Structured facts from an upstream HTTP or transport failure. Retry decisions * must use these facts rather than provider- or application-owned error text. * * `headers` is always a plain record limited to the retained retry-signal * entries: facts travel on persisted `AssistantMessage`s and through * `structuredClone` snapshots (managed fallback attempt staging), so they must * never carry a live `Headers` instance — cloning one throws `DataCloneError` * ("The object can not be cloned.") and masks the real provider failure. */ export interface TransportFailureFacts { kind: "transport"; status?: number; /** Canonical provider error code used for fallback classification. */ providerCode?: string; /** Anthropic's typed `error.type`, preserved separately at the transport boundary. */ anthropicErrorType?: string; /** OpenAI's typed `error.code`, preserved separately at the transport boundary. */ openaiErrorCode?: string; headers?: Record; } /** Opaque per-invocation marker required by managed fallback transport calls. */ export interface FallbackAttemptToken { readonly modelKey: string; readonly attemptId: string | number; } /** * Marks a single outer fallback invocation. Accounting belongs to the caller; * this token prevents managed transport calls from silently bypassing it. */ export declare function beginAttempt(modelKey: string, attemptId: string | number): FallbackAttemptToken; export declare function assertManagedAttempt(options: { fallbackManaged?: boolean; fallbackAttempt?: FallbackAttemptToken; } | undefined): void; /** * Compatibility input for callers that have not yet wrapped their HTTP facts * in the discriminated form. Only its structured fields are inspected. */ export interface FallbackTriggerInput { status?: number; providerCode?: string; code?: string; headers?: TransportHeaders; response?: { status?: number; headers?: TransportHeaders; }; error?: { code?: string; type?: string; }; } /** Extracts only explicit HTTP/transport metadata; it never parses error text. */ export declare function transportFailureFacts(error: unknown, capturedResponse?: { status?: number; headers?: TransportHeaders; }): TransportFailureFacts | undefined; /** Classifies only typed upstream transport facts without consuming response bodies. */ export declare function classifyFallbackTrigger(errorOrFacts: TransportFailureFacts | FallbackTriggerInput | unknown): FallbackTrigger;