fix: adapt AI assistant streaming answer parsing#319
Conversation
🦋 Changeset detectedLatest commit: 458c684 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
WalkthroughSwitched the assistant streaming endpoint and replaced ad-hoc byte decoding with buffered SSE parsing that extracts incremental text deltas, updates UI only when deltas arrive, and performs a final flush; parsing utilities and content-extraction logic for Changes
Sequence DiagramsequenceDiagram
participant Client as Client
participant Endpoint as /smart_answer_with_search
participant Stream as Streaming Response
participant Parser as SSE Buffer Parser
participant Delta as Delta Extractor
participant Content as Content Parser
participant UI as UI Updater
Client->>Endpoint: Request streaming answer
Endpoint->>Stream: Return streaming response
loop while stream active
Stream->>Parser: Receive chunk bytes
Parser->>Parser: Append to buffer
Parser->>Parser: consumeSSEEvents(buffer)
Parser->>Delta: Emit SSE events (event,data)
loop for each SSE event
Delta->>Delta: getAnswerDelta(event)
Delta->>UI: Incrementally update text
end
end
Stream->>Parser: Stream ends
Parser->>Parser: Decode remainder
Parser->>Delta: Final consumeSSEEvents(remainder)
Delta->>Content: Provide full accumulated text
Content->>Content: parseStreamContent(text) (extract <docs>, <think>)
Content->>UI: Final UI update + flushMessages
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #319 +/- ##
==========================================
+ Coverage 51.70% 53.27% +1.57%
==========================================
Files 60 61 +1
Lines 1439 1526 +87
Branches 454 484 +30
==========================================
+ Hits 744 813 +69
- Misses 537 547 +10
- Partials 158 166 +8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: JounQin <admin@1stg.me>
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
.gitignore (1)
19-32: Consider simplifying redundant file/directory pairs.In
.gitignore, a pattern like.codexmatches both files and directories, making.codex/redundant. You could simplify lines 19-32 to:-# Local AI code agent configs -.codex -.codex/ -.claude -.claude/ -.continue -.continue/ -.cursor -.cursor/ -.gemini -.gemini/ -.roo -.roo/ -.windsurf -.windsurf/ +# Local AI code agent configs +.codex +.claude +.continue +.cursor +.gemini +.roo +.windsurf .aider*That said, some teams prefer the explicit file/directory pairs for readability, so this is purely a style choice.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.gitignore around lines 19 - 32, The .gitignore contains redundant pairs like ".codex" and ".codex/" (same for ".claude", ".continue", ".cursor", ".gemini", ".roo", ".windsurf"); simplify by keeping only the single pattern (either the file form or the trailing-slash form) for each entry so one pattern covers both file and directory matches—update the listed symbols (.codex, .claude, .continue, .cursor, .gemini, .roo, .windsurf) to remove the duplicate counterparts.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.gitignore:
- Around line 17-33: The PR description and title claim changes for "streaming
answer parsing", "SSE event buffer", and "XML-like tags for docs", but the diff
only shows additions to .gitignore (entries like .codex, .claude, .continue,
.cursor, .gemini, .roo, .windsurf, .aider*), so reconcile the mismatch by either
(A) updating the PR title/body to accurately state that this change only adds AI
tool ignore patterns to .gitignore, or (B) add the missing implementation files
for streaming parsing, SSE buffering, and XML-like doc tags to the branch/PR so
reviewers can inspect them; ensure any added files reference the related
functions/classes (e.g., the streaming parser, SSE buffer handler, or XML tag
processor names) and update the PR summary to list those files.
In `@packages/doom/src/global/Intelligence/AIAssistant/index.tsx`:
- Around line 209-211: The current early return when (!updated) leaves the UI
stuck showing <Thinking /> if the stream produced only ignored/unrecognized
events; replace the silent return with throwing an error (e.g. throw new
Error('Stream produced no valid events')) so the existing catch path can render
the network-error fallback. Locate the check using the updated and text
variables inside the AIAssistant component (the block with "if (!updated) {
return }") and change it to throw an Error to trigger the catch branch that
displays the fallback UI.
---
Nitpick comments:
In @.gitignore:
- Around line 19-32: The .gitignore contains redundant pairs like ".codex" and
".codex/" (same for ".claude", ".continue", ".cursor", ".gemini", ".roo",
".windsurf"); simplify by keeping only the single pattern (either the file form
or the trailing-slash form) for each entry so one pattern covers both file and
directory matches—update the listed symbols (.codex, .claude, .continue,
.cursor, .gemini, .roo, .windsurf) to remove the duplicate counterparts.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 70910fe9-e06a-4dd4-b250-c742518cb62c
📒 Files selected for processing (4)
.gitignorepackages/doom/src/global/Intelligence/AIAssistant/index.tsxpackages/doom/src/global/Intelligence/AIAssistant/utils.tspackages/doom/test/global/Intelligence/AIAssistant/utils.spec.ts
Co-authored-by: JounQin <admin@1stg.me>
Summary by CodeRabbit
New Features
Tests
Chores