@ai-sdk/anthropic 2.0.0-canary.11 → 2.0.0-canary.13

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
@@ -19,7 +19,7 @@ import {
19
19
  postJsonToApi,
20
20
  resolve
21
21
  } from "@ai-sdk/provider-utils";
22
- import { z as z2 } from "zod";
22
+ import { z as z3 } from "zod";
23
23
 
24
24
  // src/anthropic-error.ts
25
25
  import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
@@ -36,6 +36,21 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
36
36
  errorToMessage: (data) => data.error.message
37
37
  });
38
38
 
39
+ // src/anthropic-messages-options.ts
40
+ import { z as z2 } from "zod";
41
+ var anthropicProviderOptions = z2.object({
42
+ /**
43
+ Include reasoning content in requests sent to the model. Defaults to `true`.
44
+
45
+ If you are experiencing issues with the model handling requests involving
46
+ */
47
+ sendReasoning: z2.boolean().optional(),
48
+ thinking: z2.object({
49
+ type: z2.union([z2.literal("enabled"), z2.literal("disabled")]),
50
+ budgetTokens: z2.number().optional()
51
+ }).optional()
52
+ });
53
+
39
54
  // src/anthropic-prepare-tools.ts
40
55
  import {
41
56
  UnsupportedFunctionalityError
@@ -460,10 +475,9 @@ function mapAnthropicStopReason(finishReason) {
460
475
 
461
476
  // src/anthropic-messages-language-model.ts
462
477
  var AnthropicMessagesLanguageModel = class {
463
- constructor(modelId, settings, config) {
478
+ constructor(modelId, config) {
464
479
  this.specificationVersion = "v2";
465
480
  this.modelId = modelId;
466
- this.settings = settings;
467
481
  this.config = config;
468
482
  }
469
483
  supportsUrl(url) {
@@ -472,9 +486,9 @@ var AnthropicMessagesLanguageModel = class {
472
486
  get provider() {
473
487
  return this.config.provider;
474
488
  }
475
- async getSupportedUrls() {
489
+ get supportedUrls() {
476
490
  var _a, _b, _c;
477
- return (_c = (_b = (_a = this.config).getSupportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
491
+ return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
478
492
  }
479
493
  async getArgs({
480
494
  prompt,
@@ -519,15 +533,15 @@ var AnthropicMessagesLanguageModel = class {
519
533
  details: "JSON response format is not supported."
520
534
  });
521
535
  }
522
- const { prompt: messagesPrompt, betas: messagesBetas } = await convertToAnthropicMessagesPrompt({
523
- prompt,
524
- sendReasoning: (_a = this.settings.sendReasoning) != null ? _a : true,
525
- warnings
526
- });
527
536
  const anthropicOptions = await parseProviderOptions2({
528
537
  provider: "anthropic",
529
538
  providerOptions,
530
- schema: anthropicProviderOptionsSchema
539
+ schema: anthropicProviderOptions
540
+ });
541
+ const { prompt: messagesPrompt, betas: messagesBetas } = await convertToAnthropicMessagesPrompt({
542
+ prompt,
543
+ sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
544
+ warnings
531
545
  });
532
546
  const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
533
547
  const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
@@ -888,139 +902,133 @@ var AnthropicMessagesLanguageModel = class {
888
902
  };
889
903
  }
890
904
  };
891
- var anthropicMessagesResponseSchema = z2.object({
892
- type: z2.literal("message"),
893
- id: z2.string().nullish(),
894
- model: z2.string().nullish(),
895
- content: z2.array(
896
- z2.discriminatedUnion("type", [
897
- z2.object({
898
- type: z2.literal("text"),
899
- text: z2.string()
905
+ var anthropicMessagesResponseSchema = z3.object({
906
+ type: z3.literal("message"),
907
+ id: z3.string().nullish(),
908
+ model: z3.string().nullish(),
909
+ content: z3.array(
910
+ z3.discriminatedUnion("type", [
911
+ z3.object({
912
+ type: z3.literal("text"),
913
+ text: z3.string()
900
914
  }),
901
- z2.object({
902
- type: z2.literal("thinking"),
903
- thinking: z2.string(),
904
- signature: z2.string()
915
+ z3.object({
916
+ type: z3.literal("thinking"),
917
+ thinking: z3.string(),
918
+ signature: z3.string()
905
919
  }),
906
- z2.object({
907
- type: z2.literal("redacted_thinking"),
908
- data: z2.string()
920
+ z3.object({
921
+ type: z3.literal("redacted_thinking"),
922
+ data: z3.string()
909
923
  }),
910
- z2.object({
911
- type: z2.literal("tool_use"),
912
- id: z2.string(),
913
- name: z2.string(),
914
- input: z2.unknown()
924
+ z3.object({
925
+ type: z3.literal("tool_use"),
926
+ id: z3.string(),
927
+ name: z3.string(),
928
+ input: z3.unknown()
915
929
  })
916
930
  ])
917
931
  ),
918
- stop_reason: z2.string().nullish(),
919
- usage: z2.object({
920
- input_tokens: z2.number(),
921
- output_tokens: z2.number(),
922
- cache_creation_input_tokens: z2.number().nullish(),
923
- cache_read_input_tokens: z2.number().nullish()
932
+ stop_reason: z3.string().nullish(),
933
+ usage: z3.object({
934
+ input_tokens: z3.number(),
935
+ output_tokens: z3.number(),
936
+ cache_creation_input_tokens: z3.number().nullish(),
937
+ cache_read_input_tokens: z3.number().nullish()
924
938
  })
925
939
  });
926
- var anthropicMessagesChunkSchema = z2.discriminatedUnion("type", [
927
- z2.object({
928
- type: z2.literal("message_start"),
929
- message: z2.object({
930
- id: z2.string().nullish(),
931
- model: z2.string().nullish(),
932
- usage: z2.object({
933
- input_tokens: z2.number(),
934
- output_tokens: z2.number(),
935
- cache_creation_input_tokens: z2.number().nullish(),
936
- cache_read_input_tokens: z2.number().nullish()
940
+ var anthropicMessagesChunkSchema = z3.discriminatedUnion("type", [
941
+ z3.object({
942
+ type: z3.literal("message_start"),
943
+ message: z3.object({
944
+ id: z3.string().nullish(),
945
+ model: z3.string().nullish(),
946
+ usage: z3.object({
947
+ input_tokens: z3.number(),
948
+ output_tokens: z3.number(),
949
+ cache_creation_input_tokens: z3.number().nullish(),
950
+ cache_read_input_tokens: z3.number().nullish()
937
951
  })
938
952
  })
939
953
  }),
940
- z2.object({
941
- type: z2.literal("content_block_start"),
942
- index: z2.number(),
943
- content_block: z2.discriminatedUnion("type", [
944
- z2.object({
945
- type: z2.literal("text"),
946
- text: z2.string()
954
+ z3.object({
955
+ type: z3.literal("content_block_start"),
956
+ index: z3.number(),
957
+ content_block: z3.discriminatedUnion("type", [
958
+ z3.object({
959
+ type: z3.literal("text"),
960
+ text: z3.string()
947
961
  }),
948
- z2.object({
949
- type: z2.literal("thinking"),
950
- thinking: z2.string()
962
+ z3.object({
963
+ type: z3.literal("thinking"),
964
+ thinking: z3.string()
951
965
  }),
952
- z2.object({
953
- type: z2.literal("tool_use"),
954
- id: z2.string(),
955
- name: z2.string()
966
+ z3.object({
967
+ type: z3.literal("tool_use"),
968
+ id: z3.string(),
969
+ name: z3.string()
956
970
  }),
957
- z2.object({
958
- type: z2.literal("redacted_thinking"),
959
- data: z2.string()
971
+ z3.object({
972
+ type: z3.literal("redacted_thinking"),
973
+ data: z3.string()
960
974
  })
961
975
  ])
962
976
  }),
963
- z2.object({
964
- type: z2.literal("content_block_delta"),
965
- index: z2.number(),
966
- delta: z2.discriminatedUnion("type", [
967
- z2.object({
968
- type: z2.literal("input_json_delta"),
969
- partial_json: z2.string()
977
+ z3.object({
978
+ type: z3.literal("content_block_delta"),
979
+ index: z3.number(),
980
+ delta: z3.discriminatedUnion("type", [
981
+ z3.object({
982
+ type: z3.literal("input_json_delta"),
983
+ partial_json: z3.string()
970
984
  }),
971
- z2.object({
972
- type: z2.literal("text_delta"),
973
- text: z2.string()
985
+ z3.object({
986
+ type: z3.literal("text_delta"),
987
+ text: z3.string()
974
988
  }),
975
- z2.object({
976
- type: z2.literal("thinking_delta"),
977
- thinking: z2.string()
989
+ z3.object({
990
+ type: z3.literal("thinking_delta"),
991
+ thinking: z3.string()
978
992
  }),
979
- z2.object({
980
- type: z2.literal("signature_delta"),
981
- signature: z2.string()
993
+ z3.object({
994
+ type: z3.literal("signature_delta"),
995
+ signature: z3.string()
982
996
  })
983
997
  ])
984
998
  }),
985
- z2.object({
986
- type: z2.literal("content_block_stop"),
987
- index: z2.number()
999
+ z3.object({
1000
+ type: z3.literal("content_block_stop"),
1001
+ index: z3.number()
988
1002
  }),
989
- z2.object({
990
- type: z2.literal("error"),
991
- error: z2.object({
992
- type: z2.string(),
993
- message: z2.string()
1003
+ z3.object({
1004
+ type: z3.literal("error"),
1005
+ error: z3.object({
1006
+ type: z3.string(),
1007
+ message: z3.string()
994
1008
  })
995
1009
  }),
996
- z2.object({
997
- type: z2.literal("message_delta"),
998
- delta: z2.object({ stop_reason: z2.string().nullish() }),
999
- usage: z2.object({ output_tokens: z2.number() })
1010
+ z3.object({
1011
+ type: z3.literal("message_delta"),
1012
+ delta: z3.object({ stop_reason: z3.string().nullish() }),
1013
+ usage: z3.object({ output_tokens: z3.number() })
1000
1014
  }),
1001
- z2.object({
1002
- type: z2.literal("message_stop")
1015
+ z3.object({
1016
+ type: z3.literal("message_stop")
1003
1017
  }),
1004
- z2.object({
1005
- type: z2.literal("ping")
1018
+ z3.object({
1019
+ type: z3.literal("ping")
1006
1020
  })
1007
1021
  ]);
1008
- var anthropicProviderOptionsSchema = z2.object({
1009
- thinking: z2.object({
1010
- type: z2.union([z2.literal("enabled"), z2.literal("disabled")]),
1011
- budgetTokens: z2.number().optional()
1012
- }).optional()
1013
- });
1014
- var anthropicReasoningMetadataSchema = z2.object({
1015
- signature: z2.string().optional(),
1016
- redactedData: z2.string().optional()
1022
+ var anthropicReasoningMetadataSchema = z3.object({
1023
+ signature: z3.string().optional(),
1024
+ redactedData: z3.string().optional()
1017
1025
  });
1018
1026
 
1019
1027
  // src/anthropic-tools.ts
1020
- import { z as z3 } from "zod";
1021
- var Bash20241022Parameters = z3.object({
1022
- command: z3.string(),
1023
- restart: z3.boolean().optional()
1028
+ import { z as z4 } from "zod";
1029
+ var Bash20241022Parameters = z4.object({
1030
+ command: z4.string(),
1031
+ restart: z4.boolean().optional()
1024
1032
  });
1025
1033
  function bashTool_20241022(options = {}) {
1026
1034
  return {
@@ -1032,9 +1040,9 @@ function bashTool_20241022(options = {}) {
1032
1040
  experimental_toToolResultContent: options.experimental_toToolResultContent
1033
1041
  };
1034
1042
  }
1035
- var Bash20250124Parameters = z3.object({
1036
- command: z3.string(),
1037
- restart: z3.boolean().optional()
1043
+ var Bash20250124Parameters = z4.object({
1044
+ command: z4.string(),
1045
+ restart: z4.boolean().optional()
1038
1046
  });
1039
1047
  function bashTool_20250124(options = {}) {
1040
1048
  return {
@@ -1046,14 +1054,14 @@ function bashTool_20250124(options = {}) {
1046
1054
  experimental_toToolResultContent: options.experimental_toToolResultContent
1047
1055
  };
1048
1056
  }
1049
- var TextEditor20241022Parameters = z3.object({
1050
- command: z3.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1051
- path: z3.string(),
1052
- file_text: z3.string().optional(),
1053
- insert_line: z3.number().int().optional(),
1054
- new_str: z3.string().optional(),
1055
- old_str: z3.string().optional(),
1056
- view_range: z3.array(z3.number().int()).optional()
1057
+ var TextEditor20241022Parameters = z4.object({
1058
+ command: z4.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1059
+ path: z4.string(),
1060
+ file_text: z4.string().optional(),
1061
+ insert_line: z4.number().int().optional(),
1062
+ new_str: z4.string().optional(),
1063
+ old_str: z4.string().optional(),
1064
+ view_range: z4.array(z4.number().int()).optional()
1057
1065
  });
1058
1066
  function textEditorTool_20241022(options = {}) {
1059
1067
  return {
@@ -1065,14 +1073,14 @@ function textEditorTool_20241022(options = {}) {
1065
1073
  experimental_toToolResultContent: options.experimental_toToolResultContent
1066
1074
  };
1067
1075
  }
1068
- var TextEditor20250124Parameters = z3.object({
1069
- command: z3.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1070
- path: z3.string(),
1071
- file_text: z3.string().optional(),
1072
- insert_line: z3.number().int().optional(),
1073
- new_str: z3.string().optional(),
1074
- old_str: z3.string().optional(),
1075
- view_range: z3.array(z3.number().int()).optional()
1076
+ var TextEditor20250124Parameters = z4.object({
1077
+ command: z4.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1078
+ path: z4.string(),
1079
+ file_text: z4.string().optional(),
1080
+ insert_line: z4.number().int().optional(),
1081
+ new_str: z4.string().optional(),
1082
+ old_str: z4.string().optional(),
1083
+ view_range: z4.array(z4.number().int()).optional()
1076
1084
  });
1077
1085
  function textEditorTool_20250124(options = {}) {
1078
1086
  return {
@@ -1084,8 +1092,8 @@ function textEditorTool_20250124(options = {}) {
1084
1092
  experimental_toToolResultContent: options.experimental_toToolResultContent
1085
1093
  };
1086
1094
  }
1087
- var Computer20241022Parameters = z3.object({
1088
- action: z3.enum([
1095
+ var Computer20241022Parameters = z4.object({
1096
+ action: z4.enum([
1089
1097
  "key",
1090
1098
  "type",
1091
1099
  "mouse_move",
@@ -1097,8 +1105,8 @@ var Computer20241022Parameters = z3.object({
1097
1105
  "screenshot",
1098
1106
  "cursor_position"
1099
1107
  ]),
1100
- coordinate: z3.array(z3.number().int()).optional(),
1101
- text: z3.string().optional()
1108
+ coordinate: z4.array(z4.number().int()).optional(),
1109
+ text: z4.string().optional()
1102
1110
  });
1103
1111
  function computerTool_20241022(options) {
1104
1112
  return {
@@ -1114,8 +1122,8 @@ function computerTool_20241022(options) {
1114
1122
  experimental_toToolResultContent: options.experimental_toToolResultContent
1115
1123
  };
1116
1124
  }
1117
- var Computer20250124Parameters = z3.object({
1118
- action: z3.enum([
1125
+ var Computer20250124Parameters = z4.object({
1126
+ action: z4.enum([
1119
1127
  "key",
1120
1128
  "hold_key",
1121
1129
  "type",
@@ -1133,12 +1141,12 @@ var Computer20250124Parameters = z3.object({
1133
1141
  "wait",
1134
1142
  "screenshot"
1135
1143
  ]),
1136
- coordinate: z3.tuple([z3.number().int(), z3.number().int()]).optional(),
1137
- duration: z3.number().optional(),
1138
- scroll_amount: z3.number().optional(),
1139
- scroll_direction: z3.enum(["up", "down", "left", "right"]).optional(),
1140
- start_coordinate: z3.tuple([z3.number().int(), z3.number().int()]).optional(),
1141
- text: z3.string().optional()
1144
+ coordinate: z4.tuple([z4.number().int(), z4.number().int()]).optional(),
1145
+ duration: z4.number().optional(),
1146
+ scroll_amount: z4.number().optional(),
1147
+ scroll_direction: z4.enum(["up", "down", "left", "right"]).optional(),
1148
+ start_coordinate: z4.tuple([z4.number().int(), z4.number().int()]).optional(),
1149
+ text: z4.string().optional()
1142
1150
  });
1143
1151
  function computerTool_20250124(options) {
1144
1152
  return {
@@ -1176,22 +1184,22 @@ function createAnthropic(options = {}) {
1176
1184
  }),
1177
1185
  ...options.headers
1178
1186
  });
1179
- const createChatModel = (modelId, settings = {}) => new AnthropicMessagesLanguageModel(modelId, settings, {
1187
+ const createChatModel = (modelId) => new AnthropicMessagesLanguageModel(modelId, {
1180
1188
  provider: "anthropic.messages",
1181
1189
  baseURL,
1182
1190
  headers: getHeaders,
1183
1191
  fetch: options.fetch,
1184
- getSupportedUrls: async () => ({
1192
+ supportedUrls: () => ({
1185
1193
  "image/*": [/^https?:\/\/.*$/]
1186
1194
  })
1187
1195
  });
1188
- const provider = function(modelId, settings) {
1196
+ const provider = function(modelId) {
1189
1197
  if (new.target) {
1190
1198
  throw new Error(
1191
1199
  "The Anthropic model function cannot be called with the new keyword."
1192
1200
  );
1193
1201
  }
1194
- return createChatModel(modelId, settings);
1202
+ return createChatModel(modelId);
1195
1203
  };
1196
1204
  provider.languageModel = createChatModel;
1197
1205
  provider.chat = createChatModel;