From dbb7aee65b2a2e66e93f86b412e4c90a1ee4cf16 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Wed, 18 Mar 2026 20:10:35 +0200 Subject: [PATCH] fix: make reasoning part text optional in generated types (#23249) Go serializes ChatMessagePart.Text with omitempty, so empty reasoning text (from reasoning_start with no delta) is omitted from JSON. The frontend receives {type: "reasoning"} with text as undefined, crashing on .trim() calls. Mark Text as optional in the reasoning variant via the variants struct tag. This generates ChatReasoningPart with text?: string and the frontend falls back to "" via nullish coalescing. Closes #23245 --- codersdk/chats.go | 2 +- site/src/api/typesGenerated.ts | 2 +- site/src/pages/AgentsPage/AgentDetail/messageParsing.ts | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/codersdk/chats.go b/codersdk/chats.go index 78c2377dc6..f14cedeab5 100644 --- a/codersdk/chats.go +++ b/codersdk/chats.go @@ -127,7 +127,7 @@ func AllChatMessagePartTypes() []ChatMessagePartType { // scripts/apitypings/main.go for the codegen that reads these. type ChatMessagePart struct { Type ChatMessagePartType `json:"type"` - Text string `json:"text,omitempty" variants:"text,reasoning"` + Text string `json:"text,omitempty" variants:"text,reasoning?"` Signature string `json:"signature,omitempty"` ToolCallID string `json:"tool_call_id,omitempty" variants:"tool-call?,tool-result?"` ToolName string `json:"tool_name,omitempty" variants:"tool-call?,tool-result?"` diff --git a/site/src/api/typesGenerated.ts b/site/src/api/typesGenerated.ts index ca8d4617d8..5c49f82474 100644 --- a/site/src/api/typesGenerated.ts +++ b/site/src/api/typesGenerated.ts @@ -1682,7 +1682,7 @@ export interface ChatQueuedMessage { // From codersdk/chats.go export interface ChatReasoningPart { readonly type: "reasoning"; - readonly text: string; + readonly text?: string; } // From codersdk/chats.go diff --git a/site/src/pages/AgentsPage/AgentDetail/messageParsing.ts b/site/src/pages/AgentsPage/AgentDetail/messageParsing.ts index 15e2dd5e8f..d12ad253e5 100644 --- a/site/src/pages/AgentsPage/AgentDetail/messageParsing.ts +++ b/site/src/pages/AgentsPage/AgentDetail/messageParsing.ts @@ -131,8 +131,9 @@ export const parseMessageContent = ( break; } case "reasoning": { - parsed.reasoning = appendText(parsed.reasoning, part.text); - parsed.blocks = appendTextBlock(parsed.blocks, "thinking", part.text); + const text = part.text ?? ""; + parsed.reasoning = appendText(parsed.reasoning, text); + parsed.blocks = appendTextBlock(parsed.blocks, "thinking", text); break; } case "tool-call": {