UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio

83 lines (82 loc) 2.76 kB
/** * 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<RetryOptions>; /** * Execute an operation with retry logic */ export declare function withRetry<T>(operation: () => Promise<T>, options?: RetryOptions): Promise<T>; /** * Enhanced timeout with retry for network operations */ export declare function withTimeoutAndRetry<T>(operation: () => Promise<T>, timeoutMs: number, retryOptions?: RetryOptions): Promise<T>; /** * 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<T>(operation: () => Promise<T>): Promise<T>; 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<void>; } /** * Utility for graceful shutdown handling */ export declare class GracefulShutdown { private operations; private shutdownPromise; track<T>(operation: Promise<T>): Promise<T>; shutdown(timeoutMs?: number): Promise<void>; private performShutdown; } /** * Global instances for convenience */ export declare const globalShutdown: GracefulShutdown; export declare const providerCircuitBreaker: CircuitBreaker; export declare const apiRateLimiter: RateLimiter;