@ai-sdk/anthropic 3.0.0-beta.92 → 3.0.0-beta.94
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/CHANGELOG.md +16 -0
- package/dist/index.d.mts +49 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.js +359 -78
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +357 -77
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +43 -3
- package/dist/internal/index.d.ts +43 -3
- package/dist/internal/index.js +334 -75
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +334 -75
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/internal/index.js
CHANGED
|
@@ -49,29 +49,6 @@ var anthropicFailedResponseHandler = (0, import_provider_utils.createJsonErrorRe
|
|
|
49
49
|
errorToMessage: (data) => data.error.message
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
// src/convert-anthropic-messages-usage.ts
|
|
53
|
-
function convertAnthropicMessagesUsage(usage) {
|
|
54
|
-
var _a, _b;
|
|
55
|
-
const inputTokens = usage.input_tokens;
|
|
56
|
-
const outputTokens = usage.output_tokens;
|
|
57
|
-
const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
|
|
58
|
-
const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
|
|
59
|
-
return {
|
|
60
|
-
inputTokens: {
|
|
61
|
-
total: inputTokens + cacheCreationTokens + cacheReadTokens,
|
|
62
|
-
noCache: inputTokens,
|
|
63
|
-
cacheRead: cacheReadTokens,
|
|
64
|
-
cacheWrite: cacheCreationTokens
|
|
65
|
-
},
|
|
66
|
-
outputTokens: {
|
|
67
|
-
total: outputTokens,
|
|
68
|
-
text: void 0,
|
|
69
|
-
reasoning: void 0
|
|
70
|
-
},
|
|
71
|
-
raw: usage
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
52
|
// src/anthropic-messages-api.ts
|
|
76
53
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
77
54
|
var import_v42 = require("zod/v4");
|
|
@@ -127,7 +104,17 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
127
104
|
type: import_v42.z.literal("tool_use"),
|
|
128
105
|
id: import_v42.z.string(),
|
|
129
106
|
name: import_v42.z.string(),
|
|
130
|
-
input: import_v42.z.unknown()
|
|
107
|
+
input: import_v42.z.unknown(),
|
|
108
|
+
// Programmatic tool calling: caller info when triggered from code execution
|
|
109
|
+
caller: import_v42.z.union([
|
|
110
|
+
import_v42.z.object({
|
|
111
|
+
type: import_v42.z.literal("code_execution_20250825"),
|
|
112
|
+
tool_id: import_v42.z.string()
|
|
113
|
+
}),
|
|
114
|
+
import_v42.z.object({
|
|
115
|
+
type: import_v42.z.literal("direct")
|
|
116
|
+
})
|
|
117
|
+
]).optional()
|
|
131
118
|
}),
|
|
132
119
|
import_v42.z.object({
|
|
133
120
|
type: import_v42.z.literal("server_tool_use"),
|
|
@@ -213,7 +200,13 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
213
200
|
type: import_v42.z.literal("code_execution_result"),
|
|
214
201
|
stdout: import_v42.z.string(),
|
|
215
202
|
stderr: import_v42.z.string(),
|
|
216
|
-
return_code: import_v42.z.number()
|
|
203
|
+
return_code: import_v42.z.number(),
|
|
204
|
+
content: import_v42.z.array(
|
|
205
|
+
import_v42.z.object({
|
|
206
|
+
type: import_v42.z.literal("code_execution_output"),
|
|
207
|
+
file_id: import_v42.z.string()
|
|
208
|
+
})
|
|
209
|
+
).optional().default([])
|
|
217
210
|
}),
|
|
218
211
|
import_v42.z.object({
|
|
219
212
|
type: import_v42.z.literal("code_execution_tool_result_error"),
|
|
@@ -345,11 +338,37 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
345
338
|
message: import_v42.z.object({
|
|
346
339
|
id: import_v42.z.string().nullish(),
|
|
347
340
|
model: import_v42.z.string().nullish(),
|
|
341
|
+
role: import_v42.z.string().nullish(),
|
|
348
342
|
usage: import_v42.z.looseObject({
|
|
349
343
|
input_tokens: import_v42.z.number(),
|
|
350
344
|
cache_creation_input_tokens: import_v42.z.number().nullish(),
|
|
351
345
|
cache_read_input_tokens: import_v42.z.number().nullish()
|
|
352
|
-
})
|
|
346
|
+
}),
|
|
347
|
+
// Programmatic tool calling: content may be pre-populated for deferred tool calls
|
|
348
|
+
content: import_v42.z.array(
|
|
349
|
+
import_v42.z.discriminatedUnion("type", [
|
|
350
|
+
import_v42.z.object({
|
|
351
|
+
type: import_v42.z.literal("tool_use"),
|
|
352
|
+
id: import_v42.z.string(),
|
|
353
|
+
name: import_v42.z.string(),
|
|
354
|
+
input: import_v42.z.unknown(),
|
|
355
|
+
caller: import_v42.z.union([
|
|
356
|
+
import_v42.z.object({
|
|
357
|
+
type: import_v42.z.literal("code_execution_20250825"),
|
|
358
|
+
tool_id: import_v42.z.string()
|
|
359
|
+
}),
|
|
360
|
+
import_v42.z.object({
|
|
361
|
+
type: import_v42.z.literal("direct")
|
|
362
|
+
})
|
|
363
|
+
]).optional()
|
|
364
|
+
})
|
|
365
|
+
])
|
|
366
|
+
).nullish(),
|
|
367
|
+
stop_reason: import_v42.z.string().nullish(),
|
|
368
|
+
container: import_v42.z.object({
|
|
369
|
+
expires_at: import_v42.z.string(),
|
|
370
|
+
id: import_v42.z.string()
|
|
371
|
+
}).nullish()
|
|
353
372
|
})
|
|
354
373
|
}),
|
|
355
374
|
import_v42.z.object({
|
|
@@ -367,7 +386,19 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
367
386
|
import_v42.z.object({
|
|
368
387
|
type: import_v42.z.literal("tool_use"),
|
|
369
388
|
id: import_v42.z.string(),
|
|
370
|
-
name: import_v42.z.string()
|
|
389
|
+
name: import_v42.z.string(),
|
|
390
|
+
// Programmatic tool calling: input may be present directly for deferred tool calls
|
|
391
|
+
input: import_v42.z.record(import_v42.z.string(), import_v42.z.unknown()).optional(),
|
|
392
|
+
// Programmatic tool calling: caller info when triggered from code execution
|
|
393
|
+
caller: import_v42.z.union([
|
|
394
|
+
import_v42.z.object({
|
|
395
|
+
type: import_v42.z.literal("code_execution_20250825"),
|
|
396
|
+
tool_id: import_v42.z.string()
|
|
397
|
+
}),
|
|
398
|
+
import_v42.z.object({
|
|
399
|
+
type: import_v42.z.literal("direct")
|
|
400
|
+
})
|
|
401
|
+
]).optional()
|
|
371
402
|
}),
|
|
372
403
|
import_v42.z.object({
|
|
373
404
|
type: import_v42.z.literal("redacted_thinking"),
|
|
@@ -457,7 +488,13 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
457
488
|
type: import_v42.z.literal("code_execution_result"),
|
|
458
489
|
stdout: import_v42.z.string(),
|
|
459
490
|
stderr: import_v42.z.string(),
|
|
460
|
-
return_code: import_v42.z.number()
|
|
491
|
+
return_code: import_v42.z.number(),
|
|
492
|
+
content: import_v42.z.array(
|
|
493
|
+
import_v42.z.object({
|
|
494
|
+
type: import_v42.z.literal("code_execution_output"),
|
|
495
|
+
file_id: import_v42.z.string()
|
|
496
|
+
})
|
|
497
|
+
).optional().default([])
|
|
461
498
|
}),
|
|
462
499
|
import_v42.z.object({
|
|
463
500
|
type: import_v42.z.literal("code_execution_tool_result_error"),
|
|
@@ -1018,6 +1055,7 @@ async function prepareTools({
|
|
|
1018
1055
|
});
|
|
1019
1056
|
const anthropicOptions = (_a = tool.providerOptions) == null ? void 0 : _a.anthropic;
|
|
1020
1057
|
const deferLoading = anthropicOptions == null ? void 0 : anthropicOptions.deferLoading;
|
|
1058
|
+
const allowedCallers = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers;
|
|
1021
1059
|
anthropicTools2.push({
|
|
1022
1060
|
name: tool.name,
|
|
1023
1061
|
description: tool.description,
|
|
@@ -1025,6 +1063,7 @@ async function prepareTools({
|
|
|
1025
1063
|
cache_control: cacheControl,
|
|
1026
1064
|
...supportsStructuredOutput === true && tool.strict != null ? { strict: tool.strict } : {},
|
|
1027
1065
|
...deferLoading != null ? { defer_loading: deferLoading } : {},
|
|
1066
|
+
...allowedCallers != null ? { allowed_callers: allowedCallers } : {},
|
|
1028
1067
|
...tool.inputExamples != null ? {
|
|
1029
1068
|
input_examples: tool.inputExamples.map(
|
|
1030
1069
|
(example) => example.input
|
|
@@ -1034,7 +1073,7 @@ async function prepareTools({
|
|
|
1034
1073
|
if (supportsStructuredOutput === true) {
|
|
1035
1074
|
betas.add("structured-outputs-2025-11-13");
|
|
1036
1075
|
}
|
|
1037
|
-
if (tool.inputExamples != null) {
|
|
1076
|
+
if (tool.inputExamples != null || allowedCallers != null) {
|
|
1038
1077
|
betas.add("advanced-tool-use-2025-11-20");
|
|
1039
1078
|
}
|
|
1040
1079
|
break;
|
|
@@ -1269,6 +1308,29 @@ async function prepareTools({
|
|
|
1269
1308
|
}
|
|
1270
1309
|
}
|
|
1271
1310
|
|
|
1311
|
+
// src/convert-anthropic-messages-usage.ts
|
|
1312
|
+
function convertAnthropicMessagesUsage(usage) {
|
|
1313
|
+
var _a, _b;
|
|
1314
|
+
const inputTokens = usage.input_tokens;
|
|
1315
|
+
const outputTokens = usage.output_tokens;
|
|
1316
|
+
const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
|
|
1317
|
+
const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
|
|
1318
|
+
return {
|
|
1319
|
+
inputTokens: {
|
|
1320
|
+
total: inputTokens + cacheCreationTokens + cacheReadTokens,
|
|
1321
|
+
noCache: inputTokens,
|
|
1322
|
+
cacheRead: cacheReadTokens,
|
|
1323
|
+
cacheWrite: cacheCreationTokens
|
|
1324
|
+
},
|
|
1325
|
+
outputTokens: {
|
|
1326
|
+
total: outputTokens,
|
|
1327
|
+
text: void 0,
|
|
1328
|
+
reasoning: void 0
|
|
1329
|
+
},
|
|
1330
|
+
raw: usage
|
|
1331
|
+
};
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1272
1334
|
// src/convert-to-anthropic-messages-prompt.ts
|
|
1273
1335
|
var import_provider2 = require("@ai-sdk/provider");
|
|
1274
1336
|
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
|
@@ -1282,7 +1344,13 @@ var codeExecution_20250522OutputSchema = (0, import_provider_utils8.lazySchema)(
|
|
|
1282
1344
|
type: import_v47.z.literal("code_execution_result"),
|
|
1283
1345
|
stdout: import_v47.z.string(),
|
|
1284
1346
|
stderr: import_v47.z.string(),
|
|
1285
|
-
return_code: import_v47.z.number()
|
|
1347
|
+
return_code: import_v47.z.number(),
|
|
1348
|
+
content: import_v47.z.array(
|
|
1349
|
+
import_v47.z.object({
|
|
1350
|
+
type: import_v47.z.literal("code_execution_output"),
|
|
1351
|
+
file_id: import_v47.z.string()
|
|
1352
|
+
})
|
|
1353
|
+
).optional().default([])
|
|
1286
1354
|
})
|
|
1287
1355
|
)
|
|
1288
1356
|
);
|
|
@@ -1308,6 +1376,18 @@ var import_v48 = require("zod/v4");
|
|
|
1308
1376
|
var codeExecution_20250825OutputSchema = (0, import_provider_utils9.lazySchema)(
|
|
1309
1377
|
() => (0, import_provider_utils9.zodSchema)(
|
|
1310
1378
|
import_v48.z.discriminatedUnion("type", [
|
|
1379
|
+
import_v48.z.object({
|
|
1380
|
+
type: import_v48.z.literal("code_execution_result"),
|
|
1381
|
+
stdout: import_v48.z.string(),
|
|
1382
|
+
stderr: import_v48.z.string(),
|
|
1383
|
+
return_code: import_v48.z.number(),
|
|
1384
|
+
content: import_v48.z.array(
|
|
1385
|
+
import_v48.z.object({
|
|
1386
|
+
type: import_v48.z.literal("code_execution_output"),
|
|
1387
|
+
file_id: import_v48.z.string()
|
|
1388
|
+
})
|
|
1389
|
+
).optional().default([])
|
|
1390
|
+
}),
|
|
1311
1391
|
import_v48.z.object({
|
|
1312
1392
|
type: import_v48.z.literal("bash_code_execution_result"),
|
|
1313
1393
|
content: import_v48.z.array(
|
|
@@ -1354,6 +1434,11 @@ var codeExecution_20250825OutputSchema = (0, import_provider_utils9.lazySchema)(
|
|
|
1354
1434
|
var codeExecution_20250825InputSchema = (0, import_provider_utils9.lazySchema)(
|
|
1355
1435
|
() => (0, import_provider_utils9.zodSchema)(
|
|
1356
1436
|
import_v48.z.discriminatedUnion("type", [
|
|
1437
|
+
// Programmatic tool calling format (mapped from { code } by AI SDK)
|
|
1438
|
+
import_v48.z.object({
|
|
1439
|
+
type: import_v48.z.literal("programmatic-tool-call"),
|
|
1440
|
+
code: import_v48.z.string()
|
|
1441
|
+
}),
|
|
1357
1442
|
import_v48.z.object({
|
|
1358
1443
|
type: import_v48.z.literal("bash_code_execution"),
|
|
1359
1444
|
command: import_v48.z.string()
|
|
@@ -1384,7 +1469,11 @@ var codeExecution_20250825InputSchema = (0, import_provider_utils9.lazySchema)(
|
|
|
1384
1469
|
var factory5 = (0, import_provider_utils9.createProviderToolFactoryWithOutputSchema)({
|
|
1385
1470
|
id: "anthropic.code_execution_20250825",
|
|
1386
1471
|
inputSchema: codeExecution_20250825InputSchema,
|
|
1387
|
-
outputSchema: codeExecution_20250825OutputSchema
|
|
1472
|
+
outputSchema: codeExecution_20250825OutputSchema,
|
|
1473
|
+
// Programmatic tool calling: tool results may be deferred to a later turn
|
|
1474
|
+
// when code execution triggers a client-executed tool that needs to be
|
|
1475
|
+
// resolved before the code execution result can be returned.
|
|
1476
|
+
supportsDeferredResults: true
|
|
1388
1477
|
});
|
|
1389
1478
|
var codeExecution_20250825 = (args = {}) => {
|
|
1390
1479
|
return factory5(args);
|
|
@@ -1457,7 +1546,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1457
1546
|
cacheControlValidator,
|
|
1458
1547
|
toolNameMapping
|
|
1459
1548
|
}) {
|
|
1460
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1549
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1461
1550
|
const betas = /* @__PURE__ */ new Set();
|
|
1462
1551
|
const blocks = groupIntoBlocks(prompt);
|
|
1463
1552
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -1827,6 +1916,19 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1827
1916
|
input: part.input,
|
|
1828
1917
|
cache_control: cacheControl
|
|
1829
1918
|
});
|
|
1919
|
+
} else if (
|
|
1920
|
+
// code execution 20250825 programmatic tool calling:
|
|
1921
|
+
// Strip the fake 'programmatic-tool-call' type before sending to Anthropic
|
|
1922
|
+
providerToolName === "code_execution" && part.input != null && typeof part.input === "object" && "type" in part.input && part.input.type === "programmatic-tool-call"
|
|
1923
|
+
) {
|
|
1924
|
+
const { type: _, ...inputWithoutType } = part.input;
|
|
1925
|
+
anthropicContent.push({
|
|
1926
|
+
type: "server_tool_use",
|
|
1927
|
+
id: part.toolCallId,
|
|
1928
|
+
name: "code_execution",
|
|
1929
|
+
input: inputWithoutType,
|
|
1930
|
+
cache_control: cacheControl
|
|
1931
|
+
});
|
|
1830
1932
|
} else {
|
|
1831
1933
|
if (providerToolName === "code_execution" || // code execution 20250522
|
|
1832
1934
|
providerToolName === "web_fetch" || providerToolName === "web_search") {
|
|
@@ -1854,11 +1956,17 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1854
1956
|
}
|
|
1855
1957
|
break;
|
|
1856
1958
|
}
|
|
1959
|
+
const callerOptions = (_k = part.providerOptions) == null ? void 0 : _k.anthropic;
|
|
1960
|
+
const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? callerOptions.caller.type === "code_execution_20250825" && callerOptions.caller.toolId ? {
|
|
1961
|
+
type: "code_execution_20250825",
|
|
1962
|
+
tool_id: callerOptions.caller.toolId
|
|
1963
|
+
} : callerOptions.caller.type === "direct" ? { type: "direct" } : void 0 : void 0;
|
|
1857
1964
|
anthropicContent.push({
|
|
1858
1965
|
type: "tool_use",
|
|
1859
1966
|
id: part.toolCallId,
|
|
1860
1967
|
name: part.toolName,
|
|
1861
1968
|
input: part.input,
|
|
1969
|
+
...caller && { caller },
|
|
1862
1970
|
cache_control: cacheControl
|
|
1863
1971
|
});
|
|
1864
1972
|
break;
|
|
@@ -1885,6 +1993,39 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1885
1993
|
});
|
|
1886
1994
|
} else if (providerToolName === "code_execution") {
|
|
1887
1995
|
const output = part.output;
|
|
1996
|
+
if (output.type === "error-text" || output.type === "error-json") {
|
|
1997
|
+
let errorInfo = {};
|
|
1998
|
+
try {
|
|
1999
|
+
if (typeof output.value === "string") {
|
|
2000
|
+
errorInfo = JSON.parse(output.value);
|
|
2001
|
+
} else if (typeof output.value === "object" && output.value !== null) {
|
|
2002
|
+
errorInfo = output.value;
|
|
2003
|
+
}
|
|
2004
|
+
} catch (e) {
|
|
2005
|
+
}
|
|
2006
|
+
if (errorInfo.type === "code_execution_tool_result_error") {
|
|
2007
|
+
anthropicContent.push({
|
|
2008
|
+
type: "code_execution_tool_result",
|
|
2009
|
+
tool_use_id: part.toolCallId,
|
|
2010
|
+
content: {
|
|
2011
|
+
type: "code_execution_tool_result_error",
|
|
2012
|
+
error_code: (_l = errorInfo.errorCode) != null ? _l : "unknown"
|
|
2013
|
+
},
|
|
2014
|
+
cache_control: cacheControl
|
|
2015
|
+
});
|
|
2016
|
+
} else {
|
|
2017
|
+
anthropicContent.push({
|
|
2018
|
+
type: "bash_code_execution_tool_result",
|
|
2019
|
+
tool_use_id: part.toolCallId,
|
|
2020
|
+
cache_control: cacheControl,
|
|
2021
|
+
content: {
|
|
2022
|
+
type: "bash_code_execution_tool_result_error",
|
|
2023
|
+
error_code: (_m = errorInfo.errorCode) != null ? _m : "unknown"
|
|
2024
|
+
}
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
break;
|
|
2028
|
+
}
|
|
1888
2029
|
if (output.type !== "json") {
|
|
1889
2030
|
warnings.push({
|
|
1890
2031
|
type: "other",
|
|
@@ -1911,7 +2052,8 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1911
2052
|
type: codeExecutionOutput.type,
|
|
1912
2053
|
stdout: codeExecutionOutput.stdout,
|
|
1913
2054
|
stderr: codeExecutionOutput.stderr,
|
|
1914
|
-
return_code: codeExecutionOutput.return_code
|
|
2055
|
+
return_code: codeExecutionOutput.return_code,
|
|
2056
|
+
content: (_n = codeExecutionOutput.content) != null ? _n : []
|
|
1915
2057
|
},
|
|
1916
2058
|
cache_control: cacheControl
|
|
1917
2059
|
});
|
|
@@ -1920,19 +2062,34 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1920
2062
|
value: output.value,
|
|
1921
2063
|
schema: codeExecution_20250825OutputSchema
|
|
1922
2064
|
});
|
|
1923
|
-
|
|
1924
|
-
|
|
2065
|
+
if (codeExecutionOutput.type === "code_execution_result") {
|
|
2066
|
+
anthropicContent.push({
|
|
2067
|
+
type: "code_execution_tool_result",
|
|
2068
|
+
tool_use_id: part.toolCallId,
|
|
2069
|
+
content: {
|
|
2070
|
+
type: codeExecutionOutput.type,
|
|
2071
|
+
stdout: codeExecutionOutput.stdout,
|
|
2072
|
+
stderr: codeExecutionOutput.stderr,
|
|
2073
|
+
return_code: codeExecutionOutput.return_code,
|
|
2074
|
+
content: (_o = codeExecutionOutput.content) != null ? _o : []
|
|
2075
|
+
},
|
|
2076
|
+
cache_control: cacheControl
|
|
2077
|
+
});
|
|
2078
|
+
} else if (codeExecutionOutput.type === "bash_code_execution_result" || codeExecutionOutput.type === "bash_code_execution_tool_result_error") {
|
|
2079
|
+
anthropicContent.push({
|
|
1925
2080
|
type: "bash_code_execution_tool_result",
|
|
1926
2081
|
tool_use_id: part.toolCallId,
|
|
1927
2082
|
cache_control: cacheControl,
|
|
1928
2083
|
content: codeExecutionOutput
|
|
1929
|
-
}
|
|
2084
|
+
});
|
|
2085
|
+
} else {
|
|
2086
|
+
anthropicContent.push({
|
|
1930
2087
|
type: "text_editor_code_execution_tool_result",
|
|
1931
2088
|
tool_use_id: part.toolCallId,
|
|
1932
2089
|
cache_control: cacheControl,
|
|
1933
2090
|
content: codeExecutionOutput
|
|
1934
|
-
}
|
|
1935
|
-
|
|
2091
|
+
});
|
|
2092
|
+
}
|
|
1936
2093
|
}
|
|
1937
2094
|
break;
|
|
1938
2095
|
}
|
|
@@ -2184,7 +2341,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2184
2341
|
providerOptions,
|
|
2185
2342
|
stream
|
|
2186
2343
|
}) {
|
|
2187
|
-
var _a, _b, _c, _d, _e, _f
|
|
2344
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2188
2345
|
const warnings = [];
|
|
2189
2346
|
if (frequencyPenalty != null) {
|
|
2190
2347
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -2306,16 +2463,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2306
2463
|
} : void 0
|
|
2307
2464
|
}))
|
|
2308
2465
|
},
|
|
2309
|
-
// container
|
|
2466
|
+
// container: For programmatic tool calling (just an ID string) or agent skills (object with id and skills)
|
|
2310
2467
|
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
2311
|
-
container:
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2468
|
+
container: anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0 ? (
|
|
2469
|
+
// Object format when skills are provided (agent skills feature)
|
|
2470
|
+
{
|
|
2471
|
+
id: anthropicOptions.container.id,
|
|
2472
|
+
skills: anthropicOptions.container.skills.map((skill) => ({
|
|
2473
|
+
type: skill.type,
|
|
2474
|
+
skill_id: skill.skillId,
|
|
2475
|
+
version: skill.version
|
|
2476
|
+
}))
|
|
2477
|
+
}
|
|
2478
|
+
) : (
|
|
2479
|
+
// String format for container ID only (programmatic tool calling)
|
|
2480
|
+
anthropicOptions.container.id
|
|
2481
|
+
)
|
|
2319
2482
|
},
|
|
2320
2483
|
// prompt:
|
|
2321
2484
|
system: messagesPrompt.system,
|
|
@@ -2429,7 +2592,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2429
2592
|
if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
|
|
2430
2593
|
betas.add("effort-2025-11-24");
|
|
2431
2594
|
}
|
|
2432
|
-
if (stream && ((
|
|
2595
|
+
if (stream && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _f : true)) {
|
|
2433
2596
|
betas.add("fine-grained-tool-streaming-2025-05-14");
|
|
2434
2597
|
}
|
|
2435
2598
|
const usingNativeOutputFormat = useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
|
|
@@ -2525,7 +2688,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2525
2688
|
});
|
|
2526
2689
|
}
|
|
2527
2690
|
async doGenerate(options) {
|
|
2528
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2691
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2529
2692
|
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
|
|
2530
2693
|
...options,
|
|
2531
2694
|
stream: false,
|
|
@@ -2603,11 +2766,23 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2603
2766
|
text: JSON.stringify(part.input)
|
|
2604
2767
|
});
|
|
2605
2768
|
} else {
|
|
2769
|
+
const caller = part.caller;
|
|
2770
|
+
const callerInfo = caller ? {
|
|
2771
|
+
type: caller.type,
|
|
2772
|
+
toolId: "tool_id" in caller ? caller.tool_id : void 0
|
|
2773
|
+
} : void 0;
|
|
2606
2774
|
content.push({
|
|
2607
2775
|
type: "tool-call",
|
|
2608
2776
|
toolCallId: part.id,
|
|
2609
2777
|
toolName: part.name,
|
|
2610
|
-
input: JSON.stringify(part.input)
|
|
2778
|
+
input: JSON.stringify(part.input),
|
|
2779
|
+
...callerInfo && {
|
|
2780
|
+
providerMetadata: {
|
|
2781
|
+
anthropic: {
|
|
2782
|
+
caller: callerInfo
|
|
2783
|
+
}
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2611
2786
|
});
|
|
2612
2787
|
}
|
|
2613
2788
|
break;
|
|
@@ -2622,11 +2797,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2622
2797
|
providerExecuted: true
|
|
2623
2798
|
});
|
|
2624
2799
|
} else if (part.name === "web_search" || part.name === "code_execution" || part.name === "web_fetch") {
|
|
2800
|
+
const inputToSerialize = part.name === "code_execution" && part.input != null && typeof part.input === "object" && "code" in part.input && !("type" in part.input) ? { type: "programmatic-tool-call", ...part.input } : part.input;
|
|
2625
2801
|
content.push({
|
|
2626
2802
|
type: "tool-call",
|
|
2627
2803
|
toolCallId: part.id,
|
|
2628
2804
|
toolName: toolNameMapping.toCustomToolName(part.name),
|
|
2629
|
-
input: JSON.stringify(
|
|
2805
|
+
input: JSON.stringify(inputToSerialize),
|
|
2630
2806
|
providerExecuted: true
|
|
2631
2807
|
});
|
|
2632
2808
|
} else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
|
|
@@ -2762,7 +2938,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2762
2938
|
type: part.content.type,
|
|
2763
2939
|
stdout: part.content.stdout,
|
|
2764
2940
|
stderr: part.content.stderr,
|
|
2765
|
-
return_code: part.content.return_code
|
|
2941
|
+
return_code: part.content.return_code,
|
|
2942
|
+
content: (_b = part.content.content) != null ? _b : []
|
|
2766
2943
|
}
|
|
2767
2944
|
});
|
|
2768
2945
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -2827,8 +3004,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2827
3004
|
usage: convertAnthropicMessagesUsage(response.usage),
|
|
2828
3005
|
request: { body: args },
|
|
2829
3006
|
response: {
|
|
2830
|
-
id: (
|
|
2831
|
-
modelId: (
|
|
3007
|
+
id: (_c = response.id) != null ? _c : void 0,
|
|
3008
|
+
modelId: (_d = response.model) != null ? _d : void 0,
|
|
2832
3009
|
headers: responseHeaders,
|
|
2833
3010
|
body: rawResponse
|
|
2834
3011
|
},
|
|
@@ -2836,20 +3013,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2836
3013
|
providerMetadata: {
|
|
2837
3014
|
anthropic: {
|
|
2838
3015
|
usage: response.usage,
|
|
2839
|
-
cacheCreationInputTokens: (
|
|
2840
|
-
stopSequence: (
|
|
3016
|
+
cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null,
|
|
3017
|
+
stopSequence: (_f = response.stop_sequence) != null ? _f : null,
|
|
2841
3018
|
container: response.container ? {
|
|
2842
3019
|
expiresAt: response.container.expires_at,
|
|
2843
3020
|
id: response.container.id,
|
|
2844
|
-
skills: (
|
|
3021
|
+
skills: (_h = (_g = response.container.skills) == null ? void 0 : _g.map((skill) => ({
|
|
2845
3022
|
type: skill.type,
|
|
2846
3023
|
skillId: skill.skill_id,
|
|
2847
3024
|
version: skill.version
|
|
2848
|
-
}))) != null ?
|
|
3025
|
+
}))) != null ? _h : null
|
|
2849
3026
|
} : null,
|
|
2850
|
-
contextManagement: (
|
|
3027
|
+
contextManagement: (_i = mapAnthropicResponseContextManagement(
|
|
2851
3028
|
response.context_management
|
|
2852
|
-
)) != null ?
|
|
3029
|
+
)) != null ? _i : null
|
|
2853
3030
|
}
|
|
2854
3031
|
}
|
|
2855
3032
|
};
|
|
@@ -2903,7 +3080,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2903
3080
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2904
3081
|
},
|
|
2905
3082
|
transform(chunk, controller) {
|
|
2906
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
|
|
3083
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2907
3084
|
if (options.includeRawChunks) {
|
|
2908
3085
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2909
3086
|
}
|
|
@@ -2963,12 +3140,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2963
3140
|
id: String(value.index)
|
|
2964
3141
|
});
|
|
2965
3142
|
} else {
|
|
3143
|
+
const caller = part.caller;
|
|
3144
|
+
const callerInfo = caller ? {
|
|
3145
|
+
type: caller.type,
|
|
3146
|
+
toolId: "tool_id" in caller ? caller.tool_id : void 0
|
|
3147
|
+
} : void 0;
|
|
3148
|
+
const hasNonEmptyInput = part.input && Object.keys(part.input).length > 0;
|
|
3149
|
+
const initialInput = hasNonEmptyInput ? JSON.stringify(part.input) : "";
|
|
2966
3150
|
contentBlocks[value.index] = {
|
|
2967
3151
|
type: "tool-call",
|
|
2968
3152
|
toolCallId: part.id,
|
|
2969
3153
|
toolName: part.name,
|
|
2970
|
-
input:
|
|
2971
|
-
firstDelta:
|
|
3154
|
+
input: initialInput,
|
|
3155
|
+
firstDelta: initialInput.length === 0,
|
|
3156
|
+
...callerInfo && { caller: callerInfo }
|
|
2972
3157
|
};
|
|
2973
3158
|
controller.enqueue({
|
|
2974
3159
|
type: "tool-input-start",
|
|
@@ -3120,7 +3305,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3120
3305
|
type: part.content.type,
|
|
3121
3306
|
stdout: part.content.stdout,
|
|
3122
3307
|
stderr: part.content.stderr,
|
|
3123
|
-
return_code: part.content.return_code
|
|
3308
|
+
return_code: part.content.return_code,
|
|
3309
|
+
content: (_b2 = part.content.content) != null ? _b2 : []
|
|
3124
3310
|
}
|
|
3125
3311
|
});
|
|
3126
3312
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -3237,12 +3423,32 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3237
3423
|
type: "tool-input-end",
|
|
3238
3424
|
id: contentBlock.toolCallId
|
|
3239
3425
|
});
|
|
3426
|
+
let finalInput = contentBlock.input === "" ? "{}" : contentBlock.input;
|
|
3427
|
+
if (contentBlock.providerToolName === "code_execution") {
|
|
3428
|
+
try {
|
|
3429
|
+
const parsed = JSON.parse(finalInput);
|
|
3430
|
+
if (parsed != null && typeof parsed === "object" && "code" in parsed && !("type" in parsed)) {
|
|
3431
|
+
finalInput = JSON.stringify({
|
|
3432
|
+
type: "programmatic-tool-call",
|
|
3433
|
+
...parsed
|
|
3434
|
+
});
|
|
3435
|
+
}
|
|
3436
|
+
} catch (e) {
|
|
3437
|
+
}
|
|
3438
|
+
}
|
|
3240
3439
|
controller.enqueue({
|
|
3241
3440
|
type: "tool-call",
|
|
3242
3441
|
toolCallId: contentBlock.toolCallId,
|
|
3243
3442
|
toolName: contentBlock.toolName,
|
|
3244
|
-
input:
|
|
3245
|
-
providerExecuted: contentBlock.providerExecuted
|
|
3443
|
+
input: finalInput,
|
|
3444
|
+
providerExecuted: contentBlock.providerExecuted,
|
|
3445
|
+
...contentBlock.caller && {
|
|
3446
|
+
providerMetadata: {
|
|
3447
|
+
anthropic: {
|
|
3448
|
+
caller: contentBlock.caller
|
|
3449
|
+
}
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
3246
3452
|
});
|
|
3247
3453
|
}
|
|
3248
3454
|
break;
|
|
@@ -3343,17 +3549,70 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3343
3549
|
}
|
|
3344
3550
|
case "message_start": {
|
|
3345
3551
|
usage.input_tokens = value.message.usage.input_tokens;
|
|
3346
|
-
usage.cache_read_input_tokens = (
|
|
3347
|
-
usage.cache_creation_input_tokens = (
|
|
3552
|
+
usage.cache_read_input_tokens = (_c = value.message.usage.cache_read_input_tokens) != null ? _c : 0;
|
|
3553
|
+
usage.cache_creation_input_tokens = (_d = value.message.usage.cache_creation_input_tokens) != null ? _d : 0;
|
|
3348
3554
|
rawUsage = {
|
|
3349
3555
|
...value.message.usage
|
|
3350
3556
|
};
|
|
3351
|
-
cacheCreationInputTokens = (
|
|
3557
|
+
cacheCreationInputTokens = (_e = value.message.usage.cache_creation_input_tokens) != null ? _e : null;
|
|
3558
|
+
if (value.message.container != null) {
|
|
3559
|
+
container = {
|
|
3560
|
+
expiresAt: value.message.container.expires_at,
|
|
3561
|
+
id: value.message.container.id,
|
|
3562
|
+
skills: null
|
|
3563
|
+
};
|
|
3564
|
+
}
|
|
3565
|
+
if (value.message.stop_reason != null) {
|
|
3566
|
+
finishReason = mapAnthropicStopReason({
|
|
3567
|
+
finishReason: value.message.stop_reason,
|
|
3568
|
+
isJsonResponseFromTool
|
|
3569
|
+
});
|
|
3570
|
+
}
|
|
3352
3571
|
controller.enqueue({
|
|
3353
3572
|
type: "response-metadata",
|
|
3354
|
-
id: (
|
|
3355
|
-
modelId: (
|
|
3573
|
+
id: (_f = value.message.id) != null ? _f : void 0,
|
|
3574
|
+
modelId: (_g = value.message.model) != null ? _g : void 0
|
|
3356
3575
|
});
|
|
3576
|
+
if (value.message.content != null) {
|
|
3577
|
+
for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
|
|
3578
|
+
const part = value.message.content[contentIndex];
|
|
3579
|
+
if (part.type === "tool_use") {
|
|
3580
|
+
const caller = part.caller;
|
|
3581
|
+
const callerInfo = caller ? {
|
|
3582
|
+
type: caller.type,
|
|
3583
|
+
toolId: "tool_id" in caller ? caller.tool_id : void 0
|
|
3584
|
+
} : void 0;
|
|
3585
|
+
controller.enqueue({
|
|
3586
|
+
type: "tool-input-start",
|
|
3587
|
+
id: part.id,
|
|
3588
|
+
toolName: part.name
|
|
3589
|
+
});
|
|
3590
|
+
const inputStr = JSON.stringify((_h = part.input) != null ? _h : {});
|
|
3591
|
+
controller.enqueue({
|
|
3592
|
+
type: "tool-input-delta",
|
|
3593
|
+
id: part.id,
|
|
3594
|
+
delta: inputStr
|
|
3595
|
+
});
|
|
3596
|
+
controller.enqueue({
|
|
3597
|
+
type: "tool-input-end",
|
|
3598
|
+
id: part.id
|
|
3599
|
+
});
|
|
3600
|
+
controller.enqueue({
|
|
3601
|
+
type: "tool-call",
|
|
3602
|
+
toolCallId: part.id,
|
|
3603
|
+
toolName: part.name,
|
|
3604
|
+
input: inputStr,
|
|
3605
|
+
...callerInfo && {
|
|
3606
|
+
providerMetadata: {
|
|
3607
|
+
anthropic: {
|
|
3608
|
+
caller: callerInfo
|
|
3609
|
+
}
|
|
3610
|
+
}
|
|
3611
|
+
}
|
|
3612
|
+
});
|
|
3613
|
+
}
|
|
3614
|
+
}
|
|
3615
|
+
}
|
|
3357
3616
|
return;
|
|
3358
3617
|
}
|
|
3359
3618
|
case "message_delta": {
|
|
@@ -3362,15 +3621,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3362
3621
|
finishReason: value.delta.stop_reason,
|
|
3363
3622
|
isJsonResponseFromTool
|
|
3364
3623
|
});
|
|
3365
|
-
stopSequence = (
|
|
3624
|
+
stopSequence = (_i = value.delta.stop_sequence) != null ? _i : null;
|
|
3366
3625
|
container = value.delta.container != null ? {
|
|
3367
3626
|
expiresAt: value.delta.container.expires_at,
|
|
3368
3627
|
id: value.delta.container.id,
|
|
3369
|
-
skills: (
|
|
3628
|
+
skills: (_k = (_j = value.delta.container.skills) == null ? void 0 : _j.map((skill) => ({
|
|
3370
3629
|
type: skill.type,
|
|
3371
3630
|
skillId: skill.skill_id,
|
|
3372
3631
|
version: skill.version
|
|
3373
|
-
}))) != null ?
|
|
3632
|
+
}))) != null ? _k : null
|
|
3374
3633
|
} : null;
|
|
3375
3634
|
if (value.delta.context_management) {
|
|
3376
3635
|
contextManagement = mapAnthropicResponseContextManagement(
|