@llmindset/hf-mcp 0.3.4 → 0.3.9
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/gradio-files.d.ts +35 -4
- package/dist/gradio-files.d.ts.map +1 -1
- package/dist/gradio-files.js +55 -21
- package/dist/gradio-files.js.map +1 -1
- package/dist/hub-inspect.d.ts +2 -2
- package/dist/jobs/types.d.ts +8 -8
- package/dist/repo-search.d.ts +2 -2
- package/dist/repo-search.test.js +3 -2
- package/dist/repo-search.test.js.map +1 -1
- package/package.json +2 -2
- package/src/gradio-files.ts +82 -31
- package/src/repo-search.test.ts +3 -2
- package/test/list-files.spec.ts +121 -0
package/dist/gradio-files.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
export type FileTypeFilter = 'all' | 'image' | 'audio' | 'text';
|
|
3
|
+
export type FileListingSource = {
|
|
4
|
+
kind: 'bucket';
|
|
5
|
+
id: string;
|
|
6
|
+
} | {
|
|
7
|
+
kind: 'dataset';
|
|
8
|
+
id: string;
|
|
9
|
+
};
|
|
2
10
|
interface FileWithUrl {
|
|
3
11
|
path: string;
|
|
4
12
|
size: number;
|
|
@@ -7,7 +15,25 @@ interface FileWithUrl {
|
|
|
7
15
|
sizeFormatted: string;
|
|
8
16
|
lastModified?: string;
|
|
9
17
|
lfs: boolean;
|
|
18
|
+
source: FileListingSource['kind'];
|
|
10
19
|
}
|
|
20
|
+
export declare const LIST_FILES_TOOL_CONFIG: {
|
|
21
|
+
readonly name: "list_files";
|
|
22
|
+
readonly description: "List files available to use as Gradio File/Image/Audio inputs. Prefer these URLs when a Space asks for a file input and the user has not provided an explicit URL.";
|
|
23
|
+
readonly schema: z.ZodObject<{
|
|
24
|
+
fileType: z.ZodDefault<z.ZodOptional<z.ZodEnum<["all", "image", "audio", "text"]>>>;
|
|
25
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
|
+
fileType: "all" | "image" | "audio" | "text";
|
|
27
|
+
}, {
|
|
28
|
+
fileType?: "all" | "image" | "audio" | "text" | undefined;
|
|
29
|
+
}>;
|
|
30
|
+
readonly annotations: {
|
|
31
|
+
readonly title: "Available Input Files";
|
|
32
|
+
readonly destructiveHint: false;
|
|
33
|
+
readonly readOnlyHint: true;
|
|
34
|
+
readonly openWorldHint: true;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
11
37
|
export declare const GRADIO_FILES_TOOL_CONFIG: {
|
|
12
38
|
readonly name: "gradio_files";
|
|
13
39
|
readonly description: "List available URLs that can be used for Gradio File Inputs. Use when an input is requested and an explicit URL has not been provided.";
|
|
@@ -30,14 +56,19 @@ export declare const GRADIO_FILES_PROMPT_CONFIG: {
|
|
|
30
56
|
description: string;
|
|
31
57
|
schema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
32
58
|
};
|
|
59
|
+
export type ListFilesParams = z.infer<typeof LIST_FILES_TOOL_CONFIG.schema>;
|
|
33
60
|
export type GradioFilesParams = z.infer<typeof GRADIO_FILES_TOOL_CONFIG.schema>;
|
|
34
|
-
export declare class
|
|
61
|
+
export declare class ListFilesTool {
|
|
35
62
|
private readonly accessToken;
|
|
36
|
-
private readonly
|
|
63
|
+
private readonly source;
|
|
64
|
+
constructor(hfToken: string, source: FileListingSource);
|
|
65
|
+
getFiles(): Promise<FileWithUrl[]>;
|
|
66
|
+
private constructFileUrl;
|
|
67
|
+
generateDetailedMarkdown(fileType?: FileTypeFilter): Promise<string>;
|
|
68
|
+
}
|
|
69
|
+
export declare class GradioFilesTool extends ListFilesTool {
|
|
37
70
|
constructor(hfToken: string, username: string);
|
|
38
71
|
getGradioFiles(): Promise<FileWithUrl[]>;
|
|
39
|
-
private constructFileUrl;
|
|
40
|
-
generateDetailedMarkdown(fileType?: 'all' | 'image' | 'audio' | 'text'): Promise<string>;
|
|
41
72
|
}
|
|
42
73
|
export {};
|
|
43
74
|
//# sourceMappingURL=gradio-files.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gradio-files.d.ts","sourceRoot":"","sources":["../src/gradio-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"gradio-files.d.ts","sourceRoot":"","sources":["../src/gradio-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;AAEhE,MAAM,MAAM,iBAAiB,GAC1B;IACA,IAAI,EAAE,QAAQ,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;CACV,GACD;IACA,IAAI,EAAE,SAAS,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACV,CAAC;AAEL,UAAU,WAAW;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,OAAO,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;CAClC;AAiFD,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;CAazB,CAAC;AAEX,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;CAa3B,CAAC;AAEX,eAAO,MAAM,0BAA0B;;;;CAItC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC;AAC5E,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,MAAM,CAAC,CAAC;AAKhF,qBAAa,aAAa;IACzB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;gBAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB;IAQhD,QAAQ,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAyCxC,OAAO,CAAC,gBAAgB;IAWlB,wBAAwB,CAAC,QAAQ,GAAE,cAAsB,GAAG,OAAO,CAAC,MAAM,CAAC;CAyCjF;AAKD,qBAAa,eAAgB,SAAQ,aAAa;gBACrC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAIvC,cAAc,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;CAG9C"}
|
package/dist/gradio-files.js
CHANGED
|
@@ -34,11 +34,11 @@ const AUDIO_EXTENSIONS = new Set([
|
|
|
34
34
|
const TEXT_EXTENSIONS = new Set([
|
|
35
35
|
'.txt',
|
|
36
36
|
'.md',
|
|
37
|
-
'json',
|
|
38
|
-
'xml',
|
|
37
|
+
'.json',
|
|
38
|
+
'.xml',
|
|
39
39
|
'.csv',
|
|
40
40
|
'.tsv',
|
|
41
|
-
'yaml',
|
|
41
|
+
'.yaml',
|
|
42
42
|
'.yml',
|
|
43
43
|
'.html',
|
|
44
44
|
'.css',
|
|
@@ -72,11 +72,25 @@ function matchesFileType(file, fileType) {
|
|
|
72
72
|
return true;
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
+
const FILE_TYPE_SCHEMA = z.enum(['all', 'image', 'audio', 'text']).optional().default('all').describe('Filter by type');
|
|
76
|
+
export const LIST_FILES_TOOL_CONFIG = {
|
|
77
|
+
name: 'list_files',
|
|
78
|
+
description: 'List files available to use as Gradio File/Image/Audio inputs. Prefer these URLs when a Space asks for a file input and the user has not provided an explicit URL.',
|
|
79
|
+
schema: z.object({
|
|
80
|
+
fileType: FILE_TYPE_SCHEMA,
|
|
81
|
+
}),
|
|
82
|
+
annotations: {
|
|
83
|
+
title: 'Available Input Files',
|
|
84
|
+
destructiveHint: false,
|
|
85
|
+
readOnlyHint: true,
|
|
86
|
+
openWorldHint: true,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
75
89
|
export const GRADIO_FILES_TOOL_CONFIG = {
|
|
76
90
|
name: 'gradio_files',
|
|
77
91
|
description: 'List available URLs that can be used for Gradio File Inputs. Use when an input is requested and an explicit URL has not been provided.',
|
|
78
92
|
schema: z.object({
|
|
79
|
-
fileType:
|
|
93
|
+
fileType: FILE_TYPE_SCHEMA,
|
|
80
94
|
}),
|
|
81
95
|
annotations: {
|
|
82
96
|
title: 'Gradio Files List',
|
|
@@ -90,21 +104,21 @@ export const GRADIO_FILES_PROMPT_CONFIG = {
|
|
|
90
104
|
description: 'Returns a list of files and their URLs to use as Gradio File Inputs.',
|
|
91
105
|
schema: z.object({}),
|
|
92
106
|
};
|
|
93
|
-
export class
|
|
107
|
+
export class ListFilesTool {
|
|
94
108
|
accessToken;
|
|
95
|
-
|
|
96
|
-
constructor(hfToken,
|
|
109
|
+
source;
|
|
110
|
+
constructor(hfToken, source) {
|
|
97
111
|
this.accessToken = hfToken;
|
|
98
|
-
this.
|
|
112
|
+
this.source = source;
|
|
99
113
|
}
|
|
100
|
-
async
|
|
114
|
+
async getFiles() {
|
|
101
115
|
try {
|
|
102
116
|
const files = [];
|
|
103
117
|
for await (const file of listFiles({
|
|
104
|
-
repo: { type:
|
|
105
|
-
recursive:
|
|
118
|
+
repo: { type: this.source.kind, name: this.source.id },
|
|
119
|
+
recursive: this.source.kind === 'bucket',
|
|
106
120
|
expand: true,
|
|
107
|
-
|
|
121
|
+
accessToken: this.accessToken,
|
|
108
122
|
})) {
|
|
109
123
|
if (file.type === 'file') {
|
|
110
124
|
const fileName = file.path.split('/').pop() || file.path;
|
|
@@ -117,8 +131,9 @@ export class GradioFilesTool {
|
|
|
117
131
|
type: file.type,
|
|
118
132
|
url: this.constructFileUrl(file.path),
|
|
119
133
|
sizeFormatted: formatBytes(file.size),
|
|
120
|
-
lastModified: file.lastCommit?.date,
|
|
134
|
+
lastModified: this.source.kind === 'bucket' ? file.uploadedAt : file.lastCommit?.date,
|
|
121
135
|
lfs: !!file.lfs,
|
|
136
|
+
source: this.source.kind,
|
|
122
137
|
});
|
|
123
138
|
}
|
|
124
139
|
}
|
|
@@ -126,20 +141,31 @@ export class GradioFilesTool {
|
|
|
126
141
|
}
|
|
127
142
|
catch (error) {
|
|
128
143
|
if (error instanceof HfApiError) {
|
|
129
|
-
throw explain(error, `Failed to list files for
|
|
144
|
+
throw explain(error, `Failed to list files for ${this.source.kind} "${this.source.id}"`);
|
|
130
145
|
}
|
|
131
146
|
throw error;
|
|
132
147
|
}
|
|
133
148
|
}
|
|
134
149
|
constructFileUrl(filePath) {
|
|
135
|
-
|
|
150
|
+
if (this.source.kind === 'bucket') {
|
|
151
|
+
const encodedPath = filePath.split('/').map(encodeURIComponent).join('/');
|
|
152
|
+
return `https://huggingface.co/buckets/${this.source.id}/resolve/${encodedPath}`;
|
|
153
|
+
}
|
|
154
|
+
return `https://huggingface.co/datasets/${this.source.id}/resolve/main/${filePath}`;
|
|
136
155
|
}
|
|
137
156
|
async generateDetailedMarkdown(fileType = 'all') {
|
|
138
|
-
const allFiles = await this.
|
|
157
|
+
const allFiles = await this.getFiles();
|
|
139
158
|
const files = allFiles.filter((file) => matchesFileType(file, fileType));
|
|
140
|
-
|
|
159
|
+
const sourceLabel = this.source.kind === 'bucket' ? 'Hugging Face Bucket' : 'Hugging Face Dataset fallback';
|
|
160
|
+
let markdown = `# Available files in ${this.source.kind}: ${this.source.id}\n\n`;
|
|
161
|
+
markdown += `**Source:** ${sourceLabel}\n`;
|
|
162
|
+
markdown += '**Use:** URLs below can be used as Gradio file inputs when accessible to the target Space.\n\n';
|
|
163
|
+
if (this.source.kind === 'bucket') {
|
|
164
|
+
markdown +=
|
|
165
|
+
'Note: private bucket URLs require authorization. A remote Gradio Space can only fetch these URLs directly if it has access; public buckets are safest for cross-Space file inputs.\n\n';
|
|
166
|
+
}
|
|
141
167
|
if (fileType !== 'all') {
|
|
142
|
-
markdown += `**Filter**: ${fileType} files only\n`;
|
|
168
|
+
markdown += `**Filter**: ${fileType} files only\n\n`;
|
|
143
169
|
}
|
|
144
170
|
if (files.length === 0) {
|
|
145
171
|
if (fileType !== 'all') {
|
|
@@ -151,15 +177,23 @@ export class GradioFilesTool {
|
|
|
151
177
|
return markdown;
|
|
152
178
|
}
|
|
153
179
|
markdown += `## All Files\n\n`;
|
|
154
|
-
markdown += `| Name | Size | Type | Last Modified |
|
|
155
|
-
markdown +=
|
|
180
|
+
markdown += `| Name | Path | Size | Type | Last Modified | URL |\n`;
|
|
181
|
+
markdown += `|------|------|------|------|---------------|-----|\n`;
|
|
156
182
|
for (const file of files) {
|
|
157
183
|
const fileName = file.path.split('/').pop() || file.path;
|
|
158
184
|
const icon = getFileIcon(fileName);
|
|
159
185
|
const lastMod = file.lastModified ? new Date(file.lastModified).toLocaleDateString() : '-';
|
|
160
|
-
markdown += `| ${escapeMarkdown(fileName)} | ${file.sizeFormatted} | ${icon} ${file.type} | ${lastMod} | ${file.url} |\n`;
|
|
186
|
+
markdown += `| ${escapeMarkdown(fileName)} | ${escapeMarkdown(file.path)} | ${file.sizeFormatted} | ${icon} ${file.type} | ${lastMod} | ${file.url} |\n`;
|
|
161
187
|
}
|
|
162
188
|
return markdown;
|
|
163
189
|
}
|
|
164
190
|
}
|
|
191
|
+
export class GradioFilesTool extends ListFilesTool {
|
|
192
|
+
constructor(hfToken, username) {
|
|
193
|
+
super(hfToken, { kind: 'dataset', id: `${username}/gradio-files` });
|
|
194
|
+
}
|
|
195
|
+
async getGradioFiles() {
|
|
196
|
+
return this.getFiles();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
165
199
|
//# sourceMappingURL=gradio-files.js.map
|
package/dist/gradio-files.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gradio-files.js","sourceRoot":"","sources":["../src/gradio-files.ts"],"names":[],"mappings":"AAAA,OAAO,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eAAe,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,cAAc;QACnB,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;CACD"}
|
package/dist/hub-inspect.d.ts
CHANGED
|
@@ -10,10 +10,10 @@ export declare const HUB_REPO_DETAILS_TOOL_CONFIG: {
|
|
|
10
10
|
}, "strip", z.ZodTypeAny, {
|
|
11
11
|
repo_ids: string[];
|
|
12
12
|
include_readme: boolean;
|
|
13
|
-
repo_type?: "
|
|
13
|
+
repo_type?: "dataset" | "space" | "model" | undefined;
|
|
14
14
|
}, {
|
|
15
15
|
repo_ids: string[];
|
|
16
|
-
repo_type?: "
|
|
16
|
+
repo_type?: "dataset" | "space" | "model" | undefined;
|
|
17
17
|
include_readme?: boolean | undefined;
|
|
18
18
|
}>;
|
|
19
19
|
readonly annotations: {
|
package/dist/jobs/types.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export declare const runArgsSchema: z.ZodObject<{
|
|
|
75
75
|
}, "strip", z.ZodTypeAny, {
|
|
76
76
|
image: string;
|
|
77
77
|
command: string | string[];
|
|
78
|
-
flavor: "cpu-basic" | "zero-a10g" | "cpu-upgrade" | "
|
|
78
|
+
flavor: "cpu-basic" | "zero-a10g" | "cpu-upgrade" | "cpu-performance" | "cpu-xl" | "sprx8" | "inf2x6" | "t4-small" | "t4-medium" | "l4x1" | "l4x4" | "l40sx1" | "l40sx4" | "l40sx8" | "a10g-small" | "a10g-large" | "a10g-largex2" | "a10g-largex4" | "a100-large" | "h100" | "h100x8";
|
|
79
79
|
timeout: string;
|
|
80
80
|
detach: boolean;
|
|
81
81
|
namespace?: string | undefined;
|
|
@@ -85,7 +85,7 @@ export declare const runArgsSchema: z.ZodObject<{
|
|
|
85
85
|
command: string | string[];
|
|
86
86
|
image?: string | undefined;
|
|
87
87
|
namespace?: string | undefined;
|
|
88
|
-
flavor?: "cpu-basic" | "zero-a10g" | "cpu-upgrade" | "
|
|
88
|
+
flavor?: "cpu-basic" | "zero-a10g" | "cpu-upgrade" | "cpu-performance" | "cpu-xl" | "sprx8" | "inf2x6" | "t4-small" | "t4-medium" | "l4x1" | "l4x4" | "l40sx1" | "l40sx4" | "l40sx8" | "a10g-small" | "a10g-large" | "a10g-largex2" | "a10g-largex4" | "a100-large" | "h100" | "h100x8" | undefined;
|
|
89
89
|
env?: Record<string, string> | undefined;
|
|
90
90
|
secrets?: Record<string, string> | undefined;
|
|
91
91
|
timeout?: string | undefined;
|
|
@@ -105,7 +105,7 @@ export declare const uvArgsSchema: z.ZodObject<{
|
|
|
105
105
|
detach: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
106
106
|
}, "strip", z.ZodTypeAny, {
|
|
107
107
|
script: string;
|
|
108
|
-
flavor: "cpu-basic" | "zero-a10g" | "cpu-upgrade" | "
|
|
108
|
+
flavor: "cpu-basic" | "zero-a10g" | "cpu-upgrade" | "cpu-performance" | "cpu-xl" | "sprx8" | "inf2x6" | "t4-small" | "t4-medium" | "l4x1" | "l4x4" | "l40sx1" | "l40sx4" | "l40sx8" | "a10g-small" | "a10g-large" | "a10g-largex2" | "a10g-largex4" | "a100-large" | "h100" | "h100x8";
|
|
109
109
|
timeout: string;
|
|
110
110
|
detach: boolean;
|
|
111
111
|
namespace?: string | undefined;
|
|
@@ -117,7 +117,7 @@ export declare const uvArgsSchema: z.ZodObject<{
|
|
|
117
117
|
}, {
|
|
118
118
|
script: string;
|
|
119
119
|
namespace?: string | undefined;
|
|
120
|
-
flavor?: "cpu-basic" | "zero-a10g" | "cpu-upgrade" | "
|
|
120
|
+
flavor?: "cpu-basic" | "zero-a10g" | "cpu-upgrade" | "cpu-performance" | "cpu-xl" | "sprx8" | "inf2x6" | "t4-small" | "t4-medium" | "l4x1" | "l4x4" | "l40sx1" | "l40sx4" | "l40sx8" | "a10g-small" | "a10g-large" | "a10g-largex2" | "a10g-largex4" | "a100-large" | "h100" | "h100x8" | undefined;
|
|
121
121
|
env?: Record<string, string> | undefined;
|
|
122
122
|
secrets?: Record<string, string> | undefined;
|
|
123
123
|
timeout?: string | undefined;
|
|
@@ -192,7 +192,7 @@ export declare const scheduledRunArgsSchema: z.ZodObject<{
|
|
|
192
192
|
}, "strip", z.ZodTypeAny, {
|
|
193
193
|
image: string;
|
|
194
194
|
command: string | string[];
|
|
195
|
-
flavor: "cpu-basic" | "zero-a10g" | "cpu-upgrade" | "
|
|
195
|
+
flavor: "cpu-basic" | "zero-a10g" | "cpu-upgrade" | "cpu-performance" | "cpu-xl" | "sprx8" | "inf2x6" | "t4-small" | "t4-medium" | "l4x1" | "l4x4" | "l40sx1" | "l40sx4" | "l40sx8" | "a10g-small" | "a10g-large" | "a10g-largex2" | "a10g-largex4" | "a100-large" | "h100" | "h100x8";
|
|
196
196
|
timeout: string;
|
|
197
197
|
detach: boolean;
|
|
198
198
|
schedule: string;
|
|
@@ -205,7 +205,7 @@ export declare const scheduledRunArgsSchema: z.ZodObject<{
|
|
|
205
205
|
schedule: string;
|
|
206
206
|
image?: string | undefined;
|
|
207
207
|
namespace?: string | undefined;
|
|
208
|
-
flavor?: "cpu-basic" | "zero-a10g" | "cpu-upgrade" | "
|
|
208
|
+
flavor?: "cpu-basic" | "zero-a10g" | "cpu-upgrade" | "cpu-performance" | "cpu-xl" | "sprx8" | "inf2x6" | "t4-small" | "t4-medium" | "l4x1" | "l4x4" | "l40sx1" | "l40sx4" | "l40sx8" | "a10g-small" | "a10g-large" | "a10g-largex2" | "a10g-largex4" | "a100-large" | "h100" | "h100x8" | undefined;
|
|
209
209
|
env?: Record<string, string> | undefined;
|
|
210
210
|
secrets?: Record<string, string> | undefined;
|
|
211
211
|
timeout?: string | undefined;
|
|
@@ -229,7 +229,7 @@ export declare const scheduledUvArgsSchema: z.ZodObject<{
|
|
|
229
229
|
suspend: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
230
230
|
}, "strip", z.ZodTypeAny, {
|
|
231
231
|
script: string;
|
|
232
|
-
flavor: "cpu-basic" | "zero-a10g" | "cpu-upgrade" | "
|
|
232
|
+
flavor: "cpu-basic" | "zero-a10g" | "cpu-upgrade" | "cpu-performance" | "cpu-xl" | "sprx8" | "inf2x6" | "t4-small" | "t4-medium" | "l4x1" | "l4x4" | "l40sx1" | "l40sx4" | "l40sx8" | "a10g-small" | "a10g-large" | "a10g-largex2" | "a10g-largex4" | "a100-large" | "h100" | "h100x8";
|
|
233
233
|
timeout: string;
|
|
234
234
|
detach: boolean;
|
|
235
235
|
schedule: string;
|
|
@@ -244,7 +244,7 @@ export declare const scheduledUvArgsSchema: z.ZodObject<{
|
|
|
244
244
|
script: string;
|
|
245
245
|
schedule: string;
|
|
246
246
|
namespace?: string | undefined;
|
|
247
|
-
flavor?: "cpu-basic" | "zero-a10g" | "cpu-upgrade" | "
|
|
247
|
+
flavor?: "cpu-basic" | "zero-a10g" | "cpu-upgrade" | "cpu-performance" | "cpu-xl" | "sprx8" | "inf2x6" | "t4-small" | "t4-medium" | "l4x1" | "l4x4" | "l40sx1" | "l40sx4" | "l40sx8" | "a10g-small" | "a10g-large" | "a10g-largex2" | "a10g-largex4" | "a100-large" | "h100" | "h100x8" | undefined;
|
|
248
248
|
env?: Record<string, string> | undefined;
|
|
249
249
|
secrets?: Record<string, string> | undefined;
|
|
250
250
|
timeout?: string | undefined;
|
package/dist/repo-search.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const REPO_SEARCH_TOOL_CONFIG: {
|
|
|
15
15
|
limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
16
16
|
}, "strip", z.ZodTypeAny, {
|
|
17
17
|
limit: number;
|
|
18
|
-
repo_types: ("
|
|
18
|
+
repo_types: ("dataset" | "space" | "model")[];
|
|
19
19
|
sort?: "createdAt" | "downloads" | "lastModified" | "likes" | "trendingScore" | undefined;
|
|
20
20
|
author?: string | undefined;
|
|
21
21
|
query?: string | undefined;
|
|
@@ -25,7 +25,7 @@ export declare const REPO_SEARCH_TOOL_CONFIG: {
|
|
|
25
25
|
author?: string | undefined;
|
|
26
26
|
query?: string | undefined;
|
|
27
27
|
limit?: number | undefined;
|
|
28
|
-
repo_types?: ("
|
|
28
|
+
repo_types?: ("dataset" | "space" | "model")[] | undefined;
|
|
29
29
|
filters?: string[] | undefined;
|
|
30
30
|
}>;
|
|
31
31
|
readonly annotations: {
|
package/dist/repo-search.test.js
CHANGED
|
@@ -56,8 +56,9 @@ describe('RepoSearchTool', () => {
|
|
|
56
56
|
limit: 5,
|
|
57
57
|
});
|
|
58
58
|
expect(calls).toHaveLength(2);
|
|
59
|
-
|
|
60
|
-
expect(
|
|
59
|
+
const callInputs = calls.map((call) => call.input);
|
|
60
|
+
expect(callInputs.some((input) => input.includes('/api/models'))).toBe(true);
|
|
61
|
+
expect(callInputs.some((input) => input.includes('/api/datasets'))).toBe(true);
|
|
61
62
|
expect(result.totalResults).toBe(2);
|
|
62
63
|
expect(result.formatted).toContain('## Models (1)');
|
|
63
64
|
expect(result.formatted).toContain('## Datasets (1)');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repo-search.test.js","sourceRoot":"","sources":["../src/repo-search.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAOlD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC/B,MAAM,aAAa,GAAG,UAAU,CAAC,KAAK,CAAC;IACvC,IAAI,KAAK,GAAoB,EAAE,CAAC;IAEhC,UAAU,CAAC,GAAG,EAAE;QACf,KAAK,GAAG,EAAE,CAAC;QACX,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,KAAwB,EAAE,IAAkB,EAAqB,EAAE;YAC1F,MAAM,WAAW,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;YACjD,KAAK,CA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,CAAC;IACd,CAAC;IAED,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;IAED,IAAI,KAAK,YAAY,OAAO,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llmindset/hf-mcp",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@huggingface/hub": "^2.
|
|
31
|
+
"@huggingface/hub": "^2.11.0",
|
|
32
32
|
"@mcp-ui/server": "^5.12.0",
|
|
33
33
|
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
34
34
|
"shell-quote": "^1.8.3",
|
package/src/gradio-files.ts
CHANGED
|
@@ -5,7 +5,18 @@ import { HfApiError } from './hf-api-call.js';
|
|
|
5
5
|
import { explain } from './error-messages.js';
|
|
6
6
|
import { getFileIcon } from './file-icons.js';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
export type FileTypeFilter = 'all' | 'image' | 'audio' | 'text';
|
|
9
|
+
|
|
10
|
+
export type FileListingSource =
|
|
11
|
+
| {
|
|
12
|
+
kind: 'bucket';
|
|
13
|
+
id: string;
|
|
14
|
+
}
|
|
15
|
+
| {
|
|
16
|
+
kind: 'dataset';
|
|
17
|
+
id: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
9
20
|
interface FileWithUrl {
|
|
10
21
|
path: string;
|
|
11
22
|
size: number;
|
|
@@ -14,6 +25,7 @@ interface FileWithUrl {
|
|
|
14
25
|
sizeFormatted: string;
|
|
15
26
|
lastModified?: string;
|
|
16
27
|
lfs: boolean;
|
|
28
|
+
source: FileListingSource['kind'];
|
|
17
29
|
}
|
|
18
30
|
|
|
19
31
|
// File type detection helpers
|
|
@@ -49,11 +61,11 @@ const AUDIO_EXTENSIONS = new Set([
|
|
|
49
61
|
const TEXT_EXTENSIONS = new Set([
|
|
50
62
|
'.txt',
|
|
51
63
|
'.md',
|
|
52
|
-
'json',
|
|
53
|
-
'xml',
|
|
64
|
+
'.json',
|
|
65
|
+
'.xml',
|
|
54
66
|
'.csv',
|
|
55
67
|
'.tsv',
|
|
56
|
-
'yaml',
|
|
68
|
+
'.yaml',
|
|
57
69
|
'.yml',
|
|
58
70
|
'.html',
|
|
59
71
|
'.css',
|
|
@@ -78,7 +90,7 @@ function isTextFile(path: string): boolean {
|
|
|
78
90
|
return TEXT_EXTENSIONS.has(getFileExtension(path));
|
|
79
91
|
}
|
|
80
92
|
|
|
81
|
-
function matchesFileType(file: FileWithUrl, fileType:
|
|
93
|
+
function matchesFileType(file: FileWithUrl, fileType: FileTypeFilter): boolean {
|
|
82
94
|
switch (fileType) {
|
|
83
95
|
case 'all':
|
|
84
96
|
return true;
|
|
@@ -93,13 +105,29 @@ function matchesFileType(file: FileWithUrl, fileType: 'all' | 'image' | 'audio'
|
|
|
93
105
|
}
|
|
94
106
|
}
|
|
95
107
|
|
|
96
|
-
|
|
108
|
+
const FILE_TYPE_SCHEMA = z.enum(['all', 'image', 'audio', 'text']).optional().default('all').describe('Filter by type');
|
|
109
|
+
|
|
110
|
+
export const LIST_FILES_TOOL_CONFIG = {
|
|
111
|
+
name: 'list_files',
|
|
112
|
+
description:
|
|
113
|
+
'List files available to use as Gradio File/Image/Audio inputs. Prefer these URLs when a Space asks for a file input and the user has not provided an explicit URL.',
|
|
114
|
+
schema: z.object({
|
|
115
|
+
fileType: FILE_TYPE_SCHEMA,
|
|
116
|
+
}),
|
|
117
|
+
annotations: {
|
|
118
|
+
title: 'Available Input Files',
|
|
119
|
+
destructiveHint: false,
|
|
120
|
+
readOnlyHint: true,
|
|
121
|
+
openWorldHint: true,
|
|
122
|
+
},
|
|
123
|
+
} as const;
|
|
124
|
+
|
|
97
125
|
export const GRADIO_FILES_TOOL_CONFIG = {
|
|
98
126
|
name: 'gradio_files',
|
|
99
127
|
description:
|
|
100
128
|
'List available URLs that can be used for Gradio File Inputs. Use when an input is requested and an explicit URL has not been provided.', // This will be dynamically set with username
|
|
101
129
|
schema: z.object({
|
|
102
|
-
fileType:
|
|
130
|
+
fileType: FILE_TYPE_SCHEMA,
|
|
103
131
|
}),
|
|
104
132
|
annotations: {
|
|
105
133
|
title: 'Gradio Files List',
|
|
@@ -115,37 +143,35 @@ export const GRADIO_FILES_PROMPT_CONFIG = {
|
|
|
115
143
|
schema: z.object({}),
|
|
116
144
|
};
|
|
117
145
|
|
|
118
|
-
|
|
146
|
+
export type ListFilesParams = z.infer<typeof LIST_FILES_TOOL_CONFIG.schema>;
|
|
119
147
|
export type GradioFilesParams = z.infer<typeof GRADIO_FILES_TOOL_CONFIG.schema>;
|
|
120
148
|
|
|
121
149
|
/**
|
|
122
|
-
* Service for listing files
|
|
150
|
+
* Service for listing files from a Hugging Face Bucket or the legacy gradio-files dataset.
|
|
123
151
|
*/
|
|
124
|
-
export class
|
|
152
|
+
export class ListFilesTool {
|
|
125
153
|
private readonly accessToken: string;
|
|
126
|
-
private readonly
|
|
154
|
+
private readonly source: FileListingSource;
|
|
127
155
|
|
|
128
|
-
constructor(hfToken: string,
|
|
156
|
+
constructor(hfToken: string, source: FileListingSource) {
|
|
129
157
|
this.accessToken = hfToken;
|
|
130
|
-
this.
|
|
158
|
+
this.source = source;
|
|
131
159
|
}
|
|
132
160
|
|
|
133
161
|
/**
|
|
134
|
-
* Get all files
|
|
162
|
+
* Get all files with stable Hub URLs.
|
|
135
163
|
*/
|
|
136
|
-
async
|
|
164
|
+
async getFiles(): Promise<FileWithUrl[]> {
|
|
137
165
|
try {
|
|
138
166
|
const files: FileWithUrl[] = [];
|
|
139
167
|
|
|
140
|
-
// List all files recursively
|
|
141
168
|
for await (const file of listFiles({
|
|
142
|
-
repo: { type:
|
|
143
|
-
recursive:
|
|
144
|
-
expand: true,
|
|
145
|
-
|
|
169
|
+
repo: { type: this.source.kind, name: this.source.id },
|
|
170
|
+
recursive: this.source.kind === 'bucket',
|
|
171
|
+
expand: true,
|
|
172
|
+
accessToken: this.accessToken,
|
|
146
173
|
})) {
|
|
147
174
|
if (file.type === 'file') {
|
|
148
|
-
// Exclude .gitattributes and .gitignore files
|
|
149
175
|
const fileName = file.path.split('/').pop() || file.path;
|
|
150
176
|
if (fileName === '.gitattributes' || fileName === '.gitignore') {
|
|
151
177
|
continue;
|
|
@@ -157,8 +183,9 @@ export class GradioFilesTool {
|
|
|
157
183
|
type: file.type,
|
|
158
184
|
url: this.constructFileUrl(file.path),
|
|
159
185
|
sizeFormatted: formatBytes(file.size),
|
|
160
|
-
lastModified: file.lastCommit?.date,
|
|
186
|
+
lastModified: this.source.kind === 'bucket' ? file.uploadedAt : file.lastCommit?.date,
|
|
161
187
|
lfs: !!file.lfs,
|
|
188
|
+
source: this.source.kind,
|
|
162
189
|
});
|
|
163
190
|
}
|
|
164
191
|
}
|
|
@@ -166,7 +193,7 @@ export class GradioFilesTool {
|
|
|
166
193
|
return files.sort((a, b) => a.path.localeCompare(b.path));
|
|
167
194
|
} catch (error) {
|
|
168
195
|
if (error instanceof HfApiError) {
|
|
169
|
-
throw explain(error, `Failed to list files for
|
|
196
|
+
throw explain(error, `Failed to list files for ${this.source.kind} "${this.source.id}"`);
|
|
170
197
|
}
|
|
171
198
|
throw error;
|
|
172
199
|
}
|
|
@@ -176,19 +203,30 @@ export class GradioFilesTool {
|
|
|
176
203
|
* Construct the URL for a file
|
|
177
204
|
*/
|
|
178
205
|
private constructFileUrl(filePath: string): string {
|
|
179
|
-
|
|
206
|
+
if (this.source.kind === 'bucket') {
|
|
207
|
+
const encodedPath = filePath.split('/').map(encodeURIComponent).join('/');
|
|
208
|
+
return `https://huggingface.co/buckets/${this.source.id}/resolve/${encodedPath}`;
|
|
209
|
+
}
|
|
210
|
+
return `https://huggingface.co/datasets/${this.source.id}/resolve/main/${filePath}`;
|
|
180
211
|
}
|
|
181
212
|
|
|
182
213
|
/**
|
|
183
214
|
* Generate detailed markdown report with files grouped by directory
|
|
184
215
|
*/
|
|
185
|
-
async generateDetailedMarkdown(fileType:
|
|
186
|
-
const allFiles = await this.
|
|
216
|
+
async generateDetailedMarkdown(fileType: FileTypeFilter = 'all'): Promise<string> {
|
|
217
|
+
const allFiles = await this.getFiles();
|
|
187
218
|
const files = allFiles.filter((file) => matchesFileType(file, fileType));
|
|
219
|
+
const sourceLabel = this.source.kind === 'bucket' ? 'Hugging Face Bucket' : 'Hugging Face Dataset fallback';
|
|
188
220
|
|
|
189
|
-
let markdown = `# Available
|
|
221
|
+
let markdown = `# Available files in ${this.source.kind}: ${this.source.id}\n\n`;
|
|
222
|
+
markdown += `**Source:** ${sourceLabel}\n`;
|
|
223
|
+
markdown += '**Use:** URLs below can be used as Gradio file inputs when accessible to the target Space.\n\n';
|
|
224
|
+
if (this.source.kind === 'bucket') {
|
|
225
|
+
markdown +=
|
|
226
|
+
'Note: private bucket URLs require authorization. A remote Gradio Space can only fetch these URLs directly if it has access; public buckets are safest for cross-Space file inputs.\n\n';
|
|
227
|
+
}
|
|
190
228
|
if (fileType !== 'all') {
|
|
191
|
-
markdown += `**Filter**: ${fileType} files only\n`;
|
|
229
|
+
markdown += `**Filter**: ${fileType} files only\n\n`;
|
|
192
230
|
}
|
|
193
231
|
|
|
194
232
|
// Handle empty results
|
|
@@ -203,17 +241,30 @@ export class GradioFilesTool {
|
|
|
203
241
|
|
|
204
242
|
// Generate table
|
|
205
243
|
markdown += `## All Files\n\n`;
|
|
206
|
-
markdown += `| Name | Size | Type | Last Modified |
|
|
207
|
-
markdown +=
|
|
244
|
+
markdown += `| Name | Path | Size | Type | Last Modified | URL |\n`;
|
|
245
|
+
markdown += `|------|------|------|------|---------------|-----|\n`;
|
|
208
246
|
|
|
209
247
|
for (const file of files) {
|
|
210
248
|
const fileName = file.path.split('/').pop() || file.path;
|
|
211
249
|
const icon = getFileIcon(fileName);
|
|
212
250
|
const lastMod = file.lastModified ? new Date(file.lastModified).toLocaleDateString() : '-';
|
|
213
251
|
|
|
214
|
-
markdown += `| ${escapeMarkdown(fileName)} | ${file.sizeFormatted} | ${icon} ${file.type} | ${lastMod} | ${file.url} |\n`;
|
|
252
|
+
markdown += `| ${escapeMarkdown(fileName)} | ${escapeMarkdown(file.path)} | ${file.sizeFormatted} | ${icon} ${file.type} | ${lastMod} | ${file.url} |\n`;
|
|
215
253
|
}
|
|
216
254
|
|
|
217
255
|
return markdown;
|
|
218
256
|
}
|
|
219
257
|
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Compatibility wrapper for the legacy gradio_files dataset behavior.
|
|
261
|
+
*/
|
|
262
|
+
export class GradioFilesTool extends ListFilesTool {
|
|
263
|
+
constructor(hfToken: string, username: string) {
|
|
264
|
+
super(hfToken, { kind: 'dataset', id: `${username}/gradio-files` });
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async getGradioFiles(): Promise<FileWithUrl[]> {
|
|
268
|
+
return this.getFiles();
|
|
269
|
+
}
|
|
270
|
+
}
|
package/src/repo-search.test.ts
CHANGED
|
@@ -70,8 +70,9 @@ describe('RepoSearchTool', () => {
|
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
expect(calls).toHaveLength(2);
|
|
73
|
-
|
|
74
|
-
expect(
|
|
73
|
+
const callInputs = calls.map((call) => call.input);
|
|
74
|
+
expect(callInputs.some((input) => input.includes('/api/models'))).toBe(true);
|
|
75
|
+
expect(callInputs.some((input) => input.includes('/api/datasets'))).toBe(true);
|
|
75
76
|
expect(result.totalResults).toBe(2);
|
|
76
77
|
expect(result.formatted).toContain('## Models (1)');
|
|
77
78
|
expect(result.formatted).toContain('## Datasets (1)');
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import * as hub from '@huggingface/hub';
|
|
3
|
+
import type { ListFileEntry } from '@huggingface/hub';
|
|
4
|
+
import { LIST_FILES_TOOL_CONFIG, ListFilesTool, GRADIO_FILES_TOOL_CONFIG } from '../src/gradio-files.js';
|
|
5
|
+
|
|
6
|
+
vi.mock('@huggingface/hub', () => ({
|
|
7
|
+
listFiles: vi.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
async function* listFileEntries(entries: ListFileEntry[]): AsyncGenerator<ListFileEntry> {
|
|
11
|
+
for (const entry of entries) {
|
|
12
|
+
yield entry;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function mockListFiles(entries: ListFileEntry[]): void {
|
|
17
|
+
vi.mocked(hub.listFiles).mockReturnValue(listFileEntries(entries));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('ListFilesTool', () => {
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
vi.clearAllMocks();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('lists bucket files recursively and encodes nested bucket URLs', async () => {
|
|
26
|
+
mockListFiles([
|
|
27
|
+
{ type: 'directory', path: 'images', size: 0 },
|
|
28
|
+
{ type: 'file', path: 'images/cat 1.png', size: 2048, uploadedAt: '2026-04-27T00:00:00Z' },
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
const tool = new ListFilesTool('hf_token', { kind: 'bucket', id: 'alice/mcp' });
|
|
32
|
+
const files = await tool.getFiles();
|
|
33
|
+
|
|
34
|
+
expect(hub.listFiles).toHaveBeenCalledWith({
|
|
35
|
+
repo: { type: 'bucket', name: 'alice/mcp' },
|
|
36
|
+
recursive: true,
|
|
37
|
+
expand: true,
|
|
38
|
+
accessToken: 'hf_token',
|
|
39
|
+
});
|
|
40
|
+
expect(files).toEqual([
|
|
41
|
+
expect.objectContaining({
|
|
42
|
+
path: 'images/cat 1.png',
|
|
43
|
+
url: 'https://huggingface.co/buckets/alice/mcp/resolve/images/cat%201.png',
|
|
44
|
+
lastModified: '2026-04-27T00:00:00Z',
|
|
45
|
+
source: 'bucket',
|
|
46
|
+
}),
|
|
47
|
+
]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('keeps legacy dataset fallback behavior and excludes git metadata files', async () => {
|
|
51
|
+
mockListFiles([
|
|
52
|
+
{ type: 'file', path: '.gitattributes', size: 100 },
|
|
53
|
+
{ type: 'file', path: '.gitignore', size: 100 },
|
|
54
|
+
{
|
|
55
|
+
type: 'file',
|
|
56
|
+
path: 'cat.png',
|
|
57
|
+
size: 1024,
|
|
58
|
+
lastCommit: { date: '2026-04-27T00:00:00Z', id: '1', title: 'add' },
|
|
59
|
+
},
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
const tool = new ListFilesTool('hf_token', { kind: 'dataset', id: 'alice/gradio-files' });
|
|
63
|
+
const files = await tool.getFiles();
|
|
64
|
+
|
|
65
|
+
expect(hub.listFiles).toHaveBeenCalledWith({
|
|
66
|
+
repo: { type: 'dataset', name: 'alice/gradio-files' },
|
|
67
|
+
recursive: false,
|
|
68
|
+
expand: true,
|
|
69
|
+
accessToken: 'hf_token',
|
|
70
|
+
});
|
|
71
|
+
expect(files).toHaveLength(1);
|
|
72
|
+
expect(files[0]).toMatchObject({
|
|
73
|
+
path: 'cat.png',
|
|
74
|
+
url: 'https://huggingface.co/datasets/alice/gradio-files/resolve/main/cat.png',
|
|
75
|
+
source: 'dataset',
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('filters image, audio, and text files in markdown', async () => {
|
|
80
|
+
mockListFiles([
|
|
81
|
+
{ type: 'file', path: 'cat.png', size: 1024 },
|
|
82
|
+
{ type: 'file', path: 'sound.wav', size: 1024 },
|
|
83
|
+
{ type: 'file', path: 'notes.json', size: 1024 },
|
|
84
|
+
]);
|
|
85
|
+
|
|
86
|
+
const tool = new ListFilesTool('hf_token', { kind: 'bucket', id: 'alice/mcp' });
|
|
87
|
+
const markdown = await tool.generateDetailedMarkdown('text');
|
|
88
|
+
|
|
89
|
+
expect(markdown).toContain('notes.json');
|
|
90
|
+
expect(markdown).not.toContain('cat.png');
|
|
91
|
+
expect(markdown).not.toContain('sound.wav');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('identifies bucket source in markdown', async () => {
|
|
95
|
+
mockListFiles([{ type: 'file', path: 'hello.txt', size: 5 }]);
|
|
96
|
+
|
|
97
|
+
const tool = new ListFilesTool('hf_token', { kind: 'bucket', id: 'alice/mcp' });
|
|
98
|
+
const markdown = await tool.generateDetailedMarkdown();
|
|
99
|
+
|
|
100
|
+
expect(markdown).toContain('# Available files in bucket: alice/mcp');
|
|
101
|
+
expect(markdown).toContain('**Source:** Hugging Face Bucket');
|
|
102
|
+
expect(markdown).toContain('private bucket URLs require authorization');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('identifies dataset fallback source in markdown', async () => {
|
|
106
|
+
mockListFiles([{ type: 'file', path: 'hello.txt', size: 5 }]);
|
|
107
|
+
|
|
108
|
+
const tool = new ListFilesTool('hf_token', { kind: 'dataset', id: 'alice/gradio-files' });
|
|
109
|
+
const markdown = await tool.generateDetailedMarkdown();
|
|
110
|
+
|
|
111
|
+
expect(markdown).toContain('# Available files in dataset: alice/gradio-files');
|
|
112
|
+
expect(markdown).toContain('**Source:** Hugging Face Dataset fallback');
|
|
113
|
+
expect(markdown).not.toContain('private bucket URLs require authorization');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('exposes list_files while keeping gradio_files compatibility config', () => {
|
|
117
|
+
expect(LIST_FILES_TOOL_CONFIG.name).toBe('list_files');
|
|
118
|
+
expect(LIST_FILES_TOOL_CONFIG.annotations.readOnlyHint).toBe(true);
|
|
119
|
+
expect(GRADIO_FILES_TOOL_CONFIG.name).toBe('gradio_files');
|
|
120
|
+
});
|
|
121
|
+
});
|