@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
|
@@ -10996,6 +10996,12 @@ function isSetSpeakerGateResultMessage(value) {
|
|
|
10996
10996
|
const msg = value;
|
|
10997
10997
|
return msg.type === "setSpeakerGateResult" && typeof msg.requestId === "string";
|
|
10998
10998
|
}
|
|
10999
|
+
function isSpeakerGateStateMessage(value) {
|
|
11000
|
+
if (!value || typeof value !== "object")
|
|
11001
|
+
return false;
|
|
11002
|
+
const msg = value;
|
|
11003
|
+
return msg.type === "speaker_gate_state" && typeof msg.sessionId === "string" && typeof msg.mode === "string" && SPEAKER_GATE_MODES.includes(msg.mode) && (msg.bargeIn === void 0 || typeof msg.bargeIn === "string" && SPEAKER_GATE_BARGE_IN.includes(msg.bargeIn));
|
|
11004
|
+
}
|
|
10999
11005
|
function isResetSpeakerEnrollmentResultMessage(value) {
|
|
11000
11006
|
if (!value || typeof value !== "object")
|
|
11001
11007
|
return false;
|
|
@@ -11050,7 +11056,7 @@ function isParentMessage(value) {
|
|
|
11050
11056
|
if (!value || typeof value !== "object")
|
|
11051
11057
|
return false;
|
|
11052
11058
|
const msg = value;
|
|
11053
|
-
return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "session_time_limit" || msg.type === "session_time_limit_control_ack" || msg.type === "recording_control_ack" || msg.type === "conversation_history_control_ack" || msg.type === "user_identified" || msg.type === "user_history_response" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "play_pose_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "voice_language_control_ack" || msg.type === "voice_language_prepare_result" || msg.type === "voice_replay_last_result" || msg.type === "setSpeakerGateResult" || msg.type === "resetSpeakerEnrollmentResult" || msg.type === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
|
|
11059
|
+
return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "session_time_limit" || msg.type === "session_time_limit_control_ack" || msg.type === "recording_control_ack" || msg.type === "conversation_history_control_ack" || msg.type === "user_identified" || msg.type === "user_history_response" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "play_pose_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "voice_language_control_ack" || msg.type === "voice_language_prepare_result" || msg.type === "voice_replay_last_result" || msg.type === "setSpeakerGateResult" || msg.type === "resetSpeakerEnrollmentResult" || msg.type === "speaker_gate_state" || msg.type === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
|
|
11054
11060
|
}
|
|
11055
11061
|
function isSessionScopedParentMessage(value) {
|
|
11056
11062
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -11071,6 +11077,7 @@ var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
|
11071
11077
|
var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
|
|
11072
11078
|
var speakerGateBySessionId = /* @__PURE__ */ new Map();
|
|
11073
11079
|
var pendingSpeakerGateAcks = /* @__PURE__ */ new Map();
|
|
11080
|
+
var pendingSpeakerGateStateBySessionId = /* @__PURE__ */ new Map();
|
|
11074
11081
|
var pendingSpeakerResets = /* @__PURE__ */ new Map();
|
|
11075
11082
|
var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
11076
11083
|
var speakControlAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
@@ -11358,6 +11365,41 @@ function handleResetSpeakerEnrollmentResult(message) {
|
|
|
11358
11365
|
pendingSpeakerResets.delete(message.requestId);
|
|
11359
11366
|
pending.resolve(message.ok ? { ok: true } : { ok: false, reason: message.reason });
|
|
11360
11367
|
}
|
|
11368
|
+
function applySpeakerGateState(prev, message) {
|
|
11369
|
+
return {
|
|
11370
|
+
available: true,
|
|
11371
|
+
mode: message.mode,
|
|
11372
|
+
bargeIn: message.bargeIn ?? prev.bargeIn
|
|
11373
|
+
};
|
|
11374
|
+
}
|
|
11375
|
+
function handleSpeakerGateState(message) {
|
|
11376
|
+
if (endedSessionIds.has(message.sessionId))
|
|
11377
|
+
return;
|
|
11378
|
+
const prev = speakerGateBySessionId.get(message.sessionId);
|
|
11379
|
+
if (prev) {
|
|
11380
|
+
if (prev.available) {
|
|
11381
|
+
speakerGateBySessionId.set(message.sessionId, applySpeakerGateState(prev, message));
|
|
11382
|
+
}
|
|
11383
|
+
return;
|
|
11384
|
+
}
|
|
11385
|
+
pendingSpeakerGateStateBySessionId.set(message.sessionId, message);
|
|
11386
|
+
}
|
|
11387
|
+
function clearPendingSpeakerRequestsForSession(sessionId, reason) {
|
|
11388
|
+
for (const [requestId, pending] of pendingSpeakerGateAcks) {
|
|
11389
|
+
if (pending.sessionId !== sessionId)
|
|
11390
|
+
continue;
|
|
11391
|
+
clearTimeout(pending.timer);
|
|
11392
|
+
pendingSpeakerGateAcks.delete(requestId);
|
|
11393
|
+
pending.resolve({ ok: false, reason });
|
|
11394
|
+
}
|
|
11395
|
+
for (const [requestId, pending] of pendingSpeakerResets) {
|
|
11396
|
+
if (pending.sessionId !== sessionId)
|
|
11397
|
+
continue;
|
|
11398
|
+
clearTimeout(pending.timer);
|
|
11399
|
+
pendingSpeakerResets.delete(requestId);
|
|
11400
|
+
pending.resolve({ ok: false, reason });
|
|
11401
|
+
}
|
|
11402
|
+
}
|
|
11361
11403
|
function handleVoiceReplayLastResult(message) {
|
|
11362
11404
|
const pending = pendingVoiceReplays.get(message.requestId);
|
|
11363
11405
|
if (!pending)
|
|
@@ -11584,7 +11626,12 @@ async function handleParentMessage(message, handlers) {
|
|
|
11584
11626
|
speakControlAvailableBySessionId.set(message.sessionId, message.speakControlAvailable ?? false);
|
|
11585
11627
|
chatReplyRecordAvailableBySessionId.set(message.sessionId, message.chatReplyRecordAvailable ?? false);
|
|
11586
11628
|
sessionTimeLimitAvailableBySessionId.set(message.sessionId, message.sessionTimeLimitAvailable ?? false);
|
|
11587
|
-
|
|
11629
|
+
{
|
|
11630
|
+
const initial = message.speakerGate?.available === true ? message.speakerGate : { available: false };
|
|
11631
|
+
const early = pendingSpeakerGateStateBySessionId.get(message.sessionId);
|
|
11632
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
11633
|
+
speakerGateBySessionId.set(message.sessionId, early && initial.available ? applySpeakerGateState(initial, early) : initial);
|
|
11634
|
+
}
|
|
11588
11635
|
if (message.voiceLanguageSwitch) {
|
|
11589
11636
|
voiceLanguageSwitchSettingsBySessionId.set(message.sessionId, message.voiceLanguageSwitch);
|
|
11590
11637
|
} else {
|
|
@@ -11711,6 +11758,8 @@ async function handleParentMessage(message, handlers) {
|
|
|
11711
11758
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
11712
11759
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
11713
11760
|
speakerGateBySessionId.delete(message.sessionId);
|
|
11761
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
11762
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
11714
11763
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
11715
11764
|
lastVoiceLanguageBySessionId.delete(message.sessionId);
|
|
11716
11765
|
ttsPoseAvailableBySessionId.delete(message.sessionId);
|
|
@@ -11804,6 +11853,10 @@ function defineAgent(handlers) {
|
|
|
11804
11853
|
handleResetSpeakerEnrollmentResult(message);
|
|
11805
11854
|
return;
|
|
11806
11855
|
}
|
|
11856
|
+
if (isSpeakerGateStateMessage(message)) {
|
|
11857
|
+
handleSpeakerGateState(message);
|
|
11858
|
+
return;
|
|
11859
|
+
}
|
|
11807
11860
|
if (isWebhookMessage(message)) {
|
|
11808
11861
|
void agentStartReady.then(() => handleWebhookMessage(message, handlers));
|
|
11809
11862
|
return;
|
|
@@ -11812,6 +11865,8 @@ function defineAgent(handlers) {
|
|
|
11812
11865
|
return;
|
|
11813
11866
|
if (message.type === "session_end") {
|
|
11814
11867
|
endedSessionIds.add(message.sessionId);
|
|
11868
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
11869
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
11815
11870
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
11816
11871
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
11817
11872
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
@@ -12001,6 +12056,8 @@ function buildIdleEnv(sessionId) {
|
|
|
12001
12056
|
...process.env.IDLE_TIMEOUT_SEC ? { IDLE_TIMEOUT_SEC: process.env.IDLE_TIMEOUT_SEC } : {}
|
|
12002
12057
|
};
|
|
12003
12058
|
}
|
|
12059
|
+
var SPEAKER_GATE_MODES = ["disabled", "auto", "manual"];
|
|
12060
|
+
var SPEAKER_GATE_BARGE_IN = ["caller_only", "anyone"];
|
|
12004
12061
|
function sendToClient(sessionId, payload) {
|
|
12005
12062
|
sendParentMessage({ type: "send_to_client", sessionId, payload });
|
|
12006
12063
|
}
|
|
@@ -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
|
}
|
|
@@ -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 asOutboundBuffer(data) {
|
|
1250
1307
|
return Buffer.isBuffer(data) ? data : Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
1251
1308
|
}
|
package/eject/llm/loop.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copied from @voicethere/agent 0.29.
|
|
1
|
+
// Copied from @voicethere/agent 0.29.3. Package updates no longer change this file.
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import {
|
|
4
4
|
type AgentHandlers,
|
|
@@ -1253,7 +1253,11 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
|
|
|
1253
1253
|
turnId: t.turnId,
|
|
1254
1254
|
text,
|
|
1255
1255
|
});
|
|
1256
|
-
sendToClient(s.sessionId, {
|
|
1256
|
+
sendToClient(s.sessionId, {
|
|
1257
|
+
type: "chat_reply",
|
|
1258
|
+
text,
|
|
1259
|
+
turnId: t.turnId,
|
|
1260
|
+
});
|
|
1257
1261
|
if (!speakChat && text.trim() !== "")
|
|
1258
1262
|
recordReply(s.sessionId, text, { turnId: t.turnId });
|
|
1259
1263
|
}
|
package/package.json
CHANGED
package/templates/README.md
CHANGED
|
@@ -17,10 +17,10 @@ import {
|
|
|
17
17
|
|
|
18
18
|
## Product vs e2e
|
|
19
19
|
|
|
20
|
-
| Kind | Dashboard create | Prebuilt seed bundle | Typical consumer
|
|
21
|
-
| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
|
|
22
|
-
| **product** | Yes (`echo`, `echo-dc`, `voice-starter`, `language-switch`, `speaker-gate`, `world-sync`, `world-sync-binary`, `game-sync`, `voice-showcase`, `recording-consent`, `positional-tts`, `spatial-showcase`, `webhooks`, `webhooks-redis`) | Yes — `dist/templates/<id>/agent.js` | Platform project create
|
|
23
|
-
| **e2e** | No | No — build from sources at test time |
|
|
20
|
+
| Kind | Dashboard create | Prebuilt seed bundle | Typical consumer |
|
|
21
|
+
| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ | --------------------------------- |
|
|
22
|
+
| **product** | Yes (`echo`, `echo-dc`, `voice-starter`, `language-switch`, `speaker-gate`, `world-sync`, `world-sync-binary`, `game-sync`, `voice-showcase`, `recording-consent`, `positional-tts`, `spatial-showcase`, `webhooks`, `webhooks-redis`) | Yes — `dist/templates/<id>/agent.js` | Platform project create |
|
|
23
|
+
| **e2e** | No | No — build from sources at test time | VoiceThere end-to-end smoke tests |
|
|
24
24
|
|
|
25
25
|
Product templates always set `seedOnCreate: true`. CI fails if a product template is missing its prebuilt bundle after `npm run build`.
|
|
26
26
|
|
|
@@ -82,7 +82,7 @@ Each folder has its own README. Summary:
|
|
|
82
82
|
|
|
83
83
|
## E2e templates
|
|
84
84
|
|
|
85
|
-
These
|
|
85
|
+
These were the end-to-end test fixtures; the tests resolve entries from the package, build them into ephemeral workdirs, and upload `dist/agent.js`.
|
|
86
86
|
|
|
87
87
|
| Id | Source | Purpose |
|
|
88
88
|
| ----------------- | ----------------------------------------- | ------------------------------------------------------ |
|
|
@@ -49,7 +49,7 @@ The `fillers` block in `voicethere.llm.json` lists short sentences the agent spe
|
|
|
49
49
|
|
|
50
50
|
## Client messages for voice replies
|
|
51
51
|
|
|
52
|
-
A voice reply also reaches the client as text. Each spoken sentence arrives as `{ "type": "assistant_delta", "turnId", "text", "spoken": true }`, and the turn ends with one `{ "type": "assistant_done", "turnId", "text", "spoken": true, "status" }`. `status` is `completed`, `failed`, `interrupted` or `cancelled`, and `text` holds the sentences delivered so far. When the runner sends an utterance id for the caller's final (`SpeechContext.utteranceId` in `onUserSpeechFinal`), both messages also carry `inReplyTo`, the caller utterance the reply answers. Render one line per `turnId` and reveal it as the speech plays. Typed (chat) turns keep sending `assistant_delta`, `assistant_done` and `chat_reply` without `spoken
|
|
52
|
+
A voice reply also reaches the client as text. Each spoken sentence arrives as `{ "type": "assistant_delta", "turnId", "text", "spoken": true }`, and the turn ends with one `{ "type": "assistant_done", "turnId", "text", "spoken": true, "status" }`. `status` is `completed`, `failed`, `interrupted` or `cancelled`, and `text` holds the sentences delivered so far. When the runner sends an utterance id for the caller's final (`SpeechContext.utteranceId` in `onUserSpeechFinal`), both messages also carry `inReplyTo`, the caller utterance the reply answers. Render one line per `turnId` and reveal it as the speech plays. Typed (chat) turns keep sending `assistant_delta`, `assistant_done` and `chat_reply` without `spoken`; the `chat_reply` is `{ "type": "chat_reply", "text", "turnId" }` with the `turnId` of the `assistant_done` before it. Fillers are never part of this reply text; see `assistant_filler` below.
|
|
53
53
|
|
|
54
54
|
## Always search first
|
|
55
55
|
|
|
@@ -19,11 +19,13 @@ The project's voice settings pick the mode the call starts in (`speakerGate.mode
|
|
|
19
19
|
- In `manual` it answers `caller` and `unknown` finals. When it hears `other` it says one short line, at most once every 30 seconds, and otherwise stays quiet.
|
|
20
20
|
- Every event writes one agent log line with a counter `n` that starts at 1 and counts all lines of the session:
|
|
21
21
|
- `speaker_gate.mode n=1 mode=auto` at connect and after each applied mode command;
|
|
22
|
-
- `speaker_gate.final n=2 speaker=caller|other|unknown|none text="..."` for every final (`none` when the event has no verdict). This line includes the transcript, so treat these logs as call content;
|
|
22
|
+
- `speaker_gate.final n=2 speaker=caller|other|unknown|none utteranceId=<id> reason=<reason> text="..."` for every final (`none` when the event has no verdict; `utteranceId` and `reason`, the speaker unknown reason such as `not_enrolled`, appear only when the runner sets them, and `text` is always last). This line includes the transcript, so treat these logs as call content;
|
|
23
23
|
- `speaker_gate.ignored n=3 utteranceId=<id> reason=speaker_mismatch` for each utterance `auto` mode drops;
|
|
24
24
|
- `speaker_gate.reset n=4` after an enrollment reset.
|
|
25
25
|
- A bystander's voice cannot change the mode: spoken commands are ignored when the verdict is `other`.
|
|
26
26
|
|
|
27
|
+
The mode you request and the mode in effect can differ. If the speaker model fails to load, the runner switches the gate to `disabled` and tells the agent once; `getSpeakerGate(sessionId)` then returns `mode: "disabled"`. A pending `setSpeakerGate` or `resetSpeakerEnrollment` call resolves `{ ok: false, reason: "session_ended" }` as soon as the session ends.
|
|
28
|
+
|
|
27
29
|
## Switching the mode
|
|
28
30
|
|
|
29
31
|
Send a data-channel chat message, `{ "type": "chat", "text": "speaker-gate:auto" }`:
|
|
@@ -119,10 +119,14 @@ defineAgent({
|
|
|
119
119
|
},
|
|
120
120
|
|
|
121
121
|
async onUserSpeechFinal(ctx) {
|
|
122
|
+
const utterance = ctx.utteranceId ? ` utteranceId=${ctx.utteranceId}` : "";
|
|
123
|
+
const reason = ctx.speakerUnknownReason
|
|
124
|
+
? ` reason=${ctx.speakerUnknownReason}`
|
|
125
|
+
: "";
|
|
122
126
|
logLine(
|
|
123
127
|
ctx.sessionId,
|
|
124
128
|
"final",
|
|
125
|
-
`speaker=${ctx.speaker ?? "none"} text=${JSON.stringify(ctx.text)}`,
|
|
129
|
+
`speaker=${ctx.speaker ?? "none"}${utterance}${reason} text=${JSON.stringify(ctx.text)}`,
|
|
126
130
|
);
|
|
127
131
|
const spoken = parseSpokenCommand(ctx.text);
|
|
128
132
|
// A bystander cannot change the mode in manual mode.
|