@hamsa-ai/voice-agents-sdk 0.4.1-beta.0 → 0.4.1-beta.2

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.1-beta.0",
3
+ "version": "0.4.1-beta.2",
4
4
  "description": "Hamsa AI - Voice Agents JavaScript SDK",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
package/types/main.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from 'events';
2
- import type { Room } from 'livekit-client';
2
+ import type { ConnectionState, LocalTrack, LocalTrackPublication, Participant, RemoteParticipant, RemoteTrack, RemoteTrackPublication, Room } from 'livekit-client';
3
3
  import LiveKitManager, { type AudioLevelsResult, type CallAnalyticsResult, type ConnectionStatsResult, type ParticipantData, type PerformanceMetricsResult, type TrackStatsResult } from './classes/livekit-manager';
4
4
  import ScreenWakeLock from './classes/screen-wake-lock';
5
5
  /**
@@ -97,6 +97,93 @@ type JobDetails = {
97
97
  /** Additional job properties that may be returned by the API */
98
98
  [key: string]: unknown;
99
99
  };
100
+ /**
101
+ * Event handler signatures for HamsaVoiceAgent
102
+ *
103
+ * Defines the type-safe interface for all events emitted by the HamsaVoiceAgent.
104
+ * Each event specifies its exact handler signature, enabling full type safety
105
+ * and IntelliSense support when using the event emitter API.
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * // Fully type-safe event handlers
110
+ * agent.on('transcriptionReceived', (text: string) => {
111
+ * console.log('User said:', text);
112
+ * });
113
+ *
114
+ * agent.on('connectionQualityChanged', ({ quality, metrics }) => {
115
+ * if (quality === 'poor') {
116
+ * showNetworkWarning(metrics);
117
+ * }
118
+ * });
119
+ * ```
120
+ */
121
+ type HamsaVoiceAgentEvents = {
122
+ /** Emitted when connection is established (before call fully starts) */
123
+ start: () => void;
124
+ /** Emitted when call is fully started and ready */
125
+ callStarted: () => void;
126
+ /** Emitted when call ends (user or agent initiated) */
127
+ callEnded: () => void;
128
+ /** Emitted when call is paused */
129
+ callPaused: () => void;
130
+ /** Emitted when call is resumed */
131
+ callResumed: () => void;
132
+ /** Emitted when connection is closed */
133
+ closed: () => void;
134
+ /** Emitted when attempting to reconnect */
135
+ reconnecting: () => void;
136
+ /** Emitted when reconnection succeeds */
137
+ reconnected: () => void;
138
+ /** Emitted when user speech is transcribed */
139
+ transcriptionReceived: (text: string) => void;
140
+ /** Emitted when agent response is received */
141
+ answerReceived: (text: string) => void;
142
+ /** Emitted when agent starts speaking */
143
+ speaking: () => void;
144
+ /** Emitted when agent is listening */
145
+ listening: () => void;
146
+ /** Emitted when an error occurs */
147
+ error: (error: Error | HamsaApiError) => void;
148
+ /** Emitted when a remote track is subscribed */
149
+ trackSubscribed: (data: {
150
+ track: RemoteTrack;
151
+ publication: RemoteTrackPublication;
152
+ participant: RemoteParticipant;
153
+ }) => void;
154
+ /** Emitted when a remote track is unsubscribed */
155
+ trackUnsubscribed: (data: {
156
+ track: RemoteTrack;
157
+ publication: RemoteTrackPublication;
158
+ participant: RemoteParticipant;
159
+ }) => void;
160
+ /** Emitted when a local track is published */
161
+ localTrackPublished: (data: {
162
+ track?: LocalTrack;
163
+ publication: LocalTrackPublication;
164
+ }) => void;
165
+ /** Emitted when analytics data is updated */
166
+ analyticsUpdated: (analytics: CallAnalyticsResult) => void;
167
+ /** Emitted when connection quality changes */
168
+ connectionQualityChanged: (data: {
169
+ quality: 'excellent' | 'good' | 'poor';
170
+ metrics: ConnectionStatsResult;
171
+ }) => void;
172
+ /** Emitted when connection state changes */
173
+ connectionStateChanged: (state: ConnectionState) => void;
174
+ /** Emitted when audio playback state changes */
175
+ audioPlaybackChanged: (playing: boolean) => void;
176
+ /** Emitted when a participant connects */
177
+ participantConnected: (participant: RemoteParticipant) => void;
178
+ /** Emitted when a participant disconnects */
179
+ participantDisconnected: (participant: RemoteParticipant) => void;
180
+ /** Emitted when data is received */
181
+ dataReceived: (message: Uint8Array, participant: Participant) => void;
182
+ /** Emitted for custom events */
183
+ customEvent: (eventType: string, eventData: unknown, metadata?: Record<string, unknown>) => void;
184
+ /** Emitted for informational messages */
185
+ info: (info: string) => void;
186
+ };
100
187
  /**
101
188
  * HamsaVoiceAgent - Main SDK class for voice agent integration
102
189
  *
@@ -104,6 +191,9 @@ type JobDetails = {
104
191
  * into web applications. It handles authentication, connection management,
105
192
  * conversation lifecycle, analytics, and client-side tool execution.
106
193
  *
194
+ * Note: This class uses declaration merging with an interface (defined below)
195
+ * to provide type-safe event handlers. This is intentional and safe.
196
+ *
107
197
  * Key features:
108
198
  * - Real-time voice communication with AI agents
109
199
  * - Comprehensive analytics and quality monitoring
@@ -784,5 +874,47 @@ declare class HamsaVoiceAgent extends EventEmitter {
784
874
  */
