@layercode/js-sdk 2.3.1 → 2.3.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/dist/types/index.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ interface ILayercodeClient {
|
|
|
37
37
|
triggerUserTurnFinished(): Promise<void>;
|
|
38
38
|
getStream(): MediaStream | null;
|
|
39
39
|
setInputDevice(deviceId: string): Promise<void>;
|
|
40
|
+
setAudioInput(state: boolean): Promise<void>;
|
|
40
41
|
listDevices(): Promise<Array<MediaDeviceInfo & {
|
|
41
42
|
default: boolean;
|
|
42
43
|
}>>;
|
|
@@ -48,6 +49,8 @@ interface ILayercodeClient {
|
|
|
48
49
|
readonly agentAudioAmplitude: number;
|
|
49
50
|
readonly isMuted: boolean;
|
|
50
51
|
readonly conversationId: string | null;
|
|
52
|
+
readonly userSpeaking: boolean;
|
|
53
|
+
readonly agentSpeaking: boolean;
|
|
51
54
|
}
|
|
52
55
|
/**
|
|
53
56
|
* Interface for LayercodeClient constructor options
|
|
@@ -63,7 +66,11 @@ interface LayercodeClientOptions {
|
|
|
63
66
|
authorizeSessionRequest?: AuthorizeSessionRequest;
|
|
64
67
|
/** Metadata to send with webhooks */
|
|
65
68
|
metadata?: Record<string, any>;
|
|
66
|
-
/**
|
|
69
|
+
/** Whether audio input is enabled. I.e. is the microphone turned on in the browser */
|
|
70
|
+
audioInput?: boolean;
|
|
71
|
+
/** Fired when audio input flag changes */
|
|
72
|
+
audioInputChanged?: (audioInput: boolean) => void;
|
|
73
|
+
/** Milliseconds before resuming agent audio after temporary pause due to user interruption (which was actually a false interruption) */
|
|
67
74
|
vadResumeDelay?: number;
|
|
68
75
|
/** Callback when connection is established */
|
|
69
76
|
onConnect?: ({ conversationId, config }: {
|
|
@@ -92,8 +99,12 @@ interface LayercodeClientOptions {
|
|
|
92
99
|
onStatusChange?: (status: string) => void;
|
|
93
100
|
/** Callback when user turn changes */
|
|
94
101
|
onUserIsSpeakingChange?: (isSpeaking: boolean) => void;
|
|
102
|
+
/** Callback when agent speaking state changes */
|
|
103
|
+
onAgentSpeakingChange?: (isSpeaking: boolean) => void;
|
|
95
104
|
/** Callback when mute state changes */
|
|
96
105
|
onMuteStateChange?: (isMuted: boolean) => void;
|
|
106
|
+
/** Whether amplitude monitoring should run for mic and speaker */
|
|
107
|
+
enableAmplitudeMonitoring?: boolean;
|
|
97
108
|
}
|
|
98
109
|
/**
|
|
99
110
|
* @class LayercodeClient
|
|
@@ -105,11 +116,13 @@ declare class LayercodeClient implements ILayercodeClient {
|
|
|
105
116
|
private wavPlayer;
|
|
106
117
|
private vad;
|
|
107
118
|
private ws;
|
|
119
|
+
private audioInput;
|
|
108
120
|
private AMPLITUDE_MONITORING_SAMPLE_RATE;
|
|
109
121
|
private pushToTalkActive;
|
|
110
122
|
private pushToTalkEnabled;
|
|
111
123
|
private canInterrupt;
|
|
112
124
|
private userIsSpeaking;
|
|
125
|
+
private agentIsSpeaking;
|
|
113
126
|
private recorderStarted;
|
|
114
127
|
private readySent;
|
|
115
128
|
private currentTurnId;
|
|
@@ -140,11 +153,13 @@ declare class LayercodeClient implements ILayercodeClient {
|
|
|
140
153
|
* @param {string} status - New status value
|
|
141
154
|
*/
|
|
142
155
|
private _setStatus;
|
|
156
|
+
private _setAgentSpeaking;
|
|
157
|
+
private _setUserSpeaking;
|
|
143
158
|
/**
|
|
144
159
|
* Handles when agent audio finishes playing
|
|
145
160
|
*/
|
|
146
161
|
private _clientResponseAudioReplayFinished;
|
|
147
|
-
private
|
|
162
|
+
private _clientInterruptAgentReplay;
|
|
148
163
|
triggerUserTurnStarted(): Promise<void>;
|
|
149
164
|
triggerUserTurnFinished(): Promise<void>;
|
|
150
165
|
sendClientResponseText(text: string): Promise<void>;
|
|
@@ -168,12 +183,25 @@ declare class LayercodeClient implements ILayercodeClient {
|
|
|
168
183
|
*/
|
|
169
184
|
private _setupAmplitudeMonitoring;
|
|
170
185
|
private _stopAmplitudeMonitoring;
|
|
186
|
+
audioInputConnect(): Promise<void>;
|
|
187
|
+
audioInputDisconnect(): Promise<void>;
|
|
188
|
+
setAudioInput(state: boolean): Promise<void>;
|
|
189
|
+
/** Emitters for audio flags */
|
|
190
|
+
private _emitAudioInput;
|
|
191
|
+
get audioInputEnabled(): boolean;
|
|
192
|
+
get userSpeaking(): boolean;
|
|
193
|
+
get agentSpeaking(): boolean;
|
|
171
194
|
/**
|
|
172
195
|
* Connects to the Layercode agent using the stored conversation ID and starts the audio conversation
|
|
173
196
|
* @async
|
|
174
197
|
* @returns {Promise<void>}
|
|
175
198
|
*/
|
|
176
199
|
connect(): Promise<void>;
|
|
200
|
+
private bindWebsocketMessageCallbacks;
|
|
201
|
+
private setupVadConfig;
|
|
202
|
+
private authorizeSession;
|
|
203
|
+
private setupAudioOutput;
|
|
204
|
+
private connectToAudioInput;
|
|
177
205
|
private _resetTurnTracking;
|
|
178
206
|
disconnect(): Promise<void>;
|
|
179
207
|
/**
|
|
@@ -197,6 +225,10 @@ declare class LayercodeClient implements ILayercodeClient {
|
|
|
197
225
|
* Restarts audio recording after a device switch to ensure audio is captured from the new device
|
|
198
226
|
*/
|
|
199
227
|
private _restartAudioRecording;
|
|
228
|
+
/**
|
|
229
|
+
* Disconnect VAD
|
|
230
|
+
*/
|
|
231
|
+
private stopVad;
|
|
200
232
|
/**
|
|
201
233
|
* Reinitializes VAD with a new stream (used after device switching)
|
|
202
234
|
*/
|
package/package.json
CHANGED