Working chat: auth, connections, streaming, folders

LLeMbas now runs end to end. Register, add an OpenAI-compatible
connection, and hold a real streaming conversation organised into
folders. Verified against the local llama-swap instance.

Streaming is the one genuinely tricky part. Sending a message returns
two HTML fragments -- the user bubble and an empty assistant bubble
carrying an sse-connect -- and that attribute is the ONLY thing that
starts a generation. Rendering an incomplete assistant message as a
streaming shell falls out of the same template, which means loading a
page whose last reply never finished simply picks it up again.

Details worth knowing about, each commented where it matters:

- SSE payloads are split across several data: lines. A raw newline in
  one data: line truncates the event, which shows up the first time a
  model emits a code block.
- Markdown is rendered server-side by the same helper for both the page
  and the final streamed frame, so the two cannot disagree. The fence
  renderer is replaced outright rather than using markdown-it's
  highlight option, which re-wraps output in a second <pre>.
- escape_text is html.escape, not nh3.clean_text: it escapes character
  by character, so escaping stream chunks separately equals escaping
  the whole string.
- The stream opens its own session via session_scope(); it outlives the
  request handler and the dependency-scoped session may be closed.
- Deleting a folder keeps the chats inside it (FK is SET NULL). Losing
  a conversation to a mis-clicked folder delete is unforgivable.
- Login failures use one message for "no such account" and "wrong
  password" so the form cannot enumerate registered addresses.

Also adds deploy/ for the gamebox install at https://chat.lan: system
unit, nginx vhost with buffering off (buffering on turns streaming into
one lump at the end), and install/update scripts following the same
service-user and /srv bind-mount conventions as llama-swap and comfyui.

