@vite-hub/source 0.0.4 → 0.1.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 +219 -82
- package/dist/{auth-Ddw55OUG.js → auth-B-tX_rp0.js} +255 -90
- package/dist/{client-CDfTmtQu.js → client-BwstxtdY.js} +584 -207
- package/dist/client.d.ts +27 -10
- package/dist/client.js +71 -13
- package/dist/collection-B_4w_J8h.d.ts +257 -0
- package/dist/{collection-B8pXGM2d.js → collection-cursor-WzV1Jd6v.js} +37 -54
- package/dist/collection-route-BplWPxHR.js +10 -0
- package/dist/drizzle.d.ts +41 -0
- package/dist/drizzle.js +89 -0
- package/dist/error-diagnostics-X0kuFjBT.js +51 -0
- package/dist/file-BX0FSvgE.js +60 -0
- package/dist/{file-EQ3AjVM6.d.ts → file-DadN9dbN.d.ts} +2 -3
- package/dist/file.d.ts +1 -1
- package/dist/file.js +1 -1
- package/dist/files.d.ts +15 -0
- package/dist/files.js +38 -0
- package/dist/github.d.ts +8 -5
- package/dist/github.js +725 -426
- package/dist/glob-BmFqTvJY.js +993 -0
- package/dist/glob.d.ts +12 -4
- package/dist/glob.js +1 -894
- package/dist/index.d.ts +118 -27
- package/dist/index.js +623 -14
- package/dist/markdown.d.ts +4 -6
- package/dist/markdown.js +2 -2
- package/dist/mcp.d.ts +3 -4
- package/dist/mcp.js +302 -5920
- package/dist/{file-BSWQg9Qv.js → mrmime-40h5OOIp.js} +1 -56
- package/dist/{path-CUhvUREm.js → path-BS8rYm0n.js} +60 -40
- package/dist/{path-BzmU4Eni.js → path-DOBpV8ol.js} +3 -7
- package/dist/server.d.ts +256 -6
- package/dist/server.js +90 -12
- package/dist/{sse-CE9Q2JqM.js → sse-D9gqqNPj.js} +50 -9
- package/dist/{streamableHttp-BszaXLmg.js → streamableHttp-BL-E7pl5.js} +40 -22
- package/dist/types-BigOktIj.d.ts +93 -0
- package/dist/{types-AIBmt_m6.js → types-CoWcW8oz.js} +2502 -1187
- package/dist/vite.d.ts +134 -13
- package/dist/vite.js +1734 -79
- package/package.json +55 -36
- package/dist/collection-CF2ON__k.d.ts +0 -92
- package/dist/collection-route-Dw7QLFyx.js +0 -6
- package/dist/content/client.d.ts +0 -3
- package/dist/content/client.js +0 -2
- package/dist/content.d.ts +0 -44
- package/dist/content.js +0 -157
- package/dist/registry-C8skfCSV.js +0 -120
- package/dist/types-Bu3WvNX9.d.ts +0 -71
package/dist/server.js
CHANGED
|
@@ -1,17 +1,62 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as sourceErrorDiagnostics } from "./error-diagnostics-X0kuFjBT.js";
|
|
2
|
+
import { t as CollectionCursorError } from "./collection-cursor-WzV1Jd6v.js";
|
|
2
3
|
import { createError, defineEventHandler, getQuery } from "h3";
|
|
4
|
+
//#region src/cached-source.ts
|
|
5
|
+
function isRuntimeFunction(value) {
|
|
6
|
+
if (value === null || Object(value) !== value) return false;
|
|
7
|
+
try {
|
|
8
|
+
Function.prototype.toString.call(value);
|
|
9
|
+
return true;
|
|
10
|
+
} catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** Cache `get(key)` in the Nitro `cache` storage. Other reader operations pass through unchanged. */
|
|
15
|
+
function cachedSource(reader, options) {
|
|
16
|
+
let cachedGet;
|
|
17
|
+
const get = reader.get;
|
|
18
|
+
async function readCached(key) {
|
|
19
|
+
cachedGet ??= import("nitro/cache").then(({ defineCachedFunction }) => defineCachedFunction((value) => get.call(reader, value), {
|
|
20
|
+
swr: false,
|
|
21
|
+
...options
|
|
22
|
+
}));
|
|
23
|
+
return await (await cachedGet)(key);
|
|
24
|
+
}
|
|
25
|
+
const facade = Object.create(reader);
|
|
26
|
+
return new Proxy(facade, {
|
|
27
|
+
get(_target, property) {
|
|
28
|
+
if (property === "get") return readCached;
|
|
29
|
+
const value = Reflect.get(reader, property, reader);
|
|
30
|
+
return isRuntimeFunction(value) ? value.bind(reader) : value;
|
|
31
|
+
},
|
|
32
|
+
set(_target, property, value) {
|
|
33
|
+
return Reflect.set(reader, property, value, reader);
|
|
34
|
+
},
|
|
35
|
+
ownKeys() {
|
|
36
|
+
return Reflect.ownKeys(reader);
|
|
37
|
+
},
|
|
38
|
+
getOwnPropertyDescriptor(_target, property) {
|
|
39
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(reader, property);
|
|
40
|
+
return descriptor ? {
|
|
41
|
+
...descriptor,
|
|
42
|
+
configurable: true
|
|
43
|
+
} : void 0;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
3
48
|
//#region src/server.ts
|
|
4
49
|
function queryValue(query, key) {
|
|
5
50
|
const value = query[key];
|
|
6
|
-
if (Array.isArray(value)) throw
|
|
51
|
+
if (Array.isArray(value)) throw sourceErrorDiagnostics.SOURCE_R0011({ message: `[vitehub] Collection query parameter ${JSON.stringify(key)} must have one value.` });
|
|
7
52
|
return value;
|
|
8
53
|
}
|
|
9
54
|
function queryLimit(query) {
|
|
10
55
|
const value = queryValue(query, "limit");
|
|
11
56
|
if (value === void 0) return;
|
|
12
|
-
if (!/^\d+$/.test(value)) throw
|
|
57
|
+
if (!/^\d+$/.test(value)) throw sourceErrorDiagnostics.SOURCE_R0012({ message: "[vitehub] Collection limit must be a positive integer." });
|
|
13
58
|
const limit = Number(value);
|
|
14
|
-
if (!Number.isSafeInteger(limit) || limit < 1) throw
|
|
59
|
+
if (!Number.isSafeInteger(limit) || limit < 1) throw sourceErrorDiagnostics.SOURCE_R0013({ message: "[vitehub] Collection limit must be a positive integer." });
|
|
15
60
|
return limit;
|
|
16
61
|
}
|
|
17
62
|
function collectionQuery(query) {
|
|
@@ -31,18 +76,43 @@ function serializeCollectionPage(value) {
|
|
|
31
76
|
const serialized = JSON.stringify(value, (_key, entry) => {
|
|
32
77
|
if (!isJSONContainer(entry) || Array.isArray(entry)) return entry;
|
|
33
78
|
const prototype = Object.getPrototypeOf(entry);
|
|
34
|
-
if (prototype !== null && Object.getPrototypeOf(prototype) !== null) throw
|
|
79
|
+
if (prototype !== null && Object.getPrototypeOf(prototype) !== null) throw sourceErrorDiagnostics.SOURCE_R0014({ message: "[vitehub] Collection pages may only contain plain objects, arrays, and toJSON() values. Use transform() for class instances and other object types." });
|
|
35
80
|
return entry;
|
|
36
81
|
});
|
|
37
|
-
if (serialized === void 0) throw
|
|
82
|
+
if (serialized === void 0) throw sourceErrorDiagnostics.SOURCE_R0015({ message: "[vitehub] Collection page is not JSON-serializable." });
|
|
38
83
|
return JSON.parse(serialized);
|
|
39
84
|
}
|
|
85
|
+
function isCallable(value) {
|
|
86
|
+
try {
|
|
87
|
+
Reflect.apply(Function.prototype.toString, value, []);
|
|
88
|
+
return true;
|
|
89
|
+
} catch {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function hasDeclaredMethod(value, key) {
|
|
94
|
+
const object = Object(value);
|
|
95
|
+
if (Object.hasOwn(object, key)) return isCallable(Reflect.get(object, key));
|
|
96
|
+
let prototype = Object.getPrototypeOf(object);
|
|
97
|
+
while (prototype && prototype !== Object.prototype) {
|
|
98
|
+
if (Object.hasOwn(prototype, key)) {
|
|
99
|
+
const constructor = Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
|
|
100
|
+
return isCallable(constructor) && constructor !== Object && constructor.prototype === prototype && isCallable(Reflect.get(object, key));
|
|
101
|
+
}
|
|
102
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
40
106
|
function assertCollection(value) {
|
|
41
|
-
if (Object(value) !== value || !(
|
|
107
|
+
if (Object(value) !== value || !hasDeclaredMethod(Object(value), "page") || !hasDeclaredMethod(Object(value), "parseQuery")) throw sourceErrorDiagnostics.SOURCE_R0016({ message: "[vitehub] defineCollectionHandler() requires a Collection." });
|
|
42
108
|
}
|
|
43
|
-
function defineCollectionHandler(collection) {
|
|
109
|
+
function defineCollectionHandler(collection, options = {}) {
|
|
44
110
|
assertCollection(collection);
|
|
45
|
-
|
|
111
|
+
if (collection.route === false) throw new TypeError("[vitehub] A server-only Collection cannot be exposed through defineCollectionHandler().");
|
|
112
|
+
const { authorize } = collection;
|
|
113
|
+
const { withAuthorization } = options;
|
|
114
|
+
if (authorize && !withAuthorization) throw sourceErrorDiagnostics.SOURCE_R0025({ message: "[vitehub] Collection authorize requires Auth. Enable Auth and add `server/auth.ts`." });
|
|
115
|
+
const handlePage = async (event) => {
|
|
46
116
|
const requestQuery = getQuery(event);
|
|
47
117
|
let cursor;
|
|
48
118
|
let limit;
|
|
@@ -62,10 +132,18 @@ function defineCollectionHandler(collection) {
|
|
|
62
132
|
signal: event.req.signal
|
|
63
133
|
}));
|
|
64
134
|
} catch (cause) {
|
|
65
|
-
if (cause instanceof CollectionCursorError)
|
|
135
|
+
if (cause instanceof CollectionCursorError) {
|
|
136
|
+
if (cause.reason === "stale") throw createError({
|
|
137
|
+
cause,
|
|
138
|
+
statusCode: 409,
|
|
139
|
+
statusMessage: cause.message
|
|
140
|
+
});
|
|
141
|
+
invalidRequest(cause);
|
|
142
|
+
}
|
|
66
143
|
throw cause;
|
|
67
144
|
}
|
|
68
|
-
}
|
|
145
|
+
};
|
|
146
|
+
return defineEventHandler(authorize && withAuthorization ? withAuthorization(authorize, handlePage) : handlePage);
|
|
69
147
|
}
|
|
70
148
|
//#endregion
|
|
71
|
-
export { defineCollectionHandler };
|
|
149
|
+
export { cachedSource, defineCollectionHandler };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as normalizeHeaders, i as createFetchWithInit, n as auth, o as
|
|
1
|
+
import { x as JSONRPCMessageSchema } from "./types-CoWcW8oz.js";
|
|
2
|
+
import { a as fetchLeavingRedirects, c as normalizeHeaders, i as createFetchWithInit, l as unfollowedRedirect, n as auth, o as fetchWithinOrigin, r as extractWWWAuthenticateParams, t as UnauthorizedError, u as createParser } from "./auth-B-tX_rp0.js";
|
|
3
3
|
//#region ../../node_modules/.pnpm/eventsource@3.0.7/node_modules/eventsource/dist/index.js
|
|
4
4
|
var ErrorEvent = class extends Event {
|
|
5
5
|
/**
|
|
@@ -62,7 +62,35 @@ function inspectableError(err) {
|
|
|
62
62
|
}
|
|
63
63
|
var __typeError = (msg) => {
|
|
64
64
|
throw TypeError(msg);
|
|
65
|
-
}
|
|
65
|
+
};
|
|
66
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
67
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
68
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
69
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
70
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
71
|
+
var _readyState;
|
|
72
|
+
var _url;
|
|
73
|
+
var _redirectUrl;
|
|
74
|
+
var _withCredentials;
|
|
75
|
+
var _fetch;
|
|
76
|
+
var _reconnectInterval;
|
|
77
|
+
var _reconnectTimer;
|
|
78
|
+
var _lastEventId;
|
|
79
|
+
var _controller;
|
|
80
|
+
var _parser;
|
|
81
|
+
var _onError;
|
|
82
|
+
var _onMessage;
|
|
83
|
+
var _onOpen;
|
|
84
|
+
var _EventSource_instances;
|
|
85
|
+
var connect_fn;
|
|
86
|
+
var _onFetchResponse;
|
|
87
|
+
var _onFetchError;
|
|
88
|
+
var getRequestOptions_fn;
|
|
89
|
+
var _onEvent;
|
|
90
|
+
var _onRetryChange;
|
|
91
|
+
var failConnection_fn;
|
|
92
|
+
var scheduleReconnect_fn;
|
|
93
|
+
var _reconnect;
|
|
66
94
|
var EventSource = class extends EventTarget {
|
|
67
95
|
constructor(url, eventSourceInitDict) {
|
|
68
96
|
var _a, _b;
|
|
@@ -96,7 +124,7 @@ var EventSource = class extends EventTarget {
|
|
|
96
124
|
value && __privateGet(this, _parser).feed(decoder.decode(value, { stream: !done })), done && (open = !1, __privateGet(this, _parser).reset(), __privateMethod(this, _EventSource_instances, scheduleReconnect_fn).call(this));
|
|
97
125
|
} while (open);
|
|
98
126
|
}), __privateAdd(this, _onFetchError, (err) => {
|
|
99
|
-
__privateSet(this, _controller, void 0),
|
|
127
|
+
__privateSet(this, _controller, void 0), err.name !== "AbortError" && err.type !== "aborted" && __privateMethod(this, _EventSource_instances, scheduleReconnect_fn).call(this, flattenError(err));
|
|
100
128
|
}), __privateAdd(this, _onEvent, (event) => {
|
|
101
129
|
typeof event.id == "string" && __privateSet(this, _lastEventId, event.id);
|
|
102
130
|
const messageEvent = new MessageEvent(event.event || "message", {
|
|
@@ -231,7 +259,7 @@ function getBaseURL() {
|
|
|
231
259
|
return doc && typeof doc == "object" && "baseURI" in doc && typeof doc.baseURI == "string" ? doc.baseURI : void 0;
|
|
232
260
|
}
|
|
233
261
|
//#endregion
|
|
234
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
262
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_@cfworker+json-schema@4.1.1_zod@4.6.7/node_modules/@modelcontextprotocol/sdk/dist/esm/client/sse.js
|
|
235
263
|
var SseError = class extends Error {
|
|
236
264
|
constructor(code, message, event) {
|
|
237
265
|
super(`SSE error: ${message}`);
|
|
@@ -254,6 +282,16 @@ var SSEClientTransport = class {
|
|
|
254
282
|
this._authProvider = opts?.authProvider;
|
|
255
283
|
this._fetch = opts?.fetch;
|
|
256
284
|
this._fetchWithInit = createFetchWithInit(opts?.fetch, opts?.requestInit);
|
|
285
|
+
this._followRedirects = opts?.redirectPolicy === "follow";
|
|
286
|
+
if (this._followRedirects) {
|
|
287
|
+
this._fetch = fetchLeavingRedirects(this._fetch);
|
|
288
|
+
this._fetchWithInit = fetchLeavingRedirects(this._fetchWithInit);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/** Error text for a redirect `response` that was not followed, or `undefined` for any other response. */
|
|
292
|
+
_unfollowedRedirect(response, url) {
|
|
293
|
+
const text = unfollowedRedirect(response, url);
|
|
294
|
+
return text && !this._followRedirects ? `${text} (redirectPolicy: 'same-origin')` : text;
|
|
257
295
|
}
|
|
258
296
|
async _authThenStart() {
|
|
259
297
|
if (!this._authProvider) throw new UnauthorizedError("No auth provider");
|
|
@@ -286,7 +324,9 @@ var SSEClientTransport = class {
|
|
|
286
324
|
});
|
|
287
325
|
}
|
|
288
326
|
_startOrAuth() {
|
|
289
|
-
const
|
|
327
|
+
const baseFetch = this?._eventSourceInit?.fetch ?? this._fetch ?? fetch;
|
|
328
|
+
const fetchImpl = this._followRedirects ? baseFetch : fetchWithinOrigin(baseFetch);
|
|
329
|
+
let redirect;
|
|
290
330
|
return new Promise((resolve, reject) => {
|
|
291
331
|
this._eventSource = new EventSource(this._url.href, {
|
|
292
332
|
...this._eventSourceInit,
|
|
@@ -297,6 +337,7 @@ var SSEClientTransport = class {
|
|
|
297
337
|
...init,
|
|
298
338
|
headers
|
|
299
339
|
});
|
|
340
|
+
redirect = this._unfollowedRedirect(response, url);
|
|
300
341
|
if (response.status === 401 && response.headers.has("www-authenticate")) {
|
|
301
342
|
const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
|
|
302
343
|
this._resourceMetadataUrl = resourceMetadataUrl;
|
|
@@ -311,7 +352,7 @@ var SSEClientTransport = class {
|
|
|
311
352
|
this._authThenStart().then(resolve, reject);
|
|
312
353
|
return;
|
|
313
354
|
}
|
|
314
|
-
const error = new SseError(event.code, event.message, event);
|
|
355
|
+
const error = new SseError(event.code, redirect ?? event.message, event);
|
|
315
356
|
reject(error);
|
|
316
357
|
this.onerror?.(error);
|
|
317
358
|
};
|
|
@@ -376,7 +417,7 @@ var SSEClientTransport = class {
|
|
|
376
417
|
body: JSON.stringify(message),
|
|
377
418
|
signal: this._abortController?.signal
|
|
378
419
|
};
|
|
379
|
-
const response = await (this._fetch ?? fetch)(this._endpoint, init);
|
|
420
|
+
const response = await fetchWithinOrigin(this._fetch ?? fetch)(this._endpoint, init);
|
|
380
421
|
if (!response.ok) {
|
|
381
422
|
const text = await response.text().catch(() => null);
|
|
382
423
|
if (response.status === 401 && this._authProvider) {
|
|
@@ -391,7 +432,7 @@ var SSEClientTransport = class {
|
|
|
391
432
|
}) !== "AUTHORIZED") throw new UnauthorizedError();
|
|
392
433
|
return this.send(message);
|
|
393
434
|
}
|
|
394
|
-
throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`);
|
|
435
|
+
throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${this._unfollowedRedirect(response, this._endpoint) ?? text}`);
|
|
395
436
|
}
|
|
396
437
|
await response.body?.cancel();
|
|
397
438
|
} catch (error) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { a as normalizeHeaders, i as createFetchWithInit, n as auth, o as
|
|
1
|
+
import { a as __toESM, i as __commonJSMin } from "./path-BS8rYm0n.js";
|
|
2
|
+
import { G as isJSONRPCResultResponse, V as isInitializedNotification, W as isJSONRPCRequest, x as JSONRPCMessageSchema } from "./types-CoWcW8oz.js";
|
|
3
|
+
import { a as fetchLeavingRedirects, c as normalizeHeaders, i as createFetchWithInit, l as unfollowedRedirect, n as auth, o as fetchWithinOrigin, r as extractWWWAuthenticateParams, s as followWithinOrigin, t as UnauthorizedError, u as createParser } from "./auth-B-tX_rp0.js";
|
|
4
4
|
/*!
|
|
5
5
|
* content-type
|
|
6
6
|
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
7
7
|
* MIT Licensed
|
|
8
8
|
*/
|
|
9
9
|
//#endregion
|
|
10
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
10
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_@cfworker+json-schema@4.1.1_zod@4.6.7/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/mediaType.js
|
|
11
11
|
var import_content_type = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports) => {
|
|
12
12
|
/**
|
|
13
13
|
* RegExp to match *( ";" parameter ) in RFC 7231 sec 3.1.1.1
|
|
@@ -132,7 +132,7 @@ function mediaTypeEssence(header) {
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
//#endregion
|
|
135
|
-
//#region ../../node_modules/.pnpm/eventsource-parser@3.1.
|
|
135
|
+
//#region ../../node_modules/.pnpm/eventsource-parser@3.1.1/node_modules/eventsource-parser/dist/stream.js
|
|
136
136
|
var EventSourceParserStream = class extends TransformStream {
|
|
137
137
|
constructor({ onError, onRetry, onComment, maxBufferSize } = {}) {
|
|
138
138
|
let parser;
|
|
@@ -157,7 +157,7 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
157
157
|
}
|
|
158
158
|
};
|
|
159
159
|
//#endregion
|
|
160
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
160
|
+
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_@cfworker+json-schema@4.1.1_zod@4.6.7/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js
|
|
161
161
|
const DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS = {
|
|
162
162
|
initialReconnectionDelay: 1e3,
|
|
163
163
|
maxReconnectionDelay: 3e4,
|
|
@@ -185,9 +185,19 @@ var StreamableHTTPClientTransport = class {
|
|
|
185
185
|
this._authProvider = opts?.authProvider;
|
|
186
186
|
this._fetch = opts?.fetch;
|
|
187
187
|
this._fetchWithInit = createFetchWithInit(opts?.fetch, opts?.requestInit);
|
|
188
|
+
this._followRedirects = opts?.redirectPolicy === "follow";
|
|
189
|
+
if (this._followRedirects) {
|
|
190
|
+
this._fetch = fetchLeavingRedirects(this._fetch);
|
|
191
|
+
this._fetchWithInit = fetchLeavingRedirects(this._fetchWithInit);
|
|
192
|
+
}
|
|
188
193
|
this._sessionId = opts?.sessionId;
|
|
189
194
|
this._reconnectionOptions = opts?.reconnectionOptions ?? DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS;
|
|
190
195
|
}
|
|
196
|
+
/** Error text for a redirect `response` that was not followed, or `undefined` for any other response. */
|
|
197
|
+
_unfollowedRedirect(response, url) {
|
|
198
|
+
const text = unfollowedRedirect(response, url);
|
|
199
|
+
return text && !this._followRedirects ? `${text} (redirectPolicy: 'same-origin')` : text;
|
|
200
|
+
}
|
|
191
201
|
async _authThenStart() {
|
|
192
202
|
if (!this._authProvider) throw new UnauthorizedError("No auth provider");
|
|
193
203
|
let result;
|
|
@@ -225,16 +235,23 @@ var StreamableHTTPClientTransport = class {
|
|
|
225
235
|
const headers = await this._commonHeaders();
|
|
226
236
|
headers.set("Accept", "text/event-stream");
|
|
227
237
|
if (resumptionToken) headers.set("last-event-id", resumptionToken);
|
|
228
|
-
const
|
|
238
|
+
const fetchFn = this._fetch ?? fetch;
|
|
239
|
+
const init = {
|
|
229
240
|
method: "GET",
|
|
230
241
|
headers,
|
|
231
242
|
signal: this._abortController?.signal
|
|
243
|
+
};
|
|
244
|
+
let response = await fetchFn(this._url, this._followRedirects ? init : {
|
|
245
|
+
...init,
|
|
246
|
+
redirect: "manual"
|
|
232
247
|
});
|
|
248
|
+
const followed = this._followRedirects ? void 0 : followWithinOrigin(fetchFn, this._url, init, response);
|
|
249
|
+
if (followed) response = await followed;
|
|
233
250
|
if (!response.ok) {
|
|
234
251
|
await response.body?.cancel();
|
|
235
252
|
if (response.status === 401 && this._authProvider) return await this._authThenStart();
|
|
236
253
|
if (response.status === 405) return;
|
|
237
|
-
throw new StreamableHTTPError(response.status, `Failed to open SSE stream: ${response.statusText}`);
|
|
254
|
+
throw new StreamableHTTPError(response.status, `Failed to open SSE stream: ${this._unfollowedRedirect(response, this._url) ?? response.statusText}`);
|
|
238
255
|
}
|
|
239
256
|
this._handleSseStream(response.body, options, true);
|
|
240
257
|
} catch (error) {
|
|
@@ -371,7 +388,7 @@ var StreamableHTTPClientTransport = class {
|
|
|
371
388
|
body: JSON.stringify(message),
|
|
372
389
|
signal: this._abortController?.signal
|
|
373
390
|
};
|
|
374
|
-
const response = await (this._fetch ?? fetch)(this._url, init);
|
|
391
|
+
const response = await fetchWithinOrigin(this._fetch ?? fetch)(this._url, init);
|
|
375
392
|
const sessionId = response.headers.get("mcp-session-id");
|
|
376
393
|
if (sessionId) this._sessionId = sessionId;
|
|
377
394
|
if (!response.ok) {
|
|
@@ -407,7 +424,7 @@ var StreamableHTTPClientTransport = class {
|
|
|
407
424
|
return this.send(message);
|
|
408
425
|
}
|
|
409
426
|
}
|
|
410
|
-
throw new StreamableHTTPError(response.status, `Error POSTing to endpoint: ${text}`);
|
|
427
|
+
throw new StreamableHTTPError(response.status, `Error POSTing to endpoint: ${this._unfollowedRedirect(response, this._url) ?? text}`);
|
|
411
428
|
}
|
|
412
429
|
this._hasCompletedAuthFlow = false;
|
|
413
430
|
this._lastUpscopingHeader = void 0;
|
|
@@ -419,16 +436,17 @@ var StreamableHTTPClientTransport = class {
|
|
|
419
436
|
const hasRequests = (Array.isArray(message) ? message : [message]).filter((msg) => "method" in msg && "id" in msg && msg.id !== void 0).length > 0;
|
|
420
437
|
const contentType = response.headers.get("content-type");
|
|
421
438
|
const responseMediaType = mediaTypeEssence(contentType);
|
|
422
|
-
if (hasRequests)
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
439
|
+
if (hasRequests) {
|
|
440
|
+
if (responseMediaType === "text/event-stream") this._handleSseStream(response.body, { onresumptiontoken }, false);
|
|
441
|
+
else if (responseMediaType === "application/json") {
|
|
442
|
+
const data = await response.json();
|
|
443
|
+
const responseMessages = Array.isArray(data) ? data.map((msg) => JSONRPCMessageSchema.parse(msg)) : [JSONRPCMessageSchema.parse(data)];
|
|
444
|
+
for (const msg of responseMessages) this.onmessage?.(msg);
|
|
445
|
+
} else {
|
|
446
|
+
await response.body?.cancel();
|
|
447
|
+
throw new StreamableHTTPError(-1, `Unexpected content type: ${contentType}`);
|
|
448
|
+
}
|
|
449
|
+
} else await response.body?.cancel();
|
|
432
450
|
} catch (error) {
|
|
433
451
|
this.onerror?.(error);
|
|
434
452
|
throw error;
|
|
@@ -458,9 +476,9 @@ var StreamableHTTPClientTransport = class {
|
|
|
458
476
|
headers,
|
|
459
477
|
signal: this._abortController?.signal
|
|
460
478
|
};
|
|
461
|
-
const response = await (this._fetch ?? fetch)(this._url, init);
|
|
479
|
+
const response = await fetchWithinOrigin(this._fetch ?? fetch)(this._url, init);
|
|
462
480
|
await response.body?.cancel();
|
|
463
|
-
if (!response.ok && response.status !== 405) throw new StreamableHTTPError(response.status, `Failed to terminate session: ${response.statusText}`);
|
|
481
|
+
if (!response.ok && response.status !== 405) throw new StreamableHTTPError(response.status, `Failed to terminate session: ${this._unfollowedRedirect(response, this._url) ?? response.statusText}`);
|
|
464
482
|
this._sessionId = void 0;
|
|
465
483
|
} catch (error) {
|
|
466
484
|
this.onerror?.(error);
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
//#region src/core/types.d.ts
|
|
2
|
+
type SourceContent = string | Uint8Array;
|
|
3
|
+
interface ReadSourceOptions {
|
|
4
|
+
encoding?: "utf8" | "binary";
|
|
5
|
+
}
|
|
6
|
+
type ReadSourceResult<TOptions extends ReadSourceOptions | undefined = undefined> = TOptions extends {
|
|
7
|
+
encoding: "binary";
|
|
8
|
+
} ? Uint8Array : string;
|
|
9
|
+
interface SourceContext {
|
|
10
|
+
abortSignal?: AbortSignal;
|
|
11
|
+
revision?: SourceRevision;
|
|
12
|
+
rootDir: string;
|
|
13
|
+
sourceRootDir?: string;
|
|
14
|
+
source?: string;
|
|
15
|
+
workspace?: string;
|
|
16
|
+
}
|
|
17
|
+
interface SourceCacheOptions {
|
|
18
|
+
maxAge?: number;
|
|
19
|
+
}
|
|
20
|
+
interface SourceRevision {
|
|
21
|
+
id: string;
|
|
22
|
+
immutable: boolean;
|
|
23
|
+
ref?: string;
|
|
24
|
+
}
|
|
25
|
+
interface SourceItem<TKey extends string = string, TData = unknown, TMetadata extends object = object> {
|
|
26
|
+
key: TKey;
|
|
27
|
+
path?: string;
|
|
28
|
+
content?: SourceContent;
|
|
29
|
+
data?: TData;
|
|
30
|
+
mediaType?: string;
|
|
31
|
+
metadata?: TMetadata;
|
|
32
|
+
}
|
|
33
|
+
interface Source<TKey extends string = string, TData = unknown, TMetadata extends object = object> {
|
|
34
|
+
name: string;
|
|
35
|
+
cache?: false | SourceCacheOptions;
|
|
36
|
+
fingerprint?: unknown;
|
|
37
|
+
resolveRevision?(ctx: SourceContext): Promise<SourceRevision | undefined>;
|
|
38
|
+
prepare?(ctx: SourceContext): Promise<void>;
|
|
39
|
+
getKeys(ctx: SourceContext): Promise<TKey[]>;
|
|
40
|
+
getItem(key: TKey, ctx: SourceContext): Promise<SourceItem<TKey, TData, TMetadata>>;
|
|
41
|
+
getItems?(ctx: SourceContext): Promise<SourceItem<TKey, TData, TMetadata>[]>;
|
|
42
|
+
getMeta?(key: TKey, ctx: SourceContext): Promise<TMetadata | undefined>;
|
|
43
|
+
}
|
|
44
|
+
interface SourceListEntry<TKey extends string = string> {
|
|
45
|
+
key: TKey;
|
|
46
|
+
type: "file" | "directory";
|
|
47
|
+
}
|
|
48
|
+
declare global {
|
|
49
|
+
interface ViteHubSourceMap {}
|
|
50
|
+
}
|
|
51
|
+
interface SourceMap extends ViteHubSourceMap {}
|
|
52
|
+
/** Resolve an optional registered name to its loader definition. */
|
|
53
|
+
type RegisteredSource<TName extends SourceName> = TName extends keyof ViteHubSourceMap ? ViteHubSourceMap[TName] extends Source ? ViteHubSourceMap[TName] : never : Source;
|
|
54
|
+
type SourceName = [keyof ViteHubSourceMap] extends [never] ? string : Extract<keyof ViteHubSourceMap, string>;
|
|
55
|
+
type SourceKeyFunction<TSource extends Source> = TSource extends unknown ? (key: Parameters<TSource["getItem"]>[0]) => void : never;
|
|
56
|
+
/** Keys accepted by every possible definition variant. */
|
|
57
|
+
type SourceKey<TSource extends Source = Source> = SourceKeyFunction<TSource> extends ((key: infer TKey) => void) ? Extract<TKey, string> : never;
|
|
58
|
+
type SourceEntry<TSource extends Source = Source> = Awaited<ReturnType<TSource["getItem"]>>;
|
|
59
|
+
type ItemData<TItem> = TItem extends {
|
|
60
|
+
data?: infer TData;
|
|
61
|
+
} ? TData : never;
|
|
62
|
+
type ItemMetadata<TItem> = TItem extends {
|
|
63
|
+
metadata?: infer TMetadata;
|
|
64
|
+
} ? TMetadata : never;
|
|
65
|
+
type SourceData<TSource extends Source = Source> = ItemData<SourceEntry<TSource>>;
|
|
66
|
+
type SourceMetadata<TSource extends Source = Source> = ItemMetadata<SourceEntry<TSource>>;
|
|
67
|
+
type SourceMeta<TSource extends Source> = TSource extends unknown ? "getMeta" extends keyof TSource ? Awaited<ReturnType<NonNullable<TSource["getMeta"]>>> | (undefined extends TSource["getMeta"] ? undefined : never) : undefined : never;
|
|
68
|
+
type SourceEntries<TSource extends Source> = TSource extends unknown ? "getItems" extends keyof TSource ? Awaited<ReturnType<NonNullable<TSource["getItems"]>>> | (undefined extends TSource["getItems"] ? SourceEntry<TSource>[] : never) : SourceEntry<TSource>[] : never;
|
|
69
|
+
interface SourceFile<TKey extends string = string, TMetadata extends object = Record<string, unknown>> extends SourceItem<TKey, unknown, TMetadata> {
|
|
70
|
+
content: SourceContent;
|
|
71
|
+
}
|
|
72
|
+
/** File loaders guarantee readable content for every item. */
|
|
73
|
+
interface FileSource<TKey extends string = string, TMetadata extends object = Record<string, unknown>> extends Source<TKey, unknown, TMetadata> {
|
|
74
|
+
getItem(key: TKey, ctx: SourceContext): Promise<SourceFile<TKey, TMetadata>>;
|
|
75
|
+
getItems?(ctx: SourceContext): Promise<SourceFile<TKey, TMetadata>[]>;
|
|
76
|
+
}
|
|
77
|
+
interface SourceFileMethods<TKey extends string> {
|
|
78
|
+
read<TOptions extends ReadSourceOptions | undefined = undefined>(key: TKey, options?: TOptions): Promise<ReadSourceResult<TOptions>>;
|
|
79
|
+
list(prefix?: string): Promise<SourceListEntry[]>;
|
|
80
|
+
}
|
|
81
|
+
/** A reader owns one revision and preparation attempt. Create another reader to refresh. */
|
|
82
|
+
type SourceReader<TSource extends Source = Source> = {
|
|
83
|
+
revision(): Promise<SourceRevision | undefined>;
|
|
84
|
+
keys(): Promise<Awaited<ReturnType<TSource["getKeys"]>>>;
|
|
85
|
+
get(key: SourceKey<TSource>): Promise<SourceEntry<TSource>>;
|
|
86
|
+
items(): Promise<SourceEntries<TSource>>;
|
|
87
|
+
meta(key: SourceKey<TSource>): Promise<SourceMeta<TSource>>;
|
|
88
|
+
exists(key: SourceKey<TSource>): Promise<boolean>;
|
|
89
|
+
} & (SourceEntry<TSource> extends {
|
|
90
|
+
content: SourceContent;
|
|
91
|
+
} ? SourceFileMethods<SourceKey<TSource>> : object);
|
|
92
|
+
//#endregion
|
|
93
|
+
export { SourceName as _, Source as a, SourceContext as c, SourceFile as d, SourceItem as f, SourceMetadata as g, SourceMap as h, RegisteredSource as i, SourceData as l, SourceListEntry as m, ReadSourceOptions as n, SourceCacheOptions as o, SourceKey as p, ReadSourceResult as r, SourceContent as s, FileSource as t, SourceEntry as u, SourceReader as v, SourceRevision as y };
|