@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
|
@@ -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,
|
|
@@ -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,
|