zidane-ui 9.2.3 → 9.4.0

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 (354) hide show
  1. package/dist/adapters/live.d.ts +8 -0
  2. package/dist/adapters/live.js +19 -8
  3. package/dist/adapters/server-composer-host.js +22 -9
  4. package/dist/adapters/server-git-host.js +5 -2
  5. package/dist/adapters/server-host.js +158 -27
  6. package/dist/adapters/server-machines-host.js +7 -0
  7. package/dist/adapters/server-media.d.ts +9 -1
  8. package/dist/adapters/server-media.js +14 -1
  9. package/dist/adapters/server-session-host.js +49 -0
  10. package/dist/adapters/server-settings-sections.js +4 -1
  11. package/dist/adapters/sse-host.js +3 -0
  12. package/dist/adapters/sse-protocol.d.ts +10 -0
  13. package/dist/appearance/ZoomIndicator.js +5 -8
  14. package/dist/chat/HostTranscript.d.ts +0 -12
  15. package/dist/chat/HostTranscript.js +20 -1
  16. package/dist/chat/SessionStreamsProvider.d.ts +9 -1
  17. package/dist/chat/SessionStreamsProvider.js +11 -2
  18. package/dist/chat/Transcript.d.ts +21 -11
  19. package/dist/chat/Transcript.js +346 -161
  20. package/dist/chat/composer/ModelOptionsPicker.js +6 -2
  21. package/dist/chat/composer/ModelPicker.d.ts +1 -1
  22. package/dist/chat/composer/PlacePicker.d.ts +3 -1
  23. package/dist/chat/composer/PlacePicker.js +5 -1
  24. package/dist/chat/composer/use-draft-target.js +15 -3
  25. package/dist/chat/headless/block-runs.js +26 -1
  26. package/dist/chat/headless/chip-views.js +1 -1
  27. package/dist/chat/headless/draft-target.d.ts +28 -1
  28. package/dist/chat/headless/draft-target.js +22 -1
  29. package/dist/chat/headless/host.d.ts +43 -7
  30. package/dist/chat/headless/hosts.d.ts +4 -0
  31. package/dist/chat/headless/index.d.ts +27 -26
  32. package/dist/chat/headless/index.js +15 -14
  33. package/dist/chat/headless/labels.d.ts +17 -0
  34. package/dist/chat/headless/labels.js +17 -0
  35. package/dist/chat/headless/markdown-chunks.d.ts +2 -1
  36. package/dist/chat/headless/markdown-chunks.js +12 -20
  37. package/dist/chat/headless/markdown-scan.d.ts +64 -0
  38. package/dist/chat/headless/markdown-scan.js +119 -0
  39. package/dist/chat/headless/markdown-stream.d.ts +64 -0
  40. package/dist/chat/headless/markdown-stream.js +143 -0
  41. package/dist/chat/headless/output-pager.d.ts +68 -0
  42. package/dist/chat/headless/output-pager.js +113 -0
  43. package/dist/chat/headless/prompt-origin.d.ts +2 -0
  44. package/dist/chat/headless/prompt-origin.js +6 -2
  45. package/dist/chat/headless/session-list.d.ts +10 -0
  46. package/dist/chat/headless/sidebar/activity.d.ts +14 -0
  47. package/dist/chat/headless/sidebar/activity.js +32 -0
  48. package/dist/chat/headless/sidebar/directory.d.ts +19 -2
  49. package/dist/chat/headless/sidebar/directory.js +19 -51
  50. package/dist/chat/headless/sidebar/environment.d.ts +15 -4
  51. package/dist/chat/headless/sidebar/environment.js +27 -9
  52. package/dist/chat/headless/sidebar/index.d.ts +2 -2
  53. package/dist/chat/headless/sidebar/index.js +2 -2
  54. package/dist/chat/headless/sidebar/labels.d.ts +19 -2
  55. package/dist/chat/headless/sidebar/labels.js +8 -1
  56. package/dist/chat/headless/sidebar/prewarm.d.ts +68 -0
  57. package/dist/chat/headless/sidebar/prewarm.js +114 -0
  58. package/dist/chat/headless/streams/actions.d.ts +4 -2
  59. package/dist/chat/headless/streams/actions.js +2 -1
  60. package/dist/chat/headless/streams/event-bytes.d.ts +17 -0
  61. package/dist/chat/headless/streams/event-bytes.js +46 -0
  62. package/dist/chat/headless/streams/live-events.d.ts +25 -1
  63. package/dist/chat/headless/streams/live-events.js +53 -2
  64. package/dist/chat/headless/streams/selectors.d.ts +3 -0
  65. package/dist/chat/headless/streams/selectors.js +8 -1
  66. package/dist/chat/headless/streams/session-streams.d.ts +15 -3
  67. package/dist/chat/headless/streams/session-streams.js +31 -3
  68. package/dist/chat/headless/streams/store.d.ts +45 -6
  69. package/dist/chat/headless/streams/store.js +85 -31
  70. package/dist/chat/headless/streams/transcript-map.d.ts +57 -0
  71. package/dist/chat/headless/streams/transcript-map.js +85 -0
  72. package/dist/chat/headless/streams/transcript.d.ts +4 -2
  73. package/dist/chat/headless/streams/transcript.js +19 -7
  74. package/dist/chat/headless/streams/types.d.ts +2 -1
  75. package/dist/chat/headless/transcript/batch.js +5 -1
  76. package/dist/chat/headless/transcript/blob-media.d.ts +15 -0
  77. package/dist/chat/headless/transcript/blob-media.js +23 -0
  78. package/dist/chat/headless/transcript/collapse.d.ts +10 -0
  79. package/dist/chat/headless/transcript/collapse.js +35 -6
  80. package/dist/chat/headless/transcript/derive.d.ts +98 -0
  81. package/dist/chat/headless/transcript/derive.js +89 -0
  82. package/dist/chat/headless/transcript/exchange-media.d.ts +3 -1
  83. package/dist/chat/headless/transcript/exchange-media.js +8 -5
  84. package/dist/chat/headless/transcript/fold-attachments.d.ts +2 -0
  85. package/dist/chat/headless/transcript/fold-attachments.js +3 -2
  86. package/dist/chat/headless/transcript/fold.d.ts +2 -1
  87. package/dist/chat/headless/transcript/fold.js +16 -6
  88. package/dist/chat/headless/transcript/incremental.d.ts +53 -0
  89. package/dist/chat/headless/transcript/incremental.js +181 -0
  90. package/dist/chat/headless/transcript/index.d.ts +2 -2
  91. package/dist/chat/headless/transcript/index.js +2 -2
  92. package/dist/chat/headless/transcript/nesting.js +2 -1
  93. package/dist/chat/headless/transcript/rail.d.ts +50 -1
  94. package/dist/chat/headless/transcript/rail.js +165 -23
  95. package/dist/chat/headless/transcript/rows.d.ts +5 -1
  96. package/dist/chat/headless/transcript/run-failures.js +2 -1
  97. package/dist/chat/headless/transcript/seams.d.ts +78 -0
  98. package/dist/chat/headless/transcript/seams.js +116 -0
  99. package/dist/chat/headless/transcript/tool-media.d.ts +6 -7
  100. package/dist/chat/headless/transcript/tool-media.js +27 -9
  101. package/dist/chat/index.d.ts +9 -8
  102. package/dist/chat/index.js +18 -17
  103. package/dist/chat/sidebar/ProjectIcon.js +1 -1
  104. package/dist/chat/sidebar/RowChips.js +2 -2
  105. package/dist/chat/sidebar/SessionSidebar.d.ts +6 -0
  106. package/dist/chat/sidebar/SessionSidebar.js +23 -16
  107. package/dist/chat/sidebar/SidebarFilterMenu.js +0 -1
  108. package/dist/chat/sidebar/SidebarFold.js +17 -16
  109. package/dist/chat/sidebar/SidebarFooter.d.ts +8 -5
  110. package/dist/chat/sidebar/SidebarFooter.js +6 -6
  111. package/dist/chat/sidebar/SidebarSessionRow.d.ts +7 -1
  112. package/dist/chat/sidebar/SidebarSessionRow.js +11 -8
  113. package/dist/chat/sidebar/session-menu.d.ts +4 -0
  114. package/dist/chat/sidebar/session-menu.js +14 -2
  115. package/dist/chat/sidebar/sidebar-live.js +28 -4
  116. package/dist/chat/sidebar/useInboxRows.js +6 -6
  117. package/dist/chat/sidebar/useInboxTriage.js +50 -47
  118. package/dist/chat/sidebar/useSessionSearch.js +19 -18
  119. package/dist/chat/testing/contract.d.ts +5 -3
  120. package/dist/chat/testing/contract.js +66 -1
  121. package/dist/chat/transcript/DiffLines.d.ts +6 -1
  122. package/dist/chat/transcript/DiffLines.js +35 -20
  123. package/dist/chat/transcript/EditDiffBlock.d.ts +5 -1
  124. package/dist/chat/transcript/EditDiffBlock.js +89 -30
  125. package/dist/chat/transcript/FileChip.js +28 -0
  126. package/dist/chat/transcript/LazyRow.d.ts +40 -40
  127. package/dist/chat/transcript/LazyRow.js +100 -149
  128. package/dist/chat/transcript/MermaidDiagram.js +2 -1
  129. package/dist/chat/transcript/PromptEcho.js +3 -11
  130. package/dist/chat/transcript/SessionChip.d.ts +11 -0
  131. package/dist/chat/transcript/SessionChip.js +34 -0
  132. package/dist/chat/transcript/SubagentBlock.js +3 -2
  133. package/dist/chat/transcript/TranscriptRail.d.ts +25 -2
  134. package/dist/chat/transcript/TranscriptRail.js +175 -17
  135. package/dist/chat/transcript/TranscriptRow.d.ts +4 -7
  136. package/dist/chat/transcript/TranscriptRow.js +4 -3
  137. package/dist/chat/transcript/actions.d.ts +37 -1
  138. package/dist/chat/transcript/actions.js +27 -1
  139. package/dist/chat/transcript/chip-details.d.ts +11 -0
  140. package/dist/chat/transcript/chip-details.js +17 -1
  141. package/dist/chat/transcript/clipped-output.d.ts +58 -0
  142. package/dist/chat/transcript/clipped-output.js +131 -0
  143. package/dist/chat/transcript/fold-attachments.js +10 -5
  144. package/dist/chat/transcript/fold-worker.js +5 -3
  145. package/dist/chat/transcript/fold.js +13 -4
  146. package/dist/chat/transcript/index.d.ts +11 -10
  147. package/dist/chat/transcript/index.js +10 -9
  148. package/dist/chat/transcript/markdown-cache.d.ts +17 -2
  149. package/dist/chat/transcript/markdown-cache.js +48 -4
  150. package/dist/chat/transcript/markdown.js +110 -55
  151. package/dist/chat/transcript/media-gallery.d.ts +3 -2
  152. package/dist/chat/transcript/media-gallery.js +19 -19
  153. package/dist/chat/transcript/messages.js +5 -4
  154. package/dist/chat/transcript/notices.js +2 -1
  155. package/dist/chat/transcript/prompt.d.ts +1 -1
  156. package/dist/chat/transcript/prompt.js +6 -4
  157. package/dist/chat/transcript/prose.js +2 -1
  158. package/dist/chat/transcript/root-items.d.ts +96 -0
  159. package/dist/chat/transcript/root-items.js +180 -0
  160. package/dist/chat/transcript/row-mount.d.ts +184 -0
  161. package/dist/chat/transcript/row-mount.js +532 -0
  162. package/dist/chat/transcript/row-parking.d.ts +152 -0
  163. package/dist/chat/transcript/row-parking.js +171 -0
  164. package/dist/chat/transcript/row-ui-state.d.ts +37 -0
  165. package/dist/chat/transcript/row-ui-state.js +53 -0
  166. package/dist/chat/transcript/run-rows.js +3 -2
  167. package/dist/chat/transcript/script-input.d.ts +1 -1
  168. package/dist/chat/transcript/tasks.js +3 -2
  169. package/dist/chat/transcript/tool-media.d.ts +4 -2
  170. package/dist/chat/transcript/tool-media.js +15 -7
  171. package/dist/chat/transcript/tool-parts.d.ts +27 -4
  172. package/dist/chat/transcript/tool-parts.js +31 -6
  173. package/dist/chat/transcript/tool-payload.js +26 -11
  174. package/dist/chat/transcript/tool-row.d.ts +2 -1
  175. package/dist/chat/transcript/tool-row.js +38 -19
  176. package/dist/chat/transcript/use-transcript-rows.d.ts +25 -8
  177. package/dist/chat/transcript/use-transcript-rows.js +28 -46
  178. package/dist/chat/transcript/useHistoryBackfill.d.ts +42 -0
  179. package/dist/chat/transcript/useHistoryBackfill.js +170 -0
  180. package/dist/chat/transcript/useStickToBottom.js +2 -3
  181. package/dist/chat/transcript/useTranscriptFind.js +2 -4
  182. package/dist/chat/transcript/useTranscriptScroll.d.ts +7 -4
  183. package/dist/chat/transcript/useTranscriptScroll.js +12 -1
  184. package/dist/chat/transcript/useTranscriptSearch.d.ts +2 -2
  185. package/dist/chat/transcript/useTranscriptSearch.js +35 -19
  186. package/dist/chat/transcript/useTranscriptSelectionCopy.d.ts +5 -5
  187. package/dist/chat/transcript/useTranscriptSelectionCopy.js +28 -7
  188. package/dist/chat/transcript/view-scope.d.ts +26 -6
  189. package/dist/chat/transcript/view-scope.js +106 -20
  190. package/dist/code/editor/FileTree.d.ts +2 -0
  191. package/dist/code/editor/FileTree.js +1 -1
  192. package/dist/code/editor/FileView.js +16 -25
  193. package/dist/code/editor/find/useFind.js +17 -17
  194. package/dist/code/editor/useCodeDocument.js +22 -19
  195. package/dist/code/editor/useDetachCleanup.js +4 -3
  196. package/dist/code/use-highlighted-html.js +12 -13
  197. package/dist/components/IconButton.d.ts +3 -1
  198. package/dist/components/IconButton.js +7 -2
  199. package/dist/components/IconButtonTip.d.ts +3 -1
  200. package/dist/components/IconButtonTip.js +2 -1
  201. package/dist/components/RowActionsMenu.js +7 -14
  202. package/dist/components/Tooltip.d.ts +4 -1
  203. package/dist/components/Tooltip.js +8 -6
  204. package/dist/components/assign-ref.d.ts +8 -0
  205. package/dist/components/assign-ref.js +12 -0
  206. package/dist/components/floating/FloatingSurface.js +2 -2
  207. package/dist/components/floating/HoverCard.js +32 -14
  208. package/dist/components/floating/Popover.js +4 -7
  209. package/dist/components/floating/useAnchoredPosition.d.ts +5 -3
  210. package/dist/components/floating/useAnchoredPosition.js +7 -7
  211. package/dist/components/object-key.d.ts +7 -0
  212. package/dist/components/object-key.js +18 -0
  213. package/dist/components/palette/PaletteList.js +2 -7
  214. package/dist/components/tooltip-arming.d.ts +3 -0
  215. package/dist/components/tooltip-arming.js +8 -1
  216. package/dist/core.css +3 -3
  217. package/dist/dist/{index-E1Z0aPmi.d.ts → index-BheVJOLc.d.ts} +3 -1
  218. package/dist/dist/index.d.ts +2 -2
  219. package/dist/files/FilesTab.js +0 -1
  220. package/dist/files/TreeColumn.d.ts +2 -4
  221. package/dist/files/TreeColumn.js +0 -5
  222. package/dist/files/headless/host.d.ts +3 -7
  223. package/dist/files/headless/labels.d.ts +0 -1
  224. package/dist/files/headless/labels.js +0 -1
  225. package/dist/files/headless/workspace-diff.js +1 -1
  226. package/dist/files/useCodeReview.js +1 -3
  227. package/dist/files/useFilesDiagnostics.d.ts +1 -1
  228. package/dist/files/useFilesDiagnostics.js +4 -11
  229. package/dist/files/useOpenFiles.js +9 -12
  230. package/dist/files/useWorkspace.d.ts +5 -7
  231. package/dist/files/useWorkspace.js +4 -15
  232. package/dist/git/GitBar.js +5 -3
  233. package/dist/git/MoveSessionDialog.d.ts +18 -8
  234. package/dist/git/MoveSessionDialog.js +32 -53
  235. package/dist/git/MoveToDialog.d.ts +61 -0
  236. package/dist/git/MoveToDialog.js +240 -0
  237. package/dist/git/SandboxManager.js +9 -4
  238. package/dist/git/SyncChip.js +11 -4
  239. package/dist/git/TeleportSessionDialog.d.ts +69 -0
  240. package/dist/git/TeleportSessionDialog.js +440 -0
  241. package/dist/git/headless/host.d.ts +14 -0
  242. package/dist/git/headless/index.d.ts +2 -1
  243. package/dist/git/headless/index.js +2 -1
  244. package/dist/git/headless/labels.d.ts +44 -1
  245. package/dist/git/headless/labels.js +50 -0
  246. package/dist/git/headless/sandboxes.d.ts +1 -1
  247. package/dist/git/headless/sandboxes.js +4 -3
  248. package/dist/git/headless/teleport.d.ts +76 -0
  249. package/dist/git/headless/teleport.js +19 -0
  250. package/dist/git/index.d.ts +4 -2
  251. package/dist/git/index.js +4 -2
  252. package/dist/git/useEnvironmentChoices.d.ts +5 -2
  253. package/dist/git/useEnvironmentChoices.js +12 -4
  254. package/dist/hooks/useLatest.d.ts +8 -0
  255. package/dist/hooks/useLatest.js +17 -0
  256. package/dist/hooks/useMinuteTick.d.ts +6 -2
  257. package/dist/hooks/useMinuteTick.js +12 -6
  258. package/dist/hooks/useNearViewport.js +11 -8
  259. package/dist/index.d.ts +3 -2
  260. package/dist/index.js +2 -1
  261. package/dist/keybindings/KeybindingsProvider.js +3 -4
  262. package/dist/keybindings/headless/catalog.d.ts +1 -1
  263. package/dist/keybindings/headless/catalog.js +18 -0
  264. package/dist/machines/AddServerForm.js +55 -3
  265. package/dist/machines/Banners.d.ts +2 -2
  266. package/dist/machines/Banners.js +3 -3
  267. package/dist/machines/DaemonMenu.js +1 -3
  268. package/dist/machines/HostsSection.js +5 -1
  269. package/dist/machines/OrganizationPanel.d.ts +25 -0
  270. package/dist/machines/OrganizationPanel.js +266 -0
  271. package/dist/machines/PersonalLayerPanel.d.ts +32 -0
  272. package/dist/machines/PersonalLayerPanel.js +360 -0
  273. package/dist/machines/headless/fixture-host.d.ts +10 -0
  274. package/dist/machines/headless/fixture-host.js +44 -0
  275. package/dist/machines/headless/host.d.ts +21 -1
  276. package/dist/machines/headless/index.d.ts +3 -1
  277. package/dist/machines/headless/index.js +3 -1
  278. package/dist/machines/headless/labels.d.ts +55 -0
  279. package/dist/machines/headless/labels.js +58 -1
  280. package/dist/machines/headless/layer.d.ts +64 -0
  281. package/dist/machines/headless/layer.js +56 -0
  282. package/dist/machines/headless/organization.d.ts +38 -0
  283. package/dist/machines/headless/organization.js +44 -0
  284. package/dist/machines/index.d.ts +3 -1
  285. package/dist/machines/index.js +3 -1
  286. package/dist/machines/testing/contract.d.ts +25 -1
  287. package/dist/machines/testing/contract.js +97 -1
  288. package/dist/motion/grow.js +12 -13
  289. package/dist/motion/swap.js +2 -5
  290. package/dist/motion/use-flip-list.d.ts +14 -0
  291. package/dist/motion/use-flip-list.js +17 -12
  292. package/dist/palette/headless/app-sources.js +37 -0
  293. package/dist/palette/headless/labels.js +3 -0
  294. package/dist/server/sse-handler.js +25 -2
  295. package/dist/session/DiffFileTree.js +1 -4
  296. package/dist/session/OpenSessionsDialog.d.ts +46 -0
  297. package/dist/session/OpenSessionsDialog.js +170 -0
  298. package/dist/session/PlanTracker.js +1 -2
  299. package/dist/session/ProjectHome.js +10 -9
  300. package/dist/session/RemindersPanel.js +10 -12
  301. package/dist/session/SecretsPanel.js +2 -1
  302. package/dist/session/SessionHeader.js +1 -0
  303. package/dist/session/SessionPeopleStack.d.ts +23 -0
  304. package/dist/session/SessionPeopleStack.js +65 -0
  305. package/dist/session/SessionPlaceMenu.js +5 -4
  306. package/dist/session/ShareSessionDialog.d.ts +32 -0
  307. package/dist/session/ShareSessionDialog.js +342 -0
  308. package/dist/session/TypingLine.d.ts +22 -0
  309. package/dist/session/TypingLine.js +31 -0
  310. package/dist/session/headless/host.d.ts +40 -1
  311. package/dist/session/headless/index.d.ts +4 -2
  312. package/dist/session/headless/index.js +3 -1
  313. package/dist/session/headless/labels.d.ts +49 -0
  314. package/dist/session/headless/labels.js +56 -0
  315. package/dist/session/headless/people.d.ts +29 -0
  316. package/dist/session/headless/people.js +53 -0
  317. package/dist/session/headless/place.d.ts +5 -0
  318. package/dist/session/headless/place.js +5 -1
  319. package/dist/session/headless/typing.d.ts +37 -0
  320. package/dist/session/headless/typing.js +60 -0
  321. package/dist/session/index.d.ts +5 -1
  322. package/dist/session/index.js +5 -1
  323. package/dist/settings/headless/fixture-performance.js +4 -2
  324. package/dist/settings/headless/performance.d.ts +4 -0
  325. package/dist/settings/headless/search.d.ts +1 -1
  326. package/dist/settings/headless/sections-host.d.ts +7 -2
  327. package/dist/settings/section.d.ts +15 -3
  328. package/dist/settings/section.js +15 -3
  329. package/dist/settings/sections/environments/EnvironmentsSection.js +30 -6
  330. package/dist/settings/sections/keybindings/labels.d.ts +3 -0
  331. package/dist/settings/sections/keybindings/labels.js +3 -0
  332. package/dist/settings/sections/keybindings/rows.js +12 -0
  333. package/dist/settings/sections/logs/LogsSection.js +5 -8
  334. package/dist/settings/sections/performance/PerformanceSection.js +8 -1
  335. package/dist/settings/sections/performance/labels.d.ts +2 -0
  336. package/dist/settings/sections/performance/labels.js +2 -0
  337. package/dist/styles.css +65 -9
  338. package/dist/terminal/HostTerminalSurface.js +28 -30
  339. package/dist/terminal/TerminalPanel.js +4 -12
  340. package/dist/terminal/TerminalProvider.d.ts +10 -2
  341. package/dist/terminal/TerminalProvider.js +10 -2
  342. package/dist/terminal/headless/labels.d.ts +0 -1
  343. package/dist/terminal/headless/labels.js +1 -2
  344. package/dist/terminal/headless/store.js +5 -1
  345. package/dist/views/headless/answers.d.ts +8 -2
  346. package/dist/views/headless/answers.js +58 -1
  347. package/dist/views/headless/placement.d.ts +78 -0
  348. package/dist/views/headless/placement.js +154 -44
  349. package/dist/workspace/LayoutBudget.js +1 -7
  350. package/package.json +2 -2
  351. package/src/styles/chat.css +3 -1
  352. package/src/styles/palette.css +3 -3
  353. package/src/styles/transcript.css +50 -5
  354. /package/dist/dist/{index-De9AbmxS.d.ts → index-ttmMvjgM.d.ts} +0 -0
@@ -3,14 +3,16 @@ import { useStaysMounted } from "../../motion/collapse.js";
3
3
  import { useChatLabels } from "../useChatLabels.js";
4
4
  import { useModelName } from "./actions.js";
5
5
  import { AnsiText } from "./AnsiText.js";
6
+ import { ClippedOutputControls, useClippedOutput } from "./clipped-output.js";
6
7
  import { EditDiffBlock } from "./EditDiffBlock.js";
7
8
  import { Caret, FailedMark } from "./frame.js";
8
9
  import { ImageGenerationBlock, drawsImageGeneration } from "./ImageGenerationBlock.js";
9
10
  import { useTranscriptRenderers } from "./renderers.js";
10
11
  import { Rolling } from "./rolling.js";
12
+ import { useRowUiState } from "./row-ui-state.js";
11
13
  import { scriptInputProps } from "./script-input.js";
12
14
  import { ToolMedia, useToolMedia } from "./tool-media.js";
13
- import { CODE_PANEL, LoadFullOutputButton, ReadFileBlock, ToolGlyph, ToolInput, ToolTiming, useFullOutput } from "./tool-parts.js";
15
+ import { CODE_PANEL, LoadFullOutputButton, ReadFileBlock, ToolGlyph, ToolInput, ToolTiming, useFullToolCall } from "./tool-parts.js";
14
16
  import { Fragment, memo, useEffect, useMemo, useState } from "react";
15
17
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
16
18
  import { computeLineDiff, isMcpJobDone, scriptProgressView } from "zidane/chat/pure";
@@ -27,7 +29,7 @@ function toolRowPropsEqual(prev, next) {
27
29
  if (prev.mode !== next.mode || prev.showResult !== next.showResult || prev.showDiff !== next.showDiff || prev.lineState !== next.lineState || prev.className !== next.className || prev.style !== next.style) return false;
28
30
  const a = prev.tool;
29
31
  const b = next.tool;
30
- return a.name === b.name && a.displayName === b.displayName && a.result === b.result && a.ok === b.ok && a.edit === b.edit && a.rawInput === b.rawInput && a.resultClipped === b.resultClipped && a.callId === b.callId && a.startedAt === b.startedAt && a.durationMs === b.durationMs && a.waitingFor === b.waitingFor && a.resuming === b.resuming && a.scriptProgress === b.scriptProgress && a.mcpJob === b.mcpJob && a.approval === b.approval && formattedEqual(a.formatted, b.formatted);
32
+ return a.name === b.name && a.displayName === b.displayName && a.result === b.result && a.ok === b.ok && a.edit === b.edit && a.rawInput === b.rawInput && a.resultClipped === b.resultClipped && a.inputClipped === b.inputClipped && a.callId === b.callId && a.turnId === b.turnId && a.startedAt === b.startedAt && a.durationMs === b.durationMs && a.waitingFor === b.waitingFor && a.resuming === b.resuming && a.scriptProgress === b.scriptProgress && a.mcpJob === b.mcpJob && a.approval === b.approval && formattedEqual(a.formatted, b.formatted);
31
33
  }
