feat: live context window status tracking during streaming

This commit is contained in:
dobby-d-elf
2026-05-10 06:51:46 -06:00
parent 8a653bac20
commit 1cf0ff01b5
3 changed files with 176 additions and 0 deletions
+12
View File
@@ -1159,6 +1159,18 @@ function attachLiveStream(activeSid, streamId, uploaded=[], options={}){
try{
const d=JSON.parse(e.data||'{}');
if((d.session_id||activeSid)!==activeSid) return;
if(d.usage&&typeof _syncCtxIndicator==='function'){
S.lastUsage={...(S.lastUsage||{}),...d.usage};
if(S.session&&S.session.session_id===activeSid){
S.session.input_tokens=d.usage.input_tokens??S.session.input_tokens;
S.session.output_tokens=d.usage.output_tokens??S.session.output_tokens;
S.session.estimated_cost=d.usage.estimated_cost??S.session.estimated_cost;
S.session.context_length=d.usage.context_length??S.session.context_length;
S.session.threshold_tokens=d.usage.threshold_tokens??S.session.threshold_tokens;
S.session.last_prompt_tokens=d.usage.last_prompt_tokens??S.session.last_prompt_tokens;
}
_syncCtxIndicator(S.lastUsage);
}
if(d.estimated===true||d.tps_available!==true||typeof d.tps!=='number'||d.tps<=0){
if(typeof _setLiveAssistantTps==='function') _setLiveAssistantTps(null);
return;
+11
View File
@@ -392,6 +392,17 @@ async function newSession(flash){
updateSendBtn();
setStatus('');
setComposerStatus('');
if(typeof _setLiveAssistantTps==='function') _setLiveAssistantTps(null);
if(typeof _syncCtxIndicator==='function'){
_syncCtxIndicator({
input_tokens:data.session.input_tokens||0,
output_tokens:data.session.output_tokens||0,
estimated_cost:data.session.estimated_cost||0,
context_length:data.session.context_length||0,
last_prompt_tokens:data.session.last_prompt_tokens||0,
threshold_tokens:data.session.threshold_tokens||0,
});
}
updateQueueBadge(S.session.session_id);
syncTopbar();renderMessages();loadDir('.');
// don't call renderSessionList here - callers do it when needed