@voicethere/agent 0.10.1 → 0.11.0

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.
Files changed (39) hide show
  1. package/README.md +88 -0
  2. package/dist/agent.js +175 -5
  3. package/dist/host/index.d.ts +4 -0
  4. package/dist/host/index.d.ts.map +1 -0
  5. package/dist/host/index.js +3 -0
  6. package/dist/host/index.js.map +1 -0
  7. package/dist/host/session-speak-controller.d.ts +70 -0
  8. package/dist/host/session-speak-controller.d.ts.map +1 -0
  9. package/dist/host/session-speak-controller.js +296 -0
  10. package/dist/host/session-speak-controller.js.map +1 -0
  11. package/dist/host/speak-text.d.ts +11 -0
  12. package/dist/host/speak-text.d.ts.map +1 -0
  13. package/dist/host/speak-text.js +21 -0
  14. package/dist/host/speak-text.js.map +1 -0
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/protocol.d.ts +95 -2
  20. package/dist/protocol.d.ts.map +1 -1
  21. package/dist/protocol.js.map +1 -1
  22. package/dist/runtime.d.ts +69 -6
  23. package/dist/runtime.d.ts.map +1 -1
  24. package/dist/runtime.js +274 -7
  25. package/dist/runtime.js.map +1 -1
  26. package/dist/templates/echo/agent.js +178 -7
  27. package/dist/templates/echo-dc/agent.js +85 -2
  28. package/dist/templates/game-sync/agent.js +85 -2
  29. package/dist/templates/language-switch/agent.js +173 -5
  30. package/dist/templates/positional-tts/agent.js +173 -5
  31. package/dist/templates/recording-consent/agent.js +173 -5
  32. package/dist/templates/spatial-showcase/agent.js +173 -5
  33. package/dist/templates/voice-showcase/agent.js +178 -7
  34. package/dist/templates/voice-starter/agent.js +176 -5
  35. package/dist/templates/webhooks/agent.js +176 -5
  36. package/dist/templates/webhooks-redis/agent.js +85 -2
  37. package/dist/templates/world-sync/agent.js +85 -2
  38. package/dist/templates/world-sync-binary/agent.js +85 -2
  39. package/package.json +7 -1
