@vite-hub/source 0.0.4 → 0.3.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 +267 -96
- package/dist/client.d.ts +27 -10
- package/dist/client.js +99 -15
- package/dist/collection-B8sgxw5-.d.ts +290 -0
- package/dist/collection-C0Rvrx3p.js +297 -0
- package/dist/collection-route-BplWPxHR.js +10 -0
- package/dist/drizzle.d.ts +48 -0
- package/dist/drizzle.js +87 -0
- package/dist/error-diagnostics-ClQKdi7c.js +194 -0
- package/dist/github-D5S0dEZe.js +1312 -0
- package/dist/{glob.js → glob-DmdMVqjx.js} +154 -57
- package/dist/index.d.ts +284 -62
- package/dist/index.js +583 -29
- package/dist/invariant-DolT9EEx.js +22 -0
- package/dist/mcp.d.ts +3 -4
- package/dist/mcp.js +184 -5917
- package/dist/object-CtSHeGQO.js +17 -0
- package/dist/{path-CUhvUREm.js → path-DFlSryRA.js} +90 -40
- package/dist/root-DJNmqCEW.js +11 -0
- package/dist/server.d.ts +24 -11
- package/dist/server.js +97 -26
- package/dist/types-Ln-FxVFn.d.ts +98 -0
- package/dist/vite.d.ts +202 -14
- package/dist/vite.js +1683 -122
- package/package.json +55 -58
- package/dist/auth-Ddw55OUG.js +0 -1261
- package/dist/client-CDfTmtQu.js +0 -7903
- package/dist/collection-B8pXGM2d.js +0 -141
- 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/file-BSWQg9Qv.js +0 -503
- package/dist/file-EQ3AjVM6.d.ts +0 -20
- package/dist/file.d.ts +0 -2
- package/dist/file.js +0 -2
- package/dist/github.d.ts +0 -17
- package/dist/github.js +0 -1033
- package/dist/glob.d.ts +0 -15
- package/dist/markdown.d.ts +0 -7
- package/dist/markdown.js +0 -10
- package/dist/path-BzmU4Eni.js +0 -36
- package/dist/registry-C8skfCSV.js +0 -120
- package/dist/sse-CE9Q2JqM.js +0 -407
- package/dist/streamableHttp-BszaXLmg.js +0 -491
- package/dist/types-AIBmt_m6.js +0 -6275
- package/dist/types-Bu3WvNX9.d.ts +0 -71
- package/tsconfig.vite.json +0 -6
- package/types/source/fallback.d.ts +0 -1
- package/types/source/index.d.ts +0 -1
package/dist/glob.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { r as Source } from "./types-Bu3WvNX9.js";
|
|
2
|
-
|
|
3
|
-
//#region src/sources/glob.d.ts
|
|
4
|
-
interface GlobSourceOptions {
|
|
5
|
-
cwd?: string;
|
|
6
|
-
dot?: boolean;
|
|
7
|
-
followSymlinks?: boolean;
|
|
8
|
-
include: string | string[];
|
|
9
|
-
ignore?: string | readonly string[];
|
|
10
|
-
keyCache?: boolean;
|
|
11
|
-
prefix?: string;
|
|
12
|
-
}
|
|
13
|
-
declare function glob(options: GlobSourceOptions): Source<string>;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { type GlobSourceOptions, glob };
|
package/dist/markdown.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { r as Source } from "./types-Bu3WvNX9.js";
|
|
2
|
-
import { n as FileSourceOptions } from "./file-EQ3AjVM6.js";
|
|
3
|
-
|
|
4
|
-
//#region src/sources/markdown.d.ts
|
|
5
|
-
declare function markdown<const TKey extends string = string>(options: FileSourceOptions<TKey>): Source<TKey>;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { markdown };
|
package/dist/markdown.js
DELETED
package/dist/path-BzmU4Eni.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ViteHubError, getViteHubErrorShape } from "@vite-hub/runtime";
|
|
2
|
-
//#region src/core/errors.ts
|
|
3
|
-
function sourceError(message, options) {
|
|
4
|
-
return new ViteHubError("SOURCE_FAILED", message, options);
|
|
5
|
-
}
|
|
6
|
-
function sourceNotFoundError(name) {
|
|
7
|
-
return new ViteHubError("SOURCE_NOT_FOUND", `[vitehub] Source "${name}" is not registered.`, { details: { name } });
|
|
8
|
-
}
|
|
9
|
-
function sourcePathError(path) {
|
|
10
|
-
const publicPath = path.slice(0, 4096);
|
|
11
|
-
return new ViteHubError("SOURCE_PATH_INVALID", `[vitehub] Source path escapes the source root: ${JSON.stringify(publicPath)}.`, { details: { path: publicPath } });
|
|
12
|
-
}
|
|
13
|
-
function isSourceError(value) {
|
|
14
|
-
const code = getViteHubErrorShape(value)?.code;
|
|
15
|
-
return code === "SOURCE_FAILED" || code === "SOURCE_NOT_FOUND" || code === "SOURCE_PATH_INVALID";
|
|
16
|
-
}
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region src/core/path.ts
|
|
19
|
-
function normalizeSourcePath(path = "") {
|
|
20
|
-
return path.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+$/, "");
|
|
21
|
-
}
|
|
22
|
-
function normalizeSafeSourcePath(path = "", options = {}) {
|
|
23
|
-
const raw = path.replace(/\\/g, "/");
|
|
24
|
-
const normalized = normalizeSourcePath(path);
|
|
25
|
-
const parts = normalized.split("/").filter(Boolean);
|
|
26
|
-
if (!options.allowEmpty && !normalized) throw sourcePathError(path);
|
|
27
|
-
if (raw.startsWith("/") || /^[a-z]:\//i.test(raw) || parts.some((part) => part === "." || part === "..")) throw sourcePathError(path);
|
|
28
|
-
if (!options.allowReserved && (parts[0] === ".git" || parts[0] === ".vitehub")) throw sourcePathError(path);
|
|
29
|
-
return normalized;
|
|
30
|
-
}
|
|
31
|
-
function decodeSourceContent(content, options) {
|
|
32
|
-
if (options?.encoding === "binary") return typeof content === "string" ? new TextEncoder().encode(content) : content;
|
|
33
|
-
return typeof content === "string" ? content : new TextDecoder().decode(content);
|
|
34
|
-
}
|
|
35
|
-
//#endregion
|
|
36
|
-
export { sourceError as a, isSourceError as i, normalizeSafeSourcePath as n, sourceNotFoundError as o, normalizeSourcePath as r, sourcePathError as s, decodeSourceContent as t };
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { a as sourceError, n as normalizeSafeSourcePath, o as sourceNotFoundError, r as normalizeSourcePath, t as decodeSourceContent } from "./path-BzmU4Eni.js";
|
|
2
|
-
//#region src/core/registry.ts
|
|
3
|
-
const sourceRegistry = /* @__PURE__ */ new Map();
|
|
4
|
-
function registerSource(name, source) {
|
|
5
|
-
sourceRegistry.set(name, source);
|
|
6
|
-
return source;
|
|
7
|
-
}
|
|
8
|
-
function registerSources(sources) {
|
|
9
|
-
for (const [name, source] of Object.entries(sources)) registerSource(name, source);
|
|
10
|
-
return sources;
|
|
11
|
-
}
|
|
12
|
-
function getRegisteredSource(name) {
|
|
13
|
-
const source = sourceRegistry.get(name);
|
|
14
|
-
if (!source) throw sourceNotFoundError(name);
|
|
15
|
-
return source;
|
|
16
|
-
}
|
|
17
|
-
function clearSources() {
|
|
18
|
-
sourceRegistry.clear();
|
|
19
|
-
}
|
|
20
|
-
function createSourceContext(name, context = {}) {
|
|
21
|
-
return {
|
|
22
|
-
abortSignal: context.abortSignal,
|
|
23
|
-
revision: context.revision,
|
|
24
|
-
rootDir: context.rootDir || process.cwd(),
|
|
25
|
-
source: context.source || name,
|
|
26
|
-
sourceRootDir: context.sourceRootDir,
|
|
27
|
-
workspace: context.workspace
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function createMissingContentError(key) {
|
|
31
|
-
return sourceError(`[vitehub] Source item ${JSON.stringify(key)} does not provide readable content.`);
|
|
32
|
-
}
|
|
33
|
-
function isNestedUnder(path, prefix) {
|
|
34
|
-
return !prefix || path === prefix || path.startsWith(`${prefix}/`);
|
|
35
|
-
}
|
|
36
|
-
function createDirectorySet(paths) {
|
|
37
|
-
const directories = /* @__PURE__ */ new Set();
|
|
38
|
-
for (const path of paths) {
|
|
39
|
-
const segments = normalizeSourcePath(path).split("/").filter(Boolean);
|
|
40
|
-
for (let index = 1; index < segments.length; index++) directories.add(segments.slice(0, index).join("/"));
|
|
41
|
-
}
|
|
42
|
-
return directories;
|
|
43
|
-
}
|
|
44
|
-
function useSource(name, context) {
|
|
45
|
-
const source = getRegisteredSource(name);
|
|
46
|
-
const ctx = createSourceContext(name, context);
|
|
47
|
-
let revisionPromise;
|
|
48
|
-
let preparePromise;
|
|
49
|
-
async function revision() {
|
|
50
|
-
if (ctx.revision) return ctx.revision;
|
|
51
|
-
revisionPromise ||= source.resolveRevision?.(ctx) ?? Promise.resolve(void 0);
|
|
52
|
-
const resolved = await revisionPromise;
|
|
53
|
-
if (resolved) ctx.revision = resolved;
|
|
54
|
-
return resolved;
|
|
55
|
-
}
|
|
56
|
-
async function ensurePrepared() {
|
|
57
|
-
await revision();
|
|
58
|
-
if (!source.prepare) return;
|
|
59
|
-
preparePromise ||= source.prepare(ctx);
|
|
60
|
-
await preparePromise;
|
|
61
|
-
}
|
|
62
|
-
async function keys() {
|
|
63
|
-
await ensurePrepared();
|
|
64
|
-
return await source.getKeys(ctx);
|
|
65
|
-
}
|
|
66
|
-
async function get(key) {
|
|
67
|
-
await ensurePrepared();
|
|
68
|
-
return await source.getItem(key, ctx);
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
revision,
|
|
72
|
-
keys,
|
|
73
|
-
get,
|
|
74
|
-
async items() {
|
|
75
|
-
await ensurePrepared();
|
|
76
|
-
if (source.getItems) return await source.getItems(ctx);
|
|
77
|
-
return await Promise.all((await keys()).map(get));
|
|
78
|
-
},
|
|
79
|
-
async read(key, options) {
|
|
80
|
-
const item = await get(key);
|
|
81
|
-
if (typeof item.content === "undefined") throw createMissingContentError(key);
|
|
82
|
-
return decodeSourceContent(item.content, options);
|
|
83
|
-
},
|
|
84
|
-
async meta(key) {
|
|
85
|
-
await ensurePrepared();
|
|
86
|
-
return await source.getMeta?.(key, ctx);
|
|
87
|
-
},
|
|
88
|
-
async exists(key) {
|
|
89
|
-
return (await keys()).includes(key);
|
|
90
|
-
},
|
|
91
|
-
async list(prefix = "") {
|
|
92
|
-
await ensurePrepared();
|
|
93
|
-
const normalizedPrefix = prefix ? normalizeSafeSourcePath(prefix, { allowEmpty: true }) : "";
|
|
94
|
-
const sourceKeys = await keys();
|
|
95
|
-
const directories = createDirectorySet(sourceKeys);
|
|
96
|
-
const result = /* @__PURE__ */ new Map();
|
|
97
|
-
for (const directory of directories) {
|
|
98
|
-
if (directory === normalizedPrefix) continue;
|
|
99
|
-
if (!isNestedUnder(directory, normalizedPrefix)) continue;
|
|
100
|
-
if (normalizeSourcePath(directory.slice(normalizedPrefix.length)).replace(/^\//, "").includes("/")) continue;
|
|
101
|
-
result.set(directory, {
|
|
102
|
-
key: directory,
|
|
103
|
-
type: "directory"
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
for (const key of sourceKeys) {
|
|
107
|
-
if (key === normalizedPrefix) continue;
|
|
108
|
-
if (!isNestedUnder(key, normalizedPrefix)) continue;
|
|
109
|
-
if (normalizeSourcePath(key.slice(normalizedPrefix.length)).replace(/^\//, "").includes("/")) continue;
|
|
110
|
-
result.set(key, {
|
|
111
|
-
key,
|
|
112
|
-
type: "file"
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
return [...result.values()].sort((left, right) => left.key.localeCompare(right.key));
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
//#endregion
|
|
120
|
-
export { useSource as a, registerSources as i, getRegisteredSource as n, registerSource as r, clearSources as t };
|
package/dist/sse-CE9Q2JqM.js
DELETED
|
@@ -1,407 +0,0 @@
|
|
|
1
|
-
import { y as JSONRPCMessageSchema } from "./types-AIBmt_m6.js";
|
|
2
|
-
import { a as normalizeHeaders, i as createFetchWithInit, n as auth, o as createParser, r as extractWWWAuthenticateParams, t as UnauthorizedError } from "./auth-Ddw55OUG.js";
|
|
3
|
-
//#region ../../node_modules/.pnpm/eventsource@3.0.7/node_modules/eventsource/dist/index.js
|
|
4
|
-
var ErrorEvent = class extends Event {
|
|
5
|
-
/**
|
|
6
|
-
* Constructs a new `ErrorEvent` instance. This is typically not called directly,
|
|
7
|
-
* but rather emitted by the `EventSource` object when an error occurs.
|
|
8
|
-
*
|
|
9
|
-
* @param type - The type of the event (should be "error")
|
|
10
|
-
* @param errorEventInitDict - Optional properties to include in the error event
|
|
11
|
-
*/
|
|
12
|
-
constructor(type, errorEventInitDict) {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
super(type), this.code = (_a = errorEventInitDict == null ? void 0 : errorEventInitDict.code) != null ? _a : void 0, this.message = (_b = errorEventInitDict == null ? void 0 : errorEventInitDict.message) != null ? _b : void 0;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Node.js "hides" the `message` and `code` properties of the `ErrorEvent` instance,
|
|
18
|
-
* when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,
|
|
19
|
-
* we explicitly include the properties in the `inspect` method.
|
|
20
|
-
*
|
|
21
|
-
* This is automatically called by Node.js when you `console.log` an instance of this class.
|
|
22
|
-
*
|
|
23
|
-
* @param _depth - The current depth
|
|
24
|
-
* @param options - The options passed to `util.inspect`
|
|
25
|
-
* @param inspect - The inspect function to use (prevents having to import it from `util`)
|
|
26
|
-
* @returns A string representation of the error
|
|
27
|
-
*/
|
|
28
|
-
[Symbol.for("nodejs.util.inspect.custom")](_depth, options, inspect) {
|
|
29
|
-
return inspect(inspectableError(this), options);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Deno "hides" the `message` and `code` properties of the `ErrorEvent` instance,
|
|
33
|
-
* when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,
|
|
34
|
-
* we explicitly include the properties in the `inspect` method.
|
|
35
|
-
*
|
|
36
|
-
* This is automatically called by Deno when you `console.log` an instance of this class.
|
|
37
|
-
*
|
|
38
|
-
* @param inspect - The inspect function to use (prevents having to import it from `util`)
|
|
39
|
-
* @param options - The options passed to `Deno.inspect`
|
|
40
|
-
* @returns A string representation of the error
|
|
41
|
-
*/
|
|
42
|
-
[Symbol.for("Deno.customInspect")](inspect, options) {
|
|
43
|
-
return inspect(inspectableError(this), options);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
function syntaxError(message) {
|
|
47
|
-
const DomException = globalThis.DOMException;
|
|
48
|
-
return typeof DomException == "function" ? new DomException(message, "SyntaxError") : new SyntaxError(message);
|
|
49
|
-
}
|
|
50
|
-
function flattenError(err) {
|
|
51
|
-
return err instanceof Error ? "errors" in err && Array.isArray(err.errors) ? err.errors.map(flattenError).join(", ") : "cause" in err && err.cause instanceof Error ? `${err}: ${flattenError(err.cause)}` : err.message : `${err}`;
|
|
52
|
-
}
|
|
53
|
-
function inspectableError(err) {
|
|
54
|
-
return {
|
|
55
|
-
type: err.type,
|
|
56
|
-
message: err.message,
|
|
57
|
-
code: err.code,
|
|
58
|
-
defaultPrevented: err.defaultPrevented,
|
|
59
|
-
cancelable: err.cancelable,
|
|
60
|
-
timeStamp: err.timeStamp
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
var __typeError = (msg) => {
|
|
64
|
-
throw TypeError(msg);
|
|
65
|
-
}, __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg), __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __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), __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value), __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method), _readyState, _url, _redirectUrl, _withCredentials, _fetch, _reconnectInterval, _reconnectTimer, _lastEventId, _controller, _parser, _onError, _onMessage, _onOpen, _EventSource_instances, connect_fn, _onFetchResponse, _onFetchError, getRequestOptions_fn, _onEvent, _onRetryChange, failConnection_fn, scheduleReconnect_fn, _reconnect;
|
|
66
|
-
var EventSource = class extends EventTarget {
|
|
67
|
-
constructor(url, eventSourceInitDict) {
|
|
68
|
-
var _a, _b;
|
|
69
|
-
super(), __privateAdd(this, _EventSource_instances), this.CONNECTING = 0, this.OPEN = 1, this.CLOSED = 2, __privateAdd(this, _readyState), __privateAdd(this, _url), __privateAdd(this, _redirectUrl), __privateAdd(this, _withCredentials), __privateAdd(this, _fetch), __privateAdd(this, _reconnectInterval), __privateAdd(this, _reconnectTimer), __privateAdd(this, _lastEventId, null), __privateAdd(this, _controller), __privateAdd(this, _parser), __privateAdd(this, _onError, null), __privateAdd(this, _onMessage, null), __privateAdd(this, _onOpen, null), __privateAdd(this, _onFetchResponse, async (response) => {
|
|
70
|
-
var _a2;
|
|
71
|
-
__privateGet(this, _parser).reset();
|
|
72
|
-
const { body, redirected, status, headers } = response;
|
|
73
|
-
if (status === 204) {
|
|
74
|
-
__privateMethod(this, _EventSource_instances, failConnection_fn).call(this, "Server sent HTTP 204, not reconnecting", 204), this.close();
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
if (redirected ? __privateSet(this, _redirectUrl, new URL(response.url)) : __privateSet(this, _redirectUrl, void 0), status !== 200) {
|
|
78
|
-
__privateMethod(this, _EventSource_instances, failConnection_fn).call(this, `Non-200 status code (${status})`, status);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (!(headers.get("content-type") || "").startsWith("text/event-stream")) {
|
|
82
|
-
__privateMethod(this, _EventSource_instances, failConnection_fn).call(this, "Invalid content type, expected \"text/event-stream\"", status);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if (__privateGet(this, _readyState) === this.CLOSED) return;
|
|
86
|
-
__privateSet(this, _readyState, this.OPEN);
|
|
87
|
-
const openEvent = new Event("open");
|
|
88
|
-
if ((_a2 = __privateGet(this, _onOpen)) == null || _a2.call(this, openEvent), this.dispatchEvent(openEvent), typeof body != "object" || !body || !("getReader" in body)) {
|
|
89
|
-
__privateMethod(this, _EventSource_instances, failConnection_fn).call(this, "Invalid response body, expected a web ReadableStream", status), this.close();
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const decoder = new TextDecoder(), reader = body.getReader();
|
|
93
|
-
let open = !0;
|
|
94
|
-
do {
|
|
95
|
-
const { done, value } = await reader.read();
|
|
96
|
-
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
|
-
} while (open);
|
|
98
|
-
}), __privateAdd(this, _onFetchError, (err) => {
|
|
99
|
-
__privateSet(this, _controller, void 0), !(err.name === "AbortError" || err.type === "aborted") && __privateMethod(this, _EventSource_instances, scheduleReconnect_fn).call(this, flattenError(err));
|
|
100
|
-
}), __privateAdd(this, _onEvent, (event) => {
|
|
101
|
-
typeof event.id == "string" && __privateSet(this, _lastEventId, event.id);
|
|
102
|
-
const messageEvent = new MessageEvent(event.event || "message", {
|
|
103
|
-
data: event.data,
|
|
104
|
-
origin: __privateGet(this, _redirectUrl) ? __privateGet(this, _redirectUrl).origin : __privateGet(this, _url).origin,
|
|
105
|
-
lastEventId: event.id || ""
|
|
106
|
-
});
|
|
107
|
-
__privateGet(this, _onMessage) && (!event.event || event.event === "message") && __privateGet(this, _onMessage).call(this, messageEvent), this.dispatchEvent(messageEvent);
|
|
108
|
-
}), __privateAdd(this, _onRetryChange, (value) => {
|
|
109
|
-
__privateSet(this, _reconnectInterval, value);
|
|
110
|
-
}), __privateAdd(this, _reconnect, () => {
|
|
111
|
-
__privateSet(this, _reconnectTimer, void 0), __privateGet(this, _readyState) === this.CONNECTING && __privateMethod(this, _EventSource_instances, connect_fn).call(this);
|
|
112
|
-
});
|
|
113
|
-
try {
|
|
114
|
-
if (url instanceof URL) __privateSet(this, _url, url);
|
|
115
|
-
else if (typeof url == "string") __privateSet(this, _url, new URL(url, getBaseURL()));
|
|
116
|
-
else throw new Error("Invalid URL");
|
|
117
|
-
} catch {
|
|
118
|
-
throw syntaxError("An invalid or illegal string was specified");
|
|
119
|
-
}
|
|
120
|
-
__privateSet(this, _parser, createParser({
|
|
121
|
-
onEvent: __privateGet(this, _onEvent),
|
|
122
|
-
onRetry: __privateGet(this, _onRetryChange)
|
|
123
|
-
})), __privateSet(this, _readyState, this.CONNECTING), __privateSet(this, _reconnectInterval, 3e3), __privateSet(this, _fetch, (_a = eventSourceInitDict == null ? void 0 : eventSourceInitDict.fetch) != null ? _a : globalThis.fetch), __privateSet(this, _withCredentials, (_b = eventSourceInitDict == null ? void 0 : eventSourceInitDict.withCredentials) != null ? _b : !1), __privateMethod(this, _EventSource_instances, connect_fn).call(this);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Returns the state of this EventSource object's connection. It can have the values described below.
|
|
127
|
-
*
|
|
128
|
-
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/readyState)
|
|
129
|
-
*
|
|
130
|
-
* Note: typed as `number` instead of `0 | 1 | 2` for compatibility with the `EventSource` interface,
|
|
131
|
-
* defined in the TypeScript `dom` library.
|
|
132
|
-
*
|
|
133
|
-
* @public
|
|
134
|
-
*/
|
|
135
|
-
get readyState() {
|
|
136
|
-
return __privateGet(this, _readyState);
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Returns the URL providing the event stream.
|
|
140
|
-
*
|
|
141
|
-
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/url)
|
|
142
|
-
*
|
|
143
|
-
* @public
|
|
144
|
-
*/
|
|
145
|
-
get url() {
|
|
146
|
-
return __privateGet(this, _url).href;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise.
|
|
150
|
-
*
|
|
151
|
-
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/withCredentials)
|
|
152
|
-
*/
|
|
153
|
-
get withCredentials() {
|
|
154
|
-
return __privateGet(this, _withCredentials);
|
|
155
|
-
}
|
|
156
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/error_event) */
|
|
157
|
-
get onerror() {
|
|
158
|
-
return __privateGet(this, _onError);
|
|
159
|
-
}
|
|
160
|
-
set onerror(value) {
|
|
161
|
-
__privateSet(this, _onError, value);
|
|
162
|
-
}
|
|
163
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/message_event) */
|
|
164
|
-
get onmessage() {
|
|
165
|
-
return __privateGet(this, _onMessage);
|
|
166
|
-
}
|
|
167
|
-
set onmessage(value) {
|
|
168
|
-
__privateSet(this, _onMessage, value);
|
|
169
|
-
}
|
|
170
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/open_event) */
|
|
171
|
-
get onopen() {
|
|
172
|
-
return __privateGet(this, _onOpen);
|
|
173
|
-
}
|
|
174
|
-
set onopen(value) {
|
|
175
|
-
__privateSet(this, _onOpen, value);
|
|
176
|
-
}
|
|
177
|
-
addEventListener(type, listener, options) {
|
|
178
|
-
const listen = listener;
|
|
179
|
-
super.addEventListener(type, listen, options);
|
|
180
|
-
}
|
|
181
|
-
removeEventListener(type, listener, options) {
|
|
182
|
-
const listen = listener;
|
|
183
|
-
super.removeEventListener(type, listen, options);
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
|
|
187
|
-
*
|
|
188
|
-
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/close)
|
|
189
|
-
*
|
|
190
|
-
* @public
|
|
191
|
-
*/
|
|
192
|
-
close() {
|
|
193
|
-
__privateGet(this, _reconnectTimer) && clearTimeout(__privateGet(this, _reconnectTimer)), __privateGet(this, _readyState) !== this.CLOSED && (__privateGet(this, _controller) && __privateGet(this, _controller).abort(), __privateSet(this, _readyState, this.CLOSED), __privateSet(this, _controller, void 0));
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
_readyState = /* @__PURE__ */ new WeakMap(), _url = /* @__PURE__ */ new WeakMap(), _redirectUrl = /* @__PURE__ */ new WeakMap(), _withCredentials = /* @__PURE__ */ new WeakMap(), _fetch = /* @__PURE__ */ new WeakMap(), _reconnectInterval = /* @__PURE__ */ new WeakMap(), _reconnectTimer = /* @__PURE__ */ new WeakMap(), _lastEventId = /* @__PURE__ */ new WeakMap(), _controller = /* @__PURE__ */ new WeakMap(), _parser = /* @__PURE__ */ new WeakMap(), _onError = /* @__PURE__ */ new WeakMap(), _onMessage = /* @__PURE__ */ new WeakMap(), _onOpen = /* @__PURE__ */ new WeakMap(), _EventSource_instances = /* @__PURE__ */ new WeakSet(), connect_fn = function() {
|
|
197
|
-
__privateSet(this, _readyState, this.CONNECTING), __privateSet(this, _controller, new AbortController()), __privateGet(this, _fetch)(__privateGet(this, _url), __privateMethod(this, _EventSource_instances, getRequestOptions_fn).call(this)).then(__privateGet(this, _onFetchResponse)).catch(__privateGet(this, _onFetchError));
|
|
198
|
-
}, _onFetchResponse = /* @__PURE__ */ new WeakMap(), _onFetchError = /* @__PURE__ */ new WeakMap(), getRequestOptions_fn = function() {
|
|
199
|
-
var _a;
|
|
200
|
-
const init = {
|
|
201
|
-
mode: "cors",
|
|
202
|
-
redirect: "follow",
|
|
203
|
-
headers: {
|
|
204
|
-
Accept: "text/event-stream",
|
|
205
|
-
...__privateGet(this, _lastEventId) ? { "Last-Event-ID": __privateGet(this, _lastEventId) } : void 0
|
|
206
|
-
},
|
|
207
|
-
cache: "no-store",
|
|
208
|
-
signal: (_a = __privateGet(this, _controller)) == null ? void 0 : _a.signal
|
|
209
|
-
};
|
|
210
|
-
return "window" in globalThis && (init.credentials = this.withCredentials ? "include" : "same-origin"), init;
|
|
211
|
-
}, _onEvent = /* @__PURE__ */ new WeakMap(), _onRetryChange = /* @__PURE__ */ new WeakMap(), failConnection_fn = function(message, code) {
|
|
212
|
-
var _a;
|
|
213
|
-
__privateGet(this, _readyState) !== this.CLOSED && __privateSet(this, _readyState, this.CLOSED);
|
|
214
|
-
const errorEvent = new ErrorEvent("error", {
|
|
215
|
-
code,
|
|
216
|
-
message
|
|
217
|
-
});
|
|
218
|
-
(_a = __privateGet(this, _onError)) == null || _a.call(this, errorEvent), this.dispatchEvent(errorEvent);
|
|
219
|
-
}, scheduleReconnect_fn = function(message, code) {
|
|
220
|
-
var _a;
|
|
221
|
-
if (__privateGet(this, _readyState) === this.CLOSED) return;
|
|
222
|
-
__privateSet(this, _readyState, this.CONNECTING);
|
|
223
|
-
const errorEvent = new ErrorEvent("error", {
|
|
224
|
-
code,
|
|
225
|
-
message
|
|
226
|
-
});
|
|
227
|
-
(_a = __privateGet(this, _onError)) == null || _a.call(this, errorEvent), this.dispatchEvent(errorEvent), __privateSet(this, _reconnectTimer, setTimeout(__privateGet(this, _reconnect), __privateGet(this, _reconnectInterval)));
|
|
228
|
-
}, _reconnect = /* @__PURE__ */ new WeakMap(), EventSource.CONNECTING = 0, EventSource.OPEN = 1, EventSource.CLOSED = 2;
|
|
229
|
-
function getBaseURL() {
|
|
230
|
-
const doc = "document" in globalThis ? globalThis.document : void 0;
|
|
231
|
-
return doc && typeof doc == "object" && "baseURI" in doc && typeof doc.baseURI == "string" ? doc.baseURI : void 0;
|
|
232
|
-
}
|
|
233
|
-
//#endregion
|
|
234
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.30.0_@cfworker+json-schema@4.1.1_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/esm/client/sse.js
|
|
235
|
-
var SseError = class extends Error {
|
|
236
|
-
constructor(code, message, event) {
|
|
237
|
-
super(`SSE error: ${message}`);
|
|
238
|
-
this.code = code;
|
|
239
|
-
this.event = event;
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
/**
|
|
243
|
-
* Client transport for SSE: this will connect to a server using Server-Sent Events for receiving
|
|
244
|
-
* messages and make separate POST requests for sending messages.
|
|
245
|
-
* @deprecated SSEClientTransport is deprecated. Prefer to use StreamableHTTPClientTransport where possible instead. Note that because some servers are still using SSE, clients may need to support both transports during the migration period.
|
|
246
|
-
*/
|
|
247
|
-
var SSEClientTransport = class {
|
|
248
|
-
constructor(url, opts) {
|
|
249
|
-
this._url = url;
|
|
250
|
-
this._resourceMetadataUrl = void 0;
|
|
251
|
-
this._scope = void 0;
|
|
252
|
-
this._eventSourceInit = opts?.eventSourceInit;
|
|
253
|
-
this._requestInit = opts?.requestInit;
|
|
254
|
-
this._authProvider = opts?.authProvider;
|
|
255
|
-
this._fetch = opts?.fetch;
|
|
256
|
-
this._fetchWithInit = createFetchWithInit(opts?.fetch, opts?.requestInit);
|
|
257
|
-
}
|
|
258
|
-
async _authThenStart() {
|
|
259
|
-
if (!this._authProvider) throw new UnauthorizedError("No auth provider");
|
|
260
|
-
let result;
|
|
261
|
-
try {
|
|
262
|
-
result = await auth(this._authProvider, {
|
|
263
|
-
serverUrl: this._url,
|
|
264
|
-
resourceMetadataUrl: this._resourceMetadataUrl,
|
|
265
|
-
scope: this._scope,
|
|
266
|
-
fetchFn: this._fetchWithInit
|
|
267
|
-
});
|
|
268
|
-
} catch (error) {
|
|
269
|
-
this.onerror?.(error);
|
|
270
|
-
throw error;
|
|
271
|
-
}
|
|
272
|
-
if (result !== "AUTHORIZED") throw new UnauthorizedError();
|
|
273
|
-
return await this._startOrAuth();
|
|
274
|
-
}
|
|
275
|
-
async _commonHeaders() {
|
|
276
|
-
const headers = {};
|
|
277
|
-
if (this._authProvider) {
|
|
278
|
-
const tokens = await this._authProvider.tokens();
|
|
279
|
-
if (tokens) headers["Authorization"] = `Bearer ${tokens.access_token}`;
|
|
280
|
-
}
|
|
281
|
-
if (this._protocolVersion) headers["mcp-protocol-version"] = this._protocolVersion;
|
|
282
|
-
const extraHeaders = normalizeHeaders(this._requestInit?.headers);
|
|
283
|
-
return new Headers({
|
|
284
|
-
...headers,
|
|
285
|
-
...extraHeaders
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
_startOrAuth() {
|
|
289
|
-
const fetchImpl = this?._eventSourceInit?.fetch ?? this._fetch ?? fetch;
|
|
290
|
-
return new Promise((resolve, reject) => {
|
|
291
|
-
this._eventSource = new EventSource(this._url.href, {
|
|
292
|
-
...this._eventSourceInit,
|
|
293
|
-
fetch: async (url, init) => {
|
|
294
|
-
const headers = await this._commonHeaders();
|
|
295
|
-
headers.set("Accept", "text/event-stream");
|
|
296
|
-
const response = await fetchImpl(url, {
|
|
297
|
-
...init,
|
|
298
|
-
headers
|
|
299
|
-
});
|
|
300
|
-
if (response.status === 401 && response.headers.has("www-authenticate")) {
|
|
301
|
-
const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
|
|
302
|
-
this._resourceMetadataUrl = resourceMetadataUrl;
|
|
303
|
-
this._scope = scope;
|
|
304
|
-
}
|
|
305
|
-
return response;
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
this._abortController = new AbortController();
|
|
309
|
-
this._eventSource.onerror = (event) => {
|
|
310
|
-
if (event.code === 401 && this._authProvider) {
|
|
311
|
-
this._authThenStart().then(resolve, reject);
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
const error = new SseError(event.code, event.message, event);
|
|
315
|
-
reject(error);
|
|
316
|
-
this.onerror?.(error);
|
|
317
|
-
};
|
|
318
|
-
this._eventSource.onopen = () => {};
|
|
319
|
-
this._eventSource.addEventListener("endpoint", (event) => {
|
|
320
|
-
const messageEvent = event;
|
|
321
|
-
try {
|
|
322
|
-
this._endpoint = new URL(messageEvent.data, this._url);
|
|
323
|
-
if (this._endpoint.origin !== this._url.origin) throw new Error(`Endpoint origin does not match connection origin: ${this._endpoint.origin}`);
|
|
324
|
-
} catch (error) {
|
|
325
|
-
reject(error);
|
|
326
|
-
this.onerror?.(error);
|
|
327
|
-
this.close();
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
330
|
-
resolve();
|
|
331
|
-
});
|
|
332
|
-
this._eventSource.onmessage = (event) => {
|
|
333
|
-
const messageEvent = event;
|
|
334
|
-
let message;
|
|
335
|
-
try {
|
|
336
|
-
message = JSONRPCMessageSchema.parse(JSON.parse(messageEvent.data));
|
|
337
|
-
} catch (error) {
|
|
338
|
-
this.onerror?.(error);
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
this.onmessage?.(message);
|
|
342
|
-
};
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
async start() {
|
|
346
|
-
if (this._eventSource) throw new Error("SSEClientTransport already started! If using Client class, note that connect() calls start() automatically.");
|
|
347
|
-
return await this._startOrAuth();
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Call this method after the user has finished authorizing via their user agent and is redirected back to the MCP client application. This will exchange the authorization code for an access token, enabling the next connection attempt to successfully auth.
|
|
351
|
-
*/
|
|
352
|
-
async finishAuth(authorizationCode) {
|
|
353
|
-
if (!this._authProvider) throw new UnauthorizedError("No auth provider");
|
|
354
|
-
if (await auth(this._authProvider, {
|
|
355
|
-
serverUrl: this._url,
|
|
356
|
-
authorizationCode,
|
|
357
|
-
resourceMetadataUrl: this._resourceMetadataUrl,
|
|
358
|
-
scope: this._scope,
|
|
359
|
-
fetchFn: this._fetchWithInit
|
|
360
|
-
}) !== "AUTHORIZED") throw new UnauthorizedError("Failed to authorize");
|
|
361
|
-
}
|
|
362
|
-
async close() {
|
|
363
|
-
this._abortController?.abort();
|
|
364
|
-
this._eventSource?.close();
|
|
365
|
-
this.onclose?.();
|
|
366
|
-
}
|
|
367
|
-
async send(message) {
|
|
368
|
-
if (!this._endpoint) throw new Error("Not connected");
|
|
369
|
-
try {
|
|
370
|
-
const headers = await this._commonHeaders();
|
|
371
|
-
headers.set("content-type", "application/json");
|
|
372
|
-
const init = {
|
|
373
|
-
...this._requestInit,
|
|
374
|
-
method: "POST",
|
|
375
|
-
headers,
|
|
376
|
-
body: JSON.stringify(message),
|
|
377
|
-
signal: this._abortController?.signal
|
|
378
|
-
};
|
|
379
|
-
const response = await (this._fetch ?? fetch)(this._endpoint, init);
|
|
380
|
-
if (!response.ok) {
|
|
381
|
-
const text = await response.text().catch(() => null);
|
|
382
|
-
if (response.status === 401 && this._authProvider) {
|
|
383
|
-
const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
|
|
384
|
-
this._resourceMetadataUrl = resourceMetadataUrl;
|
|
385
|
-
this._scope = scope;
|
|
386
|
-
if (await auth(this._authProvider, {
|
|
387
|
-
serverUrl: this._url,
|
|
388
|
-
resourceMetadataUrl: this._resourceMetadataUrl,
|
|
389
|
-
scope: this._scope,
|
|
390
|
-
fetchFn: this._fetchWithInit
|
|
391
|
-
}) !== "AUTHORIZED") throw new UnauthorizedError();
|
|
392
|
-
return this.send(message);
|
|
393
|
-
}
|
|
394
|
-
throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`);
|
|
395
|
-
}
|
|
396
|
-
await response.body?.cancel();
|
|
397
|
-
} catch (error) {
|
|
398
|
-
this.onerror?.(error);
|
|
399
|
-
throw error;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
setProtocolVersion(version) {
|
|
403
|
-
this._protocolVersion = version;
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
-
//#endregion
|
|
407
|
-
export { SSEClientTransport };
|