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:
1 parent
c199953927
commit
73b665d1a7
4 files changed
+165
-5
No files matched your search
+92
-1
@@ -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) => {
|
||||
|
||||
Reference in new issue
Block a user