Skip to content

refactor(ai-assistant): use smart doc sse parser#323

Open
yangxiaolang wants to merge 4 commits intomainfrom
refactor/ai-assistant-smart-doc-sse-parser
Open

refactor(ai-assistant): use smart doc sse parser#323
yangxiaolang wants to merge 4 commits intomainfrom
refactor/ai-assistant-smart-doc-sse-parser

Conversation

@yangxiaolang
Copy link
Copy Markdown
Contributor

@yangxiaolang yangxiaolang commented Apr 24, 2026

Summary by CodeRabbit

  • Dependencies

    • Added a SmartDoc SSE parser dependency to improve assistant streaming.
  • Refactor

    • Replaced custom SSE handling with the parser for more reliable incremental assistant updates and structured SmartDoc support.
  • Tests

    • Updated tests to validate the new streaming parser, SmartDoc parsing, and markdown formatting.
  • Style / UI

    • Improved markdown styling and wrapped thinking/assistant content for clearer rendering of thoughts and reference docs.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 24, 2026

⚠️ No Changeset found

Latest commit: ccf8dde

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 24, 2026

Warning

Rate limit exceeded

@yangxiaolang has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 19 minutes and 54 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 03c02a69-7058-4f7a-9788-f5e0278250ce

📥 Commits

Reviewing files that changed from the base of the PR and between 433a78b and ccf8dde.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (5)
  • packages/doom/package.json
  • packages/doom/src/global/Intelligence/AIAssistant/Chat/ChatRefDocs/index.tsx
  • packages/doom/src/global/Intelligence/AIAssistant/Chat/index.tsx
  • packages/doom/src/global/Intelligence/AIAssistant/index.tsx
  • packages/doom/src/global/Intelligence/AIAssistant/types.ts

Walkthrough

Replaces local SmartDoc/SSE parsing and streaming delta logic with an external SmartDoc SSE parser; updates types, components, styles, and tests to consume the parser's structured display messages and new message fields. Also adds the parser dependency to package.json.

Changes

Cohort / File(s) Summary
Dependency
packages/doom/package.json
Adds runtime dependency @yangxiaolang/smart-doc-sse-parser@0.5.2.
Assistant stream handling
packages/doom/src/global/Intelligence/AIAssistant/index.tsx
Removes manual SSE buffering/delta accumulation; wires consumeSmartDocDisplayStream with onDisplayMessage and updates in-flight ChatMessage via a syncAssistantMessage callback.
Parser utilities deleted
packages/doom/src/global/Intelligence/AIAssistant/utils.ts
Removes custom SSE/event consumption, delta extraction, SmartDoc tag parsing helpers, and associated exported types and functions (file deleted/stripped).
Tests updated to new parser
packages/doom/test/global/Intelligence/AIAssistant/utils.spec.ts
Replaces low-level SSE parsing tests with SmartDoc parser tests: incremental data: chunk handling, metadata filtering, <trace> handling, finalization detection, structured message parsing, and markdown formatting expectations.
RefDocs type updates
packages/doom/src/global/Intelligence/AIAssistant/Chat/ChatRefDocs/index.tsx
refDocs prop type changed from local RefDoc to SmartDocDisplayReferenceDoc; rendering uses doc.id, doc.path, doc.content unchanged.
Thinking process rendering
packages/doom/src/global/Intelligence/AIAssistant/Chat/ThinkingProcess/index.tsx
Wraps Markdown output in a styled container with combined chat.module.scss .markdown and global rp-doc classes.
Chat rendering adjustments
packages/doom/src/global/Intelligence/AIAssistant/Chat/index.tsx
Refactors message map to use explicit return; wraps assistant message markdown in a .markdown + rp-doc container; uses thoughtProcess for thinking output.
Types
packages/doom/src/global/Intelligence/AIAssistant/types.ts
Replaces local RefDoc with external SmartDocDisplayReferenceDoc and renames thinkingProcessthoughtProcess on ChatMessage.
Styles
packages/doom/styles/chat.module.scss
Removes narrow h2 reset; adds new .markdown rules targeting :global(.rp-doc) with comprehensive typography, spacing, and heading/list styles.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

