@vite-hub/source 0.0.1 → 0.0.2

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.
@@ -0,0 +1,41 @@
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 };
@@ -0,0 +1,307 @@
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,24 +1,21 @@
1
+ import { ViteHubError, getViteHubErrorShape } from "@vite-hub/runtime";
1
2
  import picomatch from "picomatch";
2
3
  import { isAbsolute } from "pathe";
3
4
  //#region src/core/errors.ts
4
- var SourceError = class extends Error {
5
- constructor(message, options) {
6
- super(message, options);
7
- this.name = "SourceError";
8
- }
9
- };
10
- var SourceNotFoundError = class extends SourceError {
11
- constructor(name) {
12
- super(`[vitehub] Source "${name}" is not registered.`);
13
- this.name = "SourceNotFoundError";
14
- }
15
- };
16
- var SourcePathError = class extends SourceError {
17
- constructor(path) {
18
- super(`[vitehub] Source path escapes the source root: ${JSON.stringify(path)}.`);
19
- this.name = "SourcePathError";
20
- }
21
- };
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
+ }
22
19
  //#endregion
23
20
  //#region src/core/path.ts
24
21
  function normalizeSourcePath(path = "") {
@@ -28,9 +25,9 @@ function normalizeSafeSourcePath(path = "", options = {}) {
28
25
  const raw = path.replace(/\\/g, "/");
29
26
  const normalized = normalizeSourcePath(path);
30
27
  const parts = normalized.split("/").filter(Boolean);
31
- if (!options.allowEmpty && !normalized) throw new SourcePathError(path);
32
- if (isAbsolute(raw) || parts.some((part) => part === "." || part === "..")) throw new SourcePathError(path);
33
- if (!options.allowReserved && (parts[0] === ".git" || parts[0] === ".vitehub")) throw new SourcePathError(path);
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);
34
31
  return normalized;
35
32
  }
36
33
  function matchesAny(path, patterns) {
@@ -44,4 +41,4 @@ function decodeSourceContent(content, options) {
44
41
  return typeof content === "string" ? content : new TextDecoder().decode(content);
45
42
  }
46
43
  //#endregion
47
- export { SourceError as a, normalizeSourcePath as i, matchesAny as n, SourceNotFoundError as o, normalizeSafeSourcePath as r, SourcePathError as s, decodeSourceContent as t };
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 };
@@ -1,2 +1,2 @@
1
- import { t as custom } from "../custom-CMmjCoru.js";
1
+ import { t as custom } from "../custom-EnZvMLiy.js";
2
2
  export { custom };
@@ -1,2 +1,2 @@
1
- import { i as file, n as FileSourceOptions, r as FileSourcePathOptions, t as FileSourceInlineOptions } from "../file-D8j_HGST.js";
1
+ import { i as file, n as FileSourceOptions, r as FileSourcePathOptions, t as FileSourceInlineOptions } from "../file-slFAccIZ.js";
2
2
  export { FileSourceInlineOptions, FileSourceOptions, FileSourcePathOptions, file };
@@ -1,25 +1,30 @@
1
- import { a as SourceError, i as normalizeSourcePath, r as normalizeSafeSourcePath } from "../path-C0L1l0Fw.js";
1
+ import { c as sourcePathError, i as normalizeSourcePath, o as sourceError, r as normalizeSafeSourcePath } from "../path-B5QNI5sY.js";
2
2
  import { lookup } from "mrmime";
3
3
  //#region src/sources/file.ts
4
- function basename(path) {
5
- return path.replace(/\\/g, "/").split("/").filter(Boolean).pop() || path;
6
- }
7
4
  function normalizeFileSourceOptions(input) {
8
5
  return typeof input === "string" ? { path: input } : input;
9
6
  }
10
7
  function sourceKey(options) {
11
8
  if (options.workspacePath) return normalizeSourcePath(options.workspacePath);
12
- if ("path" in options && options.path) return normalizeSourcePath(basename(normalizeSafeSourcePath(options.path)));
13
- throw new TypeError("[vitehub] source.file requires a path or workspacePath.");
9
+ if ("path" in options && options.path) return normalizeSourcePath(normalizeSafeSourcePath(options.path));
10
+ throw new TypeError("[vitehub] file requires a path or workspacePath.");
14
11
  }
15
12
  function resolveSourceRoot(ctx) {
16
13
  return ctx.sourceRootDir || ctx.rootDir;
17
14
  }
18
15
  async function readSourceFile(options, ctx) {
19
- if (!("path" in options) || !options.path) throw new TypeError("[vitehub] source.file requires path when content is not provided.");
16
+ if (!("path" in options) || !options.path) throw new TypeError("[vitehub] file requires path when content is not provided.");
20
17
  const { readFile } = await import("node:fs/promises");
21
- const { resolve } = await import("node:path");
22
- return new Uint8Array(await readFile(resolve(resolveSourceRoot(ctx), normalizeSafeSourcePath(options.path))));
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;
23
28
  }
24
29
  function file(input) {
25
30
  const options = normalizeFileSourceOptions(input);
@@ -34,12 +39,11 @@ function file(input) {
34
39
  if (requestedKey !== key) return;
35
40
  if (!("path" in options) || !options.path) return;
36
41
  const { stat } = await import("node:fs/promises");
37
- const { resolve } = await import("node:path");
38
- const info = await stat(resolve(resolveSourceRoot(ctx), normalizeSafeSourcePath(options.path)));
42
+ const info = await stat(await resolveSafeSourceFilePath(options.path, ctx));
39
43
  return { digest: `${info.size}:${info.mtimeMs}` };
40
44
  },
41
45
  async getItem(requestedKey, ctx) {
42
- if (requestedKey !== key) throw new SourceError(`[vitehub] source.file could not find ${JSON.stringify(requestedKey)}.`);
46
+ if (requestedKey !== key) throw sourceError(`[vitehub] file could not find ${JSON.stringify(requestedKey)}.`);
43
47
  return {
44
48
  key,
45
49
  path: key,
@@ -1,2 +1,2 @@
1
- import { n as GitHubSourceOptions, t as github } from "../index-ChHHP4I8.js";
1
+ import { n as GitHubSourceOptions, t as github } from "../index-CJpN2j6c.js";
2
2
  export { type GitHubSourceOptions, github };
@@ -1,2 +1,2 @@
1
- import { t as github } from "../github-Dp-ghUUj.js";
1
+ import { t as github } from "../github-B4lgrzXQ.js";
2
2
  export { github };
@@ -1,2 +1,2 @@
1
- import { n as glob, t as GlobSourceOptions } from "../glob-B_tSBNmd.js";
1
+ import { n as glob, t as GlobSourceOptions } from "../glob-CuxZwoC3.js";
2
2
  export { GlobSourceOptions, glob };
@@ -1,4 +1,4 @@
1
- import { a as SourceError, i as normalizeSourcePath, n as matchesAny, r as normalizeSafeSourcePath } from "../path-C0L1l0Fw.js";
1
+ import { i as normalizeSourcePath, n as matchesAny, o as sourceError, r as normalizeSafeSourcePath } from "../path-B5QNI5sY.js";
2
2
  import { glob as glob$1 } from "tinyglobby";
3
3
  //#region src/sources/glob.ts
4
4
  function glob(options) {
@@ -34,10 +34,17 @@ function glob(options) {
34
34
  async function getCachedKeys(ctx) {
35
35
  if (options.keyCache === false) return await refreshKeys(ctx);
36
36
  const key = await getContextKey(ctx);
37
- if (!snapshot || snapshot.key !== key) snapshot = {
38
- key,
39
- keys: refreshKeys(ctx)
40
- };
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
+ }
41
48
  return await snapshot.keys;
42
49
  }
43
50
  async function getKnownKeys(ctx) {
@@ -47,9 +54,9 @@ function glob(options) {
47
54
  }
48
55
  async function assertKey(key, ctx) {
49
56
  if ((await getKnownKeys(ctx)).includes(key)) return;
50
- if (options.keyCache !== false) throw new SourceError(`[vitehub] source.glob could not find ${JSON.stringify(key)}.`);
57
+ if (options.keyCache !== false) throw sourceError(`[vitehub] glob could not find ${JSON.stringify(key)}.`);
51
58
  if ((await refreshKeys(ctx)).includes(key)) return;
52
- throw new SourceError(`[vitehub] source.glob could not find ${JSON.stringify(key)}.`);
59
+ throw sourceError(`[vitehub] glob could not find ${JSON.stringify(key)}.`);
53
60
  }
54
61
  return {
55
62
  name: "glob",
@@ -96,7 +103,7 @@ async function resolveCwd(rootDir, cwd = ".") {
96
103
  const resolvedRoot = await realpath(resolve(rootDir));
97
104
  const resolvedCwd = await realpath(isAbsolute(cwd) ? resolve(cwd) : resolve(resolvedRoot, cwd));
98
105
  const rel = relative(resolvedRoot, resolvedCwd);
99
- if (rel && (rel.startsWith("..") || isAbsolute(rel))) throw new SourceError(`[vitehub] source.glob cwd escapes the source root: ${JSON.stringify(cwd)}.`);
106
+ if (rel && (rel.startsWith("..") || isAbsolute(rel))) throw sourceError(`[vitehub] glob cwd escapes the source root: ${JSON.stringify(cwd)}.`);
100
107
  return resolvedCwd;
101
108
  }
102
109
  //#endregion
@@ -1,12 +1,13 @@
1
- import { t as custom } from "../custom-CMmjCoru.js";
2
- import { i as file, n as FileSourceOptions } from "../file-D8j_HGST.js";
3
- import { n as GitHubSourceOptions, t as github } from "../index-ChHHP4I8.js";
4
- import { n as glob, t as GlobSourceOptions } from "../glob-B_tSBNmd.js";
5
- import { t as markdown } from "../markdown-IpYjHOyM.js";
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";
6
7
 
7
8
  //#region src/sources/index.d.ts
8
9
  declare namespace index_d_exports {
9
- export { FileSourceOptions, GitHubSourceOptions, GlobSourceOptions, custom, file, github, glob, markdown };
10
+ export { FileSourceOptions, GitHubSourceOptions, GlobSourceOptions, McpResourceContent, McpResourceDescriptor, McpResourcesClient, McpResourcesClientConfig, McpResourcesRequestOptions, McpResourcesServer, McpResourcesSourceOptions, custom, file, github, glob, markdown, mcpResources };
10
11
  }
11
12
  //#endregion
12
- export { type FileSourceOptions, type GitHubSourceOptions, type GlobSourceOptions, custom, file, github, glob, markdown, index_d_exports as t };
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,16 +1,18 @@
1
- import { t as __exportAll } from "../chunk-pbuEa-1d.js";
1
+ import { t as __exportAll } from "../chunk-D7D4PA-g.js";
2
2
  import { custom } from "./custom.js";
3
3
  import { file } from "./file.js";
4
- import { t as github } from "../github-Dp-ghUUj.js";
4
+ import { t as github } from "../github-B4lgrzXQ.js";
5
5
  import { glob } from "./glob.js";
6
6
  import { markdown } from "./markdown.js";
7
+ import { t as mcpResources } from "../mcp-resources-DSDqTfbK.js";
7
8
  //#region src/sources/index.ts
8
9
  var sources_exports = /* @__PURE__ */ __exportAll({
9
10
  custom: () => custom,
10
11
  file: () => file,
11
12
  github: () => github,
12
13
  glob: () => glob,
13
- markdown: () => markdown
14
+ markdown: () => markdown,
15
+ mcpResources: () => mcpResources
14
16
  });
15
17
  //#endregion
16
- export { custom, file, github, glob, markdown, sources_exports as t };
18
+ export { custom, file, github, glob, markdown, mcpResources, sources_exports as t };
@@ -1,2 +1,2 @@
1
- import { t as markdown } from "../markdown-IpYjHOyM.js";
1
+ import { t as markdown } from "../markdown-Beo-0cqc.js";
2
2
  export { markdown };
@@ -0,0 +1,2 @@
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 };
@@ -0,0 +1,2 @@
1
+ import { t as mcpResources } from "../mcp-resources-DSDqTfbK.js";
2
+ export { mcpResources };
@@ -7,6 +7,7 @@ type ReadSourceResult<TOptions extends ReadSourceOptions | undefined = undefined
7
7
  encoding: "binary";
8
8
  } ? Uint8Array : string;
9
9
  interface SourceContext {
10
+ abortSignal?: AbortSignal;
10
11
  rootDir: string;
11
12
  sourceRootDir?: string;
12
13
  source?: string;