Reasoning

The Reasoning component displays AI reasoning content, automatically opening during streaming and closing when finished.

Installation

pnpm dlx shadcn-svelte@latest add https://svelte-ai-elements.vercel.app/r/reasoning.json

If you prefer using jsrepo, please install via the command below:

pnpm dlx jsrepo add @ai/elements/ai-elements/reasoning

Usage

Usage with AI SDK

Build a chatbot with reasoning using Deepseek R1.

Add the following component to your frontend:

+page.svelte

Add the following route to your backend:

api/chat/+server.ts

Features

  • Automatically opens when streaming content and closes when finished
  • Manual toggle control for user interaction
  • Smooth animations and transitions powered by Radix UI
  • Visual streaming indicator with pulsing animation
  • Composable architecture with separate trigger and content components
  • Built with accessibility in mind including keyboard navigation
  • Responsive design that works across different screen sizes
  • Seamlessly integrates with both light and dark themes
  • Built on top of shadcn-svelte Collapsible primitives
  • TypeScript support with proper type definitions

Props

Reasoning

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the reasoning container
isStreamingbooleanfalseWhether the AI is currently streaming reasoning content
openboolean-Controlled state for whether the reasoning content is expanded (bindable)
defaultOpenbooleantrueDefault open state when not controlled
onOpenChange(open: boolean) => void-Callback fired when the open state changes
durationnumber-Duration in seconds that the AI spent reasoning (bindable)
childrenSnippet-Child components (typically ReasoningTrigger and ReasoningContent)
...propsCollapsibleProps-All other Collapsible component props are supported

ReasoningTrigger

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the trigger button
childrenSnippet-Custom trigger content (defaults to brain icon with thinking message)
...propsCollapsibleTriggerProps-All other CollapsibleTrigger component props are supported

ReasoningContent

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the content container
childrenSnippet-The reasoning content to display when expanded
...propsCollapsibleContentProps-All other CollapsibleContent component props are supported

Response

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the response container
childrenSnippet-Response content to render
...propsHTMLAttributes<HTMLDivElement>-All other div props are supported