diff --git a/tauri-app/src/components/ChatView.tsx b/tauri-app/src/components/ChatView.tsx index 9cd20e2..e455a5b 100644 --- a/tauri-app/src/components/ChatView.tsx +++ b/tauri-app/src/components/ChatView.tsx @@ -478,6 +478,7 @@ interface Props { try { const chunk = JSON.parse(data); const delta = chunk.choices?.[0]?.delta?.content; + const finishReason = chunk.choices?.[0]?.finish_reason; if (typeof delta === "string") { const sanitizedDelta = sanitizeMessageText(delta); tokenCount++; @@ -485,12 +486,24 @@ interface Props { fullContent += sanitizedDelta.text; streamContentAccRef.current = fullContent; } + if (finishReason) { + const parsed = parseAssistantResponse(fullContent); + setStreamContent(parsed.content); + setStreamReasoning(parsed.reasoning); + setStreamThinkingOpen(parsed.thinkingOpen); + } if (chunk.usage) usage = chunk.usage; } catch (chunkErr) { devLog.logStreamChunk(line, null, null, `Parse error: ${chunkErr}`); } } } + + // Final safety parsing step to ensure UI states match DB right before saving + const parsed = parseAssistantResponse(fullContent); + setStreamContent(parsed.content); + setStreamReasoning(parsed.reasoning); + setStreamThinkingOpen(parsed.thinkingOpen); } else { const data = await res.json(); const rawNonStream = data.choices?.[0]?.message?.content || "";