@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
|
@@ -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
|
}
|
|
@@ -35958,19 +36015,6 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
|
|
|
35958
36015
|
trackAnnouncement(s, h.done);
|
|
35959
36016
|
return h;
|
|
35960
36017
|
}
|
|
35961
|
-
function greetingDoneStatus(status) {
|
|
35962
|
-
switch (status) {
|
|
35963
|
-
case "played":
|
|
35964
|
-
case "unsupported":
|
|
35965
|
-
return "completed";
|
|
35966
|
-
case "interrupted":
|
|
35967
|
-
return "interrupted";
|
|
35968
|
-
case "cancelled":
|
|
35969
|
-
return "cancelled";
|
|
35970
|
-
case "failed":
|
|
35971
|
-
return "failed";
|
|
35972
|
-
}
|
|
35973
|
-
}
|
|
35974
36018
|
function clearFillerTimer(t, kind) {
|
|
35975
36019
|
for (const [k, timer] of t.fillerTimers) {
|
|
35976
36020
|
if (kind && k !== kind)
|
|
@@ -36565,7 +36609,11 @@ ${t.inputText}` : t.inputText, {
|
|
|
36565
36609
|
turnId: t.turnId,
|
|
36566
36610
|
text
|
|
36567
36611
|
});
|
|
36568
|
-
sendToClient(s.sessionId, {
|
|
36612
|
+
sendToClient(s.sessionId, {
|
|
36613
|
+
type: "chat_reply",
|
|
36614
|
+
text,
|
|
36615
|
+
turnId: t.turnId
|
|
36616
|
+
});
|
|
36569
36617
|
if (!speakChat && text.trim() !== "")
|
|
36570
36618
|
recordReply(s.sessionId, text, { turnId: t.turnId });
|
|
36571
36619
|
}
|
|
@@ -36772,21 +36820,14 @@ ${t.inputText}` : t.inputText, {
|
|
|
36772
36820
|
const turnId = `greet-${randomUUID3()}`;
|
|
36773
36821
|
s.history.addAssistant({ role: "assistant", text: greeting.text }, { turnId });
|
|
36774
36822
|
sendSpokenDelta(s.sessionId, turnId, greeting.text);
|
|
36775
|
-
|
|
36776
|
-
|
|
36777
|
-
|
|
36778
|
-
|
|
36779
|
-
|
|
36780
|
-
|
|
36781
|
-
}
|
|
36782
|
-
sendToClient(s.sessionId, {
|
|
36783
|
-
type: "assistant_done",
|
|
36784
|
-
turnId,
|
|
36785
|
-
text: greeting.text,
|
|
36786
|
-
spoken: true,
|
|
36787
|
-
status: greetingDoneStatus(result.status)
|
|
36788
|
-
});
|
|
36823
|
+
sendToClient(s.sessionId, {
|
|
36824
|
+
type: "assistant_done",
|
|
36825
|
+
turnId,
|
|
36826
|
+
text: greeting.text,
|
|
36827
|
+
spoken: true,
|
|
36828
|
+
status: "completed"
|
|
36789
36829
|
});
|
|
36830
|
+
speakAnnouncement(s, turnId, greeting.text, greeting.interruptible ?? D.greetingInterruptible);
|
|
36790
36831
|
}
|
|
36791
36832
|
},
|
|
36792
36833
|
onUserSpeechFinal(ctx) {
|
|
@@ -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
|
}
|
|
@@ -35958,19 +36015,6 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
|
|
|
35958
36015
|
trackAnnouncement(s, h.done);
|
|
35959
36016
|
return h;
|
|
35960
36017
|
}
|
|
35961
|
-
function greetingDoneStatus(status) {
|
|
35962
|
-
switch (status) {
|
|
35963
|
-
case "played":
|
|
35964
|
-
case "unsupported":
|
|
35965
|
-
return "completed";
|
|
35966
|
-
case "interrupted":
|
|
35967
|
-
return "interrupted";
|
|
35968
|
-
case "cancelled":
|
|
35969
|
-
return "cancelled";
|
|
35970
|
-
case "failed":
|
|
35971
|
-
return "failed";
|
|
35972
|
-
}
|
|
35973
|
-
}
|
|
35974
36018
|
function clearFillerTimer(t, kind) {
|
|
35975
36019
|
for (const [k, timer] of t.fillerTimers) {
|
|
35976
36020
|
if (kind && k !== kind)
|
|
@@ -36565,7 +36609,11 @@ ${t.inputText}` : t.inputText, {
|
|
|
36565
36609
|
turnId: t.turnId,
|
|
36566
36610
|
text
|
|
36567
36611
|
});
|
|
36568
|
-
sendToClient(s.sessionId, {
|
|
36612
|
+
sendToClient(s.sessionId, {
|
|
36613
|
+
type: "chat_reply",
|
|
36614
|
+
text,
|
|
36615
|
+
turnId: t.turnId
|
|
36616
|
+
});
|
|
36569
36617
|
if (!speakChat && text.trim() !== "")
|
|
36570
36618
|
recordReply(s.sessionId, text, { turnId: t.turnId });
|
|
36571
36619
|
}
|
|
@@ -36772,21 +36820,14 @@ ${t.inputText}` : t.inputText, {
|
|
|
36772
36820
|
const turnId = `greet-${randomUUID3()}`;
|
|
36773
36821
|
s.history.addAssistant({ role: "assistant", text: greeting.text }, { turnId });
|
|
36774
36822
|
sendSpokenDelta(s.sessionId, turnId, greeting.text);
|
|
36775
|
-
|
|
36776
|
-
|
|
36777
|
-
|
|
36778
|
-
|
|
36779
|
-
|
|
36780
|
-
|
|
36781
|
-
}
|
|
36782
|
-
sendToClient(s.sessionId, {
|
|
36783
|
-
type: "assistant_done",
|
|
36784
|
-
turnId,
|
|
36785
|
-
text: greeting.text,
|
|
36786
|
-
spoken: true,
|
|
36787
|
-
status: greetingDoneStatus(result.status)
|
|
36788
|
-
});
|
|
36823
|
+
sendToClient(s.sessionId, {
|
|
36824
|
+
type: "assistant_done",
|
|
36825
|
+
turnId,
|
|
36826
|
+
text: greeting.text,
|
|
36827
|
+
spoken: true,
|
|
36828
|
+
status: "completed"
|
|
36789
36829
|
});
|
|
36830
|
+
speakAnnouncement(s, turnId, greeting.text, greeting.interruptible ?? D.greetingInterruptible);
|
|
36790
36831
|
}
|
|
36791
36832
|
},
|
|
36792
36833
|
onUserSpeechFinal(ctx) {
|
|
@@ -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
|
}
|
|
@@ -35958,19 +36015,6 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
|
|
|
35958
36015
|
trackAnnouncement(s, h.done);
|
|
35959
36016
|
return h;
|
|
35960
36017
|
}
|
|
35961
|
-
function greetingDoneStatus(status) {
|
|
35962
|
-
switch (status) {
|
|
35963
|
-
case "played":
|
|
35964
|
-
case "unsupported":
|
|
35965
|
-
return "completed";
|
|
35966
|
-
case "interrupted":
|
|
35967
|
-
return "interrupted";
|
|
35968
|
-
case "cancelled":
|
|
35969
|
-
return "cancelled";
|
|
35970
|
-
case "failed":
|
|
35971
|
-
return "failed";
|
|
35972
|
-
}
|
|
35973
|
-
}
|
|
35974
36018
|
function clearFillerTimer(t, kind) {
|
|
35975
36019
|
for (const [k, timer] of t.fillerTimers) {
|
|
35976
36020
|
if (kind && k !== kind)
|
|
@@ -36565,7 +36609,11 @@ ${t.inputText}` : t.inputText, {
|
|
|
36565
36609
|
turnId: t.turnId,
|
|
36566
36610
|
text
|
|
36567
36611
|
});
|
|
36568
|
-
sendToClient(s.sessionId, {
|
|
36612
|
+
sendToClient(s.sessionId, {
|
|
36613
|
+
type: "chat_reply",
|
|
36614
|
+
text,
|
|
36615
|
+
turnId: t.turnId
|
|
36616
|
+
});
|
|
36569
36617
|
if (!speakChat && text.trim() !== "")
|
|
36570
36618
|
recordReply(s.sessionId, text, { turnId: t.turnId });
|
|
36571
36619
|
}
|
|
@@ -36772,21 +36820,14 @@ ${t.inputText}` : t.inputText, {
|
|
|
36772
36820
|
const turnId = `greet-${randomUUID3()}`;
|
|
36773
36821
|
s.history.addAssistant({ role: "assistant", text: greeting.text }, { turnId });
|
|
36774
36822
|
sendSpokenDelta(s.sessionId, turnId, greeting.text);
|
|
36775
|
-
|
|
36776
|
-
|
|
36777
|
-
|
|
36778
|
-
|
|
36779
|
-
|
|
36780
|
-
|
|
36781
|
-
}
|
|
36782
|
-
sendToClient(s.sessionId, {
|
|
36783
|
-
type: "assistant_done",
|
|
36784
|
-
turnId,
|
|
36785
|
-
text: greeting.text,
|
|
36786
|
-
spoken: true,
|
|
36787
|
-
status: greetingDoneStatus(result.status)
|
|
36788
|
-
});
|
|
36823
|
+
sendToClient(s.sessionId, {
|
|
36824
|
+
type: "assistant_done",
|
|
36825
|
+
turnId,
|
|
36826
|
+
text: greeting.text,
|
|
36827
|
+
spoken: true,
|
|
36828
|
+
status: "completed"
|
|
36789
36829
|
});
|
|
36830
|
+
speakAnnouncement(s, turnId, greeting.text, greeting.interruptible ?? D.greetingInterruptible);
|
|
36790
36831
|
}
|
|
36791
36832
|
},
|
|
36792
36833
|
onUserSpeechFinal(ctx) {
|