GUI settings panel: per-session instance + global defaults, notes, name lock

- ⚙️ 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).
This commit is contained in:
adm committed 2026-11-25 15:51:43 +01:00
1 parent c199953927
commit 73b665d1a7
4 files changed
+165 -5

No files matched your search

+20 -1
View File
@@ -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; }
+92 -1
View File
@@ -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) => {