@mcpview/compose 0.13.0 → 0.14.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 +120 -0
- package/README.md +131 -2
- package/esm/_dnt.polyfills.d.ts +11 -11
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +14 -14
- package/esm/src/code-mode/board.d.ts +18 -2
- package/esm/src/code-mode/board.d.ts.map +1 -1
- package/esm/src/code-mode/board.js +74 -2
- package/esm/src/code-mode/chain.d.ts +26 -1
- package/esm/src/code-mode/chain.d.ts.map +1 -1
- package/esm/src/code-mode/chain.js +248 -89
- package/esm/src/code-mode/connections.d.ts +1 -0
- package/esm/src/code-mode/connections.d.ts.map +1 -1
- package/esm/src/code-mode/connections.js +1 -0
- 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/layout-publisher.d.ts +69 -0
- package/esm/src/code-mode/layout-publisher.d.ts.map +1 -0
- package/esm/src/code-mode/layout-publisher.js +85 -0
- package/esm/src/code-mode/layout-runs.d.ts +35 -0
- package/esm/src/code-mode/layout-runs.d.ts.map +1 -0
- package/esm/src/code-mode/layout-runs.js +130 -0
- package/esm/src/code-mode/layout.d.ts +20 -0
- package/esm/src/code-mode/layout.d.ts.map +1 -0
- package/esm/src/code-mode/layout.js +54 -0
- package/esm/src/code-mode/mod.d.ts +4 -1
- package/esm/src/code-mode/mod.d.ts.map +1 -1
- package/esm/src/code-mode/mod.js +3 -0
- package/esm/src/code-mode/panel-contexts.d.ts +25 -0
- package/esm/src/code-mode/panel-contexts.d.ts.map +1 -0
- package/esm/src/code-mode/panel-contexts.js +115 -0
- package/esm/src/code-mode/providers.d.ts +3 -0
- package/esm/src/code-mode/providers.d.ts.map +1 -1
- 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 +180 -119
- package/esm/src/code-mode/sync.d.ts +11 -0
- package/esm/src/code-mode/sync.d.ts.map +1 -0
- package/esm/src/code-mode/sync.js +42 -0
- package/esm/src/code-mode/tool.d.ts +1 -1
- package/esm/src/code-mode/tool.d.ts.map +1 -1
- package/esm/src/code-mode/tool.js +14 -0
- package/esm/src/code-mode/worker-host.d.ts +70 -0
- package/esm/src/code-mode/worker-host.d.ts.map +1 -0
- package/esm/src/code-mode/worker-host.js +355 -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/html-generator.js +2 -2
- 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-controls.d.ts +7 -0
- package/esm/src/host/renderer/panel-controls.js +1 -0
- package/esm/src/host/renderer/panel-movement.d.ts.map +1 -1
- package/esm/src/host/renderer/panel-movement.js +5 -1
- package/esm/src/host/renderer/panel-resizing.d.ts.map +1 -1
- package/esm/src/host/renderer/panel-resizing.js +36 -0
- package/esm/src/host/renderer/panel-snapshot.d.ts +11 -0
- package/esm/src/host/renderer/panel-snapshot.d.ts.map +1 -0
- package/esm/src/host/renderer/panel-snapshot.js +65 -0
- package/esm/src/version.d.ts +1 -1
- package/esm/src/version.js +1 -1
- package/package.json +9 -1
- package/script/_dnt.polyfills.d.ts +11 -11
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +14 -14
- package/script/src/code-mode/board.d.ts +18 -2
- package/script/src/code-mode/board.d.ts.map +1 -1
- package/script/src/code-mode/board.js +81 -2
- package/script/src/code-mode/chain.d.ts +26 -1
- package/script/src/code-mode/chain.d.ts.map +1 -1
- package/script/src/code-mode/chain.js +247 -88
- package/script/src/code-mode/connections.d.ts +1 -0
- package/script/src/code-mode/connections.d.ts.map +1 -1
- package/script/src/code-mode/connections.js +1 -0
- 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/layout-publisher.d.ts +69 -0
- package/script/src/code-mode/layout-publisher.d.ts.map +1 -0
- package/script/src/code-mode/layout-publisher.js +88 -0
- package/script/src/code-mode/layout-runs.d.ts +35 -0
- package/script/src/code-mode/layout-runs.d.ts.map +1 -0
- package/script/src/code-mode/layout-runs.js +134 -0
- package/script/src/code-mode/layout.d.ts +20 -0
- package/script/src/code-mode/layout.d.ts.map +1 -0
- package/script/src/code-mode/layout.js +57 -0
- package/script/src/code-mode/mod.d.ts +4 -1
- package/script/src/code-mode/mod.d.ts.map +1 -1
- package/script/src/code-mode/mod.js +14 -1
- package/script/src/code-mode/panel-contexts.d.ts +25 -0
- package/script/src/code-mode/panel-contexts.d.ts.map +1 -0
- package/script/src/code-mode/panel-contexts.js +118 -0
- package/script/src/code-mode/providers.d.ts +3 -0
- package/script/src/code-mode/providers.d.ts.map +1 -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 +188 -121
- package/script/src/code-mode/sync.d.ts +11 -0
- package/script/src/code-mode/sync.d.ts.map +1 -0
- package/script/src/code-mode/sync.js +51 -0
- package/script/src/code-mode/tool.d.ts +1 -1
- package/script/src/code-mode/tool.d.ts.map +1 -1
- package/script/src/code-mode/tool.js +14 -0
- package/script/src/code-mode/worker-host.d.ts +70 -0
- package/script/src/code-mode/worker-host.d.ts.map +1 -0
- package/script/src/code-mode/worker-host.js +389 -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/html-generator.js +2 -2
- 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-controls.d.ts +7 -0
- package/script/src/host/renderer/panel-controls.js +4 -1
- package/script/src/host/renderer/panel-movement.d.ts.map +1 -1
- package/script/src/host/renderer/panel-movement.js +5 -1
- package/script/src/host/renderer/panel-resizing.d.ts.map +1 -1
- package/script/src/host/renderer/panel-resizing.js +36 -0
- package/script/src/host/renderer/panel-snapshot.d.ts +11 -0
- package/script/src/host/renderer/panel-snapshot.d.ts.map +1 -0
- package/script/src/host/renderer/panel-snapshot.js +69 -0
- package/script/src/version.d.ts +1 -1
- package/script/src/version.js +1 -1
|
@@ -1,34 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createSnippetChain = createSnippetChain;
|
|
4
|
+
const sync_js_1 = require("./sync.js");
|
|
4
5
|
const board_js_1 = require("./board.js");
|
|
5
6
|
const providers_js_1 = require("./providers.js");
|
|
7
|
+
const errors_js_1 = require("./errors.js");
|
|
6
8
|
const sandbox_js_1 = require("./sandbox.js");
|
|
7
9
|
const maxNativeSize = 4 * 1024 * 1024;
|
|
8
10
|
const maxNativeBytes = 6 * 1024 * 1024;
|
|
9
11
|
const maxSavedChains = 64;
|
|
10
|
-
const
|
|
12
|
+
const maxPanelTitle = 120;
|
|
11
13
|
function isRecord(value) {
|
|
12
14
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
13
15
|
}
|
|
14
16
|
const providerErrors = new Map([
|
|
15
|
-
["INVALID_INPUT",
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
["
|
|
17
|
+
["INVALID_INPUT", [
|
|
18
|
+
"the provider rejected the input",
|
|
19
|
+
"Check the input against the snippet's inputSchema from api.listSnippets",
|
|
20
|
+
]],
|
|
21
|
+
["ARTIFACT_UNAVAILABLE", [
|
|
22
|
+
"the input artifact is unavailable",
|
|
23
|
+
"Regenerate the artifact before retrying",
|
|
24
|
+
]],
|
|
25
|
+
["PROFILE_INVALID", [
|
|
26
|
+
"the configured provider profile is invalid or unavailable",
|
|
27
|
+
"Ask the operator to fix the provider profile; retrying will fail again",
|
|
28
|
+
]],
|
|
29
|
+
["UPSTREAM_ERROR", ["the upstream operation failed", "Retry once, then report the failure"]],
|
|
30
|
+
["TIMEOUT", ["the upstream operation timed out", "Retry once with a smaller input"]],
|
|
31
|
+
["UNAVAILABLE", ["the provider is unavailable", "Retry later"]],
|
|
20
32
|
]);
|
|
21
|
-
function providerError(result) {
|
|
33
|
+
function providerError(provider, snippet, result) {
|
|
22
34
|
const data = result.structuredContent;
|
|
23
35
|
const error = isRecord(data) ? data.error : undefined;
|
|
24
|
-
const code = isRecord(error) ? error.code : undefined;
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
const code = isRecord(error) && typeof error.code === "string" ? error.code : undefined;
|
|
37
|
+
const known = code ? providerErrors.get(code) : undefined;
|
|
38
|
+
const [detail, recovery] = known ??
|
|
39
|
+
["the provider reported an execution error", "Retry once, then report the failure"];
|
|
40
|
+
return new errors_js_1.CodeModeError("PROVIDER_ERROR", `Snippet ${snippet}: ${detail}`, recovery, {
|
|
41
|
+
context: { provider, snippet, providerCode: known ? code : "UNKNOWN" },
|
|
42
|
+
});
|
|
27
43
|
}
|
|
28
44
|
function validateParams(input, shape) {
|
|
29
|
-
if (!isRecord(input))
|
|
30
|
-
throw new
|
|
31
|
-
|
|
45
|
+
if (!isRecord(input)) {
|
|
46
|
+
throw new errors_js_1.CodeModeError("PARAMS_INVALID", "Supply params as a JSON object", "Pass an object");
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
(0, sandbox_js_1.encodeValue)(input, 8192);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
throw new errors_js_1.CodeModeError("PARAMS_INVALID", "params must be JSON of at most 8192 characters", "Pass fewer or smaller parameters", { context: { limit: 8192 } });
|
|
53
|
+
}
|
|
32
54
|
if (shape) {
|
|
33
55
|
const keys = Object.keys(input);
|
|
34
56
|
if (keys.length !== Object.keys(shape).length ||
|
|
@@ -37,138 +59,254 @@ function validateParams(input, shape) {
|
|
|
37
59
|
const kind = value === null ? "null" : Array.isArray(value) ? "array" : typeof value;
|
|
38
60
|
return !Object.hasOwn(shape, key) || shape[key] !== kind;
|
|
39
61
|
})) {
|
|
40
|
-
throw new
|
|
62
|
+
throw new errors_js_1.CodeModeError("PARAMS_INVALID", "Replay parameters must match the saved key names and JSON types", "Pass the parameters listed by listSaved, with the same types");
|
|
41
63
|
}
|
|
42
64
|
}
|
|
43
65
|
return input;
|
|
44
66
|
}
|
|
45
|
-
|
|
67
|
+
/** Map a catalog failure to a coded error. Catalog messages are constant strings. */
|
|
68
|
+
function catalogError(error) {
|
|
69
|
+
if (error instanceof errors_js_1.CodeModeError)
|
|
70
|
+
return error;
|
|
71
|
+
if (error instanceof TypeError || error instanceof RangeError || isCatalogError(error)) {
|
|
72
|
+
const catalogCode = isCatalogError(error) ? error.code : error.name;
|
|
73
|
+
return new errors_js_1.CodeModeError("CATALOG_ERROR", error.message, "Call listSaved, then replay an existing name", { context: { catalogCode } });
|
|
74
|
+
}
|
|
75
|
+
return new errors_js_1.CodeModeError("CATALOG_ERROR", "The saved chain catalog failed", "Retry once, then report the failure");
|
|
76
|
+
}
|
|
77
|
+
function isCatalogError(error) {
|
|
78
|
+
return error instanceof Error && error.name === "SnippetCatalogError" &&
|
|
79
|
+
typeof error.code === "string";
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Await a catalog operation. A failure while the caller's signal is aborted is the
|
|
83
|
+
* caller's cancellation and keeps its reason; any other failure, a store's own
|
|
84
|
+
* `AbortError` included, is a catalog failure.
|
|
85
|
+
*/
|
|
86
|
+
async function fromCatalog(work, signal) {
|
|
87
|
+
try {
|
|
88
|
+
return await work;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (signal?.aborted)
|
|
92
|
+
throw signal.reason;
|
|
93
|
+
throw catalogError(error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** The store may have written the chain even though the write was not confirmed. */
|
|
97
|
+
function saveFailed() {
|
|
98
|
+
return new errors_js_1.CodeModeError("SAVE_FAILED", "Failed to confirm that the chain was saved", "Call listSaved before saving again");
|
|
99
|
+
}
|
|
100
|
+
const SAVED_RECOVERY = "The chain was saved. Call listSaved before saving it again";
|
|
101
|
+
/**
|
|
102
|
+
* The cancellation exception: a DOMException named after the caller's reason, so
|
|
103
|
+
* a host can tell a cancelled task from a failed one. Its message carries the
|
|
104
|
+
* advice that structured fields cannot (a DOMException has no `effects`).
|
|
105
|
+
*/
|
|
106
|
+
function interrupted(reason, advice) {
|
|
107
|
+
const name = reason instanceof DOMException && reason.name === "TimeoutError"
|
|
108
|
+
? "TimeoutError"
|
|
109
|
+
: "AbortError";
|
|
110
|
+
return new DOMException(`[execute] INTERRUPTED: The chain was interrupted. Recovery: ${advice.join(". ")}.`, name);
|
|
111
|
+
}
|
|
112
|
+
function output(value, panels = [], saved, sync = []) {
|
|
46
113
|
const visible = {
|
|
47
114
|
value,
|
|
48
|
-
panels: panels.map(({ result: _result, ...panel }) => panel),
|
|
115
|
+
panels: panels.map(({ result: _result, events: _events, ...panel }) => panel),
|
|
49
116
|
...(saved === undefined ? {} : { saved }),
|
|
50
117
|
};
|
|
51
118
|
return {
|
|
52
119
|
content: [{ type: "text", text: JSON.stringify(visible) }],
|
|
53
120
|
structuredContent: visible,
|
|
54
|
-
_meta: {
|
|
121
|
+
_meta: {
|
|
122
|
+
[board_js_1.SNIPPET_PANELS_META_KEY]: panels,
|
|
123
|
+
...(sync.length ? { [sync_js_1.SNIPPET_SYNC_META_KEY]: sync } : {}),
|
|
124
|
+
},
|
|
55
125
|
};
|
|
56
126
|
}
|
|
57
127
|
/**
|
|
58
128
|
* Run JavaScript against host-configured snippet providers. Selected results stay
|
|
59
129
|
* out of guest memory except for their declared JSON value. Supplying a catalog
|
|
60
130
|
* enables named chains for calls with a trusted scope.
|
|
131
|
+
*
|
|
132
|
+
* Failures are {@link CodeModeError}s whose message reads
|
|
133
|
+
* `[execute] CODE: detail. Recovery: hint.`; a caller abort rejects with a
|
|
134
|
+
* DOMException. Once an upstream snippet call was dispatched, errors carry
|
|
135
|
+
* `effects: "possible"` and never repeat guest, provider or transport text.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* const execute = createSnippetChain(providers, catalog, { isolation: "worker" });
|
|
140
|
+
* const result = await execute({ code: "return 1;" }, { scope: "user-1" });
|
|
141
|
+
* ```
|
|
61
142
|
*/
|
|
62
|
-
function createSnippetChain(providers, catalog) {
|
|
143
|
+
function createSnippetChain(providers, catalog, options = {}) {
|
|
144
|
+
const isolation = options.isolation ?? "worker";
|
|
145
|
+
(0, sandbox_js_1.assertSandboxIsolation)(isolation);
|
|
146
|
+
const limits = (0, sandbox_js_1.resolveSandboxLimits)(options.limits);
|
|
147
|
+
const aliases = [...providers.keys()];
|
|
63
148
|
// Keep admission state only while saves overlap. Persistent catalogs are read again
|
|
64
149
|
// on the next save so a completed tenant leaves no resident quota state here.
|
|
65
150
|
const activeSaves = new Map();
|
|
66
151
|
async function execute(code, params, context, status) {
|
|
67
152
|
const receipts = new Map();
|
|
68
153
|
const selected = new Map();
|
|
154
|
+
const exposedPorts = new Map();
|
|
155
|
+
const sync = new Map();
|
|
69
156
|
let totalBytes = 0;
|
|
70
|
-
const value = await (0, sandbox_js_1.runProgram)(code, params, async (operation, args, signal) => {
|
|
157
|
+
const value = await (0, sandbox_js_1.runProgram)(code, params, async (operation, args, signal, stopped) => {
|
|
71
158
|
signal.throwIfAborted();
|
|
72
159
|
const [first, second, input] = args;
|
|
73
160
|
if (operation === "panel") {
|
|
74
161
|
const panel = typeof first === "string" ? receipts.get(first) : undefined;
|
|
75
|
-
if (!panel || args.length > 2)
|
|
76
|
-
throw new
|
|
77
|
-
|
|
78
|
-
|
|
162
|
+
if (!panel || args.length > 2) {
|
|
163
|
+
throw new errors_js_1.CodeModeError("PANEL_INVALID", "Select a receipt returned by api.runSnippet in this execution", "Pass receipt.id from this run");
|
|
164
|
+
}
|
|
165
|
+
if (second !== undefined && (typeof second !== "string" || second.length > maxPanelTitle)) {
|
|
166
|
+
throw new errors_js_1.CodeModeError("PANEL_INVALID", `Panel titles may contain at most ${maxPanelTitle} characters`, "Shorten the title", { context: { maxTitleLength: maxPanelTitle } });
|
|
79
167
|
}
|
|
80
168
|
selected.set(panel.id, { ...panel, title: second ?? panel.title });
|
|
169
|
+
exposedPorts.set(panel.id, panel.events);
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
if (operation === "sync") {
|
|
173
|
+
const rule = args.length === 1 ? (0, sync_js_1.parseSnippetSyncRule)(first) : undefined;
|
|
174
|
+
if (!rule || !(0, sync_js_1.supportsSnippetSync)(rule, exposedPorts)) {
|
|
175
|
+
throw new errors_js_1.CodeModeError("SYNC_INVALID", "Sync requires distinct selected panel receipts and their declared event and action", "Select both panels first, then use the source's declared event and the target's declared action");
|
|
176
|
+
}
|
|
177
|
+
sync.set((0, sync_js_1.snippetSyncKey)(rule), rule);
|
|
81
178
|
return null;
|
|
82
179
|
}
|
|
83
180
|
const provider = typeof first === "string" ? providers.get(first) : undefined;
|
|
84
|
-
if (!provider)
|
|
85
|
-
throw new
|
|
181
|
+
if (!provider) {
|
|
182
|
+
throw new errors_js_1.CodeModeError("PROVIDER_UNKNOWN", "No snippet provider is configured under this alias", "Use one of the configured provider aliases", { context: { available: aliases } });
|
|
183
|
+
}
|
|
184
|
+
const alias = first;
|
|
185
|
+
const callProvider = async (tool, args) => {
|
|
186
|
+
// Any provider call may have effects, and its text may echo into guest
|
|
187
|
+
// errors: redact from here on, not only after runSnippet.
|
|
188
|
+
// Reading `provider.names` may have held the event loop past the wall
|
|
189
|
+
// deadline: check the clock right before the provider can act.
|
|
190
|
+
if (stopped())
|
|
191
|
+
throw signal.reason;
|
|
192
|
+
status.dispatched = true;
|
|
193
|
+
try {
|
|
194
|
+
return await provider.call(tool, args, signal, context);
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
signal.throwIfAborted();
|
|
198
|
+
// Provider and transport errors, typed or not, may carry credentials or
|
|
199
|
+
// paths: keep only the fact.
|
|
200
|
+
throw new errors_js_1.CodeModeError("PROVIDER_UNAVAILABLE", `The ${alias} provider could not complete the request`,
|
|
201
|
+
// The request was sent: the provider may have acted before the failure.
|
|
202
|
+
"Check whether the operation took effect before retrying; the failure may be transient", { context: { provider: alias } });
|
|
203
|
+
}
|
|
204
|
+
};
|
|
86
205
|
if (operation === "listSnippets" && args.length === 1) {
|
|
87
|
-
const catalog = await
|
|
206
|
+
const catalog = await callProvider("list_snippets", {});
|
|
88
207
|
signal.throwIfAborted();
|
|
89
208
|
const snippets = isRecord(catalog.structuredContent)
|
|
90
209
|
? catalog.structuredContent.snippets
|
|
91
210
|
: undefined;
|
|
92
211
|
if (catalog.isError || !Array.isArray(snippets)) {
|
|
93
|
-
throw new
|
|
212
|
+
throw new errors_js_1.CodeModeError("PROVIDER_UNAVAILABLE", `The ${alias} provider could not list its snippets`, "Retry once; the failure may be transient", { context: { provider: alias } });
|
|
94
213
|
}
|
|
95
214
|
return snippets.filter((item) => isRecord(item) && typeof item.name === "string" && provider.names.includes(item.name)).map(({ name, description, inputSchema }) => ({ name, description, inputSchema }));
|
|
96
215
|
}
|
|
97
|
-
if (operation !== "runSnippet" || args.length !== 3 ||
|
|
98
|
-
|
|
99
|
-
throw new Error("Choose an approved named snippet and supply its input object.");
|
|
216
|
+
if (operation !== "runSnippet" || args.length !== 3 || !isRecord(input)) {
|
|
217
|
+
throw new errors_js_1.CodeModeError("ARGUMENT_INVALID", "Call api.runSnippet(provider, name, input) with an input object, or api.listSnippets(provider)", "Pass exactly the documented arguments");
|
|
100
218
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const result = await provider.call("run_snippet", { name: second, input }, signal, context);
|
|
104
|
-
signal.throwIfAborted();
|
|
105
|
-
if (result.isError) {
|
|
106
|
-
status.diagnostic = `Snippet ${second}: ${providerError(result)}`;
|
|
107
|
-
throw new Error(status.diagnostic);
|
|
219
|
+
if (typeof second !== "string" || !provider.names.includes(second)) {
|
|
220
|
+
throw new errors_js_1.CodeModeError("SNIPPET_NOT_APPROVED", "The requested snippet is not approved for this provider", "Call api.listSnippets(provider) and use one of its names", { context: { provider: alias, allowed: [...provider.names] } });
|
|
108
221
|
}
|
|
222
|
+
const result = await callProvider("run_snippet", { name: second, input });
|
|
223
|
+
signal.throwIfAborted();
|
|
224
|
+
if (result.isError)
|
|
225
|
+
throw providerError(alias, second, result);
|
|
109
226
|
if (!isRecord(result.structuredContent) || !Object.hasOwn(result.structuredContent, "value")) {
|
|
110
|
-
|
|
111
|
-
throw new Error(status.diagnostic);
|
|
227
|
+
throw new errors_js_1.CodeModeError("PROVIDER_RESULT_INVALID", `Snippet ${second} returned an invalid result`, "Report the provider bug; retrying will fail again", { context: { provider: alias, snippet: second } });
|
|
112
228
|
}
|
|
113
229
|
const value = result.structuredContent.value;
|
|
114
|
-
(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
230
|
+
const tooLarge = (limit) => new errors_js_1.CodeModeError("RECEIPT_TOO_LARGE", `Snippet ${second} returned more than the board accepts`, "Select smaller results or fewer panels", { context: { provider: alias, snippet: second, limit } });
|
|
231
|
+
try {
|
|
232
|
+
(0, sandbox_js_1.encodeValue)(value, limits.valueLength);
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
throw tooLarge(limits.valueLength);
|
|
118
236
|
}
|
|
237
|
+
let receiptSize;
|
|
238
|
+
try {
|
|
239
|
+
receiptSize = new TextEncoder().encode((0, sandbox_js_1.encodeValue)(result, maxNativeSize)).byteLength;
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
throw tooLarge(maxNativeSize);
|
|
243
|
+
}
|
|
244
|
+
totalBytes += receiptSize;
|
|
245
|
+
if (totalBytes > maxNativeBytes)
|
|
246
|
+
throw tooLarge(maxNativeBytes);
|
|
119
247
|
const id = crypto.randomUUID();
|
|
120
|
-
|
|
248
|
+
const events = (0, sync_js_1.snippetPorts)(provider.events, second);
|
|
249
|
+
receipts.set(id, {
|
|
250
|
+
id,
|
|
251
|
+
provider: alias,
|
|
252
|
+
name: second,
|
|
253
|
+
title: second,
|
|
254
|
+
result,
|
|
255
|
+
...(events ? { events } : {}),
|
|
256
|
+
});
|
|
121
257
|
return { id, value };
|
|
122
|
-
}, context.signal);
|
|
123
|
-
return { value, panels: [...selected.values()] };
|
|
258
|
+
}, context.signal, { isolation, limits });
|
|
259
|
+
return { value, panels: [...selected.values()], sync: [...sync.values()] };
|
|
124
260
|
}
|
|
125
261
|
async function call(input, context, status) {
|
|
126
262
|
const { signal, scope } = context;
|
|
127
263
|
signal?.throwIfAborted();
|
|
128
|
-
if (!isRecord(input))
|
|
129
|
-
throw new
|
|
264
|
+
if (!isRecord(input)) {
|
|
265
|
+
throw new errors_js_1.CodeModeError("INVALID_INPUT", "Supply execute inputs as a JSON object", "Pass an object with code, replay or listSaved");
|
|
266
|
+
}
|
|
130
267
|
const has = (key) => Object.hasOwn(input, key);
|
|
131
268
|
const keysAllowed = (...keys) => Object.keys(input).every((key) => keys.includes(key));
|
|
132
269
|
if (has("code") && !has("saveAs") && keysAllowed("code", "params")) {
|
|
133
|
-
if (typeof input.code !== "string")
|
|
134
|
-
throw new
|
|
270
|
+
if (typeof input.code !== "string") {
|
|
271
|
+
throw new errors_js_1.CodeModeError("INVALID_INPUT", "Supply code as a JavaScript function body", "Pass code as a string");
|
|
272
|
+
}
|
|
135
273
|
const result = await execute(input.code, validateParams(input.params === undefined ? {} : input.params), context, status);
|
|
136
274
|
signal?.throwIfAborted();
|
|
137
|
-
return output(result.value, result.panels);
|
|
275
|
+
return output(result.value, result.panels, undefined, result.sync);
|
|
138
276
|
}
|
|
139
277
|
if (!catalog || typeof scope !== "string" || !scope.trim()) {
|
|
140
|
-
throw new
|
|
278
|
+
throw new errors_js_1.CodeModeError("SAVED_CHAINS_UNAVAILABLE", "Saved chains require a configured catalog and a trusted scope", "Run the code directly, without saveAs, replay or listSaved");
|
|
141
279
|
}
|
|
142
280
|
if (input.listSaved === true && keysAllowed("listSaved")) {
|
|
143
|
-
const snippets = await catalog.list(scope);
|
|
281
|
+
const snippets = await fromCatalog(catalog.list(scope), signal);
|
|
144
282
|
signal?.throwIfAborted();
|
|
145
283
|
return output({ snippets });
|
|
146
284
|
}
|
|
147
285
|
if ((0, providers_js_1.isSnippetName)(input.replay) && keysAllowed("replay", "params")) {
|
|
148
|
-
const result = await catalog.run(scope, input.replay, input.params === undefined ? {} : input.params, {
|
|
286
|
+
const result = await fromCatalog(catalog.run(scope, input.replay, input.params === undefined ? {} : input.params, {
|
|
149
287
|
validate: validateParams,
|
|
150
288
|
execute: (code, params) => execute(code, params, context, status),
|
|
151
|
-
});
|
|
289
|
+
}), signal);
|
|
152
290
|
signal?.throwIfAborted();
|
|
153
|
-
return output(result.value, result.panels);
|
|
291
|
+
return output(result.value, result.panels, undefined, result.sync);
|
|
154
292
|
}
|
|
155
293
|
if (typeof input.code !== "string" || !has("saveAs") || !keysAllowed("code", "saveAs", "params")) {
|
|
156
|
-
throw new
|
|
294
|
+
throw new errors_js_1.CodeModeError("INVALID_INPUT", "Supply code, replay, or listSaved", "Pass exactly one of code (optionally with saveAs and params), replay (with params) or listSaved");
|
|
157
295
|
}
|
|
158
296
|
const name = input.saveAs;
|
|
159
297
|
if (!(0, providers_js_1.isSnippetName)(name)) {
|
|
160
|
-
throw new
|
|
298
|
+
throw new errors_js_1.CodeModeError("SAVE_NAME_INVALID", "Supply a nonempty saved chain name of up to 256 UTF-8 bytes without surrounding whitespace", "Use a shorter, trimmed name", { context: { maxBytes: 256 } });
|
|
161
299
|
}
|
|
162
300
|
const params = validateParams(input.params === undefined ? {} : input.params);
|
|
163
301
|
const keys = Object.keys(params);
|
|
164
302
|
if (keys.length > 32 || keys.some((key) => new TextEncoder().encode(key).byteLength > 128)) {
|
|
165
|
-
throw new
|
|
303
|
+
throw new errors_js_1.CodeModeError("PARAMS_INVALID", "Saved chain parameter contract exceeds its size limit", "Use at most 32 parameters with names of up to 128 bytes", { context: { maxKeys: 32, maxKeyBytes: 128 } });
|
|
166
304
|
}
|
|
167
305
|
let usage = activeSaves.get(scope);
|
|
168
306
|
if (!usage) {
|
|
169
307
|
usage = {
|
|
170
308
|
users: 0,
|
|
171
|
-
stored: catalog.list(scope).then((entries) => new Set(entries.map((entry) => entry.name))),
|
|
309
|
+
stored: fromCatalog(catalog.list(scope)).then((entries) => new Set(entries.map((entry) => entry.name))),
|
|
172
310
|
saving: new Set(),
|
|
173
311
|
};
|
|
174
312
|
activeSaves.set(scope, usage);
|
|
@@ -176,13 +314,15 @@ function createSnippetChain(providers, catalog) {
|
|
|
176
314
|
usage.users++;
|
|
177
315
|
let reserved = false;
|
|
178
316
|
try {
|
|
179
|
-
const savedNames = await usage.stored;
|
|
317
|
+
const savedNames = await fromCatalog(usage.stored, signal);
|
|
180
318
|
signal?.throwIfAborted();
|
|
181
|
-
if (usage.saving.has(name))
|
|
182
|
-
throw new
|
|
319
|
+
if (usage.saving.has(name)) {
|
|
320
|
+
throw new errors_js_1.CodeModeError("SAVE_NAME_CONFLICT", "A save for this chain is already in progress", "Wait for it to finish, then call listSaved");
|
|
321
|
+
}
|
|
183
322
|
if (!savedNames.has(name)) {
|
|
184
|
-
if (savedNames.size >= maxSavedChains)
|
|
185
|
-
throw new
|
|
323
|
+
if (savedNames.size >= maxSavedChains) {
|
|
324
|
+
throw new errors_js_1.CodeModeError("SAVE_CATALOG_FULL", "The saved chain catalog is full", "Reuse an existing name, or run the code without saveAs", { context: { max: maxSavedChains } });
|
|
325
|
+
}
|
|
186
326
|
savedNames.add(name);
|
|
187
327
|
reserved = true;
|
|
188
328
|
}
|
|
@@ -190,19 +330,25 @@ function createSnippetChain(providers, catalog) {
|
|
|
190
330
|
usage.saving.add(name);
|
|
191
331
|
try {
|
|
192
332
|
if (!reserved) {
|
|
193
|
-
const previous = await catalog.inspect(scope, name);
|
|
194
|
-
if (previous.code !== input.code)
|
|
195
|
-
throw new
|
|
333
|
+
const previous = await fromCatalog(catalog.inspect(scope, name), signal);
|
|
334
|
+
if (previous.code !== input.code) {
|
|
335
|
+
throw new errors_js_1.CodeModeError("SAVE_NAME_CONFLICT", "Snippet name already in use", "Pick another name, or replay the saved chain");
|
|
336
|
+
}
|
|
196
337
|
validateParams(params, previous.parameters);
|
|
197
338
|
}
|
|
198
339
|
signal?.throwIfAborted();
|
|
199
340
|
const result = await execute(input.code, params, context, status);
|
|
200
341
|
signal?.throwIfAborted();
|
|
201
|
-
status.saving = true;
|
|
202
342
|
const ref = catalog.recordSuccess(scope, input.code, params);
|
|
343
|
+
status.saving = true;
|
|
203
344
|
const saved = await catalog.save(scope, ref, name);
|
|
345
|
+
status.saved = true;
|
|
346
|
+
// The name stays counted: the chain exists even if the caller gave up meanwhile.
|
|
204
347
|
reserved = false;
|
|
205
|
-
|
|
348
|
+
// A confirmed write after the caller aborted is not a success the caller waited for.
|
|
349
|
+
if (signal?.aborted)
|
|
350
|
+
throw signal.reason;
|
|
351
|
+
return output(result.value, result.panels, saved.name, result.sync);
|
|
206
352
|
}
|
|
207
353
|
finally {
|
|
208
354
|
usage.saving.delete(name);
|
|
@@ -216,28 +362,41 @@ function createSnippetChain(providers, catalog) {
|
|
|
216
362
|
}
|
|
217
363
|
}
|
|
218
364
|
return async (input, context = {}) => {
|
|
219
|
-
const status = { dispatched: false, saving: false };
|
|
365
|
+
const status = { dispatched: false, saving: false, saved: false };
|
|
220
366
|
try {
|
|
221
367
|
return await call(input, context, status);
|
|
222
368
|
}
|
|
223
369
|
catch (error) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
370
|
+
const signal = context.signal;
|
|
371
|
+
if (status.saving) {
|
|
372
|
+
// A catalog write was attempted: classify it before the exception type, since a
|
|
373
|
+
// store may fail with a DOMException (a lost acknowledgement). Say to look before
|
|
374
|
+
// retrying. Only a write the store confirmed is reported as saved.
|
|
375
|
+
if (status.saved && signal?.aborted) {
|
|
376
|
+
throw interrupted(signal.reason, [
|
|
377
|
+
SAVED_RECOVERY,
|
|
378
|
+
...(status.dispatched ? [errors_js_1.POSSIBLE_EFFECTS_RECOVERY] : []),
|
|
379
|
+
]);
|
|
380
|
+
}
|
|
381
|
+
throw status.dispatched ? (0, errors_js_1.withPossibleEffects)(saveFailed()) : saveFailed();
|
|
382
|
+
}
|
|
383
|
+
if (!status.dispatched) {
|
|
384
|
+
if (error instanceof errors_js_1.CodeModeError || error instanceof DOMException)
|
|
385
|
+
throw error;
|
|
386
|
+
// The caller's own reason, whatever its type.
|
|
387
|
+
if (signal?.aborted)
|
|
388
|
+
throw signal.reason;
|
|
389
|
+
throw new errors_js_1.CodeModeError("EXECUTION_FAILED", "The chain failed before calling any provider", "Retry once, then report the failure");
|
|
390
|
+
}
|
|
391
|
+
if (signal?.aborted)
|
|
392
|
+
throw interrupted(signal.reason, [errors_js_1.POSSIBLE_EFFECTS_RECOVERY]);
|
|
393
|
+
if (error instanceof errors_js_1.CodeModeError) {
|
|
394
|
+
// After a dispatch, guest text might echo upstream values: keep only the kind.
|
|
395
|
+
throw (0, errors_js_1.withPossibleEffects)(error.code === "GUEST_ERROR"
|
|
396
|
+
? new errors_js_1.CodeModeError("GUEST_ERROR", `The program threw ${error.context.name ?? "an exception"}`, error.recovery, { context: error.context })
|
|
397
|
+
: error);
|
|
398
|
+
}
|
|
399
|
+
throw (0, errors_js_1.withPossibleEffects)(new errors_js_1.CodeModeError("EXECUTION_FAILED", "The chain failed after calling a provider", "Report the failure"));
|
|
241
400
|
}
|
|
242
401
|
};
|
|
243
402
|
}
|
|
@@ -6,6 +6,7 @@ export type SnippetMcpClient = Pick<Client, "callTool">;
|
|
|
6
6
|
export type SnippetProviderBinding = {
|
|
7
7
|
readonly alias: string;
|
|
8
8
|
readonly snippets: readonly string[];
|
|
9
|
+
readonly events?: SnippetProvider["events"];
|
|
9
10
|
} & ({
|
|
10
11
|
readonly url: URL | string;
|
|
11
12
|
readonly requestInit?: RequestInit;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connections.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/connections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiC,MAAM,8BAA8B,CAAC;AACrF,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AAExB,mGAAmG;AACnG,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAExD,gFAAgF;AAChF,MAAM,MAAM,sBAAsB,GAC9B;IACA,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"connections.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/connections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiC,MAAM,8BAA8B,CAAC;AACrF,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AAExB,mGAAmG;AACnG,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAExD,gFAAgF;AAChF,MAAM,MAAM,sBAAsB,GAC9B;IACA,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;CAC7C,GACC,CAAC;IACD,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;IACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC;CACzB,GAAG;IACF,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,EACX,gBAAgB,GAChB,CAAC,CAAC,OAAO,EAAE,mBAAmB,KAAK,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC;IACrF,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC;CAC9B,CAAC,CAAC;AAEL,iGAAiG;AACjG,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACzD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,SAAS,sBAAsB,EAAE,EAC3C,OAAO,GAAE;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GAC9C,OAAO,CAAC,0BAA0B,CAAC,CAkHrC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Machine-readable failures of the Code Mode `execute` tool.
|
|
3
|
+
*
|
|
4
|
+
* An MCP host usually forwards only `error.message` to the model, so the message
|
|
5
|
+
* itself is the contract, in the format shared with other MCPView Code Mode
|
|
6
|
+
* servers:
|
|
7
|
+
*
|
|
8
|
+
* [execute] <CODE>: <detail>. Recovery: <recovery>.
|
|
9
|
+
*
|
|
10
|
+
* Guest programs see the same errors as `Error` objects that also carry
|
|
11
|
+
* `code`, `recovery` and `context`, so a program can branch on `e.code`.
|
|
12
|
+
*
|
|
13
|
+
* @module code-mode/errors
|
|
14
|
+
*/
|
|
15
|
+
/** Every code the Code Mode tool can report. Codes are API: never rename one. */
|
|
16
|
+
export declare const CODE_MODE_ERROR_CODES: readonly ["INVALID_INPUT", "PARAMS_INVALID", "SAVED_CHAINS_UNAVAILABLE", "SAVE_NAME_INVALID", "SAVE_NAME_CONFLICT", "SAVE_CATALOG_FULL", "SAVE_FAILED", "CATALOG_ERROR", "GUEST_ERROR", "RESOURCE_LIMIT", "TIME_LIMIT", "RESULT_INVALID", "GUEST_STALLED", "UNAWAITED_OPERATION", "OPERATION_LIMIT", "ARGUMENT_INVALID", "OPERATION_FAILED", "SANDBOX_UNAVAILABLE", "SANDBOX_FAILED", "PROVIDER_UNKNOWN", "SNIPPET_NOT_APPROVED", "PROVIDER_UNAVAILABLE", "PROVIDER_ERROR", "PROVIDER_RESULT_INVALID", "RECEIPT_TOO_LARGE", "PANEL_INVALID", "SYNC_INVALID", "EXECUTION_FAILED", "INTERRUPTED"];
|
|
17
|
+
/** A Code Mode error code. */
|
|
18
|
+
export type CodeModeErrorCode = typeof CODE_MODE_ERROR_CODES[number];
|
|
19
|
+
/** Small, host-authored facts about a failure. Never guest or provider text. */
|
|
20
|
+
export type CodeModeErrorContext = Readonly<Record<string, string | number | boolean | readonly string[]>>;
|
|
21
|
+
/**
|
|
22
|
+
* `possible` when an upstream snippet call was already dispatched, so it may
|
|
23
|
+
* have changed something before the failure.
|
|
24
|
+
*/
|
|
25
|
+
export type CodeModeErrorEffects = "none" | "possible";
|
|
26
|
+
/** The serializable fields of a {@link CodeModeError}. */
|
|
27
|
+
export interface CodeModeErrorFields {
|
|
28
|
+
readonly code: CodeModeErrorCode;
|
|
29
|
+
readonly detail: string;
|
|
30
|
+
readonly recovery: string;
|
|
31
|
+
readonly context: CodeModeErrorContext;
|
|
32
|
+
readonly effects: CodeModeErrorEffects;
|
|
33
|
+
}
|
|
34
|
+
/** Recovery suffix used once an upstream operation may have completed. */
|
|
35
|
+
export declare const POSSIBLE_EFFECTS_RECOVERY = "One or more upstream operations may have completed. Check their effects before replaying the chain";
|
|
36
|
+
/**
|
|
37
|
+
* Render `[execute] CODE: detail. Recovery: recovery.`
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* formatCodeModeError("TIME_LIMIT", "The program used its 2000 ms of CPU", "Split the work");
|
|
42
|
+
* // "[execute] TIME_LIMIT: The program used its 2000 ms of CPU. Recovery: Split the work."
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function formatCodeModeError(code: CodeModeErrorCode, detail: string, recovery: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* A Code Mode failure with a stable code, a recovery hint and context.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* throw new CodeModeError("PROVIDER_UNKNOWN", "No provider is configured as cad", "Use one of the listed aliases", {
|
|
52
|
+
* context: { available: ["slicer"] },
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare class CodeModeError extends Error {
|
|
57
|
+
readonly name = "CodeModeError";
|
|
58
|
+
readonly code: CodeModeErrorCode;
|
|
59
|
+
/** What went wrong, without the code prefix or the recovery hint. */
|
|
60
|
+
readonly detail: string;
|
|
61
|
+
readonly recovery: string;
|
|
62
|
+
readonly context: CodeModeErrorContext;
|
|
63
|
+
readonly effects: CodeModeErrorEffects;
|
|
64
|
+
constructor(code: CodeModeErrorCode, detail: string, recovery: string, options?: {
|
|
65
|
+
context?: Record<string, unknown>;
|
|
66
|
+
effects?: CodeModeErrorEffects;
|
|
67
|
+
});
|
|
68
|
+
/** Plain fields, safe to post across a worker boundary. */
|
|
69
|
+
toJSON(): CodeModeErrorFields;
|
|
70
|
+
}
|
|
71
|
+
/** True for a {@link CodeModeError}. */
|
|
72
|
+
export declare function isCodeModeError(error: unknown): error is CodeModeError;
|
|
73
|
+
/**
|
|
74
|
+
* Rebuild an error from {@link CodeModeErrorFields}, for example after it
|
|
75
|
+
* crossed a worker boundary. Returns undefined for any other shape.
|
|
76
|
+
*/
|
|
77
|
+
export declare function codeModeErrorFromFields(value: unknown): CodeModeError | undefined;
|
|
78
|
+
/** The same failure, reported once an upstream operation may have completed. */
|
|
79
|
+
export declare function withPossibleEffects(error: CodeModeError): CodeModeError;
|
|
80
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,iFAAiF;AACjF,eAAO,MAAM,qBAAqB,ikBAkCxB,CAAC;AAEX,8BAA8B;AAC9B,MAAM,MAAM,iBAAiB,GAAG,OAAO,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAErE,gFAAgF;AAChF,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CACzC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,MAAM,EAAE,CAAC,CAC9D,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,UAAU,CAAC;AAEvD,0DAA0D;AAC1D,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC;CACxC;AAED,0EAA0E;AAC1E,eAAO,MAAM,yBAAyB,uGACgE,CAAC;AAOvG;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,iBAAiB,EACvB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,MAAM,CAIR;AAED;;;;;;;;;GASG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAkB,IAAI,mBAAmB;IACzC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,qEAAqE;IACrE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC;gBAGrC,IAAI,EAAE,iBAAiB,EACvB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,OAAO,CAAC,EAAE,oBAAoB,CAAA;KAAO;IAUrF,2DAA2D;IAC3D,MAAM,IAAI,mBAAmB;CAS9B;AAUD,wCAAwC;AACxC,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE;AAID;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,GAAG,SAAS,CAejF;AAED,gFAAgF;AAChF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa,CAQvE"}
|