AI Picker

Choose who does the work: a deck of model cards that shuffles the chosen one forward, an agent roster where a face opens into a detail card, and a radial effort dial you drag.

Installation

Installation

One command adds ai-picker and the shared AI Kit layer it is built on (tokens, faces, marks and brand icons). No animation library, light and dark built in.

$npx shadcn@latest add https://tweenui.dev/r/ai-picker.json
ai-picker-demo
components/ui/ai-picker-demo.tsx
"use client"

import * as React from "react"
import { Brain, Gauge, Zap } from "lucide-react"

import { AiDemo } from "@/lib/ai-demo"
import {
  AiStyle,
  Face,
  Mark,
  Roll,
  useAiLoop,
  useIdleHands,
  type AiMood,
} from "@/lib/ai-kit"
import {
  AiAgentRoster,
  AiEffortDial,
  AiModelDeck,
  type AiEffortLevel,
  type AiModelCard,
  type AiRosterAgent,
} from "@/registry/tween/ai-picker"

const CSS = `
.aik-pkd-scene{display:grid;grid-template-columns:minmax(0,1fr);gap:12px;justify-items:center;width:min(100%,560px)}
.aik-pkd-scene > *{min-width:0;max-width:100%}
.aik-pkd-strip{display:inline-flex;align-items:center;gap:9px;height:36px;padding:0 14px 0 8px;border-radius:18px;background:var(--aik-card);box-shadow:var(--aik-sh-card);font-size:13.5px;max-width:100%}
.aik-pkd-strip .aik-roll{color:var(--aik-text-2);line-height:20px}
.aik-pkd-task{display:flex;align-items:center;gap:10px;width:100%;padding:0 8px;font-size:15px;line-height:22px;color:var(--aik-text-2)}
.aik-pkd-task b{color:var(--aik-text);font-weight:500}
`

const MODELS: AiModelCard[] = [
  {
    id: "fast",
    name: "Mira Fast",
    tagline: "Quick edits, small fixes, renames",
    price: "$0.25 / M",
    icon: <Zap size={20} />,
    sparkValue: "1.1 s median",
    spark: [
      0.82, 0.8, 0.86, 0.78, 0.84, 0.88, 0.8, 0.86, 0.9, 0.84, 0.88, 0.86,
    ],
    meters: [
      { label: "Speed", text: "1 s", value: 0.94 },
      { label: "Depth", text: "8k", value: 0.2 },
      { label: "Cost", text: "$", value: 0.18 },
    ],
  },
  {
    id: "balanced",
    name: "Mira Balanced",
    tagline: "New sections and everyday work",
    price: "$1.50 / M",
    icon: <Gauge size={20} />,
    sparkValue: "4.2 s median",
    spark: [
      0.5, 0.58, 0.46, 0.62, 0.55, 0.48, 0.6, 0.52, 0.64, 0.56, 0.5, 0.58,
    ],
    meters: [
      { label: "Speed", text: "4 s", value: 0.6 },
      { label: "Depth", text: "24k", value: 0.55 },
      { label: "Cost", text: "$$", value: 0.5 },
    ],
  },
  {
    id: "deep",
    name: "Mira Deep",
    tagline: "Long refactors and hard bugs",
    price: "$6.00 / M",
    icon: <Brain size={20} />,
    sparkValue: "9.4 s median",
    spark: [0.2, 0.3, 0.22, 0.36, 0.26, 0.18, 0.32, 0.4, 0.24, 0.3, 0.2, 0.28],
    meters: [
      { label: "Speed", text: "9 s", value: 0.28 },
      { label: "Depth", text: "64k", value: 0.96 },
      { label: "Cost", text: "$$$", value: 0.9 },
    ],
  },
]

