{# a plugin's fields as its schema on the computer gives them: credentials typed blind and kept when left blank, models and efforts from what the runtime reports, choices in the plugin's own words; changing the model redraws the form through `refresh`, its efforts following #} {% macro fields(schema, item, values, typed, models, refresh, computer) %} {% set props = schema.get("properties") or {} %} {% set required = schema.get("required") or [] %} {% set ns = namespace(model=none, secrets=false) %} {% for name, field in props.items() %}{% if field.get("x-inspect") == "models" %}{% set ns.model = name %}{% endif %}{% if field.get("writeOnly") %}{% set ns.secrets = true %}{% endif %}{% endfor %} {% set model = ((models | selectattr("id", "equalto", values.get(ns.model)) | first | default(none)) or (models | selectattr("default") | first | default(none))) if ns.model else none %} {% for name, field in props.items() %} {% set types = [field.get("type")] + ((field.get("anyOf") or []) | map(attribute="type") | list) %} {% set choices = field.get("enum") or ((field.get("anyOf") or []) | selectattr("enum", "defined") | map(attribute="enum") | first | default(none)) %} {% set value = values.get(name) %}
{% if field.get("writeOnly") %} {% set state = "typed" if name in typed or name in item.new else "saved" if name in item.secrets else "none" %} {% include "agents/icons/key-round.svg" %} {% if state == "saved" %}{{ t.text("agents.secret.keep") }}{% else %}{{ schema | word(name ~ ".description") }}{% endif %} {% elif field.get("x-inspect") == "models" %} {% include "agents/icons/chevron-down.svg" %} {% if schema | word(name ~ ".description") %}{{ schema | word(name ~ ".description") }}{% endif %} {% elif field.get("x-inspect") == "efforts" %} {% include "agents/icons/chevron-down.svg" %} {% if schema | word(name ~ ".description") %}{{ schema | word(name ~ ".description") }}{% endif %} {% elif choices %}
{% for one in choices %}{% endfor %}
{% if schema | word(name ~ ".description") %}{{ schema | word(name ~ ".description") }}{% endif %} {% elif "boolean" in types %} {% else %} {% if schema | word(name ~ ".description") %}{{ schema | word(name ~ ".description") }}{% endif %} {% endif %}
{% endfor %} {% if ns.secrets %}
{% include "agents/icons/key-round.svg" %}
{{ t.text("agents.config.secret_note", {"computer": computer}) }}
{% endif %} {% endmacro %}