Context Picker

Picks what an assistant can see. A dropdown rather than a dialog, because attaching context happens mid-thought and a modal takes focus off the prompt you were writing.

src/components/ui/context-picker.tsx

About

From the component's own source, where it was written.

Picks what an assistant can see: files, selections, docs, tools.

A dropdown rather than a dialog, because attaching context happens mid-thought — a modal would take focus away from the prompt you were part-way through writing. Already-attached sources stay in the list with a tick rather than disappearing, so the menu does not reshuffle under the pointer.

Install

npx astralyx-ui add context-picker

Usage

import { ContextPicker } from '@/components/ui/context-picker'

<ContextPicker
  sources={sources}
  selected={attached}
  onSelect={attach}
  onDeselect={detach}
/>

Composer

Change the props and the source below follows.

Props
tsx
<ContextPicker
  sources={sources}
  selected={attached}
  onSelect={attach}
  onDeselect={detach}
/>

Examples

Attaching files and docs

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

ContextPicker

Extends Omit<ComponentProps<typeof DropdownMenuContent>, 'children' | 'onSelect'>.

PropTypeDefaultDescription
offsetnumber——
sideSide——
alignAlign——
sourcesContextSource[]required{ id, label, group?, detail?, icon?, disabled? }
selectedstring[][]Attached ids. Selected sources stay in the list with a tick rather than disappearing, so the menu does not reshuffle under the pointer.
onSelect(id: string) => void—Attach and detach.
onDeselect(id: string) => void—Attach and detach.
triggerReactNode—Replaces the default "Context" button.
emptyMessagestring'Nothing matches'—
triggerLabelReactNode'Context'Text on the default trigger. Ignored when trigger is given.
searchPlaceholderstring'Search files and docs'—
searchLabelstring'Search context sources'Accessible name for the search field.

Types

ContextSource

Picks what an assistant can see: files, selections, docs, tools.

FieldTypeDescription
idstring—
labelstring—
group?string—
detail?string—
icon?ReactNode—
disabled?boolean—