diff --git a/tui_gateway/server.py b/tui_gateway/server.py index 34368aa6f69..c153d55435b 100644 --- a/tui_gateway/server.py +++ b/tui_gateway/server.py @@ -2421,6 +2421,36 @@ def _enrich_with_attached_images(user_text: str, image_paths: list[str]) -> str: return text or "What do you see in this image?" +def _content_display_text(content: Any) -> str: + if content is None: + return "" + if isinstance(content, str): + return content + if isinstance(content, (int, float)): + return str(content) + if isinstance(content, list): + parts = [] + for part in content: + text = _content_display_text(part).strip() + if text: + parts.append(text) + return "\n".join(parts) + if isinstance(content, dict): + kind = content.get("type") + if kind in {"text", "input_text", "output_text"}: + return str(content.get("text") or content.get("content") or "") + if kind in {"image_url", "input_image", "image"}: + return "[image]" + if kind in {"input_audio", "audio"}: + return "[audio]" + if kind: + return f"[{kind}]" + if "text" in content: + return str(content.get("text") or "") + return "[structured content]" + return str(content) + + def _coerce_message_text(content: Any) -> str: """Render ``message['content']`` as a plain string for transport.