TypeScript
fix(web): show a real arrow in the context compacted divider (#20326)
Abdullah Al Zawadabfc5727bf10
diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts b/apps/web/src/components/chat/MessagesTimeline.logic.test.tsindex 650b2bf504f..d90a708a324 100644--- a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts+++ b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts@@ -1095,6 +1095,7 @@ describe("deriveMessagesTimelineRows", () => {id: "compaction-entry",createdAt: "2026-01-01T00:00:00Z",label: "Compacted context 899K → 19K tokens",+ tokenCounts: null,active: false,},]);@@ -1148,6 +1149,7 @@ describe("deriveMessagesTimelineRows", () => {expect(completedRows.find((row) => row.kind === "context-compaction")).toMatchObject({active: false,label: "Context compacted 899K → 19K tokens",+ tokenCounts: { before: "899K", after: "19K" },});expect(completedRows.at(-1)?.kind).toBe("thinking");diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.ts b/apps/web/src/components/chat/MessagesTimeline.logic.tsindex a602e954de2..34c786122a3 100644--- a/apps/web/src/components/chat/MessagesTimeline.logic.ts+++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts@@ -20,6 +20,7 @@ import {summarizeToolGroup,toolGroupAction,toolGroupSummaryKind,+ contextCompactionTokenCounts,type ToolGroupSummaryKind,} from "@t3tools/client-runtime/work-log/presentation";export {@@ -554,6 +555,7 @@ type MessagesTimelineRowContent =id: string;createdAt: string;label: string;+ tokenCounts: ReturnType<typeof contextCompactionTokenCounts>;active: boolean;}| {@@ -1562,11 +1564,14 @@ export function deriveMessagesTimelineRows(input: {) {const active = workEntryIsInActiveRun(timelineEntry.entry);hasActiveCompaction ||= active;+ const compaction = timelineEntry.entry.structuredPayload;nextRows.push({kind: "context-compaction",id: timelineEntry.id,createdAt: timelineEntry.createdAt,label: timelineEntry.entry.label,+ tokenCounts:+ compaction?.type === "compaction" ? contextCompactionTokenCounts(compaction) : null,active,});continue;diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsxindex 0fae1a3fbae..e8fd2954e2f 100644--- a/apps/web/src/components/chat/MessagesTimeline.tsx+++ b/apps/web/src/components/chat/MessagesTimeline.tsx@@ -121,6 +121,7 @@ import type { Root, RootContent } from "mdast";import { T3Wordmark } from "../T3Wordmark";import { ThreadContextChip } from "../ThreadContextChip";import {+ ArrowRightIcon,BotIcon,BrainIcon,CheckIcon,@@ -1995,6 +1996,20 @@ function ContextCompactionTimelineRow({}: {row: Extract<TimelineRow, { kind: "context-compaction" }>;}) {+ const content = (+ <span className="flex items-center gap-1.5">+ <Minimize2Icon aria-hidden="true" className="size-3" />+ {row.tokenCounts ? (+ <>+ Context compacted {row.tokenCounts.before}+ <ArrowRightIcon aria-hidden="true" className="size-3" />+ {row.tokenCounts.after} tokens+ </>+ ) : (+ row.label+ )}+ </span>+ );return (<divrole="separator"@@ -2006,18 +2021,8 @@ function ContextCompactionTimelineRow({ref={row.active ? observeVisibleAnimation : undefined}className="relative shrink-0 overflow-hidden">- <span className="flex items-center gap-1.5">- <Minimize2Icon aria-hidden="true" className="size-3" />- {row.label}- </span>- {row.active ? (- <ActivityShimmerOverlay>- <span className="flex items-center gap-1.5">- <Minimize2Icon aria-hidden="true" className="size-3" />- {row.label}- </span>- </ActivityShimmerOverlay>- ) : null}+ {content}+ {row.active ? <ActivityShimmerOverlay>{content}</ActivityShimmerOverlay> : null}</span><span className="h-px flex-1 bg-border/70" /></div>diff --git a/packages/client-runtime/src/work-log/presentation.ts b/packages/client-runtime/src/work-log/presentation.tsindex e05b1392656..b3cfcc9779b 100644--- a/packages/client-runtime/src/work-log/presentation.ts+++ b/packages/client-runtime/src/work-log/presentation.ts@@ -48,17 +48,30 @@ export function toolItemForDisplay(item: OrchestrationV2TurnItem): Orchestration}}-export function contextCompactionLabel(- item: Pick<- Extract<OrchestrationV2TurnItem, { type: "compaction" }>,- "status" | "beforeTokenCount" | "afterTokenCount"- >,-): string {- if (item.status === "running") return "Compacting context";- if (item.beforeTokenCount !== undefined && item.afterTokenCount !== undefined) {- return `Context compacted ${formatTokens(item.beforeTokenCount)} → ${formatTokens(item.afterTokenCount)} tokens`;+type CompactionLabelItem = Pick<+ Extract<OrchestrationV2TurnItem, { type: "compaction" }>,+ "status" | "beforeTokenCount" | "afterTokenCount"+>;++export function contextCompactionTokenCounts(+ item: CompactionLabelItem,+): { readonly before: string; readonly after: string } | null {+ if (+ item.status === "running" ||+ item.beforeTokenCount === undefined ||+ item.afterTokenCount === undefined+ ) {+ return null;}- return "Context compacted";+ return { before: formatTokens(item.beforeTokenCount), after: formatTokens(item.afterTokenCount) };+}++export function contextCompactionLabel(item: CompactionLabelItem): string {+ if (item.status === "running") return "Compacting context";+ const tokens = contextCompactionTokenCounts(item);+ return tokens+ ? `Context compacted ${tokens.before} → ${tokens.after} tokens`+ : "Context compacted";}export interface WorkLogPresentationEntry {