@ai-sdk/anthropic 4.0.59 → 4.0.60
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.ts +47 -1
- package/dist/index.js +958 -559
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +84 -2
- package/dist/internal/index.js +906 -507
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +125 -14
- package/package.json +1 -1
- package/src/anthropic-api.ts +23 -0
- package/src/anthropic-language-model-options.ts +13 -3
- package/src/anthropic-language-model.ts +287 -5
- package/src/anthropic-prepare-tools.ts +76 -0
- package/src/anthropic-tools.ts +25 -0
- package/src/convert-to-anthropic-prompt.ts +74 -1
- package/src/tool/computer-toolset_20260801.ts +165 -0
|
@@ -81,12 +81,20 @@ export async function convertToAnthropicPrompt({
|
|
|
81
81
|
warnings,
|
|
82
82
|
cacheControlValidator,
|
|
83
83
|
toolNameMapping,
|
|
84
|
+
toolsetNames = {},
|
|
84
85
|
}: {
|
|
85
86
|
prompt: LanguageModelV4Prompt;
|
|
86
87
|
sendReasoning: boolean;
|
|
87
88
|
warnings: SharedV4Warning[];
|
|
88
89
|
cacheControlValidator?: CacheControlValidator;
|
|
89
90
|
toolNameMapping: ToolNameMapping;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Maps custom tool names of toolset tools (e.g. the computer toolset) to
|
|
94
|
+
* the Anthropic `toolset_name`. Tool calls and results of these tools are
|
|
95
|
+
* serialized as toolset member calls.
|
|
96
|
+
*/
|
|
97
|
+
toolsetNames?: Record<string, string>;
|
|
90
98
|
}): Promise<{
|
|
91
99
|
prompt: AnthropicPrompt;
|
|
92
100
|
betas: Set<string>;
|
|
@@ -258,7 +266,7 @@ export async function convertToAnthropicPrompt({
|
|
|
258
266
|
betas.add('mid-conversation-system-clear-at-2026-08-21');
|
|
259
267
|
}
|
|
260
268
|
if (message.effort != null) {
|
|
261
|
-
betas.add('mid-conversation-
|
|
269
|
+
betas.add('mid-conversation-output-config-2026-07-01');
|
|
262
270
|
}
|
|
263
271
|
}
|
|
264
272
|
}
|
|
@@ -636,9 +644,16 @@ export async function convertToAnthropicPrompt({
|
|
|
636
644
|
break;
|
|
637
645
|
}
|
|
638
646
|
|
|
647
|
+
const toolsetName = getAnthropicToolsetName({
|
|
648
|
+
toolName: part.toolName,
|
|
649
|
+
providerOptions: part.providerOptions,
|
|
650
|
+
toolsetNames,
|
|
651
|
+
});
|
|
652
|
+
|
|
639
653
|
anthropicContent.push({
|
|
640
654
|
type: 'tool_result',
|
|
641
655
|
tool_use_id: part.toolCallId,
|
|
656
|
+
...(toolsetName != null && { toolset_name: toolsetName }),
|
|
642
657
|
content: contentValue,
|
|
643
658
|
is_error:
|
|
644
659
|
output.type === 'error-text' || output.type === 'error-json'
|
|
@@ -902,6 +917,38 @@ export async function convertToAnthropicPrompt({
|
|
|
902
917
|
break;
|
|
903
918
|
}
|
|
904
919
|
|
|
920
|
+
const toolsetName = getAnthropicToolsetName({
|
|
921
|
+
toolName: part.toolName,
|
|
922
|
+
providerOptions: part.providerOptions,
|
|
923
|
+
toolsetNames,
|
|
924
|
+
});
|
|
925
|
+
|
|
926
|
+
if (toolsetName != null) {
|
|
927
|
+
// toolset member call: the `action` is the member tool name
|
|
928
|
+
const { action, ...memberInput } = toAnthropicToolInput(
|
|
929
|
+
part.input,
|
|
930
|
+
);
|
|
931
|
+
|
|
932
|
+
if (typeof action !== 'string') {
|
|
933
|
+
warnings.push({
|
|
934
|
+
type: 'other',
|
|
935
|
+
message: `toolset tool call for tool ${part.toolName} is missing the action`,
|
|
936
|
+
});
|
|
937
|
+
break;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
anthropicContent.push({
|
|
941
|
+
type: 'tool_use',
|
|
942
|
+
id: part.toolCallId,
|
|
943
|
+
name: action,
|
|
944
|
+
toolset_name: toolsetName,
|
|
945
|
+
input: memberInput,
|
|
946
|
+
...(caller && { caller }),
|
|
947
|
+
cache_control: cacheControl,
|
|
948
|
+
});
|
|
949
|
+
break;
|
|
950
|
+
}
|
|
951
|
+
|
|
905
952
|
anthropicContent.push({
|
|
906
953
|
type: 'tool_use',
|
|
907
954
|
id: part.toolCallId,
|
|
@@ -1457,6 +1504,32 @@ function moveToolUseBlocksToEnd(
|
|
|
1457
1504
|
return result;
|
|
1458
1505
|
}
|
|
1459
1506
|
|
|
1507
|
+
/**
|
|
1508
|
+
* Resolves the Anthropic `toolset_name` for a tool call or tool result. The
|
|
1509
|
+
* toolset is identified either through the tools passed to the request or
|
|
1510
|
+
* through the `toolsetName` provider metadata of a previous response.
|
|
1511
|
+
*/
|
|
1512
|
+
function getAnthropicToolsetName({
|
|
1513
|
+
toolName,
|
|
1514
|
+
providerOptions,
|
|
1515
|
+
toolsetNames,
|
|
1516
|
+
}: {
|
|
1517
|
+
toolName: string;
|
|
1518
|
+
providerOptions: SharedV4ProviderMetadata | undefined;
|
|
1519
|
+
toolsetNames: Record<string, string>;
|
|
1520
|
+
}): string | undefined {
|
|
1521
|
+
const fromTools = toolsetNames[toolName];
|
|
1522
|
+
if (fromTools != null) {
|
|
1523
|
+
return fromTools;
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
const fromMetadata = (
|
|
1527
|
+
providerOptions?.anthropic as { toolsetName?: unknown } | undefined
|
|
1528
|
+
)?.toolsetName;
|
|
1529
|
+
|
|
1530
|
+
return typeof fromMetadata === 'string' ? fromMetadata : undefined;
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1460
1533
|
function getAnthropicCaller(
|
|
1461
1534
|
providerOptions: SharedV4ProviderMetadata | undefined,
|
|
1462
1535
|
): AnthropicToolCallCaller | undefined {
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderDefinedToolFactory,
|
|
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 = createProviderDefinedToolFactory<
|
|
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
|
+
});
|