@@ -1406,6 +1406,18 @@ async fn run_task(
14061406 } ,
14071407 ) ;
14081408 }
1409+ (
1410+ ResponseItem :: CustomToolCall { .. } ,
1411+ Some ( ResponseInputItem :: CustomToolCallOutput { call_id, output } ) ,
1412+ ) => {
1413+ items_to_record_in_conversation_history. push ( item) ;
1414+ items_to_record_in_conversation_history. push (
1415+ ResponseItem :: CustomToolCallOutput {
1416+ call_id : call_id. clone ( ) ,
1417+ output : output. clone ( ) ,
1418+ } ,
1419+ ) ;
1420+ }
14091421 (
14101422 ResponseItem :: FunctionCall { .. } ,
14111423 Some ( ResponseInputItem :: McpToolCallOutput { call_id, result } ) ,
@@ -1586,6 +1598,7 @@ async fn try_run_turn(
15861598 call_id : Some ( call_id) ,
15871599 ..
15881600 } => Some ( call_id) ,
1601+ ResponseItem :: CustomToolCallOutput { call_id, .. } => Some ( call_id) ,
15891602 _ => None ,
15901603 } )
15911604 . collect :: < Vec < _ > > ( ) ;
@@ -1603,6 +1616,7 @@ async fn try_run_turn(
16031616 call_id : Some ( call_id) ,
16041617 ..
16051618 } => Some ( call_id) ,
1619+ ResponseItem :: CustomToolCall { call_id, .. } => Some ( call_id) ,
16061620 _ => None ,
16071621 } )
16081622 . filter_map ( |call_id| {
@@ -1612,12 +1626,9 @@ async fn try_run_turn(
16121626 Some ( call_id. clone ( ) )
16131627 }
16141628 } )
1615- . map ( |call_id| ResponseItem :: FunctionCallOutput {
1629+ . map ( |call_id| ResponseItem :: CustomToolCallOutput {
16161630 call_id : call_id. clone ( ) ,
1617- output : FunctionCallOutputPayload {
1618- content : "aborted" . to_string ( ) ,
1619- success : Some ( false ) ,
1620- } ,
1631+ output : "aborted" . to_string ( ) ,
16211632 } )
16221633 . collect :: < Vec < _ > > ( )
16231634 } ;
@@ -1882,7 +1893,7 @@ async fn handle_response_item(
18821893 call_id,
18831894 ..
18841895 } => {
1885- info ! ( "FunctionCall: {arguments}" ) ;
1896+ info ! ( "FunctionCall: {name}({ arguments}) " ) ;
18861897 Some (
18871898 handle_function_call (
18881899 sess,
@@ -1939,10 +1950,32 @@ async fn handle_response_item(
19391950 . await ,
19401951 )
19411952 }
1953+ ResponseItem :: CustomToolCall {
1954+ id : _,
1955+ call_id,
1956+ name,
1957+ input,
1958+ status : _,
1959+ } => Some (
1960+ handle_custom_tool_call (
1961+ sess,
1962+ turn_context,
1963+ turn_diff_tracker,
1964+ sub_id. to_string ( ) ,
1965+ name,
1966+ input,
1967+ call_id,
1968+ )
1969+ . await ,
1970+ ) ,
19421971 ResponseItem :: FunctionCallOutput { .. } => {
19431972 debug ! ( "unexpected FunctionCallOutput from stream" ) ;
19441973 None
19451974 }
1975+ ResponseItem :: CustomToolCallOutput { .. } => {
1976+ debug ! ( "unexpected CustomToolCallOutput from stream" ) ;
1977+ None
1978+ }
19461979 ResponseItem :: Other => None ,
19471980 } ;
19481981 Ok ( output)
@@ -2032,6 +2065,58 @@ async fn handle_function_call(
20322065 }
20332066}
20342067
2068+ async fn handle_custom_tool_call (
2069+ sess : & Session ,
2070+ turn_context : & TurnContext ,
2071+ turn_diff_tracker : & mut TurnDiffTracker ,
2072+ sub_id : String ,
2073+ name : String ,
2074+ input : String ,
2075+ call_id : String ,
2076+ ) -> ResponseInputItem {
2077+ info ! ( "CustomToolCall: {name} {input}" ) ;
2078+ match name. as_str ( ) {
2079+ "apply_patch" => {
2080+ let exec_params = ExecParams {
2081+ command : vec ! [ "apply_patch" . to_string( ) , input. clone( ) ] ,
2082+ cwd : turn_context. cwd . clone ( ) ,
2083+ timeout_ms : None ,
2084+ env : HashMap :: new ( ) ,
2085+ with_escalated_permissions : None ,
2086+ justification : None ,
2087+ } ;
2088+ let resp = handle_container_exec_with_params (
2089+ exec_params,
2090+ sess,
2091+ turn_context,
2092+ turn_diff_tracker,
2093+ sub_id,
2094+ call_id,
2095+ )
2096+ . await ;
2097+
2098+ // Convert function-call style output into a custom tool call output
2099+ match resp {
2100+ ResponseInputItem :: FunctionCallOutput { call_id, output } => {
2101+ ResponseInputItem :: CustomToolCallOutput {
2102+ call_id,
2103+ output : output. content ,
2104+ }
2105+ }
2106+ // Pass through if already a custom tool output or other variant
2107+ other => other,
2108+ }
2109+ }
2110+ _ => {
2111+ debug ! ( "unexpected CustomToolCall from stream" ) ;
2112+ ResponseInputItem :: CustomToolCallOutput {
2113+ call_id,
2114+ output : format ! ( "unsupported custom tool call: {name}" ) ,
2115+ }
2116+ }
2117+ }
2118+ }
2119+
20352120fn to_exec_params ( params : ShellToolCallParams , turn_context : & TurnContext ) -> ExecParams {
20362121 ExecParams {
20372122 command : params. command ,
0 commit comments