Skip to content

@vowel.to/client v0.3.3-beta


@vowel.to/client / index / Vowel

Class: Vowel

Defined in: lib/vowel/core/VowelClient.ts:80

Main Vowel client class

Example

ts
// vowel.client.ts
import { Vowel } from '@/lib/vowel';
import { tanstackRouterAdapter } from '@/lib/vowel/adapters';
import { router } from './router';

export const vowel = new Vowel({
  apiKey: 'vkey_public_xxx',
  router: tanstackRouterAdapter(router),
  routes: [
    { path: '/products', description: 'Browse products' },
    { path: '/cart', description: 'View cart' }
  ]
});

// Register custom actions
vowel.registerAction('searchProducts', {
  description: 'Search for products',
  parameters: {
    query: { type: 'string', description: 'Search query' }
  }
}, async (params) => {
  await searchProducts(params.query);
});

Constructors

Constructor

ts
new Vowel(config): Vowel;

Defined in: lib/vowel/core/VowelClient.ts:105

Parameters

ParameterType
configVowelClientConfig

Returns

Vowel

Accessors

appId

Get Signature

ts
get appId(): string | undefined;

Defined in: lib/vowel/core/VowelClient.ts:867

Get app ID

Returns

string | undefined


apiKey

Get Signature

ts
get apiKey(): string | undefined;

Defined in: lib/vowel/core/VowelClient.ts:874

Get token issuer identifier alias

Returns

string | undefined


router

Get Signature

ts
get router(): RouterAdapter | undefined;

Defined in: lib/vowel/core/VowelClient.ts:882

Get router adapter (legacy)

Deprecated

Use navigationAdapter property instead

Returns

RouterAdapter | undefined


routes

Get Signature

ts
get routes(): VowelRoute[];

Defined in: lib/vowel/core/VowelClient.ts:889

Get configured routes

Returns

VowelRoute[]


session

Get Signature

ts
get session(): SessionManager;

Defined in: lib/vowel/core/VowelClient.ts:896

Get session manager (for internal use by action handlers)

Returns

SessionManager


voiceConfig

Get Signature

ts
get voiceConfig(): VowelVoiceConfig | undefined;

Defined in: lib/vowel/core/VowelClient.ts:903

Get voice configuration

Returns

VowelVoiceConfig | undefined


systemInstructionOverride

Get Signature

ts
get systemInstructionOverride(): string | undefined;

Defined in: lib/vowel/core/VowelClient.ts:910

Get system instruction override

Returns

string | undefined


state

Get Signature

ts
get state(): VoiceSessionState;

Defined in: lib/vowel/core/VowelClient.ts:917

Get current session state

Returns

VoiceSessionState


floatingCursor

Get Signature

ts
get floatingCursor(): FloatingCursorManager | undefined;

Defined in: lib/vowel/core/VowelClient.ts:945

Get floating cursor manager (if enabled)

Returns

FloatingCursorManager | undefined

Methods

isUserSpeaking()

ts
isUserSpeaking(): boolean;

Defined in: lib/vowel/core/VowelClient.ts:924

Check if user is currently speaking (client-side VAD)

Returns

boolean


isAIThinking()

ts
isAIThinking(): boolean;

Defined in: lib/vowel/core/VowelClient.ts:931

Check if AI is currently thinking/processing

Returns

boolean


isAISpeaking()

ts
isAISpeaking(): boolean;

Defined in: lib/vowel/core/VowelClient.ts:938

Check if AI is currently speaking

Returns

boolean


registerAction()

ts
registerAction<T>(
   name, 
   definition, 
   handler): void;

Defined in: lib/vowel/core/VowelClient.ts:992

Register a custom action that the AI can perform

⚠️ CRITICAL: Actions MUST be registered BEFORE calling startSession()! Actions registered after the session starts will have NO EFFECT. Tool definitions are sent to the server during session initialization.

Type Parameters

Type ParameterDefault type
Tany

Parameters

ParameterTypeDescription
namestringAction name (will be used as tool name)
definitionVowelActionAction definition with parameters
handlerActionHandler<T>Function to execute when action is called

Returns

void

Example

