/** * Circuit breaker implementation with sliding window */ import type { ResilienceTelemetry } from './observability.js'; import type { CircuitBreakerConfig, CircuitBreakerState } from './types.js'; import { CircuitBreakerThresholdError } from './errors.js'; /** * Observer interface for circuit breaker state changes (optional) */ export interface CircuitBreakerObserver { onStateChange?: (key: string, state: 'closed' | 'open' | 'half-open') => void; } /** * Circuit breaker with sliding window for outcome tracking */ export declare class CircuitBreaker { private readonly observer?; private states; private readonly maxCircuits; private lastCleanup; private readonly cleanupInterval; private cleanupInProgress; private readonly config; private readonly telemetry?; private readonly performanceMetrics; constructor(config: CircuitBreakerConfig, observer?: CircuitBreakerObserver | undefined, telemetry?: ResilienceTelemetry); /** * Get or create circuit state for a given key */ private getState; /** * Evict the least recently used circuit state */ private evictLeastRecentlyUsed; /** * Schedule async cleanup if needed (non-blocking) */ private scheduleAsyncCleanup; /** * Perform async cleanup of expired circuits in chunks */ private performAsyncCleanup; /** * Delete keys in chunks to prevent event loop blocking */ private deleteKeysInChunks; /** * Record an outcome in the sliding window */ private recordOutcome; /** * Count failures in the sliding window */ private countFailures; /** * Check if circuit should transition to open */ private shouldOpen; /** * Check if circuit can transition to half-open */ private canTransitionToHalfOpen; /** * Execute an operation through the circuit breaker */ execute(key: string, operation: () => Promise): Promise; /** * Get current state for a circuit (for testing/monitoring) */ getCircuitState(key: string): CircuitBreakerState | undefined; /** * Reset a specific circuit (for testing) */ reset(key: string): void; /** * Reset all circuits (for testing) */ resetAll(): void; /** * Get debug info for a circuit (for testing) */ getDebugInfo(key: string): CircuitBreakerState | undefined; /** * Get current state map size (for testing) */ getStateMapSize(): number; /** * Update performance metrics for a circuit */ private updateMetrics; /** * Get performance metrics for a circuit */ getPerformanceMetrics(key: string): { totalOperations: number; totalDuration: number; averageDuration: number; failures: number; successRate: number; } | undefined; /** * Get all performance metrics */ getAllPerformanceMetrics(): Map; /** * Create enhanced threshold error for the given circuit state */ createThresholdError(key: string, state: CircuitBreakerState): CircuitBreakerThresholdError; /** * Derive a circuit key from context */ static deriveKey(workflowId: string, stepId: string): string; } //# sourceMappingURL=circuit-breaker.d.ts.map