Handle a text chunk from the AI. Appends to the last Text flow item if it exists, otherwise creates a new one. This ensures text and tool blocks remain interleaved in chronological order.
(&mut self, text: &str)
| 421 | /// Appends to the last Text flow item if it exists, otherwise creates a new one. |
| 422 | /// This ensures text and tool blocks remain interleaved in chronological order. |
| 423 | pub fn handle_text_chunk(&mut self, text: &str) { |
| 424 | // Try to append to the last flow item if it's a Text block |
| 425 | if let Some(FlowItem::Text { content, .. }) = self.current_flow_items.last_mut() { |
| 426 | content.push_str(text); |
| 427 | } else { |
| 428 | // Last item is not Text (it's a Tool, Thinking, or empty) — create a new Text block |
| 429 | self.current_flow_items.push(FlowItem::Text { |
| 430 | content: text.to_string(), |
| 431 | is_streaming: true, |
| 432 | }); |
| 433 | } |
| 434 | self.rebuild_streaming_message(); |
| 435 | } |
| 436 | |
| 437 | /// Handle a thinking/reasoning chunk from the AI. |
| 438 | /// Thinking blocks typically appear at the start, before text/tool content. |
no test coverage detected