(message: dict[str, Any])
| 45 | |
| 46 | |
| 47 | def normalize_message_text(message: dict[str, Any]) -> str: |
| 48 | content = message.get("content", "") |
| 49 | if isinstance(content, str): |
| 50 | text = content |
| 51 | elif isinstance(content, list): |
| 52 | text = " ".join(p for p in (_flatten_block(b) for b in content) if p) |
| 53 | else: |
| 54 | text = "" if content is None else str(content) |
| 55 | text = _WHITESPACE_RUN.sub(" ", text).strip() |
| 56 | return text |
| 57 | |
| 58 | |
| 59 | def normalize_messages_to_hashes(messages: list[dict[str, Any]]) -> list[str]: |