{% import "components.html" as c with context %} {# the configuration of an agent as cards: the agent itself, then one card per channel and per runtime, kept as a stack of pages per kind with a blank page at the end to start another. field names carry the card's number, so the handler reads the cards back in the order they were added; the values sent are the configuration's own words, the page shows them in the reader's #} {% macro kind_name(family, kind) -%} {{ t.text("agents." ~ family ~ "." ~ kind) if t.has("agents." ~ family ~ "." ~ kind) else kind }} {%- endmacro %} {% macro logo(family, kind) -%} {% if family == "channel" %}{{ c.channels((kind,)) }}{% else %}{{ c.runtimes((kind,)) }}{% endif %} {%- endmacro %} {# a card's head: its logo and name, the runtime's version beside it, and the way to take the card out #} {% macro card_head(family, kind, version=none) -%}
{{ logo(family, kind) }} {{ kind_name(family, kind) }}{% if version %}{{ version }}{% endif %}
{%- endmacro %} {% macro basic(values) -%}
{{ c.select("agent-mode", "mode", [("session", t.text("agents.mode.session")), ("dangerous_individual", t.text("agents.mode.dangerous_individual"))], values.get("mode", "session")) }}
{{ t.text("agents.seconds") }}
{%- endmacro %} {# what the agent tells a conversation still waiting to be looked at #} {% macro reply(value) -%}
{{ t.text("contacts.reply") }}

{{ t.text("contacts.reply_hint") }}

{%- endmacro %} {# one channel: the options its kind takes, the credential typed in and never shown back #} {% macro channel_card(kind, n, values={}, was=none, present={}) -%} {% set p = "channel-" ~ n ~ "-" %}
{% if was is not none %}{% endif %} {{ card_head("channel", kind) }} {% if kind == "lark" %}
{{ c.select(p ~ "region", p ~ "region", [("feishu", t.text("agents.region.feishu")), ("lark", t.text("agents.region.lark"))], values.get("region", "feishu")) }}
{% elif kind == "wecom" %}
{% endif %} {# a credential already kept is not shown back: it says it is set, and changes only when a new one is typed #} {# set is the computer's word that the credential has a value there, not that the card names a variable for it #} {% if kind in secrets and present.get(secrets[kind]) %}
{{ t.text("agents.secret_set") }}
{% elif kind in secrets %}
{% endif %}
{%- endmacro %} {# the models a runtime lists, as a model field's options once it is first opened: default first, the empty choice, taking the efforts of the model the runtime answers as unasked. each carries the efforts it takes, so choosing it can offer those #} {% macro model_options(models) -%} {% set fallback = models|selectattr("default")|list %} {% for item in models if item.id != "default" %}{% endfor %} {%- endmacro %} {# a field waiting on what the computer lists: turning while it is asked, the way to ask again when it did not answer #} {% macro waiting() -%} {%- endmacro %} {# a variable of the runtime's environment: its name and its value, which the node keeps the way it keeps a credential - so one already kept is not shown back, and changes only when a new value is typed #} {% macro env_row(n, m, name="") -%} {% set p = "runtime-" ~ n ~ "-env-" ~ m ~ "-" %}
={% if name %}{{ t.text("agents.secret_set") }}{% else %}{% endif %}
{%- endmacro %} {# one runtime: a model chosen from those it lists; the effort the model takes; where it may write and reach. the model and the effort hold only what is chosen until one of them is first opened, and the runtime's list is asked for then. Default is the empty choice - as a configuration naming none - and stays so on a save that did not touch it; a model named that the runtime does not list stays named #} {% macro runtime_card(kind, n, values={}, was=none, version=none) -%} {% set p = "runtime-" ~ n ~ "-" %} {% set model = values.get("model") or "" %} {% set effort = values.get("effort") or "" %} {% set env = values.get("env", {}) %}
{% if was is not none %}{% endif %} {{ card_head("runtime", kind, version) }}
{{ c.icon("chevron-down") }}{{ waiting() }}
{# a model that takes no effort hides the field once the list says so; choosing one that does shows it again #}
{{ c.icon("chevron-down") }}{{ waiting() }}
{{ c.select(p ~ "sandbox_mode", p ~ "sandbox_mode", [("workspace-write", t.text("agents.sandbox.workspace-write")), ("danger-full-access", t.text("agents.sandbox.danger-full-access"))], values.get("sandbox_mode", "workspace-write")) }}
{% for name in env %}{{ env_row(n, loop.index0, name) }}{% endfor %}
{%- endmacro %} {# the last page of a stack: what the computer has of this family, to start a card from, asked for when the page is first seen #} {% macro blank(family) -%}
{{ t.text("agents.blank." ~ family) }}
{{ c.icon("loader-circle") }}
{%- endmacro %} {# what the computer has of one family, on the blank page: a runtime that is not there is greyed and says so; each comes with the card it starts #} {% macro kinds(family, listed) -%} {% if listed.answer != "listed" %}

{{ t.text("agents." ~ listed.answer, {"code": listed.code}) }}

{% elif family == "channel" %} {% for item in listed.kinds %}{% endfor %} {% else %} {% for item in listed.kinds %}{% if item.available %}{% endif %}{% endfor %} {% endif %} {%- endmacro %} {# the cards of one family as a stack of pages, one shown, a tab on its edge to turn them; `start` numbers the first card #} {% macro deck(family, items, start, kept=false, origins=none, present=()) -%}
{% for item in items %} {# a card of the agent says which kept card it is, as the page last had it: a form shown again after a refusal keeps where each came from #} {% set was = (origins[loop.index0] if origins is not none else loop.index0) if kept else none %} {% if family == "channel" %}{{ channel_card(item.kind, start + loop.index0, item, was, present[was] if was is not none and was < present|length else {}) }}{% else %}{{ runtime_card(item.kind, start + loop.index0, item, was) }}{% endif %} {% endfor %} {{ blank(family) }}
{%- endmacro %} {# what makes the form work, for the form it sits in: the steps, the stacks and their pages, cards and rows added and taken out, what the computer has asked for where it is first wanted, a model offering the efforts it takes, and the summary the last step reads back. the form names its computer's address in `data-computer` #} {% macro script() -%} {%- endmacro %}