{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "reasoning",
  "title": "AI Reasoning",
  "description": "Collapsible reasoning content with streaming awareness for DeepSeek R1-style thinking visualization.",
  "dependencies": [
    "@radix-ui/react-collapsible",
    "lucide-react"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/default/blocks/ai/ai-reasoning/components/elements/ai-reasoning.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport * as CollapsiblePrimitive from \"@radix-ui/react-collapsible\";\nimport { ChevronDown } from \"lucide-react\";\n\nimport { cn } from \"@/lib/utils\";\n\ninterface AiReasoningContextValue {\n  isStreaming: boolean;\n  isOpen: boolean;\n  thinkingDuration: number | null;\n}\n\nconst AiReasoningContext = React.createContext<AiReasoningContextValue | null>(\n  null\n);\n\nfunction useReasoningContext() {\n  const context = React.useContext(AiReasoningContext);\n  if (!context) {\n    throw new Error(\"AiReasoning components must be used within <AiReasoning>\");\n  }\n  return context;\n}\n\ninterface AiReasoningProps {\n  isStreaming?: boolean;\n  defaultOpen?: boolean;\n  open?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  thinkingDuration?: number | null;\n  children?: React.ReactNode;\n  className?: string;\n}\n\nfunction AiReasoning({\n  isStreaming = false,\n  defaultOpen = false,\n  open: controlledOpen,\n  onOpenChange,\n  thinkingDuration = null,\n  children,\n  className,\n}: AiReasoningProps) {\n  const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);\n\n  const isControlled = controlledOpen !== undefined;\n  const isOpen = isControlled ? controlledOpen : uncontrolledOpen;\n\n  const handleOpenChange = React.useCallback(\n    (open: boolean) => {\n      if (!isControlled) {\n        setUncontrolledOpen(open);\n      }\n      onOpenChange?.(open);\n    },\n    [isControlled, onOpenChange]\n  );\n\n  React.useEffect(() => {\n    if (isStreaming) {\n      handleOpenChange(true);\n    }\n  }, [isStreaming, handleOpenChange]);\n\n  const contextValue = React.useMemo(\n    () => ({ isStreaming, isOpen, thinkingDuration }),\n    [isStreaming, isOpen, thinkingDuration]\n  );\n\n  return (\n    <AiReasoningContext.Provider value={contextValue}>\n      <CollapsiblePrimitive.Root\n        data-slot=\"ai-reasoning\"\n        data-streaming={isStreaming}\n        open={isOpen}\n        onOpenChange={handleOpenChange}\n        className={cn(\n          \"border bg-background font-mono text-foreground transition-colors\",\n          className\n        )}\n      >\n        {children}\n      </CollapsiblePrimitive.Root>\n    </AiReasoningContext.Provider>\n  );\n}\n\ninterface AiReasoningTriggerProps {\n  children?: React.ReactNode;\n  className?: string;\n}\n\nfunction AiReasoningTrigger({ children, className }: AiReasoningTriggerProps) {\n  const { isStreaming, isOpen, thinkingDuration } = useReasoningContext();\n\n  const formattedDuration = React.useMemo(() => {\n    if (thinkingDuration === null) return null;\n    if (thinkingDuration < 1000) return `${thinkingDuration}ms`;\n    return `${(thinkingDuration / 1000).toFixed(1)}s`;\n  }, [thinkingDuration]);\n\n  return (\n    <CollapsiblePrimitive.Trigger\n      data-slot=\"ai-reasoning-trigger\"\n      className={cn(\n        \"flex w-full items-center gap-3 px-4 py-3 text-xs uppercase tracking-wider transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring\",\n        className\n      )}\n    >\n      <div className=\"flex flex-1 items-center gap-2 text-left\">\n        <span>{isStreaming ? \"THINKING...\" : \"REASONING\"}</span>\n        {isStreaming && (\n          <span className=\"inline-flex items-center gap-1 border px-2 py-0.5 text-[10px] tracking-widest\">\n            <span className=\"relative flex size-1.5\">\n              <span className=\"absolute inline-flex size-full animate-ping bg-foreground opacity-75\" />\n              <span className=\"relative inline-flex size-1.5 bg-foreground\" />\n            </span>\n            STREAMING\n          </span>\n        )}\n        {!isStreaming && formattedDuration && (\n          <span className=\"text-[10px] text-muted-foreground\">\n            {formattedDuration}\n          </span>\n        )}\n      </div>\n      {children}\n      <ChevronDown\n        className={cn(\n          \"size-3.5 shrink-0 text-muted-foreground transition-transform duration-200\",\n          isOpen && \"rotate-180\"\n        )}\n      />\n    </CollapsiblePrimitive.Trigger>\n  );\n}\n\ninterface AiReasoningContentProps {\n  children?: React.ReactNode;\n  className?: string;\n}\n\nfunction AiReasoningContent({ children, className }: AiReasoningContentProps) {\n  const { isStreaming } = useReasoningContext();\n\n  return (\n    <CollapsiblePrimitive.Content\n      data-slot=\"ai-reasoning-content\"\n      className={cn(\n        \"border-t data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down\",\n        className\n      )}\n    >\n      <div\n        className={cn(\n          \"p-4 text-xs text-muted-foreground\",\n          isStreaming && \"animate-pulse\"\n        )}\n      >\n        {children}\n        {isStreaming && (\n          <span className=\"ml-1 inline-block h-3 w-[2px] animate-pulse bg-foreground\" />\n        )}\n      </div>\n    </CollapsiblePrimitive.Content>\n  );\n}\n\ninterface AiReasoningTextProps {\n  children?: React.ReactNode;\n  className?: string;\n}\n\nfunction AiReasoningText({ children, className }: AiReasoningTextProps) {\n  return (\n    <div\n      data-slot=\"ai-reasoning-text\"\n      className={cn(\"whitespace-pre-wrap text-xs leading-relaxed\", className)}\n    >\n      {children}\n    </div>\n  );\n}\n\nexport { AiReasoning, AiReasoningTrigger, AiReasoningContent, AiReasoningText };\nexport type { AiReasoningProps };\n",
      "type": "registry:component"
    }
  ],
  "docs": "Auto-opens during streaming, shows thinking duration. Compound component with trigger and content.",
  "categories": [
    "ai"
  ],
  "type": "registry:ui"
}