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

Function normalize_stop_raw

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

336
337/// Map Grok's `reason` onto the `finish_reason` field used by the record pipeline.
338fn 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
359fn normalize_tool_raw(mut raw: Value, tool_result: Option<&Value>) -> Value {
360 // 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