@@ -191,3 +191,117 @@ test("Can properly format anthropic messages when given two tool results", async
191191 system : undefined ,
192192 } ) ;
193193} ) ;
194+
195+ test ( "Can properly format messages with bash_code_execution_tool_result blocks" , async ( ) => {
196+ const messageHistory = [
197+ new AIMessage ( {
198+ content : [
199+ {
200+ type : "server_tool_use" ,
201+ id : "bash_call" ,
202+ name : "bash_code_execution" ,
203+ input : { command : "echo 'hello'" } ,
204+ } ,
205+ {
206+ type : "bash_code_execution_tool_result" ,
207+ tool_use_id : "bash_call" ,
208+ content : {
209+ type : "bash_code_execution_result" ,
210+ stdout : "hello\n" ,
211+ stderr : "" ,
212+ return_code : 0 ,
213+ content : [ ] ,
214+ } ,
215+ } ,
216+ ] ,
217+ } ) ,
218+ ] ;
219+
220+ const formattedMessages = _convertMessagesToAnthropicPayload ( messageHistory ) ;
221+
222+ expect ( formattedMessages ) . toEqual ( {
223+ messages : [
224+ {
225+ role : "assistant" ,
226+ content : [
227+ {
228+ type : "server_tool_use" ,
229+ id : "bash_call" ,
230+ name : "bash_code_execution" ,
231+ input : { command : "echo 'hello'" } ,
232+ } ,
233+ {
234+ type : "bash_code_execution_tool_result" ,
235+ tool_use_id : "bash_call" ,
236+ content : {
237+ type : "bash_code_execution_result" ,
238+ stdout : "hello\n" ,
239+ stderr : "" ,
240+ return_code : 0 ,
241+ content : [ ] ,
242+ } ,
243+ } ,
244+ ] ,
245+ } ,
246+ ] ,
247+ system : undefined ,
248+ } ) ;
249+ } ) ;
250+
251+ test ( "Can properly format messages with text_editor_code_execution_tool_result blocks" , async ( ) => {
252+ const messageHistory = [
253+ new AIMessage ( {
254+ content : [
255+ {
256+ type : "server_tool_use" ,
257+ id : "editor_call" ,
258+ name : "text_editor_code_execution" ,
259+ input : { command : "view" , path : "/tmp/test.txt" } ,
260+ } ,
261+ {
262+ type : "text_editor_code_execution_tool_result" ,
263+ tool_use_id : "editor_call" ,
264+ content : {
265+ type : "text_editor_code_execution_view_result" ,
266+ file_type : "text" ,
267+ content : "file contents here" ,
268+ num_lines : 1 ,
269+ start_line : 1 ,
270+ total_lines : 1 ,
271+ } ,
272+ } ,
273+ ] ,
274+ } ) ,
275+ ] ;
276+
277+ const formattedMessages = _convertMessagesToAnthropicPayload ( messageHistory ) ;
278+
279+ expect ( formattedMessages ) . toEqual ( {
280+ messages : [
281+ {
282+ role : "assistant" ,
283+ content : [
284+ {
285+ type : "server_tool_use" ,
286+ id : "editor_call" ,
287+ name : "text_editor_code_execution" ,
288+ input : { command : "view" , path : "/tmp/test.txt" } ,
289+ } ,
290+ {
291+ type : "text_editor_code_execution_tool_result" ,
292+ tool_use_id : "editor_call" ,
293+ content : {
294+ type : "text_editor_code_execution_view_result" ,
295+ file_type : "text" ,
296+ content : "file contents here" ,
297+ num_lines : 1 ,
298+ start_line : 1 ,
299+ total_lines : 1 ,
300+ } ,
301+ } ,
302+ ] ,
303+ } ,
304+ ] ,
305+ system : undefined ,
306+ } ) ;
307+ } ) ;
0 commit comments