Chain of Thought
A timeline of reasoning and tool-call steps.
Usage
Basic
Loading demo...
Best Practices
- Key steps by a stable
id, not an array index. - Keep at most one
activestep; body following applies to only one. - A thinking body can be handed over whole: the component releases it at a steady pace itself, so the host does not split a paragraph into small pieces to feed it.
- Move a finished step from
activetodoneorerror, or its spinner stays. - Write tool titles as call signatures (
read_file(src/main.ts)), not bare tool names. - For custom step rendering, compose
TxReasoningDisclosureandTxToolCallCard.
API Reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
steps | AiChainStep[] | — | The steps, required. AiChainStep is { id, kind: 'thinking' | 'tool', title, body?, status: 'active' | 'done' | 'error', durationMs? }. |
streaming | boolean | false | Output is still arriving; with an active step, the header shows a thinking orb. |
defaultOpen | boolean | true | Open state while not streaming. |
label | string | 'Chain of thought' | Header label; override it on non-English surfaces. |
userOpen | boolean | — | Host-held open state that overrides everything; feed toggle back in so it survives remounts. |
collapseDelayMs | number | 2000 | While streaming, milliseconds the trail stays open after the last active step settles; 0 folds at once. |
bullets | boolean | steps.length > 1 | Whether to show step status bullet markers. Omitted for single-step thoughts by default. |
Events
| Name | Payload | Description |
|---|---|---|
toggle | (open: boolean) | Fires on a header click with the resulting open state. |
Overview
- Open state:
userOpenwins, then a user click; while streaming, the trail opens while a step isactive, then stays open forcollapseDelayMs(default 2000 ms) after the last active step settles before it folds away. When not streaming, it followsdefaultOpen. - A thinking step's
bodyis released at a steady pace whilestreamingand the step isactive(the same clock as streamed text: a steady cadence, with a backlog cleared within about 0.6 s). A settled step, and users who prefer reduced motion, see it in full at once. What is shown is always a prefix of the text that has arrived, never rewritten; unfinished Markdown (such as**bold) is closed temporarily so no stray asterisks show. - The thinking body follows its end as text is released, stops following once the reader scrolls up, and resumes near the bottom. When a tool step's
bodygrows, the active body scrolls to its end. - A
donestep withdurationMsshows its duration after the title (· 3.2s; whole seconds from 10s). - The header count is
steps.length, hidden for a single step. - The header is a native
<button>witharia-expandedandaria-controls; steps are an<ol>.
Technologies
- The thinking body is released by
use-paced-text.ts, which wrapsuseStreamPaceron the same clock asTxStreamText; a settled step and reduced motion show it in full. - The open-state grace is a timer driven by a
watch, cleared on unmount. - Source:
packages/tuffex/packages/components/src/chain-of-thought/.
查看源码
packages/tuffex/packages/components/src/chain-of-thought/index.ts