UNPKG

@callmedayz/ai-prompt-toolkit

Version:

Professional AI prompt engineering toolkit with advanced template features, real-time dashboards, conditional logic, template inheritance, live monitoring, OpenRouter integration, and 310+ model support

75 lines 2.24 kB
/** * Enhanced error handling and retry logic for OpenRouter API */ /** * Types of errors that can occur */ export declare enum ErrorType { AUTHENTICATION = "authentication", RATE_LIMIT = "rate_limit", QUOTA_EXCEEDED = "quota_exceeded", MODEL_UNAVAILABLE = "model_unavailable", NETWORK = "network", TIMEOUT = "timeout", VALIDATION = "validation", SERVER_ERROR = "server_error", UNKNOWN = "unknown" } /** * Enhanced error class with retry information */ export declare class OpenRouterError extends Error { readonly type: ErrorType; readonly statusCode?: number; readonly retryable: boolean; readonly retryAfter?: number; readonly originalError?: Error; constructor(message: string, type: ErrorType, statusCode?: number, retryable?: boolean, retryAfter?: number, originalError?: Error); } /** * Retry configuration */ export interface RetryConfig { maxRetries: number; baseDelay: number; maxDelay: number; exponentialBase: number; jitter: boolean; retryableErrors: ErrorType[]; } /** * Default retry configuration */ export declare const DEFAULT_RETRY_CONFIG: RetryConfig; /** * Parse HTTP response and create appropriate error */ export declare function parseError(response: Response, responseText: string): OpenRouterError; /** * Calculate delay for retry with exponential backoff and jitter */ export declare function calculateRetryDelay(attempt: number, config: RetryConfig, retryAfter?: number): number; /** * Enhanced retry function with sophisticated error handling */ export declare function retryWithBackoff<T>(operation: () => Promise<T>, config?: RetryConfig): Promise<T>; /** * Circuit breaker for preventing cascading failures */ export declare class CircuitBreaker { private failureThreshold; private recoveryTimeout; private failures; private lastFailureTime; private state; constructor(failureThreshold?: number, recoveryTimeout?: number); execute<T>(operation: () => Promise<T>): Promise<T>; private onSuccess; private onFailure; getState(): { state: string; failures: number; lastFailureTime: number; }; } //# sourceMappingURL=error-handling.d.ts.map