@voicethere/agent 0.29.0 → 0.29.3
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 +3 -1
- package/dist/agent.js +61 -5
- package/dist/flow/effects-node.d.ts.map +1 -1
- package/dist/flow/effects-node.js +5 -1
- package/dist/flow/effects-node.js.map +1 -1
- package/dist/llm/agent/create-llm-agent.d.ts.map +1 -1
- package/dist/llm/agent/create-llm-agent.js +14 -31
- package/dist/llm/agent/create-llm-agent.js.map +1 -1
- package/dist/protocol.d.ts +16 -3
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +75 -4
- package/dist/runtime.js.map +1 -1
- package/dist/templates/echo/agent.js +59 -2
- package/dist/templates/echo-dc/agent.js +59 -2
- package/dist/templates/flow-agent/agent.js +64 -3
- package/dist/templates/game-sync/agent.js +59 -2
- package/dist/templates/language-switch/agent.js +59 -2
- package/dist/templates/llm-agent/agent.js +71 -30
- package/dist/templates/llm-docs-rag/agent.js +71 -30
- package/dist/templates/llm-mcp-service/agent.js +71 -30
- package/dist/templates/llm-support-sticky-user/agent.js +71 -30
- package/dist/templates/positional-tts/agent.js +59 -2
- package/dist/templates/recording-consent/agent.js +59 -2
- package/dist/templates/spatial-showcase/agent.js +59 -2
- package/dist/templates/speaker-gate/agent.js +61 -4
- package/dist/templates/voice-showcase/agent.js +59 -2
- package/dist/templates/voice-starter/agent.js +59 -2
- package/dist/templates/webhooks/agent.js +59 -2
- package/dist/templates/webhooks-redis/agent.js +59 -2
- package/dist/templates/world-sync/agent.js +59 -2
- package/dist/templates/world-sync-binary/agent.js +59 -2
- package/eject/llm/loop.ts +16 -38
- package/package.json +1 -1
- package/templates/README.md +5 -5
- package/templates/llm-agent/README.md +5 -1
- package/templates/speaker-gate/README.md +3 -1
- package/templates/speaker-gate/agent.ts +5 -1
|
@@ -241,6 +241,12 @@ function isSetSpeakerGateResultMessage(value) {
|
|
|
241
241
|
const msg = value;
|
|
242
242
|
return msg.type === "setSpeakerGateResult" && typeof msg.requestId === "string";
|
|
243
243
|
}
|
|
244
|
+
function isSpeakerGateStateMessage(value) {
|
|
245
|
+
if (!value || typeof value !== "object")
|
|
246
|
+
return false;
|
|
247
|
+
const msg = value;
|
|
248
|
+
return msg.type === "speaker_gate_state" && typeof msg.sessionId === "string" && typeof msg.mode === "string" && SPEAKER_GATE_MODES.includes(msg.mode) && (msg.bargeIn === void 0 || typeof msg.bargeIn === "string" && SPEAKER_GATE_BARGE_IN.includes(msg.bargeIn));
|
|
249
|
+
}
|
|
244
250
|
function isResetSpeakerEnrollmentResultMessage(value) {
|
|
245
251
|
if (!value || typeof value !== "object")
|
|
246
252
|
return false;
|
|
@@ -295,7 +301,7 @@ function isParentMessage(value) {
|
|
|
295
301
|
if (!value || typeof value !== "object")
|
|
296
302
|
return false;
|
|
297
303
|
const msg = value;
|
|
298
|
-
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 === "session_time_limit" || msg.type === "session_time_limit_control_ack" || msg.type === "recording_control_ack" || msg.type === "conversation_history_control_ack" || msg.type === "user_identified" || msg.type === "user_history_response" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "play_pose_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "voice_language_control_ack" || msg.type === "voice_language_prepare_result" || msg.type === "voice_replay_last_result" || msg.type === "setSpeakerGateResult" || msg.type === "resetSpeakerEnrollmentResult" || msg.type === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
|
|
304
|
+
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 === "session_time_limit" || msg.type === "session_time_limit_control_ack" || msg.type === "recording_control_ack" || msg.type === "conversation_history_control_ack" || msg.type === "user_identified" || msg.type === "user_history_response" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "play_pose_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "voice_language_control_ack" || msg.type === "voice_language_prepare_result" || msg.type === "voice_replay_last_result" || msg.type === "setSpeakerGateResult" || msg.type === "resetSpeakerEnrollmentResult" || msg.type === "speaker_gate_state" || msg.type === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
|
|
299
305
|
}
|
|
300
306
|
function isSessionScopedParentMessage(value) {
|
|
301
307
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -317,6 +323,7 @@ var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
|
|
|
317
323
|
var speakerGateBySessionId = /* @__PURE__ */ new Map();
|
|
318
324
|
var SPEAKER_GATE_ACK_TIMEOUT_MS = 1e4;
|
|
319
325
|
var pendingSpeakerGateAcks = /* @__PURE__ */ new Map();
|
|
326
|
+
var pendingSpeakerGateStateBySessionId = /* @__PURE__ */ new Map();
|
|
320
327
|
var pendingSpeakerResets = /* @__PURE__ */ new Map();
|
|
321
328
|
var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
322
329
|
var speakControlAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
@@ -605,6 +612,41 @@ function handleResetSpeakerEnrollmentResult(message) {
|
|
|
605
612
|
pendingSpeakerResets.delete(message.requestId);
|
|
606
613
|
pending.resolve(message.ok ? { ok: true } : { ok: false, reason: message.reason });
|
|
607
614
|
}
|
|
615
|
+
function applySpeakerGateState(prev, message) {
|
|
616
|
+
return {
|
|
617
|
+
available: true,
|
|
618
|
+
mode: message.mode,
|
|
619
|
+
bargeIn: message.bargeIn ?? prev.bargeIn
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
function handleSpeakerGateState(message) {
|
|
623
|
+
if (endedSessionIds.has(message.sessionId))
|
|
624
|
+
return;
|
|
625
|
+
const prev = speakerGateBySessionId.get(message.sessionId);
|
|
626
|
+
if (prev) {
|
|
627
|
+
if (prev.available) {
|
|
628
|
+
speakerGateBySessionId.set(message.sessionId, applySpeakerGateState(prev, message));
|
|
629
|
+
}
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
pendingSpeakerGateStateBySessionId.set(message.sessionId, message);
|
|
633
|
+
}
|
|
634
|
+
function clearPendingSpeakerRequestsForSession(sessionId, reason) {
|
|
635
|
+
for (const [requestId, pending] of pendingSpeakerGateAcks) {
|
|
636
|
+
if (pending.sessionId !== sessionId)
|
|
637
|
+
continue;
|
|
638
|
+
clearTimeout(pending.timer);
|
|
639
|
+
pendingSpeakerGateAcks.delete(requestId);
|
|
640
|
+
pending.resolve({ ok: false, reason });
|
|
641
|
+
}
|
|
642
|
+
for (const [requestId, pending] of pendingSpeakerResets) {
|
|
643
|
+
if (pending.sessionId !== sessionId)
|
|
644
|
+
continue;
|
|
645
|
+
clearTimeout(pending.timer);
|
|
646
|
+
pendingSpeakerResets.delete(requestId);
|
|
647
|
+
pending.resolve({ ok: false, reason });
|
|
648
|
+
}
|
|
649
|
+
}
|
|
608
650
|
function handleVoiceReplayLastResult(message) {
|
|
609
651
|
const pending = pendingVoiceReplays.get(message.requestId);
|
|
610
652
|
if (!pending)
|
|
@@ -834,7 +876,12 @@ async function handleParentMessage(message, handlers) {
|
|
|
834
876
|
speakControlAvailableBySessionId.set(message.sessionId, message.speakControlAvailable ?? false);
|
|
835
877
|
chatReplyRecordAvailableBySessionId.set(message.sessionId, message.chatReplyRecordAvailable ?? false);
|
|
836
878
|
sessionTimeLimitAvailableBySessionId.set(message.sessionId, message.sessionTimeLimitAvailable ?? false);
|
|
837
|
-
|
|
879
|
+
{
|
|
880
|
+
const initial = message.speakerGate?.available === true ? message.speakerGate : { available: false };
|
|
881
|
+
const early = pendingSpeakerGateStateBySessionId.get(message.sessionId);
|
|
882
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
883
|
+
speakerGateBySessionId.set(message.sessionId, early && initial.available ? applySpeakerGateState(initial, early) : initial);
|
|
884
|
+
}
|
|
838
885
|
if (message.voiceLanguageSwitch) {
|
|
839
886
|
voiceLanguageSwitchSettingsBySessionId.set(message.sessionId, message.voiceLanguageSwitch);
|
|
840
887
|
} else {
|
|
@@ -961,6 +1008,8 @@ async function handleParentMessage(message, handlers) {
|
|
|
961
1008
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
962
1009
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
963
1010
|
speakerGateBySessionId.delete(message.sessionId);
|
|
1011
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
1012
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
964
1013
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
965
1014
|
lastVoiceLanguageBySessionId.delete(message.sessionId);
|
|
966
1015
|
ttsPoseAvailableBySessionId.delete(message.sessionId);
|
|
@@ -1054,6 +1103,10 @@ function defineAgent(handlers) {
|
|
|
1054
1103
|
handleResetSpeakerEnrollmentResult(message);
|
|
1055
1104
|
return;
|
|
1056
1105
|
}
|
|
1106
|
+
if (isSpeakerGateStateMessage(message)) {
|
|
1107
|
+
handleSpeakerGateState(message);
|
|
1108
|
+
return;
|
|
1109
|
+
}
|
|
1057
1110
|
if (isWebhookMessage(message)) {
|
|
1058
1111
|
void agentStartReady.then(() => handleWebhookMessage(message, handlers));
|
|
1059
1112
|
return;
|
|
@@ -1062,6 +1115,8 @@ function defineAgent(handlers) {
|
|
|
1062
1115
|
return;
|
|
1063
1116
|
if (message.type === "session_end") {
|
|
1064
1117
|
endedSessionIds.add(message.sessionId);
|
|
1118
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
1119
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
1065
1120
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
1066
1121
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
1067
1122
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
@@ -1391,7 +1446,7 @@ function resetSpeakerEnrollment(sessionId) {
|
|
|
1391
1446
|
pendingSpeakerResets.delete(requestId);
|
|
1392
1447
|
resolve({ ok: false, reason: "timeout" });
|
|
1393
1448
|
}, SPEAKER_GATE_ACK_TIMEOUT_MS);
|
|
1394
|
-
pendingSpeakerResets.set(requestId, { resolve, timer });
|
|
1449
|
+
pendingSpeakerResets.set(requestId, { sessionId, resolve, timer });
|
|
1395
1450
|
sendParentMessage({
|
|
1396
1451
|
type: "resetSpeakerEnrollment",
|
|
1397
1452
|
requestId,
|
|
@@ -1523,10 +1578,12 @@ defineAgent({
|
|
|
1523
1578
|
);
|
|
1524
1579
|
},
|
|
1525
1580
|
async onUserSpeechFinal(ctx) {
|
|
1581
|
+
const utterance = ctx.utteranceId ? ` utteranceId=${ctx.utteranceId}` : "";
|
|
1582
|
+
const reason = ctx.speakerUnknownReason ? ` reason=${ctx.speakerUnknownReason}` : "";
|
|
1526
1583
|
logLine(
|
|
1527
1584
|
ctx.sessionId,
|
|
1528
1585
|
"final",
|
|
1529
|
-
`speaker=${ctx.speaker ?? "none"} text=${JSON.stringify(ctx.text)}`
|
|
1586
|
+
`speaker=${ctx.speaker ?? "none"}${utterance}${reason} text=${JSON.stringify(ctx.text)}`
|
|
1530
1587
|
);
|
|
1531
1588
|
const spoken = parseSpokenCommand(ctx.text);
|
|
1532
1589
|
if (spoken && ctx.speaker !== "other") {
|
|
@@ -241,6 +241,12 @@ function isSetSpeakerGateResultMessage(value) {
|
|
|
241
241
|
const msg = value;
|
|
242
242
|
return msg.type === "setSpeakerGateResult" && typeof msg.requestId === "string";
|
|
243
243
|
}
|
|
244
|
+
function isSpeakerGateStateMessage(value) {
|
|
245
|
+
if (!value || typeof value !== "object")
|
|
246
|
+
return false;
|
|
247
|
+
const msg = value;
|
|
248
|
+
return msg.type === "speaker_gate_state" && typeof msg.sessionId === "string" && typeof msg.mode === "string" && SPEAKER_GATE_MODES.includes(msg.mode) && (msg.bargeIn === void 0 || typeof msg.bargeIn === "string" && SPEAKER_GATE_BARGE_IN.includes(msg.bargeIn));
|
|
249
|
+
}
|
|
244
250
|
function isResetSpeakerEnrollmentResultMessage(value) {
|
|
245
251
|
if (!value || typeof value !== "object")
|
|
246
252
|
return false;
|
|
@@ -295,7 +301,7 @@ function isParentMessage(value) {
|
|
|
295
301
|
if (!value || typeof value !== "object")
|
|
296
302
|
return false;
|
|
297
303
|
const msg = value;
|
|
298
|
-
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 === "session_time_limit" || msg.type === "session_time_limit_control_ack" || msg.type === "recording_control_ack" || msg.type === "conversation_history_control_ack" || msg.type === "user_identified" || msg.type === "user_history_response" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "play_pose_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "voice_language_control_ack" || msg.type === "voice_language_prepare_result" || msg.type === "voice_replay_last_result" || msg.type === "setSpeakerGateResult" || msg.type === "resetSpeakerEnrollmentResult" || msg.type === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
|
|
304
|
+
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 === "session_time_limit" || msg.type === "session_time_limit_control_ack" || msg.type === "recording_control_ack" || msg.type === "conversation_history_control_ack" || msg.type === "user_identified" || msg.type === "user_history_response" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "play_pose_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "voice_language_control_ack" || msg.type === "voice_language_prepare_result" || msg.type === "voice_replay_last_result" || msg.type === "setSpeakerGateResult" || msg.type === "resetSpeakerEnrollmentResult" || msg.type === "speaker_gate_state" || msg.type === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
|
|
299
305
|
}
|
|
300
306
|
function isSessionScopedParentMessage(value) {
|
|
301
307
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -316,6 +322,7 @@ var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
|
316
322
|
var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
|
|
317
323
|
var speakerGateBySessionId = /* @__PURE__ */ new Map();
|
|
318
324
|
var pendingSpeakerGateAcks = /* @__PURE__ */ new Map();
|
|
325
|
+
var pendingSpeakerGateStateBySessionId = /* @__PURE__ */ new Map();
|
|
319
326
|
var pendingSpeakerResets = /* @__PURE__ */ new Map();
|
|
320
327
|
var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
321
328
|
var speakControlAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
@@ -604,6 +611,41 @@ function handleResetSpeakerEnrollmentResult(message) {
|
|
|
604
611
|
pendingSpeakerResets.delete(message.requestId);
|
|
605
612
|
pending.resolve(message.ok ? { ok: true } : { ok: false, reason: message.reason });
|
|
606
613
|
}
|
|
614
|
+
function applySpeakerGateState(prev, message) {
|
|
615
|
+
return {
|
|
616
|
+
available: true,
|
|
617
|
+
mode: message.mode,
|
|
618
|
+
bargeIn: message.bargeIn ?? prev.bargeIn
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
function handleSpeakerGateState(message) {
|
|
622
|
+
if (endedSessionIds.has(message.sessionId))
|
|
623
|
+
return;
|
|
624
|
+
const prev = speakerGateBySessionId.get(message.sessionId);
|
|
625
|
+
if (prev) {
|
|
626
|
+
if (prev.available) {
|
|
627
|
+
speakerGateBySessionId.set(message.sessionId, applySpeakerGateState(prev, message));
|
|
628
|
+
}
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
pendingSpeakerGateStateBySessionId.set(message.sessionId, message);
|
|
632
|
+
}
|
|
633
|
+
function clearPendingSpeakerRequestsForSession(sessionId, reason) {
|
|
634
|
+
for (const [requestId, pending] of pendingSpeakerGateAcks) {
|
|
635
|
+
if (pending.sessionId !== sessionId)
|
|
636
|
+
continue;
|
|
637
|
+
clearTimeout(pending.timer);
|
|
638
|
+
pendingSpeakerGateAcks.delete(requestId);
|
|
639
|
+
pending.resolve({ ok: false, reason });
|
|
640
|
+
}
|
|
641
|
+
for (const [requestId, pending] of pendingSpeakerResets) {
|
|
642
|
+
if (pending.sessionId !== sessionId)
|
|
643
|
+
continue;
|
|
644
|
+
clearTimeout(pending.timer);
|
|
645
|
+
pendingSpeakerResets.delete(requestId);
|
|
646
|
+
pending.resolve({ ok: false, reason });
|
|
647
|
+
}
|
|
648
|
+
}
|
|
607
649
|
function handleVoiceReplayLastResult(message) {
|
|
608
650
|
const pending = pendingVoiceReplays.get(message.requestId);
|
|
609
651
|
if (!pending)
|
|
@@ -833,7 +875,12 @@ async function handleParentMessage(message, handlers) {
|
|
|
833
875
|
speakControlAvailableBySessionId.set(message.sessionId, message.speakControlAvailable ?? false);
|
|
834
876
|
chatReplyRecordAvailableBySessionId.set(message.sessionId, message.chatReplyRecordAvailable ?? false);
|
|
835
877
|
sessionTimeLimitAvailableBySessionId.set(message.sessionId, message.sessionTimeLimitAvailable ?? false);
|
|
836
|
-
|
|
878
|
+
{
|
|
879
|
+
const initial = message.speakerGate?.available === true ? message.speakerGate : { available: false };
|
|
880
|
+
const early = pendingSpeakerGateStateBySessionId.get(message.sessionId);
|
|
881
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
882
|
+
speakerGateBySessionId.set(message.sessionId, early && initial.available ? applySpeakerGateState(initial, early) : initial);
|
|
883
|
+
}
|
|
837
884
|
if (message.voiceLanguageSwitch) {
|
|
838
885
|
voiceLanguageSwitchSettingsBySessionId.set(message.sessionId, message.voiceLanguageSwitch);
|
|
839
886
|
} else {
|
|
@@ -960,6 +1007,8 @@ async function handleParentMessage(message, handlers) {
|
|
|
960
1007
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
961
1008
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
962
1009
|
speakerGateBySessionId.delete(message.sessionId);
|
|
1010
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
1011
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
963
1012
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
964
1013
|
lastVoiceLanguageBySessionId.delete(message.sessionId);
|
|
965
1014
|
ttsPoseAvailableBySessionId.delete(message.sessionId);
|
|
@@ -1053,6 +1102,10 @@ function defineAgent(handlers) {
|
|
|
1053
1102
|
handleResetSpeakerEnrollmentResult(message);
|
|
1054
1103
|
return;
|
|
1055
1104
|
}
|
|
1105
|
+
if (isSpeakerGateStateMessage(message)) {
|
|
1106
|
+
handleSpeakerGateState(message);
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1056
1109
|
if (isWebhookMessage(message)) {
|
|
1057
1110
|
void agentStartReady.then(() => handleWebhookMessage(message, handlers));
|
|
1058
1111
|
return;
|
|
@@ -1061,6 +1114,8 @@ function defineAgent(handlers) {
|
|
|
1061
1114
|
return;
|
|
1062
1115
|
if (message.type === "session_end") {
|
|
1063
1116
|
endedSessionIds.add(message.sessionId);
|
|
1117
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
1118
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
1064
1119
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
1065
1120
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
1066
1121
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
@@ -1364,6 +1419,8 @@ function speakAndChat(sessionId, text, options) {
|
|
|
1364
1419
|
sendToClient(sessionId, payload);
|
|
1365
1420
|
return speak(sessionId, trimmed);
|
|
1366
1421
|
}
|
|
1422
|
+
var SPEAKER_GATE_MODES = ["disabled", "auto", "manual"];
|
|
1423
|
+
var SPEAKER_GATE_BARGE_IN = ["caller_only", "anyone"];
|
|
1367
1424
|
function sendToClient(sessionId, payload) {
|
|
1368
1425
|
sendParentMessage({ type: "send_to_client", sessionId, payload });
|
|
1369
1426
|
}
|
|
@@ -241,6 +241,12 @@ function isSetSpeakerGateResultMessage(value) {
|
|
|
241
241
|
const msg = value;
|
|
242
242
|
return msg.type === "setSpeakerGateResult" && typeof msg.requestId === "string";
|
|
243
243
|
}
|
|
244
|
+
function isSpeakerGateStateMessage(value) {
|
|
245
|
+
if (!value || typeof value !== "object")
|
|
246
|
+
return false;
|
|
247
|
+
const msg = value;
|
|
248
|
+
return msg.type === "speaker_gate_state" && typeof msg.sessionId === "string" && typeof msg.mode === "string" && SPEAKER_GATE_MODES.includes(msg.mode) && (msg.bargeIn === void 0 || typeof msg.bargeIn === "string" && SPEAKER_GATE_BARGE_IN.includes(msg.bargeIn));
|
|
249
|
+
}
|
|
244
250
|
function isResetSpeakerEnrollmentResultMessage(value) {
|
|
245
251
|
if (!value || typeof value !== "object")
|
|
246
252
|
return false;
|
|
@@ -295,7 +301,7 @@ function isParentMessage(value) {
|
|
|
295
301
|
if (!value || typeof value !== "object")
|
|
296
302
|
return false;
|
|
297
303
|
const msg = value;
|
|
298
|
-
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 === "session_time_limit" || msg.type === "session_time_limit_control_ack" || msg.type === "recording_control_ack" || msg.type === "conversation_history_control_ack" || msg.type === "user_identified" || msg.type === "user_history_response" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "play_pose_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "voice_language_control_ack" || msg.type === "voice_language_prepare_result" || msg.type === "voice_replay_last_result" || msg.type === "setSpeakerGateResult" || msg.type === "resetSpeakerEnrollmentResult" || msg.type === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
|
|
304
|
+
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 === "session_time_limit" || msg.type === "session_time_limit_control_ack" || msg.type === "recording_control_ack" || msg.type === "conversation_history_control_ack" || msg.type === "user_identified" || msg.type === "user_history_response" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "play_pose_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "voice_language_control_ack" || msg.type === "voice_language_prepare_result" || msg.type === "voice_replay_last_result" || msg.type === "setSpeakerGateResult" || msg.type === "resetSpeakerEnrollmentResult" || msg.type === "speaker_gate_state" || msg.type === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
|
|
299
305
|
}
|
|
300
306
|
function isSessionScopedParentMessage(value) {
|
|
301
307
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -316,6 +322,7 @@ var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
|
316
322
|
var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
|
|
317
323
|
var speakerGateBySessionId = /* @__PURE__ */ new Map();
|
|
318
324
|
var pendingSpeakerGateAcks = /* @__PURE__ */ new Map();
|
|
325
|
+
var pendingSpeakerGateStateBySessionId = /* @__PURE__ */ new Map();
|
|
319
326
|
var pendingSpeakerResets = /* @__PURE__ */ new Map();
|
|
320
327
|
var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
321
328
|
var speakControlAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
@@ -604,6 +611,41 @@ function handleResetSpeakerEnrollmentResult(message) {
|
|
|
604
611
|
pendingSpeakerResets.delete(message.requestId);
|
|
605
612
|
pending.resolve(message.ok ? { ok: true } : { ok: false, reason: message.reason });
|
|
606
613
|
}
|
|
614
|
+
function applySpeakerGateState(prev, message) {
|
|
615
|
+
return {
|
|
616
|
+
available: true,
|
|
617
|
+
mode: message.mode,
|
|
618
|
+
bargeIn: message.bargeIn ?? prev.bargeIn
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
function handleSpeakerGateState(message) {
|
|
622
|
+
if (endedSessionIds.has(message.sessionId))
|
|
623
|
+
return;
|
|
624
|
+
const prev = speakerGateBySessionId.get(message.sessionId);
|
|
625
|
+
if (prev) {
|
|
626
|
+
if (prev.available) {
|
|
627
|
+
speakerGateBySessionId.set(message.sessionId, applySpeakerGateState(prev, message));
|
|
628
|
+
}
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
pendingSpeakerGateStateBySessionId.set(message.sessionId, message);
|
|
632
|
+
}
|
|
633
|
+
function clearPendingSpeakerRequestsForSession(sessionId, reason) {
|
|
634
|
+
for (const [requestId, pending] of pendingSpeakerGateAcks) {
|
|
635
|
+
if (pending.sessionId !== sessionId)
|
|
636
|
+
continue;
|
|
637
|
+
clearTimeout(pending.timer);
|
|
638
|
+
pendingSpeakerGateAcks.delete(requestId);
|
|
639
|
+
pending.resolve({ ok: false, reason });
|
|
640
|
+
}
|
|
641
|
+
for (const [requestId, pending] of pendingSpeakerResets) {
|
|
642
|
+
if (pending.sessionId !== sessionId)
|
|
643
|
+
continue;
|
|
644
|
+
clearTimeout(pending.timer);
|
|
645
|
+
pendingSpeakerResets.delete(requestId);
|
|
646
|
+
pending.resolve({ ok: false, reason });
|
|
647
|
+
}
|
|
648
|
+
}
|
|
607
649
|
function handleVoiceReplayLastResult(message) {
|
|
608
650
|
const pending = pendingVoiceReplays.get(message.requestId);
|
|
609
651
|
if (!pending)
|
|
@@ -833,7 +875,12 @@ async function handleParentMessage(message, handlers) {
|
|
|
833
875
|
speakControlAvailableBySessionId.set(message.sessionId, message.speakControlAvailable ?? false);
|
|
834
876
|
chatReplyRecordAvailableBySessionId.set(message.sessionId, message.chatReplyRecordAvailable ?? false);
|
|
835
877
|
sessionTimeLimitAvailableBySessionId.set(message.sessionId, message.sessionTimeLimitAvailable ?? false);
|
|
836
|
-
|
|
878
|
+
{
|
|
879
|
+
const initial = message.speakerGate?.available === true ? message.speakerGate : { available: false };
|
|
880
|
+
const early = pendingSpeakerGateStateBySessionId.get(message.sessionId);
|
|
881
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
882
|
+
speakerGateBySessionId.set(message.sessionId, early && initial.available ? applySpeakerGateState(initial, early) : initial);
|
|
883
|
+
}
|
|
837
884
|
if (message.voiceLanguageSwitch) {
|
|
838
885
|
voiceLanguageSwitchSettingsBySessionId.set(message.sessionId, message.voiceLanguageSwitch);
|
|
839
886
|
} else {
|
|
@@ -960,6 +1007,8 @@ async function handleParentMessage(message, handlers) {
|
|
|
960
1007
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
961
1008
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
962
1009
|
speakerGateBySessionId.delete(message.sessionId);
|
|
1010
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
1011
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
963
1012
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
964
1013
|
lastVoiceLanguageBySessionId.delete(message.sessionId);
|
|
965
1014
|
ttsPoseAvailableBySessionId.delete(message.sessionId);
|
|
@@ -1053,6 +1102,10 @@ function defineAgent(handlers) {
|
|
|
1053
1102
|
handleResetSpeakerEnrollmentResult(message);
|
|
1054
1103
|
return;
|
|
1055
1104
|
}
|
|
1105
|
+
if (isSpeakerGateStateMessage(message)) {
|
|
1106
|
+
handleSpeakerGateState(message);
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1056
1109
|
if (isWebhookMessage(message)) {
|
|
1057
1110
|
void agentStartReady.then(() => handleWebhookMessage(message, handlers));
|
|
1058
1111
|
return;
|
|
@@ -1061,6 +1114,8 @@ function defineAgent(handlers) {
|
|
|
1061
1114
|
return;
|
|
1062
1115
|
if (message.type === "session_end") {
|
|
1063
1116
|
endedSessionIds.add(message.sessionId);
|
|
1117
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
1118
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
1064
1119
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
1065
1120
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
1066
1121
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
@@ -1351,6 +1406,8 @@ function cancelSpeech(sessionId, target) {
|
|
|
1351
1406
|
...target?.turnId ? { turnId: target.turnId } : {}
|
|
1352
1407
|
});
|
|
1353
1408
|
}
|
|
1409
|
+
var SPEAKER_GATE_MODES = ["disabled", "auto", "manual"];
|
|
1410
|
+
var SPEAKER_GATE_BARGE_IN = ["caller_only", "anyone"];
|
|
1354
1411
|
var AGENT_LOG_MESSAGE_MAX_CHARS = 2048;
|
|
1355
1412
|
var AGENT_LOG_FIELDS_MAX_CHARS = 8192;
|
|
1356
1413
|
function truncateAgentLogMessage(message) {
|
|
@@ -244,6 +244,12 @@ function isSetSpeakerGateResultMessage(value) {
|
|
|
244
244
|
const msg = value;
|
|
245
245
|
return msg.type === "setSpeakerGateResult" && typeof msg.requestId === "string";
|
|
246
246
|
}
|
|
247
|
+
function isSpeakerGateStateMessage(value) {
|
|
248
|
+
if (!value || typeof value !== "object")
|
|
249
|
+
return false;
|
|
250
|
+
const msg = value;
|
|
251
|
+
return msg.type === "speaker_gate_state" && typeof msg.sessionId === "string" && typeof msg.mode === "string" && SPEAKER_GATE_MODES.includes(msg.mode) && (msg.bargeIn === void 0 || typeof msg.bargeIn === "string" && SPEAKER_GATE_BARGE_IN.includes(msg.bargeIn));
|
|
252
|
+
}
|
|
247
253
|
function isResetSpeakerEnrollmentResultMessage(value) {
|
|
248
254
|
if (!value || typeof value !== "object")
|
|
249
255
|
return false;
|
|
@@ -298,7 +304,7 @@ function isParentMessage(value) {
|
|
|
298
304
|
if (!value || typeof value !== "object")
|
|
299
305
|
return false;
|
|
300
306
|
const msg = value;
|
|
301
|
-
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 === "session_time_limit" || msg.type === "session_time_limit_control_ack" || msg.type === "recording_control_ack" || msg.type === "conversation_history_control_ack" || msg.type === "user_identified" || msg.type === "user_history_response" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "play_pose_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "voice_language_control_ack" || msg.type === "voice_language_prepare_result" || msg.type === "voice_replay_last_result" || msg.type === "setSpeakerGateResult" || msg.type === "resetSpeakerEnrollmentResult" || msg.type === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
|
|
307
|
+
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 === "session_time_limit" || msg.type === "session_time_limit_control_ack" || msg.type === "recording_control_ack" || msg.type === "conversation_history_control_ack" || msg.type === "user_identified" || msg.type === "user_history_response" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "play_pose_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "voice_language_control_ack" || msg.type === "voice_language_prepare_result" || msg.type === "voice_replay_last_result" || msg.type === "setSpeakerGateResult" || msg.type === "resetSpeakerEnrollmentResult" || msg.type === "speaker_gate_state" || msg.type === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
|
|
302
308
|
}
|
|
303
309
|
function isSessionScopedParentMessage(value) {
|
|
304
310
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -319,6 +325,7 @@ var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
|
319
325
|
var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
|
|
320
326
|
var speakerGateBySessionId = /* @__PURE__ */ new Map();
|
|
321
327
|
var pendingSpeakerGateAcks = /* @__PURE__ */ new Map();
|
|
328
|
+
var pendingSpeakerGateStateBySessionId = /* @__PURE__ */ new Map();
|
|
322
329
|
var pendingSpeakerResets = /* @__PURE__ */ new Map();
|
|
323
330
|
var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
324
331
|
var speakControlAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
@@ -607,6 +614,41 @@ function handleResetSpeakerEnrollmentResult(message) {
|
|
|
607
614
|
pendingSpeakerResets.delete(message.requestId);
|
|
608
615
|
pending.resolve(message.ok ? { ok: true } : { ok: false, reason: message.reason });
|
|
609
616
|
}
|
|
617
|
+
function applySpeakerGateState(prev, message) {
|
|
618
|
+
return {
|
|
619
|
+
available: true,
|
|
620
|
+
mode: message.mode,
|
|
621
|
+
bargeIn: message.bargeIn ?? prev.bargeIn
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
function handleSpeakerGateState(message) {
|
|
625
|
+
if (endedSessionIds.has(message.sessionId))
|
|
626
|
+
return;
|
|
627
|
+
const prev = speakerGateBySessionId.get(message.sessionId);
|
|
628
|
+
if (prev) {
|
|
629
|
+
if (prev.available) {
|
|
630
|
+
speakerGateBySessionId.set(message.sessionId, applySpeakerGateState(prev, message));
|
|
631
|
+
}
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
pendingSpeakerGateStateBySessionId.set(message.sessionId, message);
|
|
635
|
+
}
|
|
636
|
+
function clearPendingSpeakerRequestsForSession(sessionId, reason) {
|
|
637
|
+
for (const [requestId, pending] of pendingSpeakerGateAcks) {
|
|
638
|
+
if (pending.sessionId !== sessionId)
|
|
639
|
+
continue;
|
|
640
|
+
clearTimeout(pending.timer);
|
|
641
|
+
pendingSpeakerGateAcks.delete(requestId);
|
|
642
|
+
pending.resolve({ ok: false, reason });
|
|
643
|
+
}
|
|
644
|
+
for (const [requestId, pending] of pendingSpeakerResets) {
|
|
645
|
+
if (pending.sessionId !== sessionId)
|
|
646
|
+
continue;
|
|
647
|
+
clearTimeout(pending.timer);
|
|
648
|
+
pendingSpeakerResets.delete(requestId);
|
|
649
|
+
pending.resolve({ ok: false, reason });
|
|
650
|
+
}
|
|
651
|
+
}
|
|
610
652
|
function handleVoiceReplayLastResult(message) {
|
|
611
653
|
const pending = pendingVoiceReplays.get(message.requestId);
|
|
612
654
|
if (!pending)
|
|
@@ -836,7 +878,12 @@ async function handleParentMessage(message, handlers) {
|
|
|
836
878
|
speakControlAvailableBySessionId.set(message.sessionId, message.speakControlAvailable ?? false);
|
|
837
879
|
chatReplyRecordAvailableBySessionId.set(message.sessionId, message.chatReplyRecordAvailable ?? false);
|
|
838
880
|
sessionTimeLimitAvailableBySessionId.set(message.sessionId, message.sessionTimeLimitAvailable ?? false);
|
|
839
|
-
|
|
881
|
+
{
|
|
882
|
+
const initial = message.speakerGate?.available === true ? message.speakerGate : { available: false };
|
|
883
|
+
const early = pendingSpeakerGateStateBySessionId.get(message.sessionId);
|
|
884
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
885
|
+
speakerGateBySessionId.set(message.sessionId, early && initial.available ? applySpeakerGateState(initial, early) : initial);
|
|
886
|
+
}
|
|
840
887
|
if (message.voiceLanguageSwitch) {
|
|
841
888
|
voiceLanguageSwitchSettingsBySessionId.set(message.sessionId, message.voiceLanguageSwitch);
|
|
842
889
|
} else {
|
|
@@ -963,6 +1010,8 @@ async function handleParentMessage(message, handlers) {
|
|
|
963
1010
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
964
1011
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
965
1012
|
speakerGateBySessionId.delete(message.sessionId);
|
|
1013
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
1014
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
966
1015
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
967
1016
|
lastVoiceLanguageBySessionId.delete(message.sessionId);
|
|
968
1017
|
ttsPoseAvailableBySessionId.delete(message.sessionId);
|
|
@@ -1056,6 +1105,10 @@ function defineAgent(handlers) {
|
|
|
1056
1105
|
handleResetSpeakerEnrollmentResult(message);
|
|
1057
1106
|
return;
|
|
1058
1107
|
}
|
|
1108
|
+
if (isSpeakerGateStateMessage(message)) {
|
|
1109
|
+
handleSpeakerGateState(message);
|
|
1110
|
+
return;
|
|
1111
|
+
}
|
|
1059
1112
|
if (isWebhookMessage(message)) {
|
|
1060
1113
|
void agentStartReady.then(() => handleWebhookMessage(message, handlers));
|
|
1061
1114
|
return;
|
|
@@ -1064,6 +1117,8 @@ function defineAgent(handlers) {
|
|
|
1064
1117
|
return;
|
|
1065
1118
|
if (message.type === "session_end") {
|
|
1066
1119
|
endedSessionIds.add(message.sessionId);
|
|
1120
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
1121
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
1067
1122
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
1068
1123
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
1069
1124
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
@@ -1354,6 +1409,8 @@ function cancelSpeech(sessionId, target) {
|
|
|
1354
1409
|
...target?.turnId ? { turnId: target.turnId } : {}
|
|
1355
1410
|
});
|
|
1356
1411
|
}
|
|
1412
|
+
var SPEAKER_GATE_MODES = ["disabled", "auto", "manual"];
|
|
1413
|
+
var SPEAKER_GATE_BARGE_IN = ["caller_only", "anyone"];
|
|
1357
1414
|
function sendToClient(sessionId, payload) {
|
|
1358
1415
|
sendParentMessage({ type: "send_to_client", sessionId, payload });
|
|
1359
1416
|
}
|
|
@@ -10996,6 +10996,12 @@ function isSetSpeakerGateResultMessage(value) {
|
|
|
10996
10996
|
const msg = value;
|
|
10997
10997
|
return msg.type === "setSpeakerGateResult" && typeof msg.requestId === "string";
|
|
10998
10998
|
}
|
|
10999
|
+
function isSpeakerGateStateMessage(value) {
|
|
11000
|
+
if (!value || typeof value !== "object")
|
|
11001
|
+
return false;
|
|
11002
|
+
const msg = value;
|
|
11003
|
+
return msg.type === "speaker_gate_state" && typeof msg.sessionId === "string" && typeof msg.mode === "string" && SPEAKER_GATE_MODES.includes(msg.mode) && (msg.bargeIn === void 0 || typeof msg.bargeIn === "string" && SPEAKER_GATE_BARGE_IN.includes(msg.bargeIn));
|
|
11004
|
+
}
|
|
10999
11005
|
function isResetSpeakerEnrollmentResultMessage(value) {
|
|
11000
11006
|
if (!value || typeof value !== "object")
|
|
11001
11007
|
return false;
|
|
@@ -11050,7 +11056,7 @@ function isParentMessage(value) {
|
|
|
11050
11056
|
if (!value || typeof value !== "object")
|
|
11051
11057
|
return false;
|
|
11052
11058
|
const msg = value;
|
|
11053
|
-
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 === "session_time_limit" || msg.type === "session_time_limit_control_ack" || msg.type === "recording_control_ack" || msg.type === "conversation_history_control_ack" || msg.type === "user_identified" || msg.type === "user_history_response" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "play_pose_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "voice_language_control_ack" || msg.type === "voice_language_prepare_result" || msg.type === "voice_replay_last_result" || msg.type === "setSpeakerGateResult" || msg.type === "resetSpeakerEnrollmentResult" || msg.type === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
|
|
11059
|
+
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 === "session_time_limit" || msg.type === "session_time_limit_control_ack" || msg.type === "recording_control_ack" || msg.type === "conversation_history_control_ack" || msg.type === "user_identified" || msg.type === "user_history_response" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "play_pose_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "voice_language_control_ack" || msg.type === "voice_language_prepare_result" || msg.type === "voice_replay_last_result" || msg.type === "setSpeakerGateResult" || msg.type === "resetSpeakerEnrollmentResult" || msg.type === "speaker_gate_state" || msg.type === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
|
|
11054
11060
|
}
|
|
11055
11061
|
function isSessionScopedParentMessage(value) {
|
|
11056
11062
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -11071,6 +11077,7 @@ var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
|
11071
11077
|
var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
|
|
11072
11078
|
var speakerGateBySessionId = /* @__PURE__ */ new Map();
|
|
11073
11079
|
var pendingSpeakerGateAcks = /* @__PURE__ */ new Map();
|
|
11080
|
+
var pendingSpeakerGateStateBySessionId = /* @__PURE__ */ new Map();
|
|
11074
11081
|
var pendingSpeakerResets = /* @__PURE__ */ new Map();
|
|
11075
11082
|
var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
11076
11083
|
var speakControlAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
@@ -11358,6 +11365,41 @@ function handleResetSpeakerEnrollmentResult(message) {
|
|
|
11358
11365
|
pendingSpeakerResets.delete(message.requestId);
|
|
11359
11366
|
pending.resolve(message.ok ? { ok: true } : { ok: false, reason: message.reason });
|
|
11360
11367
|
}
|
|
11368
|
+
function applySpeakerGateState(prev, message) {
|
|
11369
|
+
return {
|
|
11370
|
+
available: true,
|
|
11371
|
+
mode: message.mode,
|
|
11372
|
+
bargeIn: message.bargeIn ?? prev.bargeIn
|
|
11373
|
+
};
|
|
11374
|
+
}
|
|
11375
|
+
function handleSpeakerGateState(message) {
|
|
11376
|
+
if (endedSessionIds.has(message.sessionId))
|
|
11377
|
+
return;
|
|
11378
|
+
const prev = speakerGateBySessionId.get(message.sessionId);
|
|
11379
|
+
if (prev) {
|
|
11380
|
+
if (prev.available) {
|
|
11381
|
+
speakerGateBySessionId.set(message.sessionId, applySpeakerGateState(prev, message));
|
|
11382
|
+
}
|
|
11383
|
+
return;
|
|
11384
|
+
}
|
|
11385
|
+
pendingSpeakerGateStateBySessionId.set(message.sessionId, message);
|
|
11386
|
+
}
|
|
11387
|
+
function clearPendingSpeakerRequestsForSession(sessionId, reason) {
|
|
11388
|
+
for (const [requestId, pending] of pendingSpeakerGateAcks) {
|
|
11389
|
+
if (pending.sessionId !== sessionId)
|
|
11390
|
+
continue;
|
|
11391
|
+
clearTimeout(pending.timer);
|
|
11392
|
+
pendingSpeakerGateAcks.delete(requestId);
|
|
11393
|
+
pending.resolve({ ok: false, reason });
|
|
11394
|
+
}
|
|
11395
|
+
for (const [requestId, pending] of pendingSpeakerResets) {
|
|
11396
|
+
if (pending.sessionId !== sessionId)
|
|
11397
|
+
continue;
|
|
11398
|
+
clearTimeout(pending.timer);
|
|
11399
|
+
pendingSpeakerResets.delete(requestId);
|
|
11400
|
+
pending.resolve({ ok: false, reason });
|
|
11401
|
+
}
|
|
11402
|
+
}
|
|
11361
11403
|
function handleVoiceReplayLastResult(message) {
|
|
11362
11404
|
const pending = pendingVoiceReplays.get(message.requestId);
|
|
11363
11405
|
if (!pending)
|
|
@@ -11584,7 +11626,12 @@ async function handleParentMessage(message, handlers) {
|
|
|
11584
11626
|
speakControlAvailableBySessionId.set(message.sessionId, message.speakControlAvailable ?? false);
|
|
11585
11627
|
chatReplyRecordAvailableBySessionId.set(message.sessionId, message.chatReplyRecordAvailable ?? false);
|
|
11586
11628
|
sessionTimeLimitAvailableBySessionId.set(message.sessionId, message.sessionTimeLimitAvailable ?? false);
|
|
11587
|
-
|
|
11629
|
+
{
|
|
11630
|
+
const initial = message.speakerGate?.available === true ? message.speakerGate : { available: false };
|
|
11631
|
+
const early = pendingSpeakerGateStateBySessionId.get(message.sessionId);
|
|
11632
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
11633
|
+
speakerGateBySessionId.set(message.sessionId, early && initial.available ? applySpeakerGateState(initial, early) : initial);
|
|
11634
|
+
}
|
|
11588
11635
|
if (message.voiceLanguageSwitch) {
|
|
11589
11636
|
voiceLanguageSwitchSettingsBySessionId.set(message.sessionId, message.voiceLanguageSwitch);
|
|
11590
11637
|
} else {
|
|
@@ -11711,6 +11758,8 @@ async function handleParentMessage(message, handlers) {
|
|
|
11711
11758
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
11712
11759
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
11713
11760
|
speakerGateBySessionId.delete(message.sessionId);
|
|
11761
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
11762
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
11714
11763
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
11715
11764
|
lastVoiceLanguageBySessionId.delete(message.sessionId);
|
|
11716
11765
|
ttsPoseAvailableBySessionId.delete(message.sessionId);
|
|
@@ -11804,6 +11853,10 @@ function defineAgent(handlers) {
|
|
|
11804
11853
|
handleResetSpeakerEnrollmentResult(message);
|
|
11805
11854
|
return;
|
|
11806
11855
|
}
|
|
11856
|
+
if (isSpeakerGateStateMessage(message)) {
|
|
11857
|
+
handleSpeakerGateState(message);
|
|
11858
|
+
return;
|
|
11859
|
+
}
|
|
11807
11860
|
if (isWebhookMessage(message)) {
|
|
11808
11861
|
void agentStartReady.then(() => handleWebhookMessage(message, handlers));
|
|
11809
11862
|
return;
|
|
@@ -11812,6 +11865,8 @@ function defineAgent(handlers) {
|
|
|
11812
11865
|
return;
|
|
11813
11866
|
if (message.type === "session_end") {
|
|
11814
11867
|
endedSessionIds.add(message.sessionId);
|
|
11868
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
11869
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
11815
11870
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
11816
11871
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
11817
11872
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
@@ -12001,6 +12056,8 @@ function buildIdleEnv(sessionId) {
|
|
|
12001
12056
|
...process.env.IDLE_TIMEOUT_SEC ? { IDLE_TIMEOUT_SEC: process.env.IDLE_TIMEOUT_SEC } : {}
|
|
12002
12057
|
};
|
|
12003
12058
|
}
|
|
12059
|
+
var SPEAKER_GATE_MODES = ["disabled", "auto", "manual"];
|
|
12060
|
+
var SPEAKER_GATE_BARGE_IN = ["caller_only", "anyone"];
|
|
12004
12061
|
function sendToClient(sessionId, payload) {
|
|
12005
12062
|
sendParentMessage({ type: "send_to_client", sessionId, payload });
|
|
12006
12063
|
}
|