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

155 lines (154 loc) 4.86 kB
/** * Retry Policy * Configurable retry strategies for observability exporters */ import type { RetryPolicy, RetryContext, RetryDecision } from "../types/index.js"; /** * Base retry policy with common configuration */ export declare abstract class BaseRetryPolicy implements RetryPolicy { abstract readonly name: string; readonly maxAttempts: number; readonly maxTotalTimeMs: number; protected readonly retryableErrors: Set<string>; protected readonly nonRetryableErrors: Set<string>; constructor(config: { maxAttempts?: number; maxTotalTimeMs?: number; retryableErrors?: string[]; nonRetryableErrors?: string[]; }); abstract shouldRetry(context: RetryContext): RetryDecision; protected isRetryableError(error: Error): boolean; protected extractErrorCode(error: Error): string; } /** * Exponential backoff retry policy * Delay increases exponentially with each attempt */ export declare class ExponentialBackoffPolicy extends BaseRetryPolicy { readonly name = "exponential-backoff"; private readonly baseDelayMs; private readonly maxDelayMs; private readonly jitterFactor; constructor(config?: { maxAttempts?: number; maxTotalTimeMs?: number; baseDelayMs?: number; maxDelayMs?: number; jitterFactor?: number; retryableErrors?: string[]; nonRetryableErrors?: string[]; }); shouldRetry(context: RetryContext): RetryDecision; } /** * Linear backoff retry policy * Delay increases linearly with each attempt */ export declare class LinearBackoffPolicy extends BaseRetryPolicy { readonly name = "linear-backoff"; private readonly delayIncrementMs; private readonly initialDelayMs; constructor(config?: { maxAttempts?: number; maxTotalTimeMs?: number; initialDelayMs?: number; delayIncrementMs?: number; retryableErrors?: string[]; nonRetryableErrors?: string[]; }); shouldRetry(context: RetryContext): RetryDecision; } /** * Fixed delay retry policy * Same delay for all retry attempts */ export declare class FixedDelayPolicy extends BaseRetryPolicy { readonly name = "fixed-delay"; private readonly delayMs; constructor(config?: { maxAttempts?: number; maxTotalTimeMs?: number; delayMs?: number; retryableErrors?: string[]; nonRetryableErrors?: string[]; }); shouldRetry(context: RetryContext): RetryDecision; } /** * No retry policy - never retries */ export declare class NoRetryPolicy implements RetryPolicy { readonly name = "no-retry"; readonly maxAttempts = 1; readonly maxTotalTimeMs = 0; shouldRetry(_context: RetryContext): RetryDecision; } /** * Circuit breaker aware retry policy * Works with circuit breaker state to prevent retries when circuit is open */ export declare class CircuitBreakerAwarePolicy extends BaseRetryPolicy { readonly name = "circuit-breaker-aware"; private readonly innerPolicy; private failures; private lastFailure; private circuitState; private readonly failureThreshold; private readonly resetTimeoutMs; constructor(config?: { innerPolicy?: RetryPolicy; failureThreshold?: number; resetTimeoutMs?: number; maxAttempts?: number; maxTotalTimeMs?: number; retryableErrors?: string[]; nonRetryableErrors?: string[]; }); shouldRetry(context: RetryContext): RetryDecision; recordFailure(): void; recordSuccess(): void; getCircuitState(): "closed" | "open" | "half-open"; reset(): void; } /** * Retry executor - executes operations with retry policy */ export declare class RetryExecutor { private readonly policy; constructor(policy: RetryPolicy); /** * Execute an operation with retry * @param operation - The async operation to execute * @param operationName - Name for logging * @returns The result of the operation * @throws The last error if all retries fail */ execute<T>(operation: () => Promise<T>, operationName: string): Promise<T>; private delay; } /** * Factory for creating retry policies */ export declare class RetryPolicyFactory { /** * Create a default policy for production use */ static createDefault(): ExponentialBackoffPolicy; /** * Create an aggressive policy for critical operations */ static createAggressive(): ExponentialBackoffPolicy; /** * Create a conservative policy for non-critical operations */ static createConservative(): LinearBackoffPolicy; /** * Create a circuit breaker aware policy */ static createWithCircuitBreaker(config?: { failureThreshold?: number; resetTimeoutMs?: number; }): CircuitBreakerAwarePolicy; }