Skip to content

@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 ​

typescript
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 ​

ts
new SibilanceClient(config, callbacks): SibilanceClient;

Defined in: CmdPr/sibilance/client/src/lib/sibilance-client.ts:96

Creates a new Sibilance client instance.

Parameters ​

ParameterTypeDescription
configSibilanceConfigClient configuration. Either surveyKey (production) or survey (test/editor mode) must be provided.
callbacksSurveyCallbacksOptional callbacks for survey lifecycle events.

Returns ​

SibilanceClient

Example ​

typescript
// 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() ​

ts
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() ​

ts
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 ​

typescript
const state = client.getSurveyState();
console.log('Current step:', state.currentStepId);
console.log('Collected info:', state.collectedInfo);
console.log('Is complete:', state.isComplete);

getVoiceState() ​

ts
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 ​

VoiceSessionState

Voice state Valtio proxy.

Example ​

typescript
import { useSnapshot } from 'valtio';

const voiceStateProxy = client.getVoiceState();
const voiceState = useSnapshot(voiceStateProxy);

if (voiceState.isConnected) {
  console.log('Session active');
}

connect() ​

ts
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 ​

typescript
try {
  await client.connect();
  console.log('Survey started!');
} catch (error) {
  console.error('Failed to start:', error);
}

disconnect() ​

ts
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() ​

ts
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() ​

ts
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() ​

ts
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() ​

ts
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 ​

ParameterTypeDescription
fieldstringField name/key for the information.
valuestringValue to record.
sourceStep?stringOptional step ID where this information was collected.

Returns ​

void

Example ​

typescript
client.recordInformation('name', 'John Doe', 'A');
client.recordInformation('email', 'john@example.com', 'B');

getYAML() ​

ts
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 ​

typescript
const yaml = client.getYAML();
// [
//   { field: 'name', value: 'John Doe', sourceStep: 'A', timestamp: 1234567890 },
//   { field: 'email', value: 'john@example.com', sourceStep: 'B', timestamp: 1234567891 }
// ]

getSurveyConfig() ​

ts
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() ​

ts
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() ​

ts
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() ​

ts
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 ​

ParameterTypeDescription
listener(state) => voidCallback function that receives the new voice state.

Returns ​

Unsubscribe function to stop listening to state changes.

ts
(): void;
Returns ​

void

Example ​

typescript
const unsubscribe = client.onStateChange((state) => {
  console.log('Voice state changed:', state);
  if (state.isConnected) {
    console.log('Session connected');
  }
});

// Later, unsubscribe
unsubscribe();

destroy() ​

ts
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