function Deck() {
  const root = React.useRef<HTMLDivElement>(null)
  const [hands, touch] = useIdleHands()
  const [value, setValue] = React.useState("fast")
  const [used, setUsed] = React.useState<string | null>(null)
  const name = (id: string) => MODELS.find((model) => model.id === id)?.name

  useAiLoop(
    root,
    async ({ sleep }) => {
      setUsed(null)
      setValue("fast")
      await sleep(1900)
      setValue("balanced")
      await sleep(1900)
      setValue("deep")
      await sleep(2100)
      setUsed("deep")
      await sleep(2300)
    },
    { gap: 300, enabled: !hands, still: () => setValue("balanced") }
  )

  return (
    <div
      ref={root}
      className="aik-pkd-scene"
      onPointerDown={touch}
      onKeyDown={touch}
    >
      <div className="aik-pkd-strip">
        {used ? (
          <Mark status="done" />
        ) : (
          <Face size={22} shape="orb" mood="listen" />
        )}
        <Roll>
          {used
            ? `The next message goes to ${name(used)}`
            : `Comparing ${name(value)}`}
        </Roll>
      </div>
      <AiModelDeck
        models={MODELS}
        value={value}
        onValueChange={(id) => {
          setUsed(null)
          setValue(id)
        }}
        onConfirm={(model) => setUsed(model.id)}
      />
    </div>
  )
}

const AGENTS: AiRosterAgent[] = [
  {
    id: "mira",
    name: "Mira",
    role: "Builds pages and sections from what is in the registry.",
    tag: "Builder",
    skills: ["React", "Layout", "Motion", "Copy"],
    tone: "blue",
    shape: "orb",
  },
  {
    id: "odo",
    name: "Odo",
    role: "Writes the tests, runs them, and fixes what fails.",
    tag: "Tester",
    skills: ["Unit tests", "Type checks", "Bug hunts"],
    tone: "violet",
    shape: "blob",
  },
  {
    id: "juno",
    name: "Juno",
    role: "Reviews every change before it merges.",
    tag: "Reviewer",
    skills: ["Code review", "Accessibility", "Performance"],
    tone: "amber",
    shape: "arch",
  },
  {
    id: "pim",
    name: "Pim",
    role: "Keeps the docs and the registry in step with the code.",
    tag: "Librarian",
    skills: ["Docs", "Registry", "Changelogs"],
    tone: "green",
    shape: "leaf",
  },
]

function Roster() {
  const root = React.useRef<HTMLDivElement>(null)
  const [hands, touch] = useIdleHands()
  const [value, setValue] = React.useState<string | null>(null)
  const [assigned, setAssigned] = React.useState<string | null>(null)

  useAiLoop(
    root,
    async ({ sleep }) => {
      setAssigned(null)
      setValue(null)
      await sleep(1500)
      setValue("odo")
      await sleep(2300)
      setValue("mira")
      await sleep(2100)
      setAssigned("mira")
      await sleep(2400)
      setValue(null)
      await sleep(900)
    },
    { gap: 300, enabled: !hands, still: () => setValue("mira") }
  )

  return (
    <div
      ref={root}
      className="aik-pkd-scene"
      onPointerDown={touch}
      onKeyDown={touch}
    >
      <p className="aik-pkd-task">
        Task: <b>Add a pricing section under the hero</b>
      </p>
      <AiAgentRoster
        agents={AGENTS}
        value={value}
        onValueChange={setValue}
        assigned={assigned}
        onAssign={(agent) => setAssigned(agent.id)}
        hint="4 agents free"
      />
    </div>
  )
}

const LEVELS: AiEffortLevel[] = [
  {
    id: "off",
    label: "Off",
    note: "Answers straight away",
    budget: "0",
    mood: "idle",
  },
  {
    id: "low",
    label: "Low",
    note: "A quick look before answering",
    budget: "4k",
    mood: "listen",
  },
  {
    id: "medium",
    label: "Medium",
    note: "Weighs a couple of options",
    budget: "16k",
    mood: "think",
  },
  {
    id: "high",
    label: "High",
    note: "Plans first, then checks its work",
    budget: "32k",
    mood: "work",
  },
  {
    id: "max",
    label: "Max",
    note: "Tries several approaches and compares",
    budget: "64k",
    mood: "work",
  },
]
const TALK: Array<[string, AiMood]> = [
  ["I will answer right away.", "idle"],
  ["I will take a quick look first.", "listen"],
  ["I will weigh two options before I write.", "think"],
  ["I will plan, build, then check my work.", "work"],
  ["I will try three approaches and keep the best.", "work"],
]

