@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/internal/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
postJsonToApi,
|
|
11
11
|
resolve
|
|
12
12
|
} from "@ai-sdk/provider-utils";
|
|
13
|
-
import { z as
|
|
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,
|
|
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
|
-
|
|
480
|
+
get supportedUrls() {
|
|
467
481
|
var _a, _b, _c;
|
|
468
|
-
return (_c = (_b = (_a = this.config).
|
|
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:
|
|
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 =
|
|
883
|
-
type:
|
|
884
|
-
id:
|
|
885
|
-
model:
|
|
886
|
-
content:
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
type:
|
|
890
|
-
text:
|
|
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
|
-
|
|
893
|
-
type:
|
|
894
|
-
thinking:
|
|
895
|
-
signature:
|
|
906
|
+
z3.object({
|
|
907
|
+
type: z3.literal("thinking"),
|
|
908
|
+
thinking: z3.string(),
|
|
909
|
+
signature: z3.string()
|
|
896
910
|
}),
|
|
897
|
-
|
|
898
|
-
type:
|
|
899
|
-
data:
|
|
911
|
+
z3.object({
|
|
912
|
+
type: z3.literal("redacted_thinking"),
|
|
913
|
+
data: z3.string()
|
|
900
914
|
}),
|
|
901
|
-
|
|
902
|
-
type:
|
|
903
|
-
id:
|
|
904
|
-
name:
|
|
905
|
-
input:
|
|
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:
|
|
910
|
-
usage:
|
|
911
|
-
input_tokens:
|
|
912
|
-
output_tokens:
|
|
913
|
-
cache_creation_input_tokens:
|
|
914
|
-
cache_read_input_tokens:
|
|
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 =
|
|
918
|
-
|
|
919
|
-
type:
|
|
920
|
-
message:
|
|
921
|
-
id:
|
|
922
|
-
model:
|
|
923
|
-
usage:
|
|
924
|
-
input_tokens:
|
|
925
|
-
output_tokens:
|
|
926
|
-
cache_creation_input_tokens:
|
|
927
|
-
cache_read_input_tokens:
|
|
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
|
-
|
|
932
|
-
type:
|
|
933
|
-
index:
|
|
934
|
-
content_block:
|
|
935
|
-
|
|
936
|
-
type:
|
|
937
|
-
text:
|
|
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
|
-
|
|
940
|
-
type:
|
|
941
|
-
thinking:
|
|
953
|
+
z3.object({
|
|
954
|
+
type: z3.literal("thinking"),
|
|
955
|
+
thinking: z3.string()
|
|
942
956
|
}),
|
|
943
|
-
|
|
944
|
-
type:
|
|
945
|
-
id:
|
|
946
|
-
name:
|
|
957
|
+
z3.object({
|
|
958
|
+
type: z3.literal("tool_use"),
|
|
959
|
+
id: z3.string(),
|
|
960
|
+
name: z3.string()
|
|
947
961
|
}),
|
|
948
|
-
|
|
949
|
-
type:
|
|
950
|
-
data:
|
|
962
|
+
z3.object({
|
|
963
|
+
type: z3.literal("redacted_thinking"),
|
|
964
|
+
data: z3.string()
|
|
951
965
|
})
|
|
952
966
|
])
|
|
953
967
|
}),
|
|
954
|
-
|
|
955
|
-
type:
|
|
956
|
-
index:
|
|
957
|
-
delta:
|
|
958
|
-
|
|
959
|
-
type:
|
|
960
|
-
partial_json:
|
|
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
|
-
|
|
963
|
-
type:
|
|
964
|
-
text:
|
|
976
|
+
z3.object({
|
|
977
|
+
type: z3.literal("text_delta"),
|
|
978
|
+
text: z3.string()
|
|
965
979
|
}),
|
|
966
|
-
|
|
967
|
-
type:
|
|
968
|
-
thinking:
|
|
980
|
+
z3.object({
|
|
981
|
+
type: z3.literal("thinking_delta"),
|
|
982
|
+
thinking: z3.string()
|
|
969
983
|
}),
|
|
970
|
-
|
|
971
|
-
type:
|
|
972
|
-
signature:
|
|
984
|
+
z3.object({
|
|
985
|
+
type: z3.literal("signature_delta"),
|
|
986
|
+
signature: z3.string()
|
|
973
987
|
})
|
|
974
988
|
])
|
|
975
989
|
}),
|
|
976
|
-
|
|
977
|
-
type:
|
|
978
|
-
index:
|
|
990
|
+
z3.object({
|
|
991
|
+
type: z3.literal("content_block_stop"),
|
|
992
|
+
index: z3.number()
|
|
979
993
|
}),
|
|
980
|
-
|
|
981
|
-
type:
|
|
982
|
-
error:
|
|
983
|
-
type:
|
|
984
|
-
message:
|
|
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
|
-
|
|
988
|
-
type:
|
|
989
|
-
delta:
|
|
990
|
-
usage:
|
|
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
|
-
|
|
993
|
-
type:
|
|
1006
|
+
z3.object({
|
|
1007
|
+
type: z3.literal("message_stop")
|
|
994
1008
|
}),
|
|
995
|
-
|
|
996
|
-
type:
|
|
1009
|
+
z3.object({
|
|
1010
|
+
type: z3.literal("ping")
|
|
997
1011
|
})
|
|
998
1012
|
]);
|
|
999
|
-
var
|
|
1000
|
-
|
|
1001
|
-
|
|
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
|
|
1012
|
-
var Bash20241022Parameters =
|
|
1013
|
-
command:
|
|
1014
|
-
restart:
|
|
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 =
|
|
1027
|
-
command:
|
|
1028
|
-
restart:
|
|
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 =
|
|
1041
|
-
command:
|
|
1042
|
-
path:
|
|
1043
|
-
file_text:
|
|
1044
|
-
insert_line:
|
|
1045
|
-
new_str:
|
|
1046
|
-
old_str:
|
|
1047
|
-
view_range:
|
|
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 =
|
|
1060
|
-
command:
|
|
1061
|
-
path:
|
|
1062
|
-
file_text:
|
|
1063
|
-
insert_line:
|
|
1064
|
-
new_str:
|
|
1065
|
-
old_str:
|
|
1066
|
-
view_range:
|
|
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 =
|
|
1079
|
-
action:
|
|
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:
|
|
1092
|
-
text:
|
|
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 =
|
|
1109
|
-
action:
|
|
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:
|
|
1128
|
-
duration:
|
|
1129
|
-
scroll_amount:
|
|
1130
|
-
scroll_direction:
|
|
1131
|
-
start_coordinate:
|
|
1132
|
-
text:
|
|
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 {
|