diff --git a/web/assets/app.css b/web/assets/app.css index 3d49333..797f618 100644 --- a/web/assets/app.css +++ b/web/assets/app.css @@ -15,6 +15,7 @@ --danger: #e5534b; --radius: 14px; --sidebar-w: 280px; + --font-size: 16px; } * { box-sizing: border-box; } @@ -29,7 +30,7 @@ html, body { background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; - font-size: 16px; + font-size: var(--font-size, 16px); line-height: 1.5; } @@ -247,6 +248,13 @@ details.thinking .reasoning { } #input:focus { outline: none; border-color: var(--accent); } #send { min-width: 52px; font-size: 1.3rem; } +/* Busy: the framework is generating, so send is unavailable. Red + hourglass + + a slow pulse make the state obvious (id+class wins over .btn:disabled grey). */ +#send.busy { + background: var(--danger); border-color: var(--danger); + opacity: 1; cursor: default; animation: send-pulse 1.2s ease-in-out infinite; +} +@keyframes send-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } } #attach { min-width: 44px; font-size: 1.2rem; } /* ---- Attachment chips (composer + sent user turn) ---- */ @@ -269,6 +277,25 @@ details.thinking .reasoning { .attach-chip button:hover { color: var(--danger); } .msg-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; } +/* ---- Queued turns (typed while busy; FIFO, no steer) ---- */ +.queue { display: flex; flex-direction: column; gap: 6px; padding: 8px 12px 0; background: var(--panel); } +.queue-chip { + display: flex; align-items: center; gap: 8px; + padding: 6px 10px; background: var(--panel-2); + border: 1px dashed var(--border); border-radius: 10px; font-size: 0.82rem; +} +.queue-chip .queue-label { + flex: 0 0 auto; color: var(--muted); font-size: 0.66rem; + text-transform: uppercase; letter-spacing: 0.6px; +} +.queue-chip .queue-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.queue-chip .queue-attach { flex: 0 0 auto; color: var(--muted); } +.queue-chip button { + border: none; background: transparent; color: var(--muted); + cursor: pointer; font-size: 0.95rem; line-height: 1; padding: 0 2px; +} +.queue-chip button:hover { color: var(--danger); } + /* ---- Stats modal ---- */ #stats-modal, #dialog, #settings-modal, #notepad-modal { position: fixed; inset: 0; z-index: 40; @@ -380,12 +407,12 @@ details.thinking .reasoning { .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 { +.field input, .field textarea, .field select { 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:focus, .field textarea:focus, .field select: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; } diff --git a/web/assets/app.js b/web/assets/app.js index b5b6748..225c749 100644 --- a/web/assets/app.js +++ b/web/assets/app.js @@ -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/.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) => { diff --git a/web/assets/locales/en.json b/web/assets/locales/en.json index 5b66944..44fbd4a 100644 --- a/web/assets/locales/en.json +++ b/web/assets/locales/en.json @@ -13,6 +13,8 @@ "settings.topk": "Top-k", "settings.minp": "Min-p", "settings.maxtokens": "Max tokens", + "settings.fontsize": "Font size", + "settings.fontsize.hint": "This device's preference (does not affect the model).", "settings.save": "Save", "settings.cancel": "Cancel", "settings.hint.session": "Changes apply only to this session.", @@ -20,6 +22,11 @@ "settings.name.locked": "The name is locked after the first interaction.", "settings.name.unlocked": "You can rename until you send the first message.", "settings.error": "Error: {msg}", + "send.idle": "Send", + "send.busy": "Busy: wait for the reply", + "queue.label": "Queued", + "queue.remove": "Remove from queue", + "queue.attachment_only": "(attachments)", "attach.title": "Attach files or images", "attach.remove": "Remove attachment", "attach.error": "Upload failed: {msg}", diff --git a/web/assets/locales/it.json b/web/assets/locales/it.json index cd633ee..be9b83d 100644 --- a/web/assets/locales/it.json +++ b/web/assets/locales/it.json @@ -13,6 +13,8 @@ "settings.topk": "Top-k", "settings.minp": "Min-p", "settings.maxtokens": "Max token", + "settings.fontsize": "Dimensione del font", + "settings.fontsize.hint": "Preferenza di questo dispositivo (non influisce sul modello).", "settings.save": "Salva", "settings.cancel": "Annulla", "settings.hint.session": "Modifiche valide solo per questa sessione.", @@ -20,6 +22,11 @@ "settings.name.locked": "Il nome è bloccato dopo la prima interazione.", "settings.name.unlocked": "Puoi rinominare finché non invii il primo messaggio.", "settings.error": "Errore: {msg}", + "send.idle": "Invia", + "send.busy": "Occupato: attendi la risposta", + "queue.label": "In coda", + "queue.remove": "Rimuovi dalla coda", + "queue.attachment_only": "(allegati)", "attach.title": "Allega file o immagini", "attach.remove": "Rimuovi allegato", "attach.error": "Caricamento fallito: {msg}", diff --git a/web/index.html b/web/index.html index 5c70d8b..7fc1431 100644 --- a/web/index.html +++ b/web/index.html @@ -39,6 +39,7 @@
+