@vogent/vogent-web-client 0.0.4 → 0.0.6

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/VogentCall.ts CHANGED
@@ -1,3 +1,45 @@
1
+ /**
2
+ * @fileoverview VogentCall provides the main interface for managing voice calls with Vogent's AI system.
3
+ *
4
+ * This class handles:
5
+ * - Call lifecycle management (start, pause, hangup)
6
+ * - Audio connection setup
7
+ * - Real-time transcript monitoring
8
+ * - Status event handling
9
+ *
10
+ * Basic usage:
11
+ * ```typescript
12
+ * const call = new VogentCall({
13
+ * sessionId: "session_id",
14
+ * dialId: "dial_id",
15
+ * token: "auth_token"
16
+ * });
17
+ *
18
+ * // Start the call
19
+ * await call.start();
20
+ *
21
+ * // Connect audio
22
+ * const audioConn = await call.connectAudio();
23
+ *
24
+ * // Monitor transcripts
25
+ * const unsubscribe = call.monitorTranscript((transcript) => {
26
+ * console.log(transcript);
27
+ * });
28
+ *
29
+ * // Monitor status changes
30
+ * call.on('status', (status) => {
31
+ * console.log('Call status:', status);
32
+ * });
33
+ *
34
+ * // Later: cleanup
35
+ * unsubscribe();
36
+ * await call.hangup();
37
+ * ```
38
+ *
39
+ * @see {@link https://docs.vogent.ai} for complete server documentation
40
+ * @module VogentCall
41
+ */
42
+
1
43
  import { ApolloClient, createHttpLink, InMemoryCache, NormalizedCacheObject, split } from '@apollo/client';
2
44
  import { setContext } from '@apollo/client/link/context';
3
45
  import { GraphQLWsLink } from '@apollo/client/link/subscriptions';
@@ -22,22 +64,49 @@ import { VonageDevice } from './devices/VonageDevice';
22
64
  import { dialStatusIsComplete } from './utils';
23
65
 
24
66
  export type Transcript = {
67
+ /** The text of the transcript */
25
68
  text: string;
69
+ /** The speaker of the transcript currently either 'HUMAN' or 'AI', or 'IVR' if IVR detection is enabled */
26
70
  speaker: string;
27
71
  }[]
28
72
 
