Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai): ignore TOOL_CALL_ARGS after a tool call ended #2274

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

Showing 9 changed files with 14 additions and 1 deletion (loading 5).

x
0 of 9 viewed, 9 left
5 additions and 0 deletions.changeset/ignore-late-tool-call-args.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/ai': patch
+---
+​
+Ignore late tool argument events so server tools receive the finalized arguments and chat clients preserve completed tool calls.
2 additions and 0 deletionsdocs/chat/stream-events.mdModified
View file
@@ -219,6 +219,8 @@
| `RUN_FINISHED` usage | TanStack `TokenUsage` (`promptTokens`) | the spec `usage` array (`inputTokens`) |
| `TOOL_CALL_END` input | `input`, parsed from the argument string | no `input`. `metadata.tanstack.args` has the argument string as the provider sent it. |
​
+`TOOL_CALL_END` finalizes the arguments. TanStack AI ignores later `TOOL_CALL_ARGS` events for the same tool call.
+​
Read `finishReason` from `metadata.tanstack.finishReason` in both cases. If you write a custom server, see [Event metadata](../protocol/metadata).
​
### Chunk events
7 additions and 1 deletionpackages/ai/src/activities/chat/stream/processor.tsModified
View file
@@ -2528,7 +2528,13 @@
if (!state) return
const existingToolCall = state.toolCalls.get(toolCallId)
- if (!existingToolCall) return
+ if (
+ !existingToolCall ||
+ existingToolCall.state === 'input-complete' ||
+ this.isToolCallPartTerminal(toolCallId)