Skip to content
1 min read · 176 words

@nhtio/adk/lib/utils/retry

Environment-neutral retry/backoff/timeout primitives shared across HTTP-backed batteries.

Remarks

These are pure helpers — no DOM, no Node built-ins, only setTimeout, AbortController, and AbortSignal, all of which exist in every target runtime (Node, browser, edge, workers). They are shared (not duplicated) by the OpenAI Chat Completions battery and the OpenAI Embeddings battery so retry behavior stays identical across the bundled batteries. The bundler inlines this module into each consumer, so sharing introduces no build coupling.

Interfaces

InterfaceDescription
BackoffConfigMinimal backoff configuration shape. Any retry config carrying baseDelayMs/maxDelayMs satisfies it structurally, so batteries can pass their own richer config objects directly.

Functions

FunctionDescription
computeBackoffExponential backoff with a ceiling: min(baseDelayMs * 2^(attempt-1), maxDelayMs).
linkAbortSignalsCombines several abort signals into one.
parseRetryAfterParses an HTTP Retry-After header value (delta-seconds or HTTP-date) into milliseconds.
sleepWithJitterAbort-aware jittered sleep used for retry backoff.