@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
package/dist/index.d.ts CHANGED
@@ -1,25 +1,84 @@
1
- import { a as SourceContent, c as SourceKey, d as SourceName, f as SourceReader, i as SourceCacheOptions, l as SourceListEntry, m as SourceSearchQuery, n as ReadSourceResult, o as SourceContext, p as SourceSearchHit, r as Source, s as SourceItem, t as ReadSourceOptions, u as SourceMap } from "./types-f6Lyjq8g.js";
2
- import { t as custom } from "./custom-EnZvMLiy.js";
3
- import { i as file, n as FileSourceOptions } from "./file-slFAccIZ.js";
4
- import { n as GitHubSourceOptions, t as github } from "./index-CJpN2j6c.js";
5
- import { n as glob, t as GlobSourceOptions } from "./glob-CuxZwoC3.js";
6
- import { t as markdown } from "./markdown-Beo-0cqc.js";
7
- 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";
8
- import { t as index_d_exports } from "./sources/index.js";
1
+ import { a as CollectionCursorValue, c as CollectionLoader, d as CollectionPageOptions, f as CollectionQuery, h as defineCollection, i as CollectionCursorError, l as CollectionOptions, m as CollectionRequestQuery, n as Collection, o as CollectionItem, p as CollectionQueryInput, r as CollectionClientItem, s as CollectionLoadOptions, t as AnyCollection, u as CollectionPage } from "./collection-CF2ON__k.js";
2
+ import { a as SourceContent, c as SourceItem, d as SourceMap, f as SourceMetadata, h as SourceRevision, i as SourceCacheOptions, l as SourceKey, m as SourceReader, n as ReadSourceResult, o as SourceContext, p as SourceName, r as Source, s as SourceData, t as ReadSourceOptions, u as SourceListEntry } from "./types-Bu3WvNX9.js";
9
3
  import { ViteHubError } from "@vite-hub/runtime";
10
4
 
5
+ //#region src/core/combine-sources.d.ts
6
+ interface CombinedSourceReader {
7
+ get(key: never): Promise<unknown>;
8
+ items?(): Promise<Array<{
9
+ key: string;
10
+ }>>;
11
+ }
12
+ type CombinedSources = Record<string, CombinedSourceReader>;
13
+ type CombinedSourceKeyFunction<TReader> = TReader extends {
14
+ get(key: infer TKey): Promise<unknown>;
15
+ } ? (key: TKey) => void : never;
16
+ type CombinedSourceKey<TReader> = CombinedSourceKeyFunction<TReader> extends ((key: infer TKey) => void) ? Extract<TKey, string> : never;
17
+ type CombinedSourceValue<TReader> = TReader extends {
18
+ get(key: never): Promise<infer TValue>;
19
+ } ? TValue : never;
20
+ type CombinedSourceItem<TReader> = TReader extends {
21
+ items(): Promise<Array<infer TItem extends {
22
+ key: string;
23
+ }>>;
24
+ } ? TItem : never;
25
+ type Equal<TLeft, TRight> = (<T>(_value?: T) => T extends TLeft ? 1 : 2) extends (<T>(_value?: T) => T extends TRight ? 1 : 2) ? (<T>(_value?: T) => T extends TRight ? 1 : 2) extends (<T>(_value?: T) => T extends TLeft ? 1 : 2) ? true : false : false;
26
+ type ValidCombinedGet<TReader> = TReader extends unknown ? TReader extends {
27
+ get: infer TGet;
28
+ } ? Equal<TGet, (key: CombinedSourceKey<TReader>) => Promise<CombinedSourceValue<TReader>>> extends true ? TReader : never : never : never;
29
+ type ValidCombinedSource<TReader> = [CombinedSourceItem<TReader>] extends [never] ? ValidCombinedGet<TReader> : Exclude<CombinedSourceItem<TReader>["key"], CombinedSourceKey<TReader>> extends never ? ValidCombinedGet<TReader> : never;
30
+ type ValidCombinedSources<TSources extends CombinedSources> = { [TSource in keyof TSources]: ValidCombinedSource<TSources[TSource]> };
31
+ type TaggedCombinedItemVariant<TSource extends string, TItem> = TItem extends {
32
+ key: string;
33
+ } ? Omit<TItem, "identity" | "source"> & {
34
+ identity: readonly [TSource, TItem["key"]];
35
+ source: TSource;
36
+ } : never;
37
+ type TaggedCombinedItem<TSource extends string, TReader> = TaggedCombinedItemVariant<TSource, CombinedSourceItem<TReader>>;
38
+ type CombinedItem<TSources extends CombinedSources> = { [TSource in Extract<keyof TSources, string>]: TaggedCombinedItem<TSource, TSources[TSource]> }[Extract<keyof TSources, string>];
39
+ type CombinedIdentity<TSources extends CombinedSources> = { [TSource in Extract<keyof TSources, string>]: readonly [source: TSource, key: CombinedSourceKey<TSources[TSource]>] }[Extract<keyof TSources, string>];
40
+ type CombinedIdentityValue<TSources extends CombinedSources, TIdentity> = TIdentity extends readonly [infer TSource extends Extract<keyof TSources, string>, string] ? CombinedSourceValue<TSources[TSource]> : never;
41
+ interface CombinedSourcesDefinition<TSources extends CombinedSources> {
42
+ readonly sources: TSources & ValidCombinedSources<TSources> & Record<Exclude<keyof TSources, string>, never>;
43
+ }
44
+ interface CombinedSourcesReader<TSources extends CombinedSources> {
45
+ get<const TIdentity extends CombinedIdentity<TSources>>(identity: TIdentity): Promise<CombinedIdentityValue<TSources, TIdentity>>;
46
+ items(): Promise<Array<CombinedItem<TSources>>>;
47
+ }
48
+ declare function combineSources<const TSources extends CombinedSources>(definition: CombinedSourcesDefinition<TSources>): CombinedSourcesReader<TSources>;
49
+ //#endregion
11
50
  //#region src/core/define.d.ts
51
+ interface KeyedSourceReader {
52
+ get(key: never): Promise<unknown>;
53
+ }
54
+ type RuntimeSourceDefinition<TReader extends KeyedSourceReader> = (context: SourceContext) => TReader;
12
55
  declare function defineSource<const TSource extends Source>(source: TSource): TSource;
56
+ declare function defineSource<const TReader extends KeyedSourceReader>(source: TReader): TReader;
57
+ declare function defineSource<const TReader extends KeyedSourceReader>(definition: RuntimeSourceDefinition<TReader>): RuntimeSourceDefinition<TReader>;
13
58
  declare function defineSources<const TSources extends Record<string, Source>>(sources: TSources): TSources;
59
+ declare function createSource<const TReader extends KeyedSourceReader>(definition: RuntimeSourceDefinition<TReader>, context: SourceContext): TReader;
14
60
  //#endregion
15
61
  //#region src/core/registry.d.ts
16
62
  declare function registerSource<const TName extends string, const TSource extends Source>(name: TName, source: TSource): TSource;
17
63
  declare function registerSources<const TSources extends Record<string, Source>>(sources: TSources): TSources;
18
- declare function getRegisteredSource<TName extends SourceName>(name: TName): Source<SourceKey<TName>>;
64
+ declare function getRegisteredSource<TName extends SourceName>(name: TName): Source<SourceKey<TName>, SourceData<TName>, SourceMetadata<TName>>;
19
65
  declare function clearSources(): void;
20
66
  declare function useSource<TName extends SourceName>(name: TName, context?: Partial<SourceContext>): SourceReader<TName>;
21
67
  //#endregion
22
68
  //#region src/core/errors.d.ts
23
69
  type SourceErrorCode = "SOURCE_FAILED" | "SOURCE_NOT_FOUND" | "SOURCE_PATH_INVALID";
24
70
  //#endregion
25
- export { type FileSourceOptions, type GitHubSourceOptions, type GlobSourceOptions, type McpResourceContent, type McpResourceDescriptor, type McpResourcesClient, type McpResourcesClientConfig, type McpResourcesRequestOptions, type McpResourcesServer, type McpResourcesSourceOptions, type ReadSourceOptions, type ReadSourceResult, type Source, type SourceCacheOptions, type SourceContent, type SourceContext, type SourceErrorCode, type SourceItem, type SourceKey, type SourceListEntry, type SourceMap, type SourceName, type SourceReader, type SourceSearchHit, type SourceSearchQuery, clearSources, custom, defineSource, defineSources, file, getRegisteredSource, github, glob, markdown, mcpResources, registerSource, registerSources, index_d_exports as source, useSource };
71
+ //#region src/ignores.d.ts
72
+ declare const sourceIgnores: Readonly<{
73
+ defaults: readonly string[];
74
+ dependencies: readonly string[];
75
+ generated: readonly string[];
76
+ media: readonly string[];
77
+ secrets: readonly string[];
78
+ system: readonly string[];
79
+ }>;
80
+ //#endregion
81
+ //#region src/sources/custom.d.ts
82
+ declare function custom<const TSource extends Source>(source: TSource): TSource;
83
+ //#endregion
84
+ export { type AnyCollection, type Collection, type CollectionClientItem, CollectionCursorError, type CollectionCursorValue, type CollectionItem, type CollectionLoadOptions, type CollectionLoader, type CollectionOptions, type CollectionPage, type CollectionPageOptions, type CollectionQuery, type CollectionQueryInput, type CollectionRequestQuery, type ReadSourceOptions, type ReadSourceResult, type Source, type SourceCacheOptions, type SourceContent, type SourceContext, type SourceData, type SourceErrorCode, type SourceItem, type SourceKey, type SourceListEntry, type SourceMap, type SourceMetadata, type SourceName, type SourceReader, type SourceRevision, clearSources, combineSources, createSource, custom, defineCollection, defineSource, defineSources, getRegisteredSource, registerSource, registerSources, sourceIgnores, useSource };
package/dist/index.js CHANGED
@@ -1,11 +1,30 @@
1
- import { i as normalizeSourcePath, o as sourceError, r as normalizeSafeSourcePath, s as sourceNotFoundError, t as decodeSourceContent } from "./path-B5QNI5sY.js";
2
- import { custom } from "./sources/custom.js";
3
- import { file } from "./sources/file.js";
4
- import { t as github } from "./github-B4lgrzXQ.js";
5
- import { glob } from "./sources/glob.js";
6
- import { markdown } from "./sources/markdown.js";
7
- import { t as mcpResources } from "./mcp-resources-DSDqTfbK.js";
8
- import { t as sources_exports } from "./sources/index.js";
1
+ import { a as sourceError } from "./path-BzmU4Eni.js";
2
+ import { a as useSource, i as registerSources, n as getRegisteredSource, r as registerSource, t as clearSources } from "./registry-C8skfCSV.js";
3
+ import { n as defineCollection, t as CollectionCursorError } from "./collection-B8pXGM2d.js";
4
+ //#region src/core/combine-sources.ts
5
+ function combineSources(definition) {
6
+ const sources = definition.sources;
7
+ async function get(identity) {
8
+ if (!Array.isArray(identity) || identity.length !== 2 || String(identity[0]) !== identity[0] || String(identity[1]) !== identity[1]) throw new TypeError("[vitehub] Combined Source identity must be a [source, key] string tuple.");
9
+ const [source, key] = identity;
10
+ if (!Object.hasOwn(sources, source)) throw sourceError(`[vitehub] Combined Source alias ${JSON.stringify(source)} is not defined.`);
11
+ return await sources[source].get(key);
12
+ }
13
+ async function items() {
14
+ const entries = Object.entries(sources);
15
+ for (const [source, reader] of entries) if (!(reader.items instanceof Function)) throw sourceError(`[vitehub] Combined Source alias ${JSON.stringify(source)} is not enumerable.`);
16
+ return (await Promise.all(entries.map(async ([source, reader]) => (await reader.items()).map((item) => ({
17
+ ...item,
18
+ identity: [source, item.key],
19
+ source
20
+ }))))).flat();
21
+ }
22
+ return {
23
+ get,
24
+ items
25
+ };
26
+ }
27
+ //#endregion
9
28
  //#region src/core/define.ts
10
29
  function defineSource(source) {
11
30
  return source;
@@ -13,107 +32,50 @@ function defineSource(source) {
13
32
  function defineSources(sources) {
14
33
  return sources;
15
34
  }
16
- //#endregion
17
- //#region src/core/registry.ts
18
- const sourceRegistry = /* @__PURE__ */ new Map();
19
- function registerSource(name, source) {
20
- sourceRegistry.set(name, source);
21
- return source;
22
- }
23
- function registerSources(sources) {
24
- for (const [name, source] of Object.entries(sources)) registerSource(name, source);
25
- return sources;
35
+ function createSource(definition, context) {
36
+ return definition(context);
26
37
  }
27
- function getRegisteredSource(name) {
28
- const source = sourceRegistry.get(name);
29
- if (!source) throw sourceNotFoundError(name);
38
+ //#endregion
39
+ //#region src/ignores.ts
40
+ const dependencies = Object.freeze([
41
+ "**/node_modules/**",
42
+ "**/.pnpm-store/**",
43
+ "**/.venv/**",
44
+ "**/dbt_packages/**"
45
+ ]);
46
+ const generated = Object.freeze([
47
+ "**/.nuxt/**",
48
+ "**/.output/**",
49
+ "**/coverage/**",
50
+ "**/playwright-report/**",
51
+ "**/target/**",
52
+ "**/test-results/**"
53
+ ]);
54
+ const media = Object.freeze(["**/*.{gif,ico,jpeg,jpg,png,webp}"]);
55
+ const secrets = Object.freeze(["**/.env", "**/.env.*"]);
56
+ const system = Object.freeze([
57
+ "**/.DS_Store",
58
+ "**/__pycache__/**",
59
+ "**/*.pyc"
60
+ ]);
61
+ const sourceIgnores = Object.freeze({
62
+ defaults: Object.freeze([
63
+ ...dependencies,
64
+ ...generated,
65
+ ...media,
66
+ ...secrets,
67
+ ...system
68
+ ]),
69
+ dependencies,
70
+ generated,
71
+ media,
72
+ secrets,
73
+ system
74
+ });
75
+ //#endregion
76
+ //#region src/sources/custom.ts
77
+ function custom(source) {
30
78
  return source;
31
79
  }
32
- function clearSources() {
33
- sourceRegistry.clear();
34
- }
35
- function createSourceContext(name, context = {}) {
36
- return {
37
- abortSignal: context.abortSignal,
38
- rootDir: context.rootDir || process.cwd(),
39
- source: context.source || name,
40
- sourceRootDir: context.sourceRootDir,
41
- workspace: context.workspace
42
- };
43
- }
44
- function createMissingContentError(key) {
45
- return sourceError(`[vitehub] Source item ${JSON.stringify(key)} does not provide readable content.`);
46
- }
47
- function isNestedUnder(path, prefix) {
48
- return !prefix || path === prefix || path.startsWith(`${prefix}/`);
49
- }
50
- function createDirectorySet(paths) {
51
- const directories = /* @__PURE__ */ new Set();
52
- for (const path of paths) {
53
- const segments = normalizeSourcePath(path).split("/").filter(Boolean);
54
- for (let index = 1; index < segments.length; index++) directories.add(segments.slice(0, index).join("/"));
55
- }
56
- return directories;
57
- }
58
- function useSource(name, context) {
59
- const source = getRegisteredSource(name);
60
- const ctx = createSourceContext(name, context);
61
- let preparePromise;
62
- async function ensurePrepared() {
63
- if (!source.prepare) return;
64
- preparePromise ||= source.prepare(ctx);
65
- await preparePromise;
66
- }
67
- async function keys() {
68
- await ensurePrepared();
69
- return await source.getKeys(ctx);
70
- }
71
- async function get(key) {
72
- await ensurePrepared();
73
- return await source.getItem(key, ctx);
74
- }
75
- return {
76
- keys,
77
- get,
78
- async read(key, options) {
79
- const item = await get(key);
80
- if (typeof item.content === "undefined") throw createMissingContentError(key);
81
- return decodeSourceContent(item.content, options);
82
- },
83
- async meta(key) {
84
- await ensurePrepared();
85
- return await source.getMeta?.(key, ctx);
86
- },
87
- async exists(key) {
88
- return (await keys()).includes(key);
89
- },
90
- async list(prefix = "") {
91
- await ensurePrepared();
92
- const normalizedPrefix = prefix ? normalizeSafeSourcePath(prefix, { allowEmpty: true }) : "";
93
- const sourceKeys = await keys();
94
- const directories = createDirectorySet(sourceKeys);
95
- const result = /* @__PURE__ */ new Map();
96
- for (const directory of directories) {
97
- if (directory === normalizedPrefix) continue;
98
- if (!isNestedUnder(directory, normalizedPrefix)) continue;
99
- if (normalizeSourcePath(directory.slice(normalizedPrefix.length)).replace(/^\//, "").includes("/")) continue;
100
- result.set(directory, {
101
- key: directory,
102
- type: "directory"
103
- });
104
- }
105
- for (const key of sourceKeys) {
106
- if (key === normalizedPrefix) continue;
107
- if (!isNestedUnder(key, normalizedPrefix)) continue;
108
- if (normalizeSourcePath(key.slice(normalizedPrefix.length)).replace(/^\//, "").includes("/")) continue;
109
- result.set(key, {
110
- key,
111
- type: "file"
112
- });
113
- }
114
- return [...result.values()].sort((left, right) => left.key.localeCompare(right.key));
115
- }
116
- };
117
- }
118
80
  //#endregion
119
- export { clearSources, custom, defineSource, defineSources, file, getRegisteredSource, github, glob, markdown, mcpResources, registerSource, registerSources, sources_exports as source, useSource };
81
+ export { CollectionCursorError, clearSources, combineSources, createSource, custom, defineCollection, defineSource, defineSources, getRegisteredSource, registerSource, registerSources, sourceIgnores, useSource };
@@ -1,7 +1,7 @@
1
- import { r as Source } from "./types-f6Lyjq8g.js";
2
- import { n as FileSourceOptions } from "./file-slFAccIZ.js";
1
+ import { r as Source } from "./types-Bu3WvNX9.js";
2
+ import { n as FileSourceOptions } from "./file-EQ3AjVM6.js";
3
3
 
4
4
  //#region src/sources/markdown.d.ts
5
5
  declare function markdown<const TKey extends string = string>(options: FileSourceOptions<TKey>): Source<TKey>;
6
6
  //#endregion
7
- export { markdown as t };
7
+ export { markdown };
@@ -1,4 +1,4 @@
1
- import { file } from "./file.js";
1
+ import { t as file } from "./file-BSWQg9Qv.js";
2
2
  //#region src/sources/markdown.ts
3
3
  function markdown(options) {
4
4
  return file({
package/dist/mcp.d.ts ADDED
@@ -0,0 +1,152 @@
1
+ import { i as SourceCacheOptions, o as SourceContext, r as Source } from "./types-Bu3WvNX9.js";
2
+
3
+ //#region src/sources/mcp-resources.d.ts
4
+ interface McpResourcesRequestOptions {
5
+ maxTotalTimeout?: number;
6
+ onprogress?: (progress: {
7
+ message?: string;
8
+ progress: number;
9
+ total?: number;
10
+ }) => void;
11
+ onresumptiontoken?: (token: string) => void;
12
+ relatedRequestId?: number | string;
13
+ relatedTask?: {
14
+ taskId: string;
15
+ };
16
+ resetTimeoutOnProgress?: boolean;
17
+ resumptionToken?: string;
18
+ signal?: AbortSignal;
19
+ task?: {
20
+ pollInterval?: number;
21
+ ttl?: number;
22
+ };
23
+ timeout?: number;
24
+ }
25
+ interface McpResourceDescriptor {
26
+ _meta?: Record<string, unknown>;
27
+ annotations?: {
28
+ audience?: Array<"assistant" | "user">;
29
+ lastModified?: string;
30
+ priority?: number;
31
+ };
32
+ description?: string;
33
+ icons?: Array<{
34
+ mimeType?: string;
35
+ sizes?: string[];
36
+ src: string;
37
+ theme?: "dark" | "light";
38
+ }>;
39
+ mimeType?: string;
40
+ name: string;
41
+ size?: number;
42
+ title?: string;
43
+ uri: string;
44
+ }
45
+ type McpResourceContent = {
46
+ _meta?: Record<string, unknown>;
47
+ blob: string;
48
+ mimeType?: string;
49
+ uri: string;
50
+ } | {
51
+ _meta?: Record<string, unknown>;
52
+ mimeType?: string;
53
+ text: string;
54
+ uri: string;
55
+ };
56
+ type McpResourcesMessage = {
57
+ id: number | string;
58
+ jsonrpc: "2.0";
59
+ method: string;
60
+ params?: {
61
+ [key: string]: unknown;
62
+ _meta?: Record<string, unknown>;
63
+ };
64
+ } | {
65
+ id?: never;
66
+ jsonrpc: "2.0";
67
+ method: string;
68
+ params?: {
69
+ [key: string]: unknown;
70
+ _meta?: Record<string, unknown>;
71
+ };
72
+ } | {
73
+ id: number | string;
74
+ jsonrpc: "2.0";
75
+ method?: never;
76
+ result: {
77
+ [key: string]: unknown;
78
+ _meta?: Record<string, unknown>;
79
+ };
80
+ } | {
81
+ error: {
82
+ code: number;
83
+ data?: unknown;
84
+ message: string;
85
+ };
86
+ id: number | string;
87
+ jsonrpc: "2.0";
88
+ method?: never;
89
+ };
90
+ interface McpResourcesTransport {
91
+ close(): Promise<void>;
92
+ onclose?: () => void;
93
+ onerror?: (error: Error) => void;
94
+ onmessage?: (message: McpResourcesMessage) => void;
95
+ send(message: McpResourcesMessage): Promise<void>;
96
+ start(): Promise<void>;
97
+ }
98
+ interface McpResourcesClient {
99
+ close?: () => void | Promise<void>;
100
+ getServerVersion?: () => {
101
+ name: string;
102
+ version: string;
103
+ } | undefined;
104
+ listResources: (params?: {
105
+ cursor?: string;
106
+ }, options?: McpResourcesRequestOptions) => Promise<{
107
+ nextCursor?: string;
108
+ resources: McpResourceDescriptor[];
109
+ }>;
110
+ readResource: (params: {
111
+ uri: string;
112
+ }, options?: McpResourcesRequestOptions) => Promise<{
113
+ contents: McpResourceContent[];
114
+ }>;
115
+ serverInfo?: unknown;
116
+ }
117
+ type McpResourcesTransportConfig = McpResourcesTransport | {
118
+ authProvider?: unknown;
119
+ fetch?: (url: string | URL, init?: RequestInit) => Promise<Response>;
120
+ reconnectionOptions?: {
121
+ initialReconnectionDelay: number;
122
+ maxReconnectionDelay: number;
123
+ maxRetries: number;
124
+ reconnectionDelayGrowFactor: number;
125
+ };
126
+ requestInit?: RequestInit;
127
+ sessionId?: string;
128
+ type?: "http";
129
+ url: string | URL;
130
+ } | {
131
+ authProvider?: unknown;
132
+ eventSourceInit?: unknown;
133
+ fetch?: (url: string | URL, init?: RequestInit) => Promise<Response>;
134
+ requestInit?: RequestInit;
135
+ type: "sse";
136
+ url: string | URL;
137
+ };
138
+ interface McpResourcesClientConfig {
139
+ transport: McpResourcesTransportConfig;
140
+ }
141
+ type McpResourcesServer = McpResourcesClient | McpResourcesClientConfig | ((ctx: SourceContext) => McpResourcesClient | McpResourcesClientConfig | Promise<McpResourcesClient | McpResourcesClientConfig>);
142
+ interface McpResourcesSourceOptions<TKey extends string = string> {
143
+ cache?: false | SourceCacheOptions;
144
+ ignore?: string | readonly string[];
145
+ include?: string | string[];
146
+ path?: (resource: McpResourceDescriptor) => TKey | string | undefined;
147
+ request?: McpResourcesRequestOptions;
148
+ server: McpResourcesServer;
149
+ }
150
+ declare function mcpResources<const TKey extends string = string>(options: McpResourcesSourceOptions<TKey>): Source<TKey>;
151
+ //#endregion
152
+ export { type McpResourceContent, type McpResourceDescriptor, type McpResourcesClient, type McpResourcesClientConfig, type McpResourcesRequestOptions, type McpResourcesServer, type McpResourcesSourceOptions, type McpResourcesTransport, type McpResourcesTransportConfig, mcpResources };