Reasoning
The model's reasoning, folded above its answer — streamed while it thinks, closed once it is done, opened by the reader who wants to know why.
-
type: 'thinking'
<aparte-chat-bubble message-id="a1" data-role="assistant" name="Assistant"></aparte-chat-bubble>
<script>
document.querySelector('aparte-chat-bubble').setSegments([
{
id: 's1',
type: 'thinking',
// Settled: the block folds, and the reader opens it if they want the reasoning. Its
// label reads "Thought"; showDuration would add how long it took.
isStreaming: false,
content: 'The user asks which transport to use. A prototype keeps the key in the browser; production should not. So: direct for the demo, backend for the release.',
},
{ id: 's2', type: 'text', content: 'Use **AparteDirectTransport** while you prototype, and switch to **AparteBackendTransport** before you ship, so the key stays on your server.' },
]);
</script>A reasoning block is a thinking segment, drawn as a disclosure above the answer. It is closed
by default: the answer is what a reader came for, and the reasoning is one click away. A model
that streams its reasoning (a <think> block, or a provider’s reasoning channel) produces the
segment during the turn; you can also build one yourself, as these demos do.
Variants
Section titled “Variants”While it streams
Section titled “While it streams”<aparte-chat-bubble message-id="a1" data-role="assistant" name="Assistant" streaming></aparte-chat-bubble>
<script>
document.querySelector('aparte-chat-bubble').setSegments([
// Still arriving: the client appends tokens to it as the model reasons.
{ id: 's1', type: 'thinking', isStreaming: true, content: 'Comparing the two transports. The direct one sends the key from the browser, which' },
]);
</script>The block takes tokens as they arrive. isStreaming: true marks it open-ended; the client
settles it with isStreaming: false when the reasoning ends. While it streams, its label
shimmers, the way conversational chats show a model still thinking; the
light stops when the block settles, and never moves under prefers-reduced-motion. A block
written by hand or restored from storage, which never streamed on this page, stays still.
The shimmer draws the label through its text fill, so a colour you set on
.aparte-thinking-label shows once the block settles, and the sweep runs between
--aparte-shimmer-base and --aparte-shimmer-shine meanwhile; set those on the label to
recolour it. To keep the label still:
.aparte-thinking-label.aparte-shimmer {
animation: none;
background-image: none;
-webkit-text-fill-color: currentColor;
color: inherit;
}Opened on purpose
Section titled “Opened on purpose”<aparte-chat-bubble message-id="a1" data-role="assistant" name="Assistant"></aparte-chat-bubble>
<script>
document.querySelector('aparte-chat-bubble').setSegments([
{
id: 's1',
type: 'thinking',
isStreaming: false,
// Absent means folded. false opens it, for a reply whose reasoning is the point.
collapsed: false,
content: 'Three facts decide it: the key must not reach the browser in production, the demo has no server, and both transports stream the same events.',
},
{ id: 's2', type: 'text', content: 'Direct for the demo, backend for production.' },
]);
</script>Leave collapsed out and the block is closed. Set collapsed: false for a reply whose
reasoning is the point, such as a worked answer.
Customize
Section titled “Customize”The label reads “Thinking” while the block streams and “Thought” once it settles (the thinking
and thought locale keys). A label you set on the segment wins over both.
With how long it took
Section titled “With how long it took”import { aparteGlobalConfig } from '@aparte/core';
aparteGlobalConfig.setSegmentDefaults('thinking', { showDuration: true });<aparte-chat-bubble message-id="a1" data-role="assistant" name="Assistant"></aparte-chat-bubble>
<script>
document.querySelector('aparte-chat-bubble').setSegments([
// showDuration, from the timing a streamed block carries: "Thought for 8s" (under a second reads "1s").
{ id: 's1', type: 'thinking', isStreaming: false, showDuration: true, meta: { aparte: { startedAt: 1_000_000, endedAt: 1_008_000 } }, content: 'Weighing the two transports against the release date.' },
// showDuration without timing (a history restored without it): just "Thought".
{ id: 's2', type: 'thinking', isStreaming: false, showDuration: true, content: 'Checking the key stays on the server.' },
// The app's own label wins over both.
{ id: 's3', type: 'thinking', isStreaming: false, label: '8.2s · 1.2k tokens', content: 'Drafting the answer.' },
]);
</script>With showDuration, a settled block reads “Thought for 8s” (the thoughtFor locale key; the
duration is written by Intl in the locale’s tag, with a floor of one second). A block with no
timing still reads “Thought”. A block’s own showDuration (showDuration?: boolean on the segment) wins; otherwise
the default decides. It is read when the block is drawn, so a block restored from storage follows
the setting too.
It is opt-in because the duration is measured in the browser, from the first reasoning delta to
the last. That is the model’s thinking time only when your provider streams its reasoning; one
that sends the reasoning in a single piece would show “1s”. After a reload the duration shows only
if your storage kept the segment’s meta. Turn it on when your provider streams reasoning.
A product that phrases it differently (“8.2s · 1.2k tokens”) writes its own by wrapping the built-in renderer:
import { getSegmentRenderer, registerSegmentRenderer, isSegmentSettled, segmentDuration } from '@aparte/core';
import type { AparteThinkingSegment } from '@aparte/core';
const builtIn = getSegmentRenderer('thinking')!;
function writeDuration(el: HTMLElement, segment: AparteThinkingSegment): void {
const ms = isSegmentSettled(segment) ? segmentDuration(segment) : undefined;
const label = el.querySelector('.aparte-thinking-label');
if (label && ms !== undefined) label.textContent = `Thought for ${(ms / 1000).toFixed(1)}s`;
}
registerSegmentRenderer<AparteThinkingSegment>({
type: 'thinking',
render(segment) {
// The built-in returns an HTML string; keep its root element as the segment's root.
const out = builtIn.render(segment);
const template = document.createElement('template');
if (typeof out === 'string') template.innerHTML = out;
const el = typeof out === 'string' ? (template.content.firstElementChild as HTMLElement) : out;
writeDuration(el, segment);
return el;
},
setup: (el, segment) => builtIn.setup?.(el, segment),
update(el, segment) {
builtIn.update?.(el, segment);
writeDuration(el, segment); // a block settles through update, never a second render
},
});Keep the root the built-in returns, and delegate setup and update: they carry the
incremental Markdown writer and the scroll anchoring.
Fields
Section titled “Fields”AparteThinkingSegment, discriminated by type: 'thinking'.
| Field | Type | Required | Description |
|---|---|---|---|
content | string | yes | |
collapsed | boolean | — | Open the block. Absent means CLOSED — a reasoning block is a disclosure, and the reader opens it. The content is behind a click, streaming or settled. false opens one on purpose. |
label | string | — | |
showDuration | boolean | — | Once settled, read “Thought for 8s” rather than “Thought”. More |
showDuration — Once settled, read “Thought for 8s” rather than “Thought”. Off by default: the
duration is measured in the browser, from the first reasoning delta to the last,
which is the model’s thinking time only when the provider streams its reasoning — a
provider that sends it in one piece would read “1s”, and a reload shows it only if
the stored segment kept its meta. Usually turned on for every block with
setSegmentDefaults('thinking', { showDuration: true }), which a block restored
from storage follows too (it is read when the block is drawn); the block’s own
field wins.
Accessibility
Section titled “Accessibility”- The block is a native
<details>: its summary opens with Enter or Space and announces whether it is expanded. - The opened panel is a focusable region named by the block’s label, so a screen reader can find the reasoning and step into it.
Related
Section titled “Related”- Tool call — the other segment a reasoning model often emits.
- Markdown and code — how the reasoning’s text is rendered.