Skip to main content

Component Layer

High-level components designed for Lens Studio integration.

EstuaryManager​

Singleton manager for SDK connections. Routes events to registered characters.

import { EstuaryManager } from 'estuary-lens-studio-sdk';

Access​

// Get instance (creates if needed)
const manager = EstuaryManager.instance;

// Check if exists
if (EstuaryManager.hasInstance) { ... }

Methods​

MethodParametersDescription
connect()-Connect using current config
disconnect()-Disconnect from server
registerCharacter()characterRegister a character handler
unregisterCharacter()characterUnregister a character
setActiveCharacter()characterSet active character
sendText()text: stringSend text message
sayLine()text: string, textOnly?: booleanScript the character to say a specific prewritten line. When textOnly is true the server emits botResponse only (no TTS). Default false.
sendClientInterrupt()messageId?: stringCancel the in-progress bot response. Server stops generation and emits interrupt. Omit messageId to interrupt the current response.
streamAudio()audioBase64: stringStream audio
startVoiceMode()-Enable server-side STT
stopVoiceMode()-Disable server-side STT
sendCameraImage()imageBase64, mimeType?, requestId?, text?, sampleRate?Send captured image to server
notifyAudioPlaybackComplete()-Notify playback done
tick()-Process WebSocket send queue (call periodically)
dispose()-Clean up resources

Setup​

// REQUIRED: assign the InternetModule before connecting (Lens Studio 5.9+).
EstuaryManager.instance.internetModule = this.internetModule;

Events​

EventDataDescription
cameraCaptureRequestCameraCaptureRequestServer requests camera capture
connectionStateChangedConnectionStateConnection state changed

Properties​

PropertyTypeDescription
configEstuaryConfig | nullCurrent configuration
isConnectedbooleanConnection status
connectionStateConnectionStateCurrent state
debugLoggingbooleanDebug mode

EstuaryCharacter​

Represents an AI character for conversations.

import { EstuaryCharacter } from 'estuary-lens-studio-sdk';

Constructor​

const character = new EstuaryCharacter(characterId, playerId);

Methods​

MethodParametersDescription
initialize()config: EstuaryConfigInitialize and optionally connect
connect()-Connect to server
disconnect()-Disconnect
sendText()message: stringSend text message
sayLine()text: string, textOnly?: booleanScript the character to say a specific prewritten line. When textOnly is true the server emits botResponse only (no TTS). Default false.
startVoiceSession()-Enable voice streaming
endVoiceSession()-Disable voice streaming
streamAudio()audioBase64: stringStream audio data
interrupt()-Interrupt current response
dispose()-Clean up resources

Properties​

PropertyTypeDescription
characterIdstringCharacter UUID
playerIdstringUser identifier
autoConnectbooleanAuto-connect on init
autoReconnectbooleanAuto-reconnect on disconnect
isConnectedbooleanConnection status
currentSessionSessionInfo | nullSession info
isVoiceSessionActivebooleanVoice session status
currentPartialResponsestringStreaming response text
currentMessageIdstringCurrent message ID
microphoneIEstuaryMicrophoneControllerMicrophone controller

Events​

EventDataDescription
connectedSessionInfoConnected to server
disconnected-Disconnected
botResponseBotResponseAI text response
voiceReceivedBotVoiceAI voice audio
transcriptSttResponseUser speech transcription
interruptInterruptDataResponse interrupted
errorstringError occurred
connectionStateChangedConnectionStateState changed
cameraCaptureRequestCameraCaptureRequestServer requests camera capture

EstuaryCredentials​

Lens Studio component for centralized credential management with automatic User ID persistence.

import { EstuaryCredentials, IEstuaryCredentials } from 'estuary-lens-studio-sdk';

Inspector Inputs​

InputTypeDescription
apiKeystringEstuary API key
characterIdstringCharacter UUID
useSnapAccountIdbooleanUse Snapchat account ID for cross-device persistence (default: true)
debugModebooleanEnable debug logging
userIdFieldstringOptional manual User ID override

Properties​

PropertyTypeDescription
serverUrlstringServer URL (default: wss://api.estuary-ai.com)
userIdstringResolved User ID (see priority chain in User Management)
isUsingSnapAccountIdbooleanWhether using Snap account-based ID

Methods​

MethodParametersReturnsDescription
validateCredentials()-booleanValidate that required fields are set

Static Access​

// Singleton access
if (EstuaryCredentials.hasInstance) {
const creds = EstuaryCredentials.instance;
print(creds.apiKey);
print(creds.userId);
print(`Using Snap ID: ${creds.isUsingSnapAccountId}`);
}

Interface​

interface IEstuaryCredentials {
apiKey: string;
characterId: string;
serverUrl: string;
debugMode: boolean;
userId: string;
isUsingSnapAccountId?: boolean;
}

EstuaryMicrophone​

Handles microphone input for voice chat.

import { EstuaryMicrophone, MicrophoneRecorder } from 'estuary-lens-studio-sdk';

Constructor​

const mic = new EstuaryMicrophone(character);

Methods​

MethodParametersDescription
setMicrophoneRecorder()recorder: MicrophoneRecorderSet audio source
startRecording()-Start capturing audio
stopRecording()-Stop capturing
toggleRecording()-Toggle recording state
dispose()-Clean up resources

Properties​

PropertyTypeDescription
sampleRatenumberRecording sample rate (16000)
debugLoggingbooleanDebug mode
isRecordingbooleanRecording status
targetCharacterEstuaryCharacterTarget character

Events​

EventDescription
recordingStartedRecording began
recordingStoppedRecording ended
audioChunkSentAudio chunk transmitted

MicrophoneRecorder Interface​

interface MicrophoneRecorder {
setSampleRate(sampleRate: number): void;
onAudioFrame: {
add(callback: (audioFrame: Float32Array) => void): void;
};
startRecording(): void;
stopRecording(): void;
}