From 87e5b715075fb56343d2d10a6a532d04d8fc615b Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Tue, 10 Nov 2026 16:55:40 +0100 Subject: feat(assistant): the transcript as chat bubbles with avatars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Questions sit on the right in an accent bubble with the user's avatar (`[assistant] user_avatar`, served at /api/avatar); replies on the left in a surface bubble with the assistant's, a "…" bubble while a reply has no text yet. The assistant's avatar is the background picture itself, zoomed by CSS onto `[assistant] face` ([centre x, centre y, size] in its pixels), so nothing is cropped on the PC; the page loads the picture once for its real size. Unset, both are plain circles. Co-Authored-By: Claude Opus 5.5 --- static/modules/assistant.js | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) (limited to 'static/modules/assistant.js') diff --git a/static/modules/assistant.js b/static/modules/assistant.js index 0384dc5..3213aa6 100644 --- a/static/modules/assistant.js +++ b/static/modules/assistant.js @@ -67,35 +67,62 @@ function addCopy(box) { } } +// One exchange as chat bubbles: the question on the right with the user's +// avatar, the reply on the left with the assistant's; "…" while a reply has +// no text yet. function turnNode(t, live) { const d = document.createElement("div"); d.className = "as-turn"; if (t.user) { - const q = document.createElement("div"); - q.className = "as-q"; - q.textContent = t.user; - d.append(q); + const row = document.createElement("div"); + row.className = "as-row me"; + row.innerHTML = `
`; + row.firstElementChild.textContent = t.user; + d.append(row); } + const row = document.createElement("div"); + row.className = "as-row bot"; + row.innerHTML = `
`; + const bubble = row.lastElementChild; if (t.tools?.length) { const tools = document.createElement("div"); tools.className = "as-tools"; tools.textContent = t.tools.join(" · "); - d.append(tools); + bubble.append(tools); } const a = document.createElement("div"); a.className = "as-a md"; - a.innerHTML = render(t.reply); + if (t.reply) a.innerHTML = render(t.reply); + else if (live) a.textContent = "…"; if (!live) addCopy(a); - d.append(a); + bubble.append(a); if (t.error && t.error !== "stopped") { const e = document.createElement("div"); e.className = "as-err bad"; e.textContent = t.error; - d.append(e); + bubble.append(e); } + d.append(row); return d; } +// The assistant's avatar is the background picture zoomed onto the face +// ([assistant] face); its real size is needed to scale it, so it is loaded once. +function faceStyle(el, face) { + if (!face || el._face) return; + el._face = true; + const img = new Image(); + img.onload = () => { + const [x, y, size] = face; + const k = 40 / size; // the avatar is 40px + const box = el.querySelector(".assistant"); + box.style.setProperty("--face-size", `${img.naturalWidth * k}px ${img.naturalHeight * k}px`); + box.style.setProperty("--face-pos", `${-(x - size / 2) * k}px ${-(y - size / 2) * k}px`); + box.classList.add("has-face"); + }; + img.src = "/api/bg"; +} + function renderLog(log, st, el) { if (el._epoch !== st.epoch || el._done > st.turns.length) { log.textContent = ""; @@ -320,6 +347,7 @@ export default { off.textContent = ""; off._offline = null; + faceStyle(el, st.face); el._busy = !!st.pending || st.state !== "idle"; // The backdrop shows more while the chat is empty. el.querySelector(".assistant").classList.toggle("idle", !st.turns.length && !st.pending); -- cgit v1.2.3