Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/ui/src/components/markdown-stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ describe("markdown stream", () => {
])
})

test("heals incomplete backticks in trailing code fence tail", () => {
expect(stream("summary\n\n```sh\nrm -rf `", true)).toEqual([
{ raw: "summary\n\n", src: "summary\n\n", mode: "live" },
{ raw: "```sh\nrm -rf `", src: "```sh\nrm -rf ``", mode: "live" },
])
})

test("handles backtick-heavy content that ends without trailing newline", () => {
const input = "run `git status` and `git"
const result = stream(input, true)
expect(result[0].raw).toBe(input)
expect(result[0].src).toContain("git status")
})

test("keeps reference-style markdown as one block", () => {
expect(stream("[docs][1]\n\n[1]: https://example.com", true)).toEqual([
{
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/markdown-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ export function stream(text: string, live: boolean) {
if (!head) return [{ raw: code.raw, src: code.raw, mode: "live" }] satisfies Block[]
return [
{ raw: head, src: heal(head), mode: "live" },
{ raw: code.raw, src: code.raw, mode: "live" },
{ raw: code.raw, src: heal(code.raw), mode: "live" },
] satisfies Block[]
}
2 changes: 1 addition & 1 deletion packages/ui/src/components/message-part.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export type PartComponent = Component<MessagePartProps>
export const PART_MAPPING: Record<string, PartComponent | undefined> = {}

const TEXT_RENDER_PACE_MS = 24
const TEXT_RENDER_SNAP = /[\s.,!?;:)\]]/
const TEXT_RENDER_SNAP = /[\s.,!?;:)\]\`]/

function step(size: number) {
if (size <= 12) return 2
Expand Down
Loading