-
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
9eb1607
2c1bc7e
7e561eb
a2da324
d98de52
59dcfd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| export function markdownHasUnclosedFence(text: string): boolean { | ||
| let open = false; | ||
| for (const line of text.split('\n')) { | ||
| if (line.startsWith('```')) open = !open; | ||
| } | ||
| return open; | ||
| } | ||
|
|
||
| export function resolveMarkdownStreamdownMode( | ||
| isStreaming: boolean, | ||
| text = '' | ||
| ): 'static' | 'streaming' { | ||
| if (isStreaming || markdownHasUnclosedFence(text)) return 'streaming'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 AGENTS.md reference: packages/components/src/components/ai-gui/AGENTS.md:L96-L96 Useful? React with 👍 / 👎.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| return 'static'; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| 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'); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.