@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);
|
|
@@ -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();
|
|
@@ -603,6 +610,41 @@ function handleResetSpeakerEnrollmentResult(message) {
|
|
|
603
610
|
pendingSpeakerResets.delete(message.requestId);
|
|
604
611
|
pending.resolve(message.ok ? { ok: true } : { ok: false, reason: message.reason });
|
|
605
612
|
}
|
|
613
|
+
function applySpeakerGateState(prev, message) {
|
|
614
|
+
return {
|
|
615
|
+
available: true,
|
|
616
|
+
mode: message.mode,
|
|
617
|
+
bargeIn: message.bargeIn ?? prev.bargeIn
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
function handleSpeakerGateState(message) {
|
|
621
|
+
if (endedSessionIds.has(message.sessionId))
|
|
622
|
+
return;
|
|
623
|
+
const prev = speakerGateBySessionId.get(message.sessionId);
|
|
624
|
+
if (prev) {
|
|
625
|
+
if (prev.available) {
|
|
626
|
+
speakerGateBySessionId.set(message.sessionId, applySpeakerGateState(prev, message));
|
|
627
|
+
}
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
pendingSpeakerGateStateBySessionId.set(message.sessionId, message);
|
|
631
|
+
}
|
|
632
|
+
function clearPendingSpeakerRequestsForSession(sessionId, reason) {
|
|
633
|
+
for (const [requestId, pending] of pendingSpeakerGateAcks) {
|
|
634
|
+
if (pending.sessionId !== sessionId)
|
|
635
|
+
continue;
|
|
636
|
+
clearTimeout(pending.timer);
|
|
637
|
+
pendingSpeakerGateAcks.delete(requestId);
|
|
638
|
+
pending.resolve({ ok: false, reason });
|
|
639
|
+
}
|
|
640
|
+
for (const [requestId, pending] of pendingSpeakerResets) {
|
|
641
|
+
if (pending.sessionId !== sessionId)
|
|
642
|
+
continue;
|
|
643
|
+
clearTimeout(pending.timer);
|
|
644
|
+
pendingSpeakerResets.delete(requestId);
|
|
645
|
+
pending.resolve({ ok: false, reason });
|
|
646
|
+
}
|
|
647
|
+
}
|
|
606
648
|
function handleVoiceReplayLastResult(message) {
|
|
607
649
|
const pending = pendingVoiceReplays.get(message.requestId);
|
|
608
650
|
if (!pending)
|
|
@@ -829,7 +871,12 @@ async function handleParentMessage(message, handlers) {
|
|
|
829
871
|
speakControlAvailableBySessionId.set(message.sessionId, message.speakControlAvailable ?? false);
|
|
830
872
|
chatReplyRecordAvailableBySessionId.set(message.sessionId, message.chatReplyRecordAvailable ?? false);
|
|
831
873
|
sessionTimeLimitAvailableBySessionId.set(message.sessionId, message.sessionTimeLimitAvailable ?? false);
|
|
832
|
-
|
|
874
|
+
{
|
|
875
|
+
const initial = message.speakerGate?.available === true ? message.speakerGate : { available: false };
|
|
876
|
+
const early = pendingSpeakerGateStateBySessionId.get(message.sessionId);
|
|
877
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
878
|
+
speakerGateBySessionId.set(message.sessionId, early && initial.available ? applySpeakerGateState(initial, early) : initial);
|
|
879
|
+
}
|
|
833
880
|
if (message.voiceLanguageSwitch) {
|
|
834
881
|
voiceLanguageSwitchSettingsBySessionId.set(message.sessionId, message.voiceLanguageSwitch);
|
|
835
882
|
} else {
|
|
@@ -956,6 +1003,8 @@ async function handleParentMessage(message, handlers) {
|
|
|
956
1003
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
957
1004
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
958
1005
|
speakerGateBySessionId.delete(message.sessionId);
|
|
1006
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
1007
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
959
1008
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
960
1009
|
lastVoiceLanguageBySessionId.delete(message.sessionId);
|
|
961
1010
|
ttsPoseAvailableBySessionId.delete(message.sessionId);
|
|
@@ -1049,6 +1098,10 @@ function defineAgent(handlers) {
|
|
|
1049
1098
|
handleResetSpeakerEnrollmentResult(message);
|
|
1050
1099
|
return;
|
|
1051
1100
|
}
|
|
1101
|
+
if (isSpeakerGateStateMessage(message)) {
|
|
1102
|
+
handleSpeakerGateState(message);
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1052
1105
|
if (isWebhookMessage(message)) {
|
|
1053
1106
|
void agentStartReady.then(() => handleWebhookMessage(message, handlers));
|
|
1054
1107
|
return;
|
|
@@ -1057,6 +1110,8 @@ function defineAgent(handlers) {
|
|
|
1057
1110
|
return;
|
|
1058
1111
|
if (message.type === "session_end") {
|
|
1059
1112
|
endedSessionIds.add(message.sessionId);
|
|
1113
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
1114
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
1060
1115
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
1061
1116
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
1062
1117
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
@@ -1246,6 +1301,8 @@ function buildIdleEnv(sessionId) {
|
|
|
1246
1301
|
...process.env.IDLE_TIMEOUT_SEC ? { IDLE_TIMEOUT_SEC: process.env.IDLE_TIMEOUT_SEC } : {}
|
|
1247
1302
|
};
|
|
1248
1303
|
}
|
|
1304
|
+
var SPEAKER_GATE_MODES = ["disabled", "auto", "manual"];
|
|
1305
|
+
var SPEAKER_GATE_BARGE_IN = ["caller_only", "anyone"];
|
|
1249
1306
|
function sendToClient(sessionId, payload) {
|
|
1250
1307
|
sendParentMessage({ type: "send_to_client", sessionId, payload });
|
|
1251
1308
|
}
|
|
@@ -20165,6 +20165,12 @@ function isSetSpeakerGateResultMessage(value) {
|
|
|
20165
20165
|
const msg = value;
|
|
20166
20166
|
return msg.type === "setSpeakerGateResult" && typeof msg.requestId === "string";
|
|
20167
20167
|
}
|
|
20168
|
+
function isSpeakerGateStateMessage(value) {
|
|
20169
|
+
if (!value || typeof value !== "object")
|
|
20170
|
+
return false;
|
|
20171
|
+
const msg = value;
|
|
20172
|
+
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));
|
|
20173
|
+
}
|
|
20168
20174
|
function isResetSpeakerEnrollmentResultMessage(value) {
|
|
20169
20175
|
if (!value || typeof value !== "object")
|
|
20170
20176
|
return false;
|
|
@@ -20219,7 +20225,7 @@ function isParentMessage(value) {
|
|
|
20219
20225
|
if (!value || typeof value !== "object")
|
|
20220
20226
|
return false;
|
|
20221
20227
|
const msg = value;
|
|
20222
|
-
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";
|
|
20228
|
+
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";
|
|
20223
20229
|
}
|
|
20224
20230
|
function isSessionScopedParentMessage(value) {
|
|
20225
20231
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -20240,6 +20246,7 @@ var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
|
20240
20246
|
var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
|
|
20241
20247
|
var speakerGateBySessionId = /* @__PURE__ */ new Map();
|
|
20242
20248
|
var pendingSpeakerGateAcks = /* @__PURE__ */ new Map();
|
|
20249
|
+
var pendingSpeakerGateStateBySessionId = /* @__PURE__ */ new Map();
|
|
20243
20250
|
var pendingSpeakerResets = /* @__PURE__ */ new Map();
|
|
20244
20251
|
var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
20245
20252
|
var speakControlAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
@@ -20528,6 +20535,41 @@ function handleResetSpeakerEnrollmentResult(message) {
|
|
|
20528
20535
|
pendingSpeakerResets.delete(message.requestId);
|
|
20529
20536
|
pending.resolve(message.ok ? { ok: true } : { ok: false, reason: message.reason });
|
|
20530
20537
|
}
|
|
20538
|
+
function applySpeakerGateState(prev, message) {
|
|
20539
|
+
return {
|
|
20540
|
+
available: true,
|
|
20541
|
+
mode: message.mode,
|
|
20542
|
+
bargeIn: message.bargeIn ?? prev.bargeIn
|
|
20543
|
+
};
|
|
20544
|
+
}
|
|
20545
|
+
function handleSpeakerGateState(message) {
|
|
20546
|
+
if (endedSessionIds.has(message.sessionId))
|
|
20547
|
+
return;
|
|
20548
|
+
const prev = speakerGateBySessionId.get(message.sessionId);
|
|
20549
|
+
if (prev) {
|
|
20550
|
+
if (prev.available) {
|
|
20551
|
+
speakerGateBySessionId.set(message.sessionId, applySpeakerGateState(prev, message));
|
|
20552
|
+
}
|
|
20553
|
+
return;
|
|
20554
|
+
}
|
|
20555
|
+
pendingSpeakerGateStateBySessionId.set(message.sessionId, message);
|
|
20556
|
+
}
|
|
20557
|
+
function clearPendingSpeakerRequestsForSession(sessionId, reason) {
|
|
20558
|
+
for (const [requestId, pending] of pendingSpeakerGateAcks) {
|
|
20559
|
+
if (pending.sessionId !== sessionId)
|
|
20560
|
+
continue;
|
|
20561
|
+
clearTimeout(pending.timer);
|
|
20562
|
+
pendingSpeakerGateAcks.delete(requestId);
|
|
20563
|
+
pending.resolve({ ok: false, reason });
|
|
20564
|
+
}
|
|
20565
|
+
for (const [requestId, pending] of pendingSpeakerResets) {
|
|
20566
|
+
if (pending.sessionId !== sessionId)
|
|
20567
|
+
continue;
|
|
20568
|
+
clearTimeout(pending.timer);
|
|
20569
|
+
pendingSpeakerResets.delete(requestId);
|
|
20570
|
+
pending.resolve({ ok: false, reason });
|
|
20571
|
+
}
|
|
20572
|
+
}
|
|
20531
20573
|
function handleVoiceReplayLastResult(message) {
|
|
20532
20574
|
const pending = pendingVoiceReplays.get(message.requestId);
|
|
20533
20575
|
if (!pending)
|
|
@@ -20757,7 +20799,12 @@ async function handleParentMessage(message, handlers) {
|
|
|
20757
20799
|
speakControlAvailableBySessionId.set(message.sessionId, message.speakControlAvailable ?? false);
|
|
20758
20800
|
chatReplyRecordAvailableBySessionId.set(message.sessionId, message.chatReplyRecordAvailable ?? false);
|
|
20759
20801
|
sessionTimeLimitAvailableBySessionId.set(message.sessionId, message.sessionTimeLimitAvailable ?? false);
|
|
20760
|
-
|
|
20802
|
+
{
|
|
20803
|
+
const initial = message.speakerGate?.available === true ? message.speakerGate : { available: false };
|
|
20804
|
+
const early = pendingSpeakerGateStateBySessionId.get(message.sessionId);
|
|
20805
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
20806
|
+
speakerGateBySessionId.set(message.sessionId, early && initial.available ? applySpeakerGateState(initial, early) : initial);
|
|
20807
|
+
}
|
|
20761
20808
|
if (message.voiceLanguageSwitch) {
|
|
20762
20809
|
voiceLanguageSwitchSettingsBySessionId.set(message.sessionId, message.voiceLanguageSwitch);
|
|
20763
20810
|
} else {
|
|
@@ -20884,6 +20931,8 @@ async function handleParentMessage(message, handlers) {
|
|
|
20884
20931
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
20885
20932
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
20886
20933
|
speakerGateBySessionId.delete(message.sessionId);
|
|
20934
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
20935
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
20887
20936
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
20888
20937
|
lastVoiceLanguageBySessionId.delete(message.sessionId);
|
|
20889
20938
|
ttsPoseAvailableBySessionId.delete(message.sessionId);
|
|
@@ -20977,6 +21026,10 @@ function defineAgent(handlers) {
|
|
|
20977
21026
|
handleResetSpeakerEnrollmentResult(message);
|
|
20978
21027
|
return;
|
|
20979
21028
|
}
|
|
21029
|
+
if (isSpeakerGateStateMessage(message)) {
|
|
21030
|
+
handleSpeakerGateState(message);
|
|
21031
|
+
return;
|
|
21032
|
+
}
|
|
20980
21033
|
if (isWebhookMessage(message)) {
|
|
20981
21034
|
void agentStartReady.then(() => handleWebhookMessage(message, handlers));
|
|
20982
21035
|
return;
|
|
@@ -20985,6 +21038,8 @@ function defineAgent(handlers) {
|
|
|
20985
21038
|
return;
|
|
20986
21039
|
if (message.type === "session_end") {
|
|
20987
21040
|
endedSessionIds.add(message.sessionId);
|
|
21041
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
21042
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
20988
21043
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
20989
21044
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
20990
21045
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
@@ -21275,6 +21330,8 @@ function cancelSpeech(sessionId, target) {
|
|
|
21275
21330
|
...target?.turnId ? { turnId: target.turnId } : {}
|
|
21276
21331
|
});
|
|
21277
21332
|
}
|
|
21333
|
+
var SPEAKER_GATE_MODES = ["disabled", "auto", "manual"];
|
|
21334
|
+
var SPEAKER_GATE_BARGE_IN = ["caller_only", "anyone"];
|
|
21278
21335
|
function recordReply(sessionId, text, o) {
|
|
21279
21336
|
if (!(chatReplyRecordAvailableBySessionId.get(sessionId) ?? false))
|
|
21280
21337
|
return false;
|
|
@@ -24618,7 +24675,11 @@ function createNodeEffects(o) {
|
|
|
24618
24675
|
};
|
|
24619
24676
|
},
|
|
24620
24677
|
chat(text, co) {
|
|
24621
|
-
sendToClient(sid, {
|
|
24678
|
+
sendToClient(sid, {
|
|
24679
|
+
type: "chat_reply",
|
|
24680
|
+
text,
|
|
24681
|
+
...co?.turnId ? { turnId: co.turnId } : {}
|
|
24682
|
+
});
|
|
24622
24683
|
if (recordReply(sid, text, co?.turnId ? { turnId: co.turnId } : void 0))
|
|
24623
24684
|
return void 0;
|
|
24624
24685
|
const h = speak(sid, text, co?.turnId ? { turnId: co.turnId } : void 0);
|
|
@@ -10995,6 +10995,12 @@ function isSetSpeakerGateResultMessage(value) {
|
|
|
10995
10995
|
const msg = value;
|
|
10996
10996
|
return msg.type === "setSpeakerGateResult" && typeof msg.requestId === "string";
|
|
10997
10997
|
}
|
|
10998
|
+
function isSpeakerGateStateMessage(value) {
|
|
10999
|
+
if (!value || typeof value !== "object")
|
|
11000
|
+
return false;
|
|
11001
|
+
const msg = value;
|
|
11002
|
+
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));
|
|
11003
|
+
}
|
|
10998
11004
|
function isResetSpeakerEnrollmentResultMessage(value) {
|
|
10999
11005
|
if (!value || typeof value !== "object")
|
|
11000
11006
|
return false;
|
|
@@ -11049,7 +11055,7 @@ function isParentMessage(value) {
|
|
|
11049
11055
|
if (!value || typeof value !== "object")
|
|
11050
11056
|
return false;
|
|
11051
11057
|
const msg = value;
|
|
11052
|
-
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";
|
|
11058
|
+
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";
|
|
11053
11059
|
}
|
|
11054
11060
|
function isSessionScopedParentMessage(value) {
|
|
11055
11061
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -11070,6 +11076,7 @@ var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
|
11070
11076
|
var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
|
|
11071
11077
|
var speakerGateBySessionId = /* @__PURE__ */ new Map();
|
|
11072
11078
|
var pendingSpeakerGateAcks = /* @__PURE__ */ new Map();
|
|
11079
|
+
var pendingSpeakerGateStateBySessionId = /* @__PURE__ */ new Map();
|
|
11073
11080
|
var pendingSpeakerResets = /* @__PURE__ */ new Map();
|
|
11074
11081
|
var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
11075
11082
|
var speakControlAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
@@ -11357,6 +11364,41 @@ function handleResetSpeakerEnrollmentResult(message) {
|
|
|
11357
11364
|
pendingSpeakerResets.delete(message.requestId);
|
|
11358
11365
|
pending.resolve(message.ok ? { ok: true } : { ok: false, reason: message.reason });
|
|
11359
11366
|
}
|
|
11367
|
+
function applySpeakerGateState(prev, message) {
|
|
11368
|
+
return {
|
|
11369
|
+
available: true,
|
|
11370
|
+
mode: message.mode,
|
|
11371
|
+
bargeIn: message.bargeIn ?? prev.bargeIn
|
|
11372
|
+
};
|
|
11373
|
+
}
|
|
11374
|
+
function handleSpeakerGateState(message) {
|
|
11375
|
+
if (endedSessionIds.has(message.sessionId))
|
|
11376
|
+
return;
|
|
11377
|
+
const prev = speakerGateBySessionId.get(message.sessionId);
|
|
11378
|
+
if (prev) {
|
|
11379
|
+
if (prev.available) {
|
|
11380
|
+
speakerGateBySessionId.set(message.sessionId, applySpeakerGateState(prev, message));
|
|
11381
|
+
}
|
|
11382
|
+
return;
|
|
11383
|
+
}
|
|
11384
|
+
pendingSpeakerGateStateBySessionId.set(message.sessionId, message);
|
|
11385
|
+
}
|
|
11386
|
+
function clearPendingSpeakerRequestsForSession(sessionId, reason) {
|
|
11387
|
+
for (const [requestId, pending] of pendingSpeakerGateAcks) {
|
|
11388
|
+
if (pending.sessionId !== sessionId)
|
|
11389
|
+
continue;
|
|
11390
|
+
clearTimeout(pending.timer);
|
|
11391
|
+
pendingSpeakerGateAcks.delete(requestId);
|
|
11392
|
+
pending.resolve({ ok: false, reason });
|
|
11393
|
+
}
|
|
11394
|
+
for (const [requestId, pending] of pendingSpeakerResets) {
|
|
11395
|
+
if (pending.sessionId !== sessionId)
|
|
11396
|
+
continue;
|
|
11397
|
+
clearTimeout(pending.timer);
|
|
11398
|
+
pendingSpeakerResets.delete(requestId);
|
|
11399
|
+
pending.resolve({ ok: false, reason });
|
|
11400
|
+
}
|
|
11401
|
+
}
|
|
11360
11402
|
function handleVoiceReplayLastResult(message) {
|
|
11361
11403
|
const pending = pendingVoiceReplays.get(message.requestId);
|
|
11362
11404
|
if (!pending)
|
|
@@ -11583,7 +11625,12 @@ async function handleParentMessage(message, handlers) {
|
|
|
11583
11625
|
speakControlAvailableBySessionId.set(message.sessionId, message.speakControlAvailable ?? false);
|
|
11584
11626
|
chatReplyRecordAvailableBySessionId.set(message.sessionId, message.chatReplyRecordAvailable ?? false);
|
|
11585
11627
|
sessionTimeLimitAvailableBySessionId.set(message.sessionId, message.sessionTimeLimitAvailable ?? false);
|
|
11586
|
-
|
|
11628
|
+
{
|
|
11629
|
+
const initial = message.speakerGate?.available === true ? message.speakerGate : { available: false };
|
|
11630
|
+
const early = pendingSpeakerGateStateBySessionId.get(message.sessionId);
|
|
11631
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
11632
|
+
speakerGateBySessionId.set(message.sessionId, early && initial.available ? applySpeakerGateState(initial, early) : initial);
|
|
11633
|
+
}
|
|
11587
11634
|
if (message.voiceLanguageSwitch) {
|
|
11588
11635
|
voiceLanguageSwitchSettingsBySessionId.set(message.sessionId, message.voiceLanguageSwitch);
|
|
11589
11636
|
} else {
|
|
@@ -11710,6 +11757,8 @@ async function handleParentMessage(message, handlers) {
|
|
|
11710
11757
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
11711
11758
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
11712
11759
|
speakerGateBySessionId.delete(message.sessionId);
|
|
11760
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
11761
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
11713
11762
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
11714
11763
|
lastVoiceLanguageBySessionId.delete(message.sessionId);
|
|
11715
11764
|
ttsPoseAvailableBySessionId.delete(message.sessionId);
|
|
@@ -11803,6 +11852,10 @@ function defineAgent(handlers) {
|
|
|
11803
11852
|
handleResetSpeakerEnrollmentResult(message);
|
|
11804
11853
|
return;
|
|
11805
11854
|
}
|
|
11855
|
+
if (isSpeakerGateStateMessage(message)) {
|
|
11856
|
+
handleSpeakerGateState(message);
|
|
11857
|
+
return;
|
|
11858
|
+
}
|
|
11806
11859
|
if (isWebhookMessage(message)) {
|
|
11807
11860
|
void agentStartReady.then(() => handleWebhookMessage(message, handlers));
|
|
11808
11861
|
return;
|
|
@@ -11811,6 +11864,8 @@ function defineAgent(handlers) {
|
|
|
11811
11864
|
return;
|
|
11812
11865
|
if (message.type === "session_end") {
|
|
11813
11866
|
endedSessionIds.add(message.sessionId);
|
|
11867
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
11868
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
11814
11869
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
11815
11870
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
11816
11871
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
@@ -12000,6 +12055,8 @@ function buildIdleEnv(sessionId) {
|
|
|
12000
12055
|
...process.env.IDLE_TIMEOUT_SEC ? { IDLE_TIMEOUT_SEC: process.env.IDLE_TIMEOUT_SEC } : {}
|
|
12001
12056
|
};
|
|
12002
12057
|
}
|
|
12058
|
+
var SPEAKER_GATE_MODES = ["disabled", "auto", "manual"];
|
|
12059
|
+
var SPEAKER_GATE_BARGE_IN = ["caller_only", "anyone"];
|
|
12003
12060
|
function sendToClient(sessionId, payload) {
|
|
12004
12061
|
sendParentMessage({ type: "send_to_client", sessionId, payload });
|
|
12005
12062
|
}
|
|
@@ -312,6 +312,12 @@ function isSetSpeakerGateResultMessage(value) {
|
|
|
312
312
|
const msg = value;
|
|
313
313
|
return msg.type === "setSpeakerGateResult" && typeof msg.requestId === "string";
|
|
314
314
|
}
|
|
315
|
+
function isSpeakerGateStateMessage(value) {
|
|
316
|
+
if (!value || typeof value !== "object")
|
|
317
|
+
return false;
|
|
318
|
+
const msg = value;
|
|
319
|
+
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));
|
|
320
|
+
}
|
|
315
321
|
function isResetSpeakerEnrollmentResultMessage(value) {
|
|
316
322
|
if (!value || typeof value !== "object")
|
|
317
323
|
return false;
|
|
@@ -366,7 +372,7 @@ function isParentMessage(value) {
|
|
|
366
372
|
if (!value || typeof value !== "object")
|
|
367
373
|
return false;
|
|
368
374
|
const msg = value;
|
|
369
|
-
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";
|
|
375
|
+
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";
|
|
370
376
|
}
|
|
371
377
|
function isSessionScopedParentMessage(value) {
|
|
372
378
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -387,6 +393,7 @@ var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
|
387
393
|
var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
|
|
388
394
|
var speakerGateBySessionId = /* @__PURE__ */ new Map();
|
|
389
395
|
var pendingSpeakerGateAcks = /* @__PURE__ */ new Map();
|
|
396
|
+
var pendingSpeakerGateStateBySessionId = /* @__PURE__ */ new Map();
|
|
390
397
|
var pendingSpeakerResets = /* @__PURE__ */ new Map();
|
|
391
398
|
var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
392
399
|
var speakControlAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
@@ -678,6 +685,41 @@ function handleResetSpeakerEnrollmentResult(message) {
|
|
|
678
685
|
pendingSpeakerResets.delete(message.requestId);
|
|
679
686
|
pending.resolve(message.ok ? { ok: true } : { ok: false, reason: message.reason });
|
|
680
687
|
}
|
|
688
|
+
function applySpeakerGateState(prev, message) {
|
|
689
|
+
return {
|
|
690
|
+
available: true,
|
|
691
|
+
mode: message.mode,
|
|
692
|
+
bargeIn: message.bargeIn ?? prev.bargeIn
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
function handleSpeakerGateState(message) {
|
|
696
|
+
if (endedSessionIds.has(message.sessionId))
|
|
697
|
+
return;
|
|
698
|
+
const prev = speakerGateBySessionId.get(message.sessionId);
|
|
699
|
+
if (prev) {
|
|
700
|
+
if (prev.available) {
|
|
701
|
+
speakerGateBySessionId.set(message.sessionId, applySpeakerGateState(prev, message));
|
|
702
|
+
}
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
pendingSpeakerGateStateBySessionId.set(message.sessionId, message);
|
|
706
|
+
}
|
|
707
|
+
function clearPendingSpeakerRequestsForSession(sessionId, reason) {
|
|
708
|
+
for (const [requestId, pending] of pendingSpeakerGateAcks) {
|
|
709
|
+
if (pending.sessionId !== sessionId)
|
|
710
|
+
continue;
|
|
711
|
+
clearTimeout(pending.timer);
|
|
712
|
+
pendingSpeakerGateAcks.delete(requestId);
|
|
713
|
+
pending.resolve({ ok: false, reason });
|
|
714
|
+
}
|
|
715
|
+
for (const [requestId, pending] of pendingSpeakerResets) {
|
|
716
|
+
if (pending.sessionId !== sessionId)
|
|
717
|
+
continue;
|
|
718
|
+
clearTimeout(pending.timer);
|
|
719
|
+
pendingSpeakerResets.delete(requestId);
|
|
720
|
+
pending.resolve({ ok: false, reason });
|
|
721
|
+
}
|
|
722
|
+
}
|
|
681
723
|
function handleVoiceReplayLastResult(message) {
|
|
682
724
|
const pending = pendingVoiceReplays.get(message.requestId);
|
|
683
725
|
if (!pending)
|
|
@@ -907,7 +949,12 @@ async function handleParentMessage(message, handlers) {
|
|
|
907
949
|
speakControlAvailableBySessionId.set(message.sessionId, message.speakControlAvailable ?? false);
|
|
908
950
|
chatReplyRecordAvailableBySessionId.set(message.sessionId, message.chatReplyRecordAvailable ?? false);
|
|
909
951
|
sessionTimeLimitAvailableBySessionId.set(message.sessionId, message.sessionTimeLimitAvailable ?? false);
|
|
910
|
-
|
|
952
|
+
{
|
|
953
|
+
const initial = message.speakerGate?.available === true ? message.speakerGate : { available: false };
|
|
954
|
+
const early = pendingSpeakerGateStateBySessionId.get(message.sessionId);
|
|
955
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
956
|
+
speakerGateBySessionId.set(message.sessionId, early && initial.available ? applySpeakerGateState(initial, early) : initial);
|
|
957
|
+
}
|
|
911
958
|
if (message.voiceLanguageSwitch) {
|
|
912
959
|
voiceLanguageSwitchSettingsBySessionId.set(message.sessionId, message.voiceLanguageSwitch);
|
|
913
960
|
} else {
|
|
@@ -1034,6 +1081,8 @@ async function handleParentMessage(message, handlers) {
|
|
|
1034
1081
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
1035
1082
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
1036
1083
|
speakerGateBySessionId.delete(message.sessionId);
|
|
1084
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
1085
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
1037
1086
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
1038
1087
|
lastVoiceLanguageBySessionId.delete(message.sessionId);
|
|
1039
1088
|
ttsPoseAvailableBySessionId.delete(message.sessionId);
|
|
@@ -1127,6 +1176,10 @@ function defineAgent(handlers) {
|
|
|
1127
1176
|
handleResetSpeakerEnrollmentResult(message);
|
|
1128
1177
|
return;
|
|
1129
1178
|
}
|
|
1179
|
+
if (isSpeakerGateStateMessage(message)) {
|
|
1180
|
+
handleSpeakerGateState(message);
|
|
1181
|
+
return;
|
|
1182
|
+
}
|
|
1130
1183
|
if (isWebhookMessage(message)) {
|
|
1131
1184
|
void agentStartReady.then(() => handleWebhookMessage(message, handlers));
|
|
1132
1185
|
return;
|
|
@@ -1135,6 +1188,8 @@ function defineAgent(handlers) {
|
|
|
1135
1188
|
return;
|
|
1136
1189
|
if (message.type === "session_end") {
|
|
1137
1190
|
endedSessionIds.add(message.sessionId);
|
|
1191
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
1192
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
1138
1193
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
1139
1194
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
1140
1195
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
@@ -1483,6 +1538,8 @@ function setVoiceLanguage(sessionId, options) {
|
|
|
1483
1538
|
});
|
|
1484
1539
|
});
|
|
1485
1540
|
}
|
|
1541
|
+
var SPEAKER_GATE_MODES = ["disabled", "auto", "manual"];
|
|
1542
|
+
var SPEAKER_GATE_BARGE_IN = ["caller_only", "anyone"];
|
|
1486
1543
|
function prepareVoiceLanguage(sessionId, options) {
|
|
1487
1544
|
const invalid = validateVoiceRequest(options);
|
|
1488
1545
|
if (!invalid.ok) {
|