@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/dist/index.mjs CHANGED
@@ -41,13 +41,6 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
41
41
 
42
42
  // src/anthropic-messages-options.ts
43
43
  import { z as z2 } from "zod";
44
- var webSearchLocationSchema = z2.object({
45
- type: z2.literal("approximate"),
46
- city: z2.string().optional(),
47
- region: z2.string().optional(),
48
- country: z2.string(),
49
- timezone: z2.string().optional()
50
- });
51
44
  var anthropicFilePartProviderOptions = z2.object({
52
45
  /**
53
46
  * Citation configuration for this document.
@@ -72,40 +65,10 @@ var anthropicFilePartProviderOptions = z2.object({
72
65
  context: z2.string().optional()
73
66
  });
74
67
  var anthropicProviderOptions = z2.object({
75
- /**
76
- Include reasoning content in requests sent to the model. Defaults to `true`.
77
-
78
- If you are experiencing issues with the model handling requests involving
79
- */
80
68
  sendReasoning: z2.boolean().optional(),
81
69
  thinking: z2.object({
82
70
  type: z2.union([z2.literal("enabled"), z2.literal("disabled")]),
83
71
  budgetTokens: z2.number().optional()
84
- }).optional(),
85
- /**
86
- * Web search tool configuration for Claude models that support it.
87
- * When provided, automatically adds the web search tool to the request.
88
- */
89
- webSearch: z2.object({
90
- /**
91
- * Limit the number of searches per request (optional)
92
- * Defaults to 5 if not specified
93
- */
94
- maxUses: z2.number().min(1).max(20).optional(),
95
- /**
96
- * Only include results from these domains (optional)
97
- * Cannot be used with blockedDomains
98
- */
99
- allowedDomains: z2.array(z2.string()).optional(),
100
- /**
101
- * Never include results from these domains (optional)
102
- * Cannot be used with allowedDomains
103
- */
104
- blockedDomains: z2.array(z2.string()).optional(),
105
- /**
106
- * Localize search results based on user location (optional)
107
- */
108
- userLocation: webSearchLocationSchema.optional()
109
72
  }).optional()
110
73
  });
111
74
 
