@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
225 lines (224 loc) • 7.42 kB
TypeScript
/**
* Retry and Circuit Breaker Constants for NeuroLink
*
* Centralized retry configuration to replace magic numbers throughout the codebase.
* Includes retry attempts, delays, backoff strategies, and circuit breaker settings.
*
* @fileoverview Retry and resilience constants for robust error handling
* @author NeuroLink Team
* @version 1.0.0
*/
/**
* Retry attempt configuration
* Balanced for reliability vs performance across different operation types
*/
export declare const RETRY_ATTEMPTS: {
/** Default retry attempts for most operations */
readonly DEFAULT: 3;
/** Critical operations that must succeed */
readonly CRITICAL: 5;
/** Quick operations that should fail fast */
readonly QUICK: 1;
/** Network operations prone to transient failures */
readonly NETWORK: 4;
/** Authentication operations */
readonly AUTH: 2;
/** Database operations */
readonly DATABASE: 3;
/** File I/O operations */
readonly FILE_IO: 2;
};
/**
* Retry delay configuration
* Configured to prevent overwhelming services while providing quick recovery
*/
export declare const RETRY_DELAYS: {
/** Base delay for exponential backoff */
readonly BASE_MS: 1000;
/** Minimum delay between retries */
readonly MIN_MS: 500;
/** Maximum delay between retries */
readonly MAX_MS: 30000;
/** Quick retry delay for fast operations */
readonly QUICK_MS: 200;
/** Network operation base delay */
readonly NETWORK_BASE_MS: 2000;
/** Authentication delay (security consideration) */
readonly AUTH_MS: 3000;
};
/**
* Exponential backoff configuration
* Controls how delays increase with each retry attempt
*/
export declare const BACKOFF_CONFIG: {
/** Standard exponential multiplier */
readonly MULTIPLIER: 2;
/** Conservative multiplier for sensitive operations */
readonly CONSERVATIVE_MULTIPLIER: 1.5;
/** Aggressive multiplier for operations that should back off quickly */
readonly AGGRESSIVE_MULTIPLIER: 3;
/** Jitter factor to prevent thundering herd */
readonly JITTER_FACTOR: 0.1;
/** Maximum jitter amount in milliseconds */
readonly MAX_JITTER_MS: 1000;
};
/**
* Circuit breaker configuration
* Prevents cascading failures and provides automatic recovery
*/
export declare const CIRCUIT_BREAKER: {
/** Failure threshold before opening circuit */
readonly FAILURE_THRESHOLD: 5;
/** Success threshold for closing circuit from half-open */
readonly SUCCESS_THRESHOLD: 3;
/** Minimum calls before calculating failure rate */
readonly MIN_CALLS: 10;
/** Failure rate threshold (0.0 to 1.0) */
readonly FAILURE_RATE_THRESHOLD: 0.5;
/** Monitoring window for failure tracking */
readonly MONITORING_WINDOW_MS: 300000;
/** Half-open max calls for testing recovery */
readonly HALF_OPEN_MAX_CALLS: 3;
};
/**
* Provider-specific retry configuration
* Different providers may need different retry strategies
*/
export declare const PROVIDER_RETRY: {
/** OpenAI retry configuration */
readonly OPENAI: {
readonly maxAttempts: 3;
readonly baseDelay: 1000;
readonly maxDelay: 30000;
readonly multiplier: 2;
};
/** Anthropic retry configuration */
readonly ANTHROPIC: {
readonly maxAttempts: 3;
readonly baseDelay: 1000;
readonly maxDelay: 30000;
readonly multiplier: 1.5;
};
/** Google (Vertex/Google AI) retry configuration */
readonly GOOGLE: {
readonly maxAttempts: 4;
readonly baseDelay: 2000;
readonly maxDelay: 30000;
readonly multiplier: 2;
};
/** AWS Bedrock retry configuration */
readonly BEDROCK: {
readonly maxAttempts: 5;
readonly baseDelay: 1000;
readonly maxDelay: 30000;
readonly multiplier: 1.5;
};
/** Azure OpenAI retry configuration */
readonly AZURE: {
readonly maxAttempts: 3;
readonly baseDelay: 1000;
readonly maxDelay: 30000;
readonly multiplier: 2;
};
/** Ollama retry configuration (local service) */
readonly OLLAMA: {
readonly maxAttempts: 1;
readonly baseDelay: 200;
readonly maxDelay: 5000;
readonly multiplier: 1.5;
};
};
/**
* Operation-specific retry configuration
* Different operations may require different retry strategies
*/
export declare const OPERATION_RETRY: {
/** Tool execution retry config */
readonly TOOL_EXECUTION: {
readonly maxAttempts: 3;
readonly baseDelay: 1000;
readonly circuitBreaker: true;
};
/** MCP operation retry config */
readonly MCP_OPERATION: {
readonly maxAttempts: 1;
readonly baseDelay: 200;
readonly circuitBreaker: false;
};
/** Network request retry config */
readonly NETWORK_REQUEST: {
readonly maxAttempts: 4;
readonly baseDelay: 2000;
readonly circuitBreaker: true;
};
/** Database operation retry config */
readonly DATABASE_OPERATION: {
readonly maxAttempts: 3;
readonly baseDelay: 1000;
readonly circuitBreaker: true;
};
/** Authentication retry config */
readonly AUTHENTICATION: {
readonly maxAttempts: 2;
readonly baseDelay: 3000;
readonly circuitBreaker: false;
};
};
/**
* Retry utility functions
*/
export declare const RetryUtils: {
/**
* Calculate exponential backoff delay
* @param attempt - Current attempt number (0-based)
* @param baseDelay - Base delay in milliseconds
* @param multiplier - Exponential multiplier
* @param maxDelay - Maximum delay cap
* @param jitter - Whether to add random jitter
* @returns Calculated delay in milliseconds
*/
readonly calculateBackoffDelay: (attempt: number, baseDelay?: number, multiplier?: number, maxDelay?: number, jitter?: boolean) => number;
/**
* Check if an error is retriable
* @param error - The error to check
* @returns True if the error should be retried
*/
readonly isRetriableError: (error: Error | unknown) => boolean;
/**
* Get retry configuration for a specific provider
* @param provider - Provider name
* @returns Retry configuration object
*/
readonly getProviderRetryConfig: (provider: string) => {
readonly maxAttempts: 3;
readonly baseDelay: 1000;
readonly maxDelay: 30000;
readonly multiplier: 2;
} | {
readonly maxAttempts: 3;
readonly baseDelay: 1000;
readonly maxDelay: 30000;
readonly multiplier: 1.5;
} | {
readonly maxAttempts: 4;
readonly baseDelay: 2000;
readonly maxDelay: 30000;
readonly multiplier: 2;
} | {
readonly maxAttempts: 5;
readonly baseDelay: 1000;
readonly maxDelay: 30000;
readonly multiplier: 1.5;
} | {
readonly maxAttempts: 1;
readonly baseDelay: 200;
readonly maxDelay: 5000;
readonly multiplier: 1.5;
};
};
export declare const DEFAULT_RETRY_ATTEMPTS: 3;
export declare const DEFAULT_INITIAL_DELAY: 1000;
export declare const DEFAULT_MAX_DELAY: 30000;
export declare const DEFAULT_BACKOFF_MULTIPLIER: 2;
export declare const CIRCUIT_BREAKER_FAILURE_THRESHOLD: 5;
export { CIRCUIT_BREAKER_RESET_MS } from "./timeouts.js";