@d0nj/dsh-narration 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -2
- package/cordis.patch.yml +7 -0
- package/dist/ansi.d.ts +13 -0
- package/dist/ansi.js +83 -0
- package/dist/client/assistant.d.ts +25 -0
- package/dist/client/assistant.js +208 -0
- package/dist/client/client.js +1609 -0
- package/dist/client/index.d.ts +16 -0
- package/dist/client/index.js +78 -0
- package/dist/client/rail.d.ts +20 -0
- package/dist/client/rail.js +182 -0
- package/dist/client/style.d.ts +4 -0
- package/dist/client/style.js +373 -0
- package/dist/client/tool.d.ts +37 -0
- package/dist/client/tool.js +384 -0
- package/dist/diff.d.ts +31 -0
- package/dist/diff.js +181 -0
- package/dist/envelope.d.ts +7 -0
- package/dist/envelope.js +29 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +39 -0
- package/dist/live.d.ts +48 -0
- package/dist/live.js +124 -0
- package/dist/narration.d.ts +9 -0
- package/dist/narration.js +27 -0
- package/dist/pacing.d.ts +17 -0
- package/dist/pacing.js +92 -0
- package/icon.svg +16 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +70 -4
|
@@ -0,0 +1,1609 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "@d0nj/dsh-narration",
|
|
3
|
+
factory(require) {
|
|
4
|
+
const __modules = new Map()
|
|
5
|
+
function __require(id) {
|
|
6
|
+
if (__modules.has(id)) return __modules.get(id)
|
|
7
|
+
const factory = __factories[id]
|
|
8
|
+
if (factory === undefined) throw new Error("@d0nj/dsh-narration: unknown module " + id)
|
|
9
|
+
const module = { exports: {} }
|
|
10
|
+
__modules.set(id, module.exports)
|
|
11
|
+
factory(module, module.exports, __require)
|
|
12
|
+
__modules.set(id, module.exports)
|
|
13
|
+
return module.exports
|
|
14
|
+
}
|
|
15
|
+
const __factories = {
|
|
16
|
+
"./client/index.js": (module, exports, __require) => {
|
|
17
|
+
const { createAssistantNarration } = __require('./client/assistant.js');
|
|
18
|
+
const { createToolNarration } = __require('./client/tool.js');
|
|
19
|
+
const { CSS, STYLE_ELEMENT_ID } = __require('./client/style.js');
|
|
20
|
+
const inject = ['slots', 'configForms'];
|
|
21
|
+
const CHAT_SLOT = 'conversation.chat.node';
|
|
22
|
+
const ASSISTANT_KEY = 'assistant-step';
|
|
23
|
+
const TOOL_KEY = 'tool-call';
|
|
24
|
+
const SHADOW_PRIORITY = -1;
|
|
25
|
+
let ReactImpl;
|
|
26
|
+
function useReact(react) {
|
|
27
|
+
ReactImpl = react;
|
|
28
|
+
}
|
|
29
|
+
function flagsOf(value) {
|
|
30
|
+
if (value === null || typeof value !== 'object')
|
|
31
|
+
return { liveReasoning: true, verboseTools: true };
|
|
32
|
+
const record = value;
|
|
33
|
+
return {
|
|
34
|
+
liveReasoning: record.liveReasoning !== false,
|
|
35
|
+
verboseTools: record.verboseTools !== false,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function installStyles(doc) {
|
|
39
|
+
const existing = doc.getElementById(STYLE_ELEMENT_ID);
|
|
40
|
+
if (existing !== null)
|
|
41
|
+
existing.remove();
|
|
42
|
+
const element = doc.createElement('style');
|
|
43
|
+
element.id = STYLE_ELEMENT_ID;
|
|
44
|
+
element.textContent = CSS;
|
|
45
|
+
doc.head.appendChild(element);
|
|
46
|
+
return () => {
|
|
47
|
+
element.remove();
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function apply(ctx) {
|
|
51
|
+
if (ReactImpl === undefined)
|
|
52
|
+
return;
|
|
53
|
+
const slots = ctx.slots;
|
|
54
|
+
if (slots === undefined)
|
|
55
|
+
return;
|
|
56
|
+
const forms = ctx.configForms;
|
|
57
|
+
const Assistant = createAssistantNarration(ReactImpl);
|
|
58
|
+
const Tool = createToolNarration(ReactImpl);
|
|
59
|
+
ctx.effect(() => installStyles(document));
|
|
60
|
+
let assistantMount;
|
|
61
|
+
let toolMount;
|
|
62
|
+
const mount = (key, component) => slots.inject(CHAT_SLOT, () => slots.register({ name: CHAT_SLOT, key, priority: SHADOW_PRIORITY }, component));
|
|
63
|
+
const sync = (value) => {
|
|
64
|
+
const flags = flagsOf(value);
|
|
65
|
+
if (flags.liveReasoning && assistantMount === undefined) {
|
|
66
|
+
assistantMount = mount(ASSISTANT_KEY, Assistant);
|
|
67
|
+
}
|
|
68
|
+
else if (!flags.liveReasoning && assistantMount !== undefined) {
|
|
69
|
+
assistantMount();
|
|
70
|
+
assistantMount = undefined;
|
|
71
|
+
}
|
|
72
|
+
if (flags.verboseTools && toolMount === undefined) {
|
|
73
|
+
toolMount = mount(TOOL_KEY, Tool);
|
|
74
|
+
}
|
|
75
|
+
else if (!flags.verboseTools && toolMount !== undefined) {
|
|
76
|
+
toolMount();
|
|
77
|
+
toolMount = undefined;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
ctx.effect(() => () => {
|
|
81
|
+
assistantMount?.();
|
|
82
|
+
toolMount?.();
|
|
83
|
+
assistantMount = undefined;
|
|
84
|
+
toolMount = undefined;
|
|
85
|
+
});
|
|
86
|
+
if (forms === undefined) {
|
|
87
|
+
sync(undefined);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const form = forms.get('narration');
|
|
91
|
+
ctx.effect(() => form.subscribe(() => sync(form.getSnapshot().value)));
|
|
92
|
+
sync(form.getSnapshot().value);
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=index.js.map
|
|
95
|
+
Object.assign(exports, { useReact: useReact, flagsOf: flagsOf, installStyles: installStyles, apply: apply, inject: inject, CHAT_SLOT: CHAT_SLOT, ASSISTANT_KEY: ASSISTANT_KEY, TOOL_KEY: TOOL_KEY, SHADOW_PRIORITY: SHADOW_PRIORITY });
|
|
96
|
+
|
|
97
|
+
},
|
|
98
|
+
"./client/assistant.js": (module, exports, __require) => {
|
|
99
|
+
const { PacedText, RateMeter } = __require('./pacing.js');
|
|
100
|
+
const { formatElapsed, formatRate, narrateCall, phaseLabel, splitPath, summarize } = __require('./live.js');
|
|
101
|
+
const { PHASE_COLOUR } = __require('./client/style.js');
|
|
102
|
+
const NO_SELECT = () => undefined;
|
|
103
|
+
const MISSING_ARGS = { text: () => undefined };
|
|
104
|
+
const REASONING_FACTORY = 'conversation.chat.reasoning.content';
|
|
105
|
+
function legacyOf(snapshot) {
|
|
106
|
+
if (snapshot === null || typeof snapshot !== 'object')
|
|
107
|
+
return undefined;
|
|
108
|
+
const legacy = snapshot.legacy;
|
|
109
|
+
return legacy !== null && typeof legacy === 'object' ? legacy : undefined;
|
|
110
|
+
}
|
|
111
|
+
function toLiveCalls(raw) {
|
|
112
|
+
if (!Array.isArray(raw))
|
|
113
|
+
return [];
|
|
114
|
+
const calls = [];
|
|
115
|
+
for (const entry of raw) {
|
|
116
|
+
if (entry === null || typeof entry !== 'object')
|
|
117
|
+
continue;
|
|
118
|
+
const record = entry;
|
|
119
|
+
if (typeof record.callId !== 'string' || typeof record.name !== 'string')
|
|
120
|
+
continue;
|
|
121
|
+
const source = record.args;
|
|
122
|
+
const usable = source !== null && typeof source === 'object' && typeof source.text === 'function';
|
|
123
|
+
calls.push({
|
|
124
|
+
callId: record.callId,
|
|
125
|
+
name: record.name,
|
|
126
|
+
phase: record.phase === 'start' ? 'start' : 'preparing',
|
|
127
|
+
time: typeof record.time === 'number' ? record.time : 0,
|
|
128
|
+
args: usable ? source : MISSING_ARGS,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return calls;
|
|
132
|
+
}
|
|
133
|
+
function assistantStatus(node) {
|
|
134
|
+
if (node === null || typeof node !== 'object')
|
|
135
|
+
return 'settled';
|
|
136
|
+
const data = node.data;
|
|
137
|
+
if (data === null || typeof data !== 'object')
|
|
138
|
+
return 'settled';
|
|
139
|
+
const status = data.status;
|
|
140
|
+
return status === 'running' || status === 'interrupted' ? status : 'settled';
|
|
141
|
+
}
|
|
142
|
+
function blocksOf(node) {
|
|
143
|
+
if (node === null || typeof node !== 'object')
|
|
144
|
+
return [];
|
|
145
|
+
const data = node.data;
|
|
146
|
+
if (data === null || typeof data !== 'object')
|
|
147
|
+
return [];
|
|
148
|
+
const blocks = data.blocks;
|
|
149
|
+
return Array.isArray(blocks) ? blocks : [];
|
|
150
|
+
}
|
|
151
|
+
function textOfBlocks(blocks, kind) {
|
|
152
|
+
let text = '';
|
|
153
|
+
for (const block of blocks) {
|
|
154
|
+
if (block === null || typeof block !== 'object')
|
|
155
|
+
continue;
|
|
156
|
+
const entry = block;
|
|
157
|
+
if (entry.kind !== kind || typeof entry.text !== 'string')
|
|
158
|
+
continue;
|
|
159
|
+
text += entry.text;
|
|
160
|
+
}
|
|
161
|
+
return text;
|
|
162
|
+
}
|
|
163
|
+
function usePacedText(React, target, animating) {
|
|
164
|
+
const [shown, setShown] = React.useState(target);
|
|
165
|
+
const stream = React.useRef({ seen: target, queue: new PacedText() });
|
|
166
|
+
React.useEffect(() => {
|
|
167
|
+
const state = stream.current;
|
|
168
|
+
const previouslySeen = state.seen;
|
|
169
|
+
state.seen = target;
|
|
170
|
+
if (!target.startsWith(previouslySeen)) {
|
|
171
|
+
state.queue.reset();
|
|
172
|
+
setShown(target);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const delta = target.slice(previouslySeen.length);
|
|
176
|
+
if (delta.length === 0)
|
|
177
|
+
return;
|
|
178
|
+
if (!animating) {
|
|
179
|
+
state.queue.reset();
|
|
180
|
+
setShown(target);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
state.queue.push(delta);
|
|
184
|
+
let frame = 0;
|
|
185
|
+
const step = () => {
|
|
186
|
+
const chunk = state.queue.take();
|
|
187
|
+
if (chunk.length > 0)
|
|
188
|
+
setShown((previous) => previous + chunk);
|
|
189
|
+
frame = state.queue.pending > 0 ? requestAnimationFrame(step) : 0;
|
|
190
|
+
};
|
|
191
|
+
frame = requestAnimationFrame(step);
|
|
192
|
+
return () => {
|
|
193
|
+
if (frame !== 0)
|
|
194
|
+
cancelAnimationFrame(frame);
|
|
195
|
+
};
|
|
196
|
+
}, [target, animating]);
|
|
197
|
+
return shown;
|
|
198
|
+
}
|
|
199
|
+
function useClock(React, working, meter, charsOf) {
|
|
200
|
+
const [now, setNow] = React.useState(() => Date.now());
|
|
201
|
+
const [rate, setRate] = React.useState(0);
|
|
202
|
+
React.useEffect(() => {
|
|
203
|
+
if (!working) {
|
|
204
|
+
meter.current.reset();
|
|
205
|
+
setRate(0);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const tick = setInterval(() => {
|
|
209
|
+
const at = Date.now();
|
|
210
|
+
setNow(at);
|
|
211
|
+
setRate(meter.current.sample(at, charsOf()));
|
|
212
|
+
}, 100);
|
|
213
|
+
return () => clearInterval(tick);
|
|
214
|
+
}, [working]);
|
|
215
|
+
return { now, rate };
|
|
216
|
+
}
|
|
217
|
+
function callRow(React, call, now) {
|
|
218
|
+
const narration = narrateCall(call, 220);
|
|
219
|
+
const parts = splitPath(narration.argument);
|
|
220
|
+
const spent = call.time > 0 ? formatElapsed(Math.max(0, now - call.time)) : '';
|
|
221
|
+
return React.createElement('div', { key: call.callId, className: 'd0nj-narr-call', 'data-preparing': String(narration.preparing) }, React.createElement('span', { className: 'd0nj-narr-verb' }, narration.verb), React.createElement('span', { className: 'd0nj-narr-arg' }, parts.directory.length > 0
|
|
222
|
+
? React.createElement('span', { className: 'd0nj-narr-dir' }, parts.directory)
|
|
223
|
+
: null, React.createElement('span', { className: 'd0nj-narr-base' }, parts.base), React.createElement('span', { className: 'd0nj-narr-caret' })), spent.length > 0 ? React.createElement('span', { className: 'd0nj-narr-spent' }, spent) : null);
|
|
224
|
+
}
|
|
225
|
+
function createAssistantNarration(React) {
|
|
226
|
+
const h = React.createElement;
|
|
227
|
+
return function AssistantNarration(props) {
|
|
228
|
+
const useChat = props.useChat ?? NO_SELECT;
|
|
229
|
+
const status = assistantStatus(props.node);
|
|
230
|
+
const streaming = status === 'running';
|
|
231
|
+
const blocks = blocksOf(props.node);
|
|
232
|
+
const reasoningTarget = textOfBlocks(blocks, 'reasoning');
|
|
233
|
+
const answer = textOfBlocks(blocks, 'text');
|
|
234
|
+
const part = typeof props.groupPart === 'string' ? props.groupPart : undefined;
|
|
235
|
+
const showReasoning = part !== 'response';
|
|
236
|
+
const showAnswer = part !== 'reasoning';
|
|
237
|
+
const rawCalls = useChat((snapshot) => legacyOf(snapshot)?.runningCalls);
|
|
238
|
+
const calls = streaming ? toLiveCalls(rawCalls) : [];
|
|
239
|
+
const reasoning = usePacedText(React, reasoningTarget, streaming);
|
|
240
|
+
const meter = React.useRef(new RateMeter());
|
|
241
|
+
const charsRef = React.useRef(0);
|
|
242
|
+
charsRef.current = reasoningTarget.length + answer.length;
|
|
243
|
+
const { now, rate } = useClock(React, streaming, meter, () => charsRef.current);
|
|
244
|
+
const start = React.useRef(0);
|
|
245
|
+
React.useEffect(() => {
|
|
246
|
+
if (streaming && start.current === 0)
|
|
247
|
+
start.current = Date.now();
|
|
248
|
+
if (!streaming)
|
|
249
|
+
start.current = 0;
|
|
250
|
+
}, [streaming]);
|
|
251
|
+
const [thinkingOpen, setThinkingOpen] = React.useState(true);
|
|
252
|
+
const toggleThinking = () => {
|
|
253
|
+
setThinkingOpen((previous) => !previous);
|
|
254
|
+
};
|
|
255
|
+
const pinned = React.useRef(true);
|
|
256
|
+
const summary = summarize({ calls, reasoning, answer, running: streaming, limit: 120 });
|
|
257
|
+
const elapsed = start.current === 0 ? 0 : Math.max(0, now - start.current);
|
|
258
|
+
const countLabel = calls.length > 1 ? String(calls.length) : '';
|
|
259
|
+
const hasReasoning = reasoningTarget.length > 0;
|
|
260
|
+
const header = streaming && showReasoning
|
|
261
|
+
? h('button', {
|
|
262
|
+
type: 'button',
|
|
263
|
+
className: 'd0nj-narr-live',
|
|
264
|
+
'data-working': 'true',
|
|
265
|
+
'aria-expanded': hasReasoning ? thinkingOpen : undefined,
|
|
266
|
+
onClick: hasReasoning ? toggleThinking : undefined,
|
|
267
|
+
}, h('span', { className: 'd0nj-narr-dot', style: { '--d0nj-narr-phase': PHASE_COLOUR[summary.phase] ?? PHASE_COLOUR.idle } }), h('span', { className: 'd0nj-narr-phase' }, phaseLabel(summary.phase)), countLabel.length > 0 ? h('span', { className: 'd0nj-narr-count' }, countLabel + ' calls') : null, h('span', { className: 'd0nj-narr-metrics' }, h('span', null, formatElapsed(elapsed)), rate > 0 ? h('span', null, formatRate(rate)) : null))
|
|
268
|
+
: null;
|
|
269
|
+
const roster = calls.length > 0 && showReasoning
|
|
270
|
+
? h('div', { className: 'd0nj-narr-calls' }, calls.map((call) => callRow(React, call, now)))
|
|
271
|
+
: null;
|
|
272
|
+
const thinkingBody = showReasoning && thinkingOpen && hasReasoning
|
|
273
|
+
? h('pre', {
|
|
274
|
+
className: 'd0nj-narr-think-body',
|
|
275
|
+
ref: (element) => {
|
|
276
|
+
if (element !== null && pinned.current)
|
|
277
|
+
element.scrollTop = element.scrollHeight;
|
|
278
|
+
},
|
|
279
|
+
onScroll: (event) => {
|
|
280
|
+
const element = event.currentTarget;
|
|
281
|
+
pinned.current = element.scrollHeight - element.scrollTop - element.clientHeight < 12;
|
|
282
|
+
},
|
|
283
|
+
}, reasoning)
|
|
284
|
+
: null;
|
|
285
|
+
const thinking = hasReasoning && showReasoning
|
|
286
|
+
? h('div', { className: 'd0nj-narr-think' }, streaming
|
|
287
|
+
? null
|
|
288
|
+
: h('button', {
|
|
289
|
+
type: 'button',
|
|
290
|
+
className: 'd0nj-narr-think-head',
|
|
291
|
+
'aria-expanded': thinkingOpen,
|
|
292
|
+
onClick: toggleThinking,
|
|
293
|
+
}, (thinkingOpen ? '\u25be ' : '\u25b8 ') + 'Thinking'), thinkingBody)
|
|
294
|
+
: null;
|
|
295
|
+
const factory = props.renderFactorySlot;
|
|
296
|
+
const answerNode = answer.length > 0 && showAnswer
|
|
297
|
+
? h('div', { className: 'd0nj-narr-answer' }, typeof factory === 'function'
|
|
298
|
+
? factory(REASONING_FACTORY, { text: answer, running: streaming })
|
|
299
|
+
: h('div', { className: 'd0nj-narr-plain' }, answer))
|
|
300
|
+
: null;
|
|
301
|
+
if (header === null && roster === null && thinking === null && answerNode === null)
|
|
302
|
+
return null;
|
|
303
|
+
return h('div', { className: 'd0nj-narr' }, header, roster, thinking, answerNode);
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
//# sourceMappingURL=assistant.js.map
|
|
307
|
+
Object.assign(exports, { toLiveCalls: toLiveCalls, assistantStatus: assistantStatus, blocksOf: blocksOf, textOfBlocks: textOfBlocks, createAssistantNarration: createAssistantNarration, REASONING_FACTORY: REASONING_FACTORY });
|
|
308
|
+
|
|
309
|
+
},
|
|
310
|
+
"./pacing.js": (module, exports, __require) => {
|
|
311
|
+
function frameBudget(pending) {
|
|
312
|
+
if (pending <= 0)
|
|
313
|
+
return 0;
|
|
314
|
+
if (pending <= 2)
|
|
315
|
+
return pending;
|
|
316
|
+
if (pending <= 16)
|
|
317
|
+
return 2;
|
|
318
|
+
if (pending <= 96)
|
|
319
|
+
return 4;
|
|
320
|
+
if (pending <= 320)
|
|
321
|
+
return 8;
|
|
322
|
+
return Math.max(16, Math.ceil(pending / 6));
|
|
323
|
+
}
|
|
324
|
+
function pairSafeLength(text) {
|
|
325
|
+
const last = text.charCodeAt(text.length - 1);
|
|
326
|
+
return last >= 0xd800 && last <= 0xdbff ? text.length - 1 : text.length;
|
|
327
|
+
}
|
|
328
|
+
class PacedText {
|
|
329
|
+
#parts = [];
|
|
330
|
+
#pending = 0;
|
|
331
|
+
#closed = false;
|
|
332
|
+
get pending() {
|
|
333
|
+
return this.#pending;
|
|
334
|
+
}
|
|
335
|
+
get closed() {
|
|
336
|
+
return this.#closed;
|
|
337
|
+
}
|
|
338
|
+
push(text) {
|
|
339
|
+
if (text.length === 0)
|
|
340
|
+
return;
|
|
341
|
+
this.#parts.push(text);
|
|
342
|
+
this.#pending += text.length;
|
|
343
|
+
}
|
|
344
|
+
close() {
|
|
345
|
+
this.#closed = true;
|
|
346
|
+
}
|
|
347
|
+
take() {
|
|
348
|
+
const limit = Math.min(frameBudget(this.#pending), this.#pending);
|
|
349
|
+
if (limit <= 0)
|
|
350
|
+
return '';
|
|
351
|
+
let out = '';
|
|
352
|
+
let need = limit;
|
|
353
|
+
while (need > 0) {
|
|
354
|
+
const head = this.#parts[0];
|
|
355
|
+
if (head === undefined)
|
|
356
|
+
break;
|
|
357
|
+
if (head.length <= need) {
|
|
358
|
+
out += head;
|
|
359
|
+
this.#parts.shift();
|
|
360
|
+
need -= head.length;
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
out += head.slice(0, need);
|
|
364
|
+
this.#parts[0] = head.slice(need);
|
|
365
|
+
need = 0;
|
|
366
|
+
}
|
|
367
|
+
const usable = pairSafeLength(out);
|
|
368
|
+
if (usable < out.length)
|
|
369
|
+
this.#parts.unshift(out.slice(usable));
|
|
370
|
+
this.#pending -= usable;
|
|
371
|
+
return out.slice(0, usable);
|
|
372
|
+
}
|
|
373
|
+
reset() {
|
|
374
|
+
this.#parts = [];
|
|
375
|
+
this.#pending = 0;
|
|
376
|
+
this.#closed = false;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
class RateMeter {
|
|
380
|
+
#window = [];
|
|
381
|
+
#spanMs;
|
|
382
|
+
constructor(spanMs = 1200) {
|
|
383
|
+
this.#spanMs = spanMs;
|
|
384
|
+
}
|
|
385
|
+
sample(at, total) {
|
|
386
|
+
const window = this.#window;
|
|
387
|
+
window.push({ at, total });
|
|
388
|
+
while (window.length > 1 && at - window[0].at > this.#spanMs)
|
|
389
|
+
window.shift();
|
|
390
|
+
const first = window[0];
|
|
391
|
+
if (first === undefined || window.length < 2)
|
|
392
|
+
return 0;
|
|
393
|
+
const elapsed = at - first.at;
|
|
394
|
+
if (elapsed <= 0)
|
|
395
|
+
return 0;
|
|
396
|
+
return Math.max(0, ((total - first.total) * 1000) / elapsed);
|
|
397
|
+
}
|
|
398
|
+
reset() {
|
|
399
|
+
this.#window.length = 0;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
//# sourceMappingURL=pacing.js.map
|
|
403
|
+
Object.assign(exports, { frameBudget: frameBudget, PacedText: PacedText, RateMeter: RateMeter });
|
|
404
|
+
|
|
405
|
+
},
|
|
406
|
+
"./live.js": (module, exports, __require) => {
|
|
407
|
+
const TOOL_NARRATION = {
|
|
408
|
+
apply_patch: { verb: 'Patching', keys: ['path'] },
|
|
409
|
+
bash: { verb: 'Running', keys: ['command'] },
|
|
410
|
+
edit: { verb: 'Editing', keys: ['file_path', 'path'] },
|
|
411
|
+
glob: { verb: 'Globbing', keys: ['pattern'] },
|
|
412
|
+
grep: { verb: 'Searching', keys: ['pattern'] },
|
|
413
|
+
pwsh: { verb: 'Running', keys: ['command'] },
|
|
414
|
+
read: { verb: 'Reading', keys: ['file_path', 'path'] },
|
|
415
|
+
read_image: { verb: 'Opening', keys: ['file_path', 'path'] },
|
|
416
|
+
subagent: { verb: 'Delegating', keys: ['description'] },
|
|
417
|
+
subagent_fork: { verb: 'Forking', keys: ['description'] },
|
|
418
|
+
web_fetch: { verb: 'Fetching', keys: ['url'] },
|
|
419
|
+
web_search: { verb: 'Searching the web', keys: ['query'] },
|
|
420
|
+
workflow: { verb: 'Orchestrating', keys: ['description'] },
|
|
421
|
+
write: { verb: 'Writing', keys: ['file_path', 'path'] },
|
|
422
|
+
};
|
|
423
|
+
const FALLBACK_KEYS = ['command', 'path', 'file_path', 'pattern', 'url', 'query', 'description', 'prompt'];
|
|
424
|
+
const PREPARING_LABEL = 'composing';
|
|
425
|
+
function clip(text, limit) {
|
|
426
|
+
const single = text.replace(/\s+/gu, ' ').trim();
|
|
427
|
+
if (single.length <= limit)
|
|
428
|
+
return single;
|
|
429
|
+
return single.slice(0, Math.max(0, completedIndex(single, limit))) + '\u2026';
|
|
430
|
+
}
|
|
431
|
+
function completedIndex(text, limit) {
|
|
432
|
+
if (limit <= 0)
|
|
433
|
+
return 0;
|
|
434
|
+
const code = text.charCodeAt(limit - 1);
|
|
435
|
+
return code >= 0xd800 && code <= 0xdbff ? limit - 1 : limit;
|
|
436
|
+
}
|
|
437
|
+
function readArgument(call, keys) {
|
|
438
|
+
for (const key of keys) {
|
|
439
|
+
const value = call.args.text(key);
|
|
440
|
+
if (value !== undefined && value.length > 0)
|
|
441
|
+
return value;
|
|
442
|
+
}
|
|
443
|
+
return '';
|
|
444
|
+
}
|
|
445
|
+
function narrateCall(call, limit = 96) {
|
|
446
|
+
const known = TOOL_NARRATION[call.name];
|
|
447
|
+
const keys = known === undefined ? FALLBACK_KEYS : known.keys;
|
|
448
|
+
const raw = readArgument(call, keys);
|
|
449
|
+
const preparing = call.phase === 'preparing';
|
|
450
|
+
const argument = raw.length > 0 ? clip(raw, limit) : preparing ? PREPARING_LABEL + '\u2026' : '';
|
|
451
|
+
const verb = known === undefined ? call.name.replaceAll('_', ' ') : known.verb;
|
|
452
|
+
return {
|
|
453
|
+
key: call.callId,
|
|
454
|
+
verb,
|
|
455
|
+
argument,
|
|
456
|
+
preparing,
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
function splitPath(value) {
|
|
460
|
+
const at = Math.max(value.lastIndexOf('/'), value.lastIndexOf('\\'));
|
|
461
|
+
return at < 0
|
|
462
|
+
? { directory: '', base: value }
|
|
463
|
+
: { directory: value.slice(0, at + 1), base: value.slice(at + 1) };
|
|
464
|
+
}
|
|
465
|
+
function formatElapsed(ms) {
|
|
466
|
+
if (!Number.isFinite(ms) || ms < 0)
|
|
467
|
+
return '0.0s';
|
|
468
|
+
const seconds = ms / 1000;
|
|
469
|
+
if (seconds < 10)
|
|
470
|
+
return seconds.toFixed(1) + 's';
|
|
471
|
+
if (seconds < 60)
|
|
472
|
+
return Math.floor(seconds) + 's';
|
|
473
|
+
const whole = Math.floor(seconds);
|
|
474
|
+
return Math.floor(whole / 60) + 'm' + String(whole % 60).padStart(2, '0') + 's';
|
|
475
|
+
}
|
|
476
|
+
function formatRate(charsPerSecond) {
|
|
477
|
+
if (!Number.isFinite(charsPerSecond) || charsPerSecond <= 0)
|
|
478
|
+
return '\u2014';
|
|
479
|
+
if (charsPerSecond < 10)
|
|
480
|
+
return charsPerSecond.toFixed(1) + '/s';
|
|
481
|
+
return Math.round(charsPerSecond) + '/s';
|
|
482
|
+
}
|
|
483
|
+
function summarize(input) {
|
|
484
|
+
const limit = input.limit ?? 96;
|
|
485
|
+
const calls = input.calls.map((call) => narrateCall(call, limit));
|
|
486
|
+
const phase = resolvePhase(input.calls, input.answer, input.reasoning, input.running);
|
|
487
|
+
return {
|
|
488
|
+
phase,
|
|
489
|
+
reasoning: input.reasoning,
|
|
490
|
+
answer: input.answer,
|
|
491
|
+
calls,
|
|
492
|
+
lead: leadSentence(phase, calls, input.reasoning, input.answer, limit),
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
function resolvePhase(calls, answer, reasoning, running) {
|
|
496
|
+
if (calls.length > 0)
|
|
497
|
+
return 'calling';
|
|
498
|
+
if (answer.length > 0)
|
|
499
|
+
return 'writing';
|
|
500
|
+
if (reasoning.length > 0)
|
|
501
|
+
return 'thinking';
|
|
502
|
+
return running ? 'holding' : 'idle';
|
|
503
|
+
}
|
|
504
|
+
const PHASE_LABEL = {
|
|
505
|
+
idle: 'Ready',
|
|
506
|
+
thinking: 'Thinking',
|
|
507
|
+
writing: 'Writing',
|
|
508
|
+
calling: 'Acting',
|
|
509
|
+
holding: 'Working',
|
|
510
|
+
};
|
|
511
|
+
function phaseLabel(phase) {
|
|
512
|
+
return PHASE_LABEL[phase];
|
|
513
|
+
}
|
|
514
|
+
function leadSentence(phase, calls, reasoning, answer, limit) {
|
|
515
|
+
const tail = lastLine(phase === 'writing' ? answer : reasoning, limit);
|
|
516
|
+
if (tail.length > 0)
|
|
517
|
+
return tail;
|
|
518
|
+
const head = calls[0];
|
|
519
|
+
if (head === undefined)
|
|
520
|
+
return '';
|
|
521
|
+
const target = head.argument.length > 0 ? ' ' + head.argument : '';
|
|
522
|
+
const more = calls.length > 1 ? ' +' + String(calls.length - 1) : '';
|
|
523
|
+
return (head.preparing ? head.verb + ' \u2026' + target : head.verb + target) + more;
|
|
524
|
+
}
|
|
525
|
+
function lastLine(text, limit) {
|
|
526
|
+
const trimmed = text.trimEnd();
|
|
527
|
+
const breakAt = trimmed.lastIndexOf('\n');
|
|
528
|
+
return clip(breakAt >= 0 ? trimmed.slice(breakAt + 1) : trimmed, limit);
|
|
529
|
+
}
|
|
530
|
+
//# sourceMappingURL=live.js.map
|
|
531
|
+
Object.assign(exports, { clip: clip, narrateCall: narrateCall, splitPath: splitPath, formatElapsed: formatElapsed, formatRate: formatRate, summarize: summarize, phaseLabel: phaseLabel, TOOL_NARRATION: TOOL_NARRATION, PREPARING_LABEL: PREPARING_LABEL });
|
|
532
|
+
|
|
533
|
+
},
|
|
534
|
+
"./client/style.js": (module, exports, __require) => {
|
|
535
|
+
const STYLE_ELEMENT_ID = 'd0nj-narration-style';
|
|
536
|
+
const TEXT_FAMILY = 'var(--dsw-font-family, inherit)';
|
|
537
|
+
const CODE_FAMILY = 'var(--dsw-font-markdown-code-block-font-family, var(--dsw-font-markdown-code-font-family, var(--dsw-font-family, ui-monospace)))';
|
|
538
|
+
const CODE = 'var(--dsw-font-markdown-code-block, var(--dsw-font-markdown-code))';
|
|
539
|
+
const LINE = 'var(--dsw-alias-border-l1)';
|
|
540
|
+
const DIM = 'var(--dsw-alias-label-secondary)';
|
|
541
|
+
const INK = 'var(--dsw-alias-label-primary)';
|
|
542
|
+
const CSS = `
|
|
543
|
+
.d0nj-narr {
|
|
544
|
+
display: flex;
|
|
545
|
+
flex-direction: column;
|
|
546
|
+
gap: 10px;
|
|
547
|
+
width: 100%;
|
|
548
|
+
min-width: 0;
|
|
549
|
+
font-family: ${TEXT_FAMILY};
|
|
550
|
+
color: ${INK};
|
|
551
|
+
}
|
|
552
|
+
.d0nj-narr-live {
|
|
553
|
+
display: flex;
|
|
554
|
+
align-items: baseline;
|
|
555
|
+
gap: 8px;
|
|
556
|
+
width: 100%;
|
|
557
|
+
margin: 0;
|
|
558
|
+
padding: 0;
|
|
559
|
+
border: 0;
|
|
560
|
+
border-radius: 4px;
|
|
561
|
+
background: transparent;
|
|
562
|
+
font-family: ${TEXT_FAMILY};
|
|
563
|
+
font-size: var(--dsw-font-xxxs-11-font-size, 11px);
|
|
564
|
+
color: ${DIM};
|
|
565
|
+
text-align: left;
|
|
566
|
+
cursor: pointer;
|
|
567
|
+
}
|
|
568
|
+
.d0nj-narr-live:focus-visible {
|
|
569
|
+
outline: 2px solid ${INK};
|
|
570
|
+
outline-offset: 2px;
|
|
571
|
+
}
|
|
572
|
+
.d0nj-narr-dot {
|
|
573
|
+
flex: none;
|
|
574
|
+
align-self: center;
|
|
575
|
+
width: 6px;
|
|
576
|
+
height: 6px;
|
|
577
|
+
border-radius: 50%;
|
|
578
|
+
background: var(--d0nj-narr-phase, var(--dsw-alias-state-idle-primary));
|
|
579
|
+
}
|
|
580
|
+
.d0nj-narr-live[data-working="true"] .d0nj-narr-dot { animation: d0nj-narr-pulse 1.6s ease-in-out infinite; }
|
|
581
|
+
.d0nj-narr-phase {
|
|
582
|
+
flex: none;
|
|
583
|
+
font-family: ${TEXT_FAMILY};
|
|
584
|
+
font-size: var(--dsw-font-xxxs-11-font-size, 11px);
|
|
585
|
+
font-weight: 600;
|
|
586
|
+
letter-spacing: 0.08em;
|
|
587
|
+
text-transform: uppercase;
|
|
588
|
+
}
|
|
589
|
+
.d0nj-narr-metrics {
|
|
590
|
+
flex: none;
|
|
591
|
+
display: flex;
|
|
592
|
+
gap: 10px;
|
|
593
|
+
margin-left: auto;
|
|
594
|
+
font-family: ${CODE_FAMILY};
|
|
595
|
+
font-size: var(--dsw-font-xxxs-11-font-size, 11px);
|
|
596
|
+
font-variant-numeric: tabular-nums;
|
|
597
|
+
color: ${DIM};
|
|
598
|
+
}
|
|
599
|
+
.d0nj-narr-calls {
|
|
600
|
+
display: flex;
|
|
601
|
+
flex-direction: column;
|
|
602
|
+
gap: 2px;
|
|
603
|
+
}
|
|
604
|
+
.d0nj-narr-call {
|
|
605
|
+
display: flex;
|
|
606
|
+
align-items: baseline;
|
|
607
|
+
gap: 8px;
|
|
608
|
+
min-width: 0;
|
|
609
|
+
font-family: ${TEXT_FAMILY};
|
|
610
|
+
font-size: var(--dsw-font-xs-13-font-size, 13px);
|
|
611
|
+
}
|
|
612
|
+
.d0nj-narr-verb {
|
|
613
|
+
flex: none;
|
|
614
|
+
color: ${INK};
|
|
615
|
+
}
|
|
616
|
+
.d0nj-narr-arg {
|
|
617
|
+
flex: 1 1 auto;
|
|
618
|
+
min-width: 0;
|
|
619
|
+
display: flex;
|
|
620
|
+
align-items: baseline;
|
|
621
|
+
overflow: hidden;
|
|
622
|
+
font-family: ${CODE_FAMILY};
|
|
623
|
+
font-size: var(--dsw-font-xxs-12-font-size, 12px);
|
|
624
|
+
color: ${DIM};
|
|
625
|
+
}
|
|
626
|
+
.d0nj-narr-dir {
|
|
627
|
+
flex: 0 1 auto;
|
|
628
|
+
min-width: 0;
|
|
629
|
+
overflow: hidden;
|
|
630
|
+
white-space: nowrap;
|
|
631
|
+
text-overflow: ellipsis;
|
|
632
|
+
direction: rtl;
|
|
633
|
+
text-align: left;
|
|
634
|
+
opacity: 0.7;
|
|
635
|
+
}
|
|
636
|
+
.d0nj-narr-base {
|
|
637
|
+
flex: none;
|
|
638
|
+
white-space: pre;
|
|
639
|
+
color: ${INK};
|
|
640
|
+
}
|
|
641
|
+
.d0nj-narr-caret {
|
|
642
|
+
flex: none;
|
|
643
|
+
width: 5px;
|
|
644
|
+
height: 11px;
|
|
645
|
+
margin-left: 2px;
|
|
646
|
+
background: ${INK};
|
|
647
|
+
animation: d0nj-narr-blink 1s steps(1) infinite;
|
|
648
|
+
}
|
|
649
|
+
.d0nj-narr-call[data-preparing="false"] .d0nj-narr-caret { display: none; }
|
|
650
|
+
.d0nj-narr-spent {
|
|
651
|
+
flex: none;
|
|
652
|
+
font-family: ${CODE_FAMILY};
|
|
653
|
+
font-size: var(--dsw-font-xxxs-11-font-size, 11px);
|
|
654
|
+
font-variant-numeric: tabular-nums;
|
|
655
|
+
color: ${DIM};
|
|
656
|
+
}
|
|
657
|
+
.d0nj-narr-think {
|
|
658
|
+
display: flex;
|
|
659
|
+
flex-direction: column;
|
|
660
|
+
gap: 6px;
|
|
661
|
+
padding-left: 12px;
|
|
662
|
+
border-left: 1px solid ${LINE};
|
|
663
|
+
}
|
|
664
|
+
.d0nj-narr-think-head {
|
|
665
|
+
display: flex;
|
|
666
|
+
align-items: center;
|
|
667
|
+
align-self: flex-start;
|
|
668
|
+
margin: 0;
|
|
669
|
+
padding: 0;
|
|
670
|
+
border: 0;
|
|
671
|
+
background: transparent;
|
|
672
|
+
color: ${DIM};
|
|
673
|
+
font-family: ${TEXT_FAMILY};
|
|
674
|
+
font-size: var(--dsw-font-xxs-12-font-size, 12px);
|
|
675
|
+
cursor: pointer;
|
|
676
|
+
}
|
|
677
|
+
.d0nj-narr-think-head:hover { color: ${INK}; }
|
|
678
|
+
.d0nj-narr-think-head:focus-visible {
|
|
679
|
+
outline: 2px solid ${INK};
|
|
680
|
+
outline-offset: 2px;
|
|
681
|
+
}
|
|
682
|
+
.d0nj-narr-think-body {
|
|
683
|
+
margin: 0;
|
|
684
|
+
max-height: none;
|
|
685
|
+
overflow: visible;
|
|
686
|
+
white-space: pre-wrap;
|
|
687
|
+
overflow-wrap: anywhere;
|
|
688
|
+
font-family: ${TEXT_FAMILY};
|
|
689
|
+
font-size: var(--dsw-font-xs-13-font-size, 13px);
|
|
690
|
+
line-height: 1.7;
|
|
691
|
+
color: ${DIM};
|
|
692
|
+
}
|
|
693
|
+
.d0nj-narr-answer {
|
|
694
|
+
min-width: 0;
|
|
695
|
+
}
|
|
696
|
+
.d0nj-narr-plain {
|
|
697
|
+
white-space: pre-wrap;
|
|
698
|
+
overflow-wrap: anywhere;
|
|
699
|
+
font-family: ${TEXT_FAMILY};
|
|
700
|
+
font-size: var(--dsw-font-s-14-font-size, 14px);
|
|
701
|
+
line-height: 1.65;
|
|
702
|
+
}
|
|
703
|
+
.d0nj-tool {
|
|
704
|
+
display: flex;
|
|
705
|
+
flex-direction: column;
|
|
706
|
+
width: 100%;
|
|
707
|
+
min-width: 0;
|
|
708
|
+
border: 1px solid ${LINE};
|
|
709
|
+
border-radius: var(--dsw-radius-m, 8px);
|
|
710
|
+
background: var(--dsw-alias-bg-layer-1);
|
|
711
|
+
overflow: hidden;
|
|
712
|
+
font-family: ${TEXT_FAMILY};
|
|
713
|
+
color: ${INK};
|
|
714
|
+
}
|
|
715
|
+
.d0nj-tool > * + * { border-top: 1px solid ${LINE}; }
|
|
716
|
+
.d0nj-tool-head {
|
|
717
|
+
display: flex;
|
|
718
|
+
align-items: baseline;
|
|
719
|
+
gap: 8px;
|
|
720
|
+
min-width: 0;
|
|
721
|
+
padding: 7px 12px;
|
|
722
|
+
font-size: var(--dsw-font-xs-13-font-size, 13px);
|
|
723
|
+
}
|
|
724
|
+
.d0nj-tool-icon {
|
|
725
|
+
flex: none;
|
|
726
|
+
align-self: center;
|
|
727
|
+
width: 1em;
|
|
728
|
+
font-size: 10px;
|
|
729
|
+
line-height: 1;
|
|
730
|
+
text-align: center;
|
|
731
|
+
color: ${DIM};
|
|
732
|
+
}
|
|
733
|
+
.d0nj-tool-icon[data-state="start"] { color: ${INK}; }
|
|
734
|
+
.d0nj-tool-icon[data-state="done"] { color: var(--dsw-alias-state-success-primary); }
|
|
735
|
+
.d0nj-tool-icon[data-state="failed"] { color: var(--dsw-alias-state-error-primary); }
|
|
736
|
+
.d0nj-tool-verb { flex: none; color: ${INK}; }
|
|
737
|
+
.d0nj-tool-target {
|
|
738
|
+
flex: 1 1 auto;
|
|
739
|
+
min-width: 0;
|
|
740
|
+
overflow: hidden;
|
|
741
|
+
text-overflow: ellipsis;
|
|
742
|
+
white-space: nowrap;
|
|
743
|
+
font-family: ${CODE_FAMILY};
|
|
744
|
+
font-size: var(--dsw-font-xxs-12-font-size, 12px);
|
|
745
|
+
color: ${DIM};
|
|
746
|
+
}
|
|
747
|
+
.d0nj-tool-state {
|
|
748
|
+
flex: none;
|
|
749
|
+
font-family: ${CODE_FAMILY};
|
|
750
|
+
font-size: var(--dsw-font-xxxs-11-font-size, 11px);
|
|
751
|
+
font-variant-numeric: tabular-nums;
|
|
752
|
+
color: ${DIM};
|
|
753
|
+
}
|
|
754
|
+
.d0nj-tool[data-error="true"] .d0nj-tool-state { color: var(--dsw-alias-state-error-primary); }
|
|
755
|
+
.d0nj-tool-meta {
|
|
756
|
+
padding: 6px 12px;
|
|
757
|
+
overflow: hidden;
|
|
758
|
+
white-space: nowrap;
|
|
759
|
+
text-overflow: ellipsis;
|
|
760
|
+
font-family: ${CODE_FAMILY};
|
|
761
|
+
font-size: var(--dsw-font-xxs-12-font-size, 12px);
|
|
762
|
+
color: ${DIM};
|
|
763
|
+
}
|
|
764
|
+
.d0nj-tool-args {
|
|
765
|
+
margin: 0;
|
|
766
|
+
padding: 8px 12px;
|
|
767
|
+
overflow-x: auto;
|
|
768
|
+
white-space: pre-wrap;
|
|
769
|
+
overflow-wrap: anywhere;
|
|
770
|
+
font: ${CODE};
|
|
771
|
+
color: ${DIM};
|
|
772
|
+
}
|
|
773
|
+
.d0nj-tool-command {
|
|
774
|
+
margin: 0;
|
|
775
|
+
padding: 8px 12px;
|
|
776
|
+
overflow-x: auto;
|
|
777
|
+
white-space: pre-wrap;
|
|
778
|
+
overflow-wrap: anywhere;
|
|
779
|
+
font: ${CODE};
|
|
780
|
+
color: ${INK};
|
|
781
|
+
}
|
|
782
|
+
.d0nj-tool-prompt {
|
|
783
|
+
color: ${DIM};
|
|
784
|
+
user-select: none;
|
|
785
|
+
}
|
|
786
|
+
.d0nj-tool-output {
|
|
787
|
+
margin: 0;
|
|
788
|
+
padding: 8px 12px;
|
|
789
|
+
max-height: 60vh;
|
|
790
|
+
overflow: auto;
|
|
791
|
+
white-space: pre-wrap;
|
|
792
|
+
overflow-wrap: anywhere;
|
|
793
|
+
font: ${CODE};
|
|
794
|
+
line-height: 1.5;
|
|
795
|
+
color: ${DIM};
|
|
796
|
+
}
|
|
797
|
+
.d0nj-tool[data-error="true"] .d0nj-tool-output { color: var(--dsw-alias-state-error-primary); }
|
|
798
|
+
.d0nj-term[data-tone="error"] { color: var(--dsw-alias-state-error-primary); }
|
|
799
|
+
.d0nj-term[data-tone="success"] { color: var(--dsw-alias-state-success-primary); }
|
|
800
|
+
.d0nj-term[data-tone="warn"] { color: var(--dsw-alias-state-warn-primary); }
|
|
801
|
+
.d0nj-term[data-bold="true"] { font-weight: 600; }
|
|
802
|
+
.d0nj-term[data-dim="true"] { opacity: 0.65; }
|
|
803
|
+
.d0nj-term[data-underline="true"] { text-decoration: underline; }
|
|
804
|
+
.d0nj-tool-output:empty, .d0nj-tool-args:empty { display: none; }
|
|
805
|
+
.d0nj-tool-sub {
|
|
806
|
+
display: flex;
|
|
807
|
+
flex-direction: column;
|
|
808
|
+
gap: 8px;
|
|
809
|
+
padding: 8px 12px;
|
|
810
|
+
}
|
|
811
|
+
.d0nj-tool-stat {
|
|
812
|
+
flex: none;
|
|
813
|
+
margin-left: 8px;
|
|
814
|
+
font-family: ${CODE_FAMILY};
|
|
815
|
+
font-size: var(--dsw-font-xxs-12-font-size, 12px);
|
|
816
|
+
font-variant-numeric: tabular-nums;
|
|
817
|
+
color: ${DIM};
|
|
818
|
+
}
|
|
819
|
+
.d0nj-diff {
|
|
820
|
+
margin: 0;
|
|
821
|
+
padding: 6px 0;
|
|
822
|
+
max-height: 60vh;
|
|
823
|
+
overflow: auto;
|
|
824
|
+
font: ${CODE};
|
|
825
|
+
line-height: 1.55;
|
|
826
|
+
}
|
|
827
|
+
.d0nj-diff-line {
|
|
828
|
+
display: flex;
|
|
829
|
+
align-items: baseline;
|
|
830
|
+
padding: 0 10px;
|
|
831
|
+
white-space: pre;
|
|
832
|
+
color: ${INK};
|
|
833
|
+
}
|
|
834
|
+
.d0nj-diff-line[data-kind="hunk"] {
|
|
835
|
+
display: block;
|
|
836
|
+
padding: 2px 10px;
|
|
837
|
+
color: ${DIM};
|
|
838
|
+
opacity: 0.75;
|
|
839
|
+
}
|
|
840
|
+
.d0nj-diff-line[data-kind="add"] {
|
|
841
|
+
color: var(--dsw-alias-state-success-primary);
|
|
842
|
+
background: color-mix(in oklab, var(--dsw-alias-state-success-primary) 14%, transparent);
|
|
843
|
+
}
|
|
844
|
+
.d0nj-diff-line[data-kind="remove"] {
|
|
845
|
+
color: var(--dsw-alias-state-error-primary);
|
|
846
|
+
background: color-mix(in oklab, var(--dsw-alias-state-error-primary) 14%, transparent);
|
|
847
|
+
}
|
|
848
|
+
.d0nj-diff-sign {
|
|
849
|
+
flex: none;
|
|
850
|
+
width: 1ch;
|
|
851
|
+
}
|
|
852
|
+
.d0nj-diff-no {
|
|
853
|
+
flex: none;
|
|
854
|
+
padding: 0 6px 0 2px;
|
|
855
|
+
text-align: right;
|
|
856
|
+
font-variant-numeric: tabular-nums;
|
|
857
|
+
opacity: 0.5;
|
|
858
|
+
}
|
|
859
|
+
.d0nj-diff-bar {
|
|
860
|
+
flex: none;
|
|
861
|
+
margin-right: 8px;
|
|
862
|
+
opacity: 0.25;
|
|
863
|
+
}
|
|
864
|
+
.d0nj-diff-text {
|
|
865
|
+
flex: 1 1 auto;
|
|
866
|
+
white-space: pre;
|
|
867
|
+
}
|
|
868
|
+
.d0nj-tool-out-wrap {
|
|
869
|
+
display: flex;
|
|
870
|
+
flex-direction: column;
|
|
871
|
+
}
|
|
872
|
+
.d0nj-tool-more {
|
|
873
|
+
align-self: flex-start;
|
|
874
|
+
margin: 8px 12px 0;
|
|
875
|
+
padding: 0;
|
|
876
|
+
border: 0;
|
|
877
|
+
background: transparent;
|
|
878
|
+
font-family: ${CODE_FAMILY};
|
|
879
|
+
font-size: var(--dsw-font-xxxs-11-font-size, 11px);
|
|
880
|
+
color: ${DIM};
|
|
881
|
+
cursor: pointer;
|
|
882
|
+
}
|
|
883
|
+
.d0nj-tool-more:hover { color: ${INK}; }
|
|
884
|
+
.d0nj-tool-more:focus-visible {
|
|
885
|
+
outline: 2px solid ${INK};
|
|
886
|
+
outline-offset: 2px;
|
|
887
|
+
}
|
|
888
|
+
@keyframes d0nj-narr-pulse {
|
|
889
|
+
0%, 100% { opacity: 1; }
|
|
890
|
+
50% { opacity: 0.3; }
|
|
891
|
+
}
|
|
892
|
+
@keyframes d0nj-narr-blink {
|
|
893
|
+
0%, 49% { opacity: 1; }
|
|
894
|
+
50%, 100% { opacity: 0; }
|
|
895
|
+
}
|
|
896
|
+
@media (prefers-reduced-motion: reduce) {
|
|
897
|
+
.d0nj-narr-dot, .d0nj-narr-caret { animation: none; }
|
|
898
|
+
}
|
|
899
|
+
`;
|
|
900
|
+
const PHASE_COLOUR = {
|
|
901
|
+
idle: 'var(--dsw-alias-state-idle-primary)',
|
|
902
|
+
thinking: 'var(--dsw-alias-label-secondary)',
|
|
903
|
+
writing: 'var(--dsw-alias-label-primary)',
|
|
904
|
+
calling: 'var(--dsw-alias-label-primary)',
|
|
905
|
+
holding: 'var(--dsw-alias-state-warn-primary)',
|
|
906
|
+
};
|
|
907
|
+
//# sourceMappingURL=style.js.map
|
|
908
|
+
Object.assign(exports, { STYLE_ELEMENT_ID: STYLE_ELEMENT_ID, CSS: CSS, PHASE_COLOUR: PHASE_COLOUR });
|
|
909
|
+
|
|
910
|
+
},
|
|
911
|
+
"./client/tool.js": (module, exports, __require) => {
|
|
912
|
+
const { compactOutput, normalizeTerminalText, parseAnsi } = __require('./ansi.js');
|
|
913
|
+
const { stripEnvelope, splitReadRange } = __require('./envelope.js');
|
|
914
|
+
const { diffLines, diffRows, diffSummary } = __require('./diff.js');
|
|
915
|
+
const { TOOL_NARRATION, clip, formatElapsed, narrateCall, splitPath } = __require('./live.js');
|
|
916
|
+
const PREVIEW_LINES = 12;
|
|
917
|
+
function followProps(options) {
|
|
918
|
+
if (options === undefined)
|
|
919
|
+
return {};
|
|
920
|
+
const pin = options.pin;
|
|
921
|
+
return {
|
|
922
|
+
ref: (element) => {
|
|
923
|
+
if (element !== null && pin.current)
|
|
924
|
+
element.scrollTop = element.scrollHeight;
|
|
925
|
+
},
|
|
926
|
+
onScroll: (event) => {
|
|
927
|
+
const element = event.currentTarget;
|
|
928
|
+
pin.current = element.scrollHeight - element.scrollTop - element.clientHeight < 12;
|
|
929
|
+
},
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
function asBlock(value) {
|
|
933
|
+
return value !== null && typeof value === 'object' ? value : undefined;
|
|
934
|
+
}
|
|
935
|
+
function text(value) {
|
|
936
|
+
return typeof value === 'string' ? value : '';
|
|
937
|
+
}
|
|
938
|
+
function maybeText(value) {
|
|
939
|
+
return typeof value === 'string' ? value : undefined;
|
|
940
|
+
}
|
|
941
|
+
function list(value) {
|
|
942
|
+
return Array.isArray(value) ? value : [];
|
|
943
|
+
}
|
|
944
|
+
function toolRoot(node) {
|
|
945
|
+
const data = asBlock(asBlock(node)?.data);
|
|
946
|
+
return asBlock(data?.root);
|
|
947
|
+
}
|
|
948
|
+
function toolName(block) {
|
|
949
|
+
return text(asBlock(block)?.name);
|
|
950
|
+
}
|
|
951
|
+
function toolPhase(block) {
|
|
952
|
+
const entry = asBlock(block);
|
|
953
|
+
if (entry === undefined || entry.kind !== undefined)
|
|
954
|
+
return 'result';
|
|
955
|
+
return entry.phase === 'preparing' ? 'preparing' : 'start';
|
|
956
|
+
}
|
|
957
|
+
function argsReader(source) {
|
|
958
|
+
const args = asBlock(source);
|
|
959
|
+
const read = args?.text;
|
|
960
|
+
if (typeof read !== 'function')
|
|
961
|
+
return { text: () => undefined };
|
|
962
|
+
return {
|
|
963
|
+
text: (key) => {
|
|
964
|
+
try {
|
|
965
|
+
const value = read.call(args, key);
|
|
966
|
+
return typeof value === 'string' ? value : undefined;
|
|
967
|
+
}
|
|
968
|
+
catch {
|
|
969
|
+
return undefined;
|
|
970
|
+
}
|
|
971
|
+
},
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
function rawArgs(block) {
|
|
975
|
+
const call = asBlock(block.call);
|
|
976
|
+
const fromCall = text(call?.argsRaw);
|
|
977
|
+
return fromCall.length > 0 ? fromCall : text(block.argsRaw);
|
|
978
|
+
}
|
|
979
|
+
function parsedArgs(block) {
|
|
980
|
+
const entry = asBlock(block);
|
|
981
|
+
if (entry === undefined)
|
|
982
|
+
return undefined;
|
|
983
|
+
const raw = rawArgs(entry);
|
|
984
|
+
if (raw.length > 0) {
|
|
985
|
+
try {
|
|
986
|
+
return asBlock(JSON.parse(raw));
|
|
987
|
+
}
|
|
988
|
+
catch {
|
|
989
|
+
return undefined;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
const args = entry.args;
|
|
993
|
+
const keys = asBlock(args)?.keys;
|
|
994
|
+
const names = typeof keys === 'function' ? keys.call(args) : [];
|
|
995
|
+
const reader = argsReader(args);
|
|
996
|
+
const out = {};
|
|
997
|
+
let found = false;
|
|
998
|
+
for (const key of list(names)) {
|
|
999
|
+
if (typeof key !== 'string')
|
|
1000
|
+
continue;
|
|
1001
|
+
const value = reader.text(key);
|
|
1002
|
+
if (value === undefined)
|
|
1003
|
+
continue;
|
|
1004
|
+
out[key] = value;
|
|
1005
|
+
found = true;
|
|
1006
|
+
}
|
|
1007
|
+
return found ? out : undefined;
|
|
1008
|
+
}
|
|
1009
|
+
function liveCallOf(block) {
|
|
1010
|
+
const entry = asBlock(block);
|
|
1011
|
+
if (entry === undefined)
|
|
1012
|
+
return undefined;
|
|
1013
|
+
const callId = text(entry.callId);
|
|
1014
|
+
const name = text(entry.name);
|
|
1015
|
+
if (callId.length === 0 || name.length === 0)
|
|
1016
|
+
return undefined;
|
|
1017
|
+
return {
|
|
1018
|
+
callId,
|
|
1019
|
+
name,
|
|
1020
|
+
phase: toolPhase(entry) === 'preparing' ? 'preparing' : 'start',
|
|
1021
|
+
time: typeof entry.time === 'number' ? entry.time : 0,
|
|
1022
|
+
args: argsReader(entry.args),
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
function fileDiffOf(name, args) {
|
|
1026
|
+
if (args === undefined)
|
|
1027
|
+
return undefined;
|
|
1028
|
+
const path = maybeText(args.file_path) ?? maybeText(args.path) ?? '';
|
|
1029
|
+
if (name === 'edit') {
|
|
1030
|
+
const before = maybeText(args.old_string);
|
|
1031
|
+
const after = maybeText(args.new_string);
|
|
1032
|
+
if (before === undefined || after === undefined)
|
|
1033
|
+
return undefined;
|
|
1034
|
+
return { path, before, after };
|
|
1035
|
+
}
|
|
1036
|
+
if (name === 'write') {
|
|
1037
|
+
const after = maybeText(args.content);
|
|
1038
|
+
if (after === undefined)
|
|
1039
|
+
return undefined;
|
|
1040
|
+
return { path, before: '', after };
|
|
1041
|
+
}
|
|
1042
|
+
return undefined;
|
|
1043
|
+
}
|
|
1044
|
+
function patchTextOf(name, args) {
|
|
1045
|
+
if (name !== 'apply_patch' || args === undefined)
|
|
1046
|
+
return undefined;
|
|
1047
|
+
return maybeText(args.patch) ?? maybeText(args.input) ?? maybeText(args.diff);
|
|
1048
|
+
}
|
|
1049
|
+
function commandOf(name, args) {
|
|
1050
|
+
if ((name !== 'bash' && name !== 'pwsh') || args === undefined)
|
|
1051
|
+
return undefined;
|
|
1052
|
+
return maybeText(args.command);
|
|
1053
|
+
}
|
|
1054
|
+
function prettyJson(raw) {
|
|
1055
|
+
if (raw.length === 0)
|
|
1056
|
+
return '';
|
|
1057
|
+
try {
|
|
1058
|
+
return JSON.stringify(JSON.parse(raw), null, 2);
|
|
1059
|
+
}
|
|
1060
|
+
catch {
|
|
1061
|
+
return raw;
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
function toolArgsText(block) {
|
|
1065
|
+
const entry = asBlock(block);
|
|
1066
|
+
if (entry === undefined)
|
|
1067
|
+
return '';
|
|
1068
|
+
const raw = rawArgs(entry);
|
|
1069
|
+
if (raw.length > 0)
|
|
1070
|
+
return prettyJson(raw);
|
|
1071
|
+
const args = entry.args;
|
|
1072
|
+
const keys = asBlock(args)?.keys;
|
|
1073
|
+
const names = typeof keys === 'function' ? keys.call(args) : [];
|
|
1074
|
+
const reader = argsReader(args);
|
|
1075
|
+
const lines = [];
|
|
1076
|
+
for (const key of list(names)) {
|
|
1077
|
+
if (typeof key !== 'string')
|
|
1078
|
+
continue;
|
|
1079
|
+
const value = reader.text(key);
|
|
1080
|
+
if (value === undefined || value.length === 0)
|
|
1081
|
+
continue;
|
|
1082
|
+
lines.push(key + ': ' + value);
|
|
1083
|
+
}
|
|
1084
|
+
return lines.join('\n');
|
|
1085
|
+
}
|
|
1086
|
+
function toolOutputText(block) {
|
|
1087
|
+
const entry = asBlock(block);
|
|
1088
|
+
if (entry === undefined)
|
|
1089
|
+
return { output: '', isError: false };
|
|
1090
|
+
let output = '';
|
|
1091
|
+
for (const part of list(entry.content)) {
|
|
1092
|
+
const item = asBlock(part);
|
|
1093
|
+
if (item === undefined || item.type !== 'text')
|
|
1094
|
+
continue;
|
|
1095
|
+
output += text(item.text);
|
|
1096
|
+
}
|
|
1097
|
+
const isError = entry.isError === true;
|
|
1098
|
+
const error = asBlock(entry.error);
|
|
1099
|
+
const reason = text(error?.reason).length > 0 ? text(error?.reason) : text(error?.code);
|
|
1100
|
+
if (isError && reason.length > 0 && !output.includes(reason)) {
|
|
1101
|
+
output = output.length > 0 ? output + '\n' + reason : reason;
|
|
1102
|
+
}
|
|
1103
|
+
return { output: output.trimEnd(), isError };
|
|
1104
|
+
}
|
|
1105
|
+
function tailPreview(source, limit = PREVIEW_LINES) {
|
|
1106
|
+
if (source.length === 0)
|
|
1107
|
+
return { shown: '', hidden: 0 };
|
|
1108
|
+
const lines = source.split('\n');
|
|
1109
|
+
if (lines.length <= limit)
|
|
1110
|
+
return { shown: source, hidden: 0 };
|
|
1111
|
+
return { shown: lines.slice(lines.length - limit).join('\n'), hidden: lines.length - limit };
|
|
1112
|
+
}
|
|
1113
|
+
const HEADER_KEYS = new Set([
|
|
1114
|
+
'command', 'content', 'description', 'diff', 'file_path', 'input', 'name',
|
|
1115
|
+
'new_string', 'old_string', 'patch', 'path', 'pattern', 'prompt', 'query', 'url',
|
|
1116
|
+
]);
|
|
1117
|
+
function describeValue(value) {
|
|
1118
|
+
if (typeof value === 'string')
|
|
1119
|
+
return clip(value, 48);
|
|
1120
|
+
if (typeof value === 'number' || typeof value === 'boolean')
|
|
1121
|
+
return String(value);
|
|
1122
|
+
if (Array.isArray(value))
|
|
1123
|
+
return String(value.length) + ' items';
|
|
1124
|
+
if (value === null || value === undefined)
|
|
1125
|
+
return '';
|
|
1126
|
+
return clip(JSON.stringify(value), 48);
|
|
1127
|
+
}
|
|
1128
|
+
function argsSummary(args, limit = 6) {
|
|
1129
|
+
if (args === undefined)
|
|
1130
|
+
return '';
|
|
1131
|
+
const parts = [];
|
|
1132
|
+
for (const [key, value] of Object.entries(args)) {
|
|
1133
|
+
if (HEADER_KEYS.has(key))
|
|
1134
|
+
continue;
|
|
1135
|
+
const described = describeValue(value);
|
|
1136
|
+
if (described.length === 0)
|
|
1137
|
+
continue;
|
|
1138
|
+
parts.push(key + ' ' + described);
|
|
1139
|
+
if (parts.length >= limit)
|
|
1140
|
+
break;
|
|
1141
|
+
}
|
|
1142
|
+
return parts.join(' \u00b7 ');
|
|
1143
|
+
}
|
|
1144
|
+
function toolDuration(block, now) {
|
|
1145
|
+
const entry = asBlock(block);
|
|
1146
|
+
if (entry === undefined)
|
|
1147
|
+
return 0;
|
|
1148
|
+
const finished = typeof entry.time === 'number' ? entry.time : 0;
|
|
1149
|
+
const started = typeof entry.callTime === 'number' ? entry.callTime : 0;
|
|
1150
|
+
if (toolPhase(entry) === 'result')
|
|
1151
|
+
return started > 0 && finished > started ? finished - started : 0;
|
|
1152
|
+
return started > 0 ? Math.max(0, now - started) : 0;
|
|
1153
|
+
}
|
|
1154
|
+
const STATE_LABEL = {
|
|
1155
|
+
preparing: 'preparing',
|
|
1156
|
+
start: 'running',
|
|
1157
|
+
result: 'done',
|
|
1158
|
+
};
|
|
1159
|
+
function renderDiffCard(React, before, after, options) {
|
|
1160
|
+
const h = React.createElement;
|
|
1161
|
+
const lines = diffLines(before, after);
|
|
1162
|
+
const summary = diffSummary(lines);
|
|
1163
|
+
const { rows } = diffRows(lines);
|
|
1164
|
+
return h('pre', {
|
|
1165
|
+
className: 'd0nj-diff',
|
|
1166
|
+
'data-added': String(summary.added),
|
|
1167
|
+
'data-removed': String(summary.removed),
|
|
1168
|
+
...followProps(options),
|
|
1169
|
+
}, rows.map((row, index) => h('span', { key: String(index), className: 'd0nj-diff-line', 'data-kind': row.kind }, row.kind === 'hunk'
|
|
1170
|
+
? row.text
|
|
1171
|
+
: [
|
|
1172
|
+
h('span', { key: 's', className: 'd0nj-diff-sign' }, row.sign),
|
|
1173
|
+
h('span', { key: 'n', className: 'd0nj-diff-no' }, row.number.padStart(row.digits)),
|
|
1174
|
+
h('span', { key: 'b', className: 'd0nj-diff-bar' }, '\u2502'),
|
|
1175
|
+
h('span', { key: 't', className: 'd0nj-diff-text' }, row.text),
|
|
1176
|
+
])));
|
|
1177
|
+
}
|
|
1178
|
+
function renderPatchCard(React, patch, options) {
|
|
1179
|
+
const h = React.createElement;
|
|
1180
|
+
return h('pre', { className: 'd0nj-diff', ...followProps(options) }, patch.split('\n').map((line, index) => h('span', {
|
|
1181
|
+
key: String(index),
|
|
1182
|
+
className: 'd0nj-diff-line',
|
|
1183
|
+
'data-kind': line.startsWith('+') ? 'add' : line.startsWith('-') ? 'remove' : 'equal',
|
|
1184
|
+
}, line)));
|
|
1185
|
+
}
|
|
1186
|
+
function renderTerminal(React, text) {
|
|
1187
|
+
const h = React.createElement;
|
|
1188
|
+
return parseAnsi(text).map((span, index) => h('span', {
|
|
1189
|
+
key: String(index),
|
|
1190
|
+
className: 'd0nj-term',
|
|
1191
|
+
'data-tone': span.tone,
|
|
1192
|
+
'data-bold': span.bold ? 'true' : undefined,
|
|
1193
|
+
'data-dim': span.dim ? 'true' : undefined,
|
|
1194
|
+
'data-underline': span.underline ? 'true' : undefined,
|
|
1195
|
+
}, span.text));
|
|
1196
|
+
}
|
|
1197
|
+
function renderOutput(React, output, options) {
|
|
1198
|
+
const h = React.createElement;
|
|
1199
|
+
if (output.length === 0)
|
|
1200
|
+
return null;
|
|
1201
|
+
const follow = followProps(options);
|
|
1202
|
+
const preview = tailPreview(output, PREVIEW_LINES);
|
|
1203
|
+
if (options === undefined || preview.hidden === 0) {
|
|
1204
|
+
return h('pre', { className: 'd0nj-tool-output', ...follow }, renderTerminal(React, output));
|
|
1205
|
+
}
|
|
1206
|
+
return h('div', { className: 'd0nj-tool-out-wrap' }, h('button', {
|
|
1207
|
+
type: 'button',
|
|
1208
|
+
className: 'd0nj-tool-more',
|
|
1209
|
+
'aria-expanded': options.expanded,
|
|
1210
|
+
onClick: options.onToggle,
|
|
1211
|
+
}, options.expanded ? 'collapse' : '\u2026 ' + String(preview.hidden) + ' earlier lines'), h('pre', { className: 'd0nj-tool-output', ...follow }, renderTerminal(React, options.expanded ? output : preview.shown)));
|
|
1212
|
+
}
|
|
1213
|
+
function cleanOutput(output) {
|
|
1214
|
+
const cleaned = compactOutput(normalizeTerminalText(stripEnvelope(output)));
|
|
1215
|
+
const split = splitReadRange(cleaned);
|
|
1216
|
+
return { body: split.text, range: split.range };
|
|
1217
|
+
}
|
|
1218
|
+
function renderBlock(React, block, now, depth, options) {
|
|
1219
|
+
const h = React.createElement;
|
|
1220
|
+
const entry = asBlock(block);
|
|
1221
|
+
if (entry === undefined || depth > 4)
|
|
1222
|
+
return null;
|
|
1223
|
+
const phase = toolPhase(entry);
|
|
1224
|
+
const name = toolName(entry);
|
|
1225
|
+
const call = liveCallOf(entry);
|
|
1226
|
+
const narration = call === undefined ? undefined : narrateCall(call, 240);
|
|
1227
|
+
const args = parsedArgs(entry);
|
|
1228
|
+
const { output, isError } = toolOutputText(entry);
|
|
1229
|
+
const spent = toolDuration(entry, now);
|
|
1230
|
+
const state = phase === 'result' ? (isError ? 'failed' : 'done') : STATE_LABEL[phase] ?? '';
|
|
1231
|
+
const stateKey = isError ? 'failed' : phase === 'result' ? 'done' : phase;
|
|
1232
|
+
const glyph = stateKey === 'failed'
|
|
1233
|
+
? '\u2715'
|
|
1234
|
+
: stateKey === 'done'
|
|
1235
|
+
? '\u2713'
|
|
1236
|
+
: stateKey === 'start'
|
|
1237
|
+
? '\u25d0'
|
|
1238
|
+
: '\u25cb';
|
|
1239
|
+
const subCalls = list(entry.subCalls);
|
|
1240
|
+
const editView = fileDiffOf(name, args);
|
|
1241
|
+
const patch = patchTextOf(name, args);
|
|
1242
|
+
const hasFileView = editView !== undefined || patch !== undefined;
|
|
1243
|
+
const command = commandOf(name, args);
|
|
1244
|
+
const parts = splitPath(command === undefined ? narration?.argument ?? '' : '');
|
|
1245
|
+
const known = TOOL_NARRATION[name] !== undefined;
|
|
1246
|
+
const extras = known ? argsSummary(args) : '';
|
|
1247
|
+
const argsText = known ? '' : toolArgsText(entry);
|
|
1248
|
+
const cleaned = cleanOutput(output);
|
|
1249
|
+
const meta = [extras, cleaned.range ?? ''].filter((part) => part.length > 0).join(' \u00b7 ');
|
|
1250
|
+
const showOutput = cleaned.body.length > 0 && (!hasFileView || isError);
|
|
1251
|
+
const stat = editView === undefined
|
|
1252
|
+
? ''
|
|
1253
|
+
: (() => {
|
|
1254
|
+
const summary = diffSummary(diffLines(editView.before, editView.after));
|
|
1255
|
+
return '+' + String(summary.added) + ' \u2212' + String(summary.removed);
|
|
1256
|
+
})();
|
|
1257
|
+
const body = editView !== undefined
|
|
1258
|
+
? renderDiffCard(React, editView.before, editView.after, options)
|
|
1259
|
+
: patch !== undefined
|
|
1260
|
+
? renderPatchCard(React, patch, options)
|
|
1261
|
+
: command !== undefined
|
|
1262
|
+
? h('pre', { className: 'd0nj-tool-command' }, h('span', { className: 'd0nj-tool-prompt' }, '\u276f '), renderTerminal(React, command))
|
|
1263
|
+
: meta.length > 0
|
|
1264
|
+
? h('div', { className: 'd0nj-tool-meta' }, meta)
|
|
1265
|
+
: argsText.length > 0
|
|
1266
|
+
? h('pre', { className: 'd0nj-tool-args' }, argsText)
|
|
1267
|
+
: null;
|
|
1268
|
+
return h('div', { className: 'd0nj-tool', 'data-error': String(isError) }, h('div', { className: 'd0nj-tool-head' }, h('span', { className: 'd0nj-tool-icon', 'data-state': stateKey }, glyph), h('span', { className: 'd0nj-tool-verb' }, narration?.verb ?? (name || 'Tool')), h('span', { className: 'd0nj-tool-target' }, parts.directory.length > 0 ? h('span', { className: 'd0nj-narr-dir' }, parts.directory) : null, h('span', { className: 'd0nj-narr-base' }, parts.base)), stat.length > 0 ? h('span', { className: 'd0nj-tool-stat' }, stat) : null, h('span', { className: 'd0nj-tool-state' }, spent > 0 ? formatElapsed(spent) + ' \u00b7 ' + state : state)), body, showOutput ? renderOutput(React, cleaned.body, options) : null, subCalls.length > 0
|
|
1269
|
+
? h('div', { className: 'd0nj-tool-sub' }, subCalls.map((sub) => renderBlock(React, sub, now, depth + 1, undefined) ?? null))
|
|
1270
|
+
: null);
|
|
1271
|
+
}
|
|
1272
|
+
function createToolNarration(React) {
|
|
1273
|
+
return function ToolNarration(props) {
|
|
1274
|
+
const [now, setNow] = React.useState(() => Date.now());
|
|
1275
|
+
const [expanded, setExpanded] = React.useState(false);
|
|
1276
|
+
const pin = React.useRef(true);
|
|
1277
|
+
const root = toolRoot(props.node);
|
|
1278
|
+
const phase = toolPhase(root);
|
|
1279
|
+
React.useEffect(() => {
|
|
1280
|
+
if (phase === 'result')
|
|
1281
|
+
return;
|
|
1282
|
+
const tick = setInterval(() => setNow(Date.now()), 200);
|
|
1283
|
+
return () => clearInterval(tick);
|
|
1284
|
+
}, [phase]);
|
|
1285
|
+
return renderBlock(React, root, now, 0, {
|
|
1286
|
+
expanded,
|
|
1287
|
+
pin,
|
|
1288
|
+
onToggle: () => {
|
|
1289
|
+
pin.current = true;
|
|
1290
|
+
setExpanded((previous) => !previous);
|
|
1291
|
+
},
|
|
1292
|
+
});
|
|
1293
|
+
};
|
|
1294
|
+
}
|
|
1295
|
+
//# sourceMappingURL=tool.js.map
|
|
1296
|
+
Object.assign(exports, { toolRoot: toolRoot, toolName: toolName, toolPhase: toolPhase, parsedArgs: parsedArgs, liveCallOf: liveCallOf, fileDiffOf: fileDiffOf, patchTextOf: patchTextOf, commandOf: commandOf, toolArgsText: toolArgsText, toolOutputText: toolOutputText, tailPreview: tailPreview, argsSummary: argsSummary, toolDuration: toolDuration, cleanOutput: cleanOutput, createToolNarration: createToolNarration });
|
|
1297
|
+
|
|
1298
|
+
},
|
|
1299
|
+
"./ansi.js": (module, exports, __require) => {
|
|
1300
|
+
const INITIAL = { tone: 'default', bold: false, dim: false, underline: false };
|
|
1301
|
+
const OSC = /\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)/gu;
|
|
1302
|
+
const CSI = /\u001b\[([0-9;?]*)([A-Za-z])/gu;
|
|
1303
|
+
function toneOf(code) {
|
|
1304
|
+
if (code === 31 || code === 91)
|
|
1305
|
+
return 'error';
|
|
1306
|
+
if (code === 32 || code === 92)
|
|
1307
|
+
return 'success';
|
|
1308
|
+
if (code === 33 || code === 93)
|
|
1309
|
+
return 'warn';
|
|
1310
|
+
if (code === 39 || code === 99)
|
|
1311
|
+
return 'default';
|
|
1312
|
+
return undefined;
|
|
1313
|
+
}
|
|
1314
|
+
function applySgr(state, parameters) {
|
|
1315
|
+
let next = state;
|
|
1316
|
+
for (const field of parameters.split(';')) {
|
|
1317
|
+
const code = field.length === 0 ? 0 : Number.parseInt(field, 10);
|
|
1318
|
+
if (!Number.isFinite(code))
|
|
1319
|
+
continue;
|
|
1320
|
+
if (code === 0) {
|
|
1321
|
+
next = INITIAL;
|
|
1322
|
+
continue;
|
|
1323
|
+
}
|
|
1324
|
+
if (code === 1)
|
|
1325
|
+
next = { ...next, bold: true };
|
|
1326
|
+
else if (code === 2)
|
|
1327
|
+
next = { ...next, dim: true };
|
|
1328
|
+
else if (code === 4)
|
|
1329
|
+
next = { ...next, underline: true };
|
|
1330
|
+
else if (code === 22)
|
|
1331
|
+
next = { ...next, bold: false, dim: false };
|
|
1332
|
+
else if (code === 24)
|
|
1333
|
+
next = { ...next, underline: false };
|
|
1334
|
+
else {
|
|
1335
|
+
const tone = toneOf(code);
|
|
1336
|
+
if (tone !== undefined)
|
|
1337
|
+
next = { ...next, tone };
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
return next;
|
|
1341
|
+
}
|
|
1342
|
+
function normalizeTerminalText(source, tabSize = 4) {
|
|
1343
|
+
const withoutOsc = source.replace(OSC, '');
|
|
1344
|
+
const lines = withoutOsc.split('\n');
|
|
1345
|
+
const flattened = lines.map((line) => {
|
|
1346
|
+
const carriage = line.lastIndexOf('\r');
|
|
1347
|
+
return carriage >= 0 ? line.slice(carriage + 1) : line;
|
|
1348
|
+
});
|
|
1349
|
+
return flattened.join('\n').replaceAll('\t', ' '.repeat(tabSize));
|
|
1350
|
+
}
|
|
1351
|
+
function compactOutput(source) {
|
|
1352
|
+
return source
|
|
1353
|
+
.replace(/[ \t]+$/gmu, '')
|
|
1354
|
+
.replace(/\n{3,}/gu, '\n\n')
|
|
1355
|
+
.replace(/^\n+/u, '')
|
|
1356
|
+
.replace(/\n+$/u, '');
|
|
1357
|
+
}
|
|
1358
|
+
function stripAnsi(source) {
|
|
1359
|
+
return normalizeTerminalText(source).replace(CSI, '');
|
|
1360
|
+
}
|
|
1361
|
+
function parseAnsi(source, tabSize = 4) {
|
|
1362
|
+
const text = normalizeTerminalText(source, tabSize);
|
|
1363
|
+
const spans = [];
|
|
1364
|
+
let state = INITIAL;
|
|
1365
|
+
let last = 0;
|
|
1366
|
+
CSI.lastIndex = 0;
|
|
1367
|
+
let match = CSI.exec(text);
|
|
1368
|
+
while (match !== null) {
|
|
1369
|
+
const index = match.index;
|
|
1370
|
+
if (index > last) {
|
|
1371
|
+
spans.push({ text: text.slice(last, index), ...state });
|
|
1372
|
+
}
|
|
1373
|
+
if (match[2] === 'm')
|
|
1374
|
+
state = applySgr(state, match[1] ?? '');
|
|
1375
|
+
last = index + match[0].length;
|
|
1376
|
+
match = CSI.exec(text);
|
|
1377
|
+
}
|
|
1378
|
+
if (last < text.length)
|
|
1379
|
+
spans.push({ text: text.slice(last), ...state });
|
|
1380
|
+
return spans;
|
|
1381
|
+
}
|
|
1382
|
+
//# sourceMappingURL=ansi.js.map
|
|
1383
|
+
Object.assign(exports, { normalizeTerminalText: normalizeTerminalText, compactOutput: compactOutput, stripAnsi: stripAnsi, parseAnsi: parseAnsi });
|
|
1384
|
+
|
|
1385
|
+
},
|
|
1386
|
+
"./envelope.js": (module, exports, __require) => {
|
|
1387
|
+
const CONTENT_OPEN = /^\s*<content(?:\s[^>]*)?>\s*$/u;
|
|
1388
|
+
const CONTENT_CLOSE = /^\s*<\/content>\s*$/u;
|
|
1389
|
+
const LEADING_CONTENT = /^\s*<content(?:\s[^>]*)?>\s*/u;
|
|
1390
|
+
const TRAILING_CONTENT = /\s*<\/content>\s*$/u;
|
|
1391
|
+
const METADATA = /^\s*<(path|type)>[^<\n]*<\/\1>\s*$/u;
|
|
1392
|
+
const READ_RANGE = /^\(Showing lines (\d+)-(\d+) of (\d+)\. Use offset=\d+ to continue\.\)$/u;
|
|
1393
|
+
function stripEnvelope(source) {
|
|
1394
|
+
const lines = source.split('\n');
|
|
1395
|
+
const kept = [];
|
|
1396
|
+
for (const line of lines) {
|
|
1397
|
+
if (CONTENT_OPEN.test(line) || CONTENT_CLOSE.test(line) || METADATA.test(line))
|
|
1398
|
+
continue;
|
|
1399
|
+
kept.push(line);
|
|
1400
|
+
}
|
|
1401
|
+
return kept.join('\n').replace(LEADING_CONTENT, '').replace(TRAILING_CONTENT, '');
|
|
1402
|
+
}
|
|
1403
|
+
function splitReadRange(source) {
|
|
1404
|
+
const lines = source.split('\n');
|
|
1405
|
+
const last = lines.length - 1;
|
|
1406
|
+
const tail = last >= 0 ? (lines[last] ?? '').trim() : '';
|
|
1407
|
+
const match = READ_RANGE.exec(tail);
|
|
1408
|
+
if (match === null)
|
|
1409
|
+
return { text: source, range: null };
|
|
1410
|
+
return {
|
|
1411
|
+
text: lines.slice(0, last).join('\n').replace(/\n+$/u, ''),
|
|
1412
|
+
range: 'lines ' + String(match[1]) + '\u2013' + String(match[2]) + ' of ' + String(match[3]),
|
|
1413
|
+
};
|
|
1414
|
+
}
|
|
1415
|
+
//# sourceMappingURL=envelope.js.map
|
|
1416
|
+
Object.assign(exports, { stripEnvelope: stripEnvelope, splitReadRange: splitReadRange });
|
|
1417
|
+
|
|
1418
|
+
},
|
|
1419
|
+
"./diff.js": (module, exports, __require) => {
|
|
1420
|
+
const MAX_TABLE = 2_000_000;
|
|
1421
|
+
const MAX_LINES = 400;
|
|
1422
|
+
function splitLines(source) {
|
|
1423
|
+
if (source.length === 0)
|
|
1424
|
+
return [];
|
|
1425
|
+
return source.split('\n');
|
|
1426
|
+
}
|
|
1427
|
+
function commonPrefix(before, after) {
|
|
1428
|
+
const limit = Math.min(before.length, after.length);
|
|
1429
|
+
let index = 0;
|
|
1430
|
+
while (index < limit && before[index] === after[index])
|
|
1431
|
+
index += 1;
|
|
1432
|
+
return index;
|
|
1433
|
+
}
|
|
1434
|
+
function commonSuffix(before, after, from) {
|
|
1435
|
+
const limit = Math.min(before.length, after.length) - from;
|
|
1436
|
+
let count = 0;
|
|
1437
|
+
while (count < limit &&
|
|
1438
|
+
before[before.length - 1 - count] === after[after.length - 1 - count]) {
|
|
1439
|
+
count += 1;
|
|
1440
|
+
}
|
|
1441
|
+
return count;
|
|
1442
|
+
}
|
|
1443
|
+
function fallbackOps(before, after) {
|
|
1444
|
+
const prefix = commonPrefix(before, after);
|
|
1445
|
+
const suffix = commonSuffix(before, after, prefix);
|
|
1446
|
+
const ops = [];
|
|
1447
|
+
for (let index = 0; index < prefix; index += 1)
|
|
1448
|
+
ops.push({ kind: 'equal', text: before[index] ?? '' });
|
|
1449
|
+
for (let index = prefix; index < before.length - suffix; index += 1) {
|
|
1450
|
+
ops.push({ kind: 'remove', text: before[index] ?? '' });
|
|
1451
|
+
}
|
|
1452
|
+
for (let index = prefix; index < after.length - suffix; index += 1) {
|
|
1453
|
+
ops.push({ kind: 'add', text: after[index] ?? '' });
|
|
1454
|
+
}
|
|
1455
|
+
for (let index = after.length - suffix; index < after.length; index += 1) {
|
|
1456
|
+
ops.push({ kind: 'equal', text: after[index] ?? '' });
|
|
1457
|
+
}
|
|
1458
|
+
return ops;
|
|
1459
|
+
}
|
|
1460
|
+
function diffOps(beforeSource, afterSource) {
|
|
1461
|
+
const before = splitLines(beforeSource);
|
|
1462
|
+
const after = splitLines(afterSource);
|
|
1463
|
+
const width = after.length + 1;
|
|
1464
|
+
if ((before.length + 1) * width > MAX_TABLE)
|
|
1465
|
+
return fallbackOps(before, after);
|
|
1466
|
+
const table = new Int32Array((before.length + 1) * width);
|
|
1467
|
+
for (let row = before.length - 1; row >= 0; row -= 1) {
|
|
1468
|
+
for (let column = after.length - 1; column >= 0; column -= 1) {
|
|
1469
|
+
table[row * width + column] =
|
|
1470
|
+
before[row] === after[column]
|
|
1471
|
+
? (table[(row + 1) * width + column + 1] ?? 0) + 1
|
|
1472
|
+
: Math.max(table[(row + 1) * width + column] ?? 0, table[row * width + column + 1] ?? 0);
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
const ops = [];
|
|
1476
|
+
let row = 0;
|
|
1477
|
+
let column = 0;
|
|
1478
|
+
while (row < before.length && column < after.length) {
|
|
1479
|
+
if (before[row] === after[column]) {
|
|
1480
|
+
ops.push({ kind: 'equal', text: before[row] ?? '' });
|
|
1481
|
+
row += 1;
|
|
1482
|
+
column += 1;
|
|
1483
|
+
continue;
|
|
1484
|
+
}
|
|
1485
|
+
const down = table[(row + 1) * width + column] ?? 0;
|
|
1486
|
+
const right = table[row * width + column + 1] ?? 0;
|
|
1487
|
+
if (down >= right) {
|
|
1488
|
+
ops.push({ kind: 'remove', text: before[row] ?? '' });
|
|
1489
|
+
row += 1;
|
|
1490
|
+
}
|
|
1491
|
+
else {
|
|
1492
|
+
ops.push({ kind: 'add', text: after[column] ?? '' });
|
|
1493
|
+
column += 1;
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
while (row < before.length) {
|
|
1497
|
+
ops.push({ kind: 'remove', text: before[row] ?? '' });
|
|
1498
|
+
row += 1;
|
|
1499
|
+
}
|
|
1500
|
+
while (column < after.length) {
|
|
1501
|
+
ops.push({ kind: 'add', text: after[column] ?? '' });
|
|
1502
|
+
column += 1;
|
|
1503
|
+
}
|
|
1504
|
+
return ops;
|
|
1505
|
+
}
|
|
1506
|
+
function diffSummary(lines) {
|
|
1507
|
+
let added = 0;
|
|
1508
|
+
let removed = 0;
|
|
1509
|
+
for (const line of lines) {
|
|
1510
|
+
if (line.kind === 'add')
|
|
1511
|
+
added += 1;
|
|
1512
|
+
if (line.kind === 'remove')
|
|
1513
|
+
removed += 1;
|
|
1514
|
+
}
|
|
1515
|
+
return { added, removed };
|
|
1516
|
+
}
|
|
1517
|
+
function diffRows(lines) {
|
|
1518
|
+
let highest = 0;
|
|
1519
|
+
for (const line of lines) {
|
|
1520
|
+
if (line.oldLine !== null)
|
|
1521
|
+
highest = Math.max(highest, line.oldLine);
|
|
1522
|
+
if (line.newLine !== null)
|
|
1523
|
+
highest = Math.max(highest, line.newLine);
|
|
1524
|
+
}
|
|
1525
|
+
const digits = Math.max(3, String(highest).length);
|
|
1526
|
+
let previous = '';
|
|
1527
|
+
const rows = [];
|
|
1528
|
+
for (const line of lines) {
|
|
1529
|
+
if (line.kind === 'hunk') {
|
|
1530
|
+
previous = '';
|
|
1531
|
+
rows.push({ kind: 'hunk', text: line.text, sign: '', number: '', digits });
|
|
1532
|
+
continue;
|
|
1533
|
+
}
|
|
1534
|
+
const raw = line.kind === 'remove' ? line.oldLine : line.newLine;
|
|
1535
|
+
const value = raw === null ? '' : String(raw);
|
|
1536
|
+
const number = value === previous || value.length === 0 ? '' : value;
|
|
1537
|
+
if (value.length > 0)
|
|
1538
|
+
previous = value;
|
|
1539
|
+
rows.push({
|
|
1540
|
+
kind: line.kind,
|
|
1541
|
+
text: line.text,
|
|
1542
|
+
sign: line.kind === 'add' ? '+' : line.kind === 'remove' ? '\u2212' : ' ',
|
|
1543
|
+
number,
|
|
1544
|
+
digits,
|
|
1545
|
+
});
|
|
1546
|
+
}
|
|
1547
|
+
return { rows, digits };
|
|
1548
|
+
}
|
|
1549
|
+
function diffLines(before, after, context = 3, maxLines = MAX_LINES) {
|
|
1550
|
+
const ops = diffOps(before, after);
|
|
1551
|
+
const keep = new Uint8Array(ops.length);
|
|
1552
|
+
for (let index = 0; index < ops.length; index += 1) {
|
|
1553
|
+
if (ops[index]?.kind === 'equal')
|
|
1554
|
+
continue;
|
|
1555
|
+
const from = Math.max(0, index - context);
|
|
1556
|
+
const to = Math.min(ops.length - 1, index + context);
|
|
1557
|
+
for (let mark = from; mark <= to; mark += 1)
|
|
1558
|
+
keep[mark] = 1;
|
|
1559
|
+
}
|
|
1560
|
+
const lines = [];
|
|
1561
|
+
let oldLine = 1;
|
|
1562
|
+
let newLine = 1;
|
|
1563
|
+
let gap = 0;
|
|
1564
|
+
for (let index = 0; index < ops.length; index += 1) {
|
|
1565
|
+
const op = ops[index];
|
|
1566
|
+
if (op === undefined)
|
|
1567
|
+
continue;
|
|
1568
|
+
if (keep[index] !== 1) {
|
|
1569
|
+
gap += 1;
|
|
1570
|
+
if (op.kind === 'equal') {
|
|
1571
|
+
oldLine += 1;
|
|
1572
|
+
newLine += 1;
|
|
1573
|
+
}
|
|
1574
|
+
continue;
|
|
1575
|
+
}
|
|
1576
|
+
if (gap > 0) {
|
|
1577
|
+
lines.push({ kind: 'hunk', text: '\u2026 ' + String(gap) + ' unchanged', oldLine: null, newLine: null });
|
|
1578
|
+
gap = 0;
|
|
1579
|
+
}
|
|
1580
|
+
if (op.kind === 'equal') {
|
|
1581
|
+
lines.push({ kind: 'equal', text: op.text, oldLine, newLine });
|
|
1582
|
+
oldLine += 1;
|
|
1583
|
+
newLine += 1;
|
|
1584
|
+
}
|
|
1585
|
+
else if (op.kind === 'remove') {
|
|
1586
|
+
lines.push({ kind: 'remove', text: op.text, oldLine, newLine: null });
|
|
1587
|
+
oldLine += 1;
|
|
1588
|
+
}
|
|
1589
|
+
else {
|
|
1590
|
+
lines.push({ kind: 'add', text: op.text, oldLine: null, newLine });
|
|
1591
|
+
newLine += 1;
|
|
1592
|
+
}
|
|
1593
|
+
if (lines.length > maxLines) {
|
|
1594
|
+
lines.push({ kind: 'hunk', text: '\u2026 diff truncated', oldLine: null, newLine: null });
|
|
1595
|
+
break;
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
return lines;
|
|
1599
|
+
}
|
|
1600
|
+
//# sourceMappingURL=diff.js.map
|
|
1601
|
+
Object.assign(exports, { diffOps: diffOps, diffSummary: diffSummary, diffRows: diffRows, diffLines: diffLines });
|
|
1602
|
+
|
|
1603
|
+
},
|
|
1604
|
+
}
|
|
1605
|
+
const entry = __require("./client/index.js")
|
|
1606
|
+
if (typeof entry.useReact === 'function') entry.useReact(require('react'))
|
|
1607
|
+
return entry
|
|
1608
|
+
},
|
|
1609
|
+
});
|