fix(tools): correct Grok response parsing for xAI Responses API (#13049)

* fix(tools): correct Grok response parsing for xAI Responses API

The xAI Responses API returns content in output[0].content[0].text,
not in output_text field. Updated GrokSearchResponse type and
runGrokSearch to extract content from the correct path.

Fixes the 'No response' issue when using Grok web search.

* fix(tools): harden Grok web_search parsing (#13049) (thanks @ereid7)

---------

Co-authored-by: erai <erai@erais-Mac-mini.local>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
Evan Reid
2026-02-09 22:51:24 -05:00
committed by GitHub
parent 8fad4c2844
commit 0c7bc303c9
3 changed files with 43 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ const {
resolveGrokApiKey,
resolveGrokModel,
resolveGrokInlineCitations,
extractGrokContent,
} = __testing;
describe("web_search perplexity baseUrl defaults", () => {
@@ -142,3 +143,23 @@ describe("web_search grok config resolution", () => {
expect(resolveGrokInlineCitations({ inlineCitations: false })).toBe(false);
});
});
describe("web_search grok response parsing", () => {
it("extracts content from Responses API output blocks", () => {
expect(
extractGrokContent({
output: [
{
content: [{ text: "hello from output" }],
},
],
}),
).toBe("hello from output");
});
it("falls back to deprecated output_text", () => {
expect(extractGrokContent({ output_text: "hello from output_text" })).toBe(
"hello from output_text",
);
});
});