Components.AI: Parse streamed text incrementally
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Problem
`TextBlockHandler.Handle` appends each streamed text update and calls `RebuildParagraphs`, which rescans all accumulated `RawText` and replaces the full paragraph collection for every update. Long responses perform repeated work and allocations as the response grows.
### Proposed fix
Maintain incremental paragraph parsing state and update only the trailing paragraph affected by each streamed chunk. Preserve the current blank-line and chunk-boundary behavior, and add focused tests for paragraph separators split across updates.
Contributes to #68227.
Contributor guide
Research direction
Locate TextBlockHandler.Handle and RebuildParagraphs, then trace how streamed updates build RawText and replace the paragraph collection. Preserve blank-line and chunk-boundary behavior while maintaining incremental parsing state for only the trailing paragraph. Add focused tests covering paragraph separators split across updates and verify long streamed responses avoid rescanning all accumulated text.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- ai
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100