zidane-ui 9.2.3 → 9.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/dist/adapters/live.d.ts +6 -0
  2. package/dist/adapters/live.js +16 -8
  3. package/dist/adapters/server-composer-host.js +22 -9
  4. package/dist/adapters/server-host.js +143 -18
  5. package/dist/adapters/server-media.d.ts +9 -1
  6. package/dist/adapters/server-media.js +14 -1
  7. package/dist/chat/HostTranscript.d.ts +0 -12
  8. package/dist/chat/HostTranscript.js +6 -1
  9. package/dist/chat/SessionStreamsProvider.d.ts +8 -0
  10. package/dist/chat/SessionStreamsProvider.js +11 -2
  11. package/dist/chat/Transcript.d.ts +20 -11
  12. package/dist/chat/Transcript.js +326 -160
  13. package/dist/chat/composer/ComposerEditor.js +1 -1
  14. package/dist/chat/headless/host.d.ts +43 -7
  15. package/dist/chat/headless/index.d.ts +7 -6
  16. package/dist/chat/headless/index.js +10 -9
  17. package/dist/chat/headless/labels.d.ts +17 -0
  18. package/dist/chat/headless/labels.js +17 -0
  19. package/dist/chat/headless/markdown-chunks.d.ts +2 -1
  20. package/dist/chat/headless/markdown-chunks.js +12 -20
  21. package/dist/chat/headless/markdown-scan.d.ts +66 -0
  22. package/dist/chat/headless/markdown-scan.js +124 -0
  23. package/dist/chat/headless/markdown-stream.d.ts +64 -0
  24. package/dist/chat/headless/markdown-stream.js +143 -0
  25. package/dist/chat/headless/output-pager.d.ts +68 -0
  26. package/dist/chat/headless/output-pager.js +113 -0
  27. package/dist/chat/headless/session-list.d.ts +10 -0
  28. package/dist/chat/headless/sidebar/activity.d.ts +14 -0
  29. package/dist/chat/headless/sidebar/activity.js +32 -0
  30. package/dist/chat/headless/sidebar/directory.d.ts +9 -1
  31. package/dist/chat/headless/sidebar/directory.js +10 -50
  32. package/dist/chat/headless/sidebar/labels.d.ts +11 -1
  33. package/dist/chat/headless/sidebar/prewarm.d.ts +68 -0
  34. package/dist/chat/headless/sidebar/prewarm.js +114 -0
  35. package/dist/chat/headless/streams/actions.d.ts +2 -0
  36. package/dist/chat/headless/streams/actions.js +1 -0
  37. package/dist/chat/headless/streams/event-bytes.d.ts +6 -0
  38. package/dist/chat/headless/streams/event-bytes.js +34 -0
  39. package/dist/chat/headless/streams/live-events.d.ts +25 -1
  40. package/dist/chat/headless/streams/live-events.js +53 -2
  41. package/dist/chat/headless/streams/selectors.d.ts +3 -0
  42. package/dist/chat/headless/streams/selectors.js +8 -1
  43. package/dist/chat/headless/streams/session-streams.d.ts +15 -3
  44. package/dist/chat/headless/streams/session-streams.js +31 -3
  45. package/dist/chat/headless/streams/store.d.ts +24 -1
  46. package/dist/chat/headless/streams/store.js +51 -26
  47. package/dist/chat/headless/streams/transcript-map.d.ts +57 -0
  48. package/dist/chat/headless/streams/transcript-map.js +88 -0
  49. package/dist/chat/headless/streams/transcript.d.ts +4 -2
  50. package/dist/chat/headless/streams/transcript.js +19 -7
  51. package/dist/chat/headless/transcript/batch.js +5 -1
  52. package/dist/chat/headless/transcript/blob-media.d.ts +15 -0
  53. package/dist/chat/headless/transcript/blob-media.js +23 -0
  54. package/dist/chat/headless/transcript/collapse.d.ts +10 -0
  55. package/dist/chat/headless/transcript/collapse.js +32 -6
  56. package/dist/chat/headless/transcript/derive.d.ts +98 -0
  57. package/dist/chat/headless/transcript/derive.js +89 -0
  58. package/dist/chat/headless/transcript/exchange-media.d.ts +3 -1
  59. package/dist/chat/headless/transcript/exchange-media.js +8 -5
  60. package/dist/chat/headless/transcript/fold-attachments.d.ts +2 -0
  61. package/dist/chat/headless/transcript/fold-attachments.js +3 -2
  62. package/dist/chat/headless/transcript/fold.d.ts +2 -1
  63. package/dist/chat/headless/transcript/fold.js +16 -6
  64. package/dist/chat/headless/transcript/incremental.d.ts +53 -0
  65. package/dist/chat/headless/transcript/incremental.js +181 -0
  66. package/dist/chat/headless/transcript/index.d.ts +2 -2
  67. package/dist/chat/headless/transcript/index.js +2 -2
  68. package/dist/chat/headless/transcript/nesting.js +2 -1
  69. package/dist/chat/headless/transcript/rail.d.ts +50 -1
  70. package/dist/chat/headless/transcript/rail.js +165 -23
  71. package/dist/chat/headless/transcript/rows.d.ts +5 -1
  72. package/dist/chat/headless/transcript/run-failures.js +2 -1
  73. package/dist/chat/headless/transcript/seams.d.ts +78 -0
  74. package/dist/chat/headless/transcript/seams.js +116 -0
  75. package/dist/chat/headless/transcript/tool-media.d.ts +6 -7
  76. package/dist/chat/headless/transcript/tool-media.js +27 -9
  77. package/dist/chat/index.d.ts +8 -7
  78. package/dist/chat/index.js +17 -16
  79. package/dist/chat/sidebar/SidebarFooter.d.ts +8 -5
  80. package/dist/chat/sidebar/SidebarFooter.js +6 -6
  81. package/dist/chat/testing/contract.d.ts +5 -3
  82. package/dist/chat/testing/contract.js +66 -1
  83. package/dist/chat/transcript/DiffLines.d.ts +6 -1
  84. package/dist/chat/transcript/DiffLines.js +35 -20
  85. package/dist/chat/transcript/EditDiffBlock.d.ts +5 -1
  86. package/dist/chat/transcript/EditDiffBlock.js +89 -30
  87. package/dist/chat/transcript/LazyRow.d.ts +40 -40
  88. package/dist/chat/transcript/LazyRow.js +101 -149
  89. package/dist/chat/transcript/MermaidDiagram.js +2 -1
  90. package/dist/chat/transcript/SubagentBlock.js +3 -2
  91. package/dist/chat/transcript/TranscriptRail.d.ts +25 -2
  92. package/dist/chat/transcript/TranscriptRail.js +175 -17
  93. package/dist/chat/transcript/TranscriptRow.d.ts +4 -7
  94. package/dist/chat/transcript/TranscriptRow.js +4 -3
  95. package/dist/chat/transcript/actions.d.ts +37 -1
  96. package/dist/chat/transcript/actions.js +27 -1
  97. package/dist/chat/transcript/clipped-output.d.ts +58 -0
  98. package/dist/chat/transcript/clipped-output.js +131 -0
  99. package/dist/chat/transcript/fold-attachments.js +10 -5
  100. package/dist/chat/transcript/fold-worker.js +3 -2
  101. package/dist/chat/transcript/fold.js +2 -1
  102. package/dist/chat/transcript/index.d.ts +10 -9
  103. package/dist/chat/transcript/index.js +9 -8
  104. package/dist/chat/transcript/markdown-cache.d.ts +7 -1
  105. package/dist/chat/transcript/markdown-cache.js +12 -1
  106. package/dist/chat/transcript/markdown.js +116 -54
  107. package/dist/chat/transcript/media-gallery.d.ts +3 -2
  108. package/dist/chat/transcript/media-gallery.js +10 -7
  109. package/dist/chat/transcript/notices.js +2 -1
  110. package/dist/chat/transcript/prompt.js +6 -4
  111. package/dist/chat/transcript/prose.js +2 -1
  112. package/dist/chat/transcript/root-items.d.ts +96 -0
  113. package/dist/chat/transcript/root-items.js +180 -0
  114. package/dist/chat/transcript/row-mount.d.ts +165 -0
  115. package/dist/chat/transcript/row-mount.js +498 -0
  116. package/dist/chat/transcript/row-parking.d.ts +125 -0
  117. package/dist/chat/transcript/row-parking.js +135 -0
  118. package/dist/chat/transcript/row-ui-state.d.ts +37 -0
  119. package/dist/chat/transcript/row-ui-state.js +53 -0
  120. package/dist/chat/transcript/run-rows.js +3 -2
  121. package/dist/chat/transcript/script-input.d.ts +1 -1
  122. package/dist/chat/transcript/tasks.js +3 -2
  123. package/dist/chat/transcript/tool-media.d.ts +4 -2
  124. package/dist/chat/transcript/tool-media.js +15 -7
  125. package/dist/chat/transcript/tool-parts.d.ts +27 -4
  126. package/dist/chat/transcript/tool-parts.js +31 -5
  127. package/dist/chat/transcript/tool-payload.js +26 -11
  128. package/dist/chat/transcript/tool-row.d.ts +2 -1
  129. package/dist/chat/transcript/tool-row.js +38 -19
  130. package/dist/chat/transcript/use-transcript-rows.d.ts +24 -7
  131. package/dist/chat/transcript/use-transcript-rows.js +28 -46
  132. package/dist/chat/transcript/useStickToBottom.js +2 -3
  133. package/dist/chat/transcript/useTranscriptSearch.js +30 -14
  134. package/dist/chat/transcript/view-scope.d.ts +26 -6
  135. package/dist/chat/transcript/view-scope.js +106 -20
  136. package/dist/dist/{index-E1Z0aPmi.d.ts → index-C6-t1SS9.d.ts} +2 -1
  137. package/dist/dist/index.d.ts +1 -1
  138. package/dist/session/SessionHeader.js +1 -0
  139. package/dist/settings/headless/fixture-performance.js +4 -2
  140. package/dist/settings/headless/performance.d.ts +4 -0
  141. package/dist/settings/headless/search.d.ts +1 -1
  142. package/dist/settings/sections/performance/PerformanceSection.js +8 -1
  143. package/dist/settings/sections/performance/labels.d.ts +2 -0
  144. package/dist/settings/sections/performance/labels.js +2 -0
  145. package/dist/styles.css +33 -2
  146. package/dist/views/headless/answers.d.ts +8 -2
  147. package/dist/views/headless/answers.js +58 -1
  148. package/dist/views/headless/placement.d.ts +78 -0
  149. package/dist/views/headless/placement.js +154 -44
  150. package/package.json +2 -2
  151. package/src/styles/transcript.css +33 -2
