fix(desktop): render already-glued reasoning as separate blocks
Repairs what is already in the transcript: reasoning persisted before the backend fix, and any provider still gluing its parts. Handles both shapes — heading-onto-heading (the **** run) and prose-onto-heading (vercel/ai#6742). Verified against 46 real glued messages from a gpt-5.6-sol session; all repair cleanly and idempotently.
This commit is contained in:
@@ -16,6 +16,7 @@ import { GeneratedImage } from '@/components/chat/generated-image-result'
|
||||
import { SCAFFOLD_LABEL_CLASS, SCAFFOLD_META_CLASS, ScaffoldRow } from '@/components/chat/scaffold-row'
|
||||
import { useI18n } from '@/i18n'
|
||||
import { generatedImageFromResult } from '@/lib/generated-images'
|
||||
import { separateGluedReasoningBlocks } from '@/lib/reasoning-blocks'
|
||||
import { useEnterAnimation } from '@/lib/use-enter-animation'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
@@ -249,7 +250,7 @@ const ReasoningTextPart: ReasoningMessagePartComponent = () => {
|
||||
containerProps={{ 'data-slot': 'aui_reasoning-text' } as ComponentProps<'div'>}
|
||||
disableArtifacts
|
||||
isRunning={status.type === 'running' || messageRunning}
|
||||
text={text.trimStart()}
|
||||
text={separateGluedReasoningBlocks(text.trimStart())}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { separateGluedReasoningBlocks } from '@/lib/reasoning-blocks'
|
||||
|
||||
describe('separateGluedReasoningBlocks', () => {
|
||||
it('splits heading-onto-heading parts (the `****` run)', () => {
|
||||
const glued =
|
||||
'**Investigating likely culprit PRs****Inspecting message schema****Analyzing interrupted tool call impact**'
|
||||
|
||||
expect(separateGluedReasoningBlocks(glued)).toBe(
|
||||
[
|
||||
'**Investigating likely culprit PRs**',
|
||||
'',
|
||||
'**Inspecting message schema**',
|
||||
'',
|
||||
'**Analyzing interrupted tool call impact**'
|
||||
].join('\n')
|
||||
)
|
||||
})
|
||||
|
||||
it('splits prose-onto-heading parts (vercel/ai#6742 repro)', () => {
|
||||
const glued =
|
||||
'**Simulating a greeting stream**\n\nIt feels like a streaming interaction!**Simulating a greeting stream**\n\nI want to meet the request.'
|
||||
|
||||
expect(separateGluedReasoningBlocks(glued)).toContain('interaction!\n\n**Simulating')
|
||||
expect(separateGluedReasoningBlocks(glued)).not.toContain('interaction!**')
|
||||
})
|
||||
|
||||
it('is idempotent on already-separated text', () => {
|
||||
const separated = '**One**\n\n**Two**'
|
||||
|
||||
expect(separateGluedReasoningBlocks(separated)).toBe(separated)
|
||||
})
|
||||
|
||||
it('leaves emphasis inside prose alone', () => {
|
||||
const prose = 'Looking at the logs, the **signature** field is missing — so the replay 400s.'
|
||||
|
||||
expect(separateGluedReasoningBlocks(prose)).toBe(prose)
|
||||
})
|
||||
|
||||
it('leaves an unclosed emphasis run alone', () => {
|
||||
expect(separateGluedReasoningBlocks('weighing options **')).toBe('weighing options **')
|
||||
})
|
||||
|
||||
it('does not split a heading that already opens the text', () => {
|
||||
expect(separateGluedReasoningBlocks('**Only one part**')).toBe('**Only one part**')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Reasoning-summary models (OpenAI's gpt-5.x family, and anything relaying the
|
||||
* Responses API onto the OpenAI chat wire) emit one delta per *completed*
|
||||
* summary part, each opening with a bold markdown heading:
|
||||
*
|
||||
* **Investigating likely culprit PRs**
|
||||
* **Inspecting message schema**
|
||||
*
|
||||
* The Responses API delimits those parts with `summary_index`; the chat wire
|
||||
* carries no such field, so concatenated deltas glue into
|
||||
* `...PRs****Inspecting...` — a `****` run markdown reads as neither a bold
|
||||
* close nor a bold open, leaving one unbroken, unspaced, half-bold paragraph.
|
||||
* The AI SDK hit the same bug (vercel/ai#6742).
|
||||
*
|
||||
* The backend now inserts the break as the deltas arrive. This repairs the text
|
||||
* we display: reasoning persisted before that fix, and any provider still
|
||||
* gluing its parts. Idempotent — a break already present is left alone.
|
||||
*/
|
||||
|
||||
// A heading butting straight onto the previous part, in the two shapes the
|
||||
// wire produces:
|
||||
// 1. heading-onto-heading — `**One****Two**`, a bare `****` run.
|
||||
// 2. prose-onto-heading — `interaction!**Two**`.
|
||||
// Emphasis that legitimately follows whitespace is left alone, and a heading
|
||||
// must close on its own line to count as a summary part.
|
||||
const GLUED_HEADING_RUN = /(?<!\*)\*{4}(?!\*)/g
|
||||
const GLUED_AFTER_PROSE = /(?<=[^\s*])(\*\*(?=[^\s*])[^\n]*?\*\*)/g
|
||||
|
||||
export function separateGluedReasoningBlocks(text: string): string {
|
||||
return text.replace(GLUED_HEADING_RUN, '**\n\n**').replace(GLUED_AFTER_PROSE, '\n\n$1')
|
||||
}
|
||||
Reference in New Issue
Block a user