@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.
@@ -10,7 +10,7 @@ import {
10
10
  postJsonToApi,
11
11
  resolve
12
12
  } from "@ai-sdk/provider-utils";
13
- import { z as z2 } from "zod";
13
+ import { z as z3 } from "zod";
14
14
 
15
15
  // src/anthropic-error.ts
16
16
  import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
@@ -27,6 +27,21 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
27
27
  errorToMessage: (data) => data.error.message
28
28
  });
29
29
 
30
+ // src/anthropic-messages-options.ts
31
+ import { z as z2 } from "zod";
32
+ var anthropicProviderOptions = z2.object({
33
+ /**
34
+ Include reasoning content in requests sent to the model. Defaults to `true`.
35
+
36
+ If you are experiencing issues with the model handling requests involving
37
+ */
38
+ sendReasoning: z2.boolean().optional(),
39
+ thinking: z2.object({
40
+ type: z2.union([z2.literal("enabled"), z2.literal("disabled")]),
41
+ budgetTokens: z2.number().optional()
42
+ }).optional()
43
+ });
44
+
30
45
  // src/anthropic-prepare-tools.ts
31
46
  import {
32
47
  UnsupportedFunctionalityError
@@ -451,10 +466,9 @@ function mapAnthropicStopReason(finishReason) {
451
466
 
452
467
  // src/anthropic-messages-language-model.ts
453
468
  var AnthropicMessagesLanguageModel = class {
454
- constructor(modelId, settings, config) {
469
+ constructor(modelId, config) {
455
470
  this.specificationVersion = "v2";
456
471
  this.modelId = modelId;
457
- this.settings = settings;
458
472
  this.config = config;
459
473
  }
460
474
  supportsUrl(url) {
@@ -463,9 +477,9 @@ var AnthropicMessagesLanguageModel = class {
463
477
  get provider() {
464
478
  return this.config.provider;
465
479
  }
466
- async getSupportedUrls() {
480
+ get supportedUrls() {
467
481
  var _a, _b, _c;
468
- return (_c = (_b = (_a = this.config).getSupportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
482
+ return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
469
483
  }
470
484
  async getArgs({
471
485
  prompt,
@@ -510,15 +524,15 @@ var AnthropicMessagesLanguageModel = class {
510
524
  details: "JSON response format is not supported."
511
525
  });
512
526
  }
513
- const { prompt: messagesPrompt, betas: messagesBetas } = await convertToAnthropicMessagesPrompt({
514
- prompt,
515
- sendReasoning: (_a = this.settings.sendReasoning) != null ? _a : true,
516
- warnings
517
- });
518
527
  const anthropicOptions = await parseProviderOptions2({
519
528
  provider: "anthropic",
520
529
  providerOptions,
521
- schema: anthropicProviderOptionsSchema
530
+ schema: anthropicProviderOptions
531
+ });
532
+ const { prompt: messagesPrompt, betas: messagesBetas } = await convertToAnthropicMessagesPrompt({
533
+ prompt,
534
+ sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
535
+ warnings
522
536
  });
523
537
  const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
524
538
  const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
@@ -879,139 +893,133 @@ var AnthropicMessagesLanguageModel = class {
879
893
  };
880
894
  }
881
895
  };
882
- var anthropicMessagesResponseSchema = z2.object({
883
- type: z2.literal("message"),
884
- id: z2.string().nullish(),
885
- model: z2.string().nullish(),
886
- content: z2.array(
887
- z2.discriminatedUnion("type", [
888
- z2.object({
889
- type: z2.literal("text"),
890
- text: z2.string()
896
+ var anthropicMessagesResponseSchema = z3.object({
897
+ type: z3.literal("message"),
898
+ id: z3.string().nullish(),
899
+ model: z3.string().nullish(),
900
+ content: z3.array(
901
+ z3.discriminatedUnion("type", [
902
+ z3.object({
903
+ type: z3.literal("text"),
904
+ text: z3.string()
891
905
  }),
892
- z2.object({
893
- type: z2.literal("thinking"),
894
- thinking: z2.string(),
895
- signature: z2.string()
906
+ z3.object({
907
+ type: z3.literal("thinking"),
908
+ thinking: z3.string(),
909
+ signature: z3.string()
896
910
  }),
897
- z2.object({
898
- type: z2.literal("redacted_thinking"),
899
- data: z2.string()
911
+ z3.object({
912
+ type: z3.literal("redacted_thinking"),
913
+ data: z3.string()
900
914
  }),
901
- z2.object({
902
- type: z2.literal("tool_use"),
903
- id: z2.string(),
904
- name: z2.string(),
905
- input: z2.unknown()
915
+ z3.object({
916
+ type: z3.literal("tool_use"),
917
+ id: z3.string(),
918
+ name: z3.string(),
919
+ input: z3.unknown()
906
920
  })
907
921
  ])
908
922
  ),
909
- stop_reason: z2.string().nullish(),
910
- usage: z2.object({
911
- input_tokens: z2.number(),
912
- output_tokens: z2.number(),
913
- cache_creation_input_tokens: z2.number().nullish(),
914
- cache_read_input_tokens: z2.number().nullish()
923
+ stop_reason: z3.string().nullish(),
924
+ usage: z3.object({
925
+ input_tokens: z3.number(),
926
+ output_tokens: z3.number(),
927
+ cache_creation_input_tokens: z3.number().nullish(),
928
+ cache_read_input_tokens: z3.number().nullish()
915
929
  })
916
930
  });
917
- var anthropicMessagesChunkSchema = z2.discriminatedUnion("type", [
918
- z2.object({
919
- type: z2.literal("message_start"),
920
- message: z2.object({
921
- id: z2.string().nullish(),
922
- model: z2.string().nullish(),
923
- usage: z2.object({
924
- input_tokens: z2.number(),
925
- output_tokens: z2.number(),
926
- cache_creation_input_tokens: z2.number().nullish(),
927
- cache_read_input_tokens: z2.number().nullish()
931
+ var anthropicMessagesChunkSchema = z3.discriminatedUnion("type", [
932
+ z3.object({
933
+ type: z3.literal("message_start"),
934
+ message: z3.object({
935
+ id: z3.string().nullish(),
936
+ model: z3.string().nullish(),
937
+ usage: z3.object({
938
+ input_tokens: z3.number(),
939
+ output_tokens: z3.number(),
940
+ cache_creation_input_tokens: z3.number().nullish(),
941
+ cache_read_input_tokens: z3.number().nullish()
928
942
  })
929
943
  })
930
944
  }),
931
- z2.object({
932
- type: z2.literal("content_block_start"),
933
- index: z2.number(),
934
- content_block: z2.discriminatedUnion("type", [
935
- z2.object({
936
- type: z2.literal("text"),
937
- text: z2.string()
945
+ z3.object({
946
+ type: z3.literal("content_block_start"),
947
+ index: z3.number(),
948
+ content_block: z3.discriminatedUnion("type", [
949
+ z3.object({
950
+ type: z3.literal("text"),
951
+ text: z3.string()
938
952
  }),
939
- z2.object({
940
- type: z2.literal("thinking"),
941
- thinking: z2.string()
953
+ z3.object({
954
+ type: z3.literal("thinking"),
955
+ thinking: z3.string()
942
956
  }),
943
- z2.object({
944
- type: z2.literal("tool_use"),
945
- id: z2.string(),
946
- name: z2.string()
957
+ z3.object({
958
+ type: z3.literal("tool_use"),
959
+ id: z3.string(),
960
+ name: z3.string()
947
961
  }),
948
- z2.object({
949
- type: z2.literal("redacted_thinking"),
950
- data: z2.string()
962
+ z3.object({
963
+ type: z3.literal("redacted_thinking"),
964
+ data: z3.string()
951
965
  })
952
966
  ])
953
967
  }),
954
- z2.object({
955
- type: z2.literal("content_block_delta"),
956
- index: z2.number(),
957
- delta: z2.discriminatedUnion("type", [
958
- z2.object({
959
- type: z2.literal("input_json_delta"),
960
- partial_json: z2.string()
968
+ z3.object({
969
+ type: z3.literal("content_block_delta"),
970
+ index: z3.number(),
971
+ delta: z3.discriminatedUnion("type", [
972
+ z3.object({
973
+ type: z3.literal("input_json_delta"),
974
+ partial_json: z3.string()
961
975
  }),
962
- z2.object({
963
- type: z2.literal("text_delta"),
964
- text: z2.string()
976
+ z3.object({
977
+ type: z3.literal("text_delta"),
978
+ text: z3.string()
965
979
  }),
966
- z2.object({
967
- type: z2.literal("thinking_delta"),
968
- thinking: z2.string()
980
+ z3.object({
981
+ type: z3.literal("thinking_delta"),
982
+ thinking: z3.string()
969
983
  }),
970
- z2.object({
971
- type: z2.literal("signature_delta"),
972
- signature: z2.string()
984
+ z3.object({
985
+ type: z3.literal("signature_delta"),
986
+ signature: z3.string()
973
987
  })
974
988
  ])
975
989
  }),
976
- z2.object({
977
- type: z2.literal("content_block_stop"),
978
- index: z2.number()
990
+ z3.object({
991
+ type: z3.literal("content_block_stop"),
992
+ index: z3.number()
979
993
  }),
980
- z2.object({
981
- type: z2.literal("error"),
982
- error: z2.object({
983
- type: z2.string(),
984
- message: z2.string()
994
+ z3.object({
995
+ type: z3.literal("error"),
996
+ error: z3.object({
997
+ type: z3.string(),
998
+ message: z3.string()
985
999
  })
986
1000
  }),
987
- z2.object({
988
- type: z2.literal("message_delta"),
989
- delta: z2.object({ stop_reason: z2.string().nullish() }),
990
- usage: z2.object({ output_tokens: z2.number() })
1001
+ z3.object({
1002
+ type: z3.literal("message_delta"),
1003
+ delta: z3.object({ stop_reason: z3.string().nullish() }),
1004
+ usage: z3.object({ output_tokens: z3.number() })
991
1005
  }),
992
- z2.object({
993
- type: z2.literal("message_stop")
1006
+ z3.object({
1007
+ type: z3.literal("message_stop")
994
1008
  }),
995
- z2.object({
996
- type: z2.literal("ping")
1009
+ z3.object({
1010
+ type: z3.literal("ping")
997
1011
  })
998
1012
  ]);
999
- var anthropicProviderOptionsSchema = z2.object({
1000
- thinking: z2.object({
1001
- type: z2.union([z2.literal("enabled"), z2.literal("disabled")]),
1002
- budgetTokens: z2.number().optional()
1003
- }).optional()
1004
- });
1005
- var anthropicReasoningMetadataSchema = z2.object({
1006
- signature: z2.string().optional(),
1007
- redactedData: z2.string().optional()
1013
+ var anthropicReasoningMetadataSchema = z3.object({
1014
+ signature: z3.string().optional(),
1015
+ redactedData: z3.string().optional()
1008
1016
  });
1009
1017
 
1010
1018
  // src/anthropic-tools.ts
1011
- import { z as z3 } from "zod";
1012
- var Bash20241022Parameters = z3.object({
1013
- command: z3.string(),
1014
- restart: z3.boolean().optional()
1019
+ import { z as z4 } from "zod";
1020
+ var Bash20241022Parameters = z4.object({
1021
+ command: z4.string(),
1022
+ restart: z4.boolean().optional()
1015
1023
  });
1016
1024
  function bashTool_20241022(options = {}) {
1017
1025
  return {
@@ -1023,9 +1031,9 @@ function bashTool_20241022(options = {}) {
1023
1031
  experimental_toToolResultContent: options.experimental_toToolResultContent
1024
1032
  };
1025
1033
  }
1026
- var Bash20250124Parameters = z3.object({
1027
- command: z3.string(),
1028
- restart: z3.boolean().optional()
1034
+ var Bash20250124Parameters = z4.object({
1035
+ command: z4.string(),
1036
+ restart: z4.boolean().optional()
1029
1037
  });
1030
1038
  function bashTool_20250124(options = {}) {
1031
1039
  return {
@@ -1037,14 +1045,14 @@ function bashTool_20250124(options = {}) {
1037
1045
  experimental_toToolResultContent: options.experimental_toToolResultContent
1038
1046
  };
1039
1047
  }
1040
- var TextEditor20241022Parameters = z3.object({
1041
- command: z3.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1042
- path: z3.string(),
1043
- file_text: z3.string().optional(),
1044
- insert_line: z3.number().int().optional(),
1045
- new_str: z3.string().optional(),
1046
- old_str: z3.string().optional(),
1047
- view_range: z3.array(z3.number().int()).optional()
1048
+ var TextEditor20241022Parameters = z4.object({
1049
+ command: z4.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1050
+ path: z4.string(),
1051
+ file_text: z4.string().optional(),
1052
+ insert_line: z4.number().int().optional(),
1053
+ new_str: z4.string().optional(),
1054
+ old_str: z4.string().optional(),
1055
+ view_range: z4.array(z4.number().int()).optional()
1048
1056
  });
1049
1057
  function textEditorTool_20241022(options = {}) {
1050
1058
  return {
@@ -1056,14 +1064,14 @@ function textEditorTool_20241022(options = {}) {
1056
1064
  experimental_toToolResultContent: options.experimental_toToolResultContent
1057
1065
  };
1058
1066
  }
1059
- var TextEditor20250124Parameters = z3.object({
1060
- command: z3.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1061
- path: z3.string(),
1062
- file_text: z3.string().optional(),
1063
- insert_line: z3.number().int().optional(),
1064
- new_str: z3.string().optional(),
1065
- old_str: z3.string().optional(),
1066
- view_range: z3.array(z3.number().int()).optional()
1067
+ var TextEditor20250124Parameters = z4.object({
1068
+ command: z4.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1069
+ path: z4.string(),
1070
+ file_text: z4.string().optional(),
1071
+ insert_line: z4.number().int().optional(),
1072
+ new_str: z4.string().optional(),
1073
+ old_str: z4.string().optional(),
1074
+ view_range: z4.array(z4.number().int()).optional()
1067
1075
  });
1068
1076
  function textEditorTool_20250124(options = {}) {
1069
1077
  return {
@@ -1075,8 +1083,8 @@ function textEditorTool_20250124(options = {}) {
1075
1083
  experimental_toToolResultContent: options.experimental_toToolResultContent
1076
1084
  };
1077
1085
  }
1078
- var Computer20241022Parameters = z3.object({
1079
- action: z3.enum([
1086
+ var Computer20241022Parameters = z4.object({
1087
+ action: z4.enum([
1080
1088
  "key",
1081
1089
  "type",
1082
1090
  "mouse_move",
@@ -1088,8 +1096,8 @@ var Computer20241022Parameters = z3.object({
1088
1096
  "screenshot",
1089
1097
  "cursor_position"
1090
1098
  ]),
1091
- coordinate: z3.array(z3.number().int()).optional(),
1092
- text: z3.string().optional()
1099
+ coordinate: z4.array(z4.number().int()).optional(),
1100
+ text: z4.string().optional()
1093
1101
  });
1094
1102
  function computerTool_20241022(options) {
1095
1103
  return {
@@ -1105,8 +1113,8 @@ function computerTool_20241022(options) {
1105
1113
  experimental_toToolResultContent: options.experimental_toToolResultContent
1106
1114
  };
1107
1115
  }
1108
- var Computer20250124Parameters = z3.object({
1109
- action: z3.enum([
1116
+ var Computer20250124Parameters = z4.object({
1117
+ action: z4.enum([
1110
1118
  "key",
1111
1119
  "hold_key",
1112
1120
  "type",
@@ -1124,12 +1132,12 @@ var Computer20250124Parameters = z3.object({
1124
1132
  "wait",
1125
1133
  "screenshot"
1126
1134
  ]),
1127
- coordinate: z3.tuple([z3.number().int(), z3.number().int()]).optional(),
1128
- duration: z3.number().optional(),
1129
- scroll_amount: z3.number().optional(),
1130
- scroll_direction: z3.enum(["up", "down", "left", "right"]).optional(),
1131
- start_coordinate: z3.tuple([z3.number().int(), z3.number().int()]).optional(),
1132
- text: z3.string().optional()
1135
+ coordinate: z4.tuple([z4.number().int(), z4.number().int()]).optional(),
1136
+ duration: z4.number().optional(),
1137
+ scroll_amount: z4.number().optional(),
1138
+ scroll_direction: z4.enum(["up", "down", "left", "right"]).optional(),
1139
+ start_coordinate: z4.tuple([z4.number().int(), z4.number().int()]).optional(),
1140
+ text: z4.string().optional()
1133
1141
  });
1134
1142
  function computerTool_20250124(options) {
1135
1143
  return {