785
875
  getRoom(): Room | null;
786
876
  }
877
+ /**
878
+ * Declaration merging: Add type-safe event methods to HamsaVoiceAgent
879
+ *
880
+ * This interface merges with the HamsaVoiceAgent class to provide fully
881
+ * typed event handler methods without requiring explicit type assertions.
882
+ *
883
+ * @example
884
+ * ```typescript
885
+ * const agent = new HamsaVoiceAgent('api_key');
886
+ *
887
+ * // ✅ Fully type-safe - no casting needed!
888
+ * agent.on('transcriptionReceived', (text) => {
889
+ * console.log(text); // text is inferred as string
890
+ * });
891
+ *
892
+ * // ❌ Type error - wrong event name
893
+ * agent.on('wrongEvent', () => {});
894
+ *
895
+ * // ❌ Type error - wrong handler signature
896
+ * agent.on('transcriptionReceived', () => {}); // Missing parameter
897
+ * ```
898
+ */
899
+ interface HamsaVoiceAgent {
900
+ /**
901
+ * Registers an event listener with type-safe event names and handlers
902
+ */
903
+ on<K extends keyof HamsaVoiceAgentEvents>(event: K, listener: HamsaVoiceAgentEvents[K]): this;
904
+ /**
905
+ * Removes an event listener with type-safe event names and handlers
906
+ */
907
+ off<K extends keyof HamsaVoiceAgentEvents>(event: K, listener: HamsaVoiceAgentEvents[K]): this;
908
+ /**
909
+ * Registers a one-time event listener with type-safe event names and handlers
910
+ */
911
+ once<K extends keyof HamsaVoiceAgentEvents>(event: K, listener: HamsaVoiceAgentEvents[K]): this;
912
+ /**
913
+ * Emits an event with type-safe event names and arguments
914
+ */
915
+ emit<K extends keyof HamsaVoiceAgentEvents>(event: K, ...args: Parameters<HamsaVoiceAgentEvents[K]>): boolean;
916
+ }
787
917
  export { HamsaVoiceAgent, HamsaApiError };
788
918
  export default HamsaVoiceAgent;
919
+ export type { AudioLevelsResult, CallAnalyticsResult, ConnectionStatsResult, ParticipantData, PerformanceMetricsResult, TrackStatsResult, } from './classes/livekit-manager';
920
+ export type { HamsaVoiceAgentEvents, StartOptions, Tool, JobDetails };