Return content as a list of MessageBlock items.
(self)
| 287 | return "\n".join(parts) |
| 288 | |
| 289 | def blocks(self) -> List[MessageBlock]: |
| 290 | """Return content as a list of MessageBlock items.""" |
| 291 | if self.content is None: |
| 292 | return [] |
| 293 | if isinstance(self.content, str): |
| 294 | return [MessageBlock.text_block(self.content)] |
| 295 | blocks: List[MessageBlock] = [] |
| 296 | for block in self.content: |
| 297 | if isinstance(block, MessageBlock): |
| 298 | blocks.append(block) |
| 299 | elif isinstance(block, dict): |
| 300 | try: |
| 301 | blocks.append(MessageBlock.from_dict(block)) |
| 302 | except Exception: |
| 303 | # Fallback to text representation of unexpected dicts |
| 304 | text_value = block.get("text") if isinstance(block, dict) else None |
| 305 | blocks.append(MessageBlock(MessageBlockType.DATA, text=text_value, data=block if isinstance(block, dict) else {})) |
| 306 | return blocks |
| 307 | |
| 308 | def clone(self) -> "Message": |
| 309 | """Deep copy of the message, preserving content blocks.""" |
no test coverage detected