@voicethere/agent 0.26.0 → 0.27.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 (69) hide show
  1. package/README.md +23 -0
  2. package/dist/agent.js +78 -1
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/llm/agent/create-llm-agent.d.ts +5 -0
  8. package/dist/llm/agent/create-llm-agent.d.ts.map +1 -1
  9. package/dist/llm/agent/create-llm-agent.js +11 -2
  10. package/dist/llm/agent/create-llm-agent.js.map +1 -1
  11. package/dist/llm/agent/define-tool.d.ts +2 -0
  12. package/dist/llm/agent/define-tool.d.ts.map +1 -1
  13. package/dist/llm/agent/define-tool.js +1 -0
  14. package/dist/llm/agent/define-tool.js.map +1 -1
  15. package/dist/llm/agent/redact.d.ts.map +1 -1
  16. package/dist/llm/agent/redact.js +1 -0
  17. package/dist/llm/agent/redact.js.map +1 -1
  18. package/dist/llm/end-user/end-user-tools.d.ts +10 -0
  19. package/dist/llm/end-user/end-user-tools.d.ts.map +1 -0
  20. package/dist/llm/end-user/end-user-tools.js +50 -0
  21. package/dist/llm/end-user/end-user-tools.js.map +1 -0
  22. package/dist/llm/index.d.ts +1 -0
  23. package/dist/llm/index.d.ts.map +1 -1
  24. package/dist/llm/index.js +1 -0
  25. package/dist/llm/index.js.map +1 -1
  26. package/dist/llm/mcp/tool-registry.d.ts +10 -1
  27. package/dist/llm/mcp/tool-registry.d.ts.map +1 -1
  28. package/dist/llm/mcp/tool-registry.js +10 -3
  29. package/dist/llm/mcp/tool-registry.js.map +1 -1
  30. package/dist/protocol.d.ts +53 -3
  31. package/dist/protocol.d.ts.map +1 -1
  32. package/dist/protocol.js +2 -0
  33. package/dist/protocol.js.map +1 -1
  34. package/dist/runtime.d.ts +34 -1
  35. package/dist/runtime.d.ts.map +1 -1
  36. package/dist/runtime.js +133 -0
  37. package/dist/runtime.js.map +1 -1
  38. package/dist/templates/echo/agent.js +87 -1
  39. package/dist/templates/echo-dc/agent.js +87 -1
  40. package/dist/templates/flow-agent/agent.js +95 -4
  41. package/dist/templates/game-sync/agent.js +87 -1
  42. package/dist/templates/language-switch/agent.js +87 -1
  43. package/dist/templates/llm-agent/agent.js +166 -6
  44. package/dist/templates/llm-docs-rag/agent.js +166 -6
  45. package/dist/templates/llm-mcp-service/agent.js +166 -6
  46. package/dist/templates/llm-support-sticky-user/agent.js +60690 -0
  47. package/dist/templates/positional-tts/agent.js +87 -1
  48. package/dist/templates/recording-consent/agent.js +87 -1
  49. package/dist/templates/registry.d.ts.map +1 -1
  50. package/dist/templates/registry.js +26 -0
  51. package/dist/templates/registry.js.map +1 -1
  52. package/dist/templates/spatial-showcase/agent.js +87 -1
  53. package/dist/templates/voice-showcase/agent.js +87 -1
  54. package/dist/templates/voice-starter/agent.js +87 -1
  55. package/dist/templates/webhooks/agent.js +87 -1
  56. package/dist/templates/webhooks-redis/agent.js +87 -1
  57. package/dist/templates/world-sync/agent.js +87 -1
  58. package/dist/templates/world-sync-binary/agent.js +87 -1
  59. package/eject/llm/loop.ts +17 -2
  60. package/package.json +1 -1
  61. package/templates/README.md +1 -0
  62. package/templates/llm-support-sticky-user/README.md +68 -0
  63. package/templates/llm-support-sticky-user/agent.ts +29 -0
  64. package/templates/llm-support-sticky-user/hooks.ts +188 -0
  65. package/templates/llm-support-sticky-user/md.d.ts +4 -0
  66. package/templates/llm-support-sticky-user/mock-crm.ts +75 -0
  67. package/templates/llm-support-sticky-user/prompt.md +21 -0
  68. package/templates/llm-support-sticky-user/tools.ts +244 -0
  69. package/templates/llm-support-sticky-user/voicethere.llm.json +52 -0
