@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/_types/@internal_voice/dist/_types/@internal_core/dist/request-context/index.d.ts
CHANGED
|
@@ -26,6 +26,27 @@ declare const MASTRA_RESOURCE_ID_KEY = "mastra__resourceId";
|
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
28
|
declare const MASTRA_THREAD_ID_KEY = "mastra__threadId";
|
|
29
|
+
/**
|
|
30
|
+
* Reserved key for setting agent scopes from middleware.
|
|
31
|
+
*
|
|
32
|
+
* Holds a `string[]` of `<type>:<value>` addresses (for example `org:acme`,
|
|
33
|
+
* `resource:user-1`, `thread:t-9`). Scope types are arbitrary; `resource:` and
|
|
34
|
+
* `thread:` are the conventions Memory reads as the run's resource and thread.
|
|
35
|
+
* Middleware-set scopes are combined with the agent's `scopes` resolver and the
|
|
36
|
+
* per-call `scopes` option. Conflicting `resource:`/`thread:` values throw.
|
|
37
|
+
*
|
|
38
|
+
* During a run, the agent passes tools, processors and sub-agents a copy of the
|
|
39
|
+
* request context whose `mastra__scopes` holds only the non-identity scopes;
|
|
40
|
+
* the caller's own request context is never modified.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* // In your auth middleware:
|
|
45
|
+
* const requestContext = c.get('requestContext');
|
|
46
|
+
* requestContext.set(MASTRA_SCOPES_KEY, [`org:${user.orgId}`, `resource:${user.id}`]);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
declare const MASTRA_SCOPES_KEY = "mastra__scopes";
|
|
29
50
|
/**
|
|
30
51
|
* Reserved key for storing version overrides on RequestContext.
|
|
31
52
|
* When set, sub-agent delegation resolves versioned agents from these overrides.
|
|
@@ -261,5 +282,5 @@ declare class RequestContext<Values extends Record<string, any> | unknown = unkn
|
|
|
261
282
|
get all(): Values extends Record<string, any> ? Values : Record<string, any>;
|
|
262
283
|
}
|
|
263
284
|
//#endregion
|
|
264
|
-
export { MASTRA_AUTH_TOKEN_KEY, MASTRA_INHERITED_MEMORY_KEY, MASTRA_MESSAGE_AUTHOR_KEY, MASTRA_RESOURCE_ID_KEY, MASTRA_THREAD_ID_KEY, MASTRA_VERSIONS_KEY, RequestContext, VersionOverrides, VersionSelector, isReservedRequestContextKey, mergeVersionOverrides };
|
|
285
|
+
export { MASTRA_AUTH_TOKEN_KEY, MASTRA_INHERITED_MEMORY_KEY, MASTRA_MESSAGE_AUTHOR_KEY, MASTRA_RESOURCE_ID_KEY, MASTRA_SCOPES_KEY, MASTRA_THREAD_ID_KEY, MASTRA_VERSIONS_KEY, RequestContext, VersionOverrides, VersionSelector, isReservedRequestContextKey, mergeVersionOverrides };
|
|
265
286
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -834,8 +834,10 @@ export type $InferZodRecordOutput<Key extends $ZodRecordKey = $ZodRecordKey, Val
|
|
|
834
834
|
export type $InferZodRecordInput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> = Key extends $partial ? Partial<Record<core.input<Key> & PropertyKey, core.input<Value>>> : [
|
|
835
835
|
Value
|
|
836
836
|
] extends [OptionalInSchema] ? Partial<Record<core.input<Key> & PropertyKey, core.input<Value>>> : Record<core.input<Key> & PropertyKey, core.input<Value>>;
|
|
837
|
-
export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodTypeInternals
|
|
837
|
+
export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodTypeInternals {
|
|
838
838
|
def: $ZodRecordDef<Key, Value>;
|
|
839
|
+
output: $InferZodRecordOutput<Key, Value>;
|
|
840
|
+
input: $InferZodRecordInput<Key, Value>;
|
|
839
841
|
isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey<Record<PropertyKey, unknown>>;
|
|
840
842
|
optin?: "optional" | undefined;
|
|
841
843
|
optout?: "optional" | undefined;
|
|
@@ -221,6 +221,8 @@ export declare function prefixIssues(path: PropertyKey, issues: errors.$ZodRawIs
|
|
|
221
221
|
export declare function unwrapMessage(message: string | {
|
|
222
222
|
message: string;
|
|
223
223
|
} | undefined | null): string | undefined;
|
|
224
|
+
/** The leading size checks of `defChecks` that set an upper bound, each paired with it. */
|
|
225
|
+
export declare function sizeCaps(defChecks: checks.$ZodCheck<never>[] | undefined): [number, checks.$ZodCheck<never>][];
|
|
224
226
|
export declare function attachSchema(issues: errors.$ZodRawIssue[], start: number, inst: schemas.$ZodType): void;
|
|
225
227
|
export declare function finalizeIssue(iss: errors.$ZodRawIssue, ctx: schemas.ParseContextInternal | undefined, config: $ZodConfig): errors.$ZodIssue;
|
|
226
228
|
export declare function getSizableOrigin(input: any): "set" | "map" | "file" | "unknown";
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-voice-aws-nova-sonic
|
|
|
3
3
|
description: Documentation for @mastra/voice-aws-nova-sonic. Use when working with @mastra/voice-aws-nova-sonic APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/voice-aws-nova-sonic"
|
|
6
|
-
version: "0.2.
|
|
6
|
+
version: "0.2.5"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
package/dist/index.cjs
CHANGED
|
@@ -986,10 +986,12 @@ var NovaSonicVoice = class extends MastraVoice {
|
|
|
986
986
|
if (this.sessionConfig?.voice) {
|
|
987
987
|
if (typeof this.sessionConfig.voice === "string") voiceId = this.sessionConfig.voice;
|
|
988
988
|
else if (this.sessionConfig.voice.name) voiceId = this.sessionConfig.voice.name;
|
|
989
|
-
} else if (this.speaker && this.speaker !== "default")
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
989
|
+
} else if (this.speaker && this.speaker !== "default") {
|
|
990
|
+
if (typeof this.speaker === "string") voiceId = this.speaker;
|
|
991
|
+
else {
|
|
992
|
+
const speakerObj = this.speaker;
|
|
993
|
+
if (speakerObj && typeof speakerObj === "object" && speakerObj.name) voiceId = speakerObj.name;
|
|
994
|
+
}
|
|
993
995
|
}
|
|
994
996
|
const promptStartEvent = {
|
|
995
997
|
promptName,
|
|
@@ -1135,17 +1137,20 @@ var NovaSonicVoice = class extends MastraVoice {
|
|
|
1135
1137
|
} else {
|
|
1136
1138
|
const eventKeys = Object.keys(jsonResponse.event || {});
|
|
1137
1139
|
this.log(`[Stream] Event keys for other events: ${eventKeys.join(", ")}`);
|
|
1138
|
-
if (eventKeys.length > 0)
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1140
|
+
if (eventKeys.length > 0) {
|
|
1141
|
+
if (eventKeys.includes("completionEnd")) {
|
|
1142
|
+
this.log("[Stream] Found completionEnd in other events, handling explicitly");
|
|
1143
|
+
this.handleServerEvent({ completionEnd: jsonResponse.event.completionEnd });
|
|
1144
|
+
} else {
|
|
1145
|
+
const eventKey = eventKeys[0];
|
|
1146
|
+
this.log(`[Stream] Dispatching other event: ${eventKey}`);
|
|
1147
|
+
const eventValue = jsonResponse.event[eventKey];
|
|
1148
|
+
if (eventValue !== void 0) {
|
|
1149
|
+
if (eventKey === "completionEnd") this.handleServerEvent({ completionEnd: eventValue });
|
|
1150
|
+
else this.handleServerEvent({ [eventKey]: eventValue });
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
} else if (Object.keys(jsonResponse).length > 0) this.log(`[Stream] Unknown event structure, keys:`, Object.keys(jsonResponse).join(", "));
|
|
1149
1154
|
}
|
|
1150
1155
|
} else {
|
|
1151
1156
|
if (this.debug) this.log("[Stream] Received event without \"event\" wrapper, keys:", Object.keys(jsonResponse).join(", "));
|
|
@@ -1220,8 +1225,8 @@ var NovaSonicVoice = class extends MastraVoice {
|
|
|
1220
1225
|
this.turnCompleted = true;
|
|
1221
1226
|
this.emit("turnComplete", { timestamp: Date.now() });
|
|
1222
1227
|
if (this.currentResponseId) {
|
|
1223
|
-
const stream
|
|
1224
|
-
if (stream
|
|
1228
|
+
const stream = this.speakerStreams.get(this.currentResponseId);
|
|
1229
|
+
if (stream) stream.end();
|
|
1225
1230
|
this.speakerStreams.delete(this.currentResponseId);
|
|
1226
1231
|
this.currentResponseId = void 0;
|
|
1227
1232
|
}
|
|
@@ -1328,8 +1333,8 @@ var NovaSonicVoice = class extends MastraVoice {
|
|
|
1328
1333
|
response_id: this.currentResponseId
|
|
1329
1334
|
});
|
|
1330
1335
|
if (this.currentResponseId) {
|
|
1331
|
-
const stream
|
|
1332
|
-
if (stream
|
|
1336
|
+
const stream = this.speakerStreams.get(this.currentResponseId);
|
|
1337
|
+
if (stream) stream.write(audioBytes);
|
|
1333
1338
|
}
|
|
1334
1339
|
} catch (error) {
|
|
1335
1340
|
this.log("[Event] Error decoding audio:", error);
|
|
@@ -1375,59 +1380,60 @@ var NovaSonicVoice = class extends MastraVoice {
|
|
|
1375
1380
|
timestamp: Date.now()
|
|
1376
1381
|
});
|
|
1377
1382
|
if (this.currentResponseId) {
|
|
1378
|
-
const stream
|
|
1379
|
-
if (stream
|
|
1383
|
+
const stream = this.speakerStreams.get(this.currentResponseId);
|
|
1384
|
+
if (stream) stream.destroy();
|
|
1380
1385
|
this.speakerStreams.delete(this.currentResponseId);
|
|
1381
1386
|
}
|
|
1382
1387
|
this.currentResponseId = void 0;
|
|
1383
1388
|
this.log("[Event] After interruption, keeping audioContentStarted=true for continued streaming");
|
|
1384
1389
|
} else if (contentEnd.type === "TOOL" && this.currentResponseId) {
|
|
1385
|
-
const stream
|
|
1386
|
-
if (stream
|
|
1387
|
-
} else if (contentEnd.type === "AUDIO")
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
this.turnCompleted
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
this.
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
this.isReceivingAssistantAudio
|
|
1407
|
-
|
|
1408
|
-
this.
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
this.
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1390
|
+
const stream = this.speakerStreams.get(this.currentResponseId);
|
|
1391
|
+
if (stream) stream.end();
|
|
1392
|
+
} else if (contentEnd.type === "AUDIO") {
|
|
1393
|
+
if (contentEnd.stopReason === "END_TURN") {
|
|
1394
|
+
this.log(`[Event] contentEnd (AUDIO) with stopReason END_TURN - signaling turn complete`);
|
|
1395
|
+
if (this.currentResponseId) {
|
|
1396
|
+
const stream = this.speakerStreams.get(this.currentResponseId);
|
|
1397
|
+
if (stream) stream.end();
|
|
1398
|
+
this.speakerStreams.delete(this.currentResponseId);
|
|
1399
|
+
this.currentResponseId = void 0;
|
|
1400
|
+
}
|
|
1401
|
+
if (!this.turnCompleted) {
|
|
1402
|
+
this.turnCompleted = true;
|
|
1403
|
+
this.emit("turnComplete", { timestamp: Date.now() });
|
|
1404
|
+
this.hasSentContentEnd = false;
|
|
1405
|
+
this.log(`[Event] Turn complete (from contentEnd AUDIO with END_TURN), ready for next turn. audioContentStarted: ${this.audioContentStarted}, audioContentName: ${this.audioContentName}`);
|
|
1406
|
+
} else this.log(`[Event] contentEnd (AUDIO) with END_TURN received but turn already completed - skipping duplicate turnComplete emission`);
|
|
1407
|
+
if (!this.turnCompleteTimeout) this.turnCompleteTimeout = setTimeout(() => {
|
|
1408
|
+
this.log(`[Event] Timeout: completionEnd not received, but turn already completed from contentEnd`);
|
|
1409
|
+
this.turnCompleteTimeout = void 0;
|
|
1410
|
+
}, 1e3);
|
|
1411
|
+
} else if (this.isReceivingAssistantAudio && contentEnd.stopReason === "PARTIAL_TURN") {
|
|
1412
|
+
this.isReceivingAssistantAudio = false;
|
|
1413
|
+
if (!this.turnCompleteTimeout && !this.turnCompleted) {
|
|
1414
|
+
this.log(`[Event] contentEnd (AUDIO) with PARTIAL_TURN for assistant output - waiting for completionEnd, setting fallback timeout`);
|
|
1415
|
+
this.turnCompleteTimeout = setTimeout(() => {
|
|
1416
|
+
if (!this.turnCompleted) {
|
|
1417
|
+
this.log(`[Event] Fallback: completionEnd not received after contentEnd (AUDIO) with PARTIAL_TURN, signaling turn complete`);
|
|
1418
|
+
this.turnCompleted = true;
|
|
1419
|
+
this.emit("turnComplete", { timestamp: Date.now() });
|
|
1420
|
+
if (this.currentResponseId) {
|
|
1421
|
+
const stream = this.speakerStreams.get(this.currentResponseId);
|
|
1422
|
+
if (stream) stream.end();
|
|
1423
|
+
this.speakerStreams.delete(this.currentResponseId);
|
|
1424
|
+
this.currentResponseId = void 0;
|
|
1425
|
+
}
|
|
1426
|
+
this.hasSentContentEnd = false;
|
|
1427
|
+
this.turnCompleteTimeout = void 0;
|
|
1419
1428
|
}
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1429
|
+
}, 2e3);
|
|
1430
|
+
}
|
|
1431
|
+
} else {
|
|
1432
|
+
this.hasSentContentEnd = false;
|
|
1433
|
+
this.turnCompleted = false;
|
|
1434
|
+
this.log(`[Event] contentEnd (AUDIO) - user input ended, stopReason: ${contentEnd.stopReason}. Keeping audioContentStarted=true for next turn. Reset hasSentContentEnd=false, turnCompleted=false.`);
|
|
1424
1435
|
}
|
|
1425
|
-
} else {
|
|
1426
|
-
this.hasSentContentEnd = false;
|
|
1427
|
-
this.turnCompleted = false;
|
|
1428
|
-
this.log(`[Event] contentEnd (AUDIO) - user input ended, stopReason: ${contentEnd.stopReason}. Keeping audioContentStarted=true for next turn. Reset hasSentContentEnd=false, turnCompleted=false.`);
|
|
1429
|
-
}
|
|
1430
|
-
else if (contentEnd.type === "TEXT") {
|
|
1436
|
+
} else if (contentEnd.type === "TEXT") {
|
|
1431
1437
|
this.currentTextGenerationStage = void 0;
|
|
1432
1438
|
this.log(`[Event] contentEnd (TEXT) received, stopReason: ${contentEnd.stopReason}. Turn completion handled by completionEnd/contentEnd(AUDIO).`);
|
|
1433
1439
|
if (contentEnd.stopReason === "END_TURN") this.hasSentContentEnd = false;
|
|
@@ -1446,8 +1452,8 @@ var NovaSonicVoice = class extends MastraVoice {
|
|
|
1446
1452
|
this.turnCompleteTimeout = void 0;
|
|
1447
1453
|
}
|
|
1448
1454
|
if (this.currentResponseId) {
|
|
1449
|
-
const stream
|
|
1450
|
-
if (stream
|
|
1455
|
+
const stream = this.speakerStreams.get(this.currentResponseId);
|
|
1456
|
+
if (stream) stream.end();
|
|
1451
1457
|
this.speakerStreams.delete(this.currentResponseId);
|
|
1452
1458
|
this.currentResponseId = void 0;
|
|
1453
1459
|
}
|
|
@@ -1547,7 +1553,7 @@ var NovaSonicVoice = class extends MastraVoice {
|
|
|
1547
1553
|
this.inputStream.end();
|
|
1548
1554
|
this.inputStream = void 0;
|
|
1549
1555
|
}
|
|
1550
|
-
for (const stream
|
|
1556
|
+
for (const stream of this.speakerStreams.values()) stream.end();
|
|
1551
1557
|
this.speakerStreams.clear();
|
|
1552
1558
|
const client = this.client;
|
|
1553
1559
|
this.client = void 0;
|
|
@@ -1685,8 +1691,8 @@ var NovaSonicVoice = class extends MastraVoice {
|
|
|
1685
1691
|
} });
|
|
1686
1692
|
this.log(`[send] audioInput chunk sent successfully`);
|
|
1687
1693
|
} else if (audioData && typeof audioData === "object" && "read" in audioData) {
|
|
1688
|
-
const stream
|
|
1689
|
-
for await (const chunk of stream
|
|
1694
|
+
const stream = audioData;
|
|
1695
|
+
for await (const chunk of stream) {
|
|
1690
1696
|
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
1691
1697
|
const base64Audio = buffer.toString("base64");
|
|
1692
1698
|
this.log(`[send] Sending audioInput chunk from stream, size: ${buffer.length} bytes, contentName: ${contentName}, turnCompleted: ${this.turnCompleted}, hasSentContentEnd: ${this.hasSentContentEnd}`);
|