@layercode/js-sdk 2.8.8 → 2.8.10
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.
|
@@ -6152,6 +6152,21 @@ class LayercodeClient {
|
|
|
6152
6152
|
});
|
|
6153
6153
|
break;
|
|
6154
6154
|
}
|
|
6155
|
+
case 'turn.end': {
|
|
6156
|
+
// Sent from the server when a turn ends
|
|
6157
|
+
if (message.role === 'user') {
|
|
6158
|
+
this._setUserSpeaking(false);
|
|
6159
|
+
}
|
|
6160
|
+
else if (message.role === 'assistant') {
|
|
6161
|
+
this._setAgentSpeaking(false);
|
|
6162
|
+
}
|
|
6163
|
+
this.options.onMessage({
|
|
6164
|
+
...message,
|
|
6165
|
+
agentSpeaking: this.agentIsSpeaking,
|
|
6166
|
+
userSpeaking: this.userIsSpeaking,
|
|
6167
|
+
});
|
|
6168
|
+
break;
|
|
6169
|
+
}
|
|
6155
6170
|
case 'response.end': {
|
|
6156
6171
|
// When audioOutput is disabled, notify server that "playback" is complete
|
|
6157
6172
|
if (!this.audioOutput && !this.sentReplayFinishedForDisabledOutput) {
|
|
@@ -6202,6 +6217,7 @@ class LayercodeClient {
|
|
|
6202
6217
|
break;
|
|
6203
6218
|
}
|
|
6204
6219
|
case 'response.text':
|
|
6220
|
+
case 'response.text.delta':
|
|
6205
6221
|
// Set turn ID from first text message if not set
|
|
6206
6222
|
if (!this.currentTurnId) {
|
|
6207
6223
|
this.currentTurnId = message.turn_id;
|
|
@@ -6854,6 +6870,23 @@ class LayercodeClient {
|
|
|
6854
6870
|
* Disconnect VAD
|
|
6855
6871
|
*/
|
|
6856
6872
|
stopVad() {
|
|
6873
|
+
// If user was speaking when VAD is destroyed, send synthetic vad_end to server
|
|
6874
|
+
// This ensures the server receives vad_end even when VAD is destroyed mid-speech
|
|
6875
|
+
// (e.g., due to mute, device change, or disconnect)
|
|
6876
|
+
// Only send if VAD is actually running (not for push-to-talk which uses trigger.turn events)
|
|
6877
|
+
if (this.userIsSpeaking && this.vad) {
|
|
6878
|
+
console.debug('[Layercode]: sending synthetic vad_end (VAD destroyed mid-speech)');
|
|
6879
|
+
this._setUserSpeaking(false); // Update state before callbacks (consistent with onSpeechEnd)
|
|
6880
|
+
const vadEndMessage = {
|
|
6881
|
+
type: 'vad_events',
|
|
6882
|
+
event: 'vad_end',
|
|
6883
|
+
};
|
|
6884
|
+
this._wsSend(vadEndMessage);
|
|
6885
|
+
this.options.onMessage({
|
|
6886
|
+
...vadEndMessage,
|
|
6887
|
+
userSpeaking: this.userIsSpeaking,
|
|
6888
|
+
});
|
|
6889
|
+
}
|
|
6857
6890
|
if (this.vad) {
|
|
6858
6891
|
this.vad.pause();
|
|
6859
6892
|
this.vad.destroy();
|