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:
1 parent
b34f968014
commit
2de3cf6139
5 files changed
+145
-10
No files matched your search
+30
-3
@@ -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; }
|
||||
|
||||
+90
-7
@@ -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) => {
|
||||
|
||||
@@ -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}",
|
||||
|
||||
@@ -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}",
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
<section id="transcript" aria-live="polite"></section>
|
||||
|
||||
<div id="attachments" class="attachments" hidden></div>
|
||||
<div id="queue" class="queue" hidden></div>
|
||||
<footer id="composer">
|
||||
<textarea id="input" rows="1" placeholder="Scrivi un messaggio…" autocomplete="off"></textarea>
|
||||
<button id="attach" class="btn ghost" aria-label="Allega file o immagini" title="Allega file o immagini">📎</button>
|
||||
@@ -115,6 +116,16 @@
|
||||
<label class="field"><span data-i18n="settings.minp">Min-p</span><input id="set-minp" type="number" step="0.05" min="0" max="1" /></label>
|
||||
<label class="field"><span data-i18n="settings.maxtokens">Max token</span><input id="set-maxtokens" type="number" step="1" min="1" /></label>
|
||||
</div>
|
||||
<label class="field" id="set-fontsize-field"><span data-i18n="settings.fontsize">Dimensione del font</span>
|
||||
<select id="set-fontsize">
|
||||
<option value="14">14 px</option>
|
||||
<option value="16">16 px</option>
|
||||
<option value="18">18 px</option>
|
||||
<option value="20">20 px</option>
|
||||
<option value="22">22 px</option>
|
||||
</select>
|
||||
</label>
|
||||
<p id="set-fontsize-hint" class="muted small" data-i18n="settings.fontsize.hint">Preferenza di questo dispositivo.</p>
|
||||
<div class="dialog-actions">
|
||||
<button id="set-cancel" class="btn" data-i18n="settings.cancel">Annulla</button>
|
||||
<button id="set-save" class="btn primary" data-i18n="settings.save">Salva</button>
|
||||
|
||||
Reference in new issue
Block a user