@sibilance.is/client v0.1.0-alpha.4
@sibilance.is/client / index / SibilanceClient
Class: SibilanceClient
Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:52
Sibilance Client - Voice Survey Client
The main client class for integrating Sibilance voice surveys into your application. Wraps the Vowel voice AI platform and provides survey-specific functionality.
Example
import { SibilanceClient } from '@sibilance.is/client';
const client = new SibilanceClient({
surveyKey: 'sibilance_your_key_here'
}, {
onComplete: (yaml) => {
console.log('Survey completed!', yaml);
}
});
await client.connect();Constructors
Constructor
new SibilanceClient(config, callbacks): SibilanceClient;Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:96
Creates a new Sibilance client instance.
Parameters
| Parameter | Type | Description |
|---|---|---|
config | SibilanceConfig | Client configuration. Either surveyKey (production) or survey (test/editor mode) must be provided. |
callbacks | SurveyCallbacks | Optional callbacks for survey lifecycle events. |
Returns
SibilanceClient
Example
// Production mode: Fetch survey from backend
const client = new SibilanceClient({
surveyKey: 'sibilance_your_key_here'
}, {
onComplete: (yaml) => console.log('Done!', yaml)
});
// Editor/test mode: Use provided survey config
const client = new SibilanceClient({
survey: {
markdown: '# My Survey\n## Start\nWelcome!',
steps: [...],
mermaidDiagram: '...',
surveyName: 'Test Survey'
}
});Methods
waitForInit()
waitForInit(): Promise<void>;Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:282
Wait for client initialization to complete.
This is automatically called by connect(), but can be used to ensure the client is ready before accessing survey state or configuration.
Returns
Promise<void>
Promise that resolves when initialization is complete.
getSurveyState()
getSurveyState(): Readonly<SurveyState>;Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:321
Get the current survey state.
Returns a readonly snapshot of the survey state including:
- Current step ID
- Collected information
- Conversation log
- Completion status
Returns
Readonly<SurveyState>
Readonly survey state object.
Example
const state = client.getSurveyState();
console.log('Current step:', state.currentStepId);
console.log('Collected info:', state.collectedInfo);
console.log('Is complete:', state.isComplete);getVoiceState()
getVoiceState(): VoiceSessionState;Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:347
Get the voice state Valtio proxy.
Returns the reactive voice state proxy. Use useSnapshot() in React components to subscribe to changes.
Returns
Voice state Valtio proxy.
Example
import { useSnapshot } from 'valtio';
const voiceStateProxy = client.getVoiceState();
const voiceState = useSnapshot(voiceStateProxy);
if (voiceState.isConnected) {
console.log('Session active');
}connect()
connect(): Promise<void>;Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:401
Start the voice survey session.
Connects to the voice AI service and begins the survey conversation. The AI will start with the first step (or the step specified in startStepId).
Returns
Promise<void>
Promise that resolves when the session is connected.
Example
try {
await client.connect();
console.log('Survey started!');
} catch (error) {
console.error('Failed to start:', error);
}disconnect()
disconnect(): Promise<void>;Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:416
Stop the voice survey session.
Disconnects from the voice AI service and ends the conversation. Survey state is preserved, so you can reconnect later if needed.
Returns
Promise<void>
Promise that resolves when the session is disconnected.
pause()
pause(): void;Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:429
Pause the voice session.
Mutes microphone and speaker but keeps the connection alive. Use resume() to continue the conversation.
Returns
void
resume()
resume(): void;Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:443
Resume a paused voice session.
Re-enables microphone and speaker to continue the conversation.
Returns
void
toggleSession()
toggleSession(): Promise<void>;Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:458
Toggle the voice session on/off.
If connected, disconnects. If disconnected, connects.
Returns
Promise<void>
Promise that resolves when the toggle is complete.
recordInformation()
recordInformation(
field,
value,
sourceStep?): void;Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:514
Manually record information without voice interaction.
Useful for programmatically adding data to the survey results, such as from form inputs or external data sources.
Parameters
| Parameter | Type | Description |
|---|---|---|
field | string | Field name/key for the information. |
value | string | Value to record. |
sourceStep? | string | Optional step ID where this information was collected. |
Returns
void
Example
client.recordInformation('name', 'John Doe', 'A');
client.recordInformation('email', 'john@example.com', 'B');getYAML()
getYAML(): any[];Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:546
Get collected survey information as YAML array.
Returns all information collected during the survey in a structured format. Each item contains the field name, value, source step, and timestamp.
Returns
any[]
Array of collected information objects.
Example
const yaml = client.getYAML();
// [
// { field: 'name', value: 'John Doe', sourceStep: 'A', timestamp: 1234567890 },
// { field: 'email', value: 'john@example.com', sourceStep: 'B', timestamp: 1234567891 }
// ]getSurveyConfig()
getSurveyConfig(): SurveyConfig | null;Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:560
Get the current survey configuration.
Returns the survey config that was loaded (either from backend or provided directly). Returns null if no survey has been loaded yet.
Returns
SurveyConfig | null
Survey configuration object or null.
complete()
complete(): void;Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:653
Manually complete the survey.
Marks the survey as complete and triggers the onComplete callback with the collected YAML data. Useful for programmatically ending surveys or handling early completion scenarios.
Returns
void
stop()
stop(): void;Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:670
Stop and reset the survey.
Stops the survey and resets all state. Does not disconnect the voice session - call disconnect() separately if needed.
Returns
void
onStateChange()
onStateChange(listener): () => void;Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:701
Subscribe to voice state changes (legacy API).
Note: For React components, prefer using useSnapshot() with getVoiceState() for automatic reactive updates via Valtio.
The listener will be called whenever the voice session state changes (connection status, speaking states, etc.). Returns an unsubscribe function.
Parameters
| Parameter | Type | Description |
|---|---|---|
listener | (state) => void | Callback function that receives the new voice state. |
Returns
Unsubscribe function to stop listening to state changes.
(): void;Returns
void
Example
const unsubscribe = client.onStateChange((state) => {
console.log('Voice state changed:', state);
if (state.isConnected) {
console.log('Session connected');
}
});
// Later, unsubscribe
unsubscribe();destroy()
destroy(): void;Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:850
Destroy the client and cleanup all resources.
Stops polling, clears timeouts, disconnects voice session, and clears all listeners. Call this when you're done with the client instance.
Returns
void