Repository navigation
fix(provider-utils): preserve prototype-named tools - #25355
duoduohappy wants to merge 1 commit into
Conversation
Prepared with Codex assistance.
|
@duoduohappy is attempting to run Vercel CI for a fork pull request of the Vercel Team on Vercel. A member of the Team first needs to approve it. |
|
@duoduohappy is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
surlymochan
left a comment
There was a problem hiding this comment.
Verified the bug and the fix by reading the diff: with plain-object maps, looking up a prototype-named tool (e.g. __proto__/constructor/toString) reads an inherited property instead of a mapping — toCustomToolName('__proto__') would have returned Object.prototype rather than the name. Switching both maps to Map makes .get() return undefined for unmapped names so the ?? name fallback is correct. The tests cover both directions, including a provider tool literally named __proto__ mapped to web_search, and the changeset (patch for @ai-sdk/provider-utils) matches the scope.
One question: are there other plain-object name maps in provider-utils with the same prototype-key pattern, or is this the only one? Not a blocker — the fix itself is complete for this helper.
|
@surlymochan Thanks for checking! A focused search of provider-utils didn’t turn up another plain-object tool-name mapping with the same pattern. The streaming tool-call tracker already uses Map. This wasn’t an exhaustive audit of every object lookup, so I’ve kept this PR scoped to the two mappings in this helper. |
|
Verified locally (macOS, Node 22.22; Repro, before/after. Ran the script from the PR description against On the open question about other plain-object name maps. I searched the packages for lookups keyed by tool names. Findings:
Fine to keep this PR scoped to Not verified: Edge suite, live OpenAI. LGTM from a contributor's point of view (non-binding). |
|
@terrorgeek Thanks for reproducing this and checking the other packages! A separate issue for the Anthropic case with your probe would be helpful. I'll keep this PR focused on createToolNameMapping. Thanks also for clearly documenting the validation scope. |
Background
Fixes #25354, which I reported after investigating tool-name mapping.
createToolNameMappingstores mappings in plain objects. Unmapped names such asconstructorandtoStringresolve to inherited functions, while__proto__resolves to an object. In the OpenAI Responses request serializer this omits the first two tool-call names and serializes the third as{}. Assigning a provider tool the custom alias__proto__also fails to store the mapping.Summary
Map<string, string>for both mapping directions, preserving the existing fallback and last-mapping-wins behavior.__proto__alias.@ai-sdk/provider-utils.Prepared with Codex assistance. The account owner has reviewed the changes and confirmed understanding.
Validation
@ai-sdk/provider-utils,@ai-sdk/openai, andaipassed.git diff --checkpassed. Modified-file guideline discovery and verifiers reported no applicable checks.pnpm type-checkwas attempted but did not complete: the selectively installed checkout lacks unrelatedtools/konsistent-providerdependencies (@vercel/ai-tsconfig/ts-library.jsonand@konsistent/convention). This is not a claim that the full workspace checks passed.End-to-End Verification
Prerequisites: Node.js 24 and pnpm 12.14.0; no API credentials are required. Tested on Windows. Baseline:
d55f3cfc456d1b7bc7db3a4b70fbf602ddc8647d.Save the following as
../vercel-tool-name-repro.mjsoutside the checkout:From the checkout root, install dependencies and build the local packages:
pnpm install --filter @ai-sdk/provider-utils... --filter @ai-sdk/openai... --filter ai... --frozen-lockfile pnpm exec turbo build --filter=ai... --filter=@ai-sdk/openai...Run from
packages/openaiso the script resolves the locally built workspace package:On a POSIX shell, the equivalent is:
node --input-type=module < ../../../vercel-tool-name-repro.mjsI built and ran this script against the baseline, then rebuilt and reran the same script after the fix. Both runs printed the checkout's
packages/openai/dist/index.jsURL, rather than a registry installation.Observed baseline calls:
{"type":"function_call","call_id":"call-1","name":"lookup","arguments":"{}"} {"type":"function_call","call_id":"call-1","arguments":"{}"} {"type":"function_call","call_id":"call-1","arguments":"{}"} {"type":"function_call","call_id":"call-1","name":{},"arguments":"{}"}After the fix:
{"type":"function_call","call_id":"call-1","name":"lookup","arguments":"{}"} {"type":"function_call","call_id":"call-1","name":"constructor","arguments":"{}"} {"type":"function_call","call_id":"call-1","name":"toString","arguments":"{}"} {"type":"function_call","call_id":"call-1","name":"__proto__","arguments":"{}"}Verification limit: this exercises the built OpenAI Responses provider's request-construction and serialization path, intercepted through its custom fetch hook. It deliberately stops before network I/O. No live OpenAI request, response, or model execution was verified; this is not full live-service end-to-end verification.
Checklist
pnpm changesetin the project root)Related Issues
Fixes #25354