@@ -151,6 +151,18 @@ var SessionSerialQueue = class {
151
151
  var SESSION_START_INIT_DELAY_ENABLED_ENV = "AGENT_SESSION_START_INIT_DELAY_ENABLED";
152
152
  var SESSION_START_INIT_DELAY_MS_ENV = "AGENT_SESSION_START_INIT_DELAY_MS";
153
153
  var DEFAULT_SESSION_START_INIT_DELAY_MS = 500;
154
+ function isSpeakResultMessage(value) {
155
+ if (!value || typeof value !== "object")
156
+ return false;
157
+ const msg = value;
158
+ return msg.type === "speak_result" && typeof msg.requestId === "string";
159
+ }
160
+ function isBargeInControlAckMessage(value) {
161
+ if (!value || typeof value !== "object")
162
+ return false;
163
+ const msg = value;
164
+ return msg.type === "barge_in_control_ack" && typeof msg.requestId === "string";
165
+ }
154
166
  function isPlayAckMessage(value) {
155
167
  if (!value || typeof value !== "object")
156
168
  return false;
@@ -259,7 +271,7 @@ function isParentMessage(value) {
259
271
  if (!value || typeof value !== "object")
260
272
  return false;
261
273
  const msg = value;
262
- 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 === "recording_control_ack" || msg.type === "conversation_history_control_ack" || 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 === "webhook";
274
+ 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 === "recording_control_ack" || msg.type === "conversation_history_control_ack" || 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 === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
263
275
  }
264
276
  function isSessionScopedParentMessage(value) {
265
277
  return isParentMessage(value) && !isWebhookMessage(value);
@@ -278,7 +290,60 @@ var mixAvailableBySessionId = /* @__PURE__ */ new Map();
278
290
  var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
279
291
  var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
280
292
  var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
293
+ var speakControlAvailableBySessionId = /* @__PURE__ */ new Map();
294
+ var speakControlWarnedSessionIds = /* @__PURE__ */ new Set();
281
295
  var endedSessionIds = /* @__PURE__ */ new Set();
296
+ var pendingSpeakResults = /* @__PURE__ */ new Map();
297
+ var pendingBargeInAcks = /* @__PURE__ */ new Map();
298
+ function handleSpeakResult(message) {
299
+ const pending = pendingSpeakResults.get(message.requestId);
300
+ if (!pending)
301
+ return;
302
+ clearTimeout(pending.timer);
303
+ pendingSpeakResults.delete(message.requestId);
304
+ pending.resolve({
305
+ requestId: message.requestId,
306
+ ...message.turnId !== void 0 ? { turnId: message.turnId } : {},
307
+ status: message.status,
308
+ playedMs: message.playedMs,
309
+ ...message.synthesizedMs !== void 0 ? { synthesizedMs: message.synthesizedMs } : {},
310
+ ...message.errorCode !== void 0 ? { errorCode: message.errorCode } : {}
311
+ });
312
+ }
313
+ function handleBargeInControlAck(message) {
314
+ const pending = pendingBargeInAcks.get(message.requestId);
315
+ if (!pending)
316
+ return;
317
+ clearTimeout(pending.timer);
318
+ pendingBargeInAcks.delete(message.requestId);
319
+ pending.resolve({
320
+ ok: message.ok,
321
+ ...message.reason ? { reason: message.reason } : {}
322
+ });
323
+ }
324
+ function clearPendingSpeakForSession(sessionId, errorCode) {
325
+ for (const [requestId, pending] of pendingSpeakResults) {
326
+ if (pending.sessionId !== sessionId)
327
+ continue;
328
+ clearTimeout(pending.timer);
329
+ pendingSpeakResults.delete(requestId);
330
+ pending.resolve({
331
+ requestId,
332
+ ...pending.turnId !== void 0 ? { turnId: pending.turnId } : {},
333
+ status: "cancelled",
334
+ playedMs: 0,
335
+ errorCode
336
+ });
337
+ }
338
+ for (const [requestId, pending] of pendingBargeInAcks) {
339
+ if (pending.sessionId !== sessionId)
340
+ continue;
341
+ clearTimeout(pending.timer);
342
+ pendingBargeInAcks.delete(requestId);
343
+ pending.resolve({ ok: false, reason: "session_ended" });
344
+ }
345
+ speakControlWarnedSessionIds.delete(sessionId);
346
+ }
282
347
  var PLAY_BYTES_MAX_DECODED_LENGTH = 64 * 1024;
283
348
  var pendingRecordingAcks = /* @__PURE__ */ new Map();
284
349
  var pendingConversationHistoryAcks = /* @__PURE__ */ new Map();
@@ -608,6 +673,7 @@ async function handleParentMessage(message, handlers) {
608
673
  mixAvailableBySessionId.set(message.sessionId, message.mixAvailable ?? false);
609
674
  voiceLanguageSwitchAvailableBySessionId.set(message.sessionId, message.voiceLanguageSwitchAvailable ?? false);
610
675
  ttsPoseAvailableBySessionId.set(message.sessionId, message.ttsPoseAvailable ?? false);
676
+ speakControlAvailableBySessionId.set(message.sessionId, message.speakControlAvailable ?? false);
611
677
  if (message.voiceLanguageSwitch) {
612
678
  voiceLanguageSwitchSettingsBySessionId.set(message.sessionId, message.voiceLanguageSwitch);
613
679
  } else {
@@ -624,7 +690,8 @@ async function handleParentMessage(message, handlers) {
624
690
  conversationHistoryAvailable: message.conversationHistoryAvailable ?? false,
625
691
  mixAvailable: message.mixAvailable ?? false,
626
692
  voiceLanguageSwitchAvailable: message.voiceLanguageSwitchAvailable ?? false,
627
- ttsPoseAvailable: message.ttsPoseAvailable ?? false
693
+ ttsPoseAvailable: message.ttsPoseAvailable ?? false,
694
+ speakControlAvailable: message.speakControlAvailable ?? false
628
695
  });
629
696
  sendParentMessage({
630
697
  type: "session_start_ack",
@@ -661,6 +728,11 @@ async function handleParentMessage(message, handlers) {
661
728
  }
662
729
  }
663
730
  break;
731
+ case "agent_interrupted": {
732
+ const { type: _type, ...interrupted } = message;
733
+ await handlers.onAgentInterrupted?.(interrupted);
734
+ break;
735
+ }
664
736
  case "data_channel_message":
665
737
  await handlers.onDataChannelMessage?.({
666
738
  sessionId: message.sessionId,
@@ -690,6 +762,8 @@ async function handleParentMessage(message, handlers) {
690
762
  voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
691
763
  lastVoiceLanguageBySessionId.delete(message.sessionId);
692
764
  ttsPoseAvailableBySessionId.delete(message.sessionId);
765
+ speakControlAvailableBySessionId.delete(message.sessionId);
766
+ clearPendingSpeakForSession(message.sessionId, "session_ended");
693
767
  await (handlers.onClientLeave ?? handlers.onSessionEnd)?.({
694
768
  sessionId: message.sessionId
695
769
  });
@@ -713,6 +787,14 @@ function defineAgent(handlers) {
713
787
  handleConversationHistoryControlAck(message);
714
788
  return;
715
789
  }
790
+ if (isSpeakResultMessage(message)) {
791
+ handleSpeakResult(message);
792
+ return;
793
+ }
794
+ if (isBargeInControlAckMessage(message)) {
795
+ handleBargeInControlAck(message);
796
+ return;
797
+ }
716
798
  if (isPlayAckMessage(message)) {
717
799
  handlePlayAck(message);
718
800
  return;
@@ -757,6 +839,7 @@ function defineAgent(handlers) {
757
839
  return;
758
840
  if (message.type === "session_end") {
759
841
  endedSessionIds.add(message.sessionId);
842
+ clearPendingSpeakForSession(message.sessionId, "session_ended");
760
843
  clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
761
844
  clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
762
845
  inboundBySession.clear(message.sessionId);
@@ -151,6 +151,18 @@ var SessionSerialQueue = class {
151
151
  var SESSION_START_INIT_DELAY_ENABLED_ENV = "AGENT_SESSION_START_INIT_DELAY_ENABLED";
152
152
  var SESSION_START_INIT_DELAY_MS_ENV = "AGENT_SESSION_START_INIT_DELAY_MS";
153
153
  var DEFAULT_SESSION_START_INIT_DELAY_MS = 500;
154
+ function isSpeakResultMessage(value) {
155
+ if (!value || typeof value !== "object")
156
+ return false;
157
+ const msg = value;
158
+ return msg.type === "speak_result" && typeof msg.requestId === "string";
159
+ }
160
+ function isBargeInControlAckMessage(value) {
161
+ if (!value || typeof value !== "object")
162
+ return false;
163
+ const msg = value;
164
+ return msg.type === "barge_in_control_ack" && typeof msg.requestId === "string";
165
+ }
154
166
  function isPlayAckMessage(value) {
155
167
  if (!value || typeof value !== "object")
156
168
  return false;
@@ -259,7 +271,7 @@ function isParentMessage(value) {
259
271
  if (!value || typeof value !== "object")
260
272
  return false;
261
273
  const msg = value;
262
- 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 === "recording_control_ack" || msg.type === "conversation_history_control_ack" || 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 === "webhook";
274
+ 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 === "recording_control_ack" || msg.type === "conversation_history_control_ack" || 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 === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
263
275
  }
264
276
  function isSessionScopedParentMessage(value) {
265
277
  return isParentMessage(value) && !isWebhookMessage(value);
@@ -278,7 +290,60 @@ var mixAvailableBySessionId = /* @__PURE__ */ new Map();
278
290
  var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
279
291
  var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
280
292
  var ttsPoseAvailableBySessionId = /* @__PURE__ */ new Map();
293
+ var speakControlAvailableBySessionId = /* @__PURE__ */ new Map();
294
+ var speakControlWarnedSessionIds = /* @__PURE__ */ new Set();
281
295
  var endedSessionIds = /* @__PURE__ */ new Set();
296
+ var pendingSpeakResults = /* @__PURE__ */ new Map();
297
+ var pendingBargeInAcks = /* @__PURE__ */ new Map();
298
+ function handleSpeakResult(message) {
299
+ const pending = pendingSpeakResults.get(message.requestId);
300
+ if (!pending)
301
+ return;
302
+ clearTimeout(pending.timer);
303
+ pendingSpeakResults.delete(message.requestId);
304
+ pending.resolve({
305
+ requestId: message.requestId,
306
+ ...message.turnId !== void 0 ? { turnId: message.turnId } : {},
307
+ status: message.status,
308
+ playedMs: message.playedMs,
309
+ ...message.synthesizedMs !== void 0 ? { synthesizedMs: message.synthesizedMs } : {},
310
+ ...message.errorCode !== void 0 ? { errorCode: message.errorCode } : {}
311
+ });
312
+ }
313
+ function handleBargeInControlAck(message) {
314
+ const pending = pendingBargeInAcks.get(message.requestId);
315
+ if (!pending)
316
+ return;
317
+ clearTimeout(pending.timer);
318
+ pendingBargeInAcks.delete(message.requestId);
319
+ pending.resolve({
320
+ ok: message.ok,
321
+ ...message.reason ? { reason: message.reason } : {}
322
+ });
323
+ }
324
+ function clearPendingSpeakForSession(sessionId, errorCode) {
325
+ for (const [requestId, pending] of pendingSpeakResults) {
326
+ if (pending.sessionId !== sessionId)
327
+ continue;
328
+ clearTimeout(pending.timer);
329
+ pendingSpeakResults.delete(requestId);
330
+ pending.resolve({
331
+ requestId,
332
+ ...pending.turnId !== void 0 ? { turnId: pending.turnId } : {},
333
+ status: "cancelled",
334
+ playedMs: 0,
335
+ errorCode
336
+ });
337
+ }
338
+ for (const [requestId, pending] of pendingBargeInAcks) {
339
+ if (pending.sessionId !== sessionId)
340
+ continue;
341
+ clearTimeout(pending.timer);
342
+ pendingBargeInAcks.delete(requestId);
343
+ pending.resolve({ ok: false, reason: "session_ended" });
344
+ }
345
+ speakControlWarnedSessionIds.delete(sessionId);
346
+ }
282
347
  var PLAY_BYTES_MAX_DECODED_LENGTH = 64 * 1024;
283
348
  var pendingRecordingAcks = /* @__PURE__ */ new Map();
284
349
  var pendingConversationHistoryAcks = /* @__PURE__ */ new Map();
@@ -608,6 +673,7 @@ async function handleParentMessage(message, handlers) {
608
673
  mixAvailableBySessionId.set(message.sessionId, message.mixAvailable ?? false);
609
674
  voiceLanguageSwitchAvailableBySessionId.set(message.sessionId, message.voiceLanguageSwitchAvailable ?? false);
610
675
  ttsPoseAvailableBySessionId.set(message.sessionId, message.ttsPoseAvailable ?? false);
676
+ speakControlAvailableBySessionId.set(message.sessionId, message.speakControlAvailable ?? false);
611
677
  if (message.voiceLanguageSwitch) {
612
678
  voiceLanguageSwitchSettingsBySessionId.set(message.sessionId, message.voiceLanguageSwitch);
613
679
  } else {
@@ -624,7 +690,8 @@ async function handleParentMessage(message, handlers) {
624
690
  conversationHistoryAvailable: message.conversationHistoryAvailable ?? false,
625
691
  mixAvailable: message.mixAvailable ?? false,
626
692
  voiceLanguageSwitchAvailable: message.voiceLanguageSwitchAvailable ?? false,
627
- ttsPoseAvailable: message.ttsPoseAvailable ?? false
693
+ ttsPoseAvailable: message.ttsPoseAvailable ?? false,
694
+ speakControlAvailable: message.speakControlAvailable ?? false
628
695
  });
629
696
  sendParentMessage({
630
697
  type: "session_start_ack",
@@ -661,6 +728,11 @@ async function handleParentMessage(message, handlers) {
661
728
  }
662
729
  }
663
730
  break;
731
+ case "agent_interrupted": {
732
+ const { type: _type, ...interrupted } = message;
733
+ await handlers.onAgentInterrupted?.(interrupted);
734
+ break;
735
+ }
664
736
  case "data_channel_message":
665
737
  await handlers.onDataChannelMessage?.({
666
738
  sessionId: message.sessionId,
@@ -690,6 +762,8 @@ async function handleParentMessage(message, handlers) {
690
762
  voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
691
763
  lastVoiceLanguageBySessionId.delete(message.sessionId);
692
764
  ttsPoseAvailableBySessionId.delete(message.sessionId);
765
+ speakControlAvailableBySessionId.delete(message.sessionId);
766
+ clearPendingSpeakForSession(message.sessionId, "session_ended");
693
767
  await (handlers.onClientLeave ?? handlers.onSessionEnd)?.({
694
768
  sessionId: message.sessionId
695
769
  });
@@ -713,6 +787,14 @@ function defineAgent(handlers) {
713
787
  handleConversationHistoryControlAck(message);
714
788
  return;
715
789
  }
790
+ if (isSpeakResultMessage(message)) {
791
+ handleSpeakResult(message);
792
+ return;
793
+ }
794
+ if (isBargeInControlAckMessage(message)) {
795
+ handleBargeInControlAck(message);
796
+ return;
797
+ }
716
798
  if (isPlayAckMessage(message)) {
717
799
  handlePlayAck(message);
718
800
  return;
@@ -757,6 +839,7 @@ function defineAgent(handlers) {
757
839
  return;
758
840
  if (message.type === "session_end") {
759
841
  endedSessionIds.add(message.sessionId);
842
+ clearPendingSpeakForSession(message.sessionId, "session_ended");
760
843
  clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
761
844
  clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
762
845
  inboundBySession.clear(message.sessionId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voicethere/agent",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "VoiceThere customer agent SDK — IPC types and runtime helpers for sandboxed child bundles",
5
5
  "type": "module",
6
6
  "exports": {
@@ -16,6 +16,12 @@
16
16
  "require": "./dist/runner.js",
17
17
  "default": "./dist/runner.js"
18
18
  },
19
+ "./host": {
20
+ "types": "./dist/host/index.d.ts",
21
+ "import": "./dist/host/index.js",
22
+ "require": "./dist/host/index.js",
23
+ "default": "./dist/host/index.js"
24
+ },
19
25
  "./verify": {
20
26
  "types": "./dist/verify/run-verify.d.ts",
21
27
  "import": "./dist/verify/run-verify.js",