Context Meter

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

A long review

Out of room

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/context-meter

Usage

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

ContextMeter props
NameTypeDefaultDescription
usagerequiredContextUsage——
showPercentbooleanonShow the percentage beside the ring; on by default, off where space is tight

Events

ContextMeter events
EventPayloadDescription
RequestedSummary{}Start a new chat that begins with a summary of this one

Source