@theoremjs/studio 0.3.4-next.753.g176c472 → 0.3.4-next.757.gde44a4d
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 +1 -1
- package/package.json +4 -4
- package/page/assets/{ConsoleFrame-CqQsb1GZ.js → ConsoleFrame-D309UtSL.js} +1 -1
- package/page/assets/{MenuBottomSheet-BInvPU7g.js → MenuBottomSheet-CVBLnUiO.js} +1 -1
- package/page/assets/{SchemaFields-Bd9lDE4d.js → SchemaFields-muOTQM8x.js} +1 -1
- package/page/assets/{ToolResultCharts-CI9TdyAV.js → ToolResultCharts-Bhesjbc4.js} +1 -1
- package/page/assets/{Toolbar-RbTb26eP.js → Toolbar-t4I6MDV_.js} +1 -1
- package/page/assets/{TraceInspector-aObqeJHi.js → TraceInspector-BqEGN_46.js} +1 -1
- package/page/assets/{TraceOverview-D5c_l1Ux.js → TraceOverview-DLEqvRF2.js} +1 -1
- package/page/assets/{browser-engine-DI5i0e2R.js → browser-engine-Fi7MROTb.js} +1 -1
- package/page/assets/{browser-transport-Dh5ab7QT.js → browser-transport-C_sHZVPa.js} +2 -2
- package/page/assets/{export-agent-Cd8Q-cK9.js → export-agent-CYZqQ4ll.js} +1 -1
- package/page/assets/{guardrail-tester-CR-zyzhr.js → guardrail-tester-D-_i4Zuj.js} +1 -1
- package/page/assets/{index-Kvukosz3.js → index-DuTrjzLN.js} +13 -13
- package/page/assets/{prompt-row-CE0EDTVb.js → prompt-row-CIxkqX9Q.js} +1 -1
- package/page/assets/{studio-code-pane-DCaWq57x.js → studio-code-pane-DEBuOivy.js} +1 -1
- package/page/assets/{studio-console-bHQq_-86.js → studio-console-DHgwXKne.js} +1 -1
- package/page/assets/{studio-decision-BaoUot8U.js → studio-decision-B_EdxnvG.js} +1 -1
- package/page/assets/{studio-embedding-BVMWcpVq.js → studio-embedding-mZIx4qHD.js} +1 -1
- package/page/assets/{studio-host-console-BfLdRxc9.js → studio-host-console-BmB0sSsX.js} +2 -2
- package/page/assets/{studio-labels-CNc-S7NH.js → studio-labels-BRouZt4M.js} +1 -1
- package/page/assets/{studio-live-DeDSZSSs.js → studio-live-Cy09vyLv.js} +1 -1
- package/page/assets/{studio-map-u2kDE0i4.js → studio-map-8aIk_pdY.js} +1 -1
- package/page/assets/{studio-trace-replay-BInKCErs.js → studio-trace-replay-BaF2UAqT.js} +1 -1
- package/page/assets/{use-one-call-D9ArlH1f.js → use-one-call-BKLi6fk_.js} +1 -1
- package/page/index.html +3 -3
- package/server/events.d.ts +2 -4
- package/server/events.js +4 -11
- package/server/handler.d.ts +3 -1
- package/server/handler.js +8 -1
- package/server/kept-sessions.d.ts +32 -0
- package/server/kept-sessions.js +103 -0
- package/server/project.d.ts +3 -1
- package/server/project.js +2 -0
- package/server/serve.js +38 -30
- package/server/test-connection.js +6 -6
- package/ui/lib/studio-watch.d.ts +0 -6
- package/ui/lib/studio-watch.js +0 -16
- package/ui/studio-compare.js +1 -35
- package/ui/studio-save.d.ts +0 -2
- package/ui/studio-save.js +2 -10
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a chat's session holds outlives the load that wrote it. A load is a process the studio
|
|
3
|
+
* replaces, so the gates, answers and detached calls of its chats live here, in the process that
|
|
4
|
+
* stays, and a load reaches them over its own server with a token only it was given. They stay in
|
|
5
|
+
* memory: a session may hold secrets, and nothing of it reaches disk.
|
|
6
|
+
*
|
|
7
|
+
* A call that detached runs on in the load that started it, so the studio keeps a replaced load
|
|
8
|
+
* until its calls end, and what they answer lands here for the load that took over.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import { createMemorySessionStore, } from '@theoremjs/web/server';
|
|
13
|
+
export function createKeptSessions() {
|
|
14
|
+
// why: a session here lasts as long as the studio does, so nothing here ages out or is evicted.
|
|
15
|
+
const store = createMemorySessionStore({
|
|
16
|
+
ttlMs: Number.MAX_SAFE_INTEGER,
|
|
17
|
+
maxSessions: Number.MAX_SAFE_INTEGER,
|
|
18
|
+
});
|
|
19
|
+
const token = crypto.randomUUID();
|
|
20
|
+
/** Each session's detached calls, by operation, with the load each runs in. */
|
|
21
|
+
const detached = new Map();
|
|
22
|
+
const waiting = new Map();
|
|
23
|
+
const isRunning = (load) => [...detached.values()].some((calls) => [...calls.values()].includes(load));
|
|
24
|
+
const note = (sessionId, state, load) => {
|
|
25
|
+
const calls = detached.get(sessionId) ?? new Map();
|
|
26
|
+
detached.set(sessionId, calls);
|
|
27
|
+
for (const [id, operation] of Object.entries(state.operations))
|
|
28
|
+
if (operation.status === 'background' && !calls.has(id))
|
|
29
|
+
calls.set(id, load);
|
|
30
|
+
for (const [id, owner] of calls) {
|
|
31
|
+
if (state.operations[id]?.status === 'background')
|
|
32
|
+
continue;
|
|
33
|
+
calls.delete(id);
|
|
34
|
+
if (!isRunning(owner)) {
|
|
35
|
+
waiting.get(owner)?.end();
|
|
36
|
+
waiting.delete(owner);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
/** Takes the load's calls out of a session; retried, as a load may be writing it too. */
|
|
41
|
+
const forget = async (sessionId, load) => {
|
|
42
|
+
for (;;) {
|
|
43
|
+
const snapshot = await store.load(sessionId);
|
|
44
|
+
if (!snapshot)
|
|
45
|
+
return;
|
|
46
|
+
const operations = Object.fromEntries(Object.entries(snapshot.state.operations).filter(([id]) => detached.get(sessionId)?.get(id) !== load));
|
|
47
|
+
const next = { ...snapshot.state, operations };
|
|
48
|
+
const write = await store.compareAndSwap(sessionId, snapshot.revision, next);
|
|
49
|
+
if (write.written)
|
|
50
|
+
return note(sessionId, next, load);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
token,
|
|
55
|
+
answer: async (request) => {
|
|
56
|
+
if (request.headers.get('authorization') !== `Bearer ${token}`)
|
|
57
|
+
return new Response(null, { status: 401 });
|
|
58
|
+
const { sessionId, write } = (await request.json());
|
|
59
|
+
if (!write)
|
|
60
|
+
return Response.json({ snapshot: await store.load(sessionId) });
|
|
61
|
+
const answer = await store.compareAndSwap(sessionId, write.expected, write.next);
|
|
62
|
+
if (answer.written)
|
|
63
|
+
note(sessionId, write.next, write.load);
|
|
64
|
+
return Response.json(answer);
|
|
65
|
+
},
|
|
66
|
+
callsEnd: (load) => {
|
|
67
|
+
if (!isRunning(load))
|
|
68
|
+
return undefined;
|
|
69
|
+
const held = waiting.get(load);
|
|
70
|
+
if (held)
|
|
71
|
+
return held.ended;
|
|
72
|
+
let end = () => { };
|
|
73
|
+
const ended = new Promise((done) => {
|
|
74
|
+
end = done;
|
|
75
|
+
});
|
|
76
|
+
waiting.set(load, { ended, end });
|
|
77
|
+
return ended;
|
|
78
|
+
},
|
|
79
|
+
loadEnded: async (load) => {
|
|
80
|
+
const sessions = [...detached].filter(([, calls]) => [...calls.values()].includes(load));
|
|
81
|
+
await Promise.all(sessions.map(([sessionId]) => forget(sessionId, load)));
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** The kept sessions as a load's store, under `link.scope` and the profile's id. */
|
|
86
|
+
export function keptSessionStore(link, profileId) {
|
|
87
|
+
const key = (sessionId) => `${link.scope}:${profileId}:${sessionId}`;
|
|
88
|
+
const ask = async (asked) => {
|
|
89
|
+
const response = await fetch(link.url, {
|
|
90
|
+
method: 'POST',
|
|
91
|
+
headers: { authorization: `Bearer ${link.token}` },
|
|
92
|
+
body: JSON.stringify(asked),
|
|
93
|
+
});
|
|
94
|
+
// The studio said what the status means; a session's text never goes in an error.
|
|
95
|
+
if (!response.ok)
|
|
96
|
+
throw new Error(`The studio's kept sessions answered ${response.status}.`);
|
|
97
|
+
return response.json();
|
|
98
|
+
};
|
|
99
|
+
return {
|
|
100
|
+
load: async (sessionId) => (await ask({ sessionId: key(sessionId) })).snapshot,
|
|
101
|
+
compareAndSwap: (sessionId, expected, next) => ask({ sessionId: key(sessionId), write: { expected, next, load: link.load } }),
|
|
102
|
+
};
|
|
103
|
+
}
|
package/server/project.d.ts
CHANGED
|
@@ -13,9 +13,11 @@
|
|
|
13
13
|
* @module
|
|
14
14
|
*/
|
|
15
15
|
import { type ProjectEdits } from './edits.ts';
|
|
16
|
-
|
|
16
|
+
import { type KeptSessionLink } from './kept-sessions.ts';
|
|
17
|
+
/** What `serve.ts` hands each load on its input. The key and the token never touch disk. */
|
|
17
18
|
export type ProjectLoad = {
|
|
18
19
|
conversationKey: string;
|
|
20
|
+
sessions: KeptSessionLink;
|
|
19
21
|
edits?: ProjectEdits;
|
|
20
22
|
};
|
|
21
23
|
/** The line this prints once it listens. `serve.ts` waits for it. */
|
package/server/project.js
CHANGED
|
@@ -17,6 +17,7 @@ import { defaultKernelScope } from '@theoremjs/agents';
|
|
|
17
17
|
import { loadSetup } from '@theoremjs/agents/cli';
|
|
18
18
|
import { editedImages, editedQuestions, registerEdits } from "./edits.js";
|
|
19
19
|
import { createStudioHandler } from "./handler.js";
|
|
20
|
+
import { keptSessionStore } from "./kept-sessions.js";
|
|
20
21
|
/** The line this prints once it listens. `serve.ts` waits for it. */
|
|
21
22
|
export const PROJECT_READY = 'theorem-studio-project-ready';
|
|
22
23
|
if (import.meta.main) {
|
|
@@ -46,6 +47,7 @@ if (import.meta.main) {
|
|
|
46
47
|
...(images ? { images } : {}),
|
|
47
48
|
upgrade: (request) => Deno.upgradeWebSocket(request),
|
|
48
49
|
conversationKey: load.conversationKey,
|
|
50
|
+
sessionStore: (profileId) => keptSessionStore(load.sessions, profileId),
|
|
49
51
|
});
|
|
50
52
|
Deno.serve({ hostname: '127.0.0.1', port, onListen: () => console.log(PROJECT_READY) }, handler);
|
|
51
53
|
}
|
package/server/serve.js
CHANGED
|
@@ -29,12 +29,13 @@ import { alertText, keyLine, loadedText } from "./alerts.js";
|
|
|
29
29
|
import { createEditedSession } from "./edited-session.js";
|
|
30
30
|
import { createEventLog, watchRun } from "./events.js";
|
|
31
31
|
import { corsHeaders, isForeign, json, KEYS_PATH, STUDIO_BASE, } from "./handler.js";
|
|
32
|
+
import { createKeptSessions } from "./kept-sessions.js";
|
|
32
33
|
import { answerOpen, chosenEditor, defaultEditor } from "./open-editor.js";
|
|
33
34
|
import { PROJECT_READY } from "./project.js";
|
|
34
35
|
import { entryOf, isInside } from "./project-source.js";
|
|
35
36
|
import { createRuns, untilRead } from "./runs.js";
|
|
36
37
|
import { answerSave, createSaveSession, isSaveRequest } from "./save-session.js";
|
|
37
|
-
import {
|
|
38
|
+
import { createWatchFeed, watchFiles } from "./watch.js";
|
|
38
39
|
function flag(name, fallback) {
|
|
39
40
|
const at = Deno.args.indexOf(`--${name}`);
|
|
40
41
|
return at >= 0 ? (Deno.args[at + 1] ?? fallback) : fallback;
|
|
@@ -69,6 +70,11 @@ async function drain(stream, each) {
|
|
|
69
70
|
}
|
|
70
71
|
/** Seals this run's chats. Every load gets it, so a chat outlives a Save; quitting ends it. */
|
|
71
72
|
const conversationKey = newConversationKey();
|
|
73
|
+
const SESSIONS = `${STUDIO_BASE}/sessions`;
|
|
74
|
+
/** What the chats wait on and run, across loads; quitting ends it. */
|
|
75
|
+
const keptSessions = createKeptSessions();
|
|
76
|
+
/** Replaced loads that still run calls that detached. */
|
|
77
|
+
const leaving = new Set();
|
|
72
78
|
/**
|
|
73
79
|
* Loads the project from disk in a new process, with the builder's unsaved `edits` laid over it
|
|
74
80
|
* when there are some. Throws what it printed when it does not start.
|
|
@@ -93,7 +99,15 @@ async function loadProject(edits) {
|
|
|
93
99
|
stdout: 'piped',
|
|
94
100
|
stderr: 'piped',
|
|
95
101
|
}).spawn();
|
|
96
|
-
const
|
|
102
|
+
const id = crypto.randomUUID();
|
|
103
|
+
const sessions = {
|
|
104
|
+
url: `http://127.0.0.1:${port}${SESSIONS}`,
|
|
105
|
+
token: keptSessions.token,
|
|
106
|
+
load: id,
|
|
107
|
+
scope: edits ? 'edited' : 'files',
|
|
108
|
+
};
|
|
109
|
+
process.status.then(() => keptSessions.loadEnded(id));
|
|
110
|
+
const load = { conversationKey, sessions, ...(edits ? { edits } : {}) };
|
|
97
111
|
const input = process.stdin.getWriter();
|
|
98
112
|
await input.write(new TextEncoder().encode(JSON.stringify(load)));
|
|
99
113
|
await input.close();
|
|
@@ -119,9 +133,9 @@ async function loadProject(edits) {
|
|
|
119
133
|
}
|
|
120
134
|
const origin = `http://127.0.0.1:${childPort}`;
|
|
121
135
|
const description = await (await fetch(origin + STUDIO_BASE)).json();
|
|
122
|
-
return { process, origin, description };
|
|
136
|
+
return { id, process, origin, description };
|
|
123
137
|
}
|
|
124
|
-
async function
|
|
138
|
+
async function end(loaded) {
|
|
125
139
|
try {
|
|
126
140
|
loaded.process.kill();
|
|
127
141
|
}
|
|
@@ -130,6 +144,18 @@ async function stop(loaded) {
|
|
|
130
144
|
}
|
|
131
145
|
await loaded.process.status;
|
|
132
146
|
}
|
|
147
|
+
/** Ends a load the studio no longer needs, once the calls it holds have ended. */
|
|
148
|
+
function stop(loaded) {
|
|
149
|
+
const ended = keptSessions.callsEnd(loaded.id);
|
|
150
|
+
if (!ended)
|
|
151
|
+
return end(loaded);
|
|
152
|
+
leaving.add(loaded);
|
|
153
|
+
void ended.then(() => {
|
|
154
|
+
leaving.delete(loaded);
|
|
155
|
+
return end(loaded);
|
|
156
|
+
});
|
|
157
|
+
return Promise.resolve();
|
|
158
|
+
}
|
|
133
159
|
/** Whether the project type-checks as it is on disk, from the setup and the entry it names, and what the checker printed. */
|
|
134
160
|
async function typeChecks() {
|
|
135
161
|
const entry = entryOf(setupFile);
|
|
@@ -188,8 +214,6 @@ catch (error) {
|
|
|
188
214
|
}
|
|
189
215
|
/** What the loads are running. When it ends the page hears of the files it was not told of. */
|
|
190
216
|
const runs = createRuns(() => void tellChanged());
|
|
191
|
-
/** The chats that hold the load: each is told when a change waits for them. */
|
|
192
|
-
const holds = createEventFeed();
|
|
193
217
|
/** The load that runs the builder's unsaved edits, while the page compares it with the files. */
|
|
194
218
|
const edited = createEditedSession({
|
|
195
219
|
load: loadProject,
|
|
@@ -212,8 +236,6 @@ const session = createSaveSession({
|
|
|
212
236
|
running: runs.busy,
|
|
213
237
|
// The files changed: the edited load lies over files that are gone, once its runs are done.
|
|
214
238
|
whenQuiet: async (swap) => {
|
|
215
|
-
if (runs.busy())
|
|
216
|
-
holds.tell({ saved: true });
|
|
217
239
|
await new Promise((quiet) => runs.whenIdle(quiet));
|
|
218
240
|
await edited.close();
|
|
219
241
|
await new Promise((swapped) => runs.whenIdle(() => {
|
|
@@ -316,7 +338,6 @@ const EVENTS = `${STUDIO_BASE}/events`;
|
|
|
316
338
|
const STATUS = `${STUDIO_BASE}/status`;
|
|
317
339
|
const SAVE = `${STUDIO_BASE}/save`;
|
|
318
340
|
const WATCH = `${STUDIO_BASE}/watch`;
|
|
319
|
-
const HOLD = `${STUDIO_BASE}/hold`;
|
|
320
341
|
const OPEN = `${STUDIO_BASE}/open`;
|
|
321
342
|
const EDITED = `${STUDIO_BASE}/edited`;
|
|
322
343
|
/**
|
|
@@ -474,9 +495,7 @@ if (feed) {
|
|
|
474
495
|
changed: () => session.changed(),
|
|
475
496
|
// why: the page would read files the running load was not read from; the end of the run tells it.
|
|
476
497
|
tell: (files) => {
|
|
477
|
-
if (runs.busy())
|
|
478
|
-
holds.tell({ saved: false });
|
|
479
|
-
else
|
|
498
|
+
if (!runs.busy())
|
|
480
499
|
feed.tell(files);
|
|
481
500
|
},
|
|
482
501
|
watch: (folders) => Deno.watchFs(folders, { recursive: false }),
|
|
@@ -489,16 +508,10 @@ function watching(request) {
|
|
|
489
508
|
const cors = corsHeaders(request, pageOrigins);
|
|
490
509
|
return feed ? feed.subscribe(cors) : new Response(null, { status: 204, headers: cors });
|
|
491
510
|
}
|
|
492
|
-
/**
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
* holds it, not the server: a tab closed on a gate has no answer to wait for.
|
|
497
|
-
*/
|
|
498
|
-
function holding(request) {
|
|
499
|
-
if (request.method !== 'GET' || new URL(request.url).pathname !== HOLD)
|
|
500
|
-
return undefined;
|
|
501
|
-
return untilRead(holds.subscribe(corsHeaders(request, pageOrigins)), runs.begin());
|
|
511
|
+
/** `POST <base>/sessions`: a load reads or writes a kept session. The token says it is one. */
|
|
512
|
+
function keptSession(request) {
|
|
513
|
+
const isOne = request.method === 'POST' && new URL(request.url).pathname === SESSIONS;
|
|
514
|
+
return isOne ? keptSessions.answer(request) : undefined;
|
|
502
515
|
}
|
|
503
516
|
/**
|
|
504
517
|
* `GET <base>/status`: what the command printed when the project opened, as it is now: what
|
|
@@ -515,8 +528,6 @@ async function answerStatus(request) {
|
|
|
515
528
|
headers: { 'content-type': 'text/plain; charset=utf-8', ...corsHeaders(request, pageOrigins) },
|
|
516
529
|
});
|
|
517
530
|
}
|
|
518
|
-
/** The longest error the page may send. */
|
|
519
|
-
const PAGE_ERROR_BYTES = 8000;
|
|
520
531
|
/**
|
|
521
532
|
* The event log: `GET` lists it, `GET ?follow` streams it, and the page `POST`s `{ text }` for an
|
|
522
533
|
* error it met, which the log keeps as the page's.
|
|
@@ -535,10 +546,7 @@ async function answerEvents(request) {
|
|
|
535
546
|
}
|
|
536
547
|
/** Keeps the error a page `POST`s as `{ text }`. */
|
|
537
548
|
async function keepPageError(request, cors) {
|
|
538
|
-
const
|
|
539
|
-
if (sent.length > PAGE_ERROR_BYTES)
|
|
540
|
-
return json(413, {}, cors);
|
|
541
|
-
const text = pageError(sent);
|
|
549
|
+
const text = pageError(await request.text());
|
|
542
550
|
if (!text)
|
|
543
551
|
return json(400, {}, cors);
|
|
544
552
|
tell('page', `the page: ${text}`);
|
|
@@ -572,9 +580,9 @@ async function answered(request) {
|
|
|
572
580
|
}
|
|
573
581
|
/** The studio's own routes, in the order they are asked; a request none answers goes to the project. */
|
|
574
582
|
const ROUTES = [
|
|
583
|
+
keptSession,
|
|
575
584
|
running,
|
|
576
585
|
watching,
|
|
577
|
-
holding,
|
|
578
586
|
openedSaying,
|
|
579
587
|
answerStatus,
|
|
580
588
|
answerEvents,
|
|
@@ -593,7 +601,7 @@ Deno.serve({ hostname: '127.0.0.1', port, onListen: () => { } }, async (request)
|
|
|
593
601
|
});
|
|
594
602
|
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
595
603
|
Deno.addSignalListener(signal, () => {
|
|
596
|
-
for (const loaded of [session.project(), edited.running()]) {
|
|
604
|
+
for (const loaded of [session.project(), edited.running(), ...leaving]) {
|
|
597
605
|
try {
|
|
598
606
|
loaded?.process.kill();
|
|
599
607
|
}
|
|
@@ -127,12 +127,12 @@ async function fetchWithTimeout(url, init, guard) {
|
|
|
127
127
|
}
|
|
128
128
|
function previewResponseBody(text, contentType) {
|
|
129
129
|
if (!contentType.includes('application/json'))
|
|
130
|
-
return text
|
|
130
|
+
return text;
|
|
131
131
|
try {
|
|
132
|
-
return JSON.stringify(JSON.parse(text), null, 2)
|
|
132
|
+
return JSON.stringify(JSON.parse(text), null, 2);
|
|
133
133
|
}
|
|
134
134
|
catch {
|
|
135
|
-
return text
|
|
135
|
+
return text;
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
@@ -219,14 +219,14 @@ function nonJsonAttempt(res, text, protocolVersion, start) {
|
|
|
219
219
|
if (!res.ok &&
|
|
220
220
|
text.toLowerCase().includes('unsupported protocol version') &&
|
|
221
221
|
protocolVersion !== MCP_PROTOCOL_VERSIONS.at(-1)) {
|
|
222
|
-
return { status: res.status, protocolError: { code: -32600, message: text
|
|
222
|
+
return { status: res.status, protocolError: { code: -32600, message: text } };
|
|
223
223
|
}
|
|
224
224
|
return {
|
|
225
225
|
response: Response.json({
|
|
226
226
|
ok: false,
|
|
227
227
|
status: res.status,
|
|
228
228
|
code: 'invalid_json',
|
|
229
|
-
error: `MCP server returned non-JSON response: ${text
|
|
229
|
+
error: `MCP server returned non-JSON response: ${text}`,
|
|
230
230
|
elapsedMs: elapsedSince(start),
|
|
231
231
|
}),
|
|
232
232
|
};
|
|
@@ -261,7 +261,7 @@ function mcpAnswerResponse(body, res, rpcData, protocolVersion, start) {
|
|
|
261
261
|
toolCount: tools.length,
|
|
262
262
|
tools: toolNames,
|
|
263
263
|
targetToolFound: targetName ? toolNames.includes(targetName) : undefined,
|
|
264
|
-
preview: JSON.stringify(rpcData.result ?? rpcData, null, 2)
|
|
264
|
+
preview: JSON.stringify(rpcData.result ?? rpcData, null, 2),
|
|
265
265
|
elapsedMs: elapsedSince(start),
|
|
266
266
|
});
|
|
267
267
|
}
|
package/ui/lib/studio-watch.d.ts
CHANGED
|
@@ -10,9 +10,3 @@ export declare function subscribeToFiles(endpoint: string, on: {
|
|
|
10
10
|
open: () => void;
|
|
11
11
|
files: (files: string[]) => void;
|
|
12
12
|
}): () => void;
|
|
13
|
-
/**
|
|
14
|
-
* Holds the project's load until the answer is called: the studio does not replace it, so what
|
|
15
|
-
* waits in it can still be answered. `onChange` when a change waits for that, `saved` when the
|
|
16
|
-
* builder saved it here and not in their editor.
|
|
17
|
-
*/
|
|
18
|
-
export declare function holdLoad(endpoint: string, onChange: (saved: boolean) => void): () => void;
|
package/ui/lib/studio-watch.js
CHANGED
|
@@ -25,19 +25,3 @@ export function subscribeToFiles(endpoint, on) {
|
|
|
25
25
|
source.close();
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Holds the project's load until the answer is called: the studio does not replace it, so what
|
|
30
|
-
* waits in it can still be answered. `onChange` when a change waits for that, `saved` when the
|
|
31
|
-
* builder saved it here and not in their editor.
|
|
32
|
-
*/
|
|
33
|
-
export function holdLoad(endpoint, onChange) {
|
|
34
|
-
if (typeof EventSource === 'undefined')
|
|
35
|
-
return () => undefined;
|
|
36
|
-
const source = new EventSource(`${endpoint}/hold`);
|
|
37
|
-
source.onmessage = (event) => {
|
|
38
|
-
onChange(JSON.parse(event.data).saved);
|
|
39
|
-
};
|
|
40
|
-
return () => {
|
|
41
|
-
source.close();
|
|
42
|
-
};
|
|
43
|
-
}
|
package/ui/studio-compare.js
CHANGED
|
@@ -20,11 +20,8 @@ import { runsAsConversation } from "./lib/conversation-types.js";
|
|
|
20
20
|
import { tracedTransport } from "./lib/project-traces.js";
|
|
21
21
|
import { noting } from "./lib/studio-activity.js";
|
|
22
22
|
import { STUDIO_LABELS } from "./lib/studio-labels.js";
|
|
23
|
-
import { getPref } from "./lib/studio-prefs.js";
|
|
24
23
|
import { editedProfileEndpoint, openEdited, projectProfileEndpoint, } from "./lib/studio-project.js";
|
|
25
|
-
import { holdLoad } from "./lib/studio-watch.js";
|
|
26
24
|
import { RefusalDetail } from "./refusal-detail.js";
|
|
27
|
-
import { useProjectSave } from "./studio-save.js";
|
|
28
25
|
const SIDES = ['saved', 'edited'];
|
|
29
26
|
/** Why the edits are not running, as the builder reads it. */
|
|
30
27
|
const NOT_RUNNING = {
|
|
@@ -129,27 +126,6 @@ function usePair() {
|
|
|
129
126
|
}, []);
|
|
130
127
|
return { busy, send, stop, refs, handles, chats, states };
|
|
131
128
|
}
|
|
132
|
-
/**
|
|
133
|
-
* Holds the project's load until a reply is done, so the answer to a gate reaches the load that
|
|
134
|
-
* asked. Answers whether a change waits for that.
|
|
135
|
-
*/
|
|
136
|
-
function useLoadHold(endpoint, isBusy) {
|
|
137
|
-
const [changeWaits, setChangeWaits] = useState(false);
|
|
138
|
-
useEffect(() => {
|
|
139
|
-
if (!isBusy)
|
|
140
|
-
return undefined;
|
|
141
|
-
const release = holdLoad(endpoint, (saved) => {
|
|
142
|
-
// why: with the watch off the page does not read an editor's change, answered or not.
|
|
143
|
-
if (saved || getPref('watch') === 'on')
|
|
144
|
-
setChangeWaits(true);
|
|
145
|
-
});
|
|
146
|
-
return () => {
|
|
147
|
-
release();
|
|
148
|
-
setChangeWaits(false);
|
|
149
|
-
};
|
|
150
|
-
}, [endpoint, isBusy]);
|
|
151
|
-
return changeWaits;
|
|
152
|
-
}
|
|
153
129
|
/** Whether the files' side is put away, for every comparison in this tab. */
|
|
154
130
|
const savedSide = { isHidden: false, listeners: new Set() };
|
|
155
131
|
function setSavedHidden(isHidden) {
|
|
@@ -582,16 +558,6 @@ export function ProjectChat(props) {
|
|
|
582
558
|
const { showsSaved, isShared, only } = useShownSides(view);
|
|
583
559
|
const sharedInput = useRef(null);
|
|
584
560
|
useChatHandle(chatRef, pair, only, !isBusy && isReady, sharedInput);
|
|
585
|
-
const gated = pair.busy.filter((side) => pair.states[side]?.phase === 'gated');
|
|
586
|
-
// why: a gate its answer failed on may be gone; held, the change would wait for no answer.
|
|
587
|
-
const isHeld = pair.busy.some((side) => !gated.includes(side) || pair.states[side]?.failure === null);
|
|
588
|
-
const changeWaits = useLoadHold(props.project.endpoint, isHeld);
|
|
589
|
-
const setGateWaits = useProjectSave()?.setGateWaits;
|
|
590
|
-
const isGated = gated.length > 0;
|
|
591
|
-
useEffect(() => {
|
|
592
|
-
setGateWaits?.(isGated);
|
|
593
|
-
return () => setGateWaits?.(false);
|
|
594
|
-
}, [setGateWaits, isGated]);
|
|
595
561
|
const shared = openSides(pair);
|
|
596
562
|
const common = {
|
|
597
563
|
detectCodeLanguage: true,
|
|
@@ -617,5 +583,5 @@ export function ProjectChat(props) {
|
|
|
617
583
|
// A new load is a new transport: the chat reads it in place and keeps its transcript.
|
|
618
584
|
transport: transports.edited, conversation: view.conversations.current.edited ?? view.conversations.current.saved, onConversationChange: view.onChange.edited,
|
|
619
585
|
// Under a refusal nothing reaches it: the edits it ran are not loaded.
|
|
620
|
-
chatRef: refused ? undefined : pair.refs.edited })) }) }, "edited"))] }) }),
|
|
586
|
+
chatRef: refused ? undefined : pair.refs.edited })) }) }, "edited"))] }) }), isShared && (_jsx(SharedSlot, { sides: shared, edited: isReady ? (pair.states.edited ?? undefined) : undefined, inputRef: sharedInput, handle: profileId, why: whyNot(refused !== undefined, isReady) }))] }));
|
|
621
587
|
}
|
package/ui/studio-save.d.ts
CHANGED
|
@@ -17,8 +17,6 @@ export interface ProjectSaveActions {
|
|
|
17
17
|
* studio holds no edits.
|
|
18
18
|
*/
|
|
19
19
|
discard: (() => void) | undefined;
|
|
20
|
-
/** Says whether a chat stands on a gate: Save waits for its answer. */
|
|
21
|
-
setGateWaits: (waits: boolean) => void;
|
|
22
20
|
}
|
|
23
21
|
/** Save for the open project, or null on a page that has none. */
|
|
24
22
|
export declare function useProjectSave(): ProjectSaveActions | null;
|
package/ui/studio-save.js
CHANGED
|
@@ -214,8 +214,6 @@ function ProjectProblems({ project, unloaded }) {
|
|
|
214
214
|
.map((each) => each.name)
|
|
215
215
|
.join(', ')}${unregistered.length > 5 ? `, and ${unregistered.length - 5} more` : ''}. A run and Save still use your files. If none of them load, the studio is probably reading a second copy of the Theorem package.` })] })), unheld.length > 0 && (_jsxs(VStack, { gap: 1, children: [_jsx(Text, { weight: "semibold", children: "The studio cannot check what it shows against your files." }), _jsx(Text, { type: "supporting", color: "secondary", children: `A run and Save still use your files. ${[...new Set(unheld)].join(' ')}${unregistered.length > 0 ? ' This usually follows from the profiles above not loading.' : ''}` })] })), differences.map((difference) => (_jsxs(VStack, { gap: 1, children: [_jsx(Text, { weight: "semibold", children: `The studio shows ${difference.of} differently from your files.` }), _jsx(Text, { type: "supporting", color: "secondary", children: `${difference.settings.length} ${difference.settings.length === 1 ? 'setting differs' : 'settings differ'}: ${settingAreas(difference.settings)}. A run and Save still use your files.` })] }, `${difference.kind}:${difference.of}`)))] }) }), children: _jsx(Token, { label: count === 1 ? '1 alert' : `${String(count)} alerts`, color: "orange" }) }));
|
|
216
216
|
}
|
|
217
|
-
/** Why Save waits while a chat stands on a gate. */
|
|
218
|
-
const GATE_WAITS = 'A chat is waiting for your answer. Answer it, then save.';
|
|
219
217
|
const ProjectSaveContext = createContext(null);
|
|
220
218
|
/** Save for the open project, or null on a page that has none. */
|
|
221
219
|
export function useProjectSave() {
|
|
@@ -250,7 +248,6 @@ export function ProjectSave({ project, workspace, update, onFilesChanged, onDisc
|
|
|
250
248
|
const [step, setStep] = useState({ at: 'closed' });
|
|
251
249
|
const [view, setView] = useState('all');
|
|
252
250
|
const [asking, setAsking] = useState(false);
|
|
253
|
-
const [gateWaits, setGateWaits] = useState(false);
|
|
254
251
|
// An agent or provider added here is at its own start, and still one the files do not hold.
|
|
255
252
|
// One removed here has no start left, and is still one the files hold.
|
|
256
253
|
const clean = useMemo(() => atStart(workspace) &&
|
|
@@ -322,7 +319,6 @@ export function ProjectSave({ project, workspace, update, onFilesChanged, onDisc
|
|
|
322
319
|
review: blocked ? undefined : open,
|
|
323
320
|
clear,
|
|
324
321
|
discard: clean ? undefined : ask,
|
|
325
|
-
setGateWaits,
|
|
326
322
|
}), [unsaved, blocked, open, clear, clean, ask]);
|
|
327
323
|
const writing = step.at === 'review' && step.writing;
|
|
328
324
|
const refusal = step.at === 'refused' || step.at === 'review' ? step.refusal : undefined;
|
|
@@ -332,16 +328,12 @@ export function ProjectSave({ project, workspace, update, onFilesChanged, onDisc
|
|
|
332
328
|
setStep({ at: 'closed' });
|
|
333
329
|
}, children: _jsx(Layout, { header: _jsx(DialogHeader, { title: `Save to ${project.name}`, subtitle: writing
|
|
334
330
|
? 'Checking that the project still loads with these lines.'
|
|
335
|
-
:
|
|
336
|
-
? GATE_WAITS
|
|
337
|
-
: 'Save writes all of these lines or none. It then type-checks and loads the project, and puts your files back unless it runs as what you tested.', endContent: step.at === 'review' &&
|
|
331
|
+
: 'Save writes all of these lines or none. It then type-checks and loads the project, and puts your files back unless it runs as what you tested.', endContent: step.at === 'review' &&
|
|
338
332
|
step.review.files.length > 1 && (_jsx(IconButton, { label: flip.label, variant: "ghost", icon: _jsx(Icon, { icon: flip.icon, size: "sm" }), tooltip: flip.tooltip, onClick: () => {
|
|
339
333
|
setView(flip.next);
|
|
340
334
|
} })), onOpenChange: writing ? undefined : () => setStep({ at: 'closed' }) }), content: _jsx(LayoutContent, { isScrollable: false, padding: 0, children: _jsx(ScrollableArea, { label: "Changes", height: "100%", paddingInline: 4, children: _jsxs(VStack, { gap: 4, children: [refusal && _jsx(RefusalBody, { refusal: refusal }), step.at === 'review' && _jsx(ReviewBody, { review: step.review, view: view })] }) }) }), footer: _jsx(LayoutFooter, { children: _jsxs(HStack, { gap: 2, justify: "between", children: [_jsx(Button, { label: "Discard all", variant: "ghost", isDisabled: writing || clean, onClick: ask }), _jsxs(HStack, { gap: 2, children: [_jsx(Button, { label: "Cancel", variant: "ghost", isDisabled: writing, onClick: () => {
|
|
341
335
|
setStep({ at: 'closed' });
|
|
342
|
-
} }), step.at === 'review' && (_jsx(Button, { label: "Save", variant: "primary",
|
|
343
|
-
// why: a save waits for the load's gate, and this dialog covers the gate.
|
|
344
|
-
isDisabled: !step.review.writable || gateWaits, isLoading: writing, onClick: () => {
|
|
336
|
+
} }), step.at === 'review' && (_jsx(Button, { label: "Save", variant: "primary", isDisabled: !step.review.writable, isLoading: writing, onClick: () => {
|
|
345
337
|
write(step.review);
|
|
346
338
|
} }))] })] }) }) }) }), _jsx(AlertDialog, { isOpen: asking, onOpenChange: setAsking, title: "Discard every unsaved edit?", description: "The project goes back to its files. Undo in the next message brings the edits back.", actionLabel: "Discard all", actionVariant: "destructive", onAction: () => {
|
|
347
339
|
setAsking(false);
|