diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-10 12:27:15 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-10 12:27:15 +0100 |
| commit | c8f5a1e68d3294d4e1c7be3c386f3cc538eeb7af (patch) | |
| tree | 8c5826354c7828d88e3dfba1254b24a7439e5e10 /static/modules/assistant.js | |
| parent | 5b5659cb830a6bf107dd0c9a0bb0f34045d6a8ce (diff) | |
| download | deck-it-c8f5a1e68d3294d4e1c7be3c386f3cc538eeb7af.tar.gz deck-it-c8f5a1e68d3294d4e1c7be3c386f3cc538eeb7af.zip | |
fix(assistant): final review fixes
Hidden main no longer shows over the offline card, Enter while busy no
longer stops a reply, autoscroll is tracked by a scroll listener so it
works while the tab is hidden, and the catalog is retried on each daemon
reconnect. Mic start is guarded against double taps and recorder
failures, a denied mic can be retried, a failed ask restores the text,
the model panel closes on any outside tap, and the font path is cached
only once found. Plus small CSS and spec corrections.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'static/modules/assistant.js')
| -rw-r--r-- | static/modules/assistant.js | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/static/modules/assistant.js b/static/modules/assistant.js index 9f38c0a..dcb6f27 100644 --- a/static/modules/assistant.js +++ b/static/modules/assistant.js @@ -94,7 +94,6 @@ function turnNode(t, live) { } function renderLog(log, st, el) { - const bottom = log.scrollHeight - log.scrollTop - log.clientHeight < 40; if (el._epoch !== st.epoch || el._done > st.turns.length) { log.textContent = ""; el._epoch = st.epoch; @@ -107,7 +106,7 @@ function renderLog(log, st, el) { live.classList.add("as-live"); log.append(live); } - if (bottom) log.scrollTop = log.scrollHeight; + if (el._stick) log.scrollTop = log.scrollHeight; } function renderStrip(strip, st, el) { @@ -156,7 +155,7 @@ function renderOp(box, op) { const name = (p) => p.slice(p.lastIndexOf("/") + 1); box.className = `as-op ${op.running ? "" : op.ok ? "good" : "bad"}`; box.textContent = op.running ? `${op.label}…` - : op.ok ? `Saved: ${op.out.map(name).join(", ")}` : `${op.label}: ${op.error}`; + : op.ok ? `Saved: ${[].concat(op.out ?? []).map(name).join(", ")}` : `${op.label}: ${op.error}`; } function renderModels(panel, st, el) { @@ -178,15 +177,26 @@ function renderModels(panel, st, el) { async function toggleMic(el) { if (el._rec) { el._rec.stop(); return; } - let stream; + if (el._recStarting) return; + el._recStarting = true; + let stream, rec; try { stream = await navigator.mediaDevices.getUserMedia({ audio: true }); + el._micDenied = false; } catch (e) { el._micDenied = true; note(el, `microphone: ${e.message}`); return; + } finally { + el._recStarting = false; + } + try { + rec = new MediaRecorder(stream); + } catch (e) { + stream.getTracks().forEach((t) => t.stop()); + note(el, `microphone: ${e.message}`); + return; } - const rec = new MediaRecorder(stream); const chunks = []; rec.ondataavailable = (e) => chunks.push(e.data); rec.onstop = async () => { @@ -242,7 +252,12 @@ export default { panel.hidden = !panel.hidden; if (!panel.hidden) act(el, "models"); }; - el.querySelector(".as-log").onclick = () => { panel.hidden = true; }; + const log = el.querySelector(".as-log"); + el._stick = true; + log.addEventListener("scroll", () => { el._stick = log.scrollHeight - log.scrollTop - log.clientHeight < 40; }); + el.addEventListener("pointerdown", (e) => { + if (!e.target.closest(".as-models, .as-model")) panel.hidden = true; + }); const bar = el.querySelector(".as-bar"); const input = bar.querySelector("textarea"); const mic = iconBtn(G.mic, "Ask by voice", "mic"); @@ -253,10 +268,10 @@ export default { const text = input.value.trim(); if (!text) return; input.value = ""; - act(el, "ask", { text }); + post("ask", { text }).catch((e) => { if (!input.value) input.value = text; note(el, e.message); }); }; input.addEventListener("keydown", (e) => { - if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); send.onclick(); } + if (e.key === "Enter" && !e.shiftKey && !e.isComposing) { e.preventDefault(); if (!el._busy) send.onclick(); } }); bar.append(mic, send); }, @@ -298,7 +313,7 @@ export default { send.title = send.getAttribute("aria-label"); const mic = el.querySelector(".mic"); const deaf = !st.hears || el._micDenied; - mic.disabled = deaf && !el._rec; + mic.disabled = !st.hears && !el._rec; mic.textContent = deaf ? G.micOff : G.mic; mic.classList.toggle("on", !!el._rec); mic.title = el._micDenied ? "Microphone not allowed" |
