@voicethere/agent 0.7.2 → 0.7.4
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/README.md +12 -11
- package/dist/agent.js +92 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/protocol.d.ts +92 -4
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js.map +1 -1
- package/dist/runtime.d.ts +45 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +285 -0
- package/dist/runtime.js.map +1 -1
- package/dist/templates/echo/agent.js +98 -1
- package/dist/templates/echo-dc/agent.js +98 -1
- package/dist/templates/game-sync/agent.js +98 -1
- package/dist/templates/positional-tts/agent.js +98 -1
- package/dist/templates/recording-consent/agent.js +98 -1
- package/dist/templates/voice-showcase/agent.js +98 -1
- package/dist/templates/voice-starter/agent.js +107 -1
- package/dist/templates/webhooks/agent.js +98 -1
- package/dist/templates/webhooks-redis/agent.js +98 -1
- package/dist/verify/lib.d.ts +1 -1
- package/dist/verify/lib.d.ts.map +1 -1
- package/dist/verify/lib.js +1 -0
- package/dist/verify/lib.js.map +1 -1
- package/package.json +5 -5
- package/templates/agent.ts +13 -0
- package/templates/mix-smoke.ts +72 -1
|
@@ -130,6 +130,24 @@ var SessionSerialQueue = class {
|
|
|
130
130
|
var SESSION_START_INIT_DELAY_ENABLED_ENV = "AGENT_SESSION_START_INIT_DELAY_ENABLED";
|
|
131
131
|
var SESSION_START_INIT_DELAY_MS_ENV = "AGENT_SESSION_START_INIT_DELAY_MS";
|
|
132
132
|
var DEFAULT_SESSION_START_INIT_DELAY_MS = 500;
|
|
133
|
+
function isPlayAckMessage(value) {
|
|
134
|
+
if (!value || typeof value !== "object")
|
|
135
|
+
return false;
|
|
136
|
+
const msg = value;
|
|
137
|
+
return msg.type === "play_ack" && typeof msg.requestId === "string";
|
|
138
|
+
}
|
|
139
|
+
function isPlayStatusAckMessage(value) {
|
|
140
|
+
if (!value || typeof value !== "object")
|
|
141
|
+
return false;
|
|
142
|
+
const msg = value;
|
|
143
|
+
return msg.type === "play_status_ack" && typeof msg.requestId === "string";
|
|
144
|
+
}
|
|
145
|
+
function isPlayStopAckMessage(value) {
|
|
146
|
+
if (!value || typeof value !== "object")
|
|
147
|
+
return false;
|
|
148
|
+
const msg = value;
|
|
149
|
+
return msg.type === "play_stop_ack" && typeof msg.requestId === "string";
|
|
150
|
+
}
|
|
133
151
|
function isRecordingControlAckMessage(value) {
|
|
134
152
|
if (!value || typeof value !== "object")
|
|
135
153
|
return false;
|
|
@@ -190,7 +208,7 @@ function isParentMessage(value) {
|
|
|
190
208
|
if (!value || typeof value !== "object")
|
|
191
209
|
return false;
|
|
192
210
|
const msg = value;
|
|
193
|
-
return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "recording_control_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "webhook";
|
|
211
|
+
return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "recording_control_ack" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "webhook";
|
|
194
212
|
}
|
|
195
213
|
function isSessionScopedParentMessage(value) {
|
|
196
214
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -207,7 +225,11 @@ var recordingAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
|
207
225
|
var mixAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
208
226
|
var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
209
227
|
var endedSessionIds = /* @__PURE__ */ new Set();
|
|
228
|
+
var PLAY_BYTES_MAX_DECODED_LENGTH = 64 * 1024;
|
|
210
229
|
var pendingRecordingAcks = /* @__PURE__ */ new Map();
|
|
230
|
+
var pendingPlayAcks = /* @__PURE__ */ new Map();
|
|
231
|
+
var pendingPlayStatusAcks = /* @__PURE__ */ new Map();
|
|
232
|
+
var pendingPlayStopAcks = /* @__PURE__ */ new Map();
|
|
211
233
|
var pendingMixAcks = /* @__PURE__ */ new Map();
|
|
212
234
|
var pendingSttAcks = /* @__PURE__ */ new Map();
|
|
213
235
|
function handleRecordingControlAck(message) {
|
|
@@ -222,6 +244,46 @@ function handleRecordingControlAck(message) {
|
|
|
222
244
|
requestId: message.requestId
|
|
223
245
|
});
|
|
224
246
|
}
|
|
247
|
+
function handlePlayAck(message) {
|
|
248
|
+
const pending = pendingPlayAcks.get(message.requestId);
|
|
249
|
+
if (!pending)
|
|
250
|
+
return;
|
|
251
|
+
clearTimeout(pending.timer);
|
|
252
|
+
pendingPlayAcks.delete(message.requestId);
|
|
253
|
+
pending.resolve({
|
|
254
|
+
ok: message.ok,
|
|
255
|
+
...message.playId ? { playId: message.playId } : {},
|
|
256
|
+
reason: message.reason,
|
|
257
|
+
requestId: message.requestId
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
function handlePlayStatusAck(message) {
|
|
261
|
+
const pending = pendingPlayStatusAcks.get(message.requestId);
|
|
262
|
+
if (!pending)
|
|
263
|
+
return;
|
|
264
|
+
clearTimeout(pending.timer);
|
|
265
|
+
pendingPlayStatusAcks.delete(message.requestId);
|
|
266
|
+
pending.resolve({
|
|
267
|
+
ok: message.ok,
|
|
268
|
+
playId: message.playId,
|
|
269
|
+
...message.status ? { status: message.status } : {},
|
|
270
|
+
reason: message.reason,
|
|
271
|
+
requestId: message.requestId
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
function handlePlayStopAck(message) {
|
|
275
|
+
const pending = pendingPlayStopAcks.get(message.requestId);
|
|
276
|
+
if (!pending)
|
|
277
|
+
return;
|
|
278
|
+
clearTimeout(pending.timer);
|
|
279
|
+
pendingPlayStopAcks.delete(message.requestId);
|
|
280
|
+
pending.resolve({
|
|
281
|
+
ok: message.ok,
|
|
282
|
+
playId: message.playId,
|
|
283
|
+
reason: message.reason,
|
|
284
|
+
requestId: message.requestId
|
|
285
|
+
});
|
|
286
|
+
}
|
|
225
287
|
function handleMixControlAck(message) {
|
|
226
288
|
const pending = pendingMixAcks.get(message.requestId);
|
|
227
289
|
if (!pending)
|
|
@@ -307,6 +369,10 @@ function sendParentMessage(message) {
|
|
|
307
369
|
process.send?.(message);
|
|
308
370
|
return;
|
|
309
371
|
}
|
|
372
|
+
if (msgType === "play" || msgType === "play_status" || msgType === "play_stop") {
|
|
373
|
+
process.send?.(message);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
310
376
|
const sessionId = message && typeof message === "object" && "sessionId" in message && typeof message.sessionId === "string" ? message.sessionId : void 0;
|
|
311
377
|
if (!allowOutboundForSession(sessionId))
|
|
312
378
|
return;
|
|
@@ -382,6 +448,16 @@ async function handleWebhookMessage(message, handlers) {
|
|
|
382
448
|
});
|
|
383
449
|
}
|
|
384
450
|
}
|
|
451
|
+
function resolveUserLanguageCode(event) {
|
|
452
|
+
const withLanguage = event;
|
|
453
|
+
const candidates = [withLanguage.language, event.text];
|
|
454
|
+
for (const value of candidates) {
|
|
455
|
+
if (typeof value === "string" && value.trim()) {
|
|
456
|
+
return value.trim();
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return void 0;
|
|
460
|
+
}
|
|
385
461
|
async function handleParentMessage(message, handlers) {
|
|
386
462
|
switch (message.type) {
|
|
387
463
|
case "session_start":
|
|
@@ -414,6 +490,15 @@ async function handleParentMessage(message, handlers) {
|
|
|
414
490
|
text: message.event.text.trim()
|
|
415
491
|
});
|
|
416
492
|
}
|
|
493
|
+
if (message.event.type === "user_language") {
|
|
494
|
+
const language = resolveUserLanguageCode(message.event);
|
|
495
|
+
if (language) {
|
|
496
|
+
await handlers.onUserLanguage?.({
|
|
497
|
+
sessionId: message.sessionId,
|
|
498
|
+
language
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
}
|
|
417
502
|
break;
|
|
418
503
|
case "data_channel_message":
|
|
419
504
|
await handlers.onDataChannelMessage?.({
|
|
@@ -458,6 +543,18 @@ function defineAgent(handlers) {
|
|
|
458
543
|
handleRecordingControlAck(message);
|
|
459
544
|
return;
|
|
460
545
|
}
|
|
546
|
+
if (isPlayAckMessage(message)) {
|
|
547
|
+
handlePlayAck(message);
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
if (isPlayStatusAckMessage(message)) {
|
|
551
|
+
handlePlayStatusAck(message);
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
if (isPlayStopAckMessage(message)) {
|
|
555
|
+
handlePlayStopAck(message);
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
461
558
|
if (isMixControlAckMessage(message)) {
|
|
462
559
|
handleMixControlAck(message);
|
|
463
560
|
return;
|
|
@@ -10884,6 +10884,24 @@ var SessionSerialQueue = class {
|
|
|
10884
10884
|
var SESSION_START_INIT_DELAY_ENABLED_ENV = "AGENT_SESSION_START_INIT_DELAY_ENABLED";
|
|
10885
10885
|
var SESSION_START_INIT_DELAY_MS_ENV = "AGENT_SESSION_START_INIT_DELAY_MS";
|
|
10886
10886
|
var DEFAULT_SESSION_START_INIT_DELAY_MS = 500;
|
|
10887
|
+
function isPlayAckMessage(value) {
|
|
10888
|
+
if (!value || typeof value !== "object")
|
|
10889
|
+
return false;
|
|
10890
|
+
const msg = value;
|
|
10891
|
+
return msg.type === "play_ack" && typeof msg.requestId === "string";
|
|
10892
|
+
}
|
|
10893
|
+
function isPlayStatusAckMessage(value) {
|
|
10894
|
+
if (!value || typeof value !== "object")
|
|
10895
|
+
return false;
|
|
10896
|
+
const msg = value;
|
|
10897
|
+
return msg.type === "play_status_ack" && typeof msg.requestId === "string";
|
|
10898
|
+
}
|
|
10899
|
+
function isPlayStopAckMessage(value) {
|
|
10900
|
+
if (!value || typeof value !== "object")
|
|
10901
|
+
return false;
|
|
10902
|
+
const msg = value;
|
|
10903
|
+
return msg.type === "play_stop_ack" && typeof msg.requestId === "string";
|
|
10904
|
+
}
|
|
10887
10905
|
function isRecordingControlAckMessage(value) {
|
|
10888
10906
|
if (!value || typeof value !== "object")
|
|
10889
10907
|
return false;
|
|
@@ -10944,7 +10962,7 @@ function isParentMessage(value) {
|
|
|
10944
10962
|
if (!value || typeof value !== "object")
|
|
10945
10963
|
return false;
|
|
10946
10964
|
const msg = value;
|
|
10947
|
-
return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "recording_control_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "webhook";
|
|
10965
|
+
return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "recording_control_ack" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "webhook";
|
|
10948
10966
|
}
|
|
10949
10967
|
function isSessionScopedParentMessage(value) {
|
|
10950
10968
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -10961,7 +10979,11 @@ var recordingAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
|
10961
10979
|
var mixAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
10962
10980
|
var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
10963
10981
|
var endedSessionIds = /* @__PURE__ */ new Set();
|
|
10982
|
+
var PLAY_BYTES_MAX_DECODED_LENGTH = 64 * 1024;
|
|
10964
10983
|
var pendingRecordingAcks = /* @__PURE__ */ new Map();
|
|
10984
|
+
var pendingPlayAcks = /* @__PURE__ */ new Map();
|
|
10985
|
+
var pendingPlayStatusAcks = /* @__PURE__ */ new Map();
|
|
10986
|
+
var pendingPlayStopAcks = /* @__PURE__ */ new Map();
|
|
10965
10987
|
var pendingMixAcks = /* @__PURE__ */ new Map();
|
|
10966
10988
|
var pendingSttAcks = /* @__PURE__ */ new Map();
|
|
10967
10989
|
function handleRecordingControlAck(message) {
|
|
@@ -10976,6 +10998,46 @@ function handleRecordingControlAck(message) {
|
|
|
10976
10998
|
requestId: message.requestId
|
|
10977
10999
|
});
|
|
10978
11000
|
}
|
|
11001
|
+
function handlePlayAck(message) {
|
|
11002
|
+
const pending = pendingPlayAcks.get(message.requestId);
|
|
11003
|
+
if (!pending)
|
|
11004
|
+
return;
|
|
11005
|
+
clearTimeout(pending.timer);
|
|
11006
|
+
pendingPlayAcks.delete(message.requestId);
|
|
11007
|
+
pending.resolve({
|
|
11008
|
+
ok: message.ok,
|
|
11009
|
+
...message.playId ? { playId: message.playId } : {},
|
|
11010
|
+
reason: message.reason,
|
|
11011
|
+
requestId: message.requestId
|
|
11012
|
+
});
|
|
11013
|
+
}
|
|
11014
|
+
function handlePlayStatusAck(message) {
|
|
11015
|
+
const pending = pendingPlayStatusAcks.get(message.requestId);
|
|
11016
|
+
if (!pending)
|
|
11017
|
+
return;
|
|
11018
|
+
clearTimeout(pending.timer);
|
|
11019
|
+
pendingPlayStatusAcks.delete(message.requestId);
|
|
11020
|
+
pending.resolve({
|
|
11021
|
+
ok: message.ok,
|
|
11022
|
+
playId: message.playId,
|
|
11023
|
+
...message.status ? { status: message.status } : {},
|
|
11024
|
+
reason: message.reason,
|
|
11025
|
+
requestId: message.requestId
|
|
11026
|
+
});
|
|
11027
|
+
}
|
|
11028
|
+
function handlePlayStopAck(message) {
|
|
11029
|
+
const pending = pendingPlayStopAcks.get(message.requestId);
|
|
11030
|
+
if (!pending)
|
|
11031
|
+
return;
|
|
11032
|
+
clearTimeout(pending.timer);
|
|
11033
|
+
pendingPlayStopAcks.delete(message.requestId);
|
|
11034
|
+
pending.resolve({
|
|
11035
|
+
ok: message.ok,
|
|
11036
|
+
playId: message.playId,
|
|
11037
|
+
reason: message.reason,
|
|
11038
|
+
requestId: message.requestId
|
|
11039
|
+
});
|
|
11040
|
+
}
|
|
10979
11041
|
function handleMixControlAck(message) {
|
|
10980
11042
|
const pending = pendingMixAcks.get(message.requestId);
|
|
10981
11043
|
if (!pending)
|
|
@@ -11061,6 +11123,10 @@ function sendParentMessage(message) {
|
|
|
11061
11123
|
process.send?.(message);
|
|
11062
11124
|
return;
|
|
11063
11125
|
}
|
|
11126
|
+
if (msgType === "play" || msgType === "play_status" || msgType === "play_stop") {
|
|
11127
|
+
process.send?.(message);
|
|
11128
|
+
return;
|
|
11129
|
+
}
|
|
11064
11130
|
const sessionId = message && typeof message === "object" && "sessionId" in message && typeof message.sessionId === "string" ? message.sessionId : void 0;
|
|
11065
11131
|
if (!allowOutboundForSession(sessionId))
|
|
11066
11132
|
return;
|
|
@@ -11136,6 +11202,16 @@ async function handleWebhookMessage(message, handlers) {
|
|
|
11136
11202
|
});
|
|
11137
11203
|
}
|
|
11138
11204
|
}
|
|
11205
|
+
function resolveUserLanguageCode(event) {
|
|
11206
|
+
const withLanguage = event;
|
|
11207
|
+
const candidates = [withLanguage.language, event.text];
|
|
11208
|
+
for (const value of candidates) {
|
|
11209
|
+
if (typeof value === "string" && value.trim()) {
|
|
11210
|
+
return value.trim();
|
|
11211
|
+
}
|
|
11212
|
+
}
|
|
11213
|
+
return void 0;
|
|
11214
|
+
}
|
|
11139
11215
|
async function handleParentMessage(message, handlers) {
|
|
11140
11216
|
switch (message.type) {
|
|
11141
11217
|
case "session_start":
|
|
@@ -11168,6 +11244,15 @@ async function handleParentMessage(message, handlers) {
|
|
|
11168
11244
|
text: message.event.text.trim()
|
|
11169
11245
|
});
|
|
11170
11246
|
}
|
|
11247
|
+
if (message.event.type === "user_language") {
|
|
11248
|
+
const language = resolveUserLanguageCode(message.event);
|
|
11249
|
+
if (language) {
|
|
11250
|
+
await handlers.onUserLanguage?.({
|
|
11251
|
+
sessionId: message.sessionId,
|
|
11252
|
+
language
|
|
11253
|
+
});
|
|
11254
|
+
}
|
|
11255
|
+
}
|
|
11171
11256
|
break;
|
|
11172
11257
|
case "data_channel_message":
|
|
11173
11258
|
await handlers.onDataChannelMessage?.({
|
|
@@ -11212,6 +11297,18 @@ function defineAgent(handlers) {
|
|
|
11212
11297
|
handleRecordingControlAck(message);
|
|
11213
11298
|
return;
|
|
11214
11299
|
}
|
|
11300
|
+
if (isPlayAckMessage(message)) {
|
|
11301
|
+
handlePlayAck(message);
|
|
11302
|
+
return;
|
|
11303
|
+
}
|
|
11304
|
+
if (isPlayStatusAckMessage(message)) {
|
|
11305
|
+
handlePlayStatusAck(message);
|
|
11306
|
+
return;
|
|
11307
|
+
}
|
|
11308
|
+
if (isPlayStopAckMessage(message)) {
|
|
11309
|
+
handlePlayStopAck(message);
|
|
11310
|
+
return;
|
|
11311
|
+
}
|
|
11215
11312
|
if (isMixControlAckMessage(message)) {
|
|
11216
11313
|
handleMixControlAck(message);
|
|
11217
11314
|
return;
|
|
@@ -133,6 +133,24 @@ var SessionSerialQueue = class {
|
|
|
133
133
|
var SESSION_START_INIT_DELAY_ENABLED_ENV = "AGENT_SESSION_START_INIT_DELAY_ENABLED";
|
|
134
134
|
var SESSION_START_INIT_DELAY_MS_ENV = "AGENT_SESSION_START_INIT_DELAY_MS";
|
|
135
135
|
var DEFAULT_SESSION_START_INIT_DELAY_MS = 500;
|
|
136
|
+
function isPlayAckMessage(value) {
|
|
137
|
+
if (!value || typeof value !== "object")
|
|
138
|
+
return false;
|
|
139
|
+
const msg = value;
|
|
140
|
+
return msg.type === "play_ack" && typeof msg.requestId === "string";
|
|
141
|
+
}
|
|
142
|
+
function isPlayStatusAckMessage(value) {
|
|
143
|
+
if (!value || typeof value !== "object")
|
|
144
|
+
return false;
|
|
145
|
+
const msg = value;
|
|
146
|
+
return msg.type === "play_status_ack" && typeof msg.requestId === "string";
|
|
147
|
+
}
|
|
148
|
+
function isPlayStopAckMessage(value) {
|
|
149
|
+
if (!value || typeof value !== "object")
|
|
150
|
+
return false;
|
|
151
|
+
const msg = value;
|
|
152
|
+
return msg.type === "play_stop_ack" && typeof msg.requestId === "string";
|
|
153
|
+
}
|
|
136
154
|
function isRecordingControlAckMessage(value) {
|
|
137
155
|
if (!value || typeof value !== "object")
|
|
138
156
|
return false;
|
|
@@ -193,7 +211,7 @@ function isParentMessage(value) {
|
|
|
193
211
|
if (!value || typeof value !== "object")
|
|
194
212
|
return false;
|
|
195
213
|
const msg = value;
|
|
196
|
-
return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "recording_control_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "webhook";
|
|
214
|
+
return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "recording_control_ack" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "webhook";
|
|
197
215
|
}
|
|
198
216
|
function isSessionScopedParentMessage(value) {
|
|
199
217
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -210,7 +228,11 @@ var recordingAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
|
210
228
|
var mixAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
211
229
|
var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
212
230
|
var endedSessionIds = /* @__PURE__ */ new Set();
|
|
231
|
+
var PLAY_BYTES_MAX_DECODED_LENGTH = 64 * 1024;
|
|
213
232
|
var pendingRecordingAcks = /* @__PURE__ */ new Map();
|
|
233
|
+
var pendingPlayAcks = /* @__PURE__ */ new Map();
|
|
234
|
+
var pendingPlayStatusAcks = /* @__PURE__ */ new Map();
|
|
235
|
+
var pendingPlayStopAcks = /* @__PURE__ */ new Map();
|
|
214
236
|
var MIX_CONTROL_ACK_TIMEOUT_MS = 5e3;
|
|
215
237
|
var pendingMixAcks = /* @__PURE__ */ new Map();
|
|
216
238
|
var pendingSttAcks = /* @__PURE__ */ new Map();
|
|
@@ -226,6 +248,46 @@ function handleRecordingControlAck(message) {
|
|
|
226
248
|
requestId: message.requestId
|
|
227
249
|
});
|
|
228
250
|
}
|
|
251
|
+
function handlePlayAck(message) {
|
|
252
|
+
const pending = pendingPlayAcks.get(message.requestId);
|
|
253
|
+
if (!pending)
|
|
254
|
+
return;
|
|
255
|
+
clearTimeout(pending.timer);
|
|
256
|
+
pendingPlayAcks.delete(message.requestId);
|
|
257
|
+
pending.resolve({
|
|
258
|
+
ok: message.ok,
|
|
259
|
+
...message.playId ? { playId: message.playId } : {},
|
|
260
|
+
reason: message.reason,
|
|
261
|
+
requestId: message.requestId
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
function handlePlayStatusAck(message) {
|
|
265
|
+
const pending = pendingPlayStatusAcks.get(message.requestId);
|
|
266
|
+
if (!pending)
|
|
267
|
+
return;
|
|
268
|
+
clearTimeout(pending.timer);
|
|
269
|
+
pendingPlayStatusAcks.delete(message.requestId);
|
|
270
|
+
pending.resolve({
|
|
271
|
+
ok: message.ok,
|
|
272
|
+
playId: message.playId,
|
|
273
|
+
...message.status ? { status: message.status } : {},
|
|
274
|
+
reason: message.reason,
|
|
275
|
+
requestId: message.requestId
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
function handlePlayStopAck(message) {
|
|
279
|
+
const pending = pendingPlayStopAcks.get(message.requestId);
|
|
280
|
+
if (!pending)
|
|
281
|
+
return;
|
|
282
|
+
clearTimeout(pending.timer);
|
|
283
|
+
pendingPlayStopAcks.delete(message.requestId);
|
|
284
|
+
pending.resolve({
|
|
285
|
+
ok: message.ok,
|
|
286
|
+
playId: message.playId,
|
|
287
|
+
reason: message.reason,
|
|
288
|
+
requestId: message.requestId
|
|
289
|
+
});
|
|
290
|
+
}
|
|
229
291
|
function handleMixControlAck(message) {
|
|
230
292
|
const pending = pendingMixAcks.get(message.requestId);
|
|
231
293
|
if (!pending)
|
|
@@ -326,6 +388,10 @@ function sendParentMessage(message) {
|
|
|
326
388
|
process.send?.(message);
|
|
327
389
|
return;
|
|
328
390
|
}
|
|
391
|
+
if (msgType === "play" || msgType === "play_status" || msgType === "play_stop") {
|
|
392
|
+
process.send?.(message);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
329
395
|
const sessionId = message && typeof message === "object" && "sessionId" in message && typeof message.sessionId === "string" ? message.sessionId : void 0;
|
|
330
396
|
if (!allowOutboundForSession(sessionId))
|
|
331
397
|
return;
|
|
@@ -401,6 +467,16 @@ async function handleWebhookMessage(message, handlers) {
|
|
|
401
467
|
});
|
|
402
468
|
}
|
|
403
469
|
}
|
|
470
|
+
function resolveUserLanguageCode(event) {
|
|
471
|
+
const withLanguage = event;
|
|
472
|
+
const candidates = [withLanguage.language, event.text];
|
|
473
|
+
for (const value of candidates) {
|
|
474
|
+
if (typeof value === "string" && value.trim()) {
|
|
475
|
+
return value.trim();
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
return void 0;
|
|
479
|
+
}
|
|
404
480
|
async function handleParentMessage(message, handlers) {
|
|
405
481
|
switch (message.type) {
|
|
406
482
|
case "session_start":
|
|
@@ -433,6 +509,15 @@ async function handleParentMessage(message, handlers) {
|
|
|
433
509
|
text: message.event.text.trim()
|
|
434
510
|
});
|
|
435
511
|
}
|
|
512
|
+
if (message.event.type === "user_language") {
|
|
513
|
+
const language = resolveUserLanguageCode(message.event);
|
|
514
|
+
if (language) {
|
|
515
|
+
await handlers.onUserLanguage?.({
|
|
516
|
+
sessionId: message.sessionId,
|
|
517
|
+
language
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
}
|
|
436
521
|
break;
|
|
437
522
|
case "data_channel_message":
|
|
438
523
|
await handlers.onDataChannelMessage?.({
|
|
@@ -477,6 +562,18 @@ function defineAgent(handlers) {
|
|
|
477
562
|
handleRecordingControlAck(message);
|
|
478
563
|
return;
|
|
479
564
|
}
|
|
565
|
+
if (isPlayAckMessage(message)) {
|
|
566
|
+
handlePlayAck(message);
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
if (isPlayStatusAckMessage(message)) {
|
|
570
|
+
handlePlayStatusAck(message);
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
if (isPlayStopAckMessage(message)) {
|
|
574
|
+
handlePlayStopAck(message);
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
480
577
|
if (isMixControlAckMessage(message)) {
|
|
481
578
|
handleMixControlAck(message);
|
|
482
579
|
return;
|
|
@@ -130,6 +130,24 @@ var SessionSerialQueue = class {
|
|
|
130
130
|
var SESSION_START_INIT_DELAY_ENABLED_ENV = "AGENT_SESSION_START_INIT_DELAY_ENABLED";
|
|
131
131
|
var SESSION_START_INIT_DELAY_MS_ENV = "AGENT_SESSION_START_INIT_DELAY_MS";
|
|
132
132
|
var DEFAULT_SESSION_START_INIT_DELAY_MS = 500;
|
|
133
|
+
function isPlayAckMessage(value) {
|
|
134
|
+
if (!value || typeof value !== "object")
|
|
135
|
+
return false;
|
|
136
|
+
const msg = value;
|
|
137
|
+
return msg.type === "play_ack" && typeof msg.requestId === "string";
|
|
138
|
+
}
|
|
139
|
+
function isPlayStatusAckMessage(value) {
|
|
140
|
+
if (!value || typeof value !== "object")
|
|
141
|
+
return false;
|
|
142
|
+
const msg = value;
|
|
143
|
+
return msg.type === "play_status_ack" && typeof msg.requestId === "string";
|
|
144
|
+
}
|
|
145
|
+
function isPlayStopAckMessage(value) {
|
|
146
|
+
if (!value || typeof value !== "object")
|
|
147
|
+
return false;
|
|
148
|
+
const msg = value;
|
|
149
|
+
return msg.type === "play_stop_ack" && typeof msg.requestId === "string";
|
|
150
|
+
}
|
|
133
151
|
function isRecordingControlAckMessage(value) {
|
|
134
152
|
if (!value || typeof value !== "object")
|
|
135
153
|
return false;
|
|
@@ -190,7 +208,7 @@ function isParentMessage(value) {
|
|
|
190
208
|
if (!value || typeof value !== "object")
|
|
191
209
|
return false;
|
|
192
210
|
const msg = value;
|
|
193
|
-
return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "recording_control_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "webhook";
|
|
211
|
+
return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "recording_control_ack" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "webhook";
|
|
194
212
|
}
|
|
195
213
|
function isSessionScopedParentMessage(value) {
|
|
196
214
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -208,7 +226,11 @@ var mixAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
|
208
226
|
var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
209
227
|
var endedSessionIds = /* @__PURE__ */ new Set();
|
|
210
228
|
var RECORDING_CONTROL_ACK_TIMEOUT_MS = 5e3;
|
|
229
|
+
var PLAY_BYTES_MAX_DECODED_LENGTH = 64 * 1024;
|
|
211
230
|
var pendingRecordingAcks = /* @__PURE__ */ new Map();
|
|
231
|
+
var pendingPlayAcks = /* @__PURE__ */ new Map();
|
|
232
|
+
var pendingPlayStatusAcks = /* @__PURE__ */ new Map();
|
|
233
|
+
var pendingPlayStopAcks = /* @__PURE__ */ new Map();
|
|
212
234
|
var pendingMixAcks = /* @__PURE__ */ new Map();
|
|
213
235
|
var pendingSttAcks = /* @__PURE__ */ new Map();
|
|
214
236
|
function handleRecordingControlAck(message) {
|
|
@@ -223,6 +245,46 @@ function handleRecordingControlAck(message) {
|
|
|
223
245
|
requestId: message.requestId
|
|
224
246
|
});
|
|
225
247
|
}
|
|
248
|
+
function handlePlayAck(message) {
|
|
249
|
+
const pending = pendingPlayAcks.get(message.requestId);
|
|
250
|
+
if (!pending)
|
|
251
|
+
return;
|
|
252
|
+
clearTimeout(pending.timer);
|
|
253
|
+
pendingPlayAcks.delete(message.requestId);
|
|
254
|
+
pending.resolve({
|
|
255
|
+
ok: message.ok,
|
|
256
|
+
...message.playId ? { playId: message.playId } : {},
|
|
257
|
+
reason: message.reason,
|
|
258
|
+
requestId: message.requestId
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
function handlePlayStatusAck(message) {
|
|
262
|
+
const pending = pendingPlayStatusAcks.get(message.requestId);
|
|
263
|
+
if (!pending)
|
|
264
|
+
return;
|
|
265
|
+
clearTimeout(pending.timer);
|
|
266
|
+
pendingPlayStatusAcks.delete(message.requestId);
|
|
267
|
+
pending.resolve({
|
|
268
|
+
ok: message.ok,
|
|
269
|
+
playId: message.playId,
|
|
270
|
+
...message.status ? { status: message.status } : {},
|
|
271
|
+
reason: message.reason,
|
|
272
|
+
requestId: message.requestId
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
function handlePlayStopAck(message) {
|
|
276
|
+
const pending = pendingPlayStopAcks.get(message.requestId);
|
|
277
|
+
if (!pending)
|
|
278
|
+
return;
|
|
279
|
+
clearTimeout(pending.timer);
|
|
280
|
+
pendingPlayStopAcks.delete(message.requestId);
|
|
281
|
+
pending.resolve({
|
|
282
|
+
ok: message.ok,
|
|
283
|
+
playId: message.playId,
|
|
284
|
+
reason: message.reason,
|
|
285
|
+
requestId: message.requestId
|
|
286
|
+
});
|
|
287
|
+
}
|
|
226
288
|
function handleMixControlAck(message) {
|
|
227
289
|
const pending = pendingMixAcks.get(message.requestId);
|
|
228
290
|
if (!pending)
|
|
@@ -311,6 +373,10 @@ function sendParentMessage(message) {
|
|
|
311
373
|
process.send?.(message);
|
|
312
374
|
return;
|
|
313
375
|
}
|
|
376
|
+
if (msgType === "play" || msgType === "play_status" || msgType === "play_stop") {
|
|
377
|
+
process.send?.(message);
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
314
380
|
const sessionId = message && typeof message === "object" && "sessionId" in message && typeof message.sessionId === "string" ? message.sessionId : void 0;
|
|
315
381
|
if (!allowOutboundForSession(sessionId))
|
|
316
382
|
return;
|
|
@@ -386,6 +452,16 @@ async function handleWebhookMessage(message, handlers) {
|
|
|
386
452
|
});
|
|
387
453
|
}
|
|
388
454
|
}
|
|
455
|
+
function resolveUserLanguageCode(event) {
|
|
456
|
+
const withLanguage = event;
|
|
457
|
+
const candidates = [withLanguage.language, event.text];
|
|
458
|
+
for (const value of candidates) {
|
|
459
|
+
if (typeof value === "string" && value.trim()) {
|
|
460
|
+
return value.trim();
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return void 0;
|
|
464
|
+
}
|
|
389
465
|
async function handleParentMessage(message, handlers) {
|
|
390
466
|
switch (message.type) {
|
|
391
467
|
case "session_start":
|
|
@@ -418,6 +494,15 @@ async function handleParentMessage(message, handlers) {
|
|
|
418
494
|
text: message.event.text.trim()
|
|
419
495
|
});
|
|
420
496
|
}
|
|
497
|
+
if (message.event.type === "user_language") {
|
|
498
|
+
const language = resolveUserLanguageCode(message.event);
|
|
499
|
+
if (language) {
|
|
500
|
+
await handlers.onUserLanguage?.({
|
|
501
|
+
sessionId: message.sessionId,
|
|
502
|
+
language
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
}
|
|
421
506
|
break;
|
|
422
507
|
case "data_channel_message":
|
|
423
508
|
await handlers.onDataChannelMessage?.({
|
|
@@ -462,6 +547,18 @@ function defineAgent(handlers) {
|
|
|
462
547
|
handleRecordingControlAck(message);
|
|
463
548
|
return;
|
|
464
549
|
}
|
|
550
|
+
if (isPlayAckMessage(message)) {
|
|
551
|
+
handlePlayAck(message);
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
if (isPlayStatusAckMessage(message)) {
|
|
555
|
+
handlePlayStatusAck(message);
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
if (isPlayStopAckMessage(message)) {
|
|
559
|
+
handlePlayStopAck(message);
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
465
562
|
if (isMixControlAckMessage(message)) {
|
|
466
563
|
handleMixControlAck(message);
|
|
467
564
|
return;
|