@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/internal/index.mjs
CHANGED
|
@@ -31,13 +31,6 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
31
31
|
|
|
32
32
|
// src/anthropic-messages-options.ts
|
|
33
33
|
import { z as z2 } from "zod";
|
|
34
|
-
var webSearchLocationSchema = z2.object({
|
|
35
|
-
type: z2.literal("approximate"),
|
|
36
|
-
city: z2.string().optional(),
|
|
37
|
-
region: z2.string().optional(),
|
|
38
|
-
country: z2.string(),
|
|
39
|
-
timezone: z2.string().optional()
|
|
40
|
-
});
|
|
41
34
|
var anthropicFilePartProviderOptions = z2.object({
|
|
42
35
|
/**
|
|
43
36
|
* Citation configuration for this document.
|
|
@@ -62,40 +55,10 @@ var anthropicFilePartProviderOptions = z2.object({
|
|
|
62
55
|
context: z2.string().optional()
|
|
63
56
|
});
|
|
64
57
|
var anthropicProviderOptions = z2.object({
|
|
65
|
-
/**
|
|
66
|
-
Include reasoning content in requests sent to the model. Defaults to `true`.
|
|
67
|
-
|
|
68
|
-
If you are experiencing issues with the model handling requests involving
|
|
69
|
-
*/
|
|
70
58
|
sendReasoning: z2.boolean().optional(),
|
|
71
59
|
thinking: z2.object({
|
|
72
60
|
type: z2.union([z2.literal("enabled"), z2.literal("disabled")]),
|
|
73
61
|
budgetTokens: z2.number().optional()
|
|
74
|
-
}).optional(),
|
|
75
|
-
/**
|
|
76
|
-
* Web search tool configuration for Claude models that support it.
|
|
77
|
-
* When provided, automatically adds the web search tool to the request.
|
|
78
|
-
*/
|
|
79
|
-
webSearch: z2.object({
|
|
80
|
-
/**
|
|
81
|
-
* Limit the number of searches per request (optional)
|
|
82
|
-
* Defaults to 5 if not specified
|
|
83
|
-
*/
|
|
84
|
-
maxUses: z2.number().min(1).max(20).optional(),
|
|
85
|
-
/**
|
|
86
|
-
* Only include results from these domains (optional)
|
|
87
|
-
* Cannot be used with blockedDomains
|
|
88
|
-
*/
|
|
89
|
-
allowedDomains: z2.array(z2.string()).optional(),
|
|
90
|
-
/**
|
|
91
|
-
* Never include results from these domains (optional)
|
|
92
|
-
* Cannot be used with allowedDomains
|
|
93
|
-
*/
|
|
94
|
-
blockedDomains: z2.array(z2.string()).optional(),
|
|
95
|
-
/**
|
|
96
|
-
* Localize search results based on user location (optional)
|
|
97
|
-
*/
|
|
98
|
-
userLocation: webSearchLocationSchema.optional()
|
|
99
62
|
}).optional()
|
|
100
63
|
});
|
|
101
64
|
|
|
@@ -127,10 +90,10 @@ function prepareTools({
|
|
|
127
90
|
anthropicTools2.push({
|
|
128
91
|
name: tool.name,
|
|
129
92
|
description: tool.description,
|
|
130
|
-
input_schema: tool.
|
|
93
|
+
input_schema: tool.inputSchema
|
|
131
94
|
});
|
|
132
95
|
break;
|
|
133
|
-
case "provider-defined":
|
|
96
|
+
case "provider-defined-client":
|
|
134
97
|
switch (tool.id) {
|
|
135
98
|
case "anthropic.computer_20250124":
|
|
136
99
|
betas.add("computer-use-2025-01-24");
|
|
@@ -185,6 +148,32 @@ function prepareTools({
|
|
|
185
148
|
break;
|
|
186
149
|
}
|
|
187
150
|
break;
|
|
151
|
+
case "provider-defined-server":
|
|
152
|
+
switch (tool.id) {
|
|
153
|
+
case "anthropic.web_search_20250305":
|
|
154
|
+
const webSearchTool = {
|
|
155
|
+
type: "web_search_20250305",
|
|
156
|
+
name: tool.name
|
|
157
|
+
};
|
|
158
|
+
if (tool.args.maxUses) {
|
|
159
|
+
webSearchTool.max_uses = tool.args.maxUses;
|
|
160
|
+
}
|
|
161
|
+
if (tool.args.allowedDomains) {
|
|
162
|
+
webSearchTool.allowed_domains = tool.args.allowedDomains;
|
|
163
|
+
}
|
|
164
|
+
if (tool.args.blockedDomains) {
|
|
165
|
+
webSearchTool.blocked_domains = tool.args.blockedDomains;
|
|
166
|
+
}
|
|
167
|
+
if (tool.args.userLocation) {
|
|
168
|
+
webSearchTool.user_location = tool.args.userLocation;
|
|
169
|
+
}
|
|
170
|
+
anthropicTools2.push(webSearchTool);
|
|
171
|
+
break;
|
|
172
|
+
default:
|
|
173
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
break;
|
|
188
177
|
default:
|
|
189
178
|
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
190
179
|
break;
|
|
@@ -425,7 +414,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
425
414
|
cache_control: void 0
|
|
426
415
|
};
|
|
427
416
|
}
|
|
428
|
-
}) : JSON.stringify(part.
|
|
417
|
+
}) : JSON.stringify(part.output);
|
|
429
418
|
anthropicContent.push({
|
|
430
419
|
type: "tool_result",
|
|
431
420
|
tool_use_id: part.toolCallId,
|
|
@@ -515,7 +504,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
515
504
|
type: "tool_use",
|
|
516
505
|
id: part.toolCallId,
|
|
517
506
|
name: part.toolName,
|
|
518
|
-
input: part.
|
|
507
|
+
input: part.input,
|
|
519
508
|
cache_control: cacheControl
|
|
520
509
|
});
|
|
521
510
|
break;
|
|
@@ -749,7 +738,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
749
738
|
type: "function",
|
|
750
739
|
name: "json",
|
|
751
740
|
description: "Respond with a JSON object.",
|
|
752
|
-
|
|
741
|
+
inputSchema: responseFormat.schema
|
|
753
742
|
} : void 0;
|
|
754
743
|
const anthropicOptions = await parseProviderOptions2({
|
|
755
744
|
provider: "anthropic",
|
|
@@ -812,27 +801,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
812
801
|
}
|
|
813
802
|
baseArgs.max_tokens = maxOutputTokens + thinkingBudget;
|
|
814
803
|
}
|
|
815
|
-
let modifiedTools = tools;
|
|
816
|
-
let modifiedToolChoice = toolChoice;
|
|
817
|
-
if (anthropicOptions == null ? void 0 : anthropicOptions.webSearch) {
|
|
818
|
-
const webSearchTool = {
|
|
819
|
-
type: "web_search_20250305",
|
|
820
|
-
name: "web_search",
|
|
821
|
-
max_uses: anthropicOptions.webSearch.maxUses,
|
|
822
|
-
allowed_domains: anthropicOptions.webSearch.allowedDomains,
|
|
823
|
-
blocked_domains: anthropicOptions.webSearch.blockedDomains,
|
|
824
|
-
...anthropicOptions.webSearch.userLocation && {
|
|
825
|
-
user_location: {
|
|
826
|
-
type: anthropicOptions.webSearch.userLocation.type,
|
|
827
|
-
country: anthropicOptions.webSearch.userLocation.country,
|
|
828
|
-
city: anthropicOptions.webSearch.userLocation.city,
|
|
829
|
-
region: anthropicOptions.webSearch.userLocation.region,
|
|
830
|
-
timezone: anthropicOptions.webSearch.userLocation.timezone
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
};
|
|
834
|
-
modifiedTools = tools ? [...tools, webSearchTool] : [webSearchTool];
|
|
835
|
-
}
|
|
836
804
|
const {
|
|
837
805
|
tools: anthropicTools2,
|
|
838
806
|
toolChoice: anthropicToolChoice,
|
|
@@ -842,7 +810,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
842
810
|
jsonResponseTool != null ? {
|
|
843
811
|
tools: [jsonResponseTool],
|
|
844
812
|
toolChoice: { type: "tool", toolName: jsonResponseTool.name }
|
|
845
|
-
} : { tools:
|
|
813
|
+
} : { tools: tools != null ? tools : [], toolChoice }
|
|
846
814
|
);
|
|
847
815
|
return {
|
|
848
816
|
args: {
|
|
@@ -969,7 +937,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
969
937
|
toolCallType: "function",
|
|
970
938
|
toolCallId: part.id,
|
|
971
939
|
toolName: part.name,
|
|
972
|
-
|
|
940
|
+
input: JSON.stringify(part.input)
|
|
973
941
|
}
|
|
974
942
|
);
|
|
975
943
|
break;
|
|
@@ -1161,7 +1129,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1161
1129
|
toolCallType: "function",
|
|
1162
1130
|
toolCallId: contentBlock.toolCallId,
|
|
1163
1131
|
toolName: contentBlock.toolName,
|
|
1164
|
-
|
|
1132
|
+
input: contentBlock.jsonText
|
|
1165
1133
|
});
|
|
1166
1134
|
}
|
|
1167
1135
|
delete toolCallContentBlocks[value.index];
|
|
@@ -1218,7 +1186,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1218
1186
|
toolCallType: "function",
|
|
1219
1187
|
toolCallId: contentBlock.toolCallId,
|
|
1220
1188
|
toolName: contentBlock.toolName,
|
|
1221
|
-
|
|
1189
|
+
inputTextDelta: value.delta.partial_json
|
|
1222
1190
|
}
|
|
1223
1191
|
);
|
|
1224
1192
|
contentBlock.jsonText += value.delta.partial_json;
|
|
@@ -1480,7 +1448,7 @@ var Bash20241022Parameters = z4.object({
|
|
|
1480
1448
|
});
|
|
1481
1449
|
function bashTool_20241022(options = {}) {
|
|
1482
1450
|
return {
|
|
1483
|
-
type: "provider-defined",
|
|
1451
|
+
type: "provider-defined-client",
|
|
1484
1452
|
id: "anthropic.bash_20241022",
|
|
1485
1453
|
args: {},
|
|
1486
1454
|
parameters: Bash20241022Parameters,
|
|
@@ -1494,7 +1462,7 @@ var Bash20250124Parameters = z4.object({
|
|
|
1494
1462
|
});
|
|
1495
1463
|
function bashTool_20250124(options = {}) {
|
|
1496
1464
|
return {
|
|
1497
|
-
type: "provider-defined",
|
|
1465
|
+
type: "provider-defined-client",
|
|
1498
1466
|
id: "anthropic.bash_20250124",
|
|
1499
1467
|
args: {},
|
|
1500
1468
|
parameters: Bash20250124Parameters,
|
|
@@ -1513,7 +1481,7 @@ var TextEditor20241022Parameters = z4.object({
|
|
|
1513
1481
|
});
|
|
1514
1482
|
function textEditorTool_20241022(options = {}) {
|
|
1515
1483
|
return {
|
|
1516
|
-
type: "provider-defined",
|
|
1484
|
+
type: "provider-defined-client",
|
|
1517
1485
|
id: "anthropic.text_editor_20241022",
|
|
1518
1486
|
args: {},
|
|
1519
1487
|
parameters: TextEditor20241022Parameters,
|
|
@@ -1532,7 +1500,7 @@ var TextEditor20250124Parameters = z4.object({
|
|
|
1532
1500
|
});
|
|
1533
1501
|
function textEditorTool_20250124(options = {}) {
|
|
1534
1502
|
return {
|
|
1535
|
-
type: "provider-defined",
|
|
1503
|
+
type: "provider-defined-client",
|
|
1536
1504
|
id: "anthropic.text_editor_20250124",
|
|
1537
1505
|
args: {},
|
|
1538
1506
|
parameters: TextEditor20250124Parameters,
|
|
@@ -1558,7 +1526,7 @@ var Computer20241022Parameters = z4.object({
|
|
|
1558
1526
|
});
|
|
1559
1527
|
function computerTool_20241022(options) {
|
|
1560
1528
|
return {
|
|
1561
|
-
type: "provider-defined",
|
|
1529
|
+
type: "provider-defined-client",
|
|
1562
1530
|
id: "anthropic.computer_20241022",
|
|
1563
1531
|
args: {
|
|
1564
1532
|
displayWidthPx: options.displayWidthPx,
|
|
@@ -1598,7 +1566,7 @@ var Computer20250124Parameters = z4.object({
|
|
|
1598
1566
|
});
|
|
1599
1567
|
function computerTool_20250124(options) {
|
|
1600
1568
|
return {
|
|
1601
|
-
type: "provider-defined",
|
|
1569
|
+
type: "provider-defined-client",
|
|
1602
1570
|
id: "anthropic.computer_20250124",
|
|
1603
1571
|
args: {
|
|
1604
1572
|
displayWidthPx: options.displayWidthPx,
|
|
@@ -1610,13 +1578,30 @@ function computerTool_20250124(options) {
|
|
|
1610
1578
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1611
1579
|
};
|
|
1612
1580
|
}
|
|
1581
|
+
var WebSearch20250305Parameters = z4.object({
|
|
1582
|
+
query: z4.string()
|
|
1583
|
+
});
|
|
1584
|
+
function webSearchTool_20250305(options = {}) {
|
|
1585
|
+
return {
|
|
1586
|
+
type: "provider-defined-server",
|
|
1587
|
+
id: "anthropic.web_search_20250305",
|
|
1588
|
+
name: "web_search",
|
|
1589
|
+
args: {
|
|
1590
|
+
...options.maxUses && { maxUses: options.maxUses },
|
|
1591
|
+
...options.allowedDomains && { allowedDomains: options.allowedDomains },
|
|
1592
|
+
...options.blockedDomains && { blockedDomains: options.blockedDomains },
|
|
1593
|
+
...options.userLocation && { userLocation: options.userLocation }
|
|
1594
|
+
}
|
|
1595
|
+
};
|
|
1596
|
+
}
|
|
1613
1597
|
var anthropicTools = {
|
|
1614
1598
|
bash_20241022: bashTool_20241022,
|
|
1615
1599
|
bash_20250124: bashTool_20250124,
|
|
1616
1600
|
textEditor_20241022: textEditorTool_20241022,
|
|
1617
1601
|
textEditor_20250124: textEditorTool_20250124,
|
|
1618
1602
|
computer_20241022: computerTool_20241022,
|
|
1619
|
-
computer_20250124: computerTool_20250124
|
|
1603
|
+
computer_20250124: computerTool_20250124,
|
|
1604
|
+
webSearch_20250305: webSearchTool_20250305
|
|
1620
1605
|
};
|
|
1621
1606
|
export {
|
|
1622
1607
|
AnthropicMessagesLanguageModel,
|