Ensemble Docs

Configuration

Complete reference for all ChatWidget props

Configuration Reference

Complete reference for all ChatWidget and PopupChatWidget configuration options.

For setup and authentication, see Quick Start.

Agent Props

PropTypeDefaultDescription
agentIdstring-Ensemble agent ID to connect to
agentVersionAgentVersion'latest'Agent version selector

AgentVersion

  • 'latest' - Use the latest version (including drafts)
  • 'published' - Use the latest published version
  • number - Use a specific version number (e.g., 1, 2)
<ChatWidget
  agentId="agent-abc123"
  agentVersion="published"
  // ...
/>

UI Props

PropTypeDefaultDescription
titlestring-Title displayed in the header
inputPlaceholderstring'Type a message...'Placeholder text for input field
displayMode'brief' | 'full''brief'Message display mode
classNamestring-Additional CSS class for the container
stylesChatWidgetStyles-Style customization (see Styling Reference)

Display Modes

  • 'brief' - Collapses previous agent steps, showing only the final response
  • 'full' - Shows all steps and intermediate responses
<ChatWidget
  title="Support Assistant"
  inputPlaceholder="Ask me anything..."
  displayMode="full"
  // ...
/>

Initial Messages

PropTypeDescription
initialAssistantMessagestringStatic greeting displayed from the assistant
initialUserMessagestringMessage sent to the agent immediately on load

These props only apply when there is no existing message history for the thread. If the user has chatted before, these are ignored.

  • initialAssistantMessage - Displays a static intro message from the assistant (does not invoke the agent)
  • initialUserMessage - Sends a message to the agent immediately, triggering a response

If both are provided, initialUserMessage takes precedence and initialAssistantMessage is skipped.

// Show a static greeting (no agent call)
<ChatWidget
  initialAssistantMessage="Hi! How can I help you today?"
  // ...
/>

// Auto-start conversation (sends to agent immediately)
<ChatWidget
  initialUserMessage="Show me my account summary"
  // ...
/>

Context

PropTypeDescription
dataContextRecord<string, unknown>Key/value pairs passed to the agent and tools

Context can be passed in two ways:

  1. Secure context - Via JWT token (tamper-proof, server-side)
  2. Client context - Via dataContext prop (for non-sensitive data)

Both are merged, with JWT context taking priority on conflicts.

<ChatWidget
  dataContext={{
    environment: 'production',
    userPreferences: { theme: 'dark' },
  }}
  // ...
/>

Voice Options

PropTypeDescription
voiceChatWidgetVoiceOptionsText-to-speech configuration

ChatWidgetVoiceOptions

PropertyTypeDefaultDescription
urlstring-TTS API endpoint URL
enabledbooleanfalseEnable voice playback
methodstring'POST'HTTP method
headersRecord<string, string>-Request headers
payloadRecord | (text: string) => Record-Request body or function to generate it
autoplayLatestbooleanfalseAuto-play the latest response
<ChatWidget
  voice={{
    url: 'https://api.example.com/tts',
    enabled: true,
    headers: { Authorization: 'Bearer ...' },
    payload: (text) => ({ text, voice: 'en-US-Neural' }),
    autoplayLatest: true,
  }}
  // ...
/>

Speech-to-Text Options

PropTypeDescription
speechToTextChatWidgetSpeechToTextOptionsSpeech recognition configuration

ChatWidgetSpeechToTextOptions

PropertyTypeDefaultDescription
enabledbooleanfalseEnable microphone input
languagestring'en-US'Recognition language (BCP-47 code)
silenceTimeoutnumber2000Silence duration (ms) before auto-stop
finalDelaynumber-Delay before finalizing transcript
onError(message: string) => void-Error callback
<ChatWidget
  speechToText={{
    enabled: true,
    language: 'en-US',
    silenceTimeout: 3000,
    onError: (msg) => console.error('Speech error:', msg),
  }}
  // ...
/>

Feedback Options

PropTypeDescription
feedbackChatWidgetFeedbackOptionsMessage feedback configuration

ChatWidgetFeedbackOptions

PropertyTypeDefaultDescription
enabledbooleantrueShow thumbs up/down on assistant messages
requireCommentForNegativebooleanfalseRequire comment when giving negative feedback

Feedback is submitted to POST {baseUrl}/api/feedback.

<ChatWidget
  feedback={{
    enabled: true,
    requireCommentForNegative: true,
  }}
  // ...
/>

Custom Widgets

PropTypeDescription
widgetsUIWidgetDefinition[]Custom widget renderers

See Custom Widgets for details.


Event Callbacks

PropTypeDescription
onError(error: Error) => voidCalled on API errors
onAuthError() => Promise<string | null>Called on 401; return new token to retry
onFinish(message: any) => voidCalled when assistant finishes responding
onData(data: any) => voidCalled on streaming data chunks
onMessage(message: UIMessage) => voidCalled when a message is added
<ChatWidget
  onError={(err) => console.error('Chat error:', err)}
  onAuthError={async () => {
    const newToken = await refreshToken();
    return newToken;
  }}
  onFinish={(msg) => console.log('Response complete:', msg)}
  // ...
/>

Ref Handle

Access the widget programmatically using a ref:

import { useRef } from 'react';
import { ChatWidget, ChatWidgetHandle } from '@anthropic/client-sdk';

function App() {
  const chatRef = useRef<ChatWidgetHandle>(null);

  const sendGreeting = () => {
    chatRef.current?.sendMessage('Hello!');
  };

  return (
    <>
      <button onClick={sendGreeting}>Send Greeting</button>
      <ChatWidget ref={chatRef} /* ... */ />
    </>
  );
}

ChatWidgetHandle

MethodTypeDescription
sendMessage(message: string) => voidSend a message programmatically

PopupChatWidget Props

PopupChatWidget accepts all ChatWidget props plus:

PropTypeDefaultDescription
anchorPosition'end' | 'start''end'Position of floating button (end = right, start = left)
defaultOpenbooleanfalseWhether popup is open by default
<PopupChatWidget
  anchorPosition="end"
  defaultOpen={false}
  title="Help"
  // ... all ChatWidget props
/>

On this page