From 6126405ab09f2dce60ae6fed58179a87c93b92c6 Mon Sep 17 00:00:00 2001 From: Glen Maddern Date: Tue, 24 Jun 2025 22:43:06 +1000 Subject: [PATCH] Fix tool results being mixed into thinking blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add missing tool-result event handling in useStreamResponse - Tool results now appear as separate ToolResultMessage components - Prevents tool response content from being incorrectly added to reasoning content - Maintains proper message order: thinking → tool call → tool result → assistant response --- .../chat-ui/src/hooks/useStreamResponse.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/examples/chat-ui/src/hooks/useStreamResponse.ts b/examples/chat-ui/src/hooks/useStreamResponse.ts index ce50559..8652f64 100644 --- a/examples/chat-ui/src/hooks/useStreamResponse.ts +++ b/examples/chat-ui/src/hooks/useStreamResponse.ts @@ -288,6 +288,29 @@ export const useStreamResponse = ({ } else { console.warn('[useStreamResponse] Tool call event missing toolName:', event) } + } else if (event.type === 'tool-result') { + debugLog(`[useStreamResponse] Tool result:`, event) + + if (event.toolName && event.toolCallId) { + setConversations((prev) => { + const updated = [...prev] + const conv = updated.find((c) => c.id === conversationId) + if (conv) { + // Add tool result message + conv.messages.push({ + role: 'tool-result', + toolName: event.toolName, + toolArgs: event.args || {}, + toolResult: event.result, + callId: event.toolCallId, + }) + } + return updated + }) + scrollToBottom(true) + } else { + console.warn('[useStreamResponse] Tool result event missing toolName or toolCallId:', event) + } } else if (event.type === 'text-delta') { debugLog(`[useStreamResponse] Text delta:`, event.textDelta)