70 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 11:04:13 +02:00
parent 5ef2af6a9f
commit dd9e0e9440
59 changed files with 6273 additions and 12 deletions
+444
View File
@@ -0,0 +1,444 @@
/*
Application styles.
Rules here resolve colour, spacing and radius through the variables in
tokens.css and never hard-code a value. Layout is flexbox and grid only --
no framework, no preprocessor, no build step.
*/
/* --- Reset ---------------------------------------------------------------- */
*,
*::before,
*::after {
box-sizing: border-box;
}
html,
body {
height: 100%;
}
body {
margin: 0;
font-family: var(--font-body);
font-size: var(--text-base);
line-height: var(--leading-normal);
color: var(--ink);
background: var(--bg);
-webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5, h6 {
margin: 0;
font-family: var(--font-display);
font-weight: 600;
line-height: var(--leading-tight);
letter-spacing: 0.01em;
}
p { margin: 0 0 var(--sp-4); }
p:last-child { margin-bottom: 0; }
a {
color: var(--accent);
text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
text-underline-offset: 2px;
}
a:hover { color: var(--accent-hover); }
button, input, textarea, select {
font: inherit;
color: inherit;
}
/* A single, consistent focus ring. Never remove it without a replacement. */
:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
border-radius: var(--radius-sm);
}
:focus:not(:focus-visible) { outline: none; }
.visually-hidden {
position: absolute;
width: 1px; height: 1px;
padding: 0; margin: -1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
/* --- Icons ---------------------------------------------------------------- */
.icon {
width: 1.25em;
height: 1.25em;
flex: none;
fill: none;
stroke: currentColor;
stroke-width: 1.7;
stroke-linecap: round;
stroke-linejoin: round;
}
.icon--sm { width: 1em; height: 1em; }
.icon--lg { width: 1.5em; height: 1.5em; }
/* The leaf is a filled silhouette, not a stroked pictogram. */
.icon--leaf { fill: currentColor; stroke: none; }
/* --- Buttons -------------------------------------------------------------- */
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: var(--sp-2);
padding: 0.5rem 0.9rem;
border: 1px solid var(--border);
border-radius: var(--radius);
background: var(--surface-raised);
color: var(--ink);
font-size: var(--text-sm);
font-weight: 500;
cursor: pointer;
transition: background var(--transition-fast), border-color var(--transition-fast),
color var(--transition-fast);
white-space: nowrap;
}
.btn:hover:not(:disabled) {
background: var(--surface-hover);
border-color: var(--border-strong);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary {
background: var(--accent);
border-color: var(--accent);
color: var(--accent-ink);
}
.btn--primary:hover:not(:disabled) {
background: var(--accent-hover);
border-color: var(--accent-hover);
}
.btn--danger { color: var(--danger); border-color: var(--border); }
.btn--danger:hover:not(:disabled) {
background: var(--danger-soft);
border-color: var(--danger);
}
.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover:not(:disabled) { background: var(--surface-hover); border-color: transparent; }
.btn--icon {
padding: 0.4rem;
border-radius: var(--radius);
background: transparent;
border-color: transparent;
color: var(--ink-muted);
}
.btn--icon:hover:not(:disabled) { background: var(--surface-hover); color: var(--ink); }
.btn--block { width: 100%; }
.btn--sm { padding: 0.3rem 0.6rem; font-size: var(--text-xs); }
/* --- Forms ---------------------------------------------------------------- */
.field { margin-bottom: var(--sp-4); }
.field__label {
display: block;
margin-bottom: var(--sp-2);
font-size: var(--text-sm);
font-weight: 500;
color: var(--ink-muted);
}
.field__hint {
margin-top: var(--sp-2);
font-size: var(--text-xs);
color: var(--ink-faint);
line-height: var(--leading-normal);
}
.input,
.textarea,
.select {
width: 100%;
padding: 0.55rem 0.7rem;
border: 1px solid var(--border);
border-radius: var(--radius);
background: var(--bg-sunken);
color: var(--ink);
font-size: var(--text-base);
transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.input:focus,
.textarea:focus,
.select:focus {
outline: none;
border-color: var(--accent);
box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-faint); }
.textarea { resize: vertical; min-height: 5rem; line-height: var(--leading-normal); }
.input--mono { font-family: var(--font-mono); font-size: var(--text-sm); }
.checkbox {
display: flex;
align-items: center;
gap: var(--sp-2);
font-size: var(--text-sm);
cursor: pointer;
}
.checkbox input { accent-color: var(--accent); width: 1rem; height: 1rem; }
/* --- Alerts --------------------------------------------------------------- */
.alert {
display: flex;
gap: var(--sp-3);
padding: var(--sp-3) var(--sp-4);
border: 1px solid var(--border);
border-left-width: 3px;
border-radius: var(--radius);
font-size: var(--text-sm);
margin-bottom: var(--sp-4);
background: var(--surface);
}
.alert--error { border-left-color: var(--danger); background: var(--danger-soft); color: var(--ink); }
.alert--success { border-left-color: var(--success); background: var(--success-soft); }
.alert--warning { border-left-color: var(--warning); background: var(--warning-soft); }
.alert__icon { color: var(--danger); flex: none; margin-top: 0.15rem; }
/* --- Badges --------------------------------------------------------------- */
.badge {
display: inline-flex;
align-items: center;
gap: var(--sp-1);
padding: 0.1rem 0.45rem;
border-radius: var(--radius-full);
font-size: var(--text-xs);
font-weight: 500;
background: var(--surface-active);
color: var(--ink-muted);
}
.badge--gold { background: var(--gold-soft); color: var(--gold); }
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
/* --- Application shell ---------------------------------------------------- */
.shell {
display: flex;
height: 100dvh;
overflow: hidden;
}
.sidebar {
width: var(--sidebar-width);
flex: none;
display: flex;
flex-direction: column;
background: var(--bg-sunken);
border-right: 1px solid var(--border);
transition: margin-left var(--transition);
}
.sidebar[hidden] { display: none; }
.sidebar__header {
display: flex;
align-items: center;
gap: var(--sp-2);
height: var(--header-height);
padding: 0 var(--sp-3);
flex: none;
}
.sidebar__brand {
display: flex;
align-items: center;
gap: var(--sp-2);
color: var(--ink);
text-decoration: none;
font-family: var(--font-display);
font-size: var(--text-lg);
font-weight: 600;
letter-spacing: 0.01em;
min-width: 0;
}
.sidebar__brand:hover { color: var(--ink); }
.sidebar__brand .brand-mark { width: 1.6rem; height: 1.6rem; flex: none; }
.sidebar__brand .brand-llm { color: var(--gold); }
.sidebar__actions { padding: 0 var(--sp-3) var(--sp-3); display: flex; gap: var(--sp-2); }
.sidebar__scroll {
flex: 1;
overflow-y: auto;
padding: 0 var(--sp-2) var(--sp-3);
scrollbar-width: thin;
scrollbar-color: var(--border-strong) transparent;
}
.sidebar__footer {
flex: none;
border-top: 1px solid var(--border);
padding: var(--sp-2);
}
.main {
flex: 1;
display: flex;
flex-direction: column;
min-width: 0;
background: var(--bg);
}
.topbar {
display: flex;
align-items: center;
gap: var(--sp-3);
height: var(--header-height);
flex: none;
padding: 0 var(--sp-4);
border-bottom: 1px solid var(--border);
background: var(--bg);
}
.topbar__title {
font-family: var(--font-display);
font-size: var(--text-md);
font-weight: 600;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
flex: 1;
}
.topbar__spacer { flex: 1; }
/* --- Sidebar navigation --------------------------------------------------- */
.nav-group { margin-bottom: var(--sp-4); }
.nav-group__label {
display: flex;
align-items: center;
justify-content: space-between;
padding: var(--sp-2) var(--sp-2) var(--sp-1);
font-size: var(--text-xs);
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.07em;
color: var(--ink-faint);
}
.nav-item {
display: flex;
align-items: center;
gap: var(--sp-2);
padding: 0.4rem var(--sp-2);
border-radius: var(--radius);
color: var(--ink-muted);
text-decoration: none;
font-size: var(--text-sm);
cursor: pointer;
position: relative;
}
.nav-item:hover { background: var(--surface-hover); color: var(--ink); }
.nav-item.is-active { background: var(--surface-active); color: var(--ink); font-weight: 500; }
.nav-item__label {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
flex: 1;
min-width: 0;
}
/* Row actions stay hidden until the row is hovered or focused within, so the
list reads calmly, but they remain keyboard reachable. */
.nav-item__actions {
display: flex;
gap: 0.1rem;
opacity: 0;
transition: opacity var(--transition-fast);
}
.nav-item:hover .nav-item__actions,
.nav-item:focus-within .nav-item__actions { opacity: 1; }
.nav-empty {
padding: var(--sp-3) var(--sp-2);
font-size: var(--text-xs);
color: var(--ink-faint);
font-style: italic;
}
/* --- Auth screens --------------------------------------------------------- */
.auth {
min-height: 100dvh;
display: grid;
place-items: center;
padding: var(--sp-6);
background:
radial-gradient(ellipse 60% 50% at 50% 0%, var(--gold-soft), transparent 70%),
var(--bg);
}
.auth__card {
width: 100%;
max-width: 25rem;
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius-xl);
padding: var(--sp-8);
box-shadow: var(--shadow-lg);
}
.auth__brand { display: grid; place-items: center; gap: var(--sp-3); margin-bottom: var(--sp-6); }
.auth__brand .brand-mark { width: 3.5rem; height: 3.5rem; }
.auth__title {
font-size: var(--text-2xl);
font-family: var(--font-display);
text-align: center;
}
.auth__subtitle {
text-align: center;
color: var(--ink-muted);
font-size: var(--text-sm);
margin-top: var(--sp-2);
}
.auth__footer {
margin-top: var(--sp-5);
padding-top: var(--sp-4);
border-top: 1px solid var(--border);
text-align: center;
font-size: var(--text-sm);
color: var(--ink-muted);
}
/* --- Empty states --------------------------------------------------------- */
.empty {
flex: 1;
display: grid;
place-content: center;
justify-items: center;
gap: var(--sp-3);
padding: var(--sp-10);
text-align: center;
}
.empty__mark { width: 4.5rem; height: 4.5rem; opacity: 0.85; }
.empty__title { font-size: var(--text-xl); font-family: var(--font-display); }
.empty__text {
color: var(--ink-muted);
font-size: var(--text-sm);
max-width: 32rem;
font-style: italic;
}
/* --- Utilities ------------------------------------------------------------ */
.stack > * + * { margin-top: var(--sp-4); }
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row--between { justify-content: space-between; }
.muted { color: var(--ink-muted); }
.faint { color: var(--ink-faint); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.mono { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* --- Small screens -------------------------------------------------------- */
@media (max-width: 48rem) {
.sidebar {
position: fixed;
inset: 0 auto 0 0;
z-index: 40;
box-shadow: var(--shadow-lg);
}
.sidebar[data-collapsed="true"] { display: none; }
}