11use crate :: codex:: Session ;
22use crate :: codex:: TurnContext ;
3+ use crate :: function_tool:: FunctionCallError ;
34use crate :: protocol:: FileChange ;
45use crate :: protocol:: ReviewDecision ;
56use crate :: safety:: SafetyCheck ;
67use crate :: safety:: assess_patch_safety;
78use codex_apply_patch:: ApplyPatchAction ;
89use codex_apply_patch:: ApplyPatchFileChange ;
9- use codex_protocol:: models:: FunctionCallOutputPayload ;
10- use codex_protocol:: models:: ResponseInputItem ;
1110use std:: collections:: HashMap ;
1211use std:: path:: PathBuf ;
1312
@@ -17,7 +16,7 @@ pub(crate) enum InternalApplyPatchInvocation {
1716 /// The `apply_patch` call was handled programmatically, without any sort
1817 /// of sandbox, because the user explicitly approved it. This is the
1918 /// result to use with the `shell` function call that contained `apply_patch`.
20- Output ( ResponseInputItem ) ,
19+ Output ( Result < String , FunctionCallError > ) ,
2120
2221 /// The `apply_patch` call was approved, either automatically because it
2322 /// appears that it should be allowed based on the user's sandbox policy
@@ -33,12 +32,6 @@ pub(crate) struct ApplyPatchExec {
3332 pub ( crate ) user_explicitly_approved_this_action : bool ,
3433}
3534
36- impl From < ResponseInputItem > for InternalApplyPatchInvocation {
37- fn from ( item : ResponseInputItem ) -> Self {
38- InternalApplyPatchInvocation :: Output ( item)
39- }
40- }
41-
4235pub ( crate ) async fn apply_patch (
4336 sess : & Session ,
4437 turn_context : & TurnContext ,
@@ -77,25 +70,15 @@ pub(crate) async fn apply_patch(
7770 } )
7871 }
7972 ReviewDecision :: Denied | ReviewDecision :: Abort => {
80- ResponseInputItem :: FunctionCallOutput {
81- call_id : call_id. to_owned ( ) ,
82- output : FunctionCallOutputPayload {
83- content : "patch rejected by user" . to_string ( ) ,
84- success : Some ( false ) ,
85- } ,
86- }
87- . into ( )
73+ InternalApplyPatchInvocation :: Output ( Err ( FunctionCallError :: RespondToModel (
74+ "patch rejected by user" . to_string ( ) ,
75+ ) ) )
8876 }
8977 }
9078 }
91- SafetyCheck :: Reject { reason } => ResponseInputItem :: FunctionCallOutput {
92- call_id : call_id. to_owned ( ) ,
93- output : FunctionCallOutputPayload {
94- content : format ! ( "patch rejected: {reason}" ) ,
95- success : Some ( false ) ,
96- } ,
97- }
98- . into ( ) ,
79+ SafetyCheck :: Reject { reason } => InternalApplyPatchInvocation :: Output ( Err (
80+ FunctionCallError :: RespondToModel ( format ! ( "patch rejected: {reason}" ) ) ,
81+ ) ) ,
9982 }
10083}
10184
0 commit comments