@lokutor/sdk 1.1.17 → 1.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -85,18 +85,68 @@ interface VoiceAgentOptions {
85
85
  language?: Language;
86
86
  serverUrl?: string;
87
87
  visemes?: boolean;
88
- onTranscription?: (text: string, isUser: boolean) => void;
88
+ onTranscription?: (text: string) => void;
89
89
  onVisemes?: (visemes: Viseme[]) => void;
90
90
  onStatusChange?: (status: string) => void;
91
- onError?: (err: any) => void;
91
+ onError?: (err: LokutorError) => void;
92
+ }
93
+ /**
94
+ * REST API response types for discovery endpoints.
95
+ */
96
+ interface VoiceInfo {
97
+ id: string;
98
+ gender?: string;
99
+ languages?: string[];
100
+ }
101
+ interface LanguageInfo {
102
+ code: string;
103
+ name: string;
104
+ }
105
+ interface ModelInfo {
106
+ name: string;
107
+ description?: string;
108
+ default?: boolean;
109
+ }
110
+ interface ServerConfig {
111
+ max_text_length: number;
112
+ min_speed: number;
113
+ max_speed: number;
114
+ min_steps: number;
115
+ max_steps: number;
116
+ sample_rate: number;
117
+ channels: number;
118
+ }
119
+ interface ServerStatus {
120
+ status: string;
121
+ timestamp: string;
122
+ version: string;
123
+ runtime: string;
124
+ inference: string;
125
+ uptime_seconds: number;
126
+ goroutines: number;
127
+ mem_alloc_bytes: number;
128
+ active_connections: number;
129
+ failed_requests: number;
130
+ ready: boolean;
131
+ }
132
+ interface HealthStatus {
133
+ status: string;
134
+ timestamp: string;
135
+ version: string;
136
+ runtime: string;
137
+ inference: string;
138
+ load: number;
92
139
  }
93
140
  /**
94
141
  * Viseme data for lip-sync animation
95
142
  * Format: {"v": index, "c": character, "t": timestamp}
96
143
  */
97
144
  interface Viseme {
145
+ /** Text-position index (which input character the model is attending to), not a stable viseme ID */
98
146
  v: number;
147
+ /** Character/phoneme being spoken (reduced set: a,e,i,o,u,m,p,b,f,v,t,d,s,z,l,n,r,k,g,sil) */
99
148
  c: string;
149
+ /** Offset in seconds from the start of the audio stream */
100
150
  t: number;
101
151
  }
102
152
  /**
@@ -121,6 +171,30 @@ interface ToolCall {
121
171
  name: string;
122
172
  arguments: string;
123
173
  }
174
+ /**
175
+ * Error code enum matching the backend API error catalog
176
+ */
177
+ type ErrorCode = 'auth.missing_key' | 'auth.invalid_key' | 'auth.rate_limited' | 'auth.time_limited' | 'validation.invalid_voice' | 'validation.invalid_language' | 'validation.text_too_long' | 'validation.speed_out_of_range' | 'validation.steps_out_of_range' | 'validation.invalid_request_format' | 'tts.synthesis_failed' | 'tts.voice_unavailable' | 'tts.model_not_found' | 'tts.session_limit_reached' | 'stt.not_configured' | 'stt.stream_create_failed' | 'stt.language_not_supported' | 'agent.session_failed' | 'agent.provider_error' | 'internal.error' | 'internal.timeout' | 'internal.cancelled' | 'ws.close';
178
+ /**
179
+ * Typed error class for all Lokutor SDK errors.
180
+ * Includes the backend error code, human-readable message,
181
+ * optional detail, and whether the operation is retryable.
182
+ */
183
+ declare class LokutorError extends Error {
184
+ readonly code: ErrorCode;
185
+ readonly detail?: string;
186
+ readonly retryable: boolean;
187
+ readonly original?: unknown;
188
+ constructor(code: ErrorCode, message: string, opts?: {
189
+ detail?: string;
190
+ retryable?: boolean;
191
+ original?: unknown;
192
+ });
193
+ }
194
+ /**
195
+ * Returns true if the given error is a retryable LokutorError.
196
+ */
197
+ declare function isRetryable(error: unknown): boolean;
124
198
 
