@ethisyscore/extension-runtime 1.135.0 → 1.137.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/README.md +2 -2
- package/dist/MockPluginStorage-BM3bq99B.d.cts +35 -0
- package/dist/MockPluginStorage-BndTX2RR.d.ts +35 -0
- package/dist/{bridge-client-RJOl8WlU.d.ts → bridge-client-CkxYcZcm.d.ts} +1 -1
- package/dist/{bridge-client-D9EYFq1l.d.cts → bridge-client-DkogtCvn.d.cts} +1 -1
- package/dist/{bridge-envelopes-M5a42rAy.d.cts → bridge-envelopes-BcKu-nQm.d.cts} +72 -1
- package/dist/{bridge-envelopes-M5a42rAy.d.ts → bridge-envelopes-BcKu-nQm.d.ts} +72 -1
- package/dist/host/index.cjs +57 -2
- package/dist/host/index.cjs.map +1 -1
- package/dist/host/index.d.cts +3 -3
- package/dist/host/index.d.ts +3 -3
- package/dist/host/index.js +57 -2
- package/dist/host/index.js.map +1 -1
- package/dist/mock-host/cli.cjs +273 -7
- package/dist/mock-host/cli.cjs.map +1 -1
- package/dist/mock-host/cli.d.cts +10 -3
- package/dist/mock-host/cli.d.ts +10 -3
- package/dist/mock-host/cli.js +272 -8
- package/dist/mock-host/cli.js.map +1 -1
- package/dist/mock-host/index.cjs +236 -1
- package/dist/mock-host/index.cjs.map +1 -1
- package/dist/mock-host/index.d.cts +14 -4
- package/dist/mock-host/index.d.ts +14 -4
- package/dist/mock-host/index.js +236 -2
- package/dist/mock-host/index.js.map +1 -1
- package/dist/plugin/index.cjs +378 -100
- package/dist/plugin/index.cjs.map +1 -1
- package/dist/plugin/index.d.cts +171 -6
- package/dist/plugin/index.d.ts +171 -6
- package/dist/plugin/index.js +366 -101
- package/dist/plugin/index.js.map +1 -1
- package/dist/{transport-UaoDRdm3.d.cts → transport-D1lE-5nt.d.cts} +30 -3
- package/dist/{transport-CFzJQiFG.d.ts → transport-INVtDo2s.d.ts} +30 -3
- package/package.json +1 -1
package/dist/plugin/index.js
CHANGED
|
@@ -5,7 +5,347 @@ import ReactReconciler from 'react-reconciler';
|
|
|
5
5
|
import { LegacyRoot, DefaultEventPriority } from 'react-reconciler/constants.js';
|
|
6
6
|
import { MUTATION_TYPE_UPDATE_TEXT, MUTATION_TYPE_UPDATE_PROPERTY, MUTATION_TYPE_INSERT_CHILD, MUTATION_TYPE_REMOVE_CHILD, NODE_TYPE_TEXT, NODE_TYPE_ELEMENT, ROOT_ID } from '@remote-dom/core';
|
|
7
7
|
|
|
8
|
-
// src/
|
|
8
|
+
// src/bridge/mcp-error.ts
|
|
9
|
+
var MCP_ERROR_CODES = [
|
|
10
|
+
"unauthorized",
|
|
11
|
+
"forbidden",
|
|
12
|
+
"not_found",
|
|
13
|
+
"invalid_request",
|
|
14
|
+
"conflict",
|
|
15
|
+
"rate_limited",
|
|
16
|
+
"timeout",
|
|
17
|
+
"unavailable",
|
|
18
|
+
"internal"
|
|
19
|
+
];
|
|
20
|
+
function isMcpErrorCode(value) {
|
|
21
|
+
return typeof value === "string" && MCP_ERROR_CODES.includes(value);
|
|
22
|
+
}
|
|
23
|
+
var RETRYABLE = ["rate_limited", "timeout", "unavailable"];
|
|
24
|
+
function isRetryableMcpErrorCode(code) {
|
|
25
|
+
return RETRYABLE.includes(code);
|
|
26
|
+
}
|
|
27
|
+
var McpToolError = class extends Error {
|
|
28
|
+
/** Machine-readable classification. `internal` when the host sent none. */
|
|
29
|
+
code;
|
|
30
|
+
/**
|
|
31
|
+
* Marks the instance for {@link isMcpToolError}. A structural marker rather than a prototype
|
|
32
|
+
* check because the error can be constructed in one bundle and inspected in another, where
|
|
33
|
+
* `instanceof` compares two different class objects and answers false.
|
|
34
|
+
*/
|
|
35
|
+
isMcpToolError = true;
|
|
36
|
+
constructor(message, code = "internal") {
|
|
37
|
+
super(message);
|
|
38
|
+
this.name = "McpHostError";
|
|
39
|
+
this.code = code;
|
|
40
|
+
}
|
|
41
|
+
/** True when this failure is worth retrying unchanged. */
|
|
42
|
+
get retryable() {
|
|
43
|
+
return isRetryableMcpErrorCode(this.code);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
function isMcpToolError(value) {
|
|
47
|
+
return value instanceof McpToolError || value !== null && typeof value === "object" && value.isMcpToolError === true && isMcpErrorCode(value.code);
|
|
48
|
+
}
|
|
49
|
+
function mcpErrorCodeFromHttpStatus(status) {
|
|
50
|
+
switch (status) {
|
|
51
|
+
case 401:
|
|
52
|
+
return "unauthorized";
|
|
53
|
+
case 403:
|
|
54
|
+
return "forbidden";
|
|
55
|
+
case 404:
|
|
56
|
+
return "not_found";
|
|
57
|
+
case 400:
|
|
58
|
+
case 422:
|
|
59
|
+
return "invalid_request";
|
|
60
|
+
case 409:
|
|
61
|
+
case 412:
|
|
62
|
+
return "conflict";
|
|
63
|
+
case 429:
|
|
64
|
+
return "rate_limited";
|
|
65
|
+
case 408:
|
|
66
|
+
case 504:
|
|
67
|
+
return "timeout";
|
|
68
|
+
case 502:
|
|
69
|
+
case 503:
|
|
70
|
+
return "unavailable";
|
|
71
|
+
default:
|
|
72
|
+
return "internal";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function classifyHostResponse(response) {
|
|
76
|
+
if (response.ok) {
|
|
77
|
+
return void 0;
|
|
78
|
+
}
|
|
79
|
+
if (isMcpErrorCode(response.mcpErrorCode)) {
|
|
80
|
+
return response.mcpErrorCode;
|
|
81
|
+
}
|
|
82
|
+
return typeof response.status === "number" ? mcpErrorCodeFromHttpStatus(response.status) : "internal";
|
|
83
|
+
}
|
|
84
|
+
function classifyHostError(err) {
|
|
85
|
+
if (err === null || typeof err !== "object") {
|
|
86
|
+
return "internal";
|
|
87
|
+
}
|
|
88
|
+
const candidate = err;
|
|
89
|
+
if (isMcpErrorCode(candidate.mcpErrorCode)) {
|
|
90
|
+
return candidate.mcpErrorCode;
|
|
91
|
+
}
|
|
92
|
+
const status = typeof candidate.status === "number" ? candidate.status : typeof candidate.statusCode === "number" ? candidate.statusCode : void 0;
|
|
93
|
+
if (status !== void 0) {
|
|
94
|
+
return mcpErrorCodeFromHttpStatus(status);
|
|
95
|
+
}
|
|
96
|
+
if (candidate.name === "AbortError" || candidate.name === "TimeoutError") {
|
|
97
|
+
return "timeout";
|
|
98
|
+
}
|
|
99
|
+
return "internal";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/plugin/pluginStorageUpload.ts
|
|
103
|
+
var PLUGIN_STORAGE_UPLOAD_MAX_BYTES = 30 * 1024 * 1024;
|
|
104
|
+
var PLUGIN_STORAGE_PREFIX_MAX_LENGTH = 84;
|
|
105
|
+
var PLUGIN_STORAGE_PATH_MAX_LENGTH = 128;
|
|
106
|
+
var PluginStorageUploadError = class extends McpToolError {
|
|
107
|
+
/** What went wrong, in terms a caller branches on. */
|
|
108
|
+
reason;
|
|
109
|
+
/** HTTP status from the server, when the host surfaced one. */
|
|
110
|
+
status;
|
|
111
|
+
/** Structural marker for {@link isPluginStorageUploadError}. */
|
|
112
|
+
isPluginStorageUploadError = true;
|
|
113
|
+
constructor(message, reason, options = {}) {
|
|
114
|
+
super(message, options.code ?? codeForReason(reason, options.status));
|
|
115
|
+
this.name = "PluginStorageUploadError";
|
|
116
|
+
this.reason = reason;
|
|
117
|
+
this.status = options.status;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
function isPluginStorageUploadError(value) {
|
|
121
|
+
return value instanceof PluginStorageUploadError || isMcpToolError(value) && value.isPluginStorageUploadError === true;
|
|
122
|
+
}
|
|
123
|
+
function pluginStorageUploadReasonFromStatus(status) {
|
|
124
|
+
switch (status) {
|
|
125
|
+
case 400:
|
|
126
|
+
return "invalid_prefix";
|
|
127
|
+
case 401:
|
|
128
|
+
return "unauthorized";
|
|
129
|
+
case 403:
|
|
130
|
+
return "forbidden";
|
|
131
|
+
case 413:
|
|
132
|
+
return "too_large";
|
|
133
|
+
case 408:
|
|
134
|
+
return "timeout";
|
|
135
|
+
case 415:
|
|
136
|
+
return "unsupported_type";
|
|
137
|
+
case 503:
|
|
138
|
+
return "busy";
|
|
139
|
+
case 507:
|
|
140
|
+
return "quota_exceeded";
|
|
141
|
+
case 500:
|
|
142
|
+
return "storage_failed";
|
|
143
|
+
default:
|
|
144
|
+
return "unknown";
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function toPluginStorageUploadError(err) {
|
|
148
|
+
if (isPluginStorageUploadError(err)) {
|
|
149
|
+
return err;
|
|
150
|
+
}
|
|
151
|
+
const message = err instanceof Error ? err.message : typeof err === "string" ? err : "Plugin storage upload failed";
|
|
152
|
+
const candidate = err !== null && typeof err === "object" ? err : {};
|
|
153
|
+
const status = typeof candidate.status === "number" ? candidate.status : typeof candidate.statusCode === "number" ? candidate.statusCode : void 0;
|
|
154
|
+
if (status !== void 0) {
|
|
155
|
+
return new PluginStorageUploadError(message, pluginStorageUploadReasonFromStatus(status), { status });
|
|
156
|
+
}
|
|
157
|
+
if (candidate.name === "AbortError") {
|
|
158
|
+
return new PluginStorageUploadError(message, "aborted", { code: "timeout" });
|
|
159
|
+
}
|
|
160
|
+
if (isMcpToolError(err)) {
|
|
161
|
+
return new PluginStorageUploadError(message, reasonForCode(err.code), { code: err.code });
|
|
162
|
+
}
|
|
163
|
+
return new PluginStorageUploadError(message, "unknown");
|
|
164
|
+
}
|
|
165
|
+
function validatePluginStoragePrefix(raw) {
|
|
166
|
+
if (typeof raw !== "string" || raw.trim().length === 0) {
|
|
167
|
+
return { ok: false, error: "A storage path prefix is required." };
|
|
168
|
+
}
|
|
169
|
+
if (raw.length > PLUGIN_STORAGE_PREFIX_MAX_LENGTH) {
|
|
170
|
+
return {
|
|
171
|
+
ok: false,
|
|
172
|
+
error: `The storage path prefix must be at most ${PLUGIN_STORAGE_PREFIX_MAX_LENGTH} characters, so the stored path fits ${PLUGIN_STORAGE_PATH_MAX_LENGTH}.`
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
if (!/^[A-Za-z0-9_\-/]+$/.test(raw)) {
|
|
176
|
+
return {
|
|
177
|
+
ok: false,
|
|
178
|
+
error: "The storage path prefix may contain only letters, digits, '-', '_' and '/' separators."
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
if (raw.split("/").some((segment) => segment.length === 0)) {
|
|
182
|
+
return {
|
|
183
|
+
ok: false,
|
|
184
|
+
error: "The storage path prefix must not start or end with '/' or contain an empty segment."
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
return { ok: true, prefix: raw };
|
|
188
|
+
}
|
|
189
|
+
function assertValidPluginStoragePrefix(raw) {
|
|
190
|
+
const result = validatePluginStoragePrefix(raw);
|
|
191
|
+
if (!result.ok) {
|
|
192
|
+
throw new PluginStorageUploadError(result.error, "invalid_prefix");
|
|
193
|
+
}
|
|
194
|
+
return result.prefix;
|
|
195
|
+
}
|
|
196
|
+
var PLUGIN_STORAGE_UPLOAD_CONTENT_TYPES = Object.freeze({
|
|
197
|
+
pdf: ["application/pdf"],
|
|
198
|
+
png: ["image/png"],
|
|
199
|
+
jpg: ["image/jpeg", "image/pjpeg", "image/jpg"],
|
|
200
|
+
jpeg: ["image/jpeg", "image/pjpeg", "image/jpg"],
|
|
201
|
+
gif: ["image/gif"],
|
|
202
|
+
webp: ["image/webp"],
|
|
203
|
+
doc: ["application/msword"],
|
|
204
|
+
docx: ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],
|
|
205
|
+
xls: ["application/vnd.ms-excel"],
|
|
206
|
+
xlsx: ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
|
|
207
|
+
ppt: ["application/vnd.ms-powerpoint"],
|
|
208
|
+
pptx: ["application/vnd.openxmlformats-officedocument.presentationml.presentation"],
|
|
209
|
+
odt: ["application/vnd.oasis.opendocument.text"],
|
|
210
|
+
ods: ["application/vnd.oasis.opendocument.spreadsheet"],
|
|
211
|
+
odp: ["application/vnd.oasis.opendocument.presentation"],
|
|
212
|
+
txt: ["text/plain"],
|
|
213
|
+
csv: ["text/csv", "application/vnd.ms-excel", "application/csv", "text/plain"],
|
|
214
|
+
zip: ["application/zip", "application/x-zip-compressed", "application/x-zip"],
|
|
215
|
+
mp3: ["audio/mpeg", "audio/mp3"],
|
|
216
|
+
m4a: ["audio/mp4", "audio/x-m4a"],
|
|
217
|
+
mp4: ["video/mp4"]
|
|
218
|
+
});
|
|
219
|
+
var OCTET_STREAM = "application/octet-stream";
|
|
220
|
+
function pluginStorageSafeExtension(fileName) {
|
|
221
|
+
if (typeof fileName !== "string" || fileName.trim().length === 0) {
|
|
222
|
+
return "";
|
|
223
|
+
}
|
|
224
|
+
const leaf = fileName.split(/[\\/]/).pop() ?? "";
|
|
225
|
+
const dot = leaf.lastIndexOf(".");
|
|
226
|
+
if (dot < 0) {
|
|
227
|
+
return "";
|
|
228
|
+
}
|
|
229
|
+
const body = leaf.slice(dot + 1);
|
|
230
|
+
return /^[A-Za-z0-9]{1,10}$/.test(body) ? `.${body.toLowerCase()}` : "";
|
|
231
|
+
}
|
|
232
|
+
function resolvePluginStorageContentType(fileName, declaredContentType) {
|
|
233
|
+
const extension = pluginStorageSafeExtension(fileName).slice(1);
|
|
234
|
+
const allowed = extension.length > 0 && Object.prototype.hasOwnProperty.call(PLUGIN_STORAGE_UPLOAD_CONTENT_TYPES, extension) ? PLUGIN_STORAGE_UPLOAD_CONTENT_TYPES[extension] : void 0;
|
|
235
|
+
if (allowed === void 0) {
|
|
236
|
+
return {
|
|
237
|
+
ok: false,
|
|
238
|
+
error: "This file type is not allowed. Allowed: " + Object.keys(PLUGIN_STORAGE_UPLOAD_CONTENT_TYPES).sort().join(", ") + "."
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
const declared = mediaTypeOf(declaredContentType);
|
|
242
|
+
if (declared === void 0 || declared === OCTET_STREAM || allowed.includes(declared)) {
|
|
243
|
+
return { ok: true, contentType: allowed[0] };
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
ok: false,
|
|
247
|
+
error: `The declared content type '${declared}' does not match the file extension '.${extension}'.`
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function mediaTypeOf(raw) {
|
|
251
|
+
if (typeof raw !== "string") {
|
|
252
|
+
return void 0;
|
|
253
|
+
}
|
|
254
|
+
const mediaType = raw.split(";")[0].trim().toLowerCase();
|
|
255
|
+
return /^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/.test(mediaType) ? mediaType : void 0;
|
|
256
|
+
}
|
|
257
|
+
async function uploadFileToPluginStorage(transport, file, options) {
|
|
258
|
+
if (typeof transport.uploadToStorage !== "function") {
|
|
259
|
+
throw new PluginStorageUploadError(
|
|
260
|
+
"The active McpTransport does not support plugin-storage uploads (no `uploadToStorage`). The host runtime must implement the uploadToStorage request kind.",
|
|
261
|
+
"unsupported"
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
const uploadToStorage = transport.uploadToStorage.bind(transport);
|
|
265
|
+
const pathPrefix = assertValidPluginStoragePrefix(options.pathPrefix);
|
|
266
|
+
const maxSizeBytes = Math.min(options.maxSizeBytes ?? PLUGIN_STORAGE_UPLOAD_MAX_BYTES, PLUGIN_STORAGE_UPLOAD_MAX_BYTES);
|
|
267
|
+
const isBuffer = file instanceof ArrayBuffer || Object.prototype.toString.call(file) === "[object ArrayBuffer]";
|
|
268
|
+
const size = isBuffer ? file.byteLength : file.size;
|
|
269
|
+
if (size > maxSizeBytes) {
|
|
270
|
+
throw new PluginStorageUploadError(
|
|
271
|
+
`File is ${size} bytes, which exceeds the ${maxSizeBytes}-byte upload limit.`,
|
|
272
|
+
"too_large"
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
const ownName = isBuffer ? void 0 : file.name;
|
|
276
|
+
const fileName = nonEmpty(options.fileName) ?? (typeof ownName === "string" ? nonEmpty(ownName) : void 0) ?? "upload.bin";
|
|
277
|
+
const declaredType = nonEmpty(options.contentType) ?? (isBuffer ? void 0 : nonEmpty(file.type));
|
|
278
|
+
const resolvedType = resolvePluginStorageContentType(fileName, declaredType);
|
|
279
|
+
if (!resolvedType.ok) {
|
|
280
|
+
throw new PluginStorageUploadError(resolvedType.error, "unsupported_type");
|
|
281
|
+
}
|
|
282
|
+
if (options.signal?.aborted === true) {
|
|
283
|
+
throw new PluginStorageUploadError("Aborted", "aborted", { code: "timeout" });
|
|
284
|
+
}
|
|
285
|
+
try {
|
|
286
|
+
const buffer = isBuffer ? file : await readBlob(file);
|
|
287
|
+
const meta = {
|
|
288
|
+
pathPrefix,
|
|
289
|
+
fileName,
|
|
290
|
+
// The canonical type for the extension: always one the server accepts, and the one
|
|
291
|
+
// it stores.
|
|
292
|
+
contentType: resolvedType.contentType,
|
|
293
|
+
sizeBytes: buffer.byteLength
|
|
294
|
+
};
|
|
295
|
+
return await uploadToStorage(meta, buffer, options.signal);
|
|
296
|
+
} catch (err) {
|
|
297
|
+
throw toPluginStorageUploadError(err);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function readBlob(blob) {
|
|
301
|
+
if (typeof blob.arrayBuffer === "function") {
|
|
302
|
+
return blob.arrayBuffer();
|
|
303
|
+
}
|
|
304
|
+
return new Promise((resolve, reject) => {
|
|
305
|
+
const reader = new FileReader();
|
|
306
|
+
reader.onload = () => resolve(reader.result);
|
|
307
|
+
reader.onerror = () => reject(reader.error ?? new Error("Could not read the file."));
|
|
308
|
+
reader.readAsArrayBuffer(blob);
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
function nonEmpty(value) {
|
|
312
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
313
|
+
}
|
|
314
|
+
function codeForReason(reason, status) {
|
|
315
|
+
if (status !== void 0) {
|
|
316
|
+
return mcpErrorCodeFromHttpStatus(status);
|
|
317
|
+
}
|
|
318
|
+
switch (reason) {
|
|
319
|
+
case "invalid_prefix":
|
|
320
|
+
case "too_large":
|
|
321
|
+
case "unsupported_type":
|
|
322
|
+
return "invalid_request";
|
|
323
|
+
case "timeout":
|
|
324
|
+
return "timeout";
|
|
325
|
+
case "unauthorized":
|
|
326
|
+
return "unauthorized";
|
|
327
|
+
case "forbidden":
|
|
328
|
+
return "forbidden";
|
|
329
|
+
case "busy":
|
|
330
|
+
return "unavailable";
|
|
331
|
+
case "aborted":
|
|
332
|
+
return "timeout";
|
|
333
|
+
default:
|
|
334
|
+
return "internal";
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function reasonForCode(code) {
|
|
338
|
+
switch (code) {
|
|
339
|
+
case "unauthorized":
|
|
340
|
+
return "unauthorized";
|
|
341
|
+
case "forbidden":
|
|
342
|
+
return "forbidden";
|
|
343
|
+
case "unavailable":
|
|
344
|
+
return "busy";
|
|
345
|
+
default:
|
|
346
|
+
return "unknown";
|
|
347
|
+
}
|
|
348
|
+
}
|
|
9
349
|
var ClientPushContext = createContext(null);
|
|
10
350
|
function useClientPushSubscription(options) {
|
|
11
351
|
const { groups, onEvent, onResync, enabled = true } = options;
|
|
@@ -562,100 +902,6 @@ function defaultConnectionFactory(port) {
|
|
|
562
902
|
};
|
|
563
903
|
}
|
|
564
904
|
|
|
565
|
-
// src/bridge/mcp-error.ts
|
|
566
|
-
var MCP_ERROR_CODES = [
|
|
567
|
-
"unauthorized",
|
|
568
|
-
"forbidden",
|
|
569
|
-
"not_found",
|
|
570
|
-
"invalid_request",
|
|
571
|
-
"conflict",
|
|
572
|
-
"rate_limited",
|
|
573
|
-
"timeout",
|
|
574
|
-
"unavailable",
|
|
575
|
-
"internal"
|
|
576
|
-
];
|
|
577
|
-
function isMcpErrorCode(value) {
|
|
578
|
-
return typeof value === "string" && MCP_ERROR_CODES.includes(value);
|
|
579
|
-
}
|
|
580
|
-
var RETRYABLE = ["rate_limited", "timeout", "unavailable"];
|
|
581
|
-
function isRetryableMcpErrorCode(code) {
|
|
582
|
-
return RETRYABLE.includes(code);
|
|
583
|
-
}
|
|
584
|
-
var McpToolError = class extends Error {
|
|
585
|
-
/** Machine-readable classification. `internal` when the host sent none. */
|
|
586
|
-
code;
|
|
587
|
-
/**
|
|
588
|
-
* Marks the instance for {@link isMcpToolError}. A structural marker rather than a prototype
|
|
589
|
-
* check because the error can be constructed in one bundle and inspected in another, where
|
|
590
|
-
* `instanceof` compares two different class objects and answers false.
|
|
591
|
-
*/
|
|
592
|
-
isMcpToolError = true;
|
|
593
|
-
constructor(message, code = "internal") {
|
|
594
|
-
super(message);
|
|
595
|
-
this.name = "McpHostError";
|
|
596
|
-
this.code = code;
|
|
597
|
-
}
|
|
598
|
-
/** True when this failure is worth retrying unchanged. */
|
|
599
|
-
get retryable() {
|
|
600
|
-
return isRetryableMcpErrorCode(this.code);
|
|
601
|
-
}
|
|
602
|
-
};
|
|
603
|
-
function isMcpToolError(value) {
|
|
604
|
-
return value instanceof McpToolError || value !== null && typeof value === "object" && value.isMcpToolError === true && isMcpErrorCode(value.code);
|
|
605
|
-
}
|
|
606
|
-
function mcpErrorCodeFromHttpStatus(status) {
|
|
607
|
-
switch (status) {
|
|
608
|
-
case 401:
|
|
609
|
-
return "unauthorized";
|
|
610
|
-
case 403:
|
|
611
|
-
return "forbidden";
|
|
612
|
-
case 404:
|
|
613
|
-
return "not_found";
|
|
614
|
-
case 400:
|
|
615
|
-
case 422:
|
|
616
|
-
return "invalid_request";
|
|
617
|
-
case 409:
|
|
618
|
-
case 412:
|
|
619
|
-
return "conflict";
|
|
620
|
-
case 429:
|
|
621
|
-
return "rate_limited";
|
|
622
|
-
case 408:
|
|
623
|
-
case 504:
|
|
624
|
-
return "timeout";
|
|
625
|
-
case 502:
|
|
626
|
-
case 503:
|
|
627
|
-
return "unavailable";
|
|
628
|
-
default:
|
|
629
|
-
return "internal";
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
function classifyHostResponse(response) {
|
|
633
|
-
if (response.ok) {
|
|
634
|
-
return void 0;
|
|
635
|
-
}
|
|
636
|
-
if (isMcpErrorCode(response.mcpErrorCode)) {
|
|
637
|
-
return response.mcpErrorCode;
|
|
638
|
-
}
|
|
639
|
-
return typeof response.status === "number" ? mcpErrorCodeFromHttpStatus(response.status) : "internal";
|
|
640
|
-
}
|
|
641
|
-
function classifyHostError(err) {
|
|
642
|
-
if (err === null || typeof err !== "object") {
|
|
643
|
-
return "internal";
|
|
644
|
-
}
|
|
645
|
-
const candidate = err;
|
|
646
|
-
if (isMcpErrorCode(candidate.mcpErrorCode)) {
|
|
647
|
-
return candidate.mcpErrorCode;
|
|
648
|
-
}
|
|
649
|
-
const status = typeof candidate.status === "number" ? candidate.status : typeof candidate.statusCode === "number" ? candidate.statusCode : void 0;
|
|
650
|
-
if (status !== void 0) {
|
|
651
|
-
return mcpErrorCodeFromHttpStatus(status);
|
|
652
|
-
}
|
|
653
|
-
if (candidate.name === "AbortError" || candidate.name === "TimeoutError") {
|
|
654
|
-
return "timeout";
|
|
655
|
-
}
|
|
656
|
-
return "internal";
|
|
657
|
-
}
|
|
658
|
-
|
|
659
905
|
// src/plugin/createPortMcpTransport.ts
|
|
660
906
|
var WIRE_INVOKE_TOOL_REQUEST = "ethisys:mcp:invokeTool";
|
|
661
907
|
var WIRE_INVOKE_TOOL_RESULT = "ethisys:mcp:invokeTool:result";
|
|
@@ -665,13 +911,15 @@ var WIRE_GET_RESOURCE_REQUEST = "ethisys:mcp:getResource";
|
|
|
665
911
|
var WIRE_GET_RESOURCE_RESULT = "ethisys:mcp:getResource:result";
|
|
666
912
|
var WIRE_UPLOAD_DOCUMENT_REQUEST = "ethisys:mcp:uploadDocument";
|
|
667
913
|
var WIRE_UPLOAD_DOCUMENT_RESULT = "ethisys:mcp:uploadDocument:result";
|
|
914
|
+
var WIRE_UPLOAD_TO_STORAGE_REQUEST = "ethisys:mcp:uploadToStorage";
|
|
915
|
+
var WIRE_UPLOAD_TO_STORAGE_RESULT = "ethisys:mcp:uploadToStorage:result";
|
|
668
916
|
var WIRE_ABORT = "ethisys:mcp:abort";
|
|
669
917
|
function isMcpResultEnvelope(value) {
|
|
670
918
|
if (value === null || typeof value !== "object") {
|
|
671
919
|
return false;
|
|
672
920
|
}
|
|
673
921
|
const v = value;
|
|
674
|
-
return (v.type === WIRE_INVOKE_TOOL_RESULT || v.type === WIRE_INVOKE_OPERATION_RESULT || v.type === WIRE_GET_RESOURCE_RESULT || v.type === WIRE_UPLOAD_DOCUMENT_RESULT) && typeof v.id === "string";
|
|
922
|
+
return (v.type === WIRE_INVOKE_TOOL_RESULT || v.type === WIRE_INVOKE_OPERATION_RESULT || v.type === WIRE_GET_RESOURCE_RESULT || v.type === WIRE_UPLOAD_DOCUMENT_RESULT || v.type === WIRE_UPLOAD_TO_STORAGE_RESULT) && typeof v.id === "string";
|
|
675
923
|
}
|
|
676
924
|
function createPortMcpTransport(port, options = {}) {
|
|
677
925
|
if (port === void 0 || port === null) {
|
|
@@ -695,10 +943,18 @@ function createPortMcpTransport(port, options = {}) {
|
|
|
695
943
|
if (reply.ok === true) {
|
|
696
944
|
resolver.resolve(reply.data);
|
|
697
945
|
} else {
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
946
|
+
const message = typeof reply.error === "string" ? reply.error : "Unknown host error";
|
|
947
|
+
const code = isMcpErrorCode(reply.code) ? reply.code : "internal";
|
|
948
|
+
if (reply.type === WIRE_UPLOAD_TO_STORAGE_RESULT) {
|
|
949
|
+
const status = typeof reply.status === "number" && Number.isInteger(reply.status) ? reply.status : void 0;
|
|
950
|
+
resolver.reject(new PluginStorageUploadError(
|
|
951
|
+
message,
|
|
952
|
+
status !== void 0 ? pluginStorageUploadReasonFromStatus(status) : "unknown",
|
|
953
|
+
{ status, code }
|
|
954
|
+
));
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
resolver.reject(new McpToolError(message, code));
|
|
702
958
|
}
|
|
703
959
|
}
|
|
704
960
|
shim.addEventListener("message", onMessage);
|
|
@@ -756,6 +1012,15 @@ function createPortMcpTransport(port, options = {}) {
|
|
|
756
1012
|
[buffer]
|
|
757
1013
|
);
|
|
758
1014
|
return data;
|
|
1015
|
+
},
|
|
1016
|
+
async uploadToStorage(meta, buffer, signal) {
|
|
1017
|
+
const data = await send(
|
|
1018
|
+
WIRE_UPLOAD_TO_STORAGE_REQUEST,
|
|
1019
|
+
{ meta, buffer },
|
|
1020
|
+
signal,
|
|
1021
|
+
[buffer]
|
|
1022
|
+
);
|
|
1023
|
+
return data;
|
|
759
1024
|
}
|
|
760
1025
|
};
|
|
761
1026
|
}
|
|
@@ -1010,6 +1275,6 @@ function useAuth(transport) {
|
|
|
1010
1275
|
};
|
|
1011
1276
|
}
|
|
1012
1277
|
|
|
1013
|
-
export { BridgeClientContext, ClientPushContext, ExtensionRuntimeProvider, HostIdentityContext, MCP_ERROR_CODES, McpToolError, PluginRealtimeContext, classifyHostError, classifyHostResponse, createPortBridgeClient, createPortMcpTransport, createRemoteRoot, decodeJwtPayload, defineDeclarativePlugin, defineEthisysPlugin, isMcpErrorCode, isMcpToolError, isRetryableMcpErrorCode, mcpErrorCodeFromHttpStatus, unwrapItems, useAuth, useBridgeClient, useBridgeLocale, useBridgeTheme, useClientPushSubscription, useExtensionRuntimeTransport, useFrontendSessionToken, useHostIdentity, useMcpQuery, useMcpResource, useMcpTool, useModuleQuery, useModuleTool, useOptionalExtensionRuntimeTransport, usePluginRealtimeSource };
|
|
1278
|
+
export { BridgeClientContext, ClientPushContext, ExtensionRuntimeProvider, HostIdentityContext, MCP_ERROR_CODES, McpToolError, PLUGIN_STORAGE_PATH_MAX_LENGTH, PLUGIN_STORAGE_PREFIX_MAX_LENGTH, PLUGIN_STORAGE_UPLOAD_CONTENT_TYPES, PLUGIN_STORAGE_UPLOAD_MAX_BYTES, PluginRealtimeContext, PluginStorageUploadError, assertValidPluginStoragePrefix, classifyHostError, classifyHostResponse, createPortBridgeClient, createPortMcpTransport, createRemoteRoot, decodeJwtPayload, defineDeclarativePlugin, defineEthisysPlugin, isMcpErrorCode, isMcpToolError, isPluginStorageUploadError, isRetryableMcpErrorCode, mcpErrorCodeFromHttpStatus, pluginStorageSafeExtension, pluginStorageUploadReasonFromStatus, resolvePluginStorageContentType, toPluginStorageUploadError, unwrapItems, uploadFileToPluginStorage, useAuth, useBridgeClient, useBridgeLocale, useBridgeTheme, useClientPushSubscription, useExtensionRuntimeTransport, useFrontendSessionToken, useHostIdentity, useMcpQuery, useMcpResource, useMcpTool, useModuleQuery, useModuleTool, useOptionalExtensionRuntimeTransport, usePluginRealtimeSource, validatePluginStoragePrefix };
|
|
1014
1279
|
//# sourceMappingURL=index.js.map
|
|
1015
1280
|
//# sourceMappingURL=index.js.map
|