Assistant text joined with '\\n\\n' (TS extractTextContent(content, '\\n\\n')).
(msg: Any)
| 101 | |
| 102 | |
| 103 | def _message_text(msg: Any) -> str: |
| 104 | """Assistant text joined with '\\n\\n' (TS extractTextContent(content, '\\n\\n')).""" |
| 105 | from src.utils.export_renderer import extract_message_content |
| 106 | |
| 107 | content = extract_message_content(msg) |
| 108 | if isinstance(content, str): |
| 109 | return content.strip() |
| 110 | if isinstance(content, list): |
| 111 | parts: list[str] = [] |
| 112 | for block in content: |
| 113 | if isinstance(block, Mapping): |
| 114 | if block.get("type") in (None, "text") and block.get("text"): |
| 115 | parts.append(str(block["text"])) |
| 116 | else: |
| 117 | text = getattr(block, "text", None) |
| 118 | if text and getattr(block, "type", "text") in (None, "text"): |
| 119 | parts.append(str(text)) |
| 120 | return "\n\n".join(parts).strip() |
| 121 | return "" |
| 122 | |
| 123 | |
| 124 | def collect_recent_assistant_texts(messages: Any) -> list[str]: |
no test coverage detected