(block: dict, lines: List[str], skip_subheading: bool)
| 655 | |
| 656 | |
| 657 | def _plain_block_lines(block: dict, lines: List[str], skip_subheading: bool) -> None: |
| 658 | block_type = block.get("type") |
| 659 | |
| 660 | if block_type == "text": |
| 661 | text = block.get("text") |
| 662 | stripped = strip_top_level_internal_text(text) if isinstance(text, str) else "" |
| 663 | if stripped: |
| 664 | lines.append(stripped) |
| 665 | lines.append("") |
| 666 | return |
| 667 | |
| 668 | if block_type == "tool_use": |
| 669 | name = block.get("name") |
| 670 | name = name if isinstance(name, str) else "unknown" |
| 671 | lines.append(f"Tool Use: {name}") |
| 672 | tool_input = block.get("input") |
| 673 | if tool_input is not None: |
| 674 | lines.append(safe_stringify(tool_input, 2)) |
| 675 | lines.append("") |
| 676 | return |
| 677 | |
| 678 | if block_type == "tool_result": |
| 679 | if not skip_subheading: |
| 680 | lines.append("Tool Result") |
| 681 | result_content = block.get("content") |
| 682 | if result_content is not None: |
| 683 | as_string = ( |
| 684 | strip_system_reminder_blocks(result_content) |
| 685 | if isinstance(result_content, str) |
| 686 | else safe_stringify(result_content, 2) |
| 687 | ) |
| 688 | if as_string: |
| 689 | lines.append(as_string) |
| 690 | if block.get("isError") or block.get("is_error"): |
| 691 | lines.append("(Error)") |
| 692 | lines.append("") |
| 693 | return |
| 694 | |
| 695 | if block_type == "image": |
| 696 | lines.append("[Image attachment]") |
| 697 | lines.append("") |
| 698 | return |
| 699 | |
| 700 | if block_type in ("thinking", "redacted_thinking"): |
| 701 | return |
| 702 | |
| 703 | label = block_type if block_type is not None else "unknown" |
| 704 | lines.append(f"[{label} content block]") |
| 705 | lines.append(safe_stringify(block, 2)) |
| 706 | lines.append("") |
| 707 | |
| 708 | |
| 709 | def render_messages_to_plain_text(messages: Any) -> str: |
no test coverage detected