Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

MessagesTimeline.logic.ts

713 lines23.0 KB

1import * as Equal from "effect/Equal";
2import {
3 formatDuration,
4 workEntryIndicatesToolNeutralStatus,
5 workLogEntryIsToolLike,
6 type TimelineEntry,
7 type TurnPlanEntry,
8 type WorkLogEntry,
9} from "../../session-logic";
10import { type ChatMessage, type ProposedPlan, type TurnDiffSummary } from "../../types";
11import { type MessageId, type OrchestrationLatestTurn, type TurnId } from "@t3tools/contracts";
12​
13export const MAX_VISIBLE_WORK_LOG_ENTRIES = 1;
14export const TIMELINE_MINIMAP_ITEM_SPACING = 8;
15export const TIMELINE_MINIMAP_MIN_ITEMS = 2;
16export const TIMELINE_MINIMAP_MAX_HEIGHT_CSS = "calc(100vh - 18rem)";
17export const TIMELINE_CONTENT_MAX_WIDTH = 768;
18export const TIMELINE_MINIMAP_PERSISTENT_GUTTER = 48;
19​
20export interface TimelineEndState {
21 readonly isAtEnd?: boolean;
22 readonly contentLength?: number;
23 readonly scroll?: number;
24 readonly scrollLength?: number;
26​
27/**
28 * Follow re-arm band above the hard bottom. Strict on purpose: LegendList's
29 * isNearEnd fires within half a viewport, which re-armed live-follow while the
30 * user was reading history and yanked them back down on the next stream chunk.
31 * A small pixel band (instead of the 1px isAtEnd epsilon alone) keeps re-arming
32 * reliable while streaming content is still growing under the viewport.
33 */
34export const TIMELINE_FOLLOW_REARM_THRESHOLD_PX = 40;
35​
36export function resolveTimelineIsAtEnd(
37 state: TimelineEndState | undefined,
38 endInset = 0,
39): boolean | undefined {
40 if (!state) {
41 return undefined;
42 }
43 if (state.isAtEnd) {
44 return true;
45 }
46 const { contentLength, scroll, scrollLength } = state;
47 if (contentLength === undefined || scroll === undefined || scrollLength === undefined) {
48 return state.isAtEnd;
49 }
50 // contentLength includes the end inset (composer overlay), so subtract it to
51 // measure the distance to the real content bottom.
52 return contentLength - scroll - scrollLength - endInset <= TIMELINE_FOLLOW_REARM_THRESHOLD_PX;
54​
55export function resolveTimelineMinimapHeightStyle(itemCount: number): string {
56 const naturalHeight = Math.max(1, (itemCount - 1) * TIMELINE_MINIMAP_ITEM_SPACING);
57 return `min(${naturalHeight}px, ${TIMELINE_MINIMAP_MAX_HEIGHT_CSS})`;
59​
60export function resolveTimelineMinimapTopPercent(index: number, itemCount: number): number {
61 if (itemCount <= 1) {
62 return 0;
63 }
64 return (Math.max(0, Math.min(index, itemCount - 1)) / (itemCount - 1)) * 100;
66​
67export function resolveTimelineMinimapIndexFromPointer(input: {
68 readonly itemCount: number;
69 readonly railTop: number;
70 readonly railHeight: number;
71 readonly pointerY: number;
72}): number | null {
73 if (input.itemCount <= 0 || input.railHeight <= 0) {
74 return null;
75 }
76 if (input.itemCount === 1) {
77 return 0;
78 }
79​
80 const progress = Math.max(0, Math.min(1, (input.pointerY - input.railTop) / input.railHeight));
81 return Math.max(0, Math.min(input.itemCount - 1, Math.round(progress * (input.itemCount - 1))));
83​
84export function resolveTimelineMinimapHasPersistentGutter(viewportWidth: number): boolean {
85 if (!Number.isFinite(viewportWidth) || viewportWidth <= 0) {
86 return false;
87 }
88​
89 const contentWidth = Math.min(viewportWidth, TIMELINE_CONTENT_MAX_WIDTH);
90 const sideGutter = Math.max(0, (viewportWidth - contentWidth) / 2);
91 return sideGutter >= TIMELINE_MINIMAP_PERSISTENT_GUTTER;
93​
94export const TIMELINE_MINIMAP_HIT_STRIP_LEFT = 12;
95export const TIMELINE_MINIMAP_HIT_STRIP_MAX_WIDTH = 40;
96export const TIMELINE_MINIMAP_EXPANDED_HIT_STRIP_WIDTH = "22rem";
97​
98/**
99 * The minimap overlays the viewport's left edge while the content column is
100 * centered, so the side gutter between them shrinks under browser zoom or a
101 * narrow pane. A fixed-width hover strip would then sit on top of the message
102 * text and swallow its pointer events. Cap the strip's width so it never
103 * extends past the gutter into the content column; 0 disables the strip.
104 */
105export function resolveTimelineMinimapHitStripWidth(viewportWidth: number): number {
106 if (!Number.isFinite(viewportWidth) || viewportWidth <= 0) {
107 return 0;
108 }
109​
110 const contentWidth = Math.min(viewportWidth, TIMELINE_CONTENT_MAX_WIDTH);
111 const sideGutter = Math.max(0, (viewportWidth - contentWidth) / 2);
112 return Math.max(
113 0,
114 Math.min(
115 TIMELINE_MINIMAP_HIT_STRIP_MAX_WIDTH,
116 Math.floor(sideGutter) - TIMELINE_MINIMAP_HIT_STRIP_LEFT,
117 ),
118 );
120​
121/**
122 * Once the preview is open, keep the full preview and the space leading to it
123 * interactive. The collapsed strip remains gutter-capped so it cannot block
124 * selecting message text.
125 */
126export function resolveTimelineMinimapInteractiveWidth(
127 collapsedWidth: number,
128 expanded: boolean,
129): number | string {
130 return expanded ? TIMELINE_MINIMAP_EXPANDED_HIT_STRIP_WIDTH : collapsedWidth;
132​
133function computeElapsedMs(startIso: string, endIso: string): number | null {
134 const start = Date.parse(startIso);
135 const end = Date.parse(endIso);
136 if (!Number.isFinite(start) || !Number.isFinite(end)) return null;
137 return Math.max(0, end - start);
139​
140function maxIsoTimestamp(a: string | null, b: string | null): string | null {
141 if (a === null) return b;
142 if (b === null) return a;
143 const aMs = Date.parse(a);
144 const bMs = Date.parse(b);
145 if (!Number.isFinite(aMs)) return b;
146 if (!Number.isFinite(bMs)) return a;
147 return bMs > aMs ? b : a;
149​
150export interface TimelineDurationMessage {
151 id: string;
152 role: "user" | "assistant" | "system";
153 createdAt: string;
154 updatedAt: string;
155 streaming: boolean;
157​
158export type TimelineLatestTurn = Pick<
159 OrchestrationLatestTurn,
160 "turnId" | "state" | "startedAt" | "completedAt"
161>;
162​
163export type MessagesTimelineRow =
164 | {
165 kind: "work";
166 id: string;
167 createdAt: string;
168 groupedEntries: WorkLogEntry[];
169 }
170 | {
171 kind: "work-toggle";
172 id: string;
173 createdAt: string;
174 groupId: string;
175 hiddenCount: number;
176 expanded: boolean;
177 onlyToolEntries: boolean;
178 }
179 | {
180 kind: "turn-fold";
181 id: string;
182 createdAt: string;
183 turnId: TurnId;
184 label: string;
185 expanded: boolean;
186 }
187 | {
188 kind: "message";
189 id: string;
190 createdAt: string;
191 message: ChatMessage;
192 durationStart: string;
193 showAssistantMeta: boolean;
194 showAssistantCopyButton: boolean;
195 assistantCopyStreaming: boolean;
196 assistantTurnDiffSummary?: TurnDiffSummary | undefined;
197 revertTurnCount?: number | undefined;
198 }
199 | {
200 kind: "proposed-plan";
201 id: string;
202 createdAt: string;
203 proposedPlan: ProposedPlan;
204 }
205 | {
206 kind: "turn-plan";
207 id: string;
208 createdAt: string;
209 turnPlan: TurnPlanEntry;
210 }
211 | { kind: "working"; id: string; createdAt: string | null };
212​
213export interface StableMessagesTimelineRowsState {
214 byId: Map<string, MessagesTimelineRow>;
215 result: MessagesTimelineRow[];
217​
218export function computeMessageDurationStart(
219 messages: ReadonlyArray<TimelineDurationMessage>,
220): Map<string, string> {
221 const result = new Map<string, string>();
222 let lastBoundary: string | null = null;
223​
224 for (const message of messages) {
225 if (message.role === "user") {
226 lastBoundary = message.createdAt;
227 }
228 result.set(message.id, lastBoundary ?? message.createdAt);
229 if (message.role === "assistant" && !message.streaming) {
230 lastBoundary = message.updatedAt;
231 }
232 }
233​
234 return result;
236​
237export function normalizeCompactToolLabel(value: string): string {
238 return value.replace(/\s+(?:complete|completed)\s*$/i, "").trim();
240​
241export function resolveAssistantMessageCopyState({
242 text,
243 showCopyButton,
244 streaming,
245}: {
246 text: string | null;
247 showCopyButton: boolean;
248 streaming: boolean;
249}) {
250 const hasText = text !== null && text.trim().length > 0;
251 return {
252 text: hasText ? text : null,
253 visible: showCopyButton && hasText && !streaming,
254 };
256​
257function deriveTerminalAssistantMessageIds(timelineEntries: ReadonlyArray<TimelineEntry>) {
258 const lastAssistantMessageIdByResponseKey = new Map<string, string>();
259 let nullTurnResponseIndex = 0;
260​
261 for (const timelineEntry of timelineEntries) {
262 if (timelineEntry.kind !== "message") {
263 continue;
264 }
265 const { message } = timelineEntry;
266 if (message.role === "user") {
267 nullTurnResponseIndex += 1;
268 continue;
269 }
270 if (message.role !== "assistant") {
271 continue;
272 }
273​
274 const responseKey = message.turnId
275 ? `turn:${message.turnId}`
276 : `unkeyed:${nullTurnResponseIndex}`;
277 lastAssistantMessageIdByResponseKey.set(responseKey, message.id);
278 }
279​
280 return new Set(lastAssistantMessageIdByResponseKey.values());
282​
283interface TurnFold {
284 turnId: TurnId;
285 anchorEntryId: string;
286 createdAt: string;
287 hiddenEntryIds: ReadonlySet<string>;
288 label: string;
290​
291/**
292 * The session's running turn is authoritative when latestTurn briefly lags or
293 * regresses behind it. Otherwise, the latest turn counts as unsettled while it
294 * is still running (or has not recorded a completion). This is deliberately
295 * keyed on turn lifecycle rather than transient working state: right after the
296 * user sends a message, the previous turn is still the "active" one until the
297 * server creates the new turn, and folding must not flicker through that window.
298 */
299function deriveUnsettledTurnId(
300 latestTurn: TimelineLatestTurn | null,
301 runningTurnId: TurnId | null,
302): TurnId | null {
303 if (runningTurnId !== null) {
304 return runningTurnId;
305 }
306 if (!latestTurn) {
307 return null;
308 }
309 const isSettled = latestTurn.completedAt !== null && latestTurn.state !== "running";
310 return isSettled ? null : latestTurn.turnId;
312​
313/**
314 * Settled turns fold their commentary and tool activity behind a
315 * "Worked for ..." row anchored at the turn's first foldable entry; the
316 * terminal assistant message stays visible below the fold.
317 */
318function deriveTurnFolds(input: {
319 timelineEntries: ReadonlyArray<TimelineEntry>;
320 terminalAssistantMessageIds: ReadonlySet<string>;
321 latestTurn: TimelineLatestTurn | null;
322 unsettledTurnId: TurnId | null;
323}): ReadonlyMap<string, TurnFold> {
324 interface TurnGroup {
325 entries: Array<TimelineEntry>;
326 terminalEntry: Extract<TimelineEntry, { kind: "message" }> | null;
327 hasStreamingMessage: boolean;
328 /**
329 * The user message that kicked the turn off. Entry timestamps alone
330 * undercount the duration (the first entry appears only once the
331 * provider starts producing output), and a turn cut short by a steer may
332 * hold a single instantaneous commentary message.
333 */
334 startBoundary: string | null;
335 }
336 const groupsByTurnId = new Map<TurnId, TurnGroup>();
337​
338 let pendingUserBoundary: string | null = null;
339 for (const entry of input.timelineEntries) {
340 if (entry.kind === "message" && entry.message.role === "user") {
341 pendingUserBoundary = entry.message.createdAt;
342 continue;
343 }
344 const turnId =
345 entry.kind === "message" && entry.message.role === "assistant"
346 ? (entry.message.turnId ?? null)
347 : entry.kind === "work"
348 ? (entry.entry.turnId ?? null)
349 : null;
350 if (!turnId) {
351 continue;
352 }
353 let group = groupsByTurnId.get(turnId);
354 if (!group) {
355 group = {
356 entries: [],
357 terminalEntry: null,
358 hasStreamingMessage: false,
359 // Each user boundary starts at most one turn; a second turn after the
360 // same user message (e.g. a steer-superseded continuation) falls back
361 // to its own first entry.
362 startBoundary: pendingUserBoundary,
363 };
364 pendingUserBoundary = null;
365 groupsByTurnId.set(turnId, group);
366 }
367 group.entries.push(entry);
368 if (entry.kind === "message") {
369 if (input.terminalAssistantMessageIds.has(entry.message.id)) {
370 group.terminalEntry = entry;
371 }
372 if (entry.message.streaming) {
373 group.hasStreamingMessage = true;
374 }
375 }
376 }
377​
378 const foldsByAnchorEntryId = new Map<string, TurnFold>();
379 for (const [turnId, group] of groupsByTurnId) {
380 if (turnId === input.unsettledTurnId) {
381 continue;
382 }
383 if (group.hasStreamingMessage) {
384 continue;
385 }
386 const hiddenEntryIds = new Set<string>();
387 for (const entry of group.entries) {
388 if (entry.id === group.terminalEntry?.id) {
389 continue;
390 }
391 // Agent-spawn CTA rows never fold: workflows outlive their launching
392 // turn (dynamic spawns, background execution), and folding the CTA
393 // when the turn settles makes a still-running fleet invisible.
394 if (entry.kind === "work" && entry.entry.agentSpawn !== undefined) {
395 continue;
396 }
397 hiddenEntryIds.add(entry.id);
398 }
399 if (hiddenEntryIds.size === 0) {
400 continue;
401 }
402​
403 const firstEntry = group.entries[0];
404 const lastEntry = group.entries.at(-1);
405 if (!firstEntry || !lastEntry) {
406 continue;
407 }
408​
409 const isLatestInterruptedTurn =
410 input.latestTurn?.turnId === turnId && input.latestTurn.state === "interrupted";
411 // A turn cut short by a steer leaves trailing work entries behind its
412 // terminal message — take whichever ended last.
413 const lastEntryEnd =
414 lastEntry.kind === "message" ? lastEntry.message.updatedAt : lastEntry.createdAt;
415 const elapsedMs =
416 input.latestTurn?.turnId === turnId &&
417 input.latestTurn.startedAt &&
418 input.latestTurn.completedAt
419 ? computeElapsedMs(input.latestTurn.startedAt, input.latestTurn.completedAt)
420 : computeElapsedMs(
421 group.startBoundary ?? firstEntry.createdAt,
422 maxIsoTimestamp(group.terminalEntry?.message.updatedAt ?? null, lastEntryEnd) ??
423 lastEntryEnd,
424 );
425 const duration = elapsedMs !== null ? formatDuration(elapsedMs) : null;
426 const label = isLatestInterruptedTurn
427 ? duration
428 ? `You stopped after ${duration}`
429 : "You stopped this response"
430 : duration
431 ? `Worked for ${duration}`
432 : "Worked";
433​
434 foldsByAnchorEntryId.set(firstEntry.id, {
435 turnId,
436 anchorEntryId: firstEntry.id,
437 createdAt: firstEntry.createdAt,
438 hiddenEntryIds,
439 label,
440 });
441 }
442 return foldsByAnchorEntryId;
444​
445export function deriveMessagesTimelineRows(input: {
446 timelineEntries: ReadonlyArray<TimelineEntry>;
447 latestTurn?: TimelineLatestTurn | null;
448 runningTurnId?: TurnId | null;
449 expandedTurnIds?: ReadonlySet<TurnId>;
450 expandedWorkGroupIds?: ReadonlySet<string>;
451 isWorking: boolean;
452 activeTurnStartedAt: string | null;
453 turnDiffSummaryByAssistantMessageId: ReadonlyMap<MessageId, TurnDiffSummary>;
454 revertTurnCountByUserMessageId: ReadonlyMap<MessageId, number>;
455}): MessagesTimelineRow[] {
456 const nextRows: MessagesTimelineRow[] = [];
457 const durationStartByMessageId = computeMessageDurationStart(
458 input.timelineEntries.flatMap((entry) => (entry.kind === "message" ? [entry.message] : [])),
459 );
460 const terminalAssistantMessageIds = deriveTerminalAssistantMessageIds(input.timelineEntries);
461 const unsettledTurnId = deriveUnsettledTurnId(
462 input.latestTurn ?? null,
463 input.runningTurnId ?? null,
464 );
465 const foldsByAnchorEntryId = deriveTurnFolds({
466 timelineEntries: input.timelineEntries,
467 terminalAssistantMessageIds,
468 latestTurn: input.latestTurn ?? null,
469 unsettledTurnId,
470 });
471 const collapsedEntryIds = new Set<string>();
472 for (const fold of foldsByAnchorEntryId.values()) {
473 if (!input.expandedTurnIds?.has(fold.turnId)) {
474 for (const entryId of fold.hiddenEntryIds) {
475 collapsedEntryIds.add(entryId);
476 }
477 }
478 }
479​
480 for (let index = 0; index < input.timelineEntries.length; index += 1) {
481 const timelineEntry = input.timelineEntries[index];
482 if (!timelineEntry) {
483 continue;
484 }
485​
486 const turnFold = foldsByAnchorEntryId.get(timelineEntry.id);
487 if (turnFold) {
488 nextRows.push({
489 kind: "turn-fold",
490 id: `turn-fold:${turnFold.turnId}`,
491 createdAt: turnFold.createdAt,
492 turnId: turnFold.turnId,
493 label: turnFold.label,
494 expanded: input.expandedTurnIds?.has(turnFold.turnId) ?? false,
495 });
496 }
497​
498 if (collapsedEntryIds.has(timelineEntry.id)) {
499 continue;
500 }
501​
502 if (timelineEntry.kind === "work") {
503 const groupedEntries = [timelineEntry.entry];
504 let cursor = index + 1;
505 while (cursor < input.timelineEntries.length) {
506 const nextEntry = input.timelineEntries[cursor];
507 if (
508 !nextEntry ||
509 nextEntry.kind !== "work" ||
510 collapsedEntryIds.has(nextEntry.id) ||
511 foldsByAnchorEntryId.has(nextEntry.id)
512 ) {
513 break;
514 }
515 groupedEntries.push(nextEntry.entry);
516 cursor += 1;
517 }
518 const visibleGroupedEntries = groupedEntries.filter(
519 (entry) => !workEntryIndicatesToolNeutralStatus(entry),
520 );
521 if (visibleGroupedEntries.length > 0) {
522 if (visibleGroupedEntries.length <= MAX_VISIBLE_WORK_LOG_ENTRIES) {
523 nextRows.push({
524 kind: "work",
525 id: timelineEntry.id,
526 createdAt: timelineEntry.createdAt,
527 groupedEntries: visibleGroupedEntries,
528 });
529 } else {
530 const groupId = `work-group:${timelineEntry.id}`;
531 const expanded = input.expandedWorkGroupIds?.has(groupId) ?? false;
532 // Agent-spawn CTA rows are always visible: a running fleet must
533 // never hide behind a "+N tool calls" toggle. Selection is by
534 // membership (spawn OR recent-tail), preserving the group's
535 // chronological order in both collapsed and expanded states
536 // (review finding: concatenating two filtered lists moved a
537 // mid-group spawn row above earlier tool rows).
538 const overflowCandidates = visibleGroupedEntries.filter(
539 (entry) => entry.agentSpawn === undefined,
540 );
541 const hiddenEntries = overflowCandidates.slice(0, -MAX_VISIBLE_WORK_LOG_ENTRIES);
542 const hiddenIds = new Set(hiddenEntries.map((entry) => entry.id));
543 const visibleEntries = visibleGroupedEntries.filter(
544 (entry) => entry.agentSpawn !== undefined || !hiddenIds.has(entry.id),
545 );
546 const renderedEntries = expanded ? visibleGroupedEntries : visibleEntries;
547​
548 for (const workEntry of renderedEntries) {
549 nextRows.push({
550 kind: "work",
551 id: workEntry.id,
552 createdAt: workEntry.createdAt,
553 groupedEntries: [workEntry],
554 });
555 }
556​
557 if (hiddenEntries.length > 0) {
558 nextRows.push({
559 kind: "work-toggle",
560 id: `work-toggle:${timelineEntry.id}`,
561 createdAt: timelineEntry.createdAt,
562 groupId,
563 hiddenCount: hiddenEntries.length,
564 expanded,
565 onlyToolEntries: visibleGroupedEntries.every((entry) =>
566 workLogEntryIsToolLike(entry),
567 ),
568 });
569 }
570 }
571 }
572 index = cursor - 1;
573 continue;
574 }
575​
576 if (timelineEntry.kind === "proposed-plan") {
577 nextRows.push({
578 kind: "proposed-plan",
579 id: timelineEntry.id,
580 createdAt: timelineEntry.createdAt,
581 proposedPlan: timelineEntry.proposedPlan,
582 });
583 continue;
584 }
585​
586 if (timelineEntry.kind === "turn-plan") {
587 nextRows.push({
588 kind: "turn-plan",
589 id: timelineEntry.id,
590 createdAt: timelineEntry.createdAt,
591 turnPlan: timelineEntry.turnPlan,
592 });
593 continue;
594 }
595​
596 const assistantTurnStillInProgress =
597 timelineEntry.message.role === "assistant" &&
598 unsettledTurnId !== null &&
599 timelineEntry.message.turnId === unsettledTurnId;
600​
601 const durationStart =
602 durationStartByMessageId.get(timelineEntry.message.id) ?? timelineEntry.message.createdAt;
603​
604 // While the turn is still running, the latest assistant message is only
605 // provisionally terminal — withhold the metadata row until the turn
606 // settles so commentary doesn't flash timestamps mid-work.
607 const showAssistantMeta =
608 timelineEntry.message.role === "assistant" &&
609 terminalAssistantMessageIds.has(timelineEntry.message.id) &&
610 !assistantTurnStillInProgress;
611​
612 nextRows.push({
613 kind: "message",
614 id: timelineEntry.id,
615 createdAt: timelineEntry.createdAt,
616 message: timelineEntry.message,
617 durationStart,
618 showAssistantMeta,
619 showAssistantCopyButton: showAssistantMeta,
620 assistantCopyStreaming: timelineEntry.message.streaming || assistantTurnStillInProgress,
621 assistantTurnDiffSummary:
622 timelineEntry.message.role === "assistant"
623 ? input.turnDiffSummaryByAssistantMessageId.get(timelineEntry.message.id)
624 : undefined,
625 revertTurnCount:
626 timelineEntry.message.role === "user"
627 ? input.revertTurnCountByUserMessageId.get(timelineEntry.message.id)
628 : undefined,
629 });
630 }
631​
632 if (input.isWorking) {
633 nextRows.push({
634 kind: "working",
635 id: "working-indicator-row",
636 createdAt: input.activeTurnStartedAt,
637 });
638 }
639​
640 return nextRows;
642​
643export function computeStableMessagesTimelineRows(
644 rows: MessagesTimelineRow[],
645 previous: StableMessagesTimelineRowsState,
646): StableMessagesTimelineRowsState {
647 const next = new Map<string, MessagesTimelineRow>();
648 let anyChanged = rows.length !== previous.byId.size;
649​
650 const result = rows.map((row, index) => {
651 const prevRow = previous.byId.get(row.id);
652 const nextRow = prevRow && isRowUnchanged(prevRow, row) ? prevRow : row;
653 next.set(row.id, nextRow);
654 if (!anyChanged && previous.result[index] !== nextRow) {
655 anyChanged = true;
656 }
657 return nextRow;
658 });
659​
660 return anyChanged ? { byId: next, result } : previous;
662​
663/** Shallow field comparison per row variant — avoids deep equality cost. */
664function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean {
665 if (a.kind !== b.kind || a.id !== b.id) return false;
666​
667 switch (a.kind) {
668 case "working":
669 return a.createdAt === (b as typeof a).createdAt;
670​
671 case "turn-fold": {
672 const bf = b as typeof a;
673 return a.createdAt === bf.createdAt && a.label === bf.label && a.expanded === bf.expanded;
674 }
675​
676 case "proposed-plan":
677 return a.proposedPlan === (b as typeof a).proposedPlan;
678​
679 case "turn-plan": {
680 const bp = b as typeof a;
681 // Plans rewrite in place: compare the snapshot's identity fields so an
682 // unchanged plan keeps its row reference (virtualization stability).
683 return a.createdAt === bp.createdAt && a.turnPlan.plan === bp.turnPlan.plan;
684 }
685​
686 case "work":
687 return Equal.equals(a.groupedEntries, (b as typeof a).groupedEntries);
688​
689 case "work-toggle": {
690 const bw = b as typeof a;
691 return (
692 a.createdAt === bw.createdAt &&
693 a.groupId === bw.groupId &&
694 a.hiddenCount === bw.hiddenCount &&
695 a.expanded === bw.expanded &&
696 a.onlyToolEntries === bw.onlyToolEntries
697 );
698 }
699​
700 case "message": {
701 const bm = b as typeof a;
702 return (
703 a.message === bm.message &&
704 a.durationStart === bm.durationStart &&
705 a.showAssistantMeta === bm.showAssistantMeta &&
706 a.showAssistantCopyButton === bm.showAssistantCopyButton &&
707 a.assistantCopyStreaming === bm.assistantCopyStreaming &&
708 a.assistantTurnDiffSummary === bm.assistantTurnDiffSummary &&
709 a.revertTurnCount === bm.revertTurnCount
710 );
711 }
712 }