Files
LLeMbas/src/lembas/web/templates/admin/general.html
T
Jaroslav Beneš b8e7745311 An instance that can be somebody else's
A name, a tagline, a logo, a favicon and the launcher icons derived from it; the
Middle-earth strings as data; themes as token sets; and a stylesheet for what
none of that reaches. All four are on one page, in one settings group.

The snapshot is a Jinja global over a process-level cache, because render() has
no session and four render paths never reach it at all -- the sign-in page, the
error pages, the offline page and the SSE fragments. A context value would have
had to be threaded through every one and would still have missed those. It being
a global is also what lets mark() branch on an uploaded logo without any of its
six call sites learning about branding; the macro that renders the sidebar link
is called brandlink now, because a macro imported as `brand` shadows the global
for the whole template and took out every page at once.

Defaults in code and overrides in the database, as the prompt fragments do, with
one difference stated in the module: an empty fragment means off, an empty
flavour string means the shipped wording. And blanked rather than dropped --
settings_store.update merges, so an omitted key leaves what was stored last time
and "I typed the default back in" would store something different from "I changed
nothing".

A custom theme sets a handful of tokens and inherits the rest, and the
inheritance is a CSS fact: tokens.css matches [data-base="shire"] as well as
[data-theme="shire"], so a custom light theme lands on parchment rather than four
light colours on near-black. Values are validated on read rather than on save,
because a theme written straight into the settings table still has to produce a
stylesheet that parses -- a `}` in a value ends the rule and silently breaks
every rule after it. The soft variants are derived from the accent, or a changed
accent leaves focus rings in the old hue and reads as half-working.

/branding.css is a route, not an inline block: an external stylesheet has no HTML
context to escape from. The link carries a content hash, so a save is not left to
the browser's cache, and it is deliberately outside the service worker's precache
list, which is versioned by the release.

The instance name moved off /admin/general rather than being duplicated there.
An upgrade keeps it: the general row is read as a seed exactly while the branding
row has never mentioned the name, which is `key in row` and not `row[key] is
truthy` -- the two read alike would resurrect the old name underneath a cleared
one.

The theme list stops being a hard-coded pair in five places. Every failure mode
in that area is silent, so it is driven under a DOM stub as well as tested.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-06 15:42:25 +02:00

138 lines
5.5 KiB
HTML

{% extends "admin/_layout.html" %}
{% from "_macros.html" import icon %}
{% set section = "general" %}
{% block title %}General - {{ brand.name }}{% endblock %}
{% block heading %}General{% endblock %}
{% block admin_content %}
<p class="admin-lede">
Instance-wide settings. These are stored in the database and take effect
immediately — no restart, and they survive one.
</p>
{% if saved %}
<div class="alert alert--success">{{ icon("check", "icon--sm") }} <span>Settings saved.</span></div>
{% endif %}
{#
The instance name used to be here. It lives on Customization now, with the
logo, the wording and the themes -- one field, one page. Left as a link rather
than duplicated: two controls writing one value is how each becomes the answer
to "why did my change not stick?".
#}
<p class="admin-lede">
The name, the logo, the wording and the themes are on
<a href="/admin/customization">Customization</a>.
</p>
<form method="post" action="/admin/general">
<section class="card">
<h2 class="card__title">Default system prompt</h2>
<p class="card__lede">
Applied to every chat that does not have a prompt of its own. A model's
prompt overrides this, and a chat's prompt overrides both — most specific
wins outright rather than the three being stacked together.
</p>
<div class="field">
<label class="field__label visually-hidden" for="system-prompt">System prompt</label>
<textarea class="textarea" id="system-prompt" name="system_prompt" rows="5"
placeholder="You are a helpful assistant.">{{ values.system_prompt }}</textarea>
<p class="field__hint">Leave empty to send no system prompt at all.</p>
</div>
</section>
<section class="card">
<h2 class="card__title">Compaction</h2>
<p class="card__lede">
A long conversation eventually fills the model's context. When it gets
close, the earlier turns are summarised and the summary is sent in their
place. The messages themselves are kept and stay readable in the
transcript — they simply stop being sent.
</p>
<div class="field">
<label class="field__label" for="compact-threshold">Compact at</label>
<input class="input" id="compact-threshold" name="compact_threshold" type="number"
min="0" max="99" value="{{ values.compact_threshold }}">
<p class="field__hint">
Percent of the model's context length. <code>0</code> turns automatic
compaction off; the button in each chat still works. Nothing happens for
a model whose context length is unset under
<a href="/admin/models">Models</a> — that is "unknown", not "small", and
this will not act on a number nobody supplied. The wording of the
summary is under <a href="/admin/prompts">Prompts</a>.
</p>
</div>
</section>
<section class="card">
<h2 class="card__title">Tool calls in an ordinary chat</h2>
<p class="card__lede">
A model ends its own turn the moment it stops asking for tools — that is
it saying it has what it needs, and nothing here overrides it. This is a
ceiling for the case where it never says so.
</p>
<div class="field">
<label class="field__label" for="max-chat-rounds">Most rounds of tool calls</label>
<input class="input" id="max-chat-rounds" name="max_chat_rounds" type="number"
min="0" max="100" value="{{ values.max_chat_rounds }}">
<p class="field__hint">
Several tools can be called in one round, so this is not a count of
tools. Leave room for at least two: <code>knowledge_get</code> and
<code>notes_get</code> read a document by an id a <em>search</em>
returned, so a ceiling of one leaves the library searchable and not
readable. <code>0</code> means no ceiling, which is how an agent chat
already works — those are bounded under
<a href="/admin/agents">Agents</a> by time and tokens instead.
</p>
</div>
</section>
<section class="card">
<h2 class="card__title">
Registration
{% if values.allow_signup %}
<span class="badge badge--success">open</span>
{% else %}
<span class="badge badge--danger">closed</span>
{% endif %}
</h2>
<div class="field">
<label class="checkbox">
<input type="checkbox" name="allow_signup" value="true"
{{ 'checked' if values.allow_signup }}>
<span>Anyone who can reach this instance may create an account</span>
</label>
<p class="field__hint">
Turn this off once your users exist. Sign-in is unaffected — existing
accounts keep working, and the "Create one" link disappears from the
sign-in page.
</p>
</div>
{% if values.allow_signup and user_count > 0 %}
<div class="alert alert--warning">
{{ icon("warning", "alert__icon") }}
<div>
<strong>Registration is open.</strong>
<div class="text-sm" style="margin-top: var(--sp-1)">
This instance has {{ user_count }} account{{ '' if user_count == 1 else 's' }}.
Anyone who can reach it can add another, and every account can use your
configured models and API keys.
</div>
</div>
</div>
{% endif %}
<p class="field__hint">
<code>LEMBAS_ALLOW_SIGNUP</code> in the environment sets only the starting
value. Once saved here, this setting wins.
</p>
</section>
<div class="form-actions"><button class="btn btn--primary" type="submit">Save settings</button></div>
</form>
{% endblock %}