@ethisyscore/extension-runtime 1.136.0 → 1.138.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-DF3DL1dI.d.ts +59 -0
- package/dist/MockPluginStorage-QKfz8CMt.d.cts +59 -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 +84 -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 +84 -2
- package/dist/host/index.js.map +1 -1
- package/dist/mock-host/cli.cjs +340 -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 +339 -8
- package/dist/mock-host/cli.js.map +1 -1
- package/dist/mock-host/index.cjs +276 -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 +276 -2
- package/dist/mock-host/index.js.map +1 -1
- package/dist/plugin/index.cjs +407 -100
- package/dist/plugin/index.cjs.map +1 -1
- package/dist/plugin/index.d.cts +186 -6
- package/dist/plugin/index.d.ts +186 -6
- package/dist/plugin/index.js +395 -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 +2 -2
package/dist/plugin/index.js
CHANGED
|
@@ -5,7 +5,376 @@ 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
|
+
/**
|
|
112
|
+
* Seconds the server asked the caller to wait (`Retry-After`), on a `rate_limited` failure
|
|
113
|
+
* when the host forwarded the header. Absent otherwise.
|
|
114
|
+
*/
|
|
115
|
+
retryAfterSeconds;
|
|
116
|
+
/** Structural marker for {@link isPluginStorageUploadError}. */
|
|
117
|
+
isPluginStorageUploadError = true;
|
|
118
|
+
constructor(message, reason, options = {}) {
|
|
119
|
+
super(message, options.code ?? codeForReason(reason, options.status));
|
|
120
|
+
this.name = "PluginStorageUploadError";
|
|
121
|
+
this.reason = reason;
|
|
122
|
+
this.status = options.status;
|
|
123
|
+
if (options.retryAfterSeconds !== void 0) {
|
|
124
|
+
this.retryAfterSeconds = options.retryAfterSeconds;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
function isPluginStorageUploadError(value) {
|
|
129
|
+
return value instanceof PluginStorageUploadError || isMcpToolError(value) && value.isPluginStorageUploadError === true;
|
|
130
|
+
}
|
|
131
|
+
function pluginStorageUploadReasonFromStatus(status) {
|
|
132
|
+
switch (status) {
|
|
133
|
+
case 400:
|
|
134
|
+
return "invalid_prefix";
|
|
135
|
+
case 401:
|
|
136
|
+
return "unauthorized";
|
|
137
|
+
case 403:
|
|
138
|
+
return "forbidden";
|
|
139
|
+
case 413:
|
|
140
|
+
return "too_large";
|
|
141
|
+
case 408:
|
|
142
|
+
return "timeout";
|
|
143
|
+
case 415:
|
|
144
|
+
return "unsupported_type";
|
|
145
|
+
case 429:
|
|
146
|
+
return "rate_limited";
|
|
147
|
+
case 503:
|
|
148
|
+
return "busy";
|
|
149
|
+
case 507:
|
|
150
|
+
return "quota_exceeded";
|
|
151
|
+
case 500:
|
|
152
|
+
return "storage_failed";
|
|
153
|
+
default:
|
|
154
|
+
return "unknown";
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function parsePluginStorageRetryAfter(raw, nowMs = Date.now()) {
|
|
158
|
+
if (typeof raw === "number") {
|
|
159
|
+
return Number.isFinite(raw) && raw >= 0 ? Math.ceil(raw) : void 0;
|
|
160
|
+
}
|
|
161
|
+
if (typeof raw !== "string" || raw.trim().length === 0) {
|
|
162
|
+
return void 0;
|
|
163
|
+
}
|
|
164
|
+
const text = raw.trim();
|
|
165
|
+
if (/^\d+$/.test(text)) {
|
|
166
|
+
return Number(text);
|
|
167
|
+
}
|
|
168
|
+
const at = /[A-Za-z]/.test(text) ? Date.parse(text) : Number.NaN;
|
|
169
|
+
return Number.isNaN(at) ? void 0 : Math.max(0, Math.ceil((at - nowMs) / 1e3));
|
|
170
|
+
}
|
|
171
|
+
function toPluginStorageUploadError(err) {
|
|
172
|
+
if (isPluginStorageUploadError(err)) {
|
|
173
|
+
return err;
|
|
174
|
+
}
|
|
175
|
+
const message = err instanceof Error ? err.message : typeof err === "string" ? err : "Plugin storage upload failed";
|
|
176
|
+
const candidate = err !== null && typeof err === "object" ? err : {};
|
|
177
|
+
const status = typeof candidate.status === "number" ? candidate.status : typeof candidate.statusCode === "number" ? candidate.statusCode : void 0;
|
|
178
|
+
if (status !== void 0) {
|
|
179
|
+
return new PluginStorageUploadError(message, pluginStorageUploadReasonFromStatus(status), {
|
|
180
|
+
status,
|
|
181
|
+
retryAfterSeconds: parsePluginStorageRetryAfter(candidate.retryAfterSeconds)
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
if (candidate.name === "AbortError") {
|
|
185
|
+
return new PluginStorageUploadError(message, "aborted", { code: "timeout" });
|
|
186
|
+
}
|
|
187
|
+
if (isMcpToolError(err)) {
|
|
188
|
+
return new PluginStorageUploadError(message, reasonForCode(err.code), { code: err.code });
|
|
189
|
+
}
|
|
190
|
+
return new PluginStorageUploadError(message, "unknown");
|
|
191
|
+
}
|
|
192
|
+
function validatePluginStoragePrefix(raw) {
|
|
193
|
+
if (typeof raw !== "string" || raw.trim().length === 0) {
|
|
194
|
+
return { ok: false, error: "A storage path prefix is required." };
|
|
195
|
+
}
|
|
196
|
+
if (raw.length > PLUGIN_STORAGE_PREFIX_MAX_LENGTH) {
|
|
197
|
+
return {
|
|
198
|
+
ok: false,
|
|
199
|
+
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}.`
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
if (!/^[A-Za-z0-9_\-/]+$/.test(raw)) {
|
|
203
|
+
return {
|
|
204
|
+
ok: false,
|
|
205
|
+
error: "The storage path prefix may contain only letters, digits, '-', '_' and '/' separators."
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
if (raw.split("/").some((segment) => segment.length === 0)) {
|
|
209
|
+
return {
|
|
210
|
+
ok: false,
|
|
211
|
+
error: "The storage path prefix must not start or end with '/' or contain an empty segment."
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return { ok: true, prefix: raw };
|
|
215
|
+
}
|
|
216
|
+
function assertValidPluginStoragePrefix(raw) {
|
|
217
|
+
const result = validatePluginStoragePrefix(raw);
|
|
218
|
+
if (!result.ok) {
|
|
219
|
+
throw new PluginStorageUploadError(result.error, "invalid_prefix");
|
|
220
|
+
}
|
|
221
|
+
return result.prefix;
|
|
222
|
+
}
|
|
223
|
+
var PLUGIN_STORAGE_UPLOAD_CONTENT_TYPES = Object.freeze({
|
|
224
|
+
pdf: ["application/pdf"],
|
|
225
|
+
png: ["image/png"],
|
|
226
|
+
jpg: ["image/jpeg", "image/pjpeg", "image/jpg"],
|
|
227
|
+
jpeg: ["image/jpeg", "image/pjpeg", "image/jpg"],
|
|
228
|
+
gif: ["image/gif"],
|
|
229
|
+
webp: ["image/webp"],
|
|
230
|
+
doc: ["application/msword"],
|
|
231
|
+
docx: ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],
|
|
232
|
+
xls: ["application/vnd.ms-excel"],
|
|
233
|
+
xlsx: ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
|
|
234
|
+
ppt: ["application/vnd.ms-powerpoint"],
|
|
235
|
+
pptx: ["application/vnd.openxmlformats-officedocument.presentationml.presentation"],
|
|
236
|
+
odt: ["application/vnd.oasis.opendocument.text"],
|
|
237
|
+
ods: ["application/vnd.oasis.opendocument.spreadsheet"],
|
|
238
|
+
odp: ["application/vnd.oasis.opendocument.presentation"],
|
|
239
|
+
txt: ["text/plain"],
|
|
240
|
+
csv: ["text/csv", "application/vnd.ms-excel", "application/csv", "text/plain"],
|
|
241
|
+
zip: ["application/zip", "application/x-zip-compressed", "application/x-zip"],
|
|
242
|
+
mp3: ["audio/mpeg", "audio/mp3"],
|
|
243
|
+
m4a: ["audio/mp4", "audio/x-m4a"],
|
|
244
|
+
mp4: ["video/mp4"]
|
|
245
|
+
});
|
|
246
|
+
var OCTET_STREAM = "application/octet-stream";
|
|
247
|
+
function pluginStorageSafeExtension(fileName) {
|
|
248
|
+
if (typeof fileName !== "string" || fileName.trim().length === 0) {
|
|
249
|
+
return "";
|
|
250
|
+
}
|
|
251
|
+
const leaf = fileName.split(/[\\/]/).pop() ?? "";
|
|
252
|
+
const dot = leaf.lastIndexOf(".");
|
|
253
|
+
if (dot < 0) {
|
|
254
|
+
return "";
|
|
255
|
+
}
|
|
256
|
+
const body = leaf.slice(dot + 1);
|
|
257
|
+
return /^[A-Za-z0-9]{1,10}$/.test(body) ? `.${body.toLowerCase()}` : "";
|
|
258
|
+
}
|
|
259
|
+
function resolvePluginStorageContentType(fileName, declaredContentType) {
|
|
260
|
+
const extension = pluginStorageSafeExtension(fileName).slice(1);
|
|
261
|
+
const allowed = extension.length > 0 && Object.prototype.hasOwnProperty.call(PLUGIN_STORAGE_UPLOAD_CONTENT_TYPES, extension) ? PLUGIN_STORAGE_UPLOAD_CONTENT_TYPES[extension] : void 0;
|
|
262
|
+
if (allowed === void 0) {
|
|
263
|
+
return {
|
|
264
|
+
ok: false,
|
|
265
|
+
error: "This file type is not allowed. Allowed: " + Object.keys(PLUGIN_STORAGE_UPLOAD_CONTENT_TYPES).sort().join(", ") + "."
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
const declared = mediaTypeOf(declaredContentType);
|
|
269
|
+
if (declared === void 0 || declared === OCTET_STREAM || allowed.includes(declared)) {
|
|
270
|
+
return { ok: true, contentType: allowed[0] };
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
ok: false,
|
|
274
|
+
error: `The declared content type '${declared}' does not match the file extension '.${extension}'.`
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
function mediaTypeOf(raw) {
|
|
278
|
+
if (typeof raw !== "string") {
|
|
279
|
+
return void 0;
|
|
280
|
+
}
|
|
281
|
+
const mediaType = raw.split(";")[0].trim().toLowerCase();
|
|
282
|
+
return /^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/.test(mediaType) ? mediaType : void 0;
|
|
283
|
+
}
|
|
284
|
+
async function uploadFileToPluginStorage(transport, file, options) {
|
|
285
|
+
if (typeof transport.uploadToStorage !== "function") {
|
|
286
|
+
throw new PluginStorageUploadError(
|
|
287
|
+
"The active McpTransport does not support plugin-storage uploads (no `uploadToStorage`). The host runtime must implement the uploadToStorage request kind.",
|
|
288
|
+
"unsupported"
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
const uploadToStorage = transport.uploadToStorage.bind(transport);
|
|
292
|
+
const pathPrefix = assertValidPluginStoragePrefix(options.pathPrefix);
|
|
293
|
+
const maxSizeBytes = Math.min(options.maxSizeBytes ?? PLUGIN_STORAGE_UPLOAD_MAX_BYTES, PLUGIN_STORAGE_UPLOAD_MAX_BYTES);
|
|
294
|
+
const isBuffer = file instanceof ArrayBuffer || Object.prototype.toString.call(file) === "[object ArrayBuffer]";
|
|
295
|
+
const size = isBuffer ? file.byteLength : file.size;
|
|
296
|
+
if (size > maxSizeBytes) {
|
|
297
|
+
throw new PluginStorageUploadError(
|
|
298
|
+
`File is ${size} bytes, which exceeds the ${maxSizeBytes}-byte upload limit.`,
|
|
299
|
+
"too_large"
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
const ownName = isBuffer ? void 0 : file.name;
|
|
303
|
+
const fileName = nonEmpty(options.fileName) ?? (typeof ownName === "string" ? nonEmpty(ownName) : void 0) ?? "upload.bin";
|
|
304
|
+
const declaredType = nonEmpty(options.contentType) ?? (isBuffer ? void 0 : nonEmpty(file.type));
|
|
305
|
+
const resolvedType = resolvePluginStorageContentType(fileName, declaredType);
|
|
306
|
+
if (!resolvedType.ok) {
|
|
307
|
+
throw new PluginStorageUploadError(resolvedType.error, "unsupported_type");
|
|
308
|
+
}
|
|
309
|
+
if (options.signal?.aborted === true) {
|
|
310
|
+
throw new PluginStorageUploadError("Aborted", "aborted", { code: "timeout" });
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
const buffer = isBuffer ? file : await readBlob(file);
|
|
314
|
+
const meta = {
|
|
315
|
+
pathPrefix,
|
|
316
|
+
fileName,
|
|
317
|
+
// The canonical type for the extension: always one the server accepts, and the one
|
|
318
|
+
// it stores.
|
|
319
|
+
contentType: resolvedType.contentType,
|
|
320
|
+
sizeBytes: buffer.byteLength
|
|
321
|
+
};
|
|
322
|
+
return await uploadToStorage(meta, buffer, options.signal);
|
|
323
|
+
} catch (err) {
|
|
324
|
+
throw toPluginStorageUploadError(err);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function readBlob(blob) {
|
|
328
|
+
if (typeof blob.arrayBuffer === "function") {
|
|
329
|
+
return blob.arrayBuffer();
|
|
330
|
+
}
|
|
331
|
+
return new Promise((resolve, reject) => {
|
|
332
|
+
const reader = new FileReader();
|
|
333
|
+
reader.onload = () => resolve(reader.result);
|
|
334
|
+
reader.onerror = () => reject(reader.error ?? new Error("Could not read the file."));
|
|
335
|
+
reader.readAsArrayBuffer(blob);
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
function nonEmpty(value) {
|
|
339
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
340
|
+
}
|
|
341
|
+
function codeForReason(reason, status) {
|
|
342
|
+
if (status !== void 0) {
|
|
343
|
+
return mcpErrorCodeFromHttpStatus(status);
|
|
344
|
+
}
|
|
345
|
+
switch (reason) {
|
|
346
|
+
case "invalid_prefix":
|
|
347
|
+
case "too_large":
|
|
348
|
+
case "unsupported_type":
|
|
349
|
+
return "invalid_request";
|
|
350
|
+
case "timeout":
|
|
351
|
+
return "timeout";
|
|
352
|
+
case "unauthorized":
|
|
353
|
+
return "unauthorized";
|
|
354
|
+
case "forbidden":
|
|
355
|
+
return "forbidden";
|
|
356
|
+
case "busy":
|
|
357
|
+
return "unavailable";
|
|
358
|
+
case "rate_limited":
|
|
359
|
+
return "rate_limited";
|
|
360
|
+
case "aborted":
|
|
361
|
+
return "timeout";
|
|
362
|
+
default:
|
|
363
|
+
return "internal";
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
function reasonForCode(code) {
|
|
367
|
+
switch (code) {
|
|
368
|
+
case "unauthorized":
|
|
369
|
+
return "unauthorized";
|
|
370
|
+
case "forbidden":
|
|
371
|
+
return "forbidden";
|
|
372
|
+
case "unavailable":
|
|
373
|
+
return "busy";
|
|
374
|
+
default:
|
|
375
|
+
return "unknown";
|
|
376
|
+
}
|
|
377
|
+
}
|
|
9
378
|
var ClientPushContext = createContext(null);
|
|
10
379
|
function useClientPushSubscription(options) {
|
|
11
380
|
const { groups, onEvent, onResync, enabled = true } = options;
|
|
@@ -562,100 +931,6 @@ function defaultConnectionFactory(port) {
|
|
|
562
931
|
};
|
|
563
932
|
}
|
|
564
933
|
|
|
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
934
|
// src/plugin/createPortMcpTransport.ts
|
|
660
935
|
var WIRE_INVOKE_TOOL_REQUEST = "ethisys:mcp:invokeTool";
|
|
661
936
|
var WIRE_INVOKE_TOOL_RESULT = "ethisys:mcp:invokeTool:result";
|
|
@@ -665,13 +940,15 @@ var WIRE_GET_RESOURCE_REQUEST = "ethisys:mcp:getResource";
|
|
|
665
940
|
var WIRE_GET_RESOURCE_RESULT = "ethisys:mcp:getResource:result";
|
|
666
941
|
var WIRE_UPLOAD_DOCUMENT_REQUEST = "ethisys:mcp:uploadDocument";
|
|
667
942
|
var WIRE_UPLOAD_DOCUMENT_RESULT = "ethisys:mcp:uploadDocument:result";
|
|
943
|
+
var WIRE_UPLOAD_TO_STORAGE_REQUEST = "ethisys:mcp:uploadToStorage";
|
|
944
|
+
var WIRE_UPLOAD_TO_STORAGE_RESULT = "ethisys:mcp:uploadToStorage:result";
|
|
668
945
|
var WIRE_ABORT = "ethisys:mcp:abort";
|
|
669
946
|
function isMcpResultEnvelope(value) {
|
|
670
947
|
if (value === null || typeof value !== "object") {
|
|
671
948
|
return false;
|
|
672
949
|
}
|
|
673
950
|
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";
|
|
951
|
+
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
952
|
}
|
|
676
953
|
function createPortMcpTransport(port, options = {}) {
|
|
677
954
|
if (port === void 0 || port === null) {
|
|
@@ -695,10 +972,18 @@ function createPortMcpTransport(port, options = {}) {
|
|
|
695
972
|
if (reply.ok === true) {
|
|
696
973
|
resolver.resolve(reply.data);
|
|
697
974
|
} else {
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
975
|
+
const message = typeof reply.error === "string" ? reply.error : "Unknown host error";
|
|
976
|
+
const code = isMcpErrorCode(reply.code) ? reply.code : "internal";
|
|
977
|
+
if (reply.type === WIRE_UPLOAD_TO_STORAGE_RESULT) {
|
|
978
|
+
const status = typeof reply.status === "number" && Number.isInteger(reply.status) ? reply.status : void 0;
|
|
979
|
+
resolver.reject(new PluginStorageUploadError(
|
|
980
|
+
message,
|
|
981
|
+
status !== void 0 ? pluginStorageUploadReasonFromStatus(status) : "unknown",
|
|
982
|
+
{ status, code, retryAfterSeconds: parsePluginStorageRetryAfter(reply.retryAfterSeconds) }
|
|
983
|
+
));
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
resolver.reject(new McpToolError(message, code));
|
|
702
987
|
}
|
|
703
988
|
}
|
|
704
989
|
shim.addEventListener("message", onMessage);
|
|
@@ -756,6 +1041,15 @@ function createPortMcpTransport(port, options = {}) {
|
|
|
756
1041
|
[buffer]
|
|
757
1042
|
);
|
|
758
1043
|
return data;
|
|
1044
|
+
},
|
|
1045
|
+
async uploadToStorage(meta, buffer, signal) {
|
|
1046
|
+
const data = await send(
|
|
1047
|
+
WIRE_UPLOAD_TO_STORAGE_REQUEST,
|
|
1048
|
+
{ meta, buffer },
|
|
1049
|
+
signal,
|
|
1050
|
+
[buffer]
|
|
1051
|
+
);
|
|
1052
|
+
return data;
|
|
759
1053
|
}
|
|
760
1054
|
};
|
|
761
1055
|
}
|
|
@@ -1010,6 +1304,6 @@ function useAuth(transport) {
|
|
|
1010
1304
|
};
|
|
1011
1305
|
}
|
|
1012
1306
|
|
|
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 };
|
|
1307
|
+
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
1308
|
//# sourceMappingURL=index.js.map
|
|
1015
1309
|
//# sourceMappingURL=index.js.map
|