32
34
  function formattedEqual(a, b) {
33
35
  if (a === b) return true;
@@ -89,10 +91,21 @@ const ToolRow = memo(({ tool, mode, showResult, showDiff, lineState, className,
89
91
  const labels = useChatLabels();
90
92
  const display = useDisplayPath();
91
93
  const { SessionTitle, ToolBody, hasToolBody } = useTranscriptRenderers();
92
- const [open, setOpen] = useState(false);
94
+ const [open, setOpen] = useRowUiState(`tool:${tool.id}`, false);
93
95
  /** Output revealed on demand while the "Tool outputs" setting is off. */
94
- const [revealOutput, setRevealOutput] = useState(false);
95
- const { full: fullResult, load: loadFullResult, available: canLoadFull, ready: fullReady } = useFullOutput(tool);
96
+ const [revealOutput, setRevealOutput] = useRowUiState(`tool-output:${tool.id}`, false);
97
+ const clippedOutput = useClippedOutput(tool);
98
+ const fullResult = clippedOutput.text;
99
+ const { full: fullCall, load: loadFullCall, available: canLoadCall, ready: callReady } = useFullToolCall(tool);
100
+ const input = fullCall !== "loading" && fullCall?.input ? fullCall.input : tool.rawInput;
101
+ const loadInputButton = tool.inputClipped && canLoadCall && (fullCall === null || fullCall === "loading") && /* @__PURE__ */ jsx(LoadFullOutputButton, {
102
+ loading: fullCall === "loading",
103
+ disabled: !callReady,
104
+ onClick: loadFullCall,
105
+ className: "mt-1.5",
106
+ label: labels.loadFullInput,
107
+ loadingLabel: labels.loadingFullInput
108
+ });
96
109
  const bodyMounted = useStaysMounted(open);
97
110
  const media = useToolMedia(tool, typeof fullResult === "string" ? fullResult : tool.result);
98
111
  const hasDiff = showDiff && tool.edit;
@@ -119,10 +132,8 @@ const ToolRow = memo(({ tool, mode, showResult, showDiff, lineState, className,
119
132
  const scriptInline = showInputPanel && tool.name === "codemode" && tool.scriptProgress !== void 0;
120
133
  const hasExpandable = interaction || showInputPanel || hasOutput || mode === "full" && tool.rawInput || hasDiff;
121
134
  const sweep = lineState === "running" && !tool.waitingFor;
122
- const outputBody = showOutputPanel ? /* @__PURE__ */ jsxs(Fragment$1, { children: [bodyMounted && canLoadFull && tool.resultClipped && typeof fullResult !== "string" && /* @__PURE__ */ jsx(LoadFullOutputButton, {
123
- loading: fullResult === "loading",
124
- disabled: !fullReady,
125
- onClick: loadFullResult,
135
+ const outputBody = showOutputPanel ? /* @__PURE__ */ jsxs(Fragment$1, { children: [bodyMounted && tool.resultClipped && /* @__PURE__ */ jsx(ClippedOutputControls, {
136
+ output: clippedOutput,
126
137
  className: "mt-1.5"
127
138
  }), !bodyMounted ? null : media ? /* @__PURE__ */ jsxs("div", {
128
139
  className: "mt-1.5 flex flex-col gap-1.5",
@@ -230,7 +241,11 @@ const ToolRow = memo(({ tool, mode, showResult, showDiff, lineState, className,
230
241
  "data-open": open,
231
242
  children: /* @__PURE__ */ jsx("div", {
232
243
  className: "zg-collapsible-inner",
233
- children: bodyMounted && /* @__PURE__ */ jsx(EditDiffBlock, { edit: tool.edit })
244
+ children: bodyMounted && /* @__PURE__ */ jsx(EditDiffBlock, {
245
+ edit: tool.edit,
246
+ ...tool.callId ? { callId: tool.callId } : {},
247
+ ...tool.turnId ? { turnId: tool.turnId } : {}
248
+ })
234
249
  })
235
250
  }),
236
251
  interaction && ToolBody && /* @__PURE__ */ jsx("div", {
@@ -249,12 +264,16 @@ const ToolRow = memo(({ tool, mode, showResult, showDiff, lineState, className,
249
264
  "data-open": open,
250
265
  children: /* @__PURE__ */ jsx("div", {
251
266
  className: "zg-collapsible-inner",
252
- children: bodyMounted && /* @__PURE__ */ jsxs(Fragment$1, { children: [showOutputPanel && !scriptInline && /* @__PURE__ */ jsx(PanelCaption, { children: labels.inputCaption }), /* @__PURE__ */ jsx(ToolInput, {
253
- name: tool.name,
254
- input: tool.rawInput,
255
- ...scriptInputProps(tool),
256
- ...scriptInline && outputBody ? { output: outputBody } : {}
257
- })] })
267
+ children: bodyMounted && /* @__PURE__ */ jsxs(Fragment$1, { children: [
268
+ showOutputPanel && !scriptInline && /* @__PURE__ */ jsx(PanelCaption, { children: labels.inputCaption }),
269
+ /* @__PURE__ */ jsx(ToolInput, {
270
+ name: tool.name,
271
+ input,
272
+ ...scriptInputProps(tool),
273
+ ...scriptInline && outputBody ? { output: outputBody } : {}
274
+ }),
275
+ loadInputButton
276
+ ] })
258
277
  })
259
278
  }),
260
279
  hasOutput && !showOutputPanel && /* @__PURE__ */ jsx("div", {
@@ -283,11 +302,11 @@ const ToolRow = memo(({ tool, mode, showResult, showDiff, lineState, className,
283
302
  "data-open": open,
284
303
  children: /* @__PURE__ */ jsx("div", {
285
304
  className: "zg-collapsible-inner",
286
- children: bodyMounted && /* @__PURE__ */ jsx(ToolInput, {
305
+ children: bodyMounted && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ToolInput, {
287
306
  name: tool.name,
288
- input: tool.rawInput,
307
+ input: input ?? tool.rawInput,
289
308
  ...scriptInputProps(tool)
290
- })
309
+ }), loadInputButton] })
291
310
  })
292
311
  })
293
312
  ]
@@ -1,8 +1,9 @@
1
- import { ChatEvent } from "../headless/host.js";
2
1
  import { Cluster, Row } from "../headless/transcript/rows.js";
3
2
  import { SelectStops } from "../headless/transcript/select-stops.js";
3
+ import { ChatEvent } from "../headless/host.js";
4
4
  import "../headless/transcript/index.js";
5
- import { RunReceipt } from "zidane/chat/pure";
5
+ import { TranscriptRowsSlice } from "../headless/transcript/incremental.js";
6
+ import { RunReceipt, TranscriptEvents } from "zidane/chat/pure";
6
7
  /** The display options that shape the rows. */
7
8
  export interface TranscriptRowsInput {
8
9
  /** Show cache notices (cache expired / break, dropped reasoning). */
@@ -30,15 +31,30 @@ export interface TranscriptRows {
30
31
  clusters: readonly Cluster[];
31
32
  /** The reply still streaming: the only row with a caret. */
32
33
  lastStreamingRow: Row | null | undefined;
34
+ /**
35
+ * `visibleRows` and `clusters` split at the open exchange: `settled` keeps
36
+ * its arrays (and every row and cluster in them) while only the open
37
+ * exchange streams. A renderer can read these instead of the joined arrays.
38
+ */
39
+ parts?: {
40
+ settled: TranscriptRowsSlice;
41
+ open: TranscriptRowsSlice;
42
+ };
33
43
  }
44
+ /** A transcript's events: an array, or the transcript store a session stream store holds (`TranscriptEvents`). */
45
+ export type TranscriptSource = readonly ChatEvent[] | TranscriptEvents<ChatEvent>;
46
+ /** Rows, or what holds them (read only when needed: `useTranscriptRows`' result joins its parts on first read). */
47
+ type RowsSource = readonly Row[] | {
48
+ readonly visibleRows: readonly Row[];
49
+ };
34
50
  /**
35
- * Runs the headless pipeline over a transcript's events, one `useMemo` per pass, and returns the rows to paint.
51
+ * Runs the headless pipeline over a transcript's events, incrementally (only the open exchange re-derives per tick), and returns the rows to paint.
36
52
  *
37
- * @param events - The session's events, oldest first.
53
+ * @param events - The session's events, oldest first, or its transcript store (then nothing walks the settled exchanges per tick).
38
54
  * @param streaming - A run is in flight, so the last reply may still be streaming.
39
55
  * @param input - The display options that shape the rows.
40
56
  */
41
- export declare function useTranscriptRows(events: readonly ChatEvent[], streaming: boolean, { showCacheNotices, codemodeShowCalls, showEditDiffs, groupToolCalls, showRunReceipt, compact }: TranscriptRowsInput): TranscriptRows;
57
+ export declare function useTranscriptRows(events: TranscriptSource, streaming: boolean, { showCacheNotices, codemodeShowCalls, showEditDiffs, groupToolCalls, showRunReceipt, compact }: TranscriptRowsInput): TranscriptRows;
42
58
  /**
43
59
  * Select-turn stops (`computeSelectStops`): which turns the cursor walks
44
60
  * and which rows light up. Derived per transcript change while the mode is
@@ -47,10 +63,11 @@ export declare function useTranscriptRows(events: readonly ChatEvent[], streamin
47
63
  * before the mode is on, and on every arrow), cached per input so a burst
48
64
  * of arrows computes once.
49
65
  *
50
- * @param visibleRows - The rows painted, from {@link useTranscriptRows}.
51
- * @param events - The session's events, oldest first.
66
+ * @param visibleRows - The rows painted, or {@link useTranscriptRows}' result (its rows are read only while the mode is on or asked).
67
+ * @param events - The session's events, oldest first, or its transcript store (read as one array only while the mode is on or asked).
52
68
  * @param showThinking - Reasoning rows are shown, so they can be stops.
53
69
  * @param selecting - Select-turn mode is on.
54
70
  * @param registerStops - Hands the app the stops source; returns its unregister function.
55
71
  */
56
- export declare function useSelectStops(visibleRows: readonly Row[], events: readonly ChatEvent[], showThinking: boolean, selecting: boolean, registerStops: ((source: () => SelectStops) => () => void) | undefined): SelectStops | null;
72
+ export declare function useSelectStops(visibleRows: RowsSource, events: TranscriptSource, showThinking: boolean, selecting: boolean, registerStops: ((source: () => SelectStops) => () => void) | undefined): SelectStops | null;
73
+ export {};
@@ -1,58 +1,40 @@
1
- import { batchTaskRuns, batchThinkingRuns, batchToolRuns, clusterByOwner } from "../headless/transcript/batch.js";
2
- import { collapseEvents } from "../headless/transcript/collapse.js";
3
1
  import { computeSelectStops } from "../headless/transcript/select-stops.js";
4
- import { dockRunReceipts, findLastStreamingRow, foldExchanges } from "../headless/transcript/fold.js";
5
- import { markRunFailures } from "../headless/transcript/run-failures.js";
6
- import { nestToolCalls, nestedCallVisible } from "../headless/transcript/nesting.js";
2
+ import { createTranscriptRowsDeriver } from "../headless/transcript/incremental.js";
7
3
  import { isHiddenRow } from "./TranscriptRow.js";
8
- import { useEffect, useLayoutEffect, useMemo, useRef } from "react";
9
- import { gatherCommandNotes, isCacheNotice, turnSelectionOwnership } from "zidane/chat/pure";
4
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
5
+ import { transcriptArray, turnSelectionOwnership } from "zidane/chat/pure";
10
6
  // src/chat/transcript/use-transcript-rows.ts
11
- const asStream = (events) => events;
7
+ function asStream(events) {
8
+ return Array.isArray(events) ? events : transcriptArray(events);
9
+ }
10
+ const rowsOf = (rows) => Array.isArray(rows) ? rows : rows.visibleRows;
12
11
  /**
13
- * Runs the headless pipeline over a transcript's events, one `useMemo` per pass, and returns the rows to paint.
12
+ * Runs the headless pipeline over a transcript's events, incrementally (only the open exchange re-derives per tick), and returns the rows to paint.
14
13
  *
15
- * @param events - The session's events, oldest first.
14
+ * @param events - The session's events, oldest first, or its transcript store (then nothing walks the settled exchanges per tick).
16
15
  * @param streaming - A run is in flight, so the last reply may still be streaming.
17
16
  * @param input - The display options that shape the rows.
18
17
  */
19
18
  function useTranscriptRows(events, streaming, { showCacheNotices, codemodeShowCalls, showEditDiffs, groupToolCalls, showRunReceipt, compact }) {
20
- const shownEvents = useMemo(() => {
21
- const shown = showCacheNotices && codemodeShowCalls ? events : events.filter((event) => (showCacheNotices || !isCacheNotice(event.notice)) && nestedCallVisible(event, codemodeShowCalls));
22
- return gatherCommandNotes(asStream(shown));
23
- }, [
19
+ const [deriver] = useState(createTranscriptRowsDeriver);
20
+ return useMemo(() => deriver.derive(events, streaming, {
21
+ showCacheNotices,
22
+ codemodeShowCalls,
23
+ showEditDiffs,
24
+ groupToolCalls,
25
+ showRunReceipt,
26
+ compact
27
+ }), [
28
+ deriver,
24
29
  events,
30
+ streaming,
25
31
  showCacheNotices,
26
- codemodeShowCalls
27
- ]);
28
- const rows = useMemo(() => nestToolCalls(collapseEvents(shownEvents, showEditDiffs, streaming)), [
29
- shownEvents,
32
+ codemodeShowCalls,
30
33
  showEditDiffs,
31
- streaming
32
- ]);
33
- const batched = useMemo(() => batchTaskRuns(batchThinkingRuns(batchToolRuns(rows, groupToolCalls))), [rows, groupToolCalls]);
34
- const failed = useMemo(() => markRunFailures(batched), [batched]);
35
- const { visibleRows: dockedRows, receiptByRowId } = useMemo(() => dockRunReceipts(failed, showRunReceipt), [failed, showRunReceipt]);
36
- const visibleRows = useMemo(() => compact ? foldExchanges(dockedRows, streaming) : dockedRows, [
37
- dockedRows,
38
- compact,
39
- streaming
34
+ groupToolCalls,
35
+ showRunReceipt,
36
+ compact
40
37
  ]);
41
- return {
42
- visibleRows,
43
- receiptByRowId,
44
- resumableId: useMemo(() => {
45
- if (streaming) return null;
46
- for (let i = visibleRows.length - 1; i >= 0; i--) {
47
- const row = visibleRows[i];
48
- if (row.kind === "separator" || row.kind === "run-summary") continue;
49
- return row.kind === "error" && row.failure ? row.id : null;
50
- }
51
- return null;
52
- }, [visibleRows, streaming]),
53
- clusters: useMemo(() => clusterByOwner(visibleRows), [visibleRows]),
54
- lastStreamingRow: findLastStreamingRow(visibleRows)
55
- };
56
38
  }
57
39
  /**
58
40
  * Select-turn stops (`computeSelectStops`): which turns the cursor walks
@@ -62,14 +44,14 @@ function useTranscriptRows(events, streaming, { showCacheNotices, codemodeShowCa
62
44
  * before the mode is on, and on every arrow), cached per input so a burst
63
45
  * of arrows computes once.
64
46
  *
65
- * @param visibleRows - The rows painted, from {@link useTranscriptRows}.
66
- * @param events - The session's events, oldest first.
47
+ * @param visibleRows - The rows painted, or {@link useTranscriptRows}' result (its rows are read only while the mode is on or asked).
48
+ * @param events - The session's events, oldest first, or its transcript store (read as one array only while the mode is on or asked).
67
49
  * @param showThinking - Reasoning rows are shown, so they can be stops.
68
50
  * @param selecting - Select-turn mode is on.
69
51
  * @param registerStops - Hands the app the stops source; returns its unregister function.
70
52
  */
71
53
  function useSelectStops(visibleRows, events, showThinking, selecting, registerStops) {
72
- const stops = useMemo(() => selecting ? computeSelectStops(visibleRows, turnSelectionOwnership(asStream(events)), (row) => isHiddenRow(row, showThinking)) : null, [
54
+ const stops = useMemo(() => selecting ? computeSelectStops(rowsOf(visibleRows), turnSelectionOwnership(asStream(events)), (row) => isHiddenRow(row, showThinking)) : null, [
73
55
  selecting,
74
56
  visibleRows,
75
57
  events,
@@ -94,7 +76,7 @@ function useSelectStops(visibleRows, events, showThinking, selecting, registerSt
94
76
  const { rows, events: evts, showThinking: show } = stopsInput.current;
95
77
  const hit = stopsCache.current;
96
78
  if (hit && hit.rows === rows && hit.events === evts && hit.show === show) return hit.stops;
97
- const fresh = computeSelectStops(rows, turnSelectionOwnership(asStream(evts)), (row) => isHiddenRow(row, show));
79
+ const fresh = computeSelectStops(rowsOf(rows), turnSelectionOwnership(asStream(evts)), (row) => isHiddenRow(row, show));
98
80
  stopsCache.current = {
99
81
  rows,
100
82
  events: evts,
@@ -0,0 +1,42 @@
1
+ /** The reader counts as idle after this long without scrolling. */
2
+ export declare const BACKFILL_QUIET_MS = 1000;
3
+ /** Rows of one session (`eventBytes`) past which pages load only on demand: prewarm's budget. */
4
+ export declare const BACKFILL_MAX_BYTES: number;
5
+ /** Runs one offered load at a time, once the reader has held still. */
6
+ export interface HistoryBackfill {
7
+ /** The load to run once the reader is idle (it runs once); `null`: nothing to load now. */
8
+ offer: (load: (() => void) | null) => void;
9
+ /** Waits a quiet period from now (a conversation opened). */
10
+ restart: () => void;
11
+ dispose: () => void;
12
+ }
13
+ /**
14
+ * Creates the scheduler of {@link useHistoryBackfill}.
15
+ *
16
+ * @param target - Where the reader's input is heard (the document).
17
+ * @param quietMs - How long the reader holds still before a load runs.
18
+ */
19
+ export declare function createHistoryBackfill(target: EventTarget, quietMs?: number): HistoryBackfill;
20
+ /** What {@link useHistoryBackfill} reads of the conversation shown. */
21
+ export interface HistoryBackfillInputs {
22
+ /** Its events are hydrated. */
23
+ ready: boolean;
24
+ /** Older pages exist (and can be loaded). */
25
+ hasMore: boolean;
26
+ /** A page is loading. */
27
+ loading: boolean;
28
+ /** How much is loaded: changes when a page lands (the window's first position, or its length). */
29
+ loaded: number;
30
+ /** Loads the next older page. */
31
+ load: () => void;
32
+ /** About how many bytes its rows hold (`eventBytes`). Absent: nothing loads in the background. */
33
+ bytes: (() => number) | undefined;
34
+ }
35
+ /**
36
+ * Loads the conversation's older pages in the background while the reader is idle (see the module comment).
37
+ *
38
+ * @param sessionId - The conversation shown.
39
+ * @param inputs - The {@link HistoryBackfillInputs}.
40
+ * @param maxBytes - The byte budget. Default {@link BACKFILL_MAX_BYTES}.
41
+ */
42
+ export declare function useHistoryBackfill(sessionId: string | null, inputs: HistoryBackfillInputs, maxBytes?: number): void;
@@ -0,0 +1,170 @@
1
+ import { useEffect, useRef } from "react";
2
+ // src/chat/transcript/useHistoryBackfill.ts
3
+ /**
4
+ * Background scrollback: once a conversation has opened and the reader holds
5
+ * still, its older pages load one at a time in idle time, until the history
6
+ * is complete or its rows reach a byte budget. The scrollbar then measures
7
+ * the whole conversation, and its top is there without a wait.
8
+ *
9
+ * Loading waits while the reader scrolls: a wheel, a touch, a press, a scroll
10
+ * key, and the scroll events that carry a gesture on (momentum, a scrollbar
11
+ * drag) restart a quiet period of {@link BACKFILL_QUIET_MS}. A scroll event
12
+ * alone never starts one: the view's own corrections (a page held in place, a
13
+ * live run followed at the bottom) are not the reader. A page lands as
14
+ * unmounted placeholders (`row-mount.ts`), and the view keeps its place
15
+ * (`useStickToBottom`, or the browser's scroll anchoring). Past the budget,
16
+ * scroll-to-load and Load earlier reach the rest.
17
+ */
18
+ /** The reader counts as idle after this long without scrolling. */
19
+ const BACKFILL_QUIET_MS = 1e3;
20
+ /** Rows of one session (`eventBytes`) past which pages load only on demand: prewarm's budget. */
21
+ const BACKFILL_MAX_BYTES = 25165824;
22
+ /** Keys that scroll the view. */
23
+ const SCROLL_KEYS = /* @__PURE__ */ new Set([
24
+ "ArrowUp",
25
+ "ArrowDown",
26
+ "PageUp",
27
+ "PageDown",
28
+ "Home",
29
+ "End",
30
+ " "
31
+ ]);
32
+ const INPUTS = [
33
+ "wheel",
34
+ "touchstart",
35
+ "touchmove",
36
+ "touchend",
37
+ "pointerdown"
38
+ ];
39
+ function requestIdle(run) {
40
+ if (typeof requestIdleCallback === "function") {
41
+ const id = requestIdleCallback(run);
42
+ return () => cancelIdleCallback(id);
43
+ }
44
+ const id = setTimeout(run, 0);
45
+ return () => clearTimeout(id);
46
+ }
47
+ /**
48
+ * Creates the scheduler of {@link useHistoryBackfill}.
49
+ *
50
+ * @param target - Where the reader's input is heard (the document).
51
+ * @param quietMs - How long the reader holds still before a load runs.
52
+ */
53
+ function createHistoryBackfill(target, quietMs = BACKFILL_QUIET_MS) {
54
+ let quiet = false;
55
+ let timer;
56
+ let cancelIdle;
57
+ let pending = null;
58
+ const kick = () => {
59
+ if (!quiet || !pending || cancelIdle) return;
60
+ cancelIdle = requestIdle(() => {
61
+ cancelIdle = void 0;
62
+ const load = pending;
63
+ pending = null;
64
+ load?.();
65
+ });
66
+ };
67
+ const restart = () => {
68
+ quiet = false;
69
+ cancelIdle?.();
70
+ cancelIdle = void 0;
71
+ clearTimeout(timer);
72
+ timer = setTimeout(() => {
73
+ timer = void 0;
74
+ quiet = true;
75
+ kick();
76
+ }, quietMs);
77
+ };
78
+ const onKey = (e) => {
79
+ if (SCROLL_KEYS.has(e.key)) restart();
80
+ };
81
+ const onScroll = (e) => {
82
+ const el = e.target;
83
+ if (quiet || !(el instanceof Element) || el.scrollHeight - el.scrollTop - el.clientHeight <= 2) return;
84
+ restart();
85
+ };
86
+ for (const type of INPUTS) target.addEventListener(type, restart, {
87
+ capture: true,
88
+ passive: true
89
+ });
90
+ target.addEventListener("keydown", onKey, { capture: true });
91
+ target.addEventListener("scroll", onScroll, {
92
+ capture: true,
93
+ passive: true
94
+ });
95
+ restart();
96
+ return {
97
+ offer(load) {
98
+ pending = load;
99
+ if (!load) {
100
+ cancelIdle?.();
101
+ cancelIdle = void 0;
102
+ }
103
+ kick();
104
+ },
105
+ restart,
106
+ dispose() {
107
+ for (const type of INPUTS) target.removeEventListener(type, restart, { capture: true });
108
+ target.removeEventListener("keydown", onKey, { capture: true });
109
+ target.removeEventListener("scroll", onScroll, { capture: true });
110
+ clearTimeout(timer);
111
+ cancelIdle?.();
112
+ cancelIdle = void 0;
113
+ pending = null;
114
+ }
115
+ };
116
+ }
117
+ /**
118
+ * Loads the conversation's older pages in the background while the reader is idle (see the module comment).
119
+ *
120
+ * @param sessionId - The conversation shown.
121
+ * @param inputs - The {@link HistoryBackfillInputs}.
122
+ * @param maxBytes - The byte budget. Default {@link BACKFILL_MAX_BYTES}.
123
+ */
124
+ function useHistoryBackfill(sessionId, inputs, maxBytes = BACKFILL_MAX_BYTES) {
125
+ const { ready, hasMore, loading, loaded, load, bytes } = inputs;
126
+ const backfill = useRef(null);
127
+ const latest = useRef({
128
+ load,
129
+ bytes
130
+ });
131
+ useEffect(() => {
132
+ latest.current = {
133
+ load,
134
+ bytes
135
+ };
136
+ });
137
+ useEffect(() => {
138
+ const created = createHistoryBackfill(document);
139
+ backfill.current = created;
140
+ return () => {
141
+ created.dispose();
142
+ backfill.current = null;
143
+ };
144
+ }, []);
145
+ useEffect(() => {
146
+ if (sessionId && ready) backfill.current?.restart();
147
+ }, [sessionId, ready]);
148
+ const measured = bytes !== void 0;
149
+ useEffect(() => {
150
+ const b = backfill.current;
151
+ if (!b) return;
152
+ if (!sessionId || !ready || !hasMore || loading || !measured) {
153
+ b.offer(null);
154
+ return;
155
+ }
156
+ b.offer(() => {
157
+ const { load, bytes } = latest.current;
158
+ if (bytes && bytes() < maxBytes) load();
159
+ });
160
+ }, [
161
+ sessionId,
162
+ ready,
163
+ hasMore,
164
+ loading,
165
+ loaded,
166
+ measured,
167
+ maxBytes
168
+ ]);
169
+ }
170
+ export { BACKFILL_MAX_BYTES, BACKFILL_QUIET_MS, createHistoryBackfill, useHistoryBackfill };
@@ -1,6 +1,6 @@
1
1
  import { currentMotionTransition } from "../../motion/springs.js";
2
2
  import { dataRowSelector } from "../headless/transcript/rail.js";
3
- import { mountRowNow } from "./LazyRow.js";
3
+ import { revealRow } from "./row-mount.js";
4
4
  import { mayShrink } from "./scroll-clamp.js";
5
5
  import { viewAbove } from "./view-anchor.js";
6
6
  import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
@@ -360,8 +360,7 @@ function useStickToBottom(scrollRef, { paused = false, rowSelector = ".zg-cv-row
360
360
  };
361
361
  restoreRows.current = (rows) => {
362
362
  const find = (id) => el.querySelector(dataRowSelector(id));
363
- const outer = rows.length > 0 ? find(rows[rows.length - 1].id) : null;
364
- if (outer) mountRowNow(outer);
363
+ if (rows.length > 0) revealRow(el, rows[rows.length - 1].id);
365
364
  for (const [i, place] of rows.entries()) {
366
365
  const target = find(place.id);
367
366
  if (!target) continue;
@@ -1,5 +1,5 @@
1
1
  import { useTranscriptFindKey } from "./useTranscriptFindKey.js";
2
- import { useCallback, useEffect, useMemo, useState } from "react";
2
+ import { useCallback, useMemo, useState } from "react";
3
3
  // src/chat/transcript/useTranscriptFind.ts
4
4
  /**
5
5
  * The find in the conversation's state: which session it is open on and the
@@ -25,9 +25,7 @@ function useTranscriptFind({ sessionId, blocked }) {
25
25
  onFind,
26
26
  ...blocked ? { blocked } : {}
27
27
  });
28
- useEffect(() => {
29
- if (target && target.sessionId !== sessionId) setTarget(null);
30
- }, [sessionId, target]);
28
+ if (target && target.sessionId !== sessionId) setTarget(null);
31
29
  const close = useCallback(() => setTarget(null), []);
32
30
  const findIn = useCallback((next) => setTarget(next), []);
33
31
  const open = target !== null && target.sessionId === sessionId;
@@ -2,9 +2,10 @@
2
2
  * The conversation's transcript scroll: stick-to-bottom (paused while
3
3
  * select-turn mode drives the cursor), where a conversation opens (back where
4
4
  * it was left, or at the bottom), the scrolled-from-top signal for the
5
- * footer's fade, and lazy scrollback. The container hands it the session's
6
- * page state and loader, whether select-turn drives the view, and the
7
- * Keep scroll position setting.
5
+ * footer's fade, lazy scrollback, and the rest of the history loading in the
6
+ * background while the reader is idle (`useHistoryBackfill`). The container
7
+ * hands it the session's page state, loader and row size, whether
8
+ * select-turn drives the view, and the Keep scroll position setting.
8
9
  */
9
10
  import { SessionPageState } from "../headless/streams/types.js";
10
11
  /** What {@link useTranscriptScroll} reads from its container. */
@@ -19,6 +20,8 @@ export interface TranscriptScrollInputs<K extends string = string> {
19
20
  selecting: boolean;
20
21
  /** Reopen a conversation where it was left (Keep scroll position). */
21
22
  keepPosition: boolean;
23
+ /** About how many bytes the session's rows hold (the stream store's `eventBytes`): what background loading budgets by. Absent: older pages load only on demand. */
24
+ eventBytes?: (sessionId: K) => number;
22
25
  }
23
26
  /**
24
27
  * The transcript's scroll: stick-to-bottom, where a conversation opens, the from-top signal and lazy scrollback (see the module comment).
@@ -27,7 +30,7 @@ export interface TranscriptScrollInputs<K extends string = string> {
27
30
  * @param hydrated - Its events have loaded.
28
31
  * @param inputs - The {@link TranscriptScrollInputs}.
29
32
  */
30
- export declare function useTranscriptScroll<K extends string>(sessionId: K | null, hydrated: boolean, { page, loadEarlier, selecting, keepPosition }: TranscriptScrollInputs<K>): {
33
+ export declare function useTranscriptScroll<K extends string>(sessionId: K | null, hydrated: boolean, { page, loadEarlier, selecting, keepPosition, eventBytes }: TranscriptScrollInputs<K>): {
31
34
  scrollRef: import("react").RefObject<HTMLElement | null>;
32
35
  pinned: boolean;
33
36
  scrolledFromTop: boolean;
@@ -1,5 +1,6 @@
1
1
  import { useFillViewportScrollback } from "./EarlierHistory.js";
2
2
  import { createRecentMap } from "./recent-map.js";
3
+ import { useHistoryBackfill } from "./useHistoryBackfill.js";
3
4
  import { useStickToBottom } from "./useStickToBottom.js";
4
5
  import { useWheelHoverPause } from "./useWheelHoverPause.js";
5
6
  import { useEffect, useLayoutEffect, useRef, useState } from "react";
@@ -21,7 +22,7 @@ const positions = createRecentMap(500);
21
22
  * @param hydrated - Its events have loaded.
22
23
  * @param inputs - The {@link TranscriptScrollInputs}.
23
24
  */
24
- function useTranscriptScroll(sessionId, hydrated, { page, loadEarlier, selecting, keepPosition }) {
25
+ function useTranscriptScroll(sessionId, hydrated, { page, loadEarlier, selecting, keepPosition, eventBytes }) {
25
26
  const scrollRef = useRef(null);
26
27
  const { pinned, snapToBottom, glideToBottom, readPosition, restorePosition } = useStickToBottom(scrollRef, { paused: selecting });
27
28
  useWheelHoverPause(scrollRef);
@@ -121,6 +122,16 @@ function useTranscriptScroll(sessionId, hydrated, { page, loadEarlier, selecting
121
122
  loadEarlier,
122
123
  slackPx: LOAD_EARLIER_PX
123
124
  });
125
+ useHistoryBackfill(sessionId, {
126
+ ready: hydrated,
127
+ hasMore: page.hasMore,
128
+ loading: page.loadingEarlier,
129
+ loaded: page.firstSeq,
130
+ load: () => {
131
+ if (sessionId) loadEarlier(sessionId);
132
+ },
133
+ bytes: sessionId && eventBytes ? () => eventBytes(sessionId) : void 0
134
+ });
124
135
  return {
125
136
  scrollRef,
126
137
  pinned,
@@ -44,12 +44,12 @@ export interface TranscriptSearchOptions {
44
44
  * the user away from the match they're reading. Only a needle CHANGE
45
45
  * scrolls.
46
46
  *
47
- * @param container - The transcript's scroll container.
47
+ * @param containerRef - The transcript's scroll container.
48
48
  * @param query - The query as typed.
49
49
  * @param revision - Changes identity when the transcript re-renders.
50
50
  * @param options - The {@link TranscriptSearchOptions}.
51
51
  */
52
- export declare function useTranscriptSearch(container: React.RefObject<HTMLElement | null>, query: string, revision: unknown, { terms, revealFirstMatch }?: TranscriptSearchOptions): TranscriptSearchState;
52
+ export declare function useTranscriptSearch(containerRef: React.RefObject<HTMLElement | null>, query: string, revision: unknown, { terms, revealFirstMatch }?: TranscriptSearchOptions): TranscriptSearchState;
53
53
  /**
54
54
  * The `::highlight()` color rules, resolved once per mount.
55
55
  * `::highlight()` pseudos can't reliably resolve CSS custom properties