ts
// ✅ CORRECT - Register before starting session
vowel.registerAction('addToCart', {
  description: 'Add product to shopping cart',
  parameters: {
    productId: {
      type: 'string',
      description: 'Product ID'
    },
    quantity: {
      type: 'number',
      description: 'Quantity',
      optional: true
    }
  }
}, async ({ productId, quantity = 1 }) => {
  await addToCart(productId, quantity);
});

// Then start the session
await vowel.startSession();

// ❌ WRONG - Too late!
await vowel.startSession();
vowel.registerAction('addToCart', ...);  // Won't work!

registerActions()

ts
registerActions(actions): void;

Defined in: lib/vowel/core/VowelClient.ts:1020

Register multiple actions at once

Parameters

ParameterType
actionsRecord<string, { definition: VowelAction; handler: ActionHandler; }>

Returns

void

Example

ts
vowel.registerActions({
  searchProducts: {
    definition: { ... },
    handler: async (params) => { ... }
  },
  addToCart: {
    definition: { ... },
    handler: async (params) => { ... }
  }
});

unregisterAction()

ts
unregisterAction(name): void;

Defined in: lib/vowel/core/VowelClient.ts:1031

Unregister an action

Parameters

ParameterType
namestring

Returns

void


getActionsConfig()

ts
getActionsConfig(): Record<string, VowelAction>;

Defined in: lib/vowel/core/VowelClient.ts:1038

Get all registered actions as a record (for configuration)

Returns

Record<string, VowelAction>


onActionNotification()

ts
onActionNotification(listener): () => void;

Defined in: lib/vowel/core/VowelClient.ts:1042

Parameters

ParameterType
listener(notification) => void

Returns

ts
(): void;
Returns

void


executeAction()

ts
executeAction(name, params): Promise<ToolResult>;

Defined in: lib/vowel/core/VowelClient.ts:1049

Execute a registered action

Parameters

ParameterType
namestring
paramsany

Returns

Promise<ToolResult>


hasAction()

ts
hasAction(name): boolean;

Defined in: lib/vowel/core/VowelClient.ts:1064

Check if an action is registered

Parameters

ParameterType
namestring

Returns

boolean


addRoutes()

ts
addRoutes(routes): void;

Defined in: lib/vowel/core/VowelClient.ts:1075

Add routes (useful for dynamic route registration)

Parameters

ParameterType
routesVowelRoute[]

Returns

void


setRoutes()

ts
setRoutes(routes): void;

Defined in: lib/vowel/core/VowelClient.ts:1082

Set routes (replaces existing)

Parameters

ParameterType
routesVowelRoute[]

Returns

void


getCurrentPath()

ts
getCurrentPath(): string;

Defined in: lib/vowel/core/VowelClient.ts:1089

Get current path

Returns

string


ts
navigate(path): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1102

Navigate to a path

Parameters

ParameterType
pathstring

Returns

Promise<void>


onStateChange()

ts
onStateChange(listener): () => void;

Defined in: lib/vowel/core/VowelClient.ts:1119

Subscribe to state changes

Parameters

ParameterType
listener(state) => void

Returns

ts
(): void;
Returns

void


clearTranscripts()

ts
clearTranscripts(): void;

Defined in: lib/vowel/core/VowelClient.ts:1154

Clear transcript history

Returns

void


clearError()

ts
clearError(): void;

Defined in: lib/vowel/core/VowelClient.ts:1161

Clear the current error state

Returns

void


getDarkMode()

ts
getDarkMode(): boolean;

Defined in: lib/vowel/core/VowelClient.ts:1168

Get current dark mode state

Returns

boolean


setDarkMode()

ts
setDarkMode(isDark): void;

Defined in: lib/vowel/core/VowelClient.ts:1175

Set dark mode state

Parameters

ParameterType
isDarkboolean

Returns

void


toggleDarkMode()

ts
toggleDarkMode(): void;

Defined in: lib/vowel/core/VowelClient.ts:1182

Toggle dark mode

Returns

void


exportState()

ts
exportState(options?): VoiceSessionState;

Defined in: lib/vowel/core/VowelClient.ts:1200

Export conversation state for later restoration

Parameters

ParameterTypeDescription
options?{ maxTurns?: number; }Export options
options.maxTurns?numberMaximum conversation turns to include (default: all)

Returns

VoiceSessionState

Serializable state object

Example

