@mcpview/compose 0.14.0 → 0.15.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/CHANGELOG.md +110 -1
- package/README.md +116 -24
- package/esm/src/code-mode/engine.d.ts +59 -0
- package/esm/src/code-mode/engine.d.ts.map +1 -0
- package/esm/src/code-mode/engine.js +189 -0
- package/esm/src/code-mode/guest-worker.d.ts +2 -5
- package/esm/src/code-mode/guest-worker.d.ts.map +1 -1
- package/esm/src/code-mode/guest-worker.js +4 -75
- package/esm/src/code-mode/sandbox-api.d.ts +37 -0
- package/esm/src/code-mode/sandbox-api.d.ts.map +1 -0
- package/esm/src/code-mode/sandbox-api.js +36 -0
- package/esm/src/code-mode/sandbox-core.d.ts +99 -21
- package/esm/src/code-mode/sandbox-core.d.ts.map +1 -1
- package/esm/src/code-mode/sandbox-core.js +926 -221
- package/esm/src/code-mode/sandbox-worker.d.ts +37 -0
- package/esm/src/code-mode/sandbox-worker.d.ts.map +1 -0
- package/esm/src/code-mode/sandbox-worker.js +140 -0
- package/esm/src/code-mode/sandbox.d.ts +142 -29
- package/esm/src/code-mode/sandbox.d.ts.map +1 -1
- package/esm/src/code-mode/sandbox.js +402 -68
- package/esm/src/code-mode/surface.d.ts +148 -0
- package/esm/src/code-mode/surface.d.ts.map +1 -0
- package/esm/src/code-mode/surface.js +204 -0
- package/esm/src/code-mode/tool.js +1 -1
- package/esm/src/code-mode/worker-host.d.ts +51 -11
- package/esm/src/code-mode/worker-host.d.ts.map +1 -1
- package/esm/src/code-mode/worker-host.js +114 -48
- package/esm/src/code-mode/worker-protocol.d.ts +45 -8
- package/esm/src/code-mode/worker-protocol.d.ts.map +1 -1
- package/esm/src/code-mode/worker-protocol.js +4 -2
- package/esm/src/version.d.ts +1 -1
- package/esm/src/version.js +1 -1
- package/package.json +9 -1
- package/script/src/code-mode/engine.d.ts +59 -0
- package/script/src/code-mode/engine.d.ts.map +1 -0
- package/script/src/code-mode/engine.js +198 -0
- package/script/src/code-mode/guest-worker.d.ts +2 -5
- package/script/src/code-mode/guest-worker.d.ts.map +1 -1
- package/script/src/code-mode/guest-worker.js +4 -98
- package/script/src/code-mode/sandbox-api.d.ts +37 -0
- package/script/src/code-mode/sandbox-api.d.ts.map +1 -0
- package/script/src/code-mode/sandbox-api.js +50 -0
- package/script/src/code-mode/sandbox-core.d.ts +99 -21
- package/script/src/code-mode/sandbox-core.d.ts.map +1 -1
- package/script/src/code-mode/sandbox-core.js +931 -221
- package/script/src/code-mode/sandbox-worker.d.ts +37 -0
- package/script/src/code-mode/sandbox-worker.d.ts.map +1 -0
- package/script/src/code-mode/sandbox-worker.js +166 -0
- package/script/src/code-mode/sandbox.d.ts +142 -29
- package/script/src/code-mode/sandbox.d.ts.map +1 -1
- package/script/src/code-mode/sandbox.js +432 -73
- package/script/src/code-mode/surface.d.ts +148 -0
- package/script/src/code-mode/surface.d.ts.map +1 -0
- package/script/src/code-mode/surface.js +211 -0
- package/script/src/code-mode/tool.js +1 -1
- package/script/src/code-mode/worker-host.d.ts +51 -11
- package/script/src/code-mode/worker-host.d.ts.map +1 -1
- package/script/src/code-mode/worker-host.js +115 -47
- package/script/src/code-mode/worker-protocol.d.ts +45 -8
- package/script/src/code-mode/worker-protocol.d.ts.map +1 -1
- package/script/src/code-mode/worker-protocol.js +4 -2
- package/script/src/version.d.ts +1 -1
- package/script/src/version.js +1 -1
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import * as dntShim from "../../_dnt.shims.js";
|
|
12
12
|
import { CodeModeError, codeModeErrorFromFields } from "./errors.js";
|
|
13
|
-
import {
|
|
13
|
+
import { encodeHostValue, HostErrorCarrier, operationFailed, } from "./sandbox-core.js";
|
|
14
14
|
/** Time a stopped guest has to report before the host gives up on it. */
|
|
15
15
|
const STOP_GRACE_MS = 250;
|
|
16
16
|
function workerRuntime(scope = dntShim.dntGlobalThis) {
|
|
@@ -26,7 +26,7 @@ function workerRuntime(scope = dntShim.dntGlobalThis) {
|
|
|
26
26
|
* Why worker isolation cannot run here, or undefined when it can. `scope` is the
|
|
27
27
|
* global object to inspect.
|
|
28
28
|
*/
|
|
29
|
-
export function workerIsolationUnavailable(scope = dntShim.dntGlobalThis) {
|
|
29
|
+
export function workerIsolationUnavailable(scope = dntShim.dntGlobalThis, worker = guestUrl()) {
|
|
30
30
|
if (typeof SharedArrayBuffer !== "function")
|
|
31
31
|
return "SharedArrayBuffer is not available";
|
|
32
32
|
const runtime = workerRuntime(scope);
|
|
@@ -38,7 +38,7 @@ export function workerIsolationUnavailable(scope = dntShim.dntGlobalThis) {
|
|
|
38
38
|
if (runtime === "node") {
|
|
39
39
|
return nodeWorkerPermission(scope.process);
|
|
40
40
|
}
|
|
41
|
-
return denoWorkerPermission();
|
|
41
|
+
return denoWorkerPermission(worker);
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* Why Node's enforced permission model forbids workers, or undefined. Audit mode
|
|
@@ -61,21 +61,29 @@ export function nodeWorkerPermission(process) {
|
|
|
61
61
|
return undefined;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* The permission Deno needs to load the guest module, or undefined for schemes it does
|
|
66
|
+
* not gate. An import query must name the port: a bare `jsr.io` asks about every port
|
|
67
|
+
* and reads "prompt", although Deno grants `jsr.io:443` by default.
|
|
68
|
+
*/
|
|
69
|
+
export function guestModulePermission(url) {
|
|
70
|
+
if (url.protocol === "file:")
|
|
71
|
+
return { name: "read", path: url };
|
|
72
|
+
if (url.protocol !== "https:" && url.protocol !== "http:")
|
|
73
|
+
return undefined;
|
|
74
|
+
const port = url.port || (url.protocol === "https:" ? "443" : "80");
|
|
75
|
+
return { name: "import", host: `${url.hostname}:${port}` };
|
|
76
|
+
}
|
|
64
77
|
/**
|
|
65
78
|
* A Deno worker inherits the host's permissions and must be able to load its module.
|
|
66
|
-
* Only the module itself is checked:
|
|
79
|
+
* Only the module itself is checked: the modules it imports are not.
|
|
67
80
|
*/
|
|
68
|
-
function denoWorkerPermission() {
|
|
81
|
+
function denoWorkerPermission(url) {
|
|
69
82
|
const deno = dntShim.dntGlobalThis.Deno;
|
|
70
83
|
const query = deno?.permissions?.querySync;
|
|
71
84
|
if (!query)
|
|
72
85
|
return undefined;
|
|
73
|
-
const
|
|
74
|
-
const descriptor = url.protocol === "file:"
|
|
75
|
-
? { name: "read", path: url }
|
|
76
|
-
: url.protocol === "https:" || url.protocol === "http:"
|
|
77
|
-
? { name: "import", host: url.host }
|
|
78
|
-
: undefined;
|
|
86
|
+
const descriptor = guestModulePermission(url);
|
|
79
87
|
if (!descriptor)
|
|
80
88
|
return undefined;
|
|
81
89
|
try {
|
|
@@ -180,26 +188,31 @@ function guestUrl() {
|
|
|
180
188
|
function importNodeBuiltin(name) {
|
|
181
189
|
return import(`node:${name}`);
|
|
182
190
|
}
|
|
183
|
-
async function spawn(onMessage,
|
|
191
|
+
async function spawn(onMessage,
|
|
192
|
+
/** `ended` is true when the worker's module ran to its end and the thread exited by itself. */
|
|
193
|
+
onFailure, url) {
|
|
184
194
|
if (workerRuntime() === "node") {
|
|
185
195
|
const { Worker } = await importNodeBuiltin("worker_threads");
|
|
186
196
|
const process = dntShim.dntGlobalThis.process;
|
|
187
|
-
const worker = new Worker(
|
|
197
|
+
const worker = new Worker(url, {
|
|
188
198
|
execArgv: nodeWorkerExecArgv(process?.execArgv ?? []),
|
|
189
199
|
env: nodeWorkerEnv(process?.env ?? {}),
|
|
190
200
|
});
|
|
201
|
+
// A thread with nothing left to do exits with code 0: under Node that is
|
|
202
|
+
// how a module that never served the sandbox ends. Deno keeps it alive.
|
|
203
|
+
const onExit = (code) => onFailure(code === 0);
|
|
191
204
|
worker.on("message", onMessage);
|
|
192
|
-
worker.on("error", onFailure);
|
|
193
|
-
worker.on("exit",
|
|
205
|
+
worker.on("error", () => onFailure());
|
|
206
|
+
worker.on("exit", onExit);
|
|
194
207
|
return {
|
|
195
208
|
post: (message) => worker.postMessage(message),
|
|
196
209
|
terminate: () => {
|
|
197
|
-
worker.off("exit",
|
|
210
|
+
worker.off("exit", onExit);
|
|
198
211
|
void worker.terminate();
|
|
199
212
|
},
|
|
200
213
|
};
|
|
201
214
|
}
|
|
202
|
-
const worker = new Worker(
|
|
215
|
+
const worker = new Worker(url, { type: "module" });
|
|
203
216
|
worker.onmessage = (event) => onMessage(event.data);
|
|
204
217
|
worker.onerror = (event) => {
|
|
205
218
|
event.preventDefault();
|
|
@@ -213,27 +226,18 @@ async function spawn(onMessage, onFailure) {
|
|
|
213
226
|
* posted, so an oversized result never crosses the worker boundary (no parse and
|
|
214
227
|
* no structured clone). The guest decodes the text.
|
|
215
228
|
*/
|
|
216
|
-
export function encodeReply(id, operation, value, valueLength
|
|
217
|
-
|
|
229
|
+
export function encodeReply(id, operation, value, valueLength, namespace,
|
|
230
|
+
/** True when the host completed the call and its effect cannot be undone. */
|
|
231
|
+
irreversible = false) {
|
|
232
|
+
const done = irreversible ? { irreversible: true } : {};
|
|
218
233
|
try {
|
|
219
|
-
//
|
|
220
|
-
json =
|
|
221
|
-
|
|
222
|
-
catch {
|
|
223
|
-
json = undefined;
|
|
224
|
-
}
|
|
225
|
-
if (json === undefined) {
|
|
226
|
-
return {
|
|
227
|
-
type: "reply",
|
|
228
|
-
id,
|
|
229
|
-
ok: false,
|
|
230
|
-
error: new CodeModeError("OPERATION_FAILED", `api.${operation} returned a value that is not JSON`, "Return plain JSON from the host operation").toJSON(),
|
|
231
|
-
};
|
|
234
|
+
// The same rule as the inline path: one function decides what crosses.
|
|
235
|
+
const json = encodeHostValue(namespace, operation, value, valueLength);
|
|
236
|
+
return { type: "reply", id, ok: true, json, ...done };
|
|
232
237
|
}
|
|
233
|
-
|
|
234
|
-
return { type: "reply", id, ok: false, error:
|
|
238
|
+
catch (error) {
|
|
239
|
+
return { type: "reply", id, ok: false, error: error.toJSON(), ...done };
|
|
235
240
|
}
|
|
236
|
-
return { type: "reply", id, ok: true, json };
|
|
237
241
|
}
|
|
238
242
|
/** The error for a worker that could not be created at all. */
|
|
239
243
|
export function workerSpawnFailure(error) {
|
|
@@ -243,17 +247,30 @@ export function workerSpawnFailure(error) {
|
|
|
243
247
|
}
|
|
244
248
|
return sandboxFailed();
|
|
245
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* The error for a worker that loaded but never reported: it stayed silent for
|
|
252
|
+
* the wall time of the program (`wallMs`), or its module ran to its end and
|
|
253
|
+
* the thread exited. No program ran, so this is no time limit of the program.
|
|
254
|
+
*/
|
|
255
|
+
export function workerNotStarted(wallMs) {
|
|
256
|
+
return new CodeModeError("SANDBOX_FAILED", wallMs === undefined
|
|
257
|
+
? "The Code Mode worker ended without serving the sandbox"
|
|
258
|
+
: `The Code Mode worker did not start within ${wallMs} ms`, 'Check that the worker module loads and that its entry calls serveSandboxWorker, or configure isolation: "inline"', { context: { worker: "not-started", ...(wallMs !== undefined && { ms: wallMs }) } });
|
|
259
|
+
}
|
|
246
260
|
function sandboxFailed() {
|
|
247
261
|
return new CodeModeError("SANDBOX_FAILED", "The Code Mode worker stopped unexpectedly", 'Run the program again. If the worker module cannot be loaded (a bundle without it, or a missing read or import permission), grant access to it or configure isolation: "inline"');
|
|
248
262
|
}
|
|
249
263
|
/**
|
|
250
|
-
* Run one program in a fresh worker and settle once with
|
|
264
|
+
* Run one program in a fresh worker and settle once: with the JSON text of
|
|
265
|
+
* what the program returned (undefined when it returned nothing), or with a
|
|
251
266
|
* {@link CodeModeError}. The worker is always terminated afterwards.
|
|
252
267
|
*
|
|
253
268
|
* @example
|
|
254
269
|
* ```ts
|
|
255
|
-
* const
|
|
256
|
-
* code: "return 1 + 1;",
|
|
270
|
+
* const json = await runInWorker({
|
|
271
|
+
* code: "return 1 + 1;",
|
|
272
|
+
* surface: { namespace: "api", operations: {}, budgets: {} },
|
|
273
|
+
* limits: SANDBOX_RESOURCE_LIMITS,
|
|
257
274
|
* call: () => Promise.reject(new Error("unused")), signal: new AbortController().signal,
|
|
258
275
|
* });
|
|
259
276
|
* ```
|
|
@@ -263,6 +280,8 @@ export function runInWorker(input) {
|
|
|
263
280
|
return new Promise((resolve, reject) => {
|
|
264
281
|
let port;
|
|
265
282
|
let settled = false;
|
|
283
|
+
/** True once the worker reported: there is a guest that may need time to stop. */
|
|
284
|
+
let ready = false;
|
|
266
285
|
let grace;
|
|
267
286
|
const finish = (outcome) => {
|
|
268
287
|
if (settled)
|
|
@@ -274,6 +293,11 @@ export function runInWorker(input) {
|
|
|
274
293
|
port?.terminate();
|
|
275
294
|
};
|
|
276
295
|
function stop() {
|
|
296
|
+
if (!ready) {
|
|
297
|
+
// No guest to wait for: the worker never reported.
|
|
298
|
+
finish(() => reject(input.signal.reason));
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
277
301
|
Atomics.store(cancel, 0, 1);
|
|
278
302
|
// A guest blocked in a host call is released by that call's own abort;
|
|
279
303
|
// one stuck in a native operation gets a grace period, then is dropped.
|
|
@@ -302,14 +326,46 @@ export function runInWorker(input) {
|
|
|
302
326
|
}
|
|
303
327
|
switch (message.type) {
|
|
304
328
|
case "ready":
|
|
329
|
+
// A worker reports once: a second report starts nothing.
|
|
330
|
+
if (ready)
|
|
331
|
+
return;
|
|
332
|
+
ready = true;
|
|
333
|
+
input.started?.();
|
|
305
334
|
send({
|
|
306
335
|
type: "run",
|
|
307
336
|
code: input.code,
|
|
308
|
-
|
|
337
|
+
surface: input.surface,
|
|
309
338
|
limits: input.limits,
|
|
339
|
+
referenceKey: input.referenceKey,
|
|
340
|
+
asksAboutUnsent: input.unsent !== undefined,
|
|
310
341
|
cancel: cancel.buffer,
|
|
311
342
|
});
|
|
312
343
|
return;
|
|
344
|
+
case "unsent": {
|
|
345
|
+
// The guest asks only when the host said it decides.
|
|
346
|
+
const decide = input.unsent;
|
|
347
|
+
if (!decide) {
|
|
348
|
+
finish(() => reject(sandboxFailed()));
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
decide(message.calls).then(() => {
|
|
352
|
+
if (!settled)
|
|
353
|
+
send({ type: "unsent-reply", ok: true });
|
|
354
|
+
}, (error) => {
|
|
355
|
+
if (settled)
|
|
356
|
+
return;
|
|
357
|
+
if (error instanceof CodeModeError) {
|
|
358
|
+
send({
|
|
359
|
+
type: "unsent-reply",
|
|
360
|
+
ok: false,
|
|
361
|
+
error: CodeModeError.prototype.toJSON.call(error),
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
else
|
|
365
|
+
finish(() => reject(sandboxFailed()));
|
|
366
|
+
});
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
313
369
|
case "call": {
|
|
314
370
|
const { id } = message;
|
|
315
371
|
// Building a reply runs host-controlled code (a provider error's own
|
|
@@ -324,25 +380,35 @@ export function runInWorker(input) {
|
|
|
324
380
|
finish(() => reject(sandboxFailed()));
|
|
325
381
|
}
|
|
326
382
|
};
|
|
327
|
-
input.call(message.operation, message.args).then((value) => reply(() => encodeReply(id, message.operation, value, input.limits.valueLength)), (error) => reply(() =>
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
383
|
+
input.call(message.operation, message.args, id).then((value) => reply(() => encodeReply(id, message.operation, value, input.limits.valueLength, input.surface.namespace, input.mustDeliver?.(id) === true)), (error) => reply(() => {
|
|
384
|
+
// The worker rebuilds the carrier from the call it is waiting on.
|
|
385
|
+
if (error instanceof HostErrorCarrier) {
|
|
386
|
+
return { type: "reply", id, ok: false, host: error.shown };
|
|
387
|
+
}
|
|
388
|
+
const failure = error instanceof CodeModeError
|
|
389
|
+
? error
|
|
390
|
+
: operationFailed(input.surface.namespace, message.operation);
|
|
391
|
+
return {
|
|
392
|
+
type: "reply",
|
|
393
|
+
id,
|
|
394
|
+
ok: false,
|
|
395
|
+
// The base serializer reads plain fields: a subclass cannot override it.
|
|
396
|
+
error: CodeModeError.prototype.toJSON.call(failure),
|
|
397
|
+
};
|
|
398
|
+
}));
|
|
334
399
|
return;
|
|
335
400
|
}
|
|
336
401
|
case "done":
|
|
337
402
|
// A guest can finish during the stop grace period: an abort still wins.
|
|
338
|
-
finish(() => input.signal.aborted ? reject(input.signal.reason) : resolve(message.
|
|
403
|
+
finish(() => input.signal.aborted ? reject(input.signal.reason) : resolve(message.json));
|
|
339
404
|
return;
|
|
340
405
|
case "fail":
|
|
341
406
|
finish(() => reject(codeModeErrorFromFields(message.error) ?? sandboxFailed()));
|
|
342
407
|
return;
|
|
343
408
|
}
|
|
344
409
|
};
|
|
345
|
-
|
|
410
|
+
const onFailure = (ended = false) => finish(() => reject(ended && !ready ? workerNotStarted() : sandboxFailed()));
|
|
411
|
+
spawn(onMessage, onFailure, input.worker ?? guestUrl()).then((spawned) => {
|
|
346
412
|
if (settled) {
|
|
347
413
|
spawned.terminate();
|
|
348
414
|
return;
|
|
@@ -1,30 +1,59 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Messages between the host and the Code Mode guest worker.
|
|
3
|
-
*
|
|
2
|
+
* Messages between the host and the Code Mode guest worker. Every value of a
|
|
3
|
+
* program crosses as JSON text, never as a tree of objects: copying a tree
|
|
4
|
+
* between threads has a nesting limit of its own, which the other isolation
|
|
5
|
+
* does not have. One SharedArrayBuffer crosses too: the cancel flag.
|
|
4
6
|
*
|
|
5
7
|
* @module code-mode/worker-protocol
|
|
6
8
|
*/
|
|
7
9
|
import type { CodeModeErrorFields } from "./errors.js";
|
|
8
|
-
import type {
|
|
10
|
+
import type { EncodedSurface, HostErrorShown, SandboxResourceLimits, UnsentCall } from "./sandbox-core.js";
|
|
9
11
|
/** Host to worker. */
|
|
10
12
|
export type HostMessage = {
|
|
11
13
|
readonly type: "run";
|
|
12
14
|
readonly code: string;
|
|
13
|
-
|
|
14
|
-
readonly
|
|
15
|
+
/** Plain data: a name, the JSON text of each constant and the table of operations. */
|
|
16
|
+
readonly surface: EncodedSurface;
|
|
17
|
+
readonly limits: SandboxResourceLimits;
|
|
18
|
+
/** The key of the record that stands for an earlier result, when the surface uses references. */
|
|
19
|
+
readonly referenceKey?: string;
|
|
20
|
+
/** True when the host decides about unsent calls: the guest then asks before it completes. */
|
|
21
|
+
readonly asksAboutUnsent: boolean;
|
|
15
22
|
/** Int32Array flag: 1 asks the guest to stop at its next interrupt check. */
|
|
16
23
|
readonly cancel: SharedArrayBuffer;
|
|
24
|
+
} | {
|
|
25
|
+
/** The host lets the program's value stand although calls were not sent. */
|
|
26
|
+
readonly type: "unsent-reply";
|
|
27
|
+
readonly ok: true;
|
|
28
|
+
} | {
|
|
29
|
+
/** The host refuses: the run fails with this error. */
|
|
30
|
+
readonly type: "unsent-reply";
|
|
31
|
+
readonly ok: false;
|
|
32
|
+
readonly error: CodeModeErrorFields;
|
|
17
33
|
} | {
|
|
18
34
|
readonly type: "reply";
|
|
19
35
|
readonly id: number;
|
|
20
36
|
readonly ok: true;
|
|
21
37
|
/** The JSON text of the result, already within `limits.valueLength`. */
|
|
22
38
|
readonly json: string;
|
|
39
|
+
/** The host completed this call and its effect cannot be undone. */
|
|
40
|
+
readonly irreversible?: true;
|
|
23
41
|
} | {
|
|
24
42
|
readonly type: "reply";
|
|
25
43
|
readonly id: number;
|
|
26
44
|
readonly ok: false;
|
|
27
45
|
readonly error: CodeModeErrorFields;
|
|
46
|
+
/**
|
|
47
|
+
* The host completed this call, its effect cannot be undone, and this error
|
|
48
|
+
* is about its result, which could not be sent.
|
|
49
|
+
*/
|
|
50
|
+
readonly irreversible?: true;
|
|
51
|
+
} | {
|
|
52
|
+
readonly type: "reply";
|
|
53
|
+
readonly id: number;
|
|
54
|
+
readonly ok: false;
|
|
55
|
+
/** The host rejected with its own error: what the program is shown. */
|
|
56
|
+
readonly host: HostErrorShown;
|
|
28
57
|
};
|
|
29
58
|
/** Worker to host. */
|
|
30
59
|
export type GuestMessage = {
|
|
@@ -33,10 +62,18 @@ export type GuestMessage = {
|
|
|
33
62
|
readonly type: "call";
|
|
34
63
|
readonly id: number;
|
|
35
64
|
readonly operation: string;
|
|
36
|
-
|
|
37
|
-
|
|
65
|
+
/** The JSON text of the list of arguments. */
|
|
66
|
+
readonly args: string;
|
|
67
|
+
}
|
|
68
|
+
/** The program finished normally with calls it did not wait for: the host decides. */
|
|
69
|
+
| {
|
|
70
|
+
readonly type: "unsent";
|
|
71
|
+
readonly calls: UnsentCall[];
|
|
72
|
+
}
|
|
73
|
+
/** `json` is the JSON text of what the program returned; absent when it returned nothing. */
|
|
74
|
+
| {
|
|
38
75
|
readonly type: "done";
|
|
39
|
-
readonly
|
|
76
|
+
readonly json?: string;
|
|
40
77
|
} | {
|
|
41
78
|
readonly type: "fail";
|
|
42
79
|
readonly error: CodeModeErrorFields;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-protocol.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/worker-protocol.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"worker-protocol.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/worker-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,UAAU,EACX,MAAM,mBAAmB,CAAC;AAE3B,sBAAsB;AACtB,MAAM,MAAM,WAAW,GACnB;IACA,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sFAAsF;IACtF,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;IACvC,iGAAiG;IACjG,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,8FAA8F;IAC9F,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,6EAA6E;IAC7E,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;CACpC,GACC;IACA,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;CACnB,GACC;IACA,uDAAuD;IACvD,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAC;CACrC,GACC;IACA,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,oEAAoE;IACpE,QAAQ,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC;CAC9B,GACC;IACA,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC;CAC9B,GACC;IACA,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,uEAAuE;IACvE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;CAC/B,CAAC;AAEJ,sBAAsB;AACtB,MAAM,MAAM,YAAY,GACpB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IACA,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,8CAA8C;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AACD,sFAAsF;GACpF;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,CAAA;CAAE;AAC3D,6FAA6F;GAC3F;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GACjD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAA;CAAE,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Messages between the host and the Code Mode guest worker.
|
|
3
|
-
*
|
|
2
|
+
* Messages between the host and the Code Mode guest worker. Every value of a
|
|
3
|
+
* program crosses as JSON text, never as a tree of objects: copying a tree
|
|
4
|
+
* between threads has a nesting limit of its own, which the other isolation
|
|
5
|
+
* does not have. One SharedArrayBuffer crosses too: the cancel flag.
|
|
4
6
|
*
|
|
5
7
|
* @module code-mode/worker-protocol
|
|
6
8
|
*/
|
package/esm/src/version.d.ts
CHANGED
package/esm/src/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcpview/compose",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Compose and synchronize multiple MCP Apps UIs into composite dashboards",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -47,6 +47,14 @@
|
|
|
47
47
|
"import": "./esm/src/code-mode/board.js",
|
|
48
48
|
"require": "./script/src/code-mode/board.js"
|
|
49
49
|
},
|
|
50
|
+
"./code-mode/sandbox": {
|
|
51
|
+
"import": "./esm/src/code-mode/sandbox-api.js",
|
|
52
|
+
"require": "./script/src/code-mode/sandbox-api.js"
|
|
53
|
+
},
|
|
54
|
+
"./code-mode/sandbox-worker": {
|
|
55
|
+
"import": "./esm/src/code-mode/sandbox-worker.js",
|
|
56
|
+
"require": "./script/src/code-mode/sandbox-worker.js"
|
|
57
|
+
},
|
|
50
58
|
"./sdk": {
|
|
51
59
|
"import": "./esm/src/sdk/mod.js",
|
|
52
60
|
"require": "./script/src/sdk/mod.js"
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The QuickJS engine of the Code Mode sandbox.
|
|
3
|
+
*
|
|
4
|
+
* It is the engine library's default build. Its WebAssembly lives in a file
|
|
5
|
+
* beside the library's own module: Node and Deno read it from there, a browser
|
|
6
|
+
* fetches it. A host that bundles its code ships that file next to its bundle.
|
|
7
|
+
*
|
|
8
|
+
* Every program runs in its own fresh WebAssembly instance, in both `worker`
|
|
9
|
+
* and `inline` isolations, with a bounded `WebAssembly.Memory` and a guarded
|
|
10
|
+
* `_malloc`: QuickJS's Emscripten build has no `malloc_usable_size`, so
|
|
11
|
+
* `setMemoryLimit` alone does not cap large strings, arrays or ArrayBuffers,
|
|
12
|
+
* and `quickjs-emscripten`'s host helpers do not check `_malloc` for `0`.
|
|
13
|
+
*
|
|
14
|
+
* @module code-mode/engine
|
|
15
|
+
*/
|
|
16
|
+
import { type QuickJSWASMModule } from "quickjs-emscripten";
|
|
17
|
+
/**
|
|
18
|
+
* Thrown by our `_malloc` wrapper when Emscripten's allocator returns `0`.
|
|
19
|
+
* Catching it before `quickjs-emscripten` copies bytes stops host helpers from
|
|
20
|
+
* writing over address `0` of linear memory, leaving the VM state uncorrupted.
|
|
21
|
+
*/
|
|
22
|
+
export declare class WasmOomError extends RangeError {
|
|
23
|
+
constructor(bytes: number);
|
|
24
|
+
}
|
|
25
|
+
/** True when our `_malloc` guard refused a host-side allocation cleanly. */
|
|
26
|
+
export declare function isWasmOom(error: unknown): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* True when QuickJS trapped inside WebAssembly on an unguarded allocation
|
|
29
|
+
* failure. The instance's state is then unknown and must be abandoned.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isWasmMemoryTrap(error: unknown): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* True when Emscripten's linear-memory allocator failed to grow or `_malloc`
|
|
34
|
+
* returned `0` after arena setup. Used to tell QuickJS's out-of-memory `null`
|
|
35
|
+
* exception apart from an intentional `throw null` even after unwinding frees
|
|
36
|
+
* the program's local variables.
|
|
37
|
+
*/
|
|
38
|
+
export declare function didHitMemoryLimit(quickjs: QuickJSWASMModule): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* A new engine module, shared with nobody, whose WebAssembly linear memory is
|
|
41
|
+
* capped for `memoryBytes`. Rejects with `SANDBOX_UNAVAILABLE` when the engine
|
|
42
|
+
* cannot be loaded here: running the program again would not help, the
|
|
43
|
+
* deployment has to change.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* const quickjs = await newEngine();
|
|
48
|
+
* const vm = quickjs.newContext();
|
|
49
|
+
* vm.dispose();
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function newEngine(memoryBytes?: number): Promise<QuickJSWASMModule>;
|
|
53
|
+
/**
|
|
54
|
+
* When `memoryBytes` is smaller than the mandatory 16 MiB initial WASM memory,
|
|
55
|
+
* reserve the surplus C heap so the program sees its configured limit instead
|
|
56
|
+
* of ~10.9 MiB. Returns an idempotent release function to call before disposal.
|
|
57
|
+
*/
|
|
58
|
+
export declare function capInitialArena(quickjs: QuickJSWASMModule, memoryBytes: number): () => void;
|
|
59
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAGL,KAAK,iBAAiB,EAEvB,MAAM,oBAAoB,CAAC;AAa5B;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,UAAU;gBAC9B,KAAK,EAAE,MAAM;CAI1B;AAED,4EAA4E;AAC5E,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEjD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAGxD;AAiBD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAErE;AAWD;;;;;;;;;;;;GAYG;AACH,wBAAsB,SAAS,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAyDhF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,IAAI,CAqC3F"}
|