How full a chat's context window is, where the tokens go, and a new chat with a summary near the limit.
A new chat
Context window
8.5K of 200K · 4%- Instructions and memory2.1K
- Files0
- Conversation6.4K
- Free192K
Long chats fill the window. Start a new chat when you change topic.
A long review
Context window
170K of 200K · 85%- Instructions and memory2.1K
- Files96K
- Conversation71.5K
- Free30.4K
This chat is near its limit. Soon the model will skip the oldest messages.
Out of room
Context window
128K of 128K · 100%- Instructions and memory2.1K
- Files64K
- Conversation61.9K
- Free0
This chat is full. The model now skips the oldest messages.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { ContextMeter } from "./ui/uicontext/components/chat/ContextMeter.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"const Message = UiSchema.TaggedEnum({ ClickedSummarize: { chat: Schema.String } })const styles = stylex.create({ row: { display: "flex", flexWrap: "wrap", gap: space.xxl, alignItems: "center" }, case: { display: "grid", gap: space.xs, justifyItems: "start" }, label: { margin: 0, color: color.faint, fontSize: font.xs }, note: { margin: 0, color: color.muted, fontSize: font.sm },})const cases = [ { key: "early", label: "A new chat", usage: { limit: 200_000, system: 2_100, files: 0, conversation: 6_400 } }, { key: "near", label: "A long review", usage: { limit: 200_000, system: 2_100, files: 96_000, conversation: 71_500 } }, { key: "full", label: "Out of room", usage: { limit: 128_000, system: 2_100, files: 64_000, conversation: 61_900 } },] as constexport const ContextMeterDemo = Html.component({ name: "ContextMeterDemo", model: Schema.Struct({ summarized: Schema.NullOr(Schema.String) }), message: Message,}).make({ init: () => ({ summarized: null }), update: { ClickedSummarize: ($, { chat }) => $.evolve({ summarized: chat }) }, view: (h, model) => h.div.children( h.div.attrs(sx(styles.row)).children( ...cases.map((c) => h.div.key(c.key).attrs(sx(styles.case)).children( h.p.attrs(sx(styles.label)).children(c.label), ContextMeter(h, { key: c.key, props: { usage: c.usage }, onEmit: { RequestedSummary: () => Message.ClickedSummarize({ chat: c.label }) } }), )), ), h.p.attrs({ role: "status", ...sx(styles.note) }).children(model.summarized === null ? "" : `Started a new chat from a summary of “${model.summarized}”.`), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/context-meterUsage
import { ContextMeter } from "./ui/uicontext/components/chat/ContextMeter.ts"import type { ContextUsage } from "./ui/uicontext/components/domain/Chat.ts"const Message = UiSchema.TaggedEnum({ ClickedSummarize: {} })// count the tokens your model will read, and start a new chat with a summary when askedexport const ChatContext = (h: Html.H<typeof Message.Type>, usage: ContextUsage) => ContextMeter(h, { props: { usage }, onEmit: { RequestedSummary: () => Message.ClickedSummarize() } })API reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
usagerequired | ContextUsage | — | — |
showPercent | boolean | on | Show the percentage beside the ring; on by default, off where space is tight |
Events
| Event | Payload | Description |
|---|---|---|
RequestedSummary | {} | Start a new chat that begins with a summary of this one |