@ai-sdk/anthropic 2.0.0-alpha.1 → 2.0.0-alpha.10
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 +69 -0
- package/dist/index.d.mts +90 -1
- package/dist/index.d.ts +90 -1
- package/dist/index.js +307 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +310 -57
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +3 -1
- package/dist/internal/index.d.ts +3 -1
- package/dist/internal/index.js +294 -48
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +296 -48
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -51,6 +51,13 @@ var anthropicFailedResponseHandler = (0, import_provider_utils.createJsonErrorRe
|
|
|
51
51
|
|
|
52
52
|
// src/anthropic-messages-options.ts
|
|
53
53
|
var import_zod2 = require("zod");
|
|
54
|
+
var webSearchLocationSchema = import_zod2.z.object({
|
|
55
|
+
type: import_zod2.z.literal("approximate"),
|
|
56
|
+
city: import_zod2.z.string().optional(),
|
|
57
|
+
region: import_zod2.z.string().optional(),
|
|
58
|
+
country: import_zod2.z.string(),
|
|
59
|
+
timezone: import_zod2.z.string().optional()
|
|
60
|
+
});
|
|
54
61
|
var anthropicProviderOptions = import_zod2.z.object({
|
|
55
62
|
/**
|
|
56
63
|
Include reasoning content in requests sent to the model. Defaults to `true`.
|
|
@@ -61,11 +68,39 @@ var anthropicProviderOptions = import_zod2.z.object({
|
|
|
61
68
|
thinking: import_zod2.z.object({
|
|
62
69
|
type: import_zod2.z.union([import_zod2.z.literal("enabled"), import_zod2.z.literal("disabled")]),
|
|
63
70
|
budgetTokens: import_zod2.z.number().optional()
|
|
71
|
+
}).optional(),
|
|
72
|
+
/**
|
|
73
|
+
* Web search tool configuration for Claude models that support it.
|
|
74
|
+
* When provided, automatically adds the web search tool to the request.
|
|
75
|
+
*/
|
|
76
|
+
webSearch: import_zod2.z.object({
|
|
77
|
+
/**
|
|
78
|
+
* Limit the number of searches per request (optional)
|
|
79
|
+
* Defaults to 5 if not specified
|
|
80
|
+
*/
|
|
81
|
+
maxUses: import_zod2.z.number().min(1).max(20).optional(),
|
|
82
|
+
/**
|
|
83
|
+
* Only include results from these domains (optional)
|
|
84
|
+
* Cannot be used with blockedDomains
|
|
85
|
+
*/
|
|
86
|
+
allowedDomains: import_zod2.z.array(import_zod2.z.string()).optional(),
|
|
87
|
+
/**
|
|
88
|
+
* Never include results from these domains (optional)
|
|
89
|
+
* Cannot be used with allowedDomains
|
|
90
|
+
*/
|
|
91
|
+
blockedDomains: import_zod2.z.array(import_zod2.z.string()).optional(),
|
|
92
|
+
/**
|
|
93
|
+
* Localize search results based on user location (optional)
|
|
94
|
+
*/
|
|
95
|
+
userLocation: webSearchLocationSchema.optional()
|
|
64
96
|
}).optional()
|
|
65
97
|
});
|
|
66
98
|
|
|
67
99
|
// src/anthropic-prepare-tools.ts
|
|
68
100
|
var import_provider = require("@ai-sdk/provider");
|
|
101
|
+
function isWebSearchTool(tool) {
|
|
102
|
+
return typeof tool === "object" && tool !== null && "type" in tool && tool.type === "web_search_20250305";
|
|
103
|
+
}
|
|
69
104
|
function prepareTools({
|
|
70
105
|
tools,
|
|
71
106
|
toolChoice
|
|
@@ -78,6 +113,10 @@ function prepareTools({
|
|
|
78
113
|
}
|
|
79
114
|
const anthropicTools2 = [];
|
|
80
115
|
for (const tool of tools) {
|
|
116
|
+
if (isWebSearchTool(tool)) {
|
|
117
|
+
anthropicTools2.push(tool);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
81
120
|
switch (tool.type) {
|
|
82
121
|
case "function":
|
|
83
122
|
anthropicTools2.push({
|
|
@@ -468,13 +507,16 @@ function groupIntoBlocks(prompt) {
|
|
|
468
507
|
}
|
|
469
508
|
|
|
470
509
|
// src/map-anthropic-stop-reason.ts
|
|
471
|
-
function mapAnthropicStopReason(
|
|
510
|
+
function mapAnthropicStopReason({
|
|
511
|
+
finishReason,
|
|
512
|
+
isJsonResponseFromTool
|
|
513
|
+
}) {
|
|
472
514
|
switch (finishReason) {
|
|
473
515
|
case "end_turn":
|
|
474
516
|
case "stop_sequence":
|
|
475
517
|
return "stop";
|
|
476
518
|
case "tool_use":
|
|
477
|
-
return "tool-calls";
|
|
519
|
+
return isJsonResponseFromTool ? "stop" : "tool-calls";
|
|
478
520
|
case "max_tokens":
|
|
479
521
|
return "length";
|
|
480
522
|
default:
|
|
@@ -486,8 +528,10 @@ function mapAnthropicStopReason(finishReason) {
|
|
|
486
528
|
var AnthropicMessagesLanguageModel = class {
|
|
487
529
|
constructor(modelId, config) {
|
|
488
530
|
this.specificationVersion = "v2";
|
|
531
|
+
var _a;
|
|
489
532
|
this.modelId = modelId;
|
|
490
533
|
this.config = config;
|
|
534
|
+
this.generateId = (_a = config.generateId) != null ? _a : import_provider_utils3.generateId;
|
|
491
535
|
}
|
|
492
536
|
supportsUrl(url) {
|
|
493
537
|
return url.protocol === "https:";
|
|
@@ -535,13 +579,27 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
535
579
|
setting: "seed"
|
|
536
580
|
});
|
|
537
581
|
}
|
|
538
|
-
if (responseFormat
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
582
|
+
if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
|
|
583
|
+
if (responseFormat.schema == null) {
|
|
584
|
+
warnings.push({
|
|
585
|
+
type: "unsupported-setting",
|
|
586
|
+
setting: "responseFormat",
|
|
587
|
+
details: "JSON response format requires a schema. The response format is ignored."
|
|
588
|
+
});
|
|
589
|
+
} else if (tools != null) {
|
|
590
|
+
warnings.push({
|
|
591
|
+
type: "unsupported-setting",
|
|
592
|
+
setting: "tools",
|
|
593
|
+
details: "JSON response format does not support tools. The provided tools are ignored."
|
|
594
|
+
});
|
|
595
|
+
}
|
|
544
596
|
}
|
|
597
|
+
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
|
|
598
|
+
type: "function",
|
|
599
|
+
name: "json",
|
|
600
|
+
description: "Respond with a JSON object.",
|
|
601
|
+
parameters: responseFormat.schema
|
|
602
|
+
} : void 0;
|
|
545
603
|
const anthropicOptions = await (0, import_provider_utils3.parseProviderOptions)({
|
|
546
604
|
provider: "anthropic",
|
|
547
605
|
providerOptions,
|
|
@@ -603,12 +661,38 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
603
661
|
}
|
|
604
662
|
baseArgs.max_tokens = maxOutputTokens + thinkingBudget;
|
|
605
663
|
}
|
|
664
|
+
let modifiedTools = tools;
|
|
665
|
+
let modifiedToolChoice = toolChoice;
|
|
666
|
+
if (anthropicOptions == null ? void 0 : anthropicOptions.webSearch) {
|
|
667
|
+
const webSearchTool = {
|
|
668
|
+
type: "web_search_20250305",
|
|
669
|
+
name: "web_search",
|
|
670
|
+
max_uses: anthropicOptions.webSearch.maxUses,
|
|
671
|
+
allowed_domains: anthropicOptions.webSearch.allowedDomains,
|
|
672
|
+
blocked_domains: anthropicOptions.webSearch.blockedDomains,
|
|
673
|
+
...anthropicOptions.webSearch.userLocation && {
|
|
674
|
+
user_location: {
|
|
675
|
+
type: anthropicOptions.webSearch.userLocation.type,
|
|
676
|
+
country: anthropicOptions.webSearch.userLocation.country,
|
|
677
|
+
city: anthropicOptions.webSearch.userLocation.city,
|
|
678
|
+
region: anthropicOptions.webSearch.userLocation.region,
|
|
679
|
+
timezone: anthropicOptions.webSearch.userLocation.timezone
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
modifiedTools = tools ? [...tools, webSearchTool] : [webSearchTool];
|
|
684
|
+
}
|
|
606
685
|
const {
|
|
607
686
|
tools: anthropicTools2,
|
|
608
687
|
toolChoice: anthropicToolChoice,
|
|
609
688
|
toolWarnings,
|
|
610
689
|
betas: toolsBetas
|
|
611
|
-
} = prepareTools(
|
|
690
|
+
} = prepareTools(
|
|
691
|
+
jsonResponseTool != null ? {
|
|
692
|
+
tools: [jsonResponseTool],
|
|
693
|
+
toolChoice: { type: "tool", toolName: jsonResponseTool.name }
|
|
694
|
+
} : { tools: modifiedTools, toolChoice: modifiedToolChoice }
|
|
695
|
+
);
|
|
612
696
|
return {
|
|
613
697
|
args: {
|
|
614
698
|
...baseArgs,
|
|
@@ -616,7 +700,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
616
700
|
tool_choice: anthropicToolChoice
|
|
617
701
|
},
|
|
618
702
|
warnings: [...warnings, ...toolWarnings],
|
|
619
|
-
betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas])
|
|
703
|
+
betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas]),
|
|
704
|
+
jsonResponseTool
|
|
620
705
|
};
|
|
621
706
|
}
|
|
622
707
|
async getHeaders({
|
|
@@ -638,8 +723,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
638
723
|
return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args)) != null ? _c : args;
|
|
639
724
|
}
|
|
640
725
|
async doGenerate(options) {
|
|
641
|
-
var _a, _b, _c, _d;
|
|
642
|
-
const { args, warnings, betas } = await this.getArgs(options);
|
|
726
|
+
var _a, _b, _c, _d, _e;
|
|
727
|
+
const { args, warnings, betas, jsonResponseTool } = await this.getArgs(options);
|
|
643
728
|
const {
|
|
644
729
|
responseHeaders,
|
|
645
730
|
value: response,
|
|
@@ -659,7 +744,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
659
744
|
for (const part of response.content) {
|
|
660
745
|
switch (part.type) {
|
|
661
746
|
case "text": {
|
|
662
|
-
|
|
747
|
+
if (jsonResponseTool == null) {
|
|
748
|
+
content.push({ type: "text", text: part.text });
|
|
749
|
+
}
|
|
663
750
|
break;
|
|
664
751
|
}
|
|
665
752
|
case "thinking": {
|
|
@@ -687,43 +774,84 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
687
774
|
break;
|
|
688
775
|
}
|
|
689
776
|
case "tool_use": {
|
|
690
|
-
content.push(
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
777
|
+
content.push(
|
|
778
|
+
// when a json response tool is used, the tool call becomes the text:
|
|
779
|
+
jsonResponseTool != null ? {
|
|
780
|
+
type: "text",
|
|
781
|
+
text: JSON.stringify(part.input)
|
|
782
|
+
} : {
|
|
783
|
+
type: "tool-call",
|
|
784
|
+
toolCallType: "function",
|
|
785
|
+
toolCallId: part.id,
|
|
786
|
+
toolName: part.name,
|
|
787
|
+
args: JSON.stringify(part.input)
|
|
788
|
+
}
|
|
789
|
+
);
|
|
790
|
+
break;
|
|
791
|
+
}
|
|
792
|
+
case "server_tool_use": {
|
|
793
|
+
continue;
|
|
794
|
+
}
|
|
795
|
+
case "web_search_tool_result": {
|
|
796
|
+
if (Array.isArray(part.content)) {
|
|
797
|
+
for (const result of part.content) {
|
|
798
|
+
if (result.type === "web_search_result") {
|
|
799
|
+
content.push({
|
|
800
|
+
type: "source",
|
|
801
|
+
sourceType: "url",
|
|
802
|
+
id: this.generateId(),
|
|
803
|
+
url: result.url,
|
|
804
|
+
title: result.title,
|
|
805
|
+
providerMetadata: {
|
|
806
|
+
anthropic: {
|
|
807
|
+
encryptedContent: result.encrypted_content,
|
|
808
|
+
pageAge: (_a = result.page_age) != null ? _a : null
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
} else if (part.content.type === "web_search_tool_result_error") {
|
|
815
|
+
throw new import_provider3.APICallError({
|
|
816
|
+
message: `Web search failed: ${part.content.error_code}`,
|
|
817
|
+
url: "web_search_api",
|
|
818
|
+
requestBodyValues: { tool_use_id: part.tool_use_id },
|
|
819
|
+
data: { error_code: part.content.error_code }
|
|
820
|
+
});
|
|
821
|
+
}
|
|
697
822
|
break;
|
|
698
823
|
}
|
|
699
824
|
}
|
|
700
825
|
}
|
|
701
826
|
return {
|
|
702
827
|
content,
|
|
703
|
-
finishReason: mapAnthropicStopReason(
|
|
828
|
+
finishReason: mapAnthropicStopReason({
|
|
829
|
+
finishReason: response.stop_reason,
|
|
830
|
+
isJsonResponseFromTool: jsonResponseTool != null
|
|
831
|
+
}),
|
|
704
832
|
usage: {
|
|
705
833
|
inputTokens: response.usage.input_tokens,
|
|
706
834
|
outputTokens: response.usage.output_tokens,
|
|
707
835
|
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
708
|
-
cachedInputTokens: (
|
|
836
|
+
cachedInputTokens: (_b = response.usage.cache_read_input_tokens) != null ? _b : void 0
|
|
709
837
|
},
|
|
710
838
|
request: { body: args },
|
|
711
839
|
response: {
|
|
712
|
-
id: (
|
|
713
|
-
modelId: (
|
|
840
|
+
id: (_c = response.id) != null ? _c : void 0,
|
|
841
|
+
modelId: (_d = response.model) != null ? _d : void 0,
|
|
714
842
|
headers: responseHeaders,
|
|
715
843
|
body: rawResponse
|
|
716
844
|
},
|
|
717
845
|
warnings,
|
|
718
846
|
providerMetadata: {
|
|
719
847
|
anthropic: {
|
|
720
|
-
cacheCreationInputTokens: (
|
|
848
|
+
cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null
|
|
721
849
|
}
|
|
722
850
|
}
|
|
723
851
|
};
|
|
724
852
|
}
|
|
725
853
|
async doStream(options) {
|
|
726
|
-
const { args, warnings, betas } = await this.getArgs(options);
|
|
854
|
+
const { args, warnings, betas, jsonResponseTool } = await this.getArgs(options);
|
|
727
855
|
const body = { ...args, stream: true };
|
|
728
856
|
const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
|
|
729
857
|
url: this.buildRequestUrl(true),
|
|
@@ -745,6 +873,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
745
873
|
const toolCallContentBlocks = {};
|
|
746
874
|
let providerMetadata = void 0;
|
|
747
875
|
let blockType = void 0;
|
|
876
|
+
const config = this.config;
|
|
877
|
+
const generateId3 = this.generateId;
|
|
748
878
|
return {
|
|
749
879
|
stream: response.pipeThrough(
|
|
750
880
|
new TransformStream({
|
|
@@ -752,7 +882,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
752
882
|
controller.enqueue({ type: "stream-start", warnings });
|
|
753
883
|
},
|
|
754
884
|
transform(chunk, controller) {
|
|
755
|
-
var _a, _b, _c, _d, _e, _f;
|
|
885
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
756
886
|
if (!chunk.success) {
|
|
757
887
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
758
888
|
return;
|
|
@@ -791,6 +921,40 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
791
921
|
};
|
|
792
922
|
return;
|
|
793
923
|
}
|
|
924
|
+
case "server_tool_use": {
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
case "web_search_tool_result": {
|
|
928
|
+
if (Array.isArray(value.content_block.content)) {
|
|
929
|
+
for (const result of value.content_block.content) {
|
|
930
|
+
if (result.type === "web_search_result") {
|
|
931
|
+
controller.enqueue({
|
|
932
|
+
type: "source",
|
|
933
|
+
sourceType: "url",
|
|
934
|
+
id: generateId3(),
|
|
935
|
+
url: result.url,
|
|
936
|
+
title: result.title,
|
|
937
|
+
providerMetadata: {
|
|
938
|
+
anthropic: {
|
|
939
|
+
encryptedContent: result.encrypted_content,
|
|
940
|
+
pageAge: (_a = result.page_age) != null ? _a : null
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
} else if (value.content_block.content.type === "web_search_tool_result_error") {
|
|
947
|
+
controller.enqueue({
|
|
948
|
+
type: "error",
|
|
949
|
+
error: {
|
|
950
|
+
type: "web-search-error",
|
|
951
|
+
message: `Web search failed: ${value.content_block.content.error_code}`,
|
|
952
|
+
code: value.content_block.content.error_code
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
794
958
|
default: {
|
|
795
959
|
const _exhaustiveCheck = contentBlockType;
|
|
796
960
|
throw new Error(
|
|
@@ -802,13 +966,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
802
966
|
case "content_block_stop": {
|
|
803
967
|
if (toolCallContentBlocks[value.index] != null) {
|
|
804
968
|
const contentBlock = toolCallContentBlocks[value.index];
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
969
|
+
if (jsonResponseTool == null) {
|
|
970
|
+
controller.enqueue({
|
|
971
|
+
type: "tool-call",
|
|
972
|
+
toolCallType: "function",
|
|
973
|
+
toolCallId: contentBlock.toolCallId,
|
|
974
|
+
toolName: contentBlock.toolName,
|
|
975
|
+
args: contentBlock.jsonText
|
|
976
|
+
});
|
|
977
|
+
}
|
|
812
978
|
delete toolCallContentBlocks[value.index];
|
|
813
979
|
}
|
|
814
980
|
blockType = void 0;
|
|
@@ -818,6 +984,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
818
984
|
const deltaType = value.delta.type;
|
|
819
985
|
switch (deltaType) {
|
|
820
986
|
case "text_delta": {
|
|
987
|
+
if (jsonResponseTool != null) {
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
821
990
|
controller.enqueue({
|
|
822
991
|
type: "text",
|
|
823
992
|
text: value.delta.text
|
|
@@ -848,16 +1017,27 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
848
1017
|
}
|
|
849
1018
|
case "input_json_delta": {
|
|
850
1019
|
const contentBlock = toolCallContentBlocks[value.index];
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
1020
|
+
if (!contentBlock) {
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
controller.enqueue(
|
|
1024
|
+
jsonResponseTool != null ? {
|
|
1025
|
+
type: "text",
|
|
1026
|
+
text: value.delta.partial_json
|
|
1027
|
+
} : {
|
|
1028
|
+
type: "tool-call-delta",
|
|
1029
|
+
toolCallType: "function",
|
|
1030
|
+
toolCallId: contentBlock.toolCallId,
|
|
1031
|
+
toolName: contentBlock.toolName,
|
|
1032
|
+
argsTextDelta: value.delta.partial_json
|
|
1033
|
+
}
|
|
1034
|
+
);
|
|
858
1035
|
contentBlock.jsonText += value.delta.partial_json;
|
|
859
1036
|
return;
|
|
860
1037
|
}
|
|
1038
|
+
case "citations_delta": {
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
861
1041
|
default: {
|
|
862
1042
|
const _exhaustiveCheck = deltaType;
|
|
863
1043
|
throw new Error(
|
|
@@ -868,23 +1048,26 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
868
1048
|
}
|
|
869
1049
|
case "message_start": {
|
|
870
1050
|
usage.inputTokens = value.message.usage.input_tokens;
|
|
871
|
-
usage.cachedInputTokens = (
|
|
1051
|
+
usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
|
|
872
1052
|
providerMetadata = {
|
|
873
1053
|
anthropic: {
|
|
874
|
-
cacheCreationInputTokens: (
|
|
1054
|
+
cacheCreationInputTokens: (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null
|
|
875
1055
|
}
|
|
876
1056
|
};
|
|
877
1057
|
controller.enqueue({
|
|
878
1058
|
type: "response-metadata",
|
|
879
|
-
id: (
|
|
880
|
-
modelId: (
|
|
1059
|
+
id: (_d = value.message.id) != null ? _d : void 0,
|
|
1060
|
+
modelId: (_e = value.message.model) != null ? _e : void 0
|
|
881
1061
|
});
|
|
882
1062
|
return;
|
|
883
1063
|
}
|
|
884
1064
|
case "message_delta": {
|
|
885
1065
|
usage.outputTokens = value.usage.output_tokens;
|
|
886
|
-
usage.totalTokens = ((
|
|
887
|
-
finishReason = mapAnthropicStopReason(
|
|
1066
|
+
usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
|
|
1067
|
+
finishReason = mapAnthropicStopReason({
|
|
1068
|
+
finishReason: value.delta.stop_reason,
|
|
1069
|
+
isJsonResponseFromTool: jsonResponseTool != null
|
|
1070
|
+
});
|
|
888
1071
|
return;
|
|
889
1072
|
}
|
|
890
1073
|
case "message_stop": {
|
|
@@ -937,6 +1120,31 @@ var anthropicMessagesResponseSchema = import_zod3.z.object({
|
|
|
937
1120
|
id: import_zod3.z.string(),
|
|
938
1121
|
name: import_zod3.z.string(),
|
|
939
1122
|
input: import_zod3.z.unknown()
|
|
1123
|
+
}),
|
|
1124
|
+
import_zod3.z.object({
|
|
1125
|
+
type: import_zod3.z.literal("server_tool_use"),
|
|
1126
|
+
id: import_zod3.z.string(),
|
|
1127
|
+
name: import_zod3.z.string(),
|
|
1128
|
+
input: import_zod3.z.record(import_zod3.z.unknown()).nullish()
|
|
1129
|
+
}),
|
|
1130
|
+
import_zod3.z.object({
|
|
1131
|
+
type: import_zod3.z.literal("web_search_tool_result"),
|
|
1132
|
+
tool_use_id: import_zod3.z.string(),
|
|
1133
|
+
content: import_zod3.z.union([
|
|
1134
|
+
import_zod3.z.array(
|
|
1135
|
+
import_zod3.z.object({
|
|
1136
|
+
type: import_zod3.z.literal("web_search_result"),
|
|
1137
|
+
url: import_zod3.z.string(),
|
|
1138
|
+
title: import_zod3.z.string(),
|
|
1139
|
+
encrypted_content: import_zod3.z.string(),
|
|
1140
|
+
page_age: import_zod3.z.string().nullish()
|
|
1141
|
+
})
|
|
1142
|
+
),
|
|
1143
|
+
import_zod3.z.object({
|
|
1144
|
+
type: import_zod3.z.literal("web_search_tool_result_error"),
|
|
1145
|
+
error_code: import_zod3.z.string()
|
|
1146
|
+
})
|
|
1147
|
+
])
|
|
940
1148
|
})
|
|
941
1149
|
])
|
|
942
1150
|
),
|
|
@@ -945,7 +1153,10 @@ var anthropicMessagesResponseSchema = import_zod3.z.object({
|
|
|
945
1153
|
input_tokens: import_zod3.z.number(),
|
|
946
1154
|
output_tokens: import_zod3.z.number(),
|
|
947
1155
|
cache_creation_input_tokens: import_zod3.z.number().nullish(),
|
|
948
|
-
cache_read_input_tokens: import_zod3.z.number().nullish()
|
|
1156
|
+
cache_read_input_tokens: import_zod3.z.number().nullish(),
|
|
1157
|
+
server_tool_use: import_zod3.z.object({
|
|
1158
|
+
web_search_requests: import_zod3.z.number()
|
|
1159
|
+
}).nullish()
|
|
949
1160
|
})
|
|
950
1161
|
});
|
|
951
1162
|
var anthropicMessagesChunkSchema = import_zod3.z.discriminatedUnion("type", [
|
|
@@ -982,6 +1193,31 @@ var anthropicMessagesChunkSchema = import_zod3.z.discriminatedUnion("type", [
|
|
|
982
1193
|
import_zod3.z.object({
|
|
983
1194
|
type: import_zod3.z.literal("redacted_thinking"),
|
|
984
1195
|
data: import_zod3.z.string()
|
|
1196
|
+
}),
|
|
1197
|
+
import_zod3.z.object({
|
|
1198
|
+
type: import_zod3.z.literal("server_tool_use"),
|
|
1199
|
+
id: import_zod3.z.string(),
|
|
1200
|
+
name: import_zod3.z.string(),
|
|
1201
|
+
input: import_zod3.z.record(import_zod3.z.unknown()).nullish()
|
|
1202
|
+
}),
|
|
1203
|
+
import_zod3.z.object({
|
|
1204
|
+
type: import_zod3.z.literal("web_search_tool_result"),
|
|
1205
|
+
tool_use_id: import_zod3.z.string(),
|
|
1206
|
+
content: import_zod3.z.union([
|
|
1207
|
+
import_zod3.z.array(
|
|
1208
|
+
import_zod3.z.object({
|
|
1209
|
+
type: import_zod3.z.literal("web_search_result"),
|
|
1210
|
+
url: import_zod3.z.string(),
|
|
1211
|
+
title: import_zod3.z.string(),
|
|
1212
|
+
encrypted_content: import_zod3.z.string(),
|
|
1213
|
+
page_age: import_zod3.z.string().nullish()
|
|
1214
|
+
})
|
|
1215
|
+
),
|
|
1216
|
+
import_zod3.z.object({
|
|
1217
|
+
type: import_zod3.z.literal("web_search_tool_result_error"),
|
|
1218
|
+
error_code: import_zod3.z.string()
|
|
1219
|
+
})
|
|
1220
|
+
])
|
|
985
1221
|
})
|
|
986
1222
|
])
|
|
987
1223
|
}),
|
|
@@ -1004,6 +1240,16 @@ var anthropicMessagesChunkSchema = import_zod3.z.discriminatedUnion("type", [
|
|
|
1004
1240
|
import_zod3.z.object({
|
|
1005
1241
|
type: import_zod3.z.literal("signature_delta"),
|
|
1006
1242
|
signature: import_zod3.z.string()
|
|
1243
|
+
}),
|
|
1244
|
+
import_zod3.z.object({
|
|
1245
|
+
type: import_zod3.z.literal("citations_delta"),
|
|
1246
|
+
citation: import_zod3.z.object({
|
|
1247
|
+
type: import_zod3.z.literal("web_search_result_location"),
|
|
1248
|
+
cited_text: import_zod3.z.string(),
|
|
1249
|
+
url: import_zod3.z.string(),
|
|
1250
|
+
title: import_zod3.z.string(),
|
|
1251
|
+
encrypted_index: import_zod3.z.string()
|
|
1252
|
+
})
|
|
1007
1253
|
})
|
|
1008
1254
|
])
|
|
1009
1255
|
}),
|
|
@@ -1195,15 +1441,19 @@ function createAnthropic(options = {}) {
|
|
|
1195
1441
|
}),
|
|
1196
1442
|
...options.headers
|
|
1197
1443
|
});
|
|
1198
|
-
const createChatModel = (modelId) =>
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1444
|
+
const createChatModel = (modelId) => {
|
|
1445
|
+
var _a2;
|
|
1446
|
+
return new AnthropicMessagesLanguageModel(modelId, {
|
|
1447
|
+
provider: "anthropic.messages",
|
|
1448
|
+
baseURL,
|
|
1449
|
+
headers: getHeaders,
|
|
1450
|
+
fetch: options.fetch,
|
|
1451
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils4.generateId,
|
|
1452
|
+
supportedUrls: () => ({
|
|
1453
|
+
"image/*": [/^https?:\/\/.*$/]
|
|
1454
|
+
})
|
|
1455
|
+
});
|
|
1456
|
+
};
|
|
1207
1457
|
const provider = function(modelId) {
|
|
1208
1458
|
if (new.target) {
|
|
1209
1459
|
throw new Error(
|