File size: 519 Bytes
6172a47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"""Shared text extraction utilities."""

from typing import Any


def extract_text_from_content(content: Any) -> str:
    """Extract concatenated text from message content (str or list of content blocks)."""
    if isinstance(content, str):
        return content
    if isinstance(content, list):
        parts = []
        for block in content:
            text = getattr(block, "text", "")
            if text and isinstance(text, str):
                parts.append(text)
        return "".join(parts)
    return ""