import { AIErrorInfo } from './errorTypes.js'; /** * Utility class for analyzing errors from various AI providers and mapping them to standardized error information. * This class provides a consistent way to interpret errors across different provider SDKs. * * @class ErrorAnalyzer * @since 2.47.0 * * @example * ```typescript * try { * const result = await provider.chat(params); * } catch (error) { * const errorInfo = ErrorAnalyzer.analyzeError(error, 'OpenAI'); * if (errorInfo.canFailover) { * // Try another provider * } * } * ``` */ export declare class ErrorAnalyzer { /** * Analyzes an error from an AI provider and returns standardized error information. * This method extracts relevant details from provider-specific error formats and * maps them to a consistent structure for easier handling. * * @static * @param {any} error - The error object thrown by the provider SDK * @param {string} [providerName] - Optional name of the provider for context * @returns {AIErrorInfo} Standardized error information * * @example * ```typescript * const errorInfo = ErrorAnalyzer.analyzeError(error, 'Anthropic'); * console.log(`Error type: ${errorInfo.errorType}`); * console.log(`Can retry: ${errorInfo.severity !== 'Fatal'}`); * ``` */ static analyzeError(error: any, providerName?: string): AIErrorInfo; /** * Extracts HTTP status code from various error object structures. * Different provider SDKs store status codes in different locations. * * @private * @static * @param {any} error - The error object to extract status code from * @returns {number | undefined} The HTTP status code if found, undefined otherwise */ private static extractHttpStatusCode; /** * Determines the standardized error type based on status code and error properties. * Uses a combination of HTTP status codes, error messages, and error class names. * * @private * @static * @param {any} error - The error object to analyze * @param {number} [statusCode] - The HTTP status code if available * @returns {AIErrorType} The categorized error type */ private static determineErrorType; /** * Determines the error severity based on the error type. * This helps decide whether to retry immediately, wait, or fail permanently. * * @private * @static * @param {AIErrorType} errorType - The categorized error type * @returns {ErrorSeverity} The severity level of the error */ private static determineSeverity; /** * Determines whether an error can potentially be resolved by switching providers. * * Strategy: We're permissive with failover - most errors should allow trying another * provider/model since vendors may use different status codes and error messages. * Only block failover for clear client-side structural errors that won't be fixed by switching. * * @private * @static * @param {AIErrorType} errorType - The categorized error type * @returns {boolean} True if failover might help, false otherwise */ private static canFailoverForError; /** * Extracts suggested retry delay from error response. * Looks for Retry-After headers and provider-specific retry delay fields. * * @private * @static * @param {any} error - The error object to extract retry delay from * @returns {number | undefined} Suggested retry delay in seconds, or undefined */ private static extractRetryDelay; /** * Extracts the provider-specific error code from the error object. * Different providers store error codes in different locations. * * @private * @static * @param {any} error - The error object to extract provider code from * @returns {string | undefined} The provider error code if found, undefined otherwise */ private static extractProviderErrorCode; } //# sourceMappingURL=errorAnalyzer.d.ts.map