@@ -4,7 +4,7 @@ use codex_core::protocol::{AskForApproval, Event, EventMsg, InputItem};
44use codex_core:: { AuthManager , ConversationManager } ;
55use codex_protocol:: config_types:: SandboxMode ;
66use pyo3:: prelude:: * ;
7- use pyo3_serde :: Serializer ;
7+ use pyo3 :: types :: { PyDict , PyList , PyString } ;
88use serde_json:: Value as JsonValue ;
99use std:: path:: PathBuf ;
1010
@@ -23,7 +23,7 @@ fn run_exec_collect(
2323 // Convert serde_json::Value -> PyObject
2424 let mut out = Vec :: with_capacity ( events. len ( ) ) ;
2525 for v in events {
26- let obj = pyo3_serde :: to_py ( py, & v) . map_err ( to_py ) ?;
26+ let obj = json_to_py ( py, & v) ?;
2727 out. push ( obj) ;
2828 }
2929 Ok ( out)
@@ -105,3 +105,35 @@ fn codex_native(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
105105 Ok ( ( ) )
106106}
107107
108+ fn json_to_py ( py : Python < ' _ > , v : & JsonValue ) -> PyResult < PyObject > {
109+ Ok ( match v {
110+ JsonValue :: Null => py. None ( ) . into_py ( py) ,
111+ JsonValue :: Bool ( b) => b. into_py ( py) ,
112+ JsonValue :: Number ( n) => {
113+ if let Some ( i) = n. as_i64 ( ) {
114+ i. into_py ( py)
115+ } else if let Some ( u) = n. as_u64 ( ) {
116+ u. into_py ( py)
117+ } else if let Some ( f) = n. as_f64 ( ) {
118+ f. into_py ( py)
119+ } else {
120+ py. None ( ) . into_py ( py)
121+ }
122+ }
123+ JsonValue :: String ( s) => PyString :: new ( py, s) . into_py ( py) ,
124+ JsonValue :: Array ( arr) => {
125+ let list = PyList :: empty ( py) ;
126+ for item in arr {
127+ list. append ( json_to_py ( py, item) ?) ?;
128+ }
129+ list. into_py ( py)
130+ }
131+ JsonValue :: Object ( map) => {
132+ let dict = PyDict :: new ( py) ;
133+ for ( k, val) in map. iter ( ) {
134+ dict. set_item ( k, json_to_py ( py, val) ?) ?;
135+ }
136+ dict. into_py ( py)
137+ }
138+ } )
139+ }
0 commit comments