@theoremjs/studio 0.3.4-next.649.gf83cea1 → 0.3.4-next.671.gfa09ab2
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 +8 -5
- package/cookbooks/catalog.js +18 -5
- package/cookbooks/tools.js +3 -3
- package/mod.d.ts +3 -3
- package/mod.js +3 -3
- package/package.json +4 -4
- package/page/assets/Banner-DEVAsFER.js +4 -0
- package/page/assets/{ConsoleFrame-B7ruuMVo.js → ConsoleFrame-CqUUcrR4.js} +1 -1
- package/page/assets/{MenuBottomSheet-Bso4osRe.js → MenuBottomSheet-DOa09vl1.js} +1 -1
- package/page/assets/{SchemaFields-DEqlS2cS.js → SchemaFields-CMwMU1Px.js} +1 -1
- package/page/assets/{ToolResultCharts-DV0Cds5H.js → ToolResultCharts-CW23-D1x.js} +1 -1
- package/page/assets/{TraceInspector-CBybmNzh.js → TraceInspector-h030OQ82.js} +1 -1
- package/page/assets/{TraceOverview-CO9Oh2_v.js → TraceOverview-BsON_uZj.js} +1 -1
- package/page/assets/{_virtual_studio-type-sources-hU0nQlME.js → _virtual_studio-type-sources-BwSqfSwd.js} +17 -3
- package/page/assets/{browser-connection-Dim6ghw7.js → browser-connection-DSUHVCT5.js} +2 -2
- package/page/assets/browser-engine-Cf6d-zNH.js +11 -0
- package/page/assets/browser-transport-BK4cbTE_.js +45 -0
- package/page/assets/{crypto-CgKfdKF3.js → crypto-CD14HeXH.js} +1 -1
- package/page/assets/{encode-files-mmy8V0Ya.js → encode-files-DhoC5hWG.js} +1 -1
- package/page/assets/{export-agent-CuUh1bR8.js → export-agent-CaHsJPsM.js} +1 -1
- package/page/assets/{guardrail-tester-Bi8kF5JO.js → guardrail-tester-BDhFLvT5.js} +1 -1
- package/page/assets/index-CqwmMJ4C.js +145 -0
- package/page/assets/{live-messages-MuPbOsZr.js → live-messages-CiLmR89m.js} +1 -1
- package/page/assets/reader-DrOfMM8I.js +5 -0
- package/page/assets/{shaped-data-BIkh6Bis.js → shaped-data-H1miOZm2.js} +1 -1
- package/page/assets/{stub-fr8Q8_U3.js → stub-nxRsh1jo.js} +4 -4
- package/page/assets/{studio-code-pane-DnKDFRIG.js → studio-code-pane-C1wH63Y2.js} +3 -3
- package/page/assets/{studio-console-C8I1MOzW.js → studio-console-DRzo4yTy.js} +1 -1
- package/page/assets/{studio-decision-wzSt60HL.js → studio-decision-C7QWMm7Q.js} +1 -1
- package/page/assets/{studio-embedding-DOOXOgyT.js → studio-embedding-D8KroBXY.js} +1 -1
- package/page/assets/{studio-host-console-Dz8tEAST.js → studio-host-console-HkX8BerX.js} +2 -2
- package/page/assets/{studio-labels-C5heV8lN.js → studio-labels-6w1SKC2D.js} +1 -1
- package/page/assets/studio-live-BmVeXAu4.js +5 -0
- package/page/assets/{studio-map-DzrF-FCH.js → studio-map-5ZU1nicW.js} +1 -1
- package/page/assets/studio-session-CjUQSXx0.js +1 -0
- package/page/assets/studio-trace-replay-CSbJSN5e.js +3 -0
- package/page/assets/{studio-type-checker-DCAG9kT0.js → studio-type-checker-BbUSqqOS.js} +1 -1
- package/page/assets/tool-schema-BmRYaywn.js +17 -0
- package/page/assets/{trace-record-CGww68wU.js → trace-record-DxgSKmYY.js} +1 -1
- package/page/assets/tree-3N-1RPZz.js +3 -0
- package/page/assets/{turn-client-Bn130DZC.js → turn-client-DN8PawJr.js} +2 -2
- package/page/assets/{use-one-call-B_dBxZ07.js → use-one-call-Br2IVJLU.js} +1 -1
- package/page/assets/{use-second-ticker-DtnVtLQo.js → use-second-ticker-CEwOSS-d.js} +1 -1
- package/page/assets/{workspace-Cy2likdd.js → workspace-CTSW941G.js} +1 -1
- package/page/index.html +16 -16
- package/replay.d.ts +13 -8
- package/replay.js +33 -31
- package/run-payload.d.ts +20 -6
- package/run-payload.js +85 -13
- package/runtime-scope.js +1 -0
- package/runtime.js +1 -0
- package/server/project.js +5 -32
- package/transport.d.ts +1 -3
- package/transport.js +0 -9
- package/ui/lib/acting-as.js +1 -6
- package/ui/lib/run-keys.d.ts +15 -5
- package/ui/lib/run-keys.js +80 -16
- package/ui/lib/studio-conversation.d.ts +2 -3
- package/ui/lib/studio-conversation.js +28 -65
- package/ui/lib/studio-keep.d.ts +34 -0
- package/ui/lib/studio-keep.js +202 -0
- package/ui/lib/studio-map-kept.d.ts +2 -2
- package/ui/lib/studio-map-kept.js +5 -10
- package/ui/lib/studio-open.d.ts +1 -1
- package/ui/lib/studio-open.js +5 -5
- package/ui/lib/studio-page.js +1 -7
- package/ui/lib/studio-restore.d.ts +2 -3
- package/ui/lib/studio-restore.js +8 -48
- package/ui/lib/studio-run-open.d.ts +10 -5
- package/ui/lib/studio-run-open.js +18 -9
- package/ui/lib/studio-session.d.ts +38 -5
- package/ui/lib/studio-session.js +133 -3
- package/ui/lib/studio-store.js +8 -30
- package/ui/profile-editor.js +3 -6
- package/ui/studio-compare.js +237 -48
- package/ui/studio-run.js +29 -15
- package/ui/studio-screen.d.ts +1 -1
- package/ui/studio-screen.js +8 -9
- package/ui/studio-trace-replay.js +39 -14
- package/vite.mjs +1 -1
- package/page/assets/Banner-DnfOgQq4.js +0 -4
- package/page/assets/browser-engine-BQs_4RXH.js +0 -11
- package/page/assets/browser-transport-K6LWGuCA.js +0 -45
- package/page/assets/index-8zuMVtQh.js +0 -145
- package/page/assets/reader-YWCb-VWE.js +0 -5
- package/page/assets/studio-live-ed1SR-Py.js +0 -5
- package/page/assets/studio-session-yEqFQo5o.js +0 -1
- package/page/assets/studio-trace-replay-WLO52a22.js +0 -3
- package/page/assets/tool-schema-BJnLgvo3.js +0 -17
- package/page/assets/tree-CvHjrQ-G.js +0 -3
- package/run-payload-core.d.ts +0 -28
- package/run-payload-core.js +0 -117
package/ui/studio-compare.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { Center } from '@astryxdesign/core/Center';
|
|
3
3
|
import { Divider } from '@astryxdesign/core/Divider';
|
|
4
4
|
import { HStack } from '@astryxdesign/core/HStack';
|
|
5
5
|
import { Icon } from '@astryxdesign/core/Icon';
|
|
@@ -8,8 +8,9 @@ import { StackItem } from '@astryxdesign/core/Stack';
|
|
|
8
8
|
import { Text } from '@astryxdesign/core/Text';
|
|
9
9
|
import { VStack } from '@astryxdesign/core/VStack';
|
|
10
10
|
import { IconLayoutSidebarLeftCollapse, IconLayoutSidebarLeftExpand } from '@tabler/icons-react';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { createComposerPendingMessage, orderComposerPendingMessages, removeComposerPendingMessage, } from '@theoremjs/agents/interface';
|
|
12
|
+
import { ChatComposerBar, DEFAULT_CHAT_MAX_WIDTH, InPlace, PaneFailure, PaneLoading, TheoremChat, } from '@theoremjs/react/ui';
|
|
13
|
+
import { clientFailure, composerFieldsFromDraft, composerHasPayload, createHttpTransport, createTraceFeed, encodeComposerDraft, followGenerationDefaults, } from '@theoremjs/web/client';
|
|
13
14
|
import { useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState, useSyncExternalStore, } from 'react';
|
|
14
15
|
import { atStart } from "../mod.js";
|
|
15
16
|
import { useActingAs } from "./lib/acting-as.js";
|
|
@@ -72,40 +73,45 @@ export function useLoadedStamp(answer) {
|
|
|
72
73
|
setLoaded(now);
|
|
73
74
|
return now;
|
|
74
75
|
}
|
|
76
|
+
/** A side's chat as it stands, and as it changes. Null until the side is mounted. */
|
|
77
|
+
function useSideState(chat) {
|
|
78
|
+
const subscribe = useCallback((listener) => (chat ? chat.subscribe(listener) : () => { }), [chat]);
|
|
79
|
+
return useSyncExternalStore(subscribe, () => chat?.getState() ?? null);
|
|
80
|
+
}
|
|
75
81
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
82
|
+
* The two sides' chats, and which of them still answers. A side rests when its turn is done: the
|
|
83
|
+
* reply ended, and any question it stopped on was answered.
|
|
78
84
|
*/
|
|
79
85
|
function usePair() {
|
|
80
|
-
const
|
|
81
|
-
const [
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
const handles = useRef({ saved: null, edited: null });
|
|
87
|
+
const [chats, setChats] = useState({
|
|
88
|
+
saved: null,
|
|
89
|
+
edited: null,
|
|
90
|
+
});
|
|
91
|
+
const [refs] = useState(() => {
|
|
92
|
+
const ref = (side) => (handle) => {
|
|
93
|
+
handles.current[side] = handle;
|
|
94
|
+
const chat = handle?.controller ?? null;
|
|
95
|
+
setChats((now) => (now[side] === chat ? now : { ...now, [side]: chat }));
|
|
96
|
+
};
|
|
97
|
+
return { saved: ref('saved'), edited: ref('edited') };
|
|
98
|
+
});
|
|
99
|
+
const states = { saved: useSideState(chats.saved), edited: useSideState(chats.edited) };
|
|
100
|
+
const busy = SIDES.filter((side) => states[side] && states[side].phase !== 'idle');
|
|
101
|
+
const send = useCallback(async (text, options) => {
|
|
102
|
+
const sent = SIDES.flatMap((side) => {
|
|
103
|
+
const chat = handles.current[side]?.controller;
|
|
104
|
+
return chat ? [[side, chat]] : [];
|
|
93
105
|
});
|
|
106
|
+
// A side's send resolves once its reply is done, or at once when it could not take it.
|
|
107
|
+
const answers = sent.map(async ([side, chat]) => [side, await chat.sendText(text, options).catch(() => null)]);
|
|
94
108
|
return new Map(await Promise.all(answers));
|
|
95
|
-
}, [
|
|
109
|
+
}, []);
|
|
96
110
|
const stop = useCallback(() => {
|
|
97
111
|
for (const side of SIDES)
|
|
98
|
-
|
|
112
|
+
handles.current[side]?.stop();
|
|
99
113
|
}, []);
|
|
100
|
-
|
|
101
|
-
saved: (handle) => {
|
|
102
|
-
chats.current.saved = handle;
|
|
103
|
-
},
|
|
104
|
-
edited: (handle) => {
|
|
105
|
-
chats.current.edited = handle;
|
|
106
|
-
},
|
|
107
|
-
}));
|
|
108
|
-
return useMemo(() => ({ busy, send, stop, refs, chats }), [busy, send, stop, refs]);
|
|
114
|
+
return { busy, send, stop, refs, handles, chats, states };
|
|
109
115
|
}
|
|
110
116
|
/** Whether the files' side is put away, for every comparison in this tab. */
|
|
111
117
|
const savedSide = { isHidden: false, listeners: new Set() };
|
|
@@ -172,10 +178,180 @@ export function SavedSide({ isCompared = true, children, }) {
|
|
|
172
178
|
function NotRunning({ refusal, actions }) {
|
|
173
179
|
return (_jsx(PaneFailure, { title: NOT_RUNNING[refusal.reason] ?? 'Your edits are not running.', actions: actions, children: _jsx(RefusalDetail, { refusal: refusal }) }));
|
|
174
180
|
}
|
|
175
|
-
/** The
|
|
176
|
-
function
|
|
177
|
-
|
|
178
|
-
|
|
181
|
+
/** The phase the shared composer shows: streaming while either side streams, else gated while either waits. */
|
|
182
|
+
function pairPhase(states) {
|
|
183
|
+
if (states.some((state) => state.phase === 'streaming'))
|
|
184
|
+
return 'streaming';
|
|
185
|
+
return states.some((state) => state.phase === 'gated') ? 'gated' : 'idle';
|
|
186
|
+
}
|
|
187
|
+
function allowsSteering(state) {
|
|
188
|
+
return state.iface != null && 'allowSteering' in state.iface && state.iface.allowSteering;
|
|
189
|
+
}
|
|
190
|
+
/** Each side's pending messages, once each: both sides hold a shared message under one id. */
|
|
191
|
+
function pairPending(states) {
|
|
192
|
+
const byId = new Map(states.flatMap((state) => state.pendingMessages.map((message) => [message.id, message])));
|
|
193
|
+
return orderComposerPendingMessages([...byId.values()]);
|
|
194
|
+
}
|
|
195
|
+
/** Whether a side's running turn would take a steer now. */
|
|
196
|
+
const takesSteer = (state) => state.phase === 'streaming' && allowsSteering(state);
|
|
197
|
+
/**
|
|
198
|
+
* The one composer of both sides. It only types for them: each side does with what is sent what
|
|
199
|
+
* its own composer would. An idle side sends it, a busy one queues it; a steer goes to each side
|
|
200
|
+
* whose running turn takes one; and each side refuses a model or file its profile does not take.
|
|
201
|
+
*/
|
|
202
|
+
function SharedComposer({ sides, edited, inputRef, }) {
|
|
203
|
+
const iface = edited.iface ?? undefined;
|
|
204
|
+
const [draftText, setDraftText] = useState('');
|
|
205
|
+
const [pendingFiles, setPendingFiles] = useState([]);
|
|
206
|
+
const [pendingVoice, setPendingVoice] = useState([]);
|
|
207
|
+
const [failure, setFailure] = useState(null);
|
|
208
|
+
const [pick, setPick] = useState({ isChosen: false });
|
|
209
|
+
// The pick follows the edited side's profile as a chat's own composer follows its profile.
|
|
210
|
+
if (iface && pick.of !== iface) {
|
|
211
|
+
const next = followGenerationDefaults(iface, pick, pick.of);
|
|
212
|
+
setPick({ ...next, of: iface, isChosen: pick.isChosen && next.model === pick.model });
|
|
213
|
+
}
|
|
214
|
+
const states = sides.map((side) => side.state);
|
|
215
|
+
const phase = pairPhase(states);
|
|
216
|
+
if (!iface)
|
|
217
|
+
return null;
|
|
218
|
+
// Unchosen, each side runs its own defaults: an edit to the defaults is what the two show.
|
|
219
|
+
const chosen = pick.isChosen ? { model: pick.model, effort: pick.effort } : {};
|
|
220
|
+
const options = () => ({ files: pendingFiles, voice: pendingVoice, ...chosen });
|
|
221
|
+
const message = async (kind) => createComposerPendingMessage({
|
|
222
|
+
kind,
|
|
223
|
+
draft: await encodeComposerDraft({ text: draftText, pendingFiles, pendingVoice }),
|
|
224
|
+
});
|
|
225
|
+
const clear = () => {
|
|
226
|
+
setDraftText('');
|
|
227
|
+
setPendingFiles([]);
|
|
228
|
+
setPendingVoice([]);
|
|
229
|
+
};
|
|
230
|
+
const takePick = (chat) => {
|
|
231
|
+
if (chosen.model !== undefined)
|
|
232
|
+
chat.setGeneration({ modelId: chosen.model, effort: chosen.effort });
|
|
233
|
+
};
|
|
234
|
+
/** Each side as its own composer would: an idle side sends, a busy one takes `kind`. */
|
|
235
|
+
const deliver = async (kind) => {
|
|
236
|
+
const text = draftText;
|
|
237
|
+
const sent = options();
|
|
238
|
+
let shared;
|
|
239
|
+
try {
|
|
240
|
+
shared = await message(kind === 'send_now' ? 'queue' : kind);
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
// The draft stays in the composer, with why it could not go.
|
|
244
|
+
setFailure(clientFailure(error, iface.labels));
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
setFailure(null);
|
|
248
|
+
clear();
|
|
249
|
+
for (const { chat, state } of sides) {
|
|
250
|
+
if (kind === 'steer') {
|
|
251
|
+
if (takesSteer(state))
|
|
252
|
+
void chat.pend(shared);
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
if (kind === 'stash') {
|
|
256
|
+
void chat.pend(shared);
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
// why: reading the attachments took time, and a side may have finished or started since.
|
|
260
|
+
if (chat.getState().phase === 'idle') {
|
|
261
|
+
void chat.sendText(text, sent);
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
takePick(chat);
|
|
265
|
+
void (kind === 'send_now' ? chat.sendNow(shared) : chat.pend(shared));
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
const each = (act) => {
|
|
269
|
+
for (const { chat } of sides)
|
|
270
|
+
act(chat);
|
|
271
|
+
};
|
|
272
|
+
const pending = pairPending(states);
|
|
273
|
+
return (_jsx(SharedDock, { children: _jsx(ChatComposerBar
|
|
274
|
+
// why: a steer goes only to a running turn, so one that no side would take is not offered.
|
|
275
|
+
, {
|
|
276
|
+
// why: a steer goes only to a running turn, so one that no side would take is not offered.
|
|
277
|
+
iface: {
|
|
278
|
+
...iface,
|
|
279
|
+
...('allowSteering' in iface
|
|
280
|
+
? { allowSteering: sides.some(({ state }) => takesSteer(state)) }
|
|
281
|
+
: {}),
|
|
282
|
+
}, draftText: draftText, pendingFiles: pendingFiles, pendingVoice: pendingVoice, pendingMessages: pending, issues: [], phase: phase, failure: failure, selectedModel: pick.model, selectedEffort: pick.effort, placeholder: "Message both", inputRef: inputRef, onDraftTextChange: setDraftText, onFilesSelected: (files) => {
|
|
283
|
+
setPendingFiles((prev) => [...prev, ...files]);
|
|
284
|
+
}, onAttachmentRemove: (index) => {
|
|
285
|
+
setPendingFiles((prev) => prev.filter((_, at) => at !== index));
|
|
286
|
+
}, onVoiceStaged: (file) => {
|
|
287
|
+
setPendingVoice([file]);
|
|
288
|
+
}, onVoiceClear: () => {
|
|
289
|
+
setPendingVoice([]);
|
|
290
|
+
}, onSubmit: () => {
|
|
291
|
+
void deliver('queue');
|
|
292
|
+
}, onStop: () => {
|
|
293
|
+
each((chat) => {
|
|
294
|
+
chat.stop();
|
|
295
|
+
});
|
|
296
|
+
}, onMenuAction: (action) => {
|
|
297
|
+
void deliver(action);
|
|
298
|
+
}, onGenerationChange: (next) => {
|
|
299
|
+
setPick({ model: next.modelId, effort: next.effort, of: iface, isChosen: true });
|
|
300
|
+
}, slotChoices: edited.slots && {
|
|
301
|
+
...edited.slots,
|
|
302
|
+
onChange: (name, value) => {
|
|
303
|
+
each((chat) => {
|
|
304
|
+
chat.pickSlot(name, value);
|
|
305
|
+
});
|
|
306
|
+
},
|
|
307
|
+
}, onPendingMove: (id, direction) => {
|
|
308
|
+
each((chat) => {
|
|
309
|
+
chat.movePending(id, direction);
|
|
310
|
+
});
|
|
311
|
+
}, onPendingRemove: (id) => {
|
|
312
|
+
each((chat) => {
|
|
313
|
+
chat.setPendingMessages((prev) => removeComposerPendingMessage(prev, id));
|
|
314
|
+
});
|
|
315
|
+
}, onPendingQueue: (id) => {
|
|
316
|
+
each((chat) => {
|
|
317
|
+
chat.queuePending(id);
|
|
318
|
+
});
|
|
319
|
+
}, onPendingRestore: (id) => {
|
|
320
|
+
void (async () => {
|
|
321
|
+
const restored = pending.find((held) => held.id === id);
|
|
322
|
+
if (!restored)
|
|
323
|
+
return;
|
|
324
|
+
// As a chat restores: what the composer holds is stashed first.
|
|
325
|
+
if (composerHasPayload(draftText, pendingFiles, pendingVoice))
|
|
326
|
+
await deliver('stash');
|
|
327
|
+
each((chat) => {
|
|
328
|
+
chat.setPendingMessages((prev) => removeComposerPendingMessage(prev, id));
|
|
329
|
+
});
|
|
330
|
+
const fields = composerFieldsFromDraft(restored.draft);
|
|
331
|
+
setDraftText(fields.text);
|
|
332
|
+
setPendingFiles(fields.files);
|
|
333
|
+
setPendingVoice(fields.voice);
|
|
334
|
+
})();
|
|
335
|
+
}, onPendingSendNow: (id) => {
|
|
336
|
+
for (const { chat, state } of sides) {
|
|
337
|
+
const held = state.pendingMessages.find((m) => m.id === id);
|
|
338
|
+
if (!held)
|
|
339
|
+
continue;
|
|
340
|
+
takePick(chat);
|
|
341
|
+
void chat.sendNow(held);
|
|
342
|
+
}
|
|
343
|
+
} }) }));
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Where the shared composer sits: the width and inset of a chat's own dock.
|
|
347
|
+
* why: it sits outside both chats' layouts, so it brings the 12px sides and 24px below they give.
|
|
348
|
+
*/
|
|
349
|
+
function SharedDock({ children }) {
|
|
350
|
+
return (_jsx(VStack, { paddingInline: 3, paddingBlockEnd: 6, children: _jsx(Center, { axis: "horizontal", width: "100%", children: _jsx(VStack, { width: "100%", maxWidth: DEFAULT_CHAT_MAX_WIDTH, children: children }) }) }));
|
|
351
|
+
}
|
|
352
|
+
/** The composer while the edits cannot take a message: it says why. */
|
|
353
|
+
function WaitingComposer({ handle, why }) {
|
|
354
|
+
return (_jsx(SharedDock, { children: _jsx(ChatComposerBar, { handle: handle, draftText: "", onDraftTextChange: () => { }, onSubmit: () => { }, isDisabled: true, placeholder: why }) }));
|
|
179
355
|
}
|
|
180
356
|
/** The agent as the files hold it: an edit may have renamed it, or made it another type. */
|
|
181
357
|
function savedOf(tested, profileId) {
|
|
@@ -275,24 +451,32 @@ function useComparison({ project, profileId, tested, note, traces }) {
|
|
|
275
451
|
}
|
|
276
452
|
/**
|
|
277
453
|
* The chat the page holds: a message goes to both sides while both are there and can take it, and
|
|
278
|
-
* to the one side otherwise. It answers with what the edits said.
|
|
454
|
+
* to the one side otherwise. It answers with what the edits said, and its controller is theirs.
|
|
279
455
|
*/
|
|
280
|
-
function useChatHandle(chatRef, pair, only, canSendBoth) {
|
|
281
|
-
const { send, stop,
|
|
282
|
-
const sendBoth = useCallback(async (text) => (await send(text)).get('edited') ?? null, [send]);
|
|
456
|
+
function useChatHandle(chatRef, pair, only, canSendBoth, sharedInput) {
|
|
457
|
+
const { send, stop, handles } = pair;
|
|
283
458
|
useImperativeHandle(chatRef, () => ({
|
|
284
|
-
send: (text) => {
|
|
459
|
+
send: (text, options) => {
|
|
285
460
|
if (only)
|
|
286
|
-
return
|
|
287
|
-
|
|
461
|
+
return handles.current[only]?.send(text, options) ?? Promise.resolve(null);
|
|
462
|
+
if (!canSendBoth)
|
|
463
|
+
return Promise.resolve(null);
|
|
464
|
+
return send(text, options).then((answers) => answers.get('edited') ?? null);
|
|
288
465
|
},
|
|
289
466
|
stop,
|
|
290
|
-
// With both sides shown, the edited side answers `send`, so its composer takes the focus.
|
|
291
467
|
focus: () => {
|
|
292
|
-
|
|
468
|
+
if (only)
|
|
469
|
+
handles.current[only]?.focus();
|
|
470
|
+
else
|
|
471
|
+
sharedInput.current?.focus();
|
|
472
|
+
},
|
|
473
|
+
get controller() {
|
|
474
|
+
const chat = handles.current[only ?? 'edited']?.controller;
|
|
475
|
+
if (!chat)
|
|
476
|
+
throw new Error('The chat is not open yet.');
|
|
477
|
+
return chat;
|
|
293
478
|
},
|
|
294
|
-
}), [only, canSendBoth,
|
|
295
|
-
return sendBoth;
|
|
479
|
+
}), [only, canSendBoth, send, stop, handles, sharedInput]);
|
|
296
480
|
}
|
|
297
481
|
/**
|
|
298
482
|
* A project's text or image profile, run by the studio's local server. While the builder has
|
|
@@ -307,7 +491,13 @@ export function ProjectChat(props) {
|
|
|
307
491
|
const showsSaved = view.inFiles && !(view.isEditing && isSavedHidden);
|
|
308
492
|
const isShared = view.isShared && showsSaved;
|
|
309
493
|
const only = isShared ? undefined : showsSaved ? 'saved' : 'edited';
|
|
310
|
-
const
|
|
494
|
+
const sharedInput = useRef(null);
|
|
495
|
+
useChatHandle(chatRef, pair, only, !isBusy && isReady, sharedInput);
|
|
496
|
+
const shared = SIDES.flatMap((side) => {
|
|
497
|
+
const chat = pair.chats[side];
|
|
498
|
+
const state = pair.states[side];
|
|
499
|
+
return chat && state ? [{ chat, state }] : [];
|
|
500
|
+
});
|
|
311
501
|
const common = {
|
|
312
502
|
detectCodeLanguage: true,
|
|
313
503
|
labels: STUDIO_LABELS,
|
|
@@ -323,7 +513,6 @@ export function ProjectChat(props) {
|
|
|
323
513
|
// A new load is a new transport: the chat reads it in place and keeps its transcript.
|
|
324
514
|
transport: transports.edited, conversation: view.conversations.current.edited ?? view.conversations.current.saved, onConversationChange: view.onChange.edited,
|
|
325
515
|
// Under a refusal nothing reaches it: the edits it ran are not loaded.
|
|
326
|
-
chatRef: refused ? undefined : pair.refs.edited })) }) }, "edited"))] }) }), isShared &&
|
|
327
|
-
|
|
328
|
-
}, onStop: pair.stop }))] }));
|
|
516
|
+
chatRef: refused ? undefined : pair.refs.edited })) }) }, "edited"))] }) }), isShared &&
|
|
517
|
+
(isReady && pair.states.edited ? (_jsx(SharedComposer, { sides: shared, edited: pair.states.edited, inputRef: sharedInput })) : (_jsx(WaitingComposer, { handle: profileId, why: whyNot(refused !== undefined, isReady) ?? 'Loading your edits' })))] }));
|
|
329
518
|
}
|
package/ui/studio-run.js
CHANGED
|
@@ -2,9 +2,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { Icon } from '@astryxdesign/core/Icon';
|
|
3
3
|
import { IconKey } from '@tabler/icons-react';
|
|
4
4
|
import { PaneState, TheoremThemeProvider, TracePlacement } from '@theoremjs/react/ui';
|
|
5
|
-
import { useEffect, useState } from 'react';
|
|
5
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
6
6
|
import { studioKeySlots } from "../browser.js";
|
|
7
|
-
import { modelRoute, modelSlots, onStudioLocal, readStudioRunIdFromUrl, STUDIO_PROVIDERS, } from "../mod.js";
|
|
7
|
+
import { modelRoute, modelSlots, onStudioLocal, readStudioRunIdFromUrl, STUDIO_PROVIDERS, withStudioRunCredentials, } from "../mod.js";
|
|
8
8
|
import { recordsTraces } from "./lib/project-traces.js";
|
|
9
9
|
import { askRunKeys } from "./lib/run-keys.js";
|
|
10
10
|
import { ProjectContext } from "./lib/studio-project.js";
|
|
@@ -27,7 +27,10 @@ function providersOf(payload) {
|
|
|
27
27
|
* `opened` is what `openStudioRun` returned for this tab.
|
|
28
28
|
*/
|
|
29
29
|
export function StudioRunScreen({ opened, supplies, }) {
|
|
30
|
-
const
|
|
30
|
+
const fromStudio = useFromStudio(opened.masked);
|
|
31
|
+
const payload = useMemo(() => fromStudio.tools
|
|
32
|
+
? withStudioRunCredentials(opened.payload, fromStudio.tools)
|
|
33
|
+
: opened.payload, [opened.payload, fromStudio.tools]);
|
|
31
34
|
// The agent and the agents it calls each read their own key slots.
|
|
32
35
|
const profiles = [
|
|
33
36
|
payload.profile,
|
|
@@ -46,7 +49,15 @@ export function StudioRunScreen({ opened, supplies, }) {
|
|
|
46
49
|
? []
|
|
47
50
|
: Object.values(profile.models).flatMap((binding) => Object.values(modelSlots(providersOf(payload), binding)))),
|
|
48
51
|
], supplies);
|
|
49
|
-
const
|
|
52
|
+
const needsKeys = !opened.project && payload.connectionMode === 'byok';
|
|
53
|
+
const { setVault } = connection;
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (needsKeys && fromStudio.keys)
|
|
56
|
+
setVault(fromStudio.keys);
|
|
57
|
+
}, [needsKeys, fromStudio.keys, setVault]);
|
|
58
|
+
const isGone = fromStudio.gone && (needsKeys || opened.masked);
|
|
59
|
+
// why: a tool called before its credentials arrive would go out with them masked.
|
|
60
|
+
const isWaiting = opened.masked && !fromStudio.tools && !fromStudio.gone;
|
|
50
61
|
const traced = recordsTraces(payload);
|
|
51
62
|
const [traceOpen, setTraceOpen] = useState(false);
|
|
52
63
|
const phone = usePhone();
|
|
@@ -54,26 +65,29 @@ export function StudioRunScreen({ opened, supplies, }) {
|
|
|
54
65
|
const title = studioRunTitle(payload);
|
|
55
66
|
return (_jsxs(TheoremThemeProvider, { mode: "dark", children: [_jsx("title", { children: `${title} · theorem studio` }), _jsx(TracePlacement, { value: "panel", children: _jsxs("div", { className: "run-page", children: [_jsx("div", { className: "run-controls", children: traced ? (_jsx(TraceButton, { open: traceOpen, isIconOnly: phone, onToggle: () => {
|
|
56
67
|
setTraceOpen((open) => !open);
|
|
57
|
-
} })) : null }),
|
|
68
|
+
} })) : null }), isGone ? (_jsx(PaneState, { icon: _jsx(Icon, { icon: IconKey, size: "lg", color: "secondary" }), title: "Open the agent from the studio again", description: "This tab takes its keys and its tools' credentials from the studio tab that opened it, and that tab no longer holds them: it was closed, reloaded, or left the studio. Open the agent in a new tab from the studio again." })) : isWaiting ? null : (_jsx(ProjectContext.Provider, { value: opened.project, children: _jsx(StudioRunner, { payload: payload, runtime: runtime, trace: traced ? traceOpen : undefined, flush: true, columns: true, className: "run-chat" }, mode) }))] }) })] }));
|
|
58
69
|
}
|
|
59
70
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
71
|
+
* What the studio tab that opened this one answers: its keys, and the credentials the kept copy of
|
|
72
|
+
* this run masked. `gone` when no studio tab holds them for it.
|
|
62
73
|
*/
|
|
63
|
-
function
|
|
74
|
+
function useFromStudio(masked) {
|
|
75
|
+
const [answer, setAnswer] = useState();
|
|
64
76
|
const [gone, setGone] = useState(false);
|
|
65
77
|
useEffect(() => {
|
|
66
|
-
if (!needed)
|
|
67
|
-
return;
|
|
68
78
|
const run = readStudioRunIdFromUrl();
|
|
69
|
-
const stop = run
|
|
79
|
+
const stop = run
|
|
80
|
+
? askRunKeys(run, (keys, tools) => {
|
|
81
|
+
setAnswer({ keys, tools });
|
|
82
|
+
}, () => {
|
|
83
|
+
setGone(true);
|
|
84
|
+
})
|
|
85
|
+
: null;
|
|
70
86
|
if (!stop) {
|
|
71
87
|
setGone(true);
|
|
72
88
|
return;
|
|
73
89
|
}
|
|
74
90
|
return stop;
|
|
75
|
-
}, [
|
|
76
|
-
|
|
77
|
-
return 'unneeded';
|
|
78
|
-
return gone ? 'gone' : 'asked';
|
|
91
|
+
}, []);
|
|
92
|
+
return { ...answer, tools: masked ? answer?.tools : undefined, gone };
|
|
79
93
|
}
|
package/ui/studio-screen.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { type ProjectFiles, type ProjectSession } from './lib/studio-project.ts'
|
|
|
4
4
|
import { type RestoredStudio } from './lib/studio-session.ts';
|
|
5
5
|
import type { ProbeResult } from './lib/tool-probe.ts';
|
|
6
6
|
import { type StudioHost, type StudioOpened } from './studio-host.ts';
|
|
7
|
-
/** The workspace's store, kept in this tab's
|
|
7
|
+
/** The workspace's store, kept in this tab's records, and the open agent's draft from it. */
|
|
8
8
|
declare function useStudioWorkspace(start: RestoredStudio, project: ProjectSession | undefined): {
|
|
9
9
|
store: {
|
|
10
10
|
getWorkspace: () => StudioWorkspace;
|
package/ui/studio-screen.js
CHANGED
|
@@ -25,7 +25,7 @@ import { IconAdjustmentsHorizontal, IconArrowBarToDown, IconArrowLeft, IconBrows
|
|
|
25
25
|
import { profileGraphFacet } from '@theoremjs/agents';
|
|
26
26
|
import { InPlace, PaneFailure, RaisedPane, useDisclosureMotion, } from '@theoremjs/react/ui';
|
|
27
27
|
import { canonical } from "../canonical.js";
|
|
28
|
-
import { addAgent, addArchitectExample, addProvider, addResearchExample, agentNodeId, compileWorkspace, createBlankDraft, createConsoleExampleDraft, createDecisionExampleDraft, createExampleDraft, createGeminiEmbeddingExampleDraft, createLiveExampleDraft, createNarratorExampleDraft,
|
|
28
|
+
import { addAgent, addArchitectExample, addProvider, addResearchExample, agentNodeId, compileWorkspace, createBlankDraft, createConsoleExampleDraft, createDecisionExampleDraft, createExampleDraft, createGeminiEmbeddingExampleDraft, createLiveExampleDraft, createNarratorExampleDraft, draftFacets, duplicateAgent, editedSince, excludeFacet, includableFacets, includeFacet, libraryDraft, localProviderAddress, mergedWithFiles, modelBindingNodeId, modelRoute, modelSharers, modelSlots, nodeOrigins, onStudioLocal, openOutcome, originLabel, originPlace, originWay, providerIdOf, providerNodeId, providerUse, rebased, removeAgent, removeLibraryTool, removeProvider, renameProvider, reopened, resetAgent, resetAgentNode, resetLibraryTool, resetProvider, sampleToolInput, scopedNodeId, setToolAllowed, sharedAsk, sharedAt, sharedEntries, studioNodeRef, studioSource, studioTree, toolSpecKeyOf, withAgentDraft, withFilesChosen, withProvider, workspaceNodeRef, workspaceRunAgent, workspaceTree, writeAsk, } from "../mod.js";
|
|
29
29
|
import { slotProviders } from "../requirements.js";
|
|
30
30
|
import { studioSurface } from "../surface.js";
|
|
31
31
|
import './studio.css';
|
|
@@ -42,7 +42,7 @@ import { FACET_ICON } from "./lib/facet-icons.js";
|
|
|
42
42
|
import { movePanel } from "./lib/panel-motion.js";
|
|
43
43
|
import { screenEndpoint } from "./lib/project-address.js";
|
|
44
44
|
import { recordsTraces } from "./lib/project-traces.js";
|
|
45
|
-
import { answerRunKeys } from "./lib/run-keys.js";
|
|
45
|
+
import { answerRunKeys, handOffStudioRun } from "./lib/run-keys.js";
|
|
46
46
|
import { sendWhenReady } from "./lib/send-when-ready.js";
|
|
47
47
|
import { clearConversation, restoreConversation, saveConversation, } from "./lib/studio-conversation.js";
|
|
48
48
|
import { STUDIO_EXAMPLES } from "./lib/studio-examples.js";
|
|
@@ -559,10 +559,9 @@ function innerNodeId(id, focus) {
|
|
|
559
559
|
return 'identity';
|
|
560
560
|
return id.startsWith(`${root}/`) ? id.slice(root.length + 1) : undefined;
|
|
561
561
|
}
|
|
562
|
-
/** Hands the compiled agent to a new tab through
|
|
563
|
-
function openInNewTab(payload, project) {
|
|
564
|
-
const runId =
|
|
565
|
-
saveStudioRunPayload(payload, runId);
|
|
562
|
+
/** Hands the compiled agent to a new tab through the browser's keep; the run route takes it. */
|
|
563
|
+
async function openInNewTab(payload, project) {
|
|
564
|
+
const runId = await handOffStudioRun(payload);
|
|
566
565
|
// A project's agent runs the project's code on its own page too.
|
|
567
566
|
const named = project ? `&project=${encodeURIComponent(project.name)}` : '';
|
|
568
567
|
// why: no `noopener`: the run tab asks this tab for its keys, which never leave memory.
|
|
@@ -803,7 +802,7 @@ function runMembers(store, page, chat) {
|
|
|
803
802
|
const result = runNow();
|
|
804
803
|
if (!result)
|
|
805
804
|
return;
|
|
806
|
-
openInNewTab({
|
|
805
|
+
void openInNewTab({
|
|
807
806
|
...runPayload(result),
|
|
808
807
|
connectionMode: page.current.on.mode,
|
|
809
808
|
localBaseUrl: page.current.connection.local.baseUrl,
|
|
@@ -892,7 +891,7 @@ function OpenInNewTabButton({ compiled, chattedId, blocked, connection, isIconOn
|
|
|
892
891
|
'Run this agent on a full page of its own, in a new tab, the way a person using it would see it', onClick: () => {
|
|
893
892
|
const run = compiled && workspaceRunAgent(compiled, chattedId);
|
|
894
893
|
if (run)
|
|
895
|
-
openInNewTab({ ...runPayload(run), ...connection }, project);
|
|
894
|
+
void openInNewTab({ ...runPayload(run), ...connection }, project);
|
|
896
895
|
} }));
|
|
897
896
|
}
|
|
898
897
|
/** Get code: a .zip, Copy, or Copy for LLM, for every agent; off while the workspace has issues. */
|
|
@@ -952,7 +951,7 @@ function ExportMenu({ store, compile, copy, }) {
|
|
|
952
951
|
},
|
|
953
952
|
] }));
|
|
954
953
|
}
|
|
955
|
-
/** The workspace's store, kept in this tab's
|
|
954
|
+
/** The workspace's store, kept in this tab's records, and the open agent's draft from it. */
|
|
956
955
|
function useStudioWorkspace(start, project) {
|
|
957
956
|
// The settings the project's profiles share, on the agents it opened as: a change to one is
|
|
958
957
|
// made on each of them.
|
|
@@ -18,13 +18,13 @@ import { StackItem } from '@astryxdesign/core/Stack';
|
|
|
18
18
|
import { Switch } from '@astryxdesign/core/Switch';
|
|
19
19
|
import { Text } from '@astryxdesign/core/Text';
|
|
20
20
|
import { VStack } from '@astryxdesign/core/VStack';
|
|
21
|
-
import { IconX } from '@tabler/icons-react';
|
|
21
|
+
import { IconChevronLeft, IconChevronRight, IconX } from '@tabler/icons-react';
|
|
22
22
|
import { useTheoremChat } from '@theoremjs/react';
|
|
23
23
|
import { ChatTranscript, ConsoleFrame, RequestCard, ResponseColumn, RunBar, TheoremLabelsProvider, TheoremThemeProvider, useLabels, useTraceInspector, } from '@theoremjs/react/ui';
|
|
24
24
|
import { createTraceFeed, recordedFeed, } from '@theoremjs/web/client';
|
|
25
25
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
26
26
|
import { createBrowserStudioTransport, startBrowserStudioConversation, } from "../browser.js";
|
|
27
|
-
import { createReplay, parseTraceFile, recordedPayload, recordedTranscript,
|
|
27
|
+
import { createReplay, parseTraceFile, recordedPayload, recordedTranscript, replayScripts, startStudioConversation, studioInterface, studioPageTools, } from "../mod.js";
|
|
28
28
|
import { pageConversationKey } from "./lib/studio-conversation.js";
|
|
29
29
|
import { STUDIO_LABELS } from "./lib/studio-labels.js";
|
|
30
30
|
/**
|
|
@@ -67,8 +67,6 @@ function TraceFileInput({ onImport }) {
|
|
|
67
67
|
setReading(true);
|
|
68
68
|
try {
|
|
69
69
|
const records = parseTraceFile(await file.text());
|
|
70
|
-
// why: a file the replay cannot read is refused here, where the card can say why.
|
|
71
|
-
replayScript(records);
|
|
72
70
|
onImport({ name: file.name, records });
|
|
73
71
|
setProblem(undefined);
|
|
74
72
|
}
|
|
@@ -99,7 +97,11 @@ function TraceFacts({ controls }) {
|
|
|
99
97
|
`${String(turns)} ${turns === 1 ? 'turn' : 'turns'}`,
|
|
100
98
|
recordedAt(script),
|
|
101
99
|
];
|
|
102
|
-
return (_jsxs(_Fragment, { children: [_jsxs(HStack, { gap: 2, vAlign: "center", children: [_jsx(StackItem, { size: "fill", children: _jsxs(VStack, { gap: 0, children: [_jsx(Text, { type: "label", maxLines: 1, children: controls.opened.name }), _jsx(Text, { type: "supporting", color: "secondary", maxLines: 1, children: facts.filter(Boolean).join(' · ') })] }) }), _jsx(IconButton, { label: "Clear trace", variant: "ghost", size: "sm", icon: _jsx(Icon, { icon: IconX, size: "sm" }), isDisabled: controls.isRunning, onClick: controls.onClear })] }),
|
|
100
|
+
return (_jsxs(_Fragment, { children: [_jsxs(HStack, { gap: 2, vAlign: "center", children: [_jsx(StackItem, { size: "fill", children: _jsxs(VStack, { gap: 0, children: [_jsx(Text, { type: "label", maxLines: 1, children: controls.opened.name }), _jsx(Text, { type: "supporting", color: "secondary", maxLines: 1, children: facts.filter(Boolean).join(' · ') })] }) }), _jsx(IconButton, { label: "Clear trace", variant: "ghost", size: "sm", icon: _jsx(Icon, { icon: IconX, size: "sm" }), isDisabled: controls.isRunning, onClick: controls.onClear })] }), controls.count > 1 ? (_jsxs(HStack, { gap: 1, vAlign: "center", children: [_jsx(IconButton, { label: "Previous conversation", variant: "ghost", size: "sm", icon: _jsx(Icon, { icon: IconChevronLeft, size: "sm" }), isDisabled: controls.isRunning || controls.picked === 0, onClick: () => {
|
|
101
|
+
controls.onPick(controls.picked - 1);
|
|
102
|
+
} }), _jsxs(Text, { type: "supporting", children: ["Conversation ", String(controls.picked + 1), " of ", String(controls.count)] }), _jsx(IconButton, { label: "Next conversation", variant: "ghost", size: "sm", icon: _jsx(Icon, { icon: IconChevronRight, size: "sm" }), isDisabled: controls.isRunning || controls.picked === controls.count - 1, onClick: () => {
|
|
103
|
+
controls.onPick(controls.picked + 1);
|
|
104
|
+
} })] })) : null, script.agent && script.agent !== payload.profile.id ? (_jsx(Banner, { status: "info", title: `Recorded with ${script.agent}; a replay runs through ${payload.profile.id}.` })) : null, turns === 0 ? (_jsx(Banner, { status: "info", title: "This trace holds no conversation to replay." })) : null, _jsx(Switch, { label: "Live tools", description: "Run the profile's tools instead of answering them from the recording.", value: controls.liveTools, onChange: controls.onLiveTools })] }));
|
|
103
105
|
}
|
|
104
106
|
const idle = () => undefined;
|
|
105
107
|
/** The trace card: the file, what it recorded, and Replay. */
|
|
@@ -150,11 +152,11 @@ function StatusBanner({ status, turns, onContinue, onLive, }) {
|
|
|
150
152
|
return (_jsxs(VStack, { gap: 1, children: [banner, problem ? _jsx(Banner, { status: "error", title: problem }) : null] }));
|
|
151
153
|
}
|
|
152
154
|
/** A replay of the imported trace: driven turn by turn, beside what the trace recorded. */
|
|
153
|
-
function ReplayConsole({ payload, iface, trace, card,
|
|
155
|
+
function ReplayConsole({ payload, iface, trace, card, records, script, shown, liveTools, runtime, onLive, }) {
|
|
154
156
|
const diverged = useRef(undefined);
|
|
155
157
|
const [status, setStatus] = useState({ kind: 'running', turn: 0 });
|
|
156
158
|
const [traces] = useState(createTraceFeed);
|
|
157
|
-
const recorded = useMemo(() => recordedFeed(
|
|
159
|
+
const recorded = useMemo(() => recordedFeed(records), [records]);
|
|
158
160
|
const replay = useMemo(() => createReplay(script, payload.profile.id, (divergence) => {
|
|
159
161
|
diverged.current ??= divergence;
|
|
160
162
|
}), [script, payload.profile.id]);
|
|
@@ -240,14 +242,32 @@ function ReplayConsole({ payload, iface, trace, card, opened, script, shown, liv
|
|
|
240
242
|
export function TraceReplay(props) {
|
|
241
243
|
return (_jsx(TheoremThemeProvider, { children: _jsx(TheoremLabelsProvider, { labels: STUDIO_LABELS, children: _jsx(TraceConsole, { ...props }) }) }));
|
|
242
244
|
}
|
|
245
|
+
/** A file with no conversation in it. */
|
|
246
|
+
const emptyScript = { agent: '', turns: [], records: [] };
|
|
247
|
+
/**
|
|
248
|
+
* What the inspector shows of a file: all of it with one conversation in it; with more, the open
|
|
249
|
+
* conversation's records and those no conversation holds (a host's tool call, a decision).
|
|
250
|
+
*/
|
|
251
|
+
function shownRecords(records, scripts, script) {
|
|
252
|
+
if (scripts.length <= 1 || !script)
|
|
253
|
+
return records;
|
|
254
|
+
const held = new Set(scripts.flatMap((each) => each.records));
|
|
255
|
+
const open = new Set(script.records);
|
|
256
|
+
return records.filter((record) => open.has(record) || !held.has(record));
|
|
257
|
+
}
|
|
243
258
|
function TraceConsole({ payload, trace, runtime, onLive, opened, onOpened, onClear, }) {
|
|
244
259
|
const iface = useMemo(() => studioInterface(payload), [payload]);
|
|
245
|
-
const
|
|
246
|
-
const
|
|
260
|
+
const scripts = useMemo(() => (opened ? replayScripts(opened.records) : []), [opened]);
|
|
261
|
+
const [pick, setPick] = useState();
|
|
262
|
+
// why: a newly opened file starts on its first conversation.
|
|
263
|
+
const picked = pick && pick.of === opened ? pick.index : 0;
|
|
264
|
+
const script = opened ? (scripts[picked] ?? emptyScript) : undefined;
|
|
265
|
+
const records = useMemo(() => shownRecords(opened?.records ?? [], scripts, script), [opened, scripts, script]);
|
|
266
|
+
const recorded = useMemo(() => recordedFeed(records), [records]);
|
|
247
267
|
const [ran, setRan] = useState();
|
|
248
268
|
const [liveTools, setLiveTools] = useState(false);
|
|
249
|
-
// invariant: a replay belongs to the
|
|
250
|
-
const run = ran
|
|
269
|
+
// invariant: a replay belongs to the conversation and the agent it ran; another of either shows the recording.
|
|
270
|
+
const run = ran && ran.of === script && ran.agent === payload.profile.id ? ran : undefined;
|
|
251
271
|
const attempt = run?.attempt ?? 0;
|
|
252
272
|
const shown = run?.shown ?? 'recorded';
|
|
253
273
|
const setShown = (next) => {
|
|
@@ -255,8 +275,8 @@ function TraceConsole({ payload, trace, runtime, onLive, opened, onOpened, onCle
|
|
|
255
275
|
setRan({ ...run, shown: next });
|
|
256
276
|
};
|
|
257
277
|
const replayOnce = () => {
|
|
258
|
-
if (
|
|
259
|
-
setRan({ of:
|
|
278
|
+
if (script)
|
|
279
|
+
setRan({ of: script, agent: payload.profile.id, attempt: attempt + 1, shown: 'replayed' });
|
|
260
280
|
};
|
|
261
281
|
// invariant: the header offers an import only for a type whose conversation a trace holds.
|
|
262
282
|
if (iface.type === 'live')
|
|
@@ -266,6 +286,11 @@ function TraceConsole({ payload, trace, runtime, onLive, opened, onOpened, onCle
|
|
|
266
286
|
const card = ({ isRunning, onStop }) => (_jsx(TraceCard, { onImport: onOpened, controls: {
|
|
267
287
|
opened,
|
|
268
288
|
script,
|
|
289
|
+
picked,
|
|
290
|
+
count: scripts.length,
|
|
291
|
+
onPick: (index) => {
|
|
292
|
+
setPick({ of: opened, index });
|
|
293
|
+
},
|
|
269
294
|
payload,
|
|
270
295
|
shown: attempt > 0 ? shown : null,
|
|
271
296
|
onShown: setShown,
|
|
@@ -282,5 +307,5 @@ function TraceConsole({ payload, trace, runtime, onLive, opened, onOpened, onCle
|
|
|
282
307
|
} }));
|
|
283
308
|
if (attempt === 0)
|
|
284
309
|
return (_jsx(TraceFrame, { iface: iface, feed: recorded, trace: trace, card: card({ isRunning: false, onStop: () => undefined }), conversation: _jsx(Conversation, { iface: iface, blocks: recordedTranscript(script) }) }));
|
|
285
|
-
return (_jsx(ReplayConsole, { payload: payload, iface: iface, trace: trace, card: card,
|
|
310
|
+
return (_jsx(ReplayConsole, { payload: payload, iface: iface, trace: trace, card: card, records: records, script: script, shown: shown, liveTools: liveTools, runtime: runtime, onLive: onLive }, attempt));
|
|
286
311
|
}
|
package/vite.mjs
CHANGED
|
@@ -140,7 +140,7 @@ function emitDeclarations(hostRoot) {
|
|
|
140
140
|
emitDeclarationOnly: true,
|
|
141
141
|
skipLibCheck: true,
|
|
142
142
|
strict: true,
|
|
143
|
-
target: ts.ScriptTarget.
|
|
143
|
+
target: ts.ScriptTarget.ES2023,
|
|
144
144
|
module: ts.ModuleKind.ESNext,
|
|
145
145
|
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
146
146
|
allowImportingTsExtensions: true,
|