@vite-hub/source 0.0.2 → 0.0.4

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.
Files changed (62) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +167 -1
  3. package/dist/auth-Ddw55OUG.js +1261 -0
  4. package/dist/client-CDfTmtQu.js +7903 -0
  5. package/dist/client.d.ts +32 -0
  6. package/dist/client.js +121 -0
  7. package/dist/collection-B8pXGM2d.js +141 -0
  8. package/dist/collection-CF2ON__k.d.ts +92 -0
  9. package/dist/collection-route-Dw7QLFyx.js +6 -0
  10. package/dist/content/client.d.ts +3 -0
  11. package/dist/content/client.js +2 -0
  12. package/dist/content.d.ts +44 -0
  13. package/dist/content.js +157 -0
  14. package/dist/file-BSWQg9Qv.js +503 -0
  15. package/dist/{file-slFAccIZ.d.ts → file-EQ3AjVM6.d.ts} +1 -1
  16. package/dist/file.d.ts +2 -0
  17. package/dist/file.js +2 -0
  18. package/dist/{index-CJpN2j6c.d.ts → github.d.ts} +4 -4
  19. package/dist/github.js +1033 -0
  20. package/dist/glob.d.ts +15 -0
  21. package/dist/glob.js +895 -0
  22. package/dist/index.d.ts +69 -10
  23. package/dist/index.js +70 -108
  24. package/dist/{markdown-Beo-0cqc.d.ts → markdown.d.ts} +3 -3
  25. package/dist/{sources/markdown.js → markdown.js} +1 -1
  26. package/dist/mcp.d.ts +152 -0
  27. package/dist/mcp.js +6115 -0
  28. package/dist/{path-B5QNI5sY.js → path-BzmU4Eni.js} +2 -10
  29. package/dist/path-CUhvUREm.js +1936 -0
  30. package/dist/registry-C8skfCSV.js +120 -0
  31. package/dist/server.d.ts +15 -0
  32. package/dist/server.js +71 -0
  33. package/dist/sse-CE9Q2JqM.js +407 -0
  34. package/dist/streamableHttp-BszaXLmg.js +491 -0
  35. package/dist/types-AIBmt_m6.js +6275 -0
  36. package/dist/types-Bu3WvNX9.d.ts +71 -0
  37. package/dist/vite.d.ts +41 -0
  38. package/dist/vite.js +629 -0
  39. package/package.json +68 -30
  40. package/tsconfig.vite.json +6 -0
  41. package/types/source/fallback.d.ts +1 -0
  42. package/types/source/index.d.ts +1 -0
  43. package/dist/chunk-D7D4PA-g.js +0 -13
  44. package/dist/custom-EnZvMLiy.d.ts +0 -6
  45. package/dist/github-B4lgrzXQ.js +0 -565
  46. package/dist/glob-CuxZwoC3.d.ts +0 -15
  47. package/dist/mcp-resources-C7-5Qeh4.d.ts +0 -41
  48. package/dist/mcp-resources-DSDqTfbK.js +0 -307
  49. package/dist/sources/custom.d.ts +0 -2
  50. package/dist/sources/custom.js +0 -6
  51. package/dist/sources/file.d.ts +0 -2
  52. package/dist/sources/file.js +0 -57
  53. package/dist/sources/github.d.ts +0 -2
  54. package/dist/sources/github.js +0 -2
  55. package/dist/sources/glob.d.ts +0 -2
  56. package/dist/sources/glob.js +0 -110
  57. package/dist/sources/index.d.ts +0 -13
  58. package/dist/sources/index.js +0 -18
  59. package/dist/sources/markdown.d.ts +0 -2
  60. package/dist/sources/mcp-resources.d.ts +0 -2
  61. package/dist/sources/mcp-resources.js +0 -2
  62. package/dist/types-f6Lyjq8g.d.ts +0 -73
@@ -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 };
@@ -1,2 +0,0 @@
1
- import { t as custom } from "../custom-EnZvMLiy.js";
2
- export { custom };
@@ -1,6 +0,0 @@
1
- //#region src/sources/custom.ts
2
- function custom(source) {
3
- return source;
4
- }
5
- //#endregion
6
- export { custom };
@@ -1,2 +0,0 @@
1
- import { i as file, n as FileSourceOptions, r as FileSourcePathOptions, t as FileSourceInlineOptions } from "../file-slFAccIZ.js";
2
- export { FileSourceInlineOptions, FileSourceOptions, FileSourcePathOptions, file };
@@ -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 };
@@ -1,2 +0,0 @@
1
- import { n as GitHubSourceOptions, t as github } from "../index-CJpN2j6c.js";
2
- export { type GitHubSourceOptions, github };
@@ -1,2 +0,0 @@
1
- import { t as github } from "../github-B4lgrzXQ.js";
2
- export { github };
@@ -1,2 +0,0 @@
1
- import { n as glob, t as GlobSourceOptions } from "../glob-CuxZwoC3.js";
2
- export { GlobSourceOptions, glob };
@@ -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 };
@@ -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 };
@@ -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 };
@@ -1,2 +0,0 @@
1
- import { t as markdown } from "../markdown-Beo-0cqc.js";
2
- export { markdown };
@@ -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 };
@@ -1,2 +0,0 @@
1
- import { t as mcpResources } from "../mcp-resources-DSDqTfbK.js";
2
- export { mcpResources };
@@ -1,73 +0,0 @@
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
- rootDir: string;
12
- sourceRootDir?: string;
13
- source?: string;
14
- workspace?: string;
15
- }
16
- interface SourceCacheOptions {
17
- maxAge?: number;
18
- }
19
- interface SourceSearchQuery {
20
- pattern: string;
21
- cwd?: string;
22
- paths?: string[];
23
- regex?: boolean;
24
- caseSensitive?: boolean;
25
- limit?: number;
26
- }
27
- interface SourceSearchHit {
28
- path: string;
29
- line: number;
30
- column: number;
31
- text: string;
32
- }
33
- interface SourceItem<TKey extends string = string> {
34
- key: TKey;
35
- path?: string;
36
- content?: SourceContent;
37
- data?: unknown;
38
- mediaType?: string;
39
- metadata?: Record<string, unknown>;
40
- }
41
- interface Source<TKey extends string = string> {
42
- name: string;
43
- cache?: false | SourceCacheOptions;
44
- fingerprint?: unknown;
45
- prepare?(ctx: SourceContext): Promise<void>;
46
- getKeys(ctx: SourceContext): Promise<TKey[]>;
47
- getItem(key: TKey, ctx: SourceContext): Promise<SourceItem<TKey>>;
48
- getItems?(ctx: SourceContext): Promise<SourceItem<TKey>[]>;
49
- getMeta?(key: TKey, ctx: SourceContext): Promise<Record<string, unknown> | undefined>;
50
- search?(query: SourceSearchQuery, ctx: SourceContext): Promise<SourceSearchHit[]>;
51
- watch?: unknown[];
52
- }
53
- interface SourceListEntry<TKey extends string = string> {
54
- key: TKey;
55
- type: "file" | "directory";
56
- }
57
- declare global {
58
- interface ViteHubSourceMap {}
59
- }
60
- interface SourceMap extends ViteHubSourceMap {}
61
- type SourceKeyOf<TSource> = TSource extends Source<infer TKey> ? TKey : string;
62
- type SourceName = [keyof ViteHubSourceMap] extends [never] ? string : Extract<keyof ViteHubSourceMap, string>;
63
- type SourceKey<TName extends SourceName = SourceName> = TName extends keyof ViteHubSourceMap ? Extract<SourceKeyOf<ViteHubSourceMap[TName]>, string> : string;
64
- interface SourceReader<TName extends SourceName = SourceName> {
65
- keys(): Promise<SourceKey<TName>[]>;
66
- get(key: SourceKey<TName>): Promise<SourceItem<SourceKey<TName>>>;
67
- read<TOptions extends ReadSourceOptions | undefined = undefined>(key: SourceKey<TName>, options?: TOptions): Promise<ReadSourceResult<TOptions>>;
68
- meta(key: SourceKey<TName>): Promise<Record<string, unknown> | undefined>;
69
- exists(key: SourceKey<TName>): Promise<boolean>;
70
- list(prefix?: SourceKey<TName> | (string & {}) | ""): Promise<SourceListEntry<SourceKey<TName>>[]>;
71
- }
72
- //#endregion
73
- export { SourceContent as a, SourceKey as c, SourceName as d, SourceReader as f, SourceCacheOptions as i, SourceListEntry as l, SourceSearchQuery as m, ReadSourceResult as n, SourceContext as o, SourceSearchHit as p, Source as r, SourceItem as s, ReadSourceOptions as t, SourceMap as u };