Command Palette

Search for a command to run...

Chain of Thought

shadcn/ui

A collapsible reasoning summary expanding into the steps an agent took.

Chain of Thought
app/layout-content.tsxapp/ai-elements/page.tsxregistry.json
trace.tsxbadge.tsx
Mapping interactive step statuses and prop schemas290msValidating strict TypeScript and lint diagnostics210ms

import { RotateCcw } from "lucide-react";import { useEffect, useState } from "react";import {	ChainOfThought,	ChainOfThoughtContent,	ChainOfThoughtHeader,	ChainOfThoughtSearchResult,	ChainOfThoughtSearchResults,	ChainOfThoughtStep,	type ChainOfThoughtStatus,} from "@/components/optics/ai-elements/chain-of-thought";import { Button } from "@/components/optics/button";interface ResearchStep {	id: string;	label: string;	description: string;	results?: string[];}const RESEARCH_STEPS: ResearchStep[] = [	{		id: "search",		label: "Searching workspace for navigation and layout tokens",		description: "320ms",		results: ["app/layout-content.tsx", "app/ai-elements/page.tsx", "registry.json"],	},	{		id: "inspect",		label: "Reading Trace and Badge primitive contracts",		description: "480ms",		results: ["trace.tsx", "badge.tsx"],	},	{		id: "synthesize",		label: "Mapping interactive step statuses and prop schemas",		description: "290ms",	},	{		id: "verify",		label: "Validating strict TypeScript and lint diagnostics",		description: "210ms",	},];function getStepStatus(index: number, activeStep: number): ChainOfThoughtStatus {	if (index < activeStep) {		return "complete";	}	if (index === activeStep) {		return "active";	}	return "pending";}function ChainOfThoughtDemo() {	const [traceState, setTraceState] = useState({ activeStep: 1, runId: 0 });	const isComplete = traceState.activeStep >= RESEARCH_STEPS.length;	useEffect(() => {		if (traceState.activeStep >= RESEARCH_STEPS.length) {			return;		}		const timer = setTimeout(() => {			setTraceState((prev) => ({ ...prev, activeStep: prev.activeStep + 1 }));		}, 1300);		return () => clearTimeout(timer);	}, [traceState.activeStep, traceState.runId]);	return (		<div className="flex w-full max-w-lg flex-col gap-4">			<ChainOfThought defaultOpen className="rounded-xl border bg-background p-4">				<ChainOfThoughtHeader status={isComplete ? "complete" : "active"}>					{isComplete ? "Researched in 4 steps" : "Researching implementation..."}				</ChainOfThoughtHeader>				<ChainOfThoughtContent>					{RESEARCH_STEPS.map((step, index) => {						const status = getStepStatus(index, traceState.activeStep);						return (							<ChainOfThoughtStep								key={step.id}								label={step.label}								description={step.description}								status={status}							>								{step.results && status !== "pending" ? (									<ChainOfThoughtSearchResults>										{step.results.map((result) => (											<ChainOfThoughtSearchResult key={result}>												{result}											</ChainOfThoughtSearchResult>										))}									</ChainOfThoughtSearchResults>								) : null}							</ChainOfThoughtStep>						);					})}				</ChainOfThoughtContent>			</ChainOfThought>			<div className="flex items-center justify-end">				<Button					type="button"					variant="outline"					size="sm"					onClick={() => setTraceState((prev) => ({ activeStep: 0, runId: prev.runId + 1 }))}				>					<RotateCcw />					Replay				</Button>			</div>		</div>	);}<ChainOfThoughtDemo />

Installation

pnpm dlx shadcn@latest add @optics/ai-chain-of-thought

Props

<ChainOfThought />
Name
Type
open
boolean
defaultOpen
boolean(default: false)
onOpenChange
((open: boolean) => void)

<ChainOfThoughtHeader />
Name
Type
icon
React.ReactNode | IconComponent
status
import("/vercel/path0/registry/optics/ai-elements/chain-o...
render
React.ReactElement
nativeButton
boolean
<ChainOfThoughtContent />
Name
Type
keepMounted
boolean(default: true)
render
React.ReactElement
hiddenUntilFound
boolean
forceMount
boolean
<ChainOfThoughtStep />
Name
Type
icon
React.ReactNode | IconComponent
label
React.ReactNode
description
React.ReactNode
status
import("/vercel/path0/registry/optics/ai-elements/chain-o...(default: complete)
defaultOpen
boolean(default: true)
<ChainOfThoughtSearchResult />
Name
Type
variant
"link" | "outline" | "default"(default: secondary)