@hamsa-ai/voice-agents-sdk 0.3.1 → 0.4.0-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/README.md +599 -19
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -0
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -0
- package/package.json +31 -14
- package/types/classes/livekit-analytics.d.ts +370 -0
- package/types/classes/livekit-audio-manager.d.ts +738 -0
- package/types/classes/livekit-connection.d.ts +318 -0
- package/types/classes/livekit-manager.d.ts +527 -0
- package/types/classes/livekit-tool-registry.d.ts +607 -0
- package/types/classes/{screen_wake_lock.d.ts → screen-wake-lock.d.ts} +4 -4
- package/types/classes/types.d.ts +325 -0
- package/types/main.d.ts +691 -32
- package/dist/index.cjs.js.LICENSE.txt +0 -8
- package/dist/index.esm.js.LICENSE.txt +0 -8
- package/dist/index.umd.js.LICENSE.txt +0 -8
- package/types/classes/audio-player-processor.worklet.d.ts +0 -8
- package/types/classes/audio-processor.worklet.d.ts +0 -4
- package/types/classes/audio_player.d.ts +0 -67
- package/types/classes/audio_recorder.d.ts +0 -37
- package/types/classes/websocket_manager.d.ts +0 -115
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types and interfaces for LiveKit modules
|
|
3
|
+
*/
|
|
4
|
+
import type { ConnectionQuality, RemoteTrack, RemoteTrackPublication } from 'livekit-client';
|
|
5
|
+
/**
|
|
6
|
+
* Function signature for client-side tools that can be executed by the agent.
|
|
7
|
+
* Tools can be synchronous or asynchronous and accept variable arguments.
|
|
8
|
+
*/
|
|
9
|
+
export type ToolFunction = (...args: unknown[]) => unknown | Promise<unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* Definition for a client-side tool that can be registered with the voice agent.
|
|
12
|
+
* These tools are made available to the agent as RPC methods during conversations.
|
|
13
|
+
*/
|
|
14
|
+
export type Tool = {
|
|
15
|
+
/** The name of the function that the agent can call */
|
|
16
|
+
function_name: string;
|
|
17
|
+
/** The implementation function to execute when the agent calls this tool */
|
|
18
|
+
fn?: ToolFunction;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Represents an audio level measurement at a specific point in time.
|
|
22
|
+
* Used for tracking audio activity and volume levels during calls.
|
|
23
|
+
*/
|
|
24
|
+
export type AudioLevel = {
|
|
25
|
+
/** Unix timestamp when the audio level was measured */
|
|
26
|
+
timestamp: number;
|
|
27
|
+
/** Audio level value (typically 0.0 to 1.0) */
|
|
28
|
+
level: number;
|
|
29
|
+
/** Optional identifier of the participant this audio level belongs to */
|
|
30
|
+
participant?: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Information about a participant in the voice conversation.
|
|
34
|
+
* Contains connection details and metadata for analytics and monitoring.
|
|
35
|
+
*/
|
|
36
|
+
export type ParticipantData = {
|
|
37
|
+
/** Unique identity of the participant (e.g., 'agent', 'user') */
|
|
38
|
+
identity: string;
|
|
39
|
+
/** Session ID assigned by LiveKit for this participant */
|
|
40
|
+
sid: string;
|
|
41
|
+
/** Unix timestamp when the participant connected */
|
|
42
|
+
connectionTime: number;
|
|
43
|
+
/** Optional metadata associated with the participant */
|
|
44
|
+
metadata?: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Statistics and metadata for a media track (audio/video stream).
|
|
48
|
+
* Tracks the lifecycle and details of each media stream in the conversation.
|
|
49
|
+
*/
|
|
50
|
+
export type TrackStatsData = {
|
|
51
|
+
/** Unique identifier for this track */
|
|
52
|
+
trackId: string;
|
|
53
|
+
/** Type of track (e.g., 'audio', 'video') */
|
|
54
|
+
kind: string;
|
|
55
|
+
/** Identity of the participant who owns this track */
|
|
56
|
+
participant: string;
|
|
57
|
+
/** Unix timestamp when this track was subscribed to */
|
|
58
|
+
subscriptionTime: number;
|
|
59
|
+
/** LiveKit track publication object containing track details */
|
|
60
|
+
publication: RemoteTrackPublication;
|
|
61
|
+
/** Track source (microphone, screen_share, etc.) */
|
|
62
|
+
source?: string;
|
|
63
|
+
/** Whether the track is currently muted */
|
|
64
|
+
muted?: boolean;
|
|
65
|
+
/** Whether the track is enabled */
|
|
66
|
+
enabled?: boolean;
|
|
67
|
+
/** Track dimensions for video tracks */
|
|
68
|
+
dimensions?: {
|
|
69
|
+
width: number;
|
|
70
|
+
height: number;
|
|
71
|
+
};
|
|
72
|
+
/** Whether the track uses simulcast */
|
|
73
|
+
simulcasted?: boolean;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Comprehensive call statistics for monitoring connection health and usage.
|
|
77
|
+
* Tracks network metrics, participant counts, and overall call quality.
|
|
78
|
+
*/
|
|
79
|
+
export type CallStats = {
|
|
80
|
+
/** Number of connection attempts made during this session */
|
|
81
|
+
connectionAttempts: number;
|
|
82
|
+
/** Number of reconnection attempts due to network issues */
|
|
83
|
+
reconnectionAttempts: number;
|
|
84
|
+
/** Total bytes received during the call */
|
|
85
|
+
totalBytesReceived: number;
|
|
86
|
+
/** Total bytes sent during the call */
|
|
87
|
+
totalBytesSent: number;
|
|
88
|
+
/** Number of network packets lost */
|
|
89
|
+
packetsLost: number;
|
|
90
|
+
/** Current number of participants in the conversation */
|
|
91
|
+
participantCount: number;
|
|
92
|
+
/** Current number of active media tracks */
|
|
93
|
+
trackCount: number;
|
|
94
|
+
/** Historical audio level measurements */
|
|
95
|
+
audioLevels: AudioLevel[];
|
|
96
|
+
/** Current overall connection quality assessment */
|
|
97
|
+
connectionQuality: string;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Real-time network connection quality metrics.
|
|
101
|
+
* Provides detailed information about network performance and reliability.
|
|
102
|
+
*/
|
|
103
|
+
export type ConnectionMetrics = {
|
|
104
|
+
/** Current network latency in milliseconds */
|
|
105
|
+
latency: number;
|
|
106
|
+
/** Packet loss percentage (0.0 to 100.0) */
|
|
107
|
+
packetLoss: number;
|
|
108
|
+
/** Current bandwidth usage in bytes per second */
|
|
109
|
+
bandwidth: number;
|
|
110
|
+
/** Qualitative assessment of connection ('excellent', 'good', 'poor', 'lost') */
|
|
111
|
+
quality: string;
|
|
112
|
+
/** Network jitter measurement in milliseconds */
|
|
113
|
+
jitter: number;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Audio quality and usage metrics for both user and agent.
|
|
117
|
+
* Tracks speaking patterns, audio levels, and quality indicators.
|
|
118
|
+
*/
|
|
119
|
+
export type AudioMetrics = {
|
|
120
|
+
/** Current audio input level from the user (0.0 to 1.0) */
|
|
121
|
+
userAudioLevel: number;
|
|
122
|
+
/** Current audio output level from the agent (0.0 to 1.0) */
|
|
123
|
+
agentAudioLevel: number;
|
|
124
|
+
/** Total time in milliseconds the user has been speaking */
|
|
125
|
+
userSpeakingTime: number;
|
|
126
|
+
/** Total time in milliseconds the agent has been speaking */
|
|
127
|
+
agentSpeakingTime: number;
|
|
128
|
+
/** Number of audio interruptions or dropouts detected */
|
|
129
|
+
audioDropouts: number;
|
|
130
|
+
/** Whether echo cancellation is currently active */
|
|
131
|
+
echoCancellationActive: boolean;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Performance metrics tracking response times and connection reliability.
|
|
135
|
+
* Measures various aspects of system and network performance.
|
|
136
|
+
*/
|
|
137
|
+
export type PerformanceMetrics = {
|
|
138
|
+
/** Total response time for agent interactions in milliseconds */
|
|
139
|
+
responseTime: number;
|
|
140
|
+
/** Current network latency measurement in milliseconds */
|
|
141
|
+
networkLatency: number;
|
|
142
|
+
/** Time taken to establish the initial connection in milliseconds */
|
|
143
|
+
connectionEstablishedTime: number;
|
|
144
|
+
/** Total number of reconnections that have occurred */
|
|
145
|
+
reconnectionCount: number;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Complete connection statistics result returned by getConnectionStats().
|
|
149
|
+
* Combines real-time metrics with historical connection data.
|
|
150
|
+
*/
|
|
151
|
+
export type ConnectionStatsResult = {
|
|
152
|
+
/** Current network latency in milliseconds */
|
|
153
|
+
latency: number;
|
|
154
|
+
/** Current packet loss percentage */
|
|
155
|
+
packetLoss: number;
|
|
156
|
+
/** Current bandwidth usage in bytes per second */
|
|
157
|
+
bandwidth: number;
|
|
158
|
+
/** Current connection quality assessment */
|
|
159
|
+
quality: string;
|
|
160
|
+
/** Current network jitter in milliseconds */
|
|
161
|
+
jitter: number;
|
|
162
|
+
/** Total connection attempts made */
|
|
163
|
+
connectionAttempts: number;
|
|
164
|
+
/** Total reconnection attempts made */
|
|
165
|
+
reconnectionAttempts: number;
|
|
166
|
+
/** Time taken to establish connection in milliseconds */
|
|
167
|
+
connectionEstablishedTime: number;
|
|
168
|
+
/** Whether currently connected to the voice agent */
|
|
169
|
+
isConnected: boolean;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Complete audio metrics result returned by getAudioLevels().
|
|
173
|
+
* Provides comprehensive audio quality and usage information.
|
|
174
|
+
*/
|
|
175
|
+
export type AudioLevelsResult = {
|
|
176
|
+
/** User's audio input level (0.0 to 1.0) */
|
|
177
|
+
userAudioLevel: number;
|
|
178
|
+
/** Agent's audio output level (0.0 to 1.0) */
|
|
179
|
+
agentAudioLevel: number;
|
|
180
|
+
/** Total user speaking time in milliseconds */
|
|
181
|
+
userSpeakingTime: number;
|
|
182
|
+
/** Total agent speaking time in milliseconds */
|
|
183
|
+
agentSpeakingTime: number;
|
|
184
|
+
/** Number of audio dropouts detected */
|
|
185
|
+
audioDropouts: number;
|
|
186
|
+
/** Whether echo cancellation is active */
|
|
187
|
+
echoCancellationActive: boolean;
|
|
188
|
+
/** Current real-time user audio level */
|
|
189
|
+
currentUserLevel: number;
|
|
190
|
+
/** Current real-time agent audio level */
|
|
191
|
+
currentAgentLevel: number;
|
|
192
|
+
/** Whether audio is currently paused */
|
|
193
|
+
isPaused?: boolean;
|
|
194
|
+
/** Current volume level */
|
|
195
|
+
volume?: number;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Complete performance metrics result returned by getPerformanceMetrics().
|
|
199
|
+
* Provides comprehensive system and network performance data.
|
|
200
|
+
*/
|
|
201
|
+
export type PerformanceMetricsResult = {
|
|
202
|
+
/** Total response time in milliseconds */
|
|
203
|
+
responseTime: number;
|
|
204
|
+
/** Current network latency in milliseconds */
|
|
205
|
+
networkLatency: number;
|
|
206
|
+
/** Connection establishment time in milliseconds */
|
|
207
|
+
connectionEstablishedTime: number;
|
|
208
|
+
/** Total reconnection count */
|
|
209
|
+
reconnectionCount: number;
|
|
210
|
+
/** Total call duration in milliseconds */
|
|
211
|
+
callDuration: number;
|
|
212
|
+
/** Average response time in milliseconds */
|
|
213
|
+
averageResponseTime: number;
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Complete track statistics result returned by getTrackStats().
|
|
217
|
+
* Provides comprehensive track information and analytics.
|
|
218
|
+
*/
|
|
219
|
+
export type TrackStatsResult = {
|
|
220
|
+
/** Total number of tracks ever created */
|
|
221
|
+
totalTracks: number;
|
|
222
|
+
/** Current number of active tracks */
|
|
223
|
+
activeTracks: number;
|
|
224
|
+
/** Number of audio elements currently active */
|
|
225
|
+
audioElements: number;
|
|
226
|
+
/** Detailed track statistics as [trackId, trackData] pairs */
|
|
227
|
+
trackDetails: [string, TrackStatsData][];
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* Complete analytics result returned by getCallAnalytics().
|
|
231
|
+
* Combines all analytics data into a comprehensive report.
|
|
232
|
+
*/
|
|
233
|
+
export type CallAnalyticsResult = {
|
|
234
|
+
/** Connection statistics and quality metrics */
|
|
235
|
+
connectionStats: ConnectionStatsResult;
|
|
236
|
+
/** Audio quality and usage metrics */
|
|
237
|
+
audioMetrics: AudioLevelsResult;
|
|
238
|
+
/** Performance metrics and timings */
|
|
239
|
+
performanceMetrics: PerformanceMetricsResult;
|
|
240
|
+
/** Current participant information */
|
|
241
|
+
participants: ParticipantData[];
|
|
242
|
+
/** Track statistics and details */
|
|
243
|
+
trackStats: TrackStatsResult;
|
|
244
|
+
/** Raw call statistics */
|
|
245
|
+
callStats: CallStats;
|
|
246
|
+
/** Additional metadata */
|
|
247
|
+
metadata: {
|
|
248
|
+
/** Call start time */
|
|
249
|
+
callStartTime: number | null;
|
|
250
|
+
/** Whether currently connected */
|
|
251
|
+
isConnected: boolean;
|
|
252
|
+
/** Whether call is paused */
|
|
253
|
+
isPaused: boolean;
|
|
254
|
+
/** Current volume level */
|
|
255
|
+
volume: number;
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* Data structure for connection quality change events.
|
|
260
|
+
* Provides detailed information about network conditions and performance.
|
|
261
|
+
*/
|
|
262
|
+
export type ConnectionQualityData = {
|
|
263
|
+
/** Current connection quality level */
|
|
264
|
+
quality: ConnectionQuality;
|
|
265
|
+
/** Identity of the participant this quality measurement applies to */
|
|
266
|
+
participant: string;
|
|
267
|
+
/** Detailed connection metrics including latency, packet loss, etc. */
|
|
268
|
+
metrics: {
|
|
269
|
+
latency: number;
|
|
270
|
+
packetLoss: number;
|
|
271
|
+
quality: string;
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* Data structure for track subscription events.
|
|
276
|
+
* Contains information about newly available audio/video streams.
|
|
277
|
+
*/
|
|
278
|
+
export type TrackSubscriptionData = {
|
|
279
|
+
/** The LiveKit track object that was subscribed to */
|
|
280
|
+
track: RemoteTrack;
|
|
281
|
+
/** The track publication containing metadata */
|
|
282
|
+
publication: RemoteTrackPublication;
|
|
283
|
+
/** Identity of the participant who owns this track */
|
|
284
|
+
participant: string;
|
|
285
|
+
/** Optional statistics about this track subscription */
|
|
286
|
+
trackStats?: TrackStatsData;
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Data structure for track unsubscription events.
|
|
290
|
+
* Contains information about audio/video streams that are no longer available.
|
|
291
|
+
*/
|
|
292
|
+
export type TrackUnsubscriptionData = {
|
|
293
|
+
/** The LiveKit track object that was unsubscribed from */
|
|
294
|
+
track: RemoteTrack;
|
|
295
|
+
/** The track publication that was removed */
|
|
296
|
+
publication: RemoteTrackPublication;
|
|
297
|
+
/** Identity of the participant who owned this track */
|
|
298
|
+
participant: string;
|
|
299
|
+
};
|
|
300
|
+
/** Minimal WebAudio types (kept lightweight for cross-env compatibility) */
|
|
301
|
+
export type MinimalAnalyser = {
|
|
302
|
+
fftSize: number;
|
|
303
|
+
frequencyBinCount: number;
|
|
304
|
+
getByteFrequencyData(dataArray: Uint8Array): void;
|
|
305
|
+
};
|
|
306
|
+
export type MinimalAudioNode = {
|
|
307
|
+
connect?(destination: unknown): void;
|
|
308
|
+
};
|
|
309
|
+
export type MinimalAudioContext = {
|
|
310
|
+
createAnalyser(): MinimalAnalyser;
|
|
311
|
+
createMediaElementSource(element: HTMLAudioElement): MinimalAudioNode;
|
|
312
|
+
createMediaStreamSource(stream: MediaStream): MinimalAudioNode;
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* Metadata provided with custom events from voice agents.
|
|
316
|
+
* Contains contextual information about when and from whom the event originated.
|
|
317
|
+
*/
|
|
318
|
+
export type CustomEventMetadata = {
|
|
319
|
+
/** Unix timestamp when the event was generated */
|
|
320
|
+
timestamp: number;
|
|
321
|
+
/** Identity of the participant who triggered the event */
|
|
322
|
+
participant: string;
|
|
323
|
+
/** The original raw message data from LiveKit */
|
|
324
|
+
rawMessage: Record<string, unknown>;
|
|
325
|
+
};
|