@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/CHANGELOG.md +20 -0
- package/dist/index.d.mts +9 -19
- package/dist/index.d.ts +9 -19
- package/dist/index.js +154 -146
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +154 -146
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +4 -22
- package/dist/internal/index.d.ts +4 -22
- package/dist/internal/index.js +150 -142
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +150 -142
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
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
|
|
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,
|
|
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
|
-
|
|
489
|
+
get supportedUrls() {
|
|
476
490
|
var _a, _b, _c;
|
|
477
|
-
return (_c = (_b = (_a = this.config).
|
|
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:
|
|
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 =
|
|
892
|
-
type:
|
|
893
|
-
id:
|
|
894
|
-
model:
|
|
895
|
-
content:
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
type:
|
|
899
|
-
text:
|
|
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
|
-
|
|
902
|
-
type:
|
|
903
|
-
thinking:
|
|
904
|
-
signature:
|
|
915
|
+
z3.object({
|
|
916
|
+
type: z3.literal("thinking"),
|
|
917
|
+
thinking: z3.string(),
|
|
918
|
+
signature: z3.string()
|
|
905
919
|
}),
|
|
906
|
-
|
|
907
|
-
type:
|
|
908
|
-
data:
|
|
920
|
+
z3.object({
|
|
921
|
+
type: z3.literal("redacted_thinking"),
|
|
922
|
+
data: z3.string()
|
|
909
923
|
}),
|
|
910
|
-
|
|
911
|
-
type:
|
|
912
|
-
id:
|
|
913
|
-
name:
|
|
914
|
-
input:
|
|
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:
|
|
919
|
-
usage:
|
|
920
|
-
input_tokens:
|
|
921
|
-
output_tokens:
|
|
922
|
-
cache_creation_input_tokens:
|
|
923
|
-
cache_read_input_tokens:
|
|
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 =
|
|
927
|
-
|
|
928
|
-
type:
|
|
929
|
-
message:
|
|
930
|
-
id:
|
|
931
|
-
model:
|
|
932
|
-
usage:
|
|
933
|
-
input_tokens:
|
|
934
|
-
output_tokens:
|
|
935
|
-
cache_creation_input_tokens:
|
|
936
|
-
cache_read_input_tokens:
|
|
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
|
-
|
|
941
|
-
type:
|
|
942
|
-
index:
|
|
943
|
-
content_block:
|
|
944
|
-
|
|
945
|
-
type:
|
|
946
|
-
text:
|
|
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
|
-
|
|
949
|
-
type:
|
|
950
|
-
thinking:
|
|
962
|
+
z3.object({
|
|
963
|
+
type: z3.literal("thinking"),
|
|
964
|
+
thinking: z3.string()
|
|
951
965
|
}),
|
|
952
|
-
|
|
953
|
-
type:
|
|
954
|
-
id:
|
|
955
|
-
name:
|
|
966
|
+
z3.object({
|
|
967
|
+
type: z3.literal("tool_use"),
|
|
968
|
+
id: z3.string(),
|
|
969
|
+
name: z3.string()
|
|
956
970
|
}),
|
|
957
|
-
|
|
958
|
-
type:
|
|
959
|
-
data:
|
|
971
|
+
z3.object({
|
|
972
|
+
type: z3.literal("redacted_thinking"),
|
|
973
|
+
data: z3.string()
|
|
960
974
|
})
|
|
961
975
|
])
|
|
962
976
|
}),
|
|
963
|
-
|
|
964
|
-
type:
|
|
965
|
-
index:
|
|
966
|
-
delta:
|
|
967
|
-
|
|
968
|
-
type:
|
|
969
|
-
partial_json:
|
|
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
|
-
|
|
972
|
-
type:
|
|
973
|
-
text:
|
|
985
|
+
z3.object({
|
|
986
|
+
type: z3.literal("text_delta"),
|
|
987
|
+
text: z3.string()
|
|
974
988
|
}),
|
|
975
|
-
|
|
976
|
-
type:
|
|
977
|
-
thinking:
|
|
989
|
+
z3.object({
|
|
990
|
+
type: z3.literal("thinking_delta"),
|
|
991
|
+
thinking: z3.string()
|
|
978
992
|
}),
|
|
979
|
-
|
|
980
|
-
type:
|
|
981
|
-
signature:
|
|
993
|
+
z3.object({
|
|
994
|
+
type: z3.literal("signature_delta"),
|
|
995
|
+
signature: z3.string()
|
|
982
996
|
})
|
|
983
997
|
])
|
|
984
998
|
}),
|
|
985
|
-
|
|
986
|
-
type:
|
|
987
|
-
index:
|
|
999
|
+
z3.object({
|
|
1000
|
+
type: z3.literal("content_block_stop"),
|
|
1001
|
+
index: z3.number()
|
|
988
1002
|
}),
|
|
989
|
-
|
|
990
|
-
type:
|
|
991
|
-
error:
|
|
992
|
-
type:
|
|
993
|
-
message:
|
|
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
|
-
|
|
997
|
-
type:
|
|
998
|
-
delta:
|
|
999
|
-
usage:
|
|
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
|
-
|
|
1002
|
-
type:
|
|
1015
|
+
z3.object({
|
|
1016
|
+
type: z3.literal("message_stop")
|
|
1003
1017
|
}),
|
|
1004
|
-
|
|
1005
|
-
type:
|
|
1018
|
+
z3.object({
|
|
1019
|
+
type: z3.literal("ping")
|
|
1006
1020
|
})
|
|
1007
1021
|
]);
|
|
1008
|
-
var
|
|
1009
|
-
|
|
1010
|
-
|
|
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
|
|
1021
|
-
var Bash20241022Parameters =
|
|
1022
|
-
command:
|
|
1023
|
-
restart:
|
|
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 =
|
|
1036
|
-
command:
|
|
1037
|
-
restart:
|
|
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 =
|
|
1050
|
-
command:
|
|
1051
|
-
path:
|
|
1052
|
-
file_text:
|
|
1053
|
-
insert_line:
|
|
1054
|
-
new_str:
|
|
1055
|
-
old_str:
|
|
1056
|
-
view_range:
|
|
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 =
|
|
1069
|
-
command:
|
|
1070
|
-
path:
|
|
1071
|
-
file_text:
|
|
1072
|
-
insert_line:
|
|
1073
|
-
new_str:
|
|
1074
|
-
old_str:
|
|
1075
|
-
view_range:
|
|
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 =
|
|
1088
|
-
action:
|
|
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:
|
|
1101
|
-
text:
|
|
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 =
|
|
1118
|
-
action:
|
|
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:
|
|
1137
|
-
duration:
|
|
1138
|
-
scroll_amount:
|
|
1139
|
-
scroll_direction:
|
|
1140
|
-
start_coordinate:
|
|
1141
|
-
text:
|
|
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
|
|
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
|
-
|
|
1192
|
+
supportedUrls: () => ({
|
|
1185
1193
|
"image/*": [/^https?:\/\/.*$/]
|
|
1186
1194
|
})
|
|
1187
1195
|
});
|
|
1188
|
-
const provider = function(modelId
|
|
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
|
|
1202
|
+
return createChatModel(modelId);
|
|
1195
1203
|
};
|
|
1196
1204
|
provider.languageModel = createChatModel;
|
|
1197
1205
|
provider.chat = createChatModel;
|