From c565decbe348e5a326790f1fd5ec33efa3274ee6 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 23 Aug 2025 15:38:32 -0500 Subject: [PATCH] Fix tools again, except it's still in the wrong format goddammit --- src/components/ai/AssistantContent.tsx | 4 ++-- src/hooks/useStreamingChat.ts | 33 ++++++++++++++++---------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/components/ai/AssistantContent.tsx b/src/components/ai/AssistantContent.tsx index b12d973e..e20e004f 100644 --- a/src/components/ai/AssistantContent.tsx +++ b/src/components/ai/AssistantContent.tsx @@ -37,9 +37,9 @@ export const AssistantContent = memo(({ content }: AssistantContentProps) => { } // Handle direct string results - if (typeof toolResult.output === 'string') { + if (toolResult.output.type === 'text') { return { - result: toolResult.output, + result: toolResult.output.value, isError: false }; } diff --git a/src/hooks/useStreamingChat.ts b/src/hooks/useStreamingChat.ts index 41848902..3829bd83 100644 --- a/src/hooks/useStreamingChat.ts +++ b/src/hooks/useStreamingChat.ts @@ -340,21 +340,28 @@ export function useStreamingChat({ // Add tool result to current message if (currentAssistantMessageId) { updateMessage(currentAssistantMessageId, (prev) => { - const currentContent = prev.content; - const content: Array = Array.isArray(currentContent) ? - currentContent.filter((part): part is TextPart | ToolCallPart | ToolResultPart => - part.type === 'text' || part.type === 'tool-call' || part.type === 'tool-result' - ) : - typeof currentContent === 'string' && currentContent ? [{ type: 'text' as const, text: currentContent }] : []; + if (prev.role === 'assistant') { + let content = prev.content; - content.push({ - type: 'tool-result' as const, - toolCallId: chunk.toolCallId, - toolName: chunk.toolName, - output: chunk.output - }); + if (typeof content === 'string') { + content = [{ type: 'text', text: content }]; + } - return { content }; + content.push({ + type: 'tool-result', + toolCallId: chunk.toolCallId, + toolName: chunk.toolName, + output: { + type: 'text', + value: String(chunk.output), + }, + }); + + return { content }; + } else { + console.warn(`Streaming message should be an assistant message. Was a ${prev.role} message.`) + return prev; + } }); } break;