From 73b665d1a7227709d1681a394048daf076a9ef8f Mon Sep 17 00:00:00 2001 From: iz0eyj Date: Wed, 25 Nov 2026 15:51:43 +0100 Subject: [PATCH] GUI settings panel: per-session instance + global defaults, notes, name lock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ⚙️ settings modal with a Sessione/Generali scope toggle: per-session edits PATCH only that session; Generali edits PUT the defaults template (future sessions only). Fields: name, notes (chat purpose), system prompt, temperature/top_p/top_k/min_p/max_tokens. - Name field disabled once locked; the sidebar ✏️ rename is disabled after the first interaction. Unexposed settings fields preserved on save. README documents the settings/identity model; 114 tests. Verified via node --check + HTTP (assets + settings flow). --- README.md | 22 +++++++++-- web/assets/app.css | 21 ++++++++++- web/assets/app.js | 93 +++++++++++++++++++++++++++++++++++++++++++++- web/index.html | 34 +++++++++++++++++ 4 files changed, 165 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e37fa83..a83ae40 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,21 @@ offline, same-origin so no CORS). It is a thin client over a **session-aware API context, runs inference (streaming SSE or not) and persists the new turns with their token usage. - `GET /api/stats` — aggregate counters (sessions, messages, prompt/completion tokens). +- `GET/PUT /api/settings/defaults` — the global default settings template. +- `PATCH /api/sessions/{id}` — rename (only before the first interaction) and/or + replace the session's own settings instance. + +**Settings & identity.** Each session owns a *settings instance* (system prompt, +notes, sampling) snapshotted from the global defaults at creation +(**copy-on-create**): editing a session affects only it, editing the defaults +affects only *future* sessions — no retroactive surprises. The user jots the +chat's purpose in **notes**. The framework assigns an evocative name (a curated +word list); it is editable only before the first interaction, then **immutable**. +At that first interaction a personal workspace folder is created +(`~/.strata-ctl//`, configurable via `workspace_root`) and a structural +identity reminder ("your name is …, your personal folder is …") is prepended to +the model's context — not an editable setting. The GUI exposes all of this in a +⚙️ settings panel (per-session or general). The standard `/v1` API stays **stateless**; conversation context lives server-side in an embedded **SQLite** database (default `~/.config/strata-ctl/sessions.db`, @@ -180,7 +195,7 @@ unknown keys never break startup. ## Status -Working and tested (106 tests, plus 2 real-file tests run on demand). Text, images, +Working and tested (114 tests, plus 2 real-file tests run on demand). Text, images, the full client-side tool loop, the Anthropic endpoint, the web GUI (session context, streaming, stats) and **agent mode** (the model using `shell_exec` on the host) have been validated live against the real Inkling engine. @@ -191,8 +206,9 @@ engine restart after a crash, a full SSRF guard against DNS rebinding, and the OpenAI Responses native endpoint. The Anthropic adapter covers the core cases but not yet the `defer_loading` / `tool_addition` / `tool_reference` tool machinery, the thinking `budget_tokens` mapping, or prompt-cache token accounting. The GUI agent's -**isolated mode** (Docker-container runner) and GUI images / advanced settings are -still to come; base/host agent mode works. +**isolated mode** (Docker-container runner) and GUI file/image upload are still to +come; base/host agent mode, per-session settings (copy-on-create), session notes, +immutable names and personal workspace folders work. ## License and credits diff --git a/web/assets/app.css b/web/assets/app.css index 6351834..85d9fdf 100644 --- a/web/assets/app.css +++ b/web/assets/app.css @@ -179,7 +179,7 @@ details.thinking .reasoning { #send { min-width: 52px; font-size: 1.3rem; } /* ---- Stats modal ---- */ -#stats-modal, #dialog { +#stats-modal, #dialog, #settings-modal { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; padding: 20px; @@ -201,6 +201,25 @@ details.thinking .reasoning { #dialog-input:focus { outline: none; border-color: var(--accent); } .dialog-actions { display: flex; gap: 8px; justify-content: flex-end; } +/* ---- Settings modal ---- */ +.settings-card { width: min(560px, 100%); max-height: 85vh; overflow-y: auto; } +.scope-toggle { display: flex; gap: 8px; margin: 0 0 12px; } +.scope-toggle .btn.active { background: var(--accent); color: #fff; border-color: var(--accent); } +#set-hint { margin: 0 0 12px; } +#set-name-hint { margin: -8px 0 12px; } +.small { font-size: 0.8rem; } +.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; } +.field > span { font-size: 0.85rem; color: var(--muted); } +.field input, .field textarea { + width: 100%; background: var(--panel-2); color: var(--text); + border: 1px solid var(--border); border-radius: 8px; + padding: 8px 10px; font-size: 16px; font-family: inherit; +} +.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); } +.field input:disabled { opacity: 0.6; } +.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; } +.sess-btn:disabled { opacity: 0.35; cursor: default; } + /* ---- Wide screens: persistent sidebar ---- */ @media (min-width: 900px) { #drawer { position: static; transform: none; width: var(--sidebar-w); flex-shrink: 0; } diff --git a/web/assets/app.js b/web/assets/app.js index aeb99b1..016eaa5 100644 --- a/web/assets/app.js +++ b/web/assets/app.js @@ -121,7 +121,8 @@ function renderSessions() { li.appendChild(el("span", "session-title", s.title)); const actions = el("span", "session-actions"); const ren = el("button", "sess-btn", "\u{270F}\u{FE0F}"); - ren.title = "Rinomina"; + ren.title = s.name_locked ? "Nome bloccato dopo la prima interazione" : "Rinomina"; + ren.disabled = s.name_locked; ren.setAttribute("aria-label", "Rinomina chat"); ren.addEventListener("click", (e) => { e.stopPropagation(); renameSessionById(s.id, s.title); }); const del = el("button", "sess-btn danger", "\u{1F5D1}\u{FE0F}"); @@ -363,6 +364,91 @@ async function showStats() { $("#stats-modal").hidden = false; } +// ---- Settings (per-session instance or global defaults) ------------------- +let settingsScope = "session"; +let settingsBase = {}; + +function currentSession() { + return state.sessions.find((s) => s.id === state.current); +} + +function fillSettingsForm(data, scope) { + const isSession = scope === "session"; + $("#set-name-field").hidden = !isSession; + $("#set-name-hint").hidden = !isSession; + if (isSession) { + const sess = currentSession(); + $("#set-name").value = sess ? sess.title : ""; + const locked = sess ? sess.name_locked : false; + $("#set-name").disabled = locked; + $("#set-name-hint").textContent = locked + ? "Il nome è bloccato dopo la prima interazione." + : "Puoi rinominare finché non invii il primo messaggio."; + $("#set-hint").textContent = "Modifiche valide solo per questa sessione."; + } else { + $("#set-hint").textContent = "Default generali: si applicano solo alle sessioni future."; + } + $("#set-notes").value = data.notes || ""; + $("#set-sp").value = data.system_prompt || ""; + $("#set-temp").value = data.temperature ?? ""; + $("#set-topp").value = data.top_p ?? ""; + $("#set-topk").value = data.top_k ?? ""; + $("#set-minp").value = data.min_p ?? ""; + $("#set-maxtokens").value = data.max_tokens ?? ""; +} + +function readSettingsForm() { + const num = (v) => (v === "" ? null : Number(v)); + const txt = (v) => (v.trim() === "" ? null : v); + return { + notes: txt($("#set-notes").value), + system_prompt: txt($("#set-sp").value), + temperature: num($("#set-temp").value), + top_p: num($("#set-topp").value), + top_k: num($("#set-topk").value), + min_p: num($("#set-minp").value), + max_tokens: num($("#set-maxtokens").value), + }; +} + +async function openSettings(scope) { + settingsScope = scope; + $("#set-scope-session").classList.toggle("active", scope === "session"); + $("#set-scope-general").classList.toggle("active", scope === "general"); + $("#settings-title").textContent = + scope === "session" ? "Impostazioni sessione" : "Impostazioni generali"; + settingsBase = + scope === "session" + ? { ...(currentSession()?.settings || {}) } + : await getJSON("/api/settings/defaults"); + fillSettingsForm(settingsBase, scope); + $("#settings-modal").hidden = false; +} + +async function saveSettings() { + // Preserve unexposed fields (seed, penalties) from the loaded instance. + const settings = { ...settingsBase, ...readSettingsForm() }; + try { + if (settingsScope === "session") { + const sess = currentSession(); + if (!sess) return; + const body = { settings }; + const newName = $("#set-name").value.trim(); + if (!sess.name_locked && newName && newName !== sess.title) body.title = newName; + await sendJSON(`/api/sessions/${sess.id}`, "PATCH", body); + state.sessions = await getJSON("/api/sessions"); + renderSessions(); + const updated = currentSession(); + if (updated) $("#session-title").textContent = updated.title; + } else { + await sendJSON("/api/settings/defaults", "PUT", settings); + } + $("#settings-modal").hidden = true; + } catch (e) { + $("#set-hint").textContent = `Errore: ${e.message}`; + } +} + // A custom modal dialog (replaces native prompt/confirm: styled, mobile-friendly, // and inspectable by automation). Resolves with the input string (or null on // cancel) when `input` is given, otherwise true/false. @@ -469,6 +555,11 @@ function wire() { }); $("#show-stats").addEventListener("click", showStats); $("#close-stats").addEventListener("click", () => { $("#stats-modal").hidden = true; }); + $("#show-settings").addEventListener("click", () => openSettings("session")); + $("#set-scope-session").addEventListener("click", () => openSettings("session")); + $("#set-scope-general").addEventListener("click", () => openSettings("general")); + $("#set-save").addEventListener("click", saveSettings); + $("#set-cancel").addEventListener("click", () => { $("#settings-modal").hidden = true; }); const input = $("#input"); input.addEventListener("input", () => autoGrow(input)); input.addEventListener("keydown", (e) => { diff --git a/web/index.html b/web/index.html index d9b3774..60515df 100644 --- a/web/index.html +++ b/web/index.html @@ -32,6 +32,7 @@ Conversazione + @@ -67,6 +68,39 @@ + + + \ No newline at end of file