ts
// Save state to localStorage
const state = vowel.exportState({ maxTurns: 20 });
localStorage.setItem('vowel-conversation', JSON.stringify(state));

importState()

ts
importState(savedState): void;

Defined in: lib/vowel/core/VowelClient.ts:1218

Import conversation state from a previous session

Parameters

ParameterTypeDescription
savedStatePartial<VoiceSessionState>Previously exported state

Returns

void

Example

ts
// Restore state from localStorage
const saved = localStorage.getItem('vowel-conversation');
if (saved) {
  vowel.importState(JSON.parse(saved));
}

startSession()

ts
startSession(options?): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1266

Start a voice session Content window should be opened before calling this (in click handler for Shopify) Navigation is handled via BroadcastChannel, not WindowProxy

⚠️ CRITICAL for iOS Safari: This method MUST be called directly from a user gesture handler (click, touchstart, touchend). iOS Safari requires AudioContext creation and getUserMedia() calls to happen within the same user gesture event handler.

✅ Correct usage:

ts
button.addEventListener('click', async () => {
  await vowel.startSession(); // Called directly from click handler
});

❌ Incorrect usage (will fail on iOS):

ts
button.addEventListener('click', () => {
  setTimeout(() => {
    vowel.startSession(); // Too late - outside gesture handler
  }, 100);
});

Parameters

ParameterTypeDescription
options?{ restoreState?: Partial<VoiceSessionState>; }Session start options
options.restoreState?Partial<VoiceSessionState>Previously exported state to restore conversation context

Returns

Promise<void>

Example

ts
// Start fresh session
await vowel.startSession();

// Start with restored context
const saved = localStorage.getItem('vowel-conversation');
if (saved) {
  await vowel.startSession({ restoreState: JSON.parse(saved) });
}

notify()

ts
notify(
   eventType, 
   message, 
data?): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1334

Send a notification to the AI about an app event This allows programmatic triggering of AI responses

Parameters

ParameterTypeDescription
eventTypestringType of event (e.g., 'notification', 'resource_issue', 'session_start')
messagestringHuman-readable message describing the event
data?Record<string, any>Optional additional data/context

Returns

Promise<void>

Example

ts
// Notify AI about a game event
vowel.notify('resource_issue', 'Low on wood', { wood: 5, required: 20 });

// Notify about session start
vowel.notify('session_start', 'Voice control is now active');

stopSession()

ts
stopSession(): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1393

Stop the current session

Returns

Promise<void>


pauseSession()

ts
pauseSession(): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1437

Pause the current session (mute microphone, keep connection alive) This is useful for temporarily stopping audio input without disconnecting

Returns

Promise<void>

Example

ts
// Pause during a phone call
await vowel.pauseSession();

// Resume after the call
await vowel.resumeSession();

resumeSession()

ts
resumeSession(): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1471

Resume a paused session (unmute microphone)

Returns

Promise<void>

Example

ts
await vowel.resumeSession();

toggleSession()

ts
toggleSession(): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1500

Toggle session on/off

Returns

Promise<void>


getAvailableMicrophones()

ts
getAvailableMicrophones(requirePermission): Promise<MediaDeviceInfo[]>;

Defined in: lib/vowel/core/VowelClient.ts:1526

Get available microphone devices

Parameters

ParameterTypeDefault valueDescription
requirePermissionbooleanfalseIf true, request getUserMedia first to get device labels. On iOS Safari, this MUST be called from a user gesture handler.

Returns

Promise<MediaDeviceInfo[]>

Promise resolving to array of MediaDeviceInfo for available audio input devices

Example

ts
const devices = await vowel.getAvailableMicrophones();
console.log('Available microphones:', devices.map(d => d.label));

hasMicrophonePermission()

ts
hasMicrophonePermission(): Promise<boolean>;

Defined in: lib/vowel/core/VowelClient.ts:1534

Check if microphone permission has been granted

Returns

Promise<boolean>

Promise resolving to true if permission granted, false otherwise


requestMicrophonePermission()

ts
requestMicrophonePermission(): Promise<boolean>;

Defined in: lib/vowel/core/VowelClient.ts:1543

Request microphone permission MUST be called from a user gesture handler on iOS Safari

Returns

Promise<boolean>

Promise resolving to true if permission granted, false otherwise


getCurrentMicrophone()

ts
getCurrentMicrophone(): MediaDeviceInfo | null;

