-
Notifications
You must be signed in to change notification settings - Fork 118
perf(components): use Streamdown static mode for finished markdown #494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
slashdevcorpse
wants to merge
6
commits into
LodyAI:main
Choose a base branch
from
slashdevcorpse:perf/streamdown-static-mode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9eb1607
perf(components): use Streamdown static mode for finished markdown
slashdevcorpse 2c1bc7e
docs(components): align Streamdown mode contract with finished static
slashdevcorpse 7e561eb
fix(components): keep Streamdown remend on unclosed fences
slashdevcorpse a2da324
docs(components): note Streamdown streaming for open fences
slashdevcorpse d98de52
fix(components): detect CommonMark open fences for Streamdown mode
slashdevcorpse 59dcfd3
fix(components): reuse container fence scan for Streamdown mode
slashdevcorpse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/components/src/components/ai-gui/markdown-streamdown-mode.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { markdownHasUnclosedFence } from '@/lib/markdown-single-dollar-math'; | ||
|
|
||
| export { markdownHasUnclosedFence }; | ||
|
|
||
| export function resolveMarkdownStreamdownMode( | ||
| isStreaming: boolean, | ||
| text = '' | ||
| ): 'static' | 'streaming' { | ||
| if (isStreaming || markdownHasUnclosedFence(text)) return 'streaming'; | ||
| return 'static'; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/components/tests/markdown-streamdown-mode.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { resolveMarkdownStreamdownMode } from '../src/components/ai-gui/markdown-streamdown-mode'; | ||
|
|
||
| describe('resolveMarkdownStreamdownMode', () => { | ||
| it('uses static mode for finished complete markdown', () => { | ||
| expect(resolveMarkdownStreamdownMode(false, 'Hello **world**.')).toBe('static'); | ||
| }); | ||
|
|
||
| it('uses streaming mode while a turn is still growing', () => { | ||
| expect(resolveMarkdownStreamdownMode(true, 'Hello **wor')).toBe('streaming'); | ||
| }); | ||
|
|
||
| it('keeps streaming mode for a finished turn with an unclosed fence', () => { | ||
| expect(resolveMarkdownStreamdownMode(false, '```ts\nconst x = 1;\n')).toBe('streaming'); | ||
| }); | ||
|
|
||
| it('keeps streaming mode for an unclosed indented backtick fence', () => { | ||
| expect(resolveMarkdownStreamdownMode(false, '1. example:\n ```ts\n const x = 1;\n')).toBe( | ||
| 'streaming' | ||
| ); | ||
| }); | ||
|
|
||
| it('keeps streaming mode for an unclosed tilde fence', () => { | ||
| expect(resolveMarkdownStreamdownMode(false, '~~~js\nconst x = 1;\n')).toBe('streaming'); | ||
| }); | ||
|
|
||
| it('uses static mode when an indented fence is closed', () => { | ||
| expect( | ||
| resolveMarkdownStreamdownMode(false, '1. example:\n ```ts\n const x = 1;\n ```\n') | ||
| ).toBe('static'); | ||
| }); | ||
|
|
||
| it('does not treat a 4-space indent as a fence', () => { | ||
| expect(resolveMarkdownStreamdownMode(false, ' ```ts\n const x = 1;\n')).toBe('static'); | ||
| }); | ||
|
|
||
| it('keeps streaming mode when a shorter closer cannot end a longer fence', () => { | ||
| expect(resolveMarkdownStreamdownMode(false, '````ts\nconst x = 1;\n```\n')).toBe('streaming'); | ||
| }); | ||
|
|
||
| it('keeps streaming mode for an unclosed blockquote fence', () => { | ||
| expect(resolveMarkdownStreamdownMode(false, '> ```tex\n> \\(x\\)\n')).toBe('streaming'); | ||
| }); | ||
|
|
||
| it('keeps streaming mode for an unclosed ordered-list fence', () => { | ||
| expect(resolveMarkdownStreamdownMode(false, '10. ```tex\n \\(x\\)\n')).toBe('streaming'); | ||
| }); | ||
|
|
||
| it('uses static mode when a nested list fence is closed', () => { | ||
| expect(resolveMarkdownStreamdownMode(false, '- ~~~tex\n \\[x\\]\n ~~~\n')).toBe('static'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a cancelled response opens a fence on a continuation line of an existing list, such as
1. explanation\n ```ts\nconst x = 1,markdownFenceAtsees four leading spaces without knowing they include the list-item indent and returns no fence. This makes the new resolver choose static mode and skip incomplete-Markdown repair even though the fence remains open. This is fresh evidence beyond the prior container-prefix comment: direct-marker forms are now handled, but ordinary continuation-line forms are still missed. Preserve list-container state while scanning.AGENTS.md reference: packages/components/src/components/ai-gui/AGENTS.md:L96-L96
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving this. Open-fence detection now uses the same per-line CommonMark scanner as
normalizeTexMathDelimiters. Same-line list/blockquote markers (10. ```tex,> ```tex) and 0–3 space continuation fences already stay on Streamdownstreaming. A 4-space continuation after1. explanationis an indented code block at document scope unless we carry list indent across lines. That is a full list parser, not this #421 slice. Interrupted mid-list continuation fences are an accepted freeze-path edge case (.github/codex-review.md).