@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.js
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = __toCommonJS(internal_exports);
|
|
|
28
28
|
// src/anthropic-messages-language-model.ts
|
|
29
29
|
var import_provider3 = require("@ai-sdk/provider");
|
|
30
30
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
31
|
-
var
|
|
31
|
+
var import_zod3 = require("zod");
|
|
32
32
|
|
|
33
33
|
// src/anthropic-error.ts
|
|
34
34
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
@@ -45,6 +45,21 @@ var anthropicFailedResponseHandler = (0, import_provider_utils.createJsonErrorRe
|
|
|
45
45
|
errorToMessage: (data) => data.error.message
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
+
// src/anthropic-messages-options.ts
|
|
49
|
+
var import_zod2 = require("zod");
|
|
50
|
+
var anthropicProviderOptions = import_zod2.z.object({
|
|
51
|
+
/**
|
|
52
|
+
Include reasoning content in requests sent to the model. Defaults to `true`.
|
|
53
|
+
|
|
54
|
+
If you are experiencing issues with the model handling requests involving
|
|
55
|
+
*/
|
|
56
|
+
sendReasoning: import_zod2.z.boolean().optional(),
|
|
57
|
+
thinking: import_zod2.z.object({
|
|
58
|
+
type: import_zod2.z.union([import_zod2.z.literal("enabled"), import_zod2.z.literal("disabled")]),
|
|
59
|
+
budgetTokens: import_zod2.z.number().optional()
|
|
60
|
+
}).optional()
|
|
61
|
+
});
|
|
62
|
+
|
|
48
63
|
// src/anthropic-prepare-tools.ts
|
|
49
64
|
var import_provider = require("@ai-sdk/provider");
|
|
50
65
|
function prepareTools({
|
|
@@ -465,10 +480,9 @@ function mapAnthropicStopReason(finishReason) {
|
|
|
465
480
|
|
|
466
481
|
// src/anthropic-messages-language-model.ts
|
|
467
482
|
var AnthropicMessagesLanguageModel = class {
|
|
468
|
-
constructor(modelId,
|
|
483
|
+
constructor(modelId, config) {
|
|
469
484
|
this.specificationVersion = "v2";
|
|
470
485
|
this.modelId = modelId;
|
|
471
|
-
this.settings = settings;
|
|
472
486
|
this.config = config;
|
|
473
487
|
}
|
|
474
488
|
supportsUrl(url) {
|
|
@@ -477,9 +491,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
477
491
|
get provider() {
|
|
478
492
|
return this.config.provider;
|
|
479
493
|
}
|
|
480
|
-
|
|
494
|
+
get supportedUrls() {
|
|
481
495
|
var _a, _b, _c;
|
|
482
|
-
return (_c = (_b = (_a = this.config).
|
|
496
|
+
return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
|
|
483
497
|
}
|
|
484
498
|
async getArgs({
|
|
485
499
|
prompt,
|
|
@@ -524,15 +538,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
524
538
|
details: "JSON response format is not supported."
|
|
525
539
|
});
|
|
526
540
|
}
|
|
527
|
-
const { prompt: messagesPrompt, betas: messagesBetas } = await convertToAnthropicMessagesPrompt({
|
|
528
|
-
prompt,
|
|
529
|
-
sendReasoning: (_a = this.settings.sendReasoning) != null ? _a : true,
|
|
530
|
-
warnings
|
|
531
|
-
});
|
|
532
541
|
const anthropicOptions = await (0, import_provider_utils3.parseProviderOptions)({
|
|
533
542
|
provider: "anthropic",
|
|
534
543
|
providerOptions,
|
|
535
|
-
schema:
|
|
544
|
+
schema: anthropicProviderOptions
|
|
545
|
+
});
|
|
546
|
+
const { prompt: messagesPrompt, betas: messagesBetas } = await convertToAnthropicMessagesPrompt({
|
|
547
|
+
prompt,
|
|
548
|
+
sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
|
|
549
|
+
warnings
|
|
536
550
|
});
|
|
537
551
|
const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
|
|
538
552
|
const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
|
|
@@ -893,139 +907,133 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
893
907
|
};
|
|
894
908
|
}
|
|
895
909
|
};
|
|
896
|
-
var anthropicMessagesResponseSchema =
|
|
897
|
-
type:
|
|
898
|
-
id:
|
|
899
|
-
model:
|
|
900
|
-
content:
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
type:
|
|
904
|
-
text:
|
|
910
|
+
var anthropicMessagesResponseSchema = import_zod3.z.object({
|
|
911
|
+
type: import_zod3.z.literal("message"),
|
|
912
|
+
id: import_zod3.z.string().nullish(),
|
|
913
|
+
model: import_zod3.z.string().nullish(),
|
|
914
|
+
content: import_zod3.z.array(
|
|
915
|
+
import_zod3.z.discriminatedUnion("type", [
|
|
916
|
+
import_zod3.z.object({
|
|
917
|
+
type: import_zod3.z.literal("text"),
|
|
918
|
+
text: import_zod3.z.string()
|
|
905
919
|
}),
|
|
906
|
-
|
|
907
|
-
type:
|
|
908
|
-
thinking:
|
|
909
|
-
signature:
|
|
920
|
+
import_zod3.z.object({
|
|
921
|
+
type: import_zod3.z.literal("thinking"),
|
|
922
|
+
thinking: import_zod3.z.string(),
|
|
923
|
+
signature: import_zod3.z.string()
|
|
910
924
|
}),
|
|
911
|
-
|
|
912
|
-
type:
|
|
913
|
-
data:
|
|
925
|
+
import_zod3.z.object({
|
|
926
|
+
type: import_zod3.z.literal("redacted_thinking"),
|
|
927
|
+
data: import_zod3.z.string()
|
|
914
928
|
}),
|
|
915
|
-
|
|
916
|
-
type:
|
|
917
|
-
id:
|
|
918
|
-
name:
|
|
919
|
-
input:
|
|
929
|
+
import_zod3.z.object({
|
|
930
|
+
type: import_zod3.z.literal("tool_use"),
|
|
931
|
+
id: import_zod3.z.string(),
|
|
932
|
+
name: import_zod3.z.string(),
|
|
933
|
+
input: import_zod3.z.unknown()
|
|
920
934
|
})
|
|
921
935
|
])
|
|
922
936
|
),
|
|
923
|
-
stop_reason:
|
|
924
|
-
usage:
|
|
925
|
-
input_tokens:
|
|
926
|
-
output_tokens:
|
|
927
|
-
cache_creation_input_tokens:
|
|
928
|
-
cache_read_input_tokens:
|
|
937
|
+
stop_reason: import_zod3.z.string().nullish(),
|
|
938
|
+
usage: import_zod3.z.object({
|
|
939
|
+
input_tokens: import_zod3.z.number(),
|
|
940
|
+
output_tokens: import_zod3.z.number(),
|
|
941
|
+
cache_creation_input_tokens: import_zod3.z.number().nullish(),
|
|
942
|
+
cache_read_input_tokens: import_zod3.z.number().nullish()
|
|
929
943
|
})
|
|
930
944
|
});
|
|
931
|
-
var anthropicMessagesChunkSchema =
|
|
932
|
-
|
|
933
|
-
type:
|
|
934
|
-
message:
|
|
935
|
-
id:
|
|
936
|
-
model:
|
|
937
|
-
usage:
|
|
938
|
-
input_tokens:
|
|
939
|
-
output_tokens:
|
|
940
|
-
cache_creation_input_tokens:
|
|
941
|
-
cache_read_input_tokens:
|
|
945
|
+
var anthropicMessagesChunkSchema = import_zod3.z.discriminatedUnion("type", [
|
|
946
|
+
import_zod3.z.object({
|
|
947
|
+
type: import_zod3.z.literal("message_start"),
|
|
948
|
+
message: import_zod3.z.object({
|
|
949
|
+
id: import_zod3.z.string().nullish(),
|
|
950
|
+
model: import_zod3.z.string().nullish(),
|
|
951
|
+
usage: import_zod3.z.object({
|
|
952
|
+
input_tokens: import_zod3.z.number(),
|
|
953
|
+
output_tokens: import_zod3.z.number(),
|
|
954
|
+
cache_creation_input_tokens: import_zod3.z.number().nullish(),
|
|
955
|
+
cache_read_input_tokens: import_zod3.z.number().nullish()
|
|
942
956
|
})
|
|
943
957
|
})
|
|
944
958
|
}),
|
|
945
|
-
|
|
946
|
-
type:
|
|
947
|
-
index:
|
|
948
|
-
content_block:
|
|
949
|
-
|
|
950
|
-
type:
|
|
951
|
-
text:
|
|
959
|
+
import_zod3.z.object({
|
|
960
|
+
type: import_zod3.z.literal("content_block_start"),
|
|
961
|
+
index: import_zod3.z.number(),
|
|
962
|
+
content_block: import_zod3.z.discriminatedUnion("type", [
|
|
963
|
+
import_zod3.z.object({
|
|
964
|
+
type: import_zod3.z.literal("text"),
|
|
965
|
+
text: import_zod3.z.string()
|
|
952
966
|
}),
|
|
953
|
-
|
|
954
|
-
type:
|
|
955
|
-
thinking:
|
|
967
|
+
import_zod3.z.object({
|
|
968
|
+
type: import_zod3.z.literal("thinking"),
|
|
969
|
+
thinking: import_zod3.z.string()
|
|
956
970
|
}),
|
|
957
|
-
|
|
958
|
-
type:
|
|
959
|
-
id:
|
|
960
|
-
name:
|
|
971
|
+
import_zod3.z.object({
|
|
972
|
+
type: import_zod3.z.literal("tool_use"),
|
|
973
|
+
id: import_zod3.z.string(),
|
|
974
|
+
name: import_zod3.z.string()
|
|
961
975
|
}),
|
|
962
|
-
|
|
963
|
-
type:
|
|
964
|
-
data:
|
|
976
|
+
import_zod3.z.object({
|
|
977
|
+
type: import_zod3.z.literal("redacted_thinking"),
|
|
978
|
+
data: import_zod3.z.string()
|
|
965
979
|
})
|
|
966
980
|
])
|
|
967
981
|
}),
|
|
968
|
-
|
|
969
|
-
type:
|
|
970
|
-
index:
|
|
971
|
-
delta:
|
|
972
|
-
|
|
973
|
-
type:
|
|
974
|
-
partial_json:
|
|
982
|
+
import_zod3.z.object({
|
|
983
|
+
type: import_zod3.z.literal("content_block_delta"),
|
|
984
|
+
index: import_zod3.z.number(),
|
|
985
|
+
delta: import_zod3.z.discriminatedUnion("type", [
|
|
986
|
+
import_zod3.z.object({
|
|
987
|
+
type: import_zod3.z.literal("input_json_delta"),
|
|
988
|
+
partial_json: import_zod3.z.string()
|
|
975
989
|
}),
|
|
976
|
-
|
|
977
|
-
type:
|
|
978
|
-
text:
|
|
990
|
+
import_zod3.z.object({
|
|
991
|
+
type: import_zod3.z.literal("text_delta"),
|
|
992
|
+
text: import_zod3.z.string()
|
|
979
993
|
}),
|
|
980
|
-
|
|
981
|
-
type:
|
|
982
|
-
thinking:
|
|
994
|
+
import_zod3.z.object({
|
|
995
|
+
type: import_zod3.z.literal("thinking_delta"),
|
|
996
|
+
thinking: import_zod3.z.string()
|
|
983
997
|
}),
|
|
984
|
-
|
|
985
|
-
type:
|
|
986
|
-
signature:
|
|
998
|
+
import_zod3.z.object({
|
|
999
|
+
type: import_zod3.z.literal("signature_delta"),
|
|
1000
|
+
signature: import_zod3.z.string()
|
|
987
1001
|
})
|
|
988
1002
|
])
|
|
989
1003
|
}),
|
|
990
|
-
|
|
991
|
-
type:
|
|
992
|
-
index:
|
|
1004
|
+
import_zod3.z.object({
|
|
1005
|
+
type: import_zod3.z.literal("content_block_stop"),
|
|
1006
|
+
index: import_zod3.z.number()
|
|
993
1007
|
}),
|
|
994
|
-
|
|
995
|
-
type:
|
|
996
|
-
error:
|
|
997
|
-
type:
|
|
998
|
-
message:
|
|
1008
|
+
import_zod3.z.object({
|
|
1009
|
+
type: import_zod3.z.literal("error"),
|
|
1010
|
+
error: import_zod3.z.object({
|
|
1011
|
+
type: import_zod3.z.string(),
|
|
1012
|
+
message: import_zod3.z.string()
|
|
999
1013
|
})
|
|
1000
1014
|
}),
|
|
1001
|
-
|
|
1002
|
-
type:
|
|
1003
|
-
delta:
|
|
1004
|
-
usage:
|
|
1015
|
+
import_zod3.z.object({
|
|
1016
|
+
type: import_zod3.z.literal("message_delta"),
|
|
1017
|
+
delta: import_zod3.z.object({ stop_reason: import_zod3.z.string().nullish() }),
|
|
1018
|
+
usage: import_zod3.z.object({ output_tokens: import_zod3.z.number() })
|
|
1005
1019
|
}),
|
|
1006
|
-
|
|
1007
|
-
type:
|
|
1020
|
+
import_zod3.z.object({
|
|
1021
|
+
type: import_zod3.z.literal("message_stop")
|
|
1008
1022
|
}),
|
|
1009
|
-
|
|
1010
|
-
type:
|
|
1023
|
+
import_zod3.z.object({
|
|
1024
|
+
type: import_zod3.z.literal("ping")
|
|
1011
1025
|
})
|
|
1012
1026
|
]);
|
|
1013
|
-
var
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
budgetTokens: import_zod2.z.number().optional()
|
|
1017
|
-
}).optional()
|
|
1018
|
-
});
|
|
1019
|
-
var anthropicReasoningMetadataSchema = import_zod2.z.object({
|
|
1020
|
-
signature: import_zod2.z.string().optional(),
|
|
1021
|
-
redactedData: import_zod2.z.string().optional()
|
|
1027
|
+
var anthropicReasoningMetadataSchema = import_zod3.z.object({
|
|
1028
|
+
signature: import_zod3.z.string().optional(),
|
|
1029
|
+
redactedData: import_zod3.z.string().optional()
|
|
1022
1030
|
});
|
|
1023
1031
|
|
|
1024
1032
|
// src/anthropic-tools.ts
|
|
1025
|
-
var
|
|
1026
|
-
var Bash20241022Parameters =
|
|
1027
|
-
command:
|
|
1028
|
-
restart:
|
|
1033
|
+
var import_zod4 = require("zod");
|
|
1034
|
+
var Bash20241022Parameters = import_zod4.z.object({
|
|
1035
|
+
command: import_zod4.z.string(),
|
|
1036
|
+
restart: import_zod4.z.boolean().optional()
|
|
1029
1037
|
});
|
|
1030
1038
|
function bashTool_20241022(options = {}) {
|
|
1031
1039
|
return {
|
|
@@ -1037,9 +1045,9 @@ function bashTool_20241022(options = {}) {
|
|
|
1037
1045
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1038
1046
|
};
|
|
1039
1047
|
}
|
|
1040
|
-
var Bash20250124Parameters =
|
|
1041
|
-
command:
|
|
1042
|
-
restart:
|
|
1048
|
+
var Bash20250124Parameters = import_zod4.z.object({
|
|
1049
|
+
command: import_zod4.z.string(),
|
|
1050
|
+
restart: import_zod4.z.boolean().optional()
|
|
1043
1051
|
});
|
|
1044
1052
|
function bashTool_20250124(options = {}) {
|
|
1045
1053
|
return {
|
|
@@ -1051,14 +1059,14 @@ function bashTool_20250124(options = {}) {
|
|
|
1051
1059
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1052
1060
|
};
|
|
1053
1061
|
}
|
|
1054
|
-
var TextEditor20241022Parameters =
|
|
1055
|
-
command:
|
|
1056
|
-
path:
|
|
1057
|
-
file_text:
|
|
1058
|
-
insert_line:
|
|
1059
|
-
new_str:
|
|
1060
|
-
old_str:
|
|
1061
|
-
view_range:
|
|
1062
|
+
var TextEditor20241022Parameters = import_zod4.z.object({
|
|
1063
|
+
command: import_zod4.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
1064
|
+
path: import_zod4.z.string(),
|
|
1065
|
+
file_text: import_zod4.z.string().optional(),
|
|
1066
|
+
insert_line: import_zod4.z.number().int().optional(),
|
|
1067
|
+
new_str: import_zod4.z.string().optional(),
|
|
1068
|
+
old_str: import_zod4.z.string().optional(),
|
|
1069
|
+
view_range: import_zod4.z.array(import_zod4.z.number().int()).optional()
|
|
1062
1070
|
});
|
|
1063
1071
|
function textEditorTool_20241022(options = {}) {
|
|
1064
1072
|
return {
|
|
@@ -1070,14 +1078,14 @@ function textEditorTool_20241022(options = {}) {
|
|
|
1070
1078
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1071
1079
|
};
|
|
1072
1080
|
}
|
|
1073
|
-
var TextEditor20250124Parameters =
|
|
1074
|
-
command:
|
|
1075
|
-
path:
|
|
1076
|
-
file_text:
|
|
1077
|
-
insert_line:
|
|
1078
|
-
new_str:
|
|
1079
|
-
old_str:
|
|
1080
|
-
view_range:
|
|
1081
|
+
var TextEditor20250124Parameters = import_zod4.z.object({
|
|
1082
|
+
command: import_zod4.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
1083
|
+
path: import_zod4.z.string(),
|
|
1084
|
+
file_text: import_zod4.z.string().optional(),
|
|
1085
|
+
insert_line: import_zod4.z.number().int().optional(),
|
|
1086
|
+
new_str: import_zod4.z.string().optional(),
|
|
1087
|
+
old_str: import_zod4.z.string().optional(),
|
|
1088
|
+
view_range: import_zod4.z.array(import_zod4.z.number().int()).optional()
|
|
1081
1089
|
});
|
|
1082
1090
|
function textEditorTool_20250124(options = {}) {
|
|
1083
1091
|
return {
|
|
@@ -1089,8 +1097,8 @@ function textEditorTool_20250124(options = {}) {
|
|
|
1089
1097
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1090
1098
|
};
|
|
1091
1099
|
}
|
|
1092
|
-
var Computer20241022Parameters =
|
|
1093
|
-
action:
|
|
1100
|
+
var Computer20241022Parameters = import_zod4.z.object({
|
|
1101
|
+
action: import_zod4.z.enum([
|
|
1094
1102
|
"key",
|
|
1095
1103
|
"type",
|
|
1096
1104
|
"mouse_move",
|
|
@@ -1102,8 +1110,8 @@ var Computer20241022Parameters = import_zod3.z.object({
|
|
|
1102
1110
|
"screenshot",
|
|
1103
1111
|
"cursor_position"
|
|
1104
1112
|
]),
|
|
1105
|
-
coordinate:
|
|
1106
|
-
text:
|
|
1113
|
+
coordinate: import_zod4.z.array(import_zod4.z.number().int()).optional(),
|
|
1114
|
+
text: import_zod4.z.string().optional()
|
|
1107
1115
|
});
|
|
1108
1116
|
function computerTool_20241022(options) {
|
|
1109
1117
|
return {
|
|
@@ -1119,8 +1127,8 @@ function computerTool_20241022(options) {
|
|
|
1119
1127
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1120
1128
|
};
|
|
1121
1129
|
}
|
|
1122
|
-
var Computer20250124Parameters =
|
|
1123
|
-
action:
|
|
1130
|
+
var Computer20250124Parameters = import_zod4.z.object({
|
|
1131
|
+
action: import_zod4.z.enum([
|
|
1124
1132
|
"key",
|
|
1125
1133
|
"hold_key",
|
|
1126
1134
|
"type",
|
|
@@ -1138,12 +1146,12 @@ var Computer20250124Parameters = import_zod3.z.object({
|
|
|
1138
1146
|
"wait",
|
|
1139
1147
|
"screenshot"
|
|
1140
1148
|
]),
|
|
1141
|
-
coordinate:
|
|
1142
|
-
duration:
|
|
1143
|
-
scroll_amount:
|
|
1144
|
-
scroll_direction:
|
|
1145
|
-
start_coordinate:
|
|
1146
|
-
text:
|
|
1149
|
+
coordinate: import_zod4.z.tuple([import_zod4.z.number().int(), import_zod4.z.number().int()]).optional(),
|
|
1150
|
+
duration: import_zod4.z.number().optional(),
|
|
1151
|
+
scroll_amount: import_zod4.z.number().optional(),
|
|
1152
|
+
scroll_direction: import_zod4.z.enum(["up", "down", "left", "right"]).optional(),
|
|
1153
|
+
start_coordinate: import_zod4.z.tuple([import_zod4.z.number().int(), import_zod4.z.number().int()]).optional(),
|
|
1154
|
+
text: import_zod4.z.string().optional()
|
|
1147
1155
|
});
|
|
1148
1156
|
function computerTool_20250124(options) {
|
|
1149
1157
|
return {
|