@ai-sdk/anthropic 4.0.38 → 4.0.39

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.
@@ -136,6 +136,7 @@ interface AnthropicServerToolUseContent {
136
136
  id: string;
137
137
  name: 'web_fetch' | 'web_search' | 'code_execution' | 'bash_code_execution' | 'text_editor_code_execution' | 'tool_search_tool_regex' | 'tool_search_tool_bm25' | 'advisor';
138
138
  input: unknown;
139
+ caller?: AnthropicToolCallCaller;
139
140
  cache_control: AnthropicCacheControl | undefined;
140
141
  }
141
142
  type AnthropicNestedTextContent = Omit<AnthropicTextContent, 'cache_control'> & {
@@ -171,6 +172,7 @@ interface AnthropicWebSearchToolResultContent {
171
172
  type: 'web_search_tool_result_error';
172
173
  error_code: string;
173
174
  };
175
+ caller?: AnthropicToolCallCaller;
174
176
  cache_control: AnthropicCacheControl | undefined;
175
177
  }
176
178
  interface AnthropicToolSearchToolResultContent {
@@ -308,6 +310,7 @@ interface AnthropicWebFetchToolResultContent {
308
310
  type: 'web_fetch_tool_result_error';
309
311
  error_code: string;
310
312
  };
313
+ caller?: AnthropicToolCallCaller;
311
314
  cache_control: AnthropicCacheControl | undefined;
312
315
  }
