From 6433cc42de1ceca7210e2b64ad3b98b3a5ce7d02 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Tue, 2 Jun 2026 13:25:23 +0900 Subject: feat(context-window): show current/max context usage per tab/model Add a 'Context Window' sidebar view showing the live context occupancy (latest request's input+output) against the model's maximum context window, resolved dynamically from the models.dev catalog. - core: models.dev catalog module (resolveContextLimit) with disk cache, TTL, stale-fallback + offline penalty memo; null for unknown models. - api: GET /models/context-limit?provider=&modelId=. - frontend: ContextWindowPanel + computeContextUsage helper; App resolves + caches the active model's max (anthropic/opencode-anthropic only); percent shown to 2 decimals; degrades to bare token count when max unknown. - tests: core catalog (13), api route (3), frontend helper (6). --- .../src/lib/components/ContextWindowPanel.svelte | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 packages/frontend/src/lib/components/ContextWindowPanel.svelte (limited to 'packages/frontend/src/lib/components/ContextWindowPanel.svelte') diff --git a/packages/frontend/src/lib/components/ContextWindowPanel.svelte b/packages/frontend/src/lib/components/ContextWindowPanel.svelte new file mode 100644 index 0000000..6c7de05 --- /dev/null +++ b/packages/frontend/src/lib/components/ContextWindowPanel.svelte @@ -0,0 +1,85 @@ + + +
+ {#if !hasUsage} +

+ No context data yet. Send a message — the current context size appears + here after the first response. +

+ {:else} +
+
+ Context Window + {#if tabTitle} + {tabTitle} + {/if} + {#if usage.percent !== null} + {usage.percent.toFixed(2)}% + {/if} +
+ + +
+ {fmt(usage.current)} + {#if usage.max !== null} + / {fmt(usage.max)} + {/if} + tokens +
+ + {#if usage.percent !== null} + + {:else} +

+ Max context size unknown for this model. +

+ {/if} + + {#if modelId} +
+ {modelId} +
+ {/if} +
+ +

+ Current context = the most recent request's prompt + output (what the + model actually held in its window that turn). Grows as the conversation + gets longer. Resets on reload. +

+ {/if} +
-- cgit v1.2.3