Streaming Text

A reply that appears as it's written, with a stop button.

Thinking…

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/stream

Usage

import { Stream, type StreamStatus } from "./ui/uicontext/components/kit/Stream.ts"
const Message = UiSchema.TaggedEnum({ ClickedStopReply: {}, ClickedRetryReply: {} })// your app appends each chunk to `text` as it arrives, and sets `status` when the reply endsexport const Reply = (h: Html.H<typeof Message.Type>, reply: { readonly status: StreamStatus; readonly text: string }) =>	Stream(h, {		key: "reply-1",		status: reply.status,		text: reply.text,		onStop: Message.ClickedStopReply(),		onRetry: Message.ClickedRetryReply(),	})

Examples

Waiting and how a reply ends

Before the first word it says it's thinking; at the end it says whether the reply finished, who stopped it, or why it failed.

Waiting

Reading 14 files…

Finished

Thought for 38s

Run the suite three times and compare which tests fail.

All 212 tests pass. The flaky checkout.spec.ts now waits for the payment frame instead of sleeping.

Stopped by a person

I'll start by renaming every customerId column to

Stopped by Grace Hopper

Failed

Failed: The model took too long to answer. Nothing was changed.

API reference

CodeBlockView function

Options

CodeBlock options
NameTypeDescription
keyrequiredstring—
coderequiredstring—
languagestring—

ReasoningView function

Options

Reasoning options
NameTypeDescription
thinkingbooleanStill thinking: the shimmering label instead of the disclosure
secondsnumberHow long it thought, once done
textstringThe reasoning itself, shown when the disclosure opens; untrusted model text

StreamView function

Options

Stream options
NameTypeDescription
statusrequired"waiting" | "streaming" | "succeeded" | "stopped" | "failed"Waiting for the first words, streaming, or ended: succeeded, stopped or failed
textrequiredstringEverything received so far
waitingLabelstringShown while nothing has arrived yet; "Thinking…" when left out
reasoning{ readonly text?: string | undefined; readonly seconds?: number | undefined }The agent's reasoning: shown as "Thought for Ns" above the reply once text arrives
stoppedByActorFor "stopped": who stopped it
failurestringFor "failed": why, in a sentence
onStopMessageSend to stop it; omit when this person can't stop it
onRetryMessageSend to try again once it failed or was stopped; omit when it can't be retried
keystringTells this reply's code blocks apart from other replies' on the page: the message id

Accessibility

  • Screen readers hear the end state, not every word: the footer is a status that says Writing, then done, stopped (and by whom) or failed (and why).
  • The message is marked busy while it runs, and Stop is a real button.
  • The agent's reasoning folds into a <details> that opens with Enter or Space.

Source