Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai-openrouter): keep timeoutMs when the caller passes an abort signal #2192

Openpcbeingused33(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromrefs/pull/2192/headopened View on GitHub

Showing 3 changed files with 186 additions and 6 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/openrouter-timeout-with-signal.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/ai-openrouter': patch
+---
+​
+fix(ai-openrouter): keep `timeoutMs` when the caller passes an abort signal. A timeout or a caller abort now also ends the retry backoff, and Node versions without `AbortSignal.any` work.
39 additions and 6 deletionspackages/ai-openrouter/src/client/http.tsModified
View file
@@ -267,8 +267,11 @@
...requestOptions,
const timeoutMs = requestOptions?.timeoutMs || options.timeoutMs || -1
- if (!init.signal && timeoutMs > 0)
- init.signal = AbortSignal.timeout(timeoutMs)
+ if (timeoutMs > 0) {
+ const timeout = AbortSignal.timeout(timeoutMs)
+ // A caller signal must not disable the configured timeout: abort on either.
+ init.signal = init.signal ? anySignal(init.signal, timeout) : timeout
+ }
const request = new Request(url, {
...init,
body: operation.body === undefined ? null : JSON.stringify(operation.body),
@@ -298,6 +301,7 @@
retryConfig,
retryCodes,
+ init.signal,
} catch (error) {