mirror of
https://github.com/multipleof4/sune.git
synced 2026-01-14 08:38:00 +00:00
Update index.html
This commit is contained in:
@@ -240,8 +240,8 @@ const lastAssistantId=()=>{const a=[...el.messages.querySelectorAll('.msg-bubble
|
|||||||
const getBubbleById=id=>el.messages.querySelector(`.msg-bubble[data-mid="${CSS.escape(id)}"]`)
|
const getBubbleById=id=>el.messages.querySelector(`.msg-bubble[data-mid="${CSS.escape(id)}"]`)
|
||||||
async function syncTranscript(){const id=lastAssistantId();if(!id)return false;const bubble=getBubbleById(id);if(!bubble)return false;const j=await fetchTranscript(id).catch(()=>null);if(!j||j.rid!==id){if(j&&j.error){setBtnSend();state.busy=false;const t=(bubble.textContent||'')+'\n\n'+j.error;renderMarkdown(bubble,t,{enhance:false});enhanceCodeBlocks(bubble,true);const i=state.messages.findIndex(m=>m.id===id);if(i>=0)state.messages[i].content=[{type:'text',text:t}];else state.messages.push({id,role:'assistant',content:[{type:'text',text:t}]});persistThread()}return false}const t=j.text||'';renderMarkdown(bubble,t,{enhance:false});if(j.error||j.done||j.phase==='done'){setBtnSend();state.busy=false;enhanceCodeBlocks(bubble,true);const i=state.messages.findIndex(m=>m.id===id);if(i>=0)state.messages[i].content=[{type:'text',text:t}];else state.messages.push({id,role:'assistant',content:[{type:'text',text:t}]});persistThread();return false}return true}
|
async function syncTranscript(){const id=lastAssistantId();if(!id)return false;const bubble=getBubbleById(id);if(!bubble)return false;const j=await fetchTranscript(id).catch(()=>null);if(!j||j.rid!==id){if(j&&j.error){setBtnSend();state.busy=false;const t=(bubble.textContent||'')+'\n\n'+j.error;renderMarkdown(bubble,t,{enhance:false});enhanceCodeBlocks(bubble,true);const i=state.messages.findIndex(m=>m.id===id);if(i>=0)state.messages[i].content=[{type:'text',text:t}];else state.messages.push({id,role:'assistant',content:[{type:'text',text:t}]});persistThread()}return false}const t=j.text||'';renderMarkdown(bubble,t,{enhance:false});if(j.error||j.done||j.phase==='done'){setBtnSend();state.busy=false;enhanceCodeBlocks(bubble,true);const i=state.messages.findIndex(m=>m.id===id);if(i>=0)state.messages[i].content=[{type:'text',text:t}];else state.messages.push({id,role:'assistant',content:[{type:'text',text:t}]});persistThread();return false}return true}
|
||||||
let syncLoopRunning=false
|
let syncLoopRunning=false
|
||||||
const syncKick=r=>{if(document.visibilityState!=='hidden')setTimeout(()=>syncLoop(r),0)}
|
const syncKick=r=>{if(!state.busy||document.visibilityState==='hidden')return;setTimeout(()=>syncLoop(r),0)}
|
||||||
async function syncLoop(){if(syncLoopRunning)return;const id=lastAssistantId();if(!id)return;syncLoopRunning=true;try{for(;;){const cont=await syncTranscript().catch(()=>false);if(!cont)break;await new Promise(r=>setTimeout(r,1200))}}finally{syncLoopRunning=false}}
|
async function syncLoop(){if(!state.busy||syncLoopRunning)return;const id=lastAssistantId();if(!id)return;syncLoopRunning=true;try{for(;;){if(!state.busy)break;const cont=await syncTranscript().catch(()=>false);if(!cont)break;await new Promise(r=>setTimeout(r,1200))}}finally{syncLoopRunning=false}}
|
||||||
;['focus','pageshow'].forEach(ev=>window.addEventListener(ev,()=>syncKick(ev)))
|
;['focus','pageshow'].forEach(ev=>window.addEventListener(ev,()=>syncKick(ev)))
|
||||||
document.addEventListener('visibilitychange',()=>{if(document.visibilityState==='visible')syncKick('visible')})
|
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.copySystemPrompt.addEventListener('click',async()=>{try{await navigator.clipboard.writeText(el.set_system_prompt.value||'')}catch{}})
|
||||||
|
|||||||
Reference in New Issue
Block a user