For the complete documentation index, see llms.txt. Markdown variants are available by appending .md to any URL or sending an Accept: text/markdown header. An agent skill is available at /.well-known/agent-skills/site-skill.md.
FrakmentFrakment

Chain of Thought

Displays a summary that expands into the steps an agent took.

Why is the checkout deploy so slow?
install    41s
compile    38s
images   3m 52s
next.config.tsscripts/optimize-images.ts

Image optimization takes almost four minutes because its cache key includes the commit hash. Key it on the image directory instead.

Chain of Thought is a summary line that expands into the steps an agent took. The summary says what happened, like "Researched in 3 steps". The steps sit inside it, each one a line of its own.

Installation

Usage

example.tsx
import {
  ChainOfThought,
  ChainOfThoughtHeader,
  ChainOfThoughtContent,
  ChainOfThoughtStep,
} from "@/components/ui/chain-of-thought";
chainofthought.tsx
<ChainOfThought defaultOpen>
  <ChainOfThoughtHeader>Researched in 3 steps</ChainOfThoughtHeader>
  <ChainOfThoughtContent>
    <ChainOfThoughtStep>Read the build log for dpl_8Kx2</ChainOfThoughtStep>
    <ChainOfThoughtStep>
      Checked bundle size for dashboard.js
    </ChainOfThoughtStep>
    <ChainOfThoughtStep>Profiled 3 API endpoints</ChainOfThoughtStep>
  </ChainOfThoughtContent>
</ChainOfThought>

Full demo

The preview on this page shows the chain-of-thought primitive composing with useChat, createChat, and transport from @frakment/ai. It streams three tool calls with a line-by-line build log and uses nested TraceCollapsible for auto-expand and manual toggle.

The composition pulls @ai-sdk/react, ai, badge, bubble, button, code-block, message, and trace. Follow the Chat tutorial for the wiring pattern, or replace createChat with your own backend that streams data-buildLog and tool parts.

In Context

Research summary

Why is the checkout deploy so slow?
install    41s
compile    38s
images   3m 52s
next.config.tsscripts/optimize-images.ts

Image optimization takes almost four minutes because its cache key includes the commit hash. Key it on the image directory instead.

API Reference

PropTypeDefaultDescription
status
runningerrorpending
—Set on TraceLine. Controls color, and shimmer when running.
openboolean—Controlled open state on TraceCollapsible. Use open={open ?? running} to open while steps stream.
defaultOpenboolean—Start expanded. Useful for static content.

Accessibility

  • TraceIcon is aria-hidden. TraceTitle is the accessible name. Write it as a sentence: "Searched for minimumReleaseAge", not just "minimumReleaseAge".
  • Status is conveyed by icon shape and color, not color alone.
  • prefers-reduced-motion: shimmer stops automatically.
  • Use open={open ?? running} so a reader's manual toggle wins over the auto state.

Anatomy

chain-of-thought.tsx
<ChainOfThought>
  <ChainOfThoughtHeader />
  <ChainOfThoughtContent>
    <ChainOfThoughtStep />
  </ChainOfThoughtContent>
</ChainOfThought>
  • ChainOfThought — collapsible root
  • ChainOfThoughtHeader — summary line ("Researched in 3 steps")
  • ChainOfThoughtContent — step list
  • ChainOfThoughtStep — one step with a Trace line

Best Practices

  • One summary per turn. The header is a single line, not a tree.
  • Keep steps atomic. One action per step.
  • Collapse by default. Steps expand on demand.
  • Keep nesting shallow. Two levels is enough.