@mcpview/compose 0.14.1 → 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 +101 -1
- package/README.md +113 -22
- 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 +399 -67
- 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 +39 -11
- package/esm/src/code-mode/worker-host.d.ts.map +1 -1
- package/esm/src/code-mode/worker-host.js +100 -43
- 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 +429 -72
- 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 +39 -11
- package/script/src/code-mode/worker-host.d.ts.map +1 -1
- package/script/src/code-mode/worker-host.js +100 -42
- 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
|
|
@@ -76,14 +76,13 @@ export function guestModulePermission(url) {
|
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* A Deno worker inherits the host's permissions and must be able to load its module.
|
|
79
|
-
* Only the module itself is checked:
|
|
79
|
+
* Only the module itself is checked: the modules it imports are not.
|
|
80
80
|
*/
|
|
81
|
-
function denoWorkerPermission() {
|
|
81
|
+
function denoWorkerPermission(url) {
|
|
82
82
|
const deno = dntShim.dntGlobalThis.Deno;
|
|
83
83
|
const query = deno?.permissions?.querySync;
|
|
84
84
|
if (!query)
|
|
85
85
|
return undefined;
|
|
86
|
-
const url = guestUrl();
|
|
87
86
|
const descriptor = guestModulePermission(url);
|
|
88
87
|
if (!descriptor)
|
|
89
88
|
return undefined;
|
|
@@ -189,26 +188,31 @@ function guestUrl() {
|
|
|
189
188
|
function importNodeBuiltin(name) {
|
|
190
189
|
return import(`node:${name}`);
|
|
191
190
|
}
|
|
192
|
-
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) {
|
|
193
194
|
if (workerRuntime() === "node") {
|
|
194
195
|
const { Worker } = await importNodeBuiltin("worker_threads");
|
|
195
196
|
const process = dntShim.dntGlobalThis.process;
|
|
196
|
-
const worker = new Worker(
|
|
197
|
+
const worker = new Worker(url, {
|
|
197
198
|
execArgv: nodeWorkerExecArgv(process?.execArgv ?? []),
|
|
198
199
|
env: nodeWorkerEnv(process?.env ?? {}),
|
|
199
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);
|
|
200
204
|
worker.on("message", onMessage);
|
|
201
|
-
worker.on("error", onFailure);
|
|
202
|
-
worker.on("exit",
|
|
205
|
+
worker.on("error", () => onFailure());
|
|
206
|
+
worker.on("exit", onExit);
|
|
203
207
|
return {
|
|
204
208
|
post: (message) => worker.postMessage(message),
|
|
205
209
|
terminate: () => {
|
|
206
|
-
worker.off("exit",
|
|
210
|
+
worker.off("exit", onExit);
|
|
207
211
|
void worker.terminate();
|
|
208
212
|
},
|
|
209
213
|
};
|
|
210
214
|
}
|
|
211
|
-
const worker = new Worker(
|
|
215
|
+
const worker = new Worker(url, { type: "module" });
|
|
212
216
|
worker.onmessage = (event) => onMessage(event.data);
|
|
213
217
|
worker.onerror = (event) => {
|
|
214
218
|
event.preventDefault();
|
|
@@ -222,27 +226,18 @@ async function spawn(onMessage, onFailure) {
|
|
|
222
226
|
* posted, so an oversized result never crosses the worker boundary (no parse and
|
|
223
227
|
* no structured clone). The guest decodes the text.
|
|
224
228
|
*/
|
|
225
|
-
export function encodeReply(id, operation, value, valueLength
|
|
226
|
-
|
|
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 } : {};
|
|
227
233
|
try {
|
|
228
|
-
//
|
|
229
|
-
json =
|
|
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 };
|
|
230
237
|
}
|
|
231
|
-
catch {
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
if (json === undefined) {
|
|
235
|
-
return {
|
|
236
|
-
type: "reply",
|
|
237
|
-
id,
|
|
238
|
-
ok: false,
|
|
239
|
-
error: new CodeModeError("OPERATION_FAILED", `api.${operation} returned a value that is not JSON`, "Return plain JSON from the host operation").toJSON(),
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
if (json.length > valueLength) {
|
|
243
|
-
return { type: "reply", id, ok: false, error: receiptTooLarge(valueLength).toJSON() };
|
|
238
|
+
catch (error) {
|
|
239
|
+
return { type: "reply", id, ok: false, error: error.toJSON(), ...done };
|
|
244
240
|
}
|
|
245
|
-
return { type: "reply", id, ok: true, json };
|
|
246
241
|
}
|
|
247
242
|
/** The error for a worker that could not be created at all. */
|
|
248
243
|
export function workerSpawnFailure(error) {
|
|
@@ -252,17 +247,30 @@ export function workerSpawnFailure(error) {
|
|
|
252
247
|
}
|
|
253
248
|
return sandboxFailed();
|
|
254
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
|
+
}
|
|
255
260
|
function sandboxFailed() {
|
|
256
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"');
|
|
257
262
|
}
|
|
258
263
|
/**
|
|
259
|
-
* 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
|
|
260
266
|
* {@link CodeModeError}. The worker is always terminated afterwards.
|
|
261
267
|
*
|
|
262
268
|
* @example
|
|
263
269
|
* ```ts
|
|
264
|
-
* const
|
|
265
|
-
* 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,
|
|
266
274
|
* call: () => Promise.reject(new Error("unused")), signal: new AbortController().signal,
|
|
267
275
|
* });
|
|
268
276
|
* ```
|
|
@@ -272,6 +280,8 @@ export function runInWorker(input) {
|
|
|
272
280
|
return new Promise((resolve, reject) => {
|
|
273
281
|
let port;
|
|
274
282
|
let settled = false;
|
|
283
|
+
/** True once the worker reported: there is a guest that may need time to stop. */
|
|
284
|
+
let ready = false;
|
|
275
285
|
let grace;
|
|
276
286
|
const finish = (outcome) => {
|
|
277
287
|
if (settled)
|
|
@@ -283,6 +293,11 @@ export function runInWorker(input) {
|
|
|
283
293
|
port?.terminate();
|
|
284
294
|
};
|
|
285
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
|
+
}
|
|
286
301
|
Atomics.store(cancel, 0, 1);
|
|
287
302
|
// A guest blocked in a host call is released by that call's own abort;
|
|
288
303
|
// one stuck in a native operation gets a grace period, then is dropped.
|
|
@@ -311,14 +326,46 @@ export function runInWorker(input) {
|
|
|
311
326
|
}
|
|
312
327
|
switch (message.type) {
|
|
313
328
|
case "ready":
|
|
329
|
+
// A worker reports once: a second report starts nothing.
|
|
330
|
+
if (ready)
|
|
331
|
+
return;
|
|
332
|
+
ready = true;
|
|
333
|
+
input.started?.();
|
|
314
334
|
send({
|
|
315
335
|
type: "run",
|
|
316
336
|
code: input.code,
|
|
317
|
-
|
|
337
|
+
surface: input.surface,
|
|
318
338
|
limits: input.limits,
|
|
339
|
+
referenceKey: input.referenceKey,
|
|
340
|
+
asksAboutUnsent: input.unsent !== undefined,
|
|
319
341
|
cancel: cancel.buffer,
|
|
320
342
|
});
|
|
321
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
|
+
}
|
|
322
369
|
case "call": {
|
|
323
370
|
const { id } = message;
|
|
324
371
|
// Building a reply runs host-controlled code (a provider error's own
|
|
@@ -333,25 +380,35 @@ export function runInWorker(input) {
|
|
|
333
380
|
finish(() => reject(sandboxFailed()));
|
|
334
381
|
}
|
|
335
382
|
};
|
|
336
|
-
input.call(message.operation, message.args).then((value) => reply(() => encodeReply(id, message.operation, value, input.limits.valueLength)), (error) => reply(() =>
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
+
}));
|
|
343
399
|
return;
|
|
344
400
|
}
|
|
345
401
|
case "done":
|
|
346
402
|
// A guest can finish during the stop grace period: an abort still wins.
|
|
347
|
-
finish(() => input.signal.aborted ? reject(input.signal.reason) : resolve(message.
|
|
403
|
+
finish(() => input.signal.aborted ? reject(input.signal.reason) : resolve(message.json));
|
|
348
404
|
return;
|
|
349
405
|
case "fail":
|
|
350
406
|
finish(() => reject(codeModeErrorFromFields(message.error) ?? sandboxFailed()));
|
|
351
407
|
return;
|
|
352
408
|
}
|
|
353
409
|
};
|
|
354
|
-
|
|
410
|
+
const onFailure = (ended = false) => finish(() => reject(ended && !ready ? workerNotStarted() : sandboxFailed()));
|
|
411
|
+
spawn(onMessage, onFailure, input.worker ?? guestUrl()).then((spawned) => {
|
|
355
412
|
if (settled) {
|
|
356
413
|
spawned.terminate();
|
|
357
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"}
|