@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/_types/@internal_voice/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +206 -873
- package/dist/_types/@internal_voice/dist/_types/@internal_core/dist/request-context/index.d.ts +22 -1
- package/dist/_types/@internal_voice/dist/_types/zod/v4/core/schemas.d.ts +3 -1
- package/dist/_types/@internal_voice/dist/_types/zod/v4/core/util.d.ts +2 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +76 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +63 -57
- package/dist/index.js.map +1 -1
- package/package.json +7 -8
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")
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
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)
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
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")
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
this.turnCompleted
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
this.
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
this.isReceivingAssistantAudio
|
|
1406
|
-
|
|
1407
|
-
this.
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
this.
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
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
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
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;
|