perf: optimize full interface loading and refresh paths
This commit is contained in:
1 parent
649a0df832
commit
f317314a3c
57 files changed
+791
-136
No files matched your search
@@ -22,8 +22,9 @@
|
||||
messages.querySelectorAll('[data-assistant-action]').forEach(button=>button.onclick=async()=>{const id=currentId,at=revision,actionId=button.dataset.assistantAction,owned=()=>live()&&id===currentId&&at===revision;if(pendingActions.has(actionId))return;pendingActions.set(actionId,id);button.disabled=true;error.textContent='';watch();try{await api('/assistant/conversations/'+id+'/actions/'+actionId+'/execute',{});if(owned())await loadCurrent();}catch(e){if(owned()){showError(e);await loadCurrent();}}finally{pendingActions.delete(actionId);}});
|
||||
if(running||[...pendingActions.values()].includes(currentId)||turns.some(t=>t.actions?.some(a=>a.status==='running')))watch();
|
||||
}
|
||||
async function loadCurrent(){if(!currentId)return;const id=currentId,at=revision,c=await api('/assistant/conversations/'+id);if(!live()||id!==currentId||at!==revision)return;conversation=c;drawMessages();}
|
||||
function watch(){if(polling)return;polling=true;setTimeout(async()=>{polling=false;if(!live())return;try{await loadCurrent();}catch(e){showError(e);}},1200);}
|
||||
async function loadCurrent(signal){if(!currentId)return;const id=currentId,at=revision,c=await api('/assistant/conversations/'+id,undefined,{signal,ownerCheck:live});if(!live()||id!==currentId||at!==revision)return;conversation=c;drawMessages();}
|
||||
const watcher=window.PageLifecycle.poll(async signal=>{if(!polling)return;polling=false;try{await loadCurrent(signal);}catch(e){if(signal.aborted)polling=true;else showError(e);}},1200,{isActive:live});
|
||||
function watch(){polling=true;watcher.schedule();}
|
||||
async function select(id){currentId=id;conversation=null;revision++;sessionStorage.setItem(key,id);drawList();if(id)await loadCurrent();else drawMessages();}
|
||||
function drawPager(){container.querySelector('#assistant-page').textContent=listPage+' / '+Math.max(1,Math.ceil(listTotal/25));container.querySelector('#assistant-prev').disabled=listPage<=1;container.querySelector('#assistant-next').disabled=listPage*25>=listTotal;}
|
||||
async function refreshList(page=listPage,requestedScope=scope){
|
||||
|
||||
Reference in new issue
Block a user