@@ -137,10 +100,10 @@ function prepareTools({
137
100
  anthropicTools2.push({
138
101
  name: tool.name,
139
102
  description: tool.description,
140
- input_schema: tool.parameters
103
+ input_schema: tool.inputSchema
141
104
  });
142
105
  break;
143
- case "provider-defined":
106
+ case "provider-defined-client":
144
107
  switch (tool.id) {
145
108
  case "anthropic.computer_20250124":
146
109
  betas.add("computer-use-2025-01-24");
@@ -195,6 +158,32 @@ function prepareTools({
195
158
  break;
196
159
  }
197
160
  break;
161
+ case "provider-defined-server":
162
+ switch (tool.id) {
163
+ case "anthropic.web_search_20250305":
164
+ const webSearchTool = {
165
+ type: "web_search_20250305",
166
+ name: tool.name
167
+ };
168
+ if (tool.args.maxUses) {
169
+ webSearchTool.max_uses = tool.args.maxUses;
170
+ }
171
+ if (tool.args.allowedDomains) {
172
+ webSearchTool.allowed_domains = tool.args.allowedDomains;
173
+ }
174
+ if (tool.args.blockedDomains) {
175
+ webSearchTool.blocked_domains = tool.args.blockedDomains;
176
+ }
177
+ if (tool.args.userLocation) {
178
+ webSearchTool.user_location = tool.args.userLocation;
179
+ }
180
+ anthropicTools2.push(webSearchTool);
181
+ break;
182
+ default:
183
+ toolWarnings.push({ type: "unsupported-tool", tool });
184
+ break;
185
+ }
186
+ break;
198
187
  default:
199
188
  toolWarnings.push({ type: "unsupported-tool", tool });
200
189
  break;
@@ -435,7 +424,7 @@ async function convertToAnthropicMessagesPrompt({
435
424
  cache_control: void 0
436
425
  };
437
426
  }
438
- }) : JSON.stringify(part.result);
427
+ }) : JSON.stringify(part.output);
439
428
  anthropicContent.push({
440
429
  type: "tool_result",
441
430
  tool_use_id: part.toolCallId,
@@ -525,7 +514,7 @@ async function convertToAnthropicMessagesPrompt({
525
514
  type: "tool_use",
526
515
  id: part.toolCallId,
527
516
  name: part.toolName,
528
- input: part.args,
517
+ input: part.input,
529
518
  cache_control: cacheControl
530
519
  });
531
520
  break;
@@ -759,7 +748,7 @@ var AnthropicMessagesLanguageModel = class {
759
748
  type: "function",
760
749
  name: "json",
761
750
  description: "Respond with a JSON object.",
762
- parameters: responseFormat.schema
751
+ inputSchema: responseFormat.schema
763
752
  } : void 0;
764
753
  const anthropicOptions = await parseProviderOptions2({
765
754
  provider: "anthropic",
@@ -822,27 +811,6 @@ var AnthropicMessagesLanguageModel = class {
822
811
  }
823
812
  baseArgs.max_tokens = maxOutputTokens + thinkingBudget;
824
813
  }
825
- let modifiedTools = tools;
826
- let modifiedToolChoice = toolChoice;
827
- if (anthropicOptions == null ? void 0 : anthropicOptions.webSearch) {
828
- const webSearchTool = {
829
- type: "web_search_20250305",
830
- name: "web_search",
831
- max_uses: anthropicOptions.webSearch.maxUses,
832
- allowed_domains: anthropicOptions.webSearch.allowedDomains,
833
- blocked_domains: anthropicOptions.webSearch.blockedDomains,
834
- ...anthropicOptions.webSearch.userLocation && {
835
- user_location: {
836
- type: anthropicOptions.webSearch.userLocation.type,
837
- country: anthropicOptions.webSearch.userLocation.country,
838
- city: anthropicOptions.webSearch.userLocation.city,
839
- region: anthropicOptions.webSearch.userLocation.region,
840
- timezone: anthropicOptions.webSearch.userLocation.timezone
841
- }
842
- }
843
- };
844
- modifiedTools = tools ? [...tools, webSearchTool] : [webSearchTool];
845
- }
846
814
  const {
847
815
  tools: anthropicTools2,
848
816
  toolChoice: anthropicToolChoice,
@@ -852,7 +820,7 @@ var AnthropicMessagesLanguageModel = class {
852
820
  jsonResponseTool != null ? {
853
821
  tools: [jsonResponseTool],
854
822
  toolChoice: { type: "tool", toolName: jsonResponseTool.name }
855
- } : { tools: modifiedTools, toolChoice: modifiedToolChoice }
823
+ } : { tools: tools != null ? tools : [], toolChoice }
856
824
  );
857
825
  return {
858
826
  args: {
@@ -979,7 +947,7 @@ var AnthropicMessagesLanguageModel = class {
979
947
  toolCallType: "function",
980
948
  toolCallId: part.id,
981
949
  toolName: part.name,
982
- args: JSON.stringify(part.input)
950
+ input: JSON.stringify(part.input)
983
951
  }
984
952
  );
985
953
  break;
@@ -1171,7 +1139,7 @@ var AnthropicMessagesLanguageModel = class {
1171
1139
  toolCallType: "function",
1172
1140
  toolCallId: contentBlock.toolCallId,
1173
1141
  toolName: contentBlock.toolName,
1174
- args: contentBlock.jsonText
1142
+ input: contentBlock.jsonText
1175
1143
  });
1176
1144
  }
1177
1145
  delete toolCallContentBlocks[value.index];
@@ -1228,7 +1196,7 @@ var AnthropicMessagesLanguageModel = class {
1228
1196
  toolCallType: "function",
1229
1197
  toolCallId: contentBlock.toolCallId,
1230
1198
  toolName: contentBlock.toolName,
1231
- argsTextDelta: value.delta.partial_json
1199
+ inputTextDelta: value.delta.partial_json
1232
1200
  }
1233
1201
  );
1234
1202
  contentBlock.jsonText += value.delta.partial_json;
@@ -1490,7 +1458,7 @@ var Bash20241022Parameters = z4.object({
1490
1458
  });
1491
1459
  function bashTool_20241022(options = {}) {
1492
1460
  return {
1493
- type: "provider-defined",
1461
+ type: "provider-defined-client",
1494
1462
  id: "anthropic.bash_20241022",
1495
1463
  args: {},
1496
1464
  parameters: Bash20241022Parameters,
@@ -1504,7 +1472,7 @@ var Bash20250124Parameters = z4.object({
1504
1472
  });
1505
1473
  function bashTool_20250124(options = {}) {
1506
1474
  return {
1507
- type: "provider-defined",
1475
+ type: "provider-defined-client",
1508
1476
  id: "anthropic.bash_20250124",
1509
1477
  args: {},
1510
1478
  parameters: Bash20250124Parameters,
@@ -1523,7 +1491,7 @@ var TextEditor20241022Parameters = z4.object({
1523
1491
  });
1524
1492
  function textEditorTool_20241022(options = {}) {
1525
1493
  return {
1526
- type: "provider-defined",
1494
+ type: "provider-defined-client",
1527
1495
  id: "anthropic.text_editor_20241022",
1528
1496
  args: {},
1529
1497
  parameters: TextEditor20241022Parameters,
@@ -1542,7 +1510,7 @@ var TextEditor20250124Parameters = z4.object({
1542
1510
  });
1543
1511
  function textEditorTool_20250124(options = {}) {
1544
1512
  return {
1545
- type: "provider-defined",
1513
+ type: "provider-defined-client",
1546
1514
  id: "anthropic.text_editor_20250124",
1547
1515
  args: {},
1548
1516
  parameters: TextEditor20250124Parameters,
@@ -1568,7 +1536,7 @@ var Computer20241022Parameters = z4.object({
1568
1536
  });
1569
1537
  function computerTool_20241022(options) {
1570
1538
  return {
1571
- type: "provider-defined",
1539
+ type: "provider-defined-client",
1572
1540
  id: "anthropic.computer_20241022",
1573
1541
  args: {
1574
1542
  displayWidthPx: options.displayWidthPx,
@@ -1608,7 +1576,7 @@ var Computer20250124Parameters = z4.object({
1608
1576
  });
1609
1577
  function computerTool_20250124(options) {
1610
1578
  return {
1611
- type: "provider-defined",
1579
+ type: "provider-defined-client",
1612
1580
  id: "anthropic.computer_20250124",
1613
1581
  args: {
1614
1582
  displayWidthPx: options.displayWidthPx,
@@ -1620,13 +1588,30 @@ function computerTool_20250124(options) {
1620
1588
  experimental_toToolResultContent: options.experimental_toToolResultContent
1621
1589
  };
1622
1590
  }
1591
+ var WebSearch20250305Parameters = z4.object({
1592
+ query: z4.string()
1593
+ });
1594
+ function webSearchTool_20250305(options = {}) {
1595
+ return {
1596
+ type: "provider-defined-server",
1597
+ id: "anthropic.web_search_20250305",
1598
+ name: "web_search",
1599
+ args: {
1600
+ ...options.maxUses && { maxUses: options.maxUses },
1601
+ ...options.allowedDomains && { allowedDomains: options.allowedDomains },
1602
+ ...options.blockedDomains && { blockedDomains: options.blockedDomains },
1603
+ ...options.userLocation && { userLocation: options.userLocation }
1604
+ }
1605
+ };
1606
+ }
1623
1607
  var anthropicTools = {
1624
1608
  bash_20241022: bashTool_20241022,
1625
1609
  bash_20250124: bashTool_20250124,
1626
1610
  textEditor_20241022: textEditorTool_20241022,
1627
1611
  textEditor_20250124: textEditorTool_20250124,
1628
1612
  computer_20241022: computerTool_20241022,
1629
- computer_20250124: computerTool_20250124
1613
+ computer_20250124: computerTool_20250124,
1614
+ webSearch_20250305: webSearchTool_20250305
1630
1615
  };
1631
1616
 
1632
1617
  // src/anthropic-provider.ts