Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions projectzero/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,13 @@ <h2 id="account-h" data-i18n="account"></h2>

// ---------------------------------------------------------------- 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)}}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Prevent a background reveal from scrolling the selected channel

If an answer finishes and the user switches to another channel while this reveal is running, each remaining iteration calls scrollLog() on the global log, repeatedly jumping the newly selected channel to the bottom and preventing the user from scrolling it until the reveal ends. Long answers can take several seconds at the minimum 8 ms per word/space chunk; stop or guard the reveal when its view is no longer active.

Useful? React with 👍 / 👎.

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}
Expand Down Expand Up @@ -390,7 +396,8 @@ <h2 id="account-h" data-i18n="account"></h2>
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()}}
Expand Down
Loading