{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "thought-trail-research-demo",
  "type": "registry:block",
  "title": "Thought Trail: Research Agent",
  "description": "AI Reasoning Steps example, Research Agent: Steps with their own icons. Sources collect as chips while the agent searches, pages tick off as it reads, and the answer cites what it found once the trail folds away. Open Found 9 sources to see them again. A take on the AI thinking state (reasoning). Fits features and app UI sections.",
  "author": "KeyframeUI <https://keyframeui.com>",
  "categories": [
    "features",
    "app-ui",
    "ai-thinking-state",
    "steps",
    "accordion",
    "ai-chat",
    "ai",
    "status",
    "motion"
  ],
  "docs": "Live preview, examples and props: https://keyframeui.com/components/thought-trail#thought-trail-research-demo",
  "registryDependencies": [
    "https://keyframeui.com/r/thought-trail.json"
  ],
  "files": [
    {
      "path": "components/thought-trail-research-demo.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useInView } from \"motion/react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { ThoughtTrail, ThoughtTrailStep } from \"@/components/ui/thought-trail\";\n\nconst question = \"Which vector database should we use for 10M embeddings?\";\n\ntype Source = { domain: string; tint: string };\n\n// Monograms instead of favicons, so the demo needs no network.\nconst sources: Source[] = [\n  { domain: \"github.com\", tint: \"bg-zinc-900 text-white dark:bg-zinc-100 dark:text-zinc-900\" },\n  { domain: \"qdrant.tech\", tint: \"bg-rose-500/15 text-rose-700 dark:text-rose-300\" },\n  { domain: \"pinecone.io\", tint: \"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300\" },\n  { domain: \"news.ycombinator.com\", tint: \"bg-orange-500/15 text-orange-700 dark:text-orange-300\" },\n  { domain: \"supabase.com\", tint: \"bg-teal-500/15 text-teal-700 dark:text-teal-300\" },\n  { domain: \"weaviate.io\", tint: \"bg-lime-500/15 text-lime-700 dark:text-lime-300\" },\n  { domain: \"timescale.com\", tint: \"bg-amber-500/15 text-amber-700 dark:text-amber-300\" },\n  { domain: \"ann-benchmarks.com\", tint: \"bg-sky-500/15 text-sky-700 dark:text-sky-300\" },\n  { domain: \"aws.amazon.com\", tint: \"bg-violet-500/15 text-violet-700 dark:text-violet-300\" },\n];\n\nconst searches = [\n  \"pgvector vs dedicated vector databases at 10M rows\",\n  \"HNSW memory use for 1536-dimension embeddings\",\n  \"Filtered vector search at high query rates\",\n];\n\nconst reads = [\n  { title: \"HNSW vs IVFFlat indexes in pgvector\", source: 0 },\n  { title: \"Payload indexes and filtered search\", source: 1 },\n  { title: \"Choosing an index for tens of millions of vectors\", source: 2 },\n  { title: \"Ask HN: Running pgvector in production?\", source: 3 },\n];\n\nconst comparison =\n  \"Ten million 1536-dimension vectors is about 60 GB of floats before the index, which still fits one large Postgres instance. pgvector keeps vectors next to the rows they describe, so there's no second system to sync. Qdrant and Pinecone pull ahead when filters get heavy at high query rates, or when the index outgrows one machine.\";\n\ntype Phase = { title: string; summary: string; ms: number; icon: React.ReactNode };\n\nconst phases: Phase[] = [\n  { title: \"Planning the search\", summary: \"Planned 3 searches\", ms: 2200, icon: <ListIcon /> },\n  { title: \"Searching the web\", summary: `Found ${sources.length} sources`, ms: 3000, icon: <GlobeIcon /> },\n  { title: `Reading ${reads.length} pages`, summary: `Read ${reads.length} pages`, ms: 3600, icon: <PageIcon /> },\n  { title: \"Comparing the options\", summary: \"Compared 3 options\", ms: 3400, icon: <ScaleIcon /> },\n];\n\nconst LEAD = 600;\nconst starts = phases.map((_, i) => LEAD + phases.slice(0, i).reduce((sum, p) => sum + p.ms, 0));\nconst END = LEAD + phases.reduce((sum, p) => sum + p.ms, 0);\n\n/** Milliseconds into the current run, from when the demo first scrolls into view. Stops at `end`. */\nfunction usePlayhead(run: number, playing: boolean, end: number) {\n  const [clock, setClock] = React.useState({ run, t: 0 });\n  React.useEffect(() => {\n    if (!playing) return;\n    const start = performance.now();\n    const timer = window.setInterval(() => {\n      const t = Math.min(end, performance.now() - start);\n      setClock({ run, t });\n      if (t >= end) window.clearInterval(timer);\n    }, 50);\n    return () => window.clearInterval(timer);\n  }, [run, playing, end]);\n  return clock.run === run ? clock.t : 0;\n}\n\n// A research agent. Sources collect as chips while it searches, pages tick\n// off as it reads them, and once it's done the trail folds away and the\n// answer cites what it found. Open \"Found 9 sources\" to see them all again.\nexport function ThoughtTrailResearchDemo() {\n  const ref = React.useRef<HTMLDivElement>(null);\n  const playing = useInView(ref, { once: true, amount: 0.4 });\n  const [run, setRun] = React.useState(0);\n  const t = usePlayhead(run, playing, END + 300);\n  const finished = t >= END;\n\n  return (\n    <div\n      ref={ref}\n      className=\"flex h-[34rem] w-full max-w-2xl flex-col overflow-hidden rounded-2xl border border-zinc-200 bg-white shadow-sm shadow-zinc-950/5 dark:border-zinc-800 dark:bg-zinc-950 dark:shadow-black/40\"\n    >\n      <div className=\"flex items-start gap-4 border-b border-zinc-100 px-5 py-4 dark:border-zinc-800/80\">\n        <div className=\"min-w-0 flex-1\">\n          <span className=\"inline-flex items-center gap-1 rounded-full bg-zinc-100 px-2 py-0.5 text-[11px] font-medium text-zinc-600 dark:bg-zinc-800 dark:text-zinc-300\">\n            <span aria-hidden className=\"size-3 [&_svg]:size-3\">\n              <GlobeIcon />\n            </span>\n            Deep research\n          </span>\n          <p className=\"mt-2 text-[15px] leading-snug font-medium text-pretty text-zinc-900 dark:text-zinc-100\">\n            {question}\n          </p>\n        </div>\n        <button\n          type=\"button\"\n          onClick={() => setRun((r) => r + 1)}\n          className=\"inline-flex h-8 shrink-0 items-center rounded-lg px-2.5 text-xs font-medium text-zinc-600 transition-[background-color,color,scale] duration-150 outline-none select-none hover:bg-zinc-100 hover:text-zinc-950 focus-visible:ring-2 focus-visible:ring-zinc-400 active:scale-[0.96] dark:text-zinc-400 dark:hover:bg-zinc-800 dark:hover:text-zinc-50 dark:focus-visible:ring-zinc-600\"\n        >\n          Run again\n        </button>\n      </div>\n\n      <div className=\"min-h-0 flex-1 overflow-y-auto px-5 py-4\">\n        {playing ? (\n          <ThoughtTrail\n            running={!finished}\n            label=\"Researching\"\n            doneLabel={({ seconds }) => `Researched for ${seconds ?? 0}s · ${sources.length} sources`}\n          >\n            {phases.map((phase, i) => {\n              if (t < starts[i]) return null;\n              const progress = Math.min(1, (t - starts[i]) / (phase.ms * 0.85));\n              const done = t >= starts[i] + phase.ms;\n              return (\n                <ThoughtTrailStep\n                  key={phase.title}\n                  status={done ? \"done\" : \"active\"}\n                  title={phase.title}\n                  summary={phase.summary}\n                  icon={phase.icon}\n                  meta={i === 1 ? `${Math.ceil(progress * sources.length)}` : undefined}\n                >\n                  <PhaseDetails index={i} progress={progress} />\n                </ThoughtTrailStep>\n              );\n            })}\n          </ThoughtTrail>\n        ) : null}\n\n        <AnimatePresence>\n          {finished ? (\n            <motion.div\n              key={run}\n              initial={{ opacity: 0, y: 8 }}\n              animate={{ opacity: 1, y: 0 }}\n              transition={{ duration: 0.35, ease: \"easeOut\", delay: 0.2 }}\n              className=\"mt-4 space-y-3 text-sm leading-relaxed text-pretty text-zinc-800 dark:text-zinc-200\"\n            >\n              <p>\n                <strong className=\"font-semibold text-zinc-950 dark:text-zinc-50\">Start with pgvector</strong> if\n                you&apos;re already on Postgres. At 10M vectors an HNSW index still fits one large instance, and you\n                keep a single database to run and back up. <Cite n={1} /> <Cite n={4} />\n              </p>\n              <p>\n                Move to a dedicated engine like Qdrant when filtered queries at high traffic start to dominate, or\n                the index needs to shard across machines. <Cite n={2} /> <Cite n={3} />\n              </p>\n            </motion.div>\n          ) : null}\n        </AnimatePresence>\n      </div>\n    </div>\n  );\n}\n\nfunction PhaseDetails({ index, progress }: { index: number; progress: number }) {\n  if (index === 0) {\n    return (\n      <ul className=\"space-y-1\">\n        {searches.slice(0, Math.ceil(progress * searches.length)).map((query) => (\n          <li key={query} className=\"flex items-center gap-2\">\n            <span aria-hidden className=\"size-3 shrink-0 text-zinc-400 dark:text-zinc-500 [&_svg]:size-3\">\n              <SearchIcon />\n            </span>\n            <span className=\"truncate\">{query}</span>\n          </li>\n        ))}\n      </ul>\n    );\n  }\n\n  if (index === 1) {\n    return (\n      <div className=\"flex flex-wrap gap-1.5\">\n        {sources.slice(0, Math.ceil(progress * sources.length)).map((source) => (\n          <motion.span\n            key={source.domain}\n            initial={{ opacity: 0, scale: 0.85 }}\n            animate={{ opacity: 1, scale: 1 }}\n            transition={{ type: \"spring\", visualDuration: 0.25, bounce: 0.3 }}\n            className=\"inline-flex items-center gap-1.5 rounded-full border border-zinc-200 bg-white py-0.5 pr-2 pl-0.5 text-xs text-zinc-600 dark:border-zinc-800 dark:bg-zinc-900 dark:text-zinc-400\"\n          >\n            <Monogram source={source} />\n            {source.domain}\n          </motion.span>\n        ))}\n      </div>\n    );\n  }\n\n  if (index === 2) {\n    return (\n      <ul className=\"space-y-1.5\">\n        {reads.map((page, i) => {\n          // Pages are read one after another across the step.\n          const read = progress >= (i + 1) / reads.length;\n          const reading = !read && progress >= i / reads.length;\n          return (\n            <li\n              key={page.title}\n              className={cn(\n                \"flex min-w-0 items-center gap-2 transition-opacity duration-300\",\n                !read && !reading && \"opacity-40\",\n              )}\n            >\n              <Monogram source={sources[page.source]} />\n              <span className={cn(\"truncate\", reading && \"text-zinc-900 dark:text-zinc-100\")}>{page.title}</span>\n              <span className=\"ml-auto shrink-0 text-xs text-zinc-400 dark:text-zinc-500\">\n                {read ? \"Read\" : reading ? \"Reading…\" : \"\"}\n              </span>\n            </li>\n          );\n        })}\n      </ul>\n    );\n  }\n\n  const words = comparison.split(\" \");\n  return <p className=\"text-pretty\">{words.slice(0, Math.ceil(progress * words.length)).join(\" \")}</p>;\n}\n\nfunction Monogram({ source }: { source: Source }) {\n  return (\n    <span\n      aria-hidden\n      className={cn(\n        \"flex size-4 shrink-0 items-center justify-center rounded-full text-[9px] font-semibold uppercase\",\n        source.tint,\n      )}\n    >\n      {source.domain[0]}\n    </span>\n  );\n}\n\nfunction Cite({ n }: { n: number }) {\n  const source = sources[reads[n - 1].source];\n  return (\n    <span\n      title={source.domain}\n      className=\"inline-flex h-4 min-w-4 -translate-y-px items-center justify-center rounded bg-zinc-100 px-1 align-middle text-[10px] font-medium text-zinc-500 tabular-nums dark:bg-zinc-800 dark:text-zinc-400\"\n    >\n      {n}\n    </span>\n  );\n}\n\nfunction GlobeIcon() {\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden>\n      <circle cx=\"8\" cy=\"8\" r=\"6.25\" stroke=\"currentColor\" strokeWidth=\"1.4\" />\n      <path d=\"M1.75 8h12.5M8 1.75c1.8 1.7 2.6 3.8 2.6 6.25S9.8 12.55 8 14.25C6.2 12.55 5.4 10.45 5.4 8S6.2 3.45 8 1.75Z\" stroke=\"currentColor\" strokeWidth=\"1.4\" />\n    </svg>\n  );\n}\n\nfunction SearchIcon() {\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden>\n      <circle cx=\"7\" cy=\"7\" r=\"4.25\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n      <path d=\"M10.25 10.25 13.5 13.5\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n    </svg>\n  );\n}\n\nfunction ListIcon() {\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden>\n      <path d=\"M6 4h7.5M6 8h7.5M6 12h7.5M2.75 4h.5M2.75 8h.5M2.75 12h.5\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n    </svg>\n  );\n}\n\nfunction PageIcon() {\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden>\n      <path d=\"M4 1.75h5L12.25 5v9.25H4z M9 1.75V5h3.25\" stroke=\"currentColor\" strokeWidth=\"1.4\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\n\nfunction ScaleIcon() {\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden>\n      <path\n        d=\"M8 2v12M4.5 14h7M3 4.5h10M3 4.5 1.25 9a2 2 0 0 0 3.5 0L3 4.5Zm10 0L11.25 9a2 2 0 0 0 3.5 0L13 4.5Z\"\n        stroke=\"currentColor\"\n        strokeWidth=\"1.3\"\n        strokeLinejoin=\"round\"\n        strokeLinecap=\"round\"\n      />\n    </svg>\n  );\n}\n"
    }
  ]
}