{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "response",
  "type": "registry:ui",
  "title": "Response",
  "description": "Streaming-safe markdown renderer that hardens incomplete blocks.",
  "dependencies": [
    "react-markdown",
    "remark-gfm"
  ],
  "registryDependencies": [
    "https://seamui.dev/r/utils.json",
    "https://seamui.dev/r/code-block.json"
  ],
  "files": [
    {
      "path": "registry/seam/ui/response.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport ReactMarkdown, { type Components } from \"react-markdown\"\nimport remarkGfm from \"remark-gfm\"\n\nimport { cn } from \"@/lib/utils\"\nimport { CodeBlock } from \"./code-block\"\n\n// Streaming hardening: a half-arrived response often ends mid-code-fence. Left\n// as-is, the open ``` swallows the rest of the stream into one broken <pre>.\n// Closing the dangling fence keeps each frame renderable while tokens land.\nfunction completeMarkdown(md: string): string {\n  const fences = md.match(/^[ \\t]*(```|~~~)/gm)\n  if (fences && fences.length % 2 === 1) {\n    const marker = fences[fences.length - 1].trim().slice(0, 3)\n    return `${md}\\n${marker}`\n  }\n  return md\n}\n\n// Fenced code renders through the seam CodeBlock (well + copy + highlight);\n// inline code stays a debossed chip. `pre` becomes a pass-through since\n// CodeBlock brings its own container.\nconst components: Components = {\n  a: ({ className, ...props }) => (\n    <a\n      className={cn(\n        \"text-primary font-medium underline underline-offset-4\",\n        className\n      )}\n      target=\"_blank\"\n      rel=\"noreferrer\"\n      {...props}\n    />\n  ),\n  pre: ({ children }) => <>{children}</>,\n  code: ({ className, children, ...props }) => {\n    const match = /language-(\\w+)/.exec(className ?? \"\")\n    const text = String(children ?? \"\")\n    // A fence with no language still arrives multiline — treat it as a block.\n    const isBlock = !!match || text.includes(\"\\n\")\n    if (isBlock) {\n      return (\n        <CodeBlock\n          code={text.replace(/\\n$/, \"\")}\n          language={match?.[1] ?? \"text\"}\n          className=\"my-3\"\n        />\n      )\n    }\n    return (\n      <code\n        className={cn(\n          \"bg-muted rounded squircle px-1.5 py-0.5 text-[0.85em] shadow-well\",\n          className\n        )}\n        {...props}\n      >\n        {children}\n      </code>\n    )\n  },\n  table: ({ className, ...props }) => (\n    <div className=\"my-3 overflow-x-auto\">\n      <table\n        className={cn(\"w-full border-collapse text-sm\", className)}\n        {...props}\n      />\n    </div>\n  ),\n  th: ({ className, ...props }) => (\n    <th\n      className={cn(\n        \"border border-border/60 px-3 py-1.5 text-left font-medium\",\n        className\n      )}\n      {...props}\n    />\n  ),\n  td: ({ className, ...props }) => (\n    <td\n      className={cn(\"border border-border/60 px-3 py-1.5\", className)}\n      {...props}\n    />\n  ),\n}\n\n// Renders a (possibly incomplete) markdown string as flat seam prose. Prose\n// sits on the canvas — no bubble, no depth; depth belongs to interactive\n// things. Streamed text appends without per-character animation (explicitly\n// forbidden) and without layout springs — reflowing text must never bounce;\n// the sense of life comes from the viewport following along, not the letters.\nfunction Response({\n  className,\n  children,\n  ...props\n}: Omit<React.ComponentProps<\"div\">, \"children\"> & { children: string }) {\n  const safe = React.useMemo(() => completeMarkdown(children ?? \"\"), [children])\n\n  return (\n    <div\n      data-slot=\"response\"\n      className={cn(\n        \"text-sm leading-relaxed\",\n        \"space-y-3 [&>:first-child]:mt-0 [&>:last-child]:mb-0\",\n        \"[&_ul]:my-3 [&_ul]:list-disc [&_ul]:pl-5 [&_ol]:my-3 [&_ol]:list-decimal [&_ol]:pl-5 [&_li]:my-1\",\n        \"[&_h1]:mt-4 [&_h1]:text-lg [&_h1]:font-semibold [&_h2]:mt-4 [&_h2]:text-base [&_h2]:font-semibold [&_h3]:mt-3 [&_h3]:font-medium\",\n        \"[&_blockquote]:border-l-2 [&_blockquote]:border-border [&_blockquote]:pl-3 [&_blockquote]:text-muted-foreground\",\n        \"[&_strong]:font-semibold [&_hr]:my-4 [&_hr]:border-border\",\n        className\n      )}\n      {...props}\n    >\n      <ReactMarkdown remarkPlugins={[remarkGfm]} components={components}>\n        {safe}\n      </ReactMarkdown>\n    </div>\n  )\n}\n\nexport { Response }\n",
      "type": "registry:ui",
      "target": "components/ui/response.tsx"
    }
  ]
}