@@ -3,15 +3,17 @@ import { useExtensionItems } from "../extensions/ExtensionsProvider.js";
3
3
  import { LinkSessionScope } from "../extensions/links.js";
4
4
  import { ViewAnswers } from "../views/headless/answers.js";
5
5
  import { eventsMayHoldViews } from "../views/headless/placement.js";
6
- import { firstRowId } from "./headless/transcript/rows.js";
7
- import { rowTurnIds, stopForRow } from "./headless/transcript/select-stops.js";
6
+ import { stopForRow } from "./headless/transcript/select-stops.js";
8
7
  import { useTranscriptActions } from "./transcript/actions.js";
9
8
  import { DiagramsContext } from "./transcript/diagrams-scope.js";
10
9
  import { LiveScriptsContext } from "./transcript/fold.js";
11
10
  import { RowIconsContext } from "./transcript/frame.js";
12
- import { CvRow, TranscriptSettling } from "./transcript/LazyRow.js";
11
+ import { CvRow, LazyRow, TranscriptSettling, useForcedRows } from "./transcript/LazyRow.js";
13
12
  import { MediaGalleryProvider } from "./transcript/media-gallery.js";
14
- import { rowCvStyle, rowEstimatePx } from "./transcript/row-estimate.js";
13
+ import { endsByRow, groupRowId, matchingItems, rootItems } from "./transcript/root-items.js";
14
+ import { rowCvStyle } from "./transcript/row-estimate.js";
15
+ import { RowMountContext, RowMounter } from "./transcript/row-mount.js";
16
+ import { RowUiStateContext, createRowUiState } from "./transcript/row-ui-state.js";
15
17
  import { SelectCursor } from "./transcript/SelectCursor.js";
