Skip to main content

Reasoning

A collapsible reasoning disclosure that auto-opens while streaming, counts elapsed seconds with rolling digits, and auto-closes after streaming finishes.

@heroicons/react

Inspecting active motion tokens and reduced-motion preferences across the container tree.

Measuring collapsible content bounds so spring height transitions avoid layout snaps.

Scheduling post-stream auto-collapse timer after final token arrival.

Customize

Speed0.45
Blur reveal (px)8
Auto-close delay (ms)1000

Installation

npx shadcn@latest add @kinetic/reasoning

Usage

Compose Reasoning, ReasoningTrigger, and ReasoningContent to present model thought traces without overwhelming the chat turn.

import {
  Reasoning,
  ReasoningContent,
  ReasoningTrigger,
} from "@/components/kinetic/ui/reasoning";

export function ThoughtPanel() {
  return (
    <Reasoning isStreaming={false} duration={4} defaultOpen>
      <ReasoningTrigger />
      <ReasoningContent>
        Checked cached parser tokens and selected the direct AST path.
      </ReasoningContent>
    </Reasoning>
  );
}

Streaming and auto-close

When isStreaming flips from false to true, Reasoning opens automatically and starts counting elapsed seconds with RollingDigits. Once isStreaming returns to false, it waits autoCloseDelayMs (default 1000 ms) before collapsing. Pass autoClose={false} or autoCloseDelayMs={0} to keep the panel open, or pass duration explicitly if your backend already tracks elapsed time.

interface StreamThoughtProps {
  readonly streaming: boolean;
  readonly text: string;
}

export function StreamThought({ streaming, text }: StreamThoughtProps) {
  return (
    <Reasoning isStreaming={streaming} autoCloseDelayMs={1200}>
      <ReasoningTrigger />
      <ReasoningContent>{text}</ReasoningContent>
    </Reasoning>
  );
}

Motion preferences

Height changes run on an interruptible spring via useAnimatedSize, while content reveals monotonically from blur to sharp so streaming text growth never re-blurs earlier lines. Use speed (0.45 default) and blurPx (8 default) to tune pacing; reduced motion opens and closes immediately.

API Reference

Reasoning

Zero-dependency streaming reasoning container with RollingDigits elapsed timer, auto-open/auto-close lifecycle, and shared motion tuning.

PropTypeDefaultDescription
open / defaultOpen / onOpenChangeboolean / boolean / (open: boolean) => voidfalseControlled or initial expanded state; defaults to open when isStreaming starts true.
isStreaming / durationboolean / numberfalse / undefinedDrives auto-open, live elapsed second counting via RollingDigits, and delayed auto-close.
autoClose / autoCloseDelayMsboolean / numbertrue / 1000Automatically closes after streaming ends; set autoClose={false} or 0 to keep open.
speed / blurPxnumber / number0.45 / 8Speed multiplier and initial blur radius (px) for content expansion and reveal.
keepMounted / disabledboolean / booleanfalse / falseKeeps closed content mounted or disables user toggle interactions.

ReasoningTrigger / ReasoningContent

Rotating-chevron disclosure trigger with RollingDigits timer and monotonic blur-fade height-animated body.

PropTypeDefaultDescription
getThinkingMessage (ReasoningTrigger)(isStreaming: boolean, duration?: number) => React.ReactNode-Optional custom formatter replacing the default thinking and duration label.
keepMounted / forceMount (ReasoningContent)boolean / booleanfalseKeeps children mounted while collapsed.
speed / blurPx (ReasoningContent)number / numberinheritedOptional per-content overrides for reveal speed and blur radius.

Notes

Pass duration directly when your backend already reports reasoning seconds, or omit it to let Reasoning measure elapsed streaming time automatically.