313
316
  interface AnthropicMcpToolUseContent {
@@ -495,6 +498,9 @@ declare const anthropicResponseSchema: _ai_sdk_provider_utils.LazySchema<{
495
498
  name: string;
496
499
  input?: Record<string, unknown> | null | undefined;
497
500
  caller?: {
501
+ type: "code_execution_20250825";
502
+ tool_id: string;
503
+ } | {
498
504
  type: "code_execution_20260120";
499
505
  tool_id: string;
500
506
  } | {
@@ -541,6 +547,15 @@ declare const anthropicResponseSchema: _ai_sdk_provider_utils.LazySchema<{
541
547
  type: "web_fetch_tool_result_error";
542
548
  error_code: string;
543
549
  };
550
+ caller?: {
551
+ type: "code_execution_20250825";
552
+ tool_id: string;
553
+ } | {
554
+ type: "code_execution_20260120";
555
+ tool_id: string;
556
+ } | {
557
+ type: "direct";
558
+ } | undefined;
544
559
  } | {
545
560
  type: "web_search_tool_result";
546
561
  tool_use_id: string;
@@ -554,6 +569,15 @@ declare const anthropicResponseSchema: _ai_sdk_provider_utils.LazySchema<{
554
569
  type: "web_search_tool_result_error";
555
570
  error_code: string;
556
571
  };
572
+ caller?: {
573
+ type: "code_execution_20250825";
574
+ tool_id: string;
575
+ } | {
576
+ type: "code_execution_20260120";
577
+ tool_id: string;
578
+ } | {
579
+ type: "direct";
580
+ } | undefined;
557
581
  } | {
558
582
  type: "code_execution_tool_result";
559
583
  tool_use_id: string;
@@ -134,6 +134,19 @@ var anthropicStopDetailsSchema = z3.object({
134
134
  explanation: z3.string().nullish(),
135
135
  recommended_model: z3.string().nullish()
136
136
  });
137
+ var anthropicToolCallCallerSchema = z3.union([
138
+ z3.object({
139
+ type: z3.literal("code_execution_20250825"),
140
+ tool_id: z3.string()
141
+ }),
142
+ z3.object({
143
+ type: z3.literal("code_execution_20260120"),
144
+ tool_id: z3.string()
145
+ }),
146
+ z3.object({
147
+ type: z3.literal("direct")
148
+ })
149
+ ]);
137
150
  var anthropicResponseSchema = lazySchema3(
138
151
  () => zodSchema3(
139
152
  z3.object({
@@ -192,34 +205,14 @@ var anthropicResponseSchema = lazySchema3(
192
205
  name: z3.string(),
193
206
  input: z3.unknown(),
194
207
  // Programmatic tool calling: caller info when triggered from code execution
195
- caller: z3.union([
196
- z3.object({
197
- type: z3.literal("code_execution_20250825"),
198
- tool_id: z3.string()
199
- }),
200
- z3.object({
201
- type: z3.literal("code_execution_20260120"),
202
- tool_id: z3.string()
203
- }),
204
- z3.object({
205
- type: z3.literal("direct")
206
- })
207
- ]).optional()
208
+ caller: anthropicToolCallCallerSchema.optional()
208
209
  }),
209
210
  z3.object({
210
211
  type: z3.literal("server_tool_use"),
211
212
  id: z3.string(),
212
213
  name: z3.string(),
213
214
  input: z3.record(z3.string(), z3.unknown()).nullish(),
214
- caller: z3.union([
215
- z3.object({
216
- type: z3.literal("code_execution_20260120"),
217
- tool_id: z3.string()
218
- }),
219
- z3.object({
220
- type: z3.literal("direct")
221
- })
222
- ]).optional()
215
+ caller: anthropicToolCallCallerSchema.optional()
223
216
  }),
224
217
  z3.object({
225
218
  type: z3.literal("mcp_tool_use"),
@@ -242,6 +235,7 @@ var anthropicResponseSchema = lazySchema3(
242
235
  z3.object({
243
236
  type: z3.literal("web_fetch_tool_result"),
244
237
  tool_use_id: z3.string(),
238
+ caller: anthropicToolCallCallerSchema.optional(),
245
239
  content: z3.union([
246
240
  z3.object({
247
241
  type: z3.literal("web_fetch_result"),
@@ -274,6 +268,7 @@ var anthropicResponseSchema = lazySchema3(
274
268
  z3.object({
275
269
  type: z3.literal("web_search_tool_result"),
276
270
  tool_use_id: z3.string(),
271
+ caller: anthropicToolCallCallerSchema.optional(),
277
272
  content: z3.union([
278
273
  z3.array(
279
274
  z3.object({
@@ -512,19 +507,7 @@ var anthropicChunkSchema = lazySchema3(
512
507
  id: z3.string(),
513
508
  name: z3.string(),
514
509
  input: z3.unknown(),
515
- caller: z3.union([
516
- z3.object({
517
- type: z3.literal("code_execution_20250825"),
518
- tool_id: z3.string()
519
- }),
520
- z3.object({
521
- type: z3.literal("code_execution_20260120"),
522
- tool_id: z3.string()
523
- }),
524
- z3.object({
525
- type: z3.literal("direct")
526
- })
527
- ]).optional()
510
+ caller: anthropicToolCallCallerSchema.optional()
528
511
  })
529
512
  ])
530
513
  ).nullish(),
@@ -554,19 +537,7 @@ var anthropicChunkSchema = lazySchema3(
554
537
  // Programmatic tool calling: input may be present directly for deferred tool calls
555
538
  input: z3.record(z3.string(), z3.unknown()).optional(),
556
539
  // Programmatic tool calling: caller info when triggered from code execution
557
- caller: z3.union([
558
- z3.object({
559
- type: z3.literal("code_execution_20250825"),
560
- tool_id: z3.string()
561
- }),
562
- z3.object({
563
- type: z3.literal("code_execution_20260120"),
564
- tool_id: z3.string()
565
- }),
566
- z3.object({
567
- type: z3.literal("direct")
568
- })
569
- ]).optional()
540
+ caller: anthropicToolCallCallerSchema.optional()
570
541
  }),
571
542
  z3.object({
572
543
  type: z3.literal("redacted_thinking"),
@@ -581,15 +552,7 @@ var anthropicChunkSchema = lazySchema3(
581
552
  id: z3.string(),
582
553
  name: z3.string(),
583
554
  input: z3.record(z3.string(), z3.unknown()).nullish(),
584
- caller: z3.union([
585
- z3.object({
586
- type: z3.literal("code_execution_20260120"),
587
- tool_id: z3.string()
588
- }),
589
- z3.object({
590
- type: z3.literal("direct")
591
- })
592
- ]).optional()
555
+ caller: anthropicToolCallCallerSchema.optional()
593
556
  }),
594
557
  z3.object({
595
558
  type: z3.literal("mcp_tool_use"),
@@ -612,6 +575,7 @@ var anthropicChunkSchema = lazySchema3(
612
575
  z3.object({
613
576
  type: z3.literal("web_fetch_tool_result"),
614
577
  tool_use_id: z3.string(),
578
+ caller: anthropicToolCallCallerSchema.optional(),
615
579
  content: z3.union([
616
580
  z3.object({
617
581
  type: z3.literal("web_fetch_result"),
@@ -644,6 +608,7 @@ var anthropicChunkSchema = lazySchema3(
644
608
  z3.object({
645
609
  type: z3.literal("web_search_tool_result"),
646
610
  tool_use_id: z3.string(),
611
+ caller: anthropicToolCallCallerSchema.optional(),
647
612
  content: z3.union([
648
613
  z3.array(
649
614
  z3.object({
@@ -2417,7 +2382,7 @@ async function convertToAnthropicPrompt({
2417
2382
  cacheControlValidator,
2418
2383
  toolNameMapping
2419
2384
  }) {
2420
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
2385
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
2421
2386
  const betas = /* @__PURE__ */ new Set();
2422
2387
  const blocks = groupIntoBlocks(prompt);
2423
2388
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -2911,6 +2876,7 @@ async function convertToAnthropicPrompt({
2911
2876
  break;
2912
2877
  }
2913
2878
  case "tool-call": {
2879
+ const caller = getAnthropicCaller(part.providerOptions);
2914
2880
  if (part.providerExecuted) {
2915
2881
  const providerToolName = toolNameMapping.toProviderToolName(
2916
2882
  part.toolName
@@ -2945,6 +2911,7 @@ async function convertToAnthropicPrompt({
2945
2911
  name: codeExecutionType,
2946
2912
  // map back to subtool name
2947
2913
  input: inputWithoutType,
2914
+ ...caller && { caller },
2948
2915
  cache_control: cacheControl
2949
2916
  });
2950
2917
  } else if (
@@ -2958,6 +2925,7 @@ async function convertToAnthropicPrompt({
2958
2925
  id: part.toolCallId,
2959
2926
  name: "code_execution",
2960
2927
  input: inputWithoutType,
2928
+ ...caller && { caller },
2961
2929
  cache_control: cacheControl
2962
2930
  });
2963
2931
  } else {
@@ -2968,6 +2936,7 @@ async function convertToAnthropicPrompt({
2968
2936
  id: part.toolCallId,
2969
2937
  name: providerToolName,
2970
2938
  input: part.input,
2939
+ ...caller && { caller },
2971
2940
  cache_control: cacheControl
2972
2941
  });
2973
2942
  } else if (providerToolName === "tool_search_tool_regex" || providerToolName === "tool_search_tool_bm25") {
@@ -2976,6 +2945,7 @@ async function convertToAnthropicPrompt({
2976
2945
  id: part.toolCallId,
2977
2946
  name: providerToolName,
2978
2947
  input: part.input,
2948
+ ...caller && { caller },
2979
2949
  cache_control: cacheControl
2980
2950
  });
2981
2951
  } else if (providerToolName === "advisor") {
@@ -2984,6 +2954,7 @@ async function convertToAnthropicPrompt({
2984
2954
  id: part.toolCallId,
2985
2955
  name: "advisor",
2986
2956
  input: {},
2957
+ ...caller && { caller },
2987
2958
  cache_control: cacheControl
2988
2959
  });
2989
2960
  } else {
@@ -2995,11 +2966,6 @@ async function convertToAnthropicPrompt({
2995
2966
  }
2996
2967
  break;
2997
2968
  }
2998
- const callerOptions = (_p = part.providerOptions) == null ? void 0 : _p.anthropic;
2999
- const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? (callerOptions.caller.type === "code_execution_20250825" || callerOptions.caller.type === "code_execution_20260120") && callerOptions.caller.toolId ? {
3000
- type: callerOptions.caller.type,
3001
- tool_id: callerOptions.caller.toolId
3002
- } : callerOptions.caller.type === "direct" ? { type: "direct" } : void 0 : void 0;
3003
2969
  anthropicContent.push({
3004
2970
  type: "tool_use",
3005
2971
  id: part.toolCallId,
@@ -3014,6 +2980,7 @@ async function convertToAnthropicPrompt({
3014
2980
  const providerToolName = toolNameMapping.toProviderToolName(
3015
2981
  part.toolName
3016
2982
  );
2983
+ const caller = getAnthropicCaller(part.providerOptions);
3017
2984
  if (mcpToolUseIds.has(part.toolCallId)) {
3018
2985
  const output = part.output;
3019
2986
  if (output.type !== "json" && output.type !== "error-json") {
@@ -3048,7 +3015,7 @@ async function convertToAnthropicPrompt({
3048
3015
  tool_use_id: part.toolCallId,
3049
3016
  content: {
3050
3017
  type: "code_execution_tool_result_error",
3051
- error_code: (_q = errorInfo.errorCode) != null ? _q : "unknown"
3018
+ error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
3052
3019
  },
3053
3020
  cache_control: cacheControl
3054
3021
  });
@@ -3059,7 +3026,7 @@ async function convertToAnthropicPrompt({
3059
3026
  cache_control: cacheControl,
3060
3027
  content: {
3061
3028
  type: "bash_code_execution_tool_result_error",
3062
- error_code: (_r = errorInfo.errorCode) != null ? _r : "unknown"
3029
+ error_code: (_q = errorInfo.errorCode) != null ? _q : "unknown"
3063
3030
  }
3064
3031
  });
3065
3032
  }
@@ -3092,7 +3059,7 @@ async function convertToAnthropicPrompt({
3092
3059
  stdout: codeExecutionOutput.stdout,
3093
3060
  stderr: codeExecutionOutput.stderr,
3094
3061
  return_code: codeExecutionOutput.return_code,
3095
- content: (_s = codeExecutionOutput.content) != null ? _s : []
3062
+ content: (_r = codeExecutionOutput.content) != null ? _r : []
3096
3063
  },
3097
3064
  cache_control: cacheControl
3098
3065
  });
@@ -3110,7 +3077,7 @@ async function convertToAnthropicPrompt({
3110
3077
  encrypted_stdout: codeExecutionOutput.encrypted_stdout,
3111
3078
  stderr: codeExecutionOutput.stderr,
3112
3079
  return_code: codeExecutionOutput.return_code,
3113
- content: (_t = codeExecutionOutput.content) != null ? _t : []
3080
+ content: (_s = codeExecutionOutput.content) != null ? _s : []
3114
3081
  },
3115
3082
  cache_control: cacheControl
3116
3083
  });
@@ -3129,7 +3096,7 @@ async function convertToAnthropicPrompt({
3129
3096
  stdout: codeExecutionOutput.stdout,
3130
3097
  stderr: codeExecutionOutput.stderr,
3131
3098
  return_code: codeExecutionOutput.return_code,
3132
- content: (_u = codeExecutionOutput.content) != null ? _u : []
3099
+ content: (_t = codeExecutionOutput.content) != null ? _t : []
3133
3100
  },
3134
3101
  cache_control: cacheControl
3135
3102
  });
@@ -3167,8 +3134,9 @@ async function convertToAnthropicPrompt({
3167
3134
  tool_use_id: part.toolCallId,
3168
3135
  content: {
3169
3136
  type: "web_fetch_tool_result_error",
3170
- error_code: (_v = extractErrorValue(output.value).errorCode) != null ? _v : "unavailable"
3137
+ error_code: (_u = extractErrorValue(output.value).errorCode) != null ? _u : "unavailable"
3171
3138
  },
3139
+ ...caller && { caller },
3172
3140
  cache_control: cacheControl
3173
3141
  });
3174
3142
  break;
@@ -3202,6 +3170,7 @@ async function convertToAnthropicPrompt({
3202
3170
  }
3203
3171
  }
3204
3172
  },
3173
+ ...caller && { caller },
3205
3174
  cache_control: cacheControl
3206
3175
  });
3207
3176
  break;
@@ -3214,8 +3183,9 @@ async function convertToAnthropicPrompt({
3214
3183
  tool_use_id: part.toolCallId,
3215
3184
  content: {
3216
3185
  type: "web_search_tool_result_error",
3217
- error_code: (_w = extractErrorValue(output.value).errorCode) != null ? _w : "unavailable"
3186
+ error_code: (_v = extractErrorValue(output.value).errorCode) != null ? _v : "unavailable"
3218
3187
  },
3188
+ ...caller && { caller },
3219
3189
  cache_control: cacheControl
3220
3190
  });
3221
3191
  break;
@@ -3241,6 +3211,7 @@ async function convertToAnthropicPrompt({
3241
3211
  encrypted_content: result.encryptedContent,
3242
3212
  type: result.type
3243
3213
  })),
3214
+ ...caller && { caller },
3244
3215
  cache_control: cacheControl
3245
3216
  });
3246
3217
  break;
@@ -3418,6 +3389,17 @@ function moveToolUseBlocksToEnd(content) {
3418
3389
  flushSegment();
3419
3390
  return result;
3420
3391
  }
3392
+ function getAnthropicCaller(providerOptions) {
3393
+ var _a;
3394
+ const caller = (_a = providerOptions == null ? void 0 : providerOptions.anthropic) == null ? void 0 : _a.caller;
3395
+ if (((caller == null ? void 0 : caller.type) === "code_execution_20250825" || (caller == null ? void 0 : caller.type) === "code_execution_20260120") && caller.toolId) {
3396
+ return {
3397
+ type: caller.type,
3398
+ tool_id: caller.toolId
3399
+ };
3400
+ }
3401
+ return (caller == null ? void 0 : caller.type) === "direct" ? { type: "direct" } : void 0;
3402
+ }
3421
3403
  function toAnthropicToolInput(input) {
3422
3404
  return typeof input === "object" && input !== null && !Array.isArray(input) ? input : { rawInvalidInput: input };
3423
3405
  }
@@ -3635,6 +3617,16 @@ function createCitationSource(citation, citationDocuments, generateId2) {
3635
3617
  }
3636
3618
  };
3637
3619
  }
3620
+ function getAnthropicCallerInfo(caller) {
3621
+ return caller == null ? void 0 : {
3622
+ type: caller.type,
3623
+ toolId: "tool_id" in caller ? caller.tool_id : void 0
3624
+ };
3625
+ }
3626
+ function getAnthropicCallerMetadata(caller) {
3627
+ const callerInfo = getAnthropicCallerInfo(caller);
3628
+ return callerInfo == null ? {} : { providerMetadata: { anthropic: { caller: callerInfo } } };
3629
+ }
3638
3630
  var AnthropicLanguageModel = class _AnthropicLanguageModel {
3639
3631
  constructor(modelId, config) {
3640
3632
  this.specificationVersion = "v4";
@@ -4315,23 +4307,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4315
4307
  text: JSON.stringify(part.input)
4316
4308
  });
4317
4309
  } else {
4318
- const caller = part.caller;
4319
- const callerInfo = caller ? {
4320
- type: caller.type,
4321
- toolId: "tool_id" in caller ? caller.tool_id : void 0
4322
- } : void 0;
4323
4310
  content.push({
4324
4311
  type: "tool-call",
4325
4312
  toolCallId: part.id,
4326
4313
  toolName: part.name,
4327
4314
  input: JSON.stringify(part.input),
4328
- ...callerInfo && {
4329
- providerMetadata: {
4330
- anthropic: {
4331
- caller: callerInfo
4332
- }
4333
- }
4334
- }
4315
+ ...getAnthropicCallerMetadata(part.caller)
4335
4316
  });
4336
4317
  }
4337
4318
  break;
@@ -4349,7 +4330,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4349
4330
  // implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
4350
4331
  // tool was not explicitly provided. We therefore bypass the general validation by marking the
4351
4332
  // tool as dynamic.
4352
- ...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {}
4333
+ ...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {},
4334
+ ...getAnthropicCallerMetadata(part.caller)
4353
4335
  });
4354
4336
  } else if (part.name === "web_search" || part.name === "code_execution" || part.name === "web_fetch") {
4355
4337
  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;
@@ -4363,7 +4345,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4363
4345
  // implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
4364
4346
  // tool was not explicitly provided. We therefore bypass the general validation by marking the
4365
4347
  // tool as dynamic.
4366
- ...markCodeExecutionDynamic && part.name === "code_execution" ? { dynamic: true } : {}
4348
+ ...markCodeExecutionDynamic && part.name === "code_execution" ? { dynamic: true } : {},
4349
+ ...getAnthropicCallerMetadata(part.caller)
4367
4350
  });
4368
4351
  } else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
4369
4352
  serverToolCalls[part.id] = part.name;
@@ -4372,7 +4355,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4372
4355
  toolCallId: part.id,
4373
4356
  toolName: toolNameMapping.toCustomToolName(part.name),
4374
4357
  input: JSON.stringify(part.input),
4375
- providerExecuted: true
4358
+ providerExecuted: true,
4359
+ ...getAnthropicCallerMetadata(part.caller)
4376
4360
  });
4377
4361
  } else if (part.name === "advisor") {
4378
4362
  content.push({
@@ -4380,7 +4364,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4380
4364
  toolCallId: part.id,
4381
4365
  toolName: toolNameMapping.toCustomToolName("advisor"),
4382
4366
  input: JSON.stringify(part.input),
4383
- providerExecuted: true
4367
+ providerExecuted: true,
4368
+ ...getAnthropicCallerMetadata(part.caller)
4384
4369
  });
4385
4370
  }
4386
4371
  break;
@@ -4439,7 +4424,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4439
4424
  data: part.content.content.source.data
4440
4425
  }
4441
4426
  }
4442
- }
4427
+ },
4428
+ ...getAnthropicCallerMetadata(part.caller)
4443
4429
  });
4444
4430
  } else if (part.content.type === "web_fetch_tool_result_error") {
4445
4431
  content.push({
@@ -4450,7 +4436,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4450
4436
  result: {
4451
4437
  type: "web_fetch_tool_result_error",
4452
4438
  errorCode: part.content.error_code
4453
- }
4439
+ },
4440
+ ...getAnthropicCallerMetadata(part.caller)
4454
4441
  });
4455
4442
  }
4456
4443
  break;
@@ -4470,7 +4457,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4470
4457
  encryptedContent: result.encrypted_content,
4471
4458
  type: result.type
4472
4459
  };
4473
- })
4460
+ }),
4461
+ ...getAnthropicCallerMetadata(part.caller)
4474
4462
  });
4475
4463
  for (const result of part.content) {
4476
4464
  content.push({
@@ -4495,7 +4483,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4495
4483
  result: {
4496
4484
  type: "web_search_tool_result_error",
4497
4485
  errorCode: part.content.error_code
4498
- }
4486
+ },
4487
+ ...getAnthropicCallerMetadata(part.caller)
4499
4488
  });
4500
4489
  }
4501
4490
  break;
@@ -4859,11 +4848,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4859
4848
  id: String(value.index)
4860
4849
  });
4861
4850
  } else {
4862
- const caller = part.caller;
4863
- const callerInfo = caller ? {
4864
- type: caller.type,
4865
- toolId: "tool_id" in caller ? caller.tool_id : void 0
4866
- } : void 0;
4851
+ const callerInfo = getAnthropicCallerInfo(part.caller);
4867
4852
  const hasNonEmptyInput = part.input && Object.keys(part.input).length > 0;
4868
4853
  const initialInput = hasNonEmptyInput ? JSON.stringify(part.input) : "";
4869
4854
  contentBlocks[value.index] = {
@@ -4883,6 +4868,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4883
4868
  return;
4884
4869
  }
4885
4870
  case "server_tool_use": {
4871
+ const callerInfo = getAnthropicCallerInfo(part.caller);
4886
4872
  if ([
4887
4873
  "web_fetch",
4888
4874
  "web_search",
@@ -4910,7 +4896,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4910
4896
  ...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {},
4911
4897
  firstDelta: finalInput.length === 0,
4912
4898
  providerToolName,
4913
- providerToolInputType
4899
+ providerToolInputType,
4900
+ ...callerInfo && { caller: callerInfo }
4914
4901
  };
4915
4902
  controller.enqueue({
4916
4903
  type: "tool-input-start",
@@ -4935,7 +4922,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4935
4922
  input: "",
4936
4923
  providerExecuted: true,
4937
4924
  firstDelta: true,
4938
- providerToolName: part.name
4925
+ providerToolName: part.name,
4926
+ ...callerInfo && { caller: callerInfo }
4939
4927
  };
4940
4928
  controller.enqueue({
4941
4929
  type: "tool-input-start",
@@ -4952,7 +4940,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4952
4940
  input: "{}",
4953
4941
  providerExecuted: true,
4954
4942
  firstDelta: true,
4955
- providerToolName: part.name
4943
+ providerToolName: part.name,
4944
+ ...callerInfo && { caller: callerInfo }
4956
4945
  };
4957
4946
  controller.enqueue({
4958
4947
  type: "tool-input-start",
@@ -4987,7 +4976,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4987
4976
  data: part.content.content.source.data
4988
4977
  }
4989
4978
  }
4990
- }
4979
+ },
4980
+ ...getAnthropicCallerMetadata(part.caller)
4991
4981
  });
4992
4982
  } else if (part.content.type === "web_fetch_tool_result_error") {
4993
4983
  controller.enqueue({
@@ -4998,7 +4988,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4998
4988
  result: {
4999
4989
  type: "web_fetch_tool_result_error",
5000
4990
  errorCode: part.content.error_code
5001
- }
4991
+ },
4992
+ ...getAnthropicCallerMetadata(part.caller)
5002
4993
  });
5003
4994
  }
5004
4995
  return;
@@ -5018,7 +5009,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5018
5009
  encryptedContent: result.encrypted_content,
5019
5010
  type: result.type
5020
5011
  };
5021
- })
5012
+ }),
5013
+ ...getAnthropicCallerMetadata(part.caller)
5022
5014
  });
5023
5015
  for (const result of part.content) {
5024
5016
  controller.enqueue({
@@ -5043,7 +5035,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5043
5035
  result: {
5044
5036
  type: "web_search_tool_result_error",
5045
5037
  errorCode: part.content.error_code
5046
- }
5038
+ },
5039
+ ...getAnthropicCallerMetadata(part.caller)
5047
5040
  });
5048
5041
  }
5049
5042
  return;
@@ -5448,11 +5441,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5448
5441
  for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
5449
5442
  const part = value.message.content[contentIndex];
5450
5443
  if (part.type === "tool_use") {
5451
- const caller = part.caller;
5452
- const callerInfo = caller ? {
5453
- type: caller.type,
5454
- toolId: "tool_id" in caller ? caller.tool_id : void 0
5455
- } : void 0;
5444
+ const callerInfo = getAnthropicCallerInfo(part.caller);
5456
5445
  controller.enqueue({
5457
5446
  type: "tool-input-start",
5458
5447
  id: part.id,