From 878cdf302b90e98703714edfaf605bd0f35813d0 Mon Sep 17 00:00:00 2001 From: Omar Nahhas Sanchez Date: Fri, 10 Apr 2026 06:28:58 +0300 Subject: [PATCH] fix: only strip reasoning_content when content is non-empty (#542) sseToJsonHandler.js unconditionally deleted reasoning_content from all non-streaming responses (added for Firecrawl SDK compatibility). This breaks thinking models (Qwen3.5, Claude extended thinking, etc.) where the model may use all tokens for reasoning, leaving content empty. When reasoning_content is stripped in that case, the response appears completely empty to the client. Fix: only strip reasoning_content when the response also has non-empty content, so that reasoning output is preserved when it is the only useful output. Co-authored-by: Agent Zero --- open-sse/handlers/chatCore/sseToJsonHandler.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/open-sse/handlers/chatCore/sseToJsonHandler.js b/open-sse/handlers/chatCore/sseToJsonHandler.js index b7fabe32..b4d68ae5 100644 --- a/open-sse/handlers/chatCore/sseToJsonHandler.js +++ b/open-sse/handlers/chatCore/sseToJsonHandler.js @@ -210,10 +210,15 @@ export async function handleForcedSSEToJson({ providerResponse, sourceFormat, pr status: "success" }, { endpoint: clientRawRequest?.endpoint || null })).catch(() => {}); - // Strip reasoning_content — breaks JSON parsers in some clients (e.g. Firecrawl AI SDK) + // Strip reasoning_content only when content is non-empty. + // When content is empty (e.g. thinking models that used all tokens for reasoning), + // reasoning_content is the only useful output and must be preserved. + // Previously this was unconditional, which broke Qwen3.5, Claude extended thinking, etc. if (parsed?.choices) { for (const choice of parsed.choices) { - if (choice?.message) delete choice.message.reasoning_content; + if (choice?.message?.reasoning_content && choice.message.content) { + delete choice.message.reasoning_content; + } } }