affectUI › Components › Agents

Response Stream

One agent answer through every state it goes through – words streaming in, stopped and continued from the exact word, failed and retried from there, done – with steer and queued messages above it.

Part of affectUI Pro. Install: npx shadcn@latest add https://www.affectui.com/r/response-stream.json · Import from @/components/ui/response-stream

When to use

  • An agent chat where the answer itself shows every state: writing, stopped, failed, done
  • Letting people stop an answer, pick it up again from the exact word, or retry after an error without starting over
  • Showing messages sent while it writes – a steer that bends the answer now, or a queued one that becomes the next answer

When not to use

  • The whole composer with model, mode and permissions – use Run Controls
  • Only the thinking before an answer – use Thinking State

Usage

import { ResponseStream } from "@/components/ui/response-stream";

export function Answer({ text, status }) {
  return (
    <ResponseStream
      text={text}
      status={status} // "streaming" | "stopped" | "failed" | "done"
      agent={{ id: "atlas", name: "Atlas" }}
      onStop={() => stream.abort()}
      onContinue={() => stream.resume()}
      onRetry={() => stream.retry()}
      onDismiss={() => removeAnswer()}
      meta={{ tokens: 182, ms: 6400 }}
    />
  );
}

Props

NameTypeDefaultDescription
textstringThe answer so far – keep appending while it streams. A trailing half word waits until it is whole; ``` fences become code blocks
status"streaming" | "stopped" | "failed" | "done"Which state the answer is in – the footer, caret and agent mark follow it
errorstringWhat went wrong, in one sentence – shown when failed
steerResponseSteer[]{ id, text, kind: "steer" | "queued" } – chips above the answer; the first queued one reads Next; more than three fold behind “+ n more”
bendsResponseBend[]{ at, text? } – character offsets where a steer bent the answer; a quiet divider there
agent{ id, name, color? }AssistantWho answers – the pixel mark is drawn from the id
meta{ tokens?, ms? }Time and tokens in the done footer
onStop() => voidStop button and Esc while it streams
onContinue() => voidContinue after a stop – keep appending to the same text
onRetry() => voidRetry after a failure – picks up from the text so far
onDismiss() => voidCalled once the stopped answer has faded out
onRemoveSteer(id: string) => voidThe × on a chip
onCopy(text: string) => voidCopy in the done footer – the text is also put on the clipboard
onRegenerate() => voidRegenerate in the done footer – the button shows only with it
escToStopbooleantrueEsc stops a streaming answer, unless focus is in a text field
classNamestringExtra class on the answer

Keyboard

  • Esc: Stop the answer while it streams
  • Tab: Move through the footer actions and the chips' remove buttons
  • Enter / Space: Press Continue, Retry, Dismiss, Copy or Regenerate

Accessibility

  • New text is announced politely in whole sentences, never word by word
  • Each status change – stopped, failed with its reason, finished – is announced once
  • While it writes the answer is marked busy; the steer divider is a separator with what it was steered with

Responsive

  • The answer only grows downwards; the footer is one row that keeps its height and never shifts sideways
  • Below 360px the indent goes and the footer may wrap; the error is its own line under the text; long words and URLs wrap, code scrolls sideways
  • Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"

Requirements

  • React 19

Related

  • Run Controls – Every control a running agent needs, in one composer – stop it, resume from the word it stopped at, retry or dismiss, steer it mid-answer or queue what's next, with Chat or Act, permissions and how full the context is
  • Agent Steering – Steer an agent while it works – queue a note for the next step and watch it glide into the plan when the agent picks it up, or interrupt right away
  • Agent Queue – The work waiting for your agents, and how fast it moves – jobs drop into a live queue, glide into free worker slots as growing bars and land in Done or Failed, while a depth chart shows the backlog build up when a rate limit pauses the workers and drain when they resume
  • Thinking State – AI working panel with a live timer, searched sources and thinking steps that appear one by one
  • Message Actions – The quiet bar under an AI message – copy turns into a check, regenerate spins and unfolds a version switcher, thumbs pop and ask why, read aloud becomes a tiny equalizer