@ai-sdk/anthropic 3.0.3 → 3.0.5

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.mjs CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  } from "@ai-sdk/provider-utils";
12
12
 
13
13
  // src/version.ts
14
- var VERSION = true ? "3.0.3" : "0.0.0-test";
14
+ var VERSION = true ? "3.0.5" : "0.0.0-test";
15
15
 
16
16
  // src/anthropic-messages-language-model.ts
17
17
  import {
@@ -2736,7 +2736,7 @@ var AnthropicMessagesLanguageModel = class {
2736
2736
  });
2737
2737
  }
2738
2738
  async doGenerate(options) {
2739
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2739
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2740
2740
  const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
2741
2741
  ...options,
2742
2742
  stream: false,
@@ -2760,6 +2760,7 @@ var AnthropicMessagesLanguageModel = class {
2760
2760
  });
2761
2761
  const content = [];
2762
2762
  const mcpToolCalls = {};
2763
+ const serverToolCalls = {};
2763
2764
  let isJsonResponseFromTool = false;
2764
2765
  for (const part of response.content) {
2765
2766
  switch (part.type) {
@@ -2854,6 +2855,7 @@ var AnthropicMessagesLanguageModel = class {
2854
2855
  providerExecuted: true
2855
2856
  });
2856
2857
  } else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
