@anganyai/voice-sdk 0.0.6 → 0.0.8

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.cts CHANGED
@@ -1,6 +1,154 @@
1
+ /**
2
+ * Simple event emitter implementation for the SDK
3
+ *
4
+ * Provides a lightweight event system without external dependencies.
5
+ * Supports typed events for better developer experience.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * interface MyEvents {
10
+ * data: [value: string];
11
+ * error: [error: Error];
12
+ * ready: [];
13
+ * }
14
+ *
15
+ * class MyClass extends EventEmitter<MyEvents> {
16
+ * doSomething() {
17
+ * this.emit('data', 'hello');
18
+ * this.emit('error', new Error('oops'));
19
+ * this.emit('ready');
20
+ * }
21
+ * }
22
+ * ```
23
+ */
24
+ declare class EventEmitter<T extends Record<string, unknown[]>> {
25
+ private listeners;
26
+ /**
27
+ * Register an event listener
28
+ *
29
+ * @param event - Event name
30
+ * @param handler - Event handler function
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * emitter.on('data', (value) => {
35
+ * console.log('Received:', value);
36
+ * });
37
+ * ```
38
+ */
39
+ on<K extends keyof T>(event: K, handler: (...args: T[K]) => void): void;
40
+ /**
41
+ * Unregister an event listener
42
+ *
43
+ * @param event - Event name
44
+ * @param handler - Event handler function to remove
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const handler = (value) => console.log(value);
49
+ * emitter.on('data', handler);
50
+ * emitter.off('data', handler);
51
+ * ```
52
+ */
53
+ off<K extends keyof T>(event: K, handler: (...args: T[K]) => void): void;
54
+ /**
55
+ * Register a one-time event listener
56
+ *
57
+ * The handler will be automatically removed after the first call.
58
+ *
59
+ * @param event - Event name
60
+ * @param handler - Event handler function
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * emitter.once('ready', () => {
65
+ * console.log('Ready! This will only fire once');
66
+ * });
67
+ * ```
68
+ */
69
+ once<K extends keyof T>(event: K, handler: (...args: T[K]) => void): void;
70
+ /**
71
+ * Emit an event
72
+ *
73
+ * Calls all registered handlers for the event in the order they were registered.
74
+ *
75
+ * @param event - Event name
76
+ * @param args - Arguments to pass to event handlers
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * emitter.emit('data', 'hello world');
81
+ * emitter.emit('error', new Error('Something went wrong'));
82
+ * ```
83
+ */
84
+ emit<K extends keyof T>(event: K, ...args: T[K]): void;
85
+ /**
86
+ * Remove all listeners for an event or all events
87
+ *
88
+ * @param event - Event name (optional). If not provided, removes all listeners.
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * // Remove all listeners for 'data' event
93
+ * emitter.removeAllListeners('data');
94
+ *
95
+ * // Remove all listeners for all events
96
+ * emitter.removeAllListeners();
97
+ * ```
98
+ */
99
+ removeAllListeners(event?: keyof T): void;
100
+ /**
101
+ * Get the number of listeners for an event
102
+ *
103
+ * @param event - Event name
104
+ * @returns Number of registered listeners
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const count = emitter.listenerCount('data');
109
+ * console.log(`There are ${count} data listeners`);
110
+ * ```
111
+ */
112
+ listenerCount(event: keyof T): number;
113
+ /**
114
+ * Get all event names that have listeners
115
+ *
116
+ * @returns Array of event names
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * const events = emitter.eventNames();
121
+ * console.log('Active events:', events);
122
+ * ```
123
+ */
124
+ eventNames(): (keyof T)[];
125
+ }
126
+
127
+ /**
128
+ * Service for handling SSE transcription streaming
129
+ * Supports both Web Streams API (browser) and EventSource (React Native)
130
+ */
131
+
132
+ /**
133
+ * EventSource-like interface for React Native SSE libraries
134
+ */
135
+ interface EventSourceLike {
136
+ addEventListener(type: string, listener: (event: any) => void): void;
137
+ removeAllEventListeners(): void;
138
+ close(): void;
139
+ }
140
+ /**
141
+ * Factory function to create EventSource instances
142
+ * Used for React Native where native EventSource doesn't support headers
143
+ */
144
+ type EventSourceFactory = (url: string, options: {
145
+ headers: Record<string, string>;
146
+ }) => EventSourceLike;
147
+
1
148
  /**
2
149
  * Core type definitions for Angany Voice SDK
3
150
  */
151
+
4
152
  /**
5
153
  * SDK configuration options
6
154
  */
