@voicethere/agent 0.29.1 → 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 +5 -1
- 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 +64 -3
- package/dist/templates/llm-docs-rag/agent.js +64 -3
- package/dist/templates/llm-mcp-service/agent.js +64 -3
- package/dist/templates/llm-support-sticky-user/agent.js +64 -3
- 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 +6 -2
- package/package.json +1 -1
- package/templates/README.md +5 -5
- package/templates/llm-agent/README.md +1 -1
- package/templates/speaker-gate/README.md +3 -1
- package/templates/speaker-gate/agent.ts +5 -1
|
@@ -30884,6 +30884,12 @@ function isSetSpeakerGateResultMessage(value) {
|
|
|
30884
30884
|
const msg = value;
|
|
30885
30885
|
return msg.type === "setSpeakerGateResult" && typeof msg.requestId === "string";
|
|
30886
30886
|
}
|
|
30887
|
+
function isSpeakerGateStateMessage(value) {
|
|
30888
|
+
if (!value || typeof value !== "object")
|
|
30889
|
+
return false;
|
|
30890
|
+
const msg = value;
|
|
30891
|
+
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));
|
|
30892
|
+
}
|
|
30887
30893
|
function isResetSpeakerEnrollmentResultMessage(value) {
|
|
30888
30894
|
if (!value || typeof value !== "object")
|
|
30889
30895
|
return false;
|
|
@@ -30938,7 +30944,7 @@ function isParentMessage(value) {
|
|
|
30938
30944
|
if (!value || typeof value !== "object")
|
|
30939
30945
|
return false;
|
|
30940
30946
|
const msg = value;
|
|
30941
|
-
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";
|
|
30947
|
+
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";
|
|
30942
30948
|
}
|
|
30943
30949
|
function isSessionScopedParentMessage(value) {
|
|
30944
30950
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -30959,6 +30965,7 @@ var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
|
30959
30965
|
var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
|
|
30960
30966
|
var speakerGateBySessionId = /* @__PURE__ */ new Map();
|
|
30961
30967
|
var pendingSpeakerGateAcks = /* @__PURE__ */ new Map();
|
|
30968
|
+
var pendingSpeakerGateStateBySessionId = /* @__PURE__ */ new Map();
|
|
30962
30969
|
var pendingSpeakerResets = /* @__PURE__ */ new Map();
|
|
30963
30970
|
var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
30964
30971
|
var speakControlAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
@@ -31249,6 +31256,41 @@ function handleResetSpeakerEnrollmentResult(message) {
|
|
|
31249
31256
|
pendingSpeakerResets.delete(message.requestId);
|
|
31250
31257
|
pending.resolve(message.ok ? { ok: true } : { ok: false, reason: message.reason });
|
|
31251
31258
|
}
|
|
31259
|
+
function applySpeakerGateState(prev, message) {
|
|
31260
|
+
return {
|
|
31261
|
+
available: true,
|
|
31262
|
+
mode: message.mode,
|
|
31263
|
+
bargeIn: message.bargeIn ?? prev.bargeIn
|
|
31264
|
+
};
|
|
31265
|
+
}
|
|
31266
|
+
function handleSpeakerGateState(message) {
|
|
31267
|
+
if (endedSessionIds.has(message.sessionId))
|
|
31268
|
+
return;
|
|
31269
|
+
const prev = speakerGateBySessionId.get(message.sessionId);
|
|
31270
|
+
if (prev) {
|
|
31271
|
+
if (prev.available) {
|
|
31272
|
+
speakerGateBySessionId.set(message.sessionId, applySpeakerGateState(prev, message));
|
|
31273
|
+
}
|
|
31274
|
+
return;
|
|
31275
|
+
}
|
|
31276
|
+
pendingSpeakerGateStateBySessionId.set(message.sessionId, message);
|
|
31277
|
+
}
|
|
31278
|
+
function clearPendingSpeakerRequestsForSession(sessionId, reason) {
|
|
31279
|
+
for (const [requestId, pending] of pendingSpeakerGateAcks) {
|
|
31280
|
+
if (pending.sessionId !== sessionId)
|
|
31281
|
+
continue;
|
|
31282
|
+
clearTimeout(pending.timer);
|
|
31283
|
+
pendingSpeakerGateAcks.delete(requestId);
|
|
31284
|
+
pending.resolve({ ok: false, reason });
|
|
31285
|
+
}
|
|
31286
|
+
for (const [requestId, pending] of pendingSpeakerResets) {
|
|
31287
|
+
if (pending.sessionId !== sessionId)
|
|
31288
|
+
continue;
|
|
31289
|
+
clearTimeout(pending.timer);
|
|
31290
|
+
pendingSpeakerResets.delete(requestId);
|
|
31291
|
+
pending.resolve({ ok: false, reason });
|
|
31292
|
+
}
|
|
31293
|
+
}
|
|
31252
31294
|
function handleVoiceReplayLastResult(message) {
|
|
31253
31295
|
const pending = pendingVoiceReplays.get(message.requestId);
|
|
31254
31296
|
if (!pending)
|
|
@@ -31478,7 +31520,12 @@ async function handleParentMessage(message, handlers) {
|
|
|
31478
31520
|
speakControlAvailableBySessionId.set(message.sessionId, message.speakControlAvailable ?? false);
|
|
31479
31521
|
chatReplyRecordAvailableBySessionId.set(message.sessionId, message.chatReplyRecordAvailable ?? false);
|
|
31480
31522
|
sessionTimeLimitAvailableBySessionId.set(message.sessionId, message.sessionTimeLimitAvailable ?? false);
|
|
31481
|
-
|
|
31523
|
+
{
|
|
31524
|
+
const initial = message.speakerGate?.available === true ? message.speakerGate : { available: false };
|
|
31525
|
+
const early = pendingSpeakerGateStateBySessionId.get(message.sessionId);
|
|
31526
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
31527
|
+
speakerGateBySessionId.set(message.sessionId, early && initial.available ? applySpeakerGateState(initial, early) : initial);
|
|
31528
|
+
}
|
|
31482
31529
|
if (message.voiceLanguageSwitch) {
|
|
31483
31530
|
voiceLanguageSwitchSettingsBySessionId.set(message.sessionId, message.voiceLanguageSwitch);
|
|
31484
31531
|
} else {
|
|
@@ -31605,6 +31652,8 @@ async function handleParentMessage(message, handlers) {
|
|
|
31605
31652
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
31606
31653
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
31607
31654
|
speakerGateBySessionId.delete(message.sessionId);
|
|
31655
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
31656
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
31608
31657
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
31609
31658
|
lastVoiceLanguageBySessionId.delete(message.sessionId);
|
|
31610
31659
|
ttsPoseAvailableBySessionId.delete(message.sessionId);
|
|
@@ -31698,6 +31747,10 @@ function defineAgent(handlers) {
|
|
|
31698
31747
|
handleResetSpeakerEnrollmentResult(message);
|
|
31699
31748
|
return;
|
|
31700
31749
|
}
|
|
31750
|
+
if (isSpeakerGateStateMessage(message)) {
|
|
31751
|
+
handleSpeakerGateState(message);
|
|
31752
|
+
return;
|
|
31753
|
+
}
|
|
31701
31754
|
if (isWebhookMessage(message)) {
|
|
31702
31755
|
void agentStartReady.then(() => handleWebhookMessage(message, handlers));
|
|
31703
31756
|
return;
|
|
@@ -31706,6 +31759,8 @@ function defineAgent(handlers) {
|
|
|
31706
31759
|
return;
|
|
31707
31760
|
if (message.type === "session_end") {
|
|
31708
31761
|
endedSessionIds.add(message.sessionId);
|
|
31762
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
31763
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
31709
31764
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
31710
31765
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
31711
31766
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
@@ -32033,6 +32088,8 @@ function setAgentState(sessionId, state2, options) {
|
|
|
32033
32088
|
...detail ? { detail: detail.slice(0, 64) } : {}
|
|
32034
32089
|
});
|
|
32035
32090
|
}
|
|
32091
|
+
var SPEAKER_GATE_MODES = ["disabled", "auto", "manual"];
|
|
32092
|
+
var SPEAKER_GATE_BARGE_IN = ["caller_only", "anyone"];
|
|
32036
32093
|
function getSessionUser(sessionId) {
|
|
32037
32094
|
return endUserBySessionId.get(sessionId);
|
|
32038
32095
|
}
|
|
@@ -36552,7 +36609,11 @@ ${t.inputText}` : t.inputText, {
|
|
|
36552
36609
|
turnId: t.turnId,
|
|
36553
36610
|
text
|
|
36554
36611
|
});
|
|
36555
|
-
sendToClient(s.sessionId, {
|
|
36612
|
+
sendToClient(s.sessionId, {
|
|
36613
|
+
type: "chat_reply",
|
|
36614
|
+
text,
|
|
36615
|
+
turnId: t.turnId
|
|
36616
|
+
});
|
|
36556
36617
|
if (!speakChat && text.trim() !== "")
|
|
36557
36618
|
recordReply(s.sessionId, text, { turnId: t.turnId });
|
|
36558
36619
|
}
|
|
@@ -30884,6 +30884,12 @@ function isSetSpeakerGateResultMessage(value) {
|
|
|
30884
30884
|
const msg = value;
|
|
30885
30885
|
return msg.type === "setSpeakerGateResult" && typeof msg.requestId === "string";
|
|
30886
30886
|
}
|
|
30887
|
+
function isSpeakerGateStateMessage(value) {
|
|
30888
|
+
if (!value || typeof value !== "object")
|
|
30889
|
+
return false;
|
|
30890
|
+
const msg = value;
|
|
30891
|
+
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));
|
|
30892
|
+
}
|
|
30887
30893
|
function isResetSpeakerEnrollmentResultMessage(value) {
|
|
30888
30894
|
if (!value || typeof value !== "object")
|
|
30889
30895
|
return false;
|
|
@@ -30938,7 +30944,7 @@ function isParentMessage(value) {
|
|
|
30938
30944
|
if (!value || typeof value !== "object")
|
|
30939
30945
|
return false;
|
|
30940
30946
|
const msg = value;
|
|
30941
|
-
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";
|
|
30947
|
+
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";
|
|
30942
30948
|
}
|
|
30943
30949
|
function isSessionScopedParentMessage(value) {
|
|
30944
30950
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -30959,6 +30965,7 @@ var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
|
30959
30965
|
var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
|
|
30960
30966
|
var speakerGateBySessionId = /* @__PURE__ */ new Map();
|
|
30961
30967
|
var pendingSpeakerGateAcks = /* @__PURE__ */ new Map();
|
|
30968
|
+
var pendingSpeakerGateStateBySessionId = /* @__PURE__ */ new Map();
|
|
30962
30969
|
var pendingSpeakerResets = /* @__PURE__ */ new Map();
|
|
30963
30970
|
var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
30964
30971
|
var speakControlAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
@@ -31249,6 +31256,41 @@ function handleResetSpeakerEnrollmentResult(message) {
|
|
|
31249
31256
|
pendingSpeakerResets.delete(message.requestId);
|
|
31250
31257
|
pending.resolve(message.ok ? { ok: true } : { ok: false, reason: message.reason });
|
|
31251
31258
|
}
|
|
31259
|
+
function applySpeakerGateState(prev, message) {
|
|
31260
|
+
return {
|
|
31261
|
+
available: true,
|
|
31262
|
+
mode: message.mode,
|
|
31263
|
+
bargeIn: message.bargeIn ?? prev.bargeIn
|
|
31264
|
+
};
|
|
31265
|
+
}
|
|
31266
|
+
function handleSpeakerGateState(message) {
|
|
31267
|
+
if (endedSessionIds.has(message.sessionId))
|
|
31268
|
+
return;
|
|
31269
|
+
const prev = speakerGateBySessionId.get(message.sessionId);
|
|
31270
|
+
if (prev) {
|
|
31271
|
+
if (prev.available) {
|
|
31272
|
+
speakerGateBySessionId.set(message.sessionId, applySpeakerGateState(prev, message));
|
|
31273
|
+
}
|
|
31274
|
+
return;
|
|
31275
|
+
}
|
|
31276
|
+
pendingSpeakerGateStateBySessionId.set(message.sessionId, message);
|
|
31277
|
+
}
|
|
31278
|
+
function clearPendingSpeakerRequestsForSession(sessionId, reason) {
|
|
31279
|
+
for (const [requestId, pending] of pendingSpeakerGateAcks) {
|
|
31280
|
+
if (pending.sessionId !== sessionId)
|
|
31281
|
+
continue;
|
|
31282
|
+
clearTimeout(pending.timer);
|
|
31283
|
+
pendingSpeakerGateAcks.delete(requestId);
|
|
31284
|
+
pending.resolve({ ok: false, reason });
|
|
31285
|
+
}
|
|
31286
|
+
for (const [requestId, pending] of pendingSpeakerResets) {
|
|
31287
|
+
if (pending.sessionId !== sessionId)
|
|
31288
|
+
continue;
|
|
31289
|
+
clearTimeout(pending.timer);
|
|
31290
|
+
pendingSpeakerResets.delete(requestId);
|
|
31291
|
+
pending.resolve({ ok: false, reason });
|
|
31292
|
+
}
|
|
31293
|
+
}
|
|
31252
31294
|
function handleVoiceReplayLastResult(message) {
|
|
31253
31295
|
const pending = pendingVoiceReplays.get(message.requestId);
|
|
31254
31296
|
if (!pending)
|
|
@@ -31478,7 +31520,12 @@ async function handleParentMessage(message, handlers) {
|
|
|
31478
31520
|
speakControlAvailableBySessionId.set(message.sessionId, message.speakControlAvailable ?? false);
|
|
31479
31521
|
chatReplyRecordAvailableBySessionId.set(message.sessionId, message.chatReplyRecordAvailable ?? false);
|
|
31480
31522
|
sessionTimeLimitAvailableBySessionId.set(message.sessionId, message.sessionTimeLimitAvailable ?? false);
|
|
31481
|
-
|
|
31523
|
+
{
|
|
31524
|
+
const initial = message.speakerGate?.available === true ? message.speakerGate : { available: false };
|
|
31525
|
+
const early = pendingSpeakerGateStateBySessionId.get(message.sessionId);
|
|
31526
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
31527
|
+
speakerGateBySessionId.set(message.sessionId, early && initial.available ? applySpeakerGateState(initial, early) : initial);
|
|
31528
|
+
}
|
|
31482
31529
|
if (message.voiceLanguageSwitch) {
|
|
31483
31530
|
voiceLanguageSwitchSettingsBySessionId.set(message.sessionId, message.voiceLanguageSwitch);
|
|
31484
31531
|
} else {
|
|
@@ -31605,6 +31652,8 @@ async function handleParentMessage(message, handlers) {
|
|
|
31605
31652
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
31606
31653
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
31607
31654
|
speakerGateBySessionId.delete(message.sessionId);
|
|
31655
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
31656
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
31608
31657
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
31609
31658
|
lastVoiceLanguageBySessionId.delete(message.sessionId);
|
|
31610
31659
|
ttsPoseAvailableBySessionId.delete(message.sessionId);
|
|
@@ -31698,6 +31747,10 @@ function defineAgent(handlers) {
|
|
|
31698
31747
|
handleResetSpeakerEnrollmentResult(message);
|
|
31699
31748
|
return;
|
|
31700
31749
|
}
|
|
31750
|
+
if (isSpeakerGateStateMessage(message)) {
|
|
31751
|
+
handleSpeakerGateState(message);
|
|
31752
|
+
return;
|
|
31753
|
+
}
|
|
31701
31754
|
if (isWebhookMessage(message)) {
|
|
31702
31755
|
void agentStartReady.then(() => handleWebhookMessage(message, handlers));
|
|
31703
31756
|
return;
|
|
@@ -31706,6 +31759,8 @@ function defineAgent(handlers) {
|
|
|
31706
31759
|
return;
|
|
31707
31760
|
if (message.type === "session_end") {
|
|
31708
31761
|
endedSessionIds.add(message.sessionId);
|
|
31762
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
31763
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
31709
31764
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
31710
31765
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
31711
31766
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
@@ -32033,6 +32088,8 @@ function setAgentState(sessionId, state2, options) {
|
|
|
32033
32088
|
...detail ? { detail: detail.slice(0, 64) } : {}
|
|
32034
32089
|
});
|
|
32035
32090
|
}
|
|
32091
|
+
var SPEAKER_GATE_MODES = ["disabled", "auto", "manual"];
|
|
32092
|
+
var SPEAKER_GATE_BARGE_IN = ["caller_only", "anyone"];
|
|
32036
32093
|
function getSessionUser(sessionId) {
|
|
32037
32094
|
return endUserBySessionId.get(sessionId);
|
|
32038
32095
|
}
|
|
@@ -36552,7 +36609,11 @@ ${t.inputText}` : t.inputText, {
|
|
|
36552
36609
|
turnId: t.turnId,
|
|
36553
36610
|
text
|
|
36554
36611
|
});
|
|
36555
|
-
sendToClient(s.sessionId, {
|
|
36612
|
+
sendToClient(s.sessionId, {
|
|
36613
|
+
type: "chat_reply",
|
|
36614
|
+
text,
|
|
36615
|
+
turnId: t.turnId
|
|
36616
|
+
});
|
|
36556
36617
|
if (!speakChat && text.trim() !== "")
|
|
36557
36618
|
recordReply(s.sessionId, text, { turnId: t.turnId });
|
|
36558
36619
|
}
|
|
@@ -30884,6 +30884,12 @@ function isSetSpeakerGateResultMessage(value) {
|
|
|
30884
30884
|
const msg = value;
|
|
30885
30885
|
return msg.type === "setSpeakerGateResult" && typeof msg.requestId === "string";
|
|
30886
30886
|
}
|
|
30887
|
+
function isSpeakerGateStateMessage(value) {
|
|
30888
|
+
if (!value || typeof value !== "object")
|
|
30889
|
+
return false;
|
|
30890
|
+
const msg = value;
|
|
30891
|
+
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));
|
|
30892
|
+
}
|
|
30887
30893
|
function isResetSpeakerEnrollmentResultMessage(value) {
|
|
30888
30894
|
if (!value || typeof value !== "object")
|
|
30889
30895
|
return false;
|
|
@@ -30938,7 +30944,7 @@ function isParentMessage(value) {
|
|
|
30938
30944
|
if (!value || typeof value !== "object")
|
|
30939
30945
|
return false;
|
|
30940
30946
|
const msg = value;
|
|
30941
|
-
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";
|
|
30947
|
+
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";
|
|
30942
30948
|
}
|
|
30943
30949
|
function isSessionScopedParentMessage(value) {
|
|
30944
30950
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -30959,6 +30965,7 @@ var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
|
30959
30965
|
var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
|
|
30960
30966
|
var speakerGateBySessionId = /* @__PURE__ */ new Map();
|
|
30961
30967
|
var pendingSpeakerGateAcks = /* @__PURE__ */ new Map();
|
|
30968
|
+
var pendingSpeakerGateStateBySessionId = /* @__PURE__ */ new Map();
|
|
30962
30969
|
var pendingSpeakerResets = /* @__PURE__ */ new Map();
|
|
30963
30970
|
var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
30964
30971
|
var speakControlAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
@@ -31249,6 +31256,41 @@ function handleResetSpeakerEnrollmentResult(message) {
|
|
|
31249
31256
|
pendingSpeakerResets.delete(message.requestId);
|
|
31250
31257
|
pending.resolve(message.ok ? { ok: true } : { ok: false, reason: message.reason });
|
|
31251
31258
|
}
|
|
31259
|
+
function applySpeakerGateState(prev, message) {
|
|
31260
|
+
return {
|
|
31261
|
+
available: true,
|
|
31262
|
+
mode: message.mode,
|
|
31263
|
+
bargeIn: message.bargeIn ?? prev.bargeIn
|
|
31264
|
+
};
|
|
31265
|
+
}
|
|
31266
|
+
function handleSpeakerGateState(message) {
|
|
31267
|
+
if (endedSessionIds.has(message.sessionId))
|
|
31268
|
+
return;
|
|
31269
|
+
const prev = speakerGateBySessionId.get(message.sessionId);
|
|
31270
|
+
if (prev) {
|
|
31271
|
+
if (prev.available) {
|
|
31272
|
+
speakerGateBySessionId.set(message.sessionId, applySpeakerGateState(prev, message));
|
|
31273
|
+
}
|
|
31274
|
+
return;
|
|
31275
|
+
}
|
|
31276
|
+
pendingSpeakerGateStateBySessionId.set(message.sessionId, message);
|
|
31277
|
+
}
|
|
31278
|
+
function clearPendingSpeakerRequestsForSession(sessionId, reason) {
|
|
31279
|
+
for (const [requestId, pending] of pendingSpeakerGateAcks) {
|
|
31280
|
+
if (pending.sessionId !== sessionId)
|
|
31281
|
+
continue;
|
|
31282
|
+
clearTimeout(pending.timer);
|
|
31283
|
+
pendingSpeakerGateAcks.delete(requestId);
|
|
31284
|
+
pending.resolve({ ok: false, reason });
|
|
31285
|
+
}
|
|
31286
|
+
for (const [requestId, pending] of pendingSpeakerResets) {
|
|
31287
|
+
if (pending.sessionId !== sessionId)
|
|
31288
|
+
continue;
|
|
31289
|
+
clearTimeout(pending.timer);
|
|
31290
|
+
pendingSpeakerResets.delete(requestId);
|
|
31291
|
+
pending.resolve({ ok: false, reason });
|
|
31292
|
+
}
|
|
31293
|
+
}
|
|
31252
31294
|
function handleVoiceReplayLastResult(message) {
|
|
31253
31295
|
const pending = pendingVoiceReplays.get(message.requestId);
|
|
31254
31296
|
if (!pending)
|
|
@@ -31478,7 +31520,12 @@ async function handleParentMessage(message, handlers) {
|
|
|
31478
31520
|
speakControlAvailableBySessionId.set(message.sessionId, message.speakControlAvailable ?? false);
|
|
31479
31521
|
chatReplyRecordAvailableBySessionId.set(message.sessionId, message.chatReplyRecordAvailable ?? false);
|
|
31480
31522
|
sessionTimeLimitAvailableBySessionId.set(message.sessionId, message.sessionTimeLimitAvailable ?? false);
|
|
31481
|
-
|
|
31523
|
+
{
|
|
31524
|
+
const initial = message.speakerGate?.available === true ? message.speakerGate : { available: false };
|
|
31525
|
+
const early = pendingSpeakerGateStateBySessionId.get(message.sessionId);
|
|
31526
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
31527
|
+
speakerGateBySessionId.set(message.sessionId, early && initial.available ? applySpeakerGateState(initial, early) : initial);
|
|
31528
|
+
}
|
|
31482
31529
|
if (message.voiceLanguageSwitch) {
|
|
31483
31530
|
voiceLanguageSwitchSettingsBySessionId.set(message.sessionId, message.voiceLanguageSwitch);
|
|
31484
31531
|
} else {
|
|
@@ -31605,6 +31652,8 @@ async function handleParentMessage(message, handlers) {
|
|
|
31605
31652
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
31606
31653
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
31607
31654
|
speakerGateBySessionId.delete(message.sessionId);
|
|
31655
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
31656
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
31608
31657
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
31609
31658
|
lastVoiceLanguageBySessionId.delete(message.sessionId);
|
|
31610
31659
|
ttsPoseAvailableBySessionId.delete(message.sessionId);
|
|
@@ -31698,6 +31747,10 @@ function defineAgent(handlers) {
|
|
|
31698
31747
|
handleResetSpeakerEnrollmentResult(message);
|
|
31699
31748
|
return;
|
|
31700
31749
|
}
|
|
31750
|
+
if (isSpeakerGateStateMessage(message)) {
|
|
31751
|
+
handleSpeakerGateState(message);
|
|
31752
|
+
return;
|
|
31753
|
+
}
|
|
31701
31754
|
if (isWebhookMessage(message)) {
|
|
31702
31755
|
void agentStartReady.then(() => handleWebhookMessage(message, handlers));
|
|
31703
31756
|
return;
|
|
@@ -31706,6 +31759,8 @@ function defineAgent(handlers) {
|
|
|
31706
31759
|
return;
|
|
31707
31760
|
if (message.type === "session_end") {
|
|
31708
31761
|
endedSessionIds.add(message.sessionId);
|
|
31762
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
31763
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
31709
31764
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
31710
31765
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
31711
31766
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
@@ -32033,6 +32088,8 @@ function setAgentState(sessionId, state2, options) {
|
|
|
32033
32088
|
...detail ? { detail: detail.slice(0, 64) } : {}
|
|
32034
32089
|
});
|
|
32035
32090
|
}
|
|
32091
|
+
var SPEAKER_GATE_MODES = ["disabled", "auto", "manual"];
|
|
32092
|
+
var SPEAKER_GATE_BARGE_IN = ["caller_only", "anyone"];
|
|
32036
32093
|
function getSessionUser(sessionId) {
|
|
32037
32094
|
return endUserBySessionId.get(sessionId);
|
|
32038
32095
|
}
|
|
@@ -36552,7 +36609,11 @@ ${t.inputText}` : t.inputText, {
|
|
|
36552
36609
|
turnId: t.turnId,
|
|
36553
36610
|
text
|
|
36554
36611
|
});
|
|
36555
|
-
sendToClient(s.sessionId, {
|
|
36612
|
+
sendToClient(s.sessionId, {
|
|
36613
|
+
type: "chat_reply",
|
|
36614
|
+
text,
|
|
36615
|
+
turnId: t.turnId
|
|
36616
|
+
});
|
|
36556
36617
|
if (!speakChat && text.trim() !== "")
|
|
36557
36618
|
recordReply(s.sessionId, text, { turnId: t.turnId });
|
|
36558
36619
|
}
|
|
@@ -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();
|
|
@@ -608,6 +615,41 @@ function handleResetSpeakerEnrollmentResult(message) {
|
|
|
608
615
|
pendingSpeakerResets.delete(message.requestId);
|
|
609
616
|
pending.resolve(message.ok ? { ok: true } : { ok: false, reason: message.reason });
|
|
610
617
|
}
|
|
618
|
+
function applySpeakerGateState(prev, message) {
|
|
619
|
+
return {
|
|
620
|
+
available: true,
|
|
621
|
+
mode: message.mode,
|
|
622
|
+
bargeIn: message.bargeIn ?? prev.bargeIn
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
function handleSpeakerGateState(message) {
|
|
626
|
+
if (endedSessionIds.has(message.sessionId))
|
|
627
|
+
return;
|
|
628
|
+
const prev = speakerGateBySessionId.get(message.sessionId);
|
|
629
|
+
if (prev) {
|
|
630
|
+
if (prev.available) {
|
|
631
|
+
speakerGateBySessionId.set(message.sessionId, applySpeakerGateState(prev, message));
|
|
632
|
+
}
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
pendingSpeakerGateStateBySessionId.set(message.sessionId, message);
|
|
636
|
+
}
|
|
637
|
+
function clearPendingSpeakerRequestsForSession(sessionId, reason) {
|
|
638
|
+
for (const [requestId, pending] of pendingSpeakerGateAcks) {
|
|
639
|
+
if (pending.sessionId !== sessionId)
|
|
640
|
+
continue;
|
|
641
|
+
clearTimeout(pending.timer);
|
|
642
|
+
pendingSpeakerGateAcks.delete(requestId);
|
|
643
|
+
pending.resolve({ ok: false, reason });
|
|
644
|
+
}
|
|
645
|
+
for (const [requestId, pending] of pendingSpeakerResets) {
|
|
646
|
+
if (pending.sessionId !== sessionId)
|
|
647
|
+
continue;
|
|
648
|
+
clearTimeout(pending.timer);
|
|
649
|
+
pendingSpeakerResets.delete(requestId);
|
|
650
|
+
pending.resolve({ ok: false, reason });
|
|
651
|
+
}
|
|
652
|
+
}
|
|
611
653
|
function handleVoiceReplayLastResult(message) {
|
|
612
654
|
const pending = pendingVoiceReplays.get(message.requestId);
|
|
613
655
|
if (!pending)
|
|
@@ -849,7 +891,12 @@ async function handleParentMessage(message, handlers) {
|
|
|
849
891
|
speakControlAvailableBySessionId.set(message.sessionId, message.speakControlAvailable ?? false);
|
|
850
892
|
chatReplyRecordAvailableBySessionId.set(message.sessionId, message.chatReplyRecordAvailable ?? false);
|
|
851
893
|
sessionTimeLimitAvailableBySessionId.set(message.sessionId, message.sessionTimeLimitAvailable ?? false);
|
|
852
|
-
|
|
894
|
+
{
|
|
895
|
+
const initial = message.speakerGate?.available === true ? message.speakerGate : { available: false };
|
|
896
|
+
const early = pendingSpeakerGateStateBySessionId.get(message.sessionId);
|
|
897
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
898
|
+
speakerGateBySessionId.set(message.sessionId, early && initial.available ? applySpeakerGateState(initial, early) : initial);
|
|
899
|
+
}
|
|
853
900
|
if (message.voiceLanguageSwitch) {
|
|
854
901
|
voiceLanguageSwitchSettingsBySessionId.set(message.sessionId, message.voiceLanguageSwitch);
|
|
855
902
|
} else {
|
|
@@ -976,6 +1023,8 @@ async function handleParentMessage(message, handlers) {
|
|
|
976
1023
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
977
1024
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
978
1025
|
speakerGateBySessionId.delete(message.sessionId);
|
|
1026
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
1027
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
979
1028
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
980
1029
|
lastVoiceLanguageBySessionId.delete(message.sessionId);
|
|
981
1030
|
ttsPoseAvailableBySessionId.delete(message.sessionId);
|
|
@@ -1069,6 +1118,10 @@ function defineAgent(handlers) {
|
|
|
1069
1118
|
handleResetSpeakerEnrollmentResult(message);
|
|
1070
1119
|
return;
|
|
1071
1120
|
}
|
|
1121
|
+
if (isSpeakerGateStateMessage(message)) {
|
|
1122
|
+
handleSpeakerGateState(message);
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1072
1125
|
if (isWebhookMessage(message)) {
|
|
1073
1126
|
void agentStartReady.then(() => handleWebhookMessage(message, handlers));
|
|
1074
1127
|
return;
|
|
@@ -1077,6 +1130,8 @@ function defineAgent(handlers) {
|
|
|
1077
1130
|
return;
|
|
1078
1131
|
if (message.type === "session_end") {
|
|
1079
1132
|
endedSessionIds.add(message.sessionId);
|
|
1133
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
1134
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
1080
1135
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
1081
1136
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
1082
1137
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
@@ -1399,6 +1454,8 @@ function setTtsPose(sessionId, pose) {
|
|
|
1399
1454
|
function clearTtsPose(sessionId) {
|
|
1400
1455
|
return sendTtsPoseControl("clear_tts_pose", { clientId: sessionId });
|
|
1401
1456
|
}
|
|
1457
|
+
var SPEAKER_GATE_MODES = ["disabled", "auto", "manual"];
|
|
1458
|
+
var SPEAKER_GATE_BARGE_IN = ["caller_only", "anyone"];
|
|
1402
1459
|
var AGENT_LOG_MESSAGE_MAX_CHARS = 2048;
|
|
1403
1460
|
var AGENT_LOG_FIELDS_MAX_CHARS = 8192;
|
|
1404
1461
|
function truncateAgentLogMessage(message) {
|
|
@@ -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();
|
|
@@ -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");
|
|
@@ -1352,6 +1407,8 @@ function cancelSpeech(sessionId, target) {
|
|
|
1352
1407
|
...target?.turnId ? { turnId: target.turnId } : {}
|
|
1353
1408
|
});
|
|
1354
1409
|
}
|
|
1410
|
+
var SPEAKER_GATE_MODES = ["disabled", "auto", "manual"];
|
|
1411
|
+
var SPEAKER_GATE_BARGE_IN = ["caller_only", "anyone"];
|
|
1355
1412
|
async function sendRecordingControl(sessionId, action) {
|
|
1356
1413
|
const requestId = randomUUID();
|
|
1357
1414
|
if (!allowOutboundForSession(sessionId)) {
|