|
8 | 8 | collectAssistantCitations, |
9 | 9 | } from "@t3tools/shared/assistantCitations"; |
10 | 10 | import { shallow } from "zustand/vanilla/shallow"; |
| 11 | +import type { HandoffTimelineRun } from "@t3tools/client-runtime/handoff"; |
11 | 12 | import { renderCodexDirectivesForCopy } from "@t3tools/shared/codexMarkdownDirectives"; |
12 | 13 | import { |
13 | 14 | commandDisplayText, |
@@ -2011,7 +2012,7 @@ function attachCreatedThreadSummaries( |
2011 | 2012 |
|
2012 | 2013 | const WORKTREE_SETUP_ROW_ID = "worktree-setup-row"; |
2013 | 2014 |
|
2014 | | -type MessagesTimelineRowsInput = Parameters<typeof deriveMessagesTimelineRows>[0]; |
| 2015 | +export type MessagesTimelineRowsInput = Parameters<typeof deriveMessagesTimelineRows>[0]; |
2015 | 2016 |
|
2016 | 2017 | export interface MessagesTimelineRowsProjection { |
2017 | 2018 | readonly input: MessagesTimelineRowsInput; |
@@ -2314,3 +2315,28 @@ export function shouldCollapseUserMessage(text: string): boolean { |
2314 | 2315 | visible.split("\n").length > MAX_COLLAPSED_USER_MESSAGE_LINES |
2315 | 2316 | ); |
2316 | 2317 | } |
| 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