MCPcopy
hub / github.com/7836246/cursor2api / connectSSE

Function connectSSE

public/logs.js:43–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41// ===== SSE =====
42let es;
43function connectSSE(){
44 if(es)try{es.close()}catch{}
45 es=new EventSource(authQ('/api/logs/stream'));
46 es.addEventListener('log',e=>{
47 const en=JSON.parse(e.data);logs.push(en);
48 if(logs.length>5000)logs=logs.slice(-3000);
49 if(!selId||selId===en.requestId){if(curTab==='logs')appendLog(en)}
50 });
51 es.addEventListener('summary',e=>{
52 const s=JSON.parse(e.data);rmap[s.requestId]=s;
53 const i=reqs.findIndex(r=>r.requestId===s.requestId);
54 if(i>=0)reqs[i]=s;else reqs.unshift(s);
55 renderRL();updCnt();
56 if(selId===s.requestId)renderSCard(s);
57 });
58 es.addEventListener('stats',e=>{applyStats(JSON.parse(e.data))});
59 es.onopen=()=>{const c=document.getElementById('conn');c.className='conn on';c.querySelector('span').textContent='已连接'};
60 es.onerror=()=>{const c=document.getElementById('conn');c.className='conn off';c.querySelector('span').textContent='重连中...';setTimeout(connectSSE,3000)};
61}
62
63// ===== Stats =====
64function updStats(){fetch(authQ('/api/stats')).then(r=>r.json()).then(applyStats).catch(()=>{})}

Callers 1

initFunction · 0.85

Calls 7

authQFunction · 0.85
appendLogFunction · 0.85
renderRLFunction · 0.85
updCntFunction · 0.85
renderSCardFunction · 0.85
applyStatsFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected