Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai-openrouter): report length when the output limit cuts a tool call #2266

Mergedcanblmz1(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/2266/headmerged by AlemTuzlak View on GitHub

Showing 6 changed files with 67 additions and 10 deletions (loading 2).

x
0 of 6 viewed, 6 left
5 additions and 0 deletions.changeset/openrouter-length-tool-cut.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/ai-openrouter': patch
+---
+​
+Report `length`, not `tool_calls`, when the output limit cuts a streamed Chat Completions tool call. With `tool_calls`, the engine ran the cut call when its partial arguments happened to parse; with `length` it closes the call without running it, as with the other OpenAI-compatible adapters.
14 additions and 10 deletionspackages/ai-openrouter/src/adapters/text.tsModified
View file
@@ -1283,6 +1283,9 @@
// Map upstream finishReason to AG-UI's narrower vocabulary while
// preserving the upstream value when it falls outside the AG-UI set.
+ // `length` wins over `tool_calls`, as in openai-base: the output limit
+ // cut a tool call that was closed above, and the engine must see
+ // `length` so it does not run that call.
// Use `tool_calls` only when a TOOL_CALL_END was actually emitted.
// OpenRouter emits 'error' as a finish reason for upstream errors;
// collapse to 'content_filter' (the closest AG-UI equivalent).
@@ -1290,16 +1293,17 @@
| 'tool_calls'
| 'length'
| 'content_filter'
- | 'stop' = emittedAnyToolCallEnd
- ? 'tool_calls'
- : pendingFinishReason === 'tool_calls'
- ? 'stop'
- : pendingFinishReason === 'length'
- ? 'length'
- : pendingFinishReason === 'content_filter' ||