{
  "schemaVersion": 1,
  "target": "react",
  "name": "artifact-preview",
  "version": "0.3.1",
  "category": "agent",
  "title": "Artifact Preview",
  "description": "A file an agent produced as a compact row. Hover, focus, or tap a ready file to open an animated preview shaped by its type: the image, a table for CSV and Excel, the opening lines of code or Markdown, a page sketch for PDF, or a plain fallback.",
  "tags": [
    "agent",
    "artifact",
    "file",
    "preview",
    "download"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {
    "@base-ui/react": "^1.9.0"
  },
  "registryDependencies": [
    {
      "name": "agent-run",
      "version": "0.1.2"
    }
  ],
  "docsPath": "/components/artifact-preview",
  "props": [
    {
      "name": "name / type",
      "type": "string",
      "description": "File name and MIME type. The extension and type choose the preview kind."
    },
    {
      "name": "status",
      "type": "\"generating\" | \"ready\" | \"failed\"",
      "description": "Generating shows a spinner and \"Writing…\"; failed shows the error under the row. Only ready files preview."
    },
    {
      "name": "path",
      "type": "string",
      "description": "Where to open or download the file. Images preview from this path unless previewSrc is set."
    },
    {
      "name": "content",
      "type": "string",
      "description": "Text for code, JSON, Markdown, and plain text previews (rendered as text, never HTML). CSV and TSV content is parsed into a table."
    },
    {
      "name": "rows",
      "type": "(string | number)[][]",
      "description": "Table data for spreadsheets such as xlsx, first row as the header. Takes precedence over parsing content."
    },
    {
      "name": "previewSrc",
      "type": "string",
      "description": "A thumbnail to show instead of path, for large images or the first page of a PDF."
    },
    {
      "name": "pages",
      "type": "number",
      "description": "Page count shown with the PDF page sketch."
    },
    {
      "name": "kind",
      "type": "\"image\" | \"table\" | \"document\" | \"code\" | \"pdf\" | \"file\"",
      "description": "Overrides the detected preview kind."
    },
    {
      "name": "preview",
      "type": "boolean",
      "default": "true",
      "description": "Set to false to show only the row."
    },
    {
      "name": "previewSide",
      "type": "\"top\" | \"bottom\" | \"left\" | \"right\"",
      "default": "\"bottom\"",
      "description": "Side of the row the preview opens on; it flips when there is no room."
    },
    {
      "name": "sizeBytes / error",
      "type": "number / string",
      "description": "Optional size and failure message."
    }
  ],
  "accessibility": [
    "The row is a button: hover, keyboard focus, or a tap opens the preview, and Escape closes it with focus kept on the row.",
    "Focus stays on the row when the preview opens; Tab moves into the preview (its Download link) and on to the row's own download link.",
    "The preview is a labelled dialog (\"Preview of name\"). Tables use real table markup with a caption, images have alt text, and the PDF sketch is a labelled image.",
    "Status is announced in a live region (\"Writing the file\", \"Ready\", \"Failed\") and also shown as text and a glyph.",
    "With reduced motion the preview and its staggered content appear without transitions; the generating spinner holds still."
  ],
  "states": [
    "generating",
    "ready",
    "failed"
  ],
  "files": [
    {
      "path": "agent/artifact-preview.tsx",
      "content": "\"use client\";\n\nimport { Popover as BasePopover } from \"@base-ui/react/popover\";\nimport { type ComponentProps, type CSSProperties, type FocusEvent, useState } from \"react\";\nimport type { ArtifactStatus } from \"./agent-run\";\n\n/** How a file previews. Detected from the extension and MIME type unless you pass `kind`. */\nexport type ArtifactKind = \"image\" | \"table\" | \"document\" | \"code\" | \"pdf\" | \"file\";\n\nexport interface ArtifactPreviewProps extends Omit<ComponentProps<\"article\">, \"children\"> {\n  name: string;\n  /** MIME type, e.g. text/markdown, text/csv, application/json, image/png. */\n  type: string;\n  status: ArtifactStatus;\n  /** Where to open or download the artifact once it is ready. Images preview from this path. */\n  path?: string;\n  /** Text content to preview for text-like types. Rendered as text, never HTML. */\n  content?: string;\n  sizeBytes?: number;\n  error?: string;\n  /** Overrides the detected preview kind. */\n  kind?: ArtifactKind;\n  /** Table data for spreadsheets (first row is the header). CSV and TSV content is parsed when this is unset. */\n  rows?: (string | number)[][];\n  /** A thumbnail to show instead of `path`, for large images or the first page of a PDF. */\n  previewSrc?: string;\n  /** Page count for documents such as PDFs. */\n  pages?: number;\n  /** Set to false to show only the row, without the hover preview. */\n  preview?: boolean;\n  /** Side of the row the preview opens on. Flips when there is not enough room. */\n  previewSide?: \"top\" | \"bottom\" | \"left\" | \"right\";\n}\n\nconst ease = \"ease-[cubic-bezier(0.23,1,0.32,1)]\";\n/** Preview content settles in as the card opens: a 2px rise and a fade, staggered by `delay`. */\nconst rise = `transition-[opacity,translate] duration-300 ${ease} starting:opacity-0 motion-safe:starting:translate-y-0.5 motion-reduce:transition-none`;\nconst delay = (index: number): CSSProperties => ({ transitionDelay: `${40 + index * 28}ms` });\n\n/**\n * A file an agent produced, as a compact row: name, type, size, and status. Hovering, focusing,\n * or tapping a ready file opens a preview shaped by its type: the image, the first rows of a\n * spreadsheet, the opening lines of code or a document, or a page sketch for a PDF.\n */\nexport function ArtifactPreview({\n  name,\n  type,\n  status,\n  path,\n  content,\n  sizeBytes,\n  error,\n  kind: kindProp,\n  rows,\n  previewSrc,\n  pages,\n  preview = true,\n  previewSide = \"bottom\",\n  className,\n  ...props\n}: ArtifactPreviewProps) {\n  const [open, setOpen] = useState(false);\n  const extension = extensionOf(name);\n  const kind = kindProp ?? kindOf(extension, type);\n  const label = typeLabel(extension, type, kind);\n  const table = kind === \"table\" ? (rows ?? (content != null ? parseDelimited(content, extension === \"tsv\" || type.includes(\"tab-separated\") ? \"\\t\" : \",\") : undefined)) : undefined;\n  const ready = status === \"ready\";\n  const canPreview = ready && preview;\n\n  const row = (\n    <>\n      <FileTile extension={extension} kind={kind} status={status} />\n      <span className=\"grid min-w-0 flex-1 text-left\">\n        <span className=\"truncate text-sm font-medium text-zinc-950 dark:text-white\">{name}</span>\n        <span className=\"flex min-w-0 items-center gap-1.5 text-xs text-zinc-500\">\n          {status === \"generating\" ? (\n            <span key=\"generating\" className={`text-sky-700 dark:text-sky-400 ${rise}`}>\n              Writing…\n            </span>\n          ) : status === \"failed\" ? (\n            <span key=\"failed\" className={`text-red-700 dark:text-red-400 ${rise}`}>\n              Failed\n            </span>\n          ) : null}\n          {status === \"failed\" ? null : (\n            <span className=\"truncate\">\n              {status === \"generating\" ? <span aria-hidden=\"true\">· </span> : null}\n              {label}\n              {sizeBytes != null && ready ? <span className=\"font-mono tabular-nums\"> · {formatSize(sizeBytes)}</span> : null}\n            </span>\n          )}\n        </span>\n      </span>\n    </>\n  );\n\n  return (\n    <article\n      data-status={status}\n      data-kind={kind}\n      aria-busy={status === \"generating\" || undefined}\n      aria-label={name}\n      className={[\n        \"rounded-xl border border-zinc-950/10 bg-white text-zinc-950 shadow-[0_1px_2px_rgb(0_0_0/0.04)]\",\n        \"dark:border-white/10 dark:bg-black dark:text-white dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.06)]\",\n        className,\n      ]\n        .filter(Boolean)\n        .join(\" \")}\n      {...props}\n    >\n      <span role=\"status\" className=\"sr-only\">\n        {status === \"generating\" ? \"Writing the file\" : status === \"failed\" ? \"Failed\" : \"Ready\"}\n      </span>\n      <div className=\"flex items-center gap-1 p-1.5\">\n        {canPreview ? (\n          <BasePopover.Root open={open} onOpenChange={setOpen}>\n            <BasePopover.Trigger\n              openOnHover\n              delay={140}\n              closeDelay={120}\n              // Keyboard focus opens the preview too; a mouse click is handled by the trigger itself.\n              onFocus={(event: FocusEvent<HTMLButtonElement>) => {\n                if (event.currentTarget.matches(\":focus-visible\")) setOpen(true);\n              }}\n              className={[\n                \"flex min-w-0 flex-1 items-center gap-3 rounded-lg p-1.5 text-left outline-none\",\n                \"transition-colors duration-150 ease-out motion-reduce:transition-none\",\n                \"hover:bg-zinc-950/[0.04] data-[popup-open]:bg-zinc-950/[0.04] dark:hover:bg-white/[0.06] dark:data-[popup-open]:bg-white/[0.06]\",\n                \"focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-sky-500\",\n              ].join(\" \")}\n            >\n              {row}\n              <span className=\"sr-only\">, show preview</span>\n            </BasePopover.Trigger>\n            <BasePopover.Portal>\n              <BasePopover.Positioner side={previewSide} align=\"start\" sideOffset={8} collisionPadding={12} className=\"z-50\">\n                <BasePopover.Popup\n                  initialFocus={false}\n                  className={[\n                    \"max-w-(--available-width) origin-(--transform-origin) overflow-hidden rounded-xl outline-none\",\n                    kind === \"table\" ? \"w-[26rem]\" : kind === \"pdf\" ? \"w-64\" : \"w-80\",\n                    \"border border-zinc-950/10 bg-white text-zinc-950 shadow-[0_12px_32px_-8px_rgb(0_0_0/0.18)]\",\n                    \"dark:border-white/15 dark:bg-black dark:text-white dark:shadow-[0_16px_48px_-12px_rgb(0_0_0/1),inset_0_1px_0_rgb(255_255_255/0.08)]\",\n                    // Enter: 180ms from 96% at the row. Exit: 110ms, a fade with a smaller scale.\n                    `transition-[opacity,scale] duration-180 ${ease} motion-reduce:transition-none`,\n                    \"data-[starting-style]:opacity-0 motion-safe:data-[starting-style]:scale-96\",\n                    \"data-[ending-style]:opacity-0 data-[ending-style]:duration-110 data-[ending-style]:ease-out motion-safe:data-[ending-style]:scale-98\",\n                  ].join(\" \")}\n                >\n                  <BasePopover.Title className=\"sr-only\">Preview of {name}</BasePopover.Title>\n                  <PreviewBody kind={kind} name={name} path={path} thumbnail={previewSrc} content={content} table={table} pages={pages} extension={extension} />\n                  {path ? (\n                    <div className=\"flex items-center justify-between gap-3 border-t border-zinc-950/[0.07] py-1.5 pr-1.5 pl-3 dark:border-white/[0.08]\">\n                      <code className=\"min-w-0 truncate font-mono text-[11px] text-zinc-500\">{path}</code>\n                      <DownloadLink path={path} name={name} withText />\n                    </div>\n                  ) : null}\n                </BasePopover.Popup>\n              </BasePopover.Positioner>\n            </BasePopover.Portal>\n          </BasePopover.Root>\n        ) : (\n          <div className=\"flex min-w-0 flex-1 items-center gap-3 p-1.5\">{row}</div>\n        )}\n        {ready && path ? <DownloadLink path={path} name={name} /> : null}\n      </div>\n      {status === \"failed\" ? (\n        <p key=\"error\" className={`border-t border-zinc-950/[0.07] px-3 py-2.5 text-xs leading-relaxed text-zinc-600 dark:border-white/[0.08] dark:text-zinc-400 ${rise}`}>\n          {error ?? \"The artifact could not be generated.\"}\n        </p>\n      ) : null}\n    </article>\n  );\n}\n\nfunction PreviewBody({\n  kind,\n  name,\n  path,\n  thumbnail,\n  content,\n  table,\n  pages,\n  extension,\n}: {\n  kind: ArtifactKind;\n  name: string;\n  path?: string;\n  thumbnail?: string;\n  content?: string;\n  table?: (string | number)[][];\n  pages?: number;\n  extension: string;\n}) {\n  if (kind === \"image\" && (thumbnail ?? path)) return <ImagePreview src={(thumbnail ?? path)!} name={name} />;\n  if (kind === \"table\" && table && table.length > 0) return <TablePreview rows={table} name={name} />;\n  if (kind === \"pdf\") return thumbnail ? <ImagePreview src={thumbnail} name={name} /> : <PagePreview pages={pages} name={name} />;\n  if (kind === \"document\" && content != null) return <DocumentPreview content={content} markdown={extension === \"md\" || extension === \"markdown\"} />;\n  if ((kind === \"code\" || kind === \"document\") && content != null) return <CodePreview content={content} json={extension === \"json\"} />;\n  return <GenericPreview extension={extension} />;\n}\n\nfunction ImagePreview({ src, name }: { src: string; name: string }) {\n  const [size, setSize] = useState<string | null>(null);\n  return (\n    <figure className=\"p-1.5\">\n      <div className=\"grid place-items-center overflow-hidden rounded-lg bg-zinc-950/[0.03] dark:bg-white/[0.04]\">\n        <img\n          src={src}\n          alt={`Preview of ${name}`}\n          onLoad={(event) => setSize(`${event.currentTarget.naturalWidth} × ${event.currentTarget.naturalHeight}`)}\n          className={`max-h-56 w-full object-contain transition-[opacity,scale,filter] duration-300 ${ease} starting:opacity-0 motion-safe:starting:scale-[1.04] motion-safe:starting:blur-[3px] motion-reduce:transition-none`}\n        />\n      </div>\n      {size ? <figcaption className=\"px-1.5 pt-1.5 font-mono text-[11px] text-zinc-500 tabular-nums\">{size}</figcaption> : null}\n    </figure>\n  );\n}\n\nconst MAX_ROWS = 5;\nconst MAX_COLUMNS = 4;\n\nfunction TablePreview({ rows, name }: { rows: (string | number)[][]; name: string }) {\n  const [header = [], ...body] = rows;\n  const shown = body.slice(0, MAX_ROWS);\n  const columns = Math.max(header.length, ...shown.map((row) => row.length));\n  const visibleColumns = Math.min(columns, MAX_COLUMNS);\n  const numeric = Array.from({ length: visibleColumns }, (_, column) => shown.length > 0 && shown.every((row) => isNumeric(row[column])));\n  const cell = \"truncate px-2.5 py-1.5\";\n\n  return (\n    <div className=\"p-1.5\">\n      <div className=\"overflow-hidden rounded-lg border border-zinc-950/[0.07] dark:border-white/[0.08]\">\n        <table className=\"w-full table-fixed border-collapse text-left text-xs\">\n          <caption className=\"sr-only\">\n            First {shown.length} of {body.length} rows of {name}\n          </caption>\n          <thead>\n            <tr className={`bg-zinc-950/[0.03] dark:bg-white/[0.04] ${rise}`} style={delay(0)}>\n              {Array.from({ length: visibleColumns }, (_, column) => (\n                <th key={column} scope=\"col\" className={`${cell} ${column === 0 && visibleColumns > 2 ? \"w-[30%]\" : \"\"} font-medium text-zinc-700 dark:text-zinc-300 ${numeric[column] ? \"text-right\" : \"\"}`}>\n                  {header[column] ?? \"\"}\n                </th>\n              ))}\n            </tr>\n          </thead>\n          <tbody>\n            {shown.map((row, index) => (\n              <tr key={index} className={`border-t border-zinc-950/[0.06] dark:border-white/[0.06] ${rise}`} style={delay(index + 1)}>\n                {Array.from({ length: visibleColumns }, (_, column) => (\n                  <td\n                    key={column}\n                    className={`${cell} text-zinc-600 dark:text-zinc-400 ${numeric[column] ? \"text-right font-mono tabular-nums\" : \"\"}`}\n                  >\n                    {row[column] ?? \"\"}\n                  </td>\n                ))}\n              </tr>\n            ))}\n          </tbody>\n        </table>\n      </div>\n      <p className=\"px-1.5 pt-1.5 text-[11px] text-zinc-500 tabular-nums\">\n        {shown.length < body.length ? `${shown.length} of ${body.length} rows` : `${body.length} ${body.length === 1 ? \"row\" : \"rows\"}`}\n        {` · ${columns} ${columns === 1 ? \"column\" : \"columns\"}`}\n      </p>\n    </div>\n  );\n}\n\nconst MAX_LINES = 12;\n\nfunction CodePreview({ content, json }: { content: string; json: boolean }) {\n  const text = json ? prettyJson(content) : content;\n  const lines = text.replace(/\\n$/, \"\").split(\"\\n\");\n  const shown = lines.slice(0, MAX_LINES);\n  const more = lines.length - shown.length;\n\n  return (\n    <div className=\"p-1.5\">\n      <pre className=\"relative overflow-hidden rounded-lg border border-zinc-950/[0.07] bg-zinc-950/[0.02] py-2 font-mono text-[11px] leading-[1.6] text-zinc-800 dark:border-white/[0.08] dark:bg-white/[0.02] dark:text-zinc-300\">\n        {shown.map((line, index) => (\n          <span key={index} className={`flex ${rise}`} style={delay(Math.min(index, 8))}>\n            <span aria-hidden=\"true\" className=\"w-8 shrink-0 pr-3 text-right text-zinc-400 tabular-nums select-none dark:text-zinc-600\">\n              {index + 1}\n            </span>\n            <span className=\"min-w-0 overflow-hidden pr-3 text-ellipsis whitespace-pre\">{line || \" \"}</span>\n          </span>\n        ))}\n        {more > 0 ? (\n          <span aria-hidden=\"true\" className=\"pointer-events-none absolute inset-x-0 bottom-0 h-8 bg-linear-to-t from-white dark:from-black\" />\n        ) : null}\n      </pre>\n      {more > 0 ? <p className=\"px-1.5 pt-1.5 text-[11px] text-zinc-500 tabular-nums\">{more} more {more === 1 ? \"line\" : \"lines\"}</p> : null}\n    </div>\n  );\n}\n\n/** Markdown and plain text read as a page: headings, list items, and paragraphs, never HTML. */\nfunction DocumentPreview({ content, markdown }: { content: string; markdown: boolean }) {\n  const blocks = content\n    .split(\"\\n\")\n    .map((line) => line.trim())\n    .filter((line) => line && !line.startsWith(\"```\"))\n    .slice(0, 9);\n\n  return (\n    <div className=\"relative max-h-64 overflow-hidden px-4 pt-3.5 pb-4\">\n      <div className=\"grid gap-1.5\">\n        {blocks.map((line, index) => {\n          const style = delay(index);\n          if (markdown && /^#{1,6}\\s/.test(line)) {\n            const level = line.match(/^#+/)![0].length;\n            return (\n              <p key={index} style={style} className={`${level === 1 ? \"text-sm\" : \"pt-1 text-xs\"} font-semibold text-zinc-950 dark:text-white ${rise}`}>\n                {inline(line.replace(/^#+\\s*/, \"\"))}\n              </p>\n            );\n          }\n          if (markdown && /^([-*+]|\\d+\\.)\\s/.test(line)) {\n            return (\n              <p key={index} style={style} className={`flex gap-2 text-xs leading-relaxed text-zinc-600 dark:text-zinc-400 ${rise}`}>\n                <span aria-hidden=\"true\" className=\"mt-[7px] size-1 shrink-0 rounded-full bg-current opacity-60\" />\n                <span className=\"min-w-0\">{inline(line.replace(/^([-*+]|\\d+\\.)\\s+/, \"\"))}</span>\n              </p>\n            );\n          }\n          return (\n            <p key={index} style={style} className={`text-xs leading-relaxed text-zinc-600 dark:text-zinc-400 ${rise}`}>\n              {markdown ? inline(line) : line}\n            </p>\n          );\n        })}\n      </div>\n      <span aria-hidden=\"true\" className=\"pointer-events-none absolute inset-x-0 bottom-0 h-6 bg-linear-to-t from-white dark:from-black\" />\n    </div>\n  );\n}\n\n/** A sketch of the first page: a title, text lines, and a figure, drawn in hairlines. */\nfunction PagePreview({ pages, name }: { pages?: number; name: string }) {\n  const lines = [\"w-full\", \"w-11/12\", \"w-full\", \"w-3/4\", \"w-full\", \"w-5/6\", \"w-2/3\"];\n  const bar = \"h-[3px] rounded-full bg-zinc-950/15 dark:bg-white/20\";\n  const grow = `origin-left transition-[opacity,scale] duration-300 ${ease} starting:opacity-0 motion-safe:starting:scale-x-50 motion-reduce:transition-none`;\n\n  return (\n    <div className=\"grid justify-items-center gap-2 px-4 pt-5 pb-3\">\n      <div role=\"img\" aria-label={`First page of ${name}${pages ? `, ${pages} pages` : \"\"}`} className=\"relative\">\n        {pages && pages > 1 ? (\n          <span\n            aria-hidden=\"true\"\n            className={`absolute inset-0 translate-x-1.5 -translate-y-1.5 rounded-md border border-zinc-950/10 bg-white dark:border-white/10 dark:bg-black ${rise}`}\n          />\n        ) : null}\n        <div className=\"relative grid aspect-[8.5/11] w-36 content-start gap-1.5 rounded-md border border-zinc-950/12 bg-white p-3.5 shadow-[0_6px_16px_-8px_rgb(0_0_0/0.2)] dark:border-white/15 dark:bg-black dark:shadow-none\">\n          <span className={`h-1.5 w-1/2 rounded-full bg-zinc-950/40 dark:bg-white/50 ${grow}`} style={delay(0)} />\n          <span className={`mb-1 ${bar} w-1/3 ${grow}`} style={delay(1)} />\n          {lines.slice(0, 3).map((width, index) => (\n            <span key={`a${index}`} className={`${bar} ${width} ${grow}`} style={delay(index + 2)} />\n          ))}\n          <span className={`my-1 h-7 rounded-sm border border-zinc-950/10 bg-zinc-950/[0.03] dark:border-white/10 dark:bg-white/[0.04] ${rise}`} style={delay(5)} />\n          {lines.slice(3).map((width, index) => (\n            <span key={`b${index}`} className={`${bar} ${width} ${grow}`} style={delay(index + 6)} />\n          ))}\n        </div>\n      </div>\n      {pages ? <p className=\"text-[11px] text-zinc-500 tabular-nums\">{pages === 1 ? \"1 page\" : `${pages} pages`}</p> : null}\n    </div>\n  );\n}\n\nfunction GenericPreview({ extension }: { extension: string }) {\n  return (\n    <div className=\"grid justify-items-center gap-2 px-4 py-6 text-center\">\n      <span\n        aria-hidden=\"true\"\n        className={`grid size-12 place-items-center rounded-xl border border-zinc-950/10 font-mono text-xs font-medium text-zinc-600 dark:border-white/15 dark:text-zinc-400 ${rise}`}\n      >\n        {extension || <PageIcon />}\n      </span>\n      <p className={`text-xs text-zinc-500 ${rise}`} style={delay(1)}>\n        No inline preview for this file type.\n      </p>\n    </div>\n  );\n}\n\nfunction DownloadLink({ path, name, withText = false }: { path: string; name: string; withText?: boolean }) {\n  return (\n    <a\n      href={path}\n      download={name}\n      aria-label={withText ? undefined : `Download ${name}`}\n      className={[\n        \"inline-flex shrink-0 items-center justify-center gap-1.5 rounded-lg text-zinc-500\",\n        withText ? \"h-7 px-2 text-xs font-medium\" : \"size-8\",\n        \"transition-[background-color,color] duration-150 ease-out motion-reduce:transition-none\",\n        \"hover:bg-zinc-950/[0.05] hover:text-zinc-950 dark:hover:bg-white/[0.08] dark:hover:text-white\",\n        \"focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-sky-500\",\n      ].join(\" \")}\n    >\n      <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" className=\"size-4\">\n        <path d=\"M8 2.75v7.5M4.75 7 8 10.25 11.25 7M3 13.25h10\" />\n      </svg>\n      {withText ? (\n        <>\n          Download<span className=\"sr-only\"> {name}</span>\n        </>\n      ) : null}\n    </a>\n  );\n}\n\n/** The file's tile: its extension in mono, with the running or failed glyph while it is not ready. */\nfunction FileTile({ extension, kind, status }: { extension: string; kind: ArtifactKind; status: ArtifactStatus }) {\n  return (\n    <span\n      aria-hidden=\"true\"\n      className={[\n        \"relative grid size-9 shrink-0 place-items-center rounded-lg border font-mono text-[10px] font-medium\",\n        \"transition-colors duration-200 ease-out motion-reduce:transition-none\",\n        status === \"failed\"\n          ? \"border-red-500/35 text-red-600 dark:text-red-400\"\n          : status === \"generating\"\n            ? \"border-sky-500/35 text-sky-600 dark:text-sky-400\"\n            : \"border-zinc-950/10 text-zinc-600 dark:border-white/10 dark:text-zinc-400\",\n      ].join(\" \")}\n    >\n      {status === \"generating\" ? (\n        <svg key=\"running\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" className=\"size-4\">\n          <circle cx=\"8\" cy=\"8\" r=\"6.25\" strokeOpacity=\"0.2\" />\n          <path d=\"M8 1.75A6.25 6.25 0 1 1 1.75 8\" className=\"origin-center motion-safe:animate-spin\" />\n        </svg>\n      ) : status === \"failed\" ? (\n        <svg key=\"failed\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" className={`size-4 ${rise}`}>\n          <circle cx=\"8\" cy=\"8\" r=\"6.25\" />\n          <path d=\"m6.1 6.1 3.8 3.8m0-3.8-3.8 3.8\" />\n        </svg>\n      ) : kind === \"image\" ? (\n        <svg key=\"image\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.25\" strokeLinejoin=\"round\" className=\"size-4\">\n          <rect x=\"2.25\" y=\"3.25\" width=\"11.5\" height=\"9.5\" rx=\"1.5\" />\n          <circle cx=\"5.75\" cy=\"6.5\" r=\"1\" />\n          <path d=\"m2.5 11.5 3.25-3 2.5 2.25 2-1.75 3.25 2.75\" />\n        </svg>\n      ) : kind === \"table\" ? (\n        <svg key=\"table\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.25\" className=\"size-4\">\n          <rect x=\"2.25\" y=\"3.25\" width=\"11.5\" height=\"9.5\" rx=\"1.5\" />\n          <path d=\"M2.25 6.5h11.5M2.25 9.6h11.5M6.25 3.25v9.5\" />\n        </svg>\n      ) : (\n        extension || <PageIcon />\n      )}\n    </span>\n  );\n}\n\nfunction PageIcon() {\n  return (\n    <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.25\" strokeLinejoin=\"round\" className=\"size-5\">\n      <path d=\"M5.5 2.75h6l3 3v11.5h-9z\" />\n      <path d=\"M11.5 2.75v3h3\" />\n    </svg>\n  );\n}\n\n/** Renders `code` and **bold** spans as text; everything else stays plain. */\nfunction inline(text: string) {\n  return text.split(/(`[^`]+`|\\*\\*[^*]+\\*\\*)/g).map((part, index) =>\n    part.startsWith(\"`\") && part.endsWith(\"`\") && part.length > 1 ? (\n      <code key={index} className=\"font-mono text-[0.95em] text-zinc-800 dark:text-zinc-200\">\n        {part.slice(1, -1)}\n      </code>\n    ) : part.startsWith(\"**\") && part.endsWith(\"**\") && part.length > 3 ? (\n      <strong key={index} className=\"font-semibold text-zinc-800 dark:text-zinc-200\">\n        {part.slice(2, -2)}\n      </strong>\n    ) : (\n      part\n    ),\n  );\n}\n\nconst imageExtensions = new Set([\"png\", \"jpg\", \"jpeg\", \"webp\", \"gif\", \"svg\", \"avif\", \"bmp\", \"ico\"]);\nconst tableExtensions = new Set([\"csv\", \"tsv\", \"xlsx\", \"xls\", \"ods\", \"numbers\"]);\nconst documentExtensions = new Set([\"md\", \"markdown\", \"mdx\", \"txt\", \"rtf\", \"log\"]);\nconst codeExtensions = new Set([\n  \"json\", \"ts\", \"tsx\", \"js\", \"jsx\", \"mjs\", \"cjs\", \"py\", \"rb\", \"go\", \"rs\", \"java\", \"kt\", \"swift\", \"c\", \"h\", \"cpp\", \"cs\", \"php\",\n  \"html\", \"css\", \"scss\", \"vue\", \"svelte\", \"yaml\", \"yml\", \"toml\", \"xml\", \"sh\", \"sql\", \"graphql\", \"env\",\n]);\n\n/** Picks a preview kind from the extension first, then the MIME type. */\nexport function kindOf(extension: string, type: string): ArtifactKind {\n  if (imageExtensions.has(extension) || type.startsWith(\"image/\")) return \"image\";\n  if (tableExtensions.has(extension) || /csv|tab-separated|spreadsheet|excel/.test(type)) return \"table\";\n  if (extension === \"pdf\" || type === \"application/pdf\") return \"pdf\";\n  if (documentExtensions.has(extension) || type === \"text/markdown\" || type === \"text/plain\") return \"document\";\n  if (codeExtensions.has(extension) || type.startsWith(\"text/\") || /json|javascript|typescript|xml|yaml/.test(type)) return \"code\";\n  return \"file\";\n}\n\nconst labels: Record<string, string> = {\n  csv: \"CSV\", tsv: \"TSV\", xlsx: \"Excel spreadsheet\", xls: \"Excel spreadsheet\", ods: \"Spreadsheet\", md: \"Markdown\", markdown: \"Markdown\",\n  mdx: \"MDX\", txt: \"Plain text\", json: \"JSON\", ts: \"TypeScript\", tsx: \"TypeScript\", js: \"JavaScript\", jsx: \"JavaScript\",\n  mjs: \"JavaScript\", py: \"Python\", pdf: \"PDF\", svg: \"SVG image\", gif: \"GIF image\", html: \"HTML\", css: \"CSS\", yaml: \"YAML\", yml: \"YAML\",\n  sql: \"SQL\", zip: \"ZIP archive\",\n};\n\nfunction typeLabel(extension: string, type: string, kind: ArtifactKind) {\n  if (labels[extension]) return labels[extension]!;\n  if (kind === \"image\" && extension) return `${extension.toUpperCase()} image`;\n  if (extension) return extension.toUpperCase();\n  return type || \"File\";\n}\n\nfunction isNumeric(value: string | number | undefined) {\n  if (typeof value === \"number\") return true;\n  return value != null && value.trim() !== \"\" && /^[-+]?[$€£]?[\\d,]*\\.?\\d+%?$/.test(value.trim());\n}\n\nfunction prettyJson(content: string) {\n  try {\n    return JSON.stringify(JSON.parse(content), null, 2);\n  } catch {\n    return content;\n  }\n}\n\n/** A small CSV/TSV reader: quoted fields, escaped quotes, and newlines inside quotes. */\nexport function parseDelimited(text: string, separator = \",\"): string[][] {\n  const rows: string[][] = [];\n  let row: string[] = [];\n  let field = \"\";\n  let quoted = false;\n  for (let i = 0; i < text.length; i++) {\n    const char = text[i]!;\n    if (quoted) {\n      if (char === '\"' && text[i + 1] === '\"') {\n        field += '\"';\n        i++;\n      } else if (char === '\"') quoted = false;\n      else field += char;\n    } else if (char === '\"' && field === \"\") quoted = true;\n    else if (char === separator) {\n      row.push(field);\n      field = \"\";\n    } else if (char === \"\\n\" || char === \"\\r\") {\n      if (char === \"\\r\" && text[i + 1] === \"\\n\") i++;\n      row.push(field);\n      rows.push(row);\n      row = [];\n      field = \"\";\n    } else field += char;\n  }\n  if (field !== \"\" || row.length > 0) {\n    row.push(field);\n    rows.push(row);\n  }\n  return rows;\n}\n\nfunction extensionOf(name: string): string {\n  const match = name.match(/\\.([a-z0-9]{1,8})$/i);\n  return match ? match[1]!.toLowerCase() : \"\";\n}\n\nfunction formatSize(bytes: number): string {\n  if (bytes < 1024) return `${bytes} B`;\n  if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;\n  return `${(bytes / 1024 / 1024).toFixed(1)} MB`;\n}\n"
    }
  ],
  "example": {
    "content": "import { ArtifactPreview } from \"@/components/shaken/agent/artifact-preview\";\n\nexport default function ArtifactPreviewExample() {\n  return (\n    <ArtifactPreview\n      className=\"w-full max-w-md\"\n      name=\"rate-limits.csv\"\n      type=\"text/csv\"\n      status=\"ready\"\n      path=\"/artifacts/rate-limits.csv\"\n      sizeBytes={58}\n      content={\"plan,requests_per_minute\\nfree,60\\npro,600\"}\n    />\n  );\n}\n"
  }
}
