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,12 @@
13
13
  * notifications go out at once (the store batches transcript events per
14
14
  * frame), a run's end neither appends an error row nor drops pending echoes,
15
15
  * and long messages split at the reducer's default size.
16
+ *
17
+ * Every write that follows the stream goes through the store's transcript
18
+ * reducers (a delta copies the open exchange, a run's end finishes the
19
+ * exchanges still live), and a transcript's state carries the store's
20
+ * transcript (`TranscriptState.transcript`): no write or read of the
21
+ * stream makes a whole-session array.
16
22
  */
17
23
  import { ChatAttachment, ChatEvent, ChatInteraction, ChatSession, ChatSessionStatus, Transcript, TranscriptState } from "../chat/headless/host.js";
18
24
  import { Readable, Writable } from "../chat/headless/store.js";
@@ -1,7 +1,8 @@
1
1
  import { writable } from "../chat/headless/store.js";
2
- import { applyLiveEvent, finishLive } from "../chat/headless/streams/live-events.js";
2
+ import { applyLiveEvent, finishLive, finishLiveTranscript } from "../chat/headless/streams/live-events.js";
3
3
  import { SessionStreamStore } from "../chat/headless/streams/store.js";
4
4
  import { transcriptSnapshot } from "../chat/headless/streams/transcript.js";
5
+ import { transcriptOfArray } from "zidane/chat/pure";
5
6
  // src/adapters/live.ts
6
7
  /** Closed sessions whose windows stay, most recent first: the desktop's prewarm window (`sidebar/directory.ts`) less the open one. */
7
8
  const RECENT_KEPT = 12;