Defined in: lib/vowel/core/VowelClient.ts:1560

Get the currently active microphone device

Returns

MediaDeviceInfo | null

MediaDeviceInfo for current device, or null if not available

Example

ts
const currentMic = vowel.getCurrentMicrophone();
if (currentMic) {
  console.log('Current microphone:', currentMic.label);
}

setMicrophoneDevice()

ts
setMicrophoneDevice(deviceId): void;

Defined in: lib/vowel/core/VowelClient.ts:1579

Set microphone device preference This will apply the device on the next microphone setup (next connection)

Parameters

ParameterTypeDescription
deviceIdstringThe device ID to use

Returns

void

Example

ts
const devices = await vowel.getAvailableMicrophones();
const usbMic = devices.find(d => d.label.includes('USB'));
if (usbMic) {
  vowel.setMicrophoneDevice(usbMic.deviceId);
}

switchMicrophoneDevice()

ts
switchMicrophoneDevice(deviceId): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1598

Switch microphone device during an active session This will reinitialize the microphone stream with the new device

Parameters

ParameterTypeDescription
deviceIdstringThe device ID to switch to

Returns

Promise<void>

Example

ts
const devices = await vowel.getAvailableMicrophones();
const newMic = devices[1];
await vowel.switchMicrophoneDevice(newMic.deviceId);

notifyEvent()

ts
notifyEvent(eventDetails, context?): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1655

Notify the AI about an app event This allows programmatic triggering of AI voice responses without user speech input

Parameters

ParameterTypeDescription
eventDetailsstringDescription of the event that occurred
context?Record<string, any>Optional context object to provide additional information

Returns

Promise<void>

Example

ts
// Simple notification
await vowel.notifyEvent('Order placed successfully!');

// Notification with context
await vowel.notifyEvent('New message received', {
  from: 'John Doe',
  preview: 'Hey, are you available?',
  timestamp: new Date().toISOString()
});

// Timer expiry notification
await vowel.notifyEvent('Your 5-minute timer has expired');

// Shopping cart update
await vowel.notifyEvent('Item added to cart', {
  productName: 'Wireless Headphones',
  price: 79.99,
  cartTotal: 3
});

sendText()

ts
sendText(text): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1679

Send text to the AI for processing Lower-level method for custom text-based interactions

Parameters

ParameterTypeDescription
textstringText to send to the AI

Returns

Promise<void>

Example

ts
// Ask a question programmatically
await vowel.sendText('What are the current promotions?');

// Provide context to the AI
await vowel.sendText('The user is looking at product ID 12345');

sendImage()

ts
sendImage(imageUrl): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1707

Send an image to the AI for processing Enables multimodal interactions where the AI can see and respond to images

Parameters

ParameterTypeDescription
imageUrlstringURL or data URI of the image to send

Returns

Promise<void>

Example

ts
// Send an image URL
await vowel.sendImage('https://example.com/product.jpg');

// Send a data URI (e.g., from canvas or file upload)
await vowel.sendImage('data:image/png;base64,iVBORw0KGgoAAAANS...');

// Combined with text context
await vowel.sendText('What do you see in this image?');
await vowel.sendImage(imageUrl);

updateContext()

ts
updateContext(context): void;

Defined in: lib/vowel/core/VowelClient.ts:1745

Update the dynamic context that gets appended to system prompt. Context is stringified, wrapped in &lt;context&gt; tags and sent via session.update.

When context changes, a session.update event is automatically sent to update the system prompt so the AI knows about the current context.

Parameters

ParameterTypeDescription
contextRecord<string, unknown> | nullContext object to append to system prompt. Use null to clear.

Returns

void

Example

ts
// Update context with current page info
vowel.updateContext({ page: 'product', productId: 'iphone-15-pro' });

// Update with multiple details
vowel.updateContext({ 
  page: 'checkout', 
  cartTotal: 199.99, 
  itemCount: 2 
});

// Clear context
vowel.updateContext(null);

getContext()

ts
getContext(): Record<string, unknown> | null;

Defined in: lib/vowel/core/VowelClient.ts:1774

Get current context value

Returns

Record<string, unknown> | null

Current context object (null if no context set)

Example

ts
const currentContext = vowel.getContext();
console.log('Current context:', currentContext);