@mcpmesh/sdk 0.9.11 → 1.0.0-beta.1
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/__tests__/claude-handler.test.js +119 -71
- package/dist/__tests__/claude-handler.test.js.map +1 -1
- package/dist/__tests__/llm-agent-media.test.d.ts +8 -0
- package/dist/__tests__/llm-agent-media.test.d.ts.map +1 -0
- package/dist/__tests__/llm-agent-media.test.js +167 -0
- package/dist/__tests__/llm-agent-media.test.js.map +1 -0
- package/dist/__tests__/media-helpers.test.d.ts +7 -0
- package/dist/__tests__/media-helpers.test.d.ts.map +1 -0
- package/dist/__tests__/media-helpers.test.js +60 -0
- package/dist/__tests__/media-helpers.test.js.map +1 -0
- package/dist/__tests__/media-param.test.d.ts +7 -0
- package/dist/__tests__/media-param.test.d.ts.map +1 -0
- package/dist/__tests__/media-param.test.js +104 -0
- package/dist/__tests__/media-param.test.js.map +1 -0
- package/dist/__tests__/media-resolver.test.d.ts +8 -0
- package/dist/__tests__/media-resolver.test.d.ts.map +1 -0
- package/dist/__tests__/media-resolver.test.js +298 -0
- package/dist/__tests__/media-resolver.test.js.map +1 -0
- package/dist/__tests__/media-result.test.d.ts +5 -0
- package/dist/__tests__/media-result.test.d.ts.map +1 -0
- package/dist/__tests__/media-result.test.js +180 -0
- package/dist/__tests__/media-result.test.js.map +1 -0
- package/dist/__tests__/media-store.test.d.ts +7 -0
- package/dist/__tests__/media-store.test.d.ts.map +1 -0
- package/dist/__tests__/media-store.test.js +102 -0
- package/dist/__tests__/media-store.test.js.map +1 -0
- package/dist/__tests__/proxy-resource-link.test.d.ts +8 -0
- package/dist/__tests__/proxy-resource-link.test.d.ts.map +1 -0
- package/dist/__tests__/proxy-resource-link.test.js +175 -0
- package/dist/__tests__/proxy-resource-link.test.js.map +1 -0
- package/dist/agent.d.ts +1 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +76 -10
- package/dist/agent.js.map +1 -1
- package/dist/api-runtime.d.ts.map +1 -1
- package/dist/api-runtime.js +7 -1
- package/dist/api-runtime.js.map +1 -1
- package/dist/config.d.ts +17 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +19 -0
- package/dist/config.js.map +1 -1
- package/dist/debug.d.ts +1 -1
- package/dist/debug.d.ts.map +1 -1
- package/dist/express.d.ts.map +1 -1
- package/dist/express.js +33 -18
- package/dist/express.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/llm-agent.d.ts +2 -0
- package/dist/llm-agent.d.ts.map +1 -1
- package/dist/llm-agent.js +62 -13
- package/dist/llm-agent.js.map +1 -1
- package/dist/llm-provider.d.ts +55 -16
- package/dist/llm-provider.d.ts.map +1 -1
- package/dist/llm-provider.js +321 -32
- package/dist/llm-provider.js.map +1 -1
- package/dist/media/index.d.ts +104 -0
- package/dist/media/index.d.ts.map +1 -0
- package/dist/media/index.js +135 -0
- package/dist/media/index.js.map +1 -0
- package/dist/media/media-store.d.ts +75 -0
- package/dist/media/media-store.d.ts.map +1 -0
- package/dist/media/media-store.js +217 -0
- package/dist/media/media-store.js.map +1 -0
- package/dist/media/resolver.d.ts +67 -0
- package/dist/media/resolver.d.ts.map +1 -0
- package/dist/media/resolver.js +311 -0
- package/dist/media/resolver.js.map +1 -0
- package/dist/media-param.d.ts +17 -0
- package/dist/media-param.d.ts.map +1 -0
- package/dist/media-param.js +32 -0
- package/dist/media-param.js.map +1 -0
- package/dist/provider-handlers/claude-handler.d.ts +21 -26
- package/dist/provider-handlers/claude-handler.d.ts.map +1 -1
- package/dist/provider-handlers/claude-handler.js +65 -45
- package/dist/provider-handlers/claude-handler.js.map +1 -1
- package/dist/provider-handlers/provider-handler.d.ts.map +1 -1
- package/dist/provider-handlers/provider-handler.js +5 -4
- package/dist/provider-handlers/provider-handler.js.map +1 -1
- package/dist/proxy.d.ts +29 -0
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +66 -21
- package/dist/proxy.js.map +1 -1
- package/dist/tls-config.d.ts +31 -0
- package/dist/tls-config.d.ts.map +1 -0
- package/dist/tls-config.js +102 -0
- package/dist/tls-config.js.map +1 -0
- package/dist/types.d.ts +63 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +33 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve resource_link URIs to provider-native multimodal content.
|
|
3
|
+
*
|
|
4
|
+
* When an LLM provider calls a tool that returns a resource_link (e.g., an image URI),
|
|
5
|
+
* the LLM currently sees just a JSON string. This module resolves the URI to base64
|
|
6
|
+
* media in provider-native format so the LLM can actually "see" the image.
|
|
7
|
+
*
|
|
8
|
+
* Based on Python's resolver:
|
|
9
|
+
* src/runtime/python/_mcp_mesh/media/resolver.py
|
|
10
|
+
*/
|
|
11
|
+
import { createDebug } from "../debug.js";
|
|
12
|
+
import { getMediaStore } from "./media-store.js";
|
|
13
|
+
const debug = createDebug("media-resolver");
|
|
14
|
+
const IMAGE_MIME_TYPES = new Set(["image/png", "image/jpeg", "image/gif", "image/webp"]);
|
|
15
|
+
const PDF_MIME_TYPES = new Set(["application/pdf"]);
|
|
16
|
+
const TEXT_MIME_TYPES = new Set([
|
|
17
|
+
"text/plain",
|
|
18
|
+
"text/csv",
|
|
19
|
+
"text/markdown",
|
|
20
|
+
"text/html",
|
|
21
|
+
"text/xml",
|
|
22
|
+
"application/json",
|
|
23
|
+
"application/xml",
|
|
24
|
+
"application/csv",
|
|
25
|
+
]);
|
|
26
|
+
function formatForClaude(b64, mimeType) {
|
|
27
|
+
return {
|
|
28
|
+
type: "image",
|
|
29
|
+
source: {
|
|
30
|
+
type: "base64",
|
|
31
|
+
media_type: mimeType,
|
|
32
|
+
data: b64,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function formatForOpenai(b64, mimeType) {
|
|
37
|
+
return {
|
|
38
|
+
type: "image_url",
|
|
39
|
+
image_url: {
|
|
40
|
+
url: `data:${mimeType};base64,${b64}`,
|
|
41
|
+
detail: "high",
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function formatForGemini(b64, mimeType) {
|
|
46
|
+
// Vercel AI SDK handles Gemini images via OpenAI-compatible format
|
|
47
|
+
return formatForOpenai(b64, mimeType);
|
|
48
|
+
}
|
|
49
|
+
const VENDOR_FORMATTERS = {
|
|
50
|
+
anthropic: formatForClaude,
|
|
51
|
+
openai: formatForOpenai,
|
|
52
|
+
gemini: formatForGemini,
|
|
53
|
+
google: formatForGemini,
|
|
54
|
+
};
|
|
55
|
+
function formatPdfForClaude(b64) {
|
|
56
|
+
return {
|
|
57
|
+
type: "document",
|
|
58
|
+
source: {
|
|
59
|
+
type: "base64",
|
|
60
|
+
media_type: "application/pdf",
|
|
61
|
+
data: b64,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function formatPdfForOpenai(_b64, filename) {
|
|
66
|
+
return {
|
|
67
|
+
type: "text",
|
|
68
|
+
text: `[Attached PDF document: ${filename}. OpenAI does not support PDF analysis. Please use Claude for PDF processing.]`,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function formatPdfForGemini(_b64, filename) {
|
|
72
|
+
return {
|
|
73
|
+
type: "text",
|
|
74
|
+
text: `[Attached PDF document: ${filename}. Gemini PDF support via LiteLLM may vary.]`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function formatTextContent(data, mimeType, filename) {
|
|
78
|
+
let text;
|
|
79
|
+
try {
|
|
80
|
+
text = data.toString("utf-8");
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
text = data.toString("latin1");
|
|
84
|
+
}
|
|
85
|
+
const maxChars = 50_000;
|
|
86
|
+
if (text.length > maxChars) {
|
|
87
|
+
text = text.slice(0, maxChars) + `\n\n[... truncated, ${text.length} total characters]`;
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
type: "text",
|
|
91
|
+
text: `--- Content of ${filename} (${mimeType}) ---\n${text}\n--- End of ${filename} ---`,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Resolve a single resource_link dict to a provider-native content part.
|
|
96
|
+
*
|
|
97
|
+
* @param resourceLink - Dict with type "resource_link" and either flat or nested resource fields
|
|
98
|
+
* @param vendor - One of "anthropic", "openai", "gemini", "google"
|
|
99
|
+
* @returns Provider-native content dict (image block or text fallback)
|
|
100
|
+
*/
|
|
101
|
+
async function resolveSingleResourceLink(resourceLink, vendor) {
|
|
102
|
+
// Support both flat format and nested resource sub-object
|
|
103
|
+
const resource = (resourceLink.resource ?? {});
|
|
104
|
+
const uri = (resource.uri ?? resourceLink.uri ?? "");
|
|
105
|
+
const mimeType = (resource.mimeType ?? resourceLink.mimeType ?? "");
|
|
106
|
+
const name = (resource.name ?? resourceLink.name ?? uri);
|
|
107
|
+
// --- Images: existing behaviour ---
|
|
108
|
+
if (IMAGE_MIME_TYPES.has(mimeType)) {
|
|
109
|
+
try {
|
|
110
|
+
const store = getMediaStore();
|
|
111
|
+
const { data, mimeType: fetchedMime } = await store.fetch(uri);
|
|
112
|
+
const b64 = data.toString("base64");
|
|
113
|
+
const formatter = VENDOR_FORMATTERS[vendor] ?? formatForOpenai;
|
|
114
|
+
const result = formatter(b64, mimeType || fetchedMime);
|
|
115
|
+
debug(`Resolved resource_link ${name} to ${vendor} image block (${data.length} bytes)`);
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
120
|
+
debug(`Failed to fetch resource_link ${uri}: ${errMsg}`);
|
|
121
|
+
return {
|
|
122
|
+
type: "text",
|
|
123
|
+
text: `[resource_link: ${name} (${mimeType || "unknown"}) at ${uri} (fetch failed)]`,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// --- PDFs: provider-specific ---
|
|
128
|
+
if (PDF_MIME_TYPES.has(mimeType)) {
|
|
129
|
+
try {
|
|
130
|
+
const store = getMediaStore();
|
|
131
|
+
const { data } = await store.fetch(uri);
|
|
132
|
+
const b64 = data.toString("base64");
|
|
133
|
+
if (vendor === "anthropic" || vendor === "claude") {
|
|
134
|
+
return formatPdfForClaude(b64);
|
|
135
|
+
}
|
|
136
|
+
else if (vendor === "gemini" || vendor === "google") {
|
|
137
|
+
return formatPdfForGemini(b64, name);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
return formatPdfForOpenai(b64, name);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
145
|
+
debug(`Failed to fetch PDF ${uri}: ${errMsg}`);
|
|
146
|
+
return { type: "text", text: `[PDF document: ${name} at ${uri}]` };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// --- Text files: read content and include as text (all providers) ---
|
|
150
|
+
if (TEXT_MIME_TYPES.has(mimeType) || mimeType.startsWith("text/")) {
|
|
151
|
+
try {
|
|
152
|
+
const store = getMediaStore();
|
|
153
|
+
const { data } = await store.fetch(uri);
|
|
154
|
+
return formatTextContent(data, mimeType, name);
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
158
|
+
debug(`Failed to fetch text file ${uri}: ${errMsg}`);
|
|
159
|
+
return { type: "text", text: `[Text document: ${name} at ${uri}]` };
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// --- Unknown / unsupported MIME type ---
|
|
163
|
+
return {
|
|
164
|
+
type: "text",
|
|
165
|
+
text: `[resource_link: ${name} (${mimeType || "unknown"}) at ${uri}]`,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Scan tool result for resource_link items and resolve to provider-native format.
|
|
170
|
+
*
|
|
171
|
+
* Returns a list of content parts for the LLM message.
|
|
172
|
+
* - For image resource_links: fetches bytes, base64 encodes, formats per vendor
|
|
173
|
+
* - For non-image or non-resource_link: wraps in text content
|
|
174
|
+
*
|
|
175
|
+
* @param toolResult - The raw tool result (could be object, string, etc.)
|
|
176
|
+
* @param vendor - One of "anthropic", "openai", "gemini", "google"
|
|
177
|
+
* @returns List of content dicts suitable for provider-specific message content arrays
|
|
178
|
+
*/
|
|
179
|
+
export async function resolveResourceLinks(toolResult, vendor) {
|
|
180
|
+
// resource_link dict
|
|
181
|
+
if (toolResult &&
|
|
182
|
+
typeof toolResult === "object" &&
|
|
183
|
+
toolResult.type === "resource_link") {
|
|
184
|
+
const part = await resolveSingleResourceLink(toolResult, vendor);
|
|
185
|
+
return [part];
|
|
186
|
+
}
|
|
187
|
+
// multi_content dict (from extractContent in proxy.ts)
|
|
188
|
+
if (toolResult &&
|
|
189
|
+
typeof toolResult === "object" &&
|
|
190
|
+
toolResult.type === "multi_content") {
|
|
191
|
+
const obj = toolResult;
|
|
192
|
+
const items = (obj.items ?? obj.content ?? []);
|
|
193
|
+
const parts = [];
|
|
194
|
+
for (const item of items) {
|
|
195
|
+
if (item &&
|
|
196
|
+
typeof item === "object" &&
|
|
197
|
+
item.type === "resource_link") {
|
|
198
|
+
parts.push(await resolveSingleResourceLink(item, vendor));
|
|
199
|
+
}
|
|
200
|
+
else if (typeof item === "string") {
|
|
201
|
+
parts.push({ type: "text", text: item });
|
|
202
|
+
}
|
|
203
|
+
else if (item && typeof item === "object") {
|
|
204
|
+
// Non-resource_link objects (e.g., text items) — preserve or serialize
|
|
205
|
+
const itemObj = item;
|
|
206
|
+
if (itemObj.type === "text" && typeof itemObj.text === "string") {
|
|
207
|
+
parts.push({ type: "text", text: itemObj.text });
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
parts.push({ type: "text", text: JSON.stringify(item) });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
parts.push({ type: "text", text: String(item) });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return parts;
|
|
218
|
+
}
|
|
219
|
+
// Plain string
|
|
220
|
+
if (typeof toolResult === "string") {
|
|
221
|
+
return [{ type: "text", text: toolResult }];
|
|
222
|
+
}
|
|
223
|
+
// Anything else (dict without resource_link type, number, etc.)
|
|
224
|
+
try {
|
|
225
|
+
const text = JSON.stringify(toolResult);
|
|
226
|
+
return [{ type: "text", text }];
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
return [{ type: "text", text: String(toolResult) }];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/** Vendors that do NOT support images in tool/function result messages. */
|
|
233
|
+
export const TOOL_IMAGE_UNSUPPORTED_VENDORS = new Set(["openai", "gemini", "google"]);
|
|
234
|
+
/**
|
|
235
|
+
* Resolve resource_links for inclusion in a tool result message.
|
|
236
|
+
*
|
|
237
|
+
* For vendors that support images in tool messages (Anthropic/Claude),
|
|
238
|
+
* returns the full multimodal content (text + image parts).
|
|
239
|
+
*
|
|
240
|
+
* For vendors that do NOT support images in tool messages (OpenAI, Gemini),
|
|
241
|
+
* returns text-only content with descriptive placeholders. The actual image
|
|
242
|
+
* should be injected via a separate user message using
|
|
243
|
+
* `resolveMediaAsUserMessage()`.
|
|
244
|
+
*
|
|
245
|
+
* @param toolResult - Raw tool result
|
|
246
|
+
* @param vendor - e.g. "anthropic", "openai", "gemini"
|
|
247
|
+
* @returns Content parts suitable for a tool result message
|
|
248
|
+
*/
|
|
249
|
+
export async function resolveResourceLinksForToolMessage(toolResult, vendor) {
|
|
250
|
+
if (!TOOL_IMAGE_UNSUPPORTED_VENDORS.has(vendor)) {
|
|
251
|
+
return resolveResourceLinks(toolResult, vendor);
|
|
252
|
+
}
|
|
253
|
+
const parts = await resolveResourceLinks(toolResult, vendor);
|
|
254
|
+
return parts.map((part) => {
|
|
255
|
+
if (part.type === "image" || part.type === "image_url") {
|
|
256
|
+
return { type: "text", text: "[Image content — see next message]" };
|
|
257
|
+
}
|
|
258
|
+
return part;
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Return a user message containing resolved images from a tool result.
|
|
263
|
+
*
|
|
264
|
+
* For vendors that do NOT support images in tool messages (OpenAI, Gemini),
|
|
265
|
+
* resolves resource_link items and packages the image parts into a
|
|
266
|
+
* `role: "user"` message that can be appended after the tool result message.
|
|
267
|
+
*
|
|
268
|
+
* For vendors that support images in tool messages (Anthropic), returns null.
|
|
269
|
+
*
|
|
270
|
+
* @param toolResult - Raw tool result
|
|
271
|
+
* @param vendor - e.g. "anthropic", "openai", "gemini"
|
|
272
|
+
* @returns A user message object with image content, or null
|
|
273
|
+
*/
|
|
274
|
+
export async function resolveMediaAsUserMessage(toolResult, vendor) {
|
|
275
|
+
if (!TOOL_IMAGE_UNSUPPORTED_VENDORS.has(vendor)) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
const parts = await resolveResourceLinks(toolResult, vendor);
|
|
279
|
+
const imageParts = parts.filter((p) => p.type === "image" || p.type === "image_url");
|
|
280
|
+
if (imageParts.length === 0) {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
role: "user",
|
|
285
|
+
content: [
|
|
286
|
+
{ type: "text", text: "The tool returned this image:" },
|
|
287
|
+
...imageParts,
|
|
288
|
+
],
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Quick check whether a tool result contains any resource_link items.
|
|
293
|
+
*
|
|
294
|
+
* This is a lightweight synchronous check used to decide whether the
|
|
295
|
+
* more expensive async resolution is needed.
|
|
296
|
+
*/
|
|
297
|
+
export function hasResourceLink(toolResult) {
|
|
298
|
+
if (!toolResult || typeof toolResult !== "object") {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
const obj = toolResult;
|
|
302
|
+
if (obj.type === "resource_link") {
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
if (obj.type === "multi_content") {
|
|
306
|
+
const items = (obj.items ?? obj.content ?? []);
|
|
307
|
+
return items.some((i) => i && typeof i === "object" && i.type === "resource_link");
|
|
308
|
+
}
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../src/media/resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,KAAK,GAAG,WAAW,CAAC,gBAAgB,CAAC,CAAC;AAE5C,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC;AAEzF,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC;AAEpD,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC9B,YAAY;IACZ,UAAU;IACV,eAAe;IACf,WAAW;IACX,UAAU;IACV,kBAAkB;IAClB,iBAAiB;IACjB,iBAAiB;CAClB,CAAC,CAAC;AAOH,SAAS,eAAe,CAAC,GAAW,EAAE,QAAgB;IACpD,OAAO;QACL,IAAI,EAAE,OAAO;QACb,MAAM,EAAE;YACN,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,QAAQ;YACpB,IAAI,EAAE,GAAG;SACV;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAW,EAAE,QAAgB;IAC3D,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,SAAS,EAAE;YACT,GAAG,EAAE,QAAQ,QAAQ,WAAW,GAAG,EAAE;YACrC,MAAM,EAA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,EAAE,CAAc,CAAC;QAC5D,OAAO,KAAK,CAAC,IAAI,CACf,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAK,CAA6B,CAAC,IAAI,KAAK,eAAe,CACxF,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema post-processing for media-typed tool parameters.
|
|
3
|
+
*
|
|
4
|
+
* Detects the "[media:TYPE]" convention in property descriptions
|
|
5
|
+
* (set by mediaParam() in types.ts) and enriches the JSON Schema
|
|
6
|
+
* with x-media-type annotations for LLM tool discovery.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Post-process a JSON Schema to enrich properties that use the
|
|
10
|
+
* [media:TYPE] description convention with x-media-type annotations.
|
|
11
|
+
*
|
|
12
|
+
* Modifies the schema in place.
|
|
13
|
+
*
|
|
14
|
+
* @param schema - JSON Schema object (from zodToJsonSchema)
|
|
15
|
+
*/
|
|
16
|
+
export declare function enrichSchemaWithMediaTypes(schema: Record<string, unknown>): void;
|
|
17
|
+
//# sourceMappingURL=media-param.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-param.d.ts","sourceRoot":"","sources":["../src/media-param.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAgBhF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema post-processing for media-typed tool parameters.
|
|
3
|
+
*
|
|
4
|
+
* Detects the "[media:TYPE]" convention in property descriptions
|
|
5
|
+
* (set by mediaParam() in types.ts) and enriches the JSON Schema
|
|
6
|
+
* with x-media-type annotations for LLM tool discovery.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Post-process a JSON Schema to enrich properties that use the
|
|
10
|
+
* [media:TYPE] description convention with x-media-type annotations.
|
|
11
|
+
*
|
|
12
|
+
* Modifies the schema in place.
|
|
13
|
+
*
|
|
14
|
+
* @param schema - JSON Schema object (from zodToJsonSchema)
|
|
15
|
+
*/
|
|
16
|
+
export function enrichSchemaWithMediaTypes(schema) {
|
|
17
|
+
const properties = schema?.properties;
|
|
18
|
+
if (!properties)
|
|
19
|
+
return;
|
|
20
|
+
for (const [, prop] of Object.entries(properties)) {
|
|
21
|
+
const desc = prop?.description;
|
|
22
|
+
if (typeof desc === "string") {
|
|
23
|
+
const match = desc.match(/^\[media:([^\]]+)\]\s*/);
|
|
24
|
+
if (match) {
|
|
25
|
+
prop["x-media-type"] = match[1];
|
|
26
|
+
prop.description = desc.replace(/^\[media:[^\]]+\]\s*/, "")
|
|
27
|
+
+ ` (accepts media URI: ${match[1]})`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=media-param.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-param.js","sourceRoot":"","sources":["../src/media-param.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAA+B;IACtE,MAAM,UAAU,GAAI,MAAkC,EAAE,UACD,CAAC;IACxD,IAAI,CAAC,UAAU;QAAE,OAAO;IAExB,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,GAAG,IAAI,EAAE,WAAW,CAAC;QAC/B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;YACnD,IAAI,KAAK,EAAE,CAAC;gBACR,IAAI,CAAC,cAAc,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;gBAChC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC;sBACrD,wBAAwB,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;YAC9C,CAAC;QACL,CAAC;IACL,CAAC;AACL,CAAC"}
|
|
@@ -4,16 +4,17 @@
|
|
|
4
4
|
* Optimized for Claude API (Claude 3.x, Sonnet, Opus, Haiku)
|
|
5
5
|
* using Anthropic's best practices for tool calling and JSON responses.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
7
|
+
* Dual output strategy (matching Python SDK):
|
|
8
|
+
* - formatSystemPrompt (direct calls): HINT mode — prompt-based JSON instructions
|
|
9
|
+
* with DECISION GUIDE for callers that don't control the provider-side API call.
|
|
10
|
+
* - prepareRequest (mesh delegation): native response_format with strict JSON schema
|
|
11
|
+
* for provider-side enforcement. The caller controls the full API call and can
|
|
12
|
+
* pass response_format directly to the Anthropic API.
|
|
13
13
|
*
|
|
14
14
|
* Features:
|
|
15
15
|
* - Anti-XML tool calling instructions
|
|
16
16
|
* - DECISION GUIDE for tool vs. direct JSON response decisions
|
|
17
|
+
* - Native response_format for structured output in mesh delegation
|
|
17
18
|
*
|
|
18
19
|
* Note: Prompt caching is not yet implemented for AI SDK v6.
|
|
19
20
|
* TODO: Re-enable via experimental_providerOptions when AI SDK v6 supports it.
|
|
@@ -28,13 +29,12 @@ import { type ProviderHandler, type VendorCapabilities, type ToolSchema, type Ou
|
|
|
28
29
|
* - Native tool calling (via Anthropic messages API)
|
|
29
30
|
* - Performs best with anti-XML tool calling instructions
|
|
30
31
|
*
|
|
31
|
-
*
|
|
32
|
-
* -
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* without cross-runtime incompatibilities and grammar compilation overhead.
|
|
32
|
+
* Dual output strategy (matching Python SDK):
|
|
33
|
+
* - formatSystemPrompt: Adds brief JSON note in strict mode, detailed HINT
|
|
34
|
+
* instructions in hint mode. Used for belt-and-suspenders prompt guidance.
|
|
35
|
+
* - prepareRequest: Sets native response_format with strict JSON schema when
|
|
36
|
+
* outputMode is "strict". Used for mesh delegation where the provider
|
|
37
|
+
* controls the full API call.
|
|
38
38
|
*
|
|
39
39
|
* Best Practices (from Anthropic docs):
|
|
40
40
|
* - Add anti-XML instructions to prevent <invoke> style tool calls
|
|
@@ -45,7 +45,8 @@ export declare class ClaudeHandler implements ProviderHandler {
|
|
|
45
45
|
/**
|
|
46
46
|
* Prepare request parameters for Claude API with output mode support.
|
|
47
47
|
*
|
|
48
|
-
* Output Mode Strategy
|
|
48
|
+
* Output Mode Strategy:
|
|
49
|
+
* - strict: Set response_format with strict JSON schema (native enforcement)
|
|
49
50
|
* - hint: No response_format, rely on prompt instructions (~95% reliable)
|
|
50
51
|
* - text: No response_format, plain text output (fastest)
|
|
51
52
|
*
|
|
@@ -64,7 +65,8 @@ export declare class ClaudeHandler implements ProviderHandler {
|
|
|
64
65
|
/**
|
|
65
66
|
* Format system prompt for Claude with output mode support.
|
|
66
67
|
*
|
|
67
|
-
* Output Mode Strategy
|
|
68
|
+
* Output Mode Strategy:
|
|
69
|
+
* - strict: Brief JSON note (response_format handles schema enforcement)
|
|
68
70
|
* - hint: Add detailed JSON schema instructions with DECISION GUIDE in prompt
|
|
69
71
|
* - text: No JSON instructions (plain text output)
|
|
70
72
|
*/
|
|
@@ -74,18 +76,11 @@ export declare class ClaudeHandler implements ProviderHandler {
|
|
|
74
76
|
*/
|
|
75
77
|
getCapabilities(): VendorCapabilities;
|
|
76
78
|
/**
|
|
77
|
-
* Determine the output mode
|
|
78
|
-
*
|
|
79
|
-
* Claude Strategy (Option A):
|
|
80
|
-
* - Always use "hint" mode (prompt-based) for schemas, never "strict"
|
|
81
|
-
* - Vercel AI SDK's generateObject() for Anthropic has issues with nested schemas
|
|
82
|
-
* - Anthropic's native structured output is slow and requires beta header
|
|
83
|
-
* - Prompt-based JSON instructions are fast and ~95% reliable for Claude
|
|
79
|
+
* Determine the optimal output mode for Claude.
|
|
84
80
|
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* -
|
|
88
|
-
* - If schema exists, always use "hint" mode (prompt-based)
|
|
81
|
+
* Uses the default implementation which returns "strict" for schemas.
|
|
82
|
+
* This enables native response_format enforcement in mesh delegation
|
|
83
|
+
* (provider-side), matching the Python SDK behavior.
|
|
89
84
|
*/
|
|
90
85
|
determineOutputMode(outputSchema: OutputSchema | null, overrideMode?: OutputMode): OutputMode;
|
|
91
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-handler.d.ts","sourceRoot":"","sources":["../../src/provider-handlers/claude-handler.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"claude-handler.d.ts","sourceRoot":"","sources":["../../src/provider-handlers/claude-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAOL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,UAAU,EAChB,MAAM,uBAAuB,CAAC;AAS/B;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,aAAc,YAAW,eAAe;IACnD,QAAQ,CAAC,MAAM,eAAe;IAE9B;;;;;;;;;;;;OAYG;IACH,cAAc,CACZ,QAAQ,EAAE,UAAU,EAAE,EACtB,KAAK,EAAE,UAAU,EAAE,GAAG,IAAI,EAC1B,YAAY,EAAE,YAAY,GAAG,IAAI,EACjC,OAAO,CAAC,EAAE;QACR,UAAU,CAAC,EAAE,UAAU,CAAC;QACxB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,GACA,eAAe;IAyDlB;;;;;;;OAOG;IACH,kBAAkB,CAChB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,UAAU,EAAE,GAAG,IAAI,EAChC,YAAY,EAAE,YAAY,GAAG,IAAI,EACjC,UAAU,CAAC,EAAE,UAAU,GACtB,MAAM;IA8FT;;OAEG;IACH,eAAe,IAAI,kBAAkB;IAWrC;;;;;;OAMG;IACH,mBAAmB,CACjB,YAAY,EAAE,YAAY,GAAG,IAAI,EACjC,YAAY,CAAC,EAAE,UAAU,GACxB,UAAU;CAId"}
|