export type RetryOptions = { /** * - Maximum number of attempts. */ maxAttempts?: number | undefined; /** * - Backoff strategy or fixed ms. */ backoff?: number | "linear" | "exponential" | undefined; /** * - Per-attempt timeout in ms (0 to disable). */ timeout?: number | undefined; /** * - Predicate deciding whether to retry an error. */ retryOn?: ((err: any) => boolean) | undefined; /** * - Jitter strategy. */ jitter?: number | boolean | "full" | "equal" | undefined; }; export class Retry { /** * @param {RetryOptions} [options={}] * @when you want backoff-with-jitter around a flaky async call (a provider request, a plan step) — the retry seam that Loop and runPlan wrap around providers * @fails rethrows the last error once attempts are exhausted; by default only transient errors (429/5xx/ECONNRESET/ETIMEDOUT) are retried. * @example * const retry = new Retry({ maxAttempts: 3, jitter: true }); * const res = await retry.call(() => provider.generate(msgs)); */ constructor(options?: RetryOptions); maxAttempts: number; backoff: number | "linear" | "exponential"; timeout: number; retryOn: (err: any) => boolean; jitter: number | boolean | "full" | "equal"; /** * Call a function with retry logic. * @param {() => Promise<*>} fn - Async function to execute. * @param {RetryOptions} [options={}] - Per-call overrides for maxAttempts, retryOn, timeout. * @returns {Promise<*>} The result of fn(). * @throws {TimeoutError} When an individual attempt exceeds the timeout. * @throws {Error} Rethrows the last error when maxAttempts is exhausted or error is not retryable. */ call(fn: () => Promise, options?: RetryOptions): Promise; /** @param {number} attempt */ _delay(attempt: number): number; /** @param {number} base */ _applyJitter(base: number): number; }