Repository navigation
fix(ai-anthropic): send the anthropic-beta header that computerUseTool needs - #1832
AlemTuzlak wants to merge 2 commits into
Conversation
computerUseTool() went out without its anthropic-beta header, so Anthropic rejected the request. Add computer-use-2025-01-24 for computer_20250124 and computer-use-2024-10-22 for computer_20241022.
🦋 Changeset detectedLatest commit: 08a7b2a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
View your CI Pipeline Execution ↗ for commit 08a7b2a
☁️ Nx Cloud last updated this comment at |
Coverage✅ Coverage held across 2 compared package(s). Each package is measured twice in this job — on this PR and on its merge-base with
|
@tanstack/ai
@tanstack/ai-acp
@tanstack/ai-angular
@tanstack/ai-anthropic
@tanstack/ai-bedrock
@tanstack/ai-byteplus
@tanstack/ai-claude-code
@tanstack/ai-client
@tanstack/ai-cloudflare
@tanstack/ai-code-mode
@tanstack/ai-code-mode-snippets
@tanstack/ai-codex
@tanstack/ai-cohere
@tanstack/ai-compaction
@tanstack/ai-devtools-core
@tanstack/ai-durable-stream
@tanstack/ai-elevenlabs
@tanstack/ai-event-client
@tanstack/ai-fal
@tanstack/ai-gemini
@tanstack/ai-grok
@tanstack/ai-grok-build
@tanstack/ai-groq
@tanstack/ai-isolate-cloudflare
@tanstack/ai-isolate-daytona
@tanstack/ai-isolate-e2b
@tanstack/ai-isolate-node
@tanstack/ai-isolate-quickjs
@tanstack/ai-isolate-quickjs-bun
@tanstack/ai-llmgateway
@tanstack/ai-lovable
@tanstack/ai-mcp
@tanstack/ai-memory
@tanstack/ai-mistral
@tanstack/ai-octane
@tanstack/ai-ollama
@tanstack/ai-ollaya
@tanstack/ai-openai
@tanstack/ai-opencode
@tanstack/ai-openrouter
@tanstack/ai-perplexity
@tanstack/ai-persistence
@tanstack/ai-preact
@tanstack/ai-react
@tanstack/ai-react-ui
@tanstack/ai-reactor
@tanstack/ai-remix
@tanstack/ai-sandbox
@tanstack/ai-sandbox-blaxel
@tanstack/ai-sandbox-boxd
@tanstack/ai-sandbox-cloudflare
@tanstack/ai-sandbox-daytona
@tanstack/ai-sandbox-docker
@tanstack/ai-sandbox-e2b
@tanstack/ai-sandbox-local-process
@tanstack/ai-sandbox-railway
@tanstack/ai-sandbox-sprites
@tanstack/ai-sandbox-upstash-box
@tanstack/ai-sandbox-vercel
@tanstack/ai-skills
@tanstack/ai-solid
@tanstack/ai-solid-ui
@tanstack/ai-svelte
@tanstack/ai-typesafe
@tanstack/ai-utils
@tanstack/ai-vercel-gateway
@tanstack/ai-vertex
@tanstack/ai-vue
@tanstack/ai-vue-ui
@tanstack/ai-worldlabs
@tanstack/openai-base
@tanstack/preact-ai-devtools
@tanstack/react-ai-devtools
@tanstack/solid-ai-devtools
@tanstack/svelte-ai-devtools
commit: |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
computerUseTool()from@tanstack/ai-anthropic/toolssends no computer use beta header, and Anthropic needs one for each of these versions. This PR adds the header that each version needs:computer-use-2025-01-24forcomputer_20250124, andcomputer-use-2024-10-22forcomputer_20241022.🎯 Changes
computeAnthropicBetasadds the computer use beta of thecomputertool intools. It follows thecode_executioncode next to it.anthropic-betaheader of the outgoing request.Docs: no change. The docs never said which header the tool sends, and the samples now work as written.
✅ Checklist
pnpm run test:pr, or these tests do not apply to this pull request.docs/for this change, or this change is not user-facing.pnpm changeset), or this PR does not change a published package.🚀 Release Impact
Root cause
Issue. A
chat()request withcomputerUseTool()has no computer use beta header. The Anthropic docs say that each earlier version needs its beta header on every request. For example,computer_20250124needscomputer-use-2025-01-24.Cause. The adapter sends
betasfromcomputeAnthropicBetas(packages/ai-anthropic/src/adapters/text.ts). That function adds the betas of code execution, skills, files, MCP, context management, and mid-conversation tools, but none for a computer use tool.Fix. When
toolshas a computer use tool,computeAnthropicBetasreads itstypeand adds the matching beta.Possible alternatives
defaultHeaders. This works today. It makes every app find and keep the right header for each version, and the adapter already owns thebetasof the other tools.computer-use-2025-01-24. Two lines shorter. It sends the wrong header forcomputer_20241022, whichcomputerUseTool()also takes.Testing
Commands run:
packages/ai-anthropic/tests/computer-use-beta.test.ts, written for this PR) on a cleanmainworktree at7095ebbf1. It fails:08a7b2a75). It passes:--maxWorkers=2oncomputer-use-beta,text.skills,provider-tools-smoke, andtools-per-model-type-safety: 48 tests pass.test:types,test:oxlint(no new warnings), andoxfmt --checkonai-anthropicand the changed files.testing/e2e.Not run locally: the E2E suite,
pnpm test:pr, and coverage. CI runs them.Manual test:
main, runpnpm --dir packages/ai-anthropic exec vitest run tests/computer-use-beta.test.ts. Both tests fail:expected [] to include 'computer-use-2025-01-24'.chat()onclaude-haiku-4-5withcomputerUseTool({ type: 'computer_20250124', name: 'computer', display_width_px: 1024, display_height_px: 768 }). The request now hasanthropic-beta: computer-use-2025-01-24.How this PR makes testing easy:
tests/computer-use-beta.test.tsrunschat()with a mocked client and reads thebetasof the request.testing/e2e/tests/anthropic-computer-use-wire.spec.tsreads the realanthropic-betaheader from a customfetch.Risk / rollback
Low. A request with a computer use tool gets one more beta header. Other requests do not change. To undo, revert this PR.
Summary by CodeRabbit