debug: Add more detailed logging for reasoning event handling

- Add debug logs inside reasoning event handler to see if it's being triggered
- Log reasoning content length as it's being collected
- Add final reasoning content summary at end of stream
- Log why reasoning isn't being added if conditions aren't met
- Cast event to any to avoid potential TypeScript issues

This will help identify why reasoning events aren't being captured
despite appearing in the event stream logs.
This commit is contained in:
Glen Maddern 2025-06-24 18:11:24 +10:00
commit 33c914e19b

View file

@ -200,7 +200,8 @@ export const useStreamResponse = ({
if (event.type === 'reasoning') {
debugLog(`[useStreamResponse] Reasoning event:`, event)
reasoning += event.textDelta || ''
reasoning += (event as any).textDelta || ''
debugLog(`[useStreamResponse] Reasoning content so far:`, reasoning.length, 'chars')
} else if (event.type === 'tool-call') {
const eventKey = `tool-call-${event.toolCallId}`
if (processedEvents.has(eventKey)) {
@ -317,6 +318,7 @@ export const useStreamResponse = ({
debugLog(`[useStreamResponse] Finished processing full stream. Final response length: ${aiResponse.length}`)
debugLog(`[useStreamResponse] Final aiResponse content:`, JSON.stringify(aiResponse))
debugLog(`[useStreamResponse] Final reasoning content:`, reasoning.length, 'chars:', reasoning.substring(0, 100))
// Add reasoning to the final message if we collected any
if (reasoning && assistantMessageCreated) {
@ -333,6 +335,8 @@ export const useStreamResponse = ({
}
return updated
})
} else {
debugLog(`[useStreamResponse] No reasoning to add. reasoning length:`, reasoning.length, 'assistantMessageCreated:', assistantMessageCreated)
}
} catch (error: unknown) {
if (controller.signal.aborted) {