Context gauge
How much of the model's context window the conversation uses, as a bar or a ring that warns before the window is full and opens on what fills it.
-
<aparte-context>
<!-- The bar takes the room it is given; the ring takes none. -->
<aparte-composer-toolbar>
<aparte-context window="128000" style="flex: 1"></aparte-context>
<aparte-context window="128000" variant="ring"></aparte-context>
</aparte-composer-toolbar>
<script>
// The gauge reads the usage each turn reports, and draws nothing before the first one.
window.dispatchEvent(new CustomEvent('aparte-message-done', {
detail: { usage: { inputTokens: 52000, outputTokens: 800 } },
}));
</script>A model reads a limited number of tokens, and a long conversation reaches the limit before anyone
notices. <aparte-context> shows how much is used, out of the current model’s window. The bar takes
the width it is given; variant="ring" takes none, for a toolbar.
It needs nothing from your code. The reading is the size of the last request as the provider reported
it; when the conversation has changed since — a new message, a summary written, a Restore — it is an
estimate of the next request, prefixed with ~, calibrated on what the provider reported last. The
window comes from the model (a provider’s model list fills in contextWindow) or from the window
attribute. Before the first turn, or without a window, it shows nothing. A conversation loaded from
storage shows the usage its last reply recorded, and a new chat starts empty.
What fills the window
Section titled “What fills the window”Click the reading, or focus it and press Enter, to open what fills the window: the system prompt, the
tools, the summary, the messages, what is free, and “other” — what the provider counted that the page
did not send, such as a server’s own instructions. The parts are estimates; the total is the
provider’s figure. With @aparte/plugin-compaction set up, the panel
says how much compacting now would free, with Compact now; while a compaction runs, and when one
failed, the gauge says so (data-compact="running" or "failed"), and the panel offers Retry. Escape or
a click outside closes it.
Variants
Section titled “Variants”Warning, then danger
Section titled “Warning, then danger”<aparte-composer-toolbar>
<aparte-context window="128000" style="flex: 1"></aparte-context>
</aparte-composer-toolbar>
<aparte-composer-toolbar>
<aparte-context window="100000" style="flex: 1"></aparte-context>
</aparte-composer-toolbar>
<script>
// One reading, two windows: 82% of the first is past warn (75%), 105% of the second past danger (90%).
window.dispatchEvent(new CustomEvent('aparte-message-done', {
detail: { usage: { inputTokens: 105000, outputTokens: 400 } },
}));
</script>At 75% of the window the gauge turns warn, at 90% danger (warn and danger attributes move
them). It reflects the level in data-level and fires aparte-context-threshold when it changes. A
request the model refused as over its window turns it danger until the next reply reports.
<aparte-context data-empty=""></aparte-context>el.addEventListener('aparte-context-threshold', (e) => use(e.detail));<aparte-context data-empty=""></aparte-context>The aparte-* tags are typed JSX intrinsics as soon as you import from @aparte/react. A presence attribute takes '', never true — React stringifies it, and data-empty={false} would render data-empty="false", which hasAttribute reads as on. Events reach you by ref, typed through the DOM.
<template>
<aparte-context data-empty=""
@aparte-context-threshold="(e) => use(e.detail)"
></aparte-context>
</template>Declared through Vue’s GlobalComponents, so vue-tsc checks the tag in any template. A presence attribute takes '' to set and null to remove, never false.
<aparte-context data-empty=""
on:aparte-context-threshold={(e) => use(e.detail)}
></aparte-context>Declared through SvelteHTMLElements, so svelte-check covers the attributes and the on: handlers. A presence attribute takes '', never false.
import { AparteContextDirective } from '@aparte/angular';<aparte-context [dataEmpty]="true"
(contextThreshold)="use($event)"></aparte-context>A standalone directive whose selector IS the tag, so the real element sits in the template — @if, @for and content projection all reach it — and no CUSTOM_ELEMENTS_SCHEMA is needed.
Installation and the framework-specific traps: React · Vue · Svelte · Angular.
When the window is full
Section titled “When the window is full”The gauge measures; @aparte/plugin-compaction decides when to summarise the older turns, past 80 % of
the window by default (see Long conversations). The gauge never asks
for a compaction itself: the plugin compacts on its own once it is set up.
Customize
Section titled “Customize”| Variable | What it sets |
|---|---|
--aparte-context-ring-size | The ring’s diameter. |
The bar wears the progress recipe, and its colours follow the level; the panel wears the popover recipe.
<aparte-context> · class AparteContext
Attributes
| Attribute | Description |
|---|---|
window | The context window, in tokens. Overrides the current model’s contextWindow. |
warn | Fraction of the window at which the level turns warn. Default 0.75. |
danger | Fraction at which it turns danger. Default 0.9. |
target | The id of the <aparte-chat> to watch, when the element is not under it. |
variant | bar (default) or ring: a progress bar with the reading beside it, or a ring with the percentage. |
used | Tokens in use before a turn of this page has reported any: a restored conversation’s last usage. The next turn’s usage replaces it. |
data-level | Reflected BY the element: ok, warn or danger. Read-only. |
data-empty | Reflected BY the element while it has nothing to show. Read-only. |
data-compact | Reflected BY the element while this chat is being compacted (running) and after a compaction failed (failed). Read-only. |
Properties
| Property | Type | Description |
|---|---|---|
used | number | null | Writes the used attribute: a reading for a conversation restored without a turn of this page, which had nothing to report until the next one. null clears it. |
window | number | null | Writes the window attribute; null gives the model’s own window back. The setter has to exist: React 19 and Svelte assign the PROPERTY whenever the element has one of that name, so <aparte-context window={8000}> — a spelling both wrappers type as valid — hit a getter alone and threw. |
level (readonly) | AparteContextLevel | null | The current level, or null while nothing is shown. |
measure (readonly) | AparteContextMeasure | null | The reading drawn now, parts and all, or null while nothing is shown. |
Events
| Event | Type | Description |
|---|---|---|
aparte-context-threshold | CustomEvent<AparteContextThresholdEventDetail> | The level changed. Bubbles. |
aparte-compact | CustomEvent<AparteCompactEventDetail> | Dispatched on window by Retry in the panel when no compactor is registered. @aparte/plugin-compaction answers it; with no listener nothing happens. |
CSS variables
| Variable | Default | Description |
|---|---|---|
--aparte-context-ring-size | 22px | Diameter of the ring variant. |
Accessibility
Section titled “Accessibility”- The gauge is a
meterwith its minimum, maximum and current value, named from thecontextLabelkey (“Context window”) followed by the reading. - The reading is a button with
aria-expandedthat opens the panel; it never opens on hover alone. - The level is written, not only coloured: the reading says how full the window is.
Related
Section titled “Related”- Compaction separator — where the model’s view starts after a summary.
- Composer — the toolbar the ring sits in.