mirror of
https://github.com/multipleof4/sune.git
synced 2026-01-14 08:38:00 +00:00
This build was committed by a bot.
This commit is contained in:
@@ -242,7 +242,7 @@ el.accountSettingsForm.addEventListener('submit',e=>{e.preventDefault();store.pr
|
||||
async function fetchTranscript(id){try{const r=await fetch(WS_BASE+'?uid='+encodeURIComponent(id));if(!r.ok)return null;return await r.json()}catch{return null}}
|
||||
async function syncTranscript(){const s=state.stream;if(!s||!s.rid)return false;const j=await fetchTranscript(s.rid);if(!j||!j.rid||j.rid!==s.rid){if(j&&j.error&&!s.done){s.done=true;setBtnSend();state.busy=false;s.text=(s.text||'')+'\n\n'+String(j.error||'');renderMarkdown(s.bubble,s.text,{enhance:false});enhanceCodeBlocks(s.bubble,true);state.messages.push(Object.assign({id:s.rid,role:'assistant',content:[{type:'text',text:s.text}]},s.meta));persistThread();state.stream={rid:null,bubble:null,meta:null,text:'',done:false};queueMicrotask(()=>el.chat.scrollTo({top:el.chat.scrollHeight,behavior:'smooth'}))}return false}const t=j.text||'';if(t&&t!==s.text){s.text=t;renderMarkdown(s.bubble,t,{enhance:false})}if(j.error&&!s.done){s.done=true;setBtnSend();state.busy=false;s.text=(s.text||'')+'\n\n'+String(j.error||'');renderMarkdown(s.bubble,s.text,{enhance:false});enhanceCodeBlocks(s.bubble,true);state.messages.push(Object.assign({id:s.rid,role:'assistant',content:[{type:'text',text:s.text}]},s.meta));persistThread();state.stream={rid:null,bubble:null,meta:null,text:'',done:false};queueMicrotask(()=>el.chat.scrollTo({top:el.chat.scrollHeight,behavior:'smooth'}));return false}if((j.done||j.phase==='done')&&!s.done){s.done=true;setBtnSend();state.busy=false;enhanceCodeBlocks(s.bubble,true);state.messages.push(Object.assign({id:s.rid,role:'assistant',content:[{type:'text',text:s.text||''}]},s.meta));persistThread();state.stream={rid:null,bubble:null,meta:null,text:s.text||'',done:false};queueMicrotask(()=>el.chat.scrollTo({top:el.chat.scrollHeight,behavior:'smooth'}));return false}return true}
|
||||
let syncLoopRunning=false
|
||||
async function syncLoop(){if(syncLoopRunning)return;const s=state.stream;if(!s||!s.rid)return;syncLoopRunning=true;try{while(await syncTranscript())await new Promise(r=>setTimeout(r,900))}finally{syncLoopRunning=false}}
|
||||
async function syncLoop(){if(syncLoopRunning)return;const s=state.stream;if(!s||!s.rid)return;syncLoopRunning=true;try{while(await syncTranscript())await new Promise(r=>setTimeout(r,1900))}finally{syncLoopRunning=false}}
|
||||
window.addEventListener('focus',()=>syncLoop())
|
||||
window.addEventListener('blur',()=>syncLoop())
|
||||
document.addEventListener('visibilitychange',()=>syncLoop())
|
||||
|
||||
Reference in New Issue
Block a user