@ai-sdk/anthropic 3.0.0-beta.91 → 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/dist/index.js CHANGED
@@ -22,7 +22,8 @@ var src_exports = {};
22
22
  __export(src_exports, {
23
23
  VERSION: () => VERSION,
24
24
  anthropic: () => anthropic,
25
- createAnthropic: () => createAnthropic
25
+ createAnthropic: () => createAnthropic,
26
+ forwardAnthropicContainerIdFromLastStep: () => forwardAnthropicContainerIdFromLastStep
26
27
  });
27
28
  module.exports = __toCommonJS(src_exports);
28
29
 
@@ -31,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
31
32
  var import_provider_utils22 = require("@ai-sdk/provider-utils");
32
33
 
33
34
  // src/version.ts
34
- var VERSION = true ? "3.0.0-beta.91" : "0.0.0-test";
35
+ var VERSION = true ? "3.0.0-beta.93" : "0.0.0-test";
35
36
 
36
37
  // src/anthropic-messages-language-model.ts
37
38
  var import_provider3 = require("@ai-sdk/provider");
@@ -134,7 +135,17 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
134
135
  type: import_v42.z.literal("tool_use"),
135
136
  id: import_v42.z.string(),
136
137
  name: import_v42.z.string(),
137
- input: import_v42.z.unknown()
138
+ input: import_v42.z.unknown(),
139
+ // Programmatic tool calling: caller info when triggered from code execution
140
+ caller: import_v42.z.union([
141
+ import_v42.z.object({
142
+ type: import_v42.z.literal("code_execution_20250825"),
143
+ tool_id: import_v42.z.string()
144
+ }),
145
+ import_v42.z.object({
146
+ type: import_v42.z.literal("direct")
147
+ })
148
+ ]).optional()
138
149
  }),
139
150
  import_v42.z.object({
140
151
  type: import_v42.z.literal("server_tool_use"),
@@ -220,7 +231,13 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
220
231
  type: import_v42.z.literal("code_execution_result"),
221
232
  stdout: import_v42.z.string(),
222
233
  stderr: import_v42.z.string(),
223
- return_code: import_v42.z.number()
234
+ return_code: import_v42.z.number(),
235
+ content: import_v42.z.array(
236
+ import_v42.z.object({
237
+ type: import_v42.z.literal("code_execution_output"),
238
+ file_id: import_v42.z.string()
239
+ })
240
+ ).optional().default([])
224
241
  }),
225
242
  import_v42.z.object({
226
243
  type: import_v42.z.literal("code_execution_tool_result_error"),
@@ -352,11 +369,37 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
352
369
  message: import_v42.z.object({
353
370
  id: import_v42.z.string().nullish(),
354
371
  model: import_v42.z.string().nullish(),
372
+ role: import_v42.z.string().nullish(),
355
373
  usage: import_v42.z.looseObject({
356
374
  input_tokens: import_v42.z.number(),
357
375
  cache_creation_input_tokens: import_v42.z.number().nullish(),
358
376
  cache_read_input_tokens: import_v42.z.number().nullish()
359
- })
377
+ }),
378
+ // Programmatic tool calling: content may be pre-populated for deferred tool calls
379
+ content: import_v42.z.array(
380
+ import_v42.z.discriminatedUnion("type", [
381
+ import_v42.z.object({
382
+ type: import_v42.z.literal("tool_use"),
383
+ id: import_v42.z.string(),
384
+ name: import_v42.z.string(),
385
+ input: import_v42.z.unknown(),
386
+ caller: import_v42.z.union([
387
+ import_v42.z.object({
388
+ type: import_v42.z.literal("code_execution_20250825"),
389
+ tool_id: import_v42.z.string()
390
+ }),
391
+ import_v42.z.object({
392
+ type: import_v42.z.literal("direct")
393
+ })
394
+ ]).optional()
395
+ })
396
+ ])
397
+ ).nullish(),
398
+ stop_reason: import_v42.z.string().nullish(),
399
+ container: import_v42.z.object({
400
+ expires_at: import_v42.z.string(),
401
+ id: import_v42.z.string()
402
+ }).nullish()
360
403
  })
361
404
  }),
