fix(xai): map server-side tool types to toolName when part.name is empty #11484
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When using
xai.tools.webSearch()withxai.responses()andstreamText, tool-call events are emitted with emptytoolName, causingAI_NoSuchToolError.Example of the error:
{ "type": "tool-call", "toolCallId": "ws_24e5ff31-0c00-48c9-c980-671b70dd254e_call_48407951", "toolName": "", "invalid": true, "error": { "name": "AI_NoSuchToolError", "toolName": "", "availableTools": ["web_search"] } }Root Cause
In
xai-responses-language-model.ts, the code mapspart.nameto the user's tool name, but only checks ifpart.namematches specific sub-tool names likeweb_search,browse_page, etc.When xAI returns
web_search_callevents,part.namemay beundefinedor empty, so the mapping fails andtoolNameremains an empty string.Solution
Check
part.typein addition topart.nameto correctly identify server-side tools:web_search_call→webSearchToolNamex_search_call→xSearchToolNamecode_execution_call/code_interpreter_call→codeExecutionToolNameview_image_call→view_imageview_x_video_call→view_x_videoChanges
doGenerateanddoStreammethodspart.nameis emptyTesting
part.namescenariosstreamTextwithxai.tools.webSearch()Fixes #11263