Fix tool results being mixed into thinking blocks

- 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
This commit is contained in:
Glen Maddern 2025-06-24 22:43:06 +10:00
commit 6126405ab0

View file

@ -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)