| 501 | } |
| 502 | |
| 503 | fn normalize_stop_raw(mut raw: Value) -> Value { |
| 504 | let stop_hook_active = raw.get("stop_hook_active").and_then(Value::as_bool); |
| 505 | if let Some(active) = stop_hook_active { |
| 506 | if let Some(obj) = raw.as_object_mut() { |
| 507 | obj.entry("finish_reason".to_string()).or_insert_with(|| { |
| 508 | Value::String(if active { "tool-calls" } else { "stop" }.to_string()) |
| 509 | }); |
| 510 | } |
| 511 | } |
| 512 | raw |
| 513 | } |
| 514 | |
| 515 | fn normalize_tool_raw(mut raw: Value) -> Value { |
| 516 | let Some(response) = raw.get("tool_response").cloned() else { |