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

Function normalize_stop_raw

atomic-agent/src/hooks/grok.rs:339–358  ·  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

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