Headless Hook

Have your own design system? useChatterflyRun drives the connection and state machine with no UI, so you can render the conversation with your own components.

Overview

useChatterflyRun is the same auto-start + WebSocket logic that powers <ChatterflyWidget>, exposed as a hook. Pair it with the exported input components (InputText, InputBoolean, etc.) or your own to build a fully custom participant surface.

Note: ChatterflyWidget/ChatAdapter implement the same auto-start contract independently rather than consuming this hook internally — both follow identical endpoints and the same session-persistence module, so behavior is consistent either way.

Usage

tsx
import { useChatterflyRun, InputText, InputBoolean } from "@chatterfly/widget";

function MyCustomChat() {
  const {
    status, activeSession, timeline, output,
    submitHandback, sendMessage, restart, disconnect, connecting, error,
  } = useChatterflyRun({
    workflowId: "wf_abc123",
    apiBase: "https://api.chatterfly.ai",
    // persistSession defaults to true — pass false to opt out
  });

  if (connecting) return <MySkeleton />;
  if (error) return <MyError code={error.code} message={error.message} />;

  // render `timeline` and `activeSession` with your own components
  return null;
}
Note: Just like ChatterflyWidget, persistSession defaults to true for serverless (workflowId/deploymentId) configs, and the hook drives the same active/dormant/hibernating connection lifecycle and token re-mint-on-expiry behavior — see Connection Lifecycle. Note: the choice-card UI (resumePrompt/clickToStart/showCompletedHistory) is a ChatterflyWidget-only convenience today — headless hosts render their own gating on top of status/connecting.

Return value

NameDescription
statusRunStatus — the client state machine (including offline/expired on connection loss/token expiry).
activeSessionThe currently open HITL session, if any.
timelineOrdered TimelineEntry[] for the whole run.
messagesDeliberation chat messages for the active session.
streamingTextAccumulated in-progress LLM tokens.
outputFinal run state once the run reaches a terminal status.
submitHandback(output?, idempotencyKey?) => Promise<ValidationError[] | null>
sendMessage(content: string) => Promise<void>
restartMints a new run (auto-start) or reconnects (direct runId).
disconnect / reconnectManual connection control.
connectingTrue while the serverless auto-start request is in flight.
errorWidgetError | null — set on config/start failures.