@voicethere/agent 0.29.0 → 0.29.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/agent.js +61 -5
- package/dist/flow/effects-node.d.ts.map +1 -1
- package/dist/flow/effects-node.js +5 -1
- package/dist/flow/effects-node.js.map +1 -1
- package/dist/llm/agent/create-llm-agent.d.ts.map +1 -1
- package/dist/llm/agent/create-llm-agent.js +14 -31
- package/dist/llm/agent/create-llm-agent.js.map +1 -1
- package/dist/protocol.d.ts +16 -3
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +75 -4
- package/dist/runtime.js.map +1 -1
- package/dist/templates/echo/agent.js +59 -2
- package/dist/templates/echo-dc/agent.js +59 -2
- package/dist/templates/flow-agent/agent.js +64 -3
- package/dist/templates/game-sync/agent.js +59 -2
- package/dist/templates/language-switch/agent.js +59 -2
- package/dist/templates/llm-agent/agent.js +71 -30
- package/dist/templates/llm-docs-rag/agent.js +71 -30
- package/dist/templates/llm-mcp-service/agent.js +71 -30
- package/dist/templates/llm-support-sticky-user/agent.js +71 -30
- package/dist/templates/positional-tts/agent.js +59 -2
- package/dist/templates/recording-consent/agent.js +59 -2
- package/dist/templates/spatial-showcase/agent.js +59 -2
- package/dist/templates/speaker-gate/agent.js +61 -4
- package/dist/templates/voice-showcase/agent.js +59 -2
- package/dist/templates/voice-starter/agent.js +59 -2
- package/dist/templates/webhooks/agent.js +59 -2
- package/dist/templates/webhooks-redis/agent.js +59 -2
- package/dist/templates/world-sync/agent.js +59 -2
- package/dist/templates/world-sync-binary/agent.js +59 -2
- package/eject/llm/loop.ts +16 -38
- package/package.json +1 -1
- package/templates/README.md +5 -5
- package/templates/llm-agent/README.md +5 -1
- package/templates/speaker-gate/README.md +3 -1
- package/templates/speaker-gate/agent.ts +5 -1
|
@@ -241,6 +241,12 @@ function isSetSpeakerGateResultMessage(value) {
|
|
|
241
241
|
const msg = value;
|
|
242
242
|
return msg.type === "setSpeakerGateResult" && typeof msg.requestId === "string";
|
|
243
243
|
}
|
|
244
|
+
function isSpeakerGateStateMessage(value) {
|
|
245
|
+
if (!value || typeof value !== "object")
|
|
246
|
+
return false;
|
|
247
|
+
const msg = value;
|
|
248
|
+
return msg.type === "speaker_gate_state" && typeof msg.sessionId === "string" && typeof msg.mode === "string" && SPEAKER_GATE_MODES.includes(msg.mode) && (msg.bargeIn === void 0 || typeof msg.bargeIn === "string" && SPEAKER_GATE_BARGE_IN.includes(msg.bargeIn));
|
|
249
|
+
}
|
|
244
250
|
function isResetSpeakerEnrollmentResultMessage(value) {
|
|
245
251
|
if (!value || typeof value !== "object")
|
|
246
252
|
return false;
|
|
@@ -295,7 +301,7 @@ function isParentMessage(value) {
|
|
|
295
301
|
if (!value || typeof value !== "object")
|
|
296
302
|
return false;
|
|
297
303
|
const msg = value;
|
|
298
|
-
return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "session_time_limit" || msg.type === "session_time_limit_control_ack" || msg.type === "recording_control_ack" || msg.type === "conversation_history_control_ack" || msg.type === "user_identified" || msg.type === "user_history_response" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "play_pose_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "voice_language_control_ack" || msg.type === "voice_language_prepare_result" || msg.type === "voice_replay_last_result" || msg.type === "setSpeakerGateResult" || msg.type === "resetSpeakerEnrollmentResult" || msg.type === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
|
|
304
|
+
return msg.type === "session_start" || msg.type === "speech_event" || msg.type === "session_end" || msg.type === "data_channel_message" || msg.type === "data_channel_binary" || msg.type === "idle_timeout" || msg.type === "session_time_limit" || msg.type === "session_time_limit_control_ack" || msg.type === "recording_control_ack" || msg.type === "conversation_history_control_ack" || msg.type === "user_identified" || msg.type === "user_history_response" || msg.type === "play_ack" || msg.type === "play_status_ack" || msg.type === "play_stop_ack" || msg.type === "play_pose_ack" || msg.type === "mix_control_ack" || msg.type === "stt_control_ack" || msg.type === "voice_language_control_ack" || msg.type === "voice_language_prepare_result" || msg.type === "voice_replay_last_result" || msg.type === "setSpeakerGateResult" || msg.type === "resetSpeakerEnrollmentResult" || msg.type === "speaker_gate_state" || msg.type === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
|
|
299
305
|
}
|
|
300
306
|
function isSessionScopedParentMessage(value) {
|
|
301
307
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -316,6 +322,7 @@ var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
|
316
322
|
var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
|
|
317
323
|
var speakerGateBySessionId = /* @__PURE__ */ new Map();
|
|
318
324
|
var pendingSpeakerGateAcks = /* @__PURE__ */ new Map();
|
|
325
|
+
var pendingSpeakerGateStateBySessionId = /* @__PURE__ */ new Map();
|
|
319
326
|
var pendingSpeakerResets = /* @__PURE__ */ new Map();
|
|
320
327
|
var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
321
328
|
var speakControlAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
@@ -603,6 +610,41 @@ function handleResetSpeakerEnrollmentResult(message) {
|
|
|
603
610
|
pendingSpeakerResets.delete(message.requestId);
|
|
604
611
|
pending.resolve(message.ok ? { ok: true } : { ok: false, reason: message.reason });
|
|
605
612
|
}
|
|
613
|
+
function applySpeakerGateState(prev, message) {
|
|
614
|
+
return {
|
|
615
|
+
available: true,
|
|
616
|
+
mode: message.mode,
|
|
617
|
+
bargeIn: message.bargeIn ?? prev.bargeIn
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
function handleSpeakerGateState(message) {
|
|
621
|
+
if (endedSessionIds.has(message.sessionId))
|
|
622
|
+
return;
|
|
623
|
+
const prev = speakerGateBySessionId.get(message.sessionId);
|
|
624
|
+
if (prev) {
|
|
625
|
+
if (prev.available) {
|
|
626
|
+
speakerGateBySessionId.set(message.sessionId, applySpeakerGateState(prev, message));
|
|
627
|
+
}
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
pendingSpeakerGateStateBySessionId.set(message.sessionId, message);
|
|
631
|
+
}
|
|
632
|
+
function clearPendingSpeakerRequestsForSession(sessionId, reason) {
|
|
633
|
+
for (const [requestId, pending] of pendingSpeakerGateAcks) {
|
|
634
|
+
if (pending.sessionId !== sessionId)
|
|
635
|
+
continue;
|
|
636
|
+
clearTimeout(pending.timer);
|
|
637
|
+
pendingSpeakerGateAcks.delete(requestId);
|
|
638
|
+
pending.resolve({ ok: false, reason });
|
|
639
|
+
}
|
|
640
|
+
for (const [requestId, pending] of pendingSpeakerResets) {
|
|
641
|
+
if (pending.sessionId !== sessionId)
|
|
642
|
+
continue;
|
|
643
|
+
clearTimeout(pending.timer);
|
|
644
|
+
pendingSpeakerResets.delete(requestId);
|
|
645
|
+
pending.resolve({ ok: false, reason });
|
|
646
|
+
}
|
|
647
|
+
}
|
|
606
648
|
function handleVoiceReplayLastResult(message) {
|
|
607
649
|
const pending = pendingVoiceReplays.get(message.requestId);
|
|
608
650
|
if (!pending)
|
|
@@ -829,7 +871,12 @@ async function handleParentMessage(message, handlers) {
|
|
|
829
871
|
speakControlAvailableBySessionId.set(message.sessionId, message.speakControlAvailable ?? false);
|
|
830
872
|
chatReplyRecordAvailableBySessionId.set(message.sessionId, message.chatReplyRecordAvailable ?? false);
|
|
831
873
|
sessionTimeLimitAvailableBySessionId.set(message.sessionId, message.sessionTimeLimitAvailable ?? false);
|
|
832
|
-
|
|
874
|
+
{
|
|
875
|
+
const initial = message.speakerGate?.available === true ? message.speakerGate : { available: false };
|
|
876
|
+
const early = pendingSpeakerGateStateBySessionId.get(message.sessionId);
|
|
877
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
878
|
+
speakerGateBySessionId.set(message.sessionId, early && initial.available ? applySpeakerGateState(initial, early) : initial);
|
|
879
|
+
}
|
|
833
880
|
if (message.voiceLanguageSwitch) {
|
|
834
881
|
voiceLanguageSwitchSettingsBySessionId.set(message.sessionId, message.voiceLanguageSwitch);
|
|
835
882
|
} else {
|
|
@@ -956,6 +1003,8 @@ async function handleParentMessage(message, handlers) {
|
|
|
956
1003
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
957
1004
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
958
1005
|
speakerGateBySessionId.delete(message.sessionId);
|
|
1006
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
1007
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
959
1008
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
960
1009
|
lastVoiceLanguageBySessionId.delete(message.sessionId);
|
|
961
1010
|
ttsPoseAvailableBySessionId.delete(message.sessionId);
|
|
@@ -1049,6 +1098,10 @@ function defineAgent(handlers) {
|
|
|
1049
1098
|
handleResetSpeakerEnrollmentResult(message);
|
|
1050
1099
|
return;
|
|
1051
1100
|
}
|
|
1101
|
+
if (isSpeakerGateStateMessage(message)) {
|
|
1102
|
+
handleSpeakerGateState(message);
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1052
1105
|
if (isWebhookMessage(message)) {
|
|
1053
1106
|
void agentStartReady.then(() => handleWebhookMessage(message, handlers));
|
|
1054
1107
|
return;
|
|
@@ -1057,6 +1110,8 @@ function defineAgent(handlers) {
|
|
|
1057
1110
|
return;
|
|
1058
1111
|
if (message.type === "session_end") {
|
|
1059
1112
|
endedSessionIds.add(message.sessionId);
|
|
1113
|
+
pendingSpeakerGateStateBySessionId.delete(message.sessionId);
|
|
1114
|
+
clearPendingSpeakerRequestsForSession(message.sessionId, "session_ended");
|
|
1060
1115
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
1061
1116
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
1062
1117
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
@@ -1246,6 +1301,8 @@ function buildIdleEnv(sessionId) {
|
|
|
1246
1301
|
...process.env.IDLE_TIMEOUT_SEC ? { IDLE_TIMEOUT_SEC: process.env.IDLE_TIMEOUT_SEC } : {}
|
|
1247
1302
|
};
|
|
1248
1303
|
}
|
|
1304
|
+
var SPEAKER_GATE_MODES = ["disabled", "auto", "manual"];
|
|
1305
|
+
var SPEAKER_GATE_BARGE_IN = ["caller_only", "anyone"];
|
|
1249
1306
|
function sendToClient(sessionId, payload) {
|
|
1250
1307
|
sendParentMessage({ type: "send_to_client", sessionId, payload });
|
|
1251
1308
|
}
|
|
@@ -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,
|
|
@@ -15,7 +15,6 @@ import {
|
|
|
15
15
|
setBargeIn,
|
|
16
16
|
speak,
|
|
17
17
|
type SpeakHandle,
|
|
18
|
-
type SpeakResultStatus,
|
|
19
18
|
} from "@voicethere/agent";
|
|
20
19
|
import {
|
|
21
20
|
type AgentContent,
|
|
@@ -488,22 +487,6 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
|
|
|
488
487
|
return h;
|
|
489
488
|
}
|
|
490
489
|
|
|
491
|
-
function greetingDoneStatus(
|
|
492
|
-
status: SpeakResultStatus,
|
|
493
|
-
): "completed" | "interrupted" | "cancelled" | "failed" {
|
|
494
|
-
switch (status) {
|
|
495
|
-
case "played":
|
|
496
|
-
case "unsupported":
|
|
497
|
-
return "completed";
|
|
498
|
-
case "interrupted":
|
|
499
|
-
return "interrupted";
|
|
500
|
-
case "cancelled":
|
|
501
|
-
return "cancelled";
|
|
502
|
-
case "failed":
|
|
503
|
-
return "failed";
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
490
|
// ---- fillers -----------------------------------------------------------
|
|
508
491
|
|
|
509
492
|
function clearFillerTimer(t: TurnState, kind?: FillerKind): void {
|
|
@@ -1270,7 +1253,11 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
|
|
|
1270
1253
|
turnId: t.turnId,
|
|
1271
1254
|
text,
|
|
1272
1255
|
});
|
|
1273
|
-
sendToClient(s.sessionId, {
|
|
1256
|
+
sendToClient(s.sessionId, {
|
|
1257
|
+
type: "chat_reply",
|
|
1258
|
+
text,
|
|
1259
|
+
turnId: t.turnId,
|
|
1260
|
+
});
|
|
1274
1261
|
if (!speakChat && text.trim() !== "")
|
|
1275
1262
|
recordReply(s.sessionId, text, { turnId: t.turnId });
|
|
1276
1263
|
}
|
|
@@ -1516,30 +1503,21 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
|
|
|
1516
1503
|
{ turnId },
|
|
1517
1504
|
);
|
|
1518
1505
|
sendSpokenDelta(s.sessionId, turnId, greeting.text);
|
|
1519
|
-
|
|
1506
|
+
// Like every spoken turn, the done goes out when the text is complete,
|
|
1507
|
+
// before the audio. Interruption arrives as barge_in/agent_interrupted.
|
|
1508
|
+
sendToClient(s.sessionId, {
|
|
1509
|
+
type: "assistant_done",
|
|
1510
|
+
turnId,
|
|
1511
|
+
text: greeting.text,
|
|
1512
|
+
spoken: true,
|
|
1513
|
+
status: "completed",
|
|
1514
|
+
});
|
|
1515
|
+
speakAnnouncement(
|
|
1520
1516
|
s,
|
|
1521
1517
|
turnId,
|
|
1522
1518
|
greeting.text,
|
|
1523
1519
|
greeting.interruptible ?? D.greetingInterruptible,
|
|
1524
1520
|
);
|
|
1525
|
-
void handle.done.then((result) => {
|
|
1526
|
-
if (s.ended) return;
|
|
1527
|
-
// The runtime cancels pending speaks when the session ends or is
|
|
1528
|
-
// reset; that is teardown, not a greeting outcome.
|
|
1529
|
-
if (
|
|
1530
|
-
result.errorCode === "session_ended" ||
|
|
1531
|
-
result.errorCode === "reset"
|
|
1532
|
-
) {
|
|
1533
|
-
return;
|
|
1534
|
-
}
|
|
1535
|
-
sendToClient(s.sessionId, {
|
|
1536
|
-
type: "assistant_done",
|
|
1537
|
-
turnId,
|
|
1538
|
-
text: greeting.text,
|
|
1539
|
-
spoken: true,
|
|
1540
|
-
status: greetingDoneStatus(result.status),
|
|
1541
|
-
});
|
|
1542
|
-
});
|
|
1543
1521
|
}
|
|
1544
1522
|
},
|
|
1545
1523
|
|
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
|
| ----------------- | ----------------------------------------- | ------------------------------------------------------ |
|
|
@@ -16,6 +16,10 @@ A voice and chat agent powered by an LLM, with custom tools and MCP servers. Sou
|
|
|
16
16
|
|
|
17
17
|
The template starts on OpenRouter with the model `anthropic/claude-haiku-5.5`. Create a key at openrouter.ai, add it as a project secret named `AGENT_OPENROUTER_API_KEY`, then deploy. For production, pick the model from OpenRouter's list yourself, checking cost, latency and tool support. The key is read by name from `apiKeySecret` in `voicethere.llm.json`; it is never stored in the file. Only project secrets whose names start with `AGENT_` reach the agent.
|
|
18
18
|
|
|
19
|
+
## Greeting
|
|
20
|
+
|
|
21
|
+
The greeting is sent like every spoken turn: `assistant_delta` and `assistant_done` (`status: "completed"`) go out as soon as its text is complete, before the audio plays. `assistant_done` does not wait for playback. If the caller cuts the greeting off, that arrives as `barge_in` / `agent_interrupted`, the same as for a reply.
|
|
22
|
+
|
|
19
23
|
## Filler phrases
|
|
20
24
|
|
|
21
25
|
The `fillers` block in `voicethere.llm.json` lists short sentences the agent speaks while the caller waits. Each situation has its own phrases; leave a situation out, or give it an empty list, to turn it off. The whole block is off when absent.
|
|
@@ -45,7 +49,7 @@ The `fillers` block in `voicethere.llm.json` lists short sentences the agent spe
|
|
|
45
49
|
|
|
46
50
|
## Client messages for voice replies
|
|
47
51
|
|
|
48
|
-
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.
|
|
49
53
|
|
|
50
54
|
## Always search first
|
|
51
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.
|