Settings & Usage
Context Picker
Pick the files, docs and past chats that go into context, each a coloured stretch of the window bar, with suggested excerpts and an overflow warning.
1 variantMIT
Preview
Add context
8 sources · 128k token window
11.4k/ 128k tokens
9%System + chat 11.4k · 117k left for the answer
- 12.6k
- 18.4k
- 9.2k
- 41.2k
- 96.8k
- 6.8k
- 15.3k
- 3.1k
0 selected · 0 tokens
Installation
Copies the component into components/ui and installs its dependencies and theme tokens.
pnpm dlx shadcn@latest add https://tuffui.com/r/context-picker.jsonUsage
Pass your own data and wire the callbacks to your agent runtime.
import { ContextPicker } from "@/components/ui/context-picker";
// Opened from the composer's paperclip, before the question is sent.
export function ComposerContext({ sources, used }: Props) {
const [selected, setSelected] = useState<string[]>([]);
return (
<ContextPicker
items={sources.map((s) => ({
id: s.id,
name: s.title, // "Chargeback policy v3"
type: s.kind, // "file" | "doc" | "chat"
detail: s.meta, // "Policy wiki · 38 pages"
tokens: s.tokenCount, // 18_400
// Suggested by a retrieval pass over the question:
excerpt: s.excerpt && { tokens: s.excerpt.tokens, note: s.excerpt.sections },
}))}
limit={128_000}
reserved={{ label: "System + chat", tokens: used }}
selectedIds={selected}
onSelectedChange={setSelected}
onAttach={(ids, modes) => attachContext(ids, modes)}
/>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| items* | ContextItem[] | — | Every source that can go into context: files, docs and past chats, with their token cost. |
| limit* | number | — | The model's context window in tokens. Past it the bar's scale stretches, the limit becomes a marker and the overflow is hatched. |
| reserved | { label: string; tokens: number } | — | Tokens already spoken for, such as the system prompt and the chat so far. Drawn grey at the start of the bar. |
| selectedIds | string[] | — | Controlled selection, in the order sources were picked. The bar fills in that order. |
| defaultSelectedIds | string[] | [] | Starting selection when uncontrolled. |
| onSelectedChange | (ids: string[]) => void | — | Called when a source is checked or unchecked, or the selection is cleared. |
| modes | Record<string, ContextMode> | — | Controlled Full / Excerpts choice per source. Sources left out go in full. Only sources with an `excerpt` show the toggle. |
| defaultModes | Record<string, ContextMode> | {} | Starting modes when uncontrolled. |
| onModesChange | (modes: Record<string, ContextMode>) => void | — | Called when a source switches between Full and Excerpts. |
| highlightedId | string | null | — | The source the agent points at: its segment stays lit, the rest dim, until someone hovers another. |
| onAttach | (ids: string[], modes: Record<string, ContextMode>) => void | — | Shows the primary "Attach N" button. Disabled when nothing is picked or the picks overflow the window. |
| searchable | boolean | true | Shows the search field and the type filter above the list. |
| typeLabels | Partial<Record<ContextItemType, string>> | { file: "Files", doc: "Docs", chat: "Chats" } | Labels in the type filter. |
| model | string | — | Model name in a tag at the right of the header. |
| icon | Icon | Stack | Phosphor icon in the header tile. |
| title | ReactNode | "Add context" | Header title. |
| subtitle | ReactNode | "8 sources · 128k token window" | Secondary line under the title. |
| formatTokens | (tokens: number) => string | "18.4k" | Token counts in the readout, the list and the footer. |
| className | string | — | Extra classes for the root element. |
type ContextItemType = "file" | "doc" | "chat";
type ContextMode = "full" | "excerpts";
type ContextItem = {
id: string;
name: string; // "Chargeback policy v3"
type: ContextItemType;
detail?: string; // "Policy wiki · 38 pages"
tokens: number; // 18_400, the whole source
excerpt?: {
tokens: number; // 3_200
note?: string; // "§4 Win-back window, §7 Evidence rules"
};
color?: string; // segment color, defaults to the palette by position
};
// Also exported: formatContextTokens(n) => "18.4k"