@llmindset/hf-mcp 0.3.1 → 0.3.3
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/docs-search/docs-semantic-search.d.ts.map +1 -1
- package/dist/docs-search/docs-semantic-search.js +7 -1
- package/dist/docs-search/docs-semantic-search.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/hub-inspect.d.ts +2 -2
- package/dist/hub-inspect.d.ts.map +1 -1
- package/dist/hub-inspect.js +1 -1
- package/dist/hub-inspect.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 +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -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 +166 -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 +26 -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/repo-search.d.ts +46 -0
- package/dist/repo-search.d.ts.map +1 -0
- package/dist/repo-search.js +310 -0
- package/dist/repo-search.js.map +1 -0
- package/dist/repo-search.test.d.ts +2 -0
- package/dist/repo-search.test.d.ts.map +1 -0
- package/dist/repo-search.test.js +130 -0
- package/dist/repo-search.test.js.map +1 -0
- 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/dist/tool-ids.d.ts +6 -5
- package/dist/tool-ids.d.ts.map +1 -1
- package/dist/tool-ids.js +9 -14
- package/dist/tool-ids.js.map +1 -1
- package/package.json +7 -3
- package/src/docs-search/doc-fetch.test.ts +98 -28
- package/src/docs-search/doc-fetch.ts +9 -16
- package/src/docs-search/docs-semantic-search.ts +8 -1
- package/src/file-icons.ts +39 -0
- package/src/gradio-files.ts +2 -40
- package/src/hf-api-call.ts +8 -10
- package/src/hub-inspect.ts +2 -2
- package/src/index.browser.ts +183 -0
- package/src/index.ts +2 -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 +29 -0
- package/src/network/ip-policy.ts +206 -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/repo-search.test.ts +155 -0
- package/src/repo-search.ts +414 -0
- 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/src/tool-ids.ts +10 -14
- 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,146 +0,0 @@
|
|
|
1
|
-
export function formatToolResult(result) {
|
|
2
|
-
if (result.isError) {
|
|
3
|
-
return formatErrorResult(result);
|
|
4
|
-
}
|
|
5
|
-
if (Array.isArray(result.content) && result.content.length > 0) {
|
|
6
|
-
return formatContentArray(result.content);
|
|
7
|
-
}
|
|
8
|
-
return 'Tool executed successfully (no content returned).';
|
|
9
|
-
}
|
|
10
|
-
function formatErrorResult(result) {
|
|
11
|
-
if (!Array.isArray(result.content) || result.content.length === 0) {
|
|
12
|
-
return 'Error: Tool execution failed (no error details provided).';
|
|
13
|
-
}
|
|
14
|
-
const errorMessages = [];
|
|
15
|
-
for (const item of result.content) {
|
|
16
|
-
if (typeof item === 'string') {
|
|
17
|
-
errorMessages.push(item);
|
|
18
|
-
}
|
|
19
|
-
else if (item && typeof item === 'object') {
|
|
20
|
-
const obj = item;
|
|
21
|
-
if (typeof obj.text === 'string') {
|
|
22
|
-
errorMessages.push(obj.text);
|
|
23
|
-
}
|
|
24
|
-
else if (typeof obj.message === 'string') {
|
|
25
|
-
errorMessages.push(obj.message);
|
|
26
|
-
}
|
|
27
|
-
else if (typeof obj.error === 'string') {
|
|
28
|
-
errorMessages.push(obj.error);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (errorMessages.length > 0) {
|
|
33
|
-
return `Error: ${errorMessages.join('\n')}`;
|
|
34
|
-
}
|
|
35
|
-
return 'Error: Tool execution failed.';
|
|
36
|
-
}
|
|
37
|
-
function formatContentArray(content) {
|
|
38
|
-
const formattedItems = [];
|
|
39
|
-
for (const item of content) {
|
|
40
|
-
const formatted = formatContentItem(item);
|
|
41
|
-
if (formatted) {
|
|
42
|
-
formattedItems.push(formatted);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (formattedItems.length === 0) {
|
|
46
|
-
return 'Tool executed successfully (no displayable content).';
|
|
47
|
-
}
|
|
48
|
-
return formattedItems.join('\n\n');
|
|
49
|
-
}
|
|
50
|
-
function formatContentItem(item) {
|
|
51
|
-
if (!item) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
if (typeof item === 'string') {
|
|
55
|
-
return item;
|
|
56
|
-
}
|
|
57
|
-
if (typeof item !== 'object') {
|
|
58
|
-
if (typeof item === 'number' || typeof item === 'boolean') {
|
|
59
|
-
return String(item);
|
|
60
|
-
}
|
|
61
|
-
return JSON.stringify(item);
|
|
62
|
-
}
|
|
63
|
-
const obj = item;
|
|
64
|
-
const type = typeof obj.type === 'string' ? obj.type.toLowerCase() : undefined;
|
|
65
|
-
switch (type) {
|
|
66
|
-
case 'text':
|
|
67
|
-
return formatTextContent(obj);
|
|
68
|
-
case 'image':
|
|
69
|
-
return formatImageContent(obj);
|
|
70
|
-
case 'resource':
|
|
71
|
-
return formatResourceContent(obj);
|
|
72
|
-
case 'embedded_resource':
|
|
73
|
-
return formatEmbeddedResourceContent(obj);
|
|
74
|
-
default:
|
|
75
|
-
if (typeof obj.text === 'string') {
|
|
76
|
-
return obj.text;
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
return JSON.stringify(item, null, 2);
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
82
|
-
return '[complex object]';
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function formatTextContent(obj) {
|
|
87
|
-
if (typeof obj.text === 'string') {
|
|
88
|
-
return obj.text;
|
|
89
|
-
}
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
function formatImageContent(obj) {
|
|
93
|
-
const parts = ['[Image Content]'];
|
|
94
|
-
if (typeof obj.mimeType === 'string') {
|
|
95
|
-
parts.push(`Type: ${obj.mimeType}`);
|
|
96
|
-
}
|
|
97
|
-
if (typeof obj.url === 'string') {
|
|
98
|
-
parts.push(`URL: ${obj.url}`);
|
|
99
|
-
}
|
|
100
|
-
if (typeof obj.data === 'string') {
|
|
101
|
-
const dataLength = obj.data.length;
|
|
102
|
-
parts.push(`Data: ${dataLength} characters (base64)`);
|
|
103
|
-
}
|
|
104
|
-
return parts.join('\n');
|
|
105
|
-
}
|
|
106
|
-
function formatResourceContent(obj) {
|
|
107
|
-
const parts = ['[Resource]'];
|
|
108
|
-
const resource = obj.resource;
|
|
109
|
-
if (resource) {
|
|
110
|
-
if (typeof resource.uri === 'string') {
|
|
111
|
-
parts.push(`URI: ${resource.uri}`);
|
|
112
|
-
}
|
|
113
|
-
if (typeof resource.name === 'string') {
|
|
114
|
-
parts.push(`Name: ${resource.name}`);
|
|
115
|
-
}
|
|
116
|
-
if (typeof resource.mimeType === 'string') {
|
|
117
|
-
parts.push(`Type: ${resource.mimeType}`);
|
|
118
|
-
}
|
|
119
|
-
if (typeof resource.description === 'string') {
|
|
120
|
-
parts.push(`Description: ${resource.description}`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return parts.join('\n');
|
|
124
|
-
}
|
|
125
|
-
function formatEmbeddedResourceContent(obj) {
|
|
126
|
-
const parts = ['[Embedded Resource]'];
|
|
127
|
-
if (typeof obj.uri === 'string') {
|
|
128
|
-
parts.push(`URI: ${obj.uri}`);
|
|
129
|
-
}
|
|
130
|
-
if (typeof obj.mimeType === 'string') {
|
|
131
|
-
parts.push(`Type: ${obj.mimeType}`);
|
|
132
|
-
}
|
|
133
|
-
if (typeof obj.blob === 'string') {
|
|
134
|
-
const blobLength = obj.blob.length;
|
|
135
|
-
parts.push(`Data: ${blobLength} characters`);
|
|
136
|
-
}
|
|
137
|
-
return parts.join('\n');
|
|
138
|
-
}
|
|
139
|
-
export function formatWarnings(warnings) {
|
|
140
|
-
if (warnings.length === 0) {
|
|
141
|
-
return '';
|
|
142
|
-
}
|
|
143
|
-
const header = warnings.length === 1 ? 'Warning:' : 'Warnings:';
|
|
144
|
-
return `${header}\n${warnings.map((w) => `- ${w}`).join('\n')}\n\n`;
|
|
145
|
-
}
|
|
146
|
-
//# sourceMappingURL=result-formatter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"result-formatter.js","sourceRoot":"","sources":["../../../src/space/utils/result-formatter.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,gBAAgB,CAAC,MAAsB;IAEtD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IAGD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,C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D,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAClC,MAAM,UAAU,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC;QACnC,KAAK,CAAC,IAAI,CAAC,SAAS,UAAU,aAAa,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAKD,MAAM,UAAU,cAAc,CAAC,QAAkB;IAChD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,EAAE,CAAC;IACX,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC;IAChE,OAAO,GAAG,MAAM,KAAK,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;AACrE,CAAC"}
|
|
@@ -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
|
-
}
|