Skip to content

fix: adapt AI assistant streaming answer parsing#319

Merged
JounQin merged 2 commits intomainfrom
fix/assistant-streaming-compat
Apr 21, 2026
Merged

fix: adapt AI assistant streaming answer parsing#319
JounQin merged 2 commits intomainfrom
fix/assistant-streaming-compat

Conversation

@yangxiaolang
Copy link
Copy Markdown
Contributor

@yangxiaolang yangxiaolang commented Apr 21, 2026

Summary by CodeRabbit

  • New Features

    • AI Assistant now streams responses via a search-enabled endpoint and delivers more reliable incremental updates, with improved extraction of documentation and thinking sections.
  • Tests

    • Added tests covering streaming parsing and incremental delta handling.
  • Chores

    • Updated .gitignore to exclude local AI agent configuration files/directories.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 21, 2026

🦋 Changeset detected

Latest commit: 458c684

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@alauda/doom Patch

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: acd3f983-dbb6-4c2e-a67e-a6b375540985

📥 Commits

Reviewing files that changed from the base of the PR and between 293b1b5 and 458c684.

📒 Files selected for processing (1)
  • .changeset/many-guests-shake.md
✅ Files skipped from review due to trivial changes (1)
  • .changeset/many-guests-shake.md

Walkthrough

Switched 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 <docs>/<think> were added/refactored and covered by new tests.

Changes

Cohort / File(s) Summary
Configuration
/.gitignore
Added patterns to ignore local AI agent config files/directories (e.g., .codex, .claude, .continue, .cursor, .gemini, .roo, .windsurf, .aider*).
Streaming entrypoint & flow
packages/doom/src/global/Intelligence/AIAssistant/index.tsx
Switched streaming endpoint to /smart/api/smart_answer_with_search; replaced global TextDecoder caching with per-request decoder; implemented buffered SSE consumption using consumeSSEEvents, applied incremental deltas via getAnswerDelta, and added an explicit final flush/parse when the stream ends.
SSE & content parsing utilities
packages/doom/src/global/Intelligence/AIAssistant/utils.ts
Added SSEEvent/SSEConsumeResult, consumeSSEEvents(buffer, event?), and getAnswerDelta(...); refactored parseStreamContent to use matchAll for <docs>/<think> extraction, support unterminated trailing tags, remove doc/think segments from final content, and improve unicode decoding handling.
Tests
packages/doom/test/global/Intelligence/AIAssistant/utils.spec.ts
New tests covering consumeSSEEvents, getAnswerDelta, and parseStreamContent, including edge cases: multi-line data, trailing remainder, ignored metadata events, incomplete docs/think sections, and extraction of refDocs/thinkingProcess.
Release changelog
.changeset/many-guests-shake.md
Added a changeset (patch) noting the fix to AI assistant streaming answer parsing.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested labels

bug

Poem

🐰 I buffered the stream and chased every byte,
events stitched together through tunnelled light,
docs tucked away, thoughts kept in a line,
deltas arrive — the answer grows fine. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: adapt AI assistant streaming answer parsing' directly reflects the main change: refactoring the streaming request endpoint and SSE parsing logic in the AIAssistant component.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/assistant-streaming-compat

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 21, 2026

Open in StackBlitz

yarn add https://pkg.pr.new/@alauda/doom@319.tgz
yarn add https://pkg.pr.new/@alauda/doom-export@319.tgz

commit: 458c684

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

❌ Patch coverage is 78.66667% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.27%. Comparing base (7bfb086) to head (458c684).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
.../doom/src/global/Intelligence/AIAssistant/utils.ts 78.66% 9 Missing and 7 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: JounQin <admin@1stg.me>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
.gitignore (1)

19-32: Consider simplifying redundant file/directory pairs.

In .gitignore, a pattern like .codex matches 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7bfb086 and 293b1b5.

📒 Files selected for processing (4)
  • .gitignore
  • packages/doom/src/global/Intelligence/AIAssistant/index.tsx
  • packages/doom/src/global/Intelligence/AIAssistant/utils.ts
  • packages/doom/test/global/Intelligence/AIAssistant/utils.spec.ts

Comment thread .gitignore
Comment thread packages/doom/src/global/Intelligence/AIAssistant/index.tsx
@JounQin JounQin merged commit c99c3ad into main Apr 21, 2026
17 checks passed
@JounQin JounQin deleted the fix/assistant-streaming-compat branch April 21, 2026 10:35
github-actions Bot pushed a commit that referenced this pull request Apr 21, 2026
Co-authored-by: JounQin <admin@1stg.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants