@vite-hub/source 0.0.3 → 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.
package/dist/index.d.ts CHANGED
@@ -1,92 +1,62 @@
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";
1
3
  import { ViteHubError } from "@vite-hub/runtime";
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
4
 
9
- //#region src/core/types.d.ts
10
- type SourceContent = string | Uint8Array;
11
- interface ReadSourceOptions {
12
- encoding?: "utf8" | "binary";
13
- }
14
- type ReadSourceResult<TOptions extends ReadSourceOptions | undefined = undefined> = TOptions extends {
15
- encoding: "binary";
16
- } ? Uint8Array : string;
17
- interface SourceContext {
18
- abortSignal?: AbortSignal;
19
- rootDir: string;
20
- sourceRootDir?: string;
21
- source?: string;
22
- workspace?: string;
23
- }
24
- interface SourceCacheOptions {
25
- maxAge?: number;
26
- }
27
- interface SourceSearchQuery {
28
- pattern: string;
29
- cwd?: string;
30
- paths?: string[];
31
- regex?: boolean;
32
- caseSensitive?: boolean;
33
- limit?: number;
34
- }
35
- interface SourceSearchHit {
36
- path: string;
37
- line: number;
38
- column: number;
39
- text: string;
40
- }
41
- interface SourceItem<TKey extends string = string, TData = unknown, TMetadata extends object = Record<string, unknown>> {
42
- key: TKey;
43
- path?: string;
44
- content?: SourceContent;
45
- data?: TData;
46
- mediaType?: string;
47
- metadata?: TMetadata;
48
- }
49
- interface Source<TKey extends string = string, TData = unknown, TMetadata extends object = Record<string, unknown>> {
50
- name: string;
51
- cache?: false | SourceCacheOptions;
52
- fingerprint?: unknown;
53
- prepare?(ctx: SourceContext): Promise<void>;
54
- getKeys(ctx: SourceContext): Promise<TKey[]>;
55
- getItem(key: TKey, ctx: SourceContext): Promise<SourceItem<TKey, TData, TMetadata>>;
56
- getItems?(ctx: SourceContext): Promise<SourceItem<TKey, TData, TMetadata>[]>;
57
- getMeta?(key: TKey, ctx: SourceContext): Promise<TMetadata | undefined>;
58
- search?(query: SourceSearchQuery, ctx: SourceContext): Promise<SourceSearchHit[]>;
59
- watch?: unknown[];
60
- }
61
- interface SourceListEntry<TKey extends string = string> {
62
- key: TKey;
63
- type: "file" | "directory";
64
- }
65
- declare global {
66
- interface ViteHubSourceMap {}
67
- }
68
- interface SourceMap extends ViteHubSourceMap {}
69
- type SourceKeyOf<TSource> = TSource extends Source<infer TKey, any, any> ? TKey : string;
70
- type SourceDataOf<TSource> = TSource extends Source<any, infer TData, any> ? TData : unknown;
71
- type SourceMetadataOf<TSource> = TSource extends Source<any, any, infer TMetadata> ? TMetadata : Record<string, unknown>;
72
- type RegisteredSource<TName extends SourceName> = TName extends keyof ViteHubSourceMap ? ViteHubSourceMap[TName] : Source;
73
- type SourceName = [keyof ViteHubSourceMap] extends [never] ? string : Extract<keyof ViteHubSourceMap, string>;
74
- type SourceKey<TName extends SourceName = SourceName> = Extract<SourceKeyOf<RegisteredSource<TName>>, string>;
75
- type SourceData<TName extends SourceName = SourceName> = SourceDataOf<RegisteredSource<TName>>;
76
- type SourceMetadata<TName extends SourceName = SourceName> = SourceMetadataOf<RegisteredSource<TName>>;
77
- interface SourceReader<TName extends SourceName = SourceName> {
78
- keys(): Promise<SourceKey<TName>[]>;
79
- get(key: SourceKey<TName>): Promise<SourceItem<SourceKey<TName>, SourceData<TName>, SourceMetadata<TName>>>;
80
- items(): Promise<Array<SourceItem<SourceKey<TName>, SourceData<TName>, SourceMetadata<TName>>>>;
81
- read<TOptions extends ReadSourceOptions | undefined = undefined>(key: SourceKey<TName>, options?: TOptions): Promise<ReadSourceResult<TOptions>>;
82
- meta(key: SourceKey<TName>): Promise<SourceMetadata<TName> | undefined>;
83
- exists(key: SourceKey<TName>): Promise<boolean>;
84
- list(prefix?: SourceKey<TName> | (string & {}) | ""): Promise<SourceListEntry<SourceKey<TName>>[]>;
85
- }
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>;
86
49
  //#endregion
87
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;
88
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>;
89
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;
90
60
  //#endregion
91
61
  //#region src/core/registry.d.ts