enhancement, dependencies

Suggested reviewers

  • JounQin

Poem

🐰 I nibble bytes and parse the stream,
smart docs sparkle like a dream,
old SSE crumbs hop away,
new messages arrive to play,
joyous rabbit — code redeemed! ✨

🚥 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 accurately reflects the main refactoring objective: replacing custom SSE handling logic with the new smart-doc-sse-parser library.
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 refactor/ai-assistant-smart-doc-sse-parser

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 24, 2026

Open in StackBlitz

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

commit: c04b171

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.32%. Comparing base (9463d58) to head (c04b171).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #323      +/-   ##
==========================================
- Coverage   53.20%   52.32%   -0.89%     
==========================================
  Files          61       61              
  Lines        1528     1462      -66     
  Branches      483      462      -21     
==========================================
- Hits          813      765      -48     
+ Misses        548      538      -10     
+ Partials      167      159       -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.

Comment thread packages/doom/src/global/Intelligence/AIAssistant/utils.ts Outdated
Comment thread packages/doom/src/global/Intelligence/AIAssistant/utils.ts Outdated
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 (2)
packages/doom/test/global/Intelligence/AIAssistant/utils.spec.ts (1)

10-86: Consider scoping tests to our own wrapper rather than re-verifying library internals.

The SmartDocSseParser, parseSmartDocMessage, and formatSmartDocMarkdown describe blocks assert library behavior directly (trace-tag replacement, metadata filtering, markdown formatting rules, exact JSON field ordering in snapshots). The library owns these invariants and their tests; mirroring them here couples this test suite to implementation details of @yangxiaolang/smart-doc-sse-parser, so library-internal refactors break tests without a local code change.

Consider trimming these down to:

  • parseStreamContent contract (already covered well at lines 88–114).
  • normalizeRefDocs defaults (partial/missing fields → defaulted shape).
  • Any wrapper-specific edge cases (incomplete tag stripping, fallback to message.result).

