From bf753eab5580e5fb93d03dcec8322a46b1c90f9d Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Wed, 22 Apr 2026 17:59:32 -0700 Subject: [PATCH] AIX: XAI: support for reasoning items --- .../adapters/xai.responsesCreate.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/modules/aix/server/dispatch/chatGenerate/adapters/xai.responsesCreate.ts b/src/modules/aix/server/dispatch/chatGenerate/adapters/xai.responsesCreate.ts index d3c609d0b..12e1a24a5 100644 --- a/src/modules/aix/server/dispatch/chatGenerate/adapters/xai.responsesCreate.ts +++ b/src/modules/aix/server/dispatch/chatGenerate/adapters/xai.responsesCreate.ts @@ -220,6 +220,16 @@ function _toXAIResponsesInput( }); } + function newReasoningItem(itemId: string | undefined, encryptedContent: string | undefined) { + // Mirror of the OpenAI Responses adapter - xAI Responses accepts the same reasoning input item shape. + inputItems.push({ + type: 'reasoning' as const, + ...(itemId ? { id: itemId } : {}), + summary: [], + ...(encryptedContent ? { encrypted_content: encryptedContent } : {}), + }); + } + for (const aixMessage of chatSequence) { const { role: messageRole, parts: messageParts } = aixMessage; @@ -319,7 +329,12 @@ function _toXAIResponsesInput( break; case 'ma': - // reasoning/thinking block - ignored for input + // xAI reuses the OpenAI Responses continuity namespace (_vnd.openai.reasoningItem). + // Only active when AIX_XAI_ADD_ENCRYPTED_REASONING is enabled and encrypted_content is captured; + // otherwise the handle is absent and we skip to avoid "Item with id rs_... not found" style errors. + const oaiReasoning = part._vnd?.openai?.reasoningItem; + if (oaiReasoning?.encryptedContent || oaiReasoning?.id) + newReasoningItem(oaiReasoning.id, oaiReasoning.encryptedContent); break; case 'tool_response':