@@ -205,6 +205,12 @@ function isConversationHistoryControlAckMessage(value) {
205
205
  const msg = value;
206
206
  return msg.type === "conversation_history_control_ack" && typeof msg.requestId === "string";
207
207
  }
208
+ function isUserHistoryResponseMessage(value) {
209
+ if (!value || typeof value !== "object")
210
+ return false;
211
+ const msg = value;
212
+ return msg.type === "user_history_response" && typeof msg.requestId === "string";
213
+ }
208
214
  function isMixControlAckMessage(value) {
209
215
  if (!value || typeof value !== "object")
210
216
  return false;
@@ -277,7 +283,7 @@ function isParentMessage(value) {
277
283
  if (!value || typeof value !== "object")
278
284
  return false;
279
285
  const msg = value;
280
- 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 === "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";
286
+ 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 === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
281
287
  }
282
288
  function isSessionScopedParentMessage(value) {
283
289
  return isParentMessage(value) && !isWebhookMessage(value);
@@ -292,6 +298,7 @@ function parseDataChannelPayload(raw) {
292
298
  var peerEnvBySessionId = /* @__PURE__ */ new Map();
293
299
  var recordingAvailableBySessionId = /* @__PURE__ */ new Map();
294
300
  var conversationHistoryAvailableBySessionId = /* @__PURE__ */ new Map();
301
+ var endUserBySessionId = /* @__PURE__ */ new Map();
295
302
  var mixAvailableBySessionId = /* @__PURE__ */ new Map();
296
303
  var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
297
304
  var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
@@ -380,6 +387,7 @@ function clearPendingSpeakForSession(sessionId, errorCode) {
380
387
  var PLAY_BYTES_MAX_DECODED_LENGTH = 64 * 1024;
381
388
  var pendingRecordingAcks = /* @__PURE__ */ new Map();
382
389
  var pendingConversationHistoryAcks = /* @__PURE__ */ new Map();
390
+ var pendingUserHistory = /* @__PURE__ */ new Map();
383
391
  var pendingPlayAcks = /* @__PURE__ */ new Map();
384
392
  var pendingPlayStatusAcks = /* @__PURE__ */ new Map();
385
393
  var pendingPlayStopAcks = /* @__PURE__ */ new Map();
@@ -414,6 +422,27 @@ function handleConversationHistoryControlAck(message) {
414
422
  requestId: message.requestId
415
423
  });
416
424
  }
425
+ function handleUserHistoryResponse(message) {
426
+ const pending = pendingUserHistory.get(message.requestId);
427
+ if (!pending)
428
+ return;
429
+ clearTimeout(pending.timer);
430
+ pendingUserHistory.delete(message.requestId);
431
+ pending.resolve({
432
+ ok: message.ok,
433
+ ...message.reason ? { reason: message.reason } : {},
434
+ conversations: Array.isArray(message.conversations) ? message.conversations : []
435
+ });
436
+ }
437
+ function clearPendingUserHistoryForSession(sessionId, reason) {
438
+ for (const [requestId, pending] of pendingUserHistory) {
439
+ if (pending.sessionId !== sessionId)
440
+ continue;
441
+ clearTimeout(pending.timer);
442
+ pendingUserHistory.delete(requestId);
443
+ pending.resolve({ ok: false, reason, conversations: [] });
444
+ }
445
+ }
417
446
  function handlePlayAck(message) {
418
447
  const pending = pendingPlayAcks.get(message.requestId);
419
448
  if (!pending)
@@ -734,6 +763,11 @@ async function handleParentMessage(message, handlers) {
734
763
  peerEnvBySessionId.set(message.sessionId, message.env);
735
764
  recordingAvailableBySessionId.set(message.sessionId, message.recordingAvailable ?? false);
736
765
  conversationHistoryAvailableBySessionId.set(message.sessionId, message.conversationHistoryAvailable ?? false);
766
+ const startUser = parseEndUserInfo(message.endUser) ?? parseEndUserEnv(message.env?.AGENT_END_USER);
767
+ if (startUser)
768
+ endUserBySessionId.set(message.sessionId, startUser);
769
+ else
770
+ endUserBySessionId.delete(message.sessionId);
737
771
  mixAvailableBySessionId.set(message.sessionId, message.mixAvailable ?? false);
738
772
  voiceLanguageSwitchAvailableBySessionId.set(message.sessionId, message.voiceLanguageSwitchAvailable ?? false);
739
773
  ttsPoseAvailableBySessionId.set(message.sessionId, message.ttsPoseAvailable ?? false);
@@ -751,6 +785,7 @@ async function handleParentMessage(message, handlers) {
751
785
  await (handlers.onClientJoin ?? handlers.onSessionStart)?.({
752
786
  sessionId: message.sessionId,
753
787
  env: message.env,
788
+ ...startUser ? { user: startUser } : {},
754
789
  recordingAvailable: message.recordingAvailable ?? false,
755
790
  conversationHistoryAvailable: message.conversationHistoryAvailable ?? false,
756
791
  mixAvailable: message.mixAvailable ?? false,
@@ -764,6 +799,27 @@ async function handleParentMessage(message, handlers) {
764
799
  sessionId: message.sessionId
765
800
  });
766
801
  break;
802
+ case "user_identified": {
803
+ if (endedSessionIds.has(message.sessionId))
804
+ break;
805
+ const user = parseEndUserInfo(message.endUser);
806
+ if (!user)
807
+ break;
808
+ endUserBySessionId.set(message.sessionId, user);
809
+ await handlers.onUserIdentified?.({
810
+ sessionId: message.sessionId,
811
+ env: peerEnvBySessionId.get(message.sessionId) ?? {},
812
+ recordingAvailable: recordingAvailableBySessionId.get(message.sessionId) ?? false,
813
+ conversationHistoryAvailable: conversationHistoryAvailableBySessionId.get(message.sessionId) ?? false,
814
+ mixAvailable: mixAvailableBySessionId.get(message.sessionId) ?? false,
815
+ voiceLanguageSwitchAvailable: voiceLanguageSwitchAvailableBySessionId.get(message.sessionId) ?? false,
816
+ ttsPoseAvailable: ttsPoseAvailableBySessionId.get(message.sessionId) ?? false,
817
+ speakControlAvailable: speakControlAvailableBySessionId.get(message.sessionId) ?? false,
818
+ sessionTimeLimitAvailable: sessionTimeLimitAvailableBySessionId.get(message.sessionId) ?? false,
819
+ user
820
+ });
821
+ break;
822
+ }
767
823
  case "speech_event":
768
824
  await handlers.onSpeechEvent?.({ sessionId: message.sessionId }, message.event);
769
825
  if (message.event.type === "user_speech_final" && typeof message.event.text === "string" && message.event.text.trim()) {
@@ -826,6 +882,7 @@ async function handleParentMessage(message, handlers) {
826
882
  peerEnvBySessionId.delete(message.sessionId);
827
883
  recordingAvailableBySessionId.delete(message.sessionId);
828
884
  conversationHistoryAvailableBySessionId.delete(message.sessionId);
885
+ endUserBySessionId.delete(message.sessionId);
829
886
  mixAvailableBySessionId.delete(message.sessionId);
830
887
  voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
831
888
  voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
@@ -860,6 +917,10 @@ function defineAgent(handlers) {
860
917
  handleConversationHistoryControlAck(message);
861
918
  return;
862
919
  }
920
+ if (isUserHistoryResponseMessage(message)) {
921
+ handleUserHistoryResponse(message);
922
+ return;
923
+ }
863
924
  if (isSpeakResultMessage(message)) {
864
925
  handleSpeakResult(message);
865
926
  return;
@@ -919,6 +980,7 @@ function defineAgent(handlers) {
919
980
  clearPendingSpeakForSession(message.sessionId, "session_ended");
920
981
  clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
921
982
  clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
983
+ clearPendingUserHistoryForSession(message.sessionId, "session_ended");
922
984
  inboundBySession.clear(message.sessionId);
923
985
  }
924
986
  if (message.type === "session_start") {
@@ -991,6 +1053,30 @@ function parseCustomerContext(raw) {
991
1053
  }
992
1054
  return void 0;
993
1055
  }
1056
+ function parseEndUserInfo(value) {
1057
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
1058
+ return void 0;
1059
+ }
1060
+ const v = value;
1061
+ if (typeof v.id !== "string" || v.id.length === 0)
1062
+ return void 0;
1063
+ const isObj = (x) => !!x && typeof x === "object" && !Array.isArray(x);
1064
+ return {
1065
+ id: v.id,
1066
+ verified: v.verified === true,
1067
+ ...isObj(v.attributes) ? { attributes: v.attributes } : {},
1068
+ ...isObj(v.sessionContext) ? { sessionContext: v.sessionContext } : {}
1069
+ };
1070
+ }
1071
+ function parseEndUserEnv(raw) {
1072
+ if (!raw?.trim())
1073
+ return void 0;
1074
+ try {
1075
+ return parseEndUserInfo(JSON.parse(raw));
1076
+ } catch {
1077
+ return void 0;
1078
+ }
1079
+ }
994
1080
  async function runErrorHook(handlers, ctx) {
995
1081
  if (!handlers.errorHook)
996
1082
  return;
@@ -205,6 +205,12 @@ function isConversationHistoryControlAckMessage(value) {
205
205
  const msg = value;
206
206
  return msg.type === "conversation_history_control_ack" && typeof msg.requestId === "string";
207
207
  }
208
+ function isUserHistoryResponseMessage(value) {
209
+ if (!value || typeof value !== "object")
210
+ return false;
211
+ const msg = value;
212
+ return msg.type === "user_history_response" && typeof msg.requestId === "string";
213
+ }
208
214
  function isMixControlAckMessage(value) {
209
215
  if (!value || typeof value !== "object")
210
216
  return false;
@@ -277,7 +283,7 @@ function isParentMessage(value) {
277
283
  if (!value || typeof value !== "object")
278
284
  return false;
279
285
  const msg = value;
280
- 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 === "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";
286
+ 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 === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
281
287
  }
282
288
  function isSessionScopedParentMessage(value) {
283
289
  return isParentMessage(value) && !isWebhookMessage(value);
@@ -292,6 +298,7 @@ function parseDataChannelPayload(raw) {
292
298
  var peerEnvBySessionId = /* @__PURE__ */ new Map();
293
299
  var recordingAvailableBySessionId = /* @__PURE__ */ new Map();
294
300
  var conversationHistoryAvailableBySessionId = /* @__PURE__ */ new Map();
301
+ var endUserBySessionId = /* @__PURE__ */ new Map();
295
302
  var mixAvailableBySessionId = /* @__PURE__ */ new Map();
296
303
  var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
297
304
  var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
@@ -379,6 +386,7 @@ function clearPendingSpeakForSession(sessionId, errorCode) {
379
386
  var PLAY_BYTES_MAX_DECODED_LENGTH = 64 * 1024;
380
387
  var pendingRecordingAcks = /* @__PURE__ */ new Map();
381
388
  var pendingConversationHistoryAcks = /* @__PURE__ */ new Map();
389
+ var pendingUserHistory = /* @__PURE__ */ new Map();
382
390
  var pendingPlayAcks = /* @__PURE__ */ new Map();
383
391
  var pendingPlayStatusAcks = /* @__PURE__ */ new Map();
384
392
  var pendingPlayStopAcks = /* @__PURE__ */ new Map();
@@ -413,6 +421,27 @@ function handleConversationHistoryControlAck(message) {
413
421
  requestId: message.requestId
414
422
  });
415
423
  }
424
+ function handleUserHistoryResponse(message) {
425
+ const pending = pendingUserHistory.get(message.requestId);
426
+ if (!pending)
427
+ return;
428
+ clearTimeout(pending.timer);
429
+ pendingUserHistory.delete(message.requestId);
430
+ pending.resolve({
431
+ ok: message.ok,
432
+ ...message.reason ? { reason: message.reason } : {},
433
+ conversations: Array.isArray(message.conversations) ? message.conversations : []
434
+ });
435
+ }
436
+ function clearPendingUserHistoryForSession(sessionId, reason) {
437
+ for (const [requestId, pending] of pendingUserHistory) {
438
+ if (pending.sessionId !== sessionId)
439
+ continue;
440
+ clearTimeout(pending.timer);
441
+ pendingUserHistory.delete(requestId);
442
+ pending.resolve({ ok: false, reason, conversations: [] });
443
+ }
444
+ }
416
445
  function handlePlayAck(message) {
417
446
  const pending = pendingPlayAcks.get(message.requestId);
418
447
  if (!pending)
@@ -730,6 +759,11 @@ async function handleParentMessage(message, handlers) {
730
759
  peerEnvBySessionId.set(message.sessionId, message.env);
731
760
  recordingAvailableBySessionId.set(message.sessionId, message.recordingAvailable ?? false);
732
761
  conversationHistoryAvailableBySessionId.set(message.sessionId, message.conversationHistoryAvailable ?? false);
762
+ const startUser = parseEndUserInfo(message.endUser) ?? parseEndUserEnv(message.env?.AGENT_END_USER);
763
+ if (startUser)
764
+ endUserBySessionId.set(message.sessionId, startUser);
765
+ else
766
+ endUserBySessionId.delete(message.sessionId);
733
767
  mixAvailableBySessionId.set(message.sessionId, message.mixAvailable ?? false);
734
768
  voiceLanguageSwitchAvailableBySessionId.set(message.sessionId, message.voiceLanguageSwitchAvailable ?? false);
735
769
  ttsPoseAvailableBySessionId.set(message.sessionId, message.ttsPoseAvailable ?? false);
@@ -747,6 +781,7 @@ async function handleParentMessage(message, handlers) {
747
781
  await (handlers.onClientJoin ?? handlers.onSessionStart)?.({
748
782
  sessionId: message.sessionId,
749
783
  env: message.env,
784
+ ...startUser ? { user: startUser } : {},
750
785
  recordingAvailable: message.recordingAvailable ?? false,
751
786
  conversationHistoryAvailable: message.conversationHistoryAvailable ?? false,
752
787
  mixAvailable: message.mixAvailable ?? false,
@@ -760,6 +795,27 @@ async function handleParentMessage(message, handlers) {
760
795
  sessionId: message.sessionId
761
796
  });
762
797
  break;
798
+ case "user_identified": {
799
+ if (endedSessionIds.has(message.sessionId))
800
+ break;
801
+ const user = parseEndUserInfo(message.endUser);
802
+ if (!user)
803
+ break;
804
+ endUserBySessionId.set(message.sessionId, user);
805
+ await handlers.onUserIdentified?.({
806
+ sessionId: message.sessionId,
807
+ env: peerEnvBySessionId.get(message.sessionId) ?? {},
808
+ recordingAvailable: recordingAvailableBySessionId.get(message.sessionId) ?? false,
809
+ conversationHistoryAvailable: conversationHistoryAvailableBySessionId.get(message.sessionId) ?? false,
810
+ mixAvailable: mixAvailableBySessionId.get(message.sessionId) ?? false,
811
+ voiceLanguageSwitchAvailable: voiceLanguageSwitchAvailableBySessionId.get(message.sessionId) ?? false,
812
+ ttsPoseAvailable: ttsPoseAvailableBySessionId.get(message.sessionId) ?? false,
813
+ speakControlAvailable: speakControlAvailableBySessionId.get(message.sessionId) ?? false,
814
+ sessionTimeLimitAvailable: sessionTimeLimitAvailableBySessionId.get(message.sessionId) ?? false,
815
+ user
816
+ });
817
+ break;
818
+ }
763
819
  case "speech_event":
764
820
  await handlers.onSpeechEvent?.({ sessionId: message.sessionId }, message.event);
765
821
  if (message.event.type === "user_speech_final" && typeof message.event.text === "string" && message.event.text.trim()) {
@@ -822,6 +878,7 @@ async function handleParentMessage(message, handlers) {
822
878
  peerEnvBySessionId.delete(message.sessionId);
823
879
  recordingAvailableBySessionId.delete(message.sessionId);
824
880
  conversationHistoryAvailableBySessionId.delete(message.sessionId);
881
+ endUserBySessionId.delete(message.sessionId);
825
882
  mixAvailableBySessionId.delete(message.sessionId);
826
883
  voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
827
884
  voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
@@ -856,6 +913,10 @@ function defineAgent(handlers) {
856
913
  handleConversationHistoryControlAck(message);
857
914
  return;
858
915
  }
916
+ if (isUserHistoryResponseMessage(message)) {
917
+ handleUserHistoryResponse(message);
918
+ return;
919
+ }
859
920
  if (isSpeakResultMessage(message)) {
860
921
  handleSpeakResult(message);
861
922
  return;
@@ -915,6 +976,7 @@ function defineAgent(handlers) {
915
976
  clearPendingSpeakForSession(message.sessionId, "session_ended");
916
977
  clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
917
978
  clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
979
+ clearPendingUserHistoryForSession(message.sessionId, "session_ended");
918
980
  inboundBySession.clear(message.sessionId);
919
981
  }
920
982
  if (message.type === "session_start") {
@@ -987,6 +1049,30 @@ function parseCustomerContext(raw) {
987
1049
  }
988
1050
  return void 0;
989
1051
  }
1052
+ function parseEndUserInfo(value) {
1053
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
1054
+ return void 0;
1055
+ }
1056
+ const v = value;
1057
+ if (typeof v.id !== "string" || v.id.length === 0)
1058
+ return void 0;
1059
+ const isObj = (x) => !!x && typeof x === "object" && !Array.isArray(x);
1060
+ return {
1061
+ id: v.id,
1062
+ verified: v.verified === true,
1063
+ ...isObj(v.attributes) ? { attributes: v.attributes } : {},
1064
+ ...isObj(v.sessionContext) ? { sessionContext: v.sessionContext } : {}
1065
+ };
1066
+ }
1067
+ function parseEndUserEnv(raw) {
1068
+ if (!raw?.trim())
1069
+ return void 0;
1070
+ try {
1071
+ return parseEndUserInfo(JSON.parse(raw));
1072
+ } catch {
1073
+ return void 0;
1074
+ }
1075
+ }
990
1076
  async function runErrorHook(handlers, ctx) {
991
1077
  if (!handlers.errorHook)
992
1078
  return;
@@ -20129,6 +20129,12 @@ function isConversationHistoryControlAckMessage(value) {
20129
20129
  const msg = value;
20130
20130
  return msg.type === "conversation_history_control_ack" && typeof msg.requestId === "string";
20131
20131
  }
20132
+ function isUserHistoryResponseMessage(value) {
20133
+ if (!value || typeof value !== "object")
20134
+ return false;
20135
+ const msg = value;
20136
+ return msg.type === "user_history_response" && typeof msg.requestId === "string";
20137
+ }
20132
20138
  function isMixControlAckMessage(value) {
20133
20139
  if (!value || typeof value !== "object")
20134
20140
  return false;
@@ -20201,7 +20207,7 @@ function isParentMessage(value) {
20201
20207
  if (!value || typeof value !== "object")
20202
20208
  return false;
20203
20209
  const msg = value;
20204
- 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 === "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";
20210
+ 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 === "speak_result" || msg.type === "barge_in_control_ack" || msg.type === "agent_interrupted" || msg.type === "webhook";
20205
20211
  }
20206
20212
  function isSessionScopedParentMessage(value) {
20207
20213
  return isParentMessage(value) && !isWebhookMessage(value);
@@ -20216,6 +20222,7 @@ function parseDataChannelPayload(raw) {
20216
20222
  var peerEnvBySessionId = /* @__PURE__ */ new Map();
20217
20223
  var recordingAvailableBySessionId = /* @__PURE__ */ new Map();
20218
20224
  var conversationHistoryAvailableBySessionId = /* @__PURE__ */ new Map();
20225
+ var endUserBySessionId = /* @__PURE__ */ new Map();
20219
20226
  var mixAvailableBySessionId = /* @__PURE__ */ new Map();
20220
20227
  var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
20221
20228
  var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
@@ -20304,6 +20311,7 @@ function clearPendingSpeakForSession(sessionId, errorCode2) {
20304
20311
  var PLAY_BYTES_MAX_DECODED_LENGTH = 64 * 1024;
20305
20312
  var pendingRecordingAcks = /* @__PURE__ */ new Map();
20306
20313
  var pendingConversationHistoryAcks = /* @__PURE__ */ new Map();
20314
+ var pendingUserHistory = /* @__PURE__ */ new Map();
20307
20315
  var pendingPlayAcks = /* @__PURE__ */ new Map();
20308
20316
  var pendingPlayStatusAcks = /* @__PURE__ */ new Map();
20309
20317
  var pendingPlayStopAcks = /* @__PURE__ */ new Map();
@@ -20338,6 +20346,27 @@ function handleConversationHistoryControlAck(message) {
20338
20346
  requestId: message.requestId
20339
20347
  });
20340
20348
  }
20349
+ function handleUserHistoryResponse(message) {
20350
+ const pending = pendingUserHistory.get(message.requestId);
20351
+ if (!pending)
20352
+ return;
20353
+ clearTimeout(pending.timer);
20354
+ pendingUserHistory.delete(message.requestId);
20355
+ pending.resolve({
20356
+ ok: message.ok,
20357
+ ...message.reason ? { reason: message.reason } : {},
20358
+ conversations: Array.isArray(message.conversations) ? message.conversations : []
20359
+ });
20360
+ }
20361
+ function clearPendingUserHistoryForSession(sessionId, reason) {
20362
+ for (const [requestId, pending] of pendingUserHistory) {
20363
+ if (pending.sessionId !== sessionId)
20364
+ continue;
20365
+ clearTimeout(pending.timer);
20366
+ pendingUserHistory.delete(requestId);
20367
+ pending.resolve({ ok: false, reason, conversations: [] });
20368
+ }
20369
+ }
20341
20370
  function handlePlayAck(message) {
20342
20371
  const pending = pendingPlayAcks.get(message.requestId);
20343
20372
  if (!pending)
@@ -20658,6 +20687,11 @@ async function handleParentMessage(message, handlers) {
20658
20687
  peerEnvBySessionId.set(message.sessionId, message.env);
20659
20688
  recordingAvailableBySessionId.set(message.sessionId, message.recordingAvailable ?? false);
20660
20689
  conversationHistoryAvailableBySessionId.set(message.sessionId, message.conversationHistoryAvailable ?? false);
20690
+ const startUser = parseEndUserInfo(message.endUser) ?? parseEndUserEnv(message.env?.AGENT_END_USER);
20691
+ if (startUser)
20692
+ endUserBySessionId.set(message.sessionId, startUser);
20693
+ else
20694
+ endUserBySessionId.delete(message.sessionId);
20661
20695
  mixAvailableBySessionId.set(message.sessionId, message.mixAvailable ?? false);
20662
20696
  voiceLanguageSwitchAvailableBySessionId.set(message.sessionId, message.voiceLanguageSwitchAvailable ?? false);
20663
20697
  ttsPoseAvailableBySessionId.set(message.sessionId, message.ttsPoseAvailable ?? false);
@@ -20675,6 +20709,7 @@ async function handleParentMessage(message, handlers) {
20675
20709
  await (handlers.onClientJoin ?? handlers.onSessionStart)?.({
20676
20710
  sessionId: message.sessionId,
20677
20711
  env: message.env,
20712
+ ...startUser ? { user: startUser } : {},
20678
20713
  recordingAvailable: message.recordingAvailable ?? false,
20679
20714
  conversationHistoryAvailable: message.conversationHistoryAvailable ?? false,
20680
20715
  mixAvailable: message.mixAvailable ?? false,
@@ -20688,6 +20723,27 @@ async function handleParentMessage(message, handlers) {
20688
20723
  sessionId: message.sessionId
20689
20724
  });
20690
20725
  break;
20726
+ case "user_identified": {
20727
+ if (endedSessionIds.has(message.sessionId))
20728
+ break;
20729
+ const user = parseEndUserInfo(message.endUser);
20730
+ if (!user)
20731
+ break;
20732
+ endUserBySessionId.set(message.sessionId, user);
20733
+ await handlers.onUserIdentified?.({
20734
+ sessionId: message.sessionId,
20735
+ env: peerEnvBySessionId.get(message.sessionId) ?? {},
20736
+ recordingAvailable: recordingAvailableBySessionId.get(message.sessionId) ?? false,
20737
+ conversationHistoryAvailable: conversationHistoryAvailableBySessionId.get(message.sessionId) ?? false,
20738
+ mixAvailable: mixAvailableBySessionId.get(message.sessionId) ?? false,
20739
+ voiceLanguageSwitchAvailable: voiceLanguageSwitchAvailableBySessionId.get(message.sessionId) ?? false,
20740
+ ttsPoseAvailable: ttsPoseAvailableBySessionId.get(message.sessionId) ?? false,
20741
+ speakControlAvailable: speakControlAvailableBySessionId.get(message.sessionId) ?? false,
20742
+ sessionTimeLimitAvailable: sessionTimeLimitAvailableBySessionId.get(message.sessionId) ?? false,
20743
+ user
20744
+ });
20745
+ break;
20746
+ }
20691
20747
  case "speech_event":
20692
20748
  await handlers.onSpeechEvent?.({ sessionId: message.sessionId }, message.event);
20693
20749
  if (message.event.type === "user_speech_final" && typeof message.event.text === "string" && message.event.text.trim()) {
@@ -20750,6 +20806,7 @@ async function handleParentMessage(message, handlers) {
20750
20806
  peerEnvBySessionId.delete(message.sessionId);
20751
20807
  recordingAvailableBySessionId.delete(message.sessionId);
20752
20808
  conversationHistoryAvailableBySessionId.delete(message.sessionId);
20809
+ endUserBySessionId.delete(message.sessionId);
20753
20810
  mixAvailableBySessionId.delete(message.sessionId);
20754
20811
  voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
20755
20812
  voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
@@ -20784,6 +20841,10 @@ function defineAgent(handlers) {
20784
20841
  handleConversationHistoryControlAck(message);
20785
20842
  return;
20786
20843
  }
20844
+ if (isUserHistoryResponseMessage(message)) {
20845
+ handleUserHistoryResponse(message);
20846
+ return;
20847
+ }
20787
20848
  if (isSpeakResultMessage(message)) {
20788
20849
  handleSpeakResult(message);
20789
20850
  return;
@@ -20843,6 +20904,7 @@ function defineAgent(handlers) {
20843
20904
  clearPendingSpeakForSession(message.sessionId, "session_ended");
20844
20905
  clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
20845
20906
  clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
20907
+ clearPendingUserHistoryForSession(message.sessionId, "session_ended");
20846
20908
  inboundBySession.clear(message.sessionId);
20847
20909
  }
20848
20910
  if (message.type === "session_start") {
@@ -20915,6 +20977,30 @@ function parseCustomerContext(raw) {
20915
20977
  }
20916
20978
  return void 0;
20917
20979
  }
20980
+ function parseEndUserInfo(value) {
20981
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
20982
+ return void 0;
20983
+ }
20984
+ const v = value;
20985
+ if (typeof v.id !== "string" || v.id.length === 0)
20986
+ return void 0;
20987
+ const isObj4 = (x) => !!x && typeof x === "object" && !Array.isArray(x);
20988
+ return {
20989
+ id: v.id,
20990
+ verified: v.verified === true,
20991
+ ...isObj4(v.attributes) ? { attributes: v.attributes } : {},
20992
+ ...isObj4(v.sessionContext) ? { sessionContext: v.sessionContext } : {}
20993
+ };
20994
+ }
20995
+ function parseEndUserEnv(raw) {
20996
+ if (!raw?.trim())
20997
+ return void 0;
20998
+ try {
20999
+ return parseEndUserInfo(JSON.parse(raw));
21000
+ } catch {
21001
+ return void 0;
21002
+ }
21003
+ }
20918
21004
  async function runErrorHook(handlers, ctx) {
20919
21005
  if (!handlers.errorHook)
20920
21006
  return;
@@ -23721,6 +23807,7 @@ function isPhone(m) {
23721
23807
  }
23722
23808
  var NON_SECRET_AGENT_KEYS = /* @__PURE__ */ new Set([
23723
23809
  "AGENT_CUSTOMER_CONTEXT",
23810
+ "AGENT_END_USER",
23724
23811
  "AGENT_SERVICE_URL"
23725
23812
  ]);
23726
23813
  function secretValuesFromEnv(env, referenced) {
@@ -23892,6 +23979,7 @@ function buildToolCallFields(a) {
23892
23979
  var MAX_TOOLS = 128;
23893
23980
  var MAX_RESULT_BYTES = 16384;
23894
23981
  var NAME_RE = /^[a-zA-Z0-9_-]{1,64}$/;
23982
+ var VERIFIED_USER_REQUIRED_MESSAGE = "this tool needs a verified user";
23895
23983
  var ToolNameConflictError = class extends Error {
23896
23984
  code = "LLM_TOOL_NAME_CONFLICT";
23897
23985
  constructor(name) {
@@ -23943,8 +24031,9 @@ var ToolRegistry = class {
23943
24031
  addSource(source) {
23944
24032
  this.sources.push(source);
23945
24033
  }
23946
- list() {
23947
- return this.build().map(({ spec, owner }) => ({ spec, owner }));
24034
+ /** Tools the model may see. Pass the session user: verified-user tools show only for a verified one. */
24035
+ list(opts = {}) {
24036
+ return this.build().filter((e) => !e.custom?.requiresVerifiedUser || opts.user?.verified === true).map(({ spec, owner }) => ({ spec, owner }));
23948
24037
  }
23949
24038
  async call(exposedName, args, opts) {
23950
24039
  const entry = this.build().find((e) => e.spec.name === exposedName);
@@ -23961,7 +24050,9 @@ var ToolRegistry = class {
23961
24050
  const startedAt = clock();
23962
24051
  let result;
23963
24052
  try {
23964
- if (entry.custom) {
24053
+ if (entry.custom?.requiresVerifiedUser && opts.user?.verified !== true) {
24054
+ result = { isError: true, content: VERIFIED_USER_REQUIRED_MESSAGE };
24055
+ } else if (entry.custom) {
23965
24056
  result = await this.callCustom(entry.custom, args, opts);
23966
24057
  } else {
23967
24058
  result = await entry.source.callTool(entry.mcpName, args, {