16
18
  import { SubagentBlock } from "./transcript/SubagentBlock.js";
17
19
  import { RailTint, useRailPublish } from "./transcript/TranscriptRail.js";
@@ -20,9 +22,51 @@ import { useSelectStops, useTranscriptRows } from "./transcript/use-transcript-r
20
22
  import { useTranscriptSelectionCopy } from "./transcript/useTranscriptSelectionCopy.js";
21
23
  import { CodemodeViewsSlot, ReplyViewPlaces, ViewsScopeContext, useViewsReady, viewsScopeOf } from "./transcript/view-scope.js";
22
24
  import { memo, useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";
23
- import { jsx, jsxs } from "react/jsx-runtime";
24
- import { DEFAULT_SETTINGS, runTailActivity } from "zidane/chat/pure";
25
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
26
+ import { DEFAULT_SETTINGS, chunkFact, runTailActivity, transcriptFromArray, transcriptOfArray } from "zidane/chat/pure";
25
27
  // src/chat/Transcript.tsx
28
+ const NO_SLICE = {
29
+ rows: [],
30
+ clusters: []
31
+ };
32
+ const NO_KEYS = [];
33
+ /** The tail that mounts with its first render: `EAGER_SCREENS` views' worth of rows (estimated), never fewer than `EAGER_MIN` rows nor more than `EAGER_MAX`. */
34
+ const EAGER_SCREENS = 1.5;
35
+ const EAGER_MIN = 6;
36
+ const EAGER_MAX = 40;
37
+ /** The keys of the transcript's tail, read from the end (a few items, whatever the length). */
38
+ function tailKeys(settled, open, sizeOf) {
39
+ const budget = (typeof window === "undefined" ? 1e3 : window.innerHeight) * EAGER_SCREENS;
40
+ const out = /* @__PURE__ */ new Set();
41
+ let rows = 0;
42
+ let px = 0;
43
+ for (let i = settled.length + open.length - 1; i >= 0; i--) {
44
+ const item = i >= settled.length ? open[i - settled.length] : settled[i];
45
+ out.add(item.key);
46
+ if (item.kind === "single" || item.kind === "group") {
47
+ rows++;
48
+ px += sizeOf(item.key) ?? item.estimate;
49
+ }
50
+ if (rows >= EAGER_MAX || rows >= EAGER_MIN && px >= budget) break;
51
+ }
52
+ return out;
53
+ }
54
+ /**
55
+ * The root rows before the transcript's flat run, behind one memoized fiber: a render that changes none of them
56
+ * (a stream tick) never walks them. The flat run after them starts where the open exchange started when the
57
+ * conversation showed, so a row never moves between the two (that would remount it).
58
+ */
59
+ const RowRun = memo(({ rows }) => /* @__PURE__ */ jsx(Fragment$1, { children: rows }));
60
+ RowRun.displayName = "RowRun";
61
+ /** Whether a transcript can hold a view (`eventsMayHoldViews`), each settled exchange read once. */
62
+ function mayHoldViews(transcript) {
63
+ return eventsMayHoldViews(transcript.tail) || transcript.chunks.some((chunk) => chunkFact(chunk, "may-hold-views", eventsMayHoldViews));
64
+ }
65
+ /** `runTailActivity` of the open exchange: its scan stops at the exchange's prompt, so the result is the whole transcript's. */
66
+ function tailActivity(transcript) {
67
+ const tail = transcript.tail.length > 0 || transcript.chunks.length === 0 ? transcript.tail : transcript.chunks.at(-1);
68
+ return runTailActivity(tail);
69
+ }
26
70
  /** zidane's defaults for those settings. */
27
71
  const DEFAULT_TRANSCRIPT_OPTIONS = {
28
72
  showRowIcons: DEFAULT_SETTINGS.showRowIcons,
@@ -47,45 +91,9 @@ const DEFAULT_TRANSCRIPT_OPTIONS = {
47
91
  viewsSave: DEFAULT_SETTINGS.viewsSave,
48
92
  viewsOrchestration: DEFAULT_SETTINGS.viewsOrchestration
49
93
  };
50
- /**
51
- * Top-level rows at the end of the transcript that mount at once (the rest
52
- * mount on approach, `LazyRow`): enough to fill the window when the session
53
- * opens pinned to the bottom, so the first frame shows real rows. Sized by
54
- * the rows' estimated heights (`EAGER_SCREENS` windows' worth), never fewer
55
- * than `EAGER_MIN` rows nor more than `EAGER_MAX`: mounting forty rows when
56
- * eight fill the window made every conversation switch pay for the other
57
- * thirty-two in its frame. Rows above mount next, from the viewport
58
- * observers, and the ones within a viewport of the view mount at once.
59
- */
60
- const EAGER_SCREENS = 1.5;
61
- const EAGER_MIN = 6;
62
- const EAGER_MAX = 40;
63
- /**
64
- * Index of the first root cluster that mounts at once (`EAGER_SCREENS`).
65
- *
66
- * @param list - The root clusters.
67
- * @param hidden - Rows that render nothing (they take no room).
68
- */
69
- function eagerTailStart(list, hidden) {
70
- const budget = (typeof window === "undefined" ? 1e3 : window.innerHeight) * EAGER_SCREENS;
71
- let px = 0;
72
- let rows = 0;
73
- for (let i = list.length - 1; i >= 0; i--) {
74
- const cluster = list[i];
75
- if (cluster.kind === "single") {
76
- if (hidden(cluster.row)) continue;
77
- px += rowEstimatePx(cluster.row);
78
- }
79
- rows++;
80
- if (rows >= EAGER_MAX || rows >= EAGER_MIN && px >= budget) return i;
81
- }
82
- return 0;
83
- }
84
94
  /** How long after a conversation first paints its rows count as already there. */
85
95
  const SETTLE_MS = 400;
86
- /** A subagent block's id among the rows: its first row's, not its position (a prepended page shifts every position). */
87
- const groupRowId = (cluster, index) => `group-${firstRowId(cluster) ?? index}-${cluster.childId}`;
88
- /** Renders a session's events as transcript rows: messages, tool calls grouped by the display options, subagent blocks, notices, and the select-turn cursor. Rows mount lazily as they near the viewport. */
96
+ /** Renders a session's events as transcript rows: messages, tool calls grouped by the display options, subagent blocks, notices, and the select-turn cursor. Rows mount as they near the view, and stay. */
89
97
  const Transcript = memo(({ events, streaming, sessionId, options, selection, turnMenu, runStatus, liveScripts = false, className, style, children }) => {
90
98
  const o = options ? {
91
99
  ...DEFAULT_TRANSCRIPT_OPTIONS,
@@ -95,6 +103,9 @@ const Transcript = memo(({ events, streaming, sessionId, options, selection, tur
95
103
  const showFullShellOutput = Boolean(o.showFullShellOutput);
96
104
  const collapseSubagents = o.hideSubagentOutput;
97
105
  const { openSession, resume } = useTranscriptActions();
106
+ const split = useRef(void 0);
107
+ const transcript = useMemo(() => Array.isArray(events) ? transcriptOfArray(events) ?? transcriptFromArray(events, split.current) : events, [events]);
108
+ split.current = transcript;
98
109
  const settle = useRef({
99
110
  sessionId: null,
100
111
  shown: false,
@@ -105,13 +116,13 @@ const Transcript = memo(({ events, streaming, sessionId, options, selection, tur
105
116
  shown: false,
106
117
  until: 0
107
118
  };
108
- const viewsReady = useViewsReady(o.views && !settle.current.shown && eventsMayHoldViews(events), sessionId);
109
- if (!settle.current.shown && events.length > 0 && viewsReady) {
119
+ const viewsReady = useViewsReady(o.views && !settle.current.shown && mayHoldViews(transcript), sessionId);
120
+ if (!settle.current.shown && transcript.length > 0 && viewsReady) {
110
121
  settle.current.shown = true;
111
122
  settle.current.until = performance.now() + SETTLE_MS;
112
123
  }
113
124
  const settling = useCallback(() => performance.now() < settle.current.until, []);
114
- const { visibleRows, receiptByRowId, resumableId, clusters, lastStreamingRow } = useTranscriptRows(events, streaming, {
125
+ const rows = useTranscriptRows(transcript, streaming, {
115
126
  showCacheNotices: o.showCacheNotices,
116
127
  codemodeShowCalls: o.codemodeShowCalls,
117
128
  showEditDiffs,
@@ -119,26 +130,49 @@ const Transcript = memo(({ events, streaming, sessionId, options, selection, tur
119
130
  showRunReceipt: o.showRunReceipt,
120
131
  compact: o.transcriptDensity === "compact"
121
132
  });
133
+ const { receiptByRowId, resumableId, lastStreamingRow } = rows;
134
+ const parts = rows.parts ?? {
135
+ settled: NO_SLICE,
136
+ open: {
137
+ rows: rows.visibleRows,
138
+ clusters: rows.clusters
139
+ }
140
+ };
141
+ const settledClusters = parts.settled.clusters;
142
+ const openClusters = parts.open.clusters;
122
143
  const slotEntries = useExtensionItems("slot");
144
+ const turnEndsPrev = useRef(null);
123
145
  const turnEnds = useMemo(() => {
124
146
  const wanted = /* @__PURE__ */ new Set();
125
147
  for (const { item } of slotEntries) if (item.at === "transcript.turn-end" && item.turnId && (item.sessionId === void 0 || item.sessionId === sessionId)) wanted.add(item.turnId);
126
148
  if (wanted.size === 0) return null;
127
- const lastRow = /* @__PURE__ */ new Map();
128
- for (const cluster of clusters) {
129
- if (cluster.kind !== "single") continue;
130
- for (const id of rowTurnIds(cluster.row)) if (wanted.has(id)) lastRow.set(id, cluster.row.id);
131
- }
132
- const byRow = /* @__PURE__ */ new Map();
133
- for (const [turnId, rowId] of lastRow) byRow.set(rowId, [...byRow.get(rowId) ?? [], turnId]);
134
- return byRow;
149
+ const ends = endsByRow({
150
+ settled: settledClusters,
151
+ open: openClusters
152
+ }, (at, add) => {
153
+ const byRow = /* @__PURE__ */ new Map();
154
+ for (const turnId of wanted) {
155
+ const where = at(turnId);
156
+ if (!where) continue;
157
+ const entry = byRow.get(where.rowId);
158
+ if (entry) entry.turns.push(turnId);
159
+ else byRow.set(where.rowId, {
160
+ where,
161
+ turns: [turnId]
162
+ });
163
+ }
164
+ for (const { where, turns } of byRow.values()) add(where, turns);
165
+ }, turnEndsPrev.current);
166
+ turnEndsPrev.current = ends;
167
+ return ends;
135
168
  }, [
136
169
  slotEntries,
137
170
  sessionId,
138
- clusters
171
+ settledClusters,
172
+ openClusters
139
173
  ]);
140
174
  const viewInputs = o.views && o.viewsInputs;
141
- const viewEvents = o.views ? events : null;
175
+ const viewEvents = o.views ? transcript : null;
142
176
  const [viewPlaces] = useState(() => new ReplyViewPlaces());
143
177
  const [viewAnswers] = useState(() => new ViewAnswers());
144
178
  useMemo(() => {
@@ -170,33 +204,37 @@ const Transcript = memo(({ events, streaming, sessionId, options, selection, tur
170
204
  o.viewsOrchestration
171
205
  ]);
172
206
  const textless = viewEvents ? viewPlaces.textlessExchanges : null;
207
+ const textlessPrev = useRef(null);
173
208
  const textlessEnds = useMemo(() => {
174
209
  if (!textless || !sessionId) return null;
175
210
  const exchanges = textless.filter((exchange) => exchange.closed || !streaming);
176
211
  if (exchanges.length === 0) return null;
177
- const lastRow = /* @__PURE__ */ new Map();
178
- for (const cluster of clusters) {
179
- if (cluster.kind !== "single") continue;
180
- for (const id of rowTurnIds(cluster.row)) lastRow.set(id, cluster.row.id);
181
- }
182
- const byRow = /* @__PURE__ */ new Map();
183
- for (const exchange of exchanges) {
184
- let rowId;
185
- for (const turnId of exchange.turns) rowId = lastRow.get(turnId) ?? rowId;
186
- if (rowId) byRow.set(rowId, exchange.turns);
187
- }
188
- return byRow;
212
+ const ends = endsByRow({
213
+ settled: settledClusters,
214
+ open: openClusters
215
+ }, (at, add) => {
216
+ for (const exchange of exchanges) {
217
+ let where;
218
+ for (const turnId of exchange.turns) where = at(turnId) ?? where;
219
+ if (where) add(where, exchange.turns);
220
+ }
221
+ }, textlessPrev.current);
222
+ textlessPrev.current = ends;
223
+ return ends;
189
224
  }, [
190
225
  textless,
191
226
  sessionId,
192
227
  streaming,
193
- clusters
228
+ settledClusters,
229
+ openClusters
194
230
  ]);
195
231
  const selectedTurnId = selection?.selected ?? null;
196
- const stops = useSelectStops(visibleRows, events, showThinking, selectedTurnId !== null, selection?.registerStops);
232
+ const stops = useSelectStops(rows, transcript, showThinking, selectedTurnId !== null, selection?.registerStops);
197
233
  const hiddenRow = useCallback((row) => isHiddenRow(row, showThinking), [showThinking]);
198
- const rail = useRailPublish(clusters, hiddenRow, receiptByRowId, selectedTurnId);
234
+ const rail = useRailPublish(parts, hiddenRow, receiptByRowId, selectedTurnId);
199
235
  const containerRef = useRef(null);
236
+ const timelineRef = useRef(null);
237
+ const [rowUiState] = useState(createRowUiState);
200
238
  const rowCtx = useMemo(() => ({
201
239
  sessionId,
202
240
  settings: {
@@ -224,7 +262,6 @@ const Transcript = memo(({ events, streaming, sessionId, options, selection, tur
224
262
  openSession,
225
263
  resume
226
264
  ]);
227
- const slotCache = useRef(/* @__PURE__ */ new Map());
228
265
  const groupCache = useRef(/* @__PURE__ */ new WeakMap());
229
266
  const renderClustersRef = useRef(() => []);
230
267
  const showRunReceipt = o.showRunReceipt;
@@ -238,8 +275,8 @@ const Transcript = memo(({ events, streaming, sessionId, options, selection, tur
238
275
  streaming,
239
276
  showRunReceipt
240
277
  ]);
241
- const renderFoldRows = useMemo(() => (list, lazy) => renderClustersRef.current(list, lazy), [foldEpoch]);
242
- const waiting = runStatus !== void 0 && streaming && runTailActivity(events) === "waiting";
278
+ const renderFoldRows = useMemo(() => (list) => renderClustersRef.current(list), [foldEpoch]);
279
+ const waiting = runStatus !== void 0 && streaming && tailActivity(transcript) === "waiting";
243
280
  const liveStatus = useMemo(() => runStatus && streaming ? {
244
281
  retry: runStatus.retry,
245
282
  waiting
@@ -248,27 +285,31 @@ const Transcript = memo(({ events, streaming, sessionId, options, selection, tur
248
285
  streaming,
249
286
  waiting
250
287
  ]);
251
- const rowProps = (row, root = false) => ({
288
+ const live = {
289
+ caret: lastStreamingRow,
290
+ receipts: receiptByRowId
291
+ };
292
+ const rowProps = (row, root = false, at = live) => ({
252
293
  row,
253
- showCaret: row === lastStreamingRow,
254
- receipt: receiptByRowId.get(row.id),
294
+ showCaret: row === at.caret,
295
+ receipt: at.receipts.get(row.id),
255
296
  resumable: row.id === resumableId,
256
297
  ctx: rowCtx,
257
298
  renderRows: row.kind === "exchange-fold" || row.kind === "message-group" ? renderFoldRows : void 0,
258
299
  status: root && row.kind === "exchange-fold" && row.live ? liveStatus : void 0
259
300
  });
260
- const groupDeps = (cluster, deps) => {
301
+ const groupDeps = (cluster, deps, at) => {
261
302
  for (const item of cluster.body) {
262
303
  if (item.kind === "group") {
263
- groupDeps(item, deps);
304
+ groupDeps(item, deps, at);
264
305
  continue;
265
306
  }
266
307
  const row = item.row;
267
- deps.push(row === lastStreamingRow, receiptByRowId.get(row.id), row.kind === "exchange-fold" || row.kind === "message-group" ? renderFoldRows : void 0);
308
+ deps.push(row === at.caret, at.receipts.get(row.id), row.kind === "exchange-fold" || row.kind === "message-group" ? renderFoldRows : void 0);
268
309
  }
269
310
  return deps;
270
311
  };
271
- const renderGroup = (cluster, ci, parentDepth) => {
312
+ const renderGroup = (cluster, ci, parentDepth, at = live) => {
272
313
  const key = groupRowId(cluster, ci);
273
314
  const deps = groupDeps(cluster, [
274
315
  key,
@@ -279,17 +320,17 @@ const Transcript = memo(({ events, streaming, sessionId, options, selection, tur
279
320
  showThinking,
280
321
  rowCtx,
281
322
  resumableId
282
- ]);
323
+ ], at);
283
324
  const hit = groupCache.current.get(cluster);
284
325
  if (hit && hit.deps.length === deps.length && hit.deps.every((d, i) => Object.is(d, deps[i]))) return hit.element;
285
- const element = buildGroup(cluster, key, parentDepth);
326
+ const element = buildGroup(cluster, key, at, parentDepth);
286
327
  groupCache.current.set(cluster, {
287
328
  deps,
288
329
  element
289
330
  });
290
331
  return element;
291
332
  };
292
- function buildGroup(cluster, key, parentDepth) {
333
+ function buildGroup(cluster, key, at, parentDepth) {
293
334
  return /* @__PURE__ */ jsx(SubagentBlock, {
294
335
  "data-row": key,
295
336
  childId: cluster.childId,
@@ -300,99 +341,216 @@ const Transcript = memo(({ events, streaming, sessionId, options, selection, tur
300
341
  defaultCollapsed: collapseSubagents,
301
342
  streaming,
302
343
  children: cluster.body.map((item, i) => {
303
- if (item.kind === "group") return renderGroup(item, i, cluster.depth);
344
+ if (item.kind === "group") return renderGroup(item, i, cluster.depth, at);
304
345
  const row = item.row;
305
346
  if (isHiddenRow(row, showThinking)) return null;
306
347
  return /* @__PURE__ */ jsx(CvRow, {
307
348
  style: rowCvStyle(row),
308
349
  "data-row": row.id,
309
- children: /* @__PURE__ */ jsx(TranscriptRow, { ...rowProps(row) })
350
+ children: /* @__PURE__ */ jsx(TranscriptRow, { ...rowProps(row, false, at) })
310
351
  }, row.id);
311
352
  })
312
353
  }, key);
313
354
  }
314
- const renderClusters = (list, lazy = false) => {
315
- const out = [];
316
- const nextSlotCache = lazy ? /* @__PURE__ */ new Map() : slotCache.current;
317
- const eagerFrom = lazy ? eagerTailStart(list, (row) => isHiddenRow(row, showThinking)) : 0;
318
- const textlessHere = lazy && sessionId ? textlessEnds : null;
319
- const renderSingle = (cluster, ci) => {
320
- if (isHiddenRow(cluster.row, showThinking)) return;
321
- const stop = stops ? stopForRow(cluster.row, stops) : null;
322
- const sel = stop !== null && stop === selectedTurnId ? "" : void 0;
323
- if (lazy) {
324
- const props = rowProps(cluster.row, true);
325
- const eager = ci >= eagerFrom;
326
- const deps = [
327
- props.row,
328
- props.showCaret,
329
- props.receipt,
330
- props.resumable,
331
- props.ctx,
332
- props.renderRows,
333
- props.status,
334
- eager,
335
- stop,
336
- sel
337
- ];
338
- const hit = slotCache.current.get(cluster.row.id);
339
- const element = hit && hit.deps.every((d, i) => Object.is(d, deps[i])) ? hit.element : /* @__PURE__ */ jsx(TranscriptRowSlot, {
340
- eager,
341
- estimatePx: rowEstimatePx(cluster.row),
342
- style: rowCvStyle(cluster.row),
343
- stop: stop ?? void 0,
344
- sel,
345
- ...props
346
- }, cluster.row.id);
347
- nextSlotCache.set(cluster.row.id, {
348
- deps,
349
- element
350
- });
351
- out.push(element);
352
- return;
353
- }
354
- out.push(/* @__PURE__ */ jsx(CvRow, {
355
- style: rowCvStyle(cluster.row),
356
- "data-stop": stop ?? void 0,
357
- "data-sel": sel,
358
- "data-row": cluster.row.id,
359
- children: /* @__PURE__ */ jsx(TranscriptRow, { ...rowProps(cluster.row) })
360
- }, cluster.row.id));
361
- };
362
- list.forEach((cluster, ci) => {
363
- if (cluster.kind === "single") {
364
- renderSingle(cluster, ci);
365
- const textless = textlessHere?.get(cluster.row.id);
366
- if (textless) out.push(/* @__PURE__ */ jsx("div", {
367
- className: "pl-2 pr-1",
368
- children: /* @__PURE__ */ jsx(CodemodeViewsSlot, {
369
- sessionId,
370
- turns: textless
371
- })
372
- }, `views-end:${cluster.row.id}`));
373
- const ends = lazy && sessionId ? turnEnds?.get(cluster.row.id) : void 0;
374
- for (const turnId of ends ?? []) out.push(/* @__PURE__ */ jsx(ExtensionSlot, {
375
- at: "transcript.turn-end",
355
+ /** A fold's or a message group's rows: the same rows, always mounted (their fold is). */
356
+ const renderClusters = (list) => list.map((cluster, ci) => {
357
+ if (cluster.kind === "group") return renderGroup(cluster, ci);
358
+ const row = cluster.row;
359
+ if (isHiddenRow(row, showThinking)) return null;
360
+ const stop = stops ? stopForRow(row, stops) : null;
361
+ return /* @__PURE__ */ jsx(CvRow, {
362
+ style: rowCvStyle(row),
363
+ "data-stop": stop ?? void 0,
364
+ "data-sel": stop !== null && stop === selectedTurnId ? "" : void 0,
365
+ "data-row": row.id,
366
+ children: /* @__PURE__ */ jsx(TranscriptRow, { ...rowProps(row) })
367
+ }, row.id);
368
+ });
369
+ const settledTextless = textlessEnds?.settled ?? null;
370
+ const settledTurnEnds = turnEnds?.settled ?? null;
371
+ const openTextless = textlessEnds?.open ?? null;
372
+ const openTurnEnds = turnEnds?.open ?? null;
373
+ const settledItems = useMemo(() => rootItems(settledClusters, hiddenRow, collapseSubagents, sessionId ? settledTextless : null, sessionId ? settledTurnEnds : null), [
374
+ settledClusters,
375
+ hiddenRow,
376
+ collapseSubagents,
377
+ sessionId,
378
+ settledTextless,
379
+ settledTurnEnds
380
+ ]);
381
+ const openItems = useMemo(() => rootItems(openClusters, hiddenRow, collapseSubagents, sessionId ? openTextless : null, sessionId ? openTurnEnds : null, settledClusters.length), [
382
+ openClusters,
383
+ hiddenRow,
384
+ collapseSubagents,
385
+ sessionId,
386
+ openTextless,
387
+ openTurnEnds,
388
+ settledClusters.length
389
+ ]);
390
+ const forced = useForcedRows();
391
+ const settledMatches = useMemo(() => matchingItems(settledItems, forced.needles), [settledItems, forced]);
392
+ const openMatches = useMemo(() => matchingItems(openItems, forced.needles), [openItems, forced]);
393
+ const selectKeys = (list) => !stops || selectedTurnId === null ? NO_KEYS : list.filter((item) => item.kind === "single" && stopForRow(item.cluster.row, stops) === selectedTurnId).map((item) => item.key);
394
+ const settledSelect = useMemo(() => selectKeys(settledItems), [
395
+ settledItems,
396
+ stops,
397
+ selectedTurnId
398
+ ]);
399
+ const openSelect = useMemo(() => selectKeys(openItems), [
400
+ openItems,
401
+ stops,
402
+ selectedTurnId
403
+ ]);
404
+ const held = useMemo(() => [
405
+ ...settledMatches,
406
+ ...openMatches,
407
+ ...settledSelect,
408
+ ...openSelect
409
+ ], [
410
+ settledMatches,
411
+ openMatches,
412
+ settledSelect,
413
+ openSelect
414
+ ]);
415
+ const [mounter] = useState(() => new RowMounter());
416
+ mounter.reset(sessionId);
417
+ const eager = useMemo(() => tailKeys(settledItems, openItems, (key) => mounter.sizeOf(key)), [
418
+ settledItems,
419
+ openItems,
420
+ mounter
421
+ ]);
422
+ const liveKeys = useMemo(() => new Set(openItems.map((item) => item.key)), [openItems]);
423
+ mounter.setTail(eager, liveKeys);
424
+ useLayoutEffect(() => mounter.hold(held, forced.all), [
425
+ mounter,
426
+ held,
427
+ forced.all
428
+ ]);
429
+ useLayoutEffect(() => () => mounter.dispose(), [mounter]);
430
+ const settledCache = useRef(/* @__PURE__ */ new Map());
431
+ const openCache = useRef(/* @__PURE__ */ new Map());
432
+ const rootElement = (item, at, out) => {
433
+ let deps;
434
+ let make;
435
+ if (item.kind === "group") {
436
+ const group = renderGroup(item.cluster, item.ci, void 0, at);
437
+ deps = [group];
438
+ make = () => /* @__PURE__ */ jsx(LazyRow, {
439
+ itemKey: item.key,
440
+ estimatePx: item.estimate,
441
+ box: true,
442
+ children: group
443
+ }, item.key);
444
+ } else if (item.kind === "views-end") {
445
+ deps = [sessionId, item.turns];
446
+ make = () => /* @__PURE__ */ jsx("div", {
447
+ className: "pl-2 pr-1",
448
+ children: /* @__PURE__ */ jsx(CodemodeViewsSlot, {
376
449
  sessionId,
377
- turnId,
378
- className: "py-1"
379
- }, `turn-end:${turnId}`));
380
- return;
381
- }
382
- out.push(renderGroup(cluster, ci));
450
+ turns: item.turns
451
+ })
452
+ }, item.key);
453
+ } else if (item.kind === "turn-end") {
454
+ deps = [sessionId, item.turnId];
455
+ make = () => /* @__PURE__ */ jsx(ExtensionSlot, {
456
+ at: "transcript.turn-end",
457
+ sessionId,
458
+ turnId: item.turnId,
459
+ className: "py-1"
460
+ }, item.key);
461
+ } else {
462
+ const row = item.cluster.row;
463
+ const stop = stops ? stopForRow(row, stops) : null;
464
+ const sel = stop !== null && stop === selectedTurnId ? "" : void 0;
465
+ const props = rowProps(row, true, at);
466
+ deps = [
467
+ props.row,
468
+ props.showCaret,
469
+ props.receipt,
470
+ props.resumable,
471
+ props.ctx,
472
+ props.renderRows,
473
+ props.status,
474
+ stop,
475
+ sel
476
+ ];
477
+ make = () => /* @__PURE__ */ jsx(TranscriptRowSlot, {
478
+ style: rowCvStyle(row),
479
+ stop: stop ?? void 0,
480
+ sel,
481
+ ...props
482
+ }, row.id);
483
+ }
484
+ const hit = openCache.current.get(item.key) ?? settledCache.current.get(item.key);
485
+ const element = hit && hit.deps.length === deps.length && hit.deps.every((d, i) => Object.is(d, deps[i])) ? hit.element : make();
486
+ out.set(item.key, {
487
+ deps,
488
+ element
383
489
  });
384
- if (lazy) slotCache.current = nextSlotCache;
385
- return out;
490
+ return element;
491
+ };
492
+ const settledRowSet = useMemo(() => new WeakSet(parts.settled.rows), [parts.settled.rows]);
493
+ const settledCaret = lastStreamingRow && settledRowSet.has(lastStreamingRow) ? lastStreamingRow : null;
494
+ const settledReceipts = parts.settled.receipts ?? receiptByRowId;
495
+ const settledLive = useMemo(() => ({
496
+ caret: settledCaret,
497
+ receipts: settledReceipts
498
+ }), [settledCaret, settledReceipts]);
499
+ const settledEls = useMemo(() => {
500
+ const next = /* @__PURE__ */ new Map();
501
+ const els = settledItems.map((item) => rootElement(item, settledLive, next));
502
+ settledCache.current = next;
503
+ return els;
504
+ }, [
505
+ settledItems,
506
+ settledLive,
507
+ rowCtx,
508
+ stops,
509
+ selectedTurnId,
510
+ resumableId,
511
+ renderFoldRows,
512
+ liveStatus,
513
+ sessionId,
514
+ showThinking,
515
+ collapseSubagents,
516
+ streaming
517
+ ]);
518
+ const openNext = /* @__PURE__ */ new Map();
519
+ const openEls = openItems.map((item) => rootElement(item, live, openNext));
520
+ openCache.current = openNext;
521
+ const runStart = useRef({
522
+ sessionId,
523
+ key: null
524
+ });
525
+ if (runStart.current.sessionId !== sessionId) runStart.current = {
526
+ sessionId,
527
+ key: null
386
528
  };
529
+ if (runStart.current.key === null && openItems.length > 0) runStart.current.key = openItems[0].key;
530
+ const runKey = runStart.current.key;
531
+ const foundAt = useMemo(() => {
532
+ if (runKey !== null) {
533
+ for (let i = settledItems.length - 1; i >= 0; i--) if (settledItems[i].key === runKey) return i;
534
+ }
535
+ return -1;
536
+ }, [settledItems, runKey]);
537
+ if (runKey !== null && foundAt < 0 && !openItems.some((item) => item.key === runKey)) runStart.current.key = openItems[0]?.key ?? null;
538
+ const runAt = foundAt < 0 ? settledItems.length : foundAt;
539
+ const prefixEls = useMemo(() => runAt === settledEls.length ? settledEls : settledEls.slice(0, runAt), [settledEls, runAt]);
540
+ const flatSettled = useMemo(() => runAt === settledEls.length ? [] : settledEls.slice(runAt), [settledEls, runAt]);
387
541
  renderClustersRef.current = renderClusters;
388
- const rootRows = renderClusters(clusters, true);
542
+ const rootRows = [
543
+ /* @__PURE__ */ jsx(RowRun, { rows: prefixEls }, "\0run"),
544
+ ...flatSettled,
545
+ ...openEls
546
+ ];
389
547
  useTranscriptSelectionCopy(containerRef);
390
548
  return /* @__PURE__ */ jsx(TranscriptSettling.Provider, {
391
549
  value: settling,
392
550
  children: /* @__PURE__ */ jsx(LiveScriptsContext.Provider, {
393
551
  value: liveScripts,
394
552
  children: /* @__PURE__ */ jsx(MediaGalleryProvider, {
395
- events,
553
+ events: transcript,
396
554
  children: /* @__PURE__ */ jsx(RowIconsContext.Provider, {
397
555
  value: o.showRowIcons,
398
556
  children: /* @__PURE__ */ jsx(DiagramsContext.Provider, {
@@ -407,17 +565,25 @@ const Transcript = memo(({ events, streaming, sessionId, options, selection, tur
407
565
  style,
408
566
  children: [
409
567
  /* @__PURE__ */ jsxs("div", {
568
+ ref: timelineRef,
410
569
  className: "zg-timeline relative pl-2 pr-1 py-1",
570
+ "data-vitems": settledItems.length + openItems.length,
411
571
  children: [
412
572
  /* @__PURE__ */ jsx(SelectCursor, {
413
573
  selected: selectedTurnId,
414
574
  layout: stops
415
575
  }),
416
576
  rail && /* @__PURE__ */ jsx(RailTint, { store: rail }),
417
- viewsReady || settle.current.shown ? rootRows : null
577
+ /* @__PURE__ */ jsx(RowUiStateContext.Provider, {
578
+ value: rowUiState,
579
+ children: /* @__PURE__ */ jsx(RowMountContext.Provider, {
580
+ value: mounter,
581
+ children: viewsReady || settle.current.shown ? rootRows : null
582
+ })
583
+ })
418
584
  ]
419
585
  }),
420
- sessionId && !streaming && events.length > 0 && /* @__PURE__ */ jsx(ExtensionSlot, {
586
+ sessionId && !streaming && transcript.length > 0 && /* @__PURE__ */ jsx(ExtensionSlot, {
421
587
  at: "transcript.turn-end",
422
588
  sessionId,
423
589
  className: "pl-2 pr-1 py-1"
@@ -2,8 +2,8 @@ import { plainTextToDocJson } from "./prompt-history-nav.js";
2
2
  import { suggestionExtension } from "./suggestion-extension.js";
3
3
  import { useLayoutEffect } from "react";
4
4
  import { jsx } from "react/jsx-runtime";
5
- import Placeholder from "@tiptap/extension-placeholder";
6
5
  import { EditorContent, useEditor } from "@tiptap/react";
6
+ import Placeholder from "@tiptap/extension-placeholder";
7
7
  import StarterKit from "@tiptap/starter-kit";
8
8
  // src/chat/composer/ComposerEditor.tsx
9
9
  /** Builds the composer's editor and renders its view. */