{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "application-08",
  "title": "Chat with run details",
  "description": "A Quenby chat with run details: chats grouped by day with a search, a sidebar that collapses and goes into a sheet on phones, a thread where the assistant thinks, asks before it reads a shared file and cites numbered sources that light up, a model picker, Send that becomes Stop, and a details panel from the header whose plan, calls, tokens and cost move as the run goes. Plug your assistant into onSend, onApprove, onDeny and onStop.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/agent-run.json",
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/avatar.json",
    "https://ui.ndekocode.dev/r/badge.json",
    "https://ui.ndekocode.dev/r/brand-logos.json",
    "https://ui.ndekocode.dev/r/brand-tile.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/call-status.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/company-mark.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/drawn-check.json",
    "https://ui.ndekocode.dev/r/dropdown-menu.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/inline-sheet.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/kbd.json",
    "https://ui.ndekocode.dev/r/live-duration.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/mesh-tile.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/progress.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/run-session.json",
    "https://ui.ndekocode.dev/r/spinner.json",
    "https://ui.ndekocode.dev/r/streamed-text.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-follow-bottom.json",
    "https://ui.ndekocode.dev/r/use-is-narrow.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/use-session.json",
    "https://ui.ndekocode.dev/r/utils.json",
    "https://ui.ndekocode.dev/r/wash.json",
    "https://ui.ndekocode.dev/r/words.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/templates/chat/application-08/index.tsx",
      "content": "'use client';\n\nimport type { CSSProperties } from 'react';\n\nimport { useIsNarrow } from '@/registry/ndeko/hooks/use-is-narrow';\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { spokenUnless } from '@/registry/ndeko/lib/demonstration';\nimport { countOf } from '@/registry/ndeko/lib/words';\nimport { InlineSheet } from '@/registry/ndeko/ui/inline-sheet';\nimport { ClockGate } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\n\nimport { AppSidebar, rowsOf } from './app-sidebar';\nimport { ChatHeader } from './chat-header';\nimport { Composer } from './composer';\nimport {\n  BRAND,\n  chatOf,\n  DECLINED_LINE,\n  LIVE_ID,\n  LIVE_TITLE,\n  NEW_CHAT_TITLE,\n  NEW_ID,\n  SOURCES,\n  STOPPED_LINE,\n} from './data';\nimport { RunDetails } from './run-details';\nimport {\n  INITIAL,\n  isBusy,\n  isOver,\n  isReadOnly,\n  LOOP_AFTER_MS,\n  reducer,\n  RESTING,\n  SCRIPT,\n  sendableTextOf,\n  type ChatState,\n  type Decision,\n} from './session';\nimport { Thread } from './thread';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\n/** The width of the `@3xl` container variant: under it the chats live in a sheet. */\nconst SIDEBAR_SHEET_BELOW_REM = 48;\n\n/** The width of the `@6xl` container variant: under it the run details live in a sheet. */\nconst DETAILS_SHEET_BELOW_REM = 72;\n\nconst SIDEBAR_WIDTH = '16rem';\n\nconst PANEL_WIDTH = '21rem';\n\ntype LayoutStyle = CSSProperties & {\n  '--sidebar-w': string;\n  '--panel-w': string;\n};\n\nfunction widthOf(isShown: boolean, width: string) {\n  if (isShown) {\n    return width;\n  }\n  return '0rem';\n}\n\nfunction layoutStyleOf(isSidebarShown: boolean, isPanelShown: boolean) {\n  const style: LayoutStyle = {\n    '--sidebar-w': widthOf(isSidebarShown, SIDEBAR_WIDTH),\n    '--panel-w': widthOf(isPanelShown, PANEL_WIDTH),\n  };\n  return style;\n}\n\nfunction titleOf(state: ChatState) {\n  if (state.activeId === LIVE_ID) {\n    if (state.question === null) {\n      return NEW_CHAT_TITLE;\n    }\n    return LIVE_TITLE;\n  }\n  if (state.activeId === NEW_ID) {\n    return NEW_CHAT_TITLE;\n  }\n  return chatOf(state.activeId).title;\n}\n\nfunction placeholderOf(state: ChatState) {\n  if (isReadOnly(state)) {\n    return 'Start a new chat to write';\n  }\n  if (state.activeId === NEW_ID) {\n    return 'Message Quenby';\n  }\n  const { stage } = state;\n  if (stage === 'idle') {\n    return 'Ask about a shipment';\n  }\n  if (stage === 'asking') {\n    return 'Allow or deny the request above';\n  }\n  if (isOver(stage)) {\n    return 'Ask a follow-up';\n  }\n  return 'Quenby is working';\n}\n\nfunction announcementOf(state: ChatState) {\n  const { stage } = state;\n  if (stage === 'thinking') {\n    return 'Quenby is thinking';\n  }\n  if (stage === 'asking') {\n    return 'Quenby asks to read the forwarder rate sheet. Allow or deny it';\n  }\n  if (stage === 'answering') {\n    return 'Quenby is writing the answer';\n  }\n  if (stage === 'done') {\n    return `The answer is ready, with ${countOf(SOURCES.length, 'source')}`;\n  }\n  if (stage === 'declined') {\n    return DECLINED_LINE;\n  }\n  if (stage === 'stopped') {\n    return STOPPED_LINE;\n  }\n  return '';\n}\n\nfunction emptyLineOf(state: ChatState) {\n  if (state.activeId === LIVE_ID) {\n    return 'The plan, the tool calls and the cost of the run show here once you ask a question.';\n  }\n  return 'Nothing runs in this chat. The details of a run show here when the assistant works.';\n}\n\n/** Nothing calls a network. A real assistant plugs in here: what a person sends, the answer to the request, and Stop. */\nexport type Application08Props = {\n  onSend?: (text: string) => void;\n  onApprove?: () => void;\n  onDeny?: () => void;\n  onStop?: () => void;\n};\n\nexport default function Application08({\n  onSend,\n  onApprove,\n  onDeny,\n  onStop,\n}: Application08Props) {\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    pressed,\n    isFinished,\n    restart,\n  } = useSession(SESSION);\n  const hasSidebarSheet = useIsNarrow(ref, SIDEBAR_SHEET_BELOW_REM);\n  const hasDetailsSheet = useIsNarrow(ref, DETAILS_SHEET_BELOW_REM);\n  const { stage } = state;\n  const isLiveChat = state.activeId === LIVE_ID;\n  const hasRun = isLiveChat && state.question !== null;\n  const sendableText = sendableTextOf(state);\n  const canSend = sendableText !== null;\n  const showsStop = isLiveChat && isBusy(stage);\n  const canReplay = isFinished && !isAutoplaying;\n  const isSidebarSheetShown = hasSidebarSheet && state.isSidebarSheetOpen;\n  const isDetailsSheetShown = hasDetailsSheet && state.isDetailsSheetOpen;\n  const isBehindSheet = isSidebarSheetShown || isDetailsSheetShown;\n  const isSidebarShown = !state.isSidebarCollapsed;\n  const isPanelShown = state.isPanelOpen && !hasDetailsSheet;\n  const message = spokenUnless(isAutoplaying, announcementOf(state));\n  const layoutStyle = layoutStyleOf(isSidebarShown, isPanelShown);\n  const canShowDetails = hasDetailsSheet || !isPanelShown;\n\n  function focusLater(selector: string) {\n    requestAnimationFrame(() => {\n      const target = ref.current?.querySelector<HTMLElement>(selector);\n      target?.focus();\n    });\n  }\n\n  function send() {\n    if (sendableText === null) {\n      return;\n    }\n    act({ type: 'sent' });\n    onSend?.(sendableText);\n  }\n\n  function stop() {\n    act({ type: 'stopped' });\n    onStop?.();\n  }\n\n  /** The two buttons leave with the request, so the focus goes to what replaces them: the line that says what was decided. */\n  function decide(decision: Decision) {\n    act({ type: 'decided', decision });\n    focusLater('[data-request]');\n    if (decision === 'denied') {\n      onDeny?.();\n      return;\n    }\n    onApprove?.();\n  }\n\n  function toggleSidebar() {\n    if (hasSidebarSheet) {\n      act({ type: 'sidebarSheet', isOpen: true });\n      focusLater('[data-sheet-close=\"chats\"]');\n      return;\n    }\n    act({ type: 'sidebarCollapsed', isCollapsed: !state.isSidebarCollapsed });\n  }\n\n  function closeSidebarSheet() {\n    act({ type: 'sidebarSheet', isOpen: false });\n    focusLater('[data-sidebar-toggle]');\n  }\n\n  function openDetailsSheet() {\n    act({ type: 'detailsSheet', isOpen: true });\n    focusLater('[data-sheet-close=\"details\"]');\n  }\n\n  function closeDetailsSheet() {\n    act({ type: 'detailsSheet', isOpen: false });\n    focusLater('[data-details-toggle]');\n  }\n\n  function toggleDetails() {\n    if (hasDetailsSheet) {\n      openDetailsSheet();\n      return;\n    }\n    act({ type: 'panel', isOpen: !state.isPanelOpen });\n  }\n\n  function showDetails() {\n    if (hasDetailsSheet) {\n      openDetailsSheet();\n      return;\n    }\n    act({ type: 'panel', isOpen: true });\n  }\n\n  function openChat(id: string) {\n    act({ type: 'chatOpened', id });\n    focusLater('[data-composer-field]');\n  }\n\n  function startNewChat() {\n    act({ type: 'newChat' });\n    focusLater('[data-composer-field]');\n  }\n\n  function suggest(text: string) {\n    act({ type: 'typed', text });\n    focusLater('[data-composer-field]');\n  }\n\n  const sidebar = {\n    rows: rowsOf(state),\n    activeId: state.activeId,\n    search: state.search,\n    onSearch: (text: string) => act({ type: 'searched', text }),\n    onOpen: openChat,\n    onNewChat: startNewChat,\n  };\n\n  const details = {\n    stage,\n    plan: state.plan,\n    calls: state.calls,\n    tokens: state.tokens,\n    costUsd: state.costUsd,\n    runModel: state.runModel,\n    hasRun,\n    emptyLine: emptyLineOf(state),\n  };\n\n  return (\n    <ClockGate isActive={isInView}>\n      <div\n        ref={ref}\n        className='bg-sidebar text-foreground @container min-h-dvh w-full'\n      >\n        <div className='relative flex h-dvh min-h-[40rem] overflow-hidden'>\n          <div\n            inert={isBehindSheet}\n            style={layoutStyle}\n            className='grid min-h-0 min-w-0 flex-1 grid-cols-1 transition-[grid-template-columns] duration-300 ease-(--ease-drawer) @3xl:grid-cols-[var(--sidebar-w)_minmax(0,1fr)] @3xl:p-2 @6xl:grid-cols-[var(--sidebar-w)_minmax(0,1fr)_var(--panel-w)]'\n          >\n            <aside\n              aria-label='Chats'\n              inert={state.isSidebarCollapsed}\n              className='hidden min-h-0 min-w-0 overflow-hidden @3xl:block'\n            >\n              <div className='h-full w-64 pe-2'>\n                {!hasSidebarSheet && <AppSidebar {...sidebar} />}\n              </div>\n            </aside>\n            <main className='bg-background @3xl:hairline-ring @3xl:ring-border flex min-h-0 min-w-0 flex-col overflow-clip @3xl:rounded-xl @3xl:shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n              <ChatHeader\n                title={titleOf(state)}\n                stage={stage}\n                model={state.model}\n                hasSidebarSheet={hasSidebarSheet}\n                hasDetailsSheet={hasDetailsSheet}\n                isSidebarShown={isSidebarShown}\n                isDetailsShown={isPanelShown}\n                canReplay={canReplay}\n                onToggleSidebar={toggleSidebar}\n                onToggleDetails={toggleDetails}\n                onModelChange={(model) => act({ type: 'modelSet', model })}\n                onReplay={restart}\n              />\n              <Thread\n                state={state}\n                pressed={pressed}\n                isActive={isInView}\n                onDecide={decide}\n                canShowDetails={canShowDetails}\n                onShowDetails={showDetails}\n                onSuggest={suggest}\n              />\n              <div className='mx-auto w-full max-w-2xl shrink-0 px-4 pb-4'>\n                <Composer\n                  draft={state.draft}\n                  placeholder={placeholderOf(state)}\n                  canSend={canSend}\n                  isRunning={showsStop}\n                  isReadOnly={isReadOnly(state)}\n                  isSendPressed={pressed === 'send'}\n                  onDraftChange={(text) => act({ type: 'typed', text })}\n                  onSend={send}\n                  onStop={stop}\n                />\n              </div>\n            </main>\n            <aside\n              aria-label='Run details'\n              inert={!state.isPanelOpen}\n              className='hidden min-h-0 min-w-0 overflow-hidden @6xl:block'\n            >\n              <div className='h-full w-[21rem] ps-2'>\n                <div className='bg-card hairline-ring ring-border dark:bg-foreground/[0.03] flex h-full min-h-0 rounded-xl p-4 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n                  {!hasDetailsSheet && (\n                    <RunDetails {...details} className='w-full' />\n                  )}\n                </div>\n              </div>\n            </aside>\n          </div>\n\n          <InlineSheet\n            name='chats'\n            label={`${BRAND.name} chats`}\n            closeLabel='Close the chats'\n            side='start'\n            isOpen={isSidebarSheetShown}\n            className='@3xl:hidden'\n            panelClassName='bg-sidebar gap-1 p-3'\n            onClose={closeSidebarSheet}\n          >\n            {hasSidebarSheet && <AppSidebar {...sidebar} />}\n          </InlineSheet>\n          <InlineSheet\n            name='details'\n            label='Run details'\n            closeLabel='Close the run details'\n            side='bottom'\n            closer='grip'\n            isOpen={isDetailsSheetShown}\n            className='@6xl:hidden'\n            panelClassName='h-[80%] px-4 pb-4'\n            onClose={closeDetailsSheet}\n          >\n            {hasDetailsSheet && <RunDetails {...details} className='flex-1' />}\n          </InlineSheet>\n          <LiveRegion message={message} />\n        </div>\n      </div>\n    </ClockGate>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-08/index.tsx"
    },
    {
      "path": "registry/ndeko/templates/chat/application-08/app-sidebar.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { PlusIcon, SearchIcon, XIcon } from '@/registry/ndeko/lib/icons';\nimport { rowPresenceOf } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { wordsOf } from '@/registry/ndeko/lib/words';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { CompanyMark } from '@/registry/ndeko/ui/company-mark';\nimport { Input } from '@/registry/ndeko/ui/input';\n\nimport {\n  BRAND,\n  CHATS,\n  DAYS,\n  LIVE_ID,\n  LIVE_TITLE,\n  NEW_ID,\n  type Day,\n} from './data';\nimport { isBusy, type ChatState } from './session';\n\nconst TITLE_WORDS = 5;\n\nexport type RowStatus = 'running' | 'waiting';\n\nexport type SidebarRow = {\n  id: string;\n  title: string;\n  day: Day;\n  status?: RowStatus;\n};\n\nfunction shortTitleOf(text: string) {\n  const words = wordsOf(text);\n  const kept = words.slice(0, TITLE_WORDS);\n  return kept.join(' ');\n}\n\nfunction liveStatusOf(state: ChatState): RowStatus | undefined {\n  if (state.stage === 'asking') {\n    return 'waiting';\n  }\n  if (isBusy(state.stage)) {\n    return 'running';\n  }\n  return undefined;\n}\n\n/** The chat the person is in sits first of its day: the new chat, then the one that holds the run, then the older ones. */\nexport function rowsOf(state: ChatState): SidebarRow[] {\n  const rows: SidebarRow[] = [];\n  if (state.newLines.length > 0) {\n    const title = shortTitleOf(state.newLines[0]);\n    rows.push({ id: NEW_ID, title, day: 'Today' });\n  }\n  if (state.question !== null) {\n    const status = liveStatusOf(state);\n    rows.push({ id: LIVE_ID, title: LIVE_TITLE, day: 'Today', status });\n  }\n  for (const chat of CHATS) {\n    rows.push({ id: chat.id, title: chat.title, day: chat.day });\n  }\n  return rows;\n}\n\nfunction needleOf(query: string) {\n  const trimmed = query.trim();\n  return trimmed.toLowerCase();\n}\n\nfunction matchesQuery(title: string, query: string) {\n  const needle = needleOf(query);\n  if (needle === '') {\n    return true;\n  }\n  const lowered = title.toLowerCase();\n  return lowered.includes(needle);\n}\n\nfunction HighlightedTitle({ title, query }: { title: string; query: string }) {\n  const needle = needleOf(query);\n  const lowered = title.toLowerCase();\n  const index = lowered.indexOf(needle);\n  const hasMatch = needle !== '' && index >= 0;\n  if (!hasMatch) {\n    return <>{title}</>;\n  }\n  const end = index + needle.length;\n\n  return (\n    <>\n      {title.slice(0, index)}\n      <mark className='bg-primary/15 rounded-[3px] text-inherit'>\n        {title.slice(index, end)}\n      </mark>\n      {title.slice(end)}\n    </>\n  );\n}\n\nconst ROW =\n  'hover:bg-foreground/5 focus-visible:ring-ring/25 flex h-8 w-full min-w-0 cursor-pointer items-center gap-2 rounded-md px-2 text-start text-[13px] outline-none transition-colors duration-150 focus-visible:ring-[3px] focus-visible:ring-inset';\n\nfunction rowToneOf(isActive: boolean) {\n  if (isActive) {\n    return 'bg-foreground/[0.07] font-medium';\n  }\n  return undefined;\n}\n\nfunction currentOf(isActive: boolean): 'page' | undefined {\n  if (isActive) {\n    return 'page';\n  }\n  return undefined;\n}\n\nconst STATUS_DOT: Record<RowStatus, string> = {\n  running: 'bg-info',\n  waiting: 'bg-warning',\n};\n\nconst STATUS_WORD: Record<RowStatus, string> = {\n  running: 'Running',\n  waiting: 'Waiting on you',\n};\n\ntype ChatRowProps = {\n  row: SidebarRow;\n  query: string;\n  isActive: boolean;\n  onOpen: (id: string) => void;\n};\n\nfunction ChatRow({ row, query, isActive, onOpen }: ChatRowProps) {\n  function open() {\n    onOpen(row.id);\n  }\n\n  return (\n    <button\n      type='button'\n      aria-current={currentOf(isActive)}\n      onClick={open}\n      className={cn(ROW, rowToneOf(isActive))}\n    >\n      <span className='min-w-0 flex-1 truncate'>\n        <HighlightedTitle title={row.title} query={query} />\n      </span>\n      {row.status && (\n        <span className='flex shrink-0 items-center'>\n          <span\n            aria-hidden='true'\n            className={cn('size-1.5 rounded-full', STATUS_DOT[row.status])}\n          />\n          <span className='sr-only'>{STATUS_WORD[row.status]}</span>\n        </span>\n      )}\n    </button>\n  );\n}\n\ntype SearchFieldProps = {\n  value: string;\n  onChange: (text: string) => void;\n};\n\nfunction SearchField({ value, onChange }: SearchFieldProps) {\n  const hasQuery = value !== '';\n\n  function clear() {\n    onChange('');\n  }\n\n  /** The first Escape empties the field. A second one is left to the sheet, which closes. */\n  function clearFromKeys(event: React.KeyboardEvent<HTMLInputElement>) {\n    if (event.key !== 'Escape' || !hasQuery) {\n      return;\n    }\n    event.stopPropagation();\n    clear();\n  }\n\n  return (\n    <div className='relative'>\n      <SearchIcon\n        aria-hidden='true'\n        className='text-muted-foreground pointer-events-none absolute start-2.5 top-1/2 size-3.5 -translate-y-1/2'\n      />\n      <Input\n        type='search'\n        size='sm'\n        aria-label='Search chats'\n        placeholder='Search chats'\n        value={value}\n        onChange={(event) => onChange(event.target.value)}\n        onKeyDown={clearFromKeys}\n        className='ps-8 pe-7'\n      />\n      {hasQuery && (\n        <button\n          type='button'\n          aria-label='Clear the search'\n          onClick={clear}\n          className='text-muted-foreground hover:bg-foreground/[0.07] hover:text-foreground focus-visible:ring-ring/25 absolute end-1.5 top-1/2 flex size-5 -translate-y-1/2 cursor-pointer items-center justify-center rounded-md outline-none focus-visible:ring-[3px]'\n        >\n          <XIcon className='size-3' />\n        </button>\n      )}\n    </div>\n  );\n}\n\ntype AppSidebarProps = {\n  rows: SidebarRow[];\n  activeId: string;\n  search: string;\n  onSearch: (text: string) => void;\n  onOpen: (id: string) => void;\n  onNewChat: () => void;\n  className?: string;\n};\n\nexport function AppSidebar({\n  rows,\n  activeId,\n  search,\n  onSearch,\n  onOpen,\n  onNewChat,\n  className,\n}: AppSidebarProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n  const shown = rows.filter((row) => matchesQuery(row.title, search));\n  const hasNoMatch = shown.length === 0;\n\n  function clearSearch() {\n    onSearch('');\n  }\n\n  return (\n    <div className={cn('flex min-h-0 w-full flex-col gap-3', className)}>\n      <div className='flex flex-col gap-2'>\n        <div className='flex h-9 items-center gap-2 px-1.5'>\n          <CompanyMark seed={BRAND.name} className='size-6 rounded-md' />\n          <span className='text-[13px] font-semibold'>{BRAND.name}</span>\n        </div>\n        <Button\n          type='button'\n          variant='outline'\n          data-new-chat\n          onClick={onNewChat}\n          className='w-full justify-start'\n        >\n          <PlusIcon />\n          New chat\n        </Button>\n        <SearchField value={search} onChange={onSearch} />\n      </div>\n      <nav\n        aria-label='Chats'\n        className='-mx-1 flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-1'\n      >\n        {DAYS.map((day) => {\n          const ofDay = shown.filter((row) => row.day === day);\n          if (ofDay.length === 0) {\n            return null;\n          }\n          return (\n            <section key={day} className='flex flex-col gap-0.5'>\n              <h2 className='text-muted-foreground flex h-6 items-center px-2 text-xs font-medium'>\n                {day}\n              </h2>\n              <ul className='flex flex-col'>\n                <AnimatePresence initial={false}>\n                  {ofDay.map((row) => (\n                    <motion.li\n                      key={row.id}\n                      className='-mx-1 overflow-hidden px-1'\n                      {...rowPresence}\n                    >\n                      <ChatRow\n                        row={row}\n                        query={search}\n                        isActive={row.id === activeId}\n                        onOpen={onOpen}\n                      />\n                    </motion.li>\n                  ))}\n                </AnimatePresence>\n              </ul>\n            </section>\n          );\n        })}\n        {hasNoMatch && (\n          <div className='flex flex-col items-start gap-1.5 px-2 text-xs'>\n            <p className='text-muted-foreground'>\n              No chat matches &quot;{search.trim()}&quot;\n            </p>\n            <Button\n              type='button'\n              variant='link'\n              size='sm'\n              onClick={clearSearch}\n              className='h-6 px-0'\n            >\n              Clear the search\n            </Button>\n          </div>\n        )}\n      </nav>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-08/app-sidebar.tsx"
    },
    {
      "path": "registry/ndeko/templates/chat/application-08/approval-card.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useId } from 'react';\n\nimport { pressedSolidOf } from '@/registry/ndeko/lib/demonstration';\nimport { CircleXIcon } from '@/registry/ndeko/lib/icons';\nimport { fadePresence } from '@/registry/ndeko/lib/motion-presets';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { BrandTile } from '@/registry/ndeko/ui/brand-tile';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { DrawnCheck } from '@/registry/ndeko/ui/drawn-check';\nimport { Kbd } from '@/registry/ndeko/ui/kbd';\nimport { Spinner } from '@/registry/ndeko/ui/spinner';\nimport { Wash } from '@/registry/ndeko/ui/wash';\n\nimport { DECLINED_LINE, FORWARDER_CONTACT, REQUEST } from './data';\nimport type { Decision, RequestView } from './session';\n\ntype RequestBodyProps = {\n  pressed: string | null;\n  onDecide: (decision: Decision) => void;\n};\n\nfunction RequestBody({ pressed, onDecide }: RequestBodyProps) {\n  const titleId = useId();\n  const keysId = useId();\n\n  function allow() {\n    onDecide('approved');\n  }\n\n  function deny() {\n    onDecide('denied');\n  }\n\n  function decideFromKeys(event: React.KeyboardEvent<HTMLDivElement>) {\n    if (event.key === 'Escape') {\n      event.preventDefault();\n      deny();\n      return;\n    }\n    const isOnCard = event.target === event.currentTarget;\n    const isEnter = event.key === 'Enter';\n    if (isEnter && isOnCard) {\n      event.preventDefault();\n      allow();\n    }\n  }\n\n  return (\n    <div\n      role='group'\n      tabIndex={0}\n      aria-labelledby={titleId}\n      aria-describedby={keysId}\n      onKeyDown={decideFromKeys}\n      className='focus-visible:ring-ring/25 relative isolate flex flex-col gap-3 rounded-xl p-3 outline-none focus-visible:ring-[3px] focus-visible:ring-inset'\n    >\n      <Wash color='var(--warning)' />\n      <div className='flex items-center gap-2.5'>\n        <BrandTile brand='googledrive' size='lg' title='Google Drive' />\n        <div className='flex min-w-0 flex-1 flex-col leading-tight'>\n          <h2 id={titleId} className='text-sm font-medium'>\n            Read a file shared with you\n          </h2>\n          <span className='text-muted-foreground truncate text-xs'>\n            {REQUEST.file}\n          </span>\n        </div>\n        <Badge variant='warning' className='hidden @md:inline-flex'>\n          Waiting on you\n        </Badge>\n      </div>\n      <dl className='bg-foreground/[0.04] flex flex-col gap-2 rounded-lg p-2.5 text-xs'>\n        <div className='flex items-center gap-2'>\n          <dt className='text-muted-foreground w-14 shrink-0'>Owner</dt>\n          <dd className='flex min-w-0 items-center gap-1.5'>\n            <Avatar seed={FORWARDER_CONTACT.name} className='size-5' />\n            <span className='min-w-0 truncate'>\n              {FORWARDER_CONTACT.name}\n              <span className='text-muted-foreground'>\n                , {FORWARDER_CONTACT.role}\n              </span>\n            </span>\n          </dd>\n        </div>\n        <div className='flex gap-2'>\n          <dt className='text-muted-foreground w-14 shrink-0'>Access</dt>\n          <dd className='min-w-0'>{REQUEST.access}</dd>\n        </div>\n        <div className='flex gap-2'>\n          <dt className='text-muted-foreground w-14 shrink-0'>Why</dt>\n          <dd className='min-w-0'>{REQUEST.reason}</dd>\n        </div>\n      </dl>\n      <div className='flex flex-wrap items-center gap-2'>\n        <Button\n          type='button'\n          size='sm'\n          onClick={allow}\n          className={pressedSolidOf(pressed === 'allow')}\n        >\n          Allow\n          <Kbd className='ms-0.5'>Enter</Kbd>\n        </Button>\n        <Button type='button' size='sm' variant='outline' onClick={deny}>\n          Deny\n          <Kbd className='ms-0.5'>Esc</Kbd>\n        </Button>\n        <span id={keysId} className='sr-only'>\n          Enter allows, Escape denies\n        </span>\n      </div>\n    </div>\n  );\n}\n\nfunction ResultGlyph({ view }: { view: RequestView }) {\n  if (view === 'reading') {\n    return <Spinner aria-hidden='true' />;\n  }\n  if (view === 'read') {\n    return <DrawnCheck tone='success' entrance='draw' />;\n  }\n  return <CircleXIcon className='text-muted-foreground size-4 shrink-0' />;\n}\n\nfunction resultLineOf(view: RequestView) {\n  if (view === 'reading') {\n    return 'Reading the rate sheet';\n  }\n  if (view === 'read') {\n    return 'Allowed. The rate sheet was read, with two quotes in it';\n  }\n  if (view === 'denied') {\n    return DECLINED_LINE;\n  }\n  return 'Not answered. The run was stopped before the sheet was read';\n}\n\nfunction ResultLine({ view }: { view: RequestView }) {\n  return (\n    <div className='flex min-h-11 items-start gap-2.5 p-3 text-[13px] leading-5'>\n      <Swap swapKey={view} className='mt-px'>\n        <ResultGlyph view={view} />\n      </Swap>\n      <p\n        key={view}\n        className='min-w-0 transition-opacity duration-300 starting:opacity-0'\n      >\n        {resultLineOf(view)}\n      </p>\n    </div>\n  );\n}\n\nfunction viewKeyOf(isAsking: boolean) {\n  if (isAsking) {\n    return 'request';\n  }\n  return 'result';\n}\n\ntype ApprovalCardProps = RequestBodyProps & {\n  view: RequestView;\n};\n\nexport function ApprovalCard({ view, pressed, onDecide }: ApprovalCardProps) {\n  const fade = fadePresence();\n  const isAsking = view === 'asking';\n\n  return (\n    <section\n      data-request\n      tabIndex={-1}\n      aria-label='Request to read the rate sheet'\n      className='bg-card hairline-ring ring-border dark:bg-foreground/[0.04] overflow-hidden rounded-xl shadow-[0_1px_2px_rgb(0_0_0/0.04)] transition-opacity duration-300 outline-none starting:opacity-0'\n    >\n      <AnimatedSize>\n        <AnimatePresence initial={false} mode='popLayout'>\n          <motion.div key={viewKeyOf(isAsking)} {...fade}>\n            {isAsking && <RequestBody pressed={pressed} onDecide={onDecide} />}\n            {!isAsking && <ResultLine view={view} />}\n          </motion.div>\n        </AnimatePresence>\n      </AnimatedSize>\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-08/approval-card.tsx"
    },
    {
      "path": "registry/ndeko/templates/chat/application-08/chat-header.tsx",
      "content": "'use client';\n\nimport { ListChecksIcon, PanelLeftIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\n\nimport type { ModelId } from './data';\nimport { ModelPicker } from './model-picker';\nimport type { Stage } from './session';\n\nconst DOT_TONE: Partial<Record<Stage, string>> = {\n  thinking: 'bg-info animate-pulse',\n  working: 'bg-info animate-pulse',\n  answering: 'bg-info animate-pulse',\n  asking: 'bg-warning',\n};\n\nfunction dotToneOf(stage: Stage) {\n  return DOT_TONE[stage];\n}\n\nfunction sidebarLabelOf(hasSheet: boolean, isShown: boolean) {\n  if (hasSheet) {\n    return 'Open the chats';\n  }\n  if (isShown) {\n    return 'Hide the chats';\n  }\n  return 'Show the chats';\n}\n\nfunction expandedOf(hasSheet: boolean, isShown: boolean) {\n  if (hasSheet) {\n    return undefined;\n  }\n  return isShown;\n}\n\nfunction popupOf(hasSheet: boolean) {\n  if (hasSheet) {\n    return 'dialog';\n  }\n  return undefined;\n}\n\nfunction detailsPressedOf(hasSheet: boolean, isShown: boolean) {\n  if (hasSheet) {\n    return undefined;\n  }\n  return isShown;\n}\n\nfunction detailsToneOf(isShown: boolean) {\n  if (isShown) {\n    return 'bg-foreground/[0.07] text-foreground';\n  }\n  return 'text-muted-foreground';\n}\n\ntype ChatHeaderProps = {\n  title: string;\n  stage: Stage;\n  model: ModelId;\n  hasSidebarSheet: boolean;\n  hasDetailsSheet: boolean;\n  isSidebarShown: boolean;\n  isDetailsShown: boolean;\n  canReplay: boolean;\n  onToggleSidebar: () => void;\n  onToggleDetails: () => void;\n  onModelChange: (model: ModelId) => void;\n  onReplay: () => void;\n};\n\nexport function ChatHeader({\n  title,\n  stage,\n  model,\n  hasSidebarSheet,\n  hasDetailsSheet,\n  isSidebarShown,\n  isDetailsShown,\n  canReplay,\n  onToggleSidebar,\n  onToggleDetails,\n  onModelChange,\n  onReplay,\n}: ChatHeaderProps) {\n  const dotTone = dotToneOf(stage);\n  const hasDot = dotTone !== undefined;\n\n  return (\n    <header className='flex h-14 shrink-0 items-center gap-1.5 px-3 @xl:px-4'>\n      <Button\n        type='button'\n        variant='ghost'\n        size='icon-sm'\n        data-sidebar-toggle\n        aria-label={sidebarLabelOf(hasSidebarSheet, isSidebarShown)}\n        aria-expanded={expandedOf(hasSidebarSheet, isSidebarShown)}\n        aria-haspopup={popupOf(hasSidebarSheet)}\n        onClick={onToggleSidebar}\n        className='text-muted-foreground'\n      >\n        <PanelLeftIcon />\n      </Button>\n      <h1 className='min-w-0 flex-1 truncate ps-1 text-sm font-medium'>\n        {title}\n      </h1>\n      <ReplayButton isShown={canReplay} onReplay={onReplay} label='Replay' />\n      <ModelPicker value={model} onValueChange={onModelChange} />\n      <Button\n        type='button'\n        variant='ghost'\n        size='sm'\n        data-details-toggle\n        aria-pressed={detailsPressedOf(hasDetailsSheet, isDetailsShown)}\n        aria-haspopup={popupOf(hasDetailsSheet)}\n        onClick={onToggleDetails}\n        className={cn('gap-1.5 px-2', detailsToneOf(isDetailsShown))}\n      >\n        <ListChecksIcon />\n        <span className='sr-only @2xl:not-sr-only'>Run details</span>\n        {hasDot && (\n          <span\n            aria-hidden='true'\n            className={cn('size-1.5 shrink-0 rounded-full', dotTone)}\n          />\n        )}\n      </Button>\n    </header>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-08/chat-header.tsx"
    },
    {
      "path": "registry/ndeko/templates/chat/application-08/cited-answer.tsx",
      "content": "'use client';\n\nimport { Fragment, useState } from 'react';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { leadingSpaceOf } from '@/registry/ndeko/lib/words';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { BrandTile } from '@/registry/ndeko/ui/brand-tile';\nimport {\n  inkClassOf,\n  shownCountOf,\n  StreamCaret,\n  useRevealedCount,\n} from '@/registry/ndeko/ui/streamed-text';\n\nimport {\n  ANSWER_TOKENS,\n  SOURCES,\n  sourceOf,\n  type AnswerToken,\n  type Source,\n} from './data';\nimport { ANSWER_WORD_MS } from './session';\n\nfunction isCiteOf(token: AnswerToken, number: number) {\n  return token.kind === 'cite' && token.source === number;\n}\n\n/** A source shows under the answer once its first mark has streamed in. */\nfunction firstMarkOf(source: Source) {\n  return ANSWER_TOKENS.findIndex((token) => isCiteOf(token, source.number));\n}\n\nfunction litOverlayOf(isLit: boolean) {\n  if (isLit) {\n    return 'opacity-100';\n  }\n  return 'opacity-0';\n}\n\nfunction litTextOf(isLit: boolean) {\n  if (isLit) {\n    return 'text-primary-ink';\n  }\n  return 'text-muted-foreground';\n}\n\nfunction toggledPin(current: number | null, number: number) {\n  if (current === number) {\n    return null;\n  }\n  return number;\n}\n\ntype CitationMarkProps = {\n  source: Source;\n  isShown: boolean;\n  isStreaming: boolean;\n  isLit: boolean;\n  isPinned: boolean;\n  onHover: (number: number | null) => void;\n  onPin: (number: number) => void;\n};\n\nfunction CitationMark({\n  source,\n  isShown,\n  isStreaming,\n  isLit,\n  isPinned,\n  onHover,\n  onPin,\n}: CitationMarkProps) {\n  function light() {\n    onHover(source.number);\n  }\n\n  function dim() {\n    onHover(null);\n  }\n\n  function pin() {\n    onPin(source.number);\n  }\n\n  return (\n    <button\n      type='button'\n      aria-pressed={isPinned}\n      aria-label={`Source ${source.number}: ${source.title}, ${source.product}`}\n      onPointerEnter={light}\n      onPointerLeave={dim}\n      onFocus={light}\n      onBlur={dim}\n      onClick={pin}\n      className={cn(\n        'keycap-3d focus-visible:ring-ring/25 relative ms-1 inline-flex h-4 min-w-4 cursor-pointer items-center justify-center rounded-[4px] px-1 align-[0.12em] text-[10px] leading-none font-medium tabular-nums transition-colors duration-150 outline-none focus-visible:ring-[3px]',\n        litTextOf(isLit),\n        inkClassOf(isStreaming, isShown)\n      )}\n    >\n      <span\n        aria-hidden='true'\n        className={cn(\n          'bg-primary/15 pointer-events-none absolute inset-0 rounded-[inherit] transition-opacity duration-150',\n          litOverlayOf(isLit)\n        )}\n      />\n      <span className='relative'>{source.number}</span>\n    </button>\n  );\n}\n\ntype SourceRowProps = {\n  source: Source;\n  isShown: boolean;\n  isStreaming: boolean;\n  isLit: boolean;\n};\n\nfunction SourceRow({ source, isShown, isStreaming, isLit }: SourceRowProps) {\n  return (\n    <li\n      className={cn(\n        'bg-foreground/[0.04] relative flex min-w-0 items-center gap-2.5 overflow-hidden rounded-lg p-2',\n        inkClassOf(isStreaming, isShown)\n      )}\n    >\n      <span\n        aria-hidden='true'\n        className={cn(\n          'bg-primary/10 pointer-events-none absolute inset-0 transition-opacity duration-150',\n          litOverlayOf(isLit)\n        )}\n      />\n      <BrandTile\n        brand={source.brand}\n        size='lg'\n        title={source.product}\n        className='relative'\n      />\n      <span className='relative flex min-w-0 flex-1 flex-col leading-tight'>\n        <span\n          className={cn(\n            'truncate text-[13px] font-medium transition-colors duration-150',\n            litTextOf(isLit)\n          )}\n        >\n          {source.title}\n        </span>\n        <span className='text-muted-foreground truncate text-xs'>\n          {source.excerpt}\n        </span>\n      </span>\n      <span className='keycap-3d text-muted-foreground relative inline-flex h-4 min-w-4 shrink-0 items-center justify-center rounded-full px-1 text-[10px] tabular-nums'>\n        {source.number}\n      </span>\n    </li>\n  );\n}\n\ntype CitedAnswerProps = {\n  isStreaming: boolean;\n  isRunning: boolean;\n  demoLitSource: number | null;\n};\n\nexport function CitedAnswer({\n  isStreaming,\n  isRunning,\n  demoLitSource,\n}: CitedAnswerProps) {\n  const [hovered, setHovered] = useState<number | null>(null);\n  const [pinned, setPinned] = useState<number | null>(null);\n  const total = ANSWER_TOKENS.length;\n  const count = useRevealedCount(total, isRunning, ANSWER_WORD_MS);\n  const shown = shownCountOf(isStreaming, count, total);\n  const lastShown = shown - 1;\n  const chosen = hovered ?? pinned;\n  const lit = chosen ?? demoLitSource;\n\n  function pin(number: number) {\n    setPinned((current) => toggledPin(current, number));\n  }\n\n  return (\n    <div className='flex flex-col gap-3'>\n      <p className='text-sm leading-relaxed'>\n        {ANSWER_TOKENS.map((token, index) => {\n          const isShown = index < shown;\n          if (token.kind === 'cite') {\n            return (\n              <CitationMark\n                key={index}\n                source={sourceOf(token.source)}\n                isShown={isShown}\n                isStreaming={isStreaming}\n                isLit={lit === token.source}\n                isPinned={pinned === token.source}\n                onHover={setHovered}\n                onPin={pin}\n              />\n            );\n          }\n          const hasCaret = isRunning && index === lastShown;\n          return (\n            <Fragment key={index}>\n              {leadingSpaceOf(index)}\n              <span className={inkClassOf(isStreaming, isShown)}>\n                {token.text}\n                {hasCaret && <StreamCaret />}\n              </span>\n            </Fragment>\n          );\n        })}\n      </p>\n      <div className='flex flex-col gap-1.5'>\n        <p className='text-muted-foreground flex items-center gap-2 px-0.5 text-xs'>\n          Sources\n          <Badge variant='secondary'>Illustrative</Badge>\n        </p>\n        <ul aria-label='Sources' className='flex flex-col gap-1.5'>\n          {SOURCES.map((source) => {\n            const firstMark = firstMarkOf(source);\n            return (\n              <SourceRow\n                key={source.number}\n                source={source}\n                isShown={firstMark < shown}\n                isStreaming={isStreaming}\n                isLit={lit === source.number}\n              />\n            );\n          })}\n        </ul>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-08/cited-answer.tsx"
    },
    {
      "path": "registry/ndeko/templates/chat/application-08/composer.tsx",
      "content": "'use client';\n\nimport { pressedSolidOf } from '@/registry/ndeko/lib/demonstration';\nimport { ArrowUpIcon, StopIcon } from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\n\nfunction isSendKey(event: React.KeyboardEvent<HTMLTextAreaElement>) {\n  const isPlainEnter = event.key === 'Enter' && !event.shiftKey;\n  return isPlainEnter && !event.nativeEvent.isComposing;\n}\n\nfunction buttonKeyOf(isRunning: boolean) {\n  if (isRunning) {\n    return 'stop';\n  }\n  return 'send';\n}\n\nfunction buttonLabelOf(isRunning: boolean) {\n  if (isRunning) {\n    return 'Stop the run';\n  }\n  return 'Send the message';\n}\n\ntype ComposerProps = {\n  draft: string;\n  placeholder: string;\n  canSend: boolean;\n  isRunning: boolean;\n  isReadOnly: boolean;\n  isSendPressed: boolean;\n  onDraftChange: (text: string) => void;\n  onSend: () => void;\n  onStop: () => void;\n};\n\nexport function Composer({\n  draft,\n  placeholder,\n  canSend,\n  isRunning,\n  isReadOnly,\n  isSendPressed,\n  onDraftChange,\n  onSend,\n  onStop,\n}: ComposerProps) {\n  const isDisabled = !canSend && !isRunning;\n\n  function handleKeys(event: React.KeyboardEvent<HTMLTextAreaElement>) {\n    if (!isSendKey(event)) {\n      return;\n    }\n    event.preventDefault();\n    if (canSend) {\n      onSend();\n    }\n  }\n\n  function press() {\n    if (isRunning) {\n      onStop();\n      return;\n    }\n    onSend();\n  }\n\n  return (\n    <div className='bg-card hairline-ring ring-foreground/12 has-[textarea:focus-visible]:ring-ring/25 dark:bg-foreground/[0.04] dark:ring-foreground/15 flex items-end gap-2 rounded-2xl p-2 shadow-[0_1px_2px_rgb(0_0_0/0.05)] transition-[box-shadow] duration-150 has-[textarea:focus-visible]:ring-[3px]'>\n      <textarea\n        data-composer-field\n        value={draft}\n        rows={1}\n        aria-label='Message to Quenby'\n        placeholder={placeholder}\n        disabled={isReadOnly}\n        onChange={(event) => onDraftChange(event.target.value)}\n        onKeyDown={handleKeys}\n        className='placeholder:text-muted-foreground/75 field-sizing-content max-h-[6lh] min-h-8 flex-1 resize-none bg-transparent px-1.5 py-1.5 text-base leading-normal outline-none md:text-[13px]'\n      />\n      <Button\n        type='button'\n        size='icon'\n        aria-label={buttonLabelOf(isRunning)}\n        disabled={isDisabled}\n        onClick={press}\n        className={pressedSolidOf(isSendPressed)}\n      >\n        <Swap swapKey={buttonKeyOf(isRunning)}>\n          {isRunning && <StopIcon />}\n          {!isRunning && <ArrowUpIcon />}\n        </Swap>\n      </Button>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-08/composer.tsx"
    },
    {
      "path": "registry/ndeko/templates/chat/application-08/data.ts",
      "content": "import type { SeriesSlot } from '@/registry/ndeko/lib/agent-run';\nimport type { BrandSlug } from '@/registry/ndeko/lib/brand-logos';\nimport { wordsOf } from '@/registry/ndeko/lib/words';\n\nexport const BRAND = { name: 'Quenby' };\n\nexport type Agent = {\n  name: string;\n  series: SeriesSlot;\n};\n\nexport const ASSISTANT: Agent = { name: 'Quenby', series: 1 };\n\nexport type ModelId =\n  'claude-sonnet' | 'claude-opus' | 'gpt-mini' | 'gemini-pro';\n\nexport type ModelOption = {\n  id: ModelId;\n  name: string;\n  brand: BrandSlug;\n  usdPerThousandTokens: number;\n};\n\n/** Coarse price tiers, not the price list of any maker. The figures are illustrative. */\nexport const MODELS: ModelOption[] = [\n  {\n    id: 'claude-sonnet',\n    name: 'Claude Sonnet',\n    brand: 'claude',\n    usdPerThousandTokens: 0.006,\n  },\n  {\n    id: 'claude-opus',\n    name: 'Claude Opus',\n    brand: 'claude',\n    usdPerThousandTokens: 0.03,\n  },\n  {\n    id: 'gpt-mini',\n    name: 'GPT mini',\n    brand: 'openai',\n    usdPerThousandTokens: 0.002,\n  },\n  {\n    id: 'gemini-pro',\n    name: 'Gemini Pro',\n    brand: 'gemini',\n    usdPerThousandTokens: 0.008,\n  },\n];\n\nexport const STARTING_MODEL: ModelId = 'claude-sonnet';\n\nexport const DEMO_MODEL: ModelId = 'claude-opus';\n\nconst FALLBACK_MODEL = MODELS[0];\n\nexport function modelOf(id: ModelId) {\n  const model = MODELS.find((candidate) => candidate.id === id);\n  return model ?? FALLBACK_MODEL;\n}\n\nexport type Day = 'Today' | 'Yesterday' | 'Previous 7 days';\n\nexport const DAYS: Day[] = ['Today', 'Yesterday', 'Previous 7 days'];\n\nexport type ChatLine = {\n  from: 'person' | 'assistant';\n  text: string;\n};\n\nexport type Chat = {\n  id: string;\n  day: Day;\n  title: string;\n  lines: ChatLine[];\n};\n\nexport const LIVE_ID = 'live';\n\nexport const NEW_ID = 'new';\n\nexport const NEW_CHAT_TITLE = 'New chat';\n\nexport const LIVE_TITLE = 'Goma lot to Antwerp';\n\n/** Invented chats about an invented exporter. They only open as read-only transcripts. */\nexport const CHATS: Chat[] = [\n  {\n    id: 'stock',\n    day: 'Today',\n    title: 'Weekly stock count',\n    lines: [\n      {\n        from: 'person',\n        text: 'Which depots have not sent their stock count this week?',\n      },\n      {\n        from: 'assistant',\n        text: 'Kinshasa and Goma have. Lubumbashi is the only depot still missing, and its count is due today.',\n      },\n    ],\n  },\n  {\n    id: 'numbering',\n    day: 'Today',\n    title: 'Invoice numbering rules',\n    lines: [\n      { from: 'person', text: 'What numbering do we use for credit notes?' },\n      {\n        from: 'assistant',\n        text: 'Credit notes carry the prefix CN and the year, then a four digit counter, for example CN-2026-0042.',\n      },\n    ],\n  },\n  {\n    id: 'insurance',\n    day: 'Yesterday',\n    title: 'Carrier insurance clauses',\n    lines: [\n      {\n        from: 'person',\n        text: 'Summarise the insurance clause in the carrier contract.',\n      },\n      {\n        from: 'assistant',\n        text: 'Cargo is covered up to 80,000 USD per shipment. Anything above needs a rider, which the carrier prices on request.',\n      },\n    ],\n  },\n  {\n    id: 'hiring',\n    day: 'Yesterday',\n    title: 'Lubumbashi depot hiring plan',\n    lines: [\n      {\n        from: 'person',\n        text: 'Draft a hiring plan for two loaders at the Lubumbashi depot.',\n      },\n      {\n        from: 'assistant',\n        text: 'Post the role on 12 November, interview the week of 17 November and confirm both offers by 25 November, so they start on 1 December.',\n      },\n    ],\n  },\n  {\n    id: 'customs',\n    day: 'Previous 7 days',\n    title: 'Customs checklist for coffee',\n    lines: [\n      {\n        from: 'person',\n        text: 'List the documents for a coffee export from Goma.',\n      },\n      {\n        from: 'assistant',\n        text: 'The certificate of origin, the phytosanitary certificate, the packing list, the commercial invoice and the export declaration, all filed before loading.',\n      },\n    ],\n  },\n  {\n    id: 'brief',\n    day: 'Previous 7 days',\n    title: 'Supplier brief in French',\n    lines: [\n      { from: 'person', text: 'Translate the supplier brief into French.' },\n      {\n        from: 'assistant',\n        text: 'Done. I kept the product names in English and used the formal vous throughout.',\n      },\n    ],\n  },\n  {\n    id: 'fuel',\n    day: 'Previous 7 days',\n    title: 'Kinshasa fuel price sheet',\n    lines: [\n      { from: 'person', text: 'Update the fuel price sheet for Kinshasa.' },\n      {\n        from: 'assistant',\n        text: 'The sheet lists the three stations you track. Prices stay marked as estimates until you confirm them.',\n      },\n    ],\n  },\n];\n\nconst FALLBACK_CHAT = CHATS[0];\n\nexport function chatOf(id: string) {\n  const chat = CHATS.find((candidate) => candidate.id === id);\n  return chat ?? FALLBACK_CHAT;\n}\n\nexport const QUESTION =\n  'Can the Goma coffee lot reach Antwerp before 28 November, and what will it cost?';\n\n/** The live chat suggests the question its run answers. A new chat suggests others, which only get the stock reply. */\nexport const LIVE_SUGGESTIONS: string[] = [QUESTION];\n\nexport const NEW_SUGGESTIONS: string[] = [\n  'Summarise the carrier contract for the Lubumbashi depot',\n  'Draft a reminder for the unpaid invoices from Kinshasa',\n  'List what a new depot in Goma needs before it opens',\n];\n\nexport const THOUGHT =\n  'The question has two parts, a date and a cost. I need the booking notes, the sailing dates and the forwarder rates for the route that fits the date. The rate sheet belongs to the forwarder, so I will ask before I open it.';\n\nexport const THOUGHT_WORDS = wordsOf(THOUGHT);\n\nexport type StepId = 'booking' | 'sailings' | 'rates' | 'customs' | 'answer';\n\nexport type CallId = 'notes' | 'sailings' | 'rates' | 'customs';\n\nexport type PlanSeed = {\n  id: StepId;\n  title: string;\n  callId?: CallId;\n};\n\nexport const PLAN: PlanSeed[] = [\n  { id: 'booking', title: 'Read the booking notes', callId: 'notes' },\n  { id: 'sailings', title: 'Check the sailing dates', callId: 'sailings' },\n  { id: 'rates', title: 'Read the forwarder rates', callId: 'rates' },\n  { id: 'customs', title: 'Check the customs deadline', callId: 'customs' },\n  { id: 'answer', title: 'Write the answer' },\n];\n\nconst FALLBACK_STEP = PLAN[0];\n\nexport function planSeedOf(id: StepId) {\n  const seed = PLAN.find((candidate) => candidate.id === id);\n  return seed ?? FALLBACK_STEP;\n}\n\nexport type CallSeed = {\n  id: CallId;\n  title: string;\n  brand: BrandSlug;\n  product: string;\n  inputTokens: number;\n  outputTokens: number;\n};\n\nexport const CALLS: CallSeed[] = [\n  {\n    id: 'notes',\n    title: 'Goma lot 14, booking notes',\n    brand: 'notion',\n    product: 'Notion',\n    inputTokens: 1420,\n    outputTokens: 180,\n  },\n  {\n    id: 'sailings',\n    title: 'Sailing calendar, November',\n    brand: 'googlecalendar',\n    product: 'Google Calendar',\n    inputTokens: 960,\n    outputTokens: 120,\n  },\n  {\n    id: 'rates',\n    title: 'Forwarder rate sheet, November',\n    brand: 'googledrive',\n    product: 'Google Drive',\n    inputTokens: 2310,\n    outputTokens: 260,\n  },\n  {\n    id: 'customs',\n    title: 'SHIP-31 Certificate of origin',\n    brand: 'linear',\n    product: 'Linear',\n    inputTokens: 840,\n    outputTokens: 110,\n  },\n];\n\nconst FALLBACK_CALL = CALLS[0];\n\nexport function callSeedOf(id: CallId) {\n  const seed = CALLS.find((candidate) => candidate.id === id);\n  return seed ?? FALLBACK_CALL;\n}\n\nexport const THOUGHT_USAGE = { input: 640, output: 210 };\n\nexport const ANSWER_USAGE = { input: 0, output: 310 };\n\nexport const CONTEXT_LIMIT = 200_000;\n\nexport type Source = {\n  number: number;\n  callId: CallId;\n  title: string;\n  excerpt: string;\n  brand: BrandSlug;\n  product: string;\n};\n\nexport const SOURCES: Source[] = [\n  {\n    number: 1,\n    callId: 'notes',\n    title: 'Goma lot 14, booking notes',\n    excerpt: '14 pallets, ready to load on 12 November',\n    brand: 'notion',\n    product: 'Notion',\n  },\n  {\n    number: 2,\n    callId: 'sailings',\n    title: 'Sailing calendar, November',\n    excerpt: 'Mombasa to Antwerp, leaves 15 November',\n    brand: 'googlecalendar',\n    product: 'Google Calendar',\n  },\n  {\n    number: 3,\n    callId: 'rates',\n    title: 'Forwarder rate sheet, November',\n    excerpt: 'Mombasa 2,140 USD, Dar es Salaam 2,450 USD',\n    brand: 'googledrive',\n    product: 'Google Drive',\n  },\n  {\n    number: 4,\n    callId: 'customs',\n    title: 'SHIP-31 Certificate of origin',\n    excerpt: 'To be filed by 20 November, still open',\n    brand: 'linear',\n    product: 'Linear',\n  },\n];\n\nconst FALLBACK_SOURCE = SOURCES[0];\n\nexport function sourceOf(number: number) {\n  const source = SOURCES.find((candidate) => candidate.number === number);\n  return source ?? FALLBACK_SOURCE;\n}\n\nconst ANSWER =\n  'Yes, through Mombasa. The lot is 14 pallets and ready to load on 12 November. [1] The only sailing that lands in Antwerp before 28 November leaves Mombasa on 15 November. [2] The forwarder quotes 2,140 USD for the lot on that route, 310 USD less than through Dar es Salaam. [3] The certificate of origin has to be filed by 20 November, and its issue is still open. [4]';\n\nexport type AnswerToken =\n  { kind: 'word'; text: string } | { kind: 'cite'; source: number };\n\nconst CITE = /^\\[(\\d+)\\]$/;\n\nfunction tokenOf(piece: string): AnswerToken {\n  const match = CITE.exec(piece);\n  if (match) {\n    const source = Number(match[1]);\n    return { kind: 'cite', source };\n  }\n  return { kind: 'word', text: piece };\n}\n\nconst ANSWER_PIECES = wordsOf(ANSWER);\n\nexport const ANSWER_TOKENS = ANSWER_PIECES.map(tokenOf);\n\nexport type Person = {\n  name: string;\n  role: string;\n};\n\nexport const FORWARDER_CONTACT: Person = {\n  name: 'Jean-Pierre Kasongo',\n  role: 'Forwarder, Mombasa desk',\n};\n\nexport const REQUEST = {\n  file: 'Forwarder rate sheet, November',\n  access: 'Read only, for this run',\n  reason: 'The Mombasa and Dar es Salaam quotes are only in this sheet',\n};\n\nexport const DECLINED_LINE =\n  'Not read. The run stopped before the rates, so there is no cost to give yet';\n\nexport const STOPPED_LINE =\n  'Stopped by you. The steps that were left did not run';\n\nexport const FOLLOW_UP_REPLY =\n  'This demonstration plays one scripted run. Replay it to watch it again.';\n",
      "type": "registry:component",
      "target": "components/templates/application-08/data.ts"
    },
    {
      "path": "registry/ndeko/templates/chat/application-08/model-picker.tsx",
      "content": "'use client';\n\nimport { WordRoll } from '@/components/core/word-roll';\nimport { ChevronDownIcon } from '@/registry/ndeko/lib/icons';\nimport { BrandTile } from '@/registry/ndeko/ui/brand-tile';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport {\n  DropdownMenu,\n  DropdownMenuContent,\n  DropdownMenuGroup,\n  DropdownMenuGroupLabel,\n  DropdownMenuRadioGroup,\n  DropdownMenuRadioItem,\n  DropdownMenuTrigger,\n} from '@/registry/ndeko/ui/dropdown-menu';\n\nimport { modelOf, MODELS, type ModelId } from './data';\n\nconst MODEL_NAMES = MODELS.map((model) => model.name);\n\ntype ModelPickerProps = {\n  value: ModelId;\n  onValueChange: (model: ModelId) => void;\n};\n\n/** The menu belongs to a person. The demonstration changes the value, and the name rolls to the new one. */\nexport function ModelPicker({ value, onValueChange }: ModelPickerProps) {\n  const model = modelOf(value);\n\n  function change(next: unknown) {\n    const found = MODELS.find((candidate) => candidate.id === next);\n    if (found) {\n      onValueChange(found.id);\n    }\n  }\n\n  return (\n    <DropdownMenu>\n      <DropdownMenuTrigger\n        render={\n          <Button\n            type='button'\n            variant='ghost'\n            size='sm'\n            aria-label={`Model: ${model.name}`}\n            className='text-foreground gap-1.5 px-2'\n          />\n        }\n      >\n        <Swap swapKey={model.brand}>\n          <BrandTile brand={model.brand} size='sm' />\n        </Swap>\n        <span className='sr-only @lg:not-sr-only'>\n          <WordRoll text={model.name} labels={MODEL_NAMES} />\n        </span>\n        <ChevronDownIcon className='size-3.5 opacity-60' />\n      </DropdownMenuTrigger>\n      <DropdownMenuContent side='bottom' align='end' className='w-56'>\n        <DropdownMenuGroup>\n          <DropdownMenuGroupLabel>\n            Model for the next message\n          </DropdownMenuGroupLabel>\n          <DropdownMenuRadioGroup value={value} onValueChange={change}>\n            {MODELS.map((option) => (\n              <DropdownMenuRadioItem\n                key={option.id}\n                value={option.id}\n                closeOnClick\n              >\n                <BrandTile brand={option.brand} size='sm' />\n                {option.name}\n              </DropdownMenuRadioItem>\n            ))}\n          </DropdownMenuRadioGroup>\n        </DropdownMenuGroup>\n      </DropdownMenuContent>\n    </DropdownMenu>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-08/model-picker.tsx"
    },
    {
      "path": "registry/ndeko/templates/chat/application-08/run-details.tsx",
      "content": "'use client';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport {\n  elapsedOf,\n  formatDuration,\n  formatTokens,\n} from '@/registry/ndeko/lib/agent-run';\nimport {\n  ListChecksIcon,\n  LoaderIcon,\n  MinusIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { BrandTile } from '@/registry/ndeko/ui/brand-tile';\nimport { CallStatusMark } from '@/registry/ndeko/ui/call-status';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { LiveDuration } from '@/registry/ndeko/ui/live-duration';\nimport { Progress } from '@/registry/ndeko/ui/progress';\n\nimport {\n  callSeedOf,\n  CONTEXT_LIMIT,\n  modelOf,\n  planSeedOf,\n  type ModelId,\n} from './data';\nimport type {\n  CallRun,\n  CallStatus,\n  PlanRun,\n  Stage,\n  StepStatus,\n  Tokens,\n} from './session';\n\n/** Under a dollar a cost keeps three decimals, as in the rest of the kit. */\nconst COST_FORMAT: Intl.NumberFormatOptions = {\n  style: 'currency',\n  currency: 'USD',\n  minimumFractionDigits: 3,\n  maximumFractionDigits: 3,\n};\n\nconst STATUS_WORD: Record<Stage, string> = {\n  idle: 'No run yet',\n  thinking: 'Thinking',\n  working: 'Working',\n  asking: 'Waiting on you',\n  answering: 'Writing the answer',\n  done: 'Done',\n  declined: 'Stopped at the request',\n  stopped: 'Stopped',\n};\n\nconst SECTION_TITLE = 'text-muted-foreground text-xs font-medium';\n\nconst MARK_BOX = 'flex size-4 shrink-0 items-center justify-center';\n\nfunction StepMark({ status }: { status: StepStatus }) {\n  if (status === 'upcoming') {\n    return (\n      <span className={MARK_BOX}>\n        <span className='bg-muted-foreground/40 size-1.5 rounded-full' />\n        <span className='sr-only'>To do</span>\n      </span>\n    );\n  }\n  if (status === 'skipped') {\n    return (\n      <span className={MARK_BOX}>\n        <MinusIcon className='text-muted-foreground size-4' />\n        <span className='sr-only'>Skipped</span>\n      </span>\n    );\n  }\n  return <CallStatusMark status={status} />;\n}\n\nfunction titleToneOf(status: StepStatus) {\n  if (status === 'skipped') {\n    return 'text-muted-foreground line-through';\n  }\n  if (status === 'upcoming') {\n    return 'text-muted-foreground';\n  }\n  return undefined;\n}\n\nfunction PlanClock({ run }: { run: PlanRun }) {\n  if (run.status === 'running') {\n    return (\n      <LiveDuration\n        item={run}\n        isRunning\n        className='text-muted-foreground w-10 shrink-0 text-end text-xs'\n      />\n    );\n  }\n  if (run.status === 'done') {\n    const elapsed = elapsedOf(run, run.endedAt ?? 0);\n    return (\n      <span className='text-muted-foreground w-10 shrink-0 text-end text-xs tabular-nums'>\n        {formatDuration(elapsed)}\n      </span>\n    );\n  }\n  return null;\n}\n\nfunction PlanSection({ plan, stage }: { plan: PlanRun[]; stage: Stage }) {\n  const isPlanning = plan.length === 0 && stage === 'thinking';\n  const doneCount = plan.filter((run) => run.status === 'done').length;\n\n  return (\n    <section className='flex flex-col gap-1.5'>\n      <h3 className={cn(SECTION_TITLE, 'flex items-center gap-1.5')}>\n        Plan\n        {plan.length > 0 && (\n          <span className='tabular-nums'>\n            {doneCount} of {plan.length}\n          </span>\n        )}\n      </h3>\n      {isPlanning && (\n        <p className='text-muted-foreground flex h-8 items-center gap-2 text-[13px]'>\n          <LoaderIcon className='size-4 animate-spin' />\n          Making a plan\n        </p>\n      )}\n      <ol aria-label='Plan' className='flex flex-col'>\n        {plan.map((run) => (\n          <li\n            key={run.id}\n            className='flex h-8 items-center gap-2 text-[13px] transition-opacity duration-300 starting:opacity-0'\n          >\n            <StepMark status={run.status} />\n            <span\n              className={cn('min-w-0 flex-1 truncate', titleToneOf(run.status))}\n            >\n              {planSeedOf(run.id).title}\n            </span>\n            <PlanClock run={run} />\n          </li>\n        ))}\n      </ol>\n    </section>\n  );\n}\n\nfunction CallMark({ status }: { status: CallStatus }) {\n  if (status === 'skipped') {\n    return (\n      <span className={MARK_BOX}>\n        <MinusIcon className='text-muted-foreground size-4' />\n        <span className='sr-only'>Skipped</span>\n      </span>\n    );\n  }\n  return <CallStatusMark status={status} />;\n}\n\nfunction CallRow({ call }: { call: CallRun }) {\n  const seed = callSeedOf(call.id);\n  const total = seed.inputTokens + seed.outputTokens;\n\n  return (\n    <li className='flex items-center gap-2.5 py-1 transition-opacity duration-300 starting:opacity-0'>\n      <BrandTile brand={seed.brand} size='lg' title={seed.product} />\n      <span className='flex min-w-0 flex-1 flex-col leading-tight'>\n        <span className='truncate text-[13px]'>{seed.title}</span>\n        <span className='text-muted-foreground truncate text-xs tabular-nums'>\n          {seed.product}, {formatTokens(total)} tokens\n        </span>\n      </span>\n      <CallMark status={call.status} />\n    </li>\n  );\n}\n\nfunction CallsSection({ calls }: { calls: CallRun[] }) {\n  const isEmpty = calls.length === 0;\n\n  return (\n    <section className='flex flex-col gap-1.5'>\n      <h3 className={cn(SECTION_TITLE, 'flex items-center gap-1.5')}>\n        Calls\n        {!isEmpty && <span className='tabular-nums'>{calls.length}</span>}\n      </h3>\n      {isEmpty && (\n        <p className='text-muted-foreground text-xs leading-5'>\n          The tools the assistant uses are listed here, with what each one cost\n          in tokens.\n        </p>\n      )}\n      <ul aria-label='Tool calls' className='flex flex-col'>\n        {calls.map((call) => (\n          <CallRow key={call.id} call={call} />\n        ))}\n      </ul>\n    </section>\n  );\n}\n\ntype UsageSectionProps = {\n  tokens: Tokens;\n  costUsd: number;\n  model: ModelId;\n};\n\nfunction UsageSection({ tokens, costUsd, model }: UsageSectionProps) {\n  const total = tokens.input + tokens.output;\n  const contextShare = (total * 100) / CONTEXT_LIMIT;\n  const option = modelOf(model);\n\n  return (\n    <section className='flex flex-col gap-2.5'>\n      <h3 className={SECTION_TITLE}>Usage</h3>\n      <div className='bg-foreground/[0.04] flex flex-col gap-3 rounded-lg p-3'>\n        <div className='flex items-end justify-between gap-3'>\n          <div className='flex min-w-0 flex-col gap-0.5'>\n            <span className='text-muted-foreground text-xs'>Cost</span>\n            <MotionNumber\n              value={costUsd}\n              format={COST_FORMAT}\n              className='text-2xl leading-8 font-semibold'\n            />\n          </div>\n          <Badge variant='secondary'>Illustrative</Badge>\n        </div>\n        <dl className='grid grid-cols-2 gap-3 text-xs'>\n          <div className='flex flex-col gap-0.5'>\n            <dt className='text-muted-foreground'>Tokens in</dt>\n            <dd className='text-[13px] font-medium tabular-nums'>\n              {formatTokens(tokens.input)}\n            </dd>\n          </div>\n          <div className='flex flex-col gap-0.5'>\n            <dt className='text-muted-foreground'>Tokens out</dt>\n            <dd className='text-[13px] font-medium tabular-nums'>\n              {formatTokens(tokens.output)}\n            </dd>\n          </div>\n        </dl>\n        <Progress value={contextShare} aria-label='Context window used' />\n        <p className='text-muted-foreground flex items-center justify-between gap-2 text-xs tabular-nums'>\n          <span>\n            {formatTokens(total)} of {formatTokens(CONTEXT_LIMIT)} context\n          </span>\n          <span className='flex items-center gap-1.5'>\n            <BrandTile brand={option.brand} size='sm' />\n            {option.name}\n          </span>\n        </p>\n      </div>\n    </section>\n  );\n}\n\nexport type RunDetailsProps = {\n  stage: Stage;\n  plan: PlanRun[];\n  calls: CallRun[];\n  tokens: Tokens;\n  costUsd: number;\n  runModel: ModelId;\n  hasRun: boolean;\n  emptyLine: string;\n  className?: string;\n};\n\nexport function RunDetails({\n  stage,\n  plan,\n  calls,\n  tokens,\n  costUsd,\n  runModel,\n  hasRun,\n  emptyLine,\n  className,\n}: RunDetailsProps) {\n  const status = STATUS_WORD[stage];\n\n  return (\n    <div className={cn('flex min-h-0 flex-col gap-4', className)}>\n      <header className='flex items-center gap-2.5'>\n        <span\n          aria-hidden='true'\n          className='keycap-3d text-muted-foreground inline-flex size-7 shrink-0 items-center justify-center rounded-md'\n        >\n          <ListChecksIcon className='size-3.5' />\n        </span>\n        <div className='flex min-w-0 flex-1 flex-col leading-tight'>\n          <h2 className='truncate text-sm font-medium'>Run details</h2>\n          {hasRun && (\n            <Swap swapKey={status} className='text-muted-foreground text-xs'>\n              {status}\n            </Swap>\n          )}\n        </div>\n      </header>\n      <div className='-mx-1.5 flex min-h-0 flex-1 flex-col gap-5 overflow-y-auto px-1.5'>\n        {!hasRun && (\n          <p className='text-muted-foreground text-[13px] leading-relaxed'>\n            {emptyLine}\n          </p>\n        )}\n        {hasRun && (\n          <>\n            <PlanSection plan={plan} stage={stage} />\n            <CallsSection calls={calls} />\n            <UsageSection tokens={tokens} costUsd={costUsd} model={runModel} />\n          </>\n        )}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-08/run-details.tsx"
    },
    {
      "path": "registry/ndeko/templates/chat/application-08/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\nimport { keyDelayOf, prefixesOf } from '@/registry/ndeko/lib/demonstration';\nimport { restingOf } from '@/registry/ndeko/lib/run-session';\n\nimport {\n  ANSWER_TOKENS,\n  ANSWER_USAGE,\n  callSeedOf,\n  DEMO_MODEL,\n  LIVE_ID,\n  modelOf,\n  NEW_ID,\n  PLAN,\n  planSeedOf,\n  QUESTION,\n  STARTING_MODEL,\n  THOUGHT_USAGE,\n  THOUGHT_WORDS,\n  type CallId,\n  type ModelId,\n  type StepId,\n} from './data';\n\nexport type Stage =\n  | 'idle'\n  | 'thinking'\n  | 'working'\n  | 'asking'\n  | 'answering'\n  | 'done'\n  | 'declined'\n  | 'stopped';\n\nexport type Decision = 'approved' | 'denied';\n\nexport type StepStatus =\n  'upcoming' | 'running' | 'waiting' | 'done' | 'skipped';\n\nexport type PlanRun = {\n  id: StepId;\n  status: StepStatus;\n  startedAt?: number;\n  endedAt?: number;\n};\n\nexport type CallStatus = 'running' | 'waiting' | 'done' | 'skipped';\n\nexport type CallRun = {\n  id: CallId;\n  status: CallStatus;\n  startedAt: number;\n  endedAt?: number;\n};\n\nexport type Tokens = {\n  input: number;\n  output: number;\n};\n\nexport type ChatState = {\n  activeId: string;\n  draft: string;\n  model: ModelId;\n  runModel: ModelId;\n  question: string | null;\n  followUps: string[];\n  newLines: string[];\n  stage: Stage;\n  stoppedFrom: Stage | null;\n  decision: Decision | null;\n  plan: PlanRun[];\n  calls: CallRun[];\n  tokens: Tokens;\n  costUsd: number;\n  startedAt?: number;\n  thoughtEndedAt?: number;\n  endedAt?: number;\n  demoLitSource: number | null;\n  isPanelOpen: boolean;\n  isDetailsSheetOpen: boolean;\n  isSidebarCollapsed: boolean;\n  isSidebarSheetOpen: boolean;\n  search: string;\n};\n\nexport type ChatAction =\n  | { type: 'typed'; text: string }\n  | { type: 'sent' }\n  | { type: 'modelSet'; model: ModelId }\n  | { type: 'thoughtDone' }\n  | { type: 'stepStarted'; id: StepId }\n  | { type: 'stepDone'; id: StepId }\n  | { type: 'asked' }\n  | { type: 'decided'; decision: Decision }\n  | { type: 'answering' }\n  | { type: 'answered' }\n  | { type: 'stopped' }\n  | { type: 'lit'; source: number | null }\n  | { type: 'panel'; isOpen: boolean }\n  | { type: 'detailsSheet'; isOpen: boolean }\n  | { type: 'sidebarCollapsed'; isCollapsed: boolean }\n  | { type: 'sidebarSheet'; isOpen: boolean }\n  | { type: 'searched'; text: string }\n  | { type: 'chatOpened'; id: string }\n  | { type: 'newChat' }\n  | { type: 'batch'; actions: ChatAction[] };\n\ntype Step = SessionStep<ChatState, ChatAction>;\n\nexport const INITIAL: ChatState = {\n  activeId: LIVE_ID,\n  draft: '',\n  model: STARTING_MODEL,\n  runModel: STARTING_MODEL,\n  question: null,\n  followUps: [],\n  newLines: [],\n  stage: 'idle',\n  stoppedFrom: null,\n  decision: null,\n  plan: [],\n  calls: [],\n  tokens: { input: 0, output: 0 },\n  costUsd: 0,\n  demoLitSource: null,\n  isPanelOpen: true,\n  isDetailsSheetOpen: false,\n  isSidebarCollapsed: false,\n  isSidebarSheetOpen: false,\n  search: '',\n};\n\nconst BUSY_STAGES: Stage[] = ['thinking', 'working', 'asking', 'answering'];\n\nconst OVER_STAGES: Stage[] = ['done', 'declined', 'stopped'];\n\nconst WORKING_STAGES: Stage[] = ['working', 'answering'];\n\nexport function isBusy(stage: Stage) {\n  return BUSY_STAGES.includes(stage);\n}\n\nexport function isOver(stage: Stage) {\n  return OVER_STAGES.includes(stage);\n}\n\nconst WRITABLE_CHATS = [LIVE_ID, NEW_ID];\n\nexport function isReadOnly(state: ChatState) {\n  return !WRITABLE_CHATS.includes(state.activeId);\n}\n\n/** The answer shows from its first word, and stays when the run was stopped halfway through it. */\nexport function showsAnswerOf(state: ChatState) {\n  if (state.stage === 'stopped') {\n    return state.stoppedFrom === 'answering';\n  }\n  const answerStages: Stage[] = ['answering', 'done'];\n  return answerStages.includes(state.stage);\n}\n\nexport type RequestView =\n  'none' | 'asking' | 'reading' | 'read' | 'denied' | 'unanswered';\n\nexport function requestViewOf(state: ChatState): RequestView {\n  if (state.stage === 'asking') {\n    return 'asking';\n  }\n  if (state.decision === 'denied') {\n    return 'denied';\n  }\n  if (state.decision === 'approved') {\n    const call = state.calls.find((candidate) => candidate.id === 'rates');\n    if (call?.status === 'done') {\n      return 'read';\n    }\n    return 'reading';\n  }\n  if (state.stoppedFrom === 'asking') {\n    return 'unanswered';\n  }\n  return 'none';\n}\n\nfunction trimmedQuestionOf(draft: string) {\n  const trimmed = draft.trim();\n  if (trimmed === '') {\n    return null;\n  }\n  const isUnfinishedDemo = QUESTION.startsWith(trimmed);\n  if (isUnfinishedDemo) {\n    return QUESTION;\n  }\n  return trimmed;\n}\n\n/**\n * What Send would post now: the first question of the live chat (a person who takes over halfway\n * through the demonstration question sends the whole of it), a follow-up once the run is over, a\n * line in a new chat. Null while the agent works or when there is nothing to send.\n */\nexport function sendableTextOf(state: ChatState) {\n  if (isReadOnly(state)) {\n    return null;\n  }\n  if (state.activeId === NEW_ID) {\n    const line = state.draft.trim();\n    if (line === '') {\n      return null;\n    }\n    return line;\n  }\n  if (state.question === null) {\n    return trimmedQuestionOf(state.draft);\n  }\n  const text = state.draft.trim();\n  const canFollowUp = isOver(state.stage) && text !== '';\n  if (canFollowUp) {\n    return text;\n  }\n  return null;\n}\n\nfunction sent(state: ChatState, now: number): ChatState {\n  const text = sendableTextOf(state);\n  if (text === null) {\n    return state;\n  }\n  if (state.activeId === NEW_ID) {\n    return { ...state, draft: '', newLines: [...state.newLines, text] };\n  }\n  if (state.question === null) {\n    return {\n      ...state,\n      draft: '',\n      question: text,\n      runModel: state.model,\n      stage: 'thinking',\n      startedAt: now,\n    };\n  }\n  return { ...state, draft: '', followUps: [...state.followUps, text] };\n}\n\nfunction costOf(model: ModelId, tokens: Tokens) {\n  const total = tokens.input + tokens.output;\n  const thousands = total / 1000;\n  return thousands * modelOf(model).usdPerThousandTokens;\n}\n\nfunction withUsage(state: ChatState, usage: Tokens): ChatState {\n  const tokens = {\n    input: state.tokens.input + usage.input,\n    output: state.tokens.output + usage.output,\n  };\n  const costUsd = state.costUsd + costOf(state.runModel, usage);\n  return { ...state, tokens, costUsd };\n}\n\nfunction thoughtDone(state: ChatState, now: number): ChatState {\n  if (state.stage !== 'thinking') {\n    return state;\n  }\n  const plan: PlanRun[] = PLAN.map((seed) => ({\n    id: seed.id,\n    status: 'upcoming',\n  }));\n  const thought: ChatState = {\n    ...state,\n    plan,\n    stage: 'working',\n    thoughtEndedAt: now,\n  };\n  return withUsage(thought, THOUGHT_USAGE);\n}\n\nfunction planRunOf(state: ChatState, id: StepId) {\n  return state.plan.find((run) => run.id === id);\n}\n\nfunction hasCall(state: ChatState, id: CallId) {\n  return state.calls.some((call) => call.id === id);\n}\n\nfunction patchedPlan(\n  state: ChatState,\n  id: StepId,\n  change: (run: PlanRun) => PlanRun\n) {\n  return state.plan.map((run) => {\n    if (run.id !== id) {\n      return run;\n    }\n    return change(run);\n  });\n}\n\nfunction patchedCalls(\n  state: ChatState,\n  id: CallId,\n  change: (call: CallRun) => CallRun\n) {\n  return state.calls.map((call) => {\n    if (call.id !== id) {\n      return call;\n    }\n    return change(call);\n  });\n}\n\nfunction stepStarted(state: ChatState, id: StepId, now: number): ChatState {\n  const isWorking = WORKING_STAGES.includes(state.stage);\n  const run = planRunOf(state, id);\n  const isUpcoming = run?.status === 'upcoming';\n  if (!isWorking || !isUpcoming) {\n    return state;\n  }\n  const plan = patchedPlan(state, id, (current) => ({\n    ...current,\n    status: 'running',\n    startedAt: now,\n  }));\n  const callId = planSeedOf(id).callId;\n  if (callId === undefined) {\n    return { ...state, plan };\n  }\n  if (hasCall(state, callId)) {\n    return { ...state, plan };\n  }\n  const call: CallRun = { id: callId, status: 'running', startedAt: now };\n  return { ...state, plan, calls: [...state.calls, call] };\n}\n\nfunction stepDone(state: ChatState, id: StepId, now: number): ChatState {\n  const isWorking = WORKING_STAGES.includes(state.stage);\n  const run = planRunOf(state, id);\n  const isRunning = run?.status === 'running';\n  if (!isWorking || !isRunning) {\n    return state;\n  }\n  const plan = patchedPlan(state, id, (current) => ({\n    ...current,\n    status: 'done',\n    endedAt: now,\n  }));\n  const callId = planSeedOf(id).callId;\n  if (callId === undefined) {\n    return { ...state, plan };\n  }\n  const calls = patchedCalls(state, callId, (current) => ({\n    ...current,\n    status: 'done',\n    endedAt: now,\n  }));\n  const seed = callSeedOf(callId);\n  const usage = { input: seed.inputTokens, output: seed.outputTokens };\n  return withUsage({ ...state, plan, calls }, usage);\n}\n\nfunction asked(state: ChatState): ChatState {\n  if (state.stage !== 'working') {\n    return state;\n  }\n  const plan = patchedPlan(state, 'rates', (run) => ({\n    ...run,\n    status: 'waiting',\n  }));\n  const calls = patchedCalls(state, 'rates', (call) => ({\n    ...call,\n    status: 'waiting',\n  }));\n  return { ...state, stage: 'asking', plan, calls };\n}\n\nfunction skippedRest(state: ChatState, now: number): ChatState {\n  const plan = state.plan.map((run) => {\n    if (run.status === 'done') {\n      return run;\n    }\n    const skipped: PlanRun = { ...run, status: 'skipped', endedAt: now };\n    return skipped;\n  });\n  const calls = state.calls.map((call) => {\n    if (call.status === 'done') {\n      return call;\n    }\n    const skipped: CallRun = { ...call, status: 'skipped', endedAt: now };\n    return skipped;\n  });\n  return { ...state, plan, calls, endedAt: now };\n}\n\nfunction decided(state: ChatState, decision: Decision, now: number): ChatState {\n  if (state.stage !== 'asking') {\n    return state;\n  }\n  if (decision === 'denied') {\n    const declined: ChatState = { ...state, stage: 'declined', decision };\n    return skippedRest(declined, now);\n  }\n  const plan = patchedPlan(state, 'rates', (run) => ({\n    ...run,\n    status: 'running',\n  }));\n  const calls = patchedCalls(state, 'rates', (call) => ({\n    ...call,\n    status: 'running',\n  }));\n  return { ...state, stage: 'working', decision, plan, calls };\n}\n\nfunction answering(state: ChatState): ChatState {\n  if (state.stage !== 'working') {\n    return state;\n  }\n  return { ...state, stage: 'answering' };\n}\n\nfunction answered(state: ChatState, now: number): ChatState {\n  if (state.stage !== 'answering') {\n    return state;\n  }\n  const finished: ChatState = { ...state, stage: 'done', endedAt: now };\n  return withUsage(finished, ANSWER_USAGE);\n}\n\nfunction stopped(state: ChatState, now: number): ChatState {\n  if (!isBusy(state.stage)) {\n    return state;\n  }\n  const halted = skippedRest(state, now);\n  const thoughtEndedAt = state.thoughtEndedAt ?? now;\n  return {\n    ...halted,\n    stage: 'stopped',\n    stoppedFrom: state.stage,\n    thoughtEndedAt,\n  };\n}\n\nfunction newChatTarget(state: ChatState) {\n  if (state.question === null) {\n    return LIVE_ID;\n  }\n  return NEW_ID;\n}\n\nfunction chatOpened(state: ChatState, id: string): ChatState {\n  return { ...state, activeId: id, isSidebarSheetOpen: false };\n}\n\nexport function applyAt(\n  state: ChatState,\n  action: ChatAction,\n  now: number\n): ChatState {\n  switch (action.type) {\n    case 'typed':\n      return { ...state, draft: action.text };\n    case 'sent':\n      return sent(state, now);\n    case 'modelSet':\n      return { ...state, model: action.model };\n    case 'thoughtDone':\n      return thoughtDone(state, now);\n    case 'stepStarted':\n      return stepStarted(state, action.id, now);\n    case 'stepDone':\n      return stepDone(state, action.id, now);\n    case 'asked':\n      return asked(state);\n    case 'decided':\n      return decided(state, action.decision, now);\n    case 'answering':\n      return answering(state);\n    case 'answered':\n      return answered(state, now);\n    case 'stopped':\n      return stopped(state, now);\n    case 'lit':\n      return { ...state, demoLitSource: action.source };\n    case 'panel':\n      return { ...state, isPanelOpen: action.isOpen };\n    case 'detailsSheet':\n      return { ...state, isDetailsSheetOpen: action.isOpen };\n    case 'sidebarCollapsed':\n      return { ...state, isSidebarCollapsed: action.isCollapsed };\n    case 'sidebarSheet':\n      return { ...state, isSidebarSheetOpen: action.isOpen };\n    case 'searched':\n      return { ...state, search: action.text };\n    case 'chatOpened':\n      return chatOpened(state, action.id);\n    case 'newChat':\n      return chatOpened(state, newChatTarget(state));\n    case 'batch': {\n      let next = state;\n      for (const inner of action.actions) {\n        next = applyAt(next, inner, now);\n      }\n      return next;\n    }\n  }\n}\n\nexport function reducer(state: ChatState, action: ChatAction) {\n  return applyAt(state, action, Date.now());\n}\n\nfunction hasAsked(state: ChatState) {\n  return state.question !== null;\n}\n\n/** Whoever answers the request, or a run that ended before it, leaves the stage `asking`. */\nfunction hasDecided(state: ChatState) {\n  return state.stage !== 'asking';\n}\n\nexport const WORD_MS = 55;\n\nexport const ANSWER_WORD_MS = 45;\n\n/** A stream is given a little longer than its words need, so its last word lands before the next step. */\nconst STREAM_MARGIN_MS = 200;\n\nconst KEY_MS = 40;\n\nconst DEMO_DECIDES_AFTER_MS = 2500;\n\nconst THOUGHT_MS = THOUGHT_WORDS.length * WORD_MS + STREAM_MARGIN_MS;\n\nconst ANSWER_MS = ANSWER_TOKENS.length * ANSWER_WORD_MS + STREAM_MARGIN_MS;\n\nfunction typingSteps(text: string, startAfter: number): Step[] {\n  const prefixes = prefixesOf(text);\n  return prefixes.map((typed, index) => ({\n    after: keyDelayOf(index, startAfter, KEY_MS),\n    by: 'demo',\n    action: { type: 'typed', text: typed },\n  }));\n}\n\nfunction frame(after: number, actions: ChatAction[]): Step {\n  return { after, action: { type: 'batch', actions } };\n}\n\nfunction started(id: StepId): ChatAction {\n  return { type: 'stepStarted', id };\n}\n\nfunction done(id: StepId): ChatAction {\n  return { type: 'stepDone', id };\n}\n\nfunction lit(after: number, source: number | null): Step {\n  return { after, by: 'demo', action: { type: 'lit', source } };\n}\n\nfunction detailsSheet(after: number, isOpen: boolean): Step {\n  return { after, by: 'demo', action: { type: 'detailsSheet', isOpen } };\n}\n\n/** On a narrow page the run details live in a sheet, which the demonstration opens and closes as a person would. */\nconst OPENING: Step[] = [\n  {\n    after: 900,\n    by: 'demo',\n    action: { type: 'modelSet', model: DEMO_MODEL },\n  },\n  ...typingSteps(QUESTION, 900),\n  {\n    after: 500,\n    by: 'person',\n    press: 'send',\n    action: { type: 'sent' },\n    isAnswered: hasAsked,\n  },\n  frame(THOUGHT_MS, [{ type: 'thoughtDone' }, started('booking')]),\n  detailsSheet(700, true),\n  frame(1200, [done('booking'), started('sailings')]),\n  frame(1200, [done('sailings'), started('rates')]),\n  detailsSheet(500, false),\n  frame(700, [{ type: 'asked' }]),\n];\n\nconst CLOSING: Step[] = [\n  {\n    after: DEMO_DECIDES_AFTER_MS,\n    by: 'person',\n    press: 'allow',\n    action: { type: 'decided', decision: 'approved' },\n    isAnswered: hasDecided,\n  },\n  frame(1400, [done('rates'), started('customs')]),\n  frame(1200, [done('customs'), started('answer'), { type: 'answering' }]),\n  frame(ANSWER_MS, [done('answer'), { type: 'answered' }]),\n  lit(800, 1),\n  lit(600, 2),\n  lit(600, 3),\n  lit(600, 4),\n  lit(500, null),\n];\n\nexport const SCRIPT: Step[] = [...OPENING, ...CLOSING];\n\nconst ASKED = restingOf(INITIAL, OPENING, applyAt);\n\n/** Under reduced motion the run waits on its request: the steps before it are done and the request to read the rates shows. */\nexport const RESTING: ChatState = {\n  ...ASKED,\n  isDetailsSheetOpen: false,\n  demoLitSource: null,\n};\n\nexport const LOOP_AFTER_MS = 3600;\n",
      "type": "registry:component",
      "target": "components/templates/application-08/session.ts"
    },
    {
      "path": "registry/ndeko/templates/chat/application-08/thinking-block.tsx",
      "content": "'use client';\n\nimport { useId, useState } from 'react';\n\nimport { WordRoll } from '@/components/core/word-roll';\nimport { elapsedOf, formatDuration } from '@/registry/ndeko/lib/agent-run';\nimport { BrainIcon, ChevronDownIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Fold } from '@/registry/ndeko/ui/chat-motion';\nimport { LiveDuration } from '@/registry/ndeko/ui/live-duration';\nimport { StreamedText } from '@/registry/ndeko/ui/streamed-text';\n\nimport { THOUGHT } from './data';\nimport { WORD_MS, type Stage } from './session';\n\nfunction headlineOf(stage: Stage, duration: string) {\n  if (stage === 'thinking') {\n    return 'Thinking';\n  }\n  if (stage === 'stopped') {\n    return `Stopped after ${duration}`;\n  }\n  return `Thought for ${duration}`;\n}\n\nfunction chevronTurnOf(isOpen: boolean) {\n  if (isOpen) {\n    return 'rotate-180';\n  }\n  return 'rotate-0';\n}\n\ntype ThinkingBlockProps = {\n  stage: Stage;\n  isActive: boolean;\n  startedAt?: number;\n  thoughtEndedAt?: number;\n};\n\nexport function ThinkingBlock({\n  stage,\n  isActive,\n  startedAt,\n  thoughtEndedAt,\n}: ThinkingBlockProps) {\n  const [openChoice, setOpenChoice] = useState<boolean | null>(null);\n  const [wasThinking, setWasThinking] = useState(stage === 'thinking');\n  const panelId = useId();\n  const isThinking = stage === 'thinking';\n  const span = { startedAt, endedAt: thoughtEndedAt };\n  const elapsed = elapsedOf(span, thoughtEndedAt ?? 0);\n  const duration = formatDuration(elapsed);\n  const headline = headlineOf(stage, duration);\n\n  if (wasThinking !== isThinking) {\n    setWasThinking(isThinking);\n    setOpenChoice(null);\n  }\n\n  const isOpen = openChoice ?? isThinking;\n\n  function toggle() {\n    setOpenChoice(!isOpen);\n  }\n\n  return (\n    <div className='bg-foreground/[0.03] dark:bg-foreground/[0.05] rounded-xl p-1.5'>\n      <button\n        type='button'\n        aria-expanded={isOpen}\n        aria-controls={panelId}\n        onClick={toggle}\n        className='hover:bg-foreground/[0.04] focus-visible:ring-ring/25 flex h-8 w-full cursor-pointer items-center gap-2 rounded-lg px-2 text-start text-[13px] outline-none focus-visible:ring-[3px]'\n      >\n        <BrainIcon className='text-muted-foreground size-4 shrink-0' />\n        <span className='min-w-0 truncate font-medium'>\n          <WordRoll text={headline} />\n        </span>\n        {isThinking && (\n          <LiveDuration\n            item={span}\n            isRunning\n            className='text-muted-foreground w-10 text-xs'\n          />\n        )}\n        <ChevronDownIcon\n          className={cn(\n            'text-muted-foreground ms-auto size-3.5 shrink-0 transition-transform duration-200 ease-(--ease-out-strong)',\n            chevronTurnOf(isOpen)\n          )}\n        />\n      </button>\n      <Fold open={isOpen} id={panelId}>\n        <p className='text-muted-foreground px-2 pt-1.5 pb-2 text-[13px] leading-relaxed'>\n          <StreamedText\n            text={THOUGHT}\n            isStreaming={isThinking}\n            isActive={isActive}\n            wordMs={WORD_MS}\n          />\n        </p>\n      </Fold>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-08/thinking-block.tsx"
    },
    {
      "path": "registry/ndeko/templates/chat/application-08/thread.tsx",
      "content": "'use client';\n\nimport { useFollowBottom } from '@/registry/ndeko/hooks/use-follow-bottom';\nimport { seriesColorOf } from '@/registry/ndeko/lib/agent-run';\nimport { MeshTile } from '@/registry/ndeko/ui/mesh-tile';\n\nimport { ApprovalCard } from './approval-card';\nimport { CitedAnswer } from './cited-answer';\nimport {\n  ASSISTANT,\n  chatOf,\n  FOLLOW_UP_REPLY,\n  LIVE_ID,\n  LIVE_SUGGESTIONS,\n  NEW_ID,\n  NEW_SUGGESTIONS,\n  type ChatLine,\n} from './data';\nimport {\n  requestViewOf,\n  showsAnswerOf,\n  type ChatState,\n  type Decision,\n} from './session';\nimport { ThinkingBlock } from './thinking-block';\nimport { WorkLine } from './work-line';\n\nfunction AssistantTile() {\n  const color = seriesColorOf(ASSISTANT.series);\n\n  return <MeshTile seed={ASSISTANT.name} color={color} size='lg' />;\n}\n\nfunction PersonBubble({ text }: { text: string }) {\n  return (\n    <p className='bg-foreground/[0.06] max-w-[85%] self-end rounded-2xl rounded-ee-md px-3.5 py-2 text-sm leading-relaxed'>\n      {text}\n    </p>\n  );\n}\n\nfunction AssistantLine({ text }: { text: string }) {\n  return (\n    <div className='flex items-start gap-2.5'>\n      <AssistantTile />\n      <p className='min-w-0 flex-1 pt-1 text-sm leading-relaxed'>{text}</p>\n    </div>\n  );\n}\n\nfunction CannedReply({ text }: { text: string }) {\n  return (\n    <>\n      <PersonBubble text={text} />\n      <div className='flex items-start gap-2.5'>\n        <AssistantTile />\n        <p className='text-muted-foreground min-w-0 flex-1 pt-1 text-sm leading-relaxed'>\n          {FOLLOW_UP_REPLY}\n        </p>\n      </div>\n    </>\n  );\n}\n\nfunction Line({ line }: { line: ChatLine }) {\n  if (line.from === 'person') {\n    return <PersonBubble text={line.text} />;\n  }\n  return <AssistantLine text={line.text} />;\n}\n\ntype EmptyChatProps = {\n  suggestions: string[];\n  onSuggest: (text: string) => void;\n};\n\nfunction EmptyChat({ suggestions, onSuggest }: EmptyChatProps) {\n  return (\n    <div className='m-auto flex w-full max-w-md flex-col items-center gap-5 py-6 text-center'>\n      <div className='flex flex-col items-center gap-1.5'>\n        <h2 className='text-base font-semibold text-balance'>\n          Ask about your shipments\n        </h2>\n        <p className='text-muted-foreground max-w-xs text-[13px] leading-relaxed text-balance'>\n          The plan, every tool call and the cost of the run show in the details\n          while the answer is written.\n        </p>\n      </div>\n      <ul\n        aria-label='Suggested questions'\n        className='flex w-full flex-col gap-1.5'\n      >\n        {suggestions.map((text) => (\n          <li key={text} className='flex'>\n            <button\n              type='button'\n              onClick={() => onSuggest(text)}\n              className='bg-foreground/[0.04] hover:bg-foreground/[0.07] focus-visible:ring-ring/25 w-full cursor-pointer rounded-lg px-3 py-2 text-start text-[13px] transition-[background-color,scale] duration-150 outline-none focus-visible:ring-[3px] active:scale-[0.97]'\n            >\n              {text}\n            </button>\n          </li>\n        ))}\n      </ul>\n    </div>\n  );\n}\n\ntype LiveChatProps = {\n  state: ChatState;\n  pressed: string | null;\n  isActive: boolean;\n  onDecide: (decision: Decision) => void;\n  canShowDetails: boolean;\n  onShowDetails: () => void;\n  onSuggest: (text: string) => void;\n};\n\nfunction LiveChat({\n  state,\n  pressed,\n  isActive,\n  onDecide,\n  canShowDetails,\n  onShowDetails,\n  onSuggest,\n}: LiveChatProps) {\n  const { stage, question } = state;\n  if (question === null) {\n    return <EmptyChat suggestions={LIVE_SUGGESTIONS} onSuggest={onSuggest} />;\n  }\n  const requestView = requestViewOf(state);\n  const showsRequest = requestView !== 'none';\n  const showsPlan = state.plan.length > 0;\n  const showsAnswer = showsAnswerOf(state);\n  const isAnswering = stage === 'answering';\n  const isStoppedMidAnswer =\n    stage === 'stopped' && state.stoppedFrom === 'answering';\n  const isStreaming = isAnswering || isStoppedMidAnswer;\n\n  return (\n    <>\n      <PersonBubble text={question} />\n      <div className='flex items-start gap-2.5'>\n        <AssistantTile />\n        <div className='flex min-w-0 flex-1 flex-col gap-3 pt-1'>\n          <span className='sr-only'>{ASSISTANT.name}</span>\n          <ThinkingBlock\n            stage={stage}\n            isActive={isActive}\n            startedAt={state.startedAt}\n            thoughtEndedAt={state.thoughtEndedAt}\n          />\n          {showsPlan && (\n            <WorkLine\n              plan={state.plan}\n              stage={stage}\n              startedAt={state.startedAt}\n              endedAt={state.endedAt}\n              canShowDetails={canShowDetails}\n              onShowDetails={onShowDetails}\n            />\n          )}\n          {showsRequest && (\n            <ApprovalCard\n              view={requestView}\n              pressed={pressed}\n              onDecide={onDecide}\n            />\n          )}\n          {showsAnswer && (\n            <CitedAnswer\n              isStreaming={isStreaming}\n              isRunning={isAnswering && isActive}\n              demoLitSource={state.demoLitSource}\n            />\n          )}\n        </div>\n      </div>\n      {state.followUps.map((text, index) => (\n        <CannedReply key={index} text={text} />\n      ))}\n    </>\n  );\n}\n\ntype ThreadProps = LiveChatProps;\n\nexport function Thread(props: ThreadProps) {\n  const { scrollerRef, contentRef, updatePinned } = useFollowBottom();\n  const { activeId, newLines } = props.state;\n  const isLive = activeId === LIVE_ID;\n  const isNew = activeId === NEW_ID;\n  const isPast = !isLive && !isNew;\n  const hasNewLines = newLines.length > 0;\n\n  return (\n    <div\n      ref={scrollerRef}\n      onScroll={updatePinned}\n      className='min-h-0 flex-1 overflow-y-auto'\n    >\n      <div\n        ref={contentRef}\n        className='mx-auto flex min-h-full w-full max-w-2xl flex-col gap-5 px-4 py-5'\n      >\n        {isLive && <LiveChat {...props} />}\n        {isNew && !hasNewLines && (\n          <EmptyChat\n            suggestions={NEW_SUGGESTIONS}\n            onSuggest={props.onSuggest}\n          />\n        )}\n        {isNew &&\n          newLines.map((text, index) => (\n            <CannedReply key={index} text={text} />\n          ))}\n        {isPast &&\n          chatOf(activeId).lines.map((line, index) => (\n            <Line key={index} line={line} />\n          ))}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-08/thread.tsx"
    },
    {
      "path": "registry/ndeko/templates/chat/application-08/work-line.tsx",
      "content": "'use client';\n\nimport { WordRoll } from '@/components/core/word-roll';\nimport {\n  elapsedOf,\n  formatDuration,\n  type CallStatus,\n} from '@/registry/ndeko/lib/agent-run';\nimport { CircleXIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { CallStatusMark } from '@/registry/ndeko/ui/call-status';\nimport { LiveDuration } from '@/registry/ndeko/ui/live-duration';\n\nimport { PLAN, planSeedOf } from './data';\nimport type { PlanRun, Stage, StepStatus } from './session';\n\nconst TITLES = PLAN.map((seed) => seed.title);\n\nconst SEGMENT_TONE: Record<StepStatus, string> = {\n  upcoming: 'bg-foreground/10',\n  running: 'bg-primary/45 animate-pulse',\n  waiting: 'bg-warning',\n  done: 'bg-primary',\n  skipped: 'bg-foreground/10',\n};\n\nconst STEP_WORD: Record<StepStatus, string> = {\n  upcoming: 'to do',\n  running: 'running',\n  waiting: 'waiting on you',\n  done: 'done',\n  skipped: 'skipped',\n};\n\nfunction currentRunOf(plan: PlanRun[]) {\n  const live = plan.find((run) => run.status === 'running');\n  if (live) {\n    return live;\n  }\n  return plan.find((run) => run.status === 'waiting');\n}\n\nfunction titleOf(plan: PlanRun[], stage: Stage, duration: string) {\n  if (stage === 'done') {\n    return `Worked for ${duration}`;\n  }\n  if (stage === 'declined') {\n    return 'Run stopped at the request';\n  }\n  if (stage === 'stopped') {\n    return 'Stopped by you';\n  }\n  const current = currentRunOf(plan);\n  if (!current) {\n    return 'Working';\n  }\n  return planSeedOf(current.id).title;\n}\n\nfunction isClockRunning(stage: Stage) {\n  return stage === 'working' || stage === 'answering';\n}\n\nfunction markOf(stage: Stage): CallStatus {\n  if (stage === 'asking') {\n    return 'waiting';\n  }\n  if (stage === 'done') {\n    return 'done';\n  }\n  return 'running';\n}\n\ntype WorkLineProps = {\n  plan: PlanRun[];\n  stage: Stage;\n  startedAt?: number;\n  endedAt?: number;\n  /** False while the details are already on screen. */\n  canShowDetails: boolean;\n  onShowDetails: () => void;\n};\n\nexport function WorkLine({\n  plan,\n  stage,\n  startedAt,\n  endedAt,\n  canShowDetails,\n  onShowDetails,\n}: WorkLineProps) {\n  const span = { startedAt, endedAt };\n  const elapsed = elapsedOf(span, endedAt ?? 0);\n  const duration = formatDuration(elapsed);\n  const title = titleOf(plan, stage, duration);\n  const isHalted = stage === 'declined' || stage === 'stopped';\n  const isWaiting = stage === 'asking';\n\n  return (\n    <div className='flex flex-col gap-2 px-1'>\n      <div className='flex h-7 items-center gap-2 text-[13px]'>\n        {!isHalted && <CallStatusMark status={markOf(stage)} />}\n        {isHalted && (\n          <CircleXIcon className='text-muted-foreground size-4 shrink-0' />\n        )}\n        <span className='min-w-0 truncate font-medium'>\n          <WordRoll text={title} labels={TITLES} />\n        </span>\n        {isClockRunning(stage) && (\n          <LiveDuration\n            item={span}\n            isRunning\n            className='text-muted-foreground w-10 shrink-0 text-xs'\n          />\n        )}\n        {isWaiting && (\n          <span className='text-warning-foreground shrink-0 text-xs'>\n            Waiting on you\n          </span>\n        )}\n        {canShowDetails && (\n          <Button\n            type='button'\n            variant='ghost'\n            size='sm'\n            onClick={onShowDetails}\n            className='text-muted-foreground ms-auto h-6 shrink-0 px-2'\n          >\n            Run details\n          </Button>\n        )}\n      </div>\n      <ol aria-label='Steps of the run' className='flex gap-1'>\n        {plan.map((run) => {\n          const seed = planSeedOf(run.id);\n          return (\n            <li\n              key={run.id}\n              className={cn(\n                'h-1 min-w-0 flex-1 rounded-full transition-colors duration-300',\n                SEGMENT_TONE[run.status]\n              )}\n            >\n              <span className='sr-only'>\n                {seed.title}, {STEP_WORD[run.status]}\n              </span>\n            </li>\n          );\n        })}\n      </ol>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-08/work-line.tsx"
    }
  ],
  "categories": [
    "templates",
    "chat"
  ],
  "type": "registry:block"
}