362
405
  import_v42.z.object({
@@ -374,7 +417,19 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
374
417
  import_v42.z.object({
375
418
  type: import_v42.z.literal("tool_use"),
376
419
  id: import_v42.z.string(),
377
- name: import_v42.z.string()
420
+ name: import_v42.z.string(),
421
+ // Programmatic tool calling: input may be present directly for deferred tool calls
422
+ input: import_v42.z.record(import_v42.z.string(), import_v42.z.unknown()).optional(),
423
+ // Programmatic tool calling: caller info when triggered from code execution
424
+ caller: import_v42.z.union([
425
+ import_v42.z.object({
426
+ type: import_v42.z.literal("code_execution_20250825"),
427
+ tool_id: import_v42.z.string()
428
+ }),
429
+ import_v42.z.object({
430
+ type: import_v42.z.literal("direct")
431
+ })
432
+ ]).optional()
378
433
  }),
379
434
  import_v42.z.object({
380
435
  type: import_v42.z.literal("redacted_thinking"),
@@ -464,7 +519,13 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
464
519
  type: import_v42.z.literal("code_execution_result"),
465
520
  stdout: import_v42.z.string(),
466
521
  stderr: import_v42.z.string(),
467
- return_code: import_v42.z.number()
522
+ return_code: import_v42.z.number(),
523
+ content: import_v42.z.array(
524
+ import_v42.z.object({
525
+ type: import_v42.z.literal("code_execution_output"),
526
+ file_id: import_v42.z.string()
527
+ })
528
+ ).optional().default([])
468
529
  }),
469
530
  import_v42.z.object({
470
531
  type: import_v42.z.literal("code_execution_tool_result_error"),
@@ -1025,6 +1086,7 @@ async function prepareTools({
1025
1086
  });
1026
1087
  const anthropicOptions = (_a = tool.providerOptions) == null ? void 0 : _a.anthropic;
1027
1088
  const deferLoading = anthropicOptions == null ? void 0 : anthropicOptions.deferLoading;
1089
+ const allowedCallers = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers;
1028
1090
  anthropicTools2.push({
1029
1091
  name: tool.name,
1030
1092
  description: tool.description,
@@ -1032,6 +1094,7 @@ async function prepareTools({
1032
1094
  cache_control: cacheControl,
1033
1095
  ...supportsStructuredOutput === true && tool.strict != null ? { strict: tool.strict } : {},
1034
1096
  ...deferLoading != null ? { defer_loading: deferLoading } : {},
1097
+ ...allowedCallers != null ? { allowed_callers: allowedCallers } : {},
1035
1098
  ...tool.inputExamples != null ? {
1036
1099
  input_examples: tool.inputExamples.map(
1037
1100
  (example) => example.input
@@ -1041,7 +1104,7 @@ async function prepareTools({
1041
1104
  if (supportsStructuredOutput === true) {
1042
1105
  betas.add("structured-outputs-2025-11-13");
1043
1106
  }
1044
- if (tool.inputExamples != null) {
1107
+ if (tool.inputExamples != null || allowedCallers != null) {
1045
1108
  betas.add("advanced-tool-use-2025-11-20");
1046
1109
  }
1047
1110
  break;
@@ -1289,7 +1352,13 @@ var codeExecution_20250522OutputSchema = (0, import_provider_utils8.lazySchema)(
1289
1352
  type: import_v47.z.literal("code_execution_result"),
1290
1353
  stdout: import_v47.z.string(),
1291
1354
  stderr: import_v47.z.string(),
1292
- return_code: import_v47.z.number()
1355
+ return_code: import_v47.z.number(),
1356
+ content: import_v47.z.array(
1357
+ import_v47.z.object({
1358
+ type: import_v47.z.literal("code_execution_output"),
1359
+ file_id: import_v47.z.string()
1360
+ })
1361
+ ).optional().default([])
1293
1362
  })
1294
1363
  )
1295
1364
  );
@@ -1315,6 +1384,18 @@ var import_v48 = require("zod/v4");
1315
1384
  var codeExecution_20250825OutputSchema = (0, import_provider_utils9.lazySchema)(
1316
1385
  () => (0, import_provider_utils9.zodSchema)(
1317
1386
  import_v48.z.discriminatedUnion("type", [
1387
+ import_v48.z.object({
1388
+ type: import_v48.z.literal("code_execution_result"),
1389
+ stdout: import_v48.z.string(),
1390
+ stderr: import_v48.z.string(),
1391
+ return_code: import_v48.z.number(),
1392
+ content: import_v48.z.array(
1393
+ import_v48.z.object({
1394
+ type: import_v48.z.literal("code_execution_output"),
1395
+ file_id: import_v48.z.string()
1396
+ })
1397
+ ).optional().default([])
1398
+ }),
1318
1399
  import_v48.z.object({
1319
1400
  type: import_v48.z.literal("bash_code_execution_result"),
1320
1401
  content: import_v48.z.array(
@@ -1361,6 +1442,11 @@ var codeExecution_20250825OutputSchema = (0, import_provider_utils9.lazySchema)(
1361
1442
  var codeExecution_20250825InputSchema = (0, import_provider_utils9.lazySchema)(
1362
1443
  () => (0, import_provider_utils9.zodSchema)(
1363
1444
  import_v48.z.discriminatedUnion("type", [
1445
+ // Programmatic tool calling format (mapped from { code } by AI SDK)
1446
+ import_v48.z.object({
1447
+ type: import_v48.z.literal("programmatic-tool-call"),
1448
+ code: import_v48.z.string()
1449
+ }),
1364
1450
  import_v48.z.object({
1365
1451
  type: import_v48.z.literal("bash_code_execution"),
1366
1452
  command: import_v48.z.string()
@@ -1391,7 +1477,11 @@ var codeExecution_20250825InputSchema = (0, import_provider_utils9.lazySchema)(
1391
1477
  var factory5 = (0, import_provider_utils9.createProviderToolFactoryWithOutputSchema)({
1392
1478
  id: "anthropic.code_execution_20250825",
1393
1479
  inputSchema: codeExecution_20250825InputSchema,
1394
- outputSchema: codeExecution_20250825OutputSchema
1480
+ outputSchema: codeExecution_20250825OutputSchema,
1481
+ // Programmatic tool calling: tool results may be deferred to a later turn
1482
+ // when code execution triggers a client-executed tool that needs to be
1483
+ // resolved before the code execution result can be returned.
1484
+ supportsDeferredResults: true
1395
1485
  });
1396
1486
  var codeExecution_20250825 = (args = {}) => {
1397
1487
  return factory5(args);
@@ -1464,7 +1554,7 @@ async function convertToAnthropicMessagesPrompt({
1464
1554
  cacheControlValidator,
1465
1555
  toolNameMapping
1466
1556
  }) {
1467
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1557
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1468
1558
  const betas = /* @__PURE__ */ new Set();
1469
1559
  const blocks = groupIntoBlocks(prompt);
1470
1560
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -1834,6 +1924,19 @@ async function convertToAnthropicMessagesPrompt({
1834
1924
  input: part.input,
1835
1925
  cache_control: cacheControl
1836
1926
  });
1927
+ } else if (
1928
+ // code execution 20250825 programmatic tool calling:
1929
+ // Strip the fake 'programmatic-tool-call' type before sending to Anthropic
1930
+ providerToolName === "code_execution" && part.input != null && typeof part.input === "object" && "type" in part.input && part.input.type === "programmatic-tool-call"
1931
+ ) {
1932
+ const { type: _, ...inputWithoutType } = part.input;
1933
+ anthropicContent.push({
1934
+ type: "server_tool_use",
1935
+ id: part.toolCallId,
1936
+ name: "code_execution",
1937
+ input: inputWithoutType,
1938
+ cache_control: cacheControl
1939
+ });
1837
1940
  } else {
1838
1941
  if (providerToolName === "code_execution" || // code execution 20250522
1839
1942
  providerToolName === "web_fetch" || providerToolName === "web_search") {
@@ -1861,11 +1964,17 @@ async function convertToAnthropicMessagesPrompt({
1861
1964
  }
1862
1965
  break;
1863
1966
  }
1967
+ const callerOptions = (_k = part.providerOptions) == null ? void 0 : _k.anthropic;
1968
+ const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? callerOptions.caller.type === "code_execution_20250825" && callerOptions.caller.toolId ? {
1969
+ type: "code_execution_20250825",
1970
+ tool_id: callerOptions.caller.toolId
1971
+ } : callerOptions.caller.type === "direct" ? { type: "direct" } : void 0 : void 0;
1864
1972
  anthropicContent.push({
1865
1973
  type: "tool_use",
1866
1974
  id: part.toolCallId,
1867
1975
  name: part.toolName,
1868
1976
  input: part.input,
1977
+ ...caller && { caller },
1869
1978
  cache_control: cacheControl
1870
1979
  });
1871
1980
  break;
@@ -1892,6 +2001,39 @@ async function convertToAnthropicMessagesPrompt({
1892
2001
  });
1893
2002
  } else if (providerToolName === "code_execution") {
1894
2003
  const output = part.output;
2004
+ if (output.type === "error-text" || output.type === "error-json") {
2005
+ let errorInfo = {};
2006
+ try {
2007
+ if (typeof output.value === "string") {
2008
+ errorInfo = JSON.parse(output.value);
2009
+ } else if (typeof output.value === "object" && output.value !== null) {
2010
+ errorInfo = output.value;
2011
+ }
2012
+ } catch (e) {
2013
+ }
2014
+ if (errorInfo.type === "code_execution_tool_result_error") {
2015
+ anthropicContent.push({
2016
+ type: "code_execution_tool_result",
2017
+ tool_use_id: part.toolCallId,
2018
+ content: {
2019
+ type: "code_execution_tool_result_error",
2020
+ error_code: (_l = errorInfo.errorCode) != null ? _l : "unknown"
2021
+ },
2022
+ cache_control: cacheControl
2023
+ });
2024
+ } else {
2025
+ anthropicContent.push({
2026
+ type: "bash_code_execution_tool_result",
2027
+ tool_use_id: part.toolCallId,
2028
+ cache_control: cacheControl,
2029
+ content: {
2030
+ type: "bash_code_execution_tool_result_error",
2031
+ error_code: (_m = errorInfo.errorCode) != null ? _m : "unknown"
2032
+ }
2033
+ });
2034
+ }
2035
+ break;
2036
+ }
1895
2037
  if (output.type !== "json") {
1896
2038
  warnings.push({
1897
2039
  type: "other",
@@ -1918,7 +2060,8 @@ async function convertToAnthropicMessagesPrompt({
1918
2060
  type: codeExecutionOutput.type,
1919
2061
  stdout: codeExecutionOutput.stdout,
1920
2062
  stderr: codeExecutionOutput.stderr,
1921
- return_code: codeExecutionOutput.return_code
2063
+ return_code: codeExecutionOutput.return_code,
2064
+ content: (_n = codeExecutionOutput.content) != null ? _n : []
1922
2065
  },
1923
2066
  cache_control: cacheControl
1924
2067
  });
@@ -1927,19 +2070,34 @@ async function convertToAnthropicMessagesPrompt({
1927
2070
  value: output.value,
1928
2071
  schema: codeExecution_20250825OutputSchema
1929
2072
  });
1930
- anthropicContent.push(
1931
- codeExecutionOutput.type === "bash_code_execution_result" || codeExecutionOutput.type === "bash_code_execution_tool_result_error" ? {
2073
+ if (codeExecutionOutput.type === "code_execution_result") {
2074
+ anthropicContent.push({
2075
+ type: "code_execution_tool_result",
2076
+ tool_use_id: part.toolCallId,
2077
+ content: {
2078
+ type: codeExecutionOutput.type,
2079
+ stdout: codeExecutionOutput.stdout,
2080
+ stderr: codeExecutionOutput.stderr,
2081
+ return_code: codeExecutionOutput.return_code,
2082
+ content: (_o = codeExecutionOutput.content) != null ? _o : []
2083
+ },
2084
+ cache_control: cacheControl
2085
+ });
2086
+ } else if (codeExecutionOutput.type === "bash_code_execution_result" || codeExecutionOutput.type === "bash_code_execution_tool_result_error") {
2087
+ anthropicContent.push({
1932
2088
  type: "bash_code_execution_tool_result",
1933
2089
  tool_use_id: part.toolCallId,
1934
2090
  cache_control: cacheControl,
1935
2091
  content: codeExecutionOutput
1936
- } : {
2092
+ });
2093
+ } else {
2094
+ anthropicContent.push({
1937
2095
  type: "text_editor_code_execution_tool_result",
1938
2096
  tool_use_id: part.toolCallId,
1939
2097
  cache_control: cacheControl,
1940
2098
  content: codeExecutionOutput
1941
- }
1942
- );
2099
+ });
2100
+ }
1943
2101
  }
1944
2102
  break;
1945
2103
  }
@@ -2191,7 +2349,7 @@ var AnthropicMessagesLanguageModel = class {
2191
2349
  providerOptions,
2192
2350
  stream
2193
2351
  }) {
2194
- var _a, _b, _c, _d, _e, _f, _g;
2352
+ var _a, _b, _c, _d, _e, _f;
2195
2353
  const warnings = [];
2196
2354
  if (frequencyPenalty != null) {
2197
2355
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -2313,16 +2471,22 @@ var AnthropicMessagesLanguageModel = class {
2313
2471
  } : void 0
2314
2472
  }))
2315
2473
  },
2316
- // container with agent skills:
2474
+ // container: For programmatic tool calling (just an ID string) or agent skills (object with id and skills)
2317
2475
  ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
2318
- container: {
2319
- id: anthropicOptions.container.id,
2320
- skills: (_f = anthropicOptions.container.skills) == null ? void 0 : _f.map((skill) => ({
2321
- type: skill.type,
2322
- skill_id: skill.skillId,
2323
- version: skill.version
2324
- }))
2325
- }
2476
+ container: anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0 ? (
2477
+ // Object format when skills are provided (agent skills feature)
2478
+ {
2479
+ id: anthropicOptions.container.id,
2480
+ skills: anthropicOptions.container.skills.map((skill) => ({
2481
+ type: skill.type,
2482
+ skill_id: skill.skillId,
2483
+ version: skill.version
2484
+ }))
2485
+ }
2486
+ ) : (
2487
+ // String format for container ID only (programmatic tool calling)
2488
+ anthropicOptions.container.id
2489
+ )
2326
2490
  },
2327
2491
  // prompt:
2328
2492
  system: messagesPrompt.system,
@@ -2436,7 +2600,7 @@ var AnthropicMessagesLanguageModel = class {
2436
2600
  if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
2437
2601
  betas.add("effort-2025-11-24");
2438
2602
  }
2439
- if (stream && ((_g = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _g : true)) {
2603
+ if (stream && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _f : true)) {
2440
2604
  betas.add("fine-grained-tool-streaming-2025-05-14");
2441
2605
  }
2442
2606
  const usingNativeOutputFormat = useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
@@ -2532,7 +2696,7 @@ var AnthropicMessagesLanguageModel = class {
2532
2696
  });
2533
2697
  }
2534
2698
  async doGenerate(options) {
2535
- var _a, _b, _c, _d, _e, _f, _g, _h;
2699
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2536
2700
  const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
2537
2701
  ...options,
2538
2702
  stream: false,
@@ -2610,11 +2774,23 @@ var AnthropicMessagesLanguageModel = class {
2610
2774
  text: JSON.stringify(part.input)
2611
2775
  });
2612
2776
  } else {
2777
+ const caller = part.caller;
2778
+ const callerInfo = caller ? {
2779
+ type: caller.type,
2780
+ toolId: "tool_id" in caller ? caller.tool_id : void 0
2781
+ } : void 0;
2613
2782
  content.push({
2614
2783
  type: "tool-call",
2615
2784
  toolCallId: part.id,
2616
2785
  toolName: part.name,
2617
- input: JSON.stringify(part.input)
2786
+ input: JSON.stringify(part.input),
2787
+ ...callerInfo && {
2788
+ providerMetadata: {
2789
+ anthropic: {
2790
+ caller: callerInfo
2791
+ }
2792
+ }
2793
+ }
2618
2794
  });
2619
2795
  }
2620
2796
  break;
@@ -2629,11 +2805,12 @@ var AnthropicMessagesLanguageModel = class {
2629
2805
  providerExecuted: true
2630
2806
  });
2631
2807
  } else if (part.name === "web_search" || part.name === "code_execution" || part.name === "web_fetch") {
2808
+ 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;
2632
2809
  content.push({
2633
2810
  type: "tool-call",
2634
2811
  toolCallId: part.id,
2635
2812
  toolName: toolNameMapping.toCustomToolName(part.name),
2636
- input: JSON.stringify(part.input),
2813
+ input: JSON.stringify(inputToSerialize),
2637
2814
  providerExecuted: true
2638
2815
  });
2639
2816
  } else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
@@ -2769,7 +2946,8 @@ var AnthropicMessagesLanguageModel = class {
2769
2946
  type: part.content.type,
2770
2947
  stdout: part.content.stdout,
2771
2948
  stderr: part.content.stderr,
2772
- return_code: part.content.return_code
2949
+ return_code: part.content.return_code,
2950
+ content: (_b = part.content.content) != null ? _b : []
2773
2951
  }
2774
2952
  });
2775
2953
  } else if (part.content.type === "code_execution_tool_result_error") {
@@ -2834,8 +3012,8 @@ var AnthropicMessagesLanguageModel = class {
2834
3012
  usage: convertAnthropicMessagesUsage(response.usage),
2835
3013
  request: { body: args },
2836
3014
  response: {
2837
- id: (_b = response.id) != null ? _b : void 0,
2838
- modelId: (_c = response.model) != null ? _c : void 0,
3015
+ id: (_c = response.id) != null ? _c : void 0,
3016
+ modelId: (_d = response.model) != null ? _d : void 0,
2839
3017
  headers: responseHeaders,
2840
3018
  body: rawResponse
2841
3019
  },
@@ -2843,20 +3021,20 @@ var AnthropicMessagesLanguageModel = class {
2843
3021
  providerMetadata: {
2844
3022
  anthropic: {
2845
3023
  usage: response.usage,
2846
- cacheCreationInputTokens: (_d = response.usage.cache_creation_input_tokens) != null ? _d : null,
2847
- stopSequence: (_e = response.stop_sequence) != null ? _e : null,
3024
+ cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null,
3025
+ stopSequence: (_f = response.stop_sequence) != null ? _f : null,
2848
3026
  container: response.container ? {
2849
3027
  expiresAt: response.container.expires_at,
2850
3028
  id: response.container.id,
2851
- skills: (_g = (_f = response.container.skills) == null ? void 0 : _f.map((skill) => ({
3029
+ skills: (_h = (_g = response.container.skills) == null ? void 0 : _g.map((skill) => ({
2852
3030
  type: skill.type,
2853
3031
  skillId: skill.skill_id,
2854
3032
  version: skill.version
2855
- }))) != null ? _g : null
3033
+ }))) != null ? _h : null
2856
3034
  } : null,
2857
- contextManagement: (_h = mapAnthropicResponseContextManagement(
3035
+ contextManagement: (_i = mapAnthropicResponseContextManagement(
2858
3036
  response.context_management
2859
- )) != null ? _h : null
3037
+ )) != null ? _i : null
2860
3038
  }
2861
3039
  }
2862
3040
  };
@@ -2910,7 +3088,7 @@ var AnthropicMessagesLanguageModel = class {
2910
3088
  controller.enqueue({ type: "stream-start", warnings });
2911
3089
  },
2912
3090
  transform(chunk, controller) {
2913
- var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
3091
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2914
3092
  if (options.includeRawChunks) {
2915
3093
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2916
3094
  }
@@ -2970,12 +3148,20 @@ var AnthropicMessagesLanguageModel = class {
2970
3148
  id: String(value.index)
2971
3149
  });
2972
3150
  } else {
3151
+ const caller = part.caller;
3152
+ const callerInfo = caller ? {
3153
+ type: caller.type,
3154
+ toolId: "tool_id" in caller ? caller.tool_id : void 0
3155
+ } : void 0;
3156
+ const hasNonEmptyInput = part.input && Object.keys(part.input).length > 0;
3157
+ const initialInput = hasNonEmptyInput ? JSON.stringify(part.input) : "";
2973
3158
  contentBlocks[value.index] = {
2974
3159
  type: "tool-call",
2975
3160
  toolCallId: part.id,
2976
3161
  toolName: part.name,
2977
- input: "",
2978
- firstDelta: true
3162
+ input: initialInput,
3163
+ firstDelta: initialInput.length === 0,
3164
+ ...callerInfo && { caller: callerInfo }
2979
3165
  };
2980
3166
  controller.enqueue({
2981
3167
  type: "tool-input-start",
@@ -3127,7 +3313,8 @@ var AnthropicMessagesLanguageModel = class {
3127
3313
  type: part.content.type,
3128
3314
  stdout: part.content.stdout,
3129
3315
  stderr: part.content.stderr,
3130
- return_code: part.content.return_code
3316
+ return_code: part.content.return_code,
3317
+ content: (_b2 = part.content.content) != null ? _b2 : []
3131
3318
  }
3132
3319
  });
3133
3320
  } else if (part.content.type === "code_execution_tool_result_error") {
@@ -3244,12 +3431,32 @@ var AnthropicMessagesLanguageModel = class {
3244
3431
  type: "tool-input-end",
3245
3432
  id: contentBlock.toolCallId
3246
3433
  });
3434
+ let finalInput = contentBlock.input === "" ? "{}" : contentBlock.input;
3435
+ if (contentBlock.providerToolName === "code_execution") {
3436
+ try {
3437
+ const parsed = JSON.parse(finalInput);
3438
+ if (parsed != null && typeof parsed === "object" && "code" in parsed && !("type" in parsed)) {
3439
+ finalInput = JSON.stringify({
3440
+ type: "programmatic-tool-call",
3441
+ ...parsed
3442
+ });
3443
+ }
3444
+ } catch (e) {
3445
+ }
3446
+ }
3247
3447
  controller.enqueue({
3248
3448
  type: "tool-call",
3249
3449
  toolCallId: contentBlock.toolCallId,
3250
3450
  toolName: contentBlock.toolName,
3251
- input: contentBlock.input === "" ? "{}" : contentBlock.input,
3252
- providerExecuted: contentBlock.providerExecuted
3451
+ input: finalInput,
3452
+ providerExecuted: contentBlock.providerExecuted,
3453
+ ...contentBlock.caller && {
3454
+ providerMetadata: {
3455
+ anthropic: {
3456
+ caller: contentBlock.caller
3457
+ }
3458
+ }
3459
+ }
3253
3460
  });
3254
3461
  }
3255
3462
  break;
@@ -3350,17 +3557,70 @@ var AnthropicMessagesLanguageModel = class {
3350
3557
  }
3351
3558
  case "message_start": {
3352
3559
  usage.input_tokens = value.message.usage.input_tokens;
3353
- usage.cache_read_input_tokens = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : 0;
3354
- usage.cache_creation_input_tokens = (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : 0;
3560
+ usage.cache_read_input_tokens = (_c = value.message.usage.cache_read_input_tokens) != null ? _c : 0;
3561
+ usage.cache_creation_input_tokens = (_d = value.message.usage.cache_creation_input_tokens) != null ? _d : 0;
3355
3562
  rawUsage = {
3356
3563
  ...value.message.usage
3357
3564
  };
3358
- cacheCreationInputTokens = (_d = value.message.usage.cache_creation_input_tokens) != null ? _d : null;
3565
+ cacheCreationInputTokens = (_e = value.message.usage.cache_creation_input_tokens) != null ? _e : null;
3566
+ if (value.message.container != null) {
3567
+ container = {
3568
+ expiresAt: value.message.container.expires_at,
3569
+ id: value.message.container.id,
3570
+ skills: null
3571
+ };
3572
+ }
3573
+ if (value.message.stop_reason != null) {
3574
+ finishReason = mapAnthropicStopReason({
3575
+ finishReason: value.message.stop_reason,
3576
+ isJsonResponseFromTool
3577
+ });
3578
+ }
3359
3579
  controller.enqueue({
3360
3580
  type: "response-metadata",
3361
- id: (_e = value.message.id) != null ? _e : void 0,
3362
- modelId: (_f = value.message.model) != null ? _f : void 0
3581
+ id: (_f = value.message.id) != null ? _f : void 0,
3582
+ modelId: (_g = value.message.model) != null ? _g : void 0
3363
3583
  });
3584
+ if (value.message.content != null) {
3585
+ for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
3586
+ const part = value.message.content[contentIndex];
3587
+ if (part.type === "tool_use") {
3588
+ const caller = part.caller;
3589
+ const callerInfo = caller ? {
3590
+ type: caller.type,
3591
+ toolId: "tool_id" in caller ? caller.tool_id : void 0
3592
+ } : void 0;
3593
+ controller.enqueue({
3594
+ type: "tool-input-start",
3595
+ id: part.id,
3596
+ toolName: part.name
3597
+ });
3598
+ const inputStr = JSON.stringify((_h = part.input) != null ? _h : {});
3599
+ controller.enqueue({
3600
+ type: "tool-input-delta",
3601
+ id: part.id,
3602
+ delta: inputStr
3603
+ });
3604
+ controller.enqueue({
3605
+ type: "tool-input-end",
3606
+ id: part.id
3607
+ });
3608
+ controller.enqueue({
3609
+ type: "tool-call",
3610
+ toolCallId: part.id,
3611
+ toolName: part.name,
3612
+ input: inputStr,
3613
+ ...callerInfo && {
3614
+ providerMetadata: {
3615
+ anthropic: {
3616
+ caller: callerInfo
3617
+ }
3618
+ }
3619
+ }
3620
+ });
3621
+ }
3622
+ }
3623
+ }
3364
3624
  return;
3365
3625
  }
3366
3626
  case "message_delta": {
@@ -3369,15 +3629,15 @@ var AnthropicMessagesLanguageModel = class {
3369
3629
  finishReason: value.delta.stop_reason,
3370
3630
  isJsonResponseFromTool
3371
3631
  });
3372
- stopSequence = (_g = value.delta.stop_sequence) != null ? _g : null;
3632
+ stopSequence = (_i = value.delta.stop_sequence) != null ? _i : null;
3373
3633
  container = value.delta.container != null ? {
3374
3634
  expiresAt: value.delta.container.expires_at,
3375
3635
  id: value.delta.container.id,
3376
- skills: (_i = (_h = value.delta.container.skills) == null ? void 0 : _h.map((skill) => ({
3636
+ skills: (_k = (_j = value.delta.container.skills) == null ? void 0 : _j.map((skill) => ({
3377
3637
  type: skill.type,
3378
3638
  skillId: skill.skill_id,
3379
3639
  version: skill.version
3380
- }))) != null ? _i : null
3640
+ }))) != null ? _k : null
3381
3641
  } : null;
3382
3642
  if (value.delta.context_management) {
3383
3643
  contextManagement = mapAnthropicResponseContextManagement(
@@ -3973,10 +4233,31 @@ function createAnthropic(options = {}) {
3973
4233
  return provider;
3974
4234
  }
3975
4235
  var anthropic = createAnthropic();
4236
+
4237
+ // src/forward-anthropic-container-id-from-last-step.ts
4238
+ function forwardAnthropicContainerIdFromLastStep({
4239
+ steps
4240
+ }) {
4241
+ var _a, _b, _c;
4242
+ for (let i = steps.length - 1; i >= 0; i--) {
4243
+ const containerId = (_c = (_b = (_a = steps[i].providerMetadata) == null ? void 0 : _a.anthropic) == null ? void 0 : _b.container) == null ? void 0 : _c.id;
4244
+ if (containerId) {
4245
+ return {
4246
+ providerOptions: {
4247
+ anthropic: {
4248
+ container: { id: containerId }
4249
+ }
4250
+ }
4251
+ };
4252
+ }
4253
+ }
4254
+ return void 0;
4255
+ }
3976
4256
  // Annotate the CommonJS export names for ESM import in node:
3977
4257
  0 && (module.exports = {
3978
4258
  VERSION,
3979
4259
  anthropic,
3980
- createAnthropic
4260
+ createAnthropic,
4261
+ forwardAnthropicContainerIdFromLastStep
3981
4262
  });
3982
4263
  //# sourceMappingURL=index.js.map