adpa-enterprise-framework-automation
Version:
Modular, standards-compliant Node.js/TypeScript automation framework for enterprise requirements, project, and data management. Provides CLI and API for BABOK v3, PMBOK 7th Edition, and DMBOK 2.0 (in progress). Production-ready Express.js API with TypeSpe
139 lines • 3.81 kB
TypeScript
/**
* 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<AIProvider | null>;
/**
* Handle provider failure and attempt fallback
*/
handleProviderFailure(failedProvider: AIProvider, error: Error): Promise<AIProvider | null>;
/**
* Execute operation with automatic fallback
*/
executeWithFallback<T>(operation: (provider: AIProvider) => Promise<T>, operationName?: string): Promise<T>;
/**
* 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<AIProvider, ProviderHealth>;
/**
* 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<void>;
/**
* Update configuration
*/
updateConfig(newConfig: Partial<FallbackConfig>): void;
/**
* Get configuration
*/
getConfig(): FallbackConfig;
/**
* Cleanup resources
*/
cleanup(): void;
}
//# sourceMappingURL=ProviderFallbackManager.d.ts.map