UI

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

Thought for 7s
  1. 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.

  2. 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.

  3. 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.

Done
Loading interactive preview…

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.

Thinking

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.

Stopped after 5s
  1. Gathering unpaid invoices

    Checked 18 invoices from September before generation was stopped by the user.

Stopped before finishing
Thinking interrupted
  1. Auditing database migrations

    Started scanning migrations for unindexed foreign keys before the stream dropped.

Stream closed unexpectedly by the upstream model gateway.
Thought for 6s
  1. Summarizing diff

    All touched files preserve existing prop defaults and pass strict Zod schema validation.

Done

Lifecycle states and parsing

Each status pairs a distinct label, icon, and footer message so state never relies on color alone.

StatusHeader labelLive previewHeader actionFooter inside expanded panel
thinkingShimmering Thinking + rolling NsTwo linesStopHidden while streaming
completeThought for Ns (or Thought process)HiddenNoneCheck icon + Done + Copy reasoning
stoppedStopped after Ns (or Stopped thinking)HiddenNoneSquare icon + Stopped before finishing + copy
errorAlert icon + Thinking interruptedHiddenRetryAlert 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 ## Heading start a new headed step.
  • An incomplete trailing **Heading line still streaming never flashes raw asterisks.

API reference

These serializable arguments and defaults come directly from the component schema.

ArgumentType / defaultDescription
reasoningstring | 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.
statusthinking | 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.
secondsnumber—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".
modelNamestringDefault: "Claude Opus 5.5"Model name read by assistive technology for the group label and thinking announcement.
modelBrandanthropic | openai | google | mistral | xai | customDefault: "anthropic"Built-in 18px provider mark drawn at the leading edge of the header.
errorstring—Reason displayed in the expanded footer when status is error.
variantcard | plainDefault: "card"Surface presentation: card draws a bordered surface; plain drops the border and outer padding to sit flush inside a message bubble.
defaultOpenbooleanDefault: falseInitial expanded state; edits do not reset a mounted instance.
copyablebooleanDefault: trueShow the Copy reasoning button inside the expanded footer once thinking settles.
stopActionstring—Registered host action requested when Stop is pressed while thinking.
retryActionstring—Registered host action requested when Retry is pressed in error status.
localestring—BCP 47 locale for duration formatting; inherited when omitted.
recipestudio | softDefault: "studio"Visual treatment. Both recipes preserve interaction behavior.
themeReasoningThemeDefault: {}Color mode, accent, and typed semantic token overrides.
motionnone | subtle | expressiveDefault: "subtle"Animation preset. System reduced-motion preferences take precedence.
motionOptionsReasoningMotionOptionsDefault: {}Fold spring, chunk fade, and shimmer sweep timing overrides in milliseconds.
dirltr | rtl—Reading direction; inherited from the page when omitted.

ReasoningStep accepts { title?, text }.

React integration

PropPurpose
openControlled 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.
presetApplication defaults overridden by explicit instance arguments.
tokensCSS variables applied after the typed theme.
ref, className, styleApplied to the root role="group" container.
Native attributesid, aria-*, data-*, and remaining <div> props forwarded to the root container.

Keyboard & accessibility

KeyAction
TabMoves to the header toggle, then to Stop or Retry when shown, then to Copy reasoning.
Enter / SpaceExpands 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": []
}

On this page