Map one rollout line to a provider-neutral message, or `None` for non-message events (`response_item`, tool calls, token counts, …).
(
record: &Value,
meta: &CodexMeta,
model: Option<&str>,
path: &Path,
offset: i64,
)
| 357 | /// Map one rollout line to a provider-neutral message, or `None` for non-message |
| 358 | /// events (`response_item`, tool calls, token counts, …). |
| 359 | fn message_from_line( |
| 360 | record: &Value, |
| 361 | meta: &CodexMeta, |
| 362 | model: Option<&str>, |
| 363 | path: &Path, |
| 364 | offset: i64, |
| 365 | ) -> Option<SessionMessageRecord> { |
| 366 | if record.get("type").and_then(Value::as_str) != Some("event_msg") { |
| 367 | return None; |
| 368 | } |
| 369 | let payload = record.get("payload")?; |
| 370 | let role = match payload.get("type").and_then(Value::as_str)? { |
| 371 | "user_message" => "user", |
| 372 | "agent_message" => "assistant", |
| 373 | _ => return None, |
| 374 | }; |
| 375 | let content = payload.get("message")?; |
| 376 | let (text, tool_names) = content_storage_text_and_tools(content, payload.get("tool_calls")); |
| 377 | if text.trim().is_empty() { |
| 378 | return None; |
| 379 | } |
| 380 | |
| 381 | let timestamp = timestamp_from_record(record); |
| 382 | if let Some(goal_context) = codex_goal_context_from_text(&text) { |
| 383 | return Some(goal_context_message( |
| 384 | meta, |
| 385 | model, |
| 386 | path, |
| 387 | offset, |
| 388 | timestamp, |
| 389 | &goal_context, |
| 390 | &message_metadata(payload, Some(&goal_context)), |
| 391 | )); |
| 392 | } |
| 393 | |
| 394 | Some(SessionMessageRecord { |
| 395 | provider: PROVIDER.to_string(), |
| 396 | message_id: format!("{}:{offset}", meta.session_id), |
| 397 | session_id: meta.session_id.clone(), |
| 398 | role: role.to_string(), |
| 399 | timestamp, |
| 400 | ordinal: offset, |
| 401 | text, |
| 402 | kind: Some("message".to_string()), |
| 403 | model: model.map(str::to_string), |
| 404 | tool_names: (!tool_names.is_empty()).then(|| tool_names.join(",")), |
| 405 | source_path: Some(path.to_string_lossy().to_string()), |
| 406 | source_offset: Some(offset), |
| 407 | metadata_json: serde_json::to_string(&message_metadata(payload, None)).ok(), |
| 408 | }) |
| 409 | } |
| 410 | |
| 411 | fn response_item_goal_context_from_line( |
| 412 | record: &Value, |
no test coverage detected