Skip to content

Commit 3004b14

Browse files
authored
feat(provider/anthropic): add bash_20250124 and text_editor_20250124 (#5024)
1 parent 822b93d commit 3004b14

File tree

5 files changed

+153
-3
lines changed

5 files changed

+153
-3
lines changed

.changeset/orange-rocks-wash.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ai-sdk/anthropic': patch
3+
---
4+
5+
feat(provider/anthropic): add bash_20250124 and text_editor_20250124 tools

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ dist-ssr
1111
server/dist
1212
public/dist
1313
.turbo
14-
test-results
14+
test-results

packages/anthropic/src/anthropic-api-types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ export type AnthropicTool =
9999
}
100100
| {
101101
name: string;
102-
type: 'text_editor_20241022';
102+
type: 'text_editor_20250124' | 'text_editor_20241022';
103103
}
104104
| {
105105
name: string;
106-
type: 'bash_20241022';
106+
type: 'bash_20250124' | 'bash_20241022';
107107
};
108108

109109
export type AnthropicToolChoice =

packages/anthropic/src/anthropic-prepare-tools.ts

+14
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,27 @@ export function prepareTools(
5858
display_number: tool.args.displayNumber as number,
5959
});
6060
break;
61+
case 'anthropic.text_editor_20250124':
62+
betas.add('computer-use-2025-01-24');
63+
anthropicTools.push({
64+
name: tool.name,
65+
type: 'text_editor_20250124',
66+
});
67+
break;
6168
case 'anthropic.text_editor_20241022':
6269
betas.add('computer-use-2024-10-22');
6370
anthropicTools.push({
6471
name: tool.name,
6572
type: 'text_editor_20241022',
6673
});
6774
break;
75+
case 'anthropic.bash_20250124':
76+
betas.add('computer-use-2025-01-24');
77+
anthropicTools.push({
78+
name: tool.name,
79+
type: 'bash_20250124',
80+
});
81+
break;
6882
case 'anthropic.bash_20241022':
6983
betas.add('computer-use-2024-10-22');
7084
anthropicTools.push({

packages/anthropic/src/anthropic-tools.ts

+131
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,54 @@ function bashTool_20241022<RESULT>(
6969
};
7070
}
7171

72+
const Bash20250124Parameters = z.object({
73+
command: z.string(),
74+
restart: z.boolean().optional(),
75+
});
76+
77+
/**
78+
* Creates a tool for running a bash command. Must have name "bash".
79+
*
80+
* Image results are supported.
81+
*
82+
* @param execute - The function to execute the tool. Optional.
83+
*/
84+
function bashTool_20250124<RESULT>(
85+
options: {
86+
execute?: ExecuteFunction<
87+
{
88+
/**
89+
* The bash command to run. Required unless the tool is being restarted.
90+
*/
91+
command: string;
92+
93+
/**
94+
* Specifying true will restart this tool. Otherwise, leave this unspecified.
95+
*/
96+
restart?: boolean;
97+
},
98+
RESULT
99+
>;
100+
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
101+
} = {},
102+
): {
103+
type: 'provider-defined';
104+
id: 'anthropic.bash_20250124';
105+
args: {};
106+
parameters: typeof Bash20250124Parameters;
107+
execute: ExecuteFunction<z.infer<typeof Bash20250124Parameters>, RESULT>;
108+
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
109+
} {
110+
return {
111+
type: 'provider-defined',
112+
id: 'anthropic.bash_20250124',
113+
args: {},
114+
parameters: Bash20250124Parameters,
115+
execute: options.execute,
116+
experimental_toToolResultContent: options.experimental_toToolResultContent,
117+
};
118+
}
119+
72120
const TextEditor20241022Parameters = z.object({
73121
command: z.enum(['view', 'create', 'str_replace', 'insert', 'undo_edit']),
74122
path: z.string(),
@@ -150,6 +198,87 @@ function textEditorTool_20241022<RESULT>(
150198
};
151199
}
152200

201+
const TextEditor20250124Parameters = z.object({
202+
command: z.enum(['view', 'create', 'str_replace', 'insert', 'undo_edit']),
203+
path: z.string(),
204+
file_text: z.string().optional(),
205+
insert_line: z.number().int().optional(),
206+
new_str: z.string().optional(),
207+
old_str: z.string().optional(),
208+
view_range: z.array(z.number().int()).optional(),
209+
});
210+
211+
/**
212+
* Creates a tool for editing text. Must have name "str_replace_editor".
213+
*
214+
* Image results are supported.
215+
*
216+
* @param execute - The function to execute the tool. Optional.
217+
*/
218+
function textEditorTool_20250124<RESULT>(
219+
options: {
220+
execute?: ExecuteFunction<
221+
{
222+
/**
223+
* The commands to run. Allowed options are: `view`, `create`, `str_replace`, `insert`, `undo_edit`.
224+
*/
225+
command: 'view' | 'create' | 'str_replace' | 'insert' | 'undo_edit';
226+
227+
/**
228+
* Absolute path to file or directory, e.g. `/repo/file.py` or `/repo`.
229+
*/
230+
path: string;
231+
232+
/**
233+
* Required parameter of `create` command, with the content of the file to be created.
234+
*/
235+
file_text?: string;
236+
237+
/**
238+
* Required parameter of `insert` command. The `new_str` will be inserted AFTER the line `insert_line` of `path`.
239+
*/
240+
insert_line?: number;
241+
242+
/**
243+
* Optional parameter of `str_replace` command containing the new string (if not given, no string will be added). Required parameter of `insert` command containing the string to insert.
244+
*/
245+
new_str?: string;
246+
247+
/**
248+
* Required parameter of `str_replace` command containing the string in `path` to replace.
249+
*/
250+
old_str?: string;
251+
252+
/**
253+
* Optional parameter of `view` command when `path` points to a file. If none is given, the full file is shown. If provided, the file will be shown in the indicated line number range, e.g. [11, 12] will show lines 11 and 12. Indexing at 1 to start. Setting `[start_line, -1]` shows all lines from `start_line` to the end of the file.
254+
*/
255+
view_range?: number[];
256+
},
257+
RESULT
258+
>;
259+
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
260+
} = {},
261+
): {
262+
type: 'provider-defined';
263+
id: 'anthropic.text_editor_20250124';
264+
args: {};
265+
parameters: typeof TextEditor20250124Parameters;
266+
execute: ExecuteFunction<
267+
z.infer<typeof TextEditor20250124Parameters>,
268+
RESULT
269+
>;
270+
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
271+
} {
272+
return {
273+
type: 'provider-defined',
274+
id: 'anthropic.text_editor_20250124',
275+
args: {},
276+
parameters: TextEditor20250124Parameters,
277+
execute: options.execute,
278+
experimental_toToolResultContent: options.experimental_toToolResultContent,
279+
};
280+
}
281+
153282
const Computer20241022Parameters = z.object({
154283
action: z.enum([
155284
'key',
@@ -383,7 +512,9 @@ function computerTool_20250124<RESULT>(options: {
383512

384513
export const anthropicTools = {
385514
bash_20241022: bashTool_20241022,
515+
bash_20250124: bashTool_20250124,
386516
textEditor_20241022: textEditorTool_20241022,
517+
textEditor_20250124: textEditorTool_20250124,
387518
computer_20241022: computerTool_20241022,
388519
computer_20250124: computerTool_20250124,
389520
};

0 commit comments

Comments
 (0)