import type { RetryOptions } from "../index.js"; import { FilesError } from "./errors.js"; /** * Normalize a caller-supplied per-attempt timeout into a usable delay: `undefined` * for unset, non-positive, or non-finite values (`Infinity` / `NaN` read as * "no timeout"), otherwise the value clamped to the 32-bit `setTimeout` max. */ export declare const timeoutMs: (timeout?: number) => number | undefined; /** * `AbortSignal.any` for runtimes without it (Node < 20): a controller that * follows the first of `signals` to abort. Listeners are detached once it * aborts; until then they stay attached, since the result must keep tracking * its sources for as long as it lives. */ export declare const manualAnySignal: (signals: AbortSignal[]) => AbortSignal; /** * Fold zero or more signals into one that aborts when any of them does, with * **no** teardown: the result stays wired to its sources for as long as it * lives, so a caller's `signal` keeps reaching a lazily-consumed body after * the operation call itself has resolved. Uses `AbortSignal.any` where the * runtime has it (the platform manages listener lifetimes), else * {@link manualAnySignal}. */ export declare const combineSignals: (signals: AbortSignal[]) => AbortSignal | undefined; export interface MergedSignals { signal?: AbortSignal; /** Clears the per-attempt timeout timer; absent when no timeout was set. */ cleanup?: () => void; } /** * Combine zero or more abort signals with an optional per-attempt timeout into * a single signal. The caller signals are folded with {@link combineSignals} * and stay attached for the life of the result; only the timeout is disposable * — `cleanup` clears its timer so a per-attempt timeout can't fire into a * body that's still streaming after the call resolved. Callers must invoke * `cleanup` in a `finally`. */ export declare const mergeSignals: (signals: AbortSignal[], timeout?: number) => MergedSignals; /** * Normalize an abort reason into a {@link FilesError} flagged `aborted`, with * the reason kept as the error's `cause`. A reason that's already a * `FilesError` (e.g. a timeout) passes through; an `Error` is wrapped with its * message; anything else is stringified. */ export declare const abortError: (cause?: unknown) => FilesError; /** * Run `fn`, rejecting early if `signal` aborts before it settles. When no * signal is given, just runs `fn`. The abort listener is detached once `fn` * settles so a long-lived signal doesn't accumulate listeners. */ export declare const runWithSignal: (signal: AbortSignal | undefined, fn: () => Promise) => Promise; /** * Sleep `ms`, rejecting early (and clearing the timer) if `signal` aborts. A * non-positive `ms` resolves immediately. */ export declare const sleep: (ms: number, signal?: AbortSignal) => Promise; /** * Maximum number of retry attempts for an operation. `0` when not retryable or * unset. A bare number is treated as `{ max }`. */ export declare const maxRetries: (retries: RetryOptions | undefined, retryable: boolean) => number; /** * Backoff delay in ms before the given (1-based) retry attempt. Uses the * caller's `backoff` curve when supplied, otherwise an exponential curve from * 100ms, capped at 30s. */ export declare const retryBackoff: (retries: RetryOptions | undefined, attempt: number, error: FilesError) => number; /** * Whether a failed attempt should be retried: under the attempt cap, a * transient `Provider` error, not an abort (aborts and timeouts are * deliberate and never retried), and not flagged `permanent` (a * deterministic failure re-issuing the request can't fix). */ export declare const canRetry: (error: FilesError, attempt: number, maxAttempts: number) => boolean; //# sourceMappingURL=retry.d.ts.map