73
+ /**
74
+ * VogentCall manages the lifecycle and state of a voice call session
75
+ */
29
76
  export class VogentCall {
30
- client: ApolloClient<NormalizedCacheObject>;
31
- sessionId: string;
32
- dialId: string;
33
- subscription?: ObservableSubscription;
34
- baseUrl: string;
35
- dial?: Dial;
36
- _handlers: {
77
+ /** Apollo GraphQL client instance for API communication */
78
+ private client: ApolloClient<NormalizedCacheObject>;
79
+
80
+ /** Unique identifier for the current session */
81
+ private sessionId: string;
82
+
83
+ /** Unique identifier for the current dial/call */
84
+ private dialId: string;
85
+
86
+ /** GraphQL subscription handle */
87
+ private subscription?: ObservableSubscription;
88
+
89
+ /** Base URL for the API endpoints */
90
+ private baseUrl: string;
91
+
92
+ /** Current dial/call state */
93
+ private dial?: Dial;
94
+
95
+ /** Array of event handlers for status changes */
96
+ private _handlers: {
37
97
  ev: 'status';
38
98
  fn: (...args: any[]) => void;
39
99
  }[];
40
100
 
101
+ /**
102
+ * Creates a new VogentCall instance
103
+ * @param dialDetails - Object containing session details and authentication, retrieved from the Vogent server API
104
+ * @param dialDetails.sessionId - Unique session identifier
105
+ * @param dialDetails.dialId - Unique dial/call identifier
106
+ * @param dialDetails.token - Authentication token
107
+ * @param config - Configuration options
108
+ * @param config.baseUrl - API base URL (defaults to 'https://api.getelto.com')
109
+ */
41
110
  constructor(dialDetails: {
42
111
  sessionId: string;
43
112
  dialId: string;
@@ -97,6 +166,12 @@ export class VogentCall {
97
166
  });
98
167
  }
99
168
 
169
+ /**
170
+ * Registers an event handler for status changes
171
+ * @param ev - Event type ('status')
172
+ * - status: called when the dial status changes, see docs.vogent.ai for more details
173
+ * @param fn - Callback function to handle the event
174
+ */
100
175
  on(ev: 'status', fn: (...args: any[]) => void) {
101
176
  this._handlers.push({
102
177
  ev,
@@ -104,6 +179,11 @@ export class VogentCall {
104
179
  });
105
180
  }
106
181
 
182
+ /**
183
+ * Subscribes to transcript updates for the current call
184
+ * @param fn - Callback function that receives transcript updates
185
+ * @returns Function to unsubscribe from transcript updates
186
+ */
107
187
  monitorTranscript(fn: (transcript: Transcript) => void): () => void {
108
188
  const subscription = this.client
109
189
  .subscribe({
@@ -130,7 +210,11 @@ export class VogentCall {
130
210
  }
131
211
  }
132
212
 
133
- updateDial(dial: Dial) {
213
+ /**
214
+ * Internal method to update dial state and trigger status handlers
215
+ * @param dial - Updated dial information
216
+ */
217
+ private updateDial(dial: Dial) {
134
218
  if (!this.dial || dial.status !== this.dial.status) {
135
219
  this._handlers.forEach((h) => {
136
220
  h.fn(dial.status);
@@ -149,6 +233,12 @@ export class VogentCall {
149
233
  };
150
234
  }
151
235
 
236
+ /**
237
+ * Establishes audio connection for the call
238
+ * @param liveListen - Whether to enable live listening mode. This should be set to true for monitoring legs (e.g. humans that are listening
239
+ * to the call who the AI should not interact with.)
240
+ * @returns Promise resolving to audio connection handle
241
+ */
152
242
  async connectAudio(liveListen: boolean = false): Promise<VogentAudioConn> {
153
243
  const token = await this.client.mutate({
154
244
  mutation: AI_GET_TOKEN,
@@ -169,6 +259,9 @@ export class VogentCall {
169
259
  return c;
170
260
  }
171
261
 
262
+ /**
263
+ * Starts the call session. Does not connect audio, you must call connectAudio() to do so.
264
+ */
172
265
  async start() {
173
266
  this.subscription = this.client
174
267
  .subscribe({
@@ -200,6 +293,10 @@ export class VogentCall {
200
293
  });
201
294
  }
202
295
 
296
+ /**
297
+ * Sets the pause state of the AI
298
+ * @param paused - Whether to pause the AI or not.
299
+ */
203
300
  async setPaused(paused: boolean) {
204
301
  if (!this.dial) {
205
302
  return;
@@ -214,6 +311,9 @@ export class VogentCall {
214
311
  });
215
312
  }
216
313
 
314
+ /**
315
+ * Ends the current call
316
+ */
217
317
  async hangup() {
218
318
  if (!this.dial) {
219
319
  return;
@@ -1,12 +1,49 @@
1
1
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
2
2
 
3
+ /**
4
+ * Interface representing an active audio connection to a Vogent call.
5
+ * Returned by VogentCall.connectAudio()
6
+ */
3
7
  export interface VogentAudioConn {
4
- on: (ev: 'mute' | 'disconnect', fn: (...args: any[]) => void) => void;
5
- mute: (status: boolean) => void;
6
- disconnect: () => void;
7
- sendDigits: (k: string) => void;
8
- }
9
-
10
- export interface VogentDevice {
11
- connect: (p: any) => Promise<VogentAudioConn>;
12
- }
8
+ /**
9
+ * Register event handlers for connection events
10
+ * @param ev - Event type to listen for
11
+ * - 'mute': Fired when the connection's mute state changes
12
+ * - 'disconnect': Fired when the connection is terminated
13
+ * @param fn - Callback function to handle the event
14
+ */
15
+ on: (ev: 'mute' | 'disconnect', fn: (...args: any[]) => void) => void;
16
+
17
+ /**
18
+ * Mute or unmute the audio connection
19
+ * @param status - True to mute, false to unmute
20
+ */
21
+ mute: (status: boolean) => void;
22
+
23
+ /**
24
+ * Terminate the audio connection
25
+ */
26
+ disconnect: () => void;
27
+
28
+ /**
29
+ * Send DTMF digits through the connection
30
+ * @param k - String of DTMF digits to send (0-9, *, #)
31
+ */
32
+ sendDigits: (k: string) => void;
33
+ }
34
+
35
+ /**
36
+ * Interface representing a device that can establish audio connections
37
+ * Currently implemented by VonageDevice
38
+ */
39
+ export interface VogentDevice {
40
+ /**
41
+ * Establish an audio connection with the specified parameters
42
+ * @param p - Connection parameters object containing:
43
+ * - params.EltoDialSessionID: The session ID for the call
44
+ * - params.LiveListen: Whether this is a monitoring connection
45
+ * - params.DialID: The ID of the dial to connect to
46
+ * @returns Promise resolving to an active audio connection
47
+ */
48
+ connect: (p: any) => Promise<VogentAudioConn>;
49
+ }
package/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './VogentCall';
2
+ export * from './devices/VogentDevice';
3
+ export { dialStatusIsComplete } from './utils';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vogent/vogent-web-client",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
6
  "@apollo/client": "^3.12.4",