UNPKG

@hivetechs/hive-ai

Version:

Real-time streaming AI consensus platform with HTTP+SSE MCP integration for Claude Code, VS Code, Cursor, and Windsurf - powered by OpenRouter's unified API

123 lines (122 loc) 3.09 kB
/** * Health Check and Monitoring System * * Proactive monitoring of OpenRouter services, model availability, * and system health with automatic degradation and recovery. */ export interface HealthCheckResult { service: string; status: 'healthy' | 'degraded' | 'unhealthy'; responseTime: number; lastChecked: Date; consecutiveFailures: number; lastError?: string; metadata?: Record<string, any>; } export interface ModelHealth { provider: string; model: string; status: 'available' | 'degraded' | 'unavailable'; avgResponseTime: number; successRate: number; lastTested: Date; errorCount: number; } export interface SystemHealth { overall: 'healthy' | 'degraded' | 'unhealthy'; openrouter: HealthCheckResult; database: HealthCheckResult; mcpServer: HealthCheckResult; models: ModelHealth[]; timestamp: Date; } export declare class HealthMonitor { private checkInterval; private healthResults; private modelHealth; private monitoringInterval; private testModels; constructor(checkInterval?: number); /** * Start continuous health monitoring */ startMonitoring(): void; /** * Stop health monitoring */ stopMonitoring(): void; /** * Run all health checks */ runHealthChecks(): Promise<void>; /** * Check OpenRouter API health */ private checkOpenRouterHealth; /** * Check database health */ private checkDatabaseHealth; /** * Check MCP server health */ private checkMCPServerHealth; /** * Check model health by testing key models */ private checkModelHealth; /** * Test individual model health */ private testModelHealth; /** * Update health result with tracking */ private updateHealthResult; /** * Get current system health */ getSystemHealth(): SystemHealth; /** * Get health status for a specific model */ getModelHealth(provider: string, model: string): ModelHealth | null; /** * Get list of healthy models for fallback */ getHealthyModels(): string[]; /** * Check if a specific service is healthy */ isServiceHealthy(serviceName: string): boolean; /** * Check if a specific model is available */ isModelAvailable(provider: string, model: string): boolean; /** * Add custom test model */ addTestModel(modelId: string): void; /** * Remove test model */ removeTestModel(modelId: string): void; /** * Get detailed health report */ getDetailedHealthReport(): { summary: SystemHealth; errorStats: any; circuitBreakers: any; uptime: number; }; } export declare const globalHealthMonitor: HealthMonitor; /** * Express middleware for health check endpoint */ export declare function healthCheckMiddleware(req: any, res: any, next: any): void; /** * CLI command for health status */ export declare function displayHealthStatus(): Promise<void>;