@ai-sdk/anthropic 3.0.119 → 3.0.120
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 +12 -0
- package/dist/index.d.mts +47 -1
- package/dist/index.d.ts +47 -1
- package/dist/index.js +834 -458
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +826 -446
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +74 -2
- package/dist/internal/index.d.ts +74 -2
- package/dist/internal/index.js +827 -451
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +825 -445
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +125 -14
- package/package.json +1 -1
- package/src/anthropic-messages-api.ts +23 -0
- package/src/anthropic-messages-language-model.ts +264 -6
- package/src/anthropic-messages-options.ts +12 -2
- package/src/anthropic-prepare-tools.ts +76 -0
- package/src/anthropic-tools.ts +25 -0
- package/src/convert-to-anthropic-messages-prompt.ts +77 -1
- package/src/tool/computer-toolset_20260801.ts +165 -0
|
@@ -115,12 +115,20 @@ export async function convertToAnthropicMessagesPrompt({
|
|
|
115
115
|
warnings,
|
|
116
116
|
cacheControlValidator,
|
|
117
117
|
toolNameMapping,
|
|
118
|
+
toolsetNames = {},
|
|
118
119
|
}: {
|
|
119
120
|
prompt: LanguageModelV3Prompt;
|
|
120
121
|
sendReasoning: boolean;
|
|
121
122
|
warnings: SharedV3Warning[];
|
|
122
123
|
cacheControlValidator?: CacheControlValidator;
|
|
123
124
|
toolNameMapping: ToolNameMapping;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Maps custom tool names of toolset tools (e.g. the computer toolset) to
|
|
128
|
+
* the Anthropic `toolset_name`. Tool calls and results of these tools are
|
|
129
|
+
* serialized as toolset member calls.
|
|
130
|
+
*/
|
|
131
|
+
toolsetNames?: Record<string, string>;
|
|
124
132
|
}): Promise<{
|
|
125
133
|
prompt: AnthropicMessagesPrompt;
|
|
126
134
|
betas: Set<string>;
|
|
@@ -263,7 +271,7 @@ export async function convertToAnthropicMessagesPrompt({
|
|
|
263
271
|
betas.add('mid-conversation-system-clear-at-2026-08-21');
|
|
264
272
|
}
|
|
265
273
|
if (systemMessages.some(message => message.output_config != null)) {
|
|
266
|
-
betas.add('mid-conversation-
|
|
274
|
+
betas.add('mid-conversation-output-config-2026-07-01');
|
|
267
275
|
}
|
|
268
276
|
}
|
|
269
277
|
|
|
@@ -540,9 +548,16 @@ export async function convertToAnthropicMessagesPrompt({
|
|
|
540
548
|
break;
|
|
541
549
|
}
|
|
542
550
|
|
|
551
|
+
const toolsetName = getAnthropicToolsetName({
|
|
552
|
+
toolName: part.toolName,
|
|
553
|
+
providerOptions: part.providerOptions,
|
|
554
|
+
toolsetNames,
|
|
555
|
+
});
|
|
556
|
+
|
|
543
557
|
anthropicContent.push({
|
|
544
558
|
type: 'tool_result',
|
|
545
559
|
tool_use_id: part.toolCallId,
|
|
560
|
+
...(toolsetName != null && { toolset_name: toolsetName }),
|
|
546
561
|
content: contentValue,
|
|
547
562
|
is_error:
|
|
548
563
|
output.type === 'error-text' || output.type === 'error-json'
|
|
@@ -804,6 +819,41 @@ export async function convertToAnthropicMessagesPrompt({
|
|
|
804
819
|
break;
|
|
805
820
|
}
|
|
806
821
|
|
|
822
|
+
const toolsetName = getAnthropicToolsetName({
|
|
823
|
+
toolName: part.toolName,
|
|
824
|
+
providerOptions: part.providerOptions,
|
|
825
|
+
toolsetNames,
|
|
826
|
+
});
|
|
827
|
+
|
|
828
|
+
if (toolsetName != null) {
|
|
829
|
+
// toolset member call: the `action` is the member tool name
|
|
830
|
+
const { action, ...memberInput } =
|
|
831
|
+
typeof part.input === 'object' &&
|
|
832
|
+
part.input !== null &&
|
|
833
|
+
!Array.isArray(part.input)
|
|
834
|
+
? (part.input as Record<string, unknown>)
|
|
835
|
+
: {};
|
|
836
|
+
|
|
837
|
+
if (typeof action !== 'string') {
|
|
838
|
+
warnings.push({
|
|
839
|
+
type: 'other',
|
|
840
|
+
message: `toolset tool call for tool ${part.toolName} is missing the action`,
|
|
841
|
+
});
|
|
842
|
+
break;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
anthropicContent.push({
|
|
846
|
+
type: 'tool_use',
|
|
847
|
+
id: part.toolCallId,
|
|
848
|
+
name: action,
|
|
849
|
+
toolset_name: toolsetName,
|
|
850
|
+
input: memberInput,
|
|
851
|
+
...(caller && { caller }),
|
|
852
|
+
cache_control: cacheControl,
|
|
853
|
+
});
|
|
854
|
+
break;
|
|
855
|
+
}
|
|
856
|
+
|
|
807
857
|
anthropicContent.push({
|
|
808
858
|
type: 'tool_use',
|
|
809
859
|
id: part.toolCallId,
|
|
@@ -1352,6 +1402,32 @@ function moveToolUseBlocksToEnd(
|
|
|
1352
1402
|
return result;
|
|
1353
1403
|
}
|
|
1354
1404
|
|
|
1405
|
+
/**
|
|
1406
|
+
* Resolves the Anthropic `toolset_name` for a tool call or tool result. The
|
|
1407
|
+
* toolset is identified either through the tools passed to the request or
|
|
1408
|
+
* through the `toolsetName` provider metadata of a previous response.
|
|
1409
|
+
*/
|
|
1410
|
+
function getAnthropicToolsetName({
|
|
1411
|
+
toolName,
|
|
1412
|
+
providerOptions,
|
|
1413
|
+
toolsetNames,
|
|
1414
|
+
}: {
|
|
1415
|
+
toolName: string;
|
|
1416
|
+
providerOptions: SharedV3ProviderMetadata | undefined;
|
|
1417
|
+
toolsetNames: Record<string, string>;
|
|
1418
|
+
}): string | undefined {
|
|
1419
|
+
const fromTools = toolsetNames[toolName];
|
|
1420
|
+
if (fromTools != null) {
|
|
1421
|
+
return fromTools;
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
const fromMetadata = (
|
|
1425
|
+
providerOptions?.anthropic as { toolsetName?: unknown } | undefined
|
|
1426
|
+
)?.toolsetName;
|
|
1427
|
+
|
|
1428
|
+
return typeof fromMetadata === 'string' ? fromMetadata : undefined;
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1355
1431
|
function getAnthropicCaller(
|
|
1356
1432
|
providerOptions: SharedV3ProviderMetadata | undefined,
|
|
1357
1433
|
): AnthropicToolCallCaller | undefined {
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderToolFactory,
|
|
3
|
+
lazySchema,
|
|
4
|
+
zodSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import { z } from 'zod/v4';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Member tools of the computer toolset. Each member is returned by the API as
|
|
10
|
+
* its own `tool_use` block; the AI SDK exposes it as the `action` of a single
|
|
11
|
+
* computer tool call.
|
|
12
|
+
*/
|
|
13
|
+
export const computerToolset_20260801Members = [
|
|
14
|
+
'screenshot',
|
|
15
|
+
'zoom',
|
|
16
|
+
'left_click',
|
|
17
|
+
'right_click',
|
|
18
|
+
'middle_click',
|
|
19
|
+
'double_click',
|
|
20
|
+
'triple_click',
|
|
21
|
+
'left_click_drag',
|
|
22
|
+
'mouse_move',
|
|
23
|
+
'left_mouse_down',
|
|
24
|
+
'left_mouse_up',
|
|
25
|
+
'cursor_position',
|
|
26
|
+
'scroll',
|
|
27
|
+
'type',
|
|
28
|
+
'key',
|
|
29
|
+
'hold_key',
|
|
30
|
+
'wait',
|
|
31
|
+
] as const;
|
|
32
|
+
|
|
33
|
+
export type ComputerToolset_20260801Member =
|
|
34
|
+
(typeof computerToolset_20260801Members)[number];
|
|
35
|
+
|
|
36
|
+
const computerToolset_20260801InputSchema = lazySchema(() =>
|
|
37
|
+
zodSchema(
|
|
38
|
+
z.object({
|
|
39
|
+
action: z.enum(computerToolset_20260801Members),
|
|
40
|
+
coordinate: z.tuple([z.number().int(), z.number().int()]).optional(),
|
|
41
|
+
duration: z.number().optional(),
|
|
42
|
+
region: z
|
|
43
|
+
.tuple([
|
|
44
|
+
z.number().int(),
|
|
45
|
+
z.number().int(),
|
|
46
|
+
z.number().int(),
|
|
47
|
+
z.number().int(),
|
|
48
|
+
])
|
|
49
|
+
.optional(),
|
|
50
|
+
repeat: z.number().int().optional(),
|
|
51
|
+
scroll_amount: z.number().optional(),
|
|
52
|
+
scroll_direction: z.enum(['up', 'down', 'left', 'right']).optional(),
|
|
53
|
+
start_coordinate: z
|
|
54
|
+
.tuple([z.number().int(), z.number().int()])
|
|
55
|
+
.optional(),
|
|
56
|
+
text: z.string().optional(),
|
|
57
|
+
}),
|
|
58
|
+
),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
export const computerToolset_20260801ArgsSchema = lazySchema(() =>
|
|
62
|
+
zodSchema(
|
|
63
|
+
z.object({
|
|
64
|
+
configs: z
|
|
65
|
+
.partialRecord(
|
|
66
|
+
z.enum(computerToolset_20260801Members),
|
|
67
|
+
z.object({
|
|
68
|
+
enabled: z.boolean().optional(),
|
|
69
|
+
deferLoading: z.boolean().optional(),
|
|
70
|
+
}),
|
|
71
|
+
)
|
|
72
|
+
.optional(),
|
|
73
|
+
}),
|
|
74
|
+
),
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
export const computerToolset_20260801 = createProviderToolFactory<
|
|
78
|
+
{
|
|
79
|
+
/**
|
|
80
|
+
* The member tool that Claude invoked. Each member is returned by the API
|
|
81
|
+
* as a separate `tool_use` block; the AI SDK maps it to the `action`.
|
|
82
|
+
*
|
|
83
|
+
* - `screenshot`: Capture the full display as an image.
|
|
84
|
+
* - `zoom`: Capture a `region` of the screen at full resolution.
|
|
85
|
+
* - `left_click`, `right_click`, `middle_click`, `double_click`, `triple_click`: Click at `coordinate`. `text` may hold modifier keys to hold while clicking.
|
|
86
|
+
* - `left_click_drag`: Drag from `start_coordinate` to `coordinate`.
|
|
87
|
+
* - `mouse_move`: Move the cursor to `coordinate` without clicking.
|
|
88
|
+
* - `left_mouse_down`, `left_mouse_up`: Press or release the left mouse button at the current position.
|
|
89
|
+
* - `cursor_position`: Report the current cursor position as text.
|
|
90
|
+
* - `scroll`: Scroll `scroll_amount` clicks in `scroll_direction` at `coordinate`.
|
|
91
|
+
* - `type`: Type the literal `text`.
|
|
92
|
+
* - `key`: Press a key or key combination (`text`), optionally `repeat` times.
|
|
93
|
+
* - `hold_key`: Hold a key or key combination (`text`) for `duration` seconds.
|
|
94
|
+
* - `wait`: Pause for `duration` seconds.
|
|
95
|
+
*/
|
|
96
|
+
action: ComputerToolset_20260801Member;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* (x, y): Pixel coordinates in the space of the screenshots you return.
|
|
100
|
+
*/
|
|
101
|
+
coordinate?: [number, number];
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Duration in seconds. Used by `hold_key` and `wait`.
|
|
105
|
+
*/
|
|
106
|
+
duration?: number;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* [x1, y1, x2, y2]: The region to zoom into. Used by `zoom`.
|
|
110
|
+
*/
|
|
111
|
+
region?: [number, number, number, number];
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* How many times to press the key. Used by `key`.
|
|
115
|
+
*/
|
|
116
|
+
repeat?: number;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The number of scroll wheel clicks. Used by `scroll`.
|
|
120
|
+
*/
|
|
121
|
+
scroll_amount?: number;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The direction to scroll. Used by `scroll`.
|
|
125
|
+
*/
|
|
126
|
+
scroll_direction?: 'up' | 'down' | 'left' | 'right';
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* (x, y): Where a drag starts. Used by `left_click_drag`.
|
|
130
|
+
*/
|
|
131
|
+
start_coordinate?: [number, number];
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Text to type, a key combination to press or hold, or modifier keys to
|
|
135
|
+
* hold during click and scroll actions.
|
|
136
|
+
*/
|
|
137
|
+
text?: string;
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
/**
|
|
141
|
+
* Per-member configuration. Members you omit keep their defaults
|
|
142
|
+
* (all members enabled, including `zoom`).
|
|
143
|
+
*/
|
|
144
|
+
configs?: Partial<
|
|
145
|
+
Record<
|
|
146
|
+
ComputerToolset_20260801Member,
|
|
147
|
+
{
|
|
148
|
+
/**
|
|
149
|
+
* Whether Claude can use this member tool. Default: true.
|
|
150
|
+
*/
|
|
151
|
+
enabled?: boolean;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Whether this member tool is only loaded once discovered through
|
|
155
|
+
* tool search. Default: false.
|
|
156
|
+
*/
|
|
157
|
+
deferLoading?: boolean;
|
|
158
|
+
}
|
|
159
|
+
>
|
|
160
|
+
>;
|
|
161
|
+
}
|
|
162
|
+
>({
|
|
163
|
+
id: 'anthropic.computer_toolset_20260801',
|
|
164
|
+
inputSchema: computerToolset_20260801InputSchema,
|
|
165
|
+
});
|