@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
42 lines (41 loc) • 1.98 kB
TypeScript
/**
* Provider-level retry utility for AI SDK calls (NL11)
*
* The Vercel AI SDK's `generateText()` and `streamText()` have built-in retry
* logic (`_retryWithExponentialBackoff()` with default `maxRetries: 2`) that
* retries on HTTP 429/500/503. These retries are completely invisible to OTel
* because they happen inside the AI SDK.
*
* This module provides an instrumented retry wrapper that:
* 1. Disables the AI SDK's internal retries (via `maxRetries: 0`)
* 2. Implements our own retry loop with full OTel span events
* 3. Records retry attempts, delays, status codes, and total attempt count
*
* @module utils/providerRetry
*/
import { type Span } from "@opentelemetry/api";
/** Maximum number of retry attempts after the initial call (total = 1 + MAX_PROVIDER_RETRIES). */
export declare const MAX_PROVIDER_RETRIES = 2;
/** Base delay in ms for exponential backoff between retries. */
export declare const BASE_RETRY_DELAY_MS = 1000;
/**
* Check whether an error thrown by the AI SDK is retryable.
*
* Uses `APICallError.isInstance()` for proper type-safe detection (the class
* uses a branded symbol marker, so `instanceof` doesn't work across package
* boundaries). Falls back to duck-typing for non-APICallError cases.
*/
export declare function isRetryableProviderError(error: unknown): boolean;
/**
* Extract the HTTP status code from an AI SDK error, if available.
*/
export declare function getErrorStatusCode(error: unknown): number | undefined;
/**
* Execute a provider call with instrumented retry logic.
*
* @param operation - The async operation to execute (should already use `maxRetries: 0`)
* @param span - The OTel span to annotate with retry events and attributes
* @param label - A human-readable label for log messages (e.g. "generateText", "streamText")
* @returns The result of the operation
*/
export declare function withProviderRetry<T>(operation: () => Promise<T>, span: Span, label: string): Promise<T>;