If you want a smoke test that the library import is wired correctly, a single expect(typeof SmartDocSseParser).toBe('function') is usually enough.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/doom/test/global/Intelligence/AIAssistant/utils.spec.ts` around
lines 10 - 86, The tests are tightly coupled to
`@yangxiaolang/smart-doc-sse-parser` internals (SmartDocSseParser,
parseSmartDocMessage, formatSmartDocMarkdown) and should be scoped to our
wrapper behavior: replace detailed library-internal assertions (trace-tag
replacement, metadata filtering, exact JSON field ordering) with a simple smoke
check for the import (e.g., expect(typeof SmartDocSseParser) toBe('function'))
and add focused tests for our wrapper contracts — ensure parseStreamContent
behavior, normalizeRefDocs defaults (missing/partial fields produce the
normalized shape), and any wrapper-specific edge cases (incomplete tag
stripping, fallback to message.result) are covered; remove or trim assertions
that re-verify library formatting logic and instead assert only the wrapper’s
transformations and defaults.
packages/doom/src/global/Intelligence/AIAssistant/utils.ts (1)

50-54: Unused thoughtProcess assignment on normalizedMessage.

Only normalizedMessage.refDocs (line 56) and normalizedMessage.result (line 58) are consumed, so spreading ...message and overriding thoughtProcess is dead work. You can simplify and drop the spread.

♻️ Suggested simplification
-export function parseStreamContent(text: string) {
-  const message = parseSmartDocMessage(text)
-  const thinkingProcess = getThinkingProcess(text, message)
-  const result = getDisplayResult(text, message)
-  const normalizedMessage = {
-    ...message,
-    result,
-    thoughtProcess: thinkingProcess ?? '',
-  }
-  return {
-    refDocs: normalizeRefDocs(normalizedMessage.refDocs),
-    thinkingProcess,
-    content: formatSmartDocMarkdown(normalizedMessage.result),
-  }
-}
+export function parseStreamContent(text: string) {
+  const message = parseSmartDocMessage(text)
+  const thinkingProcess = getThinkingProcess(text, message)
+  const result = getDisplayResult(text, message)
+  return {
+    refDocs: normalizeRefDocs(message.refDocs),
+    thinkingProcess,
+    content: formatSmartDocMarkdown(result),
+  }
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/doom/src/global/Intelligence/AIAssistant/utils.ts` around lines 50 -
54, The code unnecessarily spreads the entire message object and overrides the
thoughtProcess property in normalizedMessage, but only refDocs and result
properties are used later. To fix this, replace the spread of message with only
the needed properties refDocs and assign result directly, removing the
thoughtProcess assignment altogether in the normalizedMessage object
construction.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/doom/package.json`:
- Line 63: The dependency "@yangxiaolang/smart-doc-sse-parser" is a
personal-scoped package used by the runtime; mitigate supply-chain risk by
either 1) publishing it under the org scope (e.g., move package and its repo to
`@alauda` and update the dependency ref), 2) vendoring the parser into this
monorepo as an internal workspace package (add it under packages/ and change the
dependency to the local workspace name), or 3) if you cannot move/vendor now,
add a strict lock via package.json "resolutions" (or npm/yarn lockfile policy)
and a security policy note documenting the pinned 0.3.0 usage; update
package.json to reflect whichever approach and ensure build/test scripts
reference the new package name/location (look for the dependency entry
"@yangxiaolang/smart-doc-sse-parser" to change).

In `@packages/doom/src/global/Intelligence/AIAssistant/utils.ts`:
- Around line 29-30: The current greedy fallback regex openThinkMatch =
text.match(/<think>([\s\S]*)$/) can over-capture across closed </think> blocks;
replace it with a defensive global non-greedy extraction using
/<think>([\s\S]*?)(?:<\/think>|$)/g and pick the last match (e.g., via
Array.from(text.matchAll(...)).pop()) so you capture only the content of the
last open <think> without including intervening </think> tags; update the code
that reads openThinkMatch?.[1] accordingly and ensure this runs only when
message.thoughtProcess is empty.

---

Nitpick comments:
In `@packages/doom/src/global/Intelligence/AIAssistant/utils.ts`:
- Around line 50-54: The code unnecessarily spreads the entire message object
and overrides the thoughtProcess property in normalizedMessage, but only refDocs
and result properties are used later. To fix this, replace the spread of message
with only the needed properties refDocs and assign result directly, removing the
thoughtProcess assignment altogether in the normalizedMessage object
construction.

In `@packages/doom/test/global/Intelligence/AIAssistant/utils.spec.ts`:
- Around line 10-86: The tests are tightly coupled to
`@yangxiaolang/smart-doc-sse-parser` internals (SmartDocSseParser,
parseSmartDocMessage, formatSmartDocMarkdown) and should be scoped to our
wrapper behavior: replace detailed library-internal assertions (trace-tag
replacement, metadata filtering, exact JSON field ordering) with a simple smoke
check for the import (e.g., expect(typeof SmartDocSseParser) toBe('function'))
and add focused tests for our wrapper contracts — ensure parseStreamContent
behavior, normalizeRefDocs defaults (missing/partial fields produce the
normalized shape), and any wrapper-specific edge cases (incomplete tag
stripping, fallback to message.result) are covered; remove or trim assertions
that re-verify library formatting logic and instead assert only the wrapper’s
transformations and defaults.
🪄 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: 2b4d9964-1335-48a1-b1b4-4404093652f5

📥 Commits

Reviewing files that changed from the base of the PR and between 9463d58 and c04b171.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (4)
  • packages/doom/package.json
  • 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 packages/doom/package.json Outdated
Comment thread packages/doom/src/global/Intelligence/AIAssistant/utils.ts Outdated
… consumeSmartDocDisplayStream

Replace manual SSE parsing logic with consumeSmartDocDisplayStream API
from the library. Remove local utils.ts wrapper, rename thinkingProcess
to thoughtProcess, use SmartDocDisplayReferenceDoc type, and add
markdown content styling.
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.

🧹 Nitpick comments (1)
packages/doom/src/global/Intelligence/AIAssistant/index.tsx (1)

142-161: Minor: thoughtProcess parameter typing.

nextMessage.thoughtProcess is declared string, but ChatMessage.thoughtProcess is string | null and the body uses nextMessage.thoughtProcess || undefined — suggesting the parser may emit null/empty. Consider widening to string | null (or inferring directly from the parser's display-message type) for consistency with the underlying field.

Suggested tweak
     const syncAssistantMessage = (nextMessage: {
       content: string
-      thoughtProcess: string
+      thoughtProcess: string | null
       refDocs: ChatMessage['refDocs']
     }) => {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/doom/src/global/Intelligence/AIAssistant/index.tsx` around lines 142
