Files
LLeMbas/src/lembas/web/templates/admin/search.html
T
Jaroslav BenešandClaude Opus 5 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

187 lines
7.5 KiB
HTML

{% extends "admin/_layout.html" %}
{% from "_macros.html" import icon %}
{% set section = "search" %}
{% block title %}Web search - {{ brand.name }}{% endblock %}
{% block heading %}Web search{% endblock %}
{% block admin_content %}
<p class="admin-lede">
Lets a model look things up while it answers. It is offered as a tool the
model chooses to call, so nothing changes for a question that does not need
it — and it is only offered to models marked as supporting tools, because
sending a tool list to one that does not fails the whole request.
</p>
{% if saved %}
<div class="alert alert--success">{{ icon("check", "icon--sm") }} <span>Search settings saved.</span></div>
{% endif %}
<form method="post" action="/admin/search">
<section class="card">
<h2 class="card__title">
Web search
{% if values.enabled %}<span class="badge badge--success">on</span>
{% else %}<span class="badge">off</span>{% endif %}
</h2>
<div class="field">
<label class="checkbox">
<input type="checkbox" name="enabled" value="true" {{ 'checked' if values.enabled }}>
<span>Offer web search to models that support tools</span>
</label>
<p class="field__hint">
Who may use it is a permission — <code>tools.web_search</code> under
Groups &amp; permissions.
</p>
</div>
</section>
<section class="card">
<h2 class="card__title">Provider</h2>
<div class="field">
{% for provider in providers %}
<label class="checkbox" style="align-items: flex-start">
<input type="radio" name="provider" value="{{ provider.key }}"
{{ 'checked' if values.provider == provider.key }}>
<span>
<strong>{{ provider.label }}</strong>
{% if not provider.needs_setup %}<span class="badge">no setup</span>{% endif %}
<div class="text-xs faint">{{ provider.description }}</div>
{% if problems[provider.key] %}
<div class="text-xs" style="color: var(--danger)">{{ problems[provider.key] }}</div>
{% endif %}
</span>
</label>
{% endfor %}
</div>
<div class="grid grid--3">
<div class="field">
<label class="field__label" for="max-results">Results per search</label>
<input class="input" id="max-results" name="max_results" type="number"
min="1" max="20" value="{{ values.max_results }}">
<p class="field__hint">A ceiling — a model asking for more gets this.</p>
</div>
<div class="field">
<label class="field__label" for="safesearch">Safe search</label>
<select class="select" id="safesearch" name="safesearch">
{% for option in safesearch_options %}
<option value="{{ option }}" {{ 'selected' if option == values.safesearch }}>
{{ option }}
</option>
{% endfor %}
</select>
</div>
<div class="field">
<label class="field__label" for="timeout">Timeout (seconds)</label>
<input class="input" id="timeout" name="timeout" type="number"
min="5" max="120" step="1" value="{{ values.timeout }}">
</div>
</div>
<div class="field">
<label class="field__label" for="region">DuckDuckGo region</label>
<input class="input" id="region" name="region" maxlength="16"
value="{{ values.region }}" placeholder="wt-wt">
<p class="field__hint">
<code>wt-wt</code> is no region at all. <code>uk-en</code>,
<code>de-de</code> and so on bias results to a country.
</p>
</div>
</section>
<section class="card">
<h2 class="card__title">SearXNG</h2>
<p class="card__lede">
Only used when SearXNG is the chosen provider. Your own instance, so no
third party sees the queries.
</p>
<div class="field">
<label class="field__label" for="searxng-base-url">Instance URL</label>
<input class="input" id="searxng-base-url" name="searxng_base_url" type="url"
value="{{ values.searxng_base_url }}" placeholder="http://127.0.0.1:8888">
<p class="field__hint">
A stock SearXNG refuses JSON. Add <code>- json</code> under
<code>search.formats</code> in its <code>settings.yml</code> and restart
it, or every search will fail with that message.
</p>
</div>
</section>
<section class="card">
<h2 class="card__title">Saving links</h2>
<p class="card__lede">
Applies to the composer's <strong>Link</strong> option and to anything the
model fetches: {{ brand.name }} retrieves the page and keeps its text.
</p>
<div class="field">
<label class="checkbox">
<input type="checkbox" name="fetch_enabled" value="true"
{{ 'checked' if values.fetch_enabled }}>
<span>Let a model fetch a page itself</span>
</label>
<p class="field__hint">
Offers the <code>fetch</code> tool, so a model can read an address it
found in a search result or was given. Turning this off leaves the
composer's Link option working: that one is somebody's instruction,
while this is the model choosing an address — possibly one it read in a
page it had just fetched.
</p>
</div>
<div class="field">
<label class="checkbox">
<input type="checkbox" name="allow_private_fetch" value="true"
{{ 'checked' if values.allow_private_fetch }}>
<span>Allow fetching addresses on this machine and this network</span>
</label>
<p class="field__hint">
Off by default, and worth leaving off. This server can reach your
router, your other services and {{ brand.name }} itself; the address to fetch can
come from a model, which can be talked into things by a web page it just
read. Turn this on only if you actually want to archive pages from your
own network.
</p>
</div>
</section>
<section class="card">
<h2 class="card__title">Firecrawl</h2>
<div class="grid grid--2">
<div class="field">
<label class="field__label" for="firecrawl-base-url">API URL</label>
<input class="input" id="firecrawl-base-url" name="firecrawl_base_url" type="url"
value="{{ values.firecrawl_base_url }}"
placeholder="https://api.firecrawl.dev">
<p class="field__hint">Change only for a self-hosted Firecrawl.</p>
</div>
<div class="field">
<label class="field__label" for="firecrawl-api-key">API key</label>
<input class="input" id="firecrawl-api-key" name="firecrawl_api_key" type="password"
value="{{ unchanged if masked else '' }}"
placeholder="{{ masked or 'fc-...' }}" autocomplete="off">
<p class="field__hint">Encrypted at rest. Clear the field to remove it.</p>
</div>
</div>
</section>
<div class="form-actions"><button class="btn btn--primary" type="submit">Save settings</button></div>
</form>
<section class="card">
<h2 class="card__title">Try it</h2>
<p class="card__lede">
Runs a real search against the <em>saved</em> settings, which is what a chat
would do. Save first if you have just changed something.
</p>
<div class="row" style="gap: var(--sp-2)">
<input class="input" id="test-query" name="query" placeholder="mallorn tree"
style="flex: 1">
<button class="btn" type="button" hx-post="/admin/search/test"
hx-include="#test-query" hx-target="#search-test" hx-swap="outerHTML">
{{ icon("search", "icon--sm") }} Search
</button>
</div>
<div id="search-test"></div>
</section>
{% endblock %}