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

Function normalize_tool_raw

atomic-agent/src/hooks/grok.rs:359–397  ·  view source on GitHub ↗
(mut raw: Value, tool_result: Option<&Value>)

Source from the content-addressed store, hash-verified

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.
361 if let Some(obj) = raw.as_object_mut() {
362 if let Some(name) = obj.get("toolName").cloned() {
363 obj.entry("tool_name".to_string()).or_insert(name);
364 }
365 if let Some(id) = obj.get("toolUseId").cloned() {
366 obj.entry("tool_use_id".to_string()).or_insert(id);
367 }
368 if let Some(input) = obj.get("toolInput").cloned() {
369 obj.entry("tool_input".to_string()).or_insert(input);
370 }
371 }
372
373 let result = tool_result
374 .cloned()
375 .or_else(|| raw.get("toolResult").cloned())
376 .or_else(|| raw.get("tool_response").cloned());
377
378 if let Some(response) = result {
379 if let Some(output) = extract_tool_output(&response) {
380 insert_if_missing(&mut raw, "tool_output", Value::String(output));
381 }
382 if response.get("error").is_some() {
383 insert_if_missing(&mut raw, "status", Value::String("error".to_string()));
384 } else {
385 insert_if_missing(&mut raw, "status", Value::String("completed".to_string()));
386 }
387 // Keep a snake_case alias of the result for shared tooling.
388 insert_if_missing(&mut raw, "tool_response", response);
389 }
390
391 // File path from tool input when present.
392 if let Some(path) = extract_file_path(raw.get("toolInput").or_else(|| raw.get("tool_input"))) {
393 insert_if_missing(&mut raw, "file_path", Value::String(path));
394 }
395
396 raw
397}
398
399fn extract_tool_output(response: &Value) -> Option<String> {
400 if let Some(text) = response.as_str() {

Callers 1

parse_eventMethod · 0.70

Calls 4

extract_tool_outputFunction · 0.70
insert_if_missingFunction · 0.70
extract_file_pathFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected