Reasoning
A collapsible block that streams a model's thinking.
Reasoning is new in v0.4.0. It shows a model's reasoning in a collapsible block: open while IsStreaming is true, labelled "Thinking…", then folded to "Thought for N seconds" when streaming ends. The user can open it again with a click.
Installation
bash
shellui add reasoning
Usage
Streaming
Append to Text as chunks arrive and call StateHasChanged(). Set IsStreaming while they arrive and Duration when they stop.
<div class="w-full max-w-xl space-y-3">
<Button Variant="ButtonVariant.Outline" OnClick="RunAsync" Disabled="streaming">@(streaming ? "Thinking…" : "Run")</Button>
<Reasoning Text="@text" IsStreaming="streaming" Duration="duration" />
</div>
@code {
private string? text = "Press Run to stream a model's reasoning into this block.";
private bool streaming;
private TimeSpan? duration;
private async Task RunAsync()
{
text = "";
duration = null;
streaming = true;
var started = DateTime.UtcNow;
foreach (var word in "The user wants to know how dialogs keep focus. I should search the docs for the focus trap, then summarise what Tab does inside an open dialog.".Split(' '))
{
text += word + " ";
StateHasChanged();
await Task.Delay(90);
}
streaming = false;
duration = DateTime.UtcNow - started;
}
}
Title and child content
Title replaces the label, and child content is rendered after Text, so the body can hold markup. DefaultOpen opens it on first render.
- Find the pages that mention the focus trap.
- Read the Dialog accessibility section.
- Answer with a short example.
<div class="w-full max-w-xl space-y-3">
<Reasoning Title="Plan" DefaultOpen="true">
<ol class="list-decimal space-y-1 pl-5">
<li>Find the pages that mention the focus trap.</li>
<li>Read the Dialog accessibility section.</li>
<li>Answer with a short example.</li>
</ol>
</Reasoning>
<Reasoning Text="Checked the release notes for 0.4.0." Duration="TimeSpan.FromSeconds(3)" />
</div>
Behaviour
- On first render the block is open if
DefaultOpenorIsStreamingis set. - When
IsStreamingchanges, the block follows it: it opens when streaming starts and closes when it ends. A click toggles it in between. - The label is
Titleif set; otherwise "Thinking…" while streaming, "Thought for N seconds" onceDurationis set (rounded, at least 1 second), and "Reasoning" before either.
API Reference
| Parameter | Type | Default | Description |
|---|---|---|---|
Text |
string? |
null |
The reasoning text; line breaks are kept |
ChildContent |
RenderFragment? |
null |
Markup shown after Text |
IsStreaming |
bool |
false |
Opens the block and pulses the label while true; closes it when it turns false |
Duration |
TimeSpan? |
null |
How long the model thought, shown once streaming ends |
Title |
string? |
null |
Replaces the "Thinking…" / "Thought for …" label |
DefaultOpen |
bool |
false |
Opens the block on first render |
Class |
string? |
null |
Additional CSS classes |