From c1db709ef31a17799d5471f9e45f043e37db25b0 Mon Sep 17 00:00:00 2001 From: Nathan Esquenazi Date: Sat, 4 Apr 2026 14:26:13 -0700 Subject: [PATCH] fix: model-aware context window estimation instead of hardcoded 128k Agent review: hardcoded 128000 is wrong for Claude (200k), Gemini (1M), and smaller models (8k-32k). Added a lookup table keyed by model name substring covering major families with 128k fallback. TODO comment for fetching exact values from server. Co-Authored-By: Claude Opus 4.6 (1M context) --- static/ui.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/static/ui.js b/static/ui.js index 4a61360..fa4121a 100644 --- a/static/ui.js +++ b/static/ui.js @@ -93,8 +93,12 @@ function _syncCtxIndicator(usage){ const total=inTok+outTok; if(!total){el.style.display='none';return;} el.style.display=''; - // Estimate context window fill (assume 128k default, common for most models) - const ctxWindow=128000; + // Estimate context window from model name (rough, covers major families) + // TODO: fetch exact values from server or model metadata API + const _CTX={claude:200000,gemini:1000000,'gpt-4o':128000,'gpt-5':128000,o3:200000,o4:200000,deepseek:128000,llama:128000}; + const _m=(S.session&&S.session.model||'').toLowerCase(); + let ctxWindow=128000; + for(const[k,v]of Object.entries(_CTX)){if(_m.includes(k)){ctxWindow=v;break;}} const pct=Math.min(100,Math.round((inTok/ctxWindow)*100)); const bar=$('ctxBar'); const label=$('ctxLabel');