Knowledge, notes, memory and skills, and a harness to make them used

Four places a model can reach for, differing in who writes a record and how it
gets in front of the model.

**Knowledge** is uploaded by a person and searched by the model. It goes through
`services/files.py:prepare` — the same pipeline as a chat attachment — so the
same PDF produces the same text whichever way it arrived, and `Document` carries
the same content columns as `Attachment` for the same reason.

**Notes** are written by the model and edited by you. Too long to inject, so
they are searched.

**Memory** is short facts, and every one of them goes into every request. That
single decision is where the rest of its design comes from: records are capped
short, the block has a budget, there is no search tool because the model is
already looking at them, and they are not shareable — a record about a person is
not content to hand round.

**Skills** are saved procedures. Only the name and description are injected; the
body is fetched when the model decides one applies, which is what makes a
hundred skills affordable. A model may write and revise its own — the safety
story is not a gate but a record: every revision is kept, attributed and
revertible. A model that has just read a hostile page can save a skill that
outlives the conversation, and the honest mitigation is that it is visible and
undoable rather than that it was prevented.

**The harness** is why any of it gets used. A model handed a tools array
ignores it and answers from recall, because nothing in the request suggests
otherwise. `services/harness.py` assembles a preamble from what this chat
actually has: when to reach for each tool, the memories, the skill index.

This is an exception to "system prompts are precedence, not concatenation", and
a deliberate one. That rule governs the three *authored* layers and is
untouched — exactly one still wins. The harness is a different axis: it
describes the machinery rather than the behaviour, nobody authored it, and there
is nothing for it to disagree with. It is prepended to whichever authored prompt
won, in one system message, since several endpoints reject a second.

Supporting changes:

- **Sharing**, in one helper. `visible_to()` is the only definition of who can
  see a library item and every listing and tool goes through it. Sharing grants
  *reading*; two people editing one note with no history and no merge is worse
  than copying it. **Administrators do not bypass this** — they bypass
  permissions elsewhere because an admin can grant themselves those anyway, but
  reading somebody's private notes is a different act.
- **FTS5**, created by `db/migrations.py:ensure_fts` with the triggers an
  external-content index needs. Idempotent, like the column sync beside it.
  Terms are ANDed and then ORed: the caller is usually a model writing a whole
  question, and requiring every word loses the match on one absent term.
- **The attach button is a menu** — file, image, a web page, or a document from
  the library. Attaching a document copies it, because history must not change
  when a document is edited later.
- **A URL fetcher with an SSRF guard.** This server can reach the router, the
  other services on the box and LLeMbas itself, and the address can come from a
  model. Private ranges are refused *after resolution* and redirects are followed
  by hand so every hop is checked. An admin can open it deliberately.
- **Model capabilities split** into protocol support and a toggle per built-in
  tool. Rows predating the split have no `tool_*` keys, and absent counts as on
  when `tools` is on — otherwise an upgrade silently takes web search away from
  every model already configured for it.

Also fixes the test fixture, which built the schema with `create_all` and so ran
against a database without the FTS tables production has; it now runs
`sync_schema`, the same path startup takes.