92
62
  declare function registerSource<const TName extends string, const TSource extends Source>(name: TName, source: TSource): TSource;
@@ -98,85 +68,17 @@ declare function useSource<TName extends SourceName>(name: TName, context?: Part
98
68
  //#region src/core/errors.d.ts
99
69
  type SourceErrorCode = "SOURCE_FAILED" | "SOURCE_NOT_FOUND" | "SOURCE_PATH_INVALID";
100
70
  //#endregion
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
101
81
  //#region src/sources/custom.d.ts
102
82
  declare function custom<const TSource extends Source>(source: TSource): TSource;
103
83
  //#endregion
104
- //#region src/sources/file.d.ts
105
- interface FileSourcePathOptions<TKey extends string = string> {
106
- path: string;
107
- workspacePath?: TKey;
108
- content?: never;
109
- mediaType?: string;
110
- }
111
- interface FileSourceInlineOptions<TKey extends string = string> {
112
- workspacePath: TKey;
113
- content: SourceContent;
114
- mediaType?: string;
115
- path?: never;
116
- }
117
- type FileSourceOptions<TKey extends string = string> = FileSourcePathOptions<TKey> | FileSourceInlineOptions<TKey>;
118
- type FileSourceInput<TKey extends string = string> = FileSourceOptions<TKey> | TKey;
119
- declare function file<const TKey extends string = string>(input: FileSourceInput<TKey>): Source<TKey>;
120
- //#endregion
121
- //#region src/sources/github/types.d.ts
122
- interface GitHubSourceOptions {
123
- repo: string;
124
- ref?: string;
125
- root?: string;
126
- auth?: false | string | (() => string | undefined);
127
- include?: string | string[];
128
- exclude?: string | string[];
129
- cache?: false | SourceCacheOptions;
130
- }
131
- //#endregion
132
- //#region src/sources/github/index.d.ts
133
- declare function github<const TKey extends string = string>(options: GitHubSourceOptions): Source<TKey>;
134
- //#endregion
135
- //#region src/sources/glob.d.ts
136
- interface GlobSourceOptions {
137
- cwd?: string;
138
- dot?: boolean;
139
- followSymlinks?: boolean;
140
- include: string | string[];
141
- ignore?: string | string[];
142
- keyCache?: boolean;
143
- prefix?: string;
144
- }
145
- declare function glob<const TKey extends string = string>(options: GlobSourceOptions): Source<TKey>;
146
- //#endregion
147
- //#region src/sources/markdown.d.ts
148
- declare function markdown<const TKey extends string = string>(options: FileSourceOptions<TKey>): Source<TKey>;
149
- //#endregion
150
- //#region src/sources/mcp-resources.d.ts
151
- type McpResourcesRequestOptions = RequestOptions;
152
- type McpResourceDescriptor = Resource;
153
- type McpResourceContent = TextResourceContents | BlobResourceContents;
154
- interface McpResourcesClient {
155
- close?: () => void | Promise<void>;
156
- getServerVersion?: Client["getServerVersion"];
157
- listResources: Client["listResources"];
158
- readResource: Client["readResource"];
159
- serverInfo?: unknown;
160
- }
161
- type McpResourcesTransportConfig = Transport | ({
162
- type?: "http";
163
- url: string | URL;
164
- } & StreamableHTTPClientTransportOptions) | ({
165
- type: "sse";
166
- url: string | URL;
167
- } & SSEClientTransportOptions);
168
- interface McpResourcesClientConfig {
169
- transport: McpResourcesTransportConfig;
170
- }
171
- type McpResourcesServer = McpResourcesClient | McpResourcesClientConfig | ((ctx: SourceContext) => McpResourcesClient | McpResourcesClientConfig | Promise<McpResourcesClient | McpResourcesClientConfig>);
172
- interface McpResourcesSourceOptions<TKey extends string = string> {
173
- cache?: false | SourceCacheOptions;
174
- exclude?: string | string[];
175
- include?: string | string[];
176
- path?: (resource: McpResourceDescriptor) => TKey | string | undefined;
177
- request?: McpResourcesRequestOptions;
178
- server: McpResourcesServer;
179
- }
180
- declare function mcpResources<const TKey extends string = string>(options: McpResourcesSourceOptions<TKey>): Source<TKey>;
181
- //#endregion
182
- export { type FileSourceInlineOptions, type FileSourceOptions, type FileSourcePathOptions, type GitHubSourceOptions, type GlobSourceOptions, type McpResourceContent, type McpResourceDescriptor, type McpResourcesClient, type McpResourcesClientConfig, type McpResourcesRequestOptions, type McpResourcesServer, type McpResourcesSourceOptions, type McpResourcesTransportConfig, 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 SourceSearchHit, type SourceSearchQuery, clearSources, custom, defineSource, defineSources, file, getRegisteredSource, github, glob, markdown, mcpResources, registerSource, registerSources, useSource };
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 };