@mastra/voice-aws-nova-sonic 0.2.4 → 0.2.5

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/index.js CHANGED
@@ -985,10 +985,12 @@ var NovaSonicVoice = class extends MastraVoice {
985
985
  if (this.sessionConfig?.voice) {
986
986
  if (typeof this.sessionConfig.voice === "string") voiceId = this.sessionConfig.voice;
987
987
  else if (this.sessionConfig.voice.name) voiceId = this.sessionConfig.voice.name;
988
- } else if (this.speaker && this.speaker !== "default") if (typeof this.speaker === "string") voiceId = this.speaker;
989
- else {
990
- const speakerObj = this.speaker;
991
- if (speakerObj && typeof speakerObj === "object" && speakerObj.name) voiceId = speakerObj.name;
988
+ } else if (this.speaker && this.speaker !== "default") {
989
+ if (typeof this.speaker === "string") voiceId = this.speaker;
990
+ else {
991
+ const speakerObj = this.speaker;
992
+ if (speakerObj && typeof speakerObj === "object" && speakerObj.name) voiceId = speakerObj.name;
993
+ }
992
994
  }
993
995
  const promptStartEvent = {
994
996
  promptName,
@@ -1134,17 +1136,20 @@ var NovaSonicVoice = class extends MastraVoice {
1134
1136
  } else {
1135
1137
  const eventKeys = Object.keys(jsonResponse.event || {});
1136
1138
  this.log(`[Stream] Event keys for other events: ${eventKeys.join(", ")}`);
1137
- if (eventKeys.length > 0) if (eventKeys.includes("completionEnd")) {
1138
- this.log("[Stream] Found completionEnd in other events, handling explicitly");
1139
- this.handleServerEvent({ completionEnd: jsonResponse.event.completionEnd });
1140
- } else {
1141
- const eventKey = eventKeys[0];
1142
- this.log(`[Stream] Dispatching other event: ${eventKey}`);
1143
- const eventValue = jsonResponse.event[eventKey];
1144
- if (eventValue !== void 0) if (eventKey === "completionEnd") this.handleServerEvent({ completionEnd: eventValue });
1145
- else this.handleServerEvent({ [eventKey]: eventValue });
1146
- }
1147
- else if (Object.keys(jsonResponse).length > 0) this.log(`[Stream] Unknown event structure, keys:`, Object.keys(jsonResponse).join(", "));
1139
+ if (eventKeys.length > 0) {
1140
+ if (eventKeys.includes("completionEnd")) {
1141
+ this.log("[Stream] Found completionEnd in other events, handling explicitly");
1142
+ this.handleServerEvent({ completionEnd: jsonResponse.event.completionEnd });
1143
+ } else {
1144
+ const eventKey = eventKeys[0];
1145
+ this.log(`[Stream] Dispatching other event: ${eventKey}`);
1146
+ const eventValue = jsonResponse.event[eventKey];
1147
+ if (eventValue !== void 0) {
1148
+ if (eventKey === "completionEnd") this.handleServerEvent({ completionEnd: eventValue });
1149
+ else this.handleServerEvent({ [eventKey]: eventValue });
1150
+ }
1151
+ }
1152
+ } else if (Object.keys(jsonResponse).length > 0) this.log(`[Stream] Unknown event structure, keys:`, Object.keys(jsonResponse).join(", "));
1148
1153
  }
1149
1154
  } else {
1150
1155
  if (this.debug) this.log("[Stream] Received event without \"event\" wrapper, keys:", Object.keys(jsonResponse).join(", "));
@@ -1383,50 +1388,51 @@ var NovaSonicVoice = class extends MastraVoice {
1383
1388
  } else if (contentEnd.type === "TOOL" && this.currentResponseId) {
1384
1389
  const stream = this.speakerStreams.get(this.currentResponseId);
1385
1390
  if (stream) stream.end();
1386
- } else if (contentEnd.type === "AUDIO") if (contentEnd.stopReason === "END_TURN") {
1387
- this.log(`[Event] contentEnd (AUDIO) with stopReason END_TURN - signaling turn complete`);
1388
- if (this.currentResponseId) {
1389
- const stream = this.speakerStreams.get(this.currentResponseId);
1390
- if (stream) stream.end();
1391
- this.speakerStreams.delete(this.currentResponseId);
1392
- this.currentResponseId = void 0;
1393
- }
1394
- if (!this.turnCompleted) {
1395
- this.turnCompleted = true;
1396
- this.emit("turnComplete", { timestamp: Date.now() });
1397
- this.hasSentContentEnd = false;
1398
- this.log(`[Event] Turn complete (from contentEnd AUDIO with END_TURN), ready for next turn. audioContentStarted: ${this.audioContentStarted}, audioContentName: ${this.audioContentName}`);
1399
- } else this.log(`[Event] contentEnd (AUDIO) with END_TURN received but turn already completed - skipping duplicate turnComplete emission`);
1400
- if (!this.turnCompleteTimeout) this.turnCompleteTimeout = setTimeout(() => {
1401
- this.log(`[Event] Timeout: completionEnd not received, but turn already completed from contentEnd`);
1402
- this.turnCompleteTimeout = void 0;
1403
- }, 1e3);
1404
- } else if (this.isReceivingAssistantAudio && contentEnd.stopReason === "PARTIAL_TURN") {
1405
- this.isReceivingAssistantAudio = false;
1406
- if (!this.turnCompleteTimeout && !this.turnCompleted) {
1407
- this.log(`[Event] contentEnd (AUDIO) with PARTIAL_TURN for assistant output - waiting for completionEnd, setting fallback timeout`);
1408
- this.turnCompleteTimeout = setTimeout(() => {
1409
- if (!this.turnCompleted) {
1410
- this.log(`[Event] Fallback: completionEnd not received after contentEnd (AUDIO) with PARTIAL_TURN, signaling turn complete`);
1411
- this.turnCompleted = true;
1412
- this.emit("turnComplete", { timestamp: Date.now() });
1413
- if (this.currentResponseId) {
1414
- const stream = this.speakerStreams.get(this.currentResponseId);
1415
- if (stream) stream.end();
1416
- this.speakerStreams.delete(this.currentResponseId);
1417
- this.currentResponseId = void 0;
1391
+ } else if (contentEnd.type === "AUDIO") {
1392
+ if (contentEnd.stopReason === "END_TURN") {
1393
+ this.log(`[Event] contentEnd (AUDIO) with stopReason END_TURN - signaling turn complete`);
1394
+ if (this.currentResponseId) {
1395
+ const stream = this.speakerStreams.get(this.currentResponseId);
1396
+ if (stream) stream.end();
1397
+ this.speakerStreams.delete(this.currentResponseId);
1398
+ this.currentResponseId = void 0;
1399
+ }
1400
+ if (!this.turnCompleted) {
1401
+ this.turnCompleted = true;
1402
+ this.emit("turnComplete", { timestamp: Date.now() });
1403
+ this.hasSentContentEnd = false;
1404
+ this.log(`[Event] Turn complete (from contentEnd AUDIO with END_TURN), ready for next turn. audioContentStarted: ${this.audioContentStarted}, audioContentName: ${this.audioContentName}`);
1405
+ } else this.log(`[Event] contentEnd (AUDIO) with END_TURN received but turn already completed - skipping duplicate turnComplete emission`);
1406
+ if (!this.turnCompleteTimeout) this.turnCompleteTimeout = setTimeout(() => {
1407
+ this.log(`[Event] Timeout: completionEnd not received, but turn already completed from contentEnd`);
1408
+ this.turnCompleteTimeout = void 0;
1409
+ }, 1e3);
1410
+ } else if (this.isReceivingAssistantAudio && contentEnd.stopReason === "PARTIAL_TURN") {
1411
+ this.isReceivingAssistantAudio = false;
1412
+ if (!this.turnCompleteTimeout && !this.turnCompleted) {
1413
+ this.log(`[Event] contentEnd (AUDIO) with PARTIAL_TURN for assistant output - waiting for completionEnd, setting fallback timeout`);
1414
+ this.turnCompleteTimeout = setTimeout(() => {
1415
+ if (!this.turnCompleted) {
1416
+ this.log(`[Event] Fallback: completionEnd not received after contentEnd (AUDIO) with PARTIAL_TURN, signaling turn complete`);
1417
+ this.turnCompleted = true;
1418
+ this.emit("turnComplete", { timestamp: Date.now() });
1419
+ if (this.currentResponseId) {
1420
+ const stream = this.speakerStreams.get(this.currentResponseId);
1421
+ if (stream) stream.end();
1422
+ this.speakerStreams.delete(this.currentResponseId);
1423
+ this.currentResponseId = void 0;
1424
+ }
1425
+ this.hasSentContentEnd = false;
1426
+ this.turnCompleteTimeout = void 0;
1418
1427
  }
1419
- this.hasSentContentEnd = false;
1420
- this.turnCompleteTimeout = void 0;
1421
- }
1422
- }, 2e3);
1428
+ }, 2e3);
1429
+ }
1430
+ } else {
1431
+ this.hasSentContentEnd = false;
1432
+ this.turnCompleted = false;
1433
+ this.log(`[Event] contentEnd (AUDIO) - user input ended, stopReason: ${contentEnd.stopReason}. Keeping audioContentStarted=true for next turn. Reset hasSentContentEnd=false, turnCompleted=false.`);
1423
1434
  }
1424
- } else {
1425
- this.hasSentContentEnd = false;
1426
- this.turnCompleted = false;
1427
- this.log(`[Event] contentEnd (AUDIO) - user input ended, stopReason: ${contentEnd.stopReason}. Keeping audioContentStarted=true for next turn. Reset hasSentContentEnd=false, turnCompleted=false.`);
1428
- }
1429
- else if (contentEnd.type === "TEXT") {
1435
+ } else if (contentEnd.type === "TEXT") {
1430
1436
  this.currentTextGenerationStage = void 0;
1431
1437
  this.log(`[Event] contentEnd (TEXT) received, stopReason: ${contentEnd.stopReason}. Turn completion handled by completionEnd/contentEnd(AUDIO).`);
1432
1438
  if (contentEnd.stopReason === "END_TURN") this.hasSentContentEnd = false;