Streaming
API reference for real-time message streaming using Server-Sent Events (SSE). This powers the live chat responses in the Intercom component.
Note: Streaming is handled automatically by the Intercom component. This reference is for understanding internal behavior.
Overview
The SDK uses Server-Sent Events (SSE) for streaming deva responses in real-time:
Technology:
@microsoft/fetch-event-sourcelibraryProtocol: SSE (Server-Sent Events)
Use Case: Chat completions with devas
Streaming Flow:
User sends message
SDK opens SSE connection
Deva response streams word-by-word
UI updates in real-time
Final message received, stream closes
useStreamResponse Hook
Internal hook for managing message streaming (used by Intercom component).
Signature
Parameters
messageId: string | undefined
ID of the message to stream response for
Triggers stream when provided
threadId: string | undefined
ID of the chat thread
Required for API endpoint
Return Values
Stream Endpoint
Request
Headers:
Parameters:
threadId- Chat thread IDmessageId- User message ID to respond to
Stream Events
The stream emits different event types:
content
Partial text content chunks as deva generates response.
Event Type: content
Data Format:
Handling:
Behavior:
Sent multiple times as text generates
Each chunk adds to previous content
Must accumulate chunks client-side
response_message
Complete message object when streaming finishes.
Event Type: response_message
Data Format:
Handling:
Behavior:
Sent once at end of stream
Contains full persisted message
Triggers stream cleanup and closure
completion
Query completes but stream remains open waiting for response_message.
Event Type: completion
Behavior:
Indicates LLM finished generating
Stream stays open for final message
Typically logged for debugging
error
Stream encountered an error.
Event Type: error
Behavior:
Sets error state
Stops streaming
Closes connection
Stream States
Event Types
Component States
Idle:
isStreaming: falsemessage: nullisDone: false
Streaming:
isStreaming: truemessage: { text: "partial..." }(accumulating)isDone: false
Complete:
isStreaming: falsemessage: { ...complete }(full message)isDone: true
Error:
isStreaming: falseerror: ErrorisDone: true
UI Components
The SDK provides three components for different streaming states:
IncomingMessageIndicator
Shows typing indicator (three bouncing dots) when stream starts but before content arrives.
InProgressMessage
Displays accumulating text in real-time as content chunks arrive during streaming.
MessageStreamError
Shows error message with red background when stream fails.
Integration with Intercom
The Intercom component handles streaming automatically:
User sends message → Creates message via API
Sets
streamingMessageIdto trigger streamuseStreamResponsehook opens SSE connectionContent chunks accumulate and update UI in real-time
Final
response_messagereceived → Stream closes
The useStreamResponse hook manages all streaming state internally, including:
Opening/closing SSE connection
Accumulating content chunks
Handling errors and cleanup
Updating component state
Related Documentation
Intercom Component - Chat UI
Message Types - Message type definitions
Last updated