aboutsummaryrefslogtreecommitdiffstats
path: root/static
diff options
context:
space:
mode:
Diffstat (limited to 'static')
-rw-r--r--static/deck.css22
-rw-r--r--static/modules/assistant.js44
2 files changed, 57 insertions, 9 deletions
diff --git a/static/deck.css b/static/deck.css
index e60c732..48ec626 100644
--- a/static/deck.css
+++ b/static/deck.css
@@ -674,7 +674,27 @@ select {
.assistant .as-op, .assistant .as-notice, .assistant .as-note { font-size: 0.857rem; color: var(--udt-subtext0); }
.assistant .as-notice:empty { display: none; }
.assistant .as-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding-right: 4px; }
-.assistant .as-q { align-self: flex-end; background: var(--udt-surface1); border-radius: 12px; padding: 8px 12px; white-space: pre-wrap; margin-left: 20%; }
+.assistant .as-turn { display: flex; flex-direction: column; gap: 10px; }
+.assistant .as-row { display: flex; align-items: flex-end; gap: 10px; }
+.assistant .as-row.me { justify-content: flex-end; padding-left: 15%; }
+.assistant .as-row.bot { padding-right: 10%; }
+.assistant .as-av {
+ flex: none; width: 40px; height: 40px; border-radius: 20px;
+ background: var(--udt-surface1) center / cover no-repeat;
+}
+.assistant .as-av.me { background-image: url("/api/avatar"); }
+.assistant.has-face .as-av.bot { background-image: url("/api/bg"); background-size: var(--face-size); background-position: var(--face-pos); }
+.assistant .as-q, .assistant .as-bubble { padding: 10px 14px; border-radius: 16px; min-width: 0; }
+.assistant .as-q {
+ white-space: pre-wrap; color: var(--udt-crust);
+ background: color-mix(in srgb, var(--udt-accent) 85%, var(--udt-text)); border-bottom-right-radius: 4px;
+}
+.assistant .as-bubble {
+ background: color-mix(in srgb, var(--udt-surface0) 88%, transparent);
+ border: 1px solid var(--udt-surface1); border-bottom-left-radius: 4px;
+}
+.assistant .as-bubble .md > :first-child { margin-top: 0; }
+.assistant .as-bubble .md > :last-child { margin-bottom: 0; }
.assistant .as-tools { font-size: 0.786rem; color: var(--udt-overlay0); }
.assistant .md { line-height: 1.45; overflow-wrap: anywhere; }
.assistant .md pre { position: relative; background: var(--udt-crust); border-radius: 8px; padding: 10px; overflow-x: auto; }
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 = `<div class="as-q"></div><div class="as-av me"></div>`;
+ row.firstElementChild.textContent = t.user;
+ d.append(row);
}
+ const row = document.createElement("div");
+ row.className = "as-row bot";
+ row.innerHTML = `<div class="as-av bot"></div><div class="as-bubble"></div>`;
+ 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);