@@ -59,6 +207,12 @@ interface VoiceConfig {
59
207
  * Platform-specific configuration
60
208
  */
61
209
  platform?: PlatformConfig;
210
+ /**
211
+ * EventSource factory for React Native environments
212
+ * When provided, uses EventSource instead of fetch streams for SSE
213
+ * Required for React Native as it doesn't support Web Streams API
214
+ */
215
+ eventSourceFactory?: EventSourceFactory;
62
216
  }
63
217
  /**
64
218
  * Log levels
@@ -203,132 +357,6 @@ interface ResourceConfig {
203
357
  custom?: Record<string, unknown>;
204
358
  }
205
359
 
206
- /**
207
- * Simple event emitter implementation for the SDK
208
- *
209
- * Provides a lightweight event system without external dependencies.
210
- * Supports typed events for better developer experience.
211
- *
212
- * @example
213
- * ```typescript
214
- * interface MyEvents {
215
- * data: [value: string];
216
- * error: [error: Error];
217
- * ready: [];
218
- * }
219
- *
220
- * class MyClass extends EventEmitter<MyEvents> {
221
- * doSomething() {
222
- * this.emit('data', 'hello');
223
- * this.emit('error', new Error('oops'));
224
- * this.emit('ready');
225
- * }
226
- * }
227
- * ```
228
- */
229
- declare class EventEmitter<T extends Record<string, unknown[]>> {
230
- private listeners;
231
- /**
232
- * Register an event listener
233
- *
234
- * @param event - Event name
235
- * @param handler - Event handler function
236
- *
237
- * @example
238
- * ```typescript
239
- * emitter.on('data', (value) => {
240
- * console.log('Received:', value);
241
- * });
242
- * ```
243
- */
244
- on<K extends keyof T>(event: K, handler: (...args: T[K]) => void): void;
245
- /**
246
- * Unregister an event listener
247
- *
248
- * @param event - Event name
249
- * @param handler - Event handler function to remove
250
- *
251
- * @example
252
- * ```typescript
253
- * const handler = (value) => console.log(value);
254
- * emitter.on('data', handler);
255
- * emitter.off('data', handler);
256
- * ```
257
- */
258
- off<K extends keyof T>(event: K, handler: (...args: T[K]) => void): void;
259
- /**
260
- * Register a one-time event listener
261
- *
262
- * The handler will be automatically removed after the first call.
263
- *
264
- * @param event - Event name
265
- * @param handler - Event handler function
266
- *
267
- * @example
268
- * ```typescript
269
- * emitter.once('ready', () => {
270
- * console.log('Ready! This will only fire once');
271
- * });
272
- * ```
273
- */
274
- once<K extends keyof T>(event: K, handler: (...args: T[K]) => void): void;
275
- /**
276
- * Emit an event
277
- *
278
- * Calls all registered handlers for the event in the order they were registered.
279
- *
280
- * @param event - Event name
281
- * @param args - Arguments to pass to event handlers
282
- *
283
- * @example
284
- * ```typescript
285
- * emitter.emit('data', 'hello world');
286
- * emitter.emit('error', new Error('Something went wrong'));
287
- * ```
288
- */
289
- emit<K extends keyof T>(event: K, ...args: T[K]): void;
290
- /**
291
- * Remove all listeners for an event or all events
292
- *
293
- * @param event - Event name (optional). If not provided, removes all listeners.
294
- *
295
- * @example
296
- * ```typescript
297
- * // Remove all listeners for 'data' event
298
- * emitter.removeAllListeners('data');
299
- *
300
- * // Remove all listeners for all events
301
- * emitter.removeAllListeners();
302
- * ```
303
- */
304
- removeAllListeners(event?: keyof T): void;
305
- /**
306
- * Get the number of listeners for an event
307
- *
308
- * @param event - Event name
309
- * @returns Number of registered listeners
310
- *
311
- * @example
312
- * ```typescript
313
- * const count = emitter.listenerCount('data');
314
- * console.log(`There are ${count} data listeners`);
315
- * ```
316
- */
317
- listenerCount(event: keyof T): number;
318
- /**
319
- * Get all event names that have listeners
320
- *
321
- * @returns Array of event names
322
- *
323
- * @example
324
- * ```typescript
325
- * const events = emitter.eventNames();
326
- * console.log('Active events:', events);
327
- * ```
328
- */
329
- eventNames(): (keyof T)[];
330
- }
331
-
332
360
  /**
333
361
  * Authentication type definitions for Angany Voice SDK
334
362
  */
