aboutsummaryrefslogtreecommitdiffstats
path: root/static/modules
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-10 12:45:52 +0100
committerDanilo M. <danix@danix.xyz>2026-11-10 12:45:52 +0100
commitc30385b92ff767f8aaff58bf0bc1e5c42ce9036c (patch)
tree724f3fca1eacf2ba2cd3d7046befd8b464e42e97 /static/modules
parentc8f5a1e68d3294d4e1c7be3c386f3cc538eeb7af (diff)
downloaddeck-it-c30385b92ff767f8aaff58bf0bc1e5c42ce9036c.tar.gz
deck-it-c30385b92ff767f8aaff58bf0bc1e5c42ce9036c.zip
fix(assistant): voice-only tab, tools in an overlay, silent clips dropped
The first voice question on the tablet was a 0.66 s silent clip: the mic gave no feedback until the next poll, an extra tap made a near-empty recording, and the model invented a question from the silence. The mic now turns red on the tap itself, and a clip whose loudest sample is under 1500 (room noise measured ~260, speech 15000+) is not sent. Typing happens on the PC, so the text field, send button and the ask action are gone; the bar is a large mic and a stop icon. The presets and ops move into an overlay opened from the header, so the transcript gets the screen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'static/modules')
-rw-r--r--static/modules/assistant.js87
1 files changed, 49 insertions, 38 deletions
diff --git a/static/modules/assistant.js b/static/modules/assistant.js
index dcb6f27..0159936 100644
--- a/static/modules/assistant.js
+++ b/static/modules/assistant.js
@@ -21,12 +21,15 @@
import { offline } from "../offline.js";
import { render } from "../md.js";
-import { toWav } from "../wav.js";
+import { peak, toWav } from "../wav.js";
// Font Awesome codepoints, present in Inconsolata Nerd Font.
-const G = { send: "", stop: "", mic: "", micOff: "", plus: "",
+const G = { tools: "", stop: "", mic: "", micOff: "", plus: "",
cloud: "", close: "", copy: "", fallback: "" };
const MAX_REC = 59;
+// Below this peak a clip is silence (room noise measured ~260, speech
+// 15000+); the model would invent a question from it, so it is not sent.
+const SILENT = 1500;
const STATUS = { thinking: "thinking…", transcribing: "transcribing…" };
async function post(action, body = {}) {
@@ -109,18 +112,20 @@ function renderLog(log, st, el) {
if (el._stick) log.scrollTop = log.scrollHeight;
}
+function renderPicking(box, st, el) {
+ box.hidden = !st.picking;
+ if (!st.picking || box._key === st.picking) return;
+ box._key = st.picking;
+ box.innerHTML = `<span></span>`;
+ box.firstElementChild.textContent = `${st.picking}: choose the file on the PC`;
+ const cancel = iconBtn(G.close, "Cancel");
+ cancel.onclick = () => act(el, "cancel");
+ box.append(cancel);
+}
+
+// The presets and ops, in an overlay opened from the header, so the
+// transcript keeps the screen.
function renderStrip(strip, st, el) {
- if (st.picking) {
- const key = `picking:${st.picking}`;
- if (strip._key === key) return;
- strip._key = key;
- strip.innerHTML = `<div class="as-picking"><span></span></div>`;
- strip.querySelector("span").textContent = `${st.picking}: choose the file on the PC`;
- const cancel = iconBtn(G.close, "Cancel");
- cancel.onclick = () => act(el, "cancel");
- strip.firstElementChild.append(cancel);
- return;
- }
const cat = st.catalog;
const key = JSON.stringify([cat?.presets, cat?.ops, st.catalogError]);
if (strip._key === key) return;
@@ -142,7 +147,7 @@ function renderStrip(strip, st, el) {
b.innerHTML = `<i class="nf"></i><span></span>`;
b.querySelector("i").textContent = item.icon || G.fallback;
b.querySelector("span").textContent = item.label;
- b.onclick = () => act(el, "pick", { [kind]: item.label });
+ b.onclick = () => { strip.hidden = true; act(el, "pick", { [kind]: item.label }); };
row.append(b);
}
strip.append(row);
@@ -175,10 +180,17 @@ function renderModels(panel, st, el) {
}
}
+// The mic's look follows the recorder at once, not at the next poll: a tap
+// with no feedback invites a second one, which made a silent clip.
+function micLook(el) {
+ el.querySelector(".mic").classList.toggle("on", !!(el._rec || el._recStarting));
+}
+
async function toggleMic(el) {
if (el._rec) { el._rec.stop(); return; }
if (el._recStarting) return;
el._recStarting = true;
+ micLook(el);
let stream, rec;
try {
stream = await navigator.mediaDevices.getUserMedia({ audio: true });
@@ -189,6 +201,7 @@ async function toggleMic(el) {
return;
} finally {
el._recStarting = false;
+ micLook(el);
}
try {
rec = new MediaRecorder(stream);
@@ -204,9 +217,11 @@ async function toggleMic(el) {
clearTimeout(el._recCap);
const secs = (Date.now() - el._recAt) / 1000;
el._rec = null;
+ micLook(el);
if (secs < 0.5) return;
try {
const wav = await toWav(new Blob(chunks, { type: rec.mimeType }));
+ if (peak(wav) < SILENT) return note(el, "nothing heard");
const r = await fetch("/api/assistant/voice", {
method: "POST", headers: { "Content-Type": "audio/wav" }, body: wav,
});
@@ -218,6 +233,7 @@ async function toggleMic(el) {
el._rec = rec;
el._recAt = Date.now();
rec.start();
+ micLook(el);
el._recCap = setTimeout(() => rec.state === "recording" && rec.stop(), MAX_REC * 1000);
}
@@ -233,23 +249,27 @@ export default {
<div class="as-main">
<div class="as-head">
<button class="as-model"><i class="nf"></i><span></span></button>
- <span class="as-status"></span>
</div>
<div class="as-models" hidden></div>
- <div class="as-strip"></div>
+ <div class="as-strip" hidden></div>
+ <div class="as-picking" hidden></div>
<div class="as-op" hidden></div>
<div class="as-log"></div>
<div class="as-notice"></div>
- <div class="as-bar"><textarea rows="1" aria-label="Question"></textarea></div>
+ <div class="as-bar"><span class="as-status"></span></div>
</div>
</div>`;
const head = el.querySelector(".as-head");
- const fresh = iconBtn(G.plus, "New chat");
- fresh.onclick = () => act(el, "new");
- head.append(fresh);
const panel = el.querySelector(".as-models");
+ const strip = el.querySelector(".as-strip");
+ const tools = iconBtn(G.tools, "Presets and file operations", "tools");
+ tools.onclick = () => { strip.hidden = !strip.hidden; panel.hidden = true; };
+ const fresh = iconBtn(G.plus, "New chat", "fresh");
+ fresh.onclick = () => act(el, "new");
+ head.append(tools, fresh);
el.querySelector(".as-model").onclick = () => {
panel.hidden = !panel.hidden;
+ strip.hidden = true;
if (!panel.hidden) act(el, "models");
};
const log = el.querySelector(".as-log");
@@ -257,23 +277,16 @@ export default {
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;
+ if (!e.target.closest(".as-strip, .tools")) strip.hidden = true;
});
+ // No keyboard: the PC is at hand for typing. Voice, and Stop while a
+ // reply streams.
const bar = el.querySelector(".as-bar");
- const input = bar.querySelector("textarea");
const mic = iconBtn(G.mic, "Ask by voice", "mic");
mic.onclick = () => toggleMic(el);
- const send = iconBtn(G.send, "Send", "send");
- send.onclick = () => {
- if (el._busy) return act(el, "stop");
- const text = input.value.trim();
- if (!text) return;
- input.value = "";
- 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.isComposing) { e.preventDefault(); if (!el._busy) send.onclick(); }
- });
- bar.append(mic, send);
+ const stop = iconBtn(G.stop, "Stop", "stop");
+ stop.onclick = () => act(el, "stop");
+ bar.append(mic, stop);
},
update(st, el) {
@@ -303,19 +316,17 @@ export default {
const panel = el.querySelector(".as-models");
if (!panel.hidden) renderModels(panel, st, el);
renderStrip(el.querySelector(".as-strip"), st, el);
+ renderPicking(el.querySelector(".as-picking"), st, el);
renderOp(el.querySelector(".as-op"), st.op);
renderLog(el.querySelector(".as-log"), st, el);
el.querySelector(".as-notice").textContent = el._note || st.notice || "";
- const send = el.querySelector(".send");
- send.textContent = el._busy ? G.stop : G.send;
- send.setAttribute("aria-label", el._busy ? "Stop" : "Send");
- send.title = send.getAttribute("aria-label");
+ el.querySelector(".stop").hidden = !el._busy;
const mic = el.querySelector(".mic");
const deaf = !st.hears || el._micDenied;
mic.disabled = !st.hears && !el._rec;
mic.textContent = deaf ? G.micOff : G.mic;
- mic.classList.toggle("on", !!el._rec);
+ micLook(el);
mic.title = el._micDenied ? "Microphone not allowed"
: !st.hears ? `${st.wanted || st.model} takes no audio`
: el._rec ? `Recording ${Math.floor((Date.now() - el._recAt) / 1000)}s, tap to send` : "Ask by voice";