{# an agent's face: the first letter of its name on its own colour #}
{% macro avatar(agent, size="sm") %}
{{ agent.name[:1] | upper }}
{% endmacro %}
{# a plugin's logo, standing for its name; a puzzle piece for a kind without one #}
{% macro logo(kind) %}{% include ["agents/logos/" ~ kind ~ ".svg", "agents/icons/puzzle.svg"] %}{% endmacro %}
{# how an agent is: at work for how long, idle, failed and why, or offline while its computer is away #}
{% macro status(row) %}
{% set state = row.state %}
{% if state == "working" %}{{ row.activity.working.since_ms | lasted }}
{% elif state == "failed" %}{{ row.activity.reason or t.text("agents.state.failed") }}
{% elif state == "offline" %}{{ t.text("agents.state.offline") }}
{% else %}{{ t.text("agents.idle") }}{% endif %}
{% endmacro %}
{# a window's length: so many days, hours or minutes #}
{% macro period(window) -%}
{%- set minutes = window.duration_minutes -%}
{%- if window.name %}{{ window.name }} {% endif -%}
{%- if minutes and minutes % 1440 == 0 %}{{ t.text("agents.quota.days", {"n": minutes // 1440}) }}{% elif minutes and minutes % 60 == 0 %}{{ t.text("agents.quota.hours", {"n": minutes // 60}) }}{% elif minutes %}{{ t.text("agents.quota.minutes", {"n": minutes}) }}{% endif -%}
{%- endmacro %}
{# logos in a line, clipped where the cell ends; the names behind them in a
panel a pointer's hover or a tap opens. The list is drawn again as agents
change: a panel pinned open stays open, one under the pointer shows again #}
{% macro peek(key, label) %}
{{ caller("names") }}
{% endmacro %}
{# where an agent talks: each channel's logo, and the bot's name as its connection reported it #}
{% macro channels(row) %}
{% if row.kept.agent.channel %}
{% call(part) peek(ref(row.kept.agent.id) ~ ":channel", t.text("agents.column.channel")) %}
{% for provider in row.kept.agent.channel %}
{% if part == "logos" %}{{ logo(provider.kind) }}{% else %}
{% set link = (row.activity.channels | selectattr("connection", "equalto", provider.connection) | first | default(none)) if row.activity else none %}
{{ logo(provider.kind) }}{{ (link.identity.name or link.identity.id) if link and link.identity else "—" }}
{% endif %}
{% endfor %}
{% endcall %}
{% else %}
—
{% endif %}
{% endmacro %}
{% macro quota(row, provider, detailed=false) %}
{% set runtime = (row.activity.runtimes | selectattr("connection", "equalto", provider.connection) | first | default(none)) if row.activity else none %}
{% if runtime and runtime.quota and runtime.quota.windows %}
{% for window in runtime.quota.windows %}
{% set pct = "%g" | format(window.remaining_pct | round(1)) %}
{% set reset = detailed and window.resets_at_ms is not none %}
{{ pct }}%
{% if window.name or window.duration_minutes or reset %}
{% if window.name or window.duration_minutes %}{{ period(window) }}{% endif %}
{% if reset %}{{ t.text("agents.quota.resets", {"when": window.resets_at_ms | moment}) }}{% endif %}
{% endif %}
{% endfor %}
{% else %}
{{ t.text("agents.quota.unknown") }}
{% endif %}
{% endmacro %}
{# what an agent runs on, in the order it tries them: each runtime's logo; the
model, whether it stands by and what quota it has left in the panel #}
{% macro runtimes(row) %}
{% if row.kept.agent.harness %}
{% call(part) peek(ref(row.kept.agent.id) ~ ":runtime", t.text("agents.column.runtime")) %}
{% for provider in row.kept.agent.harness %}
{% if part == "logos" %}{{ logo(provider.kind) }}{% else %}
{% set runtime = (row.activity.runtimes | selectattr("connection", "equalto", provider.connection) | first | default(none)) if row.activity else none %}
{{ logo(provider.kind) }}{{ provider["values"].get("model") or t.text("agents.model.default") }}{% if not loop.first %}{{ t.text("agents.standby") }}{% endif %}
{% if runtime and runtime.quota and runtime.quota.windows %}
{% for window in runtime.quota.windows %}
{% set pct = "%g" | format(window.remaining_pct | round(1)) %}
{{ period(window) }}{{ pct }}%
{% endfor %}
{% else %}{{ t.text("agents.quota.unknown") }}{% endif %}
{% endif %}
{% endfor %}
{% endcall %}
{% else %}
—
{% endif %}
{% endmacro %}
{# today's tokens and what they cost #}
{% macro usage(row) %}
{% if row.activity and (row.activity.usage.input or row.activity.usage.output) %}
{{ (row.activity.usage.input + row.activity.usage.output) | tokens }}{% if row.activity.usage.cost is not none %}${{ "%.2f" | format(row.activity.usage.cost) }}{% endif %}
{% else %}
—
{% endif %}
{% endmacro %}
{# a channel of the draft by the bot its connection reported, else its first value; a runtime by its model #}
{% macro headline(row, label, item) -%}
{% if label == "harness" %}{{ item["values"].get("model") or t.text("agents.model.default") }}
{%- else %}{% set link = (row.activity.channels | selectattr("connection", "equalto", item.connection) | first | default(none)) if row and row.activity and item.connection else none %}{{ (link.identity.name or link.identity.id) if link and link.identity else (item["values"].values() | select("string") | first | default("—")) }}{% endif %}
{%- endmacro %}
{# what else an item holds, in its plugin's words: values worded where the plugin words them, efforts after their field's name, credentials only as saved, typed or how an empty one runs #}
{% macro summary(schema, item) -%}
{% set parts = [] %}
{% for name, field in (schema.get("properties") or {}).items() %}
{% set value = item["values"].get(name) %}
{% if field.get("writeOnly") %}
{% if name in item.new %}{% set _ = parts.append(t.text("agents.secret.typed", {"name": schema | word(name ~ ".title", name)})) %}
{% elif name in item.secrets %}{% set _ = parts.append(t.text("agents.secret.saved_named", {"name": schema | word(name ~ ".title", name)})) %}
{% elif schema | word(name ~ ".empty") %}{% set _ = parts.append(schema | word(name ~ ".empty")) %}{% endif %}
{% elif field.get("x-inspect") == "models" or value is none or value == "" %}
{% elif field.get("x-inspect") == "efforts" %}{% set _ = parts.append((schema | word(name ~ ".title", name)) ~ " " ~ (schema | word(name ~ "." ~ value, value | string))) %}
{% else %}{% set _ = parts.append(schema | word(name ~ "." ~ value, value | string)) %}{% endif %}
{% endfor %}
{{- parts | join(" · ") -}}
{%- endmacro %}