@ai-sdk/anthropic 3.0.0-beta.92 → 3.0.0-beta.93
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 +8 -0
- package/dist/index.d.mts +49 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.js +336 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +334 -54
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +40 -0
- package/dist/internal/index.d.ts +40 -0
- package/dist/internal/index.js +311 -52
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +311 -52
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/internal/index.js
CHANGED
|
@@ -127,7 +127,17 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
127
127
|
type: import_v42.z.literal("tool_use"),
|
|
128
128
|
id: import_v42.z.string(),
|
|
129
129
|
name: import_v42.z.string(),
|
|
130
|
-
input: import_v42.z.unknown()
|
|
130
|
+
input: import_v42.z.unknown(),
|
|
131
|
+
// Programmatic tool calling: caller info when triggered from code execution
|
|
132
|
+
caller: import_v42.z.union([
|
|
133
|
+
import_v42.z.object({
|
|
134
|
+
type: import_v42.z.literal("code_execution_20250825"),
|
|
135
|
+
tool_id: import_v42.z.string()
|
|
136
|
+
}),
|
|
137
|
+
import_v42.z.object({
|
|
138
|
+
type: import_v42.z.literal("direct")
|
|
139
|
+
})
|
|
140
|
+
]).optional()
|
|
131
141
|
}),
|
|
132
142
|
import_v42.z.object({
|
|
133
143
|
type: import_v42.z.literal("server_tool_use"),
|
|
@@ -213,7 +223,13 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
213
223
|
type: import_v42.z.literal("code_execution_result"),
|
|
214
224
|
stdout: import_v42.z.string(),
|
|
215
225
|
stderr: import_v42.z.string(),
|
|
216
|
-
return_code: import_v42.z.number()
|
|
226
|
+
return_code: import_v42.z.number(),
|
|
227
|
+
content: import_v42.z.array(
|
|
228
|
+
import_v42.z.object({
|
|
229
|
+
type: import_v42.z.literal("code_execution_output"),
|
|
230
|
+
file_id: import_v42.z.string()
|
|
231
|
+
})
|
|
232
|
+
).optional().default([])
|
|
217
233
|
}),
|
|
218
234
|
import_v42.z.object({
|
|
219
235
|
type: import_v42.z.literal("code_execution_tool_result_error"),
|
|
@@ -345,11 +361,37 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
345
361
|
message: import_v42.z.object({
|
|
346
362
|
id: import_v42.z.string().nullish(),
|
|
347
363
|
model: import_v42.z.string().nullish(),
|
|
364
|
+
role: import_v42.z.string().nullish(),
|
|
348
365
|
usage: import_v42.z.looseObject({
|
|
349
366
|
input_tokens: import_v42.z.number(),
|
|
350
367
|
cache_creation_input_tokens: import_v42.z.number().nullish(),
|
|
351
368
|
cache_read_input_tokens: import_v42.z.number().nullish()
|
|
352
|
-
})
|
|
369
|
+
}),
|
|
370
|
+
// Programmatic tool calling: content may be pre-populated for deferred tool calls
|
|
371
|
+
content: import_v42.z.array(
|
|
372
|
+
import_v42.z.discriminatedUnion("type", [
|
|
373
|
+
import_v42.z.object({
|
|
374
|
+
type: import_v42.z.literal("tool_use"),
|
|
375
|
+
id: import_v42.z.string(),
|
|
376
|
+
name: import_v42.z.string(),
|
|
377
|
+
input: import_v42.z.unknown(),
|
|
378
|
+
caller: import_v42.z.union([
|
|
379
|
+
import_v42.z.object({
|
|
380
|
+
type: import_v42.z.literal("code_execution_20250825"),
|
|
381
|
+
tool_id: import_v42.z.string()
|
|
382
|
+
}),
|
|
383
|
+
import_v42.z.object({
|
|
384
|
+
type: import_v42.z.literal("direct")
|
|
385
|
+
})
|
|
386
|
+
]).optional()
|
|
387
|
+
})
|
|
388
|
+
])
|
|
389
|
+
).nullish(),
|
|
390
|
+
stop_reason: import_v42.z.string().nullish(),
|
|
391
|
+
container: import_v42.z.object({
|
|
392
|
+
expires_at: import_v42.z.string(),
|
|
393
|
+
id: import_v42.z.string()
|
|
394
|
+
}).nullish()
|
|
353
395
|
})
|
|
354
396
|
}),
|
|
355
397
|
import_v42.z.object({
|
|
@@ -367,7 +409,19 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
367
409
|
import_v42.z.object({
|
|
368
410
|
type: import_v42.z.literal("tool_use"),
|
|
369
411
|
id: import_v42.z.string(),
|
|
370
|
-
name: import_v42.z.string()
|
|
412
|
+
name: import_v42.z.string(),
|
|
413
|
+
// Programmatic tool calling: input may be present directly for deferred tool calls
|
|
414
|
+
input: import_v42.z.record(import_v42.z.string(), import_v42.z.unknown()).optional(),
|
|
415
|
+
// Programmatic tool calling: caller info when triggered from code execution
|
|
416
|
+
caller: import_v42.z.union([
|
|
417
|
+
import_v42.z.object({
|
|
418
|
+
type: import_v42.z.literal("code_execution_20250825"),
|
|
419
|
+
tool_id: import_v42.z.string()
|
|
420
|
+
}),
|
|
421
|
+
import_v42.z.object({
|
|
422
|
+
type: import_v42.z.literal("direct")
|
|
423
|
+
})
|
|
424
|
+
]).optional()
|
|
371
425
|
}),
|
|
372
426
|
import_v42.z.object({
|
|
373
427
|
type: import_v42.z.literal("redacted_thinking"),
|
|
@@ -457,7 +511,13 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
457
511
|
type: import_v42.z.literal("code_execution_result"),
|
|
458
512
|
stdout: import_v42.z.string(),
|
|
459
513
|
stderr: import_v42.z.string(),
|
|
460
|
-
return_code: import_v42.z.number()
|
|
514
|
+
return_code: import_v42.z.number(),
|
|
515
|
+
content: import_v42.z.array(
|
|
516
|
+
import_v42.z.object({
|
|
517
|
+
type: import_v42.z.literal("code_execution_output"),
|
|
518
|
+
file_id: import_v42.z.string()
|
|
519
|
+
})
|
|
520
|
+
).optional().default([])
|
|
461
521
|
}),
|
|
462
522
|
import_v42.z.object({
|
|
463
523
|
type: import_v42.z.literal("code_execution_tool_result_error"),
|
|
@@ -1018,6 +1078,7 @@ async function prepareTools({
|
|
|
1018
1078
|
});
|
|
1019
1079
|
const anthropicOptions = (_a = tool.providerOptions) == null ? void 0 : _a.anthropic;
|
|
1020
1080
|
const deferLoading = anthropicOptions == null ? void 0 : anthropicOptions.deferLoading;
|
|
1081
|
+
const allowedCallers = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers;
|
|
1021
1082
|
anthropicTools2.push({
|
|
1022
1083
|
name: tool.name,
|
|
1023
1084
|
description: tool.description,
|
|
@@ -1025,6 +1086,7 @@ async function prepareTools({
|
|
|
1025
1086
|
cache_control: cacheControl,
|
|
1026
1087
|
...supportsStructuredOutput === true && tool.strict != null ? { strict: tool.strict } : {},
|
|
1027
1088
|
...deferLoading != null ? { defer_loading: deferLoading } : {},
|
|
1089
|
+
...allowedCallers != null ? { allowed_callers: allowedCallers } : {},
|
|
1028
1090
|
...tool.inputExamples != null ? {
|
|
1029
1091
|
input_examples: tool.inputExamples.map(
|
|
1030
1092
|
(example) => example.input
|
|
@@ -1034,7 +1096,7 @@ async function prepareTools({
|
|
|
1034
1096
|
if (supportsStructuredOutput === true) {
|
|
1035
1097
|
betas.add("structured-outputs-2025-11-13");
|
|
1036
1098
|
}
|
|
1037
|
-
if (tool.inputExamples != null) {
|
|
1099
|
+
if (tool.inputExamples != null || allowedCallers != null) {
|
|
1038
1100
|
betas.add("advanced-tool-use-2025-11-20");
|
|
1039
1101
|
}
|
|
1040
1102
|
break;
|
|
@@ -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(
|