@ai-sdk/anthropic 1.1.10 → 1.1.12

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 1.1.12
4
+
5
+ ### Patch Changes
6
+
7
+ - b3e5a15: fix (provider/anthropic): add model setting to allow omitting reasoning content from model requests
8
+
9
+ ## 1.1.11
10
+
11
+ ### Patch Changes
12
+
13
+ - 00276ae: feat (provider/anthropic): update types for Anthropic computer_20250124 tool
14
+ - a4f8714: feat (provider/anthropic): update beta flag for sonnet-3-7 when using new computer-use tool
15
+
3
16
  ## 1.1.10
4
17
 
5
18
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -12,6 +12,13 @@ interface AnthropicMessagesSettings {
12
12
  optionally mark content for caching) and this setting is no longer needed.
13
13
  */
14
14
  cacheControl?: boolean;
15
+ /**
16
+ Include reasoning content in requests sent to the model. Defaults to `true`.
17
+
18
+ If you are experiencing issues with the model handling requests involving
19
+ reasoning content, you can set this to `false` to omit them from the request.
20
+ */
21
+ sendReasoning?: boolean;
15
22
  }
16
23
 
17
24
  type ExecuteFunction<PARAMETERS, RESULT> = undefined | ((args: PARAMETERS, options: {
@@ -196,6 +203,31 @@ declare function computerTool_20241022<RESULT>(options: {
196
203
  execute: ExecuteFunction<z.infer<typeof Computer20241022Parameters>, RESULT>;
197
204
  experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
198
205
  };
206
+ declare const Computer20250124Parameters: z.ZodObject<{
207
+ action: z.ZodEnum<["key", "hold_key", "type", "cursor_position", "mouse_move", "left_mouse_down", "left_mouse_up", "left_click", "left_click_drag", "right_click", "middle_click", "double_click", "triple_click", "scroll", "wait", "screenshot"]>;
208
+ coordinate: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
209
+ duration: z.ZodOptional<z.ZodNumber>;
210
+ scroll_amount: z.ZodOptional<z.ZodNumber>;
211
+ scroll_direction: z.ZodOptional<z.ZodEnum<["up", "down", "left", "right"]>>;
212
+ start_coordinate: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
213
+ text: z.ZodOptional<z.ZodString>;
214
+ }, "strip", z.ZodTypeAny, {
215
+ action: "type" | "key" | "mouse_move" | "left_click" | "left_click_drag" | "right_click" | "middle_click" | "double_click" | "screenshot" | "cursor_position" | "hold_key" | "left_mouse_down" | "left_mouse_up" | "triple_click" | "scroll" | "wait";
216
+ text?: string | undefined;
217
+ coordinate?: [number, number] | undefined;
218
+ duration?: number | undefined;
219
+ scroll_amount?: number | undefined;
220
+ scroll_direction?: "up" | "down" | "left" | "right" | undefined;
221
+ start_coordinate?: [number, number] | undefined;
222
+ }, {
223
+ action: "type" | "key" | "mouse_move" | "left_click" | "left_click_drag" | "right_click" | "middle_click" | "double_click" | "screenshot" | "cursor_position" | "hold_key" | "left_mouse_down" | "left_mouse_up" | "triple_click" | "scroll" | "wait";
224
+ text?: string | undefined;
225
+ coordinate?: [number, number] | undefined;
226
+ duration?: number | undefined;
227
+ scroll_amount?: number | undefined;
228
+ scroll_direction?: "up" | "down" | "left" | "right" | undefined;
229
+ start_coordinate?: [number, number] | undefined;
230
+ }>;
199
231
  /**
200
232
  * Creates a tool for executing actions on a computer. Must have name "computer".
201
233
  *
@@ -212,27 +244,48 @@ declare function computerTool_20250124<RESULT>(options: {
212
244
  displayNumber?: number;
213
245
  execute?: ExecuteFunction<{
214
246
  /**
215
- * The action to perform. The available actions are:
216
247
  * - `key`: Press a key or key-combination on the keyboard.
217
248
  * - This supports xdotool's `key` syntax.
218
249
  * - Examples: "a", "Return", "alt+Tab", "ctrl+s", "Up", "KP_0" (for the numpad 0 key).
250
+ * - `hold_key`: Hold down a key or multiple keys for a specified duration (in seconds). Supports the same syntax as `key`.
219
251
  * - `type`: Type a string of text on the keyboard.
220
252
  * - `cursor_position`: Get the current (x, y) pixel coordinate of the cursor on the screen.
221
253
  * - `mouse_move`: Move the cursor to a specified (x, y) pixel coordinate on the screen.
222
- * - `left_click`: Click the left mouse button.
223
- * - `left_click_drag`: Click and drag the cursor to a specified (x, y) pixel coordinate on the screen.
224
- * - `right_click`: Click the right mouse button.
225
- * - `middle_click`: Click the middle mouse button.
226
- * - `double_click`: Double-click the left mouse button.
254
+ * - `left_mouse_down`: Press the left mouse button.
255
+ * - `left_mouse_up`: Release the left mouse button.
256
+ * - `left_click`: Click the left mouse button at the specified (x, y) pixel coordinate on the screen. You can also include a key combination to hold down while clicking using the `text` parameter.
257
+ * - `left_click_drag`: Click and drag the cursor from `start_coordinate` to a specified (x, y) pixel coordinate on the screen.
258
+ * - `right_click`: Click the right mouse button at the specified (x, y) pixel coordinate on the screen.
259
+ * - `middle_click`: Click the middle mouse button at the specified (x, y) pixel coordinate on the screen.
260
+ * - `double_click`: Double-click the left mouse button at the specified (x, y) pixel coordinate on the screen.
261
+ * - `triple_click`: Triple-click the left mouse button at the specified (x, y) pixel coordinate on the screen.
262
+ * - `scroll`: Scroll the screen in a specified direction by a specified amount of clicks of the scroll wheel, at the specified (x, y) pixel coordinate. DO NOT use PageUp/PageDown to scroll.
263
+ * - `wait`: Wait for a specified duration (in seconds).
227
264
  * - `screenshot`: Take a screenshot of the screen.
228
265
  */
229
- action: 'key' | 'type' | 'mouse_move' | 'left_click' | 'left_click_drag' | 'right_click' | 'middle_click' | 'double_click' | 'screenshot' | 'cursor_position';
266
+ action: 'key' | 'hold_key' | 'type' | 'cursor_position' | 'mouse_move' | 'left_mouse_down' | 'left_mouse_up' | 'left_click' | 'left_click_drag' | 'right_click' | 'middle_click' | 'double_click' | 'triple_click' | 'scroll' | 'wait' | 'screenshot';
230
267
  /**
231
268
  * (x, y): The x (pixels from the left edge) and y (pixels from the top edge) coordinates to move the mouse to. Required only by `action=mouse_move` and `action=left_click_drag`.
232
269
  */
233
- coordinate?: number[];
270
+ coordinate?: [number, number];
234
271
  /**
235
- * Required only by `action=type` and `action=key`.
272
+ * The duration to hold the key down for. Required only by `action=hold_key` and `action=wait`.
273
+ */
274
+ duration?: number;
275
+ /**
276
+ * The number of 'clicks' to scroll. Required only by `action=scroll`.
277
+ */
278
+ scroll_amount?: number;
279
+ /**
280
+ * The direction to scroll the screen. Required only by `action=scroll`.
281
+ */
282
+ scroll_direction?: 'up' | 'down' | 'left' | 'right';
283
+ /**
284
+ * (x, y): The x (pixels from the left edge) and y (pixels from the top edge) coordinates to start the drag from. Required only by `action=left_click_drag`.
285
+ */
286
+ start_coordinate?: [number, number];
287
+ /**
288
+ * Required only by `action=type`, `action=key`, and `action=hold_key`. Can also be used by click or scroll actions to hold down keys while clicking or scrolling.
236
289
  */
237
290
  text?: string;
238
291
  }, RESULT>;
@@ -241,8 +294,8 @@ declare function computerTool_20250124<RESULT>(options: {
241
294
  type: 'provider-defined';
242
295
  id: 'anthropic.computer_20250124';
243
296
  args: {};
244
- parameters: typeof Computer20241022Parameters;
245
- execute: ExecuteFunction<z.infer<typeof Computer20241022Parameters>, RESULT>;
297
+ parameters: typeof Computer20250124Parameters;
298
+ execute: ExecuteFunction<z.infer<typeof Computer20250124Parameters>, RESULT>;
246
299
  experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
247
300
  };
248
301
  declare const anthropicTools: {
package/dist/index.d.ts CHANGED
@@ -12,6 +12,13 @@ interface AnthropicMessagesSettings {
12
12
  optionally mark content for caching) and this setting is no longer needed.
13
13
  */
14
14
  cacheControl?: boolean;
15
+ /**
16
+ Include reasoning content in requests sent to the model. Defaults to `true`.
17
+
18
+ If you are experiencing issues with the model handling requests involving
19
+ reasoning content, you can set this to `false` to omit them from the request.
20
+ */
21
+ sendReasoning?: boolean;
15
22
  }
16
23
 
17
24
  type ExecuteFunction<PARAMETERS, RESULT> = undefined | ((args: PARAMETERS, options: {
@@ -196,6 +203,31 @@ declare function computerTool_20241022<RESULT>(options: {
196
203
  execute: ExecuteFunction<z.infer<typeof Computer20241022Parameters>, RESULT>;
197
204
  experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
198
205
  };
206
+ declare const Computer20250124Parameters: z.ZodObject<{
207
+ action: z.ZodEnum<["key", "hold_key", "type", "cursor_position", "mouse_move", "left_mouse_down", "left_mouse_up", "left_click", "left_click_drag", "right_click", "middle_click", "double_click", "triple_click", "scroll", "wait", "screenshot"]>;
208
+ coordinate: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
209
+ duration: z.ZodOptional<z.ZodNumber>;
210
+ scroll_amount: z.ZodOptional<z.ZodNumber>;
211
+ scroll_direction: z.ZodOptional<z.ZodEnum<["up", "down", "left", "right"]>>;
212
+ start_coordinate: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
213
+ text: z.ZodOptional<z.ZodString>;
214
+ }, "strip", z.ZodTypeAny, {
215
+ action: "type" | "key" | "mouse_move" | "left_click" | "left_click_drag" | "right_click" | "middle_click" | "double_click" | "screenshot" | "cursor_position" | "hold_key" | "left_mouse_down" | "left_mouse_up" | "triple_click" | "scroll" | "wait";
216
+ text?: string | undefined;
217
+ coordinate?: [number, number] | undefined;
218
+ duration?: number | undefined;
219
+ scroll_amount?: number | undefined;
220
+ scroll_direction?: "up" | "down" | "left" | "right" | undefined;
221
+ start_coordinate?: [number, number] | undefined;
222
+ }, {
223
+ action: "type" | "key" | "mouse_move" | "left_click" | "left_click_drag" | "right_click" | "middle_click" | "double_click" | "screenshot" | "cursor_position" | "hold_key" | "left_mouse_down" | "left_mouse_up" | "triple_click" | "scroll" | "wait";
224
+ text?: string | undefined;
225
+ coordinate?: [number, number] | undefined;
226
+ duration?: number | undefined;
227
+ scroll_amount?: number | undefined;
228
+ scroll_direction?: "up" | "down" | "left" | "right" | undefined;
229
+ start_coordinate?: [number, number] | undefined;
230
+ }>;
199
231
  /**
200
232
  * Creates a tool for executing actions on a computer. Must have name "computer".
201
233
  *
@@ -212,27 +244,48 @@ declare function computerTool_20250124<RESULT>(options: {
212
244
  displayNumber?: number;
213
245
  execute?: ExecuteFunction<{
214
246
  /**
215
- * The action to perform. The available actions are:
216
247
  * - `key`: Press a key or key-combination on the keyboard.
217
248
  * - This supports xdotool's `key` syntax.
218
249
  * - Examples: "a", "Return", "alt+Tab", "ctrl+s", "Up", "KP_0" (for the numpad 0 key).
250
+ * - `hold_key`: Hold down a key or multiple keys for a specified duration (in seconds). Supports the same syntax as `key`.
219
251
  * - `type`: Type a string of text on the keyboard.
220
252
  * - `cursor_position`: Get the current (x, y) pixel coordinate of the cursor on the screen.
221
253
  * - `mouse_move`: Move the cursor to a specified (x, y) pixel coordinate on the screen.
222
- * - `left_click`: Click the left mouse button.
223
- * - `left_click_drag`: Click and drag the cursor to a specified (x, y) pixel coordinate on the screen.
224
- * - `right_click`: Click the right mouse button.
225
- * - `middle_click`: Click the middle mouse button.
226
- * - `double_click`: Double-click the left mouse button.
254
+ * - `left_mouse_down`: Press the left mouse button.
255
+ * - `left_mouse_up`: Release the left mouse button.
256
+ * - `left_click`: Click the left mouse button at the specified (x, y) pixel coordinate on the screen. You can also include a key combination to hold down while clicking using the `text` parameter.
257
+ * - `left_click_drag`: Click and drag the cursor from `start_coordinate` to a specified (x, y) pixel coordinate on the screen.
258
+ * - `right_click`: Click the right mouse button at the specified (x, y) pixel coordinate on the screen.
259
+ * - `middle_click`: Click the middle mouse button at the specified (x, y) pixel coordinate on the screen.
260
+ * - `double_click`: Double-click the left mouse button at the specified (x, y) pixel coordinate on the screen.
261
+ * - `triple_click`: Triple-click the left mouse button at the specified (x, y) pixel coordinate on the screen.
262
+ * - `scroll`: Scroll the screen in a specified direction by a specified amount of clicks of the scroll wheel, at the specified (x, y) pixel coordinate. DO NOT use PageUp/PageDown to scroll.
263
+ * - `wait`: Wait for a specified duration (in seconds).
227
264
  * - `screenshot`: Take a screenshot of the screen.
228
265
  */
229
- action: 'key' | 'type' | 'mouse_move' | 'left_click' | 'left_click_drag' | 'right_click' | 'middle_click' | 'double_click' | 'screenshot' | 'cursor_position';
266
+ action: 'key' | 'hold_key' | 'type' | 'cursor_position' | 'mouse_move' | 'left_mouse_down' | 'left_mouse_up' | 'left_click' | 'left_click_drag' | 'right_click' | 'middle_click' | 'double_click' | 'triple_click' | 'scroll' | 'wait' | 'screenshot';
230
267
  /**
231
268
  * (x, y): The x (pixels from the left edge) and y (pixels from the top edge) coordinates to move the mouse to. Required only by `action=mouse_move` and `action=left_click_drag`.
232
269
  */
233
- coordinate?: number[];
270
+ coordinate?: [number, number];
234
271
  /**
235
- * Required only by `action=type` and `action=key`.
272
+ * The duration to hold the key down for. Required only by `action=hold_key` and `action=wait`.
273
+ */
274
+ duration?: number;
275
+ /**
276
+ * The number of 'clicks' to scroll. Required only by `action=scroll`.
277
+ */
278
+ scroll_amount?: number;
279
+ /**
280
+ * The direction to scroll the screen. Required only by `action=scroll`.
281
+ */
282
+ scroll_direction?: 'up' | 'down' | 'left' | 'right';
283
+ /**
284
+ * (x, y): The x (pixels from the left edge) and y (pixels from the top edge) coordinates to start the drag from. Required only by `action=left_click_drag`.
285
+ */
286
+ start_coordinate?: [number, number];
287
+ /**
288
+ * Required only by `action=type`, `action=key`, and `action=hold_key`. Can also be used by click or scroll actions to hold down keys while clicking or scrolling.
236
289
  */
237
290
  text?: string;
238
291
  }, RESULT>;
@@ -241,8 +294,8 @@ declare function computerTool_20250124<RESULT>(options: {
241
294
  type: 'provider-defined';
242
295
  id: 'anthropic.computer_20250124';
243
296
  args: {};
244
- parameters: typeof Computer20241022Parameters;
245
- execute: ExecuteFunction<z.infer<typeof Computer20241022Parameters>, RESULT>;
297
+ parameters: typeof Computer20250124Parameters;
298
+ execute: ExecuteFunction<z.infer<typeof Computer20250124Parameters>, RESULT>;
246
299
  experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
247
300
  };
248
301
  declare const anthropicTools: {
package/dist/index.js CHANGED
@@ -70,9 +70,9 @@ function prepareTools(mode) {
70
70
  });
71
71
  break;
72
72
  case "provider-defined":
73
- betas.add("computer-use-2024-10-22");
74
73
  switch (tool.id) {
75
74
  case "anthropic.computer_20250124":
75
+ betas.add("computer-use-2025-01-24");
76
76
  anthropicTools2.push({
77
77
  name: tool.name,
78
78
  type: "computer_20250124",
@@ -82,6 +82,7 @@ function prepareTools(mode) {
82
82
  });
83
83
  break;
84
84
  case "anthropic.computer_20241022":
85
+ betas.add("computer-use-2024-10-22");
85
86
  anthropicTools2.push({
86
87
  name: tool.name,
87
88
  type: "computer_20241022",
@@ -91,12 +92,14 @@ function prepareTools(mode) {
91
92
  });
92
93
  break;
93
94
  case "anthropic.text_editor_20241022":
95
+ betas.add("computer-use-2024-10-22");
94
96
  anthropicTools2.push({
95
97
  name: tool.name,
96
98
  type: "text_editor_20241022"
97
99
  });
98
100
  break;
99
101
  case "anthropic.bash_20241022":
102
+ betas.add("computer-use-2024-10-22");
100
103
  anthropicTools2.push({
101
104
  name: tool.name,
102
105
  type: "bash_20241022"
@@ -159,7 +162,9 @@ function prepareTools(mode) {
159
162
  var import_provider2 = require("@ai-sdk/provider");
160
163
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
161
164
  function convertToAnthropicMessagesPrompt({
162
- prompt
165
+ prompt,
166
+ sendReasoning,
167
+ warnings
163
168
  }) {
164
169
  var _a, _b, _c, _d;
165
170
  const betas = /* @__PURE__ */ new Set();
@@ -323,12 +328,19 @@ function convertToAnthropicMessagesPrompt({
323
328
  break;
324
329
  }
325
330
  case "reasoning": {
326
- anthropicContent.push({
327
- type: "thinking",
328
- thinking: part.text,
329
- signature: part.signature,
330
- cache_control: cacheControl
331
- });
331
+ if (sendReasoning) {
332
+ anthropicContent.push({
333
+ type: "thinking",
334
+ thinking: part.text,
335
+ signature: part.signature,
336
+ cache_control: cacheControl
337
+ });
338
+ } else {
339
+ warnings.push({
340
+ type: "other",
341
+ message: "sending reasoning content is disabled for this model"
342
+ });
343
+ }
332
344
  break;
333
345
  }
334
346
  case "redacted-reasoning": {
@@ -460,7 +472,7 @@ var AnthropicMessagesLanguageModel = class {
460
472
  seed,
461
473
  providerMetadata: providerOptions
462
474
  }) {
463
- var _a, _b, _c;
475
+ var _a, _b, _c, _d;
464
476
  const type = mode.type;
465
477
  const warnings = [];
466
478
  if (frequencyPenalty != null) {
@@ -489,10 +501,12 @@ var AnthropicMessagesLanguageModel = class {
489
501
  });
490
502
  }
491
503
  const { prompt: messagesPrompt, betas: messagesBetas } = convertToAnthropicMessagesPrompt({
492
- prompt
504
+ prompt,
505
+ sendReasoning: (_a = this.settings.sendReasoning) != null ? _a : true,
506
+ warnings
493
507
  });
494
508
  const thinkingOptions = thinkingOptionsSchema.safeParse(
495
- (_a = providerOptions == null ? void 0 : providerOptions.anthropic) == null ? void 0 : _a.thinking
509
+ (_b = providerOptions == null ? void 0 : providerOptions.anthropic) == null ? void 0 : _b.thinking
496
510
  );
497
511
  if (!thinkingOptions.success) {
498
512
  throw new import_provider3.InvalidArgumentError({
@@ -501,8 +515,8 @@ var AnthropicMessagesLanguageModel = class {
501
515
  cause: thinkingOptions.error
502
516
  });
503
517
  }
504
- const isThinking = ((_b = thinkingOptions.data) == null ? void 0 : _b.type) === "enabled";
505
- const thinkingBudget = (_c = thinkingOptions.data) == null ? void 0 : _c.budgetTokens;
518
+ const isThinking = ((_c = thinkingOptions.data) == null ? void 0 : _c.type) === "enabled";
519
+ const thinkingBudget = (_d = thinkingOptions.data) == null ? void 0 : _d.budgetTokens;
506
520
  const baseArgs = {
507
521
  // model id:
508
522
  model: this.modelId,
@@ -1044,6 +1058,32 @@ function computerTool_20241022(options) {
1044
1058
  experimental_toToolResultContent: options.experimental_toToolResultContent
1045
1059
  };
1046
1060
  }
1061
+ var Computer20250124Parameters = import_zod3.z.object({
1062
+ action: import_zod3.z.enum([
1063
+ "key",
1064
+ "hold_key",
1065
+ "type",
1066
+ "cursor_position",
1067
+ "mouse_move",
1068
+ "left_mouse_down",
1069
+ "left_mouse_up",
1070
+ "left_click",
1071
+ "left_click_drag",
1072
+ "right_click",
1073
+ "middle_click",
1074
+ "double_click",
1075
+ "triple_click",
1076
+ "scroll",
1077
+ "wait",
1078
+ "screenshot"
1079
+ ]),
1080
+ coordinate: import_zod3.z.tuple([import_zod3.z.number().int(), import_zod3.z.number().int()]).optional(),
1081
+ duration: import_zod3.z.number().optional(),
1082
+ scroll_amount: import_zod3.z.number().optional(),
1083
+ scroll_direction: import_zod3.z.enum(["up", "down", "left", "right"]).optional(),
1084
+ start_coordinate: import_zod3.z.tuple([import_zod3.z.number().int(), import_zod3.z.number().int()]).optional(),
1085
+ text: import_zod3.z.string().optional()
1086
+ });
1047
1087
  function computerTool_20250124(options) {
1048
1088
  return {
1049
1089
  type: "provider-defined",
@@ -1053,7 +1093,7 @@ function computerTool_20250124(options) {
1053
1093
  displayHeightPx: options.displayHeightPx,
1054
1094
  displayNumber: options.displayNumber
1055
1095
  },
1056
- parameters: Computer20241022Parameters,
1096
+ parameters: Computer20250124Parameters,
1057
1097
  execute: options.execute,
1058
1098
  experimental_toToolResultContent: options.experimental_toToolResultContent
1059
1099
  };