/** * Enhanced Provider Fallback Manager * * Implements intelligent automatic fallback mechanisms for AI providers * to maximize uptime and performance through seamless provider switching. * * @version 1.0.0 * @author Requirements Gathering Agent Team * @created 2024 * * Key Features: * - Automatic provider fallback on failures * - Health monitoring and recovery * - Performance-based provider selection * - Circuit breaker integration * - Configurable fallback strategies * * @filepath src/modules/ai/ProviderFallbackManager.ts */ import { AIProvider } from './types.js'; export interface FallbackConfig { enabled: boolean; fallbackOrder: AIProvider[]; healthCheckInterval: number; healthCheckTimeout: number; maxConsecutiveFailures: number; recoveryCheckInterval: number; performanceThreshold: { maxResponseTime: number; minSuccessRate: number; }; } export interface ProviderHealth { provider: AIProvider; isHealthy: boolean; lastHealthCheck: Date; consecutiveFailures: number; averageResponseTime: number; successRate: number; lastError?: string; } export interface FallbackEvent { timestamp: Date; fromProvider: AIProvider; toProvider: AIProvider; reason: string; success: boolean; } export declare class ProviderFallbackManager { private static instance; private config; private providerHealth; private currentProvider; private fallbackHistory; private healthCheckInterval; private retryManager; private providerManager; private clientManager; private readonly DEFAULT_CONFIG; private constructor(); static getInstance(): ProviderFallbackManager; /** * Initialize health monitoring for all configured providers */ private initializeHealthMonitoring; /** * Get the best available provider based on health and performance */ getBestProvider(): Promise; /** * Handle provider failure and attempt fallback */ handleProviderFailure(failedProvider: AIProvider, error: Error): Promise; /** * Execute operation with automatic fallback */ executeWithFallback(operation: (provider: AIProvider) => Promise, operationName?: string): Promise; /** * Perform health check on all providers */ private performHealthCheck; /** * Switch to a different provider */ private switchToProvider; /** * Find the next available provider after a failure */ private findNextProvider; /** * Check if a provider is healthy */ private isProviderHealthy; /** * Check if a provider is configured */ private isProviderConfigured; /** * Update provider performance metrics */ private updateProviderMetrics; /** * Get current provider from configuration */ private getCurrentProviderFromConfig; /** * Parse fallback order from environment variable */ private parseFallbackOrder; /** * Get current provider health status */ getProviderHealth(): Map; /** * Get fallback history */ getFallbackHistory(): FallbackEvent[]; /** * Get current active provider */ getCurrentProvider(): AIProvider | null; /** * Force a provider switch (for testing or manual control) */ forceProviderSwitch(provider: AIProvider): Promise; /** * Update configuration */ updateConfig(newConfig: Partial): void; /** * Get configuration */ getConfig(): FallbackConfig; /** * Cleanup resources */ cleanup(): void; } //# sourceMappingURL=ProviderFallbackManager.d.ts.map