@@ -1355,6 +1383,11 @@ declare class Conversation extends EventEmitter<ConversationEvents> {
1355
1383
  private ephemeralCredentials?;
1356
1384
  private accessToken?;
1357
1385
  constructor(id: string, options: ConversationOptions, authManager: AuthManager, urls: ConversationUrls);
1386
+ /**
1387
+ * Set EventSource factory for React Native environments
1388
+ * Call this before initialize() to use EventSource instead of fetch streams for SSE
1389
+ */
1390
+ setEventSourceFactory(factory: EventSourceFactory): void;
1358
1391
  /**
1359
1392
  * Initialize and start the conversation
1360
1393
  */
@@ -1774,4 +1807,4 @@ declare function hasErrorCode(error: unknown, code: string): boolean;
1774
1807
  */
1775
1808
  declare const VERSION = "0.0.2";
1776
1809
 
1777
- export { AnganyError, AnganyVoice, type AuthError, type AuthEvents, AuthManager, type AuthOptions, type AuthState, type AuthStatus, AuthenticationError, type BackendAuthOptions, type ClientCredentials, ConfigurationError, Conversation, ConversationError, type ConversationOptions, type ConversationState, type ConversationStatus, type ConversationUrls, ErrorCodes, EventEmitter, type FrontendAuthOptions, type LogLevel, MediaError, NetworkError, PermissionError, ResourceError, type ServiceAccountAuthOptions, type ServiceAccountCredentials, type SpeakOptions, type TokenSet, type TranscriptionEvent, type UserInfo, VERSION, ValidationError, type VoiceConfig, type VoiceResource, hasErrorCode, isAnganyError };
1810
+ export { AnganyError, AnganyVoice, type AuthError, type AuthEvents, AuthManager, type AuthOptions, type AuthState, type AuthStatus, AuthenticationError, type BackendAuthOptions, type ClientCredentials, ConfigurationError, Conversation, ConversationError, type ConversationOptions, type ConversationState, type ConversationStatus, type ConversationUrls, ErrorCodes, EventEmitter, type EventSourceFactory, type EventSourceLike, type FrontendAuthOptions, type LogLevel, MediaError, NetworkError, PermissionError, ResourceError, type ServiceAccountAuthOptions, type ServiceAccountCredentials, type SpeakOptions, type TokenSet, type TranscriptionEvent, type UserInfo, VERSION, ValidationError, type VoiceConfig, type VoiceResource, hasErrorCode, isAnganyError };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,154 @@
1
+ /**
2
+ * Simple event emitter implementation for the SDK
3
+ *
4
+ * Provides a lightweight event system without external dependencies.
5
+ * Supports typed events for better developer experience.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * interface MyEvents {
10
+ * data: [value: string];
11
+ * error: [error: Error];
12
+ * ready: [];
13
+ * }
14
+ *
15
+ * class MyClass extends EventEmitter<MyEvents> {
16
+ * doSomething() {
17
+ * this.emit('data', 'hello');
18
+ * this.emit('error', new Error('oops'));
19
+ * this.emit('ready');
20
+ * }
21
+ * }
22
+ * ```
23
+ */
24
+ declare class EventEmitter<T extends Record<string, unknown[]>> {
25
+ private listeners;
26
+ /**
27
+ * Register an event listener
28
+ *
29
+ * @param event - Event name
30
+ * @param handler - Event handler function
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * emitter.on('data', (value) => {
35
+ * console.log('Received:', value);
36
+ * });
37
+ * ```
38
+ */
39
+ on<K extends keyof T>(event: K, handler: (...args: T[K]) => void): void;
40
+ /**
41
+ * Unregister an event listener
42
+ *
43
+ * @param event - Event name
44
+ * @param handler - Event handler function to remove
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const handler = (value) => console.log(value);
49
+ * emitter.on('data', handler);
50
+ * emitter.off('data', handler);
51
+ * ```
52
+ */
53
+ off<K extends keyof T>(event: K, handler: (...args: T[K]) => void): void;
54
+ /**
55
+ * Register a one-time event listener
56
+ *
57
+ * The handler will be automatically removed after the first call.
58
+ *
59
+ * @param event - Event name
60
+ * @param handler - Event handler function
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * emitter.once('ready', () => {
65
+ * console.log('Ready! This will only fire once');
66
+ * });
67
+ * ```
68
+ */
69
+ once<K extends keyof T>(event: K, handler: (...args: T[K]) => void): void;
70
+ /**
71
+ * Emit an event
72
+ *
73
+ * Calls all registered handlers for the event in the order they were registered.
74
+ *
75
+ * @param event - Event name
76
+ * @param args - Arguments to pass to event handlers
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * emitter.emit('data', 'hello world');
81
+ * emitter.emit('error', new Error('Something went wrong'));
82
+ * ```
83
+ */
84
+ emit<K extends keyof T>(event: K, ...args: T[K]): void;
85
+ /**
86
+ * Remove all listeners for an event or all events
87
+ *
88
+ * @param event - Event name (optional). If not provided, removes all listeners.
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * // Remove all listeners for 'data' event
93
+ * emitter.removeAllListeners('data');
94
+ *
95
+ * // Remove all listeners for all events
96
+ * emitter.removeAllListeners();
97
+ * ```
98
+ */
99
+ removeAllListeners(event?: keyof T): void;
100
+ /**
101
+ * Get the number of listeners for an event
102
+ *
103
+ * @param event - Event name
104
+ * @returns Number of registered listeners
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const count = emitter.listenerCount('data');
109
+ * console.log(`There are ${count} data listeners`);
110
+ * ```
111
+ */
112
+ listenerCount(event: keyof T): number;
113
+ /**
114
+ * Get all event names that have listeners
115
+ *
116
+ * @returns Array of event names
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * const events = emitter.eventNames();
121
+ * console.log('Active events:', events);
122
+ * ```
123
+ */
124
+ eventNames(): (keyof T)[];
125
+ }
126
+
127
+ /**
128
+ * Service for handling SSE transcription streaming
129
+ * Supports both Web Streams API (browser) and EventSource (React Native)
130
+ */
131
+
132
+ /**
133
+ * EventSource-like interface for React Native SSE libraries
134
+ */
135
+ interface EventSourceLike {
136
+ addEventListener(type: string, listener: (event: any) => void): void;
137
+ removeAllEventListeners(): void;
138
+ close(): void;
139
+ }
140
+ /**
141
+ * Factory function to create EventSource instances
142
+ * Used for React Native where native EventSource doesn't support headers
143
+ */
144
+ type EventSourceFactory = (url: string, options: {
145
+ headers: Record<string, string>;
146
+ }) => EventSourceLike;
147
+
1
148
  /**
2
149
  * Core type definitions for Angany Voice SDK
3
150
  */
151
+
4
152
  /**
5
153
  * SDK configuration options
6
154
  */
@@ -59,6 +207,12 @@ interface VoiceConfig {
59
207
  * Platform-specific configuration
60
208
  */
61
209
  platform?: PlatformConfig;
210
+ /**
211
+ * EventSource factory for React Native environments
212
+ * When provided, uses EventSource instead of fetch streams for SSE
213
+ * Required for React Native as it doesn't support Web Streams API
214
+ */
215
+ eventSourceFactory?: EventSourceFactory;
62
216
  }
63
217
  /**
64
218
  * Log levels
@@ -203,132 +357,6 @@ interface ResourceConfig {
203
357
  custom?: Record<string, unknown>;
204
358
  }
205
359
 
206
- /**
207
- * Simple event emitter implementation for the SDK
208
- *
209
- * Provides a lightweight event system without external dependencies.
210
- * Supports typed events for better developer experience.
211
- *
212
- * @example
213
- * ```typescript
214
- * interface MyEvents {
215
- * data: [value: string];
216
- * error: [error: Error];
217
- * ready: [];
218
- * }
219
- *
220
- * class MyClass extends EventEmitter<MyEvents> {
221
- * doSomething() {
222
- * this.emit('data', 'hello');
223
- * this.emit('error', new Error('oops'));
224
- * this.emit('ready');
225
- * }
226
- * }
227
- * ```
228
- */
229
- declare class EventEmitter<T extends Record<string, unknown[]>> {
230
- private listeners;
231
- /**
232
- * Register an event listener
233
- *
234
- * @param event - Event name
235
- * @param handler - Event handler function
236
- *
237
- * @example
238
- * ```typescript
239
- * emitter.on('data', (value) => {
240
- * console.log('Received:', value);
241
- * });
242
- * ```
243
- */
244
- on<K extends keyof T>(event: K, handler: (...args: T[K]) => void): void;
245
- /**
246
- * Unregister an event listener
247
- *
248
- * @param event - Event name
249
- * @param handler - Event handler function to remove
250
- *
251
- * @example
252
- * ```typescript
253
- * const handler = (value) => console.log(value);
254
- * emitter.on('data', handler);
255
- * emitter.off('data', handler);
256
- * ```
257
- */
258
- off<K extends keyof T>(event: K, handler: (...args: T[K]) => void): void;
259
- /**
260
- * Register a one-time event listener
261
- *
262
- * The handler will be automatically removed after the first call.
263
- *
264
- * @param event - Event name
265
- * @param handler - Event handler function
266
- *
267
- * @example
268
- * ```typescript
269
- * emitter.once('ready', () => {
270
- * console.log('Ready! This will only fire once');
271
- * });
272
- * ```
273
- */
274
- once<K extends keyof T>(event: K, handler: (...args: T[K]) => void): void;
275
- /**
276
- * Emit an event
277
- *
278
- * Calls all registered handlers for the event in the order they were registered.
279
- *
280
- * @param event - Event name
281
- * @param args - Arguments to pass to event handlers
282
- *
283
- * @example
284
- * ```typescript
285
- * emitter.emit('data', 'hello world');
286
- * emitter.emit('error', new Error('Something went wrong'));
287
- * ```
288
- */
289
- emit<K extends keyof T>(event: K, ...args: T[K]): void;
290
- /**
291
- * Remove all listeners for an event or all events
292
- *
293
- * @param event - Event name (optional). If not provided, removes all listeners.
294
- *
295
- * @example
296
- * ```typescript
297
- * // Remove all listeners for 'data' event
298
- * emitter.removeAllListeners('data');
299
- *
300
- * // Remove all listeners for all events
301
- * emitter.removeAllListeners();
302
- * ```
303
- */
304
- removeAllListeners(event?: keyof T): void;
305
- /**
306
- * Get the number of listeners for an event
307
- *
308
- * @param event - Event name
309
- * @returns Number of registered listeners
310
- *
311
- * @example
312
- * ```typescript
313
- * const count = emitter.listenerCount('data');
314
- * console.log(`There are ${count} data listeners`);
315
- * ```
316
- */
317
- listenerCount(event: keyof T): number;
318
- /**
319
- * Get all event names that have listeners
320
- *
321
- * @returns Array of event names
322
- *
323
- * @example
324
- * ```typescript
325
- * const events = emitter.eventNames();
326
- * console.log('Active events:', events);
327
- * ```
328
- */
329
- eventNames(): (keyof T)[];
330
- }
331
-
332
360
  /**
333
361
  * Authentication type definitions for Angany Voice SDK
334
362
  */
@@ -1355,6 +1383,11 @@ declare class Conversation extends EventEmitter<ConversationEvents> {
1355
1383
  private ephemeralCredentials?;
1356
1384
  private accessToken?;
1357
1385
  constructor(id: string, options: ConversationOptions, authManager: AuthManager, urls: ConversationUrls);
1386
+ /**
1387
+ * Set EventSource factory for React Native environments
1388
+ * Call this before initialize() to use EventSource instead of fetch streams for SSE
1389
+ */
1390
+ setEventSourceFactory(factory: EventSourceFactory): void;
1358
1391
  /**
1359
1392
  * Initialize and start the conversation
1360
1393
  */
@@ -1774,4 +1807,4 @@ declare function hasErrorCode(error: unknown, code: string): boolean;
1774
1807
  */
1775
1808
  declare const VERSION = "0.0.2";
1776
1809
 
1777
- export { AnganyError, AnganyVoice, type AuthError, type AuthEvents, AuthManager, type AuthOptions, type AuthState, type AuthStatus, AuthenticationError, type BackendAuthOptions, type ClientCredentials, ConfigurationError, Conversation, ConversationError, type ConversationOptions, type ConversationState, type ConversationStatus, type ConversationUrls, ErrorCodes, EventEmitter, type FrontendAuthOptions, type LogLevel, MediaError, NetworkError, PermissionError, ResourceError, type ServiceAccountAuthOptions, type ServiceAccountCredentials, type SpeakOptions, type TokenSet, type TranscriptionEvent, type UserInfo, VERSION, ValidationError, type VoiceConfig, type VoiceResource, hasErrorCode, isAnganyError };
1810
+ export { AnganyError, AnganyVoice, type AuthError, type AuthEvents, AuthManager, type AuthOptions, type AuthState, type AuthStatus, AuthenticationError, type BackendAuthOptions, type ClientCredentials, ConfigurationError, Conversation, ConversationError, type ConversationOptions, type ConversationState, type ConversationStatus, type ConversationUrls, ErrorCodes, EventEmitter, type EventSourceFactory, type EventSourceLike, type FrontendAuthOptions, type LogLevel, MediaError, NetworkError, PermissionError, ResourceError, type ServiceAccountAuthOptions, type ServiceAccountCredentials, type SpeakOptions, type TokenSet, type TranscriptionEvent, type UserInfo, VERSION, ValidationError, type VoiceConfig, type VoiceResource, hasErrorCode, isAnganyError };