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.
- package/dist/adapters/live.d.ts +6 -0
- package/dist/adapters/live.js +16 -8
- package/dist/adapters/server-composer-host.js +22 -9
- package/dist/adapters/server-host.js +143 -18
- package/dist/adapters/server-media.d.ts +9 -1
- package/dist/adapters/server-media.js +14 -1
- package/dist/chat/HostTranscript.d.ts +0 -12
- package/dist/chat/HostTranscript.js +6 -1
- package/dist/chat/SessionStreamsProvider.d.ts +8 -0
- package/dist/chat/SessionStreamsProvider.js +11 -2
- package/dist/chat/Transcript.d.ts +20 -11
- package/dist/chat/Transcript.js +326 -160
- package/dist/chat/composer/ComposerEditor.js +1 -1
- package/dist/chat/headless/host.d.ts +43 -7
- package/dist/chat/headless/index.d.ts +7 -6
- package/dist/chat/headless/index.js +10 -9
- package/dist/chat/headless/labels.d.ts +17 -0
- package/dist/chat/headless/labels.js +17 -0
- package/dist/chat/headless/markdown-chunks.d.ts +2 -1
- package/dist/chat/headless/markdown-chunks.js +12 -20
- package/dist/chat/headless/markdown-scan.d.ts +66 -0
- package/dist/chat/headless/markdown-scan.js +124 -0
- package/dist/chat/headless/markdown-stream.d.ts +64 -0
- package/dist/chat/headless/markdown-stream.js +143 -0
- package/dist/chat/headless/output-pager.d.ts +68 -0
- package/dist/chat/headless/output-pager.js +113 -0
- package/dist/chat/headless/session-list.d.ts +10 -0
- package/dist/chat/headless/sidebar/activity.d.ts +14 -0
- package/dist/chat/headless/sidebar/activity.js +32 -0
- package/dist/chat/headless/sidebar/directory.d.ts +9 -1
- package/dist/chat/headless/sidebar/directory.js +10 -50
- package/dist/chat/headless/sidebar/labels.d.ts +11 -1
- package/dist/chat/headless/sidebar/prewarm.d.ts +68 -0
- package/dist/chat/headless/sidebar/prewarm.js +114 -0
- package/dist/chat/headless/streams/actions.d.ts +2 -0
- package/dist/chat/headless/streams/actions.js +1 -0
- package/dist/chat/headless/streams/event-bytes.d.ts +6 -0
- package/dist/chat/headless/streams/event-bytes.js +34 -0
- package/dist/chat/headless/streams/live-events.d.ts +25 -1
- package/dist/chat/headless/streams/live-events.js +53 -2
- package/dist/chat/headless/streams/selectors.d.ts +3 -0
- package/dist/chat/headless/streams/selectors.js +8 -1
- package/dist/chat/headless/streams/session-streams.d.ts +15 -3
- package/dist/chat/headless/streams/session-streams.js +31 -3
- package/dist/chat/headless/streams/store.d.ts +24 -1
- package/dist/chat/headless/streams/store.js +51 -26
- package/dist/chat/headless/streams/transcript-map.d.ts +57 -0
- package/dist/chat/headless/streams/transcript-map.js +88 -0
- package/dist/chat/headless/streams/transcript.d.ts +4 -2
- package/dist/chat/headless/streams/transcript.js +19 -7
- package/dist/chat/headless/transcript/batch.js +5 -1
- package/dist/chat/headless/transcript/blob-media.d.ts +15 -0
- package/dist/chat/headless/transcript/blob-media.js +23 -0
- package/dist/chat/headless/transcript/collapse.d.ts +10 -0
- package/dist/chat/headless/transcript/collapse.js +32 -6
- package/dist/chat/headless/transcript/derive.d.ts +98 -0
- package/dist/chat/headless/transcript/derive.js +89 -0
- package/dist/chat/headless/transcript/exchange-media.d.ts +3 -1
- package/dist/chat/headless/transcript/exchange-media.js +8 -5
- package/dist/chat/headless/transcript/fold-attachments.d.ts +2 -0
- package/dist/chat/headless/transcript/fold-attachments.js +3 -2
- package/dist/chat/headless/transcript/fold.d.ts +2 -1
- package/dist/chat/headless/transcript/fold.js +16 -6
- package/dist/chat/headless/transcript/incremental.d.ts +53 -0
- package/dist/chat/headless/transcript/incremental.js +181 -0
- package/dist/chat/headless/transcript/index.d.ts +2 -2
- package/dist/chat/headless/transcript/index.js +2 -2
- package/dist/chat/headless/transcript/nesting.js +2 -1
- package/dist/chat/headless/transcript/rail.d.ts +50 -1
- package/dist/chat/headless/transcript/rail.js +165 -23
- package/dist/chat/headless/transcript/rows.d.ts +5 -1
- package/dist/chat/headless/transcript/run-failures.js +2 -1
- package/dist/chat/headless/transcript/seams.d.ts +78 -0
- package/dist/chat/headless/transcript/seams.js +116 -0
- package/dist/chat/headless/transcript/tool-media.d.ts +6 -7
- package/dist/chat/headless/transcript/tool-media.js +27 -9
- package/dist/chat/index.d.ts +8 -7
- package/dist/chat/index.js +17 -16
- package/dist/chat/sidebar/SidebarFooter.d.ts +8 -5
- package/dist/chat/sidebar/SidebarFooter.js +6 -6
- package/dist/chat/testing/contract.d.ts +5 -3
- package/dist/chat/testing/contract.js +66 -1
- package/dist/chat/transcript/DiffLines.d.ts +6 -1
- package/dist/chat/transcript/DiffLines.js +35 -20
- package/dist/chat/transcript/EditDiffBlock.d.ts +5 -1
- package/dist/chat/transcript/EditDiffBlock.js +89 -30
- package/dist/chat/transcript/LazyRow.d.ts +40 -40
- package/dist/chat/transcript/LazyRow.js +101 -149
- package/dist/chat/transcript/MermaidDiagram.js +2 -1
- package/dist/chat/transcript/SubagentBlock.js +3 -2
- package/dist/chat/transcript/TranscriptRail.d.ts +25 -2
- package/dist/chat/transcript/TranscriptRail.js +175 -17
- package/dist/chat/transcript/TranscriptRow.d.ts +4 -7
- package/dist/chat/transcript/TranscriptRow.js +4 -3
- package/dist/chat/transcript/actions.d.ts +37 -1
- package/dist/chat/transcript/actions.js +27 -1
- package/dist/chat/transcript/clipped-output.d.ts +58 -0
- package/dist/chat/transcript/clipped-output.js +131 -0
- package/dist/chat/transcript/fold-attachments.js +10 -5
- package/dist/chat/transcript/fold-worker.js +3 -2
- package/dist/chat/transcript/fold.js +2 -1
- package/dist/chat/transcript/index.d.ts +10 -9
- package/dist/chat/transcript/index.js +9 -8
- package/dist/chat/transcript/markdown-cache.d.ts +7 -1
- package/dist/chat/transcript/markdown-cache.js +12 -1
- package/dist/chat/transcript/markdown.js +116 -54
- package/dist/chat/transcript/media-gallery.d.ts +3 -2
- package/dist/chat/transcript/media-gallery.js +10 -7
- package/dist/chat/transcript/notices.js +2 -1
- package/dist/chat/transcript/prompt.js +6 -4
- package/dist/chat/transcript/prose.js +2 -1
- package/dist/chat/transcript/root-items.d.ts +96 -0
- package/dist/chat/transcript/root-items.js +180 -0
- package/dist/chat/transcript/row-mount.d.ts +165 -0
- package/dist/chat/transcript/row-mount.js +498 -0
- package/dist/chat/transcript/row-parking.d.ts +125 -0
- package/dist/chat/transcript/row-parking.js +135 -0
- package/dist/chat/transcript/row-ui-state.d.ts +37 -0
- package/dist/chat/transcript/row-ui-state.js +53 -0
- package/dist/chat/transcript/run-rows.js +3 -2
- package/dist/chat/transcript/script-input.d.ts +1 -1
- package/dist/chat/transcript/tasks.js +3 -2
- package/dist/chat/transcript/tool-media.d.ts +4 -2
- package/dist/chat/transcript/tool-media.js +15 -7
- package/dist/chat/transcript/tool-parts.d.ts +27 -4
- package/dist/chat/transcript/tool-parts.js +31 -5
- package/dist/chat/transcript/tool-payload.js +26 -11
- package/dist/chat/transcript/tool-row.d.ts +2 -1
- package/dist/chat/transcript/tool-row.js +38 -19
- package/dist/chat/transcript/use-transcript-rows.d.ts +24 -7
- package/dist/chat/transcript/use-transcript-rows.js +28 -46
- package/dist/chat/transcript/useStickToBottom.js +2 -3
- package/dist/chat/transcript/useTranscriptSearch.js +30 -14
- package/dist/chat/transcript/view-scope.d.ts +26 -6
- package/dist/chat/transcript/view-scope.js +106 -20
- package/dist/dist/{index-E1Z0aPmi.d.ts → index-C6-t1SS9.d.ts} +2 -1
- package/dist/dist/index.d.ts +1 -1
- package/dist/session/SessionHeader.js +1 -0
- package/dist/settings/headless/fixture-performance.js +4 -2
- package/dist/settings/headless/performance.d.ts +4 -0
- package/dist/settings/headless/search.d.ts +1 -1
- package/dist/settings/sections/performance/PerformanceSection.js +8 -1
- package/dist/settings/sections/performance/labels.d.ts +2 -0
- package/dist/settings/sections/performance/labels.js +2 -0
- package/dist/styles.css +33 -2
- package/dist/views/headless/answers.d.ts +8 -2
- package/dist/views/headless/answers.js +58 -1
- package/dist/views/headless/placement.d.ts +78 -0
- package/dist/views/headless/placement.js +154 -44
- package/package.json +2 -2
- package/src/styles/transcript.css +33 -2
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { Readable } from "../store.js";
|
|
15
15
|
import { Cluster, Row } from "./rows.js";
|
|
16
|
-
import { RunReceipt } from "zidane/chat/pure";
|
|
16
|
+
import { PromptOutlineEntry, RunReceipt } from "zidane/chat/pure";
|
|
17
17
|
/** One exchange on the rail: a typed prompt and the run that answered it. */
|
|
18
18
|
export interface RailExchange {
|
|
19
19
|
/** The prompt row's id: the exchange's id and the row a jump lands on. */
|
|
@@ -28,6 +28,14 @@ export interface RailExchange {
|
|
|
28
28
|
lastRowId: string;
|
|
29
29
|
/** The receipt of the run that answered (model, duration), when it docked one. */
|
|
30
30
|
receipt?: RunReceipt;
|
|
31
|
+
/**
|
|
32
|
+
* A prompt of the session's outline whose history is not loaded yet: no rows (`firstRowId` and `lastRowId` are
|
|
33
|
+
* empty), its turn and where it sits. A jump loads up to `index` first.
|
|
34
|
+
*/
|
|
35
|
+
unloaded?: {
|
|
36
|
+
turnId: string;
|
|
37
|
+
index: number;
|
|
38
|
+
};
|
|
31
39
|
}
|
|
32
40
|
/** The rail's exchanges and how any turn maps to the exchange that holds it. */
|
|
33
41
|
export interface RailModel {
|
|
@@ -62,6 +70,41 @@ export declare function computeRailModel(clusters: readonly Cluster[], { isHidde
|
|
|
62
70
|
isHidden?: (row: Row) => boolean;
|
|
63
71
|
receipts?: ReadonlyMap<string, RunReceipt>;
|
|
64
72
|
}): RailModel;
|
|
73
|
+
/**
|
|
74
|
+
* {@link computeRailModel} over the two parts an incremental transcript paints: the settled
|
|
75
|
+
* clusters fold once (per clusters array), each stream tick folds the open ones. The settled
|
|
76
|
+
* exchanges' rail entries keep their objects, and the turn map reads through to theirs.
|
|
77
|
+
*
|
|
78
|
+
* @param parts - The settled and the open root clusters.
|
|
79
|
+
* @param parts.settled - The settled exchanges' clusters and receipts.
|
|
80
|
+
* @param parts.settled.clusters - The settled root clusters (one fold per array).
|
|
81
|
+
* @param parts.settled.receipts - The receipts docked on them.
|
|
82
|
+
* @param parts.open - The open exchange's clusters.
|
|
83
|
+
* @param parts.open.clusters - The open root clusters.
|
|
84
|
+
* @param options - As {@link computeRailModel}'s; `receipts` holds both parts'.
|
|
85
|
+
* @param options.isHidden - Whether a row paints nothing.
|
|
86
|
+
* @param options.receipts - The run receipts, by the id of the reply row they dock on.
|
|
87
|
+
*/
|
|
88
|
+
export declare function computeRailModelParts(parts: {
|
|
89
|
+
settled: {
|
|
90
|
+
clusters: readonly Cluster[];
|
|
91
|
+
receipts?: ReadonlyMap<string, RunReceipt>;
|
|
92
|
+
};
|
|
93
|
+
open: {
|
|
94
|
+
clusters: readonly Cluster[];
|
|
95
|
+
};
|
|
96
|
+
}, { isHidden, receipts }?: {
|
|
97
|
+
isHidden?: (row: Row) => boolean;
|
|
98
|
+
receipts?: ReadonlyMap<string, RunReceipt>;
|
|
99
|
+
}): RailModel;
|
|
100
|
+
/**
|
|
101
|
+
* The rail with the session's whole outline: the outline's prompts before the first loaded one (their history is
|
|
102
|
+
* not loaded yet) as unloaded exchanges, then the loaded exchanges. The same array when there are none to add.
|
|
103
|
+
*
|
|
104
|
+
* @param model - The loaded exchanges.
|
|
105
|
+
* @param outline - The session's prompts, oldest first, or `null` when there is none (all loaded, or the host can't say).
|
|
106
|
+
*/
|
|
107
|
+
export declare function railWithOutline(model: RailModel, outline: readonly PromptOutlineEntry[] | null): readonly RailExchange[];
|
|
65
108
|
/**
|
|
66
109
|
* Whether two exchange lists show the same rail: same exchanges, same text, same span and receipt.
|
|
67
110
|
*
|
|
@@ -75,6 +118,10 @@ export interface TranscriptRailState extends RailModel {
|
|
|
75
118
|
hovered: string | null;
|
|
76
119
|
/** The exchange holding select-turn mode's cursor, or `null` outside the mode. */
|
|
77
120
|
selected: string | null;
|
|
121
|
+
/** The session's whole prompt outline while part of its history is not loaded; `null` otherwise. */
|
|
122
|
+
outline: readonly PromptOutlineEntry[] | null;
|
|
123
|
+
/** Loads the history up to a turn position (`Transcript.loadThrough`); `null`: unloaded prompts can't be reached. */
|
|
124
|
+
loadThrough: ((index: number) => Promise<boolean>) | null;
|
|
78
125
|
}
|
|
79
126
|
/**
|
|
80
127
|
* The bridge between a transcript and its rail: the transcript publishes its
|
|
@@ -88,6 +135,8 @@ export interface TranscriptRailStore extends Readable<TranscriptRailState> {
|
|
|
88
135
|
hover: (id: string | null) => void;
|
|
89
136
|
/** The exchange holding select-turn mode's cursor, or `null`. */
|
|
90
137
|
select: (id: string | null) => void;
|
|
138
|
+
/** The session's outline (`null`: none, all is loaded) and how to load up to one of its prompts. */
|
|
139
|
+
publishOutline: (outline: readonly PromptOutlineEntry[] | null, loadThrough: ((index: number) => Promise<boolean>) | null) => void;
|
|
91
140
|
}
|
|
92
141
|
/** A rail store with no exchange: one per transcript view (the provider makes it). */
|
|
93
142
|
export declare function createTranscriptRailStore(): TranscriptRailStore;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { writable } from "../store.js";
|
|
2
2
|
import { rowTurnIds } from "./select-stops.js";
|
|
3
|
+
import { noteTranscriptPass } from "zidane/chat/pure";
|
|
3
4
|
// src/chat/headless/transcript/rail.ts
|
|
4
5
|
/** The longest text an exchange keeps for its preview: the card clamps its lines, this bounds the work. */
|
|
5
6
|
const PREVIEW_CHARS = 320;
|
|
@@ -59,28 +60,95 @@ function* rowsWithin(row) {
|
|
|
59
60
|
* @param options.receipts - The run receipts, by the id of the reply row they dock on.
|
|
60
61
|
*/
|
|
61
62
|
function computeRailModel(clusters, { isHidden = () => false, receipts } = {}) {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
63
|
+
const fold = railFold();
|
|
64
|
+
foldRail(fold, clusters, isHidden, receipts);
|
|
65
|
+
closeRail(fold, receipts);
|
|
66
|
+
return {
|
|
67
|
+
exchanges: fold.exchanges,
|
|
68
|
+
exchangeOfTurn: fold.exchangeOfTurn
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Two turn maps read as one: the settled exchanges' and the open part's (which wins). */
|
|
72
|
+
var LayeredTurns = class {
|
|
73
|
+
base;
|
|
74
|
+
top = /* @__PURE__ */ new Map();
|
|
75
|
+
constructor(base) {
|
|
76
|
+
this.base = base;
|
|
77
|
+
}
|
|
78
|
+
get size() {
|
|
79
|
+
let n = this.base.size;
|
|
80
|
+
for (const key of this.top.keys()) n += this.base.has(key) ? 0 : 1;
|
|
81
|
+
return n;
|
|
82
|
+
}
|
|
83
|
+
get(key) {
|
|
84
|
+
return this.top.has(key) ? this.top.get(key) : this.base.get(key);
|
|
85
|
+
}
|
|
86
|
+
has(key) {
|
|
87
|
+
return this.top.has(key) || this.base.has(key);
|
|
88
|
+
}
|
|
89
|
+
set(key, value) {
|
|
90
|
+
this.top.set(key, value);
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
forEach(callback) {
|
|
94
|
+
for (const [key, value] of this) callback(value, key, this);
|
|
95
|
+
}
|
|
96
|
+
*entries() {
|
|
97
|
+
for (const [key, value] of this.base) if (!this.top.has(key)) yield [key, value];
|
|
98
|
+
yield* this.top.entries();
|
|
99
|
+
}
|
|
100
|
+
*keys() {
|
|
101
|
+
for (const [key] of this.entries()) yield key;
|
|
102
|
+
}
|
|
103
|
+
*values() {
|
|
104
|
+
for (const [, value] of this.entries()) yield value;
|
|
105
|
+
}
|
|
106
|
+
[Symbol.iterator]() {
|
|
107
|
+
return this.entries();
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
function railFold(base) {
|
|
111
|
+
if (!base) return {
|
|
112
|
+
exchanges: [],
|
|
113
|
+
shared: false,
|
|
114
|
+
exchangeOfTurn: /* @__PURE__ */ new Map(),
|
|
115
|
+
current: null,
|
|
116
|
+
lastReply: null
|
|
117
|
+
};
|
|
118
|
+
return {
|
|
119
|
+
exchanges: base.exchanges,
|
|
120
|
+
shared: true,
|
|
121
|
+
exchangeOfTurn: new LayeredTurns(base.exchangeOfTurn),
|
|
122
|
+
current: base.current ? { ...base.current } : null,
|
|
123
|
+
lastReply: base.lastReply
|
|
76
124
|
};
|
|
125
|
+
}
|
|
126
|
+
function closeRail(fold, receipts) {
|
|
127
|
+
const current = fold.current;
|
|
128
|
+
if (!current) return;
|
|
129
|
+
const lastReply = fold.lastReply;
|
|
130
|
+
if (lastReply && lastReply.kind === "markdown") {
|
|
131
|
+
current.answer = previewOf(lastReply) || null;
|
|
132
|
+
const receipt = receipts?.get(lastReply.id);
|
|
133
|
+
if (receipt) current.receipt = receipt;
|
|
134
|
+
}
|
|
135
|
+
if (fold.shared) {
|
|
136
|
+
fold.exchanges = [...fold.exchanges];
|
|
137
|
+
fold.shared = false;
|
|
138
|
+
}
|
|
139
|
+
fold.exchanges.push(current);
|
|
140
|
+
fold.current = null;
|
|
141
|
+
fold.lastReply = null;
|
|
142
|
+
}
|
|
143
|
+
function foldRail(fold, clusters, isHidden, receipts) {
|
|
144
|
+
noteTranscriptPass("rail", clusters.length);
|
|
77
145
|
for (const cluster of clusters) {
|
|
78
146
|
if (cluster.kind !== "single") continue;
|
|
79
147
|
const row = cluster.row;
|
|
80
148
|
if (isHidden(row)) continue;
|
|
81
149
|
if (row.kind === "user-prompt" && !row.synthetic && row.childId === void 0) {
|
|
82
|
-
|
|
83
|
-
current = {
|
|
150
|
+
closeRail(fold, receipts);
|
|
151
|
+
fold.current = {
|
|
84
152
|
id: row.id,
|
|
85
153
|
prompt: previewOf(row),
|
|
86
154
|
answer: null,
|
|
@@ -88,18 +156,80 @@ function computeRailModel(clusters, { isHidden = () => false, receipts } = {}) {
|
|
|
88
156
|
lastRowId: row.id
|
|
89
157
|
};
|
|
90
158
|
}
|
|
159
|
+
const current = fold.current;
|
|
91
160
|
if (!current) continue;
|
|
92
161
|
current.lastRowId = row.id;
|
|
93
|
-
for (const id of rowTurnIds(row)) if (!exchangeOfTurn.has(id)) exchangeOfTurn.set(id, current.id);
|
|
94
|
-
for (const inner of rowsWithin(row)) if (inner.kind === "markdown" && inner.text.trim() !== "") lastReply = inner;
|
|
162
|
+
for (const id of rowTurnIds(row)) if (!fold.exchangeOfTurn.has(id)) fold.exchangeOfTurn.set(id, current.id);
|
|
163
|
+
for (const inner of rowsWithin(row)) if (inner.kind === "markdown" && inner.text.trim() !== "") fold.lastReply = inner;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/** The settled clusters' fold, per clusters array (its rows keep their identity while only the open exchange changes). */
|
|
167
|
+
const settledRails = /* @__PURE__ */ new WeakMap();
|
|
168
|
+
/**
|
|
169
|
+
* {@link computeRailModel} over the two parts an incremental transcript paints: the settled
|
|
170
|
+
* clusters fold once (per clusters array), each stream tick folds the open ones. The settled
|
|
171
|
+
* exchanges' rail entries keep their objects, and the turn map reads through to theirs.
|
|
172
|
+
*
|
|
173
|
+
* @param parts - The settled and the open root clusters.
|
|
174
|
+
* @param parts.settled - The settled exchanges' clusters and receipts.
|
|
175
|
+
* @param parts.settled.clusters - The settled root clusters (one fold per array).
|
|
176
|
+
* @param parts.settled.receipts - The receipts docked on them.
|
|
177
|
+
* @param parts.open - The open exchange's clusters.
|
|
178
|
+
* @param parts.open.clusters - The open root clusters.
|
|
179
|
+
* @param options - As {@link computeRailModel}'s; `receipts` holds both parts'.
|
|
180
|
+
* @param options.isHidden - Whether a row paints nothing.
|
|
181
|
+
* @param options.receipts - The run receipts, by the id of the reply row they dock on.
|
|
182
|
+
*/
|
|
183
|
+
function computeRailModelParts(parts, { isHidden = () => false, receipts } = {}) {
|
|
184
|
+
const { settled, open } = parts;
|
|
185
|
+
let hit = settledRails.get(settled.clusters);
|
|
186
|
+
const settledReceipts = settled.receipts ?? receipts;
|
|
187
|
+
if (!hit || hit.isHidden !== isHidden || hit.receipts !== settledReceipts) {
|
|
188
|
+
const fold = railFold();
|
|
189
|
+
foldRail(fold, settled.clusters, isHidden, settledReceipts);
|
|
190
|
+
hit = {
|
|
191
|
+
isHidden,
|
|
192
|
+
receipts: settledReceipts,
|
|
193
|
+
fold
|
|
194
|
+
};
|
|
195
|
+
settledRails.set(settled.clusters, hit);
|
|
95
196
|
}
|
|
96
|
-
|
|
197
|
+
const fold = railFold(hit.fold);
|
|
198
|
+
foldRail(fold, open.clusters, isHidden, receipts);
|
|
199
|
+
closeRail(fold, receipts);
|
|
97
200
|
return {
|
|
98
|
-
exchanges,
|
|
99
|
-
exchangeOfTurn
|
|
201
|
+
exchanges: fold.exchanges,
|
|
202
|
+
exchangeOfTurn: fold.exchangeOfTurn
|
|
100
203
|
};
|
|
101
204
|
}
|
|
102
205
|
/**
|
|
206
|
+
* The rail with the session's whole outline: the outline's prompts before the first loaded one (their history is
|
|
207
|
+
* not loaded yet) as unloaded exchanges, then the loaded exchanges. The same array when there are none to add.
|
|
208
|
+
*
|
|
209
|
+
* @param model - The loaded exchanges.
|
|
210
|
+
* @param outline - The session's prompts, oldest first, or `null` when there is none (all loaded, or the host can't say).
|
|
211
|
+
*/
|
|
212
|
+
function railWithOutline(model, outline) {
|
|
213
|
+
if (!outline || outline.length === 0) return model.exchanges;
|
|
214
|
+
const unloaded = [];
|
|
215
|
+
for (const prompt of outline) {
|
|
216
|
+
if (model.exchangeOfTurn.has(prompt.turnId)) break;
|
|
217
|
+
unloaded.push({
|
|
218
|
+
id: `outline:${prompt.turnId}`,
|
|
219
|
+
prompt: prompt.text,
|
|
220
|
+
answer: null,
|
|
221
|
+
firstRowId: "",
|
|
222
|
+
lastRowId: "",
|
|
223
|
+
unloaded: {
|
|
224
|
+
turnId: prompt.turnId,
|
|
225
|
+
index: prompt.index
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
if (unloaded.length === outline.length && model.exchanges.length > 0) return model.exchanges;
|
|
230
|
+
return unloaded.length > 0 ? [...unloaded, ...model.exchanges] : model.exchanges;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
103
233
|
* Whether two exchange lists show the same rail: same exchanges, same text, same span and receipt.
|
|
104
234
|
*
|
|
105
235
|
* @param a - One list.
|
|
@@ -116,6 +246,11 @@ function sameRail(a, b) {
|
|
|
116
246
|
/** Whether two turn maps send every turn to the same exchange. */
|
|
117
247
|
function sameTurns(a, b) {
|
|
118
248
|
if (a === b) return true;
|
|
249
|
+
if (a instanceof LayeredTurns && b instanceof LayeredTurns && a.base === b.base) {
|
|
250
|
+
if (a.top.size !== b.top.size) return false;
|
|
251
|
+
for (const [turn, exchange] of a.top) if (b.top.get(turn) !== exchange) return false;
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
119
254
|
if (a.size !== b.size) return false;
|
|
120
255
|
for (const [turn, exchange] of a) if (b.get(turn) !== exchange) return false;
|
|
121
256
|
return true;
|
|
@@ -125,7 +260,9 @@ function createTranscriptRailStore() {
|
|
|
125
260
|
const state = writable({
|
|
126
261
|
...EMPTY_RAIL,
|
|
127
262
|
hovered: null,
|
|
128
|
-
selected: null
|
|
263
|
+
selected: null,
|
|
264
|
+
outline: null,
|
|
265
|
+
loadThrough: null
|
|
129
266
|
});
|
|
130
267
|
return {
|
|
131
268
|
get: state.get,
|
|
@@ -142,7 +279,12 @@ function createTranscriptRailStore() {
|
|
|
142
279
|
select: (id) => state.set((prev) => prev.selected === id ? prev : {
|
|
143
280
|
...prev,
|
|
144
281
|
selected: id
|
|
282
|
+
}),
|
|
283
|
+
publishOutline: (outline, loadThrough) => state.set((prev) => prev.outline === outline && prev.loadThrough === loadThrough ? prev : {
|
|
284
|
+
...prev,
|
|
285
|
+
outline,
|
|
286
|
+
loadThrough
|
|
145
287
|
})
|
|
146
288
|
};
|
|
147
289
|
}
|
|
148
|
-
export { EMPTY_RAIL, computeRailModel, createTranscriptRailStore, dataRowSelector, plainPreview, sameRail };
|
|
290
|
+
export { EMPTY_RAIL, computeRailModel, computeRailModelParts, createTranscriptRailStore, dataRowSelector, plainPreview, railWithOutline, sameRail };
|
|
@@ -231,8 +231,12 @@ export type Row = (Owned & {
|
|
|
231
231
|
ok: boolean | null;
|
|
232
232
|
/** Wire id of the call — the key for the lazy full-result fetch. */
|
|
233
233
|
callId?: string;
|
|
234
|
-
/** True when `result`
|
|
234
|
+
/** True when the host clipped `result` for the wire (`clipped.result`; expand offers a full fetch). */
|
|
235
235
|
resultClipped?: boolean;
|
|
236
|
+
/** Per media block of the result, the blob it is held as (`StreamEvent.mediaRefs`): its address by hash. */
|
|
237
|
+
mediaRefs?: readonly (string | null)[];
|
|
238
|
+
/** True when the host clipped `rawInput` for the wire (`clipped.input`; expand offers the whole input). */
|
|
239
|
+
inputClipped?: boolean;
|
|
236
240
|
/**
|
|
237
241
|
* Timing, from the host: `startedAt` while the call is unpaired (its
|
|
238
242
|
* `tool` event's), `durationMs` once its result landed (its
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createRunStopMarker } from "zidane/chat/pure";
|
|
1
|
+
import { createRunStopMarker, noteTranscriptPass } from "zidane/chat/pure";
|
|
2
2
|
// src/chat/headless/transcript/run-failures.ts
|
|
3
3
|
/** A reset time: the clock time today, with the date on any other day. */
|
|
4
4
|
function formatResetTime(resetsAt) {
|
|
@@ -57,6 +57,7 @@ const markRows = createRunStopMarker({
|
|
|
57
57
|
* @param rows - The transcript rows, oldest first.
|
|
58
58
|
*/
|
|
59
59
|
function markRunFailures(rows) {
|
|
60
|
+
noteTranscriptPass("run-failures", rows.length);
|
|
60
61
|
return markRepaired(markRows(rows));
|
|
61
62
|
}
|
|
62
63
|
/** Each repaired error's copy, per row: a row that did not change keeps its identity (memoised rows stay put). */
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a transcript can be cut so that its parts derive rows on their own.
|
|
3
|
+
*
|
|
4
|
+
* Every pass of the row pipeline (`derive.ts`) stops at an exchange start (a
|
|
5
|
+
* top-level prompt and the separators before it), except where data ties two
|
|
6
|
+
* exchanges together:
|
|
7
|
+
*
|
|
8
|
+
* - ids: a result, a nested call, a script's progress or a queued spawn names
|
|
9
|
+
* a call of an earlier exchange (`callId`, `parentToolCallId`); a subagent
|
|
10
|
+
* or a turn spans exchanges (`childId`, `spawn.parentChildId`, `turnId`:
|
|
11
|
+
* clustering, ordinals); a call without an id pairs by turn and tool name.
|
|
12
|
+
* - environment setups: the last attempt is marked as such (all setups tie),
|
|
13
|
+
* and a running one at an exchange's end moves into the next exchange.
|
|
14
|
+
* - a broken-environment error is marked repaired by the next reply, which
|
|
15
|
+
* may be in a later exchange.
|
|
16
|
+
*
|
|
17
|
+
* Exchanges tied this way form one block, derived together. Ties are rare
|
|
18
|
+
* (a background subagent writing across a prompt, a setup), so a block is
|
|
19
|
+
* almost always one exchange.
|
|
20
|
+
*/
|
|
21
|
+
import { ChatEvent } from "../host.js";
|
|
22
|
+
/** What one exchange's events tie to. */
|
|
23
|
+
export interface ExchangeTies {
|
|
24
|
+
/** Ids it shares with any exchange holding the same id. */
|
|
25
|
+
keys: readonly string[];
|
|
26
|
+
/** It ends on a running (or waited-for) setup, which moves into the next exchange. */
|
|
27
|
+
heldEnd: boolean;
|
|
28
|
+
/** It holds a broken-environment error a later reply may mark repaired. */
|
|
29
|
+
envError: boolean;
|
|
30
|
+
/** It holds what shows the environment works (a reply, a custom row, a setup). */
|
|
31
|
+
works: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The ties of a settled exchange (computed once per chunk).
|
|
35
|
+
*
|
|
36
|
+
* @param chunk - The exchange's events, never changed.
|
|
37
|
+
*/
|
|
38
|
+
export declare function chunkTies(chunk: readonly ChatEvent[]): ExchangeTies;
|
|
39
|
+
/**
|
|
40
|
+
* The ties of the open exchange (computed each time: it changes every frame).
|
|
41
|
+
*
|
|
42
|
+
* @param tail - The open exchange's events.
|
|
43
|
+
*/
|
|
44
|
+
export declare function tailTies(tail: readonly ChatEvent[]): ExchangeTies;
|
|
45
|
+
/** A run of chunks derived together: `[start, end)`. */
|
|
46
|
+
export interface Block {
|
|
47
|
+
start: number;
|
|
48
|
+
end: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The blocks of a list of exchanges, grown one exchange at a time. Reused
|
|
52
|
+
* while the list only grows (a commit appends one exchange); any other change
|
|
53
|
+
* plans again from the start.
|
|
54
|
+
*/
|
|
55
|
+
export declare class BlockPlan {
|
|
56
|
+
/** The exchanges planned so far. */
|
|
57
|
+
chunks: ReadonlyArray<readonly ChatEvent[]>;
|
|
58
|
+
/** The blocks, oldest first, covering every planned exchange. */
|
|
59
|
+
blocks: Block[];
|
|
60
|
+
private firstSeen;
|
|
61
|
+
private openRepair;
|
|
62
|
+
private lastHeld;
|
|
63
|
+
/**
|
|
64
|
+
* Brings the plan to `chunks`.
|
|
65
|
+
*
|
|
66
|
+
* @param chunks - The settled exchanges, oldest first.
|
|
67
|
+
*/
|
|
68
|
+
update(chunks: ReadonlyArray<readonly ChatEvent[]>): void;
|
|
69
|
+
/**
|
|
70
|
+
* The index of the first block an exchange with `ties`, appended after the planned ones, must join (`blocks.length` for none).
|
|
71
|
+
*
|
|
72
|
+
* @param ties - The appended exchange's ties.
|
|
73
|
+
*/
|
|
74
|
+
joinFrom(ties: ExchangeTies): number;
|
|
75
|
+
private add;
|
|
76
|
+
/** The earliest exchange the one at `index` ties to (`index` for none); `record` files its ids. */
|
|
77
|
+
private reach;
|
|
78
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { chunkFact, readEnvironmentSetup } from "zidane/chat/pure";
|
|
2
|
+
// src/chat/headless/transcript/seams.ts
|
|
3
|
+
function tiesOf(events) {
|
|
4
|
+
const keys = /* @__PURE__ */ new Set();
|
|
5
|
+
let envError = false;
|
|
6
|
+
let works = false;
|
|
7
|
+
for (const e of events) {
|
|
8
|
+
if (e.callId) keys.add(`c:${e.callId}`);
|
|
9
|
+
if (e.parentToolCallId) keys.add(`c:${e.parentToolCallId}`);
|
|
10
|
+
if (e.spawn?.callId) keys.add(`c:${e.spawn.callId}`);
|
|
11
|
+
if (e.spawn?.parentChildId) keys.add(`o:${e.spawn.parentChildId}`);
|
|
12
|
+
if (e.childId) keys.add(`o:${e.childId}`);
|
|
13
|
+
if (e.turnId) keys.add(`t:${e.turnId}`);
|
|
14
|
+
if (e.tool && !e.callId && (e.kind === "tool" || e.kind === "tool-result" || e.kind === "error")) keys.add(`p:${e.turnId ?? ""}::${e.tool}`);
|
|
15
|
+
if (readEnvironmentSetup(e)) keys.add("setup");
|
|
16
|
+
if (e.kind === "error" && e.detail?.environment) envError = true;
|
|
17
|
+
if (e.kind === "markdown" && e.text.trim() !== "" || e.kind === "custom") works = true;
|
|
18
|
+
}
|
|
19
|
+
let heldEnd = false;
|
|
20
|
+
for (let i = events.length - 1; i >= 0 && !heldEnd; i--) {
|
|
21
|
+
const setup = readEnvironmentSetup(events[i]);
|
|
22
|
+
if (!setup) break;
|
|
23
|
+
heldEnd = setup.state === "running" || setup.waited === true;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
keys: [...keys],
|
|
27
|
+
heldEnd,
|
|
28
|
+
envError,
|
|
29
|
+
works
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The ties of a settled exchange (computed once per chunk).
|
|
34
|
+
*
|
|
35
|
+
* @param chunk - The exchange's events, never changed.
|
|
36
|
+
*/
|
|
37
|
+
function chunkTies(chunk) {
|
|
38
|
+
return chunkFact(chunk, "row-ties", tiesOf);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The ties of the open exchange (computed each time: it changes every frame).
|
|
42
|
+
*
|
|
43
|
+
* @param tail - The open exchange's events.
|
|
44
|
+
*/
|
|
45
|
+
function tailTies(tail) {
|
|
46
|
+
return tiesOf(tail);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The blocks of a list of exchanges, grown one exchange at a time. Reused
|
|
50
|
+
* while the list only grows (a commit appends one exchange); any other change
|
|
51
|
+
* plans again from the start.
|
|
52
|
+
*/
|
|
53
|
+
var BlockPlan = class {
|
|
54
|
+
/** The exchanges planned so far. */
|
|
55
|
+
chunks = [];
|
|
56
|
+
/** The blocks, oldest first, covering every planned exchange. */
|
|
57
|
+
blocks = [];
|
|
58
|
+
firstSeen = /* @__PURE__ */ new Map();
|
|
59
|
+
openRepair = -1;
|
|
60
|
+
lastHeld = false;
|
|
61
|
+
/**
|
|
62
|
+
* Brings the plan to `chunks`.
|
|
63
|
+
*
|
|
64
|
+
* @param chunks - The settled exchanges, oldest first.
|
|
65
|
+
*/
|
|
66
|
+
update(chunks) {
|
|
67
|
+
if (chunks === this.chunks) return;
|
|
68
|
+
let same = chunks.length >= this.chunks.length;
|
|
69
|
+
for (let i = 0; same && i < this.chunks.length; i++) same = chunks[i] === this.chunks[i];
|
|
70
|
+
if (!same) {
|
|
71
|
+
this.blocks = [];
|
|
72
|
+
this.firstSeen = /* @__PURE__ */ new Map();
|
|
73
|
+
this.openRepair = -1;
|
|
74
|
+
this.lastHeld = false;
|
|
75
|
+
}
|
|
76
|
+
for (let i = same ? this.chunks.length : 0; i < chunks.length; i++) this.add(i, chunkTies(chunks[i]));
|
|
77
|
+
this.chunks = chunks;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The index of the first block an exchange with `ties`, appended after the planned ones, must join (`blocks.length` for none).
|
|
81
|
+
*
|
|
82
|
+
* @param ties - The appended exchange's ties.
|
|
83
|
+
*/
|
|
84
|
+
joinFrom(ties) {
|
|
85
|
+
const reach = this.reach(this.chunks.length, ties, false);
|
|
86
|
+
let b = this.blocks.length;
|
|
87
|
+
while (b > 0 && this.blocks[b - 1].end > reach) b--;
|
|
88
|
+
return b;
|
|
89
|
+
}
|
|
90
|
+
add(index, ties) {
|
|
91
|
+
const reach = this.reach(index, ties, true);
|
|
92
|
+
let start = index;
|
|
93
|
+
while (this.blocks.length > 0 && this.blocks.at(-1).end > reach) start = this.blocks.pop().start;
|
|
94
|
+
this.blocks.push({
|
|
95
|
+
start,
|
|
96
|
+
end: index + 1
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/** The earliest exchange the one at `index` ties to (`index` for none); `record` files its ids. */
|
|
100
|
+
reach(index, ties, record) {
|
|
101
|
+
let reach = index;
|
|
102
|
+
for (const key of ties.keys) {
|
|
103
|
+
const seen = this.firstSeen.get(key);
|
|
104
|
+
if (seen !== void 0) reach = Math.min(reach, seen);
|
|
105
|
+
else if (record) this.firstSeen.set(key, index);
|
|
106
|
+
}
|
|
107
|
+
if (this.lastHeld) reach = Math.min(reach, index - 1);
|
|
108
|
+
if (ties.works && this.openRepair >= 0) reach = Math.min(reach, this.openRepair);
|
|
109
|
+
if (record) {
|
|
110
|
+
this.openRepair = ties.envError ? index : ties.works ? -1 : this.openRepair;
|
|
111
|
+
this.lastHeld = ties.heldEnd;
|
|
112
|
+
}
|
|
113
|
+
return reach;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
export { BlockPlan, chunkTies, tailTies };
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A tool result's media, read from its text: the transcript carries each
|
|
3
|
-
* image, video or audio block as a stand-in line (`[image: image/png, 742500
|
|
4
|
-
* b64 bytes]`, core's `toolResultToText`), which an app that serves the
|
|
5
|
-
* bytes turns back into the media (`TranscriptActions.toolMediaUrl`).
|
|
6
|
-
*/
|
|
7
1
|
/** One media block of a tool result, as parsed from its text stand-in. */
|
|
8
2
|
export interface ToolMediaItem {
|
|
9
3
|
/** What the block is. */
|
|
@@ -14,13 +8,18 @@ export interface ToolMediaItem {
|
|
|
14
8
|
index: number;
|
|
15
9
|
/** The stand-in line, shown again if the media fails to load. */
|
|
16
10
|
marker: string;
|
|
11
|
+
/** The blob hash the store holds the block by, when it does: its address for good. */
|
|
12
|
+
hash?: string;
|
|
17
13
|
}
|
|
18
14
|
/**
|
|
19
15
|
* The media stand-ins of a result's text, in order, and the text without them.
|
|
20
16
|
*
|
|
21
17
|
* @param text - The tool result's text.
|
|
18
|
+
* @param keep - Which items become media; the others stay in the text as their stand-in line (an app that can serve
|
|
19
|
+
* them not). Every item keeps its position among the result's media (`index`). Default: all.
|
|
20
|
+
* @param refs - The blobs the blocks are held as, by position (`StreamEvent.mediaRefs`): their `hash`.
|
|
22
21
|
*/
|
|
23
|
-
export declare function parseToolMedia(text: string): {
|
|
22
|
+
export declare function parseToolMedia(text: string, keep?: (item: ToolMediaItem) => boolean, refs?: readonly (string | null)[]): {
|
|
24
23
|
media: ToolMediaItem[];
|
|
25
24
|
rest: string;
|
|
26
25
|
};
|
|
@@ -1,22 +1,40 @@
|
|
|
1
|
+
import { blobHashOf } from "./blob-media.js";
|
|
1
2
|
// src/chat/headless/transcript/tool-media.ts
|
|
2
|
-
|
|
3
|
+
/**
|
|
4
|
+
* A tool result's media, read from its text: the transcript carries each
|
|
5
|
+
* image, video or audio block as a stand-in line (`[image: image/png, 742500
|
|
6
|
+
* b64 bytes]`, core's `toolResultToText`), which an app that serves the
|
|
7
|
+
* bytes turns back into the media (`TranscriptActions.toolMediaUrl`). A block
|
|
8
|
+
* the store holds by hash reads `ref attachment://<hash>` in place of its size:
|
|
9
|
+
* its `hash` addresses it for good (`TranscriptActions.blobMediaUrl`).
|
|
10
|
+
*/
|
|
11
|
+
const MARKER = /^\[(image|video|audio): ([^,\]]+), (?:\d+ b64 bytes|ref ([^\]]*))\]$/;
|
|
3
12
|
/**
|
|
4
13
|
* The media stand-ins of a result's text, in order, and the text without them.
|
|
5
14
|
*
|
|
6
15
|
* @param text - The tool result's text.
|
|
16
|
+
* @param keep - Which items become media; the others stay in the text as their stand-in line (an app that can serve
|
|
17
|
+
* them not). Every item keeps its position among the result's media (`index`). Default: all.
|
|
18
|
+
* @param refs - The blobs the blocks are held as, by position (`StreamEvent.mediaRefs`): their `hash`.
|
|
7
19
|
*/
|
|
8
|
-
function parseToolMedia(text) {
|
|
20
|
+
function parseToolMedia(text, keep, refs) {
|
|
9
21
|
const media = [];
|
|
10
22
|
const rest = [];
|
|
23
|
+
let index = 0;
|
|
11
24
|
for (const line of text.split("\n")) {
|
|
12
25
|
const m = MARKER.exec(line.trim());
|
|
13
|
-
if (m)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
if (m) {
|
|
27
|
+
const hash = blobHashOf(refs?.[index] ?? void 0) ?? blobHashOf(m[3]?.trim());
|
|
28
|
+
const item = {
|
|
29
|
+
kind: m[1],
|
|
30
|
+
mediaType: m[2].trim(),
|
|
31
|
+
index: index++,
|
|
32
|
+
marker: line.trim(),
|
|
33
|
+
...hash ? { hash } : {}
|
|
34
|
+
};
|
|
35
|
+
if (!keep || keep(item)) media.push(item);
|
|
36
|
+
else rest.push(line);
|
|
37
|
+
} else rest.push(line);
|
|
20
38
|
}
|
|
21
39
|
return {
|
|
22
40
|
media,
|