@vite-hub/source 0.0.2 → 0.0.3
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 +32 -0
- package/dist/index.d.ts +167 -10
- package/dist/index.js +1093 -9
- package/package.json +2 -30
- package/dist/chunk-D7D4PA-g.js +0 -13
- package/dist/custom-EnZvMLiy.d.ts +0 -6
- package/dist/file-slFAccIZ.d.ts +0 -20
- package/dist/github-B4lgrzXQ.js +0 -565
- package/dist/glob-CuxZwoC3.d.ts +0 -15
- package/dist/index-CJpN2j6c.d.ts +0 -17
- package/dist/markdown-Beo-0cqc.d.ts +0 -7
- package/dist/mcp-resources-C7-5Qeh4.d.ts +0 -41
- package/dist/mcp-resources-DSDqTfbK.js +0 -307
- package/dist/path-B5QNI5sY.js +0 -44
- package/dist/sources/custom.d.ts +0 -2
- package/dist/sources/custom.js +0 -6
- package/dist/sources/file.d.ts +0 -2
- package/dist/sources/file.js +0 -57
- package/dist/sources/github.d.ts +0 -2
- package/dist/sources/github.js +0 -2
- package/dist/sources/glob.d.ts +0 -2
- package/dist/sources/glob.js +0 -110
- package/dist/sources/index.d.ts +0 -13
- package/dist/sources/index.js +0 -18
- package/dist/sources/markdown.d.ts +0 -2
- package/dist/sources/markdown.js +0 -10
- package/dist/sources/mcp-resources.d.ts +0 -2
- package/dist/sources/mcp-resources.js +0 -2
- package/dist/types-f6Lyjq8g.d.ts +0 -73
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { r as Source } from "./types-f6Lyjq8g.js";
|
|
2
|
-
import { n as FileSourceOptions } from "./file-slFAccIZ.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 as t };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { i as SourceCacheOptions, o as SourceContext, r as Source } from "./types-f6Lyjq8g.js";
|
|
2
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
3
|
-
import { SSEClientTransportOptions } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
4
|
-
import { StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
5
|
-
import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
6
|
-
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
7
|
-
import { BlobResourceContents, Resource, TextResourceContents } from "@modelcontextprotocol/sdk/types.js";
|
|
8
|
-
|
|
9
|
-
//#region src/sources/mcp-resources.d.ts
|
|
10
|
-
type McpResourcesRequestOptions = RequestOptions;
|
|
11
|
-
type McpResourceDescriptor = Resource;
|
|
12
|
-
type McpResourceContent = TextResourceContents | BlobResourceContents;
|
|
13
|
-
interface McpResourcesClient {
|
|
14
|
-
close?: () => void | Promise<void>;
|
|
15
|
-
getServerVersion?: Client["getServerVersion"];
|
|
16
|
-
listResources: Client["listResources"];
|
|
17
|
-
readResource: Client["readResource"];
|
|
18
|
-
serverInfo?: unknown;
|
|
19
|
-
}
|
|
20
|
-
type McpResourcesTransportConfig = Transport | ({
|
|
21
|
-
type?: "http";
|
|
22
|
-
url: string | URL;
|
|
23
|
-
} & StreamableHTTPClientTransportOptions) | ({
|
|
24
|
-
type: "sse";
|
|
25
|
-
url: string | URL;
|
|
26
|
-
} & SSEClientTransportOptions);
|
|
27
|
-
interface McpResourcesClientConfig {
|
|
28
|
-
transport: McpResourcesTransportConfig;
|
|
29
|
-
}
|
|
30
|
-
type McpResourcesServer = McpResourcesClient | McpResourcesClientConfig | ((ctx: SourceContext) => McpResourcesClient | McpResourcesClientConfig | Promise<McpResourcesClient | McpResourcesClientConfig>);
|
|
31
|
-
interface McpResourcesSourceOptions<TKey extends string = string> {
|
|
32
|
-
cache?: false | SourceCacheOptions;
|
|
33
|
-
exclude?: string | string[];
|
|
34
|
-
include?: string | string[];
|
|
35
|
-
path?: (resource: McpResourceDescriptor) => TKey | string | undefined;
|
|
36
|
-
request?: McpResourcesRequestOptions;
|
|
37
|
-
server: McpResourcesServer;
|
|
38
|
-
}
|
|
39
|
-
declare function mcpResources<const TKey extends string = string>(options: McpResourcesSourceOptions<TKey>): Source<TKey>;
|
|
40
|
-
//#endregion
|
|
41
|
-
export { McpResourcesRequestOptions as a, McpResourcesTransportConfig as c, McpResourcesClientConfig as i, mcpResources as l, McpResourceDescriptor as n, McpResourcesServer as o, McpResourcesClient as r, McpResourcesSourceOptions as s, McpResourceContent as t };
|
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
import { i as normalizeSourcePath, n as matchesAny, o as sourceError, r as normalizeSafeSourcePath } from "./path-B5QNI5sY.js";
|
|
2
|
-
import { Cause, Data, Effect, Exit, Ref, Scope } from "effect";
|
|
3
|
-
//#region ../internal/src/effect.ts
|
|
4
|
-
var EffectBoundaryFailure = class extends Data.TaggedError("EffectBoundaryFailure") {};
|
|
5
|
-
function createEffectBoundary(options) {
|
|
6
|
-
function interruptionError(signal) {
|
|
7
|
-
if (signal?.aborted && signal.reason !== void 0) return signal.reason;
|
|
8
|
-
const error = new Error(options.interruptionMessage);
|
|
9
|
-
error.name = "AbortError";
|
|
10
|
-
return error;
|
|
11
|
-
}
|
|
12
|
-
function causeValues(cause, signal) {
|
|
13
|
-
return cause.reasons.map((reason) => {
|
|
14
|
-
if (Cause.isFailReason(reason)) return reason.error instanceof EffectBoundaryFailure ? reason.error.cause : reason.error;
|
|
15
|
-
if (Cause.isDieReason(reason)) return reason.defect;
|
|
16
|
-
return interruptionError(signal);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
function tryPromise(evaluate) {
|
|
20
|
-
return Effect.tryPromise({
|
|
21
|
-
catch: (cause) => new EffectBoundaryFailure({ cause }),
|
|
22
|
-
try: (signal) => Promise.resolve(evaluate(signal))
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
async function run(effect, runOptions = {}) {
|
|
26
|
-
const exit = await Effect.runPromiseExit(effect, runOptions.signal ? { signal: runOptions.signal } : void 0);
|
|
27
|
-
if (Exit.isSuccess(exit)) return exit.value;
|
|
28
|
-
const causes = causeValues(exit.cause, runOptions.signal);
|
|
29
|
-
if (causes.length === 1) throw causes[0];
|
|
30
|
-
throw new AggregateError(causes, options.aggregateMessage);
|
|
31
|
-
}
|
|
32
|
-
function acquireWithCapturedRelease(scope, failures, acquire, release) {
|
|
33
|
-
return Scope.provide(Effect.acquireRelease(acquire, (resource, exit) => Effect.matchCauseEffect(release(resource, exit), {
|
|
34
|
-
onFailure: (cause) => Ref.update(failures, (current) => [...current, ...causeValues(cause)]),
|
|
35
|
-
onSuccess: () => Effect.void
|
|
36
|
-
})), scope);
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
acquireWithCapturedRelease,
|
|
40
|
-
causeValues,
|
|
41
|
-
closeScopeWithCapturedReleases: Effect.fn("ViteHub.EffectBoundary.closeScope")(function* (scope, failures, closeOptions) {
|
|
42
|
-
yield* Scope.close(scope, closeOptions.exit ?? Exit.void);
|
|
43
|
-
const causes = yield* Ref.get(failures);
|
|
44
|
-
if (causes.length === 0) return;
|
|
45
|
-
const cause = causes.length === 1 ? causes[0] : new AggregateError(causes, closeOptions.aggregateMessage ?? options.aggregateMessage);
|
|
46
|
-
return yield* Effect.fail(new EffectBoundaryFailure({ cause }));
|
|
47
|
-
}),
|
|
48
|
-
run,
|
|
49
|
-
tryPromise
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
//#endregion
|
|
53
|
-
//#region src/sources/mcp-resources.ts
|
|
54
|
-
const mcpEffectBoundary = createEffectBoundary({
|
|
55
|
-
aggregateMessage: "[vitehub] MCP Resource Source operation failed for multiple reasons.",
|
|
56
|
-
interruptionMessage: "[vitehub] MCP Resource Source operation was interrupted."
|
|
57
|
-
});
|
|
58
|
-
function isMcpResourcesClient(value) {
|
|
59
|
-
return typeof value === "object" && value !== null && typeof value.listResources === "function" && typeof value.readResource === "function";
|
|
60
|
-
}
|
|
61
|
-
function isMcpResourcesClientConfig(value) {
|
|
62
|
-
return typeof value === "object" && value !== null && "transport" in value;
|
|
63
|
-
}
|
|
64
|
-
function isMcpTransport(value) {
|
|
65
|
-
return typeof value === "object" && value !== null && typeof value.close === "function" && typeof value.send === "function" && typeof value.start === "function";
|
|
66
|
-
}
|
|
67
|
-
async function createMcpTransport(config) {
|
|
68
|
-
if (isMcpTransport(config)) return config;
|
|
69
|
-
const { type = "http", url, ...options } = config;
|
|
70
|
-
if (type === "sse") {
|
|
71
|
-
const { SSEClientTransport } = await import("@modelcontextprotocol/sdk/client/sse.js");
|
|
72
|
-
return new SSEClientTransport(new URL(url), options);
|
|
73
|
-
}
|
|
74
|
-
const { StreamableHTTPClientTransport } = await import("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
75
|
-
return new StreamableHTTPClientTransport(new URL(url), options);
|
|
76
|
-
}
|
|
77
|
-
async function createMcpClient(config) {
|
|
78
|
-
const [{ Client }, transport] = await Promise.all([import("@modelcontextprotocol/sdk/client/index.js"), createMcpTransport(config.transport)]);
|
|
79
|
-
return {
|
|
80
|
-
client: new Client({
|
|
81
|
-
name: "vitehub-source",
|
|
82
|
-
version: "0.0.1"
|
|
83
|
-
}),
|
|
84
|
-
transport
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
async function resolveMcpServer(server, ctx) {
|
|
88
|
-
const resolved = typeof server === "function" ? await server(ctx) : server;
|
|
89
|
-
if (isMcpResourcesClient(resolved) || isMcpResourcesClientConfig(resolved)) return resolved;
|
|
90
|
-
throw new TypeError("[vitehub] mcpResources({ server }) must resolve to an MCP client or MCP client config.");
|
|
91
|
-
}
|
|
92
|
-
function withRequestSignal(request, signal) {
|
|
93
|
-
return {
|
|
94
|
-
...request,
|
|
95
|
-
signal: request?.signal && request.signal !== signal ? AbortSignal.any([request.signal, signal]) : signal
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
async function withMcpClient(server, ctx, request, callback) {
|
|
99
|
-
const effect = Effect.flatMap(mcpEffectBoundary.tryPromise(() => resolveMcpServer(server, ctx)), (resolved) => {
|
|
100
|
-
if (isMcpResourcesClient(resolved)) return mcpEffectBoundary.tryPromise((signal) => callback(resolved, withRequestSignal(request, signal)));
|
|
101
|
-
return Effect.acquireUseRelease(mcpEffectBoundary.tryPromise(() => createMcpClient(resolved)), ({ client, transport }) => mcpEffectBoundary.tryPromise((signal) => client.connect(transport, { signal })).pipe(Effect.andThen(mcpEffectBoundary.tryPromise((signal) => callback(client, withRequestSignal(request, signal))))), ({ client }) => mcpEffectBoundary.tryPromise(() => client.close?.()));
|
|
102
|
-
});
|
|
103
|
-
return await mcpEffectBoundary.run(effect, { signal: ctx.abortSignal });
|
|
104
|
-
}
|
|
105
|
-
function extensionForMimeType(mimeType) {
|
|
106
|
-
if (!mimeType) return;
|
|
107
|
-
if (mimeType === "application/json") return "json";
|
|
108
|
-
if (mimeType === "text/markdown") return "md";
|
|
109
|
-
if (mimeType === "text/plain") return "txt";
|
|
110
|
-
if (mimeType === "text/html") return "html";
|
|
111
|
-
if (mimeType === "application/xml" || mimeType === "text/xml") return "xml";
|
|
112
|
-
if (mimeType === "application/octet-stream") return "bin";
|
|
113
|
-
}
|
|
114
|
-
function normalizePathSegment(input) {
|
|
115
|
-
return input.normalize("NFKD").replace(/\\/g, "/").replace(/[^\w./-]+/g, "-").replace(/\/+/g, "/").replace(/(^|\/)\.+(?=\/|$)/g, "").replace(/^-+|-+$/g, "");
|
|
116
|
-
}
|
|
117
|
-
function defaultResourcePath(resource) {
|
|
118
|
-
let path = "";
|
|
119
|
-
try {
|
|
120
|
-
const url = new URL(resource.uri);
|
|
121
|
-
const protocol = url.protocol.replace(/:$/, "");
|
|
122
|
-
path = [url.hostname || url.host, decodeURIComponent(url.pathname).replace(/^\/+/, "") || resource.name || protocol].filter(Boolean).join("/");
|
|
123
|
-
} catch {
|
|
124
|
-
path = resource.name || resource.uri;
|
|
125
|
-
}
|
|
126
|
-
let normalized = normalizePathSegment(path);
|
|
127
|
-
if (!normalized) normalized = normalizePathSegment(resource.name || resource.uri);
|
|
128
|
-
const extension = extensionForMimeType(resource.mimeType);
|
|
129
|
-
if (extension && !normalized.split("/").at(-1)?.includes(".")) normalized = `${normalized}.${extension}`;
|
|
130
|
-
return normalizeSafeSourcePath(normalized);
|
|
131
|
-
}
|
|
132
|
-
function resourcePathNeedsContentMimeType(resource, options) {
|
|
133
|
-
if (options.path || resource.mimeType) return false;
|
|
134
|
-
return !defaultResourcePath(resource).split("/").at(-1)?.includes(".");
|
|
135
|
-
}
|
|
136
|
-
function resourceWithContentMimeType(resource, contents) {
|
|
137
|
-
if (resource.mimeType) return resource;
|
|
138
|
-
const content = contents.find((item) => item.uri === resource.uri) || contents[0];
|
|
139
|
-
const mimeType = contents.length > 1 ? "application/json" : content?.mimeType;
|
|
140
|
-
return mimeType ? {
|
|
141
|
-
...resource,
|
|
142
|
-
mimeType
|
|
143
|
-
} : resource;
|
|
144
|
-
}
|
|
145
|
-
function resourceKey(resource, options) {
|
|
146
|
-
return normalizeSafeSourcePath(options.path?.(resource) ?? defaultResourcePath(resource));
|
|
147
|
-
}
|
|
148
|
-
function shouldInclude(path, options) {
|
|
149
|
-
if (options.include && !matchesAny(path, options.include)) return false;
|
|
150
|
-
if (options.exclude && matchesAny(path, options.exclude)) return false;
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
async function listAllResources(client, request) {
|
|
154
|
-
const resources = [];
|
|
155
|
-
let cursor;
|
|
156
|
-
do {
|
|
157
|
-
const page = await client.listResources(cursor ? { cursor } : void 0, request);
|
|
158
|
-
resources.push(...page.resources);
|
|
159
|
-
cursor = page.nextCursor;
|
|
160
|
-
} while (cursor);
|
|
161
|
-
return resources;
|
|
162
|
-
}
|
|
163
|
-
async function readResourceContents(client, resource, request) {
|
|
164
|
-
return (await client.readResource({ uri: resource.uri }, request)).contents;
|
|
165
|
-
}
|
|
166
|
-
async function createEntries(resources, options, client) {
|
|
167
|
-
const entries = [];
|
|
168
|
-
const seen = /* @__PURE__ */ new Map();
|
|
169
|
-
for (const resource of resources) {
|
|
170
|
-
let contents;
|
|
171
|
-
let resolvedResource = resource;
|
|
172
|
-
if (client && resourcePathNeedsContentMimeType(resource, options)) {
|
|
173
|
-
contents = await readResourceContents(client, resource, options.request);
|
|
174
|
-
resolvedResource = resourceWithContentMimeType(resource, contents);
|
|
175
|
-
}
|
|
176
|
-
const key = resourceKey(resolvedResource, options);
|
|
177
|
-
if (!shouldInclude(key, options)) continue;
|
|
178
|
-
const existingUri = seen.get(key);
|
|
179
|
-
if (existingUri) throw sourceError(`[vitehub] mcpResources produced duplicate path ${JSON.stringify(key)} for ${JSON.stringify(existingUri)} and ${JSON.stringify(resource.uri)}.`);
|
|
180
|
-
seen.set(key, resource.uri);
|
|
181
|
-
entries.push({
|
|
182
|
-
contents,
|
|
183
|
-
key,
|
|
184
|
-
resource: resolvedResource
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
return entries;
|
|
188
|
-
}
|
|
189
|
-
function decodeBase64(value) {
|
|
190
|
-
if (typeof Buffer !== "undefined") return new Uint8Array(Buffer.from(value, "base64"));
|
|
191
|
-
const binary = atob(value);
|
|
192
|
-
const bytes = new Uint8Array(binary.length);
|
|
193
|
-
for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
|
|
194
|
-
return bytes;
|
|
195
|
-
}
|
|
196
|
-
function contentToSourceContent(content) {
|
|
197
|
-
if ("text" in content && typeof content.text === "string") return content.text;
|
|
198
|
-
if ("blob" in content && typeof content.blob === "string") return decodeBase64(content.blob);
|
|
199
|
-
return "";
|
|
200
|
-
}
|
|
201
|
-
function createResourceItem(key, resource, contents) {
|
|
202
|
-
const content = contents.find((item) => item.uri === resource.uri) || contents[0];
|
|
203
|
-
if (!content) throw sourceError(`[vitehub] mcpResources could not read resource ${JSON.stringify(resource.uri)}.`);
|
|
204
|
-
const multipleContents = contents.length > 1;
|
|
205
|
-
return {
|
|
206
|
-
key,
|
|
207
|
-
path: key,
|
|
208
|
-
content: multipleContents ? JSON.stringify(contents, null, 2) : contentToSourceContent(content),
|
|
209
|
-
mediaType: multipleContents ? "application/json" : content.mimeType || resource.mimeType,
|
|
210
|
-
metadata: {
|
|
211
|
-
description: resource.description,
|
|
212
|
-
name: resource.name,
|
|
213
|
-
serverResourceCount: contents.length,
|
|
214
|
-
size: resource.size,
|
|
215
|
-
title: resource.title,
|
|
216
|
-
uri: resource.uri
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
function mcpResources(options) {
|
|
221
|
-
if (!options || typeof options !== "object" || !options.server) throw new TypeError("[vitehub] mcpResources({ server }) requires an MCP server.");
|
|
222
|
-
async function getEntries(ctx) {
|
|
223
|
-
return await withMcpClient(options.server, ctx, options.request, async (client, request) => {
|
|
224
|
-
return await createEntries(await listAllResources(client, request), {
|
|
225
|
-
...options,
|
|
226
|
-
request
|
|
227
|
-
}, client);
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
async function getItems(ctx) {
|
|
231
|
-
return await withMcpClient(options.server, ctx, options.request, async (client, request) => {
|
|
232
|
-
const scopedOptions = {
|
|
233
|
-
...options,
|
|
234
|
-
request
|
|
235
|
-
};
|
|
236
|
-
const entries = await createEntries(await listAllResources(client, request), scopedOptions, client);
|
|
237
|
-
return await Promise.all(entries.map(async ({ contents, key, resource }) => {
|
|
238
|
-
return createResourceItem(key, resource, contents ?? await readResourceContents(client, resource, request));
|
|
239
|
-
}));
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
return {
|
|
243
|
-
cache: options.cache,
|
|
244
|
-
fingerprint: {
|
|
245
|
-
exclude: options.exclude,
|
|
246
|
-
include: options.include,
|
|
247
|
-
server: typeof options.server === "function" ? "[function]" : isMcpResourcesClient(options.server) ? {
|
|
248
|
-
client: true,
|
|
249
|
-
serverInfo: options.server.serverInfo
|
|
250
|
-
} : options.server
|
|
251
|
-
},
|
|
252
|
-
name: "mcpResources",
|
|
253
|
-
async getKeys(ctx) {
|
|
254
|
-
return (await getEntries(ctx)).map((entry) => entry.key);
|
|
255
|
-
},
|
|
256
|
-
async getItems(ctx) {
|
|
257
|
-
return await getItems(ctx);
|
|
258
|
-
},
|
|
259
|
-
async getMeta(key, ctx) {
|
|
260
|
-
const entry = (await getEntries(ctx)).find((entry) => entry.key === key);
|
|
261
|
-
if (!entry) return;
|
|
262
|
-
return {
|
|
263
|
-
description: entry.resource.description,
|
|
264
|
-
mimeType: entry.resource.mimeType,
|
|
265
|
-
name: entry.resource.name,
|
|
266
|
-
size: entry.resource.size,
|
|
267
|
-
title: entry.resource.title,
|
|
268
|
-
uri: entry.resource.uri
|
|
269
|
-
};
|
|
270
|
-
},
|
|
271
|
-
async getItem(key, ctx) {
|
|
272
|
-
return await withMcpClient(options.server, ctx, options.request, async (client, request) => {
|
|
273
|
-
const entry = (await createEntries(await listAllResources(client, request), {
|
|
274
|
-
...options,
|
|
275
|
-
request
|
|
276
|
-
}, client)).find((entry) => entry.key === key);
|
|
277
|
-
if (!entry) throw sourceError(`[vitehub] mcpResources could not find ${JSON.stringify(key)}.`);
|
|
278
|
-
const result = entry.contents ?? await readResourceContents(client, entry.resource, request);
|
|
279
|
-
return createResourceItem(key, entry.resource, result);
|
|
280
|
-
});
|
|
281
|
-
},
|
|
282
|
-
async search(query, ctx) {
|
|
283
|
-
const pattern = query.regex ? new RegExp(query.pattern, query.caseSensitive ? "g" : "gi") : void 0;
|
|
284
|
-
const search = query.caseSensitive ? query.pattern : query.pattern.toLowerCase();
|
|
285
|
-
const results = [];
|
|
286
|
-
for (const item of await getItems(ctx)) {
|
|
287
|
-
if (typeof item.content !== "string") continue;
|
|
288
|
-
if (query.paths?.length && !query.paths.some((path) => item.path && normalizeSourcePath(item.path).startsWith(normalizeSourcePath(path)))) continue;
|
|
289
|
-
const lines = item.content.split(/\r?\n/);
|
|
290
|
-
for (const [index, line] of lines.entries()) {
|
|
291
|
-
const matchIndex = pattern ? line.search(pattern) : (query.caseSensitive ? line : line.toLowerCase()).indexOf(search);
|
|
292
|
-
if (matchIndex === -1) continue;
|
|
293
|
-
results.push({
|
|
294
|
-
column: matchIndex + 1,
|
|
295
|
-
line: index + 1,
|
|
296
|
-
path: item.path || item.key,
|
|
297
|
-
text: line
|
|
298
|
-
});
|
|
299
|
-
if (query.limit && results.length >= query.limit) return results;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
return results;
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
//#endregion
|
|
307
|
-
export { mcpResources as t };
|
package/dist/path-B5QNI5sY.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { ViteHubError, getViteHubErrorShape } from "@vite-hub/runtime";
|
|
2
|
-
import picomatch from "picomatch";
|
|
3
|
-
import { isAbsolute } from "pathe";
|
|
4
|
-
//#region src/core/errors.ts
|
|
5
|
-
function sourceError(message, options) {
|
|
6
|
-
return new ViteHubError("SOURCE_FAILED", message, options);
|
|
7
|
-
}
|
|
8
|
-
function sourceNotFoundError(name) {
|
|
9
|
-
return new ViteHubError("SOURCE_NOT_FOUND", `[vitehub] Source "${name}" is not registered.`, { details: { name } });
|
|
10
|
-
}
|
|
11
|
-
function sourcePathError(path) {
|
|
12
|
-
const publicPath = path.slice(0, 4096);
|
|
13
|
-
return new ViteHubError("SOURCE_PATH_INVALID", `[vitehub] Source path escapes the source root: ${JSON.stringify(publicPath)}.`, { details: { path: publicPath } });
|
|
14
|
-
}
|
|
15
|
-
function isSourceError(value) {
|
|
16
|
-
const code = getViteHubErrorShape(value)?.code;
|
|
17
|
-
return code === "SOURCE_FAILED" || code === "SOURCE_NOT_FOUND" || code === "SOURCE_PATH_INVALID";
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/core/path.ts
|
|
21
|
-
function normalizeSourcePath(path = "") {
|
|
22
|
-
return path.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+$/, "");
|
|
23
|
-
}
|
|
24
|
-
function normalizeSafeSourcePath(path = "", options = {}) {
|
|
25
|
-
const raw = path.replace(/\\/g, "/");
|
|
26
|
-
const normalized = normalizeSourcePath(path);
|
|
27
|
-
const parts = normalized.split("/").filter(Boolean);
|
|
28
|
-
if (!options.allowEmpty && !normalized) throw sourcePathError(path);
|
|
29
|
-
if (isAbsolute(raw) || parts.some((part) => part === "." || part === "..")) throw sourcePathError(path);
|
|
30
|
-
if (!options.allowReserved && (parts[0] === ".git" || parts[0] === ".vitehub")) throw sourcePathError(path);
|
|
31
|
-
return normalized;
|
|
32
|
-
}
|
|
33
|
-
function matchesAny(path, patterns) {
|
|
34
|
-
if (!patterns) return true;
|
|
35
|
-
const list = Array.isArray(patterns) ? patterns : [patterns];
|
|
36
|
-
const normalizedPath = normalizeSourcePath(path);
|
|
37
|
-
return picomatch.isMatch(normalizedPath, list.map((pattern) => normalizeSourcePath(pattern)), { dot: true });
|
|
38
|
-
}
|
|
39
|
-
function decodeSourceContent(content, options) {
|
|
40
|
-
if (options?.encoding === "binary") return typeof content === "string" ? new TextEncoder().encode(content) : content;
|
|
41
|
-
return typeof content === "string" ? content : new TextDecoder().decode(content);
|
|
42
|
-
}
|
|
43
|
-
//#endregion
|
|
44
|
-
export { isSourceError as a, sourcePathError as c, normalizeSourcePath as i, matchesAny as n, sourceError as o, normalizeSafeSourcePath as r, sourceNotFoundError as s, decodeSourceContent as t };
|
package/dist/sources/custom.d.ts
DELETED
package/dist/sources/custom.js
DELETED
package/dist/sources/file.d.ts
DELETED
package/dist/sources/file.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { c as sourcePathError, i as normalizeSourcePath, o as sourceError, r as normalizeSafeSourcePath } from "../path-B5QNI5sY.js";
|
|
2
|
-
import { lookup } from "mrmime";
|
|
3
|
-
//#region src/sources/file.ts
|
|
4
|
-
function normalizeFileSourceOptions(input) {
|
|
5
|
-
return typeof input === "string" ? { path: input } : input;
|
|
6
|
-
}
|
|
7
|
-
function sourceKey(options) {
|
|
8
|
-
if (options.workspacePath) return normalizeSourcePath(options.workspacePath);
|
|
9
|
-
if ("path" in options && options.path) return normalizeSourcePath(normalizeSafeSourcePath(options.path));
|
|
10
|
-
throw new TypeError("[vitehub] file requires a path or workspacePath.");
|
|
11
|
-
}
|
|
12
|
-
function resolveSourceRoot(ctx) {
|
|
13
|
-
return ctx.sourceRootDir || ctx.rootDir;
|
|
14
|
-
}
|
|
15
|
-
async function readSourceFile(options, ctx) {
|
|
16
|
-
if (!("path" in options) || !options.path) throw new TypeError("[vitehub] file requires path when content is not provided.");
|
|
17
|
-
const { readFile } = await import("node:fs/promises");
|
|
18
|
-
return new Uint8Array(await readFile(await resolveSafeSourceFilePath(options.path, ctx)));
|
|
19
|
-
}
|
|
20
|
-
async function resolveSafeSourceFilePath(path, ctx) {
|
|
21
|
-
const { realpath } = await import("node:fs/promises");
|
|
22
|
-
const { relative, resolve, sep } = await import("node:path");
|
|
23
|
-
const root = await realpath(resolve(resolveSourceRoot(ctx)));
|
|
24
|
-
const target = await realpath(resolve(root, normalizeSafeSourcePath(path)));
|
|
25
|
-
const rel = relative(root, target);
|
|
26
|
-
if (rel === ".." || rel.startsWith(`..${sep}`)) throw sourcePathError(path);
|
|
27
|
-
return target;
|
|
28
|
-
}
|
|
29
|
-
function file(input) {
|
|
30
|
-
const options = normalizeFileSourceOptions(input);
|
|
31
|
-
const key = sourceKey(options);
|
|
32
|
-
const mediaType = options.mediaType || lookup(key);
|
|
33
|
-
return {
|
|
34
|
-
name: "file",
|
|
35
|
-
async getKeys() {
|
|
36
|
-
return [key];
|
|
37
|
-
},
|
|
38
|
-
async getMeta(requestedKey, ctx) {
|
|
39
|
-
if (requestedKey !== key) return;
|
|
40
|
-
if (!("path" in options) || !options.path) return;
|
|
41
|
-
const { stat } = await import("node:fs/promises");
|
|
42
|
-
const info = await stat(await resolveSafeSourceFilePath(options.path, ctx));
|
|
43
|
-
return { digest: `${info.size}:${info.mtimeMs}` };
|
|
44
|
-
},
|
|
45
|
-
async getItem(requestedKey, ctx) {
|
|
46
|
-
if (requestedKey !== key) throw sourceError(`[vitehub] file could not find ${JSON.stringify(requestedKey)}.`);
|
|
47
|
-
return {
|
|
48
|
-
key,
|
|
49
|
-
path: key,
|
|
50
|
-
content: typeof options.content === "undefined" ? await readSourceFile(options, ctx) : options.content,
|
|
51
|
-
mediaType
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
//#endregion
|
|
57
|
-
export { file };
|
package/dist/sources/github.d.ts
DELETED
package/dist/sources/github.js
DELETED
package/dist/sources/glob.d.ts
DELETED
package/dist/sources/glob.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { i as normalizeSourcePath, n as matchesAny, o as sourceError, r as normalizeSafeSourcePath } from "../path-B5QNI5sY.js";
|
|
2
|
-
import { glob as glob$1 } from "tinyglobby";
|
|
3
|
-
//#region src/sources/glob.ts
|
|
4
|
-
function glob(options) {
|
|
5
|
-
let snapshot;
|
|
6
|
-
let latest;
|
|
7
|
-
async function getContextKey(ctx) {
|
|
8
|
-
return resolveCwd(resolveSourceRoot(ctx), options.cwd);
|
|
9
|
-
}
|
|
10
|
-
async function loadKeys(ctx) {
|
|
11
|
-
const cwd = await resolveCwd(resolveSourceRoot(ctx), options.cwd);
|
|
12
|
-
const ignore = normalizePatterns(options.ignore);
|
|
13
|
-
return (await glob$1(options.include, {
|
|
14
|
-
cwd,
|
|
15
|
-
dot: options.dot ?? false,
|
|
16
|
-
followSymbolicLinks: options.followSymlinks ?? false,
|
|
17
|
-
ignore: [
|
|
18
|
-
"**/.git/**",
|
|
19
|
-
"**/node_modules/**",
|
|
20
|
-
...ignore
|
|
21
|
-
],
|
|
22
|
-
onlyFiles: true
|
|
23
|
-
})).map((file) => normalizeSourcePath(file)).filter((file) => matchesAny(file, options.include) && !matchesAny(file, ignore)).sort((left, right) => left.localeCompare(right));
|
|
24
|
-
}
|
|
25
|
-
async function refreshKeys(ctx) {
|
|
26
|
-
const key = await getContextKey(ctx);
|
|
27
|
-
const keys = await loadKeys(ctx);
|
|
28
|
-
latest = {
|
|
29
|
-
key,
|
|
30
|
-
keys
|
|
31
|
-
};
|
|
32
|
-
return keys;
|
|
33
|
-
}
|
|
34
|
-
async function getCachedKeys(ctx) {
|
|
35
|
-
if (options.keyCache === false) return await refreshKeys(ctx);
|
|
36
|
-
const key = await getContextKey(ctx);
|
|
37
|
-
if (!snapshot || snapshot.key !== key) {
|
|
38
|
-
const keys = refreshKeys(ctx);
|
|
39
|
-
const entry = {
|
|
40
|
-
key,
|
|
41
|
-
keys
|
|
42
|
-
};
|
|
43
|
-
snapshot = entry;
|
|
44
|
-
keys.catch(() => {
|
|
45
|
-
if (snapshot === entry) snapshot = void 0;
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
return await snapshot.keys;
|
|
49
|
-
}
|
|
50
|
-
async function getKnownKeys(ctx) {
|
|
51
|
-
const key = await getContextKey(ctx);
|
|
52
|
-
if (latest?.key === key) return latest.keys;
|
|
53
|
-
return await getCachedKeys(ctx);
|
|
54
|
-
}
|
|
55
|
-
async function assertKey(key, ctx) {
|
|
56
|
-
if ((await getKnownKeys(ctx)).includes(key)) return;
|
|
57
|
-
if (options.keyCache !== false) throw sourceError(`[vitehub] glob could not find ${JSON.stringify(key)}.`);
|
|
58
|
-
if ((await refreshKeys(ctx)).includes(key)) return;
|
|
59
|
-
throw sourceError(`[vitehub] glob could not find ${JSON.stringify(key)}.`);
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
name: "glob",
|
|
63
|
-
async prepare(ctx) {
|
|
64
|
-
snapshot = void 0;
|
|
65
|
-
await getCachedKeys(ctx);
|
|
66
|
-
},
|
|
67
|
-
getKeys(ctx) {
|
|
68
|
-
return getCachedKeys(ctx);
|
|
69
|
-
},
|
|
70
|
-
async getMeta(key, ctx) {
|
|
71
|
-
await assertKey(key, ctx);
|
|
72
|
-
const { stat } = await import("node:fs/promises");
|
|
73
|
-
const { resolve } = await import("node:path");
|
|
74
|
-
const info = await stat(resolve(await resolveCwd(resolveSourceRoot(ctx), options.cwd), key));
|
|
75
|
-
return { digest: `${info.size}:${info.mtimeMs}` };
|
|
76
|
-
},
|
|
77
|
-
async getItem(key, ctx) {
|
|
78
|
-
await assertKey(key, ctx);
|
|
79
|
-
const { readFile, stat } = await import("node:fs/promises");
|
|
80
|
-
const { resolve } = await import("node:path");
|
|
81
|
-
const cwd = await resolveCwd(resolveSourceRoot(ctx), options.cwd);
|
|
82
|
-
const prefix = normalizeSafeSourcePath(options.prefix || "", { allowEmpty: true });
|
|
83
|
-
const bytes = await readFile(resolve(cwd, key));
|
|
84
|
-
const info = await stat(resolve(cwd, key));
|
|
85
|
-
return {
|
|
86
|
-
key,
|
|
87
|
-
path: normalizeSourcePath(prefix ? `${prefix}/${key}` : key),
|
|
88
|
-
content: new Uint8Array(bytes),
|
|
89
|
-
metadata: { mtime: info.mtimeMs }
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
function normalizePatterns(patterns) {
|
|
95
|
-
return Array.isArray(patterns) ? patterns : patterns ? [patterns] : [];
|
|
96
|
-
}
|
|
97
|
-
function resolveSourceRoot(ctx) {
|
|
98
|
-
return ctx.sourceRootDir || ctx.rootDir;
|
|
99
|
-
}
|
|
100
|
-
async function resolveCwd(rootDir, cwd = ".") {
|
|
101
|
-
const { realpath } = await import("node:fs/promises");
|
|
102
|
-
const { isAbsolute, relative, resolve } = await import("node:path");
|
|
103
|
-
const resolvedRoot = await realpath(resolve(rootDir));
|
|
104
|
-
const resolvedCwd = await realpath(isAbsolute(cwd) ? resolve(cwd) : resolve(resolvedRoot, cwd));
|
|
105
|
-
const rel = relative(resolvedRoot, resolvedCwd);
|
|
106
|
-
if (rel && (rel.startsWith("..") || isAbsolute(rel))) throw sourceError(`[vitehub] glob cwd escapes the source root: ${JSON.stringify(cwd)}.`);
|
|
107
|
-
return resolvedCwd;
|
|
108
|
-
}
|
|
109
|
-
//#endregion
|
|
110
|
-
export { glob };
|
package/dist/sources/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { t as custom } from "../custom-EnZvMLiy.js";
|
|
2
|
-
import { i as file, n as FileSourceOptions } from "../file-slFAccIZ.js";
|
|
3
|
-
import { n as GitHubSourceOptions, t as github } from "../index-CJpN2j6c.js";
|
|
4
|
-
import { n as glob, t as GlobSourceOptions } from "../glob-CuxZwoC3.js";
|
|
5
|
-
import { t as markdown } from "../markdown-Beo-0cqc.js";
|
|
6
|
-
import { a as McpResourcesRequestOptions, i as McpResourcesClientConfig, l as mcpResources, n as McpResourceDescriptor, o as McpResourcesServer, r as McpResourcesClient, s as McpResourcesSourceOptions, t as McpResourceContent } from "../mcp-resources-C7-5Qeh4.js";
|
|
7
|
-
|
|
8
|
-
//#region src/sources/index.d.ts
|
|
9
|
-
declare namespace index_d_exports {
|
|
10
|
-
export { FileSourceOptions, GitHubSourceOptions, GlobSourceOptions, McpResourceContent, McpResourceDescriptor, McpResourcesClient, McpResourcesClientConfig, McpResourcesRequestOptions, McpResourcesServer, McpResourcesSourceOptions, custom, file, github, glob, markdown, mcpResources };
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
export { type FileSourceOptions, type GitHubSourceOptions, type GlobSourceOptions, type McpResourceContent, type McpResourceDescriptor, type McpResourcesClient, type McpResourcesClientConfig, type McpResourcesRequestOptions, type McpResourcesServer, type McpResourcesSourceOptions, custom, file, github, glob, markdown, mcpResources, index_d_exports as t };
|
package/dist/sources/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "../chunk-D7D4PA-g.js";
|
|
2
|
-
import { custom } from "./custom.js";
|
|
3
|
-
import { file } from "./file.js";
|
|
4
|
-
import { t as github } from "../github-B4lgrzXQ.js";
|
|
5
|
-
import { glob } from "./glob.js";
|
|
6
|
-
import { markdown } from "./markdown.js";
|
|
7
|
-
import { t as mcpResources } from "../mcp-resources-DSDqTfbK.js";
|
|
8
|
-
//#region src/sources/index.ts
|
|
9
|
-
var sources_exports = /* @__PURE__ */ __exportAll({
|
|
10
|
-
custom: () => custom,
|
|
11
|
-
file: () => file,
|
|
12
|
-
github: () => github,
|
|
13
|
-
glob: () => glob,
|
|
14
|
-
markdown: () => markdown,
|
|
15
|
-
mcpResources: () => mcpResources
|
|
16
|
-
});
|
|
17
|
-
//#endregion
|
|
18
|
-
export { custom, file, github, glob, markdown, mcpResources, sources_exports as t };
|
package/dist/sources/markdown.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { a as McpResourcesRequestOptions, c as McpResourcesTransportConfig, i as McpResourcesClientConfig, l as mcpResources, n as McpResourceDescriptor, o as McpResourcesServer, r as McpResourcesClient, s as McpResourcesSourceOptions, t as McpResourceContent } from "../mcp-resources-C7-5Qeh4.js";
|
|
2
|
-
export { McpResourceContent, McpResourceDescriptor, McpResourcesClient, McpResourcesClientConfig, McpResourcesRequestOptions, McpResourcesServer, McpResourcesSourceOptions, McpResourcesTransportConfig, mcpResources };
|