- 161, The parameter typing for syncAssistantMessage's nextMessage currently
declares thoughtProcess as string but the underlying ChatMessage.thoughtProcess
is string | null and the code uses nextMessage.thoughtProcess || undefined;
update the type of nextMessage.thoughtProcess to string | null (or use the
parser/display-message type that already defines thoughtProcess) so the
signature matches ChatMessage and avoids inconsistent null/undefined handling in
syncAssistantMessage and the flushMessages update.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/doom/src/global/Intelligence/AIAssistant/index.tsx`:
- Around line 142-161: The parameter typing for syncAssistantMessage's
nextMessage currently declares thoughtProcess as string but the underlying
ChatMessage.thoughtProcess is string | null and the code uses
nextMessage.thoughtProcess || undefined; update the type of
nextMessage.thoughtProcess to string | null (or use the parser/display-message
type that already defines thoughtProcess) so the signature matches ChatMessage
and avoids inconsistent null/undefined handling in syncAssistantMessage and the
flushMessages update.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cdf241d5-50fb-4e17-8ea3-d89c822ee46b

📥 Commits

Reviewing files that changed from the base of the PR and between c04b171 and 433a78b.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (8)
  • packages/doom/package.json
  • packages/doom/src/global/Intelligence/AIAssistant/Chat/ChatRefDocs/index.tsx
  • packages/doom/src/global/Intelligence/AIAssistant/Chat/ThinkingProcess/index.tsx
  • packages/doom/src/global/Intelligence/AIAssistant/Chat/index.tsx
  • packages/doom/src/global/Intelligence/AIAssistant/index.tsx
  • packages/doom/src/global/Intelligence/AIAssistant/types.ts
  • packages/doom/src/global/Intelligence/AIAssistant/utils.ts
  • packages/doom/styles/chat.module.scss
💤 Files with no reviewable changes (1)
  • packages/doom/src/global/Intelligence/AIAssistant/utils.ts
✅ Files skipped from review due to trivial changes (2)
  • packages/doom/package.json
  • packages/doom/src/global/Intelligence/AIAssistant/Chat/ChatRefDocs/index.tsx

Comment thread packages/doom/src/global/Intelligence/AIAssistant/index.tsx Outdated
Comment thread packages/doom/src/global/Intelligence/AIAssistant/Chat/index.tsx Outdated
border-bottom: 0;
}

p {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

这些 CSS 有必要覆盖吗?跟主站点就不一致了。这个是什么考虑?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

这块是想让 AIAssistant 这边的 md 整体紧凑一点

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

可以让产品和设计确认下吧

parseSmartDocMessage,
parseStreamContent,
SmartDocSseParser,
} from '#global/Intelligence/AIAssistant/utils.ts'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

这个 test 应该不需要了吧,现在 CI 是挂的

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