{#- SPDX-License-Identifier: Apache-2.0 -#} {#- Shared pieces for the pages that list plugins: a stage's controls, a kind's plugin table and the settings dialogs. Import with context: they read pipeline, plugins and models. -#} {% import "_macros.html" as m with context %} {% macro setting(plugin, field, spec, val, row) %} {% set kinds = (spec.anyOf | map(attribute="type") | list) if spec.anyOf else [spec.type] %}
{% if field == "model" and row.choices %} {% elif "boolean" in kinds and "null" in kinds %} {% elif "boolean" in kinds %} {% elif "integer" in kinds or "number" in kinds %} {% elif "array" in kinds %} {% else %} {% endif %} {% if spec.description %}

{{ spec.description }}

{% endif %}
{% endmacro %} {# The model control, the same on every plugin that takes one: a select, and a check to apply it. #} {% macro model_picker(c, back, label) %} {% call m.post("model", back) %} {% endcall %} {% endmacro %} {% macro health(p) %} {#- The pill says the state; the reason goes under it, wrapped, so a long config error cannot stretch the table. -#} {%- set d = p.detail or "" %}{% set short = d.split(" (")[0] if " (" in d else d %} {%- if p.healthy %}healthy {%- elif p.started %}{{ short or "unhealthy" }} {%- else %}{{ short or "not started" }}{% endif -%} {%- if not p.healthy and short != d %}
{{ d }}
{% endif -%} {% endmacro %} {# A stage runs or is paused: the same pill switch as Enabled. On is running, off is paused, so the state is the switch and there is no separate button or badge. #} {% macro stage_toggle(stage, s, back) %} {{ m.switch("stage", back, not (s and s.paused), "Run " ~ stage, {"stage": stage}, "run", "on", "off") }} {% endmacro %} {% macro kind_body(kind, label, stage, back) %} {% if stage and pipeline and pipeline.stages.get(stage) %} {% set s = pipeline.stages[stage] %}
{{ label }} stage {{ stage }} {{ stage_toggle(stage, s, back) }} {% if s.loaded and s.failed %}{% call m.post("retry-parked", back) %}{% endcall %}{% endif %}
Pending{{ s.pending if s.loaded else "…" }}
Running{{ s.running if s.loaded else "…" }}
Failed{{ s.failed if s.loaded else "…" }}parked, out of attempts
Per second{{ ("%.2f" | format(s.per_second)) if s.loaded else "…" }}
{% call m.post("limit", back) %} {% set uses_model = models | selectattr("kind", "equalto", kind) | list %}

The pressure valve: the most {{ stage }} jobs running together. It limits claims, it starts no threads of its own, and with nothing queued it does nothing.{% if not uses_model %} No plugin here uses a model, so this only paces the work.{% endif %}

{% endcall %}
{% if stage_fields is defined %}{{ setting_rows(back, stage_fields) }}{% endif %}
{% endif %}
{{ label }}
{% if kind == "enricher" %}{% endif %}{% if stage %}{% endif %}{% if kind == "enricher" %}{% endif %} {% set names = plugins | map(attribute="name") | list %} {# A provider runs one instance per account, named plugin@account. Those are listed under the provider, not as plugins of their own. An instance whose provider is gone is still shown. #} {% for p in plugins if p.kind == kind and ("@" not in p.name or p.name.split("@")[0] not in names) %} {% set cs = models | selectattr("kind", "equalto", p.kind) | selectattr("name", "equalto", p.name) | list %} {% set c = cs[0] if cs else none %} {% set sr = (settings_rows | selectattr("kind", "equalto", p.kind) | selectattr("name", "equalto", p.name) | list) if settings_rows is defined else [] %} {% set has_options = sr and (sr[0].config_schema.properties.keys() | reject("equalto", "model") | list) %} {% if kind == "enricher" %}{% set es = pipeline.enrichers.get("enrich." ~ p.name) if pipeline else none %} {% endif %} {% if stage %}{% endif %} {% if kind == "enricher" %} {% endif %} {% for ch in plugins if p.kind == kind and ch.kind == kind and "@" not in p.name and ch.name.startswith(p.name ~ "@") %} {% if kind == "enricher" %}{% endif %} {% if stage %}{% endif %} {% if kind == "enricher" %}{% endif %} {% endfor %} {% else %} {% endfor %}
PluginVersionAt onceHealthModelEnabledPauseActions
{{ p.name }}{{ p.version }}{% call m.post("limit", back) %} {% endcall %}{{ health(p) }} {% if c and c.choices %}{{ model_picker(c, back, p.name) }} {% else %}—{% endif %} {{ m.switch("plugin", back, p.enabled, "Enable " ~ p.name, {"name": p.name}, "verb", "enable", "disable") }}{{ stage_toggle("enrich." ~ p.name, pipeline.enrichers.get("enrich." ~ p.name) if pipeline else none, back) }}
{% if kind == "provider" %}{% if accounts | selectattr("provider", "equalto", p.name) | list %}{% endif %} {% elif has_options %}{% endif %} {% call m.post("plugin", back) %}{% endcall %}
  ↳ {{ ch.name.split("@", 1)[1] }}{{ health(ch) }}—{{ m.switch("plugin", back, ch.enabled, "Enable " ~ ch.name, {"name": ch.name}, "verb", "enable", "disable") }}
{% call m.post("plugin", back) %}{% endcall %}
{% if kind == "cache_store" %}No cache plugin installed. Core's own SQLite cache (in raw.db) is in use.{% else %}No {{ label | lower }} installed.{% endif %}
{% if kind != "enricher" %}
Turn a plugin off to take it out of the pipeline for now; turn it on to put it back.
{% endif %}
{% endmacro %} {% macro kind_pane(kind, label, stage, page="/general") %}
{{ kind_body(kind, label, stage, page ~ "?tab=" ~ kind) }}
{% endmacro %} {# Token usage rows for one page. ``back`` is where an action returns to. #} {% macro usage_card(rows, back, title="Model & token usage", reset=false, pick=true) %}
{{ title }} {% if reset %}{{ m.confirm("reset-usage", back, "Clear usage stats", "Clear the token figures? Mail, the index and the cache stay.", "Clear", {}, "trash") }}{% endif %}
{% for u in rows %} {% set c = u.component %} {% set has_settings = c and c.config_schema and (c.config_schema.properties.keys() | reject("equalto", "model") | list) %} {% else %} {% endfor %}
WorkspaceStageModelCallsCachedInOutSavedActions
{{ u.workspace }}{{ u.stage }} {% if pick and c and c.choices %}{{ model_picker(c, back, c.label) }} {% else %} {{ u.model_text or "—" }} {% endif %} {{ "{:,}".format(u.calls) }}{{ "{:,}".format(u.cached_calls) }} {{ "{:,}".format(u.tokens_in) }}{{ "{:,}".format(u.tokens_out) }} {{ "{:,}".format(u.tokens_saved) }} {% if c %} {% endif %}
No model usage recorded yet.
{% endmacro %} {# The agents (external workers) the page is given; each can be revoked. #} {% macro agents_card(list, back, title="Agents") %}
{{ title }}
{% for a in list %} {% else %} {% endfor %}
AgentKindsLast seenStateRevoke
{{ a.label }} {{ a.kinds | join(", ") or "—" }} {{ a.last_seen_at or "never" }} {% if a.revoked %}revoked{% else %}active{% endif %} {% if not a.revoked %}{{ m.confirm("revoke-agent", back, "Revoke " ~ a.label, "Revoke " ~ a.label ~ "? Its jobs return to the queue.", "Revoke", {"agent_id": a.id}, "x") }}{% endif %}
No agents registered.
{% endmacro %} {# Settings of the stage's kind (core's own), changed in place: one field and a Save each, in the stage card. They apply on the next reload. #} {% macro setting_rows(back, fields) %} {% for f in fields %}
{% call m.post("stage-setting", back) %} {% if f.choices %} {% elif f.type == "text" %} {% else %} {% endif %}

{{ f.hint }}

{% endcall %}
{% endfor %} {% endmacro %} {% macro dialogs(back) %} {% for c in (settings_rows if settings_rows is defined else []) %}{% if c.config_schema and (c.config_schema.properties.keys() | reject("equalto", "model") | list) %} {% endif %}{% endfor %} {% endmacro %} {# A provider's schedule manager: one block per account it syncs. The gear on its row opens it. #} {% macro schedule_dialogs(back) %} {% for p in plugins if p.kind == "provider" and "@" not in p.name %} {% endfor %} {% endmacro %}