function Dial() {
  const root = React.useRef<HTMLDivElement>(null)
  const [hands, touch] = useIdleHands()
  const [value, setValue] = React.useState(2)

  useAiLoop(
    root,
    async ({ sleep }) => {
      for (const next of [0, 1, 2, 3, 4, 2]) {
        setValue(next)
        await sleep(1300)
      }
    },
    { gap: 500, enabled: !hands, still: () => setValue(3) }
  )

  const [line, mood] = TALK[value] ?? TALK[0]!
  return (
    <div
      ref={root}
      className="aik-pkd-scene"
      onPointerDown={touch}
      onKeyDown={touch}
    >
      <AiEffortDial levels={LEVELS} value={value} onValueChange={setValue} />
      <div className="aik-pkd-strip">
        <Face size={22} shape="blob" tone="violet" mood={mood} />
        <Roll>{line}</Roll>
      </div>
    </div>
  )
}

export function AiPickerDemo({ only }: { only?: string }) {
  return (
    <>
      <AiStyle id="ai-picker-demo" css={CSS} />
      <AiDemo
        only={only}
        tabs={[
          { name: "Model deck", node: <Deck /> },
          { name: "Agent roster", node: <Roster /> },
          { name: "Effort dial", node: <Dial /> },
        ]}
      />
    </>
  )
}

Installation

pnpm dlx shadcn@latest add https://tweenui.dev/r/ai-picker.json

Usage

import {
  AiAgentRoster,
  AiEffortDial,
  AiModelDeck,
} from "@/components/ui/ai-picker"
const [model, setModel] = useState("balanced")
 
<AiModelDeck
  models={[
    {
      id: "fast",
      name: "Mira Fast",
      tagline: "Quick edits and small fixes",
      price: "$0.25 / M",
      icon: <Zap size={20} />,
      spark: [0.8, 0.86, 0.78, 0.9, 0.84],
      sparkValue: "1.1 s median",
      meters: [
        { label: "Speed", text: "1 s", value: 0.94 },
        { label: "Depth", text: "8k", value: 0.2 },
        { label: "Cost", text: "$", value: 0.18 },
      ],
    },
    // two more
  ]}
  value={model}
  onValueChange={setModel}
  onConfirm={(chosen) => useModel(chosen.id)}
/>

Versions

  • AiModelDeck stacks model cards in depth. Choosing another shuffles the deck: the chosen card comes forward, its sparkline wipes in and its meters fill. Arrow keys, the dots and the cards behind all navigate; Enter confirms.
  • AiAgentRoster is a row of faces. Selecting one opens it in place into a card with its role, its skills and an assign button, while the others slide aside. Escape or the close button returns to the row.
  • AiEffortDial is a radial dial for reasoning effort. Drag the knob or use the arrow keys, Home and End. The arc fills, the ticks light, the face in the middle acts out the level, and the list beside it stays in step.

Props

AiModelDeck

PropTypeDefaultDescription
modelsAiModelCard[]id, name, tagline, price, meters, spark.
valuestringThe id of the front card.
onValueChange(id: string) => voidCalled when another card is chosen.
onConfirm(model: AiModelCard) => voidCalled by the button under the deck, or Enter.
confirmLabelstring"Use"The button label. The model name follows it.

Each meter is { label, text, value } with value from 0 to 1. spark is a list of points from 0 to 1.

AiAgentRoster

PropTypeDefaultDescription
agentsAiRosterAgent[]id, name, role, tag, skills, tone, shape.
valuestring | nullThe opened agent, or null for the resting row.
onValueChange(id: string | null) => voidCalled on select and on close.
onAssign(agent: AiRosterAgent) => voidCalled by the assign button.
assignedstring | nullnullShows this agent as assigned.
titlestring"Who should take this?"The card's heading.
hintstringA short note at the right of the heading.

AiEffortDial

PropTypeDefaultDescription
levelsAiEffortLevel[]id, label, note, budget, mood.
valuenumberIndex of the chosen level.
onValueChange(index: number) => voidCalled on drag, click and key press.
agent{ tone?, shape? }The face in the middle of the dial.
labelstring"Reasoning effort"Read by screen readers for the slider.