125
199
  /**
126
200
  * Interface for audio hardware management (Browser/Node parity)
@@ -166,6 +240,7 @@ declare class VoiceAgentClient {
166
240
  private reconnecting;
167
241
  private reconnectAttempts;
168
242
  private maxReconnectAttempts;
243
+ private serverUrl;
169
244
  constructor(config: LokutorConfig & {
170
245
  prompt: string;
171
246
  voice?: VoiceStyle;
@@ -174,6 +249,7 @@ declare class VoiceAgentClient {
174
249
  onVisemes?: (visemes: Viseme[]) => void;
175
250
  enableAudio?: boolean;
176
251
  tools?: ToolDefinition[];
252
+ serverUrl?: string;
177
253
  });
178
254
  /**
179
255
  * Connect to the Lokutor Voice Agent server
@@ -182,7 +258,7 @@ declare class VoiceAgentClient {
182
258
  connect(customAudioManager?: AudioManager): Promise<boolean>;
183
259
  /**
184
260
  * The "Golden Path" - Starts a managed session with hardware handled automatically.
185
- * This is the recommended way to start a conversation in both Browser and Node.js.
261
+ * This is the recommended way to start a conversation in browser environments.
186
262
  */
187
263
  startManaged(config?: {
188
264
  audioManager?: AudioManager;
@@ -218,6 +294,15 @@ declare class VoiceAgentClient {
218
294
  * Disconnect from the server
219
295
  */
220
296
  disconnect(): void;
297
+ /**
298
+ * Returns true if the client is currently connected.
299
+ */
300
+ get connected(): boolean;
301
+ /**
302
+ * Returns the current generation counter.
303
+ * Useful for correlating audio/viseme chunks with utterances.
304
+ */
305
+ get generation(): number;
221
306
  /**
222
307
  * Toggles the microphone mute state (if managed by client)
223
308
  * returns the new mute state
@@ -227,6 +312,36 @@ declare class VoiceAgentClient {
227
312
  * Gets the microphone volume amplitude 0-1 (if managed by client)
228
313
  */
229
314
  getAmplitude(): number;
315
+ /**
316
+ * Fetch available voice styles from the server.
317
+ * No authentication required.
318
+ */
319
+ static fetchVoices(baseUrl?: string): Promise<VoiceInfo[]>;
320
+ /**
321
+ * Fetch supported languages from the server.
322
+ * No authentication required.
323
+ */
324
+ static fetchLanguages(baseUrl?: string): Promise<LanguageInfo[]>;
325
+ /**
326
+ * Fetch loaded TTS model versions from the server.
327
+ * No authentication required.
328
+ */
329
+ static fetchModels(baseUrl?: string): Promise<ModelInfo[]>;
330
+ /**
331
+ * Fetch server configuration (limits and defaults).
332
+ * No authentication required.
333
+ */
334
+ static fetchConfig(baseUrl?: string): Promise<ServerConfig>;
335
+ /**
336
+ * Fetch rich runtime status from the server.
337
+ * No authentication required.
338
+ */
339
+ static fetchStatus(baseUrl?: string): Promise<ServerStatus>;
340
+ /**
341
+ * Fetch health/liveness status from the server.
342
+ * No authentication required.
343
+ */
344
+ static fetchHealth(baseUrl?: string): Promise<HealthStatus>;
230
345
  /**
231
346
  * Update the system prompt mid-conversation
232
347
  */
@@ -475,4 +590,78 @@ declare class BrowserAudioManager {
475
590
  isRecording(): boolean;
476
591
  }
477
592
 
478
- export { AUDIO_CONFIG, type AnalyserConfig, type AudioManager, type BrowserAudioConfig, BrowserAudioManager, type BrowserAudioOptions, DEFAULT_URLS, Language, type LokutorConfig, StreamResampler, type SynthesizeOptions, TTSClient, type ToolCall, type ToolDefinition, type Viseme, VoiceAgentClient, type VoiceAgentOptions, VoiceStyle, applyLowPassFilter, bytesToPcm16, calculateRMS, float32ToPcm16, normalizeAudio, pcm16ToBytes, pcm16ToFloat32, resample, resampleWithAntiAliasing, simpleConversation, simpleTTS };
593
+ interface ConversationalPanelConfig {
594
+ container: HTMLElement;
595
+ title: string;
596
+ description: string;
597
+ prompt: string;
598
+ voice?: string;
599
+ language?: string;
600
+ /** Accent color for the sphere glow and highlights, e.g. '#e74c3c' */
601
+ accentColor?: string;
602
+ /** Background color, e.g. '#0a0a0a' */
603
+ backgroundColor?: string;
604
+ /** API key for connecting to the voice agent */
605
+ apiKey: string;
606
+ /** Reference to the ConvoAgent class */
607
+ ConvoAgent: any;
608
+ /** Reference to the SphereVisualizer class */
609
+ SphereVisualizer: any;
610
+ /** URL for the connecting sound asset */
611
+ connectingSoundSrc?: string;
612
+ /** Background image for the curtain, e.g. '/background_gradient.jpeg' */
613
+ curtainBgSrc?: string;
614
+ }
615
+ declare class ConversationalPanel {
616
+ private cfg;
617
+ private container;
618
+ private agent;
619
+ private visualizer;
620
+ private timerTicker;
621
+ private connectingSound;
622
+ private connectingFadeTimer;
623
+ private isRunning;
624
+ private el;
625
+ private curtain;
626
+ private curtainTitle;
627
+ private curtainDesc;
628
+ private startBtn;
629
+ private errorEl;
630
+ private errorText;
631
+ private timerEl;
632
+ private canvas;
633
+ private muteBtn;
634
+ private stopBtn;
635
+ private visualizerWrap;
636
+ onTranscription?: (text: string) => void;
637
+ onResponse?: (text: string) => void;
638
+ onStart?: () => void;
639
+ onStop?: () => void;
640
+ onError?: (err: any) => void;
641
+ constructor(cfg: ConversationalPanelConfig);
642
+ private buildDOM;
643
+ private esc;
644
+ /** Start the conversation (called when user clicks "Start Conversation" or externally) */
645
+ start(): Promise<void>;
646
+ /** Stop / disconnect the conversation */
647
+ stop(): void;
648
+ /** Update accent color dynamically */
649
+ setColor(color: string): void;
650
+ /** Update title text */
651
+ setTitle(title: string): void;
652
+ /** Update description text */
653
+ setDescription(desc: string): void;
654
+ /** Update prompt (only takes effect on next start()) */
655
+ setPrompt(prompt: string): void;
656
+ /** Show an error message */
657
+ showError(text: string): void;
658
+ /** Destroy the component, removing all DOM and stopping any active session */
659
+ destroy(): void;
660
+ private startTimer;
661
+ private toggleMute;
662
+ private playConnectingSound;
663
+ private fadeOutConnectingSound;
664
+ private playErrorTone;
665
+ }
666
+
667
+ export { AUDIO_CONFIG, type AnalyserConfig, type AudioManager, type BrowserAudioConfig, BrowserAudioManager, type BrowserAudioOptions, ConversationalPanel, type ConversationalPanelConfig, DEFAULT_URLS, type ErrorCode, type HealthStatus, Language, type LanguageInfo, type LokutorConfig, LokutorError, type ModelInfo, type ServerConfig, type ServerStatus, StreamResampler, type SynthesizeOptions, TTSClient, type ToolCall, type ToolDefinition, type Viseme, VoiceAgentClient, type VoiceAgentOptions, type VoiceInfo, VoiceStyle, applyLowPassFilter, bytesToPcm16, calculateRMS, float32ToPcm16, isRetryable, normalizeAudio, pcm16ToBytes, pcm16ToFloat32, resample, resampleWithAntiAliasing, simpleConversation, simpleTTS };
package/dist/index.d.ts CHANGED
@@ -85,18 +85,68 @@ interface VoiceAgentOptions {
85
85
  language?: Language;
86
86
  serverUrl?: string;
87
87
  visemes?: boolean;
88
- onTranscription?: (text: string, isUser: boolean) => void;
88
+ onTranscription?: (text: string) => void;
89
89
  onVisemes?: (visemes: Viseme[]) => void;
90
90
  onStatusChange?: (status: string) => void;
91
- onError?: (err: any) => void;
91
+ onError?: (err: LokutorError) => void;
92
+ }
93
+ /**
94
+ * REST API response types for discovery endpoints.
95
+ */
96
+ interface VoiceInfo {
97
+ id: string;
98
+ gender?: string;
99
+ languages?: string[];
100
+ }
101
+ interface LanguageInfo {
102
+ code: string;
103
+ name: string;
104
+ }
105
+ interface ModelInfo {
106
+ name: string;
107
+ description?: string;
108
+ default?: boolean;
109
+ }
110
+ interface ServerConfig {
111
+ max_text_length: number;
112
+ min_speed: number;
113
+ max_speed: number;
114
+ min_steps: number;
115
+ max_steps: number;
116
+ sample_rate: number;
117
+ channels: number;
118
+ }
119
+ interface ServerStatus {
120
+ status: string;
121
+ timestamp: string;
122
+ version: string;
123
+ runtime: string;
124
+ inference: string;
125
+ uptime_seconds: number;
126
+ goroutines: number;
127
+ mem_alloc_bytes: number;
128
+ active_connections: number;
129
+ failed_requests: number;
130
+ ready: boolean;
131
+ }
132
+ interface HealthStatus {
133
+ status: string;
134
+ timestamp: string;
135
+ version: string;
136
+ runtime: string;
137
+ inference: string;
138
+ load: number;
92
139
  }
93
140
  /**
94
141
  * Viseme data for lip-sync animation
95
142
  * Format: {"v": index, "c": character, "t": timestamp}
96
143
  */
97
144
  interface Viseme {
145
+ /** Text-position index (which input character the model is attending to), not a stable viseme ID */
98
146
  v: number;
147
+ /** Character/phoneme being spoken (reduced set: a,e,i,o,u,m,p,b,f,v,t,d,s,z,l,n,r,k,g,sil) */
99
148
  c: string;
149
+ /** Offset in seconds from the start of the audio stream */
100
150
  t: number;
101
151
  }
102
152
  /**
@@ -121,6 +171,30 @@ interface ToolCall {
121
171
  name: string;
122
172
  arguments: string;
123
173
  }
174
+ /**
175
+ * Error code enum matching the backend API error catalog
176
+ */
177
+ type ErrorCode = 'auth.missing_key' | 'auth.invalid_key' | 'auth.rate_limited' | 'auth.time_limited' | 'validation.invalid_voice' | 'validation.invalid_language' | 'validation.text_too_long' | 'validation.speed_out_of_range' | 'validation.steps_out_of_range' | 'validation.invalid_request_format' | 'tts.synthesis_failed' | 'tts.voice_unavailable' | 'tts.model_not_found' | 'tts.session_limit_reached' | 'stt.not_configured' | 'stt.stream_create_failed' | 'stt.language_not_supported' | 'agent.session_failed' | 'agent.provider_error' | 'internal.error' | 'internal.timeout' | 'internal.cancelled' | 'ws.close';
178
+ /**
179
+ * Typed error class for all Lokutor SDK errors.
180
+ * Includes the backend error code, human-readable message,
181
+ * optional detail, and whether the operation is retryable.
182
+ */
183
+ declare class LokutorError extends Error {
184
+ readonly code: ErrorCode;
185
+ readonly detail?: string;
186
+ readonly retryable: boolean;
187
+ readonly original?: unknown;
188
+ constructor(code: ErrorCode, message: string, opts?: {
189
+ detail?: string;
190
+ retryable?: boolean;
191
+ original?: unknown;
192
+ });
193
+ }
194
+ /**
195
+ * Returns true if the given error is a retryable LokutorError.
196
+ */
197
+ declare function isRetryable(error: unknown): boolean;
124
198
 
125
199
  /**
126
200
  * Interface for audio hardware management (Browser/Node parity)
@@ -166,6 +240,7 @@ declare class VoiceAgentClient {
166
240
  private reconnecting;
167
241
  private reconnectAttempts;
168
242
  private maxReconnectAttempts;
243
+ private serverUrl;
169
244
  constructor(config: LokutorConfig & {
170
245
  prompt: string;
171
246
  voice?: VoiceStyle;
@@ -174,6 +249,7 @@ declare class VoiceAgentClient {
174
249
  onVisemes?: (visemes: Viseme[]) => void;
175
250
  enableAudio?: boolean;
176
251
  tools?: ToolDefinition[];
252
+ serverUrl?: string;
177
253
  });
178
254
  /**
179
255
  * Connect to the Lokutor Voice Agent server
@@ -182,7 +258,7 @@ declare class VoiceAgentClient {
182
258
  connect(customAudioManager?: AudioManager): Promise<boolean>;
183
259
  /**
184
260
  * The "Golden Path" - Starts a managed session with hardware handled automatically.
185
- * This is the recommended way to start a conversation in both Browser and Node.js.
261
+ * This is the recommended way to start a conversation in browser environments.
186
262
  */
187
263
  startManaged(config?: {
188
264
  audioManager?: AudioManager;
@@ -218,6 +294,15 @@ declare class VoiceAgentClient {
218
294
  * Disconnect from the server
219
295
  */
220
296
  disconnect(): void;
297
+ /**
298
+ * Returns true if the client is currently connected.
299
+ */
300
+ get connected(): boolean;
301
+ /**
302
+ * Returns the current generation counter.
303
+ * Useful for correlating audio/viseme chunks with utterances.
304
+ */
305
+ get generation(): number;
221
306
  /**
222
307
  * Toggles the microphone mute state (if managed by client)
223
308
  * returns the new mute state
@@ -227,6 +312,36 @@ declare class VoiceAgentClient {
227
312
  * Gets the microphone volume amplitude 0-1 (if managed by client)
228
313
  */
229
314
  getAmplitude(): number;
315
+ /**
316
+ * Fetch available voice styles from the server.
317
+ * No authentication required.
318
+ */
319
+ static fetchVoices(baseUrl?: string): Promise<VoiceInfo[]>;
320
+ /**
321
+ * Fetch supported languages from the server.
322
+ * No authentication required.
323
+ */
324
+ static fetchLanguages(baseUrl?: string): Promise<LanguageInfo[]>;
325
+ /**
326
+ * Fetch loaded TTS model versions from the server.
327
+ * No authentication required.
328
+ */
329
+ static fetchModels(baseUrl?: string): Promise<ModelInfo[]>;
330
+ /**
331
+ * Fetch server configuration (limits and defaults).
332
+ * No authentication required.
333
+ */
334
+ static fetchConfig(baseUrl?: string): Promise<ServerConfig>;
335
+ /**
336
+ * Fetch rich runtime status from the server.
337
+ * No authentication required.
338
+ */
339
+ static fetchStatus(baseUrl?: string): Promise<ServerStatus>;
340
+ /**
341
+ * Fetch health/liveness status from the server.
342
+ * No authentication required.
343
+ */
344
+ static fetchHealth(baseUrl?: string): Promise<HealthStatus>;
230
345
  /**
231
346
  * Update the system prompt mid-conversation
232
347
  */
@@ -475,4 +590,78 @@ declare class BrowserAudioManager {
475
590
  isRecording(): boolean;
476
591
  }
477
592
 
478
- export { AUDIO_CONFIG, type AnalyserConfig, type AudioManager, type BrowserAudioConfig, BrowserAudioManager, type BrowserAudioOptions, DEFAULT_URLS, Language, type LokutorConfig, StreamResampler, type SynthesizeOptions, TTSClient, type ToolCall, type ToolDefinition, type Viseme, VoiceAgentClient, type VoiceAgentOptions, VoiceStyle, applyLowPassFilter, bytesToPcm16, calculateRMS, float32ToPcm16, normalizeAudio, pcm16ToBytes, pcm16ToFloat32, resample, resampleWithAntiAliasing, simpleConversation, simpleTTS };
593
+ interface ConversationalPanelConfig {
594
+ container: HTMLElement;
595
+ title: string;
596
+ description: string;
597
+ prompt: string;
598
+ voice?: string;
599
+ language?: string;
600
+ /** Accent color for the sphere glow and highlights, e.g. '#e74c3c' */
601
+ accentColor?: string;
602
+ /** Background color, e.g. '#0a0a0a' */
603
+ backgroundColor?: string;
604
+ /** API key for connecting to the voice agent */
605
+ apiKey: string;
606
+ /** Reference to the ConvoAgent class */
607
+ ConvoAgent: any;
608
+ /** Reference to the SphereVisualizer class */
609
+ SphereVisualizer: any;
610
+ /** URL for the connecting sound asset */
611
+ connectingSoundSrc?: string;
612
+ /** Background image for the curtain, e.g. '/background_gradient.jpeg' */
613
+ curtainBgSrc?: string;
614
+ }
615
+ declare class ConversationalPanel {
616
+ private cfg;
617
+ private container;
618
+ private agent;
619
+ private visualizer;
620
+ private timerTicker;
621
+ private connectingSound;
622
+ private connectingFadeTimer;
623
+ private isRunning;
624
+ private el;
625
+ private curtain;
626
+ private curtainTitle;
627
+ private curtainDesc;
628
+ private startBtn;
629
+ private errorEl;
630
+ private errorText;
631
+ private timerEl;
632
+ private canvas;
633
+ private muteBtn;
634
+ private stopBtn;
635
+ private visualizerWrap;
636
+ onTranscription?: (text: string) => void;
637
+ onResponse?: (text: string) => void;
638
+ onStart?: () => void;
639
+ onStop?: () => void;
640
+ onError?: (err: any) => void;
641
+ constructor(cfg: ConversationalPanelConfig);
642
+ private buildDOM;
643
+ private esc;
644
+ /** Start the conversation (called when user clicks "Start Conversation" or externally) */
645
+ start(): Promise<void>;
646
+ /** Stop / disconnect the conversation */
647
+ stop(): void;
648
+ /** Update accent color dynamically */
649
+ setColor(color: string): void;
650
+ /** Update title text */
651
+ setTitle(title: string): void;
652
+ /** Update description text */
653
+ setDescription(desc: string): void;
654
+ /** Update prompt (only takes effect on next start()) */
655
+ setPrompt(prompt: string): void;
656
+ /** Show an error message */
657
+ showError(text: string): void;
658
+ /** Destroy the component, removing all DOM and stopping any active session */
659
+ destroy(): void;
660
+ private startTimer;
661
+ private toggleMute;
662
+ private playConnectingSound;
663
+ private fadeOutConnectingSound;
664
+ private playErrorTone;
665
+ }
666
+
667
+ export { AUDIO_CONFIG, type AnalyserConfig, type AudioManager, type BrowserAudioConfig, BrowserAudioManager, type BrowserAudioOptions, ConversationalPanel, type ConversationalPanelConfig, DEFAULT_URLS, type ErrorCode, type HealthStatus, Language, type LanguageInfo, type LokutorConfig, LokutorError, type ModelInfo, type ServerConfig, type ServerStatus, StreamResampler, type SynthesizeOptions, TTSClient, type ToolCall, type ToolDefinition, type Viseme, VoiceAgentClient, type VoiceAgentOptions, type VoiceInfo, VoiceStyle, applyLowPassFilter, bytesToPcm16, calculateRMS, float32ToPcm16, isRetryable, normalizeAudio, pcm16ToBytes, pcm16ToFloat32, resample, resampleWithAntiAliasing, simpleConversation, simpleTTS };