Connection state

A small inline status pill for streaming connections that shows when the socket drops, reconnects, or resumes the stream. It renders nothing while the phase is "online".

Connection state
LIVE · running in a sandboxed iframe
Installed with shadcn add · 1 workaround · theme from registry.json
  • installed base item https://r.assistant-ui.com/shimmer-style.json (registry preview settings)
See how it was built

Installation

pnpm dlx shadcn@latest add @assistant-ui/elements-connection-state

Requires @assistant-ui in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { ConnectionState } from "@/components/assistant-ui/elements/connection-state";export function Status({ phase, onRetry }: { phase: "online" | "dropped" | "reconnecting" | "resumed"; onRetry: () => void }) {  return <ConnectionState phase={phase} onRetry={onRetry} />;}
  • Show it when the streaming socket drops while the server-side run continues, so users know nothing was lost.
  • Use the onRetry callback to offer a manual Reconnect action during the dropped phase.
  • Display the attempt counter while automatic reconnection is in progress.
  • Confirm recovery with the resumed phase and the number of tokens picked up from the stream.

Examples

Dropped with manual retry

Shows the amber lost-connection message and a Reconnect button that calls onRetry.

dropped-with-manual-retry.tsx
import { ConnectionState } from "@/components/assistant-ui/elements/connection-state";export function DroppedExample() {  return <ConnectionState phase="dropped" onRetry={() => console.log("retry")} />;}

Reconnecting with attempt counter

Shows the spinner and the current reconnection attempt number.

reconnecting-with-attempt-counter.tsx
import { ConnectionState } from "@/components/assistant-ui/elements/connection-state";export function ReconnectingExample() {  return <ConnectionState phase="reconnecting" attempt={3} />;}

Resumed with token count

Confirms the stream was picked back up and shows how many tokens were recovered.

resumed-with-token-count.tsx
import { ConnectionState } from "@/components/assistant-ui/elements/connection-state";export function ResumedExample() {  return <ConnectionState phase="resumed" resumedTokens={128} className="mx-auto" />;}

Live region for screen readers

Passes standard div attributes through to the root so the status can be announced.

live-region-for-screen-readers.tsx
import { ConnectionState } from "@/components/assistant-ui/elements/connection-state";export function LiveExample({ phase }: { phase: "online" | "dropped" | "reconnecting" | "resumed" }) {  return <ConnectionState phase={phase} role="status" aria-live="polite" />;}

API reference

PropTypeDefaultDescription
phase"online" | "dropped" | "reconnecting" | "resumed"—Current connection phase. Required. When "online", the component returns null and renders nothing.
attemptnumber—Reconnection attempt number. Shown as "attempt N" only in the reconnecting phase when defined.
resumedTokensnumber—Number of tokens recovered after resuming. Shown as "+N tokens" only in the resumed phase when defined.
onRetry() => void—Called when the Reconnect button is clicked in the dropped phase.
classNamestring—Additional classes merged onto the root div via cn().
...propsOmit<ComponentProps<"div">, "children" | "phase" | "attempt" | "resumedTokens" | "onRetry">—Any other native div attributes (for example role, aria-live, id, style) are spread onto the root element.

Accessibility

  • The source sets no role or aria-live on the root; pass role="status" and aria-live="polite" if the phase change should be announced to screen readers.
  • The Reconnect control is a real button with type="button" and visible text, so it is keyboard-focusable and labelled.
  • Icons have no aria-label; the adjacent text conveys the state, so they are decorative.
  • The spinner uses motion-reduce:animate-none to respect reduced-motion preferences.
  • The fade-in and slide animation classes do not include a motion-reduce override in the source; add one in your app CSS if needed.
  • Text colors rely on the paper surface and foreground tokens; verify contrast of the amber and emerald icons in both light and dark themes.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Connection state" component (assistant-ui/elements-connection-state) from its shadcn registry.1. Install it with: npx shadcn@latest add @assistant-ui/elements-connection-state2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: phase, attempt, resumedTokens, onRetry, className, ...props.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { ConnectionState } from "@/components/assistant-ui/elements/connection-state";export function Status({ phase, onRetry }: { phase: "online" | "dropped" | "reconnecting" | "resumed"; onRetry: () => void }) {  return <ConnectionState phase={phase} onRetry={onRetry} />;}```

Files & dependencies

  • components/assistant-ui/elements/connection-state.tsx
dependencieslucide-react
registryDependencieshttps://r.assistant-ui.com/elements-surfaces.json

Looks similar, elsewhere