{% for ev in events %}
{% set t = ev.get("type","") %}
{% set message = ev.get("message") %}
{% set msg_content = message.get("content") or [] if message is mapping else [] %}
{% if t == "assistant" %}
{% for p in msg_content %}
{% if p is mapping and p.get("type") == "tool_use" %}
{% set inp = p.get("input") if p.get("input") is mapping else {} %}
{% elif p is mapping and p.get("type") == "text" and (p.get("text", "") | string).strip() %}
text{{ p.text }}
{% endif %}
{% endfor %}
{% elif t == "user" %}
{% for p in msg_content %}
{% if p is mapping and p.get("type") == "tool_result" %}
{% set c = p.get("content") or [] %}
result
{%- if c is string %}{{ c }}{%- elif c is sequence and c and c[0] is mapping and c[0].get("text") %}{{ c[0].get("text") | string }}{%- endif %}
{% endif %}
{% endfor %}
{% elif t in ("item.started", "item.completed") and ev.get("item") is mapping %}
{% set item = ev.get("item") %}
{% set item_type = item.get("type", "") %}
{% set item_text = item.get("text", "") | string %}
{% if item_type == "agent_message" and item_text.strip() %}