Map Grok's `reason` onto the `finish_reason` field used by the record pipeline.
(mut raw: Value, reason: Option<&str>)
| 336 | |
| 337 | /// Map Grok's `reason` onto the `finish_reason` field used by the record pipeline. |
| 338 | fn normalize_stop_raw(mut raw: Value, reason: Option<&str>) -> Value { |
| 339 | let finish = match reason { |
| 340 | Some("end_turn") | None => "stop", |
| 341 | Some("channel_closed") | Some("shutdown") => "session-end", |
| 342 | Some(other) => other, |
| 343 | }; |
| 344 | if let Some(obj) = raw.as_object_mut() { |
| 345 | obj.entry("finish_reason".to_string()) |
| 346 | .or_insert_with(|| Value::String(finish.to_string())); |
| 347 | // Also mirror snake_case aliases the orchestrator may look up. |
| 348 | if let Some(active) = obj.get("stopHookActive").cloned() { |
| 349 | obj.entry("stop_hook_active".to_string()).or_insert(active); |
| 350 | } |
| 351 | if let Some(msg) = obj.get("lastAssistantMessage").cloned() { |
| 352 | obj.entry("last_assistant_message".to_string()) |
| 353 | .or_insert(msg); |
| 354 | } |
| 355 | } |
| 356 | raw |
| 357 | } |
| 358 | |
| 359 | fn normalize_tool_raw(mut raw: Value, tool_result: Option<&Value>) -> Value { |
| 360 | // Mirror camelCase tool fields into the snake_case keys downstream expects. |