/** * Retry and resilience utilities for NeuroLink * Part of Sub-phase 3.3.3 - Edge Case Handling */ import type { RetryOptions } from "../types/index.js"; /** * Calculate exponential backoff delay with jitter * @param attempt - Current attempt number (1-based) * @param initialDelay - Initial delay in milliseconds * @param multiplier - Backoff multiplier for exponential growth * @param maxDelay - Maximum delay cap in milliseconds * @param addJitter - Whether to add random jitter to prevent thundering herd * @returns Calculated delay in milliseconds */ export declare function calculateBackoffDelay(attempt: number, initialDelay?: number, multiplier?: number, maxDelay?: number, addJitter?: boolean): number; /** * Error types that are typically retryable */ export declare class NetworkError extends Error { readonly cause?: Error | undefined; constructor(message: string, cause?: Error | undefined); } export declare class TemporaryError extends Error { readonly cause?: Error | undefined; constructor(message: string, cause?: Error | undefined); } /** * Default retry configuration */ export declare const DEFAULT_RETRY_CONFIG: Required; /** * Execute an operation with retry logic */ export declare function withRetry(operation: () => Promise, options?: RetryOptions): Promise; /** * Enhanced timeout with retry for network operations */ export declare function withTimeoutAndRetry(operation: () => Promise, timeoutMs: number, retryOptions?: RetryOptions): Promise; /** * Circuit breaker pattern for preventing cascading failures */ export declare class CircuitBreaker { private threshold; private timeout; private monitorWindow; private failures; private lastFailureTime; private state; constructor(threshold?: number, timeout?: number, // 1 minute monitorWindow?: number); execute(operation: () => Promise): Promise; private onSuccess; private onFailure; getState(): string; reset(): void; } /** * Rate limiter to prevent overwhelming APIs */ export declare class RateLimiter { private maxRequests; private windowMs; private requests; constructor(maxRequests: number, windowMs: number); acquire(): Promise; } /** * Utility for graceful shutdown handling */ export declare class GracefulShutdown { private operations; private shutdownPromise; track(operation: Promise): Promise; shutdown(timeoutMs?: number): Promise; private performShutdown; } /** * Global instances for convenience */ export declare const globalShutdown: GracefulShutdown; export declare const providerCircuitBreaker: CircuitBreaker; export declare const apiRateLimiter: RateLimiter;