GeezerVison is showing github.com — fix(web): reasoning previews no longer cut emojis in half (#42755) · patroza/t3code@f99eceb
File treeExpand file treeCollapse file tree Open diff view settings apps/web/src/components/chat
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/MessagesTimeline.browser.test.tsx +27-1Lines changed: 27 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -43,7 +43,11 @@ import { | 43 | 43 | deriveTimelineEntriesFromVisibleTurnItems, | 44 | 44 | } from "../../session-logic"; | 45 | 45 | import { ViewedImagesTimelineRow } from "./TimelineWorkEntryRow"; | 46 | | -import { THOUGHT_PREVIEW_MAX_LENGTH, thoughtPreviewMarkdown } from "./TimelineWorkEntryRow.logic"; | | 46 | +import { | | 47 | + THOUGHT_PREVIEW_MAX_LENGTH, | | 48 | + THOUGHT_PREVIEW_SOURCE_MAX_LENGTH, | | 49 | + thoughtPreviewMarkdown, | | 50 | +} from "./TimelineWorkEntryRow.logic"; | 47 | 51 | import { wordsHast } from "~/markdown/wordsHast"; | 48 | 52 | import { TimelineRowCtx } from "./timelineRowContext"; | 49 | 53 | import { searchableMessageSegments } from "@t3tools/shared/threadFindText"; | @@ -2302,6 +2306,28 @@ describe("compact reasoning math", () => { | 2302 | 2306 | ), | 2303 | 2307 | ).toEqual(expected); | 2304 | 2308 | }); | | 2309 | + | | 2310 | + it("does not split a surrogate pair at the reasoning preview source limit", async () => { | | 2311 | + setup(); | | 2312 | + const prefix = `[l](${"u".repeat(8_100)}) `; | | 2313 | + const filler = "c".repeat(THOUGHT_PREVIEW_SOURCE_MAX_LENGTH - 1 - prefix.length); | | 2314 | + await using screen = await renderTimeline( | | 2315 | + [ | | 2316 | + work("thought-1", { | | 2317 | + label: "Thinking", | | 2318 | + tone: "thinking", | | 2319 | + itemType: "reasoning", | | 2320 | + toolLifecycleStatus: "inProgress", | | 2321 | + detail: `${prefix}${filler}😀 tail`, | | 2322 | + }), | | 2323 | + ], | | 2324 | + { isWorking: true }, | | 2325 | + ); | | 2326 | + await vi.waitFor(() => { | | 2327 | + expect(screen.text()).toContain(`l ${filler}`); | | 2328 | + }); | | 2329 | + expect(screen.text()).not.toContain("\uFFFD"); | | 2330 | + }); | 2305 | 2331 | }); | 2306 | 2332 |
| 2307 | 2333 | it("renders automatic compaction as one live divider that finishes with its reason and token delta", async () => { | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/TimelineWorkEntryRow.logic.ts +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | resolveWorkEntryToolPresentation, | 5 | 5 | toolGroupAction, | 6 | 6 | } from "@t3tools/client-runtime/work-log/presentation"; | | 7 | +import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations"; | 7 | 8 | import { isJavaScriptReplTool } from "@t3tools/shared/toolActivity"; | 8 | 9 | import { formatWorkspaceRelativePath } from "../../filePathDisplay"; | 9 | 10 | import { m, type MessageResolver } from "../../i18n/messages"; | @@ -208,6 +209,15 @@ export function workEntryIconName(workEntry: TimelineWorkEntry): WorkEntryIconNa | 208 | 209 | export const THOUGHT_PREVIEW_SOURCE_MAX_LENGTH = 8_192; | 209 | 210 | export const THOUGHT_PREVIEW_MAX_LENGTH = 2_048; | 210 | 211 |
| | 212 | +export function sliceThoughtPreviewSource(text: string): string { | | 213 | + return text.slice( | | 214 | + 0, | | 215 | + splitsSurrogatePair(text, THOUGHT_PREVIEW_SOURCE_MAX_LENGTH) | | 216 | + ? THOUGHT_PREVIEW_SOURCE_MAX_LENGTH - 1 | | 217 | + : THOUGHT_PREVIEW_SOURCE_MAX_LENGTH, | | 218 | + ); | | 219 | +} | | 220 | + | 211 | 221 | const thoughtPreviews = new Map<string, MarkdownExtensions>(); | 212 | 222 |
| 213 | 223 | /** Compact reasoning keeps formulas while flattening other Markdown into label text. */ | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/TimelineWorkEntryRow.tsx +2-5Lines changed: 2 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -79,8 +79,8 @@ import { | 79 | 79 | workEntryRawCommand, | 80 | 80 | buildToolCallExpandedBody, | 81 | 81 | workEntryIconName, | | 82 | + sliceThoughtPreviewSource, | 82 | 83 | thoughtPreviewMarkdown, | 83 | | - THOUGHT_PREVIEW_SOURCE_MAX_LENGTH, | 84 | 84 | } from "./TimelineWorkEntryRow.logic"; | 85 | 85 |
| 86 | 86 | export function useThreadReadTarget(entry: TimelineWorkEntry, environmentId: EnvironmentId) { | @@ -603,10 +603,7 @@ function WorkEntryLogRow(props: WorkEntryRowProps) { | 603 | 603 | {isReasoning && !expanded ? ( | 604 | 604 | <ChatMarkdown | 605 | 605 | inline | 606 | | - text={(workEntry.detail ?? previewText).slice( | 607 | | - 0, | 608 | | - THOUGHT_PREVIEW_SOURCE_MAX_LENGTH, | 609 | | - )} | | 606 | + text={sliceThoughtPreviewSource(workEntry.detail ?? previewText)} | 610 | 607 | cwd={ctx.markdownCwd} | 611 | 608 | parseRawHtml={false} | 612 | 609 | extensions={ | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/TimelineWorkGroupRows.tsx +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -57,8 +57,8 @@ import { | 57 | 57 | SimpleWorkEntryRow, | 58 | 58 | } from "./TimelineWorkEntryRow"; | 59 | 59 | import { | | 60 | + sliceThoughtPreviewSource, | 60 | 61 | thoughtPreviewMarkdown, | 61 | | - THOUGHT_PREVIEW_SOURCE_MAX_LENGTH, | 62 | 62 | toolGroupSummaryIconName, | 63 | 63 | workEntryIconName, | 64 | 64 | } from "./TimelineWorkEntryRow.logic"; | @@ -631,7 +631,7 @@ export function LiveWorkEntryTimelineRow({ | 631 | 631 | const failed = workEntryDisplayIndicatesToolFailure(row.entry); | 632 | 632 | const thoughtLine = | 633 | 633 | row.thought && !row.expanded | 634 | | - ? liveThoughtLine((row.thought.detail ?? "").slice(0, THOUGHT_PREVIEW_SOURCE_MAX_LENGTH)) | | 634 | + ? liveThoughtLine(sliceThoughtPreviewSource(row.thought.detail ?? "")) | 635 | 635 | : ""; | 636 | 636 | const thoughtIsStatus = thoughtLine !== "" && row.entry === row.thought; | 637 | 637 |
| @@ -689,7 +689,7 @@ export function LiveWorkEntryTimelineRow({ | 689 | 689 | ) : row.entry.itemType === "reasoning" ? ( | 690 | 690 | <ChatMarkdown | 691 | 691 | inline | 692 | | - text={(row.entry.detail ?? label).slice(0, THOUGHT_PREVIEW_SOURCE_MAX_LENGTH)} | | 692 | + text={sliceThoughtPreviewSource(row.entry.detail ?? label)} | 693 | 693 | cwd={ctx.markdownCwd} | 694 | 694 | parseRawHtml={false} | 695 | 695 | extensions={ | |
|