{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chat-03",
  "title": "Reasoning and tool calls",
  "description": "A reply that shows how long it thought, folds its reasoning, runs two tool calls from running to done and cites its sources.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-loader.json",
    "https://ui.ndekocode.dev/r/chat-message.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/chat-reasoning.json",
    "https://ui.ndekocode.dev/r/chat-response-stream.json",
    "https://ui.ndekocode.dev/r/chat-source.json",
    "https://ui.ndekocode.dev/r/chat-tool.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/chat/chat-03/index.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useEffect, useRef, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { FeatherIcon, RotateCcwIcon } from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { TextLoader } from '@/registry/ndeko/ui/chat-loader';\nimport {\n  Message,\n  MessageAvatar,\n  MessageContent,\n  MessageGlyph,\n} from '@/registry/ndeko/ui/chat-message';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport {\n  Reasoning,\n  ReasoningContent,\n  ReasoningTrigger,\n} from '@/registry/ndeko/ui/chat-reasoning';\nimport {\n  ResponseStreamSegments,\n  useTextStream,\n} from '@/registry/ndeko/ui/chat-response-stream';\nimport {\n  Tool,\n  type ToolPart,\n  type ToolState,\n} from '@/registry/ndeko/ui/chat-tool';\n\nimport {\n  answer,\n  asker,\n  finishedStep,\n  question,\n  reasoning,\n  reasoningWordMs,\n  runSchedule,\n  thoughtLabel,\n  toolCalls,\n  type RunStep,\n  type ToolCall,\n} from './data';\nimport { rowPresenceOf } from './presence';\nimport { ReplySources } from './reply-sources';\n\nfunction toolStateOf(tool: ToolCall, step: RunStep): ToolState {\n  const isDone = step >= tool.doneAt;\n  if (isDone) {\n    return 'output-available';\n  }\n  return 'input-available';\n}\n\nfunction outputOf(tool: ToolCall, state: ToolState) {\n  const isDone = state === 'output-available';\n  if (isDone) {\n    return tool.output;\n  }\n  return undefined;\n}\n\nfunction toolPartOf(tool: ToolCall, step: RunStep): ToolPart {\n  const state = toolStateOf(tool, step);\n  return {\n    type: tool.type,\n    state,\n    input: tool.input,\n    output: outputOf(tool, state),\n    toolCallId: tool.toolCallId,\n  };\n}\n\nfunction hasAppeared(tool: ToolCall, step: RunStep) {\n  return step >= tool.appearsAt;\n}\n\nfunction ReasoningBody({\n  isRunning,\n  segments,\n}: {\n  isRunning: boolean;\n  segments: ReturnType<typeof useTextStream>['segments'];\n}) {\n  if (isRunning) {\n    return <ResponseStreamSegments segments={segments} />;\n  }\n  return reasoning;\n}\n\nfunction Reply03() {\n  const [step, setStep] = useState<RunStep>(finishedStep);\n  const [reasoningSource, setReasoningSource] = useState('');\n  const timers = useRef(new Set<ReturnType<typeof setTimeout>>());\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n  const isRunning = step < finishedStep;\n  const isFinished = !isRunning;\n  const visibleTools = toolCalls.filter((tool) => hasAppeared(tool, step));\n  const reasoningStream = useTextStream({\n    textStream: reasoningSource,\n    mode: 'fade',\n    segmentDelay: reasoningWordMs,\n  });\n\n  useEffect(() => {\n    const pending = timers.current;\n    return () => {\n      pending.forEach((timer) => clearTimeout(timer));\n    };\n  }, []);\n\n  function schedule(task: () => void, delay: number) {\n    const timer = setTimeout(() => {\n      timers.current.delete(timer);\n      task();\n    }, delay);\n    timers.current.add(timer);\n  }\n\n  function runAgain() {\n    if (isRunning) {\n      return;\n    }\n    setStep(0);\n    setReasoningSource(reasoning);\n    reasoningStream.startStreaming();\n    for (const entry of runSchedule) {\n      schedule(() => setStep(entry.step), entry.atMs);\n    }\n  }\n\n  return (\n    <div className='bg-background text-foreground min-h-dvh w-full px-4 py-8 sm:px-6 sm:py-10'>\n      <div className='mx-auto flex max-w-2xl flex-col gap-6'>\n        <Message className='justify-end'>\n          <MessageContent className='max-w-[85%] sm:max-w-[75%]'>\n            {question}\n          </MessageContent>\n          <MessageAvatar alt={asker.name} className='hidden sm:inline-flex' />\n        </Message>\n\n        <Message>\n          <MessageGlyph>\n            <FeatherIcon />\n          </MessageGlyph>\n          <div className='min-w-0 flex-1 space-y-3 pt-1.5'>\n            <Reasoning isStreaming={isRunning}>\n              <ReasoningTrigger>\n                <Swap swapKey={String(isRunning)}>\n                  {isRunning && <TextLoader text='Thinking' />}\n                  {isFinished && thoughtLabel}\n                </Swap>\n              </ReasoningTrigger>\n              <ReasoningContent>\n                <ReasoningBody\n                  isRunning={isRunning}\n                  segments={reasoningStream.segments}\n                />\n              </ReasoningContent>\n            </Reasoning>\n\n            <ul aria-label='Tool calls' className='flex flex-col'>\n              <AnimatePresence initial={false}>\n                {visibleTools.map((tool) => (\n                  <motion.li\n                    key={tool.id}\n                    className='-mx-1 overflow-hidden px-1'\n                    {...rowPresence}\n                  >\n                    <div className='pb-2'>\n                      <Tool toolPart={toolPartOf(tool, step)} />\n                    </div>\n                  </motion.li>\n                ))}\n              </AnimatePresence>\n            </ul>\n\n            <AnimatePresence initial={false}>\n              {isFinished && (\n                <motion.div\n                  key='answer'\n                  className='-mx-1 overflow-hidden px-1'\n                  {...rowPresence}\n                >\n                  <div className='space-y-4 pb-1'>\n                    <MessageContent markdown variant='plain'>\n                      {answer}\n                    </MessageContent>\n                    <ReplySources />\n                    <Button\n                      type='button'\n                      variant='ghost'\n                      size='sm'\n                      onClick={runAgain}\n                      className='text-muted-foreground -ms-2'\n                    >\n                      <RotateCcwIcon />\n                      Run again\n                    </Button>\n                  </div>\n                </motion.div>\n              )}\n            </AnimatePresence>\n          </div>\n        </Message>\n      </div>\n    </div>\n  );\n}\n\nexport default Reply03;\n",
      "type": "registry:component",
      "target": "components/blocks/chat-03/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/chat/chat-03/reply-sources.tsx",
      "content": "import {\n  Source,\n  SourceContent,\n  SourceTrigger,\n} from '@/registry/ndeko/ui/chat-source';\n\nimport { sources } from './data';\n\nexport function ReplySources() {\n  return (\n    <div className='space-y-2'>\n      <p className='text-muted-foreground text-xs font-medium'>Sources</p>\n      <ul className='flex flex-wrap gap-1.5'>\n        {sources.map((source) => (\n          <li key={source.href}>\n            <Source href={source.href}>\n              <SourceTrigger label={source.title} showMark />\n              <SourceContent\n                title={source.title}\n                description={source.description}\n              />\n            </Source>\n          </li>\n        ))}\n      </ul>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/chat-03/reply-sources.tsx"
    },
    {
      "path": "registry/ndeko/blocks/chat/chat-03/presence.ts",
      "content": "import type { MotionProps, Transition } from 'motion/react';\n\ntype PresenceProps = Pick<\n  MotionProps,\n  'initial' | 'animate' | 'exit' | 'transition'\n>;\n\nconst EASE_OUT_STRONG: [number, number, number, number] = [0.23, 1, 0.32, 1];\n\nconst ENTER: Transition = { duration: 0.2, ease: EASE_OUT_STRONG };\n\nconst EXIT: Transition = { duration: 0.14, ease: EASE_OUT_STRONG };\n\nconst ROW_PRESENCE: PresenceProps = {\n  initial: { height: 0, opacity: 0 },\n  animate: { height: 'auto', opacity: 1 },\n  exit: { height: 0, opacity: 0, transition: EXIT },\n  transition: ENTER,\n};\n\nconst FADE_PRESENCE: PresenceProps = {\n  initial: { opacity: 0 },\n  animate: { opacity: 1 },\n  exit: { opacity: 0, transition: EXIT },\n  transition: ENTER,\n};\n\nexport function rowPresenceOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_PRESENCE;\n  }\n  return ROW_PRESENCE;\n}\n",
      "type": "registry:component",
      "target": "components/blocks/chat-03/presence.ts"
    },
    {
      "path": "registry/ndeko/blocks/chat/chat-03/data.ts",
      "content": "export type RunStep = 0 | 1 | 2 | 3 | 4 | 5;\n\nexport const finishedStep: RunStep = 5;\n\nexport type ScheduledStep = {\n  step: RunStep;\n  atMs: number;\n};\n\nexport const runSchedule: ScheduledStep[] = [\n  { step: 1, atMs: 500 },\n  { step: 2, atMs: 1700 },\n  { step: 3, atMs: 2000 },\n  { step: 4, atMs: 3400 },\n  { step: 5, atMs: 4000 },\n];\n\nexport type ToolCall = {\n  id: string;\n  type: string;\n  toolCallId: string;\n  appearsAt: RunStep;\n  doneAt: RunStep;\n  input: Record<string, unknown>;\n  output: Record<string, unknown>;\n};\n\nexport type CitedSource = {\n  href: string;\n  title: string;\n  description: string;\n};\n\nexport const asker = {\n  name: 'Jonas Weber',\n};\n\nexport const question =\n  'Check the API reference against the changelog and tell me what changed in 2.4';\n\nexport const reasoning =\n  'The API reference was last edited on 12 March, before 2.4 shipped, so it is probably behind. I will find the 2.4 entry in the changelog first, then read the parts of the API reference it touches: pagination, rate limits and the comment endpoints.';\n\nexport const thoughtLabel = 'Thought for 4 seconds';\n\nexport const answer = [\n  'Three changes from 2.4 are missing from the API reference:',\n  '',\n  '1. **Pagination** on `/documents` moved from `page` to `cursor`.',\n  '2. Workspace tokens now get 120 requests a minute instead of 60.',\n  '3. `DELETE /comments/{id}` is new and not listed yet.',\n  '',\n  'The reference also still documents `archived=true` on `/spaces`, which 2.4 removed. I can draft the edits as suggestions on the page.',\n].join('\\n');\n\nexport const toolCalls: ToolCall[] = [\n  {\n    id: 'search',\n    type: 'search_pages',\n    toolCallId: 'call_7hq2',\n    appearsAt: 1,\n    doneAt: 2,\n    input: { query: 'changelog 2.4', space: 'Engineering' },\n    output: {\n      matches: 3,\n      best: 'Changelog / 2.4',\n      updated: '2026-10-21',\n    },\n  },\n  {\n    id: 'read',\n    type: 'read_page',\n    toolCallId: 'call_9kd4',\n    appearsAt: 3,\n    doneAt: 4,\n    input: { page: 'API reference', sections: ['Pagination', 'Rate limits'] },\n    output: {\n      words: 1240,\n      lastEdited: '2026-03-12',\n      endpoints: ['/documents', '/spaces', '/comments'],\n    },\n  },\n];\n\nexport const sources: CitedSource[] = [\n  {\n    href: 'https://docs.quillstone.example/engineering/changelog#2-4',\n    title: 'Changelog, 2.4',\n    description:\n      'Cursor pagination, higher limits for workspace tokens and comment deletion.',\n  },\n  {\n    href: 'https://docs.quillstone.example/engineering/api-reference',\n    title: 'API reference',\n    description:\n      'Endpoints, parameters and errors of the public API, last edited in March.',\n  },\n  {\n    href: 'https://docs.quillstone.example/engineering/rate-limits',\n    title: 'Rate limits',\n    description:\n      'How requests are counted per token and what happens past the limit.',\n  },\n];\n\nexport const reasoningWordMs = 55;\n",
      "type": "registry:component",
      "target": "components/blocks/chat-03/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "chat"
  ],
  "type": "registry:block"
}