@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.
- package/README.md +23 -0
- package/dist/agent.js +78 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/llm/agent/create-llm-agent.d.ts +5 -0
- package/dist/llm/agent/create-llm-agent.d.ts.map +1 -1
- package/dist/llm/agent/create-llm-agent.js +11 -2
- package/dist/llm/agent/create-llm-agent.js.map +1 -1
- package/dist/llm/agent/define-tool.d.ts +2 -0
- package/dist/llm/agent/define-tool.d.ts.map +1 -1
- package/dist/llm/agent/define-tool.js +1 -0
- package/dist/llm/agent/define-tool.js.map +1 -1
- package/dist/llm/agent/redact.d.ts.map +1 -1
- package/dist/llm/agent/redact.js +1 -0
- package/dist/llm/agent/redact.js.map +1 -1
- package/dist/llm/end-user/end-user-tools.d.ts +10 -0
- package/dist/llm/end-user/end-user-tools.d.ts.map +1 -0
- package/dist/llm/end-user/end-user-tools.js +50 -0
- package/dist/llm/end-user/end-user-tools.js.map +1 -0
- package/dist/llm/index.d.ts +1 -0
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +1 -0
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/mcp/tool-registry.d.ts +10 -1
- package/dist/llm/mcp/tool-registry.d.ts.map +1 -1
- package/dist/llm/mcp/tool-registry.js +10 -3
- package/dist/llm/mcp/tool-registry.js.map +1 -1
- package/dist/protocol.d.ts +53 -3
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +2 -0
- package/dist/protocol.js.map +1 -1
- package/dist/runtime.d.ts +34 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +133 -0
- package/dist/runtime.js.map +1 -1
- package/dist/templates/echo/agent.js +87 -1
- package/dist/templates/echo-dc/agent.js +87 -1
- package/dist/templates/flow-agent/agent.js +95 -4
- package/dist/templates/game-sync/agent.js +87 -1
- package/dist/templates/language-switch/agent.js +87 -1
- package/dist/templates/llm-agent/agent.js +166 -6
- package/dist/templates/llm-docs-rag/agent.js +166 -6
- package/dist/templates/llm-mcp-service/agent.js +166 -6
- package/dist/templates/llm-support-sticky-user/agent.js +60690 -0
- package/dist/templates/positional-tts/agent.js +87 -1
- package/dist/templates/recording-consent/agent.js +87 -1
- package/dist/templates/registry.d.ts.map +1 -1
- package/dist/templates/registry.js +26 -0
- package/dist/templates/registry.js.map +1 -1
- package/dist/templates/spatial-showcase/agent.js +87 -1
- package/dist/templates/voice-showcase/agent.js +87 -1
- package/dist/templates/voice-starter/agent.js +87 -1
- package/dist/templates/webhooks/agent.js +87 -1
- package/dist/templates/webhooks-redis/agent.js +87 -1
- package/dist/templates/world-sync/agent.js +87 -1
- package/dist/templates/world-sync-binary/agent.js +87 -1
- package/eject/llm/loop.ts +17 -2
- package/package.json +1 -1
- package/templates/README.md +1 -0
- package/templates/llm-support-sticky-user/README.md +68 -0
- package/templates/llm-support-sticky-user/agent.ts +29 -0
- package/templates/llm-support-sticky-user/hooks.ts +188 -0
- package/templates/llm-support-sticky-user/md.d.ts +4 -0
- package/templates/llm-support-sticky-user/mock-crm.ts +75 -0
- package/templates/llm-support-sticky-user/prompt.md +21 -0
- package/templates/llm-support-sticky-user/tools.ts +244 -0
- package/templates/llm-support-sticky-user/voicethere.llm.json +52 -0
|
@@ -10959,6 +10959,12 @@ function isConversationHistoryControlAckMessage(value) {
|
|
|
10959
10959
|
const msg = value;
|
|
10960
10960
|
return msg.type === "conversation_history_control_ack" && typeof msg.requestId === "string";
|
|
10961
10961
|
}
|
|
10962
|
+
function isUserHistoryResponseMessage(value) {
|
|
10963
|
+
if (!value || typeof value !== "object")
|
|
10964
|
+
return false;
|
|
10965
|
+
const msg = value;
|
|
10966
|
+
return msg.type === "user_history_response" && typeof msg.requestId === "string";
|
|
10967
|
+
}
|
|
10962
10968
|
function isMixControlAckMessage(value) {
|
|
10963
10969
|
if (!value || typeof value !== "object")
|
|
10964
10970
|
return false;
|
|
@@ -11031,7 +11037,7 @@ function isParentMessage(value) {
|
|
|
11031
11037
|
if (!value || typeof value !== "object")
|
|
11032
11038
|
return false;
|
|
11033
11039
|
const msg = value;
|
|
11034
|
-
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";
|
|
11040
|
+
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";
|
|
11035
11041
|
}
|
|
11036
11042
|
function isSessionScopedParentMessage(value) {
|
|
11037
11043
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -11046,6 +11052,7 @@ function parseDataChannelPayload(raw) {
|
|
|
11046
11052
|
var peerEnvBySessionId = /* @__PURE__ */ new Map();
|
|
11047
11053
|
var recordingAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
11048
11054
|
var conversationHistoryAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
11055
|
+
var endUserBySessionId = /* @__PURE__ */ new Map();
|
|
11049
11056
|
var mixAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
11050
11057
|
var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
11051
11058
|
var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
|
|
@@ -11133,6 +11140,7 @@ function clearPendingSpeakForSession(sessionId, errorCode) {
|
|
|
11133
11140
|
var PLAY_BYTES_MAX_DECODED_LENGTH = 64 * 1024;
|
|
11134
11141
|
var pendingRecordingAcks = /* @__PURE__ */ new Map();
|
|
11135
11142
|
var pendingConversationHistoryAcks = /* @__PURE__ */ new Map();
|
|
11143
|
+
var pendingUserHistory = /* @__PURE__ */ new Map();
|
|
11136
11144
|
var pendingPlayAcks = /* @__PURE__ */ new Map();
|
|
11137
11145
|
var pendingPlayStatusAcks = /* @__PURE__ */ new Map();
|
|
11138
11146
|
var pendingPlayStopAcks = /* @__PURE__ */ new Map();
|
|
@@ -11167,6 +11175,27 @@ function handleConversationHistoryControlAck(message) {
|
|
|
11167
11175
|
requestId: message.requestId
|
|
11168
11176
|
});
|
|
11169
11177
|
}
|
|
11178
|
+
function handleUserHistoryResponse(message) {
|
|
11179
|
+
const pending = pendingUserHistory.get(message.requestId);
|
|
11180
|
+
if (!pending)
|
|
11181
|
+
return;
|
|
11182
|
+
clearTimeout(pending.timer);
|
|
11183
|
+
pendingUserHistory.delete(message.requestId);
|
|
11184
|
+
pending.resolve({
|
|
11185
|
+
ok: message.ok,
|
|
11186
|
+
...message.reason ? { reason: message.reason } : {},
|
|
11187
|
+
conversations: Array.isArray(message.conversations) ? message.conversations : []
|
|
11188
|
+
});
|
|
11189
|
+
}
|
|
11190
|
+
function clearPendingUserHistoryForSession(sessionId, reason) {
|
|
11191
|
+
for (const [requestId, pending] of pendingUserHistory) {
|
|
11192
|
+
if (pending.sessionId !== sessionId)
|
|
11193
|
+
continue;
|
|
11194
|
+
clearTimeout(pending.timer);
|
|
11195
|
+
pendingUserHistory.delete(requestId);
|
|
11196
|
+
pending.resolve({ ok: false, reason, conversations: [] });
|
|
11197
|
+
}
|
|
11198
|
+
}
|
|
11170
11199
|
function handlePlayAck(message) {
|
|
11171
11200
|
const pending = pendingPlayAcks.get(message.requestId);
|
|
11172
11201
|
if (!pending)
|
|
@@ -11484,6 +11513,11 @@ async function handleParentMessage(message, handlers) {
|
|
|
11484
11513
|
peerEnvBySessionId.set(message.sessionId, message.env);
|
|
11485
11514
|
recordingAvailableBySessionId.set(message.sessionId, message.recordingAvailable ?? false);
|
|
11486
11515
|
conversationHistoryAvailableBySessionId.set(message.sessionId, message.conversationHistoryAvailable ?? false);
|
|
11516
|
+
const startUser = parseEndUserInfo(message.endUser) ?? parseEndUserEnv(message.env?.AGENT_END_USER);
|
|
11517
|
+
if (startUser)
|
|
11518
|
+
endUserBySessionId.set(message.sessionId, startUser);
|
|
11519
|
+
else
|
|
11520
|
+
endUserBySessionId.delete(message.sessionId);
|
|
11487
11521
|
mixAvailableBySessionId.set(message.sessionId, message.mixAvailable ?? false);
|
|
11488
11522
|
voiceLanguageSwitchAvailableBySessionId.set(message.sessionId, message.voiceLanguageSwitchAvailable ?? false);
|
|
11489
11523
|
ttsPoseAvailableBySessionId.set(message.sessionId, message.ttsPoseAvailable ?? false);
|
|
@@ -11501,6 +11535,7 @@ async function handleParentMessage(message, handlers) {
|
|
|
11501
11535
|
await (handlers.onClientJoin ?? handlers.onSessionStart)?.({
|
|
11502
11536
|
sessionId: message.sessionId,
|
|
11503
11537
|
env: message.env,
|
|
11538
|
+
...startUser ? { user: startUser } : {},
|
|
11504
11539
|
recordingAvailable: message.recordingAvailable ?? false,
|
|
11505
11540
|
conversationHistoryAvailable: message.conversationHistoryAvailable ?? false,
|
|
11506
11541
|
mixAvailable: message.mixAvailable ?? false,
|
|
@@ -11514,6 +11549,27 @@ async function handleParentMessage(message, handlers) {
|
|
|
11514
11549
|
sessionId: message.sessionId
|
|
11515
11550
|
});
|
|
11516
11551
|
break;
|
|
11552
|
+
case "user_identified": {
|
|
11553
|
+
if (endedSessionIds.has(message.sessionId))
|
|
11554
|
+
break;
|
|
11555
|
+
const user = parseEndUserInfo(message.endUser);
|
|
11556
|
+
if (!user)
|
|
11557
|
+
break;
|
|
11558
|
+
endUserBySessionId.set(message.sessionId, user);
|
|
11559
|
+
await handlers.onUserIdentified?.({
|
|
11560
|
+
sessionId: message.sessionId,
|
|
11561
|
+
env: peerEnvBySessionId.get(message.sessionId) ?? {},
|
|
11562
|
+
recordingAvailable: recordingAvailableBySessionId.get(message.sessionId) ?? false,
|
|
11563
|
+
conversationHistoryAvailable: conversationHistoryAvailableBySessionId.get(message.sessionId) ?? false,
|
|
11564
|
+
mixAvailable: mixAvailableBySessionId.get(message.sessionId) ?? false,
|
|
11565
|
+
voiceLanguageSwitchAvailable: voiceLanguageSwitchAvailableBySessionId.get(message.sessionId) ?? false,
|
|
11566
|
+
ttsPoseAvailable: ttsPoseAvailableBySessionId.get(message.sessionId) ?? false,
|
|
11567
|
+
speakControlAvailable: speakControlAvailableBySessionId.get(message.sessionId) ?? false,
|
|
11568
|
+
sessionTimeLimitAvailable: sessionTimeLimitAvailableBySessionId.get(message.sessionId) ?? false,
|
|
11569
|
+
user
|
|
11570
|
+
});
|
|
11571
|
+
break;
|
|
11572
|
+
}
|
|
11517
11573
|
case "speech_event":
|
|
11518
11574
|
await handlers.onSpeechEvent?.({ sessionId: message.sessionId }, message.event);
|
|
11519
11575
|
if (message.event.type === "user_speech_final" && typeof message.event.text === "string" && message.event.text.trim()) {
|
|
@@ -11576,6 +11632,7 @@ async function handleParentMessage(message, handlers) {
|
|
|
11576
11632
|
peerEnvBySessionId.delete(message.sessionId);
|
|
11577
11633
|
recordingAvailableBySessionId.delete(message.sessionId);
|
|
11578
11634
|
conversationHistoryAvailableBySessionId.delete(message.sessionId);
|
|
11635
|
+
endUserBySessionId.delete(message.sessionId);
|
|
11579
11636
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
11580
11637
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
11581
11638
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
@@ -11610,6 +11667,10 @@ function defineAgent(handlers) {
|
|
|
11610
11667
|
handleConversationHistoryControlAck(message);
|
|
11611
11668
|
return;
|
|
11612
11669
|
}
|
|
11670
|
+
if (isUserHistoryResponseMessage(message)) {
|
|
11671
|
+
handleUserHistoryResponse(message);
|
|
11672
|
+
return;
|
|
11673
|
+
}
|
|
11613
11674
|
if (isSpeakResultMessage(message)) {
|
|
11614
11675
|
handleSpeakResult(message);
|
|
11615
11676
|
return;
|
|
@@ -11669,6 +11730,7 @@ function defineAgent(handlers) {
|
|
|
11669
11730
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
11670
11731
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
11671
11732
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
11733
|
+
clearPendingUserHistoryForSession(message.sessionId, "session_ended");
|
|
11672
11734
|
inboundBySession.clear(message.sessionId);
|
|
11673
11735
|
}
|
|
11674
11736
|
if (message.type === "session_start") {
|
|
@@ -11741,6 +11803,30 @@ function parseCustomerContext(raw) {
|
|
|
11741
11803
|
}
|
|
11742
11804
|
return void 0;
|
|
11743
11805
|
}
|
|
11806
|
+
function parseEndUserInfo(value) {
|
|
11807
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
11808
|
+
return void 0;
|
|
11809
|
+
}
|
|
11810
|
+
const v = value;
|
|
11811
|
+
if (typeof v.id !== "string" || v.id.length === 0)
|
|
11812
|
+
return void 0;
|
|
11813
|
+
const isObj = (x) => !!x && typeof x === "object" && !Array.isArray(x);
|
|
11814
|
+
return {
|
|
11815
|
+
id: v.id,
|
|
11816
|
+
verified: v.verified === true,
|
|
11817
|
+
...isObj(v.attributes) ? { attributes: v.attributes } : {},
|
|
11818
|
+
...isObj(v.sessionContext) ? { sessionContext: v.sessionContext } : {}
|
|
11819
|
+
};
|
|
11820
|
+
}
|
|
11821
|
+
function parseEndUserEnv(raw) {
|
|
11822
|
+
if (!raw?.trim())
|
|
11823
|
+
return void 0;
|
|
11824
|
+
try {
|
|
11825
|
+
return parseEndUserInfo(JSON.parse(raw));
|
|
11826
|
+
} catch {
|
|
11827
|
+
return void 0;
|
|
11828
|
+
}
|
|
11829
|
+
}
|
|
11744
11830
|
async function runErrorHook(handlers, ctx) {
|
|
11745
11831
|
if (!handlers.errorHook)
|
|
11746
11832
|
return;
|
|
@@ -276,6 +276,12 @@ function isConversationHistoryControlAckMessage(value) {
|
|
|
276
276
|
const msg = value;
|
|
277
277
|
return msg.type === "conversation_history_control_ack" && typeof msg.requestId === "string";
|
|
278
278
|
}
|
|
279
|
+
function isUserHistoryResponseMessage(value) {
|
|
280
|
+
if (!value || typeof value !== "object")
|
|
281
|
+
return false;
|
|
282
|
+
const msg = value;
|
|
283
|
+
return msg.type === "user_history_response" && typeof msg.requestId === "string";
|
|
284
|
+
}
|
|
279
285
|
function isMixControlAckMessage(value) {
|
|
280
286
|
if (!value || typeof value !== "object")
|
|
281
287
|
return false;
|
|
@@ -348,7 +354,7 @@ function isParentMessage(value) {
|
|
|
348
354
|
if (!value || typeof value !== "object")
|
|
349
355
|
return false;
|
|
350
356
|
const msg = value;
|
|
351
|
-
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";
|
|
357
|
+
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";
|
|
352
358
|
}
|
|
353
359
|
function isSessionScopedParentMessage(value) {
|
|
354
360
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -363,6 +369,7 @@ function parseDataChannelPayload(raw) {
|
|
|
363
369
|
var peerEnvBySessionId = /* @__PURE__ */ new Map();
|
|
364
370
|
var recordingAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
365
371
|
var conversationHistoryAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
372
|
+
var endUserBySessionId = /* @__PURE__ */ new Map();
|
|
366
373
|
var mixAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
367
374
|
var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
368
375
|
var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
|
|
@@ -451,6 +458,7 @@ function clearPendingSpeakForSession(sessionId, errorCode) {
|
|
|
451
458
|
var PLAY_BYTES_MAX_DECODED_LENGTH = 64 * 1024;
|
|
452
459
|
var pendingRecordingAcks = /* @__PURE__ */ new Map();
|
|
453
460
|
var pendingConversationHistoryAcks = /* @__PURE__ */ new Map();
|
|
461
|
+
var pendingUserHistory = /* @__PURE__ */ new Map();
|
|
454
462
|
var pendingPlayAcks = /* @__PURE__ */ new Map();
|
|
455
463
|
var pendingPlayStatusAcks = /* @__PURE__ */ new Map();
|
|
456
464
|
var pendingPlayStopAcks = /* @__PURE__ */ new Map();
|
|
@@ -488,6 +496,27 @@ function handleConversationHistoryControlAck(message) {
|
|
|
488
496
|
requestId: message.requestId
|
|
489
497
|
});
|
|
490
498
|
}
|
|
499
|
+
function handleUserHistoryResponse(message) {
|
|
500
|
+
const pending = pendingUserHistory.get(message.requestId);
|
|
501
|
+
if (!pending)
|
|
502
|
+
return;
|
|
503
|
+
clearTimeout(pending.timer);
|
|
504
|
+
pendingUserHistory.delete(message.requestId);
|
|
505
|
+
pending.resolve({
|
|
506
|
+
ok: message.ok,
|
|
507
|
+
...message.reason ? { reason: message.reason } : {},
|
|
508
|
+
conversations: Array.isArray(message.conversations) ? message.conversations : []
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
function clearPendingUserHistoryForSession(sessionId, reason) {
|
|
512
|
+
for (const [requestId, pending] of pendingUserHistory) {
|
|
513
|
+
if (pending.sessionId !== sessionId)
|
|
514
|
+
continue;
|
|
515
|
+
clearTimeout(pending.timer);
|
|
516
|
+
pendingUserHistory.delete(requestId);
|
|
517
|
+
pending.resolve({ ok: false, reason, conversations: [] });
|
|
518
|
+
}
|
|
519
|
+
}
|
|
491
520
|
function handlePlayAck(message) {
|
|
492
521
|
const pending = pendingPlayAcks.get(message.requestId);
|
|
493
522
|
if (!pending)
|
|
@@ -808,6 +837,11 @@ async function handleParentMessage(message, handlers) {
|
|
|
808
837
|
peerEnvBySessionId.set(message.sessionId, message.env);
|
|
809
838
|
recordingAvailableBySessionId.set(message.sessionId, message.recordingAvailable ?? false);
|
|
810
839
|
conversationHistoryAvailableBySessionId.set(message.sessionId, message.conversationHistoryAvailable ?? false);
|
|
840
|
+
const startUser = parseEndUserInfo(message.endUser) ?? parseEndUserEnv(message.env?.AGENT_END_USER);
|
|
841
|
+
if (startUser)
|
|
842
|
+
endUserBySessionId.set(message.sessionId, startUser);
|
|
843
|
+
else
|
|
844
|
+
endUserBySessionId.delete(message.sessionId);
|
|
811
845
|
mixAvailableBySessionId.set(message.sessionId, message.mixAvailable ?? false);
|
|
812
846
|
voiceLanguageSwitchAvailableBySessionId.set(message.sessionId, message.voiceLanguageSwitchAvailable ?? false);
|
|
813
847
|
ttsPoseAvailableBySessionId.set(message.sessionId, message.ttsPoseAvailable ?? false);
|
|
@@ -825,6 +859,7 @@ async function handleParentMessage(message, handlers) {
|
|
|
825
859
|
await (handlers.onClientJoin ?? handlers.onSessionStart)?.({
|
|
826
860
|
sessionId: message.sessionId,
|
|
827
861
|
env: message.env,
|
|
862
|
+
...startUser ? { user: startUser } : {},
|
|
828
863
|
recordingAvailable: message.recordingAvailable ?? false,
|
|
829
864
|
conversationHistoryAvailable: message.conversationHistoryAvailable ?? false,
|
|
830
865
|
mixAvailable: message.mixAvailable ?? false,
|
|
@@ -838,6 +873,27 @@ async function handleParentMessage(message, handlers) {
|
|
|
838
873
|
sessionId: message.sessionId
|
|
839
874
|
});
|
|
840
875
|
break;
|
|
876
|
+
case "user_identified": {
|
|
877
|
+
if (endedSessionIds.has(message.sessionId))
|
|
878
|
+
break;
|
|
879
|
+
const user = parseEndUserInfo(message.endUser);
|
|
880
|
+
if (!user)
|
|
881
|
+
break;
|
|
882
|
+
endUserBySessionId.set(message.sessionId, user);
|
|
883
|
+
await handlers.onUserIdentified?.({
|
|
884
|
+
sessionId: message.sessionId,
|
|
885
|
+
env: peerEnvBySessionId.get(message.sessionId) ?? {},
|
|
886
|
+
recordingAvailable: recordingAvailableBySessionId.get(message.sessionId) ?? false,
|
|
887
|
+
conversationHistoryAvailable: conversationHistoryAvailableBySessionId.get(message.sessionId) ?? false,
|
|
888
|
+
mixAvailable: mixAvailableBySessionId.get(message.sessionId) ?? false,
|
|
889
|
+
voiceLanguageSwitchAvailable: voiceLanguageSwitchAvailableBySessionId.get(message.sessionId) ?? false,
|
|
890
|
+
ttsPoseAvailable: ttsPoseAvailableBySessionId.get(message.sessionId) ?? false,
|
|
891
|
+
speakControlAvailable: speakControlAvailableBySessionId.get(message.sessionId) ?? false,
|
|
892
|
+
sessionTimeLimitAvailable: sessionTimeLimitAvailableBySessionId.get(message.sessionId) ?? false,
|
|
893
|
+
user
|
|
894
|
+
});
|
|
895
|
+
break;
|
|
896
|
+
}
|
|
841
897
|
case "speech_event":
|
|
842
898
|
await handlers.onSpeechEvent?.({ sessionId: message.sessionId }, message.event);
|
|
843
899
|
if (message.event.type === "user_speech_final" && typeof message.event.text === "string" && message.event.text.trim()) {
|
|
@@ -900,6 +956,7 @@ async function handleParentMessage(message, handlers) {
|
|
|
900
956
|
peerEnvBySessionId.delete(message.sessionId);
|
|
901
957
|
recordingAvailableBySessionId.delete(message.sessionId);
|
|
902
958
|
conversationHistoryAvailableBySessionId.delete(message.sessionId);
|
|
959
|
+
endUserBySessionId.delete(message.sessionId);
|
|
903
960
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
904
961
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
905
962
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
@@ -934,6 +991,10 @@ function defineAgent(handlers) {
|
|
|
934
991
|
handleConversationHistoryControlAck(message);
|
|
935
992
|
return;
|
|
936
993
|
}
|
|
994
|
+
if (isUserHistoryResponseMessage(message)) {
|
|
995
|
+
handleUserHistoryResponse(message);
|
|
996
|
+
return;
|
|
997
|
+
}
|
|
937
998
|
if (isSpeakResultMessage(message)) {
|
|
938
999
|
handleSpeakResult(message);
|
|
939
1000
|
return;
|
|
@@ -993,6 +1054,7 @@ function defineAgent(handlers) {
|
|
|
993
1054
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
994
1055
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
995
1056
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
1057
|
+
clearPendingUserHistoryForSession(message.sessionId, "session_ended");
|
|
996
1058
|
inboundBySession.clear(message.sessionId);
|
|
997
1059
|
}
|
|
998
1060
|
if (message.type === "session_start") {
|
|
@@ -1065,6 +1127,30 @@ function parseCustomerContext(raw) {
|
|
|
1065
1127
|
}
|
|
1066
1128
|
return void 0;
|
|
1067
1129
|
}
|
|
1130
|
+
function parseEndUserInfo(value) {
|
|
1131
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1132
|
+
return void 0;
|
|
1133
|
+
}
|
|
1134
|
+
const v = value;
|
|
1135
|
+
if (typeof v.id !== "string" || v.id.length === 0)
|
|
1136
|
+
return void 0;
|
|
1137
|
+
const isObj = (x) => !!x && typeof x === "object" && !Array.isArray(x);
|
|
1138
|
+
return {
|
|
1139
|
+
id: v.id,
|
|
1140
|
+
verified: v.verified === true,
|
|
1141
|
+
...isObj(v.attributes) ? { attributes: v.attributes } : {},
|
|
1142
|
+
...isObj(v.sessionContext) ? { sessionContext: v.sessionContext } : {}
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
function parseEndUserEnv(raw) {
|
|
1146
|
+
if (!raw?.trim())
|
|
1147
|
+
return void 0;
|
|
1148
|
+
try {
|
|
1149
|
+
return parseEndUserInfo(JSON.parse(raw));
|
|
1150
|
+
} catch {
|
|
1151
|
+
return void 0;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1068
1154
|
async function runErrorHook(handlers, ctx) {
|
|
1069
1155
|
if (!handlers.errorHook)
|
|
1070
1156
|
return;
|
|
@@ -30848,6 +30848,12 @@ function isConversationHistoryControlAckMessage(value) {
|
|
|
30848
30848
|
const msg = value;
|
|
30849
30849
|
return msg.type === "conversation_history_control_ack" && typeof msg.requestId === "string";
|
|
30850
30850
|
}
|
|
30851
|
+
function isUserHistoryResponseMessage(value) {
|
|
30852
|
+
if (!value || typeof value !== "object")
|
|
30853
|
+
return false;
|
|
30854
|
+
const msg = value;
|
|
30855
|
+
return msg.type === "user_history_response" && typeof msg.requestId === "string";
|
|
30856
|
+
}
|
|
30851
30857
|
function isMixControlAckMessage(value) {
|
|
30852
30858
|
if (!value || typeof value !== "object")
|
|
30853
30859
|
return false;
|
|
@@ -30920,7 +30926,7 @@ function isParentMessage(value) {
|
|
|
30920
30926
|
if (!value || typeof value !== "object")
|
|
30921
30927
|
return false;
|
|
30922
30928
|
const msg = value;
|
|
30923
|
-
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";
|
|
30929
|
+
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";
|
|
30924
30930
|
}
|
|
30925
30931
|
function isSessionScopedParentMessage(value) {
|
|
30926
30932
|
return isParentMessage(value) && !isWebhookMessage(value);
|
|
@@ -30935,6 +30941,7 @@ function parseDataChannelPayload(raw) {
|
|
|
30935
30941
|
var peerEnvBySessionId = /* @__PURE__ */ new Map();
|
|
30936
30942
|
var recordingAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
30937
30943
|
var conversationHistoryAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
30944
|
+
var endUserBySessionId = /* @__PURE__ */ new Map();
|
|
30938
30945
|
var mixAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
30939
30946
|
var voiceLanguageSwitchAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
30940
30947
|
var lastVoiceLanguageBySessionId = /* @__PURE__ */ new Map();
|
|
@@ -30944,6 +30951,7 @@ var sessionTimeLimitAvailableBySessionId = /* @__PURE__ */ new Map();
|
|
|
30944
30951
|
var sessionTimeLimitWarnedSessionIds = /* @__PURE__ */ new Set();
|
|
30945
30952
|
var speakControlWarnedSessionIds = /* @__PURE__ */ new Set();
|
|
30946
30953
|
var endedSessionIds = /* @__PURE__ */ new Set();
|
|
30954
|
+
var USER_HISTORY_TIMEOUT_MS = 5e3;
|
|
30947
30955
|
var BARGE_IN_CONTROL_ACK_TIMEOUT_MS = 5e3;
|
|
30948
30956
|
var SPEAK_RESULT_SAFETY_TIMEOUT_MS = 6e5;
|
|
30949
30957
|
var pendingSpeakResults = /* @__PURE__ */ new Map();
|
|
@@ -31024,6 +31032,7 @@ function clearPendingSpeakForSession(sessionId, errorCode) {
|
|
|
31024
31032
|
var PLAY_BYTES_MAX_DECODED_LENGTH = 64 * 1024;
|
|
31025
31033
|
var pendingRecordingAcks = /* @__PURE__ */ new Map();
|
|
31026
31034
|
var pendingConversationHistoryAcks = /* @__PURE__ */ new Map();
|
|
31035
|
+
var pendingUserHistory = /* @__PURE__ */ new Map();
|
|
31027
31036
|
var pendingPlayAcks = /* @__PURE__ */ new Map();
|
|
31028
31037
|
var pendingPlayStatusAcks = /* @__PURE__ */ new Map();
|
|
31029
31038
|
var pendingPlayStopAcks = /* @__PURE__ */ new Map();
|
|
@@ -31058,6 +31067,27 @@ function handleConversationHistoryControlAck(message) {
|
|
|
31058
31067
|
requestId: message.requestId
|
|
31059
31068
|
});
|
|
31060
31069
|
}
|
|
31070
|
+
function handleUserHistoryResponse(message) {
|
|
31071
|
+
const pending = pendingUserHistory.get(message.requestId);
|
|
31072
|
+
if (!pending)
|
|
31073
|
+
return;
|
|
31074
|
+
clearTimeout(pending.timer);
|
|
31075
|
+
pendingUserHistory.delete(message.requestId);
|
|
31076
|
+
pending.resolve({
|
|
31077
|
+
ok: message.ok,
|
|
31078
|
+
...message.reason ? { reason: message.reason } : {},
|
|
31079
|
+
conversations: Array.isArray(message.conversations) ? message.conversations : []
|
|
31080
|
+
});
|
|
31081
|
+
}
|
|
31082
|
+
function clearPendingUserHistoryForSession(sessionId, reason) {
|
|
31083
|
+
for (const [requestId, pending] of pendingUserHistory) {
|
|
31084
|
+
if (pending.sessionId !== sessionId)
|
|
31085
|
+
continue;
|
|
31086
|
+
clearTimeout(pending.timer);
|
|
31087
|
+
pendingUserHistory.delete(requestId);
|
|
31088
|
+
pending.resolve({ ok: false, reason, conversations: [] });
|
|
31089
|
+
}
|
|
31090
|
+
}
|
|
31061
31091
|
function handlePlayAck(message) {
|
|
31062
31092
|
const pending = pendingPlayAcks.get(message.requestId);
|
|
31063
31093
|
if (!pending)
|
|
@@ -31378,6 +31408,11 @@ async function handleParentMessage(message, handlers) {
|
|
|
31378
31408
|
peerEnvBySessionId.set(message.sessionId, message.env);
|
|
31379
31409
|
recordingAvailableBySessionId.set(message.sessionId, message.recordingAvailable ?? false);
|
|
31380
31410
|
conversationHistoryAvailableBySessionId.set(message.sessionId, message.conversationHistoryAvailable ?? false);
|
|
31411
|
+
const startUser = parseEndUserInfo(message.endUser) ?? parseEndUserEnv(message.env?.AGENT_END_USER);
|
|
31412
|
+
if (startUser)
|
|
31413
|
+
endUserBySessionId.set(message.sessionId, startUser);
|
|
31414
|
+
else
|
|
31415
|
+
endUserBySessionId.delete(message.sessionId);
|
|
31381
31416
|
mixAvailableBySessionId.set(message.sessionId, message.mixAvailable ?? false);
|
|
31382
31417
|
voiceLanguageSwitchAvailableBySessionId.set(message.sessionId, message.voiceLanguageSwitchAvailable ?? false);
|
|
31383
31418
|
ttsPoseAvailableBySessionId.set(message.sessionId, message.ttsPoseAvailable ?? false);
|
|
@@ -31395,6 +31430,7 @@ async function handleParentMessage(message, handlers) {
|
|
|
31395
31430
|
await (handlers.onClientJoin ?? handlers.onSessionStart)?.({
|
|
31396
31431
|
sessionId: message.sessionId,
|
|
31397
31432
|
env: message.env,
|
|
31433
|
+
...startUser ? { user: startUser } : {},
|
|
31398
31434
|
recordingAvailable: message.recordingAvailable ?? false,
|
|
31399
31435
|
conversationHistoryAvailable: message.conversationHistoryAvailable ?? false,
|
|
31400
31436
|
mixAvailable: message.mixAvailable ?? false,
|
|
@@ -31408,6 +31444,27 @@ async function handleParentMessage(message, handlers) {
|
|
|
31408
31444
|
sessionId: message.sessionId
|
|
31409
31445
|
});
|
|
31410
31446
|
break;
|
|
31447
|
+
case "user_identified": {
|
|
31448
|
+
if (endedSessionIds.has(message.sessionId))
|
|
31449
|
+
break;
|
|
31450
|
+
const user = parseEndUserInfo(message.endUser);
|
|
31451
|
+
if (!user)
|
|
31452
|
+
break;
|
|
31453
|
+
endUserBySessionId.set(message.sessionId, user);
|
|
31454
|
+
await handlers.onUserIdentified?.({
|
|
31455
|
+
sessionId: message.sessionId,
|
|
31456
|
+
env: peerEnvBySessionId.get(message.sessionId) ?? {},
|
|
31457
|
+
recordingAvailable: recordingAvailableBySessionId.get(message.sessionId) ?? false,
|
|
31458
|
+
conversationHistoryAvailable: conversationHistoryAvailableBySessionId.get(message.sessionId) ?? false,
|
|
31459
|
+
mixAvailable: mixAvailableBySessionId.get(message.sessionId) ?? false,
|
|
31460
|
+
voiceLanguageSwitchAvailable: voiceLanguageSwitchAvailableBySessionId.get(message.sessionId) ?? false,
|
|
31461
|
+
ttsPoseAvailable: ttsPoseAvailableBySessionId.get(message.sessionId) ?? false,
|
|
31462
|
+
speakControlAvailable: speakControlAvailableBySessionId.get(message.sessionId) ?? false,
|
|
31463
|
+
sessionTimeLimitAvailable: sessionTimeLimitAvailableBySessionId.get(message.sessionId) ?? false,
|
|
31464
|
+
user
|
|
31465
|
+
});
|
|
31466
|
+
break;
|
|
31467
|
+
}
|
|
31411
31468
|
case "speech_event":
|
|
31412
31469
|
await handlers.onSpeechEvent?.({ sessionId: message.sessionId }, message.event);
|
|
31413
31470
|
if (message.event.type === "user_speech_final" && typeof message.event.text === "string" && message.event.text.trim()) {
|
|
@@ -31470,6 +31527,7 @@ async function handleParentMessage(message, handlers) {
|
|
|
31470
31527
|
peerEnvBySessionId.delete(message.sessionId);
|
|
31471
31528
|
recordingAvailableBySessionId.delete(message.sessionId);
|
|
31472
31529
|
conversationHistoryAvailableBySessionId.delete(message.sessionId);
|
|
31530
|
+
endUserBySessionId.delete(message.sessionId);
|
|
31473
31531
|
mixAvailableBySessionId.delete(message.sessionId);
|
|
31474
31532
|
voiceLanguageSwitchAvailableBySessionId.delete(message.sessionId);
|
|
31475
31533
|
voiceLanguageSwitchSettingsBySessionId.delete(message.sessionId);
|
|
@@ -31504,6 +31562,10 @@ function defineAgent(handlers) {
|
|
|
31504
31562
|
handleConversationHistoryControlAck(message);
|
|
31505
31563
|
return;
|
|
31506
31564
|
}
|
|
31565
|
+
if (isUserHistoryResponseMessage(message)) {
|
|
31566
|
+
handleUserHistoryResponse(message);
|
|
31567
|
+
return;
|
|
31568
|
+
}
|
|
31507
31569
|
if (isSpeakResultMessage(message)) {
|
|
31508
31570
|
handleSpeakResult(message);
|
|
31509
31571
|
return;
|
|
@@ -31563,6 +31625,7 @@ function defineAgent(handlers) {
|
|
|
31563
31625
|
clearPendingSpeakForSession(message.sessionId, "session_ended");
|
|
31564
31626
|
clearPendingRecordingAcksForSession(message.sessionId, "session_ended");
|
|
31565
31627
|
clearPendingConversationHistoryAcksForSession(message.sessionId, "session_ended");
|
|
31628
|
+
clearPendingUserHistoryForSession(message.sessionId, "session_ended");
|
|
31566
31629
|
inboundBySession.clear(message.sessionId);
|
|
31567
31630
|
}
|
|
31568
31631
|
if (message.type === "session_start") {
|
|
@@ -31635,6 +31698,30 @@ function parseCustomerContext(raw) {
|
|
|
31635
31698
|
}
|
|
31636
31699
|
return void 0;
|
|
31637
31700
|
}
|
|
31701
|
+
function parseEndUserInfo(value) {
|
|
31702
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
31703
|
+
return void 0;
|
|
31704
|
+
}
|
|
31705
|
+
const v = value;
|
|
31706
|
+
if (typeof v.id !== "string" || v.id.length === 0)
|
|
31707
|
+
return void 0;
|
|
31708
|
+
const isObj2 = (x) => !!x && typeof x === "object" && !Array.isArray(x);
|
|
31709
|
+
return {
|
|
31710
|
+
id: v.id,
|
|
31711
|
+
verified: v.verified === true,
|
|
31712
|
+
...isObj2(v.attributes) ? { attributes: v.attributes } : {},
|
|
31713
|
+
...isObj2(v.sessionContext) ? { sessionContext: v.sessionContext } : {}
|
|
31714
|
+
};
|
|
31715
|
+
}
|
|
31716
|
+
function parseEndUserEnv(raw) {
|
|
31717
|
+
if (!raw?.trim())
|
|
31718
|
+
return void 0;
|
|
31719
|
+
try {
|
|
31720
|
+
return parseEndUserInfo(JSON.parse(raw));
|
|
31721
|
+
} catch {
|
|
31722
|
+
return void 0;
|
|
31723
|
+
}
|
|
31724
|
+
}
|
|
31638
31725
|
async function runErrorHook(handlers, ctx) {
|
|
31639
31726
|
if (!handlers.errorHook)
|
|
31640
31727
|
return;
|
|
@@ -31862,6 +31949,32 @@ function setAgentState(sessionId, state2, options) {
|
|
|
31862
31949
|
...detail ? { detail: detail.slice(0, 64) } : {}
|
|
31863
31950
|
});
|
|
31864
31951
|
}
|
|
31952
|
+
function getSessionUser(sessionId) {
|
|
31953
|
+
return endUserBySessionId.get(sessionId);
|
|
31954
|
+
}
|
|
31955
|
+
async function getUserHistory(sessionId, opts = {}) {
|
|
31956
|
+
if (!allowOutboundForSession(sessionId)) {
|
|
31957
|
+
return { ok: false, reason: "session_ended", conversations: [] };
|
|
31958
|
+
}
|
|
31959
|
+
if (!isVoicethereAgentChild()) {
|
|
31960
|
+
return { ok: true, reason: "local_mock", conversations: [] };
|
|
31961
|
+
}
|
|
31962
|
+
const requestId = randomUUID();
|
|
31963
|
+
return new Promise((resolve) => {
|
|
31964
|
+
const timer = setTimeout(() => {
|
|
31965
|
+
pendingUserHistory.delete(requestId);
|
|
31966
|
+
resolve({ ok: false, reason: "timeout", conversations: [] });
|
|
31967
|
+
}, USER_HISTORY_TIMEOUT_MS);
|
|
31968
|
+
pendingUserHistory.set(requestId, { sessionId, resolve, timer });
|
|
31969
|
+
sendParentMessage({
|
|
31970
|
+
type: "user_history_request",
|
|
31971
|
+
requestId,
|
|
31972
|
+
sessionId,
|
|
31973
|
+
limit: opts.limit ?? 5,
|
|
31974
|
+
maxTurnsPerConversation: opts.maxTurnsPerConversation ?? 50
|
|
31975
|
+
});
|
|
31976
|
+
});
|
|
31977
|
+
}
|
|
31865
31978
|
function sendToClient(sessionId, payload) {
|
|
31866
31979
|
sendParentMessage({ type: "send_to_client", sessionId, payload });
|
|
31867
31980
|
}
|
|
@@ -32669,6 +32782,7 @@ function isPhone(m) {
|
|
|
32669
32782
|
}
|
|
32670
32783
|
var NON_SECRET_AGENT_KEYS = /* @__PURE__ */ new Set([
|
|
32671
32784
|
"AGENT_CUSTOMER_CONTEXT",
|
|
32785
|
+
"AGENT_END_USER",
|
|
32672
32786
|
"AGENT_SERVICE_URL"
|
|
32673
32787
|
]);
|
|
32674
32788
|
function secretValuesFromEnv(env, referenced) {
|
|
@@ -32840,6 +32954,7 @@ function buildToolCallFields(a) {
|
|
|
32840
32954
|
var MAX_TOOLS = 128;
|
|
32841
32955
|
var MAX_RESULT_BYTES = 16384;
|
|
32842
32956
|
var NAME_RE = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
32957
|
+
var VERIFIED_USER_REQUIRED_MESSAGE = "this tool needs a verified user";
|
|
32843
32958
|
var ToolNameConflictError = class extends Error {
|
|
32844
32959
|
code = "LLM_TOOL_NAME_CONFLICT";
|
|
32845
32960
|
constructor(name) {
|
|
@@ -32891,8 +33006,9 @@ var ToolRegistry = class {
|
|
|
32891
33006
|
addSource(source) {
|
|
32892
33007
|
this.sources.push(source);
|
|
32893
33008
|
}
|
|
32894
|
-
|
|
32895
|
-
|
|
33009
|
+
/** Tools the model may see. Pass the session user: verified-user tools show only for a verified one. */
|
|
33010
|
+
list(opts = {}) {
|
|
33011
|
+
return this.build().filter((e) => !e.custom?.requiresVerifiedUser || opts.user?.verified === true).map(({ spec, owner }) => ({ spec, owner }));
|
|
32896
33012
|
}
|
|
32897
33013
|
async call(exposedName, args, opts) {
|
|
32898
33014
|
const entry = this.build().find((e) => e.spec.name === exposedName);
|
|
@@ -32909,7 +33025,9 @@ var ToolRegistry = class {
|
|
|
32909
33025
|
const startedAt = clock();
|
|
32910
33026
|
let result;
|
|
32911
33027
|
try {
|
|
32912
|
-
if (entry.custom) {
|
|
33028
|
+
if (entry.custom?.requiresVerifiedUser && opts.user?.verified !== true) {
|
|
33029
|
+
result = { isError: true, content: VERIFIED_USER_REQUIRED_MESSAGE };
|
|
33030
|
+
} else if (entry.custom) {
|
|
32913
33031
|
result = await this.callCustom(entry.custom, args, opts);
|
|
32914
33032
|
} else {
|
|
32915
33033
|
result = await entry.source.callTool(entry.mcpName, args, {
|
|
@@ -33805,6 +33923,7 @@ function defineTool(t) {
|
|
|
33805
33923
|
name: t.name,
|
|
33806
33924
|
description: t.description,
|
|
33807
33925
|
inputSchema: t.inputSchema,
|
|
33926
|
+
...t.requiresVerifiedUser ? { requiresVerifiedUser: true } : {},
|
|
33808
33927
|
handler: async (args, ctx) => String(await t.handler(args, ctx))
|
|
33809
33928
|
};
|
|
33810
33929
|
}
|
|
@@ -33848,6 +33967,45 @@ ${h.text}`).join("\n\n");
|
|
|
33848
33967
|
});
|
|
33849
33968
|
}
|
|
33850
33969
|
|
|
33970
|
+
// dist/llm/end-user/end-user-tools.js
|
|
33971
|
+
var MAX_CHARS = 6e3;
|
|
33972
|
+
function endUserTools(load = getUserHistory) {
|
|
33973
|
+
return [
|
|
33974
|
+
defineTool({
|
|
33975
|
+
name: "get_previous_conversations",
|
|
33976
|
+
description: "Read earlier conversations with this verified user, to avoid repeating questions or steps they already went through.",
|
|
33977
|
+
inputSchema: {
|
|
33978
|
+
type: "object",
|
|
33979
|
+
additionalProperties: false,
|
|
33980
|
+
properties: { limit: { type: "integer", minimum: 1, maximum: 10 } }
|
|
33981
|
+
},
|
|
33982
|
+
requiresVerifiedUser: true,
|
|
33983
|
+
handler: async (args, ctx) => {
|
|
33984
|
+
const limit2 = typeof args.limit === "number" && Number.isInteger(args.limit) ? Math.min(10, Math.max(1, args.limit)) : 3;
|
|
33985
|
+
const res = await load(ctx.sessionId, { limit: limit2 });
|
|
33986
|
+
if (!res.ok)
|
|
33987
|
+
return "Earlier conversations are unavailable right now.";
|
|
33988
|
+
if (res.conversations.length === 0) {
|
|
33989
|
+
return "No earlier conversations with this user.";
|
|
33990
|
+
}
|
|
33991
|
+
const text = res.conversations.map((c, i) => `Conversation ${i + 1} (${c.sessionStartedAt}):
|
|
33992
|
+
` + c.turns.map((t) => `${t.role}: ${t.text}`).join("\n")).join("\n\n");
|
|
33993
|
+
return text.length > MAX_CHARS ? text.slice(0, MAX_CHARS) : text;
|
|
33994
|
+
}
|
|
33995
|
+
}),
|
|
33996
|
+
defineTool({
|
|
33997
|
+
name: "get_current_user",
|
|
33998
|
+
description: "Who the current user is: their id, whether they are verified, and the attributes the customer's system gave.",
|
|
33999
|
+
inputSchema: { type: "object", additionalProperties: false },
|
|
34000
|
+
handler: (_args, ctx) => JSON.stringify(ctx.user ? {
|
|
34001
|
+
id: ctx.user.id,
|
|
34002
|
+
verified: ctx.user.verified,
|
|
34003
|
+
attributes: ctx.user.attributes ?? {}
|
|
34004
|
+
} : { id: null, verified: false, attributes: {} })
|
|
34005
|
+
})
|
|
34006
|
+
];
|
|
34007
|
+
}
|
|
34008
|
+
|
|
33851
34009
|
// dist/llm/agent/config.js
|
|
33852
34010
|
var LLM_AGENT_CONFIG_DEFAULTS = {
|
|
33853
34011
|
maxOutputTokens: 512,
|
|
@@ -35925,6 +36083,7 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
|
|
|
35925
36083
|
toolSources: config2.toolSources ?? [],
|
|
35926
36084
|
customTools: [
|
|
35927
36085
|
...opts.tools ?? [],
|
|
36086
|
+
...opts.endUserTools === true ? endUserTools() : [],
|
|
35928
36087
|
...knowledgeTool ? [knowledgeTool] : []
|
|
35929
36088
|
],
|
|
35930
36089
|
secretNames: [
|
|
@@ -35981,7 +36140,8 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
|
|
|
35981
36140
|
timeoutMs: toolTimeoutMs,
|
|
35982
36141
|
sessionId: s.sessionId,
|
|
35983
36142
|
turnId: t.turnId,
|
|
35984
|
-
callId: call.id
|
|
36143
|
+
callId: call.id,
|
|
36144
|
+
...getSessionUser(s.sessionId) ? { user: getSessionUser(s.sessionId) } : {}
|
|
35985
36145
|
});
|
|
35986
36146
|
})();
|
|
35987
36147
|
const raced = await Promise.race([work, aborted2]);
|
|
@@ -36066,7 +36226,7 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
|
|
|
36066
36226
|
model: resolveModel(config2.provider, config2.model),
|
|
36067
36227
|
system: opts.systemPrompt,
|
|
36068
36228
|
messages,
|
|
36069
|
-
tools: registry2 ? registry2.list().map((e) => e.spec) : [],
|
|
36229
|
+
tools: registry2 ? registry2.list({ user: getSessionUser(s.sessionId) }).map((e) => e.spec) : [],
|
|
36070
36230
|
...config2.toolChoice === "required-first-round" && t.llmCalls === 1 ? { toolChoice: "required" } : {},
|
|
36071
36231
|
temperature: config2.temperature,
|
|
36072
36232
|
maxOutputTokens: config2.maxOutputTokens ?? D.maxOutputTokens,
|