{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "retrieval-chunks",
  "title": "Retrieval Chunks",
  "description": "Ranked source passages with a searching state, highlighted query terms, relevance bars, and expandable text.",
  "dependencies": [
    "@solar-icons/react@^2.2.0",
    "cn@^0.3.0",
    "motion@^13.4.0"
  ],
  "registryDependencies": [
    "https://pastaui.com/r/pastaui-styles.json"
  ],
  "files": [
    {
      "path": "src/components/ai/retrieval-chunks.tsx",
      "content": "import { ArrowRightUpIcon as ArrowUpRightIcon } from '@solar-icons/react/linear/arrow-right-up'\nimport { DatabaseIcon } from '@solar-icons/react/linear/database'\nimport { LoaderIcon } from '@solar-icons/react/linear/loader'\nimport { MotionConfig, motion } from 'motion/react'\nimport * as React from 'react'\n\nimport { cn } from 'cn'\n\ninterface RetrievalChunk {\n  content: string\n  id: string\n  location?: string\n  score: number\n  source: string\n}\n\ninterface RetrievalChunksProps extends React.ComponentProps<'section'> {\n  highlight?: string[]\n  items: RetrievalChunk[]\n  searching?: boolean\n  onOpen?: (id: string) => void\n  query: string\n}\n\nconst ease = [0.23, 1, 0.32, 1] as const\n\nfunction escape(value: string) {\n  return value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\nfunction Highlight({ terms, text }: { terms: string[]; text: string }) {\n  if (!terms.length) return <>{text}</>\n  const pattern = new RegExp(`(${terms.map(escape).join('|')})`, 'gi')\n  return (\n    <>\n      {text.split(pattern).map((part, index) =>\n        index % 2 ? (\n          <mark className=\"rounded-[4px] bg-foreground/6 px-0.5 text-inherit\" key={index}>\n            {part}\n          </mark>\n        ) : (\n          part\n        ),\n      )}\n    </>\n  )\n}\n\nfunction RetrievalChunks({\n  className,\n  highlight = [],\n  items,\n  onOpen,\n  query,\n  searching = false,\n  ...props\n}: RetrievalChunksProps) {\n  const [expanded, setExpanded] = React.useState<Set<string>>(() => new Set())\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <section\n        data-slot=\"retrieval-chunks\"\n        className={cn(\n          'rounded-[16px] bg-card p-2 font-sans text-sm font-[450] tracking-[-0.05px] text-muted-foreground shadow-card',\n          className,\n        )}\n        {...props}\n      >\n        <header className=\"px-3 pt-2\">\n          <div className=\"flex items-center gap-2\">\n            <DatabaseIcon className=\"size-4 text-muted-foreground\" />\n            <h3 className=\"text-sm leading-5 font-medium text-muted-foreground\">\n              Retrieved context\n            </h3>\n            <span\n              aria-live=\"polite\"\n              className=\"ml-auto flex items-center gap-1.5 text-[13px] leading-5 text-muted-foreground/70 tabular-nums\"\n            >\n              {searching && (\n                <LoaderIcon\n                  aria-hidden=\"true\"\n                  className=\"size-3.5 animate-spin motion-reduce:animate-none\"\n                />\n              )}\n              {searching\n                ? 'Searching'\n                : `${items.length} ${items.length === 1 ? 'match' : 'matches'}`}\n            </span>\n          </div>\n          <p className=\"mt-1.5 text-[13px] leading-5 text-muted-foreground\">\n            Searched for <span className=\"text-foreground/80\">“{query}”</span>\n          </p>\n        </header>\n        <ol className=\"mt-2 flex flex-col\">\n          {items.map((item, index) => {\n            const body = (\n              <>\n                <span className=\"flex items-center gap-3\">\n                  <span className=\"flex size-5 shrink-0 items-center justify-center rounded-md bg-foreground/6 text-[11px] text-muted-foreground tabular-nums\">\n                    {index + 1}\n                  </span>\n                  <span className=\"flex min-w-0 flex-1 items-center gap-1\">\n                    <span className=\"truncate text-[15px] leading-6 font-medium text-foreground\">\n                      {item.source}\n                    </span>\n                    {onOpen && (\n                      <ArrowUpRightIcon\n                        aria-hidden=\"true\"\n                        className=\"size-3.5 shrink-0 text-muted-foreground opacity-0 transition-opacity duration-150 ease-out group-hover:opacity-100 group-focus-visible:opacity-100 pointer-coarse:opacity-100\"\n                      />\n                    )}\n                  </span>\n                  <span className=\"flex shrink-0 items-center gap-2 text-[13px] leading-5 text-muted-foreground/70 tabular-nums\">\n                    {[item.location, `${Math.round(item.score * 100)}%`]\n                      .filter(Boolean)\n                      .join(' · ')}\n                    <span\n                      aria-hidden=\"true\"\n                      className=\"h-1 w-10 overflow-hidden rounded-full bg-foreground/6\"\n                    >\n                      <motion.span\n                        animate={{ scaleX: item.score }}\n                        className=\"block h-full origin-left rounded-full bg-muted-foreground/70\"\n                        initial={{ scaleX: 0 }}\n                        transition={{ duration: 0.6, ease }}\n                      />\n                    </span>\n                  </span>\n                </span>\n                <span\n                  className={cn(\n                    'mt-1 block pl-8 text-sm leading-6 text-foreground/75',\n                    !expanded.has(item.id) && 'line-clamp-2',\n                  )}\n                >\n                  “<Highlight terms={highlight} text={item.content} />”\n                </span>\n              </>\n            )\n\n            return (\n              <motion.li\n                animate={{ opacity: 1, y: 0, filter: 'blur(0px)' }}\n                initial={{ opacity: 0, y: 6, filter: 'blur(3px)' }}\n                key={item.id}\n                layout=\"position\"\n                transition={{ duration: 0.3, ease }}\n              >\n                {onOpen ? (\n                  <button\n                    className=\"group block w-full rounded-[12px] p-3 text-left transition-colors duration-150 ease-out outline-none hover:bg-foreground/4 focus-visible:ring-2 focus-visible:ring-ring\"\n                    onClick={() => onOpen(item.id)}\n                    type=\"button\"\n                  >\n                    {body}\n                  </button>\n                ) : (\n                  <div className=\"p-3\">{body}</div>\n                )}\n                {item.content.length > 140 && (\n                  <button\n                    aria-expanded={expanded.has(item.id)}\n                    className=\"-mt-2 mb-1 ml-11 rounded-sm text-[13px] leading-5 text-muted-foreground/70 outline-none hover:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring\"\n                    onClick={() =>\n                      setExpanded((current) => {\n                        const next = new Set(current)\n                        if (next.has(item.id)) next.delete(item.id)\n                        else next.add(item.id)\n                        return next\n                      })\n                    }\n                    type=\"button\"\n                  >\n                    {expanded.has(item.id) ? 'Show less' : 'Show more'}\n                  </button>\n                )}\n              </motion.li>\n            )\n          })}\n          {searching &&\n            [0, 1].slice(items.length > 1 ? 1 : 0).map((row) => (\n              <li aria-hidden=\"true\" className=\"space-y-2 p-3\" key={`skeleton-${row}`}>\n                <span className=\"flex items-center gap-3\">\n                  <span className=\"size-5 animate-pulse rounded-md bg-foreground/6 motion-reduce:animate-none\" />\n                  <span className=\"h-3.5 w-40 animate-pulse rounded-full bg-foreground/6 motion-reduce:animate-none\" />\n                </span>\n                <span className=\"ml-8 block h-3 w-4/5 animate-pulse rounded-full bg-foreground/6 motion-reduce:animate-none\" />\n              </li>\n            ))}\n        </ol>\n      </section>\n    </MotionConfig>\n  )\n}\n\nexport { RetrievalChunks }\nexport type { RetrievalChunk, RetrievalChunksProps }\n",
      "type": "registry:component",
      "target": "@components/ai/retrieval-chunks.tsx"
    }
  ],
  "type": "registry:component"
}