MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / _flatten_block

Function _flatten_block

uncommon_route/normalize.py:22–44  ·  view source on GitHub ↗
(block: Any)

Source from the content-addressed store, hash-verified

20
21
22def _flatten_block(block: Any) -> str:
23 if not isinstance(block, dict):
24 return ""
25 btype = block.get("type", "")
26 if btype == "text":
27 return str(block.get("text", ""))
28 if btype == "tool_use":
29 name = block.get("name", "")
30 args = block.get("input", block.get("arguments", {}))
31 canonical = json.dumps(args, sort_keys=True, separators=(",", ":"), ensure_ascii=False)
32 return f"[tool_use:{name}({canonical})]"
33 if btype == "tool_result":
34 inner = block.get("content", "")
35 if not inner:
36 return ""
37 if isinstance(inner, str):
38 return inner
39 if isinstance(inner, list):
40 return " ".join(_flatten_block(b) for b in inner)
41 return ""
42 if btype in ("image", "input_image"):
43 return "[image]"
44 return ""
45
46
47def normalize_message_text(message: dict[str, Any]) -> str:

Callers 1

normalize_message_textFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected