{
  "schemaVersion": 1,
  "target": "react",
  "name": "sources",
  "version": "0.1.0",
  "category": "ai-elements",
  "title": "Sources",
  "description": "The links an agent used for a reply, as a Used 5 sources toggle with stacked favicons that opens into a numbered list of titles and domains.",
  "tags": [
    "ai",
    "agent",
    "sources",
    "citations",
    "links",
    "search",
    "base-ui"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {
    "@base-ui/react": "^1.9.0"
  },
  "registryDependencies": [
    {
      "name": "agent-state",
      "version": "0.1.0"
    }
  ],
  "docsPath": "/components/sources",
  "props": [
    {
      "name": "sources",
      "type": "{ title, url, domain?, icon? }[]",
      "description": "Sources in citation order. domain defaults to the URL host; icon is a favicon URL with the domain initial as fallback."
    },
    {
      "name": "searching",
      "type": "boolean",
      "default": "false",
      "description": "The agent is still collecting: the toggle shows the Searching mark and the count so far."
    },
    {
      "name": "label",
      "type": "ReactNode",
      "description": "Replaces the toggle text."
    },
    {
      "name": "previewCount",
      "type": "number",
      "default": "3",
      "description": "How many favicons stack in the toggle."
    },
    {
      "name": "defaultOpen / open / onOpenChange",
      "type": "boolean / (open) => void",
      "description": "Base UI Collapsible open state, uncontrolled or controlled."
    }
  ],
  "accessibility": [
    "Built on Base UI Collapsible: the toggle is a button with aria-expanded and aria-controls, operable with Enter and Space.",
    "Each source is a real link with a visible focus ring and an sr-only note that it opens in a new tab.",
    "Favicons are decorative (aria-hidden); the title and domain name each source.",
    "The list height and opacity animate in 220ms and close in 180ms; instant with reduced motion. The Searching mark holds a still frame under reduced motion."
  ],
  "states": [
    "collapsed",
    "expanded",
    "searching",
    "empty"
  ],
  "files": [
    {
      "path": "agent/sources.tsx",
      "content": "\"use client\";\n\nimport { Avatar } from \"@base-ui/react/avatar\";\nimport { Collapsible } from \"@base-ui/react/collapsible\";\nimport type { ReactNode } from \"react\";\nimport { AgentState } from \"./agent-state\";\n\nfunction cx(...classes: (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 interface SourceItem {\n  /** Page title. */\n  title: string;\n  /** Full URL the agent read. */\n  url: string;\n  /** Shown under the title. Defaults to the URL's host without `www.`. */\n  domain?: string;\n  /** Favicon image. Falls back to the domain's initial while loading or when it fails. */\n  icon?: string;\n}\n\nexport interface SourcesProps extends Omit<Collapsible.Root.Props, \"className\" | \"children\"> {\n  sources: SourceItem[];\n  /** Replaces the toggle text. Defaults to \"Used 5 sources\". */\n  label?: ReactNode;\n  /** The agent is still collecting sources: the toggle shows a Searching mark and the count so far. */\n  searching?: boolean;\n  /** How many favicons stack in the toggle. */\n  previewCount?: number;\n  className?: string;\n}\n\n/** Host of a URL without `www.`, or the URL itself when it does not parse. */\nexport function sourceDomain(url: string): string {\n  try {\n    return new URL(url).hostname.replace(/^www\\./, \"\");\n  } catch {\n    return url;\n  }\n}\n\n/**\n * The links an agent used for a reply: a quiet \"Used 5 sources\" toggle with stacked favicons that\n * opens into a numbered list of titles and domains. Numbers match Inline Citation chips.\n */\nexport function Sources({ sources, label, searching = false, previewCount = 3, className, ...props }: SourcesProps) {\n  const count = sources.length;\n  const noun = count === 1 ? \"source\" : \"sources\";\n  const text = label ?? (searching ? `Searching, ${count} ${noun} so far` : `Used ${count} ${noun}`);\n\n  return (\n    <Collapsible.Root className={cx(\"w-full\", className)} {...props} disabled={props.disabled || count === 0}>\n      <Collapsible.Trigger\n        className={cx(\n          \"group -ml-1.5 inline-flex min-h-8 max-w-[calc(100%+0.375rem)] cursor-pointer items-center gap-2 rounded-lg py-1 pr-2 pl-1.5 text-left text-sm\",\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          \"data-disabled:cursor-default data-disabled:hover:bg-transparent\",\n        )}\n      >\n        {count > 0 ? (\n          <span aria-hidden=\"true\" className=\"flex shrink-0 items-center\">\n            {sources.slice(0, previewCount).map((source, index) => (\n              <SourceIcon\n                key={source.url}\n                source={source}\n                className={cx(\n                  \"ring-2 ring-white dark:ring-black\",\n                  index > 0 && \"-ml-1.5\",\n                  `transition-[opacity,scale] duration-200 ${ease} starting:scale-90 starting:opacity-0 motion-reduce:transition-none`,\n                )}\n              />\n            ))}\n          </span>\n        ) : null}\n        {searching ? (\n          <AgentState variant=\"plain\" size=\"sm\" activity=\"searching\" label={text} className=\"text-sm\" />\n        ) : (\n          <span className=\"min-w-0 truncate font-medium\">{text}</span>\n        )}\n        <svg\n          aria-hidden=\"true\"\n          viewBox=\"0 0 16 16\"\n          fill=\"none\"\n          className={cx(\n            \"size-4 shrink-0 text-zinc-400 dark:text-zinc-500\",\n            `transition-[rotate,color] duration-200 ${ease} motion-reduce:transition-none`,\n            \"group-hover:text-current group-data-panel-open:rotate-180 group-data-panel-open:text-current\",\n            count === 0 && \"hidden\",\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      <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 className=\"mt-1.5 grid gap-px\">\n          {sources.map((source, index) => (\n            <li key={source.url}>\n              <a\n                href={source.url}\n                target=\"_blank\"\n                rel=\"noreferrer\"\n                className={cx(\n                  \"group/link -mx-1.5 grid grid-cols-[1.25rem_1.25rem_minmax(0,1fr)] items-center gap-x-2.5 rounded-lg px-1.5 py-1.5\",\n                  \"transition-colors duration-150 ease-out motion-reduce:transition-none\",\n                  \"hover:bg-zinc-950/[0.04] dark:hover:bg-white/[0.06]\",\n                  \"focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-sky-500\",\n                )}\n              >\n                <span className=\"text-right font-mono text-xs text-zinc-500 tabular-nums\">{index + 1}</span>\n                <SourceIcon source={source} />\n                <span className=\"min-w-0\">\n                  <span className=\"block truncate text-sm leading-5 text-zinc-950 group-hover/link:underline group-hover/link:decoration-zinc-950/30 group-hover/link:underline-offset-2 dark:text-white dark:group-hover/link:decoration-white/40\">\n                    {source.title}\n                  </span>\n                  <span className=\"block truncate text-xs leading-4 text-zinc-500\">{source.domain ?? sourceDomain(source.url)}</span>\n                </span>\n                <span className=\"sr-only\">(opens in a new tab)</span>\n              </a>\n            </li>\n          ))}\n        </ol>\n      </Collapsible.Panel>\n    </Collapsible.Root>\n  );\n}\n\n/** A 20px round favicon with the domain's initial as its fallback. Decorative; the title names the source. */\nexport function SourceIcon({ source, className }: { source: SourceItem; className?: string }) {\n  const domain = source.domain ?? sourceDomain(source.url);\n  return (\n    <Avatar.Root\n      aria-hidden=\"true\"\n      className={cx(\n        \"relative inline-flex size-5 shrink-0 items-center justify-center overflow-hidden rounded-full bg-white select-none\",\n        \"shadow-[inset_0_0_0_1px_rgb(9_9_11/0.1)] dark:bg-black dark:shadow-[inset_0_0_0_1px_rgb(255_255_255/0.16)]\",\n        className,\n      )}\n    >\n      {source.icon ? <Avatar.Image src={source.icon} alt=\"\" className=\"size-3.5 object-contain\" /> : null}\n      <Avatar.Fallback className=\"text-[10px] leading-none font-semibold text-zinc-600 dark:text-zinc-300\">\n        {domain.charAt(0).toUpperCase()}\n      </Avatar.Fallback>\n    </Avatar.Root>\n  );\n}\n"
    }
  ],
  "example": {
    "content": "import { Sources } from \"@/components/shaken/agent/sources\";\n\nconst sources = [\n  { title: \"Connection pooling with PgBouncer\", url: \"https://www.pgbouncer.org/features.html\" },\n  { title: \"Tuning max_connections for small instances\", url: \"https://www.postgresql.org/docs/current/runtime-config-connection.html\" },\n  { title: \"Serverless Postgres and connection limits\", url: \"https://neon.tech/docs/connect/connection-pooling\" },\n  { title: \"Prisma: connection management in serverless functions\", url: \"https://www.prisma.io/docs/guides/performance-and-optimization/connection-management\" },\n  { title: \"Why transaction pooling breaks prepared statements\", url: \"https://github.com/pgbouncer/pgbouncer/issues/695\" },\n];\n\nexport default function SourcesExample() {\n  return (\n    <div className=\"grid w-full max-w-lg gap-3\">\n      <p className=\"text-sm leading-relaxed text-zinc-800 dark:text-zinc-200\">\n        Put PgBouncer in transaction mode in front of the database and cap each function at one connection. Serverless\n        functions open a new connection per cold start, so without a pooler a traffic spike exhausts the 100 connection limit\n        within seconds.\n      </p>\n      <Sources sources={sources} defaultOpen />\n    </div>\n  );\n}\n"
  }
}
