"""Renderer for turn-duration metadata.
On ``stream_end`` the backend reports ``elapsed_seconds`` — the total time the
agent spent on the user's request (all LLM calls, tool calls, planning, and
sub-agent steps). We render it as a dim ``⏱ 2m 16s`` line below the answer so the
cost of each turn is visible at a glance.
"""
from __future__ import annotations
from rich.console import RenderableType
from rich.text import Text
from clients.terminal.tui.duration import format_duration
from clients.terminal.tui.themes import get_active_theme
from .base import ContentRenderer
class TurnMetaRenderer(ContentRenderer):
"""Render turn-duration metadata as a dim ``⏱ 2m 16s`` line."""
def accepts(self, msg: dict) -> bool:
return msg.get("type") == "turn_meta"
def render(self, msg: dict) -> RenderableType:
theme = get_active_theme()
elapsed = msg.get("elapsed_seconds")
return Text(f"⏱ {format_duration(elapsed)}", style=theme.text_dim.hex)