{
  "schemaVersion": 1,
  "target": "react",
  "name": "chain-of-thought",
  "version": "0.1.0",
  "category": "ai-elements",
  "title": "Chain of Thought",
  "description": "A summary line that expands into the ordered steps an agent took, each on a hairline rail with a status glyph, the sources it read, and any images.",
  "tags": [
    "ai",
    "agent",
    "reasoning",
    "steps",
    "sources",
    "search",
    "collapsible"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {
    "@base-ui/react": "^1.9.0"
  },
  "registryDependencies": [
    {
      "name": "agent-state",
      "version": "0.1.0"
    },
    {
      "name": "step-list",
      "version": "0.3.0"
    }
  ],
  "docsPath": "/components/chain-of-thought",
  "props": [
    {
      "name": "steps",
      "type": "{ id, label, status?, detail?, activity?, results?, images?, content? }[]",
      "description": "Steps in order. status is queued, running, done (default), failed, or skipped. results are { title, url } sources; images are { src, alt, caption? }."
    },
    {
      "name": "summary",
      "type": "ReactNode",
      "default": "\"Took N steps\"",
      "description": "The collapsed line once finished. While a step runs, the line shows that step with its live mark instead."
    },
    {
      "name": "open / defaultOpen / onOpenChange",
      "type": "boolean / boolean / (open) => void",
      "default": "defaultOpen false",
      "description": "Controlled or uncontrolled open state."
    },
    {
      "name": "maxResults",
      "type": "number",
      "default": "4",
      "description": "Sources shown per step before the rest fold into \"+N\"."
    }
  ],
  "accessibility": [
    "Built on Base UI Collapsible: the summary line is a button with aria-expanded, operable with Enter and Space.",
    "Every step has a screen-reader status after its label; glyphs and marks are decorative. Skipped steps are struck through and labeled.",
    "Source links name the page title before the host name, so the accessible name includes the visible text. They open in a new tab.",
    "Images require alt text. The list is aria-busy while a step runs.",
    "With reduced motion the marks hold still and steps, glyphs, and the panel appear without animation."
  ],
  "states": [
    "running",
    "done",
    "failed",
    "collapsed",
    "expanded"
  ],
  "files": [
    {
      "path": "agent/chain-of-thought.tsx",
      "content": "\"use client\";\n\nimport { Collapsible } from \"@base-ui/react/collapsible\";\nimport type { ReactNode } from \"react\";\nimport { type AgentActivity, AgentMark } from \"./agent-state\";\nimport { StatusGlyph, type StatusGlyphKind } from \"./step-list\";\n\nfunction cx(...classes: Array<string | false | null | undefined>) {\n  return classes.filter(Boolean).join(\" \");\n}\n\nconst ease = \"ease-[cubic-bezier(0.23,1,0.32,1)]\";\n\nexport type ChainOfThoughtStatus = \"queued\" | \"running\" | \"done\" | \"failed\" | \"skipped\";\n\nconst glyphs: Record<Exclude<ChainOfThoughtStatus, \"running\">, StatusGlyphKind> = {\n  queued: \"queued\",\n  done: \"success\",\n  failed: \"failed\",\n  skipped: \"skipped\",\n};\n\nconst spoken: Record<ChainOfThoughtStatus, string> = {\n  queued: \"Queued\",\n  running: \"In progress\",\n  done: \"Done\",\n  failed: \"Failed\",\n  skipped: \"Skipped\",\n};\n\nexport interface ChainOfThoughtResult {\n  /** Page title. Read by screen readers before the host name. */\n  title: string;\n  url: string;\n}\n\nexport interface ChainOfThoughtImage {\n  src: string;\n  alt: string;\n  caption?: ReactNode;\n}\n\nexport interface ChainOfThoughtStep {\n  id: string;\n  /** What the agent did, in a few words: \"Searched for rate limit docs\". */\n  label: ReactNode;\n  /** @default \"done\" */\n  status?: ChainOfThoughtStatus;\n  /** A secondary line: what it found, or why it failed. */\n  detail?: ReactNode;\n  /** Which Agent State mark moves while this step runs. Defaults to thinking. */\n  activity?: AgentActivity;\n  /** Sources the step looked at, shown as host name links. */\n  results?: ChainOfThoughtResult[];\n  /** Images the step looked at or produced, shown as a small grid of thumbnails. */\n  images?: ChainOfThoughtImage[];\n  /** Any extra content under the step, for example a quoted snippet. */\n  content?: ReactNode;\n}\n\nexport interface ChainOfThoughtProps {\n  steps: ChainOfThoughtStep[];\n  /**\n   * The collapsed line once the agent has finished, for example \"Checked 6 sources\". While a\n   * step runs, the line shows that step instead. Defaults to \"Took N steps\".\n   */\n  summary?: ReactNode;\n  /** Controlled open state. Pair with `onOpenChange`. */\n  open?: boolean;\n  /** Initial open state when uncontrolled. */\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  /** Shows at most this many sources per step and folds the rest into \"+N\". @default 4 */\n  maxResults?: number;\n  className?: string;\n}\n\n/**\n * A summary line that expands into the ordered steps the agent took. Each step sits on a\n * hairline rail with its status glyph, an optional detail line, the sources it read, and any\n * images. While a step runs, the summary line follows it with that step's live mark.\n */\nexport function ChainOfThought({\n  steps,\n  summary,\n  open,\n  defaultOpen = false,\n  onOpenChange,\n  maxResults = 4,\n  className,\n}: ChainOfThoughtProps) {\n  const running = steps.find((step) => (step.status ?? \"done\") === \"running\");\n  const failed = steps.some((step) => step.status === \"failed\");\n  const lineText = running ? running.label : (summary ?? `Took ${steps.length} ${steps.length === 1 ? \"step\" : \"steps\"}`);\n\n  return (\n    <Collapsible.Root\n      open={open}\n      defaultOpen={defaultOpen}\n      onOpenChange={onOpenChange ? (next) => onOpenChange(next) : undefined}\n      data-running={running ? \"\" : undefined}\n      className={cx(\"w-full min-w-0\", className)}\n    >\n      <Collapsible.Trigger\n        className={cx(\n          \"group -mx-1.5 flex h-7 max-w-[calc(100%+0.75rem)] cursor-pointer items-center gap-2 rounded-md px-1.5 text-left text-sm select-none\",\n          \"text-zinc-600 transition-[background-color,color] duration-150 ease-out motion-reduce:transition-none\",\n          \"hover:bg-zinc-950/[0.04] hover:text-zinc-950 data-[panel-open]:text-zinc-950\",\n          \"dark:text-zinc-400 dark:hover:bg-white/[0.06] dark:hover:text-white dark:data-[panel-open]:text-white\",\n          \"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500\",\n        )}\n      >\n        <span aria-hidden=\"true\" className=\"inline-flex size-4 shrink-0 items-center justify-center\">\n          {running ? (\n            <AgentMark key={running.id} activity={running.activity ?? \"thinking\"} size={16} className=\"text-zinc-950 dark:text-white\" />\n          ) : failed ? (\n            <StatusGlyph kind=\"failed\" />\n          ) : (\n            <RailIcon />\n          )}\n        </span>\n        <span\n          key={running ? running.id : \"summary\"}\n          className={cx(\n            \"min-w-0 truncate\",\n            running ? \"after:content-['…']\" : \"\",\n            `transition-[opacity,filter,translate] duration-300 ${ease} starting:translate-y-[3px] starting:opacity-0 starting:blur-[2px] motion-reduce:transition-none`,\n          )}\n        >\n          {lineText}\n        </span>\n        {failed && !running ? <span className=\"sr-only\">, one or more steps failed</span> : null}\n        <svg\n          aria-hidden=\"true\"\n          viewBox=\"0 0 16 16\"\n          fill=\"none\"\n          className={cx(\n            \"size-3.5 shrink-0 text-zinc-400 dark:text-zinc-500\",\n            `transition-[rotate,color] duration-220 ${ease} motion-reduce:transition-none`,\n            \"group-hover:text-current group-data-[panel-open]:rotate-180 group-data-[panel-open]:text-current\",\n          )}\n        >\n          <path d=\"m4.5 6.25 3.5 3.5 3.5-3.5\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n        </svg>\n      </Collapsible.Trigger>\n\n      <Collapsible.Panel\n        className={cx(\n          \"h-(--collapsible-panel-height) overflow-hidden\",\n          `transition-[height,opacity] duration-220 ${ease} motion-reduce:transition-none`,\n          \"data-[starting-style]:h-0 data-[starting-style]:opacity-0\",\n          \"data-[ending-style]:h-0 data-[ending-style]:opacity-0 data-[ending-style]:duration-180\",\n        )}\n      >\n        <ol aria-busy={running ? true : undefined} className=\"grid pt-3 pb-1\">\n          {steps.map((step, index) => (\n            <Step key={step.id} step={step} last={index === steps.length - 1} maxResults={maxResults} />\n          ))}\n        </ol>\n      </Collapsible.Panel>\n    </Collapsible.Root>\n  );\n}\n\nfunction Step({ step, last, maxResults }: { step: ChainOfThoughtStep; last: boolean; maxResults: number }) {\n  const status = step.status ?? \"done\";\n  const results = step.results ?? [];\n  const shown = results.slice(0, maxResults);\n  const hidden = results.length - shown.length;\n\n  return (\n    <li\n      data-status={status}\n      className={cx(\n        \"relative grid grid-cols-[1rem_minmax(0,1fr)] gap-x-3 pb-4 last:pb-0\",\n        `transition-[opacity,translate] duration-200 ${ease} starting:translate-y-1 starting:opacity-0 motion-reduce:transition-none`,\n      )}\n    >\n      {!last ? (\n        <span\n          aria-hidden=\"true\"\n          className={cx(\n            \"absolute top-6 bottom-1 left-[7.5px] w-px transition-colors duration-300 motion-reduce:transition-none\",\n            status === \"done\" ? \"bg-zinc-950/20 dark:bg-white/20\" : \"bg-zinc-950/[0.08] dark:bg-white/10\",\n          )}\n        />\n      ) : null}\n      <span aria-hidden=\"true\" className=\"flex h-5 w-4 items-center justify-center\">\n        {status === \"running\" ? (\n          <AgentMark activity={step.activity ?? \"thinking\"} size={16} className=\"text-zinc-950 dark:text-white\" />\n        ) : (\n          <StatusGlyph key={status} kind={glyphs[status]} />\n        )}\n      </span>\n\n      <div className=\"min-w-0\">\n        <p\n          className={cx(\n            \"text-sm leading-5 break-words transition-colors duration-200 motion-reduce:transition-none\",\n            status === \"queued\" ? \"text-zinc-500\" : status === \"skipped\" ? \"text-zinc-500 line-through decoration-zinc-500/60\" : \"text-zinc-950 dark:text-white\",\n          )}\n        >\n          {step.label}\n          <span className=\"sr-only\">, {spoken[status]}</span>\n        </p>\n        {step.detail != null ? (\n          <p className={cx(\"mt-0.5 text-xs leading-5\", status === \"failed\" ? \"text-red-600 dark:text-red-400\" : \"text-zinc-500\")}>{step.detail}</p>\n        ) : null}\n\n        {shown.length ? (\n          <ul aria-label=\"Sources\" className=\"mt-2 flex flex-wrap gap-1.5\">\n            {shown.map((result) => (\n              <li key={result.url} className={`transition-opacity duration-200 ${ease} starting:opacity-0 motion-reduce:transition-none`}>\n                <a\n                  href={result.url}\n                  target=\"_blank\"\n                  rel=\"noreferrer\"\n                  title={result.title}\n                  className={cx(\n                    \"inline-flex h-6 max-w-56 items-center gap-1.5 rounded-md border px-2 text-xs\",\n                    \"border-zinc-950/10 text-zinc-600 transition-[background-color,border-color,color] duration-150 ease-out motion-reduce:transition-none\",\n                    \"hover:border-zinc-950/20 hover:bg-zinc-950/[0.03] hover:text-zinc-950\",\n                    \"dark:border-white/10 dark:text-zinc-400 dark:hover:border-white/20 dark:hover:bg-white/[0.06] dark:hover:text-white\",\n                    \"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500\",\n                  )}\n                >\n                  <GlobeIcon />\n                  <span className=\"sr-only\">{result.title}, </span>\n                  <span className=\"truncate\">{hostname(result.url)}</span>\n                </a>\n              </li>\n            ))}\n            {hidden > 0 ? (\n              <li className=\"inline-flex h-6 items-center px-1 font-mono text-xs text-zinc-500 tabular-nums\">\n                <span aria-hidden=\"true\">+{hidden}</span>\n                <span className=\"sr-only\">and {hidden} more</span>\n              </li>\n            ) : null}\n          </ul>\n        ) : null}\n\n        {step.images?.length ? (\n          <div className=\"mt-2 grid grid-cols-2 gap-2 sm:grid-cols-3\">\n            {step.images.map((image) => (\n              <figure key={image.src} className=\"min-w-0\">\n                <img\n                  src={image.src}\n                  alt={image.alt}\n                  loading=\"lazy\"\n                  className=\"aspect-[4/3] w-full rounded-lg border border-zinc-950/10 bg-zinc-950/[0.02] object-cover dark:border-white/10 dark:bg-transparent\"\n                />\n                {image.caption != null ? <figcaption className=\"mt-1 truncate text-xs text-zinc-500\">{image.caption}</figcaption> : null}\n              </figure>\n            ))}\n          </div>\n        ) : null}\n\n        {step.content != null ? <div className=\"mt-2 text-sm text-zinc-600 dark:text-zinc-400\">{step.content}</div> : null}\n      </div>\n    </li>\n  );\n}\n\nfunction hostname(url: string): string {\n  try {\n    return new URL(url).hostname.replace(/^www\\./, \"\");\n  } catch {\n    return url;\n  }\n}\n\n/** Three nodes on a rail: the collapsed form of the step list. */\nfunction RailIcon() {\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth={1.5} strokeLinecap=\"round\" className=\"size-4 text-zinc-400 dark:text-zinc-500\">\n      <circle cx=\"4.5\" cy=\"3.5\" r=\"1.25\" />\n      <circle cx=\"4.5\" cy=\"8\" r=\"1.25\" />\n      <circle cx=\"4.5\" cy=\"12.5\" r=\"1.25\" />\n      <path d=\"M8.5 3.5h5M8.5 8h3.5M8.5 12.5h5\" />\n    </svg>\n  );\n}\n\nfunction GlobeIcon() {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth={1.25} className=\"size-3 shrink-0 opacity-70\">\n      <circle cx=\"8\" cy=\"8\" r=\"6\" />\n      <path d=\"M2 8h12M8 2c1.7 1.7 2.5 3.7 2.5 6S9.7 12.3 8 14C6.3 12.3 5.5 10.3 5.5 8S6.3 3.7 8 2Z\" />\n    </svg>\n  );\n}\n"
    }
  ],
  "example": {
    "content": "import { ChainOfThought } from \"@/components/shaken/agent/chain-of-thought\";\n\nexport default function ChainOfThoughtExample() {\n  return (\n    <ChainOfThought\n      className=\"max-w-lg\"\n      defaultOpen\n      summary=\"Checked 5 sources on webhook retries\"\n      steps={[\n        {\n          id: \"search\",\n          label: \"Searched for webhook retry behavior\",\n          detail: \"5 results\",\n          results: [\n            { title: \"Webhooks: retries and backoff\", url: \"https://docs.stripe.com/webhooks\" },\n            { title: \"Delivering webhooks reliably\", url: \"https://github.blog/engineering/webhooks\" },\n            { title: \"Idempotent receivers\", url: \"https://developer.mozilla.org/en-US/docs/Glossary/Idempotent\" },\n            { title: \"Retry policies\", url: \"https://learn.microsoft.com/azure/architecture/patterns/retry\" },\n            { title: \"Exponential backoff\", url: \"https://cloud.google.com/storage/docs/retry-strategy\" },\n          ],\n        },\n        { id: \"read\", label: \"Read the retry and backoff guide\", detail: \"Retries continue for up to 3 days with exponential backoff\" },\n        { id: \"compare\", label: \"Compared it with the current handler\", detail: \"The handler returns 500 on duplicates, which triggers more retries\" },\n        { id: \"draft\", label: \"Drafted an idempotency fix\" },\n      ]}\n    />\n  );\n}\n"
  }
}
