@hamsa-ai/voice-agents-sdk 0.4.3-beta.1 → 0.4.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hamsa-ai/voice-agents-sdk",
3
- "version": "0.4.3-beta.1",
3
+ "version": "0.4.3",
4
4
  "description": "Hamsa AI - Voice Agents JavaScript SDK",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -188,6 +188,8 @@ export declare class LiveKitConnection extends EventEmitter {
188
188
  private reconnectionAttempts;
189
189
  /** Whether we've already emitted a 'connected' event for the current session */
190
190
  private hasEmittedConnected;
191
+ /** Debug logger instance for conditional logging */
192
+ private readonly logger;
191
193
  /**
192
194
  * Creates a new LiveKitConnection instance
193
195
  *
@@ -197,19 +199,21 @@ export declare class LiveKitConnection extends EventEmitter {
197
199
  *
198
200
  * @param lkUrl - LiveKit WebSocket URL (e.g., 'wss://livekit.example.com')
199
201
  * @param accessToken - JWT token for room authentication and authorization
202
+ * @param debug - Enable debug logging (defaults to false)
200
203
  *
201
204
  * @example
202
205
  * ```typescript
203
206
  * const connection = new LiveKitConnection(
204
207
  * 'wss://rtc.eu.tryhamsa.com',
205
- * 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
208
+ * 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
209
+ * false
206
210
  * );
207
211
  *
208
212
  * // Connection is ready for use
209
213
  * await connection.connect();
210
214
  * ```
211
215
  */
212
- constructor(lkUrl: string, accessToken: string);
216
+ constructor(lkUrl: string, accessToken: string, debug?: boolean);
213
217
  /**
214
218
  * Provides access to the underlying LiveKit room instance
215
219
  *
@@ -33,6 +33,7 @@
33
33
  */
34
34
  import { EventEmitter } from 'events';
35
35
  import type { Room } from 'livekit-client';
36
+ import { type DebugLogger } from '../utils';
36
37
  import { LiveKitAnalytics } from './livekit-analytics';
37
38
  import { LiveKitAudioManager } from './livekit-audio-manager';
38
39
  import { LiveKitConnection } from './livekit-connection';
@@ -59,6 +60,8 @@ export default class LiveKitManager extends EventEmitter {
59
60
  lkUrl: string;
60
61
  /** JWT access token for authentication */
61
62
  accessToken: string;
63
+ /** Debug logger instance for conditional logging */
64
+ logger: DebugLogger;
62
65
  /**
63
66
  * Creates a new LiveKitManager instance
64
67
  *
@@ -83,7 +86,7 @@ export default class LiveKitManager extends EventEmitter {
83
86
  * );
84
87
  * ```
85
88
  */
86
- constructor(lkUrl: string, accessToken: string, tools?: Tool[]);
89
+ constructor(lkUrl: string, accessToken: string, tools?: Tool[], debug?: boolean);
87
90
  /**
88
91
  * Establishes connection to the LiveKit room and initializes voice agent communication
89
92
  *
package/types/main.d.ts CHANGED
@@ -21,6 +21,8 @@ type HamsaVoiceAgentConfig = {
21
21
  API_URL?: string;
22
22
  /** LiveKit RTC WebSocket URL. Defaults to 'wss://rtc.eu.tryhamsa.com' */
23
23
  LIVEKIT_URL?: string;
24
+ /** Enable debug logging for troubleshooting. Defaults to false */
25
+ debug?: boolean;
24
26
  };
25
27
  /**
26
28
  * Configuration options for starting a voice agent conversation
@@ -302,8 +304,6 @@ declare class HamsaVoiceAgent extends EventEmitter {
302
304
  private static readonly DEFAULT_OUTPUT_VOLUME;
303
305
  /** Default fallback input volume when not connected */
304
306
  private static readonly DEFAULT_INPUT_VOLUME;
305
- /** Delay in milliseconds before auto-disconnect when agent leaves (allows LiveKit cleanup) */
306
- private static readonly AGENT_DISCONNECT_DELAY_MS;
307
307
  /** Internal LiveKit manager instance for WebRTC communication */
308
308
  liveKitManager: LiveKitManager | null;
309
309
  /** Hamsa API key for authentication */
@@ -312,12 +312,16 @@ declare class HamsaVoiceAgent extends EventEmitter {
312
312
  API_URL: string;
313
313
  /** LiveKit RTC WebSocket URL */
314
314
  LIVEKIT_URL: string;
315
+ /** Enable debug logging for troubleshooting */
316
+ debug: boolean;
315
317
  /** Job ID for tracking conversation completion status */
316
318
  jobId: string | null;
317
319
  /** Screen wake lock manager to prevent device sleep during calls */
318
320
  wakeLockManager: ScreenWakeLock;
319
321
  /** Flag to track if the user initiated the call end to prevent duplicate disconnection logic */
320
322
  private userInitiatedEnd;
323
+ /** Debug logger instance for conditional logging */
324
+ private readonly logger;
321
325
  /**
322
326
  * Creates a new HamsaVoiceAgent instance
323
327
  *
@@ -340,7 +344,7 @@ declare class HamsaVoiceAgent extends EventEmitter {
340
344
  *
341
345
  * @throws {Error} If apiKey is not provided or invalid
342
346
  */
343
- constructor(apiKey: string, { API_URL, LIVEKIT_URL, }?: HamsaVoiceAgentConfig);
347
+ constructor(apiKey: string, { API_URL, LIVEKIT_URL, debug, }?: HamsaVoiceAgentConfig);
344
348
  /**
345
349
  * Adjusts the volume level for voice agent audio playback
346
350
  *
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Debug utility for conditional logging throughout the SDK
3
+ *
4
+ * This utility provides a centralized way to handle debug logging without
5
+ * needing biome-ignore comments for console statements. It only logs when
6
+ * debug mode is enabled.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const logger = createDebugLogger(this.debug);
11
+ * logger.log('Connection established', { source: 'LiveKitConnection' });
12
+ * logger.error('Failed to connect', { source: 'LiveKitConnection', error });
13
+ * ```
14
+ */
15
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error';
16
+ type LogOptions = {
17
+ source?: string;
18
+ level?: LogLevel;
19
+ error?: unknown;
20
+ };
21
+ /**
22
+ * Debug logger interface
23
+ */
24
+ export type DebugLogger = {
25
+ /**
26
+ * Log a debug message (only when debug mode is enabled)
27
+ */
28
+ log: (message: unknown, options?: LogOptions) => void;
29
+ /**
30
+ * Log an info message (only when debug mode is enabled)
31
+ */
32
+ info: (message: unknown, options?: LogOptions) => void;
33
+ /**
34
+ * Log a warning message (only when debug mode is enabled)
35
+ */
36
+ warn: (message: unknown, options?: LogOptions) => void;
37
+ /**
38
+ * Log an error message (always logs, regardless of debug mode)
39
+ */
40
+ error: (message: unknown, options?: LogOptions) => void;
41
+ };
42
+ /**
43
+ * Creates a debug logger instance
44
+ *
45
+ * @param debug - Whether debug mode is enabled
46
+ * @returns A debug logger instance
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const logger = createDebugLogger(true);
51
+ * logger.log('Starting connection', { source: 'LiveKitConnection' });
52
+ * logger.error('Connection failed', { source: 'LiveKitConnection', error });
53
+ * ```
54
+ */
55
+ export declare const createDebugLogger: (debug: boolean) => DebugLogger;
56
+ export {};
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Utility functions for the Voice Agents SDK
3
+ */
4
+ export type { DebugLogger } from './debug';
5
+ export { createDebugLogger } from './debug';