A React Native app for the ultimate thinking partner.

fix(streaming): handle error and stop_reason chunks gracefully

- Add error chunk handling to prevent stream crashes
- Handle stop_reason chunks to properly mark stream completion
- Clean up streaming state when errors occur

This prevents the app from crashing when the server sends error chunks during streaming.

+18
+18
App.tsx
··· 480 480 const handleStreamingChunk = useCallback((chunk: StreamingChunk) => { 481 481 console.log('Streaming chunk:', chunk.message_type, 'content:', chunk.content, 'reasoning:', chunk.reasoning); 482 482 483 + // Handle error chunks 484 + if ((chunk as any).error) { 485 + console.error('Error chunk received:', (chunk as any).error); 486 + setIsStreaming(false); 487 + setIsSendingMessage(false); 488 + setStreamingMessage(''); 489 + setStreamingReasoning(''); 490 + setIsReasoningStreaming(false); 491 + return; 492 + } 493 + 494 + // Handle stop_reason chunks 495 + if (chunk.message_type === 'stop_reason') { 496 + console.log('Stop reason received:', (chunk as any).stopReason || (chunk as any).stop_reason); 497 + streamCompleteRef.current = true; 498 + return; 499 + } 500 + 483 501 // Capture message ID if present 484 502 if (chunk.id && !streamingMessageId) { 485 503 setStreamingMessageId(chunk.id);