/** * src/llm/ProviderFailover.ts * * Provider failover with circuit breaker, failure classification, probe * recovery, and per-member provider preferences. * * Implements docs/architecture/provider-failover.md: * - Failure classification (401/402/429/408/503/404) * - Three-state circuit breaker (CLOSED → OPEN → HALF_OPEN → CLOSED) * - Probe recovery 30s before cooldown expiry * - 5 recovery strategies */ import type { ILLMProvider } from './ILLMProvider.ts'; import type { LLMRequest, LLMResponse, LLMChunk } from './types.ts'; import type { ProviderChainConfig } from './providerFailoverTypes.ts'; import type { CircuitBreakerState } from './providerFailoverTypes.ts'; import { classifyError, AllProvidersFailedError } from './ProviderFailoverError.ts'; export { classifyError, AllProvidersFailedError }; /** * Orchestrates multiple LLM providers with failover, circuit breaker, * failure classification, and probe recovery. * * Usage: * ``` * const chain = new ProviderChain([groq, openai, ollama], ['groq', 'openai', 'ollama']) * const response = await chain.complete(request) * ``` * * If the first provider fails, the chain tries the next, applying * retry strategies and circuit breaker state per provider. */ export declare class ProviderChain implements ILLMProvider { private providers; private readonly chainConfig; private circuitBreakers; private announcedPrimary; private providerNames; readonly modelMap: Map; constructor(providers: ILLMProvider[], providerNames?: string[], chainConfig?: ProviderChainConfig, modelMap?: Map); /** complete() keeps its own loop on purpose: attempts run through * executeWithStrategy (per-provider retries with index backoff, then model * fallbacks) and the terminal error carries the last failure's category. * Delegating to withActiveProviders would run model fallbacks twice. */ complete(request: LLMRequest): Promise; stream(request: LLMRequest): Promise>; embed(text: string): Promise; /** * Shared failover loop for stream/embed. Iterates active providers, * tries each with model fallbacks, and handles breaker tripping. */ private withActiveProviders; private recordProviderFailure; /** Permanent failures other than a missing model end the fallback walk. */ private static isHardStop; /** Shared model-fallback path: re-attempt on each remaining model until one * succeeds or a hard-stop failure ends the walk; throws the last error. */ private tryRemainingModels; /** Test-only construction helper — production chains are assembled by * LLMRouter.buildChainFromEntries, which owns config and redaction wiring. */ static buildChain(providers: Map, preferred: string, fallbackOrder: string[], modelMap?: Map): { chain: ProviderChain; names: string[]; }; private completeWithTimeout; private executeWithStrategy; private onSuccess; private tripBreaker; private requireActiveProviders; private computeActiveProviders; private providerName; /** * Announces a provider transition exactly once. The "Using X (primary)" * line is emitted a single time per chain instance; fallbacks stay * per-call so operator logs show every hop without 20 identical lines. */ private announce; private freshState; getBreakerState(name: string): CircuitBreakerState | undefined; setModel(model: string): void; getContextWindow(): number; } //# sourceMappingURL=ProviderFailover.d.ts.map