@vitemcp/server 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ViteMCP.cjs +179 -100
- package/dist/ViteMCP.cjs.map +1 -1
- package/dist/ViteMCP.d.cts +21 -0
- package/dist/ViteMCP.d.ts +21 -0
- package/dist/ViteMCP.js +160 -81
- package/dist/ViteMCP.js.map +1 -1
- package/package.json +1 -1
package/dist/ViteMCP.cjs
CHANGED
|
@@ -201,6 +201,17 @@ var createOAuthRouter = (options) => {
|
|
|
201
201
|
return app;
|
|
202
202
|
};
|
|
203
203
|
|
|
204
|
+
// src/cancelResponseBody.ts
|
|
205
|
+
var cancelResponseBody = async (response) => {
|
|
206
|
+
if (!response.body) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
await response.body.cancel();
|
|
211
|
+
} catch (e4) {
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
204
215
|
// src/DiscoveryDocumentCache.ts
|
|
205
216
|
var DiscoveryDocumentCache = class {
|
|
206
217
|
get size() {
|
|
@@ -288,6 +299,7 @@ var DiscoveryDocumentCache = class {
|
|
|
288
299
|
throw error;
|
|
289
300
|
}
|
|
290
301
|
if (!res.ok) {
|
|
302
|
+
await cancelResponseBody(res);
|
|
291
303
|
throw new Error(
|
|
292
304
|
`Failed to fetch discovery document from ${url}: ${res.status} ${res.statusText}`
|
|
293
305
|
);
|
|
@@ -334,7 +346,7 @@ async function compileSchema(schema) {
|
|
|
334
346
|
let ajvModule;
|
|
335
347
|
try {
|
|
336
348
|
ajvModule = await Promise.resolve().then(() => _interopRequireWildcard(require("ajv")));
|
|
337
|
-
} catch (
|
|
349
|
+
} catch (e5) {
|
|
338
350
|
throw new Error(
|
|
339
351
|
'The "ajv" package is required to validate JSON Schema tool parameters. Install it with: npm install ajv'
|
|
340
352
|
);
|
|
@@ -347,7 +359,7 @@ async function compileSchema(schema) {
|
|
|
347
359
|
unwrapDefault(formatsModule)
|
|
348
360
|
);
|
|
349
361
|
addFormats(ajv);
|
|
350
|
-
} catch (
|
|
362
|
+
} catch (e6) {
|
|
351
363
|
}
|
|
352
364
|
return ajv.compile(schema);
|
|
353
365
|
}
|
|
@@ -395,6 +407,7 @@ var readMedia = async (source, kind) => {
|
|
|
395
407
|
signal: AbortSignal.timeout(_nullishCoalesce(source.timeoutMs, () => ( MEDIA_FETCH_TIMEOUT_MS)))
|
|
396
408
|
});
|
|
397
409
|
if (!response.ok) {
|
|
410
|
+
await cancelResponseBody(response);
|
|
398
411
|
throw new Error(`Server responded with status: ${response.status}`);
|
|
399
412
|
}
|
|
400
413
|
rawData = Buffer.from(await response.arrayBuffer());
|
|
@@ -573,7 +586,9 @@ var ViteMCP = class {
|
|
|
573
586
|
async embedded(uri) {
|
|
574
587
|
const direct = this.#resources.find((resource) => resource.uri === uri);
|
|
575
588
|
if (direct) {
|
|
576
|
-
const loaded = await direct.load(
|
|
589
|
+
const loaded = await direct.load(
|
|
590
|
+
this.#makeContext(void 0, void 0).context
|
|
591
|
+
);
|
|
577
592
|
const first = Array.isArray(loaded) ? loaded[0] : loaded;
|
|
578
593
|
if (!first) {
|
|
579
594
|
throw new UnexpectedStateError(`Resource loaded no content: ${uri}`, {
|
|
@@ -589,7 +604,7 @@ var ViteMCP = class {
|
|
|
589
604
|
}
|
|
590
605
|
const loaded = await template.load(
|
|
591
606
|
params,
|
|
592
|
-
this.#makeContext(void 0, void 0)
|
|
607
|
+
this.#makeContext(void 0, void 0).context
|
|
593
608
|
);
|
|
594
609
|
const first = Array.isArray(loaded) ? loaded[0] : loaded;
|
|
595
610
|
if (!first) {
|
|
@@ -748,13 +763,14 @@ var ViteMCP = class {
|
|
|
748
763
|
)
|
|
749
764
|
},
|
|
750
765
|
(async (args, ctx) => {
|
|
751
|
-
const
|
|
766
|
+
const timeout = tool.timeoutMs ? { controller: new AbortController(), ms: tool.timeoutMs } : void 0;
|
|
767
|
+
const { context, release } = this.#makeContext(
|
|
768
|
+
auth,
|
|
769
|
+
ctx,
|
|
770
|
+
_optionalChain([timeout, 'optionalAccess', _23 => _23.controller, 'access', _24 => _24.signal])
|
|
771
|
+
);
|
|
752
772
|
try {
|
|
753
|
-
const result = await (
|
|
754
|
-
tool.execute(args, context),
|
|
755
|
-
tool.timeoutMs,
|
|
756
|
-
tool.name
|
|
757
|
-
) : tool.execute(args, context));
|
|
773
|
+
const result = await (timeout ? withTimeout(tool.execute(args, context), timeout, tool.name) : tool.execute(args, context));
|
|
758
774
|
return normalizeToolResult(result, tool.outputSchema !== void 0);
|
|
759
775
|
} catch (error) {
|
|
760
776
|
if (error instanceof UserError) {
|
|
@@ -765,6 +781,8 @@ var ViteMCP = class {
|
|
|
765
781
|
};
|
|
766
782
|
}
|
|
767
783
|
throw error;
|
|
784
|
+
} finally {
|
|
785
|
+
release();
|
|
768
786
|
}
|
|
769
787
|
})
|
|
770
788
|
);
|
|
@@ -782,16 +800,20 @@ var ViteMCP = class {
|
|
|
782
800
|
mimeType: resource.mimeType
|
|
783
801
|
},
|
|
784
802
|
(async (uri, ctx) => {
|
|
785
|
-
const context = this.#makeContext(auth, ctx);
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
803
|
+
const { context, release } = this.#makeContext(auth, ctx);
|
|
804
|
+
try {
|
|
805
|
+
const loaded = await resource.load(context);
|
|
806
|
+
const bodies = Array.isArray(loaded) ? loaded : [loaded];
|
|
807
|
+
return {
|
|
808
|
+
contents: bodies.map((body) => ({
|
|
809
|
+
...body,
|
|
810
|
+
mimeType: _nullishCoalesce(body.mimeType, () => ( resource.mimeType)),
|
|
811
|
+
uri: _nullishCoalesce(body.uri, () => ( uri.toString()))
|
|
812
|
+
}))
|
|
813
|
+
};
|
|
814
|
+
} finally {
|
|
815
|
+
release();
|
|
816
|
+
}
|
|
795
817
|
})
|
|
796
818
|
);
|
|
797
819
|
}
|
|
@@ -818,16 +840,20 @@ var ViteMCP = class {
|
|
|
818
840
|
mimeType: template.mimeType
|
|
819
841
|
},
|
|
820
842
|
(async (uri, args, ctx) => {
|
|
821
|
-
const context = this.#makeContext(auth, ctx);
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
843
|
+
const { context, release } = this.#makeContext(auth, ctx);
|
|
844
|
+
try {
|
|
845
|
+
const loaded = await template.load(_nullishCoalesce(args, () => ( {})), context);
|
|
846
|
+
const bodies = Array.isArray(loaded) ? loaded : [loaded];
|
|
847
|
+
return {
|
|
848
|
+
contents: bodies.map((body) => ({
|
|
849
|
+
...body,
|
|
850
|
+
mimeType: _nullishCoalesce(body.mimeType, () => ( template.mimeType)),
|
|
851
|
+
uri: _nullishCoalesce(body.uri, () => ( uri.toString()))
|
|
852
|
+
}))
|
|
853
|
+
};
|
|
854
|
+
} finally {
|
|
855
|
+
release();
|
|
856
|
+
}
|
|
831
857
|
})
|
|
832
858
|
);
|
|
833
859
|
}
|
|
@@ -842,19 +868,23 @@ var ViteMCP = class {
|
|
|
842
868
|
description: prompt.description
|
|
843
869
|
},
|
|
844
870
|
(async (args, ctx) => {
|
|
845
|
-
const context = this.#makeContext(auth, ctx);
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
871
|
+
const { context, release } = this.#makeContext(auth, ctx);
|
|
872
|
+
try {
|
|
873
|
+
const loaded = await prompt.load(_nullishCoalesce(args, () => ( {})), context);
|
|
874
|
+
if (typeof loaded !== "string") {
|
|
875
|
+
return loaded;
|
|
876
|
+
}
|
|
877
|
+
return {
|
|
878
|
+
messages: [
|
|
879
|
+
{
|
|
880
|
+
content: { text: loaded, type: "text" },
|
|
881
|
+
role: "user"
|
|
882
|
+
}
|
|
883
|
+
]
|
|
884
|
+
};
|
|
885
|
+
} finally {
|
|
886
|
+
release();
|
|
849
887
|
}
|
|
850
|
-
return {
|
|
851
|
-
messages: [
|
|
852
|
-
{
|
|
853
|
-
content: { text: loaded, type: "text" },
|
|
854
|
-
role: "user"
|
|
855
|
-
}
|
|
856
|
-
]
|
|
857
|
-
};
|
|
858
888
|
})
|
|
859
889
|
);
|
|
860
890
|
}
|
|
@@ -869,54 +899,70 @@ var ViteMCP = class {
|
|
|
869
899
|
);
|
|
870
900
|
return app;
|
|
871
901
|
}
|
|
872
|
-
/**
|
|
873
|
-
|
|
902
|
+
/**
|
|
903
|
+
* Bridges the v2 per-request context onto ViteMCP's `Context`.
|
|
904
|
+
*
|
|
905
|
+
* `timeoutSignal` is folded into `context.signal` for a tool that declares
|
|
906
|
+
* `timeoutMs`; everything else mirrors the SDK's request signal alone. Call
|
|
907
|
+
* `release()` once the handler has settled — see {@link requestScope}.
|
|
908
|
+
*/
|
|
909
|
+
#makeContext(auth, rawCtx, timeoutSignal) {
|
|
874
910
|
const ctx = rawCtx;
|
|
875
|
-
const mcpReq = _optionalChain([ctx, 'optionalAccess',
|
|
876
|
-
const requestedLevel = _optionalChain([mcpReq, 'optionalAccess',
|
|
911
|
+
const mcpReq = _optionalChain([ctx, 'optionalAccess', _25 => _25.mcpReq]);
|
|
912
|
+
const requestedLevel = _optionalChain([mcpReq, 'optionalAccess', _26 => _26._meta, 'optionalAccess', _27 => _27["io.modelcontextprotocol/logLevel"]]);
|
|
877
913
|
const emit = (level, message, data) => {
|
|
878
914
|
if (!requestedLevel) {
|
|
879
915
|
return;
|
|
880
916
|
}
|
|
881
|
-
void _optionalChain([mcpReq, 'optionalAccess',
|
|
917
|
+
void _optionalChain([mcpReq, 'optionalAccess', _28 => _28.notify, 'optionalCall', _29 => _29({
|
|
882
918
|
method: "notifications/message",
|
|
883
919
|
params: { data: { context: data, message }, level }
|
|
884
|
-
}), 'optionalAccess',
|
|
920
|
+
}), 'optionalAccess', _30 => _30.catch, 'call', _31 => _31(() => {
|
|
885
921
|
})]);
|
|
886
922
|
};
|
|
923
|
+
const scope = requestScope(_optionalChain([mcpReq, 'optionalAccess', _32 => _32.signal]), timeoutSignal);
|
|
887
924
|
return {
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
progress: progress.progress,
|
|
912
|
-
progressToken,
|
|
913
|
-
total: progress.total
|
|
925
|
+
context: {
|
|
926
|
+
auth,
|
|
927
|
+
elicit: (params) => _server.inputRequired.elicit({
|
|
928
|
+
message: params.message,
|
|
929
|
+
requestedSchema: params.requestedSchema
|
|
930
|
+
}),
|
|
931
|
+
input: (key, schema) => _server.acceptedContent.call(void 0,
|
|
932
|
+
_optionalChain([mcpReq, 'optionalAccess', _33 => _33.inputResponses]),
|
|
933
|
+
key,
|
|
934
|
+
schema
|
|
935
|
+
),
|
|
936
|
+
inputRequired: (inputRequests, requestState) => _server.inputRequired.call(void 0, { inputRequests, requestState }),
|
|
937
|
+
inputResponses: _optionalChain([mcpReq, 'optionalAccess', _34 => _34.inputResponses]),
|
|
938
|
+
log: {
|
|
939
|
+
debug: (m, d) => emit("debug", m, d),
|
|
940
|
+
error: (m, d) => emit("error", m, d),
|
|
941
|
+
info: (m, d) => emit("info", m, d),
|
|
942
|
+
warn: (m, d) => emit("warning", m, d)
|
|
943
|
+
},
|
|
944
|
+
reportProgress: async (progress) => {
|
|
945
|
+
const progressToken = _optionalChain([mcpReq, 'optionalAccess', _35 => _35._meta, 'optionalAccess', _36 => _36.progressToken]);
|
|
946
|
+
if (progressToken === void 0) {
|
|
947
|
+
return;
|
|
914
948
|
}
|
|
915
|
-
|
|
949
|
+
await _optionalChain([mcpReq, 'optionalAccess', _37 => _37.notify, 'optionalCall', _38 => _38({
|
|
950
|
+
method: "notifications/progress",
|
|
951
|
+
params: {
|
|
952
|
+
message: progress.message,
|
|
953
|
+
progress: progress.progress,
|
|
954
|
+
progressToken,
|
|
955
|
+
total: progress.total
|
|
956
|
+
}
|
|
957
|
+
})]);
|
|
958
|
+
},
|
|
959
|
+
requestId: _optionalChain([mcpReq, 'optionalAccess', _39 => _39.id]),
|
|
960
|
+
// The SDK exposes this as an accessor; call it so callers get the
|
|
961
|
+
// value.
|
|
962
|
+
requestState: _optionalChain([mcpReq, 'optionalAccess', _40 => _40.requestState, 'optionalCall', _41 => _41()]),
|
|
963
|
+
signal: scope.signal
|
|
916
964
|
},
|
|
917
|
-
|
|
918
|
-
// The SDK exposes this as an accessor; call it so callers get the value.
|
|
919
|
-
requestState: _optionalChain([mcpReq, 'optionalAccess', _37 => _37.requestState, 'optionalCall', _38 => _38()])
|
|
965
|
+
release: scope.release
|
|
920
966
|
};
|
|
921
967
|
}
|
|
922
968
|
/**
|
|
@@ -925,7 +971,7 @@ var ViteMCP = class {
|
|
|
925
971
|
* no addressee on a stateless transport.
|
|
926
972
|
*/
|
|
927
973
|
#notifyListChanged(kind) {
|
|
928
|
-
const notifier = _optionalChain([this, 'access',
|
|
974
|
+
const notifier = _optionalChain([this, 'access', _42 => _42.#handler, 'optionalAccess', _43 => _43.notify]);
|
|
929
975
|
if (!notifier) {
|
|
930
976
|
return;
|
|
931
977
|
}
|
|
@@ -938,7 +984,7 @@ var ViteMCP = class {
|
|
|
938
984
|
// Authentication has already run in the route below, which is the only
|
|
939
985
|
// place that can turn a refusal into an HTTP status. What reaches here
|
|
940
986
|
// is either an authenticated session or a deliberately anonymous one.
|
|
941
|
-
async () => this.#buildServer(_optionalChain([this, 'access',
|
|
987
|
+
async () => this.#buildServer(_optionalChain([this, 'access', _44 => _44.#authStore, 'access', _45 => _45.getStore, 'call', _46 => _46(), 'optionalAccess', _47 => _47.auth])),
|
|
942
988
|
{
|
|
943
989
|
// Tradeoff: `server/discover` advertises only 2026-07-28, so legacy
|
|
944
990
|
// requests are answered unadvertised and skip Mcp-* validation.
|
|
@@ -948,8 +994,8 @@ var ViteMCP = class {
|
|
|
948
994
|
}
|
|
949
995
|
);
|
|
950
996
|
this.#corsMiddleware = config.cors === false ? null : _cors.cors.call(void 0, config.cors);
|
|
951
|
-
const oauth = _nullishCoalesce(this.#options.oauth, () => ( _optionalChain([this, 'access',
|
|
952
|
-
if (_optionalChain([oauth, 'optionalAccess',
|
|
997
|
+
const oauth = _nullishCoalesce(this.#options.oauth, () => ( _optionalChain([this, 'access', _48 => _48.#options, 'access', _49 => _49.auth, 'optionalAccess', _50 => _50.getOAuthConfig, 'call', _51 => _51()])));
|
|
998
|
+
if (_optionalChain([oauth, 'optionalAccess', _52 => _52.enabled]) !== false && (_nullishCoalesce(_nullishCoalesce(_optionalChain([oauth, 'optionalAccess', _53 => _53.proxy]), () => ( _optionalChain([oauth, 'optionalAccess', _54 => _54.authorizationServer]))), () => ( _optionalChain([oauth, 'optionalAccess', _55 => _55.protectedResource]))))) {
|
|
953
999
|
this.#honoApp.route(
|
|
954
1000
|
"/",
|
|
955
1001
|
createOAuthRouter({
|
|
@@ -963,10 +1009,10 @@ var ViteMCP = class {
|
|
|
963
1009
|
this.#servesProtectedResourceMetadata = Boolean(oauth.protectedResource);
|
|
964
1010
|
}
|
|
965
1011
|
const health = this.#options.health;
|
|
966
|
-
if (_optionalChain([health, 'optionalAccess',
|
|
1012
|
+
if (_optionalChain([health, 'optionalAccess', _56 => _56.enabled]) !== false) {
|
|
967
1013
|
this.#honoApp.get(
|
|
968
|
-
_nullishCoalesce(_optionalChain([health, 'optionalAccess',
|
|
969
|
-
(c) => c.text(_nullishCoalesce(_optionalChain([health, 'optionalAccess',
|
|
1014
|
+
_nullishCoalesce(_optionalChain([health, 'optionalAccess', _57 => _57.path]), () => ( "/health")),
|
|
1015
|
+
(c) => c.text(_nullishCoalesce(_optionalChain([health, 'optionalAccess', _58 => _58.message]), () => ( "ok")), _nullishCoalesce(_optionalChain([health, 'optionalAccess', _59 => _59.status]), () => ( 200)))
|
|
970
1016
|
);
|
|
971
1017
|
}
|
|
972
1018
|
const endpoint = `${_nullishCoalesce(config.basePath, () => ( ""))}${_nullishCoalesce(config.endpoint, () => ( "/mcp"))}`;
|
|
@@ -1003,7 +1049,7 @@ var ViteMCP = class {
|
|
|
1003
1049
|
"Content-Type": "application/json"
|
|
1004
1050
|
});
|
|
1005
1051
|
req.resume();
|
|
1006
|
-
res.once("finish", () => _optionalChain([res, 'access',
|
|
1052
|
+
res.once("finish", () => _optionalChain([res, 'access', _60 => _60.socket, 'optionalAccess', _61 => _61.end, 'call', _62 => _62()]));
|
|
1007
1053
|
res.end(
|
|
1008
1054
|
JSON.stringify({
|
|
1009
1055
|
error: "invalid_request",
|
|
@@ -1013,7 +1059,7 @@ var ViteMCP = class {
|
|
|
1013
1059
|
return;
|
|
1014
1060
|
}
|
|
1015
1061
|
const response = await app.fetch(
|
|
1016
|
-
nodeToWebRequest(req, body, useTls),
|
|
1062
|
+
nodeToWebRequest(req, body, useTls, clientDisconnectSignal(res)),
|
|
1017
1063
|
{
|
|
1018
1064
|
incoming: req,
|
|
1019
1065
|
outgoing: res
|
|
@@ -1066,7 +1112,7 @@ var ViteMCP = class {
|
|
|
1066
1112
|
return void 0;
|
|
1067
1113
|
}
|
|
1068
1114
|
const standard = schema["~standard"];
|
|
1069
|
-
if (_optionalChain([standard, 'optionalAccess',
|
|
1115
|
+
if (_optionalChain([standard, 'optionalAccess', _63 => _63.jsonSchema])) {
|
|
1070
1116
|
return schema;
|
|
1071
1117
|
}
|
|
1072
1118
|
try {
|
|
@@ -1100,7 +1146,7 @@ var ViteMCP = class {
|
|
|
1100
1146
|
);
|
|
1101
1147
|
}
|
|
1102
1148
|
};
|
|
1103
|
-
var nodeToWebRequest = (req, body, secure) => {
|
|
1149
|
+
var nodeToWebRequest = (req, body, secure, signal) => {
|
|
1104
1150
|
const host = _nullishCoalesce(req.headers.host, () => ( "localhost"));
|
|
1105
1151
|
const url = `${secure ? "https" : "http"}://${host}${_nullishCoalesce(req.url, () => ( "/"))}`;
|
|
1106
1152
|
const headers = new Headers();
|
|
@@ -1121,20 +1167,53 @@ var nodeToWebRequest = (req, body, secure) => {
|
|
|
1121
1167
|
return new Request(url, {
|
|
1122
1168
|
headers,
|
|
1123
1169
|
method,
|
|
1170
|
+
signal,
|
|
1124
1171
|
...hasBody ? { body } : {}
|
|
1125
1172
|
});
|
|
1126
1173
|
};
|
|
1127
|
-
var
|
|
1174
|
+
var clientDisconnectSignal = (res) => {
|
|
1175
|
+
const controller = new AbortController();
|
|
1176
|
+
const abortIfPremature = () => {
|
|
1177
|
+
if (!res.writableEnded) {
|
|
1178
|
+
controller.abort(new Error("Client disconnected"));
|
|
1179
|
+
}
|
|
1180
|
+
};
|
|
1181
|
+
if (res.closed) {
|
|
1182
|
+
abortIfPremature();
|
|
1183
|
+
} else {
|
|
1184
|
+
res.once("close", abortIfPremature);
|
|
1185
|
+
}
|
|
1186
|
+
return controller.signal;
|
|
1187
|
+
};
|
|
1188
|
+
var withTimeout = (work, timeout, toolName) => new Promise((resolve, reject) => {
|
|
1128
1189
|
const timer = setTimeout(() => {
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
toolName
|
|
1133
|
-
})
|
|
1190
|
+
const error = new UserError(
|
|
1191
|
+
`Tool '${toolName}' timed out after ${timeout.ms}ms`,
|
|
1192
|
+
{ timeoutMs: timeout.ms, toolName }
|
|
1134
1193
|
);
|
|
1135
|
-
|
|
1194
|
+
timeout.controller.abort(error);
|
|
1195
|
+
reject(error);
|
|
1196
|
+
}, timeout.ms);
|
|
1136
1197
|
work.then(resolve, reject).finally(() => clearTimeout(timer));
|
|
1137
1198
|
});
|
|
1199
|
+
var requestScope = (...sources) => {
|
|
1200
|
+
const controller = new AbortController();
|
|
1201
|
+
const detach = new AbortController();
|
|
1202
|
+
for (const source of sources) {
|
|
1203
|
+
if (source === void 0) {
|
|
1204
|
+
continue;
|
|
1205
|
+
}
|
|
1206
|
+
if (source.aborted) {
|
|
1207
|
+
controller.abort(source.reason);
|
|
1208
|
+
break;
|
|
1209
|
+
}
|
|
1210
|
+
source.addEventListener("abort", () => controller.abort(source.reason), {
|
|
1211
|
+
once: true,
|
|
1212
|
+
signal: detach.signal
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
return { release: () => detach.abort(), signal: controller.signal };
|
|
1216
|
+
};
|
|
1138
1217
|
var formatBytes = (bytes) => {
|
|
1139
1218
|
if (bytes >= 1024 * 1024 && bytes % (1024 * 1024) === 0) {
|
|
1140
1219
|
return `${bytes / (1024 * 1024)} MiB`;
|
|
@@ -1166,8 +1245,8 @@ var assertStandardSchema = (schema, toolName, field) => {
|
|
|
1166
1245
|
if (schema === void 0) {
|
|
1167
1246
|
return;
|
|
1168
1247
|
}
|
|
1169
|
-
const standard = _optionalChain([schema, 'optionalAccess',
|
|
1170
|
-
if (typeof _optionalChain([standard, 'optionalAccess',
|
|
1248
|
+
const standard = _optionalChain([schema, 'optionalAccess', _64 => _64["~standard"]]);
|
|
1249
|
+
if (typeof _optionalChain([standard, 'optionalAccess', _65 => _65.validate]) !== "function") {
|
|
1171
1250
|
throw new UnexpectedStateError(
|
|
1172
1251
|
`Tool '${toolName}' ${field} must implement Standard Schema. If you are using Zod, upgrade to version 3.24 or later.`,
|
|
1173
1252
|
{ toolName }
|
|
@@ -1176,13 +1255,13 @@ var assertStandardSchema = (schema, toolName, field) => {
|
|
|
1176
1255
|
};
|
|
1177
1256
|
var promptArgsSchema = (prompt) => {
|
|
1178
1257
|
const args = prompt.arguments;
|
|
1179
|
-
if (!_optionalChain([args, 'optionalAccess',
|
|
1258
|
+
if (!_optionalChain([args, 'optionalAccess', _66 => _66.length])) {
|
|
1180
1259
|
return void 0;
|
|
1181
1260
|
}
|
|
1182
1261
|
const shape = {};
|
|
1183
1262
|
for (const arg of args) {
|
|
1184
1263
|
const completer = _nullishCoalesce(arg.complete, () => ( (prompt.complete ? (value) => prompt.complete(arg.name, value) : void 0)));
|
|
1185
|
-
const valueSchema = _optionalChain([arg, 'access',
|
|
1264
|
+
const valueSchema = _optionalChain([arg, 'access', _67 => _67.enum, 'optionalAccess', _68 => _68.length]) ? _zod.z.enum(arg.enum) : _zod.z.string();
|
|
1186
1265
|
const described = arg.description ? valueSchema.describe(arg.description) : valueSchema;
|
|
1187
1266
|
const base = completer ? _server.completable.call(void 0,
|
|
1188
1267
|
described,
|