Reasoning
Display an AI model's extended thinking with a shimmering header, live seconds counter, two-line streaming preview, and collapsible headed steps on a vertical rail.
import { Reasoning } from '@uthereal/ui/reasoning'Reasoning playground
Reading the webhook handler
The handler in api/billing/webhook.ts verifies the signature and runs fulfillOrder on every invoice.paid event without recording processed event IDs.
Checking Stripe retry timing
Stripe redelivers when the endpoint times out. Logs show fulfillOrder averages 11.4s because PDF receipts render inline before returning 200.
Choosing a fix
Record event.id in processed_events inside the same transaction, derive the idempotency key from the invoice ID, and move PDF rendering to a background job.
Overview
Reasoning renders the collapsible extended-thinking block above an AI reply. While status is thinking, the header shimmers Thinking, counts elapsed seconds in tabular numerals, and streams the latest text in a two-line preview. When status switches to complete, the block folds to Thought for Ns and expands into headed steps connected along a vertical rail with a Copy reasoning control.
Use Reasoning when an assistant exposes extended thinking or a chain-of-thought summary before answering. For tool calls with structured inputs, outputs, and approvals, use Tools. For an editable, approvable step checklist, use Plan. For a single-line busy indicator without expandable reasoning text, use Thinking indicator. For the formatted, cited reply below the reasoning block, use Answer.
Usage
'use client'
import { Reasoning } from '@uthereal/ui/reasoning'
export function AssistantReasoning({
text,
done,
seconds,
onAbort,
}: {
text: string
done: boolean
seconds?: number
onAbort: () => void
}) {
return (
<Reasoning
reasoning={text}
status={done ? 'complete' : 'thinking'}
seconds={done ? seconds : undefined}
modelName="Claude Opus 5.5"
modelBrand="anthropic"
onStop={onAbort}
/>
)
}Pass the growing reasoning string while the model streams and switch status to complete when answer tokens start. Omit seconds during streaming to measure elapsed time automatically, then store and pass the recorded seconds when restoring historical messages.
Examples
Live thinking preview
While status is thinking, the header shows a shimmering label, a live seconds counter, a Stop action, and a two-line preview anchored to the newest wrapped line. Settled headed steps are live in the playground above.
Interruption recovery and plain embedding
Use status="stopped" after an abort and status="error" with error and retryAction or onRetry when a stream fails. Set variant="plain" when placing Reasoning inside an existing bordered message container so cards never nest.
Gathering unpaid invoices
Checked 18 invoices from September before generation was stopped by the user.
Auditing database migrations
Started scanning migrations for unindexed foreign keys before the stream dropped.
Summarizing diff
All touched files preserve existing prop defaults and pass strict Zod schema validation.
Lifecycle states and parsing
Each status pairs a distinct label, icon, and footer message so state never relies on color alone.
| Status | Header label | Live preview | Header action | Footer inside expanded panel |
|---|---|---|---|---|
thinking | Shimmering Thinking + rolling Ns | Two lines | Stop | Hidden while streaming |
complete | Thought for Ns (or Thought process) | Hidden | None | Check icon + Done + Copy reasoning |
stopped | Stopped after Ns (or Stopped thinking) | Hidden | None | Square icon + Stopped before finishing + copy |
error | Alert icon + Thinking interrupted | Hidden | Retry | Alert icon + error reason (or default text) + copy |
The exported parseReasoning(input) helper converts a raw streaming string or ReasoningStep[] array into normalized { title?, text } steps:
- Blank lines separate paragraphs within the current step.
- Lines formatted as
**Heading**or## Headingstart a new headed step. - An incomplete trailing
**Headingline still streaming never flashes raw asterisks.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
reasoning | string | ReasoningStep[]— | Streamed reasoning text or structured steps. Blank lines split paragraphs, and **Heading** or ## Heading lines start new steps without flashing partial asterisks while streaming. |
status | thinking | complete | stopped | errorDefault: "complete" | Lifecycle state: thinking shimmers with a live counter and two-line preview; complete folds to "Thought for Ns"; stopped reports an aborted trace; error shows an interruption icon and recovery detail. |
seconds | number— | Seconds spent thinking, formatted as 7s or 1m 12s. Omit while thinking to measure elapsed seconds live; a completed block without seconds reads "Thought process". |
modelName | stringDefault: "Claude Opus 5.5" | Model name read by assistive technology for the group label and thinking announcement. |
modelBrand | anthropic | openai | google | mistral | xai | customDefault: "anthropic" | Built-in 18px provider mark drawn at the leading edge of the header. |
error | string— | Reason displayed in the expanded footer when status is error. |
variant | card | plainDefault: "card" | Surface presentation: card draws a bordered surface; plain drops the border and outer padding to sit flush inside a message bubble. |
defaultOpen | booleanDefault: false | Initial expanded state; edits do not reset a mounted instance. |
copyable | booleanDefault: true | Show the Copy reasoning button inside the expanded footer once thinking settles. |
stopAction | string— | Registered host action requested when Stop is pressed while thinking. |
retryAction | string— | Registered host action requested when Retry is pressed in error status. |
locale | string— | BCP 47 locale for duration formatting; inherited when omitted. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes preserve interaction behavior. |
theme | ReasoningThemeDefault: {} | Color mode, accent, and typed semantic token overrides. |
motion | none | subtle | expressiveDefault: "subtle" | Animation preset. System reduced-motion preferences take precedence. |
motionOptions | ReasoningMotionOptionsDefault: {} | Fold spring, chunk fade, and shimmer sweep timing overrides in milliseconds. |
dir | ltr | rtl— | Reading direction; inherited from the page when omitted. |
ReasoningStep accepts { title?, text }.
React integration
| Prop | Purpose |
|---|---|
open | Controlled expanded state of the full reasoning panel. Pair with onOpenChange. |
onOpenChange(open) | Called when the header toggle is pressed in controlled or uncontrolled mode. |
onStop() | Shows the Stop header button while status is thinking and runs when pressed. |
onRetry() | Shows the Retry header button when status is error and runs when pressed. |
onAction(action) | Called for registered host actions (stopAction, retryAction). |
onCopyResult(copied) | Called after Copy reasoning runs with whether the clipboard write succeeded. |
renderModelMark() | Custom 18px decorative provider mark replacing the built-in modelBrand mark. |
preset | Application defaults overridden by explicit instance arguments. |
tokens | CSS variables applied after the typed theme. |
ref, className, style | Applied to the root role="group" container. |
| Native attributes | id, aria-*, data-*, and remaining <div> props forwarded to the root container. |
Keyboard & accessibility
| Key | Action |
|---|---|
Tab | Moves to the header toggle, then to Stop or Retry when shown, then to Copy reasoning. |
Enter / Space | Expands or collapses the reasoning panel from the header toggle. |
The root renders role="group" labelled with modelName ("<modelName> reasoning"). The header uses a native <button> with aria-expanded, aria-controls, and aria-labelledby. The expanded panel renders a role="region" carrying aria-busy while status is thinking, and the two-line live preview sets aria-hidden="true" so screen readers do not duplicate streamed text. A polite role="status" live region announces status transitions only, never individual seconds or chunks. Logical CSS properties preserve alignment in RTL (dir="rtl"), and forced-colors: active maps card borders, rail lines, step dots, and focus outlines to system colors.
Motion and theming
Opening and closing the reasoning panel and collapsing the live preview animate measured height on a critically damped 260ms bounce-free spring paired with a 160ms opacity fade. When text wraps in the two-line live preview, it glides upward on a 240ms bounce-free spring driven by a single ResizeObserver. Newly appended streamed chunks fade in once over 140ms, header label swaps crossfade (100ms out, 160ms in with a 2px rise), and the elapsed seconds counter rolls inside a reserved tabular width. The Thinking shimmer pauses offscreen and in background tabs. prefers-reduced-motion: reduce drops the shimmer sweep, live-tail glide, chunk fades, and height springs while keeping 120ms opacity crossfades; motion="none" makes every change immediate (0ms).
theme accepts a mode, an accent, and semantic tokens for surfaces, borders, text, semantic status colors, radii, typography, and control sizing. An application-wide UtherealProvider supplies defaults.
Composition
In an agent composition, Reasoning is a leaf. Supply status, reasoning, and recorded seconds from host state. stopAction and retryAction must name registered host actions. See Building with agents.
{
"type": "Reasoning",
"props": {
"modelName": "Claude Opus 5.5",
"modelBrand": "anthropic",
"status": "complete",
"seconds": 7,
"variant": "card",
"reasoning": [
{
"title": "Reading the webhook handler",
"text": "The handler verifies the signature and runs fulfillOrder on every invoice.paid event without recording processed event IDs."
},
{
"title": "Choosing a fix",
"text": "Record event.id in processed_events inside the same transaction and derive the idempotency key from the invoice ID."
}
]
},
"children": []
}