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

Function normalize_tool_raw

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

Source from the content-addressed store, hash-verified

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