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
This commit is contained in:
Glen Maddern 2025-06-25 12:05:00 +10:00
commit 12dc6433c3

View file

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