Skip to content

Commit 52061da

Browse files
refactor(web): timeline row derivation, position restore and find reader live in hooks
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1637084 commit 52061da

5 files changed

Lines changed: 391 additions & 285 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.logic.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
collectAssistantCitations,
99
} from "@t3tools/shared/assistantCitations";
1010
import { shallow } from "zustand/vanilla/shallow";
11+
import type { HandoffTimelineRun } from "@t3tools/client-runtime/handoff";
1112
import { renderCodexDirectivesForCopy } from "@t3tools/shared/codexMarkdownDirectives";
1213
import {
1314
commandDisplayText,
@@ -2011,7 +2012,7 @@ function attachCreatedThreadSummaries(
20112012

20122013
const WORKTREE_SETUP_ROW_ID = "worktree-setup-row";
20132014

2014-
type MessagesTimelineRowsInput = Parameters<typeof deriveMessagesTimelineRows>[0];
2015+
export type MessagesTimelineRowsInput = Parameters<typeof deriveMessagesTimelineRows>[0];
20152016

20162017
export interface MessagesTimelineRowsProjection {
20172018
readonly input: MessagesTimelineRowsInput;
@@ -2314,3 +2315,28 @@ export function shouldCollapseUserMessage(text: string): boolean {
23142315
visible.split("\n").length > MAX_COLLAPSED_USER_MESSAGE_LINES
23152316
);
23162317
}
2318+
2319+
export function handoffRunsSignature(runs: ReadonlyArray<HandoffTimelineRun>): string {
2320+
return runs
2321+
.map(
2322+
(run) =>
2323+
`${run.id}\0${run.providerInstanceId}\0${run.ordinal}\0${run.modelSelection.instanceId}\0${run.modelSelection.model}`,
2324+
)
2325+
.join("\n");
2326+
}
2327+
2328+
// Expanded-id sets can be rebuilt during render; comparing them by content keeps
2329+
// the render-time state update in useIncrementalTimelineRows from repeating forever.
2330+
export function sameRowsInput(
2331+
left: MessagesTimelineRowsInput,
2332+
right: MessagesTimelineRowsInput,
2333+
): boolean {
2334+
for (const key of Object.keys(right) as Array<keyof MessagesTimelineRowsInput>) {
2335+
const previous = left[key];
2336+
const next = right[key];
2337+
if (Object.is(previous, next)) continue;
2338+
if (previous instanceof Set && next instanceof Set && shallow(previous, next)) continue;
2339+
return false;
2340+
}
2341+
return Object.keys(left).length === Object.keys(right).length;
2342+
}

0 commit comments

Comments
 (0)