Skip to content

fix(tanstack-ai): avoid duplicate tool call ids#424

Merged
threepointone merged 4 commits intomainfrom
fix-tanstack-ai-tool-call-id
Mar 18, 2026
Merged

fix(tanstack-ai): avoid duplicate tool call ids#424
threepointone merged 4 commits intomainfrom
fix-tanstack-ai-tool-call-id

Conversation

@vaibhavshn
Copy link
Collaborator

Previously, all tool call ids were chatcmplt, which made new tool call requests and responses get appended to previous parts. This fixes it so all tool calls have unique tool call ids, same as workers-ai-provider.

  • Change generateId to use 'chatcmpl' prefix and truncated UUID format
  • Generate unique IDs per tool call index instead of trusting backend IDs
  • Track tool call state across chunks to ensure stable IDs in streaming
  • Update test assertions to expect 'chatcmpl-' prefix instead of 'workers-ai-'

@changeset-bot
Copy link

changeset-bot bot commented Feb 27, 2026

🦋 Changeset detected

Latest commit: 60dd5db

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/tanstack-ai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 27, 2026

Open in StackBlitz

npx https://pkg.pr.new/cloudflare/ai/ai-gateway-provider@424
npx https://pkg.pr.new/cloudflare/ai/@cloudflare/tanstack-ai@424
npx https://pkg.pr.new/cloudflare/ai/workers-ai-provider@424

commit: 60dd5db

vaibhavshn and others added 4 commits March 18, 2026 21:14
- Change generateId to use 'chatcmpl' prefix and truncated UUID format
- Generate unique IDs per tool call index instead of trusting backend IDs
- Track tool call state across chunks to ensure stable IDs in streaming
- Update test assertions to expect 'chatcmpl-' prefix instead of 'workers-ai-'
- Change default test script to run once, add test:watch for watch mode
- Create ToolCallDisplay component with collapsible UI for tool calls
- Show tool name, arguments, and results in formatted JSON
- Add expand/collapse button with rotation animation
- Match tool calls with their results using toolCallId
- Skip rendering standalone tool-result parts (already shown in tool-call)
- Style differently for user vs assistant messages
- Add formatJson helper to pretty-print JSON strings
Stop forcing tool call IDs through a 9-char alphanumeric sanitization step used for Workers AI binding compatibility. The sanitizeToolCallId function and its uses were removed; IDs are now passed through as-provided, and generated fallback IDs are derived per tool-call index (e.g. `call${streamId}${tcIndex}`) to avoid duplicates. Tests and E2E expectations were updated to reflect the new behavior. Also removed a stray console.log in the example and re-enabled a commented provider entry; the changeset message was updated to explain the ID-generation change.
@threepointone threepointone force-pushed the fix-tanstack-ai-tool-call-id branch from 39a9405 to 60dd5db Compare March 18, 2026 21:40
@threepointone threepointone merged commit 76e5b0c into main Mar 18, 2026
3 checks passed
@threepointone threepointone deleted the fix-tanstack-ai-tool-call-id branch March 18, 2026 21:45
@github-actions github-actions bot mentioned this pull request Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants