Map Grok's `reason` onto the `finish_reason` field used by the record pipeline.
(mut raw: Value, reason: Option<&str>)
| 394 | |
| 395 | /// Map Grok's `reason` onto the `finish_reason` field used by the record pipeline. |
| 396 | fn normalize_stop_raw(mut raw: Value, reason: Option<&str>) -> Value { |
| 397 | let finish = match reason { |
| 398 | Some("end_turn") | None => "stop", |
| 399 | Some("channel_closed") | Some("shutdown") => "session-end", |
| 400 | Some(other) => other, |
| 401 | }; |
| 402 | if let Some(obj) = raw.as_object_mut() { |
| 403 | obj.entry("finish_reason".to_string()) |
| 404 | .or_insert_with(|| Value::String(finish.to_string())); |
| 405 | // Also mirror snake_case aliases the orchestrator may look up. |
| 406 | if let Some(active) = obj.get("stopHookActive").cloned() { |
| 407 | obj.entry("stop_hook_active".to_string()).or_insert(active); |
| 408 | } |
| 409 | if let Some(msg) = obj.get("lastAssistantMessage").cloned() { |
| 410 | obj.entry("last_assistant_message".to_string()) |
| 411 | .or_insert(msg); |
| 412 | } |
| 413 | } |
| 414 | raw |
| 415 | } |
| 416 | |
| 417 | fn normalize_tool_raw(mut raw: Value, tool_result: Option<&Value>) -> Value { |
| 418 | // Mirror camelCase tool fields into the snake_case keys downstream expects. |