Captain UI

Streaming text

Feed it a bursty token stream and it reveals the reply at a steady reading pace, a whole word at a time, with bold, inline code, lists and a caret while it writes.

npx shadcn@latest add @captain/streaming-text
Pro

The checkout test keeps failing on CI but passes locally. Can you find out why?

Usage

import { StreamingText } from "@/components/ui/streaming-text"

const { messages, status } = useChat()
const last = messages.at(-1)

<StreamingText text={textOf(last)} done={status === "ready"} />

Props

PropTypeDefaultWhat it does
textstringEverything received so far. Append as tokens arrive, for example the text of the last message from useChat.
donebooleanfalseSet when the stream ends. The reveal catches up, then the caret goes.
pacenumber60Characters per second when the buffer is nearly empty. A burst drains in about 0.6s.
onRevealed() => voidCalled once the last word is on screen.

Accessibility

  • The reply is an aria-live region marked aria-busy while it streams, so screen readers read it once, whole, instead of word by word.
  • Reduced motion keeps the fade and drops the blur and the lift.
  • The caret is decorative and hidden from assistive tech.