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
@@ -13,6 +13,7 @@
13
13
  import { ChatEvent } from "../headless/host.js";
14
14
  import { TranscriptActions } from "./actions.js";
15
15
  import { MouseEvent, ReactNode } from "react";
16
+ import { TranscriptEvents } from "zidane/chat/pure";
16
17
  /** What a medium's component hands the gallery: its key, and for the menu what it is and where it loads from. */
17
18
  export interface GalleryMedium {
18
19
  /** Its key in its exchange (`mediumKey`). */
@@ -43,8 +44,8 @@ export declare function useMediaGallery(): MediaGallery | null;
43
44
  export declare function messageMediaUrlOf(actions: Pick<TranscriptActions, 'messageMediaUrl'>, src: string): string | undefined;
44
45
  /** Props for {@link MediaGalleryProvider}. */
45
46
  export interface MediaGalleryProviderProps {
46
- /** The transcript's events, whose media the gallery steps through. */
47
- events: readonly ChatEvent[];
47
+ /** The transcript's events, whose media the gallery steps through, or its transcript store (read when a medium opens). */
48
+ events: readonly ChatEvent[] | TranscriptEvents<ChatEvent>;
48
49
  children?: ReactNode;
49
50
  }
50
51
  /**
@@ -5,11 +5,11 @@ import { exchangesMedia } from "../headless/transcript/exchange-media.js";
5
5
  import { PdfPreview } from "../PdfPreview.js";
6
6
  import { TextPreview } from "../TextPreview.js";
7
7
  import { useChatLabels } from "../useChatLabels.js";
8
- import { useTranscriptActions } from "./actions.js";
8
+ import { attachmentSrcOf, toolMediaSrcOf, useTranscriptActions } from "./actions.js";
9
9
  import { useTranscriptRenderers } from "./renderers.js";
10
10
  import { Suspense, createContext, lazy, useCallback, useContext, useMemo, useRef, useState } from "react";
11
11
  import { jsx, jsxs } from "react/jsx-runtime";
12
- import { messageMediaOf } from "zidane/chat/pure";
12
+ import { messageMediaOf, transcriptArray } from "zidane/chat/pure";
13
13
  // src/chat/transcript/media-gallery.tsx
14
14
  const RowActionsMenu = lazy(() => import("../../components/RowActionsMenu.js").then((m) => ({ default: m.RowActionsMenu })));
15
15
  const GalleryContext = createContext(null);
@@ -170,7 +170,7 @@ function lightboxItemOf(medium, { actions, mediumActions, TextPreview, isLoaded
170
170
  };
171
171
  }
172
172
  if (medium.from === "tool") {
173
- const url = actions.toolMediaUrl?.(medium.callId, medium.index);
173
+ const url = toolMediaSrcOf(actions, medium.callId, medium);
174
174
  if (!url) return null;
175
175
  return {
176
176
  key: medium.key,
@@ -257,17 +257,20 @@ function MediaGalleryProvider({ events, children }) {
257
257
  const live = useRef({
258
258
  itemOf,
259
259
  lightbox,
260
- mediumActions
260
+ mediumActions,
261
+ actions
261
262
  });
262
263
  live.current = {
263
264
  itemOf,
264
265
  lightbox,
265
- mediumActions
266
+ mediumActions,
267
+ actions
266
268
  };
267
269
  const gallery = useMemo(() => ({
268
270
  open(key, origin) {
269
- const { itemOf, lightbox } = live.current;
270
- const exchanges = exchangesMedia(eventsRef.current);
271
+ const { itemOf, lightbox, actions: current } = live.current;
272
+ const source = eventsRef.current;
273
+ const exchanges = exchangesMedia(Array.isArray(source) ? source : transcriptArray(source), (att) => attachmentSrcOf(current, att));
271
274
  const row = origin.closest("[data-row]");
272
275
  const prompts = rootRef.current ? [...rootRef.current.querySelectorAll("[data-prompt]")] : [];
273
276
  const at = row ? prompts.filter((p) => p === row || p.compareDocumentPosition(row) & Node.DOCUMENT_POSITION_FOLLOWING).length : -1;
@@ -7,6 +7,7 @@ import { useTranscriptActions } from "./actions.js";
7
7
  import { AuthFailureCard } from "./AuthFailureCard.js";
8
8
  import { Caret } from "./frame.js";
9
9
  import { useTranscriptRenderers } from "./renderers.js";
10
+ import { useRowPartKey, useRowUiState } from "./row-ui-state.js";
10
11
  import { memo, useId, useState } from "react";
11
12
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
12
13
  import { CONTINUE_PROMPT, SESSION_EVENT_STATUS_STYLE, describeSpawnEnd, sessionDirLabel, sessionEventExcerpt, sessionEventMeta, shortSessionId, spawnStartParts } from "zidane/chat/pure";
@@ -335,7 +336,7 @@ const COMMAND_DETAIL_LINE = "26.4px";
335
336
  * monospace `<pre>` would misrender them as a wall of mono.
336
337
  */
337
338
  const CommandDetailRow = memo(({ label, text, syntax, className, style }) => {
338
- const [open, setOpen] = useState(false);
339
+ const [open, setOpen] = useRowUiState(useRowPartKey("command-detail"), false);
339
340
  const mounted = useStaysMounted(open);
340
341
  const labels = useChatLabels();
341
342
  const { Markdown, CodeBlock } = useTranscriptRenderers();
@@ -4,6 +4,7 @@ import { mediumKey } from "../headless/transcript/exchange-media.js";
4
4
  import { PdfPreview } from "../PdfPreview.js";
5
5
  import { TextPreview } from "../TextPreview.js";
6
6
  import { useChatLabels } from "../useChatLabels.js";
7
+ import { attachmentSrcOf, useTranscriptActions } from "./actions.js";
7
8
  import { Dot, useRowIcons } from "./frame.js";
8
9
  import { useMediaGallery } from "./media-gallery.js";
9
10
  import { MessageMedia, promptMediaOf } from "./message-media.js";
@@ -65,13 +66,14 @@ function UserPromptAttachments({ items, className, style }) {
65
66
  const labels = useChatLabels();
66
67
  const lightbox = useLightbox();
67
68
  const mediaGallery = useMediaGallery();
69
+ const actions = useTranscriptActions();
68
70
  const { TextPreview: TextPreview$1 = TextPreview } = useTranscriptRenderers();
69
71
  const [failed, setFailed] = useState(() => /* @__PURE__ */ new Set());
70
72
  const isImage = (att) => att.mediaType.startsWith("image/");
71
73
  const gallery = items.map((att, idx) => ({
72
74
  att,
73
75
  idx,
74
- src: att.dataUrl
76
+ src: attachmentSrcOf(actions, att)
75
77
  })).filter((entry) => entry.src !== void 0 && (isImage(entry.att) ? !failed.has(entry.idx) : isPdfAttachment(entry.att) || isTextLike(entry.att)));
76
78
  const galleryItems = gallery.map(({ att, idx, src }) => isImage(att) ? {
77
79
  key: String(idx),
@@ -115,14 +117,14 @@ function UserPromptAttachments({ items, className, style }) {
115
117
  title: att.name,
116
118
  "aria-label": labels.viewAttachment(att.name),
117
119
  onClick: (event) => openAt(idx, position, event.currentTarget),
118
- onContextMenu: mediaGallery && att.dataUrl ? (event) => mediaGallery.menu(event, {
120
+ onContextMenu: mediaGallery ? (event) => mediaGallery.menu(event, {
119
121
  key: mediumKey.attachment(idx),
120
122
  kind: "image",
121
- url: att.dataUrl
123
+ url: gallery[position].src
122
124
  }) : void 0,
123
125
  className: "zg-press-subtle block p-0 border-0 bg-transparent cursor-zoom-in rounded-zg-md focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--zg-ring)]",
124
126
  children: /* @__PURE__ */ jsx("img", {
125
- src: att.dataUrl,
127
+ src: gallery[position].src,
126
128
  alt: att.name,
127
129
  onError: () => setFailed((prev) => new Set(prev).add(idx)),
128
130
  className: "block w-16 h-16 object-cover rounded-zg-md bg-[var(--zg-tray)] shadow-[inset_0_0_0_1px_var(--zg-hairline)]"
@@ -2,6 +2,7 @@ import { useStaysMounted } from "../../motion/collapse.js";
2
2
  import { useChatLabels } from "../useChatLabels.js";
3
3
  import { Caret } from "./frame.js";
4
4
  import { useTranscriptRenderers } from "./renderers.js";
5
+ import { useRowPartKey, useRowUiState } from "./row-ui-state.js";
5
6
  import { ToolTiming } from "./tool-parts.js";
6
7
  import { memo, useState } from "react";
7
8
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -74,7 +75,7 @@ const ThinkingRow = memo(({ text, thinkingMs, live, autoExpand = false, classNam
74
75
  * groups); replayed groups render a bare count.
75
76
  */
76
77
  const ThinkingBatchRow = memo(({ thoughts, totalMs, autoExpand = false, className, style }) => {
77
- const [open, setOpen] = useState(false);
78
+ const [open, setOpen] = useRowUiState(useRowPartKey("thoughts"), false);
78
79
  const labels = useChatLabels();
79
80
  return /* @__PURE__ */ jsxs("div", {
80
81
  className: ["text-xs", className].filter(Boolean).join(" "),
@@ -0,0 +1,96 @@
1
+ /**
2
+ * The transcript's root items: each root row, each worker's block, and what
3
+ * follows a turn (the codemode views of an exchange with no reply text, the
4
+ * extensions' `transcript.turn-end` items), keyed and estimated. And the
5
+ * text a search reads from a row's data, to know which unmounted rows to
6
+ * mount for it.
7
+ */
8
+ import { Cluster, GroupCluster, Row } from "../headless/transcript/rows.js";
9
+ import "../headless/transcript/index.js";
10
+ /** A root item's key and first-pass height. */
11
+ export interface RootItemSpec {
12
+ /** Its id among the root items: the row's id for a row. */
13
+ key: string;
14
+ /** Its height before it is measured (px). */
15
+ estimate: number;
16
+ }
17
+ /** A root item and what it renders. */
18
+ export type RootItem = RootItemSpec & ({
19
+ kind: 'single';
20
+ cluster: Extract<Cluster, {
21
+ kind: 'single';
22
+ }>;
23
+ } | {
24
+ kind: 'group';
25
+ cluster: GroupCluster;
26
+ ci: number;
27
+ } | {
28
+ kind: 'views-end';
29
+ rowId: string;
30
+ turns: readonly string[];
31
+ } | {
32
+ kind: 'turn-end';
33
+ turnId: string;
34
+ });
35
+ /** A subagent block's id among the rows: its first row's, not its position (a prepended page shifts every position). */
36
+ export declare function groupRowId(cluster: GroupCluster, index: number): string;
37
+ /**
38
+ * The root items, in order.
39
+ *
40
+ * @param clusters - The transcript's root clusters.
41
+ * @param hidden - Rows that render nothing (no item).
42
+ * @param collapsedGroups - Worker blocks start collapsed.
43
+ * @param textlessEnds - After which row the codemode views of an exchange with no reply text go, or null.
44
+ * @param turnEnds - After which row the extensions' items for which turns go, or null.
45
+ * @param offset - Where `clusters` start among the transcript's clusters (the open part's, after the settled ones).
46
+ */
47
+ export declare function rootItems(clusters: readonly Cluster[], hidden: (row: Row) => boolean, collapsedGroups: boolean, textlessEnds: ReadonlyMap<string, readonly string[]> | null, turnEnds: ReadonlyMap<string, readonly string[]> | null, offset?: number): RootItem[];
48
+ /**
49
+ * Every string a row holds, lowercased: what it shows (and some it does not, ids and paths). Cached per row object.
50
+ * A search mounts the rows whose text holds its needle; the DOM walk then finds what they really show.
51
+ *
52
+ * @param row - A row, or a block's cluster.
53
+ */
54
+ export declare function rowSearchText(row: object): string;
55
+ /**
56
+ * The id of the last root row holding each turn among `clusters`: once per clusters array (a settled part's, read
57
+ * every tick, is walked once).
58
+ *
59
+ * @param clusters - Root clusters.
60
+ */
61
+ export declare function lastRowByTurn(clusters: readonly Cluster[]): ReadonlyMap<string, string>;
62
+ /** What follows rows, split by the part their row is in: an item list per part derives from its own. */
63
+ export interface PartEnds {
64
+ settled: ReadonlyMap<string, readonly string[]> | null;
65
+ open: ReadonlyMap<string, readonly string[]> | null;
66
+ }
67
+ /**
68
+ * Places groups of turns after the last root row holding one of them, in the part that row is in.
69
+ * Each part's map is `previous`'s while it holds the same: the settled items then stay.
70
+ *
71
+ * @param parts - The settled and the open root clusters.
72
+ * @param parts.settled - The settled clusters.
73
+ * @param parts.open - The open clusters.
74
+ * @param place - Calls `at` for each group: `at(turnId)` is where a turn's last row is.
75
+ * @param previous - The last result.
76
+ */
77
+ export declare function endsByRow(parts: {
78
+ settled: readonly Cluster[];
79
+ open: readonly Cluster[];
80
+ }, place: (at: (turnId: string) => {
81
+ rowId: string;
82
+ open: boolean;
83
+ } | undefined, add: (where: {
84
+ rowId: string;
85
+ open: boolean;
86
+ }, turns: readonly string[]) => void) => void, previous: PartEnds | null): PartEnds;
87
+ /**
88
+ * The keys of the items whose data holds one of `needles` (lowercased).
89
+ *
90
+ * @param items - The root items, or their settled and open parts.
91
+ * @param needles - What the search looks for.
92
+ */
93
+ export declare function matchingItems(items: readonly RootItem[] | {
94
+ settled: readonly RootItem[];
95
+ open: readonly RootItem[];
96
+ }, needles: readonly string[]): string[];
@@ -0,0 +1,180 @@
1
+ import { firstRowId } from "../headless/transcript/rows.js";
2
+ import { rowTurnIds } from "../headless/transcript/select-stops.js";
3
+ import { rowEstimatePx } from "./row-estimate.js";
4
+ import { noteTranscriptPass } from "zidane/chat/pure";
5
+ // src/chat/transcript/root-items.ts
6
+ /** A subagent block's id among the rows: its first row's, not its position (a prepended page shifts every position). */
7
+ function groupRowId(cluster, index) {
8
+ return `group-${firstRowId(cluster) ?? index}-${cluster.childId}`;
9
+ }
10
+ /** A collapsed worker block: its header line. */
11
+ const GROUP_COLLAPSED_PX = 34;
12
+ function groupEstimate(cluster) {
13
+ let px = GROUP_COLLAPSED_PX;
14
+ for (const item of cluster.body) px += item.kind === "group" ? groupEstimate(item) : rowEstimatePx(item.row);
15
+ return px;
16
+ }
17
+ /**
18
+ * The root items, in order.
19
+ *
20
+ * @param clusters - The transcript's root clusters.
21
+ * @param hidden - Rows that render nothing (no item).
22
+ * @param collapsedGroups - Worker blocks start collapsed.
23
+ * @param textlessEnds - After which row the codemode views of an exchange with no reply text go, or null.
24
+ * @param turnEnds - After which row the extensions' items for which turns go, or null.
25
+ * @param offset - Where `clusters` start among the transcript's clusters (the open part's, after the settled ones).
26
+ */
27
+ function rootItems(clusters, hidden, collapsedGroups, textlessEnds, turnEnds, offset = 0) {
28
+ noteTranscriptPass("root-items", clusters.length);
29
+ const out = [];
30
+ clusters.forEach((cluster, at) => {
31
+ const ci = offset + at;
32
+ if (cluster.kind === "group") {
33
+ out.push({
34
+ kind: "group",
35
+ cluster,
36
+ ci,
37
+ key: groupRowId(cluster, ci),
38
+ estimate: collapsedGroups ? GROUP_COLLAPSED_PX : groupEstimate(cluster)
39
+ });
40
+ return;
41
+ }
42
+ const row = cluster.row;
43
+ if (hidden(row)) return;
44
+ out.push({
45
+ kind: "single",
46
+ cluster,
47
+ key: row.id,
48
+ estimate: rowEstimatePx(row)
49
+ });
50
+ const textless = textlessEnds?.get(row.id);
51
+ if (textless) out.push({
52
+ kind: "views-end",
53
+ rowId: row.id,
54
+ turns: textless,
55
+ key: `views-end:${row.id}`,
56
+ estimate: 0
57
+ });
58
+ for (const turnId of turnEnds?.get(row.id) ?? []) out.push({
59
+ kind: "turn-end",
60
+ turnId,
61
+ key: `turn-end:${turnId}`,
62
+ estimate: 0
63
+ });
64
+ });
65
+ return out;
66
+ }
67
+ const TEXT_CACHE = /* @__PURE__ */ new WeakMap();
68
+ /** A row's text past this is not searched for unmounted matches (it mounts once the reader scrolls to it). */
69
+ const MAX_TEXT = 2e5;
70
+ /**
71
+ * Every string a row holds, lowercased: what it shows (and some it does not, ids and paths). Cached per row object.
72
+ * A search mounts the rows whose text holds its needle; the DOM walk then finds what they really show.
73
+ *
74
+ * @param row - A row, or a block's cluster.
75
+ */
76
+ function rowSearchText(row) {
77
+ const hit = TEXT_CACHE.get(row);
78
+ if (hit !== void 0) return hit;
79
+ const parts = [];
80
+ let size = 0;
81
+ const walk = (value, depth) => {
82
+ if (size > MAX_TEXT || depth > 8) return;
83
+ if (typeof value === "string") {
84
+ parts.push(value);
85
+ size += value.length;
86
+ } else if (Array.isArray(value)) for (const v of value) walk(v, depth + 1);
87
+ else if (value && typeof value === "object") for (const v of Object.values(value)) walk(v, depth + 1);
88
+ };
89
+ walk(row, 0);
90
+ const text = parts.join("\n").toLowerCase();
91
+ TEXT_CACHE.set(row, text);
92
+ return text;
93
+ }
94
+ /** Each turn's last root row among `clusters` (single clusters only), made once per clusters array. */
95
+ const lastRows = /* @__PURE__ */ new WeakMap();
96
+ /**
97
+ * The id of the last root row holding each turn among `clusters`: once per clusters array (a settled part's, read
98
+ * every tick, is walked once).
99
+ *
100
+ * @param clusters - Root clusters.
101
+ */
102
+ function lastRowByTurn(clusters) {
103
+ let map = lastRows.get(clusters);
104
+ if (!map) {
105
+ noteTranscriptPass("turn-rows", clusters.length);
106
+ const out = /* @__PURE__ */ new Map();
107
+ for (const cluster of clusters) {
108
+ if (cluster.kind !== "single") continue;
109
+ for (const id of rowTurnIds(cluster.row)) out.set(id, cluster.row.id);
110
+ }
111
+ map = out;
112
+ lastRows.set(clusters, map);
113
+ }
114
+ return map;
115
+ }
116
+ function sameEnds(a, b) {
117
+ if (a === b) return true;
118
+ if (!a || !b || a.size !== b.size) return false;
119
+ for (const [rowId, turns] of a) {
120
+ const other = b.get(rowId);
121
+ if (!other || other.length !== turns.length || other.some((t, i) => t !== turns[i])) return false;
122
+ }
123
+ return true;
124
+ }
125
+ /**
126
+ * Places groups of turns after the last root row holding one of them, in the part that row is in.
127
+ * Each part's map is `previous`'s while it holds the same: the settled items then stay.
128
+ *
129
+ * @param parts - The settled and the open root clusters.
130
+ * @param parts.settled - The settled clusters.
131
+ * @param parts.open - The open clusters.
132
+ * @param place - Calls `at` for each group: `at(turnId)` is where a turn's last row is.
133
+ * @param previous - The last result.
134
+ */
135
+ function endsByRow(parts, place, previous) {
136
+ const settledRows = lastRowByTurn(parts.settled);
137
+ const openRows = lastRowByTurn(parts.open);
138
+ const at = (turnId) => {
139
+ const open = openRows.get(turnId);
140
+ if (open !== void 0) return {
141
+ rowId: open,
142
+ open: true
143
+ };
144
+ const settled = settledRows.get(turnId);
145
+ return settled !== void 0 ? {
146
+ rowId: settled,
147
+ open: false
148
+ } : void 0;
149
+ };
150
+ const settled = /* @__PURE__ */ new Map();
151
+ const open = /* @__PURE__ */ new Map();
152
+ place(at, (where, turns) => (where.open ? open : settled).set(where.rowId, turns));
153
+ const s = settled.size > 0 ? settled : null;
154
+ const o = open.size > 0 ? open : null;
155
+ return {
156
+ settled: previous && sameEnds(previous.settled, s) ? previous.settled : s,
157
+ open: previous && sameEnds(previous.open, o) ? previous.open : o
158
+ };
159
+ }
160
+ /** Matches past this many items are not mounted ahead (the search's own cap is 500 matches). */
161
+ const MAX_MATCH_ITEMS = 500;
162
+ /**
163
+ * The keys of the items whose data holds one of `needles` (lowercased).
164
+ *
165
+ * @param items - The root items, or their settled and open parts.
166
+ * @param needles - What the search looks for.
167
+ */
168
+ function matchingItems(items, needles) {
169
+ if (needles.length === 0) return [];
170
+ const out = [];
171
+ const all = Array.isArray(items) ? items : [...items.settled, ...items.open];
172
+ for (const item of all) {
173
+ if (item.kind !== "single" && item.kind !== "group") continue;
174
+ const text = rowSearchText(item.kind === "single" ? item.cluster.row : item.cluster);
175
+ if (needles.some((needle) => text.includes(needle))) out.push(item.key);
176
+ if (out.length >= MAX_MATCH_ITEMS) break;
177
+ }
178
+ return out;
179
+ }
180
+ export { endsByRow, groupRowId, lastRowByTurn, matchingItems, rootItems, rowSearchText };
@@ -0,0 +1,165 @@
1
+ /** A root row's state: a placeholder that never mounted, its content mounted, or a placeholder again (parked). */
2
+ export type RowPhase = 'lazy' | 'mounted' | 'parked';
3
+ /** What a row wrapper hands its transcript's mounter. */
4
+ export interface RowSlot {
5
+ /** The root item's key (the row's id). */
6
+ key: string;
7
+ /** The wrapper element. */
8
+ el: HTMLElement;
9
+ /** A `content-visibility: auto` row; false for a plain box (a worker's block). */
10
+ cv: boolean;
11
+ /** Its phase now (the mounter keeps it). */
12
+ phase: RowPhase;
13
+ /** Renders the row in a phase: `background` when mounted ahead of the view, `parkedPx` its height parked. */
14
+ set: (phase: RowPhase, background: boolean, parkedPx?: number) => void;
15
+ }
16
+ /** How a new wrapper starts. */
17
+ export interface RowStart {
18
+ /** Its content mounts with it. */
19
+ mounted: boolean;
20
+ /** It is the transcript's tail (may play the enter animation if new). */
21
+ eager: boolean;
22
+ /** It mounted before in this transcript (a wrapper made again: never new). */
23
+ seen: boolean;
24
+ }
25
+ /** One transcript's root rows: what mounts, what parks, and their heights. */
26
+ export declare class RowMounter {
27
+ private scope;
28
+ private readonly slots;
29
+ private readonly byEl;
30
+ /** The last phase of each key in this transcript: a wrapper made again starts from it. */
31
+ private readonly phases;
32
+ private eager;
33
+ private live;
34
+ private held;
35
+ private all;
36
+ private reveals;
37
+ private readonly skipped;
38
+ /** Each mounted row's height as last laid out (its ResizeObserver entry): what a parked placeholder keeps. */
39
+ private readonly boxes;
40
+ private readonly near;
41
+ private readonly queue;
42
+ private mountedCount;
43
+ private timeline;
44
+ private scroller;
45
+ private far;
46
+ private close;
47
+ private ro;
48
+ private readonly cvEvents;
49
+ private readonly io;
50
+ private pumpScheduled;
51
+ private lastActivity;
52
+ private direction;
53
+ private lastTop;
54
+ private parkTimer;
55
+ /** Rows mounted since the last parking pass found the transcript within budget. */
56
+ private dirty;
57
+ private parking;
58
+ private detach;
59
+ /**
60
+ * The transcript shows `scope` (a session): another one forgets this one's phases and jumps.
61
+ *
62
+ * @param scope - The session shown.
63
+ */
64
+ reset(scope: unknown): void;
65
+ private sizeKey;
66
+ /**
67
+ * The row's last true height, if it was ever measured rendered.
68
+ *
69
+ * @param key - The row's key.
70
+ */
71
+ sizeOf(key: string): number | undefined;
72
+ /**
73
+ * What the render holds as the tail (mounts with its first render) and the live exchange (never parks).
74
+ *
75
+ * @param eager - The tail's keys.
76
+ * @param live - The open exchange's keys.
77
+ */
78
+ setTail(eager: ReadonlySet<string>, live: ReadonlySet<string>): void;
79
+ /**
80
+ * How a new wrapper for `key` starts.
81
+ *
82
+ * @param key - The row's key.
83
+ */
84
+ start(key: string): RowStart;
85
+ /**
86
+ * Rows to mount wherever they are and keep mounted while held (a search's matches, the select cursor's turn).
87
+ * Call it from a layout effect: the rows render before the next paint.
88
+ *
89
+ * @param keys - The held rows.
90
+ * @param all - Every row (a search with no needle to narrow it).
91
+ */
92
+ hold(keys: readonly string[], all: boolean): void;
93
+ /**
94
+ * Mounts the row `key` now, wherever it is, and holds it a while (the last few jumps). Call it outside React's
95
+ * render and effects: it commits synchronously.
96
+ *
97
+ * @param key - The row's key.
98
+ * @returns Its wrapper, or null when this transcript has no such row.
99
+ */
100
+ reveal(key: string): HTMLElement | null;
101
+ /**
102
+ * Mounts the rows within `px` above and below the root row holding `el` (by their heights now), so a jump to
103
+ * `el` lands among rows at their real heights: mounted after it, they would move it. The rows render with the
104
+ * next commit.
105
+ *
106
+ * @param el - An element inside a root row.
107
+ * @param px - How far each way.
108
+ * @returns Whether any row was not mounted.
109
+ */
110
+ mountAround(el: Element, px: number): boolean;
111
+ /**
112
+ * A wrapper arrived (its layout effect): observe it, and queue it if it has not mounted.
113
+ *
114
+ * @param slot - The wrapper.
115
+ * @returns The stop.
116
+ */
117
+ register(slot: RowSlot): () => void;
118
+ /** Stops observing (the transcript unmounted). */
119
+ dispose(): void;
120
+ private ensure;
121
+ private observeApproach;
122
+ private mounted;
123
+ /** Moves a row to `phase` and renders it there. */
124
+ private transition;
125
+ private onFar;
126
+ private onNear;
127
+ private onCvState;
128
+ /** Observing again reports the row's size now: a row just rendered may have kept its placeholder's. */
129
+ private remeasure;
130
+ private onResize;
131
+ private schedulePump;
132
+ private pump;
133
+ private scheduleParking;
134
+ private whenIdle;
135
+ /** Whether a row must stay mounted now, wherever it is. */
136
+ private isHeld;
137
+ /** One parking pass: plan on a clean layout, then park the plan in idle slices while the reader holds still. */
138
+ private parkPass;
139
+ /** Counts for tests and the perf harness. */
140
+ stats(): {
141
+ mounted: number;
142
+ parked: number;
143
+ rows: number;
144
+ };
145
+ }
146
+ /** The mounter of the transcript around a row wrapper; null outside one (every row mounts). */
147
+ export declare const RowMountContext: import("react").Context<RowMounter | null>;
148
+ /**
149
+ * Mounts the transcript rows within `px` above and below the root row holding `el` (`RowMounter.mountAround`).
150
+ *
151
+ * @param scroller - The transcript's scroll container.
152
+ * @param el - An element inside a root row.
153
+ * @param px - How far each way.
154
+ * @returns Whether any row was not mounted (they render with the next commit).
155
+ */
156
+ export declare function mountAround(scroller: Element, el: Element, px: number): boolean;
157
+ /**
158
+ * The element of the transcript row `id` under `scroller`, mounting its content first if it has not mounted (a jump
159
+ * to a turn, a view put back where it was). Call it outside React's render and effects: it commits synchronously.
160
+ *
161
+ * @param scroller - The transcript's scroll container.
162
+ * @param id - The row's id (a root row's, or a worker block's).
163
+ * @returns The row's element, or null when no transcript there has it.
164
+ */
165
+ export declare function revealRow(scroller: Element, id: string): HTMLElement | null;