MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / normalize_stop_raw

Function normalize_stop_raw

atomic-agent/src/hooks/grok.rs:396–415  ·  view source on GitHub ↗

Map Grok's `reason` onto the `finish_reason` field used by the record pipeline.

(mut raw: Value, reason: Option<&str>)

Source from the content-addressed store, hash-verified

394
395/// Map Grok's `reason` onto the `finish_reason` field used by the record pipeline.
396fn 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
417fn normalize_tool_raw(mut raw: Value, tool_result: Option<&Value>) -> Value {
418 // Mirror camelCase tool fields into the snake_case keys downstream expects.

Callers 1

parse_eventMethod · 0.70

Calls 1

getMethod · 0.65

Tested by

no test coverage detected