| 307 | } |
| 308 | |
| 309 | fn wait_for_turn_summary( |
| 310 | line_rx: &mpsc::Receiver<std::io::Result<String>>, |
| 311 | deadline: Instant, |
| 312 | ) -> Result<CodexAppServerSummary> { |
| 313 | let mut text = String::new(); |
| 314 | let mut model = None; |
| 315 | loop { |
| 316 | let line = recv_line(line_rx, deadline)?; |
| 317 | let value: Value = serde_json::from_str(&line)?; |
| 318 | if model.is_none() { |
| 319 | model = find_model_id(&value); |
| 320 | } |
| 321 | if let Some(error) = value.get("error") { |
| 322 | return Err(TraceDecayError::Config { |
| 323 | message: format!("codex app-server turn failed: {error}"), |
| 324 | }); |
| 325 | } |
| 326 | match value.get("method").and_then(Value::as_str) { |
| 327 | Some("item/agentMessage/delta") => { |
| 328 | if let Some(delta) = value.pointer("/params/delta").and_then(Value::as_str) { |
| 329 | text.push_str(delta); |
| 330 | } |
| 331 | } |
| 332 | Some("item/completed") if text.trim().is_empty() => { |
| 333 | if let Some(item_text) = collect_item_text(value.get("params")) { |
| 334 | text.push_str(&item_text); |
| 335 | } |
| 336 | } |
| 337 | Some("turn/completed") => { |
| 338 | return Ok(CodexAppServerSummary { text, model }); |
| 339 | } |
| 340 | _ => {} |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | fn recv_line( |
| 346 | line_rx: &mpsc::Receiver<std::io::Result<String>>, |