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
@@ -0,0 +1,64 @@
1
+ /**
2
+ * A streaming reply's chunks, kept up to date as text arrives instead of split
3
+ * again from the start on every frame.
4
+ *
5
+ * `splitMarkdown` reads the whole reply, and so did the partial-fence and
6
+ * partial-emphasis trims (their patterns anchor at the end, but scan the whole
7
+ * string to get there) and the open-fence read of the last chunk: O(L) per
8
+ * frame, O(L²) over a reply. A {@link MarkdownStream} keeps the scan's state
9
+ * (the open fence or HTML block, the closed chunks, the line not yet whole) and
10
+ * reads only the characters that arrived since the last frame, plus the line
11
+ * still arriving. Closed chunks keep their string from frame to frame, so a
12
+ * memoised render compares them by identity.
13
+ *
14
+ * The chunks it gives once the text is final are exactly `splitMarkdown(text,
15
+ * { streaming: true })`. Internal to the chat area.
16
+ */
17
+ import { OpenFence } from "./markdown-chunks.js";
18
+ /** One frame of a reply. */
19
+ export interface MarkdownFrame {
20
+ /** The chunks that can no longer change. The same array until one more closes. */
21
+ closed: readonly string[];
22
+ /** The rest, held back as the trims hold it while streaming. May be empty. */
23
+ tail: string;
24
+ /** The fence the tail ends inside, while streaming (as `openFenceOf` reads it). */
25
+ fence: OpenFence | null;
26
+ }
27
+ /** What the stream read: deterministic counts for the tests and benches. */
28
+ export interface MarkdownStreamStats {
29
+ /** Characters read by the scan: new characters, each whole line once, and the line still arriving on each frame. */
30
+ scanned: number;
31
+ /** Frames asked for. */
32
+ frames: number;
33
+ /** Texts that did not extend the last one, so the scan started over. */
34
+ restarts: number;
35
+ }
36
+ /** One reply's chunks, read incrementally. Feed it the reply on each frame. */
37
+ export declare class MarkdownStream {
38
+ private text;
39
+ /** Where the line not yet whole starts. */
40
+ private lineStart;
41
+ /** Where the search for the next newline resumes. */
42
+ private searched;
43
+ private scanner;
44
+ private starts;
45
+ private chunks;
46
+ private view;
47
+ /** Whether a chunk starts at the line not yet whole is already decided. */
48
+ private decided;
49
+ readonly stats: MarkdownStreamStats;
50
+ /**
51
+ * The reply's chunks as of `text`.
52
+ *
53
+ * @param text - The whole reply so far. Usually the last one with more at its end; anything else starts the scan over.
54
+ * @param streaming - Still streaming: trim what is still arriving, and read the open fence.
55
+ */
56
+ frame(text: string, streaming: boolean): MarkdownFrame;
57
+ /** The fence open at the end of the tail, `last` being its trimmed last line. */
58
+ private openFence;
59
+ private wholeLine;
60
+ /** A chunk starts at `at` (a line start): the one before closes, without the newline between them. */
61
+ private cut;
62
+ private closedView;
63
+ private restart;
64
+ }
@@ -0,0 +1,143 @@
1
+ import { BlockScanner, fenceLanguage, isDefinitionLine, opensChunk, withoutCR } from "./markdown-scan.js";
2
+ import { isFenceClose, parseFenceOpen } from "zidane/chat/pure";
3
+ // src/chat/headless/markdown-stream.ts
4
+ /** A last line of one or two backticks or tildes: a fence still arriving (`withoutPartialFence`). */
5
+ const PARTIAL_FENCE_LINE = /^ {0,3}(?:`{1,2}|~{1,2})$/;
6
+ /** A last line of emphasis markers with nothing after them (`withoutPartialEmphasis`). */
7
+ const PARTIAL_EMPHASIS_LINE = /^( {0,3}(?:[*+-]|\d{1,9}[.)]) +)?(?:\*{1,3}|_{1,3})$/;
8
+ const NONE = [];
9
+ /**
10
+ * A copy of `text` that holds nothing of the string it was cut from. A slice
11
+ * keeps its source alive, and the source here is the whole reply as of one
12
+ * frame: a closed chunk, held for the reply's life (and by the parse cache),
13
+ * would hold a frame's reply each. Slicing a concatenation flattens it into a
14
+ * string of its own first.
15
+ */
16
+ function detach(text) {
17
+ return text.length < 13 ? text : `${text} `.slice(0, -1);
18
+ }
19
+ /** One reply's chunks, read incrementally. Feed it the reply on each frame. */
20
+ var MarkdownStream = class {
21
+ text = "";
22
+ /** Where the line not yet whole starts. */
23
+ lineStart = 0;
24
+ /** Where the search for the next newline resumes. */
25
+ searched = 0;
26
+ scanner = new BlockScanner(0);
27
+ starts = [0];
28
+ chunks = [];
29
+ view = NONE;
30
+ /** Whether a chunk starts at the line not yet whole is already decided. */
31
+ decided = false;
32
+ stats = {
33
+ scanned: 0,
34
+ frames: 0,
35
+ restarts: 0
36
+ };
37
+ /**
38
+ * The reply's chunks as of `text`.
39
+ *
40
+ * @param text - The whole reply so far. Usually the last one with more at its end; anything else starts the scan over.
41
+ * @param streaming - Still streaming: trim what is still arriving, and read the open fence.
42
+ */
43
+ frame(text, streaming) {
44
+ this.stats.frames++;
45
+ if (!text.startsWith(this.text)) this.restart();
46
+ this.text = text;
47
+ let from = this.searched;
48
+ for (let nl = text.indexOf("\n", from); nl !== -1; nl = text.indexOf("\n", from)) {
49
+ this.stats.scanned += nl + 1 - from;
50
+ this.wholeLine(text.slice(this.lineStart, nl));
51
+ this.lineStart = nl + 1;
52
+ from = nl + 1;
53
+ }
54
+ this.stats.scanned += text.length - from;
55
+ this.searched = text.length;
56
+ const partial = text.slice(this.lineStart);
57
+ this.stats.scanned += partial.length;
58
+ let cutAt = -1;
59
+ if (this.scanner.pending && !this.decided) {
60
+ const opens = opensChunk(partial, false);
61
+ if (opens !== void 0) {
62
+ this.decided = true;
63
+ if (opens) this.cut(this.lineStart);
64
+ } else if (!streaming && opensChunk(partial, true)) cutAt = this.lineStart;
65
+ }
66
+ const { fence, html } = this.scanner;
67
+ const whole = this.scanner.refs || !fence && !html && isDefinitionLine(partial) || text.length < 1200;
68
+ let closed = NONE;
69
+ let tailStart = 0;
70
+ if (!whole) {
71
+ closed = this.closedView();
72
+ tailStart = this.starts.at(-1);
73
+ if (cutAt >= 0) {
74
+ closed = [...closed, detach(text.slice(tailStart, cutAt - 1))];
75
+ tailStart = cutAt;
76
+ }
77
+ }
78
+ if (!streaming) return {
79
+ closed,
80
+ tail: text.slice(tailStart),
81
+ fence: null
82
+ };
83
+ let last = partial;
84
+ if (this.lineStart > 0 && PARTIAL_FENCE_LINE.test(last)) last = "";
85
+ else if (PARTIAL_EMPHASIS_LINE.test(last)) last = last.replace(PARTIAL_EMPHASIS_LINE, "$1");
86
+ const tail = last === partial ? text.slice(tailStart) : text.slice(tailStart, this.lineStart) + last;
87
+ return {
88
+ closed,
89
+ tail,
90
+ fence: this.openFence(last, tailStart)
91
+ };
92
+ }
93
+ /** The fence open at the end of the tail, `last` being its trimmed last line. */
94
+ openFence(last, tailStart) {
95
+ const { text, lineStart } = this;
96
+ let open = this.scanner.fence;
97
+ let at = this.scanner.fenceAt;
98
+ let end = this.scanner.fenceEnd;
99
+ if (open) {
100
+ if (isFenceClose(withoutCR(last), open.char, open.length)) open = null;
101
+ } else if (!this.scanner.html) {
102
+ open = parseFenceOpen(withoutCR(last));
103
+ at = lineStart;
104
+ end = -1;
105
+ }
106
+ if (!open || open.indent !== 0) return null;
107
+ const opener = end < 0 ? last : text.slice(at, end);
108
+ const body = end < 0 ? "" : text.slice(end + 1, lineStart) + last;
109
+ return {
110
+ before: at > tailStart ? text.slice(tailStart, at - 1) : "",
111
+ language: fenceLanguage(opener.slice(open.length)),
112
+ code: body.endsWith("\n") ? body.slice(0, -1) : body
113
+ };
114
+ }
115
+ wholeLine(line) {
116
+ const at = this.lineStart;
117
+ if (this.scanner.pending && !this.decided && opensChunk(line, true)) this.cut(at);
118
+ this.decided = false;
119
+ this.scanner.feed(line, at);
120
+ this.stats.scanned += line.length;
121
+ }
122
+ /** A chunk starts at `at` (a line start): the one before closes, without the newline between them. */
123
+ cut(at) {
124
+ this.chunks.push(detach(this.text.slice(this.starts.at(-1), at - 1)));
125
+ this.starts.push(at);
126
+ this.scanner.startChunk();
127
+ }
128
+ closedView() {
129
+ if (this.view.length !== this.chunks.length) this.view = this.chunks.slice();
130
+ return this.view;
131
+ }
132
+ restart() {
133
+ this.stats.restarts++;
134
+ this.lineStart = 0;
135
+ this.searched = 0;
136
+ this.scanner = new BlockScanner(0);
137
+ this.starts = [0];
138
+ this.chunks = [];
139
+ this.view = NONE;
140
+ this.decided = false;
141
+ }
142
+ };
143
+ export { MarkdownStream };
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Paging through a tool result the host clipped for the wire: a pure model
3
+ * of what is loaded (the text from the start, the whole length), read one
4
+ * range at a time through the host (`ChatHost.toolOutputRange`). "Load full
5
+ * output" reads the first page, "Load more" the next one, "Load all" the
6
+ * rest, a few pages at a time and appended in order. Sizes and offsets are
7
+ * UTF-16 code units, as `ToolResultSlice` counts them.
8
+ */
9
+ import { Readable } from "./store.js";
10
+ import { ToolResultSlice } from "zidane/chat";
11
+ /** UTF-16 code units in one page of a clipped tool result: what "Load full output" and "Load more" each read. */
12
+ export declare const TOOL_OUTPUT_PAGE_SIZE = 65536;
13
+ /** A range of a tool result's text, in UTF-16 code units. */
14
+ export interface ToolOutputRange {
15
+ /** Where the range starts. */
16
+ offset: number;
17
+ /** How many code units it covers. */
18
+ length: number;
19
+ }
20
+ /** Reads one range of a call's result: `null` when the host holds no result for the call. */
21
+ export type ToolOutputRangeReader = (range: ToolOutputRange) => Promise<ToolResultSlice | null>;
22
+ /** What a {@link ToolOutputPager} has loaded. */
23
+ export interface ToolOutputPagerState {
24
+ /** The text loaded so far, from the start of the result. */
25
+ text: string;
26
+ /** The whole result's length; `null` until the first page answered. */
27
+ total: number | null;
28
+ /** The host holds no result for the call: the clipped preview stays. */
29
+ missing: boolean;
30
+ /** A read is in flight. */
31
+ loading: boolean;
32
+ /** The last read's failure, raw (the UI words it through labels); `null` when it succeeded. */
33
+ error: string | null;
34
+ }
35
+ /** A clipped result's pages, loaded on demand. */
36
+ export interface ToolOutputPager extends Readable<ToolOutputPagerState> {
37
+ /** Reads the next page (the first one on the first call). No-op while a read runs or once all is loaded. */
38
+ loadMore: () => Promise<void>;
39
+ /** Reads every page still missing, appended in order. No-op while a read runs or once all is loaded. */
40
+ loadAll: () => Promise<void>;
41
+ }
42
+ /** Options of {@link createToolOutputPager}. */
43
+ export interface ToolOutputPagerOptions {
44
+ /** Code units per page. Default {@link TOOL_OUTPUT_PAGE_SIZE}. */
45
+ pageSize?: number;
46
+ /** Pages "Load all" reads at once. Default 4. */
47
+ parallel?: number;
48
+ }
49
+ /**
50
+ * Whether every page of the result is loaded.
51
+ *
52
+ * @param state - The pager's state.
53
+ */
54
+ export declare function toolOutputPagerDone(state: ToolOutputPagerState): boolean;
55
+ /**
56
+ * A range of a whole text, as a host that holds the text whole answers it (a server too old for ranges).
57
+ *
58
+ * @param text - The whole result.
59
+ * @param range - The range asked.
60
+ */
61
+ export declare function sliceToolOutput(text: string, range: ToolOutputRange): ToolResultSlice;
62
+ /**
63
+ * A pager over one call's result.
64
+ *
65
+ * @param read - Reads a range of the result (the host's `toolOutputRange`, bound to the call).
66
+ * @param options - Page size and how many pages "Load all" reads at once.
67
+ */
68
+ export declare function createToolOutputPager(read: ToolOutputRangeReader, options?: ToolOutputPagerOptions): ToolOutputPager;
@@ -0,0 +1,113 @@
1
+ import { writable } from "./store.js";
2
+ // src/chat/headless/output-pager.ts
3
+ /** UTF-16 code units in one page of a clipped tool result: what "Load full output" and "Load more" each read. */
4
+ const TOOL_OUTPUT_PAGE_SIZE = 65536;
5
+ /** Pages "Load all" reads at once. */
6
+ const PARALLEL_PAGES = 4;
7
+ /**
8
+ * Whether every page of the result is loaded.
9
+ *
10
+ * @param state - The pager's state.
11
+ */
12
+ function toolOutputPagerDone(state) {
13
+ return state.missing || state.total !== null && state.text.length >= state.total;
14
+ }
15
+ /**
16
+ * A range of a whole text, as a host that holds the text whole answers it (a server too old for ranges).
17
+ *
18
+ * @param text - The whole result.
19
+ * @param range - The range asked.
20
+ */
21
+ function sliceToolOutput(text, range) {
22
+ const offset = Math.min(Math.max(0, Math.floor(range.offset)), text.length);
23
+ return {
24
+ text: text.slice(offset, offset + Math.max(0, Math.floor(range.length))),
25
+ offset,
26
+ total: text.length
27
+ };
28
+ }
29
+ const INITIAL = {
30
+ text: "",
31
+ total: null,
32
+ missing: false,
33
+ loading: false,
34
+ error: null
35
+ };
36
+ /**
37
+ * A pager over one call's result.
38
+ *
39
+ * @param read - Reads a range of the result (the host's `toolOutputRange`, bound to the call).
40
+ * @param options - Page size and how many pages "Load all" reads at once.
41
+ */
42
+ function createToolOutputPager(read, options = {}) {
43
+ const pageSize = Math.max(1, options.pageSize ?? 65536);
44
+ const parallel = Math.max(1, options.parallel ?? PARALLEL_PAGES);
45
+ const state = writable(INITIAL);
46
+ /** Reads up to `pages` pages from the end of what is loaded. */
47
+ const run = async (pages) => {
48
+ const start = state.get();
49
+ if (start.loading || toolOutputPagerDone(start)) return;
50
+ let { text, total } = start;
51
+ let missing = false;
52
+ let error = null;
53
+ state.set({
54
+ ...start,
55
+ loading: true,
56
+ error: null
57
+ });
58
+ let left = pages;
59
+ while (left > 0 && error === null && !missing && (total === null || text.length < total)) {
60
+ const count = total === null ? 1 : Math.min(left, parallel, Math.ceil((total - text.length) / pageSize));
61
+ const from = text.length;
62
+ const reads = await Promise.allSettled(Array.from({ length: count }, (_, i) => read({
63
+ offset: from + i * pageSize,
64
+ length: pageSize
65
+ })));
66
+ left -= count;
67
+ for (const answer of reads) {
68
+ const appended = text.length > from;
69
+ if (answer.status === "rejected") {
70
+ error = answer.reason instanceof Error ? answer.reason.message : String(answer.reason);
71
+ break;
72
+ }
73
+ const slice = answer.value;
74
+ if (slice === null) {
75
+ missing = text.length === 0;
76
+ if (!missing) error = `no result past ${text.length}`;
77
+ break;
78
+ }
79
+ if (slice.offset !== text.length) {
80
+ if (!appended) error = `slice at ${slice.offset}, asked ${text.length}`;
81
+ break;
82
+ }
83
+ if (slice.text.length === 0 && slice.offset < slice.total) {
84
+ error = `empty slice at ${slice.offset} of ${slice.total}`;
85
+ break;
86
+ }
87
+ text += slice.text;
88
+ total = slice.total;
89
+ }
90
+ if (left > 0) state.set({
91
+ text,
92
+ total,
93
+ missing,
94
+ loading: true,
95
+ error
96
+ });
97
+ }
98
+ state.set({
99
+ text,
100
+ total: missing ? 0 : total,
101
+ missing,
102
+ loading: false,
103
+ error
104
+ });
105
+ };
106
+ return {
107
+ get: state.get,
108
+ subscribe: state.subscribe,
109
+ loadMore: () => run(1),
110
+ loadAll: () => run(Number.POSITIVE_INFINITY)
111
+ };
112
+ }
113
+ export { TOOL_OUTPUT_PAGE_SIZE, createToolOutputPager, sliceToolOutput, toolOutputPagerDone };
@@ -247,6 +247,16 @@ export declare function dateBucket(at: number, now: number, labels?: {
247
247
  modelVerdictTitle: (approved: boolean, model: string, confidence: string | null) => string;
248
248
  loadFullOutput: string;
249
249
  loadingFullOutput: string;
250
+ loadMoreOutput: string;
251
+ loadAllOutput: string;
252
+ loadingOutput: string;
253
+ outputLoaded: (loaded: string, total: string) => string;
254
+ outputLoadFailed: string;
255
+ loadFullInput: string;
256
+ loadingFullInput: string;
257
+ loadFullDiff: string;
258
+ loadingFullDiff: string;
259
+ diffNotShown: (hunks: number, size: string) => string;
250
260
  showOutput: string;
251
261
  inputCaption: string;
252
262
  outputCaption: string;
@@ -7,6 +7,11 @@
7
7
  *
8
8
  * Subagent events are left out: the parent's own call that spawned them
9
9
  * (still running) is what the row says.
10
+ *
11
+ * A window gets the transcript stream only of the sessions it shows or keeps
12
+ * warm (`sessions.subscribe`). For the others, the running tools come from
13
+ * the session's work list (`work:snapshot`, sent to every window), named by
14
+ * the tool alone.
10
15
  */
11
16
  import { SidebarLabels } from "./labels.js";
12
17
  import { StreamEvent } from "zidane/chat";
@@ -38,6 +43,15 @@ export type SessionActivitySignal = {
38
43
  kind: 'stream:retry:cleared';
39
44
  sessionId: string;
40
45
  source: string;
46
+ } | {
47
+ kind: 'work:snapshot';
48
+ sessionId: string;
49
+ items: readonly {
50
+ kind: string;
51
+ id: string;
52
+ label: string;
53
+ childId?: string;
54
+ }[];
41
55
  } | {
42
56
  kind: 'event';
43
57
  sessionId: string;
@@ -22,6 +22,37 @@ const THINKING = {
22
22
  phase: "thinking",
23
23
  run: true
24
24
  };
25
+ /** A tool named by its name alone (a work list item), as the row words it. */
26
+ function toolByName(callId, name) {
27
+ const overview = toolOverview({
28
+ name,
29
+ displayName: displayNameFor(name, {}),
30
+ ok: null
31
+ });
32
+ return {
33
+ callId,
34
+ label: overview.label,
35
+ ...overview.title ? { title: overview.title } : {}
36
+ };
37
+ }
38
+ /**
39
+ * The running tools as the session's work list has them. A tool the stream
40
+ * already named keeps its words (they read its input); a new one is named by
41
+ * the tool alone. Background tasks and subagents' calls are left out.
42
+ */
43
+ function reduceWorkSnapshot(prev, items) {
44
+ const running = items.filter((item) => item.kind === "tool" && item.childId === void 0);
45
+ const before = prev?.tools ?? [];
46
+ if (running.length === before.length && running.every((item, i) => before[i].callId === item.id)) return prev;
47
+ if (!prev && running.length === 0) return prev;
48
+ const tools = running.map((item) => before.find((t) => t.callId === item.id) ?? toolByName(item.id, item.label));
49
+ const phase = prev?.phase === "compacting" || prev?.phase === "retrying" ? prev.phase : "thinking";
50
+ return {
51
+ tools,
52
+ phase: tools.length === 0 && prev ? prev.phase : phase,
53
+ run: prev?.run ?? true
54
+ };
55
+ }
25
56
  /**
26
57
  * The next activity after `signal`; the same object when nothing a row shows changed, `null` once the run ended.
27
58
  *
@@ -52,6 +83,7 @@ function reduceActivity(prev, signal) {
52
83
  ...prev,
53
84
  phase: "thinking"
54
85
  } : prev;
86
+ case "work:snapshot": return reduceWorkSnapshot(prev, signal.items);
55
87
  case "event": {
56
88
  const event = signal.event;
57
89
  if (event.childId) return prev;
@@ -19,7 +19,8 @@
19
19
  * switch drops every stream, unless the runtime comes back as the same
20
20
  * process. After a reconnect (runtime or the open session's server), the
21
21
  * windows on screen climb the reconnect ladder (`streams.resync`).
22
- * - Prewarm: the transcripts around the open session load in idle time.
22
+ * - Prewarm: the transcripts around the open session load in idle time,
23
+ * when the open session or the order around it changes (`prewarm.ts`).
23
24
  * - Spaces: the shown space (kept by the views store), the slide direction of
24
25
  * the last switch, following the open session to its space, and reopening
25
26
  * the conversation last open in a space when switching back to it.
@@ -126,6 +127,8 @@ export interface SessionDirectoryStreams<K extends string, P> {
126
127
  resync: (sessionId: K) => void;
127
128
  /** Drop every cached transcript except these. */
128
129
  evictExcept: (keep: ReadonlySet<K>) => void;
130
+ /** About how many bytes the session's cached rows hold: prewarm keeps its window within a byte budget. */
131
+ eventBytes?: (sessionId: K) => number;
129
132
  /** Drop every stream (a runtime switch). */
130
133
  dropAll: () => void;
131
134
  /** Drop one session's stream (deleted). */
@@ -220,6 +223,11 @@ export interface SessionDirectoryOptions<S extends SidebarListSession, P, C = un
220
223
  pinned?: () => Iterable<S['id']>;
221
224
  /** A window that only ever shows this session (its other sessions are never opened). */
222
225
  pinnedSession?: S['id'] | null;
226
+ /** Prewarm's settle delay and byte budget (`prewarm.ts`). */
227
+ prewarm?: {
228
+ delayMs?: number;
229
+ maxBytes?: number;
230
+ };
223
231
  /** Schedules prewarm reads; defaults to `requestIdleCallback` with a timer fallback. */
224
232
  idle?: {
225
233
  request: (run: () => void) => number;
@@ -1,6 +1,7 @@
1
1
  import { constant, writable } from "../store.js";
2
2
  import { applyInboxPatch, nextWakeAt } from "./inbox-state.js";
3
3
  import { createNotificationStore } from "./notifications.js";
4
+ import { createPrewarmer } from "./prewarm.js";
4
5
  import { NO_SIDEBAR_CONTRIBUTIONS, filterQueryOf, filtersForSpace, mergeSidebarSpaces, resolveGrouping, resolveSort, spaceMembership, switcherSpaces } from "./query.js";
5
6
  import { isProjectMember } from "./rows.js";
6
7
  import { VIEW_CHOICE } from "./types.js";
@@ -16,8 +17,6 @@ function withInboxFields(row, fields) {
16
17
  else next[key] = fields[key];
17
18
  return next;
18
19
  }
19
- const PREWARM_FULL_THRESHOLD = 12;
20
- const PREWARM_WINDOW_RADIUS = 6;
21
20
  /** The activity axis as a relative `updatedAt` bound, for a saved view's query. */
22
21
  const ACTIVITY_BOUND = {
23
22
  "1d": "-1d",
@@ -232,51 +231,13 @@ function createSessionDirectory(options) {
232
231
  patch({ hostNotice: null });
233
232
  }
234
233
  };
235
- let stopPrewarm = null;
236
- const prewarm = () => {
237
- stopPrewarm?.();
238
- stopPrewarm = null;
239
- const { allSessions: raw, activeSessionId } = state.get();
240
- if (raw.length === 0) return;
241
- let candidates;
242
- if (raw.length <= PREWARM_FULL_THRESHOLD) candidates = raw;
243
- else {
244
- const anchor = activeSessionId ? raw.findIndex((s) => s.id === activeSessionId) : -1;
245
- const center = anchor === -1 ? 0 : anchor;
246
- const start = Math.max(0, center - PREWARM_WINDOW_RADIUS);
247
- const end = Math.min(raw.length, center + PREWARM_WINDOW_RADIUS + 1);
248
- candidates = raw.slice(start, end);
249
- }
250
- const keep = new Set(candidates.map((s) => s.id));
251
- if (activeSessionId) keep.add(activeSessionId);
252
- for (const key of options.pinned?.() ?? []) keep.add(key);
253
- streams.evictExcept(keep);
254
- const targets = candidates.filter((session) => !streams.hasEvents(session.id));
255
- if (targets.length === 0) return;
256
- let cancelled = false;
257
- let handle;
258
- const pump = (index) => {
259
- if (cancelled || index >= targets.length) return;
260
- handle = idle.request(() => {
261
- if (cancelled) return;
262
- const session = targets[index];
263
- const next = () => pump(index + 1);
264
- if (streams.hasEvents(session.id)) {
265
- next();
266
- return;
267
- }
268
- options.loadEvents(session.id, { prewarm: true }).then((events) => {
269
- if (cancelled) return;
270
- if (!streams.hasEvents(session.id)) streams.setEventsPage(session.id, events);
271
- }).catch(() => {}).finally(next);
272
- });
273
- };
274
- pump(0);
275
- stopPrewarm = () => {
276
- cancelled = true;
277
- if (handle !== void 0) idle.cancel(handle);
278
- };
279
- };
234
+ const prewarmer = createPrewarmer({
235
+ streams,
236
+ loadEvents: options.loadEvents,
237
+ idle,
238
+ ...options.pinned ? { pinned: options.pinned } : {},
239
+ ...options.prewarm
240
+ });
280
241
  /** `direction`: the way the list slides; by default the switcher's order (a wrapping step overrides it). */
281
242
  const showSpace = (spaceId, direction) => {
282
243
  const { spaces, switcherSpaces: order, activeSpace, allSessions, activeSessionId, spacesOn } = state.get();
@@ -353,7 +314,7 @@ function createSessionDirectory(options) {
353
314
  lastRows = allSessions;
354
315
  lastActive = activeSessionId;
355
316
  reconcile();
356
- prewarm();
317
+ prewarmer.update(allSessions, activeSessionId);
357
318
  }));
358
319
  offs.push(options.settings.subscribe(reconcile));
359
320
  offs.push(views.space.subscribe(reconcile));
@@ -546,8 +507,7 @@ function createSessionDirectory(options) {
546
507
  return () => {
547
508
  for (const off of offs.splice(0).reverse()) off();
548
509
  followContributions = null;
549
- stopPrewarm?.();
550
- stopPrewarm = null;
510
+ prewarmer.stop();
551
511
  };
552
512
  },
553
513
  refresh,
@@ -1,7 +1,7 @@
1
1
  import { SecretTimeLeft } from "../secrets.js";
2
2
  import { u as AuthFailure } from "../../../dist/timeout-CmTx6V9y.js";
3
3
  import "../../../dist/index.js";
4
- import { $L as SecretTtl, HM as McpJobView, iM as TaskOutcomeCounts, rM as TaskOutcome } from "../../../dist/index-E1Z0aPmi.js";
4
+ import { AM as TaskOutcomeCounts, kM as TaskOutcome, kR as SecretTtl, mN as McpJobView } from "../../../dist/index-C6-t1SS9.js";
5
5
  import "../index.js";
6
6
  /** The default English strings of the session sidebar, merged over the chat layer's. */
7
7
  export declare const DEFAULT_SIDEBAR_LABELS: {
@@ -310,6 +310,16 @@ export declare const DEFAULT_SIDEBAR_LABELS: {
310
310
  modelVerdictTitle: (approved: boolean, model: string, confidence: string | null) => string;
311
311
  loadFullOutput: string;
312
312
  loadingFullOutput: string;
313
+ loadMoreOutput: string;
314
+ loadAllOutput: string;
315
+ loadingOutput: string;
316
+ outputLoaded: (loaded: string, total: string) => string;
317
+ outputLoadFailed: string;
318
+ loadFullInput: string;
319
+ loadingFullInput: string;
320
+ loadFullDiff: string;
321
+ loadingFullDiff: string;
322
+ diffNotShown: (hunks: number, size: string) => string;
313
323
  showOutput: string;
314
324
  inputCaption: string;
315
325
  outputCaption: string;