Skip to content

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'
On this page
Open

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.

Open

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:

css
.aparte-thinking-label.aparte-shimmer {
  animation: none;
  background-image: none;
  -webkit-text-fill-color: currentColor;
  color: inherit;
}
Open

Leave collapsed out and the block is closed. Set collapsed: false for a reply whose reasoning is the point, such as a worked answer.

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.

ts
import { aparteGlobalConfig } from '@aparte/core';

aparteGlobalConfig.setSegmentDefaults('thinking', { showDuration: true });
Open

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:

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

AparteThinkingSegment, discriminated by type: 'thinking'.

FieldTypeRequiredDescription
contentstringyes
collapsedboolean—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.
labelstring—
showDurationboolean—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.

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