@@ -108,7 +109,9 @@ function createLiveState(options = {}) {
108
109
  const t = transcript(sessionId);
109
110
  t.echoes = [];
110
111
  t.state.set((s) => ({
111
- ...s,
112
+ running: s.running,
113
+ hasEarlier: s.hasEarlier,
114
+ loadingEarlier: s.loadingEarlier,
112
115
  ...patch,
113
116
  events: [...events],
114
117
  hydrated: true
@@ -135,11 +138,14 @@ function createLiveState(options = {}) {
135
138
  store.appendUserPrompt(sessionId, text, void 0, attachments ?? []);
136
139
  },
137
140
  setRunning(sessionId, running, status) {
138
- transcript(sessionId).state.set((s) => s.running === running ? s : {
139
- ...s,
140
- running,
141
- events: running ? s.events : finishLive(s.events)
142
- });
141
+ transcript(sessionId);
142
+ if (store.getRunningSnapshot(sessionId) !== running) {
143
+ const prior = store.getTranscriptSnapshot(sessionId);
144
+ store.write(sessionId, {
145
+ running,
146
+ ...!running && prior ? { transcript: finishLiveTranscript(prior) } : {}
147
+ });
148
+ }
143
149
  patchSession(sessionId, {
144
150
  status: status ?? (running ? "running" : "completed"),
145
151
  updatedAt: Date.now()
@@ -185,8 +191,10 @@ function transcriptState(store, sessionId) {
185
191
  const prev = get();
186
192
  const resolved = typeof next === "function" ? next(prev) : next;
187
193
  if (Object.is(resolved, prev)) return;
194
+ const kept = resolved.transcript === prev.transcript;
195
+ const events = resolved.transcript && !kept ? { transcript: resolved.transcript } : (prev.transcript ? transcriptOfArray(resolved.events) !== prev.transcript : resolved.events !== prev.events) ? { events: resolved.events } : null;
188
196
  store.write(sessionId, {
189
- ...resolved.events !== prev.events ? { events: resolved.events } : {},
197
+ ...events,
190
198
  running: resolved.running,
191
199
  page: resolved.hydrated ? {
192
200
  firstSeq: store.getPageSnapshot(sessionId).firstSeq,
@@ -1,7 +1,7 @@
1
1
  import { createResourceStore, readableResource } from "../app/headless/resource.js";
2
2
  import { createModelPickerPrefs } from "../chat/headless/composer/model-picker-prefs.js";
3
3
  import { createRunMeter } from "../chat/headless/composer/run-meter.js";
4
- import { fmtTokens, formatCostLabel } from "zidane/chat/pure";
4
+ import { createDraftAttachmentCodec, fmtTokens, formatCostLabel } from "zidane/chat/pure";
5
5
  // src/adapters/server-composer-host.ts
6
6
  /** A resource's data seen through `map`; each snapshot maps once, so readers see a stable value. */
7
7
  function mapped(resource, map) {
@@ -116,6 +116,11 @@ function createServerComposerHost(options) {
116
116
  return () => void listeners.delete(filtered);
117
117
  };
118
118
  let seq = 0;
119
+ /** Draft attachments are chips on the wire: each file's bytes go up or come down once. */
120
+ const draftFiles = createDraftAttachmentCodec({
121
+ put: (file) => client.call("attachments.put", file),
122
+ get: (hash) => client.call("attachments.get", { hash })
123
+ });
119
124
  /** Each session's fields a `#` reference shows: a row change that moves none of them (a write to its history, a run) reads nothing again. */
120
125
  const chatKeys = /* @__PURE__ */ new Map();
121
126
  const chatsMoved = (signal) => {
@@ -191,7 +196,13 @@ function createServerComposerHost(options) {
191
196
  };
192
197
  return {
193
198
  drafts: {
194
- get: async (sessionId) => client.call("drafts.get", { sessionId }),
199
+ get: async (sessionId) => {
200
+ const { attachments, ...draft } = await client.call("drafts.get", { sessionId });
201
+ return attachments?.length ? {
202
+ ...draft,
203
+ attachments: await draftFiles.toFiles(attachments)
204
+ } : draft;
205
+ },
195
206
  set: async (sessionId, text, shell) => {
196
207
  await client.call("drafts.set", {
197
208
  sessionId,
@@ -199,21 +210,23 @@ function createServerComposerHost(options) {
199
210
  ...shell !== void 0 ? { shell } : {}
200
211
  });
201
212
  },
202
- setAttachments: async (sessionId, attachments) => {
213
+ setAttachments: (sessionId, attachments) => draftFiles.inOrder(`published:${sessionId}`, async () => {
203
214
  await client.call("drafts.setAttachments", {
204
215
  sessionId,
205
- attachments
216
+ attachments: await draftFiles.toChips(attachments)
206
217
  });
207
- },
218
+ }),
208
219
  onChanged: (listener) => on(["draft:changed"], ({ sessionId, text, shell }) => listener({
209
220
  sessionId,
210
221
  text,
211
222
  ...shell !== void 0 ? { shell } : {}
212
223
  })),
213
- onAttachmentsChanged: (listener) => on(["draft:attachments"], ({ sessionId, attachments }) => listener({
214
- sessionId,
215
- attachments
216
- }))
224
+ onAttachmentsChanged: (listener) => on(["draft:attachments"], ({ sessionId, attachments }) => {
225
+ draftFiles.inOrder(`received:${sessionId}`, () => draftFiles.toFiles(attachments)).then((files) => listener({
226
+ sessionId,
227
+ attachments: files
228
+ }), () => void 0);
229
+ })
217
230
  },
218
231
  completions: {
219
232
  ...client.can("files.list") ? { files: async (root) => root ? resources.fetch(filesSpec(root)) : [] } : {},
@@ -1,10 +1,12 @@
1
+ import { sliceToolOutput } from "../chat/headless/output-pager.js";
1
2
  import { promptOriginWire } from "../chat/headless/prompt-origin.js";
2
3
  import { wireOriginal } from "../chat/headless/send-flow.js";
3
4
  import { applyInboxPatch } from "../chat/headless/sidebar/inbox-state.js";
4
5
  import { writable } from "../chat/headless/store.js";
6
+ import "../chat/headless/streams/session-streams.js";
5
7
  import { createLiveState } from "./live.js";
6
8
  import { createServerClient } from "./server-client.js";
7
- import { mediaTicketOf, messageMediaAddress } from "./server-media.js";
9
+ import { blobMediaAddress, mediaTicketOf, messageMediaAddress } from "./server-media.js";
8
10
  import { createServerTranscriptMembers } from "./server-transcript-members.js";
9
11
  import { climbReconnectLadder, createRecentChanges, cursorValid, messageMediaOf } from "zidane/chat/pure";
10
12
  // src/adapters/server-host.ts
@@ -100,12 +102,27 @@ function createServerHost(options) {
100
102
  /** A session's signals that arrive while its reconnect ladder runs (`resume`), applied after what it brings. */
101
103
  const resuming = /* @__PURE__ */ new Map();
102
104
  const models = writable([]);
105
+ let subscribing = Promise.resolve();
106
+ /** The watched sessions whose run in flight the host can replay, as of the last subscription (`runReplay`). */
107
+ let runsInFlight = /* @__PURE__ */ new Set();
108
+ const syncSubscriptions = () => {
109
+ subscribing = subscribing.then(() => client.call("sessions.subscribe", { sessionIds: [...watched] }).then((result) => {
110
+ runsInFlight = new Set(result?.running ?? []);
111
+ }, onError));
112
+ return subscribing;
113
+ };
103
114
  const state = createLiveState({
104
115
  onOpen: (sessionId) => {
105
116
  watched.add(sessionId);
106
- if (client.hello()) hydrate(sessionId).catch(onError);
117
+ if (client.hello()) {
118
+ syncSubscriptions();
119
+ hydrate(sessionId).catch(onError);
120
+ }
121
+ },
122
+ onClose: (sessionId) => {
123
+ watched.delete(sessionId);
124
+ if (client.hello()) syncSubscriptions();
107
125
  },
108
- onClose: (sessionId) => watched.delete(sessionId),
109
126
  evict: true
110
127
  });
111
128
  /** The changes applied while the list is read again. They are newer than its answer (`createRecentChanges`). */
@@ -178,10 +195,10 @@ function createServerHost(options) {
178
195
  case "history:changed": if (watched.has(signal.sessionId) && state.applyHistory(signal.sessionId, signal)) reread(signal.sessionId);
179
196
  }
180
197
  };
181
- const loadPage = async (sessionId, before) => {
198
+ const loadPage = async (sessionId, before, limit = PAGE_TURNS) => {
182
199
  return client.call("sessions.loadEvents", {
183
200
  sessionId,
184
- limit: PAGE_TURNS,
201
+ limit,
185
202
  ...before !== void 0 ? { before } : {}
186
203
  });
187
204
  };
@@ -189,27 +206,72 @@ function createServerHost(options) {
189
206
  const buffered = [];
190
207
  hydrating.set(sessionId, buffered);
191
208
  let stale = false;
209
+ let replay = [];
192
210
  try {
211
+ await subscribing;
212
+ const run = runReplay(sessionId);
193
213
  const page = await loadPage(sessionId);
194
214
  const running = await client.call("chat.isRunning", { sessionId });
195
215
  stale = !state.hydrate(sessionId, page.events, {
196
216
  running,
197
217
  hasEarlier: page.cursor !== void 0
198
218
  }, page.pos, page.historyId);
199
- if (!stale) cursors.set(sessionId, {
200
- before: page.cursor,
201
- ...page.pos !== void 0 ? { pos: page.pos } : {},
202
- ...page.pos !== void 0 && page.historyId !== void 0 ? { historyId: page.historyId } : {}
203
- });
219
+ if (!stale) {
220
+ cursors.set(sessionId, {
221
+ before: page.cursor,
222
+ ...page.pos !== void 0 ? { pos: page.pos } : {},
223
+ ...page.pos !== void 0 && page.historyId !== void 0 ? { historyId: page.historyId } : {}
224
+ });
225
+ replay = await run;
226
+ }
204
227
  } finally {
205
228
  if (hydrating.get(sessionId) === buffered) hydrating.delete(sessionId);
206
- for (const { signal, meta } of buffered) onSignal(signal, meta);
229
+ for (const { signal, meta } of inSeqOrder(replay, buffered)) onSignal(signal, meta);
207
230
  }
208
231
  if (stale && attempts > 1) return hydrate(sessionId, attempts - 1);
209
232
  const interactions = await client.call("interactions.list", { sessionId });
210
233
  for (const i of state.pending(sessionId).get()) state.resolveInteraction(i.requestId);
211
234
  for (const i of interactions) state.addInteraction(sessionId, i.request);
212
235
  }
236
+ /** `replay` and `buffered` merged by number, each number once (the replay's copy); an unnumbered signal keeps its place. */
237
+ function inSeqOrder(replay, buffered) {
238
+ const replayed = new Set(replay.map((entry) => entry.seq));
239
+ const out = [];
240
+ let next = 0;
241
+ for (const entry of buffered) {
242
+ if (entry.meta !== void 0) {
243
+ while (next < replay.length && replay[next].seq <= entry.meta.seq) out.push({
244
+ signal: replay[next].signal,
245
+ meta: { seq: replay[next++].seq }
246
+ });
247
+ if (replayed.has(entry.meta.seq)) continue;
248
+ }
249
+ out.push(entry);
250
+ }
251
+ for (; next < replay.length; next++) out.push({
252
+ signal: replay[next].signal,
253
+ meta: { seq: replay[next].seq }
254
+ });
255
+ return out;
256
+ }
257
+ /**
258
+ * What the session's run in flight streamed and did not save yet
259
+ * (`sessions.resume` with `run`): the text of the step in flight, which the
260
+ * page a window reads cannot hold. Its transcript events only, by number.
261
+ * Asked only for a session the subscription answered as running. Empty when
262
+ * no run is in flight, or the server has none to give.
263
+ */
264
+ async function runReplay(sessionId) {
265
+ const from = client.hello()?.signalEpoch;
266
+ if (from === void 0 || !runsInFlight.has(sessionId)) return [];
267
+ const result = await client.call("sessions.resume", {
268
+ sessionId,
269
+ epoch: from,
270
+ afterSeq: -1,
271
+ run: true
272
+ }).catch(() => null);
273
+ return result?.ok && typeof result.through === "number" ? result.signals.filter((entry) => entry.signal.kind === "event") : [];
274
+ }
213
275
  /**
214
276
  * Reads a transcript again for a signal (a rewrite, a missed write, a run's end). One such read per session is in
215
277
  * flight. A read asked for while another runs is made when the first ends, if the first did not bring the window up
@@ -249,6 +311,7 @@ function createServerHost(options) {
249
311
  for (const { signal, meta } of held) if (meta === void 0 || meta.seq > replayedTo) onSignal(signal, meta);
250
312
  }
251
313
  };
314
+ await subscribing;
252
315
  const outcome = await climbReconnectLadder(bookmark, {
253
316
  resume: async (from, afterSeq) => {
254
317
  const result = await client.call("sessions.resume", {
@@ -295,24 +358,25 @@ function createServerHost(options) {
295
358
  }
296
359
  await hydrate(sessionId);
297
360
  };
298
- const loadEarlier = async (sessionId) => {
361
+ /** Splices the page before the window in; `true` when it did. `limit`: its turns (default a page's). */
362
+ const loadEarlier = async (sessionId, limit) => {
299
363
  const cursor = cursors.get(sessionId);
300
364
  const before = cursor?.before;
301
365
  const t = state.transcript(sessionId).state;
302
- if (before === void 0 || t.get().loadingEarlier) return;
366
+ if (before === void 0 || t.get().loadingEarlier) return false;
303
367
  t.set((s) => ({
304
368
  ...s,
305
369
  loadingEarlier: true
306
370
  }));
307
371
  try {
308
- const page = await loadPage(sessionId, before);
372
+ const page = await loadPage(sessionId, before, limit);
309
373
  if (!cursorValid(cursor?.pos, page, cursor?.historyId)) {
310
374
  t.set((s) => ({
311
375
  ...s,
312
376
  loadingEarlier: false
313
377
  }));
314
378
  await hydrate(sessionId);
315
- return;
379
+ return false;
316
380
  }
317
381
  cursors.set(sessionId, {
318
382
  before: page.cursor,
@@ -325,14 +389,40 @@ function createServerHost(options) {
325
389
  hasEarlier: page.cursor !== void 0,
326
390
  loadingEarlier: false
327
391
  }));
392
+ return true;
328
393
  } catch (error) {
329
394
  t.set((s) => ({
330
395
  ...s,
331
396
  loadingEarlier: false
332
397
  }));
333
398
  onError(error);
399
+ return false;
334
400
  }
335
401
  };
402
+ /** Loads the earlier pages up to turn position `index`, the gap at once (`Transcript.loadThrough`). */
403
+ const loadThrough = async (sessionId, index) => {
404
+ for (;;) {
405
+ const before = cursors.get(sessionId)?.before;
406
+ if (before === void 0 || before <= index) return before === void 0 ? state.transcript(sessionId).state.get().hydrated : true;
407
+ if (!await loadEarlier(sessionId, Math.min(before - index, 1e3))) return false;
408
+ }
409
+ };
410
+ /** The prompt outline (`sessions.loadEvents` with `outline`); `null` from a server from before it. */
411
+ const outline = async (sessionId) => {
412
+ const page = await client.call("sessions.loadEvents", {
413
+ sessionId,
414
+ outline: true,
415
+ limit: 1
416
+ });
417
+ return page.outline ? {
418
+ prompts: page.outline,
419
+ ...page.pos !== void 0 ? { pos: page.pos } : {},
420
+ ...page.floor !== void 0 ? { floor: page.floor } : {},
421
+ ...page.historyId !== void 0 ? { historyId: page.historyId } : {}
422
+ } : null;
423
+ };
424
+ /** Each session's transcript, one object per readable the state holds (readers memo on it; an evicted one goes with it). */
425
+ const transcripts = /* @__PURE__ */ new WeakMap();
336
426
  const refresh = async () => {
337
427
  const reading = listChanges.begin();
338
428
  try {
@@ -370,6 +460,7 @@ function createServerHost(options) {
370
460
  if (epoch === void 0 || hello.signalEpoch !== epoch) seqs.clear();
371
461
  epoch = hello.signalEpoch;
372
462
  loadModels().catch(onError);
463
+ if (watched.size > 0) syncSubscriptions();
373
464
  if (!reconnected) return;
374
465
  refresh().catch(onError);
375
466
  for (const bookmark of bookmarks) resume(bookmark.sessionId, bookmark).catch(onError);
@@ -517,7 +608,19 @@ function createServerHost(options) {
517
608
  setSpace: (spaceId) => client.call("sidebar.setSpace", { spaceId })
518
609
  } } : {}
519
610
  },
520
- transcript: (sessionId) => state.readable(sessionId, { loadEarlier: () => void loadEarlier(sessionId) }),
611
+ transcript: (sessionId) => {
612
+ const readable = state.readable(sessionId, { loadEarlier: () => void loadEarlier(sessionId) });
613
+ let transcript = transcripts.get(readable);
614
+ if (!transcript) {
615
+ transcript = {
616
+ ...readable,
617
+ loadThrough: (index) => loadThrough(sessionId, index),
618
+ outline: () => outline(sessionId)
619
+ };
620
+ transcripts.set(readable, transcript);
621
+ }
622
+ return transcript;
623
+ },
521
624
  async send({ sessionId, prompt, attachments, model, thinking, activatedSkills, echo, keepDraft, delivery, origin, literal }) {
522
625
  if (echo !== false && !delivery) state.echoPrompt(sessionId, prompt, attachments?.map(({ original: _original, ...a }) => a));
523
626
  await applyChoice(sessionId, model, thinking);
@@ -582,9 +685,27 @@ function createServerHost(options) {
582
685
  }
583
686
  },
584
687
  models,
585
- toolOutput: (sessionId, callId) => client.call("sessions.getToolResult", {
688
+ toolOutput: async (sessionId, callId) => {
689
+ const text = await client.call("sessions.getToolResult", {
690
+ sessionId,
691
+ callId
692
+ });
693
+ return typeof text === "string" ? text : null;
694
+ },
695
+ toolOutputRange: async (sessionId, callId, range, turnId) => {
696
+ const answer = await client.call("sessions.getToolResult", {
697
+ sessionId,
698
+ callId,
699
+ range,
700
+ ...turnId ? { turnId } : {}
701
+ });
702
+ if (answer === null || answer === void 0) return null;
703
+ return typeof answer === "string" ? sliceToolOutput(answer, range) : answer;
704
+ },
705
+ toolCall: (sessionId, callId, turnId) => client.call("sessions.getToolCall", {
586
706
  sessionId,
587
- callId
707
+ callId,
708
+ ...turnId ? { turnId } : {}
588
709
  }),
589
710
  messageMediaUrl(sessionId, src) {
590
711
  const media = messageMediaOf(src);
@@ -594,6 +715,10 @@ function createServerHost(options) {
594
715
  const cwd = folders.get(sessionId);
595
716
  return ticket && cwd !== void 0 ? messageMediaAddress(ticket, cwd, src) : void 0;
596
717
  },
718
+ blobMediaUrl(hash) {
719
+ const ticket = mediaTicketOf(client);
720
+ return ticket ? blobMediaAddress(ticket, hash) : void 0;
721
+ },
597
722
  cancelTool(sessionId, callId) {
598
723
  client.call("chat.cancelWork", {
599
724
  sessionId,
@@ -19,4 +19,12 @@ export declare function mediaTicketOf(client: ServerClient): string | null;
19
19
  * @param cwd - The session's folder.
20
20
  * @param src - The `src` as the message wrote it.
21
21
  */
22
- export declare function messageMediaAddress(ticket: string, cwd: string, src: string): string;
22
+ export declare function messageMediaAddress(ticket: string, cwd: string, src: string): string;
23
+ /**
24
+ * Where a medium the server's session store holds by hash loads from: the
25
+ * same address for the same bytes, which the server marks immutable.
26
+ *
27
+ * @param ticket - The client's media ticket.
28
+ * @param hash - The blob's hash.
29
+ */
30
+ export declare function blobMediaAddress(ticket: string, hash: string): string;
@@ -35,4 +35,17 @@ function messageMediaAddress(ticket, cwd, src) {
35
35
  src
36
36
  })}`;
37
37
  }
38
- export { mediaTicketOf, messageMediaAddress };
38
+ /**
39
+ * Where a medium the server's session store holds by hash loads from: the
40
+ * same address for the same bytes, which the server marks immutable.
41
+ *
42
+ * @param ticket - The client's media ticket.
43
+ * @param hash - The blob's hash.
44
+ */
45
+ function blobMediaAddress(ticket, hash) {
46
+ return `${SERVER_MEDIA_PATH}?${new URLSearchParams({
47
+ ticket,
48
+ blob: hash
49
+ })}`;
50
+ }
51
+ export { blobMediaAddress, mediaTicketOf, messageMediaAddress };
@@ -1,15 +1,3 @@
1
- /**
2
- * `Transcript` over a `ChatHost`: reads `host.transcript(sessionId)`,
3
- * shows a loading line until its history has arrived, an "Earlier messages"
4
- * control while older events exist, and binds the rows' actions to the host
5
- * (full tool output, stopping a call, continuing a failed run through
6
- * `send`, fixing a failed sign-in over the nearest settings host's accounts).
7
- * An action the host leaves out hides its control.
8
- *
9
- * <ChatProvider host={host}>
10
- * <HostTranscript sessionId={id} onOpenSession={setActive} />
11
- * </ChatProvider>
12
- */
13
1
  import { AuthSettingsTarget } from "./headless/transcript/auth-failure.js";
14
2
  import "./headless/transcript/index.js";
15
3
  import { TranscriptProps } from "./Transcript.js";
@@ -4,6 +4,7 @@ import { useChatHost } from "./ChatProvider.js";
4
4
  import { useReadable } from "./headless/store.js";
5
5
  import { DEFAULT_TRANSCRIPT_OPTIONS, Transcript } from "./Transcript.js";
6
6
  import { TranscriptActionsProvider } from "./transcript/actions.js";
7
+ import { useRailOutline } from "./transcript/TranscriptRail.js";
7
8
  import { useChatLabels } from "./useChatLabels.js";
8
9
  import { useMemo } from "react";
9
10
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -23,11 +24,15 @@ function HostTranscript({ sessionId, onOpenSession, onRunInTerminal, onOpenSetti
23
24
  const labels = useChatLabels();
24
25
  const transcript = useMemo(() => host.transcript(sessionId), [host, sessionId]);
25
26
  const state = useReadable(transcript);
27
+ useRailOutline(transcript, Boolean(state.hasEarlier));
26
28
  const actions = useMemo(() => ({
27
29
  sessionId,
28
30
  ...host.toolOutput ? { toolOutput: (callId) => host.toolOutput(sessionId, callId) } : {},
31
+ ...host.toolOutputRange ? { toolOutputRange: (callId, range, turnId) => host.toolOutputRange(sessionId, callId, range, turnId) } : {},
32
+ ...host.toolCall ? { toolCall: (callId, turnId) => host.toolCall(sessionId, callId, turnId) } : {},
29
33
  ...host.cancelTool ? { cancelTool: (callId) => host.cancelTool(sessionId, callId) } : {},
30
34
  ...host.messageMediaUrl ? { messageMediaUrl: (src) => host.messageMediaUrl(sessionId, src) } : {},
35
+ ...host.blobMediaUrl ? { blobMediaUrl: host.blobMediaUrl } : {},
31
36
  ...onOpenSession ? { openSession: onOpenSession } : {},
32
37
  ...host.send ? { resume: (prompt) => void host.send({
33
38
  sessionId,
@@ -117,7 +122,7 @@ function HostTranscript({ sessionId, onOpenSession, onRunInTerminal, onOpenSetti
117
122
  })
118
123
  }), /* @__PURE__ */ jsx(Transcript, {
119
124
  ...props,
120
- events: state.events,
125
+ events: state.transcript ?? state.events,
121
126
  streaming: state.running,
122
127
  sessionId
123
128
  })]
@@ -15,6 +15,7 @@ import { SessionStreams } from "./headless/streams/session-streams.js";
15
15
  import { SessionStreamActions } from "./headless/streams/actions.js";
16
16
  import "./headless/streams/index.js";
17
17
  import { ReactNode } from "react";
18
+ import { TranscriptEvents } from "zidane/chat/pure";
18
19
  import { SystemMdFile } from "zidane/chat";
19
20
  /** Props of {@link SessionStreamsProvider}. */
20
21
  export interface SessionStreamsProviderProps<K extends string = string> {
@@ -41,6 +42,13 @@ export declare function useSessionStreamActions<K extends string = string>(): Se
41
42
  * @param sessionId - The session (`null`: none).
42
43
  */
43
44
  export declare function useSessionEvents<K extends string>(sessionId: K | null): readonly ChatEvent[];
45
+ /**
46
+ * The session's events as the store holds them: settled exchanges and the open one (`TranscriptEvents`). A
47
+ * `Transcript` handed it walks only the open exchange per streamed delta, and no whole-session array is made.
48
+ *
49
+ * @param sessionId - The session (`null`: none).
50
+ */
51
+ export declare function useSessionTranscript<K extends string>(sessionId: K | null): TranscriptEvents<ChatEvent>;
44
52
  /**
45
53
  * A value derived from the session's events, recomputed only when the events
46
54
  * change. `select` should be stable (module-level or memoised) and return a
@@ -1,5 +1,5 @@
1
1
  import { createSessionStreamActions } from "./headless/streams/actions.js";
2
- import { readSessionEvents, readSessionFallback, readSessionPage, readSessionRetry, readSessionRunning, readSessionSystemMd, selectEditEvents, stableSelection } from "./headless/streams/selectors.js";
2
+ import { readSessionEvents, readSessionFallback, readSessionPage, readSessionRetry, readSessionRunning, readSessionSystemMd, readSessionTranscript, selectEditEvents, stableSelection } from "./headless/streams/selectors.js";
3
3
  import { createContext, useCallback, useContext, useMemo, useRef, useState, useSyncExternalStore } from "react";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  // src/chat/SessionStreamsProvider.tsx
@@ -63,6 +63,15 @@ function useSessionEvents(sessionId) {
63
63
  return useSessionSnapshot(sessionId, readSessionEvents);
64
64
  }
65
65
  /**
66
+ * The session's events as the store holds them: settled exchanges and the open one (`TranscriptEvents`). A
67
+ * `Transcript` handed it walks only the open exchange per streamed delta, and no whole-session array is made.
68
+ *
69
+ * @param sessionId - The session (`null`: none).
70
+ */
71
+ function useSessionTranscript(sessionId) {
72
+ return useSessionSnapshot(sessionId, readSessionTranscript);
73
+ }
74
+ /**
66
75
  * A value derived from the session's events, recomputed only when the events
67
76
  * change. `select` should be stable (module-level or memoised) and return a
68
77
  * stable reference for unchanged input.
@@ -183,4 +192,4 @@ function useCaptureRunState() {
183
192
  return () => store.runStateVersion === version;
184
193
  }, [store]);
185
194
  }
186
- export { SessionStreamsProvider, useCaptureRunState, useHasSessionEvents, useIsSessionHydrated, useOptionalSessionStreamActions, usePeekRunSeq, usePeekSessionEvents, usePeekSessionRunning, useSessionEdits, useSessionEvents, useSessionEventsSelector, useSessionFallbackModel, useSessionPage, useSessionRetry, useSessionRunning, useSessionStreamActions, useSessionStreams, useSessionSystemMd };
195
+ export { SessionStreamsProvider, useCaptureRunState, useHasSessionEvents, useIsSessionHydrated, useOptionalSessionStreamActions, usePeekRunSeq, usePeekSessionEvents, usePeekSessionRunning, useSessionEdits, useSessionEvents, useSessionEventsSelector, useSessionFallbackModel, useSessionPage, useSessionRetry, useSessionRunning, useSessionStreamActions, useSessionStreams, useSessionSystemMd, useSessionTranscript };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The chat transcript: zidane events in, the rows of a session out. Runs the
3
3
  * headless pipeline (`use-transcript-rows.ts`) with the display options,
4
- * walks the rows into subagent blocks and lazy root rows, and paints the
4
+ * walks the rows into subagent blocks and virtual root rows, and paints the
5
5
  * select-turn cursor when the app drives that mode.
6
6
  *
7
7
  * <Transcript events={events} streaming={running} sessionId={id} options={{ transcriptDensity: 'compact' }} />
@@ -11,21 +11,26 @@
11
11
  * the actions (`TranscriptActionsProvider`), both provided around it.
12
12
  * `HostTranscript` is this component over a `ChatHost`.
13
13
  *
14
- * Scroll performance (keep it at frame rate on 3,000+ turn sessions): rows
15
- * keep their identity across stream ticks, each renders through the
16
- * memoized `TranscriptRow` with one shared `RowContext`, a root row whose
14
+ * Scroll performance (keep it at frame rate on 10,000+ row sessions): every
15
+ * root item is a lazy wrapper (`LazyRow`) that mounts its content on
16
+ * approach and keeps it, at its measured height before and after
17
+ * (`row-mount.ts`); only past a budget, while the reader is idle, do rows far
18
+ * from the view park. Scrolling back over rows already seen mounts nothing.
19
+ * Rows keep their identity across stream ticks, each renders through the
20
+ * memoized `TranscriptRow` with one shared `RowContext`, and a root row whose
17
21
  * inputs did not change reuses its element (React skips it without a props
18
- * compare), and root rows mount on approach (`LazyRow`) except the last
19
- * `EAGER_TAIL`.
22
+ * compare). The settled exchanges' elements are made once per settled list
23
+ * and sit behind one memoized fiber (`RowRun`), so a stream tick walks the
24
+ * open exchange only.
20
25
  *
21
26
  * The extensions' `transcript.turn-end` items draw after the turn they name
22
27
  * (`turnId`: after the last root row holding it; none holds it, not drawn),
23
28
  * the rest once at the end when the run has ended.
24
29
  */
25
- import { ChatEvent } from "./headless/host.js";
26
30
  import { SelectStops } from "./headless/transcript/select-stops.js";
27
31
  import "./headless/transcript/index.js";
28
32
  import { TranscriptTurnMenu, TurnMenuTarget } from "./transcript/TranscriptRow.js";
33
+ import { TranscriptSource } from "./transcript/use-transcript-rows.js";
29
34
  import { CSSProperties, ReactNode } from "react";
30
35
  import { RunRetry } from "zidane/chat/pure";
31
36
  import { Settings } from "zidane/chat";
@@ -46,8 +51,12 @@ export interface TranscriptSelection {
46
51
  }
47
52
  /** Props for {@link Transcript}. */
48
53
  export interface TranscriptProps {
49
- /** The session's events, oldest first. The transcript turns them into rows. */
50
- events: readonly ChatEvent[];
54
+ /**
55
+ * The session's events, oldest first, or its transcript store (`TranscriptEvents`, a session stream store's
56
+ * `getTranscriptSnapshot`). From a store, a streamed delta walks the open exchange only; an array is split into
57
+ * exchanges first (one walk), unless a store made it.
58
+ */
59
+ events: TranscriptSource;
51
60
  /** A run is in flight: the last reply may still be streaming. */
52
61
  streaming: boolean;
53
62
  /** The session shown; switching it replays the first-paint settle (no enter animations). */
@@ -79,6 +88,6 @@ export interface TranscriptProps {
79
88
  /** Rendered after the rows, inside the transcript (a menu the app owns). */
80
89
  children?: ReactNode;
81
90
  }
82
- /** Renders a session's events as transcript rows: messages, tool calls grouped by the display options, subagent blocks, notices, and the select-turn cursor. Rows mount lazily as they near the viewport. */
91
+ /** Renders a session's events as transcript rows: messages, tool calls grouped by the display options, subagent blocks, notices, and the select-turn cursor. Rows mount as they near the view, and stay. */
83
92
  export declare const Transcript: import("react").MemoExoticComponent<({ events, streaming, sessionId, options, selection, turnMenu, runStatus, liveScripts, className, style, children }: TranscriptProps) => import("react").JSX.Element>;
84
- export type { TranscriptTurnMenu, TurnMenuTarget };
93
+ export type { TranscriptSource, TranscriptTurnMenu, TurnMenuTarget };