web GUI: busy send indicator, message queue (no steer), font-size setting

- Send button turns red with hourglass + pulse while a turn is in flight; accessible busy label (state.busy).

- Type-ahead while busy is queued FIFO and delivered as normal turns when free (no mid-loop steer); removable chips; queue cleared on session switch.

- Font-size select in Settings: device-local (localStorage), scales UI via root --font-size; not a model/session parameter.

- i18n keys added (it/en). Frontend-only; release rebuilt.
This commit is contained in:
adm committed 2026-11-27 21:13:51 +01:00
1 parent b34f968014
commit 2de3cf6139
5 files changed
+145 -10

No files matched your search

+90 -7
View File
@@ -6,7 +6,7 @@
const $ = (sel) => document.querySelector(sel);
const state = { sessions: [], current: null, busy: false, attachments: [] };
const state = { sessions: [], current: null, busy: false, attachments: [], queue: [] };
// ---- i18n: new user-facing strings go through t(key, params) --------------
// Catalogs are served at /assets/locales/<lang>.json; language follows the
@@ -226,6 +226,10 @@ async function selectSession(id) {
state.current = id;
state.attachments = [];
renderAttachments();
// Queued turns belong to the session they were typed in: drop them on switch
// so they can never be delivered to a different session.
state.queue = [];
renderQueue();
const sess = state.sessions.find((s) => s.id === id);
$("#session-title").textContent = sess ? sess.title : "Conversazione";
$("#model-name").textContent = sess ? sess.model : "";
@@ -301,6 +305,28 @@ function renderAttachments() {
for (const a of state.attachments) box.appendChild(attachChip(a, true));
}
// Pending turns typed while the framework is busy (FIFO, no steer). Shown as
// removable chips above the composer; each runs as a normal turn when free.
function renderQueue() {
const box = $("#queue");
box.textContent = "";
box.hidden = state.queue.length === 0;
for (const item of state.queue) {
const chip = el("div", "queue-chip");
chip.appendChild(el("span", "queue-label", t("queue.label")));
chip.appendChild(el("span", "queue-text", item.content || t("queue.attachment_only")));
if (item.attachments.length) chip.appendChild(el("span", "queue-attach", `\u{1F4CE} ${item.attachments.length}`));
const x = el("button", null, "\u{00D7}");
x.setAttribute("aria-label", t("queue.remove"));
x.addEventListener("click", () => {
state.queue = state.queue.filter((q) => q !== item);
renderQueue();
});
chip.appendChild(x);
box.appendChild(chip);
}
}
function readFileAsDataURL(file) {
return new Promise((resolve, reject) => {
const fr = new FileReader();
@@ -329,14 +355,25 @@ async function sendMessage() {
const input = $("#input");
const content = input.value.trim();
const attachments = state.attachments.slice();
if ((!content && !attachments.length) || state.busy || !state.current) return;
state.busy = true;
$("#send").disabled = true;
if ((!content && !attachments.length) || !state.current) return;
input.value = "";
autoGrow(input);
state.attachments = [];
renderAttachments();
if (state.busy) {
// Framework busy: queue the turn (no steer). It runs as a normal new turn
// when the current one finishes, so the model never sees a mid-loop inject.
state.queue.push({ content, attachments });
renderQueue();
return;
}
await dispatchTurn(content, attachments);
}
// Run one turn end-to-end (the former sendMessage body). On completion it drains
// the next queued turn, if any, so type-ahead messages are delivered in order.
async function dispatchTurn(content, attachments) {
setBusy(true);
const t = $("#transcript");
const empty = t.querySelector(".empty");
if (empty) empty.remove();
@@ -357,13 +394,22 @@ async function sendMessage() {
} catch (e) {
t.appendChild(messageNode("assistant", `Errore: ${e.message}`, null, null, Date.now() / 1000));
} finally {
state.busy = false;
$("#send").disabled = false;
input.focus();
setBusy(false);
$("#input").focus();
scrollDown();
drainQueue();
}
}
// Deliver the next queued turn (FIFO). dispatchTurn sets busy synchronously, so
// this never double-fires; each queued turn drains the next when it ends.
function drainQueue() {
if (state.busy || !state.queue.length || !state.current) return;
const next = state.queue.shift();
renderQueue();
dispatchTurn(next.content, next.attachments);
}
// The only turn path: tools are always on (no user toggle). Stream tool_call /
// tool_result / final events (observability, no gate).
async function agentTurn(content, t, attachments) {
@@ -686,6 +732,21 @@ function closeNotepad() { $("#notepad-modal").hidden = true; }
let settingsScope = "session";
let settingsBase = {};
// Font size: a device-local display preference (localStorage, like sidebarW),
// NOT a model/session parameter. Scales the UI via the root --font-size variable
// (rem-based sizes follow); the 16px composer input stays fixed for iOS focus.
const FONT_MIN = 12, FONT_MAX = 24, FONT_DEFAULT = 16;
function loadFontSize() {
let n = FONT_DEFAULT;
try { n = Number(localStorage.getItem("fontSize")) || FONT_DEFAULT; } catch { /* private mode */ }
return Math.max(FONT_MIN, Math.min(FONT_MAX, n));
}
function applyFontSize(px) {
const n = Math.max(FONT_MIN, Math.min(FONT_MAX, Number(px) || FONT_DEFAULT));
document.documentElement.style.setProperty("--font-size", n + "px");
try { localStorage.setItem("fontSize", String(n)); } catch { /* private mode */ }
}
function currentSession() {
return state.sessions.find((s) => s.id === state.current);
}
@@ -715,6 +776,8 @@ function fillSettingsForm(data, scope) {
$("#set-topk").value = data.top_k ?? "";
$("#set-minp").value = data.min_p ?? "";
$("#set-maxtokens").value = data.max_tokens ?? "";
// Display preference is device-local and scope-independent.
$("#set-fontsize").value = String(loadFontSize());
}
function readSettingsForm() {
@@ -760,6 +823,9 @@ async function openSettings(scope) {
}
async function saveSettings() {
// Font size is a device-local display preference: apply + persist it here,
// never in the backend payload (it is not a model/session parameter).
applyFontSize(Number($("#set-fontsize").value));
// Preserve unexposed fields (seed, penalties) from the loaded instance.
const settings = { ...settingsBase, ...readSettingsForm() };
try {
@@ -827,6 +893,21 @@ function autoGrow(t) {
t.style.height = Math.min(t.scrollHeight, window.innerHeight * 0.4) + "px";
}
// Reflect the in-flight turn on the send button: red + hourglass + an explicit
// "busy" label, so it is unmistakable that the framework is generating and a new
// message cannot be sent yet (the disabled grey alone was easy to miss). Driven
// by the local turn flag: it covers the common case where THIS GUI sent the turn.
function setBusy(on) {
state.busy = on;
const send = $("#send");
send.disabled = on;
send.classList.toggle("busy", on);
send.textContent = on ? "\u23F3" : "\u27A4";
const label = t(on ? "send.busy" : "send.idle");
send.setAttribute("aria-label", label);
send.title = label;
}
// ---- Resizable sidebar/chat separator (desktop only) ----------------------
function initSplitter() {
const splitter = $("#splitter");
@@ -880,6 +961,7 @@ function wire() {
$("#scrim").addEventListener("click", closeDrawer);
$("#new-session").addEventListener("click", newSession);
$("#send").addEventListener("click", sendMessage);
$("#send").setAttribute("aria-label", t("send.idle"));
$("#attach").title = t("attach.title");
$("#attach").setAttribute("aria-label", t("attach.title"));
$("#attach").addEventListener("click", () => $("#file-input").click());
@@ -916,6 +998,7 @@ function wire() {
(async () => {
await loadI18n();
applyI18n();
applyFontSize(loadFontSize());
wire();
await loadSessions();
})().catch((e) => {