Chain of Thought

A composable component for displaying AI's step-by-step reasoning process. Features collapsible steps with custom icons, content items, and visual connectors to show the thinking flow.

Installation

Copy and paste the following code into your project.

pnpm dlx shadcn-svelte@latest add https://svelte-ai-elements.vercel.app/p/chain-of-thought.json

Examples

Basic Usage

A simple chain of thought showing the AI's reasoning process for selecting a sorting algorithm. Each step is collapsible and shows the progression of thought.

Advanced with Icons and Code

A more complex example showing database optimization reasoning with custom icons for each step and embedded code blocks. Demonstrates the full power of the component with rich content.

Component API

ChainOfThought

PropTypeDefaultDescription
childrenSnippet-The ChainOfThoughtStep components to display
classstring-Additional CSS classes

ChainOfThoughtStep

PropTypeDefaultDescription
childrenSnippet-The trigger and content components
classstring-Additional CSS classes
isLastbooleanfalseWhether this is the last step (hides connector line)
openboolean-Control the open state (makes component controlled)
onOpenChange(open: boolean) => void-Callback when open state changes
...propsCollapsibleRootProps-Additional Collapsible component props from bits-ui

ChainOfThoughtTrigger

PropTypeDefaultDescription
childrenSnippet-The trigger text content
classstring-Additional CSS classes
leftIconSnippet-Optional icon to display on the left side
swapIconOnHoverbooleantrueWhether to swap the left icon with chevron on hover
...propsCollapsibleTriggerProps-Additional Collapsible trigger props from bits-ui

ChainOfThoughtContent

PropTypeDefaultDescription
childrenSnippet-The content items to display
classstring-Additional CSS classes
...propsCollapsibleContentProps-Additional Collapsible content props from bits-ui

ChainOfThoughtItem

PropTypeDefaultDescription
childrenSnippet-The item content
classstring-Additional CSS classes
...propsHTMLAttributes<HTMLDivElement>-Additional HTML div props

Usage Notes

Component Structure

The Chain of Thought component follows a composable pattern. Wrap your steps in ChainOfThought, then use ChainOfThoughtStep for each reasoning step. Each step contains a ChainOfThoughtTrigger and ChainOfThoughtContent.

Custom Icons

Use the leftIcon snippet prop on the trigger to add custom icons from @lucide/svelte. By default, the icon swaps with a chevron on hover, but you can disable this with swapIconOnHover={false}.

Visual Connectors

The component automatically adds visual connector lines between steps. Set isLast={true} on the final step to hide the connector line after it.

Rich Content

You can embed any content inside ChainOfThoughtItem, including code blocks, images, or other components. This makes it perfect for showing complex reasoning with examples.