{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "prompt-01",
  "title": "Prompt with a status tray",
  "description": "A composer on a quiet tray whose one key dictates, sends or stops, while a status line slides out from under the card and rolls through the work.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/agent-run.json",
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/dropdown-menu.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/level-bars.json",
    "https://ui.ndekocode.dev/r/live-duration.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/media-clock.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/motion-word-roll.json",
    "https://ui.ndekocode.dev/r/segments.json",
    "https://ui.ndekocode.dev/r/textarea.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/tooltip.json",
    "https://ui.ndekocode.dev/r/use-agent-run.json",
    "https://ui.ndekocode.dev/r/use-autoplay.json",
    "https://ui.ndekocode.dev/r/use-kept-height.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/use-timeouts.json",
    "https://ui.ndekocode.dev/r/utils.json",
    "https://ui.ndekocode.dev/r/words.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/prompt/prompt-01.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion, useAnimate } from 'motion/react';\nimport { useContext, useEffect, useRef, useState } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { WordRoll } from '@/components/core/word-roll';\nimport {\n  ClockGateContext,\n  useRunSnapshot,\n} from '@/registry/ndeko/hooks/use-agent-run';\nimport {\n  typingSteps,\n  useAutoplay,\n  type AutoplayStep,\n} from '@/registry/ndeko/hooks/use-autoplay';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\nimport {\n  createRunStore,\n  elapsedOf,\n  emptyRun,\n  formatDuration,\n  type PlanStep,\n  type RunEvent,\n  type RunSnapshot,\n} from '@/registry/ndeko/lib/agent-run';\nimport {\n  hold,\n  PRESS_LEAD_MS,\n  pressedQuietOf,\n  pressedSolidOf,\n  spokenUnless,\n  usePress,\n} from '@/registry/ndeko/lib/demonstration';\nimport {\n  ArrowUpIcon,\n  BookOpenIcon,\n  CircleCheckIcon,\n  CircleXIcon,\n  FileTextIcon,\n  GlobeIcon,\n  HandIcon,\n  LoaderIcon,\n  MicIcon,\n  PaperclipIcon,\n  RotateCcwIcon,\n  SlidersIcon,\n  TerminalIcon,\n  XIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { EASE_OUT_STRONG, SPRING } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { appendWord, countOf, wordsOf } from '@/registry/ndeko/lib/words';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport {\n  DropdownMenu,\n  DropdownMenuCheckboxItem,\n  DropdownMenuContent,\n  DropdownMenuGroup,\n  DropdownMenuGroupLabel,\n  DropdownMenuTrigger,\n} from '@/registry/ndeko/ui/dropdown-menu';\nimport { ClockGate, LiveDuration } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { Segments, type Segment } from '@/registry/ndeko/ui/segments';\nimport { Textarea } from '@/registry/ndeko/ui/textarea';\nimport {\n  Tooltip,\n  TooltipContent,\n  TooltipTrigger,\n} from '@/registry/ndeko/ui/tooltip';\n\nimport { ClockSince } from './_parts/clock';\nimport { LevelBars } from '@/registry/ndeko/ui/level-bars';\nimport {\n  caretToEnd,\n  isOwnKey,\n  isSendKey,\n  useAutosize,\n} from './_parts/use-autosize';\n\nexport type TrayLine =\n  | { kind: 'listening'; since: number }\n  | { kind: 'working'; title: string; run: RunSnapshot }\n  | { kind: 'waiting'; run: RunSnapshot }\n  | { kind: 'answered'; run: RunSnapshot }\n  | { kind: 'stopped'; run: RunSnapshot }\n  | { kind: 'failed'; detail: string };\n\ntype TrayLineKind = TrayLine['kind'];\n\nconst LINE_PRESENCE = {\n  initial: { opacity: 0 },\n  animate: { opacity: 1 },\n  exit: { opacity: 0, transition: { duration: 0.14 } },\n  transition: { duration: 0.2 },\n};\n\nconst LANDING = { duration: 0.32, ease: EASE_OUT_STRONG };\n\nconst NUDGE = { duration: 0.28, ease: EASE_OUT_STRONG };\n\n/** Wide enough for 1m 04s, so a tick never moves the words beside the clock. */\nconst CLOCK_BOX = 'text-muted-foreground w-12 shrink-0 text-end';\n\nfunction runningStepOf(run: RunSnapshot) {\n  return run.plan.find((step) => step.status === 'running');\n}\n\nfunction failedStepOf(run: RunSnapshot) {\n  return run.plan.find((step) => step.status === 'failed');\n}\n\nfunction isWorking(run: RunSnapshot) {\n  const isRunning = run.status === 'running';\n  const isWaiting = run.status === 'waiting';\n  return isRunning || isWaiting;\n}\n\nfunction finishedDurationOf(run: RunSnapshot) {\n  const end = run.endedAt ?? run.startedAt ?? 0;\n  const elapsed = elapsedOf(run, end);\n  return formatDuration(elapsed);\n}\n\n/** Listening takes the tray before the answer does. */\nexport function trayLineOf(\n  run: RunSnapshot,\n  listeningSince: number | null\n): TrayLine | null {\n  if (listeningSince !== null) {\n    return { kind: 'listening', since: listeningSince };\n  }\n  if (run.status === 'running') {\n    const step = runningStepOf(run);\n    const title = step?.title ?? 'Starting';\n    return { kind: 'working', title, run };\n  }\n  if (run.status === 'waiting') {\n    return { kind: 'waiting', run };\n  }\n  if (run.status === 'done') {\n    return { kind: 'answered', run };\n  }\n  if (run.status === 'cancelled') {\n    return { kind: 'stopped', run };\n  }\n  if (run.status === 'failed') {\n    const step = failedStepOf(run);\n    const detail = step?.detail ?? 'The answer failed';\n    return { kind: 'failed', detail };\n  }\n  return null;\n}\n\nfunction lineTextOf(line: TrayLine) {\n  if (line.kind === 'listening') {\n    return 'Listening';\n  }\n  if (line.kind === 'working') {\n    return line.title;\n  }\n  if (line.kind === 'waiting') {\n    return 'Waiting on you';\n  }\n  if (line.kind === 'answered') {\n    const duration = finishedDurationOf(line.run);\n    return `Answered in ${duration}`;\n  }\n  if (line.kind === 'stopped') {\n    const duration = finishedDurationOf(line.run);\n    return `Stopped after ${duration}`;\n  }\n  return line.detail;\n}\n\nfunction StopGlyph({ className }: { className?: string }) {\n  return (\n    <span\n      aria-hidden='true'\n      className={cn('size-2.5 rounded-[2px] bg-current', className)}\n    />\n  );\n}\n\nfunction LineGlyph({\n  kind,\n  listeningIntensity,\n}: {\n  kind: TrayLineKind;\n  listeningIntensity: number;\n}) {\n  const isOnScreen = useContext(ClockGateContext);\n\n  if (kind === 'listening') {\n    return (\n      <LevelBars\n        isActive={isOnScreen}\n        intensity={listeningIntensity}\n        count={4}\n        seed={2}\n        className='h-3.5 gap-[2px]'\n        barClassName='w-[2px]'\n      />\n    );\n  }\n  if (kind === 'working') {\n    return (\n      <LoaderIcon className='text-muted-foreground size-3.5 animate-spin' />\n    );\n  }\n  if (kind === 'waiting') {\n    return <HandIcon className='text-warning-foreground size-3.5' />;\n  }\n  if (kind === 'answered') {\n    return <CircleCheckIcon className='text-success-foreground size-3.5' />;\n  }\n  if (kind === 'stopped') {\n    return <StopGlyph className='text-muted-foreground size-2' />;\n  }\n  return <CircleXIcon className='text-destructive-ink size-3.5' />;\n}\n\nfunction LineTime({ line }: { line: TrayLine }) {\n  if (line.kind === 'listening') {\n    return (\n      <ClockSince startedAt={line.since} isRunning className={CLOCK_BOX} />\n    );\n  }\n  if (line.kind === 'working') {\n    return <LiveDuration item={line.run} isRunning className={CLOCK_BOX} />;\n  }\n  return null;\n}\n\nfunction textToneOf(kind: TrayLineKind) {\n  if (kind === 'failed') {\n    return 'text-destructive-ink';\n  }\n  return 'text-foreground/80';\n}\n\nfunction StatusLine({\n  line,\n  listeningIntensity,\n  onRetry,\n  isRetryPressed,\n}: {\n  line: TrayLine;\n  listeningIntensity: number;\n  onRetry?: () => void;\n  isRetryPressed: boolean;\n}) {\n  const [scope, animate] = useAnimate<HTMLDivElement>();\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const kind = line.kind;\n  const lastKind = useRef(kind);\n  const text = lineTextOf(line);\n  const isFailed = kind === 'failed';\n  const canRetry = isFailed && onRetry !== undefined;\n\n  useEffect(() => {\n    const isSameKind = lastKind.current === kind;\n    lastKind.current = kind;\n    if (isSameKind) {\n      return;\n    }\n    if (shouldReduceMotion) {\n      return;\n    }\n    if (kind === 'answered') {\n      animate(scope.current, { scale: [1.04, 1] }, LANDING);\n    }\n    if (kind === 'failed') {\n      animate(scope.current, { x: [0, 4, 0] }, NUDGE);\n    }\n  }, [kind, shouldReduceMotion, animate, scope]);\n\n  return (\n    <div\n      ref={scope}\n      className='flex h-9 origin-left items-center gap-2.5 ps-3 pe-1.5 text-xs'\n    >\n      <Swap swapKey={line.kind} className='size-3.5 shrink-0 justify-center'>\n        <LineGlyph kind={line.kind} listeningIntensity={listeningIntensity} />\n      </Swap>\n      <span\n        className={cn(\n          'min-w-0 flex-1 truncate transition-colors duration-200',\n          textToneOf(line.kind)\n        )}\n      >\n        <WordRoll text={text} />\n      </span>\n      <LineTime line={line} />\n      {canRetry && (\n        <Button\n          type='button'\n          variant='ghost'\n          size='sm'\n          onClick={onRetry}\n          className={cn('h-6 px-2', pressedQuietOf(isRetryPressed))}\n        >\n          <RotateCcwIcon className='size-3.5' />\n          Retry\n        </Button>\n      )}\n    </div>\n  );\n}\n\nexport type StatusTrayProps = {\n  /** The answer in progress or just finished. While it is idle, the tray stays folded under the card. */\n  run: RunSnapshot;\n  /** Set while the microphone listens: the tray says so with live levels and a clock. */\n  listeningSince?: number | null;\n  /** How loud the voice is while listening, from 0 for silence to 1. */\n  listeningIntensity?: number;\n  onRetry?: () => void;\n  /** Shows Retry held down, for a demonstration that presses it. */\n  isRetryPressed?: boolean;\n  /** A demonstration drives the tray: its line is shown but not read aloud. */\n  isDemonstrated?: boolean;\n  children: React.ReactNode;\n  className?: string;\n};\n\nfunction lineRoleOf(isDemonstrated: boolean) {\n  if (isDemonstrated) {\n    return undefined;\n  }\n  return 'status';\n}\n\nexport function StatusTray({\n  run,\n  listeningSince = null,\n  listeningIntensity = 1,\n  onRetry,\n  isRetryPressed = false,\n  isDemonstrated = false,\n  children,\n  className,\n}: StatusTrayProps) {\n  const line = trayLineOf(run, listeningSince);\n\n  return (\n    <div\n      className={cn(\n        'bg-foreground/[0.04] dark:bg-foreground/[0.05] rounded-2xl p-1',\n        className\n      )}\n    >\n      <div className='relative z-10'>{children}</div>\n      {/*\n        The line is pinned to the bottom of a box that grows, so it comes out from under the card.\n        It stays outside the resizing box because its clock ticks.\n      */}\n      <div className='relative overflow-hidden'>\n        <AnimatedSize>\n          {line && <div aria-hidden='true' className='h-9' />}\n        </AnimatedSize>\n        <AnimatePresence initial={false}>\n          {line && (\n            <motion.div\n              key='status'\n              role={lineRoleOf(isDemonstrated)}\n              className='absolute inset-x-0 bottom-0'\n              {...LINE_PRESENCE}\n            >\n              <StatusLine\n                line={line}\n                listeningIntensity={listeningIntensity}\n                onRetry={onRetry}\n                isRetryPressed={isRetryPressed}\n              />\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n    </div>\n  );\n}\n\nexport type TrayKeyMode = 'mic' | 'send' | 'stop' | 'stop-listening';\n\nconst KEY_LABEL: Record<TrayKeyMode, string> = {\n  mic: 'Dictate a prompt',\n  send: 'Send the prompt',\n  stop: 'Stop the answer',\n  'stop-listening': 'Stop listening',\n};\n\nfunction glyphKeyOf(mode: TrayKeyMode) {\n  if (mode === 'stop-listening') {\n    return 'stop';\n  }\n  return mode;\n}\n\nfunction KeyGlyph({ mode }: { mode: TrayKeyMode }) {\n  if (mode === 'mic') {\n    return <MicIcon />;\n  }\n  if (mode === 'send') {\n    return <ArrowUpIcon />;\n  }\n  return <StopGlyph />;\n}\n\nexport function trayKeyModeOf(\n  isListening: boolean,\n  isAnswering: boolean,\n  hasText: boolean\n): TrayKeyMode {\n  if (isListening) {\n    return 'stop-listening';\n  }\n  if (isAnswering) {\n    return 'stop';\n  }\n  if (hasText) {\n    return 'send';\n  }\n  return 'mic';\n}\n\ntype TrayKeyProps = {\n  mode: TrayKeyMode;\n  onPress: (mode: TrayKeyMode) => void;\n  disabled?: boolean;\n  /** Shows the key held down, for a demonstration that presses it. */\n  isPressed?: boolean;\n};\n\nexport function TrayKey({\n  mode,\n  onPress,\n  disabled,\n  isPressed = false,\n}: TrayKeyProps) {\n  return (\n    <Button\n      type='button'\n      size='icon'\n      aria-label={KEY_LABEL[mode]}\n      disabled={disabled}\n      onClick={() => onPress(mode)}\n      className={pressedSolidOf(isPressed)}\n    >\n      <Swap swapKey={glyphKeyOf(mode)}>\n        <KeyGlyph mode={mode} />\n      </Swap>\n    </Button>\n  );\n}\n\ntype ToolId = 'docs' | 'web' | 'code';\n\ntype Tool = {\n  id: ToolId;\n  label: string;\n  icon: React.ReactNode;\n  step: string;\n  stepMs: number;\n  failure: string;\n};\n\nconst TOOLS: Tool[] = [\n  {\n    id: 'docs',\n    label: 'Search the docs',\n    icon: <BookOpenIcon />,\n    step: 'Searching the docs',\n    stepMs: 1500,\n    failure: 'The docs search timed out',\n  },\n  {\n    id: 'web',\n    label: 'Search the web',\n    icon: <GlobeIcon />,\n    step: 'Searching the web',\n    stepMs: 1300,\n    failure: 'The web search was refused',\n  },\n  {\n    id: 'code',\n    label: 'Run code',\n    icon: <TerminalIcon />,\n    step: 'Running the code',\n    stepMs: 1200,\n    failure: 'The code ran past its time limit',\n  },\n];\n\nconst READ_MS = 1100;\n\nconst WRITE_MS = 1700;\n\nconst WRITE_FAILURE = 'The model stopped responding';\n\nconst ANSWERED_HOLD_MS = 1800;\n\nconst STOPPED_HOLD_MS = 1800;\n\nconst FIRST_WORD_MS = 450;\n\nconst WORD_GAP_MS = 260;\n\nconst QUIET_INTENSITY = 0.12;\n\nconst MAX_FIELD_HEIGHT = 168;\n\nconst DICTATION =\n  'Summarize the open pull requests and flag any that touch billing';\n\nconst IDLE_RUN = emptyRun({ id: 'answer', title: 'Answer' });\n\n/** The piece opens on an answer that just landed, so the tray shows before anything plays. */\nconst ANSWERED_RUN = emptyRun({\n  id: 'answer',\n  title: 'Answer',\n  status: 'done',\n  startedAt: 0,\n  endedAt: 4300,\n});\n\nconst DEMO_PROMPTS = [\n  DICTATION,\n  'Which Brightmoor invoices are still unpaid?',\n  'Draft a reply to the pricing question from Ostrava',\n];\n\n/** One answer in three fails, so the tray shows its error and Retry. */\nconst FAILING_ROUND = 3;\n\ntype PressKey = 'key' | 'retry';\n\ntype TrayFile = {\n  id: string;\n  name: string;\n};\n\nconst SEED_FILES: TrayFile[] = [\n  { id: 'seed-invoices', name: 'q3-invoices.csv' },\n  { id: 'seed-pricing', name: 'brightmoor-pricing.pdf' },\n];\n\ntype Outcome = 'answers' | 'fails';\n\nconst OUTCOMES: Segment<Outcome>[] = [\n  { value: 'answers', label: 'Answers' },\n  { value: 'fails', label: 'Fails' },\n];\n\ntype TimedEvent = {\n  at: number;\n  event: RunEvent;\n};\n\ntype Timeline = {\n  events: TimedEvent[];\n  endsAt: number;\n};\n\ntype SentPrompt = {\n  text: string;\n  steps: PlanStep[];\n};\n\nfunction readTitleOf(fileCount: number) {\n  if (fileCount === 0) {\n    return 'Reading the question';\n  }\n  const files = countOf(fileCount, 'file');\n  return `Reading ${files}`;\n}\n\nfunction toolOf(id: string) {\n  return TOOLS.find((tool) => tool.id === id);\n}\n\nfunction stepMsOf(step: PlanStep) {\n  if (step.id === 'read') {\n    return READ_MS;\n  }\n  if (step.id === 'write') {\n    return WRITE_MS;\n  }\n  const tool = toolOf(step.id);\n  return tool?.stepMs ?? WRITE_MS;\n}\n\nfunction failureOf(step: PlanStep) {\n  const tool = toolOf(step.id);\n  return tool?.failure ?? WRITE_FAILURE;\n}\n\n/** The answer only does what it was given: a step for the files, one per tool that is on, then the writing. */\nfunction planOf(fileCount: number, tools: ToolId[]): PlanStep[] {\n  const steps: PlanStep[] = [\n    { id: 'read', title: readTitleOf(fileCount), status: 'upcoming' },\n  ];\n  for (const tool of TOOLS) {\n    const isOn = tools.includes(tool.id);\n    if (isOn) {\n      steps.push({ id: tool.id, title: tool.step, status: 'upcoming' });\n    }\n  }\n  steps.push({ id: 'write', title: 'Writing the answer', status: 'upcoming' });\n  return steps;\n}\n\n/** A failing answer breaks on its last tool, or on the writing when no tool is on. */\nfunction failingStepIdOf(steps: PlanStep[]) {\n  const toolSteps = steps.filter((step) => toolOf(step.id) !== undefined);\n  const lastTool = toolSteps.at(-1);\n  return lastTool?.id ?? 'write';\n}\n\nfunction timelineOf(steps: PlanStep[], shouldFail: boolean): Timeline {\n  const events: TimedEvent[] = [];\n  const failingId = failingStepIdOf(steps);\n  let at = 0;\n  for (const step of steps) {\n    events.push({\n      at,\n      event: {\n        type: 'step.updated',\n        id: step.id,\n        patch: { status: 'running' },\n      },\n    });\n    at += stepMsOf(step);\n    const isFailing = shouldFail && step.id === failingId;\n    if (isFailing) {\n      events.push({\n        at,\n        event: {\n          type: 'step.updated',\n          id: step.id,\n          patch: { status: 'failed', detail: failureOf(step) },\n        },\n      });\n      events.push({ at, event: { type: 'run.finished', status: 'failed' } });\n      return { events, endsAt: at };\n    }\n    events.push({\n      at,\n      event: { type: 'step.updated', id: step.id, patch: { status: 'done' } },\n    });\n  }\n  events.push({ at, event: { type: 'run.finished', status: 'done' } });\n  return { events, endsAt: at };\n}\n\nfunction announcementOf(line: TrayLine | null) {\n  if (!line) {\n    return '';\n  }\n  const text = lineTextOf(line);\n  if (line.kind === 'stopped') {\n    return `${text}. Your prompt is back in the field`;\n  }\n  return text;\n}\n\nfunction toolsLabelOf(count: number) {\n  const tools = countOf(count, 'tool');\n  return `Tools, ${tools} on`;\n}\n\nfunction FileChips({\n  files,\n  onRemove,\n}: {\n  files: TrayFile[];\n  onRemove: (id: string) => void;\n}) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const hasFiles = files.length > 0;\n  const fileIds = files.map((file) => file.id);\n  const order = fileIds.join(' ');\n\n  return (\n    <ul\n      aria-label='Attached files'\n      className={cn('flex flex-wrap gap-1.5', hasFiles && 'px-1 pt-1')}\n    >\n      <AnimatePresence initial={false} mode='popLayout'>\n        {files.map((file) => (\n          <motion.li\n            key={file.id}\n            layout\n            layoutDependency={order}\n            initial={{ opacity: 0, scale: 0.95 }}\n            animate={{ opacity: 1, scale: 1 }}\n            exit={{ opacity: 0, scale: 0.95 }}\n            transition={chipTransitionOf(shouldReduceMotion)}\n            className='bg-foreground/[0.05] flex h-6 max-w-full items-center gap-1 rounded-md ps-1.5 pe-0.5 text-xs'\n          >\n            <FileTextIcon className='text-muted-foreground size-3.5 shrink-0' />\n            <span className='max-w-36 truncate'>{file.name}</span>\n            <Button\n              type='button'\n              variant='ghost'\n              size='icon-sm'\n              aria-label={`Remove ${file.name}`}\n              onClick={() => onRemove(file.id)}\n              className='text-muted-foreground size-5'\n            >\n              <XIcon className='size-3' />\n            </Button>\n          </motion.li>\n        ))}\n      </AnimatePresence>\n    </ul>\n  );\n}\n\nfunction chipTransitionOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return { duration: 0 };\n  }\n  return SPRING;\n}\n\nfunction ToolsMenu({\n  tools,\n  onToggle,\n  disabled,\n}: {\n  tools: ToolId[];\n  onToggle: (id: ToolId, isOn: boolean) => void;\n  disabled: boolean;\n}) {\n  const count = tools.length;\n  const hasTools = count > 0;\n\n  return (\n    <DropdownMenu>\n      <Tooltip>\n        <TooltipTrigger\n          render={\n            <DropdownMenuTrigger\n              disabled={disabled}\n              render={\n                <Button\n                  type='button'\n                  variant='outline'\n                  size='icon'\n                  aria-label={toolsLabelOf(count)}\n                  className='relative'\n                />\n              }\n            />\n          }\n        >\n          <SlidersIcon />\n          {hasTools && (\n            <span\n              aria-hidden='true'\n              className='chip-3d absolute -end-1 -top-1 flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[10px] font-medium [--chip:var(--primary)]'\n            >\n              <MotionNumber value={count} />\n            </span>\n          )}\n        </TooltipTrigger>\n        <TooltipContent>Tools</TooltipContent>\n      </Tooltip>\n      <DropdownMenuContent side='top' align='start' className='min-w-52'>\n        <DropdownMenuGroup>\n          <DropdownMenuGroupLabel>Tools for this answer</DropdownMenuGroupLabel>\n          {TOOLS.map((tool) => (\n            <DropdownMenuCheckboxItem\n              key={tool.id}\n              checked={tools.includes(tool.id)}\n              onCheckedChange={(isOn) => onToggle(tool.id, isOn)}\n            >\n              {tool.icon}\n              {tool.label}\n            </DropdownMenuCheckboxItem>\n          ))}\n        </DropdownMenuGroup>\n      </DropdownMenuContent>\n    </DropdownMenu>\n  );\n}\n\nfunction withTool(tools: ToolId[], id: ToolId, isOn: boolean) {\n  const others = tools.filter((tool) => tool !== id);\n  if (isOn) {\n    return [...others, id];\n  }\n  return others;\n}\n\nexport default function Prompt01() {\n  const [draft, setDraft] = useState('');\n  const [files, setFiles] = useState<TrayFile[]>(SEED_FILES);\n  const [tools, setTools] = useState<ToolId[]>(['docs']);\n  const [outcome, setOutcome] = useState<Outcome>('answers');\n  const [listeningSince, setListeningSince] = useState<number | null>(null);\n  const [wordsLeft, setWordsLeft] = useState(0);\n  const [round, setRound] = useState(0);\n  const [store] = useState(() => createRunStore(ANSWERED_RUN));\n  const run = useRunSnapshot(store);\n  const { schedule, clearAll } = useTimeouts();\n  const { pressed, press } = usePress<PressKey>();\n  const textareaRef = useRef<HTMLTextAreaElement>(null);\n  const fileInputRef = useRef<HTMLInputElement>(null);\n  const draftBeforeListening = useRef('');\n  const lastPrompt = useRef<SentPrompt | null>(null);\n  const fileCounter = useRef(0);\n  const isListening = listeningSince !== null;\n  const isAnswering = isWorking(run);\n  const isFailed = run.status === 'failed';\n  const hasText = draft.trim().length > 0;\n  const keyMode = trayKeyModeOf(isListening, isAnswering, hasText);\n  const isSpeaking = wordsLeft > 0;\n  const listeningIntensity = levelIntensityOf(isSpeaking);\n  const line = trayLineOf(run, listeningSince);\n  const announcement = announcementOf(line);\n  useAutosize(textareaRef, draft, MAX_FIELD_HEIGHT);\n\n  function fold() {\n    store.dispatch({ type: 'reset', snapshot: IDLE_RUN });\n  }\n\n  function startAnswer(steps: PlanStep[], shouldFail: boolean) {\n    clearAll();\n    store.dispatch({ type: 'reset', snapshot: IDLE_RUN });\n    store.dispatch({ type: 'plan.set', steps });\n    store.dispatch({ type: 'run.started' });\n    const timeline = timelineOf(steps, shouldFail);\n    for (const timed of timeline.events) {\n      schedule(() => store.dispatch(timed.event), timed.at);\n    }\n    if (shouldFail) {\n      return;\n    }\n    // A demonstration folds the tray itself when its next round starts, so the answered line holds through the loop.\n    if (isAutoplaying) {\n      return;\n    }\n    const foldAt = timeline.endsAt + ANSWERED_HOLD_MS;\n    schedule(fold, foldAt);\n  }\n\n  function endListening() {\n    clearAll();\n    setListeningSince(null);\n    setWordsLeft(0);\n  }\n\n  function startListening() {\n    clearAll();\n    draftBeforeListening.current = draft;\n    setListeningSince(Date.now());\n    const words = wordsOf(DICTATION);\n    setWordsLeft(words.length);\n    words.forEach((word, index) => {\n      const wordDelay = index * WORD_GAP_MS;\n      const delay = FIRST_WORD_MS + wordDelay;\n      schedule(() => {\n        setDraft((current) => appendWord(current, word));\n        setWordsLeft((current) => current - 1);\n      }, delay);\n    });\n  }\n\n  function stopListening() {\n    endListening();\n    caretToEnd(textareaRef);\n  }\n\n  function cancelListening() {\n    endListening();\n    setDraft(draftBeforeListening.current);\n    caretToEnd(textareaRef);\n  }\n\n  function send() {\n    if (!hasText) {\n      return;\n    }\n    if (isAnswering) {\n      return;\n    }\n    if (isListening) {\n      endListening();\n    }\n    const steps = planOf(files.length, tools);\n    const shouldFail = outcome === 'fails';\n    lastPrompt.current = { text: draft, steps };\n    setDraft('');\n    startAnswer(steps, shouldFail);\n  }\n\n  function stop() {\n    if (!isAnswering) {\n      return;\n    }\n    clearAll();\n    const step = runningStepOf(run);\n    if (step) {\n      store.dispatch({\n        type: 'step.updated',\n        id: step.id,\n        patch: { status: 'skipped' },\n      });\n    }\n    store.dispatch({ type: 'run.finished', status: 'cancelled' });\n    setDraft(lastPrompt.current?.text ?? '');\n    caretToEnd(textareaRef);\n    schedule(fold, STOPPED_HOLD_MS);\n  }\n\n  function retry() {\n    const sent = lastPrompt.current;\n    if (!sent) {\n      return;\n    }\n    startAnswer(sent.steps, false);\n  }\n\n  function pressKey(mode: TrayKeyMode) {\n    if (mode === 'mic') {\n      startListening();\n      return;\n    }\n    if (mode === 'stop-listening') {\n      stopListening();\n      return;\n    }\n    if (mode === 'stop') {\n      stop();\n      return;\n    }\n    send();\n  }\n\n  function handleFieldKeys(event: React.KeyboardEvent<HTMLTextAreaElement>) {\n    if (!isSendKey(event)) {\n      return;\n    }\n    event.preventDefault();\n    send();\n  }\n\n  function handleEscape(event: React.KeyboardEvent<HTMLDivElement>) {\n    if (event.key !== 'Escape') {\n      return;\n    }\n    if (!isOwnKey(event)) {\n      return;\n    }\n    if (isListening) {\n      event.preventDefault();\n      cancelListening();\n      return;\n    }\n    if (isAnswering) {\n      event.preventDefault();\n      stop();\n      return;\n    }\n    if (isFailed) {\n      event.preventDefault();\n      fold();\n    }\n  }\n\n  function addFiles(event: React.ChangeEvent<HTMLInputElement>) {\n    const list = event.target.files;\n    if (!list) {\n      return;\n    }\n    const added = Array.from(list, (file) => {\n      fileCounter.current += 1;\n      return { id: `file-${fileCounter.current}`, name: file.name };\n    });\n    setFiles((current) => [...current, ...added]);\n    event.target.value = '';\n  }\n\n  function removeFile(id: string) {\n    setFiles((current) => current.filter((file) => file.id !== id));\n  }\n\n  function toggleTool(id: ToolId, isOn: boolean) {\n    setTools((current) => withTool(current, id, isOn));\n  }\n\n  function resetDemo() {\n    clearAll();\n    store.dispatch({ type: 'reset', snapshot: ANSWERED_RUN });\n    setDraft('');\n    setOutcome('answers');\n    setRound((current) => current + 1);\n  }\n\n  const demoPrompt = DEMO_PROMPTS[round % DEMO_PROMPTS.length];\n  const demoPlan = planOf(files.length, tools);\n  const answerMs = timelineOf(demoPlan, false).endsAt;\n  const failureMs = timelineOf(demoPlan, true).endsAt;\n  const isFailingRound = round % FAILING_ROUND === FAILING_ROUND - 1;\n  const typing = typingSteps(demoPrompt, setDraft, {\n    startAfter: 800,\n    characterMs: 34,\n  });\n  const passing: AutoplayStep[] = [\n    { after: 560, run: () => press('key') },\n    { after: PRESS_LEAD_MS, run: () => pressKey('send') },\n    { after: answerMs + 400, run: hold },\n  ];\n  const failing: AutoplayStep[] = [\n    { after: 450, run: () => setOutcome('fails') },\n    { after: 600, run: () => press('key') },\n    { after: PRESS_LEAD_MS, run: () => pressKey('send') },\n    { after: failureMs + 1100, run: () => setOutcome('answers') },\n    { after: 700, run: () => press('retry') },\n    { after: PRESS_LEAD_MS, run: retry },\n    { after: answerMs + 400, run: hold },\n  ];\n  let ending = passing;\n  if (isFailingRound) {\n    ending = failing;\n  }\n  const steps = [{ after: 1600, run: fold }, ...typing, ...ending];\n  const { ref, isInView, isAutoplaying } = useAutoplay(steps, {\n    loopAfter: 2200,\n    onReset: resetDemo,\n  });\n\n  useKeptHeight(ref);\n\n  return (\n    <div\n      ref={ref}\n      onKeyDown={handleEscape}\n      className='flex w-full max-w-[26rem] flex-col gap-3'\n    >\n      <ClockGate isActive={isInView}>\n        <StatusTray\n          run={run}\n          listeningSince={listeningSince}\n          listeningIntensity={listeningIntensity}\n          onRetry={retry}\n          isRetryPressed={pressed === 'retry'}\n          isDemonstrated={isAutoplaying}\n        >\n          <div className='bg-card hairline-ring ring-foreground/12 dark:ring-foreground/15 has-[textarea:focus]:ring-ring/25 flex flex-col gap-1 rounded-[calc(var(--radius-2xl)-0.25rem)] p-1.5 shadow-[0_1px_2px_rgb(0_0_0/0.04)] transition-shadow duration-150 has-[textarea:focus]:ring-[3px]'>\n            <FileChips files={files} onRemove={removeFile} />\n            <Textarea\n              ref={textareaRef}\n              rows={1}\n              value={draft}\n              onChange={(event) => setDraft(event.target.value)}\n              onKeyDown={handleFieldKeys}\n              readOnly={isListening}\n              aria-label='Prompt'\n              placeholder='Ask about this project'\n              className='max-h-none min-h-10 border-0 bg-transparent px-2 py-1.5 shadow-none ring-0 focus-visible:ring-0 dark:bg-transparent'\n            />\n            <div className='flex items-center gap-1.5 px-0.5 pb-0.5'>\n              <input\n                ref={fileInputRef}\n                type='file'\n                multiple\n                tabIndex={-1}\n                aria-hidden='true'\n                className='hidden'\n                onChange={addFiles}\n              />\n              <Tooltip>\n                <TooltipTrigger\n                  render={\n                    <Button\n                      type='button'\n                      variant='outline'\n                      size='icon'\n                      aria-label='Attach files'\n                      disabled={isAnswering}\n                      onClick={() => fileInputRef.current?.click()}\n                    />\n                  }\n                >\n                  <PaperclipIcon />\n                </TooltipTrigger>\n                <TooltipContent>Attach files</TooltipContent>\n              </Tooltip>\n              <ToolsMenu\n                tools={tools}\n                onToggle={toggleTool}\n                disabled={isAnswering}\n              />\n              <span className='flex-1' />\n              <TrayKey\n                mode={keyMode}\n                onPress={pressKey}\n                isPressed={pressed === 'key'}\n              />\n            </div>\n          </div>\n        </StatusTray>\n        <div className='flex items-center justify-between gap-3 px-1'>\n          <p className='text-muted-foreground text-xs'>Next answer</p>\n          <Segments\n            value={outcome}\n            segments={OUTCOMES}\n            onValueChange={setOutcome}\n            label='Next answer'\n            className='w-36'\n          />\n        </div>\n      </ClockGate>\n      <LiveRegion message={spokenUnless(isAutoplaying, announcement)} />\n    </div>\n  );\n}\n\nfunction levelIntensityOf(isSpeaking: boolean) {\n  if (isSpeaking) {\n    return 1;\n  }\n  return QUIET_INTENSITY;\n}\n",
      "type": "registry:component",
      "target": "components/prompt/prompt-01.tsx"
    },
    {
      "path": "registry/ndeko/components/prompt/_parts/clock.tsx",
      "content": "'use client';\n\nimport { useNow } from '@/registry/ndeko/hooks/use-agent-run';\nimport { formatClock } from '@/registry/ndeko/lib/media-clock';\nimport { cn } from '@/registry/ndeko/lib/utils';\n\ntype ClockSinceProps = {\n  startedAt: number;\n  isRunning: boolean;\n  className?: string;\n};\n\n/** A minutes and seconds clock; only this text re-renders while it runs. */\nexport function ClockSince({\n  startedAt,\n  isRunning,\n  className,\n}: ClockSinceProps) {\n  const now = useNow(250, isRunning);\n  const elapsed = now - startedAt;\n  const text = formatClock(elapsed);\n\n  return <span className={cn('tabular-nums', className)}>{text}</span>;\n}\n",
      "type": "registry:component",
      "target": "components/prompt/_parts/clock.tsx"
    },
    {
      "path": "registry/ndeko/components/prompt/_parts/use-autosize.ts",
      "content": "'use client';\n\nimport { useLayoutEffect } from 'react';\n\nfunction fitHeight(textarea: HTMLTextAreaElement, maxHeight: number) {\n  textarea.style.height = 'auto';\n  const height = Math.min(textarea.scrollHeight, maxHeight);\n  textarea.style.height = `${height}px`;\n}\n\n/** Also fits again when the width changes, and when `remountKey` changes for a textarea shown again. */\nexport function useAutosize(\n  ref: React.RefObject<HTMLTextAreaElement | null>,\n  value: string,\n  maxHeight: number,\n  remountKey?: unknown\n) {\n  useLayoutEffect(() => {\n    const textarea = ref.current;\n    if (!textarea) {\n      return;\n    }\n    fitHeight(textarea, maxHeight);\n    let lastWidth = textarea.offsetWidth;\n    const observer = new ResizeObserver(() => {\n      const width = textarea.offsetWidth;\n      if (width === lastWidth) {\n        return;\n      }\n      lastWidth = width;\n      fitHeight(textarea, maxHeight);\n    });\n    observer.observe(textarea);\n    return () => observer.disconnect();\n  }, [ref, value, maxHeight, remountKey]);\n}\n\nexport function isSendKey(event: React.KeyboardEvent<HTMLTextAreaElement>) {\n  const isEnter = event.key === 'Enter';\n  const isNewLine = event.shiftKey;\n  const isComposing = event.nativeEvent.isComposing;\n  const isPlainEnter = isEnter && !isNewLine;\n  return isPlainEnter && !isComposing;\n}\n\n/** Puts the caret after the last character once React has committed the new text. */\nexport function caretToEnd(ref: React.RefObject<HTMLTextAreaElement | null>) {\n  requestAnimationFrame(() => {\n    const textarea = ref.current;\n    if (!textarea) {\n      return;\n    }\n    const end = textarea.value.length;\n    textarea.focus();\n    textarea.setSelectionRange(end, end);\n  });\n}\n\n/** Keydown that started inside this element, not in a menu or popover portalled out of it. */\nexport function isOwnKey(event: React.KeyboardEvent<HTMLElement>) {\n  const target = event.target;\n  if (!(target instanceof Node)) {\n    return false;\n  }\n  return event.currentTarget.contains(target);\n}\n",
      "type": "registry:component",
      "target": "components/prompt/_parts/use-autosize.ts"
    }
  ],
  "categories": [
    "components",
    "prompt"
  ],
  "type": "registry:component"
}