@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.
@@ -6158,6 +6158,21 @@ registerProcessor('audio_processor', AudioProcessor);
6158
6158
  });
6159
6159
  break;
6160
6160
  }
6161
+ case 'turn.end': {
6162
+ // Sent from the server when a turn ends
6163
+ if (message.role === 'user') {
6164
+ this._setUserSpeaking(false);
6165
+ }
6166
+ else if (message.role === 'assistant') {
6167
+ this._setAgentSpeaking(false);
6168
+ }
6169
+ this.options.onMessage({
6170
+ ...message,
6171
+ agentSpeaking: this.agentIsSpeaking,
6172
+ userSpeaking: this.userIsSpeaking,
6173
+ });
6174
+ break;
6175
+ }
6161
6176
  case 'response.end': {
6162
6177
  // When audioOutput is disabled, notify server that "playback" is complete
6163
6178
  if (!this.audioOutput && !this.sentReplayFinishedForDisabledOutput) {
@@ -6208,6 +6223,7 @@ registerProcessor('audio_processor', AudioProcessor);
6208
6223
  break;
6209
6224
  }
6210
6225
  case 'response.text':
6226
+ case 'response.text.delta':
6211
6227
  // Set turn ID from first text message if not set
6212
6228
  if (!this.currentTurnId) {
6213
6229
  this.currentTurnId = message.turn_id;
@@ -6860,6 +6876,23 @@ registerProcessor('audio_processor', AudioProcessor);
6860
6876
  * Disconnect VAD
6861
6877
  */
6862
6878
  stopVad() {
6879
+ // If user was speaking when VAD is destroyed, send synthetic vad_end to server
6880
+ // This ensures the server receives vad_end even when VAD is destroyed mid-speech
6881
+ // (e.g., due to mute, device change, or disconnect)
6882
+ // Only send if VAD is actually running (not for push-to-talk which uses trigger.turn events)
6883
+ if (this.userIsSpeaking && this.vad) {
6884
+ console.debug('[Layercode]: sending synthetic vad_end (VAD destroyed mid-speech)');
6885
+ this._setUserSpeaking(false); // Update state before callbacks (consistent with onSpeechEnd)
6886
+ const vadEndMessage = {
6887
+ type: 'vad_events',
6888
+ event: 'vad_end',
6889
+ };
6890
+ this._wsSend(vadEndMessage);
6891
+ this.options.onMessage({
6892
+ ...vadEndMessage,
6893
+ userSpeaking: this.userIsSpeaking,
6894
+ });
6895
+ }
6863
6896
  if (this.vad) {
6864
6897
  this.vad.pause();
6865
6898
  this.vad.destroy();