{% macro failure(error, t) %} {% endmacro %} {% macro pair(label, item) %}
{{ label }}{{ item if item is not none else '—' }}
{% endmacro %} {% macro flag(state, t, pill=false) %} {% set tone = 'work' if state in ('started','attempt','responding','upstream','attempt_done','redact') else ('on' if state in ('success','retried','done','on') else ('fail' if state in ('failed','handed_on','attempt_failed','agent_error') else 'off')) %} {{ t.text('magpie.state.' ~ state) }} {% endmacro %} {% macro count(value) %}{{ value | tokens if value is not none else '—' }}{% endmacro %} {% macro integer(value) %}{{ ('{:,}'.format(value)) if value is not none else '—' }}{% endmacro %} {% macro estimate(value, precision=4) %}{{ ('$' ~ (('%.' ~ precision ~ 'f') | format(value))) if value is not none else '—' }}{% endmacro %} {% macro client_logo(source, icon='') %} {% if source in ('bazaar_contrib_codex', 'codex') or icon == 'codex-color' %}{% include 'magpie/logos/codex.svg' %} {% elif source == 'claude' or icon == 'claudecode-color' %}{% include 'magpie/logos/claudecode.svg' %} {% elif source.startswith('opencode') or icon == 'opencode' %} {% else %}{% include 'magpie/icons/activity.svg' %}{% endif %} {% endmacro %} {% macro provider_logo(provider, icon='') %} {% set local = {'openrouter':'openrouter','anthropic':'anthropic','deepseek':'deepseek-color','kimi':'kimi','minimax':'minimax-color','zhipu':'zhipu-color','qwen':'qwen-color','workbuddy':'workbuddy-color','workbuddy-ai':'workbuddy-color','opencode-zen-free':'opencode','minimax-code':'minimax-color','minimax-code-global':'minimax-color'} %} {% set chosen = icon if icon in local.values() else local.get(provider) %} {% if chosen %} {% else %}{% include 'magpie/icons/coins.svg' %}{% endif %} {% endmacro %} {% macro client(source, label, icon='') %}{{ client_logo(source, icon) }}{{ label or '—' }}{% endmacro %} {% macro provider(key, name, model='', icon='') %}{{ provider_logo(key, icon) }}{{ name or key or '—' }}{% if model %}{{ model }}{% endif %}{% endmacro %} {% macro entry_link(row, index, filters, target, offset=0) %}{{ target('requests', route=row.get('route_id'), row=index if not row.get('route_id') else none, offset=offset or none, **filters) }}{% endmacro %} {% macro request_key(route, index, offset) %}{% if route %}r{{ route }}{% elif index is not none %}{{ offset }}:{{ index }}{% endif %}{% endmacro %} {% macro route_status(item, state, t) %} {% set result = 'agent_error' if item.get('result') == 'failed' else item.get('result') %} {% set label = result or ('attempt_failed' if item.get('failed') else state) %} {% set attempt = item.get('attempt', 0) %} {% set status = item.get('status', 0) %} {% set show_attempt = attempt > 1 or (attempt and label == 'attempt_failed') %} {% set show_status = status >= 400 or (status and label == 'attempt_failed') %} {{ flag(label, t, true) }} {% if show_attempt or show_status %} {%- if show_attempt -%} {{ t.text('magpie.live.try_number', {'count': attempt}) }}{% if item.get('changed_destination') %} · {{ t.text('magpie.live.switched') }}{% endif %}{% if show_status %} · {% endif %} {%- endif -%} {% if show_status %}HTTP {{ status }}{% endif %} {% endif %} {% endmacro %} {% macro route_failures(item, providers, t) %} {% if item.get('failed_attempts') %} {% endif %} {% endmacro %} {% macro route(item, clients, providers, t, state, group, gateway) %} {% set source = item.get('agent', '') %}{% set destination = item.get('provider', '') %} {% set from_client = clients.get(source, {}) %}{% set to_provider = providers.get(destination, {}) %} {% set usage = item.get('usage', {}) %} {% set when = item.get('time') or item.get('started') %} {% set elapsed = item.get('elapsed') if item.get('elapsed') is not none else item.get('ms') %} {% set element = 'a' if item.get('recorded') else 'div' %}
<{{ element }} class="ev live-row"{% if element == 'a' %} href="{{ link('requests', gateway, route=item.route_id, via='through') }}"{% endif %}> {{ client_logo(source, from_client.get('icon', '')) }}{{ source_name(source, from_client.get('name', '')) or '—' }} {% if usage.get('requested') %}{{ usage.requested }}{% endif %} {% include 'server/icons/chevron-right.svg' %} {% if destination %}{{ provider(destination, to_provider.get('name') or item.get('provider_name'), item.get('model', ''), to_provider.get('icon', '')) }}{% else %}{{ t.text('magpie.state.' ~ state) }}{% endif %} {% if usage.get('account') %}{{ usage.account }}{% endif %} {% if usage.get('reported') %}{{ t.text('magpie.live.reported', {'model': usage.reported}) }}{% endif %} {{ route_status(item, state, t) }} {{ elapsed | duration('compact') if elapsed is not none else '—' }} {% if usage.get('effort') or usage.get('first_output') or usage.get('first_text') or usage.get('tokens') is not none or usage.get('cache_hit') is not none %} {% if usage.effort %}{{ t.text('magpie.request.effort') }} {{ usage.effort }}{% endif %} {% if usage.first_output %}{{ t.text('magpie.request.first') }} {{ usage.first_output | duration('compact') }}{% endif %} {% if usage.first_text %}{{ t.text('magpie.request.first_text') }} {{ usage.first_text | duration('compact') }}{% endif %} {% if usage.tokens is not none %}{{ count(usage.tokens) }} {{ t.text('magpie.usage.tokens') }}{% endif %} {% if usage.cache_hit is not none %}{{ t.text('magpie.request.cache_hit') }} {{ usage.cache_hit }}%{% endif %} {% endif %} {{ route_failures(item, providers, t) }}
{% endmacro %}