{% from 'magpie/parts.html' import client, client_logo, provider, provider_logo, pair, integer, count, estimate, failure, route, flag, entry_link with context %}

{{ t.text('magpie.live.title') }}

{% if errors.get('route-events/snapshot') %}{{ failure(errors['route-events/snapshot'], t) }}{% endif %} {% if errors.get('concurrency') %}{{ failure(errors['concurrency'], t) }}{% endif %}
{% for item in live.routes %}{{ route(item, clients, providers, t) }}{% endfor %} {% for item in live.unrouted %}{{ route(item, clients, providers, t) }}{% endfor %}

{{ t.text('magpie.live.empty') }}

{% for state in ('started','attempt','responding','slot','rpm','redact','upstream','attempt_done') %} {% endfor %} {% for id in ((clients | list) + ['bazaar_contrib_codex','codex','claude','opencode']) | unique %} {% set meta = clients.get(id, {}) %} {% endfor %} {% for id, meta in providers.items() %}{% endfor %}

{{ t.text('magpie.live.stats') }}

{% if statistics %}{{ t.text('magpie.live.attempt_count', {'count': integer(statistics | sum(attribute='tries'))}) }} · {{ t.text('magpie.live.failure_count', {'count': integer(statistics | sum(attribute='failed'))}) }}{% endif %}
{% if errors.get('usage/requests') %}{{ failure(errors['usage/requests'], t) }}{% else %} {% for speed in statistics %} {{ provider(speed.provider, speed.get('provider_name'), speed.model, speed.get('icon','')) }} {% set reasons %}{% for reason, amount in speed.reasons.items() %}{{ t.text('magpie.reason.' ~ reason) }} {{ t.text('magpie.live.times', {'count': integer(amount)}) }}{% if not loop.last %} · {% endif %}{% endfor %}{% endset %} {{ reasons | trim }} {{ t.text('magpie.live.attempt_count', {'count': integer(speed.tries)}) }}{{ t.text('magpie.live.failure_count', {'count': integer(speed.failed)}) }}{% include 'server/icons/chevron-right.svg' %} {% else %}

{{ t.text('magpie.live.no_stats') }}

{% endfor %} {% endif %}