From 12dc6433c33efa32ea193371dcddacd129a8e43d Mon Sep 17 00:00:00 2001 From: Glen Maddern Date: Wed, 25 Jun 2025 12:05:00 +1000 Subject: [PATCH] Enhance debug logging to show complete conversation state - Show entire messages array after each new message addition - Include message index, role, content/reasoning status, and tool info - Add final conversation state with content/reasoning lengths - Provides complete visibility into data structure evolution --- .../chat-ui/src/hooks/useStreamResponse.ts | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/examples/chat-ui/src/hooks/useStreamResponse.ts b/examples/chat-ui/src/hooks/useStreamResponse.ts index bf4af23..ac8d423 100644 --- a/examples/chat-ui/src/hooks/useStreamResponse.ts +++ b/examples/chat-ui/src/hooks/useStreamResponse.ts @@ -185,6 +185,14 @@ export const useStreamResponse = ({ }) assistantMessageIndex = conv.messages.length - 1 debugMessages('Added new reasoning assistant message at index', assistantMessageIndex) + debugMessages('Current messages:', conv.messages.map((msg, i) => ({ + index: i, + role: msg.role, + hasContent: 'content' in msg && !!msg.content, + hasReasoning: 'reasoning' in msg && !!msg.reasoning, + isStreaming: 'isReasoningStreaming' in msg ? msg.isReasoningStreaming : false, + toolName: 'toolName' in msg ? msg.toolName : undefined + }))) } return updated }) @@ -252,6 +260,14 @@ export const useStreamResponse = ({ callId: event.toolCallId || 'unknown', }) debugMessages('Added new tool-call message:', event.toolName, 'callId:', event.toolCallId) + debugMessages('Current messages:', conv.messages.map((msg, i) => ({ + index: i, + role: msg.role, + hasContent: 'content' in msg && !!msg.content, + hasReasoning: 'reasoning' in msg && !!msg.reasoning, + isStreaming: 'isReasoningStreaming' in msg ? msg.isReasoningStreaming : false, + toolName: 'toolName' in msg ? msg.toolName : undefined + }))) } } return updated @@ -281,6 +297,14 @@ export const useStreamResponse = ({ callId: (event as any).toolCallId, }) debugMessages('Added new tool-result message:', (event as any).toolName, 'callId:', (event as any).toolCallId) + debugMessages('Current messages:', conv.messages.map((msg, i) => ({ + index: i, + role: msg.role, + hasContent: 'content' in msg && !!msg.content, + hasReasoning: 'reasoning' in msg && !!msg.reasoning, + isStreaming: 'isReasoningStreaming' in msg ? msg.isReasoningStreaming : false, + toolName: 'toolName' in msg ? msg.toolName : undefined + }))) } else { } } @@ -328,6 +352,14 @@ export const useStreamResponse = ({ conv.messages.push({ role: 'assistant', content: '' }) assistantMessageIndex = conv.messages.length - 1 debugMessages('Added new content assistant message at index', assistantMessageIndex, '(after reasoning:', needsNewAssistantMessage, ')') + debugMessages('Current messages:', conv.messages.map((msg, i) => ({ + index: i, + role: msg.role, + hasContent: 'content' in msg && !!msg.content, + hasReasoning: 'reasoning' in msg && !!msg.reasoning, + isStreaming: 'isReasoningStreaming' in msg ? msg.isReasoningStreaming : false, + toolName: 'toolName' in msg ? msg.toolName : undefined + }))) } return updated }) @@ -391,6 +423,24 @@ export const useStreamResponse = ({ debugMessages('Stream processing completed. Final message count:', assistantMessageCreated ? 'created' : 'none') + // Show final conversation state + setConversations((prev) => { + const conv = prev.find((c) => c.id === conversationId) + if (conv) { + debugMessages('Final conversation state:', conv.messages.map((msg, i) => ({ + index: i, + role: msg.role, + hasContent: 'content' in msg && !!msg.content, + hasReasoning: 'reasoning' in msg && !!msg.reasoning, + isStreaming: 'isReasoningStreaming' in msg ? msg.isReasoningStreaming : false, + toolName: 'toolName' in msg ? msg.toolName : undefined, + contentLength: 'content' in msg ? msg.content?.length || 0 : 0, + reasoningLength: 'reasoning' in msg ? msg.reasoning?.length || 0 : 0 + }))) + } + return prev + }) + // Final cleanup - ensure reasoning streaming is stopped if (assistantMessageCreated && currentReasoningStartTime) { if (!currentReasoningEndTime) {