UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, and professional CLI. Built-in tools operational, 58+ external MCP servers discoverable. Connect to filesystem, GitHub, database operations, and more. Build, test, and

212 lines (211 loc) 6.39 kB
/** * Provider Health Checking System * Prevents 500 errors by validating provider availability and configuration */ import { AIProviderName } from "../core/types.js"; export interface ProviderHealthStatus { provider: AIProviderName; isHealthy: boolean; isConfigured: boolean; hasApiKey: boolean; lastChecked: Date; error?: string; warning?: string; responseTime?: number; configurationIssues: string[]; recommendations: string[]; } export interface ProviderHealthCheckOptions { timeout?: number; includeConnectivityTest?: boolean; includeModelValidation?: boolean; cacheResults?: boolean; maxCacheAge?: number; } export declare class ProviderHealthChecker { private static healthCache; private static readonly DEFAULT_TIMEOUT; private static readonly DEFAULT_CACHE_AGE; private static readonly CONSECUTIVE_FAILURE_THRESHOLD; private static consecutiveFailures; /** * Validate and return a safe failure threshold value */ private static getValidatedFailureThreshold; /** * Comprehensive health check for a provider */ static checkProviderHealth(providerName: AIProviderName, options?: ProviderHealthCheckOptions): Promise<ProviderHealthStatus>; /** * Check environment configuration for a provider */ private static checkEnvironmentConfiguration; /** * Check API key validity (format validation) */ private static checkApiKeyValidity; /** * Check connectivity to provider endpoints */ private static checkConnectivity; /** * Check model availability (if possible without making API calls) */ private static checkModelAvailability; /** * Get required environment variables for a provider */ private static getRequiredEnvironmentVariables; /** * Get API key environment variable for a provider */ private static getApiKeyEnvironmentVariable; /** * Validate API key format for a provider */ private static validateApiKeyFormat; /** * Get health check endpoint for connectivity testing */ private static getProviderHealthEndpoint; /** * Provider-specific configuration checks */ private static checkProviderSpecificConfig; /** * Check Vertex AI configuration */ private static checkVertexAIConfig; /** * Get Vertex AI project ID from environment variables */ private static getVertexProjectId; /** * Check Vertex AI authentication */ private static checkVertexAuthentication; /** * Check Google Application Credentials file */ private static checkGoogleApplicationCredentials; /** * Check individual Google credentials */ private static checkIndividualGoogleCredentials; /** * Check AWS Bedrock configuration */ private static checkBedrockConfig; /** * Check AWS region configuration */ private static checkAWSRegion; /** * Check AWS credentials */ private static checkAWSCredentials; /** * Check Bedrock models */ private static checkBedrockModels; /** * Check Bedrock endpoint */ private static checkBedrockEndpoint; /** * Check Azure OpenAI configuration */ private static checkAzureConfig; /** * Check Ollama configuration */ private static checkOllamaConfig; /** * Get common models for a provider */ private static getCommonModelsForProvider; /** * Get cached health status if still valid */ private static getCachedHealth; /** * Check if Vertex AI supports Anthropic models (dual provider architecture) */ static checkVertexAnthropicSupport(): Promise<{ isSupported: boolean; hasCreateVertexAnthropic: boolean; hasCorrectTypes: boolean; hasValidProject: boolean; hasRegionalSupport: boolean; hasNetworkAccess: boolean; hasAnthropicModels: boolean; authentication: { isValid: boolean; method: string; issues: string[]; }; projectConfiguration: { isValid: boolean; projectId: string | undefined; region: string | undefined; issues: string[]; }; modelSupport: { availableModels: string[]; recommendedModels: string[]; deprecatedModels: string[]; }; recommendations: string[]; troubleshooting: string[]; }>; /** * Validate Vertex AI authentication configuration */ private static validateVertexAuthentication; /** * Validate Vertex AI project configuration */ private static validateVertexProjectConfiguration; /** * Check if the specified region supports Anthropic models */ private static checkVertexRegionalSupport; /** * Check network connectivity to Vertex AI endpoints */ private static checkVertexNetworkConnectivity; /** * Check if Anthropic model integration is enabled in the project */ private static checkAnthropicModelIntegration; /** * Initialize health checks in the background (NON-BLOCKING) * Starts background health monitoring without blocking initialization */ static initializeBackgroundHealthChecks(): void; /** * Clear health cache for a provider or all providers */ static clearHealthCache(providerName?: AIProviderName): void; /** * Get the best healthy provider from a list of options (NON-BLOCKING) * Prioritizes healthy providers over configured but unhealthy ones * Uses fast, cached health checks to avoid blocking initialization */ static getBestHealthyProvider(preferredProviders?: string[]): Promise<string | null>; /** * Get health status for all registered providers */ static checkAllProvidersHealth(options?: ProviderHealthCheckOptions): Promise<ProviderHealthStatus[]>; /** * Get a summary of provider health */ static getHealthSummary(healthStatuses: ProviderHealthStatus[]): { total: number; healthy: number; configured: number; hasIssues: number; healthyProviders: string[]; unhealthyProviders: string[]; }; }