Flatten text-bearing content, including Anthropic tool_result blocks.
(value: Any)
| 1422 | |
| 1423 | |
| 1424 | def _risk_text(value: Any) -> str: |
| 1425 | """Flatten text-bearing content, including Anthropic tool_result blocks.""" |
| 1426 | if value is None: |
| 1427 | return "" |
| 1428 | if isinstance(value, str): |
| 1429 | return value |
| 1430 | if isinstance(value, list): |
| 1431 | parts = [_risk_text(item) for item in value] |
| 1432 | return "\n".join(part for part in parts if part) |
| 1433 | if isinstance(value, dict): |
| 1434 | parts: list[str] = [] |
| 1435 | for key in ("text", "content", "message", "error", "stderr", "stdout"): |
| 1436 | if key in value: |
| 1437 | parts.append(_risk_text(value.get(key))) |
| 1438 | return "\n".join(part for part in parts if part) |
| 1439 | return str(value or "") |
| 1440 | |
| 1441 | |
| 1442 | def _tool_call_command(tool_call: dict[str, Any]) -> str: |
no test coverage detected