@@ -240,3 +240,117 @@ test("Drop content blocks that we don't know how to handle", async () => {
240240 system : undefined ,
241241 } ) ;
242242} ) ;
243+
244+ test ( "Can properly format messages with bash_code_execution_tool_result blocks" , async ( ) => {
245+ const messageHistory = [
246+ new AIMessage ( {
247+ content : [
248+ {
249+ type : "server_tool_use" ,
250+ id : "bash_call" ,
251+ name : "bash_code_execution" ,
252+ input : { command : "echo 'hello'" } ,
253+ } ,
254+ {
255+ type : "bash_code_execution_tool_result" ,
256+ tool_use_id : "bash_call" ,
257+ content : {
258+ type : "bash_code_execution_result" ,
259+ stdout : "hello\n" ,
260+ stderr : "" ,
261+ return_code : 0 ,
262+ content : [ ] ,
263+ } ,
264+ } ,
265+ ] ,
266+ } ) ,
267+ ] ;
268+
269+ const formattedMessages = _convertMessagesToAnthropicPayload ( messageHistory ) ;
270+
271+ expect ( formattedMessages ) . toEqual ( {
272+ messages : [
273+ {
274+ role : "assistant" ,
275+ content : [
276+ {
277+ type : "server_tool_use" ,
278+ id : "bash_call" ,
279+ name : "bash_code_execution" ,
280+ input : { command : "echo 'hello'" } ,
281+ } ,
282+ {
283+ type : "bash_code_execution_tool_result" ,
284+ tool_use_id : "bash_call" ,
285+ content : {
286+ type : "bash_code_execution_result" ,
287+ stdout : "hello\n" ,
288+ stderr : "" ,
289+ return_code : 0 ,
290+ content : [ ] ,
291+ } ,
292+ } ,
293+ ] ,
294+ } ,
295+ ] ,
296+ system : undefined ,
297+ } ) ;
298+ } ) ;
299+
300+ test ( "Can properly format messages with text_editor_code_execution_tool_result blocks" , async ( ) => {
301+ const messageHistory = [
302+ new AIMessage ( {
303+ content : [
304+ {
305+ type : "server_tool_use" ,
306+ id : "editor_call" ,
307+ name : "text_editor_code_execution" ,
308+ input : { command : "view" , path : "/tmp/test.txt" } ,
309+ } ,
310+ {
311+ type : "text_editor_code_execution_tool_result" ,
312+ tool_use_id : "editor_call" ,
313+ content : {
314+ type : "text_editor_code_execution_view_result" ,
315+ file_type : "text" ,
316+ content : "file contents here" ,
317+ num_lines : 1 ,
318+ start_line : 1 ,
319+ total_lines : 1 ,
320+ } ,
321+ } ,
322+ ] ,
323+ } ) ,
324+ ] ;
325+
326+ const formattedMessages = _convertMessagesToAnthropicPayload ( messageHistory ) ;
327+
328+ expect ( formattedMessages ) . toEqual ( {
329+ messages : [
330+ {
331+ role : "assistant" ,
332+ content : [
333+ {
334+ type : "server_tool_use" ,
335+ id : "editor_call" ,
336+ name : "text_editor_code_execution" ,
337+ input : { command : "view" , path : "/tmp/test.txt" } ,
338+ } ,
339+ {
340+ type : "text_editor_code_execution_tool_result" ,
341+ tool_use_id : "editor_call" ,
342+ content : {
343+ type : "text_editor_code_execution_view_result" ,
344+ file_type : "text" ,
345+ content : "file contents here" ,
346+ num_lines : 1 ,
347+ start_line : 1 ,
348+ total_lines : 1 ,
349+ } ,
350+ } ,
351+ ] ,
352+ } ,
353+ ] ,
354+ system : undefined ,
355+ } ) ;
356+ } ) ;
0 commit comments