diff --git a/CHANGELOG.md b/CHANGELOG.md index e70c427..5e06471 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project are documented here. The format follows ## [Unreleased] +### Changed + +- Desktop app: a finished AI answer now reveals word by word (a short "typing" animation, + respecting `prefers-reduced-motion`) instead of appearing all at once. The answer itself is + still generated and transmitted in one piece — this is a client-side reveal of the already- + complete text, not real token streaming from the worker. + ### Fixed - Desktop app: changing "Model on this device" snapped back to the old value and never actually diff --git a/projectzero/static/index.html b/projectzero/static/index.html index e3f2f3f..e30e347 100644 --- a/projectzero/static/index.html +++ b/projectzero/static/index.html @@ -340,7 +340,13 @@
// ---------------------------------------------------------------- channels function markNav(){document.querySelectorAll("nav [data-channel]").forEach(b=>b.setAttribute("aria-current",String(b.dataset.channel===state.active)))} -function renderAi(){$("chat-title").textContent=t("aiChat");$("log").replaceChildren();if(!state.ai.length)sysmsg(t("aiEmpty"));for(const m of state.ai)$("log").append(el("div",{class:"msg"+(m.role==="user"?" mine":"")},el("div",{class:"who",text:m.role==="user"?t("you"):t("ai")+(m.model?" - "+m.model:"")}),m.role==="user"?m.content:md(m.content)));scrollLog()} +function renderAi(){$("chat-title").textContent=t("aiChat");$("log").replaceChildren();if(!state.ai.length)sysmsg(t("aiEmpty")); + for(const m of state.ai)$("log").append(el("div",{class:"msg"+(m.role==="user"?" mine":"")},el("div",{class:"who",text:m.role==="user"?t("you"):t("ai")+(m.model?" - "+m.model:"")}),el("div",{class:"body"},m.role==="user"?m.content:md(m.content))));scrollLog()} +async function typeReveal(container,fullText){ + let reduced=false;try{reduced=matchMedia("(prefers-reduced-motion: reduce)").matches}catch(e){} + if(reduced){container.replaceChildren(md(fullText));return} + const chunks=fullText.split(/(\s+)/).filter(Boolean);const delay=Math.max(8,Math.min(40,900/Math.max(chunks.length,1))); + let shown="";for(const c of chunks){shown+=c;container.replaceChildren(md(shown));scrollLog();await sleep(delay)}} async function openChannel(id){state.active=id;markNav();setView("main");const ai=id==="ai";$("ai-controls").classList.toggle("hidden",!ai); const c=state.channels.find(x=>x.id===id);$("group-controls").classList.toggle("hidden",!c||c.kind!=="group"); if(ai){renderAi();return} @@ -390,7 +396,8 @@ const history=state.ai.slice(-15).map(m=>({role:m.role,content:m.content})); try{const job=await post("/api/jobs",{model,privacy,allow_untrusted:privacy==="community",messages:history,max_output_tokens:256});refreshMe(); for(let i=0;i<200;i++){await sleep(i<10?1000:3000);const s=await call("/api/jobs/"+job.id);renderPending(pendingLine,pendingText,pendingTimeline,s); - if(s.status==="completed"){state.ai.push({role:"assistant",content:s.output.content,model});renderAi();refreshMe();return} + if(s.status==="completed"){state.ai.push({role:"assistant",content:s.output.content,model});renderAi(); + await typeReveal($("log").lastElementChild.querySelector(".body"),s.output.content);refreshMe();return} if(s.status==="failed"||s.status==="cancelled"){setPendingDots(pendingLine,false);pendingText.textContent=t("noAnswer",{reason:s.error||s.status});refreshMe();return}} setPendingDots(pendingLine,false);pendingText.textContent=t("tooLong")} catch(e){setPendingDots(pendingLine,false);pendingText.textContent=t("error")+": "+e.message;state.ai.pop()}}