@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.mjs
CHANGED
|
@@ -36,29 +36,6 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
36
36
|
errorToMessage: (data) => data.error.message
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
// src/convert-anthropic-messages-usage.ts
|
|
40
|
-
function convertAnthropicMessagesUsage(usage) {
|
|
41
|
-
var _a, _b;
|
|
42
|
-
const inputTokens = usage.input_tokens;
|
|
43
|
-
const outputTokens = usage.output_tokens;
|
|
44
|
-
const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
|
|
45
|
-
const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
|
|
46
|
-
return {
|
|
47
|
-
inputTokens: {
|
|
48
|
-
total: inputTokens + cacheCreationTokens + cacheReadTokens,
|
|
49
|
-
noCache: inputTokens,
|
|
50
|
-
cacheRead: cacheReadTokens,
|
|
51
|
-
cacheWrite: cacheCreationTokens
|
|
52
|
-
},
|
|
53
|
-
outputTokens: {
|
|
54
|
-
total: outputTokens,
|
|
55
|
-
text: void 0,
|
|
56
|
-
reasoning: void 0
|
|
57
|
-
},
|
|
58
|
-
raw: usage
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
39
|
// src/anthropic-messages-api.ts
|
|
63
40
|
import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
|
|
64
41
|
import { z as z2 } from "zod/v4";
|
|
@@ -114,7 +91,17 @@ var anthropicMessagesResponseSchema = lazySchema2(
|
|
|
114
91
|
type: z2.literal("tool_use"),
|
|
115
92
|
id: z2.string(),
|
|
116
93
|
name: z2.string(),
|
|
117
|
-
input: z2.unknown()
|
|
94
|
+
input: z2.unknown(),
|
|
95
|
+
// Programmatic tool calling: caller info when triggered from code execution
|
|
96
|
+
caller: z2.union([
|
|
97
|
+
z2.object({
|
|
98
|
+
type: z2.literal("code_execution_20250825"),
|
|
99
|
+
tool_id: z2.string()
|
|
100
|
+
}),
|
|
101
|
+
z2.object({
|
|
102
|
+
type: z2.literal("direct")
|
|
103
|
+
})
|
|
104
|
+
]).optional()
|
|
118
105
|
}),
|
|
119
106
|
z2.object({
|
|
120
107
|
type: z2.literal("server_tool_use"),
|
|
@@ -200,7 +187,13 @@ var anthropicMessagesResponseSchema = lazySchema2(
|
|
|
200
187
|
type: z2.literal("code_execution_result"),
|
|
201
188
|
stdout: z2.string(),
|
|
202
189
|
stderr: z2.string(),
|
|
203
|
-
return_code: z2.number()
|
|
190
|
+
return_code: z2.number(),
|
|
191
|
+
content: z2.array(
|
|
192
|
+
z2.object({
|
|
193
|
+
type: z2.literal("code_execution_output"),
|
|
194
|
+
file_id: z2.string()
|
|
195
|
+
})
|
|
196
|
+
).optional().default([])
|
|
204
197
|
}),
|
|
205
198
|
z2.object({
|
|
206
199
|
type: z2.literal("code_execution_tool_result_error"),
|
|
@@ -332,11 +325,37 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
332
325
|
message: z2.object({
|
|
333
326
|
id: z2.string().nullish(),
|
|
334
327
|
model: z2.string().nullish(),
|
|
328
|
+
role: z2.string().nullish(),
|
|
335
329
|
usage: z2.looseObject({
|
|
336
330
|
input_tokens: z2.number(),
|
|
337
331
|
cache_creation_input_tokens: z2.number().nullish(),
|
|
338
332
|
cache_read_input_tokens: z2.number().nullish()
|
|
339
|
-
})
|
|
333
|
+
}),
|
|
334
|
+
// Programmatic tool calling: content may be pre-populated for deferred tool calls
|
|
335
|
+
content: z2.array(
|
|
336
|
+
z2.discriminatedUnion("type", [
|
|
337
|
+
z2.object({
|
|
338
|
+
type: z2.literal("tool_use"),
|
|
339
|
+
id: z2.string(),
|
|
340
|
+
name: z2.string(),
|
|
341
|
+
input: z2.unknown(),
|
|
342
|
+
caller: z2.union([
|
|
343
|
+
z2.object({
|
|
344
|
+
type: z2.literal("code_execution_20250825"),
|
|
345
|
+
tool_id: z2.string()
|
|
346
|
+
}),
|
|
347
|
+
z2.object({
|
|
348
|
+
type: z2.literal("direct")
|
|
349
|
+
})
|
|
350
|
+
]).optional()
|
|
351
|
+
})
|
|
352
|
+
])
|
|
353
|
+
).nullish(),
|
|
354
|
+
stop_reason: z2.string().nullish(),
|
|
355
|
+
container: z2.object({
|
|
356
|
+
expires_at: z2.string(),
|
|
357
|
+
id: z2.string()
|
|
358
|
+
}).nullish()
|
|
340
359
|
})
|
|
341
360
|
}),
|
|
342
361
|
z2.object({
|
|
@@ -354,7 +373,19 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
354
373
|
z2.object({
|
|
355
374
|
type: z2.literal("tool_use"),
|
|
356
375
|
id: z2.string(),
|
|
357
|
-
name: z2.string()
|
|
376
|
+
name: z2.string(),
|
|
377
|
+
// Programmatic tool calling: input may be present directly for deferred tool calls
|
|
378
|
+
input: z2.record(z2.string(), z2.unknown()).optional(),
|
|
379
|
+
// Programmatic tool calling: caller info when triggered from code execution
|
|
380
|
+
caller: z2.union([
|
|
381
|
+
z2.object({
|
|
382
|
+
type: z2.literal("code_execution_20250825"),
|
|
383
|
+
tool_id: z2.string()
|
|
384
|
+
}),
|
|
385
|
+
z2.object({
|
|
386
|
+
type: z2.literal("direct")
|
|
387
|
+
})
|
|
388
|
+
]).optional()
|
|
358
389
|
}),
|
|
359
390
|
z2.object({
|
|
360
391
|
type: z2.literal("redacted_thinking"),
|
|
@@ -444,7 +475,13 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
444
475
|
type: z2.literal("code_execution_result"),
|
|
445
476
|
stdout: z2.string(),
|
|
446
477
|
stderr: z2.string(),
|
|
447
|
-
return_code: z2.number()
|
|
478
|
+
return_code: z2.number(),
|
|
479
|
+
content: z2.array(
|
|
480
|
+
z2.object({
|
|
481
|
+
type: z2.literal("code_execution_output"),
|
|
482
|
+
file_id: z2.string()
|
|
483
|
+
})
|
|
484
|
+
).optional().default([])
|
|
448
485
|
}),
|
|
449
486
|
z2.object({
|
|
450
487
|
type: z2.literal("code_execution_tool_result_error"),
|
|
@@ -1015,6 +1052,7 @@ async function prepareTools({
|
|
|
1015
1052
|
});
|
|
1016
1053
|
const anthropicOptions = (_a = tool.providerOptions) == null ? void 0 : _a.anthropic;
|
|
1017
1054
|
const deferLoading = anthropicOptions == null ? void 0 : anthropicOptions.deferLoading;
|
|
1055
|
+
const allowedCallers = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers;
|
|
1018
1056
|
anthropicTools2.push({
|
|
1019
1057
|
name: tool.name,
|
|
1020
1058
|
description: tool.description,
|
|
@@ -1022,6 +1060,7 @@ async function prepareTools({
|
|
|
1022
1060
|
cache_control: cacheControl,
|
|
1023
1061
|
...supportsStructuredOutput === true && tool.strict != null ? { strict: tool.strict } : {},
|
|
1024
1062
|
...deferLoading != null ? { defer_loading: deferLoading } : {},
|
|
1063
|
+
...allowedCallers != null ? { allowed_callers: allowedCallers } : {},
|
|
1025
1064
|
...tool.inputExamples != null ? {
|
|
1026
1065
|
input_examples: tool.inputExamples.map(
|
|
1027
1066
|
(example) => example.input
|
|
@@ -1031,7 +1070,7 @@ async function prepareTools({
|
|
|
1031
1070
|
if (supportsStructuredOutput === true) {
|
|
1032
1071
|
betas.add("structured-outputs-2025-11-13");
|
|
1033
1072
|
}
|
|
1034
|
-
if (tool.inputExamples != null) {
|
|
1073
|
+
if (tool.inputExamples != null || allowedCallers != null) {
|
|
1035
1074
|
betas.add("advanced-tool-use-2025-11-20");
|
|
1036
1075
|
}
|
|
1037
1076
|
break;
|
|
@@ -1266,6 +1305,29 @@ async function prepareTools({
|
|
|
1266
1305
|
}
|
|
1267
1306
|
}
|
|
1268
1307
|
|
|
1308
|
+
// src/convert-anthropic-messages-usage.ts
|
|
1309
|
+
function convertAnthropicMessagesUsage(usage) {
|
|
1310
|
+
var _a, _b;
|
|
1311
|
+
const inputTokens = usage.input_tokens;
|
|
1312
|
+
const outputTokens = usage.output_tokens;
|
|
1313
|
+
const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
|
|
1314
|
+
const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
|
|
1315
|
+
return {
|
|
1316
|
+
inputTokens: {
|
|
1317
|
+
total: inputTokens + cacheCreationTokens + cacheReadTokens,
|
|
1318
|
+
noCache: inputTokens,
|
|
1319
|
+
cacheRead: cacheReadTokens,
|
|
1320
|
+
cacheWrite: cacheCreationTokens
|
|
1321
|
+
},
|
|
1322
|
+
outputTokens: {
|
|
1323
|
+
total: outputTokens,
|
|
1324
|
+
text: void 0,
|
|
1325
|
+
reasoning: void 0
|
|
1326
|
+
},
|
|
1327
|
+
raw: usage
|
|
1328
|
+
};
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1269
1331
|
// src/convert-to-anthropic-messages-prompt.ts
|
|
1270
1332
|
import {
|
|
1271
1333
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
@@ -1290,7 +1352,13 @@ var codeExecution_20250522OutputSchema = lazySchema6(
|
|
|
1290
1352
|
type: z7.literal("code_execution_result"),
|
|
1291
1353
|
stdout: z7.string(),
|
|
1292
1354
|
stderr: z7.string(),
|
|
1293
|
-
return_code: z7.number()
|
|
1355
|
+
return_code: z7.number(),
|
|
1356
|
+
content: z7.array(
|
|
1357
|
+
z7.object({
|
|
1358
|
+
type: z7.literal("code_execution_output"),
|
|
1359
|
+
file_id: z7.string()
|
|
1360
|
+
})
|
|
1361
|
+
).optional().default([])
|
|
1294
1362
|
})
|
|
1295
1363
|
)
|
|
1296
1364
|
);
|
|
@@ -1320,6 +1388,18 @@ import { z as z8 } from "zod/v4";
|
|
|
1320
1388
|
var codeExecution_20250825OutputSchema = lazySchema7(
|
|
1321
1389
|
() => zodSchema7(
|
|
1322
1390
|
z8.discriminatedUnion("type", [
|
|
1391
|
+
z8.object({
|
|
1392
|
+
type: z8.literal("code_execution_result"),
|
|
1393
|
+
stdout: z8.string(),
|
|
1394
|
+
stderr: z8.string(),
|
|
1395
|
+
return_code: z8.number(),
|
|
1396
|
+
content: z8.array(
|
|
1397
|
+
z8.object({
|
|
1398
|
+
type: z8.literal("code_execution_output"),
|
|
1399
|
+
file_id: z8.string()
|
|
1400
|
+
})
|
|
1401
|
+
).optional().default([])
|
|
1402
|
+
}),
|
|
1323
1403
|
z8.object({
|
|
1324
1404
|
type: z8.literal("bash_code_execution_result"),
|
|
1325
1405
|
content: z8.array(
|
|
@@ -1366,6 +1446,11 @@ var codeExecution_20250825OutputSchema = lazySchema7(
|
|
|
1366
1446
|
var codeExecution_20250825InputSchema = lazySchema7(
|
|
1367
1447
|
() => zodSchema7(
|
|
1368
1448
|
z8.discriminatedUnion("type", [
|
|
1449
|
+
// Programmatic tool calling format (mapped from { code } by AI SDK)
|
|
1450
|
+
z8.object({
|
|
1451
|
+
type: z8.literal("programmatic-tool-call"),
|
|
1452
|
+
code: z8.string()
|
|
1453
|
+
}),
|
|
1369
1454
|
z8.object({
|
|
1370
1455
|
type: z8.literal("bash_code_execution"),
|
|
1371
1456
|
command: z8.string()
|
|
@@ -1396,7 +1481,11 @@ var codeExecution_20250825InputSchema = lazySchema7(
|
|
|
1396
1481
|
var factory5 = createProviderToolFactoryWithOutputSchema4({
|
|
1397
1482
|
id: "anthropic.code_execution_20250825",
|
|
1398
1483
|
inputSchema: codeExecution_20250825InputSchema,
|
|
1399
|
-
outputSchema: codeExecution_20250825OutputSchema
|
|
1484
|
+
outputSchema: codeExecution_20250825OutputSchema,
|
|
1485
|
+
// Programmatic tool calling: tool results may be deferred to a later turn
|
|
1486
|
+
// when code execution triggers a client-executed tool that needs to be
|
|
1487
|
+
// resolved before the code execution result can be returned.
|
|
1488
|
+
supportsDeferredResults: true
|
|
1400
1489
|
});
|
|
1401
1490
|
var codeExecution_20250825 = (args = {}) => {
|
|
1402
1491
|
return factory5(args);
|
|
@@ -1473,7 +1562,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1473
1562
|
cacheControlValidator,
|
|
1474
1563
|
toolNameMapping
|
|
1475
1564
|
}) {
|
|
1476
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1565
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1477
1566
|
const betas = /* @__PURE__ */ new Set();
|
|
1478
1567
|
const blocks = groupIntoBlocks(prompt);
|
|
1479
1568
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -1843,6 +1932,19 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1843
1932
|
input: part.input,
|
|
1844
1933
|
cache_control: cacheControl
|
|
1845
1934
|
});
|
|
1935
|
+
} else if (
|
|
1936
|
+
// code execution 20250825 programmatic tool calling:
|
|
1937
|
+
// Strip the fake 'programmatic-tool-call' type before sending to Anthropic
|
|
1938
|
+
providerToolName === "code_execution" && part.input != null && typeof part.input === "object" && "type" in part.input && part.input.type === "programmatic-tool-call"
|
|
1939
|
+
) {
|
|
1940
|
+
const { type: _, ...inputWithoutType } = part.input;
|
|
1941
|
+
anthropicContent.push({
|
|
1942
|
+
type: "server_tool_use",
|
|
1943
|
+
id: part.toolCallId,
|
|
1944
|
+
name: "code_execution",
|
|
1945
|
+
input: inputWithoutType,
|
|
1946
|
+
cache_control: cacheControl
|
|
1947
|
+
});
|
|
1846
1948
|
} else {
|
|
1847
1949
|
if (providerToolName === "code_execution" || // code execution 20250522
|
|
1848
1950
|
providerToolName === "web_fetch" || providerToolName === "web_search") {
|
|
@@ -1870,11 +1972,17 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1870
1972
|
}
|
|
1871
1973
|
break;
|
|
1872
1974
|
}
|
|
1975
|
+
const callerOptions = (_k = part.providerOptions) == null ? void 0 : _k.anthropic;
|
|
1976
|
+
const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? callerOptions.caller.type === "code_execution_20250825" && callerOptions.caller.toolId ? {
|
|
1977
|
+
type: "code_execution_20250825",
|
|
1978
|
+
tool_id: callerOptions.caller.toolId
|
|
1979
|
+
} : callerOptions.caller.type === "direct" ? { type: "direct" } : void 0 : void 0;
|
|
1873
1980
|
anthropicContent.push({
|
|
1874
1981
|
type: "tool_use",
|
|
1875
1982
|
id: part.toolCallId,
|
|
1876
1983
|
name: part.toolName,
|
|
1877
1984
|
input: part.input,
|
|
1985
|
+
...caller && { caller },
|
|
1878
1986
|
cache_control: cacheControl
|
|
1879
1987
|
});
|
|
1880
1988
|
break;
|
|
@@ -1901,6 +2009,39 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1901
2009
|
});
|
|
1902
2010
|
} else if (providerToolName === "code_execution") {
|
|
1903
2011
|
const output = part.output;
|
|
2012
|
+
if (output.type === "error-text" || output.type === "error-json") {
|
|
2013
|
+
let errorInfo = {};
|
|
2014
|
+
try {
|
|
2015
|
+
if (typeof output.value === "string") {
|
|
2016
|
+
errorInfo = JSON.parse(output.value);
|
|
2017
|
+
} else if (typeof output.value === "object" && output.value !== null) {
|
|
2018
|
+
errorInfo = output.value;
|
|
2019
|
+
}
|
|
2020
|
+
} catch (e) {
|
|
2021
|
+
}
|
|
2022
|
+
if (errorInfo.type === "code_execution_tool_result_error") {
|
|
2023
|
+
anthropicContent.push({
|
|
2024
|
+
type: "code_execution_tool_result",
|
|
2025
|
+
tool_use_id: part.toolCallId,
|
|
2026
|
+
content: {
|
|
2027
|
+
type: "code_execution_tool_result_error",
|
|
2028
|
+
error_code: (_l = errorInfo.errorCode) != null ? _l : "unknown"
|
|
2029
|
+
},
|
|
2030
|
+
cache_control: cacheControl
|
|
2031
|
+
});
|
|
2032
|
+
} else {
|
|
2033
|
+
anthropicContent.push({
|
|
2034
|
+
type: "bash_code_execution_tool_result",
|
|
2035
|
+
tool_use_id: part.toolCallId,
|
|
2036
|
+
cache_control: cacheControl,
|
|
2037
|
+
content: {
|
|
2038
|
+
type: "bash_code_execution_tool_result_error",
|
|
2039
|
+
error_code: (_m = errorInfo.errorCode) != null ? _m : "unknown"
|
|
2040
|
+
}
|
|
2041
|
+
});
|
|
2042
|
+
}
|
|
2043
|
+
break;
|
|
2044
|
+
}
|
|
1904
2045
|
if (output.type !== "json") {
|
|
1905
2046
|
warnings.push({
|
|
1906
2047
|
type: "other",
|
|
@@ -1927,7 +2068,8 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1927
2068
|
type: codeExecutionOutput.type,
|
|
1928
2069
|
stdout: codeExecutionOutput.stdout,
|
|
1929
2070
|
stderr: codeExecutionOutput.stderr,
|
|
1930
|
-
return_code: codeExecutionOutput.return_code
|
|
2071
|
+
return_code: codeExecutionOutput.return_code,
|
|
2072
|
+
content: (_n = codeExecutionOutput.content) != null ? _n : []
|
|
1931
2073
|
},
|
|
1932
2074
|
cache_control: cacheControl
|
|
1933
2075
|
});
|
|
@@ -1936,19 +2078,34 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1936
2078
|
value: output.value,
|
|
1937
2079
|
schema: codeExecution_20250825OutputSchema
|
|
1938
2080
|
});
|
|
1939
|
-
|
|
1940
|
-
|
|
2081
|
+
if (codeExecutionOutput.type === "code_execution_result") {
|
|
2082
|
+
anthropicContent.push({
|
|
2083
|
+
type: "code_execution_tool_result",
|
|
2084
|
+
tool_use_id: part.toolCallId,
|
|
2085
|
+
content: {
|
|
2086
|
+
type: codeExecutionOutput.type,
|
|
2087
|
+
stdout: codeExecutionOutput.stdout,
|
|
2088
|
+
stderr: codeExecutionOutput.stderr,
|
|
2089
|
+
return_code: codeExecutionOutput.return_code,
|
|
2090
|
+
content: (_o = codeExecutionOutput.content) != null ? _o : []
|
|
2091
|
+
},
|
|
2092
|
+
cache_control: cacheControl
|
|
2093
|
+
});
|
|
2094
|
+
} else if (codeExecutionOutput.type === "bash_code_execution_result" || codeExecutionOutput.type === "bash_code_execution_tool_result_error") {
|
|
2095
|
+
anthropicContent.push({
|
|
1941
2096
|
type: "bash_code_execution_tool_result",
|
|
1942
2097
|
tool_use_id: part.toolCallId,
|
|
1943
2098
|
cache_control: cacheControl,
|
|
1944
2099
|
content: codeExecutionOutput
|
|
1945
|
-
}
|
|
2100
|
+
});
|
|
2101
|
+
} else {
|
|
2102
|
+
anthropicContent.push({
|
|
1946
2103
|
type: "text_editor_code_execution_tool_result",
|
|
1947
2104
|
tool_use_id: part.toolCallId,
|
|
1948
2105
|
cache_control: cacheControl,
|
|
1949
2106
|
content: codeExecutionOutput
|
|
1950
|
-
}
|
|
1951
|
-
|
|
2107
|
+
});
|
|
2108
|
+
}
|
|
1952
2109
|
}
|
|
1953
2110
|
break;
|
|
1954
2111
|
}
|
|
@@ -2200,7 +2357,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2200
2357
|
providerOptions,
|
|
2201
2358
|
stream
|
|
2202
2359
|
}) {
|
|
2203
|
-
var _a, _b, _c, _d, _e, _f
|
|
2360
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2204
2361
|
const warnings = [];
|
|
2205
2362
|
if (frequencyPenalty != null) {
|
|
2206
2363
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -2322,16 +2479,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2322
2479
|
} : void 0
|
|
2323
2480
|
}))
|
|
2324
2481
|
},
|
|
2325
|
-
// container
|
|
2482
|
+
// container: For programmatic tool calling (just an ID string) or agent skills (object with id and skills)
|
|
2326
2483
|
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
2327
|
-
container:
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2484
|
+
container: anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0 ? (
|
|
2485
|
+
// Object format when skills are provided (agent skills feature)
|
|
2486
|
+
{
|
|
2487
|
+
id: anthropicOptions.container.id,
|
|
2488
|
+
skills: anthropicOptions.container.skills.map((skill) => ({
|
|
2489
|
+
type: skill.type,
|
|
2490
|
+
skill_id: skill.skillId,
|
|
2491
|
+
version: skill.version
|
|
2492
|
+
}))
|
|
2493
|
+
}
|
|
2494
|
+
) : (
|
|
2495
|
+
// String format for container ID only (programmatic tool calling)
|
|
2496
|
+
anthropicOptions.container.id
|
|
2497
|
+
)
|
|
2335
2498
|
},
|
|
2336
2499
|
// prompt:
|
|
2337
2500
|
system: messagesPrompt.system,
|
|
@@ -2445,7 +2608,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2445
2608
|
if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
|
|
2446
2609
|
betas.add("effort-2025-11-24");
|
|
2447
2610
|
}
|
|
2448
|
-
if (stream && ((
|
|
2611
|
+
if (stream && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _f : true)) {
|
|
2449
2612
|
betas.add("fine-grained-tool-streaming-2025-05-14");
|
|
2450
2613
|
}
|
|
2451
2614
|
const usingNativeOutputFormat = useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
|
|
@@ -2541,7 +2704,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2541
2704
|
});
|
|
2542
2705
|
}
|
|
2543
2706
|
async doGenerate(options) {
|
|
2544
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2707
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2545
2708
|
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
|
|
2546
2709
|
...options,
|
|
2547
2710
|
stream: false,
|
|
@@ -2619,11 +2782,23 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2619
2782
|
text: JSON.stringify(part.input)
|
|
2620
2783
|
});
|
|
2621
2784
|
} else {
|
|
2785
|
+
const caller = part.caller;
|
|
2786
|
+
const callerInfo = caller ? {
|
|
2787
|
+
type: caller.type,
|
|
2788
|
+
toolId: "tool_id" in caller ? caller.tool_id : void 0
|
|
2789
|
+
} : void 0;
|
|
2622
2790
|
content.push({
|
|
2623
2791
|
type: "tool-call",
|
|
2624
2792
|
toolCallId: part.id,
|
|
2625
2793
|
toolName: part.name,
|
|
2626
|
-
input: JSON.stringify(part.input)
|
|
2794
|
+
input: JSON.stringify(part.input),
|
|
2795
|
+
...callerInfo && {
|
|
2796
|
+
providerMetadata: {
|
|
2797
|
+
anthropic: {
|
|
2798
|
+
caller: callerInfo
|
|
2799
|
+
}
|
|
2800
|
+
}
|
|
2801
|
+
}
|
|
2627
2802
|
});
|
|
2628
2803
|
}
|
|
2629
2804
|
break;
|
|
@@ -2638,11 +2813,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2638
2813
|
providerExecuted: true
|
|
2639
2814
|
});
|
|
2640
2815
|
} else if (part.name === "web_search" || part.name === "code_execution" || part.name === "web_fetch") {
|
|
2816
|
+
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;
|
|
2641
2817
|
content.push({
|
|
2642
2818
|
type: "tool-call",
|
|
2643
2819
|
toolCallId: part.id,
|
|
2644
2820
|
toolName: toolNameMapping.toCustomToolName(part.name),
|
|
2645
|
-
input: JSON.stringify(
|
|
2821
|
+
input: JSON.stringify(inputToSerialize),
|
|
2646
2822
|
providerExecuted: true
|
|
2647
2823
|
});
|
|
2648
2824
|
} else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
|
|
@@ -2778,7 +2954,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2778
2954
|
type: part.content.type,
|
|
2779
2955
|
stdout: part.content.stdout,
|
|
2780
2956
|
stderr: part.content.stderr,
|
|
2781
|
-
return_code: part.content.return_code
|
|
2957
|
+
return_code: part.content.return_code,
|
|
2958
|
+
content: (_b = part.content.content) != null ? _b : []
|
|
2782
2959
|
}
|
|
2783
2960
|
});
|
|
2784
2961
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -2843,8 +3020,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2843
3020
|
usage: convertAnthropicMessagesUsage(response.usage),
|
|
2844
3021
|
request: { body: args },
|
|
2845
3022
|
response: {
|
|
2846
|
-
id: (
|
|
2847
|
-
modelId: (
|
|
3023
|
+
id: (_c = response.id) != null ? _c : void 0,
|
|
3024
|
+
modelId: (_d = response.model) != null ? _d : void 0,
|
|
2848
3025
|
headers: responseHeaders,
|
|
2849
3026
|
body: rawResponse
|
|
2850
3027
|
},
|
|
@@ -2852,20 +3029,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2852
3029
|
providerMetadata: {
|
|
2853
3030
|
anthropic: {
|
|
2854
3031
|
usage: response.usage,
|
|
2855
|
-
cacheCreationInputTokens: (
|
|
2856
|
-
stopSequence: (
|
|
3032
|
+
cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null,
|
|
3033
|
+
stopSequence: (_f = response.stop_sequence) != null ? _f : null,
|
|
2857
3034
|
container: response.container ? {
|
|
2858
3035
|
expiresAt: response.container.expires_at,
|
|
2859
3036
|
id: response.container.id,
|
|
2860
|
-
skills: (
|
|
3037
|
+
skills: (_h = (_g = response.container.skills) == null ? void 0 : _g.map((skill) => ({
|
|
2861
3038
|
type: skill.type,
|
|
2862
3039
|
skillId: skill.skill_id,
|
|
2863
3040
|
version: skill.version
|
|
2864
|
-
}))) != null ?
|
|
3041
|
+
}))) != null ? _h : null
|
|
2865
3042
|
} : null,
|
|
2866
|
-
contextManagement: (
|
|
3043
|
+
contextManagement: (_i = mapAnthropicResponseContextManagement(
|
|
2867
3044
|
response.context_management
|
|
2868
|
-
)) != null ?
|
|
3045
|
+
)) != null ? _i : null
|
|
2869
3046
|
}
|
|
2870
3047
|
}
|
|
2871
3048
|
};
|
|
@@ -2919,7 +3096,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2919
3096
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2920
3097
|
},
|
|
2921
3098
|
transform(chunk, controller) {
|
|
2922
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
|
|
3099
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2923
3100
|
if (options.includeRawChunks) {
|
|
2924
3101
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2925
3102
|
}
|
|
@@ -2979,12 +3156,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2979
3156
|
id: String(value.index)
|
|
2980
3157
|
});
|
|
2981
3158
|
} else {
|
|
3159
|
+
const caller = part.caller;
|
|
3160
|
+
const callerInfo = caller ? {
|
|
3161
|
+
type: caller.type,
|
|
3162
|
+
toolId: "tool_id" in caller ? caller.tool_id : void 0
|
|
3163
|
+
} : void 0;
|
|
3164
|
+
const hasNonEmptyInput = part.input && Object.keys(part.input).length > 0;
|
|
3165
|
+
const initialInput = hasNonEmptyInput ? JSON.stringify(part.input) : "";
|
|
2982
3166
|
contentBlocks[value.index] = {
|
|
2983
3167
|
type: "tool-call",
|
|
2984
3168
|
toolCallId: part.id,
|
|
2985
3169
|
toolName: part.name,
|
|
2986
|
-
input:
|
|
2987
|
-
firstDelta:
|
|
3170
|
+
input: initialInput,
|
|
3171
|
+
firstDelta: initialInput.length === 0,
|
|
3172
|
+
...callerInfo && { caller: callerInfo }
|
|
2988
3173
|
};
|
|
2989
3174
|
controller.enqueue({
|
|
2990
3175
|
type: "tool-input-start",
|
|
@@ -3136,7 +3321,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3136
3321
|
type: part.content.type,
|
|
3137
3322
|
stdout: part.content.stdout,
|
|
3138
3323
|
stderr: part.content.stderr,
|
|
3139
|
-
return_code: part.content.return_code
|
|
3324
|
+
return_code: part.content.return_code,
|
|
3325
|
+
content: (_b2 = part.content.content) != null ? _b2 : []
|
|
3140
3326
|
}
|
|
3141
3327
|
});
|
|
3142
3328
|
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
@@ -3253,12 +3439,32 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3253
3439
|
type: "tool-input-end",
|
|
3254
3440
|
id: contentBlock.toolCallId
|
|
3255
3441
|
});
|
|
3442
|
+
let finalInput = contentBlock.input === "" ? "{}" : contentBlock.input;
|
|
3443
|
+
if (contentBlock.providerToolName === "code_execution") {
|
|
3444
|
+
try {
|
|
3445
|
+
const parsed = JSON.parse(finalInput);
|
|
3446
|
+
if (parsed != null && typeof parsed === "object" && "code" in parsed && !("type" in parsed)) {
|
|
3447
|
+
finalInput = JSON.stringify({
|
|
3448
|
+
type: "programmatic-tool-call",
|
|
3449
|
+
...parsed
|
|
3450
|
+
});
|
|
3451
|
+
}
|
|
3452
|
+
} catch (e) {
|
|
3453
|
+
}
|
|
3454
|
+
}
|
|
3256
3455
|
controller.enqueue({
|
|
3257
3456
|
type: "tool-call",
|
|
3258
3457
|
toolCallId: contentBlock.toolCallId,
|
|
3259
3458
|
toolName: contentBlock.toolName,
|
|
3260
|
-
input:
|
|
3261
|
-
providerExecuted: contentBlock.providerExecuted
|
|
3459
|
+
input: finalInput,
|
|
3460
|
+
providerExecuted: contentBlock.providerExecuted,
|
|
3461
|
+
...contentBlock.caller && {
|
|
3462
|
+
providerMetadata: {
|
|
3463
|
+
anthropic: {
|
|
3464
|
+
caller: contentBlock.caller
|
|
3465
|
+
}
|
|
3466
|
+
}
|
|
3467
|
+
}
|
|
3262
3468
|
});
|
|
3263
3469
|
}
|
|
3264
3470
|
break;
|
|
@@ -3359,17 +3565,70 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3359
3565
|
}
|
|
3360
3566
|
case "message_start": {
|
|
3361
3567
|
usage.input_tokens = value.message.usage.input_tokens;
|
|
3362
|
-
usage.cache_read_input_tokens = (
|
|
3363
|
-
usage.cache_creation_input_tokens = (
|
|
3568
|
+
usage.cache_read_input_tokens = (_c = value.message.usage.cache_read_input_tokens) != null ? _c : 0;
|
|
3569
|
+
usage.cache_creation_input_tokens = (_d = value.message.usage.cache_creation_input_tokens) != null ? _d : 0;
|
|
3364
3570
|
rawUsage = {
|
|
3365
3571
|
...value.message.usage
|
|
3366
3572
|
};
|
|
3367
|
-
cacheCreationInputTokens = (
|
|
3573
|
+
cacheCreationInputTokens = (_e = value.message.usage.cache_creation_input_tokens) != null ? _e : null;
|
|
3574
|
+
if (value.message.container != null) {
|
|
3575
|
+
container = {
|
|
3576
|
+
expiresAt: value.message.container.expires_at,
|
|
3577
|
+
id: value.message.container.id,
|
|
3578
|
+
skills: null
|
|
3579
|
+
};
|
|
3580
|
+
}
|
|
3581
|
+
if (value.message.stop_reason != null) {
|
|
3582
|
+
finishReason = mapAnthropicStopReason({
|
|
3583
|
+
finishReason: value.message.stop_reason,
|
|
3584
|
+
isJsonResponseFromTool
|
|
3585
|
+
});
|
|
3586
|
+
}
|
|
3368
3587
|
controller.enqueue({
|
|
3369
3588
|
type: "response-metadata",
|
|
3370
|
-
id: (
|
|
3371
|
-
modelId: (
|
|
3589
|
+
id: (_f = value.message.id) != null ? _f : void 0,
|
|
3590
|
+
modelId: (_g = value.message.model) != null ? _g : void 0
|
|
3372
3591
|
});
|
|
3592
|
+
if (value.message.content != null) {
|
|
3593
|
+
for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
|
|
3594
|
+
const part = value.message.content[contentIndex];
|
|
3595
|
+
if (part.type === "tool_use") {
|
|
3596
|
+
const caller = part.caller;
|
|
3597
|
+
const callerInfo = caller ? {
|
|
3598
|
+
type: caller.type,
|
|
3599
|
+
toolId: "tool_id" in caller ? caller.tool_id : void 0
|
|
3600
|
+
} : void 0;
|
|
3601
|
+
controller.enqueue({
|
|
3602
|
+
type: "tool-input-start",
|
|
3603
|
+
id: part.id,
|
|
3604
|
+
toolName: part.name
|
|
3605
|
+
});
|
|
3606
|
+
const inputStr = JSON.stringify((_h = part.input) != null ? _h : {});
|
|
3607
|
+
controller.enqueue({
|
|
3608
|
+
type: "tool-input-delta",
|
|
3609
|
+
id: part.id,
|
|
3610
|
+
delta: inputStr
|
|
3611
|
+
});
|
|
3612
|
+
controller.enqueue({
|
|
3613
|
+
type: "tool-input-end",
|
|
3614
|
+
id: part.id
|
|
3615
|
+
});
|
|
3616
|
+
controller.enqueue({
|
|
3617
|
+
type: "tool-call",
|
|
3618
|
+
toolCallId: part.id,
|
|
3619
|
+
toolName: part.name,
|
|
3620
|
+
input: inputStr,
|
|
3621
|
+
...callerInfo && {
|
|
3622
|
+
providerMetadata: {
|
|
3623
|
+
anthropic: {
|
|
3624
|
+
caller: callerInfo
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
3628
|
+
});
|
|
3629
|
+
}
|
|
3630
|
+
}
|
|
3631
|
+
}
|
|
3373
3632
|
return;
|
|
3374
3633
|
}
|
|
3375
3634
|
case "message_delta": {
|
|
@@ -3378,15 +3637,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3378
3637
|
finishReason: value.delta.stop_reason,
|
|
3379
3638
|
isJsonResponseFromTool
|
|
3380
3639
|
});
|
|
3381
|
-
stopSequence = (
|
|
3640
|
+
stopSequence = (_i = value.delta.stop_sequence) != null ? _i : null;
|
|
3382
3641
|
container = value.delta.container != null ? {
|
|
3383
3642
|
expiresAt: value.delta.container.expires_at,
|
|
3384
3643
|
id: value.delta.container.id,
|
|
3385
|
-
skills: (
|
|
3644
|
+
skills: (_k = (_j = value.delta.container.skills) == null ? void 0 : _j.map((skill) => ({
|
|
3386
3645
|
type: skill.type,
|
|
3387
3646
|
skillId: skill.skill_id,
|
|
3388
3647
|
version: skill.version
|
|
3389
|
-
}))) != null ?
|
|
3648
|
+
}))) != null ? _k : null
|
|
3390
3649
|
} : null;
|
|
3391
3650
|
if (value.delta.context_management) {
|
|
3392
3651
|
contextManagement = mapAnthropicResponseContextManagement(
|