{
  "schemaVersion": 1,
  "target": "react",
  "name": "model-selector",
  "version": "0.1.0",
  "category": "ai-elements",
  "title": "Model Selector",
  "description": "A searchable model picker grouped by provider with context sizes and capability tags, plus a reasoning effort select with rising bars.",
  "tags": [
    "ai",
    "model",
    "picker",
    "combobox",
    "select",
    "reasoning",
    "effort"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {
    "@base-ui/react": "^1.9.0"
  },
  "registryDependencies": [],
  "docsPath": "/components/model-selector",
  "props": [
    {
      "name": "ModelSelector models",
      "type": "{ id, name, provider, context?, capabilities?, description?, disabled? }[]",
      "description": "Models in order; they group by provider. capabilities are vision, tools, reasoning, files, audio, or fast."
    },
    {
      "name": "ModelSelector value / defaultValue / onValueChange",
      "type": "string / string / (id) => void",
      "default": "first enabled model",
      "description": "The selected model id."
    },
    {
      "name": "ModelSelector searchPlaceholder",
      "type": "string",
      "default": "\"Search models\"",
      "description": "Placeholder of the search field. Search matches name, provider, and capability words."
    },
    {
      "name": "ReasoningEffort levels",
      "type": "{ value, label, description? }[]",
      "default": "Low, Medium, High",
      "description": "Levels from least to most effort."
    },
    {
      "name": "ReasoningEffort value / defaultValue / onValueChange",
      "type": "string / string / (value) => void",
      "default": "\"medium\"",
      "description": "The selected level."
    },
    {
      "name": "side",
      "type": "\"top\" | \"bottom\"",
      "default": "\"bottom\"",
      "description": "Popup side for either control, for example top in a composer."
    },
    {
      "name": "disabled",
      "type": "boolean",
      "default": "false",
      "description": "Disables the trigger."
    }
  ],
  "accessibility": [
    "The model list is a Base UI Combobox with the search field inside the popup: arrows move, Enter picks, Escape closes, and focus returns to the trigger.",
    "Triggers have accessible names that include their purpose (\"Model: Claude Sonnet 4.5\", \"Reasoning effort: Medium\").",
    "An empty search is announced politely by the Combobox empty state. Disabled models stay visible with a reason and are skipped by the keyboard.",
    "Reasoning effort is a Base UI Select with role=\"listbox\" options; the bars are decorative and the level is text.",
    "With reduced motion both popups appear without scale."
  ],
  "states": [],
  "files": [
    {
      "path": "agent/model-selector.tsx",
      "content": "\"use client\";\n\nimport { Combobox } from \"@base-ui/react/combobox\";\nimport { Select } from \"@base-ui/react/select\";\nimport { type ReactNode, useMemo, useState } from \"react\";\n\nfunction cx(...classes: Array<string | false | null | undefined>) {\n  return classes.filter(Boolean).join(\" \");\n}\n\nconst ease = \"ease-[cubic-bezier(0.23,1,0.32,1)]\";\n\n// Shared by both popups: the overlay surface and the 160ms enter, 110ms exit from the trigger.\nconst popupSurface = cx(\n  \"origin-(--transform-origin) rounded-xl outline-none\",\n  \"border border-zinc-950/10 bg-white text-zinc-950 shadow-[0_12px_32px_-8px_rgb(0_0_0/0.18)]\",\n  \"dark:border-white/15 dark:bg-black dark:text-white dark:shadow-[0_16px_48px_-12px_rgb(0_0_0/1),inset_0_1px_0_rgb(255_255_255/0.08)]\",\n  `transition-[opacity,scale] duration-160 ${ease} motion-reduce:transition-none`,\n  \"data-[starting-style]:opacity-0 motion-safe:data-[starting-style]:scale-96\",\n  \"data-[ending-style]:opacity-0 data-[ending-style]:duration-110 data-[ending-style]:ease-out motion-safe:data-[ending-style]:scale-98\",\n);\n\nconst triggerBase = cx(\n  \"group inline-flex h-8 max-w-full min-w-0 cursor-pointer items-center gap-2 rounded-lg px-2 text-sm select-none\",\n  \"text-zinc-700 transition-[background-color,color] duration-150 ease-out motion-reduce:transition-none\",\n  \"hover:bg-zinc-950/[0.04] hover:text-zinc-950 data-[popup-open]:bg-zinc-950/[0.06] data-[popup-open]:text-zinc-950\",\n  \"dark:text-zinc-300 dark:hover:bg-white/[0.06] dark:hover:text-white dark:data-[popup-open]:bg-white/[0.09] dark:data-[popup-open]:text-white\",\n  \"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500\",\n  \"disabled:pointer-events-none disabled:opacity-45\",\n);\n\nconst itemBase = cx(\n  \"flex cursor-default items-start gap-2.5 rounded-md px-2 py-2 outline-none select-none\",\n  \"data-[highlighted]:bg-zinc-950/[0.05] dark:data-[highlighted]:bg-white/[0.08]\",\n  \"data-[disabled]:cursor-not-allowed data-[disabled]:opacity-45\",\n);\n\n// ---------------------------------------------------------------------------\n// Model selector\n\nexport type ModelCapability = \"vision\" | \"tools\" | \"reasoning\" | \"files\" | \"audio\" | \"fast\";\n\nconst capabilityLabels: Record<ModelCapability, string> = {\n  vision: \"Vision\",\n  tools: \"Tools\",\n  reasoning: \"Reasoning\",\n  files: \"Files\",\n  audio: \"Audio\",\n  fast: \"Fast\",\n};\n\nexport interface ModelOption {\n  id: string;\n  /** Display name, for example \"Claude Sonnet 5.5\". */\n  name: string;\n  /** Groups the list and labels the monogram on the trigger. */\n  provider: string;\n  /** Context window in tokens. Shown as \"200K context\". */\n  context?: number;\n  capabilities?: ModelCapability[];\n  /** A short note under the name, for example \"Best for long documents\". */\n  description?: ReactNode;\n  /** Keeps the model visible but not selectable. Say why in `description`. */\n  disabled?: boolean;\n}\n\nexport interface ModelSelectorProps {\n  models: ModelOption[];\n  /** Selected model id. Pair with `onValueChange`. */\n  value?: string;\n  /** Initial model id when uncontrolled. Defaults to the first enabled model. */\n  defaultValue?: string;\n  onValueChange?: (id: string) => void;\n  /** @default \"Search models\" */\n  searchPlaceholder?: string;\n  disabled?: boolean;\n  /** Classes for the trigger button. */\n  className?: string;\n  /** Popup side relative to the trigger. @default \"bottom\" */\n  side?: \"top\" | \"bottom\";\n}\n\nconst compact = new Intl.NumberFormat(\"en\", { notation: \"compact\", maximumFractionDigits: 1 });\n\nfunction matches(model: ModelOption, query: string) {\n  const words = query.toLowerCase().trim().split(/\\s+/).filter(Boolean);\n  if (!words.length) return true;\n  const haystack = [model.name, model.provider, ...(model.capabilities ?? []).map((capability) => capabilityLabels[capability])].join(\" \").toLowerCase();\n  return words.every((word) => haystack.includes(word));\n}\n\n/**\n * A model picker: a quiet trigger with the model's name that opens a searchable list grouped\n * by provider. Each row shows the context size and capability badges. Type to filter by name,\n * provider, or capability (\"vision\", \"reasoning\"); arrows move, Enter picks.\n */\nexport function ModelSelector({\n  models,\n  value: valueProp,\n  defaultValue,\n  onValueChange,\n  searchPlaceholder = \"Search models\",\n  disabled = false,\n  className,\n  side = \"bottom\",\n}: ModelSelectorProps) {\n  const [uncontrolled, setUncontrolled] = useState(() => defaultValue ?? models.find((model) => !model.disabled)?.id);\n  const id = valueProp ?? uncontrolled;\n  const selected = models.find((model) => model.id === id) ?? null;\n  const [query, setQuery] = useState(\"\");\n\n  const groups = useMemo(() => {\n    const byProvider = new Map<string, ModelOption[]>();\n    for (const model of models) byProvider.set(model.provider, [...(byProvider.get(model.provider) ?? []), model]);\n    return Array.from(byProvider, ([provider, items]) => ({ value: provider, items }));\n  }, [models]);\n\n  return (\n    <Combobox.Root\n      items={groups}\n      value={selected}\n      onValueChange={(model: ModelOption | null) => {\n        if (!model) return;\n        if (valueProp === undefined) setUncontrolled(model.id);\n        onValueChange?.(model.id);\n      }}\n      itemToStringLabel={(model: ModelOption) => model.name}\n      isItemEqualToValue={(a: ModelOption, b: ModelOption) => a.id === b.id}\n      filter={(model: ModelOption, search: string) => matches(model, search)}\n      onInputValueChange={setQuery}\n      disabled={disabled}\n    >\n      <Combobox.Trigger className={cx(triggerBase, className)}>\n        {selected ? <Monogram provider={selected.provider} /> : null}\n        <span className=\"sr-only\">Model: </span>\n        <span className=\"min-w-0 truncate font-medium\">{selected ? selected.name : \"Choose a model\"}</span>\n        <Chevron />\n      </Combobox.Trigger>\n      <Combobox.Portal>\n        <Combobox.Positioner side={side} align=\"start\" sideOffset={6} className=\"z-50 outline-none\">\n          <Combobox.Popup className={cx(popupSurface, \"flex max-h-[min(28rem,var(--available-height))] w-[min(24rem,calc(100vw-2rem))] flex-col overflow-hidden\")}>\n            <div className=\"flex items-center gap-2 border-b border-zinc-950/[0.07] px-3 dark:border-white/[0.08]\">\n              <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth={1.5} strokeLinecap=\"round\" className=\"size-4 shrink-0 text-zinc-400 dark:text-zinc-500\">\n                <circle cx=\"7\" cy=\"7\" r=\"4.25\" />\n                <path d=\"m10.25 10.25 3 3\" />\n              </svg>\n              <Combobox.Input\n                aria-label=\"Search models\"\n                placeholder={searchPlaceholder}\n                className=\"h-11 min-w-0 flex-1 bg-transparent text-sm text-zinc-950 outline-none placeholder:text-zinc-400 dark:text-white dark:placeholder:text-zinc-500\"\n              />\n            </div>\n            <Combobox.Empty className=\"text-sm text-zinc-500 empty:hidden\">\n              <p className=\"px-4 py-6 text-center\">No models match &ldquo;{query.trim()}&rdquo;</p>\n            </Combobox.Empty>\n            <Combobox.List className=\"min-h-0 flex-1 overflow-y-auto overscroll-contain p-1.5 empty:hidden\">\n              {(group: { value: string; items: ModelOption[] }) => (\n                <Combobox.Group key={group.value} items={group.items} className=\"not-first:mt-1.5\">\n                  <Combobox.GroupLabel className=\"px-2 pt-1.5 pb-1 text-xs font-medium text-zinc-500 select-none\">{group.value}</Combobox.GroupLabel>\n                  <Combobox.Collection>\n                    {(model: ModelOption) => (\n                      <Combobox.Item key={model.id} value={model} disabled={model.disabled} className={itemBase}>\n                        <ModelRow model={model} />\n                        <Combobox.ItemIndicator className=\"mt-0.5 flex size-4 shrink-0 items-center justify-center text-zinc-950 dark:text-white\">\n                          <Check />\n                        </Combobox.ItemIndicator>\n                      </Combobox.Item>\n                    )}\n                  </Combobox.Collection>\n                </Combobox.Group>\n              )}\n            </Combobox.List>\n          </Combobox.Popup>\n        </Combobox.Positioner>\n      </Combobox.Portal>\n    </Combobox.Root>\n  );\n}\n\nfunction ModelRow({ model }: { model: ModelOption }) {\n  const capabilities = model.capabilities ?? [];\n  return (\n    <div className=\"min-w-0 flex-1\">\n      <p className=\"truncate text-sm leading-5 text-zinc-950 dark:text-white\">{model.name}</p>\n      {model.description != null ? <p className=\"text-xs leading-5 text-zinc-500\">{model.description}</p> : null}\n      {model.context != null || capabilities.length ? (\n        <div className=\"mt-1 flex flex-wrap items-center gap-1\">\n          {model.context != null ? (\n            <span className=\"mr-1.5 font-mono text-[11px] text-zinc-500 tabular-nums\">{compact.format(model.context)} context</span>\n          ) : null}\n          {capabilities.map((capability) => (\n            <span\n              key={capability}\n              className=\"inline-flex h-[18px] items-center gap-1 rounded-[5px] border border-zinc-950/10 px-1.5 text-[11px] leading-none text-zinc-600 dark:border-white/10 dark:text-zinc-400 [&_svg]:size-3 [&_svg]:shrink-0\"\n            >\n              <CapabilityIcon capability={capability} />\n              {capabilityLabels[capability]}\n            </span>\n          ))}\n        </div>\n      ) : null}\n    </div>\n  );\n}\n\n/** The provider's initial in a small hairline square. No logos: they belong to their owners. */\nfunction Monogram({ provider }: { provider: string }) {\n  return (\n    <span\n      aria-hidden=\"true\"\n      className=\"flex size-5 shrink-0 items-center justify-center rounded-md border border-zinc-950/10 text-[11px] leading-none font-semibold text-zinc-600 dark:border-white/15 dark:text-zinc-300\"\n    >\n      {provider.trim().charAt(0).toUpperCase()}\n    </span>\n  );\n}\n\nfunction CapabilityIcon({ capability }: { capability: ModelCapability }) {\n  const paths: Record<ModelCapability, ReactNode> = {\n    vision: (\n      <>\n        <path d=\"M1.75 8S4 3.75 8 3.75 14.25 8 14.25 8 12 12.25 8 12.25 1.75 8 1.75 8Z\" />\n        <circle cx=\"8\" cy=\"8\" r=\"2\" />\n      </>\n    ),\n    tools: <path d=\"M9.75 2.5a3.25 3.25 0 0 0-3 4.5L2.5 11.25 4.75 13.5 9 9.25a3.25 3.25 0 0 0 4.5-3l-2 1.25-1.75-.5-.5-1.75Z\" />,\n    reasoning: <path d=\"M8 2.25 9.4 6.6 13.75 8 9.4 9.4 8 13.75 6.6 9.4 2.25 8 6.6 6.6Z\" />,\n    files: <path d=\"M4 1.75h5L12.25 5v9.25H4ZM9 1.75V5h3.25\" />,\n    audio: <path d=\"M3 6.5v3M5.75 4.5v7M8.5 2.5v11M11.25 5v6M14 7v2\" />,\n    fast: <path d=\"M9 1.75 3.5 9H8l-1 5.25L12.5 7H8Z\" />,\n  };\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth={1.4} strokeLinecap=\"round\" strokeLinejoin=\"round\">\n      {paths[capability]}\n    </svg>\n  );\n}\n\n// ---------------------------------------------------------------------------\n// Reasoning effort\n\nexport interface ReasoningEffortLevel {\n  value: string;\n  label: string;\n  /** One line about the trade-off, shown in the list. */\n  description?: ReactNode;\n}\n\nexport const defaultEffortLevels: ReasoningEffortLevel[] = [\n  { value: \"low\", label: \"Low\", description: \"Quick replies for simple asks\" },\n  { value: \"medium\", label: \"Medium\", description: \"Balanced speed and depth\" },\n  { value: \"high\", label: \"High\", description: \"Thinks longer on hard problems\" },\n];\n\nexport interface ReasoningEffortProps {\n  /** Levels from least to most effort. The bars on the trigger fill in this order. */\n  levels?: ReasoningEffortLevel[];\n  value?: string;\n  /** @default \"medium\" when it exists, otherwise the first level */\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  disabled?: boolean;\n  /** Classes for the trigger button. */\n  className?: string;\n  /** Popup side relative to the trigger. @default \"bottom\" */\n  side?: \"top\" | \"bottom\";\n}\n\n/**\n * How hard the model should think: a compact select whose trigger shows rising bars filled up\n * to the chosen level, with a one-line trade-off for each level in the list.\n */\nexport function ReasoningEffort({\n  levels = defaultEffortLevels,\n  value: valueProp,\n  defaultValue,\n  onValueChange,\n  disabled = false,\n  className,\n  side = \"bottom\",\n}: ReasoningEffortProps) {\n  const [uncontrolled, setUncontrolled] = useState(\n    () => defaultValue ?? levels.find((level) => level.value === \"medium\")?.value ?? levels[0]?.value ?? \"\",\n  );\n  const value = valueProp ?? uncontrolled;\n  const index = Math.max(0, levels.findIndex((level) => level.value === value));\n  const current = levels[index];\n\n  return (\n    <Select.Root\n      value={value}\n      onValueChange={(next: string | null) => {\n        if (next == null) return;\n        if (valueProp === undefined) setUncontrolled(next);\n        onValueChange?.(next);\n      }}\n      items={levels.map((level) => ({ value: level.value, label: level.label }))}\n      disabled={disabled}\n    >\n      <Select.Trigger className={cx(triggerBase, className)}>\n        <EffortBars level={index + 1} total={levels.length} />\n        <span className=\"sr-only\">Reasoning effort: </span>\n        <Select.Value className=\"min-w-0 truncate\">{() => current?.label}</Select.Value>\n        <Chevron />\n      </Select.Trigger>\n      <Select.Portal>\n        <Select.Positioner side={side} align=\"start\" sideOffset={6} alignItemWithTrigger={false} className=\"z-50 outline-none\">\n          <Select.Popup className={cx(popupSurface, \"w-64 p-1.5\")}>\n            <Select.List>\n              {levels.map((level, levelIndex) => (\n                <Select.Item key={level.value} value={level.value} className={cx(itemBase, \"items-center\")}>\n                  <EffortBars level={levelIndex + 1} total={levels.length} />\n                  <div className=\"min-w-0 flex-1\">\n                    <Select.ItemText className=\"block text-sm leading-5 text-zinc-950 dark:text-white\">{level.label}</Select.ItemText>\n                    {level.description != null ? <p className=\"text-xs leading-5 text-zinc-500\">{level.description}</p> : null}\n                  </div>\n                  <Select.ItemIndicator className=\"flex size-4 shrink-0 items-center justify-center text-zinc-950 dark:text-white\">\n                    <Check />\n                  </Select.ItemIndicator>\n                </Select.Item>\n              ))}\n            </Select.List>\n          </Select.Popup>\n        </Select.Positioner>\n      </Select.Portal>\n    </Select.Root>\n  );\n}\n\n/** Rising bars, filled up to `level` of `total`. The fill eases between levels. */\nexport function EffortBars({ level, total, className }: { level: number; total: number; className?: string }) {\n  const count = Math.max(1, total);\n  const gap = 1.5;\n  const width = (12 - gap * (count - 1)) / count;\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" className={cx(\"size-4 shrink-0\", className)}>\n      {Array.from({ length: count }, (_, i) => {\n        const height = 4 + ((10 - 4) * i) / Math.max(1, count - 1);\n        return (\n          <rect\n            key={i}\n            x={2 + i * (width + gap)}\n            y={13 - height}\n            width={width}\n            height={height}\n            rx={0.75}\n            fill=\"currentColor\"\n            className={cx(\"transition-[fill-opacity] duration-200 ease-out motion-reduce:transition-none\", i < level ? \"fill-current\" : \"\")}\n            fillOpacity={i < level ? 1 : 0.22}\n          />\n        );\n      })}\n    </svg>\n  );\n}\n\nfunction Chevron() {\n  return (\n    <svg\n      aria-hidden=\"true\"\n      viewBox=\"0 0 16 16\"\n      fill=\"none\"\n      className=\"size-3.5 shrink-0 text-zinc-400 transition-colors duration-150 group-hover:text-current motion-reduce:transition-none dark:text-zinc-500\"\n    >\n      <path d=\"m4.5 6.25 3.5 3.5 3.5-3.5\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\n\nfunction Check() {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth={1.6} strokeLinecap=\"round\" strokeLinejoin=\"round\" className=\"size-4\">\n      <path d=\"m3.75 8.25 2.75 2.75 5.75-6\" />\n    </svg>\n  );\n}\n"
    }
  ],
  "example": {
    "content": "\"use client\";\n\nimport { useState } from \"react\";\nimport { type ModelOption, ModelSelector, ReasoningEffort } from \"@/components/shaken/agent/model-selector\";\n\nconst models: ModelOption[] = [\n  { id: \"claude-sonnet-5-5\", name: \"Claude Sonnet 5.5\", provider: \"Anthropic\", context: 200_000, capabilities: [\"vision\", \"tools\", \"reasoning\"] },\n  { id: \"claude-haiku-5-5\", name: \"Claude Haiku 5.5\", provider: \"Anthropic\", context: 200_000, capabilities: [\"vision\", \"tools\", \"fast\"] },\n  { id: \"gpt-5\", name: \"GPT-5\", provider: \"OpenAI\", context: 400_000, capabilities: [\"vision\", \"tools\", \"reasoning\"] },\n  { id: \"gpt-5-mini\", name: \"GPT-5 mini\", provider: \"OpenAI\", context: 400_000, capabilities: [\"tools\", \"fast\"] },\n  { id: \"gemini-2-5-pro\", name: \"Gemini 2.5 Pro\", provider: \"Google\", context: 1_000_000, capabilities: [\"vision\", \"audio\", \"reasoning\"] },\n  {\n    id: \"gemini-2-5-flash\",\n    name: \"Gemini 2.5 Flash\",\n    provider: \"Google\",\n    context: 1_000_000,\n    capabilities: [\"vision\", \"fast\"],\n    description: \"Not enabled for this workspace\",\n    disabled: true,\n  },\n];\n\nexport default function ModelSelectorExample() {\n  const [model, setModel] = useState(\"claude-sonnet-5-5\");\n  const [effort, setEffort] = useState(\"medium\");\n  return (\n    <div className=\"flex flex-wrap items-center gap-1 rounded-xl border border-zinc-950/10 p-1.5 dark:border-white/10\">\n      <ModelSelector models={models} value={model} onValueChange={setModel} />\n      <span aria-hidden=\"true\" className=\"h-4 w-px bg-zinc-950/10 dark:bg-white/10\" />\n      <ReasoningEffort value={effort} onValueChange={setEffort} />\n    </div>\n  );\n}\n"
  }
}
