@ai-sdk/anthropic 2.0.0-alpha.13 → 2.0.0-alpha.15
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 +21 -0
- package/dist/index.d.mts +44 -100
- package/dist/index.d.ts +44 -100
- package/dist/index.js +59 -74
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -74
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +44 -6
- package/dist/internal/index.d.ts +44 -6
- package/dist/internal/index.js +59 -74
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +59 -74
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -51,13 +51,6 @@ 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
|
-
});
|
|
61
54
|
var anthropicFilePartProviderOptions = import_zod2.z.object({
|
|
62
55
|
/**
|
|
63
56
|
* Citation configuration for this document.
|
|
@@ -82,40 +75,10 @@ var anthropicFilePartProviderOptions = import_zod2.z.object({
|
|
|
82
75
|
context: import_zod2.z.string().optional()
|
|
83
76
|
});
|
|
84
77
|
var anthropicProviderOptions = import_zod2.z.object({
|
|
85
|
-
/**
|
|
86
|
-
Include reasoning content in requests sent to the model. Defaults to `true`.
|
|
87
|
-
|
|
88
|
-
If you are experiencing issues with the model handling requests involving
|
|
89
|
-
*/
|
|
90
78
|
sendReasoning: import_zod2.z.boolean().optional(),
|
|
91
79
|
thinking: import_zod2.z.object({
|
|
92
80
|
type: import_zod2.z.union([import_zod2.z.literal("enabled"), import_zod2.z.literal("disabled")]),
|
|
93
81
|
budgetTokens: import_zod2.z.number().optional()
|
|
94
|
-
}).optional(),
|
|
95
|
-
/**
|
|
96
|
-
* Web search tool configuration for Claude models that support it.
|
|
97
|
-
* When provided, automatically adds the web search tool to the request.
|
|
98
|
-
*/
|
|
99
|
-
webSearch: import_zod2.z.object({
|
|
100
|
-
/**
|
|
101
|
-
* Limit the number of searches per request (optional)
|
|
102
|
-
* Defaults to 5 if not specified
|
|
103
|
-
*/
|
|
104
|
-
maxUses: import_zod2.z.number().min(1).max(20).optional(),
|
|
105
|
-
/**
|
|
106
|
-
* Only include results from these domains (optional)
|
|
107
|
-
* Cannot be used with blockedDomains
|
|
108
|
-
*/
|
|
109
|
-
allowedDomains: import_zod2.z.array(import_zod2.z.string()).optional(),
|
|
110
|
-
/**
|
|
111
|
-
* Never include results from these domains (optional)
|
|
112
|
-
* Cannot be used with allowedDomains
|
|
113
|
-
*/
|
|
114
|
-
blockedDomains: import_zod2.z.array(import_zod2.z.string()).optional(),
|
|
115
|
-
/**
|
|
116
|
-
* Localize search results based on user location (optional)
|
|
117
|
-
*/
|
|
118
|
-
userLocation: webSearchLocationSchema.optional()
|
|
119
82
|
}).optional()
|
|
120
83
|
});
|
|
121
84
|
|
|
@@ -145,10 +108,10 @@ function prepareTools({
|
|
|
145
108
|
anthropicTools2.push({
|
|
146
109
|
name: tool.name,
|
|
147
110
|
description: tool.description,
|
|
148
|
-
input_schema: tool.
|
|
111
|
+
input_schema: tool.inputSchema
|
|
149
112
|
});
|
|
150
113
|
break;
|
|
151
|
-
case "provider-defined":
|
|
114
|
+
case "provider-defined-client":
|
|
152
115
|
switch (tool.id) {
|
|
153
116
|
case "anthropic.computer_20250124":
|
|
154
117
|
betas.add("computer-use-2025-01-24");
|
|
@@ -203,6 +166,32 @@ function prepareTools({
|
|
|
203
166
|
break;
|
|
204
167
|
}
|
|
205
168
|
break;
|
|
169
|
+
case "provider-defined-server":
|
|
170
|
+
switch (tool.id) {
|
|
171
|
+
case "anthropic.web_search_20250305":
|
|
172
|
+
const webSearchTool = {
|
|
173
|
+
type: "web_search_20250305",
|
|
174
|
+
name: tool.name
|
|
175
|
+
};
|
|
176
|
+
if (tool.args.maxUses) {
|
|
177
|
+
webSearchTool.max_uses = tool.args.maxUses;
|
|
178
|
+
}
|
|
179
|
+
if (tool.args.allowedDomains) {
|
|
180
|
+
webSearchTool.allowed_domains = tool.args.allowedDomains;
|
|
181
|
+
}
|
|
182
|
+
if (tool.args.blockedDomains) {
|
|
183
|
+
webSearchTool.blocked_domains = tool.args.blockedDomains;
|
|
184
|
+
}
|
|
185
|
+
if (tool.args.userLocation) {
|
|
186
|
+
webSearchTool.user_location = tool.args.userLocation;
|
|
187
|
+
}
|
|
188
|
+
anthropicTools2.push(webSearchTool);
|
|
189
|
+
break;
|
|
190
|
+
default:
|
|
191
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
break;
|
|
206
195
|
default:
|
|
207
196
|
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
208
197
|
break;
|
|
@@ -441,7 +430,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
441
430
|
cache_control: void 0
|
|
442
431
|
};
|
|
443
432
|
}
|
|
444
|
-
}) : JSON.stringify(part.
|
|
433
|
+
}) : JSON.stringify(part.output);
|
|
445
434
|
anthropicContent.push({
|
|
446
435
|
type: "tool_result",
|
|
447
436
|
tool_use_id: part.toolCallId,
|
|
@@ -531,7 +520,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
531
520
|
type: "tool_use",
|
|
532
521
|
id: part.toolCallId,
|
|
533
522
|
name: part.toolName,
|
|
534
|
-
input: part.
|
|
523
|
+
input: part.input,
|
|
535
524
|
cache_control: cacheControl
|
|
536
525
|
});
|
|
537
526
|
break;
|
|
@@ -765,7 +754,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
765
754
|
type: "function",
|
|
766
755
|
name: "json",
|
|
767
756
|
description: "Respond with a JSON object.",
|
|
768
|
-
|
|
757
|
+
inputSchema: responseFormat.schema
|
|
769
758
|
} : void 0;
|
|
770
759
|
const anthropicOptions = await (0, import_provider_utils3.parseProviderOptions)({
|
|
771
760
|
provider: "anthropic",
|
|
@@ -828,27 +817,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
828
817
|
}
|
|
829
818
|
baseArgs.max_tokens = maxOutputTokens + thinkingBudget;
|
|
830
819
|
}
|
|
831
|
-
let modifiedTools = tools;
|
|
832
|
-
let modifiedToolChoice = toolChoice;
|
|
833
|
-
if (anthropicOptions == null ? void 0 : anthropicOptions.webSearch) {
|
|
834
|
-
const webSearchTool = {
|
|
835
|
-
type: "web_search_20250305",
|
|
836
|
-
name: "web_search",
|
|
837
|
-
max_uses: anthropicOptions.webSearch.maxUses,
|
|
838
|
-
allowed_domains: anthropicOptions.webSearch.allowedDomains,
|
|
839
|
-
blocked_domains: anthropicOptions.webSearch.blockedDomains,
|
|
840
|
-
...anthropicOptions.webSearch.userLocation && {
|
|
841
|
-
user_location: {
|
|
842
|
-
type: anthropicOptions.webSearch.userLocation.type,
|
|
843
|
-
country: anthropicOptions.webSearch.userLocation.country,
|
|
844
|
-
city: anthropicOptions.webSearch.userLocation.city,
|
|
845
|
-
region: anthropicOptions.webSearch.userLocation.region,
|
|
846
|
-
timezone: anthropicOptions.webSearch.userLocation.timezone
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
};
|
|
850
|
-
modifiedTools = tools ? [...tools, webSearchTool] : [webSearchTool];
|
|
851
|
-
}
|
|
852
820
|
const {
|
|
853
821
|
tools: anthropicTools2,
|
|
854
822
|
toolChoice: anthropicToolChoice,
|
|
@@ -858,7 +826,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
858
826
|
jsonResponseTool != null ? {
|
|
859
827
|
tools: [jsonResponseTool],
|
|
860
828
|
toolChoice: { type: "tool", toolName: jsonResponseTool.name }
|
|
861
|
-
} : { tools:
|
|
829
|
+
} : { tools: tools != null ? tools : [], toolChoice }
|
|
862
830
|
);
|
|
863
831
|
return {
|
|
864
832
|
args: {
|
|
@@ -985,7 +953,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
985
953
|
toolCallType: "function",
|
|
986
954
|
toolCallId: part.id,
|
|
987
955
|
toolName: part.name,
|
|
988
|
-
|
|
956
|
+
input: JSON.stringify(part.input)
|
|
989
957
|
}
|
|
990
958
|
);
|
|
991
959
|
break;
|
|
@@ -1177,7 +1145,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1177
1145
|
toolCallType: "function",
|
|
1178
1146
|
toolCallId: contentBlock.toolCallId,
|
|
1179
1147
|
toolName: contentBlock.toolName,
|
|
1180
|
-
|
|
1148
|
+
input: contentBlock.jsonText
|
|
1181
1149
|
});
|
|
1182
1150
|
}
|
|
1183
1151
|
delete toolCallContentBlocks[value.index];
|
|
@@ -1234,7 +1202,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1234
1202
|
toolCallType: "function",
|
|
1235
1203
|
toolCallId: contentBlock.toolCallId,
|
|
1236
1204
|
toolName: contentBlock.toolName,
|
|
1237
|
-
|
|
1205
|
+
inputTextDelta: value.delta.partial_json
|
|
1238
1206
|
}
|
|
1239
1207
|
);
|
|
1240
1208
|
contentBlock.jsonText += value.delta.partial_json;
|
|
@@ -1496,7 +1464,7 @@ var Bash20241022Parameters = import_zod4.z.object({
|
|
|
1496
1464
|
});
|
|
1497
1465
|
function bashTool_20241022(options = {}) {
|
|
1498
1466
|
return {
|
|
1499
|
-
type: "provider-defined",
|
|
1467
|
+
type: "provider-defined-client",
|
|
1500
1468
|
id: "anthropic.bash_20241022",
|
|
1501
1469
|
args: {},
|
|
1502
1470
|
parameters: Bash20241022Parameters,
|
|
@@ -1510,7 +1478,7 @@ var Bash20250124Parameters = import_zod4.z.object({
|
|
|
1510
1478
|
});
|
|
1511
1479
|
function bashTool_20250124(options = {}) {
|
|
1512
1480
|
return {
|
|
1513
|
-
type: "provider-defined",
|
|
1481
|
+
type: "provider-defined-client",
|
|
1514
1482
|
id: "anthropic.bash_20250124",
|
|
1515
1483
|
args: {},
|
|
1516
1484
|
parameters: Bash20250124Parameters,
|
|
@@ -1529,7 +1497,7 @@ var TextEditor20241022Parameters = import_zod4.z.object({
|
|
|
1529
1497
|
});
|
|
1530
1498
|
function textEditorTool_20241022(options = {}) {
|
|
1531
1499
|
return {
|
|
1532
|
-
type: "provider-defined",
|
|
1500
|
+
type: "provider-defined-client",
|
|
1533
1501
|
id: "anthropic.text_editor_20241022",
|
|
1534
1502
|
args: {},
|
|
1535
1503
|
parameters: TextEditor20241022Parameters,
|
|
@@ -1548,7 +1516,7 @@ var TextEditor20250124Parameters = import_zod4.z.object({
|
|
|
1548
1516
|
});
|
|
1549
1517
|
function textEditorTool_20250124(options = {}) {
|
|
1550
1518
|
return {
|
|
1551
|
-
type: "provider-defined",
|
|
1519
|
+
type: "provider-defined-client",
|
|
1552
1520
|
id: "anthropic.text_editor_20250124",
|
|
1553
1521
|
args: {},
|
|
1554
1522
|
parameters: TextEditor20250124Parameters,
|
|
@@ -1574,7 +1542,7 @@ var Computer20241022Parameters = import_zod4.z.object({
|
|
|
1574
1542
|
});
|
|
1575
1543
|
function computerTool_20241022(options) {
|
|
1576
1544
|
return {
|
|
1577
|
-
type: "provider-defined",
|
|
1545
|
+
type: "provider-defined-client",
|
|
1578
1546
|
id: "anthropic.computer_20241022",
|
|
1579
1547
|
args: {
|
|
1580
1548
|
displayWidthPx: options.displayWidthPx,
|
|
@@ -1614,7 +1582,7 @@ var Computer20250124Parameters = import_zod4.z.object({
|
|
|
1614
1582
|
});
|
|
1615
1583
|
function computerTool_20250124(options) {
|
|
1616
1584
|
return {
|
|
1617
|
-
type: "provider-defined",
|
|
1585
|
+
type: "provider-defined-client",
|
|
1618
1586
|
id: "anthropic.computer_20250124",
|
|
1619
1587
|
args: {
|
|
1620
1588
|
displayWidthPx: options.displayWidthPx,
|
|
@@ -1626,13 +1594,30 @@ function computerTool_20250124(options) {
|
|
|
1626
1594
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1627
1595
|
};
|
|
1628
1596
|
}
|
|
1597
|
+
var WebSearch20250305Parameters = import_zod4.z.object({
|
|
1598
|
+
query: import_zod4.z.string()
|
|
1599
|
+
});
|
|
1600
|
+
function webSearchTool_20250305(options = {}) {
|
|
1601
|
+
return {
|
|
1602
|
+
type: "provider-defined-server",
|
|
1603
|
+
id: "anthropic.web_search_20250305",
|
|
1604
|
+
name: "web_search",
|
|
1605
|
+
args: {
|
|
1606
|
+
...options.maxUses && { maxUses: options.maxUses },
|
|
1607
|
+
...options.allowedDomains && { allowedDomains: options.allowedDomains },
|
|
1608
|
+
...options.blockedDomains && { blockedDomains: options.blockedDomains },
|
|
1609
|
+
...options.userLocation && { userLocation: options.userLocation }
|
|
1610
|
+
}
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1629
1613
|
var anthropicTools = {
|
|
1630
1614
|
bash_20241022: bashTool_20241022,
|
|
1631
1615
|
bash_20250124: bashTool_20250124,
|
|
1632
1616
|
textEditor_20241022: textEditorTool_20241022,
|
|
1633
1617
|
textEditor_20250124: textEditorTool_20250124,
|
|
1634
1618
|
computer_20241022: computerTool_20241022,
|
|
1635
|
-
computer_20250124: computerTool_20250124
|
|
1619
|
+
computer_20250124: computerTool_20250124,
|
|
1620
|
+
webSearch_20250305: webSearchTool_20250305
|
|
1636
1621
|
};
|
|
1637
1622
|
|
|
1638
1623
|
// src/anthropic-provider.ts
|