Knowledge bases, and a file input that lines up
**Bases.** Documents now live in named collections rather than one flat pile, and a chat can be pointed at particular ones — "answer from the contracts folder" is a different question from "answer from everything I have ever uploaded". A chat with none attached still searches everything its owner can see, because empty means unscoped, not empty. The harness names the attached bases. Without that the model cannot tell "there is nothing about this" from "I am only allowed to see one folder", and it phrases a miss as the former. **Sharing moves to the base.** A document is visible to whoever can see the base it lives in, so `Document` is gone from the shareable types and `documents.visible()` filters through `base_id`. "This folder is the team's" is the granularity people think in; per-document grants meant answering "who can see this?" by checking every file. Moving a document between bases changes who can see it, so the destination has to be one you own. `Document.base_id` is nullable only because the column had to be added to a table that already had rows. `sweep_unfiled()` runs at startup beside the orphaned-upload sweep and files anything predating bases into its owner's default, which is what makes "always set" true everywhere else. **The file input.** `.input` gave it a fixed height and horizontal padding, so the browser's own button sat hard against the left edge while the filename floated off the centre line. A file input is two controls in one box and neither inherits anything useful, so it gets its own rule: no horizontal padding, the button sized to `--control-h` with the divider that separates it, and the text centred with line-height rather than flexbox, which file inputs do not lay out reliably. 437 tests, ruff clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
<span class="picker__option-body">
|
||||
<span class="picker__option-name">{{ document.title }}</span>
|
||||
<span class="picker__option-note">
|
||||
{{ document.kind }}
|
||||
{% if document.base %}{{ document.base.name }} · {% endif %}{{ document.kind }}
|
||||
{%- if document.pages %} · {{ document.pages }}p{% endif %}
|
||||
{%- if document.owner_id != user.id %} · shared{% endif %}
|
||||
</span>
|
||||
|
||||
@@ -68,6 +68,36 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if knowledge_bases %}
|
||||
{# Which bases this chat draws on. None ticked means everything you can
|
||||
see, which is what a chat with nothing chosen should do. #}
|
||||
<div class="field">
|
||||
<label class="field__label">Knowledge</label>
|
||||
<form hx-patch="/api/chats/{{ chat.id }}" hx-swap="none" hx-trigger="change">
|
||||
{# Always submitted, so unticking the last box still says something.
|
||||
An absent checkbox carries no signal of its own. #}
|
||||
<input type="hidden" name="knowledge_base_ids" value="">
|
||||
<div class="checkbox-row">
|
||||
{% for base in knowledge_bases %}
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" name="knowledge_base_ids" value="{{ base.id }}"
|
||||
{{ 'checked' if base.id in attached_base_ids }}>
|
||||
<span>{{ base.name }}</span>
|
||||
</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</form>
|
||||
<p class="field__hint">
|
||||
{% if attached_base_ids %}
|
||||
Searches in this chat are limited to what is ticked.
|
||||
{% else %}
|
||||
Nothing ticked, so this chat can search everything in your
|
||||
<a href="/library/knowledge">library</a>.
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if can.get("chat.params") %}
|
||||
<div class="grid grid--3">
|
||||
<div class="field">
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
{% extends "library/_layout.html" %}
|
||||
{% from "_macros.html" import icon %}
|
||||
{% set section = "knowledge" %}
|
||||
|
||||
{% block title %}{{ base.name }} - LLeMbas{% endblock %}
|
||||
{% block heading %}{{ base.name }}{% 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 knowledge bases
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% if is_owner %}
|
||||
<section class="card">
|
||||
<h2 class="card__title">Add to this base</h2>
|
||||
<div class="grid grid--2">
|
||||
<form method="post" action="/api/library/documents" enctype="multipart/form-data">
|
||||
<input type="hidden" name="base_id" value="{{ base.id }}">
|
||||
<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. A PDF has its text read once, now.
|
||||
</p>
|
||||
</div>
|
||||
<button class="btn btn--primary" type="submit">Upload</button>
|
||||
</form>
|
||||
|
||||
<form method="post" action="/api/library/documents/link">
|
||||
<input type="hidden" name="base_id" value="{{ base.id }}">
|
||||
<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>
|
||||
{% endif %}
|
||||
|
||||
<form method="get" action="/library/knowledge/{{ base.id }}" class="btn-row"
|
||||
style="margin-bottom: var(--sp-5)">
|
||||
<input class="input" type="search" name="q" value="{{ q }}" style="flex: 1"
|
||||
placeholder="Search this base…">
|
||||
<button class="btn" type="submit">{{ icon("search", "icon--sm") }} Search</button>
|
||||
{% if q %}<a class="btn btn--sm" href="/library/knowledge/{{ base.id }}">Clear</a>{% endif %}
|
||||
</form>
|
||||
|
||||
{% if not documents %}
|
||||
<div class="empty">
|
||||
{{ icon("archive", "empty__mark") }}
|
||||
<h2 class="empty__title">{{ "Nothing found" if q else "Empty" }}</h2>
|
||||
<p class="empty__text">
|
||||
{% if q %}Nothing in this base matches “{{ q }}”.
|
||||
{% else %}Add a file or a web page above.{% 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/{{ 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 %}
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% include "library/_pager.html" %}
|
||||
{% endif %}
|
||||
|
||||
<form method="post" action="/api/library/bases/{{ base.id }}" style="margin-top: var(--sp-8)">
|
||||
<section class="card">
|
||||
<h2 class="card__title">This base</h2>
|
||||
<div class="grid grid--2">
|
||||
<div class="field">
|
||||
<label class="field__label" for="name">Name</label>
|
||||
<input class="input" id="name" name="name" value="{{ base.name }}" maxlength="200"
|
||||
{{ 'disabled' if not is_owner }}>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="field__label" for="description">Description</label>
|
||||
<input class="input" id="description" name="description" maxlength="2000"
|
||||
value="{{ base.description }}" {{ 'disabled' if not is_owner }}>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{% include "library/_share.html" %}
|
||||
|
||||
{% if is_owner %}
|
||||
<div class="form-actions">
|
||||
<button class="btn btn--primary" type="submit">Save</button>
|
||||
<span class="spacer"></span>
|
||||
<button class="btn btn--danger" type="submit"
|
||||
formaction="/api/library/bases/{{ base.id }}/delete"
|
||||
data-confirm-button="Delete “{{ base.name }}” and the {{ pager.total }} document(s) in it? Messages they were attached to keep their copies."
|
||||
data-confirm-title="Delete knowledge base">
|
||||
{{ icon("trash", "icon--sm") }} Delete base
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endblock %}
|
||||
@@ -7,85 +7,60 @@
|
||||
|
||||
{% 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.
|
||||
Knowledge bases are collections of documents, images and saved web pages. Keep
|
||||
them separate — one per subject, project or client — and a chat can be pointed
|
||||
at just the ones it should draw on. Sharing happens here too: share a base and
|
||||
everything in it comes with it.
|
||||
</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>
|
||||
{% if error %}
|
||||
<div class="alert alert--error">{{ icon("warning", "alert__icon") }} <span>{{ error }}</span></div>
|
||||
{% endif %}
|
||||
|
||||
<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 %}
|
||||
{% if bases %}
|
||||
<ul class="model-list">
|
||||
{% for document in documents %}
|
||||
{% for base in bases %}
|
||||
<li class="model-list__item">
|
||||
<div style="min-width: 0">
|
||||
<a href="/library/knowledge/{{ document.id }}"><strong>{{ document.title }}</strong></a>
|
||||
<a href="/library/knowledge/{{ base.id }}"><strong>{{ base.name }}</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 %}
|
||||
{{ counts.get(base.id, 0) }} document{{ '' if counts.get(base.id, 0) == 1 else 's' }}
|
||||
{%- if base.description %} · {{ base.description }}{% 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 %}
|
||||
{% if base.owner_id != user.id %}<span class="badge">shared with you</span>{% endif %}
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% include "library/_pager.html" %}
|
||||
{% else %}
|
||||
<div class="empty">
|
||||
{{ icon("archive", "empty__mark") }}
|
||||
<h2 class="empty__title">No knowledge bases yet</h2>
|
||||
<p class="empty__text">
|
||||
Make one below, then put documents in it. A chat with no base attached
|
||||
searches everything you have; a chat pointed at one searches only that.
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<section class="card" style="margin-top: var(--sp-6)">
|
||||
<h2 class="card__title">New knowledge base</h2>
|
||||
<form method="post" action="/api/library/bases">
|
||||
<div class="grid grid--2">
|
||||
<div class="field">
|
||||
<label class="field__label" for="base-name">Name</label>
|
||||
<input class="input" id="base-name" name="name" required maxlength="200"
|
||||
placeholder="Contracts">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="field__label" for="base-description">Description</label>
|
||||
<input class="input" id="base-description" name="description" maxlength="2000"
|
||||
placeholder="What belongs in here.">
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn--primary" type="submit">{{ icon("plus", "icon--sm") }} Create</button>
|
||||
</form>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
|
||||
{% 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>
|
||||
<a class="btn btn--sm" href="/library/knowledge/{{ document.base_id }}">
|
||||
{{ icon("chevron-right", "icon--sm") }} Back to {{ document.base.name if document.base else "the base" }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<form method="post" action="/api/library/documents/{{ document.id }}">
|
||||
@@ -28,6 +30,22 @@
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{% if document.base %}
|
||||
<div class="field">
|
||||
<label class="field__label" for="base_id">Knowledge base</label>
|
||||
{# Moving a document changes who can see it, which is the point of bases.
|
||||
Only bases this person can write to are offered. #}
|
||||
<select class="select" id="base_id" name="base_id" {{ 'disabled' if not is_owner }}>
|
||||
{% for option in user_bases %}
|
||||
<option value="{{ option.id }}" {{ 'selected' if option.id == document.base_id }}>
|
||||
{{ option.name }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<p class="field__hint">Moving it changes who can see it.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<dl class="detail-list">
|
||||
<dt>Kind</dt><dd>{{ document.kind }}</dd>
|
||||
{% if document.source_url %}
|
||||
@@ -50,8 +68,6 @@
|
||||
{% endif %}
|
||||
</section>
|
||||
|
||||
{% include "library/_share.html" %}
|
||||
|
||||
{% if is_owner %}
|
||||
<div class="form-actions">
|
||||
<button class="btn btn--primary" type="submit">Save</button>
|
||||
|
||||
Reference in New Issue
Block a user