@ethisyscore/extension-runtime 1.136.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/mock-host/cli.cjs
CHANGED
|
@@ -69,6 +69,29 @@ var MCP_ERROR_CODES = [
|
|
|
69
69
|
function isMcpErrorCode(value) {
|
|
70
70
|
return typeof value === "string" && MCP_ERROR_CODES.includes(value);
|
|
71
71
|
}
|
|
72
|
+
var RETRYABLE = ["rate_limited", "timeout", "unavailable"];
|
|
73
|
+
function isRetryableMcpErrorCode(code) {
|
|
74
|
+
return RETRYABLE.includes(code);
|
|
75
|
+
}
|
|
76
|
+
var McpToolError = class extends Error {
|
|
77
|
+
/** Machine-readable classification. `internal` when the host sent none. */
|
|
78
|
+
code;
|
|
79
|
+
/**
|
|
80
|
+
* Marks the instance for {@link isMcpToolError}. A structural marker rather than a prototype
|
|
81
|
+
* check because the error can be constructed in one bundle and inspected in another, where
|
|
82
|
+
* `instanceof` compares two different class objects and answers false.
|
|
83
|
+
*/
|
|
84
|
+
isMcpToolError = true;
|
|
85
|
+
constructor(message, code = "internal") {
|
|
86
|
+
super(message);
|
|
87
|
+
this.name = "McpHostError";
|
|
88
|
+
this.code = code;
|
|
89
|
+
}
|
|
90
|
+
/** True when this failure is worth retrying unchanged. */
|
|
91
|
+
get retryable() {
|
|
92
|
+
return isRetryableMcpErrorCode(this.code);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
72
95
|
function mcpErrorCodeFromHttpStatus(status) {
|
|
73
96
|
switch (status) {
|
|
74
97
|
case 401:
|
|
@@ -435,6 +458,9 @@ var WorkerRemoteDomTransport = class {
|
|
|
435
458
|
case "ethisys:mcp:uploadDocument":
|
|
436
459
|
this.dispatchMcp(message, "ethisys:mcp:uploadDocument:result", (m) => this.handleUploadDocument(m));
|
|
437
460
|
return;
|
|
461
|
+
case "ethisys:mcp:uploadToStorage":
|
|
462
|
+
this.dispatchMcp(message, "ethisys:mcp:uploadToStorage:result", (m) => this.handleUploadToStorage(m));
|
|
463
|
+
return;
|
|
438
464
|
case "ethisys:mcp:abort":
|
|
439
465
|
this.inFlightAborts.get(message.id ?? "")?.abort();
|
|
440
466
|
return;
|
|
@@ -672,11 +698,63 @@ var WorkerRemoteDomTransport = class {
|
|
|
672
698
|
this.replyError(message.id, "ethisys:mcp:uploadDocument:result", err);
|
|
673
699
|
}
|
|
674
700
|
}
|
|
675
|
-
|
|
701
|
+
async handleUploadToStorage(message) {
|
|
702
|
+
const resultType = "ethisys:mcp:uploadToStorage:result";
|
|
703
|
+
let token;
|
|
704
|
+
try {
|
|
705
|
+
token = await this.capabilityTokenProvider();
|
|
706
|
+
} catch (err) {
|
|
707
|
+
this.replyError(message.id, resultType, err, true);
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
if (this.disposed) {
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
try {
|
|
714
|
+
const result = await this.mcpClient.fetch({
|
|
715
|
+
kind: "uploadToStorage",
|
|
716
|
+
meta: message.meta,
|
|
717
|
+
buffer: message.buffer,
|
|
718
|
+
capabilityToken: token,
|
|
719
|
+
signal: this.requestSignal(message.id)
|
|
720
|
+
});
|
|
721
|
+
this.reportVersionSkew(result);
|
|
722
|
+
this.safePostMessage({
|
|
723
|
+
id: message.id,
|
|
724
|
+
type: resultType,
|
|
725
|
+
ok: result.ok,
|
|
726
|
+
data: result.data,
|
|
727
|
+
error: result.error,
|
|
728
|
+
code: classifyHostResponse(result),
|
|
729
|
+
// The HTTP status, on failure only. A bare number carries no host internals, and it
|
|
730
|
+
// is the only way the plugin can tell 413 (file too large) from 507 (quota) from 503
|
|
731
|
+
// (storage lock busy): the closed MCP code folds all three into `internal`/`unavailable`.
|
|
732
|
+
...!result.ok && typeof result.status === "number" ? { status: result.status } : {}
|
|
733
|
+
});
|
|
734
|
+
} catch (err) {
|
|
735
|
+
this.replyError(message.id, resultType, err, true);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
replyError(id, type, err, includeStatus = false) {
|
|
676
739
|
const message = err instanceof Error ? err.message : "MCP request failed";
|
|
677
|
-
|
|
740
|
+
const status = includeStatus ? statusOf(err) : void 0;
|
|
741
|
+
this.safePostMessage({
|
|
742
|
+
id,
|
|
743
|
+
type,
|
|
744
|
+
ok: false,
|
|
745
|
+
error: message,
|
|
746
|
+
code: classifyHostError(err),
|
|
747
|
+
...status !== void 0 ? { status } : {}
|
|
748
|
+
});
|
|
678
749
|
}
|
|
679
750
|
};
|
|
751
|
+
function statusOf(err) {
|
|
752
|
+
if (err === null || typeof err !== "object") {
|
|
753
|
+
return void 0;
|
|
754
|
+
}
|
|
755
|
+
const candidate = err;
|
|
756
|
+
return typeof candidate.status === "number" ? candidate.status : typeof candidate.statusCode === "number" ? candidate.statusCode : void 0;
|
|
757
|
+
}
|
|
680
758
|
|
|
681
759
|
// src/host/worker/component-registry.ts
|
|
682
760
|
var CONTRACT_B_PRIMITIVES = [
|
|
@@ -700,6 +778,180 @@ var CONTRACT_B_PRIMITIVES = [
|
|
|
700
778
|
];
|
|
701
779
|
new Set(CONTRACT_B_PRIMITIVES);
|
|
702
780
|
|
|
781
|
+
// src/plugin/pluginStorageUpload.ts
|
|
782
|
+
var PLUGIN_STORAGE_UPLOAD_MAX_BYTES = 30 * 1024 * 1024;
|
|
783
|
+
var PLUGIN_STORAGE_PREFIX_MAX_LENGTH = 84;
|
|
784
|
+
var PLUGIN_STORAGE_PATH_MAX_LENGTH = 128;
|
|
785
|
+
var PluginStorageUploadError = class extends McpToolError {
|
|
786
|
+
/** What went wrong, in terms a caller branches on. */
|
|
787
|
+
reason;
|
|
788
|
+
/** HTTP status from the server, when the host surfaced one. */
|
|
789
|
+
status;
|
|
790
|
+
/** Structural marker for {@link isPluginStorageUploadError}. */
|
|
791
|
+
isPluginStorageUploadError = true;
|
|
792
|
+
constructor(message, reason, options = {}) {
|
|
793
|
+
super(message, options.code ?? codeForReason(reason, options.status));
|
|
794
|
+
this.name = "PluginStorageUploadError";
|
|
795
|
+
this.reason = reason;
|
|
796
|
+
this.status = options.status;
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
function validatePluginStoragePrefix(raw) {
|
|
800
|
+
if (typeof raw !== "string" || raw.trim().length === 0) {
|
|
801
|
+
return { ok: false, error: "A storage path prefix is required." };
|
|
802
|
+
}
|
|
803
|
+
if (raw.length > PLUGIN_STORAGE_PREFIX_MAX_LENGTH) {
|
|
804
|
+
return {
|
|
805
|
+
ok: false,
|
|
806
|
+
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}.`
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
if (!/^[A-Za-z0-9_\-/]+$/.test(raw)) {
|
|
810
|
+
return {
|
|
811
|
+
ok: false,
|
|
812
|
+
error: "The storage path prefix may contain only letters, digits, '-', '_' and '/' separators."
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
if (raw.split("/").some((segment) => segment.length === 0)) {
|
|
816
|
+
return {
|
|
817
|
+
ok: false,
|
|
818
|
+
error: "The storage path prefix must not start or end with '/' or contain an empty segment."
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
return { ok: true, prefix: raw };
|
|
822
|
+
}
|
|
823
|
+
var PLUGIN_STORAGE_UPLOAD_CONTENT_TYPES = Object.freeze({
|
|
824
|
+
pdf: ["application/pdf"],
|
|
825
|
+
png: ["image/png"],
|
|
826
|
+
jpg: ["image/jpeg", "image/pjpeg", "image/jpg"],
|
|
827
|
+
jpeg: ["image/jpeg", "image/pjpeg", "image/jpg"],
|
|
828
|
+
gif: ["image/gif"],
|
|
829
|
+
webp: ["image/webp"],
|
|
830
|
+
doc: ["application/msword"],
|
|
831
|
+
docx: ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],
|
|
832
|
+
xls: ["application/vnd.ms-excel"],
|
|
833
|
+
xlsx: ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
|
|
834
|
+
ppt: ["application/vnd.ms-powerpoint"],
|
|
835
|
+
pptx: ["application/vnd.openxmlformats-officedocument.presentationml.presentation"],
|
|
836
|
+
odt: ["application/vnd.oasis.opendocument.text"],
|
|
837
|
+
ods: ["application/vnd.oasis.opendocument.spreadsheet"],
|
|
838
|
+
odp: ["application/vnd.oasis.opendocument.presentation"],
|
|
839
|
+
txt: ["text/plain"],
|
|
840
|
+
csv: ["text/csv", "application/vnd.ms-excel", "application/csv", "text/plain"],
|
|
841
|
+
zip: ["application/zip", "application/x-zip-compressed", "application/x-zip"],
|
|
842
|
+
mp3: ["audio/mpeg", "audio/mp3"],
|
|
843
|
+
m4a: ["audio/mp4", "audio/x-m4a"],
|
|
844
|
+
mp4: ["video/mp4"]
|
|
845
|
+
});
|
|
846
|
+
var OCTET_STREAM = "application/octet-stream";
|
|
847
|
+
function pluginStorageSafeExtension(fileName) {
|
|
848
|
+
if (typeof fileName !== "string" || fileName.trim().length === 0) {
|
|
849
|
+
return "";
|
|
850
|
+
}
|
|
851
|
+
const leaf = fileName.split(/[\\/]/).pop() ?? "";
|
|
852
|
+
const dot = leaf.lastIndexOf(".");
|
|
853
|
+
if (dot < 0) {
|
|
854
|
+
return "";
|
|
855
|
+
}
|
|
856
|
+
const body = leaf.slice(dot + 1);
|
|
857
|
+
return /^[A-Za-z0-9]{1,10}$/.test(body) ? `.${body.toLowerCase()}` : "";
|
|
858
|
+
}
|
|
859
|
+
function resolvePluginStorageContentType(fileName, declaredContentType) {
|
|
860
|
+
const extension = pluginStorageSafeExtension(fileName).slice(1);
|
|
861
|
+
const allowed = extension.length > 0 && Object.prototype.hasOwnProperty.call(PLUGIN_STORAGE_UPLOAD_CONTENT_TYPES, extension) ? PLUGIN_STORAGE_UPLOAD_CONTENT_TYPES[extension] : void 0;
|
|
862
|
+
if (allowed === void 0) {
|
|
863
|
+
return {
|
|
864
|
+
ok: false,
|
|
865
|
+
error: "This file type is not allowed. Allowed: " + Object.keys(PLUGIN_STORAGE_UPLOAD_CONTENT_TYPES).sort().join(", ") + "."
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
const declared = mediaTypeOf(declaredContentType);
|
|
869
|
+
if (declared === void 0 || declared === OCTET_STREAM || allowed.includes(declared)) {
|
|
870
|
+
return { ok: true, contentType: allowed[0] };
|
|
871
|
+
}
|
|
872
|
+
return {
|
|
873
|
+
ok: false,
|
|
874
|
+
error: `The declared content type '${declared}' does not match the file extension '.${extension}'.`
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
function mediaTypeOf(raw) {
|
|
878
|
+
if (typeof raw !== "string") {
|
|
879
|
+
return void 0;
|
|
880
|
+
}
|
|
881
|
+
const mediaType = raw.split(";")[0].trim().toLowerCase();
|
|
882
|
+
return /^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/.test(mediaType) ? mediaType : void 0;
|
|
883
|
+
}
|
|
884
|
+
function codeForReason(reason, status) {
|
|
885
|
+
if (status !== void 0) {
|
|
886
|
+
return mcpErrorCodeFromHttpStatus(status);
|
|
887
|
+
}
|
|
888
|
+
switch (reason) {
|
|
889
|
+
case "invalid_prefix":
|
|
890
|
+
case "too_large":
|
|
891
|
+
case "unsupported_type":
|
|
892
|
+
return "invalid_request";
|
|
893
|
+
case "timeout":
|
|
894
|
+
return "timeout";
|
|
895
|
+
case "unauthorized":
|
|
896
|
+
return "unauthorized";
|
|
897
|
+
case "forbidden":
|
|
898
|
+
return "forbidden";
|
|
899
|
+
case "busy":
|
|
900
|
+
return "unavailable";
|
|
901
|
+
case "aborted":
|
|
902
|
+
return "timeout";
|
|
903
|
+
default:
|
|
904
|
+
return "internal";
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// src/mock-host/MockPluginStorage.ts
|
|
909
|
+
var MockPluginStorage = class {
|
|
910
|
+
files = /* @__PURE__ */ new Map();
|
|
911
|
+
/** Store `buffer` under a new path below `meta.pathPrefix`. */
|
|
912
|
+
store(meta, buffer) {
|
|
913
|
+
const prefix = validatePluginStoragePrefix(meta.pathPrefix);
|
|
914
|
+
if (!prefix.ok) {
|
|
915
|
+
throw new PluginStorageUploadError(prefix.error, "invalid_prefix", { status: 400 });
|
|
916
|
+
}
|
|
917
|
+
if (buffer.byteLength > PLUGIN_STORAGE_UPLOAD_MAX_BYTES) {
|
|
918
|
+
throw new PluginStorageUploadError(
|
|
919
|
+
`The upload exceeds the ${PLUGIN_STORAGE_UPLOAD_MAX_BYTES}-byte limit.`,
|
|
920
|
+
"too_large",
|
|
921
|
+
{ status: 413 }
|
|
922
|
+
);
|
|
923
|
+
}
|
|
924
|
+
const fileName = meta.fileName && meta.fileName.length > 0 ? meta.fileName : "upload.bin";
|
|
925
|
+
const type = resolvePluginStorageContentType(fileName, meta.contentType);
|
|
926
|
+
if (!type.ok) {
|
|
927
|
+
throw new PluginStorageUploadError(type.error, "unsupported_type", { status: 415 });
|
|
928
|
+
}
|
|
929
|
+
const path2 = `${prefix.prefix}/${randomGuidN()}${pluginStorageSafeExtension(fileName)}`;
|
|
930
|
+
const bytes = new Uint8Array(buffer.slice(0));
|
|
931
|
+
this.files.set(path2, { path: path2, fileName, contentType: type.contentType, bytes });
|
|
932
|
+
return { path: path2, fileName, contentType: type.contentType, sizeBytes: bytes.byteLength };
|
|
933
|
+
}
|
|
934
|
+
/** The stored file at `path`, or `undefined`. */
|
|
935
|
+
get(path2) {
|
|
936
|
+
return this.files.get(path2);
|
|
937
|
+
}
|
|
938
|
+
/** Every stored file, in upload order. */
|
|
939
|
+
list() {
|
|
940
|
+
return [...this.files.values()];
|
|
941
|
+
}
|
|
942
|
+
/** Forget every stored file. */
|
|
943
|
+
clear() {
|
|
944
|
+
this.files.clear();
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
function randomGuidN() {
|
|
948
|
+
const bytes = new Uint8Array(16);
|
|
949
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
950
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
951
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
952
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
953
|
+
}
|
|
954
|
+
|
|
703
955
|
// src/mock-host/cli.ts
|
|
704
956
|
async function loadResources(dir) {
|
|
705
957
|
const absDir = path__namespace.resolve(dir);
|
|
@@ -945,6 +1197,7 @@ import {
|
|
|
945
1197
|
WorkerRemoteDomTransport,
|
|
946
1198
|
SemanticComponentRegistry,
|
|
947
1199
|
} from "@ethisyscore/extension-runtime/host";
|
|
1200
|
+
import { MockPluginStorage } from "@ethisyscore/extension-runtime/mock-host";
|
|
948
1201
|
|
|
949
1202
|
const PRIMITIVES = ${safePrimitives};
|
|
950
1203
|
const bundleUrl = ${safeUrl};
|
|
@@ -960,12 +1213,18 @@ const registry = SemanticComponentRegistry.fromMap(componentMap);
|
|
|
960
1213
|
|
|
961
1214
|
// Mock-host MCP client: no platform, so every tool/resource call resolves
|
|
962
1215
|
// to a friendly placeholder. Authors who need real MCP traffic should run
|
|
963
|
-
// against the full platform host.
|
|
1216
|
+
// against the full platform host. uploadToStorage writes into an in-memory
|
|
1217
|
+
// plugin storage and returns a server-style {prefix}/{guid}{ext} path; an
|
|
1218
|
+
// invalid prefix or an over-size body throws with status 400 / 413, which the
|
|
1219
|
+
// transport forwards to the plugin as a typed error.
|
|
1220
|
+
const pluginStorage = new MockPluginStorage();
|
|
964
1221
|
const mcpClient = {
|
|
965
|
-
fetch: async (req) =>
|
|
966
|
-
ok: true,
|
|
967
|
-
|
|
968
|
-
|
|
1222
|
+
fetch: async (req) => req.kind === "uploadToStorage"
|
|
1223
|
+
? { ok: true, data: pluginStorage.store(req.meta, req.buffer) }
|
|
1224
|
+
: {
|
|
1225
|
+
ok: true,
|
|
1226
|
+
data: { mockHost: true, kind: req.kind, name: req.name ?? req.uri },
|
|
1227
|
+
},
|
|
969
1228
|
};
|
|
970
1229
|
|
|
971
1230
|
// The capability token never crosses the worker boundary \u2014 supply a marker
|
|
@@ -988,10 +1247,15 @@ transport.onRemoteDom(() => {
|
|
|
988
1247
|
// devtools (e.g., to terminate the worker between iteration cycles).
|
|
989
1248
|
window.__MOCK_HOST_TRANSPORT__ = transport;
|
|
990
1249
|
window.__MOCK_HOST_REGISTRY__ = registry;
|
|
1250
|
+
window.__MOCK_HOST_PLUGIN_STORAGE__ = pluginStorage;
|
|
991
1251
|
`;
|
|
992
1252
|
}
|
|
1253
|
+
var defaultMockPluginStorage = new MockPluginStorage();
|
|
993
1254
|
var defaultMockMcpClient = {
|
|
994
1255
|
fetch: async (req) => {
|
|
1256
|
+
if (req.kind === "uploadToStorage") {
|
|
1257
|
+
return { ok: true, data: defaultMockPluginStorage.store(req.meta, req.buffer) };
|
|
1258
|
+
}
|
|
995
1259
|
if (req.kind === "uploadDocument") {
|
|
996
1260
|
return {
|
|
997
1261
|
ok: true,
|
|
@@ -1174,6 +1438,8 @@ async function run(args) {
|
|
|
1174
1438
|
}
|
|
1175
1439
|
|
|
1176
1440
|
exports.bootContractBHost = bootContractBHost;
|
|
1441
|
+
exports.defaultMockMcpClient = defaultMockMcpClient;
|
|
1442
|
+
exports.defaultMockPluginStorage = defaultMockPluginStorage;
|
|
1177
1443
|
exports.loadResources = loadResources;
|
|
1178
1444
|
exports.loadTools = loadTools;
|
|
1179
1445
|
exports.normaliseEntry = normaliseEntry;
|