/** * @fileoverview State Manager - Handles voice session state and listener notifications * * This file contains the `StateManager` class which provides reactive state management * for the Vowel client. It maintains the current session state, tracks speaking states * (user, AI thinking, AI speaking), manages transcripts, and notifies subscribers of * state changes. * * Responsibilities: * - Maintaining session connection state * - Tracking user and AI speaking states * - Managing conversation transcripts * - Notifying listeners of state changes * - Providing immutable state access * * @module @vowel.to/client/managers * @author vowel.to * @license Proprietary */ /** * Voice session state */ export interface VoiceSessionState { isConnecting: boolean; isConnected: boolean; isDisconnecting: boolean; isResuming: boolean; status: string; transcripts: Array<{ role: "user" | "assistant"; text: string; timestamp: Date; }>; isUserSpeaking: boolean; isAIThinking: boolean; isToolExecuting: boolean; isAISpeaking: boolean; isHibernated: boolean; error?: { message: string; details?: string | object; timestamp: Date; } | null; } /** * State change listener function */ export type StateChangeListener = (state: VoiceSessionState) => void; /** * State Manager class * Manages voice session state and notifies listeners of changes */ export declare class StateManager { private state; private listeners; constructor(initialState?: Partial); /** * Get current state (returns a copy) */ getState(): VoiceSessionState; /** * Update state and notify listeners */ updateState(updates: Partial): void; /** * Add a transcript entry */ addTranscript(transcript: { role: "user" | "assistant"; text: string; timestamp: Date; }): void; /** * Clear transcript history */ clearTranscripts(): void; /** * Subscribe to state changes * @returns Unsubscribe function */ subscribe(listener: StateChangeListener): () => void; /** * Notify all listeners of state change */ private notifyListeners; /** * Set user speaking state */ setUserSpeaking(isSpeaking: boolean): void; /** * Set AI thinking state */ setAIThinking(isThinking: boolean): void; /** * Set tool executing state */ setToolExecuting(isExecuting: boolean): void; /** * Set AI speaking state */ setAISpeaking(isSpeaking: boolean): void; /** * Set hibernated state */ setHibernated(isHibernated: boolean): void; /** * Clear error state */ clearError(): void; /** * Reset state to initial values */ reset(): void; /** * Export conversation state for restoration * Returns a serializable object containing transcripts * * @param options - Export options * @param options.maxTurns - Maximum number of conversation turns to include (default: all) * @returns Serializable state object * * @example * ```ts * const state = vowel.exportState({ maxTurns: 10 }); * localStorage.setItem('vowel-state', JSON.stringify(state)); * ``` */ exportState(options?: { maxTurns?: number; }): VoiceSessionState; /** * Import conversation state from a previous session * Merges transcripts into current state * * @param savedState - Previously exported state * * @example * ```ts * const savedState = JSON.parse(localStorage.getItem('vowel-state')); * vowel.importState(savedState); * ``` */ importState(savedState: Partial): void; } //# sourceMappingURL=StateManager.d.ts.map