@ai-sdk/anthropic 3.0.110 → 3.0.111

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 3.0.111
4
+
5
+ ### Patch Changes
6
+
7
+ - 8533108: Preserve Anthropic server-tool caller metadata in multi-turn conversations.
8
+ - Updated dependencies [31205a4]
9
+ - @ai-sdk/provider-utils@4.0.46
10
+
3
11
  ## 3.0.110
4
12
 
5
13
  ### Patch Changes
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
32
32
  var import_provider_utils26 = require("@ai-sdk/provider-utils");
33
33
 
34
34
  // src/version.ts
35
- var VERSION = true ? "3.0.110" : "0.0.0-test";
35
+ var VERSION = true ? "3.0.111" : "0.0.0-test";
36
36
 
37
37
  // src/anthropic-messages-language-model.ts
38
38
  var import_provider3 = require("@ai-sdk/provider");
@@ -66,6 +66,19 @@ var anthropicStopDetailsSchema = import_v42.z.object({
66
66
  explanation: import_v42.z.string().nullish(),
67
67
  recommended_model: import_v42.z.string().nullish()
68
68
  });
69
+ var anthropicToolCallCallerSchema = import_v42.z.union([
70
+ import_v42.z.object({
71
+ type: import_v42.z.literal("code_execution_20250825"),
72
+ tool_id: import_v42.z.string()
73
+ }),
74
+ import_v42.z.object({
75
+ type: import_v42.z.literal("code_execution_20260120"),
76
+ tool_id: import_v42.z.string()
77
+ }),
78
+ import_v42.z.object({
79
+ type: import_v42.z.literal("direct")
80
+ })
81
+ ]);
69
82
  var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
