{% from "components/field_renderer.html" import render_hitl_field, status_badge %} {% from "components/dialog_renderer.html" import render_hitl_dialog, render_dialog_confirmed %} {# Determine if the job has reached a terminal state (EntityStatus.value is lowercase) #} {% set job_status = job.status.value %} {% set is_terminal = job_status in ("completed", "failed", "stopped", "cancelled") %} {# Outer div — WebSocket pushes updates, no HTMX polling needed #}
{# ── Job status bar ──────────────────────────────────────────────── #}
{{ job.id }} {{ status_badge(job_status) }} {# Case count #} {% if cases_data %} {{ cases_data | length }} case{{ "s" if cases_data | length != 1 }} {% endif %}
{# Created at timestamp #} {% if job.created_at %} {{ job.created_at }} {% endif %}
{# ── Cases list ──────────────────────────────────────────────────── #} {% if cases_data %}
{% for case_info in cases_data %} {% set case = case_info.case %} {% set hitl_form = case_info.hitl_form %} {% set hitl_dialog = case_info.hitl_dialog %} {% set case_status = case.status.value %} {% set auto_expand = case_status in ("awaiting", "in_progress") %}
{# Case header — clickable to toggle #} {# Expandable body: steps + HITL form #}
{# Steps list #} {% if case.updates %}
{% for step in case.updates %} {% set step_payload = step.payload or {} %} {% set step_duration = step_payload.get("duration") if step_payload is mapping else none %} {% set step_message = step_payload.get("message") if step_payload is mapping else none %}
{# Step status icon #}
{% if step.error %} {% elif step.is_final %} {% else %} {% endif %}
{# Step details #}
{% if step.index %} #{{ step.index }} {% endif %} {% if step.name == "HITL Answer" %}👤 {{ step_payload.get("_hitl_label", "User response") if step_payload is mapping else "User response" }}{% else %}{{ step.name or "Step" }}{% endif %}
{% if step_duration is not none and step_duration is number %} {{ "%.1f"|format(step_duration) }}s {% elif step_duration is not none and step_duration %} {{ step_duration }}s {% endif %} {% if step.cost %} ${{ "%.4f"|format(step.cost) }} {% endif %}
{% if step_message %}

{{ step_message }}

{% endif %} {% if step.name == "HITL Answer" and step_payload is mapping %}
{% for key, val in step_payload.items() if key != "_hitl_label" %}
{{ key }}: {% if val is sameas true %} Yes {% elif val is sameas false %} No {% elif val %} {{ val }} {% else %} empty {% endif %}
{% endfor %}
{% endif %} {% if step.error %}

{{ step.error }}

{% endif %}
{# Show reply content as a blockquote #} {% if step_payload is mapping and step_payload.get("reply") %}

Reply content:

{{ step_payload.get("reply") }}
{% endif %} {# Show approved content card below the step row #} {% if step_payload is mapping and step_payload.get("approved_content") %} {{ render_dialog_confirmed(step_payload.get("approved_content"), step_payload.get("approved_content_type", "text")) }} {% endif %} {% endfor %}
{% else %}
No steps recorded yet.
{% endif %} {# HITL form — only shown when case is AWAITING and has form #} {% if hitl_form and has_human_answer %}
Human Input Required
{% if hitl_form is mapping %}
{% for field_name, field_def in hitl_form.items() %} {{ render_hitl_field(field_name, field_def) }} {% endfor %}
{% endif %}
{% endif %} {# HITL dialog — chat-like interface for content review #} {% if hitl_dialog and has_human_answer %} {{ render_hitl_dialog(case.id, hitl_dialog) }} {% endif %}
{% endfor %}
{% else %} {# No cases yet #}

Waiting for cases...

{% endif %}