@llmindset/hf-mcp 0.3.2 → 0.3.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/docs-search/doc-fetch.d.ts +1 -0
- package/dist/docs-search/doc-fetch.d.ts.map +1 -1
- package/dist/docs-search/doc-fetch.js +9 -12
- package/dist/docs-search/doc-fetch.js.map +1 -1
- package/dist/docs-search/doc-fetch.test.js +56 -11
- package/dist/docs-search/doc-fetch.test.js.map +1 -1
- package/dist/file-icons.d.ts +3 -0
- package/dist/file-icons.d.ts.map +1 -0
- package/dist/file-icons.js +38 -0
- package/dist/file-icons.js.map +1 -0
- package/dist/gradio-files.d.ts +0 -1
- package/dist/gradio-files.d.ts.map +1 -1
- package/dist/gradio-files.js +2 -35
- package/dist/gradio-files.js.map +1 -1
- package/dist/hf-api-call.d.ts.map +1 -1
- package/dist/hf-api-call.js +7 -7
- package/dist/hf-api-call.js.map +1 -1
- package/dist/index.browser.d.ts +48 -0
- package/dist/index.browser.d.ts.map +1 -0
- package/dist/index.browser.js +153 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/jobs/commands/uv-utils.d.ts +0 -3
- package/dist/jobs/commands/uv-utils.d.ts.map +1 -1
- package/dist/jobs/commands/uv-utils.js +2 -2
- package/dist/jobs/commands/uv-utils.js.map +1 -1
- package/dist/jobs/jobs-tool.d.ts.map +1 -1
- package/dist/jobs/jobs-tool.js +11 -12
- package/dist/jobs/jobs-tool.js.map +1 -1
- package/dist/jobs/schema-help.d.ts +2 -9
- package/dist/jobs/schema-help.d.ts.map +1 -1
- package/dist/jobs/schema-help.js +3 -3
- package/dist/jobs/schema-help.js.map +1 -1
- package/dist/jobs/sse-handler.d.ts +3 -2
- package/dist/jobs/sse-handler.d.ts.map +1 -1
- package/dist/jobs/sse-handler.js +8 -4
- package/dist/jobs/sse-handler.js.map +1 -1
- package/dist/jobs/types.d.ts +1 -1
- package/dist/logger.d.ts +2 -2
- package/dist/logger.d.ts.map +1 -1
- package/dist/network/fetch-profile.d.ts +24 -0
- package/dist/network/fetch-profile.d.ts.map +1 -0
- package/dist/network/fetch-profile.js +80 -0
- package/dist/network/fetch-profile.js.map +1 -0
- package/dist/network/index.d.ts +5 -0
- package/dist/network/index.d.ts.map +1 -0
- package/dist/network/index.js +5 -0
- package/dist/network/index.js.map +1 -0
- package/dist/network/ip-policy.d.ts +6 -0
- package/dist/network/ip-policy.d.ts.map +1 -0
- package/dist/network/ip-policy.js +202 -0
- package/dist/network/ip-policy.js.map +1 -0
- package/dist/network/ip-policy.test.d.ts +2 -0
- package/dist/network/ip-policy.test.d.ts.map +1 -0
- package/dist/network/ip-policy.test.js +46 -0
- package/dist/network/ip-policy.test.js.map +1 -0
- package/dist/network/safe-fetch.d.ts +16 -0
- package/dist/network/safe-fetch.d.ts.map +1 -0
- package/dist/network/safe-fetch.js +124 -0
- package/dist/network/safe-fetch.js.map +1 -0
- package/dist/network/safe-fetch.test.d.ts +2 -0
- package/dist/network/safe-fetch.test.d.ts.map +1 -0
- package/dist/network/safe-fetch.test.js +136 -0
- package/dist/network/safe-fetch.test.js.map +1 -0
- package/dist/network/url-policy.d.ts +32 -0
- package/dist/network/url-policy.d.ts.map +1 -0
- package/dist/network/url-policy.js +230 -0
- package/dist/network/url-policy.js.map +1 -0
- package/dist/network/url-policy.test.d.ts +2 -0
- package/dist/network/url-policy.test.d.ts.map +1 -0
- package/dist/network/url-policy.test.js +57 -0
- package/dist/network/url-policy.test.js.map +1 -0
- package/dist/readme-utils.d.ts.map +1 -1
- package/dist/readme-utils.js +3 -4
- package/dist/readme-utils.js.map +1 -1
- package/dist/space/commands/discover.d.ts +0 -5
- package/dist/space/commands/discover.d.ts.map +1 -1
- package/dist/space/commands/discover.js +9 -2
- package/dist/space/commands/discover.js.map +1 -1
- package/dist/space/commands/invoke.js +1 -59
- package/dist/space/commands/invoke.js.map +1 -1
- package/dist/space/commands/view-parameters.d.ts.map +1 -1
- package/dist/space/commands/view-parameters.js +3 -98
- package/dist/space/commands/view-parameters.js.map +1 -1
- package/dist/space/dynamic-space-tool.d.ts.map +1 -1
- package/dist/space/dynamic-space-tool.js +5 -2
- package/dist/space/dynamic-space-tool.js.map +1 -1
- package/dist/space/utils/gradio-caller.d.ts.map +1 -1
- package/dist/space/utils/gradio-caller.js +13 -6
- package/dist/space/utils/gradio-caller.js.map +1 -1
- package/dist/space/utils/space-http.d.ts +8 -0
- package/dist/space/utils/space-http.d.ts.map +1 -0
- package/dist/space/utils/space-http.js +49 -0
- package/dist/space/utils/space-http.js.map +1 -0
- package/dist/space-files.d.ts +0 -1
- package/dist/space-files.d.ts.map +1 -1
- package/dist/space-files.js +3 -36
- package/dist/space-files.js.map +1 -1
- package/package.json +6 -2
- package/src/docs-search/doc-fetch.test.ts +98 -28
- package/src/docs-search/doc-fetch.ts +9 -16
- package/src/file-icons.ts +39 -0
- package/src/gradio-files.ts +2 -40
- package/src/hf-api-call.ts +8 -10
- package/src/index.browser.ts +183 -0
- package/src/index.ts +1 -0
- package/src/jobs/commands/uv-utils.ts +2 -2
- package/src/jobs/jobs-tool.ts +13 -12
- package/src/jobs/schema-help.ts +4 -4
- package/src/jobs/sse-handler.ts +12 -7
- package/src/logger.ts +2 -2
- package/src/network/fetch-profile.ts +112 -0
- package/src/network/index.ts +4 -0
- package/src/network/ip-policy.test.ts +58 -0
- package/src/network/ip-policy.ts +252 -0
- package/src/network/safe-fetch.test.ts +181 -0
- package/src/network/safe-fetch.ts +174 -0
- package/src/network/url-policy.test.ts +100 -0
- package/src/network/url-policy.ts +304 -0
- package/src/readme-utils.ts +11 -10
- package/src/space/commands/discover.ts +10 -2
- package/src/space/commands/invoke.ts +1 -88
- package/src/space/commands/view-parameters.ts +3 -136
- package/src/space/dynamic-space-tool.ts +6 -2
- package/src/space/utils/gradio-caller.ts +25 -12
- package/src/space/utils/space-http.ts +75 -0
- package/src/space-files.ts +3 -41
- package/test/fetch-guard.spec.ts +70 -0
- package/test/jobs/sse-handler.spec.ts +60 -0
- package/dist/space/utils/result-formatter.d.ts +0 -4
- package/dist/space/utils/result-formatter.d.ts.map +0 -1
- package/dist/space/utils/result-formatter.js +0 -146
- package/dist/space/utils/result-formatter.js.map +0 -1
- package/src/space/utils/result-formatter.ts +0 -226
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Formats tool result for user-friendly display
|
|
5
|
-
* Handles different content types:
|
|
6
|
-
* - Text content (primary)
|
|
7
|
-
* - Image content (with descriptions)
|
|
8
|
-
* - Resource content (with URIs)
|
|
9
|
-
* - Error results
|
|
10
|
-
*/
|
|
11
|
-
export function formatToolResult(result: CallToolResult): string {
|
|
12
|
-
// Handle error results
|
|
13
|
-
if (result.isError) {
|
|
14
|
-
return formatErrorResult(result);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Handle successful results with content
|
|
18
|
-
if (Array.isArray(result.content) && result.content.length > 0) {
|
|
19
|
-
return formatContentArray(result.content);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Fallback for empty results
|
|
23
|
-
return 'Tool executed successfully (no content returned).';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Formats error results
|
|
28
|
-
*/
|
|
29
|
-
function formatErrorResult(result: CallToolResult): string {
|
|
30
|
-
if (!Array.isArray(result.content) || result.content.length === 0) {
|
|
31
|
-
return 'Error: Tool execution failed (no error details provided).';
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const errorMessages: string[] = [];
|
|
35
|
-
|
|
36
|
-
for (const item of result.content) {
|
|
37
|
-
if (typeof item === 'string') {
|
|
38
|
-
errorMessages.push(item);
|
|
39
|
-
} else if (item && typeof item === 'object') {
|
|
40
|
-
const obj = item as Record<string, unknown>;
|
|
41
|
-
if (typeof obj.text === 'string') {
|
|
42
|
-
errorMessages.push(obj.text);
|
|
43
|
-
} else if (typeof obj.message === 'string') {
|
|
44
|
-
errorMessages.push(obj.message);
|
|
45
|
-
} else if (typeof obj.error === 'string') {
|
|
46
|
-
errorMessages.push(obj.error);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (errorMessages.length > 0) {
|
|
52
|
-
return `Error: ${errorMessages.join('\n')}`;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return 'Error: Tool execution failed.';
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Formats an array of content items
|
|
60
|
-
*/
|
|
61
|
-
function formatContentArray(content: unknown[]): string {
|
|
62
|
-
const formattedItems: string[] = [];
|
|
63
|
-
|
|
64
|
-
for (const item of content) {
|
|
65
|
-
const formatted = formatContentItem(item);
|
|
66
|
-
if (formatted) {
|
|
67
|
-
formattedItems.push(formatted);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (formattedItems.length === 0) {
|
|
72
|
-
return 'Tool executed successfully (no displayable content).';
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return formattedItems.join('\n\n');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Formats a single content item
|
|
80
|
-
*/
|
|
81
|
-
function formatContentItem(item: unknown): string | null {
|
|
82
|
-
if (!item) {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Handle string content
|
|
87
|
-
if (typeof item === 'string') {
|
|
88
|
-
return item;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Handle non-object content
|
|
92
|
-
if (typeof item !== 'object') {
|
|
93
|
-
if (typeof item === 'number' || typeof item === 'boolean') {
|
|
94
|
-
return String(item);
|
|
95
|
-
}
|
|
96
|
-
return JSON.stringify(item);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const obj = item as Record<string, unknown>;
|
|
100
|
-
const type = typeof obj.type === 'string' ? obj.type.toLowerCase() : undefined;
|
|
101
|
-
|
|
102
|
-
switch (type) {
|
|
103
|
-
case 'text':
|
|
104
|
-
return formatTextContent(obj);
|
|
105
|
-
|
|
106
|
-
case 'image':
|
|
107
|
-
return formatImageContent(obj);
|
|
108
|
-
|
|
109
|
-
case 'resource':
|
|
110
|
-
return formatResourceContent(obj);
|
|
111
|
-
|
|
112
|
-
case 'embedded_resource':
|
|
113
|
-
return formatEmbeddedResourceContent(obj);
|
|
114
|
-
|
|
115
|
-
default:
|
|
116
|
-
// Try to extract text from unknown types
|
|
117
|
-
if (typeof obj.text === 'string') {
|
|
118
|
-
return obj.text;
|
|
119
|
-
}
|
|
120
|
-
// Fallback to JSON representation
|
|
121
|
-
try {
|
|
122
|
-
return JSON.stringify(item, null, 2);
|
|
123
|
-
} catch {
|
|
124
|
-
return '[complex object]';
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Formats text content
|
|
131
|
-
*/
|
|
132
|
-
function formatTextContent(obj: Record<string, unknown>): string | null {
|
|
133
|
-
if (typeof obj.text === 'string') {
|
|
134
|
-
return obj.text;
|
|
135
|
-
}
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Formats image content
|
|
141
|
-
*/
|
|
142
|
-
function formatImageContent(obj: Record<string, unknown>): string {
|
|
143
|
-
const parts: string[] = ['[Image Content]'];
|
|
144
|
-
|
|
145
|
-
// Add MIME type if available
|
|
146
|
-
if (typeof obj.mimeType === 'string') {
|
|
147
|
-
parts.push(`Type: ${obj.mimeType}`);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Add URL if available
|
|
151
|
-
if (typeof obj.url === 'string') {
|
|
152
|
-
parts.push(`URL: ${obj.url}`);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Add data indicator if present
|
|
156
|
-
if (typeof obj.data === 'string') {
|
|
157
|
-
const dataLength = obj.data.length;
|
|
158
|
-
parts.push(`Data: ${dataLength} characters (base64)`);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return parts.join('\n');
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Formats resource content
|
|
166
|
-
*/
|
|
167
|
-
function formatResourceContent(obj: Record<string, unknown>): string {
|
|
168
|
-
const parts: string[] = ['[Resource]'];
|
|
169
|
-
|
|
170
|
-
// Extract resource details
|
|
171
|
-
const resource = obj.resource as Record<string, unknown> | undefined;
|
|
172
|
-
if (resource) {
|
|
173
|
-
if (typeof resource.uri === 'string') {
|
|
174
|
-
parts.push(`URI: ${resource.uri}`);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (typeof resource.name === 'string') {
|
|
178
|
-
parts.push(`Name: ${resource.name}`);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if (typeof resource.mimeType === 'string') {
|
|
182
|
-
parts.push(`Type: ${resource.mimeType}`);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (typeof resource.description === 'string') {
|
|
186
|
-
parts.push(`Description: ${resource.description}`);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return parts.join('\n');
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Formats embedded resource content
|
|
195
|
-
*/
|
|
196
|
-
function formatEmbeddedResourceContent(obj: Record<string, unknown>): string {
|
|
197
|
-
const parts: string[] = ['[Embedded Resource]'];
|
|
198
|
-
|
|
199
|
-
if (typeof obj.uri === 'string') {
|
|
200
|
-
parts.push(`URI: ${obj.uri}`);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (typeof obj.mimeType === 'string') {
|
|
204
|
-
parts.push(`Type: ${obj.mimeType}`);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Add blob indicator if present
|
|
208
|
-
if (typeof obj.blob === 'string') {
|
|
209
|
-
const blobLength = obj.blob.length;
|
|
210
|
-
parts.push(`Data: ${blobLength} characters`);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return parts.join('\n');
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Formats a list of warnings
|
|
218
|
-
*/
|
|
219
|
-
export function formatWarnings(warnings: string[]): string {
|
|
220
|
-
if (warnings.length === 0) {
|
|
221
|
-
return '';
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const header = warnings.length === 1 ? 'Warning:' : 'Warnings:';
|
|
225
|
-
return `${header}\n${warnings.map((w) => `- ${w}`).join('\n')}\n\n`;
|
|
226
|
-
}
|