70
83
  () => (0, import_provider_utils2.zodSchema)(
71
84
  import_v42.z.object({
@@ -124,34 +137,14 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
124
137
  name: import_v42.z.string(),
125
138
  input: import_v42.z.unknown(),
126
139
  // Programmatic tool calling: caller info when triggered from code execution
127
- caller: import_v42.z.union([
128
- import_v42.z.object({
129
- type: import_v42.z.literal("code_execution_20250825"),
130
- tool_id: import_v42.z.string()
131
- }),
132
- import_v42.z.object({
133
- type: import_v42.z.literal("code_execution_20260120"),
134
- tool_id: import_v42.z.string()
135
- }),
136
- import_v42.z.object({
137
- type: import_v42.z.literal("direct")
138
- })
139
- ]).optional()
140
+ caller: anthropicToolCallCallerSchema.optional()
140
141
  }),
141
142
  import_v42.z.object({
142
143
  type: import_v42.z.literal("server_tool_use"),
143
144
  id: import_v42.z.string(),
144
145
  name: import_v42.z.string(),
145
146
  input: import_v42.z.record(import_v42.z.string(), import_v42.z.unknown()).nullish(),
146
- caller: import_v42.z.union([
147
- import_v42.z.object({
148
- type: import_v42.z.literal("code_execution_20260120"),
149
- tool_id: import_v42.z.string()
150
- }),
151
- import_v42.z.object({
152
- type: import_v42.z.literal("direct")
153
- })
154
- ]).optional()
147
+ caller: anthropicToolCallCallerSchema.optional()
155
148
  }),
156
149
  import_v42.z.object({
157
150
  type: import_v42.z.literal("mcp_tool_use"),
@@ -174,6 +167,7 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
174
167
  import_v42.z.object({
175
168
  type: import_v42.z.literal("web_fetch_tool_result"),
176
169
  tool_use_id: import_v42.z.string(),
170
+ caller: anthropicToolCallCallerSchema.optional(),
177
171
  content: import_v42.z.union([
178
172
  import_v42.z.object({
179
173
  type: import_v42.z.literal("web_fetch_result"),
@@ -206,6 +200,7 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
206
200
  import_v42.z.object({
207
201
  type: import_v42.z.literal("web_search_tool_result"),
208
202
  tool_use_id: import_v42.z.string(),
203
+ caller: anthropicToolCallCallerSchema.optional(),
209
204
  content: import_v42.z.union([
210
205
  import_v42.z.array(
211
206
  import_v42.z.object({
@@ -442,19 +437,7 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
442
437
  id: import_v42.z.string(),
443
438
  name: import_v42.z.string(),
444
439
  input: import_v42.z.unknown(),
445
- caller: import_v42.z.union([
446
- import_v42.z.object({
447
- type: import_v42.z.literal("code_execution_20250825"),
448
- tool_id: import_v42.z.string()
449
- }),
450
- import_v42.z.object({
451
- type: import_v42.z.literal("code_execution_20260120"),
452
- tool_id: import_v42.z.string()
453
- }),
454
- import_v42.z.object({
455
- type: import_v42.z.literal("direct")
456
- })
457
- ]).optional()
440
+ caller: anthropicToolCallCallerSchema.optional()
458
441
  })
459
442
  ])
460
443
  ).nullish(),
@@ -484,19 +467,7 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
484
467
  // Programmatic tool calling: input may be present directly for deferred tool calls
485
468
  input: import_v42.z.record(import_v42.z.string(), import_v42.z.unknown()).optional(),
486
469
  // Programmatic tool calling: caller info when triggered from code execution
487
- caller: import_v42.z.union([
488
- import_v42.z.object({
489
- type: import_v42.z.literal("code_execution_20250825"),
490
- tool_id: import_v42.z.string()
491
- }),
492
- import_v42.z.object({
493
- type: import_v42.z.literal("code_execution_20260120"),
494
- tool_id: import_v42.z.string()
495
- }),
496
- import_v42.z.object({
497
- type: import_v42.z.literal("direct")
498
- })
499
- ]).optional()
470
+ caller: anthropicToolCallCallerSchema.optional()
500
471
  }),
501
472
  import_v42.z.object({
502
473
  type: import_v42.z.literal("redacted_thinking"),
@@ -511,15 +482,7 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
511
482
  id: import_v42.z.string(),
512
483
  name: import_v42.z.string(),
513
484
  input: import_v42.z.record(import_v42.z.string(), import_v42.z.unknown()).nullish(),
514
- caller: import_v42.z.union([
515
- import_v42.z.object({
516
- type: import_v42.z.literal("code_execution_20260120"),
517
- tool_id: import_v42.z.string()
518
- }),
519
- import_v42.z.object({
520
- type: import_v42.z.literal("direct")
521
- })
522
- ]).optional()
485
+ caller: anthropicToolCallCallerSchema.optional()
523
486
  }),
524
487
  import_v42.z.object({
525
488
  type: import_v42.z.literal("mcp_tool_use"),
@@ -542,6 +505,7 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
542
505
  import_v42.z.object({
543
506
  type: import_v42.z.literal("web_fetch_tool_result"),
544
507
  tool_use_id: import_v42.z.string(),
508
+ caller: anthropicToolCallCallerSchema.optional(),
545
509
  content: import_v42.z.union([
546
510
  import_v42.z.object({
547
511
  type: import_v42.z.literal("web_fetch_result"),
@@ -574,6 +538,7 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
574
538
  import_v42.z.object({
575
539
  type: import_v42.z.literal("web_search_tool_result"),
576
540
  tool_use_id: import_v42.z.string(),
541
+ caller: anthropicToolCallCallerSchema.optional(),
577
542
  content: import_v42.z.union([
578
543
  import_v42.z.array(
579
544
  import_v42.z.object({
@@ -2254,7 +2219,7 @@ async function convertToAnthropicMessagesPrompt({
2254
2219
  cacheControlValidator,
2255
2220
  toolNameMapping
2256
2221
  }) {
2257
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
2222
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
2258
2223
  const betas = /* @__PURE__ */ new Set();
2259
2224
  const blocks = groupIntoBlocks(prompt);
2260
2225
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -2659,6 +2624,7 @@ async function convertToAnthropicMessagesPrompt({
2659
2624
  break;
2660
2625
  }
2661
2626
  case "tool-call": {
2627
+ const caller = getAnthropicCaller(part.providerOptions);
2662
2628
  if (part.providerExecuted) {
2663
2629
  const providerToolName = toolNameMapping.toProviderToolName(
2664
2630
  part.toolName
@@ -2693,6 +2659,7 @@ async function convertToAnthropicMessagesPrompt({
2693
2659
  name: subtoolName,
2694
2660
  // map back to subtool name
2695
2661
  input,
2662
+ ...caller && { caller },
2696
2663
  cache_control: cacheControl
2697
2664
  });
2698
2665
  } else if (
@@ -2706,6 +2673,7 @@ async function convertToAnthropicMessagesPrompt({
2706
2673
  id: part.toolCallId,
2707
2674
  name: "code_execution",
2708
2675
  input: inputWithoutType,
2676
+ ...caller && { caller },
2709
2677
  cache_control: cacheControl
2710
2678
  });
2711
2679
  } else {
@@ -2716,6 +2684,7 @@ async function convertToAnthropicMessagesPrompt({
2716
2684
  id: part.toolCallId,
2717
2685
  name: providerToolName,
2718
2686
  input: part.input,
2687
+ ...caller && { caller },
2719
2688
  cache_control: cacheControl
2720
2689
  });
2721
2690
  } else if (providerToolName === "tool_search_tool_regex" || providerToolName === "tool_search_tool_bm25") {
@@ -2724,6 +2693,7 @@ async function convertToAnthropicMessagesPrompt({
2724
2693
  id: part.toolCallId,
2725
2694
  name: providerToolName,
2726
2695
  input: part.input,
2696
+ ...caller && { caller },
2727
2697
  cache_control: cacheControl
2728
2698
  });
2729
2699
  } else if (providerToolName === "advisor") {
@@ -2732,6 +2702,7 @@ async function convertToAnthropicMessagesPrompt({
2732
2702
  id: part.toolCallId,
2733
2703
  name: "advisor",
2734
2704
  input: {},
2705
+ ...caller && { caller },
2735
2706
  cache_control: cacheControl
2736
2707
  });
2737
2708
  } else {
@@ -2743,11 +2714,6 @@ async function convertToAnthropicMessagesPrompt({
2743
2714
  }
2744
2715
  break;
2745
2716
  }
2746
- const callerOptions = (_o = part.providerOptions) == null ? void 0 : _o.anthropic;
2747
- const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? (callerOptions.caller.type === "code_execution_20250825" || callerOptions.caller.type === "code_execution_20260120") && callerOptions.caller.toolId ? {
2748
- type: callerOptions.caller.type,
2749
- tool_id: callerOptions.caller.toolId
2750
- } : callerOptions.caller.type === "direct" ? { type: "direct" } : void 0 : void 0;
2751
2717
  anthropicContent.push({
2752
2718
  type: "tool_use",
2753
2719
  id: part.toolCallId,
@@ -2762,6 +2728,7 @@ async function convertToAnthropicMessagesPrompt({
2762
2728
  const providerToolName = toolNameMapping.toProviderToolName(
2763
2729
  part.toolName
2764
2730
  );
2731
+ const caller = getAnthropicCaller(part.providerOptions);
2765
2732
  if (mcpToolUseIds.has(part.toolCallId)) {
2766
2733
  const output = part.output;
2767
2734
  if (output.type !== "json" && output.type !== "error-json") {
@@ -2796,7 +2763,7 @@ async function convertToAnthropicMessagesPrompt({
2796
2763
  tool_use_id: part.toolCallId,
2797
2764
  content: {
2798
2765
  type: "code_execution_tool_result_error",
2799
- error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
2766
+ error_code: (_o = errorInfo.errorCode) != null ? _o : "unknown"
2800
2767
  },
2801
2768
  cache_control: cacheControl
2802
2769
  });
@@ -2807,7 +2774,7 @@ async function convertToAnthropicMessagesPrompt({
2807
2774
  cache_control: cacheControl,
2808
2775
  content: {
2809
2776
  type: "bash_code_execution_tool_result_error",
2810
- error_code: (_q = errorInfo.errorCode) != null ? _q : "unknown"
2777
+ error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
2811
2778
  }
2812
2779
  });
2813
2780
  }
@@ -2840,7 +2807,7 @@ async function convertToAnthropicMessagesPrompt({
2840
2807
  stdout: codeExecutionOutput.stdout,
2841
2808
  stderr: codeExecutionOutput.stderr,
2842
2809
  return_code: codeExecutionOutput.return_code,
2843
- content: (_r = codeExecutionOutput.content) != null ? _r : []
2810
+ content: (_q = codeExecutionOutput.content) != null ? _q : []
2844
2811
  },
2845
2812
  cache_control: cacheControl
2846
2813
  });
@@ -2858,7 +2825,7 @@ async function convertToAnthropicMessagesPrompt({
2858
2825
  encrypted_stdout: codeExecutionOutput.encrypted_stdout,
2859
2826
  stderr: codeExecutionOutput.stderr,
2860
2827
  return_code: codeExecutionOutput.return_code,
2861
- content: (_s = codeExecutionOutput.content) != null ? _s : []
2828
+ content: (_r = codeExecutionOutput.content) != null ? _r : []
2862
2829
  },
2863
2830
  cache_control: cacheControl
2864
2831
  });
@@ -2877,7 +2844,7 @@ async function convertToAnthropicMessagesPrompt({
2877
2844
  stdout: codeExecutionOutput.stdout,
2878
2845
  stderr: codeExecutionOutput.stderr,
2879
2846
  return_code: codeExecutionOutput.return_code,
2880
- content: (_t = codeExecutionOutput.content) != null ? _t : []
2847
+ content: (_s = codeExecutionOutput.content) != null ? _s : []
2881
2848
  },
2882
2849
  cache_control: cacheControl
2883
2850
  });
@@ -2915,8 +2882,9 @@ async function convertToAnthropicMessagesPrompt({
2915
2882
  tool_use_id: part.toolCallId,
2916
2883
  content: {
2917
2884
  type: "web_fetch_tool_result_error",
2918
- error_code: (_u = (await extractErrorValue(output.value)).errorCode) != null ? _u : "unavailable"
2885
+ error_code: (_t = (await extractErrorValue(output.value)).errorCode) != null ? _t : "unavailable"
2919
2886
  },
2887
+ ...caller && { caller },
2920
2888
  cache_control: cacheControl
2921
2889
  });
2922
2890
  break;
@@ -2950,6 +2918,7 @@ async function convertToAnthropicMessagesPrompt({
2950
2918
  }
2951
2919
  }
2952
2920
  },
2921
+ ...caller && { caller },
2953
2922
  cache_control: cacheControl
2954
2923
  });
2955
2924
  break;
@@ -2962,8 +2931,9 @@ async function convertToAnthropicMessagesPrompt({
2962
2931
  tool_use_id: part.toolCallId,
2963
2932
  content: {
2964
2933
  type: "web_search_tool_result_error",
2965
- error_code: (_v = (await extractErrorValue(output.value)).errorCode) != null ? _v : "unavailable"
2934
+ error_code: (_u = (await extractErrorValue(output.value)).errorCode) != null ? _u : "unavailable"
2966
2935
  },
2936
+ ...caller && { caller },
2967
2937
  cache_control: cacheControl
2968
2938
  });
2969
2939
  break;
@@ -2989,6 +2959,7 @@ async function convertToAnthropicMessagesPrompt({
2989
2959
  encrypted_content: result.encryptedContent,
2990
2960
  type: result.type
2991
2961
  })),
2962
+ ...caller && { caller },
2992
2963
  cache_control: cacheControl
2993
2964
  });
2994
2965
  break;
@@ -3160,6 +3131,17 @@ function moveToolUseBlocksToEnd(content) {
3160
3131
  flushSegment();
3161
3132
  return result;
3162
3133
  }
3134
+ function getAnthropicCaller(providerOptions) {
3135
+ var _a;
3136
+ const caller = (_a = providerOptions == null ? void 0 : providerOptions.anthropic) == null ? void 0 : _a.caller;
3137
+ if (((caller == null ? void 0 : caller.type) === "code_execution_20250825" || (caller == null ? void 0 : caller.type) === "code_execution_20260120") && caller.toolId) {
3138
+ return {
3139
+ type: caller.type,
3140
+ tool_id: caller.toolId
3141
+ };
3142
+ }
3143
+ return (caller == null ? void 0 : caller.type) === "direct" ? { type: "direct" } : void 0;
3144
+ }
3163
3145
 
3164
3146
  // src/map-anthropic-stop-reason.ts
3165
3147
  function mapAnthropicStopReason({
@@ -3376,6 +3358,16 @@ function createCitationSource(citation, citationDocuments, generateId3) {
3376
3358
  }
3377
3359
  };
3378
3360
  }
3361
+ function getAnthropicCallerInfo(caller) {
3362
+ return caller == null ? void 0 : {
3363
+ type: caller.type,
3364
+ toolId: "tool_id" in caller ? caller.tool_id : void 0
3365
+ };
3366
+ }
3367
+ function getAnthropicCallerMetadata(caller) {
3368
+ const callerInfo = getAnthropicCallerInfo(caller);
3369
+ return callerInfo == null ? {} : { providerMetadata: { anthropic: { caller: callerInfo } } };
3370
+ }
3379
3371
  var AnthropicMessagesLanguageModel = class {
3380
3372
  constructor(modelId, config) {
3381
3373
  this.specificationVersion = "v3";
@@ -4024,23 +4016,12 @@ var AnthropicMessagesLanguageModel = class {
4024
4016
  text: JSON.stringify(part.input)
4025
4017
  });
4026
4018
  } else {
4027
- const caller = part.caller;
4028
- const callerInfo = caller ? {
4029
- type: caller.type,
4030
- toolId: "tool_id" in caller ? caller.tool_id : void 0
4031
- } : void 0;
4032
4019
  content.push({
4033
4020
  type: "tool-call",
4034
4021
  toolCallId: part.id,
4035
4022
  toolName: part.name,
4036
4023
  input: JSON.stringify(part.input),
4037
- ...callerInfo && {
4038
- providerMetadata: {
4039
- anthropic: {
4040
- caller: callerInfo
4041
- }
4042
- }
4043
- }
4024
+ ...getAnthropicCallerMetadata(part.caller)
4044
4025
  });
4045
4026
  }
4046
4027
  break;
@@ -4058,7 +4039,8 @@ var AnthropicMessagesLanguageModel = class {
4058
4039
  // implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
4059
4040
  // tool was not explicitly provided. We therefore bypass the general validation by marking the
4060
4041
  // tool as dynamic.
4061
- ...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {}
4042
+ ...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {},
4043
+ ...getAnthropicCallerMetadata(part.caller)
4062
4044
  });
4063
4045
  } else if (part.name === "web_search" || part.name === "code_execution" || part.name === "web_fetch") {
4064
4046
  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;
@@ -4072,7 +4054,8 @@ var AnthropicMessagesLanguageModel = class {
4072
4054
  // implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
4073
4055
  // tool was not explicitly provided. We therefore bypass the general validation by marking the
4074
4056
  // tool as dynamic.
4075
- ...markCodeExecutionDynamic && part.name === "code_execution" ? { dynamic: true } : {}
4057
+ ...markCodeExecutionDynamic && part.name === "code_execution" ? { dynamic: true } : {},
4058
+ ...getAnthropicCallerMetadata(part.caller)
4076
4059
  });
4077
4060
  } else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
4078
4061
  serverToolCalls[part.id] = part.name;
@@ -4081,7 +4064,8 @@ var AnthropicMessagesLanguageModel = class {
4081
4064
  toolCallId: part.id,
4082
4065
  toolName: toolNameMapping.toCustomToolName(part.name),
4083
4066
  input: JSON.stringify(part.input),
4084
- providerExecuted: true
4067
+ providerExecuted: true,
4068
+ ...getAnthropicCallerMetadata(part.caller)
4085
4069
  });
4086
4070
  } else if (part.name === "advisor") {
4087
4071
  content.push({
@@ -4089,7 +4073,8 @@ var AnthropicMessagesLanguageModel = class {
4089
4073
  toolCallId: part.id,
4090
4074
  toolName: toolNameMapping.toCustomToolName("advisor"),
4091
4075
  input: JSON.stringify(part.input),
4092
- providerExecuted: true
4076
+ providerExecuted: true,
4077
+ ...getAnthropicCallerMetadata(part.caller)
4093
4078
  });
4094
4079
  }
4095
4080
  break;
@@ -4148,7 +4133,8 @@ var AnthropicMessagesLanguageModel = class {
4148
4133
  data: part.content.content.source.data
4149
4134
  }
4150
4135
  }
4151
- }
4136
+ },
4137
+ ...getAnthropicCallerMetadata(part.caller)
4152
4138
  });
4153
4139
  } else if (part.content.type === "web_fetch_tool_result_error") {
4154
4140
  content.push({
@@ -4159,7 +4145,8 @@ var AnthropicMessagesLanguageModel = class {
4159
4145
  result: {
4160
4146
  type: "web_fetch_tool_result_error",
4161
4147
  errorCode: part.content.error_code
4162
- }
4148
+ },
4149
+ ...getAnthropicCallerMetadata(part.caller)
4163
4150
  });
4164
4151
  }
4165
4152
  break;
@@ -4179,7 +4166,8 @@ var AnthropicMessagesLanguageModel = class {
4179
4166
  encryptedContent: result.encrypted_content,
4180
4167
  type: result.type
4181
4168
  };
4182
- })
4169
+ }),
4170
+ ...getAnthropicCallerMetadata(part.caller)
4183
4171
  });
4184
4172
  for (const result of part.content) {
4185
4173
  content.push({
@@ -4204,7 +4192,8 @@ var AnthropicMessagesLanguageModel = class {
4204
4192
  result: {
4205
4193
  type: "web_search_tool_result_error",
4206
4194
  errorCode: part.content.error_code
4207
- }
4195
+ },
4196
+ ...getAnthropicCallerMetadata(part.caller)
4208
4197
  });
4209
4198
  }
4210
4199
  break;
@@ -4565,11 +4554,7 @@ var AnthropicMessagesLanguageModel = class {
4565
4554
  id: String(value.index)
4566
4555
  });
4567
4556
  } else {
4568
- const caller = part.caller;
4569
- const callerInfo = caller ? {
4570
- type: caller.type,
4571
- toolId: "tool_id" in caller ? caller.tool_id : void 0
4572
- } : void 0;
4557
+ const callerInfo = getAnthropicCallerInfo(part.caller);
4573
4558
  const hasNonEmptyInput = part.input && Object.keys(part.input).length > 0;
4574
4559
  const initialInput = hasNonEmptyInput ? JSON.stringify(part.input) : "";
4575
4560
  contentBlocks[value.index] = {
@@ -4589,6 +4574,7 @@ var AnthropicMessagesLanguageModel = class {
4589
4574
  return;
4590
4575
  }
4591
4576
  case "server_tool_use": {
4577
+ const callerInfo = getAnthropicCallerInfo(part.caller);
4592
4578
  if ([
4593
4579
  "web_fetch",
4594
4580
  "web_search",
@@ -4616,7 +4602,8 @@ var AnthropicMessagesLanguageModel = class {
4616
4602
  ...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {},
4617
4603
  firstDelta: finalInput.length === 0,
4618
4604
  providerToolName,
4619
- providerToolInputType
4605
+ providerToolInputType,
4606
+ ...callerInfo && { caller: callerInfo }
4620
4607
  };
4621
4608
  controller.enqueue({
4622
4609
  type: "tool-input-start",
@@ -4641,7 +4628,8 @@ var AnthropicMessagesLanguageModel = class {
4641
4628
  input: "",
4642
4629
  providerExecuted: true,
4643
4630
  firstDelta: true,
4644
- providerToolName: part.name
4631
+ providerToolName: part.name,
4632
+ ...callerInfo && { caller: callerInfo }
4645
4633
  };
4646
4634
  controller.enqueue({
4647
4635
  type: "tool-input-start",
@@ -4658,7 +4646,8 @@ var AnthropicMessagesLanguageModel = class {
4658
4646
  input: "{}",
4659
4647
  providerExecuted: true,
4660
4648
  firstDelta: true,
4661
- providerToolName: part.name
4649
+ providerToolName: part.name,
4650
+ ...callerInfo && { caller: callerInfo }
4662
4651
  };
4663
4652
  controller.enqueue({
4664
4653
  type: "tool-input-start",
@@ -4693,7 +4682,8 @@ var AnthropicMessagesLanguageModel = class {
4693
4682
  data: part.content.content.source.data
4694
4683
  }
4695
4684
  }
4696
- }
4685
+ },
4686
+ ...getAnthropicCallerMetadata(part.caller)
4697
4687
  });
4698
4688
  } else if (part.content.type === "web_fetch_tool_result_error") {
4699
4689
  controller.enqueue({
@@ -4704,7 +4694,8 @@ var AnthropicMessagesLanguageModel = class {
4704
4694
  result: {
4705
4695
  type: "web_fetch_tool_result_error",
4706
4696
  errorCode: part.content.error_code
4707
- }
4697
+ },
4698
+ ...getAnthropicCallerMetadata(part.caller)
4708
4699
  });
4709
4700
  }
4710
4701
  return;
@@ -4724,7 +4715,8 @@ var AnthropicMessagesLanguageModel = class {
4724
4715
  encryptedContent: result.encrypted_content,
4725
4716
  type: result.type
4726
4717
  };
4727
- })
4718
+ }),
4719
+ ...getAnthropicCallerMetadata(part.caller)
4728
4720
  });
4729
4721
  for (const result of part.content) {
4730
4722
  controller.enqueue({
@@ -4749,7 +4741,8 @@ var AnthropicMessagesLanguageModel = class {
4749
4741
  result: {
4750
4742
  type: "web_search_tool_result_error",
4751
4743
  errorCode: part.content.error_code
4752
- }
4744
+ },
4745
+ ...getAnthropicCallerMetadata(part.caller)
4753
4746
  });
4754
4747
  }
4755
4748
  return;
@@ -5149,11 +5142,7 @@ var AnthropicMessagesLanguageModel = class {
5149
5142
  for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
5150
5143
  const part = value.message.content[contentIndex];
5151
5144
  if (part.type === "tool_use") {
5152
- const caller = part.caller;
5153
- const callerInfo = caller ? {
5154
- type: caller.type,
5155
- toolId: "tool_id" in caller ? caller.tool_id : void 0
5156
- } : void 0;
5145
+ const callerInfo = getAnthropicCallerInfo(part.caller);
5157
5146
  controller.enqueue({
5158
5147
  type: "tool-input-start",
5159
5148
  id: part.id,