@mcpview/compose 0.13.1 → 0.14.1
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 +118 -0
- package/README.md +53 -0
- package/esm/src/code-mode/chain.d.ts +24 -1
- package/esm/src/code-mode/chain.d.ts.map +1 -1
- package/esm/src/code-mode/chain.js +219 -86
- package/esm/src/code-mode/errors.d.ts +80 -0
- package/esm/src/code-mode/errors.d.ts.map +1 -0
- package/esm/src/code-mode/errors.js +140 -0
- package/esm/src/code-mode/guest-worker.d.ts +11 -0
- package/esm/src/code-mode/guest-worker.d.ts.map +1 -0
- package/esm/src/code-mode/guest-worker.js +80 -0
- package/esm/src/code-mode/mod.d.ts +3 -1
- package/esm/src/code-mode/mod.d.ts.map +1 -1
- package/esm/src/code-mode/mod.js +2 -0
- package/esm/src/code-mode/sandbox-core.d.ts +61 -0
- package/esm/src/code-mode/sandbox-core.d.ts.map +1 -0
- package/esm/src/code-mode/sandbox-core.js +424 -0
- package/esm/src/code-mode/sandbox.d.ts +68 -7
- package/esm/src/code-mode/sandbox.d.ts.map +1 -1
- package/esm/src/code-mode/sandbox.js +182 -120
- package/esm/src/code-mode/tool.d.ts.map +1 -1
- package/esm/src/code-mode/tool.js +2 -0
- package/esm/src/code-mode/worker-host.d.ts +82 -0
- package/esm/src/code-mode/worker-host.d.ts.map +1 -0
- package/esm/src/code-mode/worker-host.js +364 -0
- package/esm/src/code-mode/worker-protocol.d.ts +44 -0
- package/esm/src/code-mode/worker-protocol.d.ts.map +1 -0
- package/esm/src/code-mode/worker-protocol.js +7 -0
- package/esm/src/host/renderer/css/panel-controls.d.ts.map +1 -1
- package/esm/src/host/renderer/css/panel-controls.js +5 -1
- package/esm/src/host/renderer/js/card-height.d.ts +11 -1
- package/esm/src/host/renderer/js/card-height.d.ts.map +1 -1
- package/esm/src/host/renderer/js/card-height.js +57 -10
- package/esm/src/host/renderer/js/event-bus.d.ts +11 -0
- package/esm/src/host/renderer/js/event-bus.d.ts.map +1 -1
- package/esm/src/host/renderer/js/event-bus.js +49 -8
- package/esm/src/host/renderer/js/intrinsic-layout.d.ts +26 -0
- package/esm/src/host/renderer/js/intrinsic-layout.d.ts.map +1 -0
- package/esm/src/host/renderer/js/intrinsic-layout.js +44 -0
- package/esm/src/host/renderer/panel-resizing.d.ts.map +1 -1
- package/esm/src/host/renderer/panel-resizing.js +8 -0
- package/esm/src/version.d.ts +1 -1
- package/esm/src/version.js +1 -1
- package/package.json +1 -1
- package/script/src/code-mode/chain.d.ts +24 -1
- package/script/src/code-mode/chain.d.ts.map +1 -1
- package/script/src/code-mode/chain.js +218 -85
- package/script/src/code-mode/errors.d.ts +80 -0
- package/script/src/code-mode/errors.d.ts.map +1 -0
- package/script/src/code-mode/errors.js +148 -0
- package/script/src/code-mode/guest-worker.d.ts +11 -0
- package/script/src/code-mode/guest-worker.d.ts.map +1 -0
- package/script/src/code-mode/guest-worker.js +105 -0
- package/script/src/code-mode/mod.d.ts +3 -1
- package/script/src/code-mode/mod.d.ts.map +1 -1
- package/script/src/code-mode/mod.js +9 -1
- package/script/src/code-mode/sandbox-core.d.ts +61 -0
- package/script/src/code-mode/sandbox-core.d.ts.map +1 -0
- package/script/src/code-mode/sandbox-core.js +430 -0
- package/script/src/code-mode/sandbox.d.ts +68 -7
- package/script/src/code-mode/sandbox.d.ts.map +1 -1
- package/script/src/code-mode/sandbox.js +190 -122
- package/script/src/code-mode/tool.d.ts.map +1 -1
- package/script/src/code-mode/tool.js +2 -0
- package/script/src/code-mode/worker-host.d.ts +82 -0
- package/script/src/code-mode/worker-host.d.ts.map +1 -0
- package/script/src/code-mode/worker-host.js +399 -0
- package/script/src/code-mode/worker-protocol.d.ts +44 -0
- package/script/src/code-mode/worker-protocol.d.ts.map +1 -0
- package/script/src/code-mode/worker-protocol.js +8 -0
- package/script/src/host/renderer/css/panel-controls.d.ts.map +1 -1
- package/script/src/host/renderer/css/panel-controls.js +5 -1
- package/script/src/host/renderer/js/card-height.d.ts +11 -1
- package/script/src/host/renderer/js/card-height.d.ts.map +1 -1
- package/script/src/host/renderer/js/card-height.js +57 -10
- package/script/src/host/renderer/js/event-bus.d.ts +11 -0
- package/script/src/host/renderer/js/event-bus.d.ts.map +1 -1
- package/script/src/host/renderer/js/event-bus.js +50 -8
- package/script/src/host/renderer/js/intrinsic-layout.d.ts +26 -0
- package/script/src/host/renderer/js/intrinsic-layout.d.ts.map +1 -0
- package/script/src/host/renderer/js/intrinsic-layout.js +48 -0
- package/script/src/host/renderer/panel-resizing.d.ts.map +1 -1
- package/script/src/host/renderer/panel-resizing.js +8 -0
- package/script/src/version.d.ts +1 -1
- package/script/src/version.js +1 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Machine-readable failures of the Code Mode `execute` tool.
|
|
4
|
+
*
|
|
5
|
+
* An MCP host usually forwards only `error.message` to the model, so the message
|
|
6
|
+
* itself is the contract, in the format shared with other MCPView Code Mode
|
|
7
|
+
* servers:
|
|
8
|
+
*
|
|
9
|
+
* [execute] <CODE>: <detail>. Recovery: <recovery>.
|
|
10
|
+
*
|
|
11
|
+
* Guest programs see the same errors as `Error` objects that also carry
|
|
12
|
+
* `code`, `recovery` and `context`, so a program can branch on `e.code`.
|
|
13
|
+
*
|
|
14
|
+
* @module code-mode/errors
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.CodeModeError = exports.POSSIBLE_EFFECTS_RECOVERY = exports.CODE_MODE_ERROR_CODES = void 0;
|
|
18
|
+
exports.formatCodeModeError = formatCodeModeError;
|
|
19
|
+
exports.isCodeModeError = isCodeModeError;
|
|
20
|
+
exports.codeModeErrorFromFields = codeModeErrorFromFields;
|
|
21
|
+
exports.withPossibleEffects = withPossibleEffects;
|
|
22
|
+
/** Every code the Code Mode tool can report. Codes are API: never rename one. */
|
|
23
|
+
exports.CODE_MODE_ERROR_CODES = [
|
|
24
|
+
// Input checked before the program runs.
|
|
25
|
+
"INVALID_INPUT",
|
|
26
|
+
"PARAMS_INVALID",
|
|
27
|
+
"SAVED_CHAINS_UNAVAILABLE",
|
|
28
|
+
"SAVE_NAME_INVALID",
|
|
29
|
+
"SAVE_NAME_CONFLICT",
|
|
30
|
+
"SAVE_CATALOG_FULL",
|
|
31
|
+
"SAVE_FAILED",
|
|
32
|
+
"CATALOG_ERROR",
|
|
33
|
+
// The guest program and its sandbox.
|
|
34
|
+
"GUEST_ERROR",
|
|
35
|
+
"RESOURCE_LIMIT",
|
|
36
|
+
"TIME_LIMIT",
|
|
37
|
+
"RESULT_INVALID",
|
|
38
|
+
"GUEST_STALLED",
|
|
39
|
+
"UNAWAITED_OPERATION",
|
|
40
|
+
"OPERATION_LIMIT",
|
|
41
|
+
"ARGUMENT_INVALID",
|
|
42
|
+
"OPERATION_FAILED",
|
|
43
|
+
"SANDBOX_UNAVAILABLE",
|
|
44
|
+
"SANDBOX_FAILED",
|
|
45
|
+
// Providers and the board.
|
|
46
|
+
"PROVIDER_UNKNOWN",
|
|
47
|
+
"SNIPPET_NOT_APPROVED",
|
|
48
|
+
"PROVIDER_UNAVAILABLE",
|
|
49
|
+
"PROVIDER_ERROR",
|
|
50
|
+
"PROVIDER_RESULT_INVALID",
|
|
51
|
+
"RECEIPT_TOO_LARGE",
|
|
52
|
+
"PANEL_INVALID",
|
|
53
|
+
"SYNC_INVALID",
|
|
54
|
+
// After an upstream call was dispatched.
|
|
55
|
+
"EXECUTION_FAILED",
|
|
56
|
+
"INTERRUPTED",
|
|
57
|
+
];
|
|
58
|
+
/** Recovery suffix used once an upstream operation may have completed. */
|
|
59
|
+
exports.POSSIBLE_EFFECTS_RECOVERY = "One or more upstream operations may have completed. Check their effects before replaying the chain";
|
|
60
|
+
function sentence(text) {
|
|
61
|
+
const trimmed = text.trim();
|
|
62
|
+
return /[.!?]$/.test(trimmed) ? trimmed : `${trimmed}.`;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Render `[execute] CODE: detail. Recovery: recovery.`
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* formatCodeModeError("TIME_LIMIT", "The program used its 2000 ms of CPU", "Split the work");
|
|
70
|
+
* // "[execute] TIME_LIMIT: The program used its 2000 ms of CPU. Recovery: Split the work."
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
function formatCodeModeError(code, detail, recovery) {
|
|
74
|
+
return `[execute] ${code}: ${detail.trim().replace(/[.!?]$/, "")}. Recovery: ${sentence(recovery)}`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A Code Mode failure with a stable code, a recovery hint and context.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* throw new CodeModeError("PROVIDER_UNKNOWN", "No provider is configured as cad", "Use one of the listed aliases", {
|
|
82
|
+
* context: { available: ["slicer"] },
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
class CodeModeError extends Error {
|
|
87
|
+
name = "CodeModeError";
|
|
88
|
+
code;
|
|
89
|
+
/** What went wrong, without the code prefix or the recovery hint. */
|
|
90
|
+
detail;
|
|
91
|
+
recovery;
|
|
92
|
+
context;
|
|
93
|
+
effects;
|
|
94
|
+
constructor(code, detail, recovery, options = {}) {
|
|
95
|
+
super(formatCodeModeError(code, detail, recovery));
|
|
96
|
+
this.code = code;
|
|
97
|
+
this.detail = detail;
|
|
98
|
+
this.recovery = recovery;
|
|
99
|
+
this.context = freezeContext(options.context ?? {});
|
|
100
|
+
this.effects = options.effects ?? "none";
|
|
101
|
+
}
|
|
102
|
+
/** Plain fields, safe to post across a worker boundary. */
|
|
103
|
+
toJSON() {
|
|
104
|
+
return {
|
|
105
|
+
code: this.code,
|
|
106
|
+
detail: this.detail,
|
|
107
|
+
recovery: this.recovery,
|
|
108
|
+
context: this.context,
|
|
109
|
+
effects: this.effects,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.CodeModeError = CodeModeError;
|
|
114
|
+
function freezeContext(value) {
|
|
115
|
+
const entries = Object.entries(value).filter(([, item]) => typeof item === "string" || typeof item === "number" || typeof item === "boolean" ||
|
|
116
|
+
(Array.isArray(item) && item.every((entry) => typeof entry === "string"))).map(([key, item]) => [key, Array.isArray(item) ? Object.freeze([...item]) : item]);
|
|
117
|
+
return Object.freeze(Object.fromEntries(entries));
|
|
118
|
+
}
|
|
119
|
+
/** True for a {@link CodeModeError}. */
|
|
120
|
+
function isCodeModeError(error) {
|
|
121
|
+
return error instanceof CodeModeError;
|
|
122
|
+
}
|
|
123
|
+
const KNOWN_CODES = new Set(exports.CODE_MODE_ERROR_CODES);
|
|
124
|
+
/**
|
|
125
|
+
* Rebuild an error from {@link CodeModeErrorFields}, for example after it
|
|
126
|
+
* crossed a worker boundary. Returns undefined for any other shape.
|
|
127
|
+
*/
|
|
128
|
+
function codeModeErrorFromFields(value) {
|
|
129
|
+
if (!value || typeof value !== "object")
|
|
130
|
+
return undefined;
|
|
131
|
+
const fields = value;
|
|
132
|
+
if (typeof fields.code !== "string" || !KNOWN_CODES.has(fields.code) ||
|
|
133
|
+
typeof fields.detail !== "string" || typeof fields.recovery !== "string" ||
|
|
134
|
+
(fields.effects !== "none" && fields.effects !== "possible") ||
|
|
135
|
+
!fields.context || typeof fields.context !== "object" || Array.isArray(fields.context)) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
return new CodeModeError(fields.code, fields.detail, fields.recovery, {
|
|
139
|
+
context: fields.context,
|
|
140
|
+
effects: fields.effects,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/** The same failure, reported once an upstream operation may have completed. */
|
|
144
|
+
function withPossibleEffects(error) {
|
|
145
|
+
if (error.effects === "possible")
|
|
146
|
+
return error;
|
|
147
|
+
return new CodeModeError(error.code, error.detail, `${error.recovery.trim().replace(/[.!?]$/, "")}. ${exports.POSSIBLE_EFFECTS_RECOVERY}`, { context: error.context, effects: "possible" });
|
|
148
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker entry for Code Mode programs. It owns one QuickJS VM, runs one
|
|
3
|
+
* program, and asks the host for each api operation. The host terminates the
|
|
4
|
+
* worker afterwards. Loaded by `worker-host.ts` under Deno (Web Worker) and
|
|
5
|
+
* Node (`node:worker_threads`); keep it free of top-level await, which the
|
|
6
|
+
* CommonJS npm build rejects.
|
|
7
|
+
*
|
|
8
|
+
* @module code-mode/guest-worker
|
|
9
|
+
*/
|
|
10
|
+
import "../../_dnt.polyfills.js";
|
|
11
|
+
//# sourceMappingURL=guest-worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guest-worker.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/guest-worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
/**
|
|
27
|
+
* Worker entry for Code Mode programs. It owns one QuickJS VM, runs one
|
|
28
|
+
* program, and asks the host for each api operation. The host terminates the
|
|
29
|
+
* worker afterwards. Loaded by `worker-host.ts` under Deno (Web Worker) and
|
|
30
|
+
* Node (`node:worker_threads`); keep it free of top-level await, which the
|
|
31
|
+
* CommonJS npm build rejects.
|
|
32
|
+
*
|
|
33
|
+
* @module code-mode/guest-worker
|
|
34
|
+
*/
|
|
35
|
+
require("../../_dnt.polyfills.js");
|
|
36
|
+
const dntShim = __importStar(require("../../_dnt.shims.js"));
|
|
37
|
+
const quickjs_emscripten_1 = require("quickjs-emscripten");
|
|
38
|
+
const errors_js_1 = require("./errors.js");
|
|
39
|
+
const sandbox_core_js_1 = require("./sandbox-core.js");
|
|
40
|
+
/** The host port, or undefined when this module is loaded outside a worker. */
|
|
41
|
+
function connect() {
|
|
42
|
+
const deno = dntShim.dntGlobalThis.Deno;
|
|
43
|
+
if (typeof deno?.version?.deno === "string") {
|
|
44
|
+
const workerScope = dntShim.dntGlobalThis
|
|
45
|
+
.WorkerGlobalScope;
|
|
46
|
+
if (typeof workerScope !== "function" || !(dntShim.dntGlobalThis instanceof workerScope)) {
|
|
47
|
+
return Promise.resolve(undefined);
|
|
48
|
+
}
|
|
49
|
+
const scope = dntShim.dntGlobalThis;
|
|
50
|
+
return Promise.resolve({
|
|
51
|
+
post: (message) => scope.postMessage(message),
|
|
52
|
+
listen: (handler) => scope.addEventListener("message", (event) => handler(event.data)),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return Promise.resolve().then(() => __importStar(require("node:worker_threads"))).then(({ parentPort }) => {
|
|
56
|
+
if (!parentPort)
|
|
57
|
+
return undefined;
|
|
58
|
+
return {
|
|
59
|
+
post: (message) => parentPort.postMessage(message),
|
|
60
|
+
listen: (handler) => parentPort.on("message", handler),
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
void connect().then((port) => {
|
|
65
|
+
if (!port)
|
|
66
|
+
return;
|
|
67
|
+
const waiting = new Map();
|
|
68
|
+
let nextCall = 0;
|
|
69
|
+
let started = false;
|
|
70
|
+
port.listen((message) => {
|
|
71
|
+
if (message.type === "reply") {
|
|
72
|
+
const waiter = waiting.get(message.id);
|
|
73
|
+
if (!waiter)
|
|
74
|
+
return;
|
|
75
|
+
waiting.delete(message.id);
|
|
76
|
+
if (message.ok)
|
|
77
|
+
waiter.resolve(JSON.parse(message.json));
|
|
78
|
+
else {
|
|
79
|
+
waiter.reject((0, errors_js_1.codeModeErrorFromFields)(message.error) ??
|
|
80
|
+
new errors_js_1.CodeModeError("OPERATION_FAILED", "The operation failed", "Retry once"));
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (message.type !== "run" || started)
|
|
85
|
+
return;
|
|
86
|
+
started = true;
|
|
87
|
+
const cancel = new Int32Array(message.cancel);
|
|
88
|
+
(0, quickjs_emscripten_1.getQuickJS)().then((quickjs) => (0, sandbox_core_js_1.runVm)({
|
|
89
|
+
quickjs,
|
|
90
|
+
code: message.code,
|
|
91
|
+
params: message.params,
|
|
92
|
+
limits: message.limits,
|
|
93
|
+
isCancelled: () => Atomics.load(cancel, 0) === 1,
|
|
94
|
+
call: (operation, args) => new Promise((resolve, reject) => {
|
|
95
|
+
const id = nextCall++;
|
|
96
|
+
waiting.set(id, { resolve, reject });
|
|
97
|
+
port.post({ type: "call", id, operation, args });
|
|
98
|
+
}),
|
|
99
|
+
})).then((value) => port.post({ type: "done", value }), (error) => port.post({
|
|
100
|
+
type: "fail",
|
|
101
|
+
error: (error instanceof errors_js_1.CodeModeError ? error : new errors_js_1.CodeModeError("SANDBOX_FAILED", "The sandbox failed while running the program", "Run the program again")).toJSON(),
|
|
102
|
+
}));
|
|
103
|
+
});
|
|
104
|
+
port.post({ type: "ready" });
|
|
105
|
+
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/** Run selected snippets across host-configured MCP providers in one Code Mode call. */
|
|
2
2
|
import "../../_dnt.polyfills.js";
|
|
3
|
-
export { createSnippetChain, type SnippetChainExecutor, type SnippetPanelReceipt, } from "./chain.js";
|
|
3
|
+
export { createSnippetChain, type SnippetChainExecutor, type SnippetChainOptions, type SnippetPanelReceipt, } from "./chain.js";
|
|
4
|
+
export { CODE_MODE_ERROR_CODES, CodeModeError, type CodeModeErrorCode, type CodeModeErrorContext, type CodeModeErrorEffects, type CodeModeErrorFields, formatCodeModeError, isCodeModeError, } from "./errors.js";
|
|
5
|
+
export { assertSandboxIsolation, CODE_MODE_LIMITS, type SandboxIsolation, type SandboxLimits, } from "./sandbox.js";
|
|
4
6
|
export { connectSnippetProviders, type SnippetMcpClient, type SnippetProviderBinding, type SnippetProviderConnections, } from "./connections.js";
|
|
5
7
|
export type { SnippetChainContext, SnippetProvider } from "./providers.js";
|
|
6
8
|
export { createSnippetExecuteTool, type SnippetExecuteToolOptions } from "./tool.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/mod.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,OAAO,yBAAyB,CAAC;AAEjC,OAAO,EACL,kBAAkB,EAClB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,uBAAuB,EACvB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,0BAA0B,GAChC,MAAM,kBAA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,EACrB,cAAc,EACd,mBAAmB,GACpB,MAAM,WAAW,CAAC"}
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.supportsSnippetSync = exports.snippetSyncKey = exports.SNIPPET_SYNC_META_KEY = exports.parseSnippetSyncRule = exports.registerSnippetProvider = exports.createSnippetExecuteTool = exports.connectSnippetProviders = exports.createSnippetChain = void 0;
|
|
3
|
+
exports.supportsSnippetSync = exports.snippetSyncKey = exports.SNIPPET_SYNC_META_KEY = exports.parseSnippetSyncRule = exports.registerSnippetProvider = exports.createSnippetExecuteTool = exports.connectSnippetProviders = exports.CODE_MODE_LIMITS = exports.assertSandboxIsolation = exports.isCodeModeError = exports.formatCodeModeError = exports.CodeModeError = exports.CODE_MODE_ERROR_CODES = exports.createSnippetChain = void 0;
|
|
4
4
|
/** Run selected snippets across host-configured MCP providers in one Code Mode call. */
|
|
5
5
|
require("../../_dnt.polyfills.js");
|
|
6
6
|
var chain_js_1 = require("./chain.js");
|
|
7
7
|
Object.defineProperty(exports, "createSnippetChain", { enumerable: true, get: function () { return chain_js_1.createSnippetChain; } });
|
|
8
|
+
var errors_js_1 = require("./errors.js");
|
|
9
|
+
Object.defineProperty(exports, "CODE_MODE_ERROR_CODES", { enumerable: true, get: function () { return errors_js_1.CODE_MODE_ERROR_CODES; } });
|
|
10
|
+
Object.defineProperty(exports, "CodeModeError", { enumerable: true, get: function () { return errors_js_1.CodeModeError; } });
|
|
11
|
+
Object.defineProperty(exports, "formatCodeModeError", { enumerable: true, get: function () { return errors_js_1.formatCodeModeError; } });
|
|
12
|
+
Object.defineProperty(exports, "isCodeModeError", { enumerable: true, get: function () { return errors_js_1.isCodeModeError; } });
|
|
13
|
+
var sandbox_js_1 = require("./sandbox.js");
|
|
14
|
+
Object.defineProperty(exports, "assertSandboxIsolation", { enumerable: true, get: function () { return sandbox_js_1.assertSandboxIsolation; } });
|
|
15
|
+
Object.defineProperty(exports, "CODE_MODE_LIMITS", { enumerable: true, get: function () { return sandbox_js_1.CODE_MODE_LIMITS; } });
|
|
8
16
|
var connections_js_1 = require("./connections.js");
|
|
9
17
|
Object.defineProperty(exports, "connectSnippetProviders", { enumerable: true, get: function () { return connections_js_1.connectSnippetProviders; } });
|
|
10
18
|
var tool_js_1 = require("./tool.js");
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QuickJS driver for Code Mode programs. Runs identically on the main thread
|
|
3
|
+
* and inside a worker: it has no runtime-specific code and reaches the host only
|
|
4
|
+
* through the `call` function it is given.
|
|
5
|
+
*
|
|
6
|
+
* @module code-mode/sandbox-core
|
|
7
|
+
*/
|
|
8
|
+
import { type QuickJSWASMModule } from "quickjs-emscripten";
|
|
9
|
+
import { CodeModeError } from "./errors.js";
|
|
10
|
+
/** Resource limits of one program. */
|
|
11
|
+
export interface SandboxLimits {
|
|
12
|
+
/** Guest CPU time. Time spent waiting for host operations is not counted. */
|
|
13
|
+
readonly cpuMs: number;
|
|
14
|
+
/** Wall-clock time of the whole program, host operations included. */
|
|
15
|
+
readonly wallMs: number;
|
|
16
|
+
readonly memoryBytes: number;
|
|
17
|
+
readonly stackBytes: number;
|
|
18
|
+
/** `listSnippets` and `runSnippet` calls: upstream, possibly side-effecting work. */
|
|
19
|
+
readonly providerCalls: number;
|
|
20
|
+
/** `panel` and `sync` calls: board choices kept in host memory. */
|
|
21
|
+
readonly boardOperations: number;
|
|
22
|
+
/** Maximum length, in UTF-16 code units, of the JSON text of a value crossing the sandbox boundary. */
|
|
23
|
+
readonly valueLength: number;
|
|
24
|
+
}
|
|
25
|
+
/** Default limits of a Code Mode program. */
|
|
26
|
+
export declare const CODE_MODE_LIMITS: SandboxLimits;
|
|
27
|
+
/** Maximum source length accepted by the code-mode execute tool. */
|
|
28
|
+
export declare const maxCodeLength = 16384;
|
|
29
|
+
/** Serialize data crossing the QuickJS boundary within the supplied limit. */
|
|
30
|
+
export declare function encodeValue(value: unknown, limit?: number): string;
|
|
31
|
+
/** The error for a host result that exceeds the JSON limit of the boundary. */
|
|
32
|
+
export declare function receiptTooLarge(limit: number): CodeModeError;
|
|
33
|
+
/** Inputs of {@link runVm}. */
|
|
34
|
+
export interface RunVmOptions {
|
|
35
|
+
readonly quickjs: QuickJSWASMModule;
|
|
36
|
+
readonly code: string;
|
|
37
|
+
readonly params: Record<string, unknown>;
|
|
38
|
+
readonly limits: SandboxLimits;
|
|
39
|
+
/** Perform one host operation. Rejections should be {@link CodeModeError}s. */
|
|
40
|
+
call(operation: string, args: unknown[]): Promise<unknown>;
|
|
41
|
+
/** Polled by the QuickJS interrupt handler and between host operations. */
|
|
42
|
+
isCancelled(): boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Run a function body in an isolated QuickJS context. Only JSON and the four
|
|
46
|
+
* `api` operations cross into the host. Failures are {@link CodeModeError}s.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* const value = await runVm({
|
|
51
|
+
* quickjs: await getQuickJS(),
|
|
52
|
+
* code: "return api.params.n * 2;",
|
|
53
|
+
* params: { n: 21 },
|
|
54
|
+
* limits: CODE_MODE_LIMITS,
|
|
55
|
+
* call: () => Promise.reject(new Error("unused")),
|
|
56
|
+
* isCancelled: () => false,
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function runVm(options: RunVmOptions): Promise<unknown>;
|
|
61
|
+
//# sourceMappingURL=sandbox-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-core.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/sandbox-core.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAsB,KAAK,iBAAiB,EAAS,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,sCAA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