/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 * @plan PLAN-20250909-TOKTRACK.P08 */ import type { GenerateContentResponse } from '@google/genai'; export interface HttpError extends Error { status?: number; } export interface RetryOptions { maxAttempts: number; initialDelayMs: number; maxDelayMs: number; shouldRetryOnError: (error: Error, retryFetchErrors?: boolean) => boolean; shouldRetryOnContent?: (content: GenerateContentResponse) => boolean; onPersistent429?: (error?: unknown) => Promise; trackThrottleWaitTime?: (waitTimeMs: number) => void; retryFetchErrors?: boolean; signal?: AbortSignal; } export declare const STREAM_INTERRUPTED_ERROR_CODE = "LLXPRT_STREAM_INTERRUPTED"; export declare function createStreamInterruptionError(message: string, details?: Record, cause?: unknown): Error; export declare function getErrorCode(error: unknown): string | undefined; export declare function isNetworkTransientError(error: unknown): boolean; /** * Predicate function to determine if a retry should be attempted. * @plan PLAN-20250219-GMERGE021.R13.P01 * @requirement REQ-R13-001 Network error codes retried unconditionally * @requirement REQ-R13-002 isRetryableError exported for reuse * * Decision precedence (CRITICAL - do not reorder): * 1. Network error codes (ETIMEDOUT, ECONNRESET, etc.) → ALWAYS retry (regardless of retryFetchErrors) * 2. retryFetchErrors=true + generic "fetch failed" message → retry * 3. ApiError with status 400 → NEVER retry * 4. ApiError or generic status 429 or 5xx → retry * 5. All others → do not retry * * @param error The error object. * @param retryFetchErrors Whether to retry generic fetch failures (default: false). * @returns True if the error is retryable, false otherwise. */ export declare function isRetryableError(error: Error | unknown, retryFetchErrors?: boolean): boolean; /** * Retries a function with exponential backoff and jitter. * @param fn The asynchronous function to retry. * @param options Optional retry configuration. * @returns A promise that resolves with the result of the function if successful. * @throws The last error encountered if all attempts fail. */ export declare function retryWithBackoff(fn: () => Promise, options?: Partial): Promise; /** * Determines if an error is an Anthropic overloaded_error. * Anthropic returns overloaded_error as an error type (not HTTP status): * {"type":"error","error":{"type":"overloaded_error","message":"Overloaded"}} * @param error The error object. * @returns True if the error is an overloaded_error, false otherwise. */ export declare function isOverloadError(error: unknown): boolean; /** * Extracts the HTTP status code from an error object. * @param error The error object. * @returns The HTTP status code, or undefined if not found. */ export declare function getErrorStatus(error: unknown): number | undefined; /** * Error indicating a model was not found (HTTP 404). * Used by googleQuotaErrors to classify 404 responses. */ export declare class ModelNotFoundError extends Error { code: number; constructor(message: string, code?: number); }