2858
+ serverToolCalls[part.id] = part.name;
2857
2859
  content.push({
2858
2860
  type: "tool-call",
2859
2861
  toolCallId: part.id,
@@ -3017,11 +3019,12 @@ var AnthropicMessagesLanguageModel = class {
3017
3019
  }
3018
3020
  // tool search tool results:
3019
3021
  case "tool_search_tool_result": {
3022
+ const providerToolName = (_c = serverToolCalls[part.tool_use_id]) != null ? _c : "tool_search_tool_regex";
3020
3023
  if (part.content.type === "tool_search_tool_search_result") {
3021
3024
  content.push({
3022
3025
  type: "tool-result",
3023
3026
  toolCallId: part.tool_use_id,
3024
- toolName: toolNameMapping.toCustomToolName("tool_search"),
3027
+ toolName: toolNameMapping.toCustomToolName(providerToolName),
3025
3028
  result: part.content.tool_references.map((ref) => ({
3026
3029
  type: ref.type,
3027
3030
  toolName: ref.tool_name
@@ -3031,7 +3034,7 @@ var AnthropicMessagesLanguageModel = class {
3031
3034
  content.push({
3032
3035
  type: "tool-result",
3033
3036
  toolCallId: part.tool_use_id,
3034
- toolName: toolNameMapping.toCustomToolName("tool_search"),
3037
+ toolName: toolNameMapping.toCustomToolName(providerToolName),
3035
3038
  isError: true,
3036
3039
  result: {
3037
3040
  type: "tool_search_tool_result_error",
@@ -3050,13 +3053,13 @@ var AnthropicMessagesLanguageModel = class {
3050
3053
  finishReason: response.stop_reason,
3051
3054
  isJsonResponseFromTool
3052
3055
  }),
3053
- raw: (_c = response.stop_reason) != null ? _c : void 0
3056
+ raw: (_d = response.stop_reason) != null ? _d : void 0
3054
3057
  },
3055
3058
  usage: convertAnthropicMessagesUsage(response.usage),
3056
3059
  request: { body: args },
3057
3060
  response: {
3058
- id: (_d = response.id) != null ? _d : void 0,
3059
- modelId: (_e = response.model) != null ? _e : void 0,
3061
+ id: (_e = response.id) != null ? _e : void 0,
3062
+ modelId: (_f = response.model) != null ? _f : void 0,
3060
3063
  headers: responseHeaders,
3061
3064
  body: rawResponse
3062
3065
  },
@@ -3064,20 +3067,20 @@ var AnthropicMessagesLanguageModel = class {
3064
3067
  providerMetadata: {
3065
3068
  anthropic: {
3066
3069
  usage: response.usage,
3067
- cacheCreationInputTokens: (_f = response.usage.cache_creation_input_tokens) != null ? _f : null,
3068
- stopSequence: (_g = response.stop_sequence) != null ? _g : null,
3070
+ cacheCreationInputTokens: (_g = response.usage.cache_creation_input_tokens) != null ? _g : null,
3071
+ stopSequence: (_h = response.stop_sequence) != null ? _h : null,
3069
3072
  container: response.container ? {
3070
3073
  expiresAt: response.container.expires_at,
3071
3074
  id: response.container.id,
3072
- skills: (_i = (_h = response.container.skills) == null ? void 0 : _h.map((skill) => ({
3075
+ skills: (_j = (_i = response.container.skills) == null ? void 0 : _i.map((skill) => ({
3073
3076
  type: skill.type,
3074
3077
  skillId: skill.skill_id,
3075
3078
  version: skill.version
3076
- }))) != null ? _i : null
3079
+ }))) != null ? _j : null
3077
3080
  } : null,
3078
- contextManagement: (_j = mapAnthropicResponseContextManagement(
3081
+ contextManagement: (_k = mapAnthropicResponseContextManagement(
3079
3082
  response.context_management
3080
- )) != null ? _j : null
3083
+ )) != null ? _k : null
3081
3084
  }
3082
3085
  }
3083
3086
  };
@@ -3120,6 +3123,7 @@ var AnthropicMessagesLanguageModel = class {
3120
3123
  };
3121
3124
  const contentBlocks = {};
3122
3125
  const mcpToolCalls = {};
3126
+ const serverToolCalls = {};
3123
3127
  let contextManagement = null;
3124
3128
  let rawUsage = void 0;
3125
3129
  let cacheCreationInputTokens = null;
@@ -3134,7 +3138,7 @@ var AnthropicMessagesLanguageModel = class {
3134
3138
  controller.enqueue({ type: "stream-start", warnings });
3135
3139
  },
3136
3140
  transform(chunk, controller) {
3137
- var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
3141
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
3138
3142
  if (options.includeRawChunks) {
3139
3143
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
3140
3144
  }
@@ -3246,6 +3250,7 @@ var AnthropicMessagesLanguageModel = class {
3246
3250
  providerExecuted: true
3247
3251
  });
3248
3252
  } else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
3253
+ serverToolCalls[part.id] = part.name;
3249
3254
  const customToolName = toolNameMapping.toCustomToolName(
3250
3255
  part.name
3251
3256
  );
@@ -3390,11 +3395,12 @@ var AnthropicMessagesLanguageModel = class {
3390
3395
  }
3391
3396
  // tool search tool results:
3392
3397
  case "tool_search_tool_result": {
3398
+ const providerToolName = (_c = serverToolCalls[part.tool_use_id]) != null ? _c : "tool_search_tool_regex";
3393
3399
  if (part.content.type === "tool_search_tool_search_result") {
3394
3400
  controller.enqueue({
3395
3401
  type: "tool-result",
3396
3402
  toolCallId: part.tool_use_id,
3397
- toolName: toolNameMapping.toCustomToolName("tool_search"),
3403
+ toolName: toolNameMapping.toCustomToolName(providerToolName),
3398
3404
  result: part.content.tool_references.map((ref) => ({
3399
3405
  type: ref.type,
3400
3406
  toolName: ref.tool_name
@@ -3404,7 +3410,7 @@ var AnthropicMessagesLanguageModel = class {
3404
3410
  controller.enqueue({
3405
3411
  type: "tool-result",
3406
3412
  toolCallId: part.tool_use_id,
3407
- toolName: toolNameMapping.toCustomToolName("tool_search"),
3413
+ toolName: toolNameMapping.toCustomToolName(providerToolName),
3408
3414
  isError: true,
3409
3415
  result: {
3410
3416
  type: "tool_search_tool_result_error",
@@ -3603,12 +3609,12 @@ var AnthropicMessagesLanguageModel = class {
3603
3609
  }
3604
3610
  case "message_start": {
3605
3611
  usage.input_tokens = value.message.usage.input_tokens;
3606
- usage.cache_read_input_tokens = (_c = value.message.usage.cache_read_input_tokens) != null ? _c : 0;
3607
- usage.cache_creation_input_tokens = (_d = value.message.usage.cache_creation_input_tokens) != null ? _d : 0;
3612
+ usage.cache_read_input_tokens = (_d = value.message.usage.cache_read_input_tokens) != null ? _d : 0;
3613
+ usage.cache_creation_input_tokens = (_e = value.message.usage.cache_creation_input_tokens) != null ? _e : 0;
3608
3614
  rawUsage = {
3609
3615
  ...value.message.usage
3610
3616
  };
3611
- cacheCreationInputTokens = (_e = value.message.usage.cache_creation_input_tokens) != null ? _e : null;
3617
+ cacheCreationInputTokens = (_f = value.message.usage.cache_creation_input_tokens) != null ? _f : null;
3612
3618
  if (value.message.container != null) {
3613
3619
  container = {
3614
3620
  expiresAt: value.message.container.expires_at,
@@ -3627,8 +3633,8 @@ var AnthropicMessagesLanguageModel = class {
3627
3633
  }
3628
3634
  controller.enqueue({
3629
3635
  type: "response-metadata",
3630
- id: (_f = value.message.id) != null ? _f : void 0,
3631
- modelId: (_g = value.message.model) != null ? _g : void 0
3636
+ id: (_g = value.message.id) != null ? _g : void 0,
3637
+ modelId: (_h = value.message.model) != null ? _h : void 0
3632
3638
  });
3633
3639
  if (value.message.content != null) {
3634
3640
  for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
@@ -3644,7 +3650,7 @@ var AnthropicMessagesLanguageModel = class {
3644
3650
  id: part.id,
3645
3651
  toolName: part.name
3646
3652
  });
3647
- const inputStr = JSON.stringify((_h = part.input) != null ? _h : {});
3653
+ const inputStr = JSON.stringify((_i = part.input) != null ? _i : {});
3648
3654
  controller.enqueue({
3649
3655
  type: "tool-input-delta",
3650
3656
  id: part.id,
@@ -3679,17 +3685,17 @@ var AnthropicMessagesLanguageModel = class {
3679
3685
  finishReason: value.delta.stop_reason,
3680
3686
  isJsonResponseFromTool
3681
3687
  }),
3682
- raw: (_i = value.delta.stop_reason) != null ? _i : void 0
3688
+ raw: (_j = value.delta.stop_reason) != null ? _j : void 0
3683
3689
  };
3684
- stopSequence = (_j = value.delta.stop_sequence) != null ? _j : null;
3690
+ stopSequence = (_k = value.delta.stop_sequence) != null ? _k : null;
3685
3691
  container = value.delta.container != null ? {
3686
3692
  expiresAt: value.delta.container.expires_at,
3687
3693
  id: value.delta.container.id,
3688
- skills: (_l = (_k = value.delta.container.skills) == null ? void 0 : _k.map((skill) => ({
3694
+ skills: (_m = (_l = value.delta.container.skills) == null ? void 0 : _l.map((skill) => ({
3689
3695
  type: skill.type,
3690
3696
  skillId: skill.skill_id,
3691
3697
  version: skill.version
3692
- }))) != null ? _l : null
3698
+ }))) != null ? _m : null
3693
3699
  } : null;
3694
3700
  if (value.delta.context_management) {
3695
3701
  contextManagement = mapAnthropicResponseContextManagement(