Skip to content

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.

  • <aparte-context>
On this page
Open

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: the size of the last request, as the provider reported it, out of the current model’s window. The bar takes the width it is given; variant="ring" takes none, for a toolbar, with the full reading in its tooltip.

It needs nothing from your code: it listens to the usage each turn reports, and takes the window 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.

Open

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.

html
<aparte-context auto-compact=""></aparte-context>
js
el.addEventListener('aparte-context-threshold', (e) => use(e.detail));

Installation and the framework-specific traps: React · Vue · Svelte · Angular.

With auto-compact, a turn that ends in danger dispatches aparte-compact for its chat, one request at a time: once it is answered, the next turn still in danger asks again. What answers is @aparte/plugin-compaction: it summarises the oldest turns and keeps the recent ones (see Compaction notice). Without the plugin, the gauge only measures.

VariableWhat it sets
--aparte-context-ring-sizeThe ring’s diameter.

The bar wears the progress recipe, and its colours follow the level.

<aparte-context> · class AparteContext

Attributes

AttributeDescription
windowThe context window, in tokens. Overrides the current model’s contextWindow.
warnFraction of the window at which the level turns warn. Default 0.75.
dangerFraction at which it turns danger. Default 0.9.
targetThe id of the <aparte-chat> to watch, when the element is not under it.
variantbar (default) or ring: a progress bar with the reading beside it, or a ring with the percentage.
auto-compactDispatch aparte-compact on each turn that ends in danger, one request at a time.
data-levelReflected BY the element: ok, warn or danger. Read-only.
data-emptyReflected BY the element while it has nothing to show. Read-only.

Properties

PropertyTypeDescription
used (readonly)number | nullTokens the last turn reported, or null before the first turn.
windownumber | nullWrites 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 | nullThe current level, or null while nothing is shown.

Events

EventTypeDescription
aparte-context-thresholdCustomEvent<AparteContextThresholdEventDetail>The level changed. Bubbles.
aparte-compactCustomEvent<AparteCompactEventDetail>Dispatched on window when auto-compact is set and a turn ends in danger: compact this target’s transcript. One request at a time — the next turn in danger asks again once the plugin has answered — and only while the attribute is present. @aparte/plugin-compaction answers it; with no listener nothing happens.

CSS variables

VariableDefaultDescription
--aparte-context-ring-size22pxDiameter of the ring variant.
  • The gauge is a meter with its minimum, maximum and current value, named from the contextLabel key (“Context window”) followed by the reading.
  • The level is written, not only coloured: the reading says how full the window is.