430 tests, ruff clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jaroslav Beneš
2026-07-21 19:43:57 +02:00
parent 3ad4c82b86
commit 1eba860d39
49 changed files with 5028 additions and 148 deletions
+4
View File
@@ -69,6 +69,10 @@
transition: color var(--transition-fast), border-color var(--transition-fast);
}
.tabs__tab:hover { color: var(--ink); }
/* The library's tabs are links between pages rather than radios, so the active
one is marked server-side. Same bar, same look. */
.tabs__tab.is-active { color: var(--ink); border-bottom-color: var(--accent); }
a.tabs__tab { text-decoration: none; }
.tabs__panel { display: none; }
+28
View File
@@ -733,6 +733,34 @@ button, input, textarea, select {
box-shadow: var(--shadow-lg);
overflow: hidden;
}
/* The composer's attach menu opens upwards: it sits at the bottom of the
window, so a menu dropping down would be off screen. */
.picker--up .picker__menu {
top: auto;
bottom: calc(100% + var(--sp-1));
left: 0;
right: auto;
}
.picker__menu--compact { width: min(18rem, calc(100vw - var(--sp-8))); padding: var(--sp-1); }
.picker__option-note {
font-size: var(--text-xs);
color: var(--ink-faint);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* A dialog that holds a searchable list rather than a question. */
.dialog--wide { width: min(34rem, calc(100vw - var(--sp-6))); }
.dialog__results {
max-height: min(24rem, 50vh);
overflow-y: auto;
scrollbar-width: thin;
border: 1px solid var(--border);
border-radius: var(--radius);
}
.dialog__results .picker__list { max-height: none; }
.picker__search { padding: var(--sp-2); border-bottom: 1px solid var(--border); }
.input--sm { height: var(--control-h-sm); font-size: var(--text-xs); }
.picker__list { max-height: 22rem; overflow-y: auto; scrollbar-width: thin; padding: var(--sp-1); }
+120
View File
@@ -148,6 +148,126 @@
});
}
/* --- Attaching something that is not a file ----------------------------
The composer's menu offers four things; two of them are the file picker
with a different filter, and two need a round trip. Both of those post a
form and get a chip back, exactly like an upload, so the composer does not
have to know where a chip came from. */
function chipTarget() {
return document.getElementById("attachments");
}
function chatId() {
var input = document.getElementById("file-input");
var url = (input && input.dataset.uploadUrl) || "";
var match = url.match(/chat_id=([^&]+)/);
return match ? decodeURIComponent(match[1]) : "";
}
function postForChip(url, body) {
var target = chipTarget();
if (!target) return Promise.resolve();
return fetch(url, { method: "POST", body: body, credentials: "same-origin" })
.then(function (response) { return response.text(); })
.then(function (html) {
target.insertAdjacentHTML("beforeend", html);
if (window.htmx) window.htmx.process(target.lastElementChild);
});
}
function attachLink() {
if (!window.lembas || !window.lembas.prompt) return;
window.lembas.prompt({
title: "Attach a web page",
message: "The page is fetched now and its text attached, so it will not " +
"change between writing this and sending it.",
placeholder: "https://example.com/article",
confirmLabel: "Fetch",
}).then(function (url) {
if (!url || !url.trim()) return;
var body = new FormData();
body.append("url", url.trim());
body.append("chat_id", chatId());
return postForChip("/api/files/link", body);
});
}
/* The knowledge dialog re-queries the server as you type rather than
filtering in the browser: the library is searched with FTS, which is what
makes it work at five hundred documents instead of five. */
function attachKnowledge() {
var dialog = document.createElement("dialog");
dialog.className = "dialog dialog--wide";
dialog.innerHTML =
'<div class="dialog__form">' +
'<h2 class="dialog__title">Attach from your library</h2>' +
'<input class="input" type="search" placeholder="Search your documents…" ' +
'aria-label="Search your documents">' +
'<div class="dialog__results"></div>' +
'<div class="dialog__actions"><button class="btn" type="button">Close</button></div>' +
"</div>";
document.body.appendChild(dialog);
var search = dialog.querySelector("input");
var results = dialog.querySelector(".dialog__results");
var close = dialog.querySelector("button");
function load(query) {
fetch("/api/files/knowledge-picker?q=" + encodeURIComponent(query || ""), {
credentials: "same-origin",
})
.then(function (response) { return response.text(); })
.then(function (html) { results.innerHTML = html; })
.catch(function () { results.textContent = "Could not load your library."; });
}
var pending = null;
search.addEventListener("input", function () {
clearTimeout(pending);
pending = setTimeout(function () { load(search.value); }, 200);
});
results.addEventListener("click", function (event) {
var option = event.target.closest("[data-attach-knowledge]");
if (!option) return;
var body = new FormData();
body.append("document_id", option.dataset.attachKnowledge);
body.append("chat_id", chatId());
postForChip("/api/files/from-knowledge", body);
finish();
});
function finish() {
dialog.close();
setTimeout(function () { dialog.remove(); }, 200);
}
close.addEventListener("click", finish);
dialog.addEventListener("cancel", function (event) {
event.preventDefault();
finish();
});
dialog.addEventListener("click", function (event) {
if (event.target === dialog) finish();
});
dialog.showModal();
load("");
search.focus();
}
document.addEventListener("click", function (event) {
var choice = event.target.closest("[data-attach]");
if (!choice) return;
event.preventDefault();
var kind = choice.dataset.attach;
if (kind === "file") document.getElementById("file-input").click();
else if (kind === "image") document.getElementById("image-input").click();
else if (kind === "link") attachLink();
else if (kind === "knowledge") attachKnowledge();
});
function setupDropzone() {
var zone = document.querySelector("[data-dropzone]");
if (!zone) return;
@@ -124,10 +124,11 @@
<section class="card">
<h2 class="card__title">Capabilities</h2>
<p class="card__lede">
Endpoints rarely advertise these reliably, so they are your call.
<strong>reasoning</strong> shows the thinking block,
<strong>vision</strong> lets images be sent to this model, and
<strong>tools</strong> is reserved for a feature not built yet.
What this endpoint can do. Endpoints rarely advertise it reliably, so it
is your call. <strong>reasoning</strong> shows the thinking block,
<strong>vision</strong> lets images be sent, and <strong>tools</strong> is
whether a tool list may be sent at all — turn it on for a model that does
not support tool calling and every one of its replies fails.
</p>
<div class="checkbox-row">
{% for name in capabilities %}
@@ -140,6 +141,35 @@
</div>
</section>
<section class="card">
<h2 class="card__title">
Built-in tools
{% if not (model.capabilities_json or {}).get("tools") %}
<span class="badge">needs tools</span>
{% endif %}
</h2>
<p class="card__lede">
What this model is given, as opposed to what it is capable of. None of it
applies unless <strong>tools</strong> is ticked above. Each one is also
subject to the instance being configured for it and to the reader's own
permissions — this only decides whether it is offered to <em>this</em>
model.
</p>
<div class="checkbox-row">
{# A model configured before these existed has no tool_* keys. Ticked by
default when `tools` is on, matching what the tool registry does, so
the form shows what will actually happen rather than a row of empty
boxes that would take web search away on the next save. #}
{% for key, label in tool_capabilities %}
<label class="checkbox">
<input type="checkbox" name="capability" value="{{ key }}"
{{ 'checked' if (model.capabilities_json or {}).get(key, tool_default) }}>
<span>{{ label }}</span>
</label>
{% endfor %}
</div>
</section>
<section class="card">
<h2 class="card__title">Availability</h2>
@@ -108,6 +108,28 @@
</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: LLeMbas retrieves the page and keeps its text.
</p>
<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 LLeMbas 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">
+56 -7
View File
@@ -17,10 +17,16 @@
<div class="composer" {% if can.get("files.upload") %}data-dropzone{% endif %}>
{% if can.get("files.upload") %}
{# Outside the form: it is only ever read by JavaScript, and inside it would
be submitted as an empty file part on every message. #}
be submitted as an empty file part on every message.
Two inputs rather than one whose accept attribute is rewritten: changing
accept and then calling click() in the same tick is unreliable in Safari,
and two hidden inputs cost nothing. #}
<input class="visually-hidden" type="file" id="file-input" multiple
data-upload-url="/api/files{% if chat %}?chat_id={{ chat.id }}{% endif %}"
accept="image/*,.pdf,.txt,.md,.csv,.json,.py,.js,.ts,.rs,.go,.sh,.sql,.yaml,.yml,.toml,.log"
accept=".pdf,.txt,.md,.csv,.json,.py,.js,.ts,.rs,.go,.sh,.sql,.yaml,.yml,.toml,.log"
onchange="window.lembas.uploadFiles(this.files); this.value = ''">
<input class="visually-hidden" type="file" id="image-input" multiple accept="image/*"
onchange="window.lembas.uploadFiles(this.files); this.value = ''">
{% endif %}
@@ -47,11 +53,54 @@
<div class="composer__row">
{% if can.get("files.upload") %}
<button class="btn btn--icon composer__btn" type="button"
aria-label="Attach a file" title="Attach a file"
onclick="document.getElementById('file-input').click()">
{{ icon("attach") }}
</button>
{# A menu rather than the file picker straight away: there are four ways
to attach something now, and only one of them is a file on disk.
Uses the same picker machinery as the model chooser -- see ui.js. #}
<div class="picker picker--up" data-picker>
<button class="btn btn--icon composer__btn" type="button" data-picker-toggle
aria-haspopup="menu" aria-expanded="false"
aria-label="Attach" title="Attach">
{{ icon("attach") }}
</button>
<div class="picker__menu picker__menu--compact" data-picker-menu role="menu"
hidden aria-label="Attach">
<button class="picker__option" type="button" role="menuitem"
data-attach="file">
{{ icon("attach", "icon--sm") }}
<span class="picker__option-body">
<span class="picker__option-name">File</span>
<span class="picker__option-note">PDF, text, code</span>
</span>
</button>
<button class="picker__option" type="button" role="menuitem"
data-attach="image">
{{ icon("image", "icon--sm") }}
<span class="picker__option-body">
<span class="picker__option-name">Image</span>
<span class="picker__option-note">Sent only to vision models</span>
</span>
</button>
<button class="picker__option" type="button" role="menuitem"
data-attach="link">
{{ icon("link", "icon--sm") }}
<span class="picker__option-body">
<span class="picker__option-name">Link</span>
<span class="picker__option-note">Fetch a page and attach its text</span>
</span>
</button>
{% if can.get("library.use") %}
<button class="picker__option" type="button" role="menuitem"
data-attach="knowledge">
{{ icon("archive", "icon--sm") }}
<span class="picker__option-body">
<span class="picker__option-name">Knowledge</span>
<span class="picker__option-note">From your library</span>
</span>
</button>
{% endif %}
</div>
</div>
{% endif %}
<textarea class="composer__input" name="content" rows="1"
@@ -0,0 +1,38 @@
{% from "_macros.html" import icon %}
{#
The list inside the composer's Knowledge dialog.
Swapped in on its own so typing in the filter re-queries the server: the
library is searched with FTS rather than filtered in the browser, which is
what makes it work when there are five hundred documents rather than five.
#}
<div id="knowledge-results">
{% if not documents %}
<p class="muted text-sm" style="padding: var(--sp-3)">
{% if q %}
Nothing matches “{{ q }}”.
{% else %}
Your library is empty. <a href="/library/knowledge">Add something to it</a>.
{% endif %}
</p>
{% else %}
<ul class="picker__list">
{% for document in documents %}
<li>
<button class="picker__option" type="button"
data-attach-knowledge="{{ document.id }}">
{{ icon("archive" if not document.is_image else "image", "icon--sm") }}
<span class="picker__option-body">
<span class="picker__option-name">{{ document.title }}</span>
<span class="picker__option-note">
{{ document.kind }}
{%- if document.pages %} · {{ document.pages }}p{% endif %}
{%- if document.owner_id != user.id %} · shared{% endif %}
</span>
</span>
</button>
</li>
{% endfor %}
</ul>
{% endif %}
</div>
@@ -0,0 +1,46 @@
{% extends "base.html" %}
{% from "_macros.html" import icon %}
{#
The library shell.
Keeps the chat sidebar rather than having its own like the admin area does:
administration is a different place, but a library is part of using the thing
— you go there mid-conversation to add a document and come straight back.
#}
{% block head %}
<link rel="stylesheet" href="{{ url_for('static', path='css/chat.css') }}">
<link rel="stylesheet" href="{{ url_for('static', path='css/admin.css') }}">
{% endblock %}
{% block body_attrs %} data-authenticated="true"{% endblock %}
{% block body %}
<div class="shell">
{% include "partials/sidebar.html" %}
<main class="main">
<header class="topbar">
<h1 class="topbar__title">{% block heading %}Library{% endblock %}</h1>
<div class="topbar__actions">{% block actions %}{% endblock %}</div>
</header>
<nav class="tabs__bar" aria-label="Library">
<a class="tabs__tab {{ 'is-active' if section == 'knowledge' }}"
href="/library/knowledge">{{ icon("archive", "icon--sm") }} Knowledge</a>
<a class="tabs__tab {{ 'is-active' if section == 'notes' }}"
href="/library/notes">{{ icon("pencil", "icon--sm") }} Notes</a>
<a class="tabs__tab {{ 'is-active' if section == 'skills' }}"
href="/library/skills">{{ icon("sparkle", "icon--sm") }} Skills</a>
<span class="spacer"></span>
<a class="tabs__tab" href="/settings">{{ icon("user", "icon--sm") }} Memory</a>
</nav>
<div class="admin-scroll">
<div class="admin-page">
{% block library_content %}{% endblock %}
</div>
</div>
</main>
</div>
{% endblock %}
@@ -0,0 +1,15 @@
{#
Shared pager. Rendered only when there is more than one page, so a small
library shows nothing at all rather than a lone disabled "1".
#}
{% if pager.pages > 1 %}
<div class="btn-row" style="justify-content: center; margin-top: var(--sp-5)">
{% if pager.page > 1 %}
<a class="btn btn--sm" href="?page={{ pager.page - 1 }}{{ '&q=' ~ q if q }}">Previous</a>
{% endif %}
<span class="text-sm faint">Page {{ pager.page }} of {{ pager.pages }} · {{ pager.total }} items</span>
{% if pager.page < pager.pages %}
<a class="btn btn--sm" href="?page={{ pager.page + 1 }}{{ '&q=' ~ q if q }}">Next</a>
{% endif %}
</div>
{% endif %}
@@ -0,0 +1,66 @@
{% from "_macros.html" import icon %}
{#
The share panel on a detail page.
Sharing grants *reading*. Two people editing one note with no history and no
merge is worse than the inconvenience of copying it, so there is no "can edit"
here and the copy is deliberate rather than missing.
Only the owner sees this at all: someone a thing was shared with cannot share
it onward, which keeps "who can see this" answerable by asking one person.
#}
{% if is_owner and can_share %}
<section class="card">
<h2 class="card__title">
Shared with
{% if shared_users or shared_groups %}
<span class="badge badge--gold">{{ shared_users|length + shared_groups|length }}</span>
{% else %}
<span class="badge">nobody</span>
{% endif %}
</h2>
<p class="card__lede">
They will be able to read this, and their models will find it. They cannot
change it or share it on.
</p>
{% if groups %}
<div class="field">
<label class="field__label">Groups</label>
<div class="checkbox-row">
{% for group in groups %}
<label class="checkbox">
<input type="checkbox" name="share_group" value="{{ group.id }}"
{{ 'checked' if group.id in shared_groups }}>
<span>{{ group.name }}</span>
</label>
{% endfor %}
</div>
</div>
{% endif %}
{% if people %}
<div class="field">
<label class="field__label">People</label>
<div class="checkbox-row">
{% for person in people %}
<label class="checkbox">
<input type="checkbox" name="share_user" value="{{ person.id }}"
{{ 'checked' if person.id in shared_users }}>
<span>{{ person.name }}</span>
</label>
{% endfor %}
</div>
</div>
{% endif %}
{% if not groups and not people %}
<p class="muted text-sm">There is nobody else on this instance yet.</p>
{% endif %}
</section>
{% elif not is_owner %}
<div class="alert">
{{ icon("users", "alert__icon") }}
<span>Shared with you. You can read this but not change it.</span>
</div>
{% endif %}
@@ -0,0 +1,91 @@
{% extends "library/_layout.html" %}
{% from "_macros.html" import icon %}
{% set section = "knowledge" %}
{% block title %}Knowledge - LLeMbas{% endblock %}
{% block heading %}Knowledge{% endblock %}
{% block library_content %}
<p class="admin-lede">
Documents, images and saved web pages you have collected. A model with the
knowledge tool searches these before it searches the web, and you can attach
any of them to a message.
</p>
<section class="card">
<h2 class="card__title">Add</h2>
<div class="grid grid--2">
<form method="post" action="/api/library/documents" enctype="multipart/form-data">
<div class="field">
<label class="field__label" for="doc-file">A file</label>
<input class="input" id="doc-file" type="file" name="file" required
accept="image/*,.pdf,.txt,.md,.csv,.json,.py,.js,.ts,.rs,.go,.sh,.sql,.yaml,.yml,.toml,.log">
<p class="field__hint">
Images, PDFs and text. PDFs have their text read once, now.
</p>
</div>
<button class="btn btn--primary" type="submit">Upload</button>
</form>
<form method="post" action="/api/library/documents/link">
<div class="field">
<label class="field__label" for="doc-url">A web page</label>
<input class="input" id="doc-url" type="url" name="url" required
placeholder="https://example.com/article">
<p class="field__hint">
Fetched now and kept as text, so it survives the page changing.
</p>
</div>
<button class="btn" type="submit">Save page</button>
</form>
</div>
</section>
<form method="get" action="/library/knowledge" class="btn-row" style="margin-bottom: var(--sp-5)">
<input class="input" type="search" name="q" value="{{ q }}" style="flex: 1"
placeholder="Search titles and contents…">
<button class="btn" type="submit">{{ icon("search", "icon--sm") }} Search</button>
{% if q %}<a class="btn btn--sm" href="/library/knowledge">Clear</a>{% endif %}
</form>
{% if not documents %}
<div class="empty">
{{ icon("archive", "empty__mark") }}
<h2 class="empty__title">{{ "Nothing found" if q else "The shelves are bare" }}</h2>
<p class="empty__text">
{% if q %}
No document matches “{{ q }}”.
{% else %}
Add a file or a web page above and it becomes searchable — by you, and by
any model you have given the knowledge tool.
{% endif %}
</p>
</div>
{% else %}
<ul class="model-list">
{% for document in documents %}
<li class="model-list__item">
<div style="min-width: 0">
<a href="/library/knowledge/{{ document.id }}"><strong>{{ document.title }}</strong></a>
<div class="text-xs faint">
{{ document.kind }}
{%- if document.pages %} · {{ document.pages }} page{{ '' if document.pages == 1 else 's' }}{% endif %}
{%- if document.size_bytes %} · {{ document.human_size }}{% endif %}
{%- if document.source_url %} · {{ document.source_url[:60] }}{% endif %}
</div>
{% if document.description %}
<div class="text-xs faint">{{ document.description }}</div>
{% endif %}
</div>
<div class="btn-row">
{% if document.extraction_error %}
<span class="badge badge--danger" title="{{ document.extraction_error }}">no text</span>
{% endif %}
{% if document.owner_id != user.id %}<span class="badge">shared</span>{% endif %}
</div>
</li>
{% endfor %}
</ul>
{% include "library/_pager.html" %}
{% endif %}
{% endblock %}
@@ -0,0 +1,85 @@
{% extends "library/_layout.html" %}
{% from "_macros.html" import icon %}
{% set section = "knowledge" %}
{% block title %}{{ document.title }} - LLeMbas{% endblock %}
{% block heading %}{{ document.title }}{% endblock %}
{% block library_content %}
<div class="btn-row" style="margin-bottom: var(--sp-5)">
<a class="btn btn--sm" href="/library/knowledge">{{ icon("chevron-right", "icon--sm") }} All documents</a>
</div>
<form method="post" action="/api/library/documents/{{ document.id }}">
<section class="card">
<h2 class="card__title">Details</h2>
<div class="field">
<label class="field__label" for="title">Title</label>
<input class="input" id="title" name="title" value="{{ document.title }}"
maxlength="300" {{ 'disabled' if not is_owner }}>
</div>
<div class="field">
<label class="field__label" for="description">Description</label>
<textarea class="textarea" id="description" name="description" rows="2"
{{ 'disabled' if not is_owner }}
placeholder="What this is, and when it is worth reading.">{{ document.description }}</textarea>
<p class="field__hint">
Searched along with the contents, so a line here helps a model find it.
</p>
</div>
<dl class="detail-list">
<dt>Kind</dt><dd>{{ document.kind }}</dd>
{% if document.source_url %}
<dt>Source</dt>
<dd><a href="{{ document.source_url }}" target="_blank" rel="noopener noreferrer nofollow">{{ document.source_url }}</a></dd>
{% endif %}
{% if document.pages %}<dt>Pages</dt><dd>{{ document.pages }}</dd>{% endif %}
{% if document.size_bytes %}<dt>Size</dt><dd>{{ document.human_size }}</dd>{% endif %}
<dt>Text</dt>
<dd>
{{ "{:,}".format(document.extracted_text|length) }} characters
{%- if document.truncated %} · truncated{% endif %}
</dd>
</dl>
{% if document.extraction_error %}
<div class="alert alert--warning">
{{ icon("warning", "alert__icon") }} <span>{{ document.extraction_error }}</span>
</div>
{% endif %}
</section>
{% include "library/_share.html" %}
{% if is_owner %}
<div class="form-actions">
<button class="btn btn--primary" type="submit">Save</button>
{% if document.stored_name %}
<a class="btn" href="/api/library/documents/{{ document.id }}/content">Download</a>
{% endif %}
<span class="spacer"></span>
<button class="btn btn--danger" type="submit"
formaction="/api/library/documents/{{ document.id }}/delete"
data-confirm-button="Delete “{{ document.title }}”? Messages it was already attached to keep their copy."
data-confirm-title="Delete document">
{{ icon("trash", "icon--sm") }} Delete
</button>
</div>
{% endif %}
</form>
{% if document.is_image and document.stored_name %}
<section class="card">
<h2 class="card__title">Preview</h2>
<img src="/api/library/documents/{{ document.id }}/content" alt="{{ document.title }}"
style="max-width: 100%; border-radius: var(--radius)">
</section>
{% elif document.extracted_text %}
<section class="card">
<h2 class="card__title">Text</h2>
<p class="card__lede">What a model is given when it reads this.</p>
<div class="reasoning__body" style="max-height: 30rem">{{ document.extracted_text }}</div>
</section>
{% endif %}
{% endblock %}
@@ -0,0 +1,64 @@
{% extends "library/_layout.html" %}
{% from "_macros.html" import icon %}
{% set section = "notes" %}
{% block title %}{{ note.title if note else "New note" }} - LLeMbas{% endblock %}
{% block heading %}{{ note.title if note else "New note" }}{% endblock %}
{% block library_content %}
<div class="btn-row" style="margin-bottom: var(--sp-5)">
<a class="btn btn--sm" href="/library/notes">{{ icon("chevron-right", "icon--sm") }} All notes</a>
</div>
<form method="post"
action="{{ '/api/library/notes/' ~ note.id if note else '/api/library/notes' }}">
<section class="card">
<div class="field">
<label class="field__label" for="title">Title</label>
<input class="input" id="title" name="title" maxlength="300" required
value="{{ note.title if note else '' }}"
{{ 'disabled' if note and not is_owner }}
placeholder="What this note is about">
<p class="field__hint">
Shown in search results, so it is what decides whether a model opens it.
</p>
</div>
<div class="field">
<label class="field__label" for="body">Body</label>
<textarea class="textarea" id="body" name="body" rows="18"
{{ 'disabled' if note and not is_owner }}
placeholder="Markdown.">{{ note.body if note else '' }}</textarea>
</div>
{% if note and note.author == "model" %}
<p class="field__hint">
{{ icon("sparkle", "icon--sm") }}
Written by a model. Edit it freely — it is yours.
</p>
{% endif %}
</section>
{% if note %}{% include "library/_share.html" %}{% endif %}
{% if not note or is_owner %}
<div class="form-actions">
<button class="btn btn--primary" type="submit">{{ "Save" if note else "Create note" }}</button>
{% if note %}
<span class="spacer"></span>
<button class="btn btn--danger" type="submit"
formaction="/api/library/notes/{{ note.id }}/delete"
data-confirm-button="Delete “{{ note.title }}”?"
data-confirm-title="Delete note">
{{ icon("trash", "icon--sm") }} Delete
</button>
{% endif %}
</div>
{% endif %}
</form>
{% if note and body_html %}
<section class="card">
<h2 class="card__title">Rendered</h2>
<div class="msg__body">{{ body_html|safe }}</div>
</section>
{% endif %}
{% endblock %}
@@ -0,0 +1,55 @@
{% extends "library/_layout.html" %}
{% from "_macros.html" import icon %}
{% set section = "notes" %}
{% block title %}Notes - LLeMbas{% endblock %}
{% block heading %}Notes{% endblock %}
{% block actions %}
<a class="btn btn--primary btn--sm" href="/library/notes/new">{{ icon("plus", "icon--sm") }} New note</a>
{% endblock %}
{% block library_content %}
<p class="admin-lede">
Longer things worth keeping between conversations. A model writes these itself
when it works something out, and you can edit or delete any of them — they are
yours, not its.
</p>
<form method="get" action="/library/notes" class="btn-row" style="margin-bottom: var(--sp-5)">
<input class="input" type="search" name="q" value="{{ q }}" style="flex: 1"
placeholder="Search notes…">
<button class="btn" type="submit">{{ icon("search", "icon--sm") }} Search</button>
{% if q %}<a class="btn btn--sm" href="/library/notes">Clear</a>{% endif %}
</form>
{% if not notes %}
<div class="empty">
{{ icon("pencil", "empty__mark") }}
<h2 class="empty__title">{{ "Nothing found" if q else "No notes yet" }}</h2>
<p class="empty__text">
{% if q %}
No note matches “{{ q }}”.
{% else %}
Give a model the notes tool and it will start keeping them, or write the
first one yourself.
{% endif %}
</p>
</div>
{% else %}
<ul class="model-list">
{% for note in notes %}
<li class="model-list__item">
<div style="min-width: 0">
<a href="/library/notes/{{ note.id }}"><strong>{{ note.title }}</strong></a>
<div class="text-xs faint">{{ note.body[:160] }}{{ "…" if note.body|length > 160 }}</div>
</div>
<div class="btn-row">
{% if note.author == "model" %}<span class="badge badge--gold">written by a model</span>{% endif %}
{% if note.owner_id != user.id %}<span class="badge">shared</span>{% endif %}
</div>
</li>
{% endfor %}
</ul>
{% include "library/_pager.html" %}
{% endif %}
{% endblock %}
@@ -0,0 +1,126 @@
{% extends "library/_layout.html" %}
{% from "_macros.html" import icon %}
{% set section = "skills" %}
{% block title %}{{ skill.name if skill else "New skill" }} - LLeMbas{% endblock %}
{% block heading %}{{ skill.name if skill else "New skill" }}{% endblock %}
{% block library_content %}
<div class="btn-row" style="margin-bottom: var(--sp-5)">
<a class="btn btn--sm" href="/library/skills">{{ icon("chevron-right", "icon--sm") }} All skills</a>
</div>
<form method="post"
action="{{ '/api/library/skills/' ~ skill.id if skill else '/api/library/skills' }}">
<section class="card">
{% if not skill %}
<div class="field">
<label class="field__label" for="name">Name</label>
<input class="input mono" id="name" name="name" required maxlength="60"
placeholder="weekly-report" pattern="[a-zA-Z0-9 _-]+">
<p class="field__hint">
Lowercase letters, numbers and hyphens. This is how a model asks for it,
and it cannot be changed later.
</p>
</div>
{% endif %}
<div class="field">
<label class="field__label" for="description">When to use it</label>
<textarea class="textarea" id="description" name="description" rows="2" required
{{ 'disabled' if skill and not is_owner }}
placeholder="When the user asks for the weekly report.">{{ skill.description if skill else '' }}</textarea>
<p class="field__hint">
<strong>The load-bearing field.</strong> This one line is all a model
sees until it opens the skill, so it has to say when the skill applies —
not what it does.
</p>
</div>
<div class="field">
<label class="field__label" for="body">Instructions</label>
<textarea class="textarea" id="body" name="body" rows="18"
{{ 'disabled' if skill and not is_owner }}
placeholder="Markdown. Steps, conventions, things to avoid.">{{ skill.body if skill else '' }}</textarea>
</div>
{% if skill %}
<div class="field">
<label class="checkbox">
<input type="checkbox" name="enabled" value="true" {{ 'checked' if skill.enabled }}
{{ 'disabled' if not is_owner }}>
<span>Offer this skill to models</span>
</label>
<p class="field__hint">
Turned off, it stays here but disappears from the list the model sees.
</p>
</div>
{% endif %}
{% if skill and skill.author == "model" %}
<div class="alert alert--warning">
{{ icon("sparkle", "alert__icon") }}
<div>
<strong>A model wrote this version.</strong>
<div class="text-sm" style="margin-top: var(--sp-1)">
Worth reading before you rely on it. A model that has just read a web
page can be talked into things by that page, and a skill persists.
Every earlier version is below.
</div>
</div>
</div>
{% endif %}
</section>
{% if skill %}{% include "library/_share.html" %}{% endif %}
{% if not skill or is_owner %}
<div class="form-actions">
<button class="btn btn--primary" type="submit">{{ "Save" if skill else "Create skill" }}</button>
{% if skill %}
<span class="spacer"></span>
<button class="btn btn--danger" type="submit"
formaction="/api/library/skills/{{ skill.id }}/delete"
data-confirm-button="Delete the skill “{{ skill.name }}” and all its history?"
data-confirm-title="Delete skill">
{{ icon("trash", "icon--sm") }} Delete
</button>
{% endif %}
</div>
{% endif %}
</form>
{% if skill and revisions %}
<section class="card">
<h2 class="card__title">History <span class="badge">{{ revisions|length }}</span></h2>
<p class="card__lede">
What this skill said before each change. This is the whole safety story for a
model editing its own instructions: not a gate, but a record and a way back.
</p>
<ul class="model-list">
{% for revision in revisions %}
<li class="model-list__item">
<div style="min-width: 0">
<strong>{{ revision.created_at.strftime("%Y-%m-%d %H:%M") }}</strong>
{% if revision.author == "model" %}
<span class="badge badge--gold">model</span>
{% else %}
<span class="badge">you</span>
{% endif %}
{% if revision.note %}<div class="text-xs faint">{{ revision.note }}</div>{% endif %}
<div class="text-xs faint">{{ revision.body[:200] }}{{ "…" if revision.body|length > 200 }}</div>
</div>
{% if is_owner %}
<form method="post"
action="/api/library/skills/{{ skill.id }}/revert/{{ revision.id }}"
data-confirm="Put the skill back to this version? The current one is kept in the history."
data-confirm-label="Revert" data-confirm-danger="false">
<button class="btn btn--sm" type="submit">{{ icon("refresh", "icon--sm") }} Revert</button>
</form>
{% endif %}
</li>
{% endfor %}
</ul>
</section>
{% endif %}
{% endblock %}
@@ -0,0 +1,57 @@
{% extends "library/_layout.html" %}
{% from "_macros.html" import icon %}
{% set section = "skills" %}
{% block title %}Skills - LLeMbas{% endblock %}
{% block heading %}Skills{% endblock %}
{% block actions %}
<a class="btn btn--primary btn--sm" href="/library/skills/new">{{ icon("plus", "icon--sm") }} New skill</a>
{% endblock %}
{% block library_content %}
<p class="admin-lede">
Saved procedures. Every enabled skill's name and description are shown to the
model on each turn; it reads the instructions only when it decides one
applies. A model may write and revise its own — every version is kept, so any
change can be read and undone.
</p>
<form method="get" action="/library/skills" class="btn-row" style="margin-bottom: var(--sp-5)">
<input class="input" type="search" name="q" value="{{ q }}" style="flex: 1"
placeholder="Search skills…">
<button class="btn" type="submit">{{ icon("search", "icon--sm") }} Search</button>
{% if q %}<a class="btn btn--sm" href="/library/skills">Clear</a>{% endif %}
</form>
{% if not skills %}
<div class="empty">
{{ icon("sparkle", "empty__mark") }}
<h2 class="empty__title">{{ "Nothing found" if q else "No skills yet" }}</h2>
<p class="empty__text">
{% if q %}
No skill matches “{{ q }}”.
{% else %}
Write one for a task you explain often, or let a model save one after it
has worked the task out.
{% endif %}
</p>
</div>
{% else %}
<ul class="model-list">
{% for skill in skills %}
<li class="model-list__item">
<div style="min-width: 0">
<a href="/library/skills/{{ skill.id }}"><strong class="mono">{{ skill.name }}</strong></a>
<div class="text-xs faint">{{ skill.description }}</div>
</div>
<div class="btn-row">
{% if not skill.enabled %}<span class="badge">off</span>{% endif %}
{% if skill.author == "model" %}<span class="badge badge--gold">written by a model</span>{% endif %}
{% if skill.owner_id != user.id %}<span class="badge">shared</span>{% endif %}
</div>
</li>
{% endfor %}
</ul>
{% include "library/_pager.html" %}
{% endif %}
{% endblock %}
@@ -70,6 +70,13 @@
</nav>
<div class="sidebar__footer">
{% if can.get("library.use") %}
<a class="nav-item" href="/library/knowledge">
{{ icon("archive", "icon--sm") }}
<span class="nav-item__label">Library</span>
</a>
{% endif %}
<a class="nav-item" href="/settings">
{{ icon("user", "icon--sm") }}
<span class="nav-item__label">{{ user.name }}</span>
+68
View File
@@ -40,6 +40,11 @@
<label class="tabs__tab" for="tab-audio">{{ icon("speaker", "icon--sm") }} Audio</label>
{% endif %}
{% if can.get("library.use") %}
<input class="visually-hidden" type="radio" name="settings-tab" id="tab-memory">
<label class="tabs__tab" for="tab-memory">{{ icon("sparkle", "icon--sm") }} Memory</label>
{% endif %}
<input class="visually-hidden" type="radio" name="settings-tab" id="tab-security">
<label class="tabs__tab" for="tab-security">{{ icon("key", "icon--sm") }} Security</label>
</div>
@@ -275,6 +280,69 @@
</section>
{% endif %}
{# --- Memory --- #}
{% if can.get("library.use") %}
<section class="tabs__panel" data-tab="tab-memory">
<div class="card">
<h2 class="card__title">
What models remember about you
<span class="badge">{{ memories|length }}</span>
</h2>
<p class="card__lede">
Short facts, shown to every model you talk to on every turn — so
they are few and short on purpose. Anything longer belongs in a
<a href="/library/notes">note</a>. Nothing here is shared with
anyone else, ever.
</p>
{% if memories %}
<ul class="model-list">
{% for memory in memories %}
<li class="model-list__item">
<form method="post" action="/api/library/memories/{{ memory.id }}"
class="row" style="flex: 1; gap: var(--sp-2); min-width: 0">
<input class="input" name="content" value="{{ memory.content }}"
maxlength="{{ memory_limit }}" style="flex: 1">
<button class="btn btn--sm" type="submit">Save</button>
<button class="btn btn--sm btn--danger" type="submit"
formaction="/api/library/memories/{{ memory.id }}/delete"
data-confirm-button="Forget this?"
data-confirm-title="Forget">
{{ icon("trash", "icon--sm") }}
</button>
</form>
{% if memory.author == "model" %}
<span class="badge badge--gold">remembered</span>
{% endif %}
</li>
{% endfor %}
</ul>
{% else %}
<p class="muted text-sm">
Nothing yet. A model with the memory tool adds to this when you
tell it something worth keeping.
</p>
{% endif %}
</div>
<div class="card">
<h2 class="card__title">Add one</h2>
<form method="post" action="/api/library/memories" class="row"
style="gap: var(--sp-2)">
<input class="input" name="content" required style="flex: 1"
maxlength="{{ memory_limit }}"
placeholder="Prefers metric units and a 24-hour clock.">
<button class="btn btn--primary" type="submit">Remember</button>
</form>
<p class="field__hint">
One fact per record, at most {{ memory_limit }} characters. Never
put a password or a key here — it is sent to the model with every
message.
</p>
</div>
</section>
{% endif %}
{# --- Security --- #}
<section class="tabs__panel" data-tab="tab-security">
<div class="card">