Skip to main content

Events and Types

Complete reference for all events emitted by EstuaryClient, plus enums and utility types.

EstuaryEventMap

The full typed event map. Each entry defines the event name and its callback signature.

EventCallbackDescription
connected(session: SessionInfo) => voidSuccessfully connected and authenticated
disconnected(reason: string) => voidConnection closed
reconnecting(attempt: number) => voidAttempting to reconnect (attempt number)
connectionStateChanged(state: ConnectionState) => voidConnection state transition
botResponse(response: BotResponse) => voidText response chunk from the character
botVoice(voice: BotVoice) => voidVoice audio chunk from the character
sttResponse(response: SttResponse) => voidSpeech-to-text transcription result
interrupt(data: InterruptData) => voidResponse was interrupted
error(error: Error) => voidAn error occurred
authError(error: string) => voidAuthentication failed
quotaExceeded(data: QuotaExceededData) => voidUsage quota exceeded
cameraCaptureRequest(request: CameraCaptureRequest) => voidServer requests a camera image
voiceStarted() => voidVoice session started
voiceStopped() => voidVoice session stopped
livekitConnected(room: string) => voidLiveKit room connected
livekitDisconnected() => voidLiveKit room disconnected
audioPlaybackStarted(messageId: string) => voidAudio playback started for a message
audioPlaybackComplete(messageId: string) => voidAudio playback finished for a message
characterAction(action: CharacterAction) => voidParsed action from bot response (action tags are auto-stripped from botResponse.text)
memoryUpdated(event: MemoryUpdatedEvent) => voidReal-time memory extraction notification (requires realtimeMemory: true in config)

Usage

client.on('connected', (session) => {
// session: SessionInfo
});

client.on('botResponse', (response) => {
// response: BotResponse
});

client.on('sttResponse', (response) => {
// response: SttResponse
});

client.on('interrupt', (data) => {
// data: InterruptData
});

client.on('error', (error) => {
// error: Error (may be EstuaryError)
});

client.on('quotaExceeded', (data) => {
// data: QuotaExceededData
});

client.on('cameraCaptureRequest', (request) => {
// request: CameraCaptureRequest
// Capture and send an image in response
client.sendCameraImage(imageBase64, 'image/jpeg', request.requestId);
});

client.on('voiceStarted', () => {
// No arguments
});

ConnectionState

Enum representing the client's connection state.

import { ConnectionState } from '@estuary-ai/sdk';
ValueDescription
ConnectionState.DisconnectedNot connected to the server
ConnectionState.ConnectingConnection in progress
ConnectionState.ConnectedConnected and authenticated
ConnectionState.ReconnectingLost connection, attempting to reconnect
ConnectionState.ErrorConnection failed (auth error, max retries, etc.)
client.on('connectionStateChanged', (state) => {
if (state === ConnectionState.Connected) {
console.log('Ready');
}
});

VoiceTransport

Type alias for the voice transport option.

type VoiceTransport = 'websocket' | 'livekit' | 'auto';
ValueDescription
'websocket'Stream audio as base64 PCM over WebSocket
'livekit'Use LiveKit WebRTC (requires livekit-client)
'auto'Prefer LiveKit if available, fall back to WebSocket

ErrorCode

Enum of all typed error codes used by EstuaryError.

import { ErrorCode } from '@estuary-ai/sdk';
ValueDescription
CONNECTION_FAILEDWebSocket connection failed
AUTH_FAILEDAPI key or credentials invalid
CONNECTION_TIMEOUTConnection attempt timed out
QUOTA_EXCEEDEDUsage quota exceeded
VOICE_NOT_SUPPORTEDNo voice transport available
VOICE_ALREADY_ACTIVEstartVoice() called while voice is already active
VOICE_NOT_ACTIVEVoice operation called without active voice session
LIVEKIT_UNAVAILABLELiveKit requested but livekit-client not installed
MICROPHONE_DENIEDUser denied microphone permission
NOT_CONNECTEDOperation requires a connection but client is disconnected
REST_ERRORREST API request failed
UNKNOWNUnclassified error

EstuaryError

Error class extending Error with a typed code property.

import { EstuaryError, ErrorCode } from '@estuary-ai/sdk';

Properties

PropertyTypeDescription
codeErrorCodeTyped error code
messagestringHuman-readable error message
detailsunknown (optional)Additional error context
namestringAlways 'EstuaryError'

Usage

try {
await client.connect();
} catch (err) {
if (err instanceof EstuaryError) {
console.error(`[${err.code}] ${err.message}`);
if (err.details) {
console.error('Details:', err.details);
}
}
}