mirror of
https://github.com/multipleof4/devsune.git
synced 2026-01-14 00:17:56 +00:00
Update index.html
This commit is contained in:
@@ -237,10 +237,11 @@ 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,21900))}finally{syncLoopRunning=false}}
|
||||
window.addEventListener('focus',()=>syncLoop())
|
||||
window.addEventListener('blur',()=>syncLoop())
|
||||
document.addEventListener('visibilitychange',()=>syncLoop())
|
||||
const syncLog=(...a)=>console.debug('[sync]',...a)
|
||||
const syncKick=r=>{if(document.visibilityState!=='hidden')setTimeout(()=>syncLoop(r),0)}
|
||||
async function syncLoop(reason='manual'){if(syncLoopRunning){syncLog('busy',reason);return}const s=state.stream;if(!s?.rid){syncLog('no rid',reason);return}syncLoopRunning=true;syncLog('start',reason,s.rid);try{for(let i=1;;i++){const cont=await syncTranscript().catch(e=>(syncLog('err',e),false));syncLog('tick',i,{visible:document.visibilityState,focused:document.hasFocus(),cont});if(!cont)break;await new Promise(r=>setTimeout(r,1200))}}finally{syncLoopRunning=false;syncLog('end')}}
|
||||
;['focus','pageshow'].forEach(ev=>window.addEventListener(ev,()=>syncKick(ev)))
|
||||
document.addEventListener('visibilitychange',()=>{if(document.visibilityState==='visible')syncKick('visible')})
|
||||
el.copySystemPrompt.addEventListener('click',async()=>{try{await navigator.clipboard.writeText(el.set_system_prompt.value||'')}catch{}})
|
||||
el.pasteSystemPrompt.addEventListener('click',async()=>{try{el.set_system_prompt.value=await navigator.clipboard.readText()}catch{}})
|
||||
el.copyHTML.addEventListener('click',async()=>{try{await navigator.clipboard.writeText(el.htmlEditor.textContent||'')}catch{}})
|
||||
|
||||
Reference in New Issue
Block a user