llm-agent-runtime 0.1.17 → 0.1.21

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 (80) hide show
  1. package/USAGE.md +5 -3
  2. package/dist/agent.d.ts +0 -1
  3. package/dist/agent.js +1 -69
  4. package/dist/create-runtime.d.ts +5 -3
  5. package/dist/create-runtime.js +1 -321
  6. package/dist/embeddings/xenova.d.ts +0 -1
  7. package/dist/embeddings/xenova.js +1 -69
  8. package/dist/env-llm.d.ts +0 -1
  9. package/dist/env-llm.js +1 -114
  10. package/dist/errors.d.ts +0 -1
  11. package/dist/errors.js +1 -17
  12. package/dist/index.d.ts +1 -2
  13. package/dist/index.js +1 -15
  14. package/dist/intents/define.d.ts +0 -1
  15. package/dist/intents/define.js +1 -52
  16. package/dist/intents/general.d.ts +0 -1
  17. package/dist/intents/general.js +1 -67
  18. package/dist/llm.d.ts +0 -1
  19. package/dist/llm.js +1 -112
  20. package/dist/rag/index.d.ts +0 -1
  21. package/dist/rag/index.js +1 -140
  22. package/dist/rag/loaders.d.ts +0 -1
  23. package/dist/rag/loaders.js +1 -80
  24. package/dist/rag/sources.d.ts +0 -1
  25. package/dist/rag/sources.js +1 -101
  26. package/dist/redis.d.ts +0 -1
  27. package/dist/redis.js +1 -18
  28. package/dist/services/agent-runner.d.ts +0 -1
  29. package/dist/services/agent-runner.js +1 -18
  30. package/dist/services/chat-cache.d.ts +0 -1
  31. package/dist/services/chat-cache.js +1 -70
  32. package/dist/services/conversation.d.ts +0 -1
  33. package/dist/services/conversation.js +1 -68
  34. package/dist/services/extract.d.ts +0 -1
  35. package/dist/services/extract.js +1 -64
  36. package/dist/services/flow-router.d.ts +0 -1
  37. package/dist/services/flow-router.js +1 -191
  38. package/dist/services/intent-embeddings.d.ts +0 -1
  39. package/dist/services/intent-embeddings.js +1 -45
  40. package/dist/services/intent-router.d.ts +0 -1
  41. package/dist/services/intent-router.js +1 -98
  42. package/dist/services/simple-config.d.ts +0 -1
  43. package/dist/services/simple-config.js +1 -70
  44. package/dist/services/token-usage.d.ts +10 -5
  45. package/dist/services/token-usage.js +1 -63
  46. package/dist/services/usage-store.d.ts +15 -3
  47. package/dist/services/usage-store.js +1 -92
  48. package/dist/types.d.ts +2 -2
  49. package/dist/types.js +1 -1
  50. package/dist/utils/message.d.ts +0 -1
  51. package/dist/utils/message.js +1 -13
  52. package/dist/utils/normalize.d.ts +0 -1
  53. package/dist/utils/normalize.js +1 -8
  54. package/package.json +6 -3
  55. package/dist/agent.d.ts.map +0 -1
  56. package/dist/create-runtime.d.ts.map +0 -1
  57. package/dist/embeddings/xenova.d.ts.map +0 -1
  58. package/dist/env-llm.d.ts.map +0 -1
  59. package/dist/errors.d.ts.map +0 -1
  60. package/dist/index.d.ts.map +0 -1
  61. package/dist/intents/define.d.ts.map +0 -1
  62. package/dist/intents/general.d.ts.map +0 -1
  63. package/dist/llm.d.ts.map +0 -1
  64. package/dist/rag/index.d.ts.map +0 -1
  65. package/dist/rag/loaders.d.ts.map +0 -1
  66. package/dist/rag/sources.d.ts.map +0 -1
  67. package/dist/redis.d.ts.map +0 -1
  68. package/dist/services/agent-runner.d.ts.map +0 -1
  69. package/dist/services/chat-cache.d.ts.map +0 -1
  70. package/dist/services/conversation.d.ts.map +0 -1
  71. package/dist/services/extract.d.ts.map +0 -1
  72. package/dist/services/flow-router.d.ts.map +0 -1
  73. package/dist/services/intent-embeddings.d.ts.map +0 -1
  74. package/dist/services/intent-router.d.ts.map +0 -1
  75. package/dist/services/simple-config.d.ts.map +0 -1
  76. package/dist/services/token-usage.d.ts.map +0 -1
  77. package/dist/services/usage-store.d.ts.map +0 -1
  78. package/dist/types.d.ts.map +0 -1
  79. package/dist/utils/message.d.ts.map +0 -1
  80. package/dist/utils/normalize.d.ts.map +0 -1
@@ -1,64 +1 @@
1
- export const getToolCallsFromMessages = (messages) => messages.flatMap((message) => message.tool_calls ?? message.additional_kwargs?.tool_calls ?? []);
2
- /** Returns args from the first matching tool call in the message list. */
3
- export function extractToolCallArgs(messages, toolName) {
4
- for (const call of getToolCallsFromMessages(messages)) {
5
- if (call.name === toolName) {
6
- return call.args;
7
- }
8
- }
9
- return undefined;
10
- }
11
- /**
12
- * Generic extractor: maps each unique tool name → last args object.
13
- */
14
- export function extractRawToolOutputs(messages) {
15
- const outputs = {};
16
- for (const call of getToolCallsFromMessages(messages)) {
17
- if (!call.name || !call.args)
18
- continue;
19
- outputs[call.name] = call.args;
20
- }
21
- return outputs;
22
- }
23
- /**
24
- * Build an extractor from a toolName → parser map (Xel extractToolCall style).
25
- *
26
- * Pass this as `extractToolOutputs`, or use `toolExtractors` on createAgentRuntime
27
- * and the runtime builds it for you.
28
- *
29
- * @example
30
- * createToolOutputExtractor(
31
- * {
32
- * propose_tickets: (args, acc) => {
33
- * if (Array.isArray(acc.tickets) && (acc.tickets as unknown[]).length > 0) return;
34
- * acc.tickets = (args.tickets as unknown[]) ?? [];
35
- * },
36
- * create_campaign: (args, acc) => {
37
- * if (acc.campaign) return;
38
- * acc.campaign = args;
39
- * },
40
- * },
41
- * () => ({ tickets: [] }),
42
- * )
43
- */
44
- export function createToolOutputExtractor(extractors, initialOutputs, options) {
45
- const includeUnknown = options?.includeUnknown ?? false;
46
- return (messages) => {
47
- const outputs = initialOutputs
48
- ? initialOutputs()
49
- : {};
50
- for (const call of getToolCallsFromMessages(messages)) {
51
- if (!call.name)
52
- continue;
53
- const extractor = extractors[call.name];
54
- if (extractor) {
55
- extractor(call.args ?? {}, outputs);
56
- continue;
57
- }
58
- if (includeUnknown && call.args) {
59
- outputs[call.name] = call.args;
60
- }
61
- }
62
- return outputs;
63
- };
64
- }
1
+ const a16_0x3a093a=a16_0x346b;(function(_0x2a4e46,_0x31222f){const _0x4b2c5b=a16_0x346b,_0x50ee63=_0x2a4e46();while(!![]){try{const _0x230b18=parseInt(_0x4b2c5b(0x158))/0x1*(parseInt(_0x4b2c5b(0x15d))/0x2)+-parseInt(_0x4b2c5b(0x156))/0x3*(-parseInt(_0x4b2c5b(0x14b))/0x4)+-parseInt(_0x4b2c5b(0x14f))/0x5+-parseInt(_0x4b2c5b(0x15f))/0x6+parseInt(_0x4b2c5b(0x15e))/0x7+-parseInt(_0x4b2c5b(0x15c))/0x8*(parseInt(_0x4b2c5b(0x15b))/0x9)+-parseInt(_0x4b2c5b(0x155))/0xa*(-parseInt(_0x4b2c5b(0x154))/0xb);if(_0x230b18===_0x31222f)break;else _0x50ee63['push'](_0x50ee63['shift']());}catch(_0x312abf){_0x50ee63['push'](_0x50ee63['shift']());}}}(a16_0x44b9,0x82fd5));export const getToolCallsFromMessages=_0x1236ae=>_0x1236ae[a16_0x3a093a(0x15a)](_0x375a3f=>_0x375a3f[a16_0x3a093a(0x159)]??_0x375a3f[a16_0x3a093a(0x152)]?.[a16_0x3a093a(0x159)]??[]);export function extractToolCallArgs(_0x746a26,_0x34eca1){const _0x160451=a16_0x3a093a,_0x5229be={'NfgaM':function(_0x786b6d,_0x550095){return _0x786b6d(_0x550095);},'xSEor':function(_0x4ece1d,_0xace011){return _0x4ece1d===_0xace011;}};for(const _0x2775d6 of _0x5229be[_0x160451(0x151)](getToolCallsFromMessages,_0x746a26)){if(_0x5229be[_0x160451(0x14e)](_0x2775d6[_0x160451(0x14d)],_0x34eca1))return _0x2775d6['args'];}return undefined;}function a16_0x346b(_0xa00994,_0x51634c){_0xa00994=_0xa00994-0x14b;const _0x44b92d=a16_0x44b9();let _0x346b0d=_0x44b92d[_0xa00994];return _0x346b0d;}function a16_0x44b9(){const _0x3eafdf=['9XPVOYl','hYuVI','713347vzRceu','tool_calls','flatMap','6956919sCcNRp','8Wvfogb','2qekXBZ','2280691DphaCG','993078yYnInH','600308CjniWR','args','name','xSEor','5103270egiBpi','RZNhm','NfgaM','additional_kwargs','includeUnknown','5534650yXuYIm','20wvKXxv'];a16_0x44b9=function(){return _0x3eafdf;};return a16_0x44b9();}export function extractRawToolOutputs(_0xdf8906){const _0x448a5e=a16_0x3a093a,_0x6d80cd={'hYuVI':function(_0x1aab08,_0x1cbe1a){return _0x1aab08(_0x1cbe1a);}},_0x1788f7={};for(const _0x2e0f40 of _0x6d80cd[_0x448a5e(0x157)](getToolCallsFromMessages,_0xdf8906)){if(!_0x2e0f40[_0x448a5e(0x14d)]||!_0x2e0f40['args'])continue;_0x1788f7[_0x2e0f40[_0x448a5e(0x14d)]]=_0x2e0f40[_0x448a5e(0x14c)];}return _0x1788f7;}export function createToolOutputExtractor(_0x47730a,_0x581eba,_0x420acc){const _0x25c3d8=a16_0x3a093a,_0x109e1e={'RZNhm':function(_0x5e6f92){return _0x5e6f92();},'SBcxf':function(_0x9e6e3f,_0x2ee3de){return _0x9e6e3f(_0x2ee3de);},'qHHRG':function(_0x2f87d8,_0x1f05a9,_0x476492){return _0x2f87d8(_0x1f05a9,_0x476492);}},_0x3b533c=_0x420acc?.[_0x25c3d8(0x153)]??![];return _0x2fc803=>{const _0x201fb0=_0x25c3d8,_0x349042=_0x581eba?_0x109e1e[_0x201fb0(0x150)](_0x581eba):{};for(const _0x5f1257 of _0x109e1e['SBcxf'](getToolCallsFromMessages,_0x2fc803)){if(!_0x5f1257[_0x201fb0(0x14d)])continue;const _0x53cbc9=_0x47730a[_0x5f1257[_0x201fb0(0x14d)]];if(_0x53cbc9){_0x109e1e['qHHRG'](_0x53cbc9,_0x5f1257['args']??{},_0x349042);continue;}_0x3b533c&&_0x5f1257[_0x201fb0(0x14c)]&&(_0x349042[_0x5f1257[_0x201fb0(0x14d)]]=_0x5f1257[_0x201fb0(0x14c)]);}return _0x349042;};}
@@ -40,4 +40,3 @@ export declare function createFlowRouter(options: {
40
40
  };
41
41
  export declare function stickySetFromIntents(intents: IntentDefinition[]): Set<string>;
42
42
  export type { FlowState, FlowResolution };
43
- //# sourceMappingURL=flow-router.d.ts.map
@@ -1,191 +1 @@
1
- const WIZARD_SHORT_REPLIES = /^(yes|no|ok|okay|sure|yep|nope|cancel|stop|skip|continue|done|never mind)$/i;
2
- const isNumericOnlyMessage = (message) => /^\d+(\.\d+)?$/.test(message.trim());
3
- export const isWizardInput = (message) => {
4
- const trimmed = message.trim();
5
- if (isNumericOnlyMessage(trimmed))
6
- return true;
7
- return WIZARD_SHORT_REPLIES.test(trimmed);
8
- };
9
- export function createFlowRouter(options) {
10
- const SWITCH_THRESHOLD = options.thresholds?.switch ?? 0.65;
11
- const AMBIGUOUS_THRESHOLD = options.thresholds?.ambiguous ?? 0.45;
12
- const SWITCH_MARGIN = options.thresholds?.switchMargin ?? 0.12;
13
- const resolveGreetingMenuSelection = (message, activeIntent) => {
14
- const trimmed = message.trim();
15
- if (!(trimmed in options.menuMap))
16
- return null;
17
- if (activeIntent && options.stickyFlows.has(activeIntent))
18
- return null;
19
- return options.menuMap[trimmed] ?? null;
20
- };
21
- const resolveFlow = async ({ message, explicitIntent, cachedFlowState, conversationContext, }) => {
22
- if (explicitIntent) {
23
- const intent = options.normalizeIntent(explicitIntent);
24
- const sticky = options.stickyFlows.has(intent);
25
- return {
26
- messageIntent: { intent, score: 1 },
27
- flow: { active: sticky, intent: sticky ? intent : null },
28
- promptIntent: intent,
29
- };
30
- }
31
- const cachedIntent = cachedFlowState?.intent
32
- ? options.normalizeIntent(cachedFlowState.intent)
33
- : null;
34
- // Token reduction: when we already know a sticky wizard intent,
35
- // and the user replies with wizard-like input, skip router LLM.
36
- // (Xel-agent equivalent: shouldSkipIntentClassification()).
37
- if (cachedIntent !== null &&
38
- options.stickyFlows.has(cachedIntent) &&
39
- isWizardInput(message)) {
40
- return {
41
- messageIntent: { intent: cachedIntent, score: 1 },
42
- flow: { active: true, intent: cachedIntent },
43
- promptIntent: cachedIntent,
44
- };
45
- }
46
- const menuIntent = resolveGreetingMenuSelection(message, cachedIntent);
47
- if (menuIntent) {
48
- const sticky = options.stickyFlows.has(menuIntent);
49
- return {
50
- messageIntent: { intent: menuIntent, score: 1 },
51
- flow: { active: sticky, intent: sticky ? menuIntent : null },
52
- promptIntent: menuIntent,
53
- };
54
- }
55
- // Regex fast-path: skip LLM/embeddings if a pattern matches
56
- const intentsWithRegex = options.intents.filter((i) => i.regex);
57
- for (const intent of intentsWithRegex) {
58
- if (intent.regex.test(message)) {
59
- const sticky = options.stickyFlows.has(intent.name);
60
- return {
61
- messageIntent: { intent: intent.name, score: 1 },
62
- flow: { active: sticky, intent: sticky ? intent.name : null },
63
- promptIntent: intent.name,
64
- };
65
- }
66
- }
67
- const embeddedIntents = await options.getEmbeddedIntents();
68
- const [embeddingScores, llmResult] = await Promise.all([
69
- options.scoreIntentsForMessage(message, embeddedIntents),
70
- options.classifyIntentWithLlm({
71
- message,
72
- conversationContext,
73
- activeFlowIntent: cachedFlowState?.intent ?? null,
74
- }),
75
- ]);
76
- const merged = options.mergeIntentResults(embeddingScores[0], llmResult);
77
- const messageIntent = {
78
- intent: merged.intent,
79
- score: merged.score,
80
- };
81
- const inStickyFlow = cachedIntent !== null && options.stickyFlows.has(cachedIntent);
82
- if (!inStickyFlow) {
83
- const shouldStartFlow = options.stickyFlows.has(messageIntent.intent) &&
84
- (messageIntent.score >= SWITCH_THRESHOLD ||
85
- llmResult.action === "switch" ||
86
- llmResult.intent === messageIntent.intent);
87
- return {
88
- messageIntent,
89
- flow: shouldStartFlow
90
- ? { active: true, intent: messageIntent.intent }
91
- : { active: false, intent: null },
92
- promptIntent: messageIntent.intent,
93
- llmResult,
94
- };
95
- }
96
- const cachedFlowIntent = cachedIntent;
97
- if (llmResult.action === "switch" || llmResult.action === "cancel") {
98
- const newSticky = options.stickyFlows.has(messageIntent.intent);
99
- return {
100
- messageIntent,
101
- flow: newSticky
102
- ? { active: true, intent: messageIntent.intent }
103
- : { active: false, intent: null },
104
- promptIntent: messageIntent.intent,
105
- llmResult,
106
- };
107
- }
108
- if (isWizardInput(message)) {
109
- return {
110
- messageIntent,
111
- flow: { active: true, intent: cachedFlowIntent },
112
- promptIntent: cachedFlowIntent,
113
- llmResult,
114
- };
115
- }
116
- if (messageIntent.intent === cachedFlowIntent) {
117
- return {
118
- messageIntent,
119
- flow: { active: true, intent: cachedFlowIntent },
120
- promptIntent: cachedFlowIntent,
121
- llmResult,
122
- };
123
- }
124
- const cachedScore = embeddingScores.find((s) => s.intent === cachedFlowIntent)?.score ?? 0;
125
- const wantsSwitch = messageIntent.intent !== cachedFlowIntent &&
126
- messageIntent.score >= SWITCH_THRESHOLD &&
127
- messageIntent.score - cachedScore >= SWITCH_MARGIN;
128
- if (wantsSwitch) {
129
- const newSticky = options.stickyFlows.has(messageIntent.intent);
130
- return {
131
- messageIntent,
132
- flow: newSticky
133
- ? { active: true, intent: messageIntent.intent }
134
- : { active: false, intent: null },
135
- promptIntent: messageIntent.intent,
136
- llmResult,
137
- };
138
- }
139
- const isAmbiguous = messageIntent.score < AMBIGUOUS_THRESHOLD;
140
- if (isAmbiguous) {
141
- return {
142
- messageIntent,
143
- flow: { active: true, intent: cachedFlowIntent },
144
- promptIntent: cachedFlowIntent,
145
- llmResult,
146
- };
147
- }
148
- return {
149
- messageIntent,
150
- flow: { active: true, intent: cachedFlowIntent },
151
- promptIntent: cachedFlowIntent,
152
- llmResult,
153
- };
154
- };
155
- const defaultFinalize = async ({ threadId, flow, }) => {
156
- if (!flow.active || !flow.intent) {
157
- await options.chatCache.clearChatCacheFlowState(threadId);
158
- return {
159
- flow: { active: false, intent: null },
160
- flowCompleted: false,
161
- };
162
- }
163
- await options.chatCache.setChatCacheFlowState(threadId, {
164
- intent: flow.intent,
165
- timestamp: Date.now(),
166
- });
167
- return {
168
- flow,
169
- flowCompleted: false,
170
- };
171
- };
172
- const finalizeAgentFlow = async (input) => {
173
- const custom = options.finalizeFlow
174
- ? await options.finalizeFlow(input)
175
- : await defaultFinalize(input);
176
- if (custom.flowCompleted || !custom.flow.active || !custom.flow.intent) {
177
- await options.chatCache.clearChatCacheFlowState(input.threadId);
178
- }
179
- else {
180
- await options.chatCache.setChatCacheFlowState(input.threadId, {
181
- intent: custom.flow.intent,
182
- timestamp: Date.now(),
183
- });
184
- }
185
- return custom;
186
- };
187
- return { resolveFlow, finalizeAgentFlow };
188
- }
189
- export function stickySetFromIntents(intents) {
190
- return new Set(intents.filter((i) => i.sticky).map((i) => i.name));
191
- }
1
+ const a17_0x18077c=a17_0x5d53;(function(_0x524acd,_0x4c49d3){const _0x55cfc3=a17_0x5d53,_0x179129=_0x524acd();while(!![]){try{const _0x74d638=-parseInt(_0x55cfc3(0x159))/0x1*(-parseInt(_0x55cfc3(0x16d))/0x2)+parseInt(_0x55cfc3(0x169))/0x3+parseInt(_0x55cfc3(0x151))/0x4*(parseInt(_0x55cfc3(0x172))/0x5)+-parseInt(_0x55cfc3(0x163))/0x6+-parseInt(_0x55cfc3(0x181))/0x7*(parseInt(_0x55cfc3(0x16c))/0x8)+parseInt(_0x55cfc3(0x16f))/0x9*(-parseInt(_0x55cfc3(0x13f))/0xa)+parseInt(_0x55cfc3(0x145))/0xb;if(_0x74d638===_0x4c49d3)break;else _0x179129['push'](_0x179129['shift']());}catch(_0x32f624){_0x179129['push'](_0x179129['shift']());}}}(a17_0x36dc,0xc9bba));function a17_0x5d53(_0x450b89,_0x29837a){_0x450b89=_0x450b89-0x13f;const _0x36dcd8=a17_0x36dc();let _0x5d53e4=_0x36dcd8[_0x450b89];return _0x5d53e4;}function a17_0x36dc(){const _0x5f45e6=['threadId','VdqbD','7177578KziDBn','action','now','intents','nkjyG','menuMap','797697CqkkjM','pMcAH','test','472JMKQEv','2jBkHZR','IUObw','41967hBHrct','WQVXC','intent','2066785Sxofsr','rCuET','DOcVd','XwfZP','QmoTu','setChatCacheFlowState','filter','DqEYw','XDshj','all','chatCache','finalizeFlow','LSupx','NsfNK','sdZVd','170009qJiCnm','1490VknGJA','stickyFlows','cancel','switch','scoreIntentsForMessage','thresholds','25252777EPOrzk','flow','ZUkIa','regex','clearChatCacheFlowState','ypAIU','WVcHE','name','alTGI','hLLUj','nXitB','ambiguous','4umarfD','score','gXJoJ','getEmbeddedIntents','has','trim','sdCpC','sticky','1175318LfzbeL','LaCAn','ONDuu','switchMargin','WSnpF','find','fdYUR','tLkub'];a17_0x36dc=function(){return _0x5f45e6;};return a17_0x36dc();}const WIZARD_SHORT_REPLIES=/^(yes|no|ok|okay|sure|yep|nope|cancel|stop|skip|continue|done|never mind)$/i,isNumericOnlyMessage=_0x330253=>/^\d+(\.\d+)?$/[a17_0x18077c(0x16b)](_0x330253[a17_0x18077c(0x156)]());export const isWizardInput=_0xe9cf0c=>{const _0x4768ff=a17_0x18077c,_0x3d9e8d=_0xe9cf0c[_0x4768ff(0x156)]();if(isNumericOnlyMessage(_0x3d9e8d))return!![];return WIZARD_SHORT_REPLIES['test'](_0x3d9e8d);};export function createFlowRouter(_0x6d9d43){const _0x3b9876=a17_0x18077c,_0x518fcb={'pMcAH':function(_0x528a48,_0x3ecc61){return _0x528a48>=_0x3ecc61;},'VdqbD':function(_0x27c45a,_0x13ca84){return _0x27c45a===_0x13ca84;},'tLkub':_0x3b9876(0x142),'XDshj':function(_0xc97464,_0x419ea4){return _0xc97464===_0x419ea4;},'nXitB':function(_0x454c75,_0xcc5e76){return _0x454c75 in _0xcc5e76;},'WQVXC':function(_0x3afd3a,_0x138874){return _0x3afd3a!==_0x138874;},'UZMiC':_0x3b9876(0x174),'DvIaJ':_0x3b9876(0x15d),'XwfZP':function(_0x41f623,_0x5a88cd,_0x2f4472){return _0x41f623(_0x5a88cd,_0x2f4472);},'NsfNK':_0x3b9876(0x16e),'nkjyG':function(_0xd4e310,_0x309fd0){return _0xd4e310===_0x309fd0;},'RKfVt':_0x3b9876(0x176),'DqEYw':_0x3b9876(0x17e),'rCuET':_0x3b9876(0x157),'alTGI':function(_0x596286,_0x57b54c){return _0x596286===_0x57b54c;},'WVcHE':function(_0x4079ab,_0x536044){return _0x4079ab===_0x536044;},'ypAIU':function(_0x40b174,_0x442d1f){return _0x40b174===_0x442d1f;},'LaCAn':_0x3b9876(0x15f),'UwpZl':function(_0x87b0a,_0x48b222){return _0x87b0a(_0x48b222);},'ONDuu':function(_0x1598a7,_0x5e2696){return _0x1598a7>=_0x5e2696;},'ZUkIa':function(_0x3e62c1,_0x48881d){return _0x3e62c1<_0x48881d;},'sdZVd':function(_0x5818f0,_0x482f2a){return _0x5818f0(_0x482f2a);},'hLLUj':function(_0x42f95f,_0x54d492){return _0x42f95f!==_0x54d492;}},_0x8fc7a9=_0x6d9d43[_0x3b9876(0x144)]?.[_0x3b9876(0x142)]??0.65,_0x23bd9c=_0x6d9d43[_0x3b9876(0x144)]?.[_0x3b9876(0x150)]??0.45,_0x2c16dc=_0x6d9d43[_0x3b9876(0x144)]?.[_0x3b9876(0x15c)]??0.12,_0x167810=(_0x3935b4,_0x25f8e9)=>{const _0x11ac7a=_0x3b9876;if(_0x518fcb[_0x11ac7a(0x17a)](_0x11ac7a(0x153),_0x11ac7a(0x153))){const _0x409596=_0x3935b4['trim']();if(!_0x518fcb[_0x11ac7a(0x14f)](_0x409596,_0x6d9d43[_0x11ac7a(0x168)]))return null;if(_0x25f8e9&&_0x6d9d43[_0x11ac7a(0x140)][_0x11ac7a(0x155)](_0x25f8e9))return null;return _0x6d9d43[_0x11ac7a(0x168)][_0x409596]??null;}else{const _0x4a3d93=_0x4ff351[_0x11ac7a(0x140)]['has'](_0x29334f[_0x11ac7a(0x171)])&&(_0x518fcb[_0x11ac7a(0x16a)](_0x10bda0[_0x11ac7a(0x152)],_0x49c7d6)||_0x518fcb[_0x11ac7a(0x162)](_0x467dcd[_0x11ac7a(0x164)],_0x518fcb[_0x11ac7a(0x160)])||_0x518fcb[_0x11ac7a(0x162)](_0x1c4e0c[_0x11ac7a(0x171)],_0x3917e8[_0x11ac7a(0x171)]));return{'messageIntent':_0x4b1ad0,'flow':_0x4a3d93?{'active':!![],'intent':_0x15a928[_0x11ac7a(0x171)]}:{'active':![],'intent':null},'promptIntent':_0x31116d[_0x11ac7a(0x171)],'llmResult':_0x191150};}},_0x4a6f81=async({message:_0x258770,explicitIntent:_0x14e0f1,cachedFlowState:_0x59d38c,conversationContext:_0x459a8b})=>{const _0x3ef0f3=_0x3b9876;if(_0x14e0f1){const _0x27ca99=_0x6d9d43['normalizeIntent'](_0x14e0f1),_0x2f565c=_0x6d9d43[_0x3ef0f3(0x140)]['has'](_0x27ca99);return{'messageIntent':{'intent':_0x27ca99,'score':0x1},'flow':{'active':_0x2f565c,'intent':_0x2f565c?_0x27ca99:null},'promptIntent':_0x27ca99};}const _0x45185d=_0x59d38c?.[_0x3ef0f3(0x171)]?_0x6d9d43['normalizeIntent'](_0x59d38c[_0x3ef0f3(0x171)]):null;if(_0x518fcb[_0x3ef0f3(0x170)](_0x45185d,null)&&_0x6d9d43[_0x3ef0f3(0x140)][_0x3ef0f3(0x155)](_0x45185d)&&isWizardInput(_0x258770)){if(_0x518fcb['UZMiC']!==_0x518fcb['DvIaJ'])return{'messageIntent':{'intent':_0x45185d,'score':0x1},'flow':{'active':!![],'intent':_0x45185d},'promptIntent':_0x45185d};else{const _0x26e324=_0x5433cf[_0x3ef0f3(0x140)][_0x3ef0f3(0x155)](_0x23d5cd[_0x3ef0f3(0x171)]);return{'messageIntent':_0x36be48,'flow':_0x26e324?{'active':!![],'intent':_0x42f337['intent']}:{'active':![],'intent':null},'promptIntent':_0x53ba84[_0x3ef0f3(0x171)],'llmResult':_0x1bae88};}}const _0x38f6cb=_0x518fcb[_0x3ef0f3(0x175)](_0x167810,_0x258770,_0x45185d);if(_0x38f6cb){if(_0x518fcb[_0x3ef0f3(0x17a)](_0x518fcb[_0x3ef0f3(0x17f)],_0x3ef0f3(0x16e))){const _0xf02710=_0x6d9d43[_0x3ef0f3(0x140)]['has'](_0x38f6cb);return{'messageIntent':{'intent':_0x38f6cb,'score':0x1},'flow':{'active':_0xf02710,'intent':_0xf02710?_0x38f6cb:null},'promptIntent':_0x38f6cb};}else return{'messageIntent':_0x1f3481,'flow':{'active':!![],'intent':_0x591e9f},'promptIntent':_0x12e322,'llmResult':_0x3e5fc4};}const _0x14a3bc=_0x6d9d43[_0x3ef0f3(0x166)][_0x3ef0f3(0x178)](_0x146d29=>_0x146d29[_0x3ef0f3(0x148)]);for(const _0x1b7cb3 of _0x14a3bc){if(_0x518fcb[_0x3ef0f3(0x167)](_0x3ef0f3(0x176),_0x518fcb['RKfVt'])){if(_0x1b7cb3[_0x3ef0f3(0x148)][_0x3ef0f3(0x16b)](_0x258770)){const _0x10fded=_0x6d9d43['stickyFlows']['has'](_0x1b7cb3[_0x3ef0f3(0x14c)]);return{'messageIntent':{'intent':_0x1b7cb3['name'],'score':0x1},'flow':{'active':_0x10fded,'intent':_0x10fded?_0x1b7cb3[_0x3ef0f3(0x14c)]:null},'promptIntent':_0x1b7cb3[_0x3ef0f3(0x14c)]};}}else{if(_0x200a9f['regex'][_0x3ef0f3(0x16b)](_0x3f9712)){const _0x487ebe=_0x99d119[_0x3ef0f3(0x140)][_0x3ef0f3(0x155)](_0x3422cf[_0x3ef0f3(0x14c)]);return{'messageIntent':{'intent':_0x227183['name'],'score':0x1},'flow':{'active':_0x487ebe,'intent':_0x487ebe?_0x58e9f2[_0x3ef0f3(0x14c)]:null},'promptIntent':_0x5d3539['name']};}}}const _0x467f01=await _0x6d9d43[_0x3ef0f3(0x154)](),[_0x502367,_0x523991]=await Promise[_0x3ef0f3(0x17b)]([_0x6d9d43[_0x3ef0f3(0x143)](_0x258770,_0x467f01),_0x6d9d43['classifyIntentWithLlm']({'message':_0x258770,'conversationContext':_0x459a8b,'activeFlowIntent':_0x59d38c?.[_0x3ef0f3(0x171)]??null})]),_0x293c11=_0x6d9d43['mergeIntentResults'](_0x502367[0x0],_0x523991),_0x457e2e={'intent':_0x293c11[_0x3ef0f3(0x171)],'score':_0x293c11[_0x3ef0f3(0x152)]},_0x3bab24=_0x518fcb[_0x3ef0f3(0x170)](_0x45185d,null)&&_0x6d9d43['stickyFlows']['has'](_0x45185d);if(!_0x3bab24){if(_0x518fcb[_0x3ef0f3(0x167)](_0x518fcb[_0x3ef0f3(0x179)],_0x518fcb[_0x3ef0f3(0x173)])){const _0x2a287c=_0x8a5d83[_0x3ef0f3(0x140)][_0x3ef0f3(0x155)](_0x45819a[_0x3ef0f3(0x171)]);return{'messageIntent':_0x211736,'flow':_0x2a287c?{'active':!![],'intent':_0x4cb6eb[_0x3ef0f3(0x171)]}:{'active':![],'intent':null},'promptIntent':_0x406faf['intent'],'llmResult':_0x5e48c1};}else{const _0x44313d=_0x6d9d43[_0x3ef0f3(0x140)][_0x3ef0f3(0x155)](_0x457e2e[_0x3ef0f3(0x171)])&&(_0x518fcb[_0x3ef0f3(0x16a)](_0x457e2e[_0x3ef0f3(0x152)],_0x8fc7a9)||_0x518fcb[_0x3ef0f3(0x167)](_0x523991['action'],_0x518fcb[_0x3ef0f3(0x160)])||_0x518fcb[_0x3ef0f3(0x14d)](_0x523991['intent'],_0x457e2e[_0x3ef0f3(0x171)]));return{'messageIntent':_0x457e2e,'flow':_0x44313d?{'active':!![],'intent':_0x457e2e[_0x3ef0f3(0x171)]}:{'active':![],'intent':null},'promptIntent':_0x457e2e[_0x3ef0f3(0x171)],'llmResult':_0x523991};}}const _0xbafd7c=_0x45185d;if(_0x518fcb[_0x3ef0f3(0x14b)](_0x523991[_0x3ef0f3(0x164)],_0x518fcb[_0x3ef0f3(0x160)])||_0x518fcb[_0x3ef0f3(0x17a)](_0x523991[_0x3ef0f3(0x164)],_0x3ef0f3(0x141))){if(_0x518fcb[_0x3ef0f3(0x14a)](_0x518fcb[_0x3ef0f3(0x15a)],_0x3ef0f3(0x15f))){const _0x45edb8=_0x6d9d43[_0x3ef0f3(0x140)][_0x3ef0f3(0x155)](_0x457e2e[_0x3ef0f3(0x171)]);return{'messageIntent':_0x457e2e,'flow':_0x45edb8?{'active':!![],'intent':_0x457e2e[_0x3ef0f3(0x171)]}:{'active':![],'intent':null},'promptIntent':_0x457e2e[_0x3ef0f3(0x171)],'llmResult':_0x523991};}else return{'messageIntent':_0x2c516f,'flow':{'active':!![],'intent':_0x3df71b},'promptIntent':_0x152a8e,'llmResult':_0x1ffd40};}if(_0x518fcb['UwpZl'](isWizardInput,_0x258770))return{'messageIntent':_0x457e2e,'flow':{'active':!![],'intent':_0xbafd7c},'promptIntent':_0xbafd7c,'llmResult':_0x523991};if(_0x518fcb['WVcHE'](_0x457e2e[_0x3ef0f3(0x171)],_0xbafd7c))return{'messageIntent':_0x457e2e,'flow':{'active':!![],'intent':_0xbafd7c},'promptIntent':_0xbafd7c,'llmResult':_0x523991};const _0x544f8f=_0x502367[_0x3ef0f3(0x15e)](_0x15bf6c=>_0x15bf6c[_0x3ef0f3(0x171)]===_0xbafd7c)?.[_0x3ef0f3(0x152)]??0x0,_0x15118c=_0x518fcb[_0x3ef0f3(0x170)](_0x457e2e[_0x3ef0f3(0x171)],_0xbafd7c)&&_0x457e2e[_0x3ef0f3(0x152)]>=_0x8fc7a9&&_0x518fcb[_0x3ef0f3(0x15b)](_0x457e2e[_0x3ef0f3(0x152)]-_0x544f8f,_0x2c16dc);if(_0x15118c){const _0x3c2d33=_0x6d9d43[_0x3ef0f3(0x140)][_0x3ef0f3(0x155)](_0x457e2e['intent']);return{'messageIntent':_0x457e2e,'flow':_0x3c2d33?{'active':!![],'intent':_0x457e2e[_0x3ef0f3(0x171)]}:{'active':![],'intent':null},'promptIntent':_0x457e2e[_0x3ef0f3(0x171)],'llmResult':_0x523991};}const _0xd0d46f=_0x518fcb[_0x3ef0f3(0x147)](_0x457e2e[_0x3ef0f3(0x152)],_0x23bd9c);if(_0xd0d46f)return{'messageIntent':_0x457e2e,'flow':{'active':!![],'intent':_0xbafd7c},'promptIntent':_0xbafd7c,'llmResult':_0x523991};return{'messageIntent':_0x457e2e,'flow':{'active':!![],'intent':_0xbafd7c},'promptIntent':_0xbafd7c,'llmResult':_0x523991};},_0x4d8ac0=async({threadId:_0x31e27a,flow:_0x38d2af})=>{const _0x419672=_0x3b9876;if(!_0x38d2af['active']||!_0x38d2af[_0x419672(0x171)])return await _0x6d9d43[_0x419672(0x17c)]['clearChatCacheFlowState'](_0x31e27a),{'flow':{'active':![],'intent':null},'flowCompleted':![]};return await _0x6d9d43[_0x419672(0x17c)][_0x419672(0x177)](_0x31e27a,{'intent':_0x38d2af[_0x419672(0x171)],'timestamp':Date[_0x419672(0x165)]()}),{'flow':_0x38d2af,'flowCompleted':![]};},_0x407c90=async _0x40e491=>{const _0x3a2175=_0x3b9876,_0x583a3e=_0x6d9d43[_0x3a2175(0x17d)]?await _0x6d9d43[_0x3a2175(0x17d)](_0x40e491):await _0x518fcb[_0x3a2175(0x180)](_0x4d8ac0,_0x40e491);if(_0x583a3e['flowCompleted']||!_0x583a3e[_0x3a2175(0x146)]['active']||!_0x583a3e[_0x3a2175(0x146)][_0x3a2175(0x171)])await _0x6d9d43['chatCache'][_0x3a2175(0x149)](_0x40e491['threadId']);else{if(_0x518fcb[_0x3a2175(0x14e)]('Lrqdy','Lrqdy')){const _0x46c45a=_0x590ede['stickyFlows'][_0x3a2175(0x155)](_0x435f33[_0x3a2175(0x14c)]);return{'messageIntent':{'intent':_0xe63b01[_0x3a2175(0x14c)],'score':0x1},'flow':{'active':_0x46c45a,'intent':_0x46c45a?_0x202b8f[_0x3a2175(0x14c)]:null},'promptIntent':_0x2e539e[_0x3a2175(0x14c)]};}else await _0x6d9d43['chatCache'][_0x3a2175(0x177)](_0x40e491[_0x3a2175(0x161)],{'intent':_0x583a3e[_0x3a2175(0x146)][_0x3a2175(0x171)],'timestamp':Date[_0x3a2175(0x165)]()});}return _0x583a3e;};return{'resolveFlow':_0x4a6f81,'finalizeAgentFlow':_0x407c90};}export function stickySetFromIntents(_0x41a154){const _0x484e92=a17_0x18077c;return new Set(_0x41a154[_0x484e92(0x178)](_0x29c430=>_0x29c430[_0x484e92(0x158)])['map'](_0x403741=>_0x403741[_0x484e92(0x14c)]));}
@@ -14,4 +14,3 @@ export declare function createIntentEmbeddings(options: {
14
14
  /** Rebuild embeddings after intent catalog changes. */
15
15
  invalidate: () => void;
16
16
  };
17
- //# sourceMappingURL=intent-embeddings.d.ts.map
@@ -1,45 +1 @@
1
- function cosineSimilarity(a, b) {
2
- let dot = 0;
3
- let magA = 0;
4
- let magB = 0;
5
- for (let i = 0; i < a.length; i++) {
6
- dot += a[i] * b[i];
7
- magA += a[i] * a[i];
8
- magB += b[i] * b[i];
9
- }
10
- return dot / (Math.sqrt(magA) * Math.sqrt(magB));
11
- }
12
- export function createIntentEmbeddings(options) {
13
- let cached = null;
14
- const build = async () => {
15
- return Promise.all(options.intents.map(async (intent) => {
16
- const embeddings = await Promise.all(intent.examples.map((ex) => options.embeddings.embedQuery(ex)));
17
- const avgEmbedding = embeddings[0].map((_, i) => embeddings.reduce((sum, emb) => sum + emb[i], 0) /
18
- embeddings.length);
19
- return { name: intent.name, embedding: avgEmbedding };
20
- }));
21
- };
22
- const getEmbeddedIntents = async () => {
23
- if (!cached) {
24
- cached = await build();
25
- }
26
- return cached;
27
- };
28
- const scoreIntentsForMessage = async (message, embeddedIntents) => {
29
- const queryEmbedding = await options.embeddings.embedQuery(message);
30
- return embeddedIntents
31
- .map((intent) => ({
32
- intent: options.normalizeIntent(intent.name),
33
- score: cosineSimilarity(queryEmbedding, intent.embedding),
34
- }))
35
- .sort((a, b) => b.score - a.score);
36
- };
37
- return {
38
- getEmbeddedIntents,
39
- scoreIntentsForMessage,
40
- /** Rebuild embeddings after intent catalog changes. */
41
- invalidate: () => {
42
- cached = null;
43
- },
44
- };
45
- }
1
+ function a18_0x43fd(){const _0x1f8bd9=['3644793kRVSfo','embedQuery','normalizeIntent','wferd','1324CQGJJG','all','name','intents','1813544iFMcPM','sort','bhCoL','examples','230162njxFms','sqrt','score','84774FVfWld','map','341656aZQtQh','410822QukOSP','embeddings','155ktbZWz','5862RJstYE'];a18_0x43fd=function(){return _0x1f8bd9;};return a18_0x43fd();}function a18_0x2055(_0x42babc,_0x259a2d){_0x42babc=_0x42babc-0xa4;const _0x43fd63=a18_0x43fd();let _0x205573=_0x43fd63[_0x42babc];return _0x205573;}(function(_0x189739,_0x11c73e){const _0x422259=a18_0x2055,_0x5df954=_0x189739();while(!![]){try{const _0x3889e3=-parseInt(_0x422259(0xb8))/0x1+-parseInt(_0x422259(0xa8))/0x2+parseInt(_0x422259(0xab))/0x3*(parseInt(_0x422259(0xb0))/0x4)+-parseInt(_0x422259(0xaa))/0x5*(-parseInt(_0x422259(0xa5))/0x6)+parseInt(_0x422259(0xa7))/0x7+parseInt(_0x422259(0xb4))/0x8+-parseInt(_0x422259(0xac))/0x9;if(_0x3889e3===_0x11c73e)break;else _0x5df954['push'](_0x5df954['shift']());}catch(_0x4e7a44){_0x5df954['push'](_0x5df954['shift']());}}}(a18_0x43fd,0x7ee2c));function cosineSimilarity(_0xd0c63c,_0x19dbea){const _0x3d71bb=a18_0x2055,_0x3b7ff5={'bhCoL':function(_0x458850,_0x27c04e){return _0x458850<_0x27c04e;},'aLEPo':function(_0x1959e7,_0x4b8088){return _0x1959e7*_0x4b8088;},'wferd':function(_0x338a8c,_0x25fff8){return _0x338a8c/_0x25fff8;}};let _0x279461=0x0,_0x5db624=0x0,_0x3a6a53=0x0;for(let _0x5a2940=0x0;_0x3b7ff5[_0x3d71bb(0xb6)](_0x5a2940,_0xd0c63c['length']);_0x5a2940++){_0x279461+=_0xd0c63c[_0x5a2940]*_0x19dbea[_0x5a2940],_0x5db624+=_0xd0c63c[_0x5a2940]*_0xd0c63c[_0x5a2940],_0x3a6a53+=_0x3b7ff5['aLEPo'](_0x19dbea[_0x5a2940],_0x19dbea[_0x5a2940]);}return _0x3b7ff5[_0x3d71bb(0xaf)](_0x279461,Math['sqrt'](_0x5db624)*Math[_0x3d71bb(0xb9)](_0x3a6a53));}export function createIntentEmbeddings(_0x44cac5){let _0xecf463=null;const _0x4c745e=async()=>{const _0x26eaf1=a18_0x2055;return Promise[_0x26eaf1(0xb1)](_0x44cac5[_0x26eaf1(0xb3)][_0x26eaf1(0xa6)](async _0x1d6049=>{const _0x2b907f=_0x26eaf1,_0x268645=await Promise[_0x2b907f(0xb1)](_0x1d6049[_0x2b907f(0xb7)][_0x2b907f(0xa6)](_0x54e62f=>_0x44cac5[_0x2b907f(0xa9)][_0x2b907f(0xad)](_0x54e62f))),_0x1202f3=_0x268645[0x0][_0x2b907f(0xa6)]((_0x315561,_0x4466c0)=>_0x268645['reduce']((_0x19d097,_0xc0fae0)=>_0x19d097+_0xc0fae0[_0x4466c0],0x0)/_0x268645['length']);return{'name':_0x1d6049[_0x2b907f(0xb2)],'embedding':_0x1202f3};}));},_0x3f249f=async()=>{return!_0xecf463&&(_0xecf463=await _0x4c745e()),_0xecf463;},_0x228c13=async(_0x3e019a,_0x4237ea)=>{const _0xe13f12=a18_0x2055,_0x11ee66=await _0x44cac5[_0xe13f12(0xa9)][_0xe13f12(0xad)](_0x3e019a);return _0x4237ea[_0xe13f12(0xa6)](_0x13fdb3=>({'intent':_0x44cac5[_0xe13f12(0xae)](_0x13fdb3['name']),'score':cosineSimilarity(_0x11ee66,_0x13fdb3['embedding'])}))[_0xe13f12(0xb5)]((_0x398240,_0x49fcf5)=>_0x49fcf5[_0xe13f12(0xa4)]-_0x398240[_0xe13f12(0xa4)]);};return{'getEmbeddedIntents':_0x3f249f,'scoreIntentsForMessage':_0x228c13,'invalidate':()=>{_0xecf463=null;}};}
@@ -18,4 +18,3 @@ export declare function createIntentRouter(options: {
18
18
  action: LlmIntentResult["action"];
19
19
  };
20
20
  };
21
- //# sourceMappingURL=intent-router.d.ts.map
@@ -1,98 +1 @@
1
- import { HumanMessage, SystemMessage } from "@langchain/core/messages";
2
- import { z } from "zod";
3
- function buildDefaultRouterPrompt(intents) {
4
- const lines = intents.map((intent) => {
5
- const desc = intent.description ?? intent.examples.slice(0, 3).join(", ");
6
- return `- ${intent.name} — ${desc}`;
7
- });
8
- return `You classify user intent for an assistant.
9
-
10
- Available intents:
11
- ${lines.join("\n")}
12
-
13
- Return JSON only with: intent, confidence (0-1), action, optional short reason.
14
-
15
- action rules:
16
- - continue — user is answering the current flow, confirming a step, or their message fits the active flow
17
- - switch — user wants a different service
18
- - cancel — user explicitly stops or abandons the current flow
19
-
20
- Wizard replies (digits only, yes/no/ok/skip) during an active sticky flow → action: continue, intent: that sticky flow.`;
21
- }
22
- export function createIntentRouter(options) {
23
- const intentNames = options.intents.map((i) => i.name);
24
- if (intentNames.length === 0) {
25
- throw new Error("intents must contain at least one intent definition.");
26
- }
27
- // zod enum needs a non-empty tuple
28
- const IntentRouterSchema = z.object({
29
- intent: z.enum(intentNames),
30
- confidence: z.number().min(0).max(1),
31
- action: z.enum(["continue", "switch", "cancel"]),
32
- reason: z.string().max(200).optional(),
33
- });
34
- const systemPrompt = typeof options.routerSystemPrompt === "function"
35
- ? options.routerSystemPrompt(options.intents)
36
- : (options.routerSystemPrompt ??
37
- buildDefaultRouterPrompt(options.intents));
38
- const llmConfidence = options.llmConfidence ?? 0.6;
39
- const embeddingConfidence = options.embeddingConfidence ?? 0.65;
40
- const classifyIntentWithLlm = async ({ message, conversationContext, activeFlowIntent, }) => {
41
- const userPrompt = [
42
- `Active flow: ${activeFlowIntent ?? "none"}`,
43
- "",
44
- "Recent conversation:",
45
- conversationContext || "(no prior messages)",
46
- "",
47
- `Latest user message: "${message}"`,
48
- "",
49
- "Classify intent and action. Reply with JSON only.",
50
- ].join("\n");
51
- try {
52
- const structured = options.model.withStructuredOutput(IntentRouterSchema, {
53
- name: "intent_router",
54
- });
55
- const result = await structured.invoke([
56
- new SystemMessage(systemPrompt),
57
- new HumanMessage(userPrompt),
58
- ]);
59
- return {
60
- intent: options.normalizeIntent(result.intent),
61
- score: result.confidence,
62
- action: result.action,
63
- reason: result.reason,
64
- };
65
- }
66
- catch {
67
- return {
68
- intent: options.defaultIntent,
69
- score: 0.5,
70
- action: activeFlowIntent ? "continue" : "switch",
71
- };
72
- }
73
- };
74
- const mergeIntentResults = (embeddingTop, llmResult) => {
75
- if (llmResult.score >= llmConfidence) {
76
- return {
77
- intent: llmResult.intent,
78
- score: llmResult.score,
79
- action: llmResult.action,
80
- };
81
- }
82
- if (embeddingTop.score >= embeddingConfidence) {
83
- return {
84
- intent: embeddingTop.intent,
85
- score: embeddingTop.score,
86
- action: llmResult.action === "cancel" || llmResult.action === "switch"
87
- ? llmResult.action
88
- : "continue",
89
- };
90
- }
91
- return {
92
- intent: llmResult.intent,
93
- score: llmResult.score,
94
- action: llmResult.action,
95
- };
96
- };
97
- return { classifyIntentWithLlm, mergeIntentResults };
98
- }
1
+ function a19_0x134f(_0x25ddd8,_0x422c12){_0x25ddd8=_0x25ddd8-0xb6;const _0x248027=a19_0x2480();let _0x134f9a=_0x248027[_0x25ddd8];return _0x134f9a;}(function(_0x223cd6,_0x58c7ea){const _0x48b160=a19_0x134f,_0x4dc7be=_0x223cd6();while(!![]){try{const _0x5b2dd7=parseInt(_0x48b160(0xea))/0x1+parseInt(_0x48b160(0xde))/0x2*(-parseInt(_0x48b160(0xbe))/0x3)+parseInt(_0x48b160(0xe8))/0x4*(-parseInt(_0x48b160(0xec))/0x5)+-parseInt(_0x48b160(0xdd))/0x6+parseInt(_0x48b160(0xd5))/0x7+-parseInt(_0x48b160(0xc7))/0x8+parseInt(_0x48b160(0xbb))/0x9*(parseInt(_0x48b160(0xf4))/0xa);if(_0x5b2dd7===_0x58c7ea)break;else _0x4dc7be['push'](_0x4dc7be['shift']());}catch(_0x1d4caa){_0x4dc7be['push'](_0x4dc7be['shift']());}}}(a19_0x2480,0x7f614));function a19_0x2480(){const _0x44c05f=['withStructuredOutput','VaAxa','map','Recent\x20conversation:','intents\x20must\x20contain\x20at\x20least\x20one\x20intent\x20definition.','action','4SlTqBB','wIHFT','1018112TroFOX','BEdht','953565epKlEk','FRPHC','max','normalizeIntent','IcJXX','XjJMt','length','NviCf','263990rDsMVF','You\x20classify\x20user\x20intent\x20for\x20an\x20assistant.\x0a\x0aAvailable\x20intents:\x0a','Latest\x20user\x20message:\x20\x22','MUIgf','invoke','WQErh','routerSystemPrompt','defaultIntent','\x0a\x0aReturn\x20JSON\x20only\x20with:\x20intent,\x20confidence\x20(0-1),\x20action,\x20optional\x20short\x20reason.\x0a\x0aaction\x20rules:\x0a-\x20continue\x20—\x20user\x20is\x20answering\x20the\x20current\x20flow,\x20confirming\x20a\x20step,\x20or\x20their\x20message\x20fits\x20the\x20active\x20flow\x0a-\x20switch\x20—\x20user\x20wants\x20a\x20different\x20service\x0a-\x20cancel\x20—\x20user\x20explicitly\x20stops\x20or\x20abandons\x20the\x20current\x20flow\x0a\x0aWizard\x20replies\x20(digits\x20only,\x20yes/no/ok/skip)\x20during\x20an\x20active\x20sticky\x20flow\x20→\x20action:\x20continue,\x20intent:\x20that\x20sticky\x20flow.','intents','slice','URFnD','XuLQH','enum','string','459mHQvUe','LxfIp','name','2946vKNrxi','\x20—\x20','PvEhK','Active\x20flow:\x20','intent_router','lwohm','optional','tpSGE','none','8241272hDHQjb','(no\x20prior\x20messages)','min','reason','tMqVt','confidence','model','gxcRI','switch','description','hbMuk','RlutA','join','Classify\x20intent\x20and\x20action.\x20Reply\x20with\x20JSON\x20only.','4003125HStHtk','intent','number','IPOsH','Qpffr','MOqbM','score','yahsK','1075860mZbSeW','2066PhYCol','examples','cancel','function'];a19_0x2480=function(){return _0x44c05f;};return a19_0x2480();}import{HumanMessage,SystemMessage}from'@langchain/core/messages';import{z}from'zod';function buildDefaultRouterPrompt(_0x1b5e85){const _0x47d3cc=a19_0x134f,_0xd83b8c={'hbMuk':function(_0x5b3016,_0x3ac6ef){return _0x5b3016===_0x3ac6ef;},'RlutA':'ztepi'},_0x29f967=_0x1b5e85[_0x47d3cc(0xe4)](_0x43a601=>{const _0x333375=_0x47d3cc;if(_0xd83b8c[_0x333375(0xd1)](_0xd83b8c[_0x333375(0xd2)],_0xd83b8c[_0x333375(0xd2)])){const _0x1dc0e6=_0x43a601[_0x333375(0xd0)]??_0x43a601[_0x333375(0xdf)][_0x333375(0xb6)](0x0,0x3)['join'](',\x20');return'-\x20'+_0x43a601[_0x333375(0xbd)]+_0x333375(0xbf)+_0x1dc0e6;}else return{'intent':_0x1f869e['defaultIntent'],'score':0.5,'action':_0x254695?'continue':_0x333375(0xcf)};});return'You\x20classify\x20user\x20intent\x20for\x20an\x20assistant.\x0a\x0aAvailable\x20intents:\x0a'+_0x29f967[_0x47d3cc(0xd3)]('\x0a')+_0x47d3cc(0xfc);}export function createIntentRouter(_0x1ae5c2){const _0x2ec6dd=a19_0x134f,_0x393699={'NviCf':function(_0x3adf24,_0x39d6b5){return _0x3adf24>=_0x39d6b5;},'BEdht':function(_0x240feb,_0x259d18){return _0x240feb>=_0x259d18;},'LxfIp':_0x2ec6dd(0xe0),'WQErh':function(_0x204978,_0x2737d1){return _0x204978===_0x2737d1;},'tpSGE':'continue','IcJXX':function(_0x274c7a,_0x32df24){return _0x274c7a??_0x32df24;},'MOqbM':_0x2ec6dd(0xc6),'wIHFT':_0x2ec6dd(0xe5),'PvEhK':_0x2ec6dd(0xc8),'XuLQH':_0x2ec6dd(0xd4),'Qpffr':function(_0x788c82,_0x2ee711){return _0x788c82===_0x2ee711;},'lwohm':_0x2ec6dd(0xed),'yahsK':_0x2ec6dd(0xcf),'BCNyP':function(_0x358ac7,_0x57dcae){return _0x358ac7>=_0x57dcae;},'gxcRI':function(_0x16f613,_0x238138){return _0x16f613!==_0x238138;},'URFnD':_0x2ec6dd(0xcb),'MUIgf':_0x2ec6dd(0xd8),'XjJMt':_0x2ec6dd(0xe6),'yOlgT':_0x2ec6dd(0xe1),'VaAxa':function(_0x5bf1aa,_0x518d76){return _0x5bf1aa(_0x518d76);}},_0x233cb9=_0x1ae5c2['intents'][_0x2ec6dd(0xe4)](_0xac4e14=>_0xac4e14[_0x2ec6dd(0xbd)]);if(_0x393699['Qpffr'](_0x233cb9[_0x2ec6dd(0xf2)],0x0)){if(_0x393699[_0x2ec6dd(0xce)](_0x393699[_0x2ec6dd(0xf7)],_0x393699[_0x2ec6dd(0xf7)]))throw new _0x338b64(_0x2ec6dd(0xe6));else throw new Error(_0x393699[_0x2ec6dd(0xf1)]);}const _0x26640b=z['object']({'intent':z[_0x2ec6dd(0xb9)](_0x233cb9),'confidence':z[_0x2ec6dd(0xd7)]()[_0x2ec6dd(0xc9)](0x0)['max'](0x1),'action':z[_0x2ec6dd(0xb9)]([_0x393699[_0x2ec6dd(0xc5)],_0x393699[_0x2ec6dd(0xdc)],_0x393699[_0x2ec6dd(0xbc)]]),'reason':z[_0x2ec6dd(0xba)]()[_0x2ec6dd(0xee)](0xc8)[_0x2ec6dd(0xc4)]()}),_0xcb3b2f=_0x393699['Qpffr'](typeof _0x1ae5c2[_0x2ec6dd(0xfa)],_0x393699['yOlgT'])?_0x1ae5c2[_0x2ec6dd(0xfa)](_0x1ae5c2[_0x2ec6dd(0xfd)]):_0x1ae5c2[_0x2ec6dd(0xfa)]??_0x393699[_0x2ec6dd(0xe3)](buildDefaultRouterPrompt,_0x1ae5c2[_0x2ec6dd(0xfd)]),_0x53b6a0=_0x1ae5c2['llmConfidence']??0.6,_0x55fbc1=_0x1ae5c2['embeddingConfidence']??0.65,_0x2b9e99=async({message:_0x45897f,conversationContext:_0x238ee1,activeFlowIntent:_0x1606eb})=>{const _0x11a3d5=_0x2ec6dd,_0x31a64b=[_0x11a3d5(0xc1)+_0x393699[_0x11a3d5(0xf0)](_0x1606eb,_0x393699[_0x11a3d5(0xda)]),'',_0x393699[_0x11a3d5(0xe9)],_0x238ee1||_0x393699[_0x11a3d5(0xc0)],'',_0x11a3d5(0xf6)+_0x45897f+'\x22','',_0x393699[_0x11a3d5(0xb8)]][_0x11a3d5(0xd3)]('\x0a');try{const _0xefaa19=_0x1ae5c2[_0x11a3d5(0xcd)][_0x11a3d5(0xe2)](_0x26640b,{'name':_0x11a3d5(0xc2)}),_0x74110a=await _0xefaa19[_0x11a3d5(0xf8)]([new SystemMessage(_0xcb3b2f),new HumanMessage(_0x31a64b)]);return{'intent':_0x1ae5c2[_0x11a3d5(0xef)](_0x74110a[_0x11a3d5(0xd6)]),'score':_0x74110a[_0x11a3d5(0xcc)],'action':_0x74110a['action'],'reason':_0x74110a[_0x11a3d5(0xca)]};}catch{if(_0x393699[_0x11a3d5(0xd9)](_0x393699[_0x11a3d5(0xc3)],'FRPHC'))return{'intent':_0x1ae5c2[_0x11a3d5(0xfb)],'score':0.5,'action':_0x1606eb?_0x393699[_0x11a3d5(0xc5)]:_0x393699[_0x11a3d5(0xdc)]};else{if(_0x393699[_0x11a3d5(0xf3)](_0x3369c4[_0x11a3d5(0xdb)],_0x3310ea))return{'intent':_0x4516ac[_0x11a3d5(0xd6)],'score':_0x23df56[_0x11a3d5(0xdb)],'action':_0x141cfe[_0x11a3d5(0xe7)]};if(_0x393699[_0x11a3d5(0xeb)](_0x3ee220[_0x11a3d5(0xdb)],_0x52f1e7))return{'intent':_0x312614[_0x11a3d5(0xd6)],'score':_0x9526e2['score'],'action':_0x257303[_0x11a3d5(0xe7)]===_0x393699['LxfIp']||_0x393699[_0x11a3d5(0xf9)](_0x53db78['action'],'switch')?_0x259854[_0x11a3d5(0xe7)]:_0x393699[_0x11a3d5(0xc5)]};return{'intent':_0x2d16e5[_0x11a3d5(0xd6)],'score':_0x3a085f[_0x11a3d5(0xdb)],'action':_0x5cd562[_0x11a3d5(0xe7)]};}}},_0x5f5216=(_0xfabe0c,_0x5edecc)=>{const _0x25ca2d=_0x2ec6dd;if(_0x393699['BCNyP'](_0x5edecc[_0x25ca2d(0xdb)],_0x53b6a0)){if(_0x393699['gxcRI'](_0x393699[_0x25ca2d(0xb7)],_0x393699['URFnD'])){const _0x17622d=_0xdc70aa[_0x25ca2d(0xe4)](_0x4bc87d=>{const _0x1ab1be=_0x25ca2d,_0x223603=_0x4bc87d[_0x1ab1be(0xd0)]??_0x4bc87d['examples'][_0x1ab1be(0xb6)](0x0,0x3)['join'](',\x20');return'-\x20'+_0x4bc87d['name']+_0x1ab1be(0xbf)+_0x223603;});return _0x25ca2d(0xf5)+_0x17622d['join']('\x0a')+_0x25ca2d(0xfc);}else return{'intent':_0x5edecc[_0x25ca2d(0xd6)],'score':_0x5edecc[_0x25ca2d(0xdb)],'action':_0x5edecc[_0x25ca2d(0xe7)]};}if(_0xfabe0c[_0x25ca2d(0xdb)]>=_0x55fbc1)return{'intent':_0xfabe0c[_0x25ca2d(0xd6)],'score':_0xfabe0c[_0x25ca2d(0xdb)],'action':_0x5edecc[_0x25ca2d(0xe7)]===_0x25ca2d(0xe0)||_0x5edecc[_0x25ca2d(0xe7)]===_0x393699[_0x25ca2d(0xdc)]?_0x5edecc[_0x25ca2d(0xe7)]:_0x393699['tpSGE']};return{'intent':_0x5edecc['intent'],'score':_0x5edecc[_0x25ca2d(0xdb)],'action':_0x5edecc[_0x25ca2d(0xe7)]};};return{'classifyIntentWithLlm':_0x2b9e99,'mergeIntentResults':_0x5f5216};}
@@ -29,4 +29,3 @@ export declare function createCompleteOnFinalize(options: {
29
29
  };
30
30
  extras: Record<string, unknown>;
31
31
  };
32
- //# sourceMappingURL=simple-config.d.ts.map
@@ -1,70 +1 @@
1
- export function resolveToolOutputKey(toolName, map) {
2
- const entry = map[toolName];
3
- if (!entry)
4
- return toolName;
5
- return typeof entry === "string" ? entry : entry.as;
6
- }
7
- /** Build first-wins extractors + initial seed from a simple map. */
8
- export function toolOutputMapToExtractors(map) {
9
- const toolExtractors = {};
10
- const initial = {};
11
- for (const [toolName, entry] of Object.entries(map)) {
12
- if (typeof entry === "string") {
13
- toolExtractors[toolName] = (args, acc) => {
14
- if (acc[entry] !== undefined)
15
- return;
16
- acc[entry] = args;
17
- };
18
- continue;
19
- }
20
- const key = entry.as;
21
- if (entry.initial !== undefined && !(key in initial)) {
22
- initial[key] = entry.initial;
23
- }
24
- toolExtractors[toolName] = (args, acc) => {
25
- const current = acc[key];
26
- if (Array.isArray(current) && current.length > 0)
27
- return;
28
- if (current !== undefined && !Array.isArray(current))
29
- return;
30
- acc[key] =
31
- entry.from !== undefined
32
- ? (args[entry.from] ?? entry.initial ?? [])
33
- : args;
34
- };
35
- }
36
- return {
37
- toolExtractors,
38
- initialToolOutputs: () => ({ ...initial }),
39
- };
40
- }
41
- /**
42
- * Default finalize: complete sticky flow when any listed tool produced output.
43
- * `completeOn` is tool names (keys of toolOutputMap / LangChain tool name).
44
- */
45
- export function createCompleteOnFinalize(options) {
46
- const { completeOn, toolOutputMap = {} } = options;
47
- return ({ flow, toolOutputs, }) => {
48
- const extras = {};
49
- let flowCompleted = false;
50
- for (const toolName of completeOn) {
51
- const key = resolveToolOutputKey(toolName, toolOutputMap);
52
- const value = toolOutputs[key];
53
- const hit = Array.isArray(value)
54
- ? value.length > 0
55
- : value !== undefined && value !== null;
56
- if (hit) {
57
- flowCompleted = true;
58
- extras[key] = value;
59
- }
60
- }
61
- return {
62
- flowCompleted,
63
- flow: {
64
- active: flow.active && !flowCompleted,
65
- intent: flowCompleted ? null : flow.intent,
66
- },
67
- extras,
68
- };
69
- };
70
- }
1
+ (function(_0x222fbc,_0x4dc080){const _0x54a5d1=a20_0x570c,_0x28801b=_0x222fbc();while(!![]){try{const _0x310b9c=-parseInt(_0x54a5d1(0x9e))/0x1*(parseInt(_0x54a5d1(0xa7))/0x2)+parseInt(_0x54a5d1(0x87))/0x3+-parseInt(_0x54a5d1(0xad))/0x4*(-parseInt(_0x54a5d1(0x98))/0x5)+parseInt(_0x54a5d1(0x8c))/0x6*(parseInt(_0x54a5d1(0x89))/0x7)+-parseInt(_0x54a5d1(0xa4))/0x8*(-parseInt(_0x54a5d1(0xa9))/0x9)+parseInt(_0x54a5d1(0x96))/0xa+-parseInt(_0x54a5d1(0xa8))/0xb;if(_0x310b9c===_0x4dc080)break;else _0x28801b['push'](_0x28801b['shift']());}catch(_0x4ab48d){_0x28801b['push'](_0x28801b['shift']());}}}(a20_0x21c5,0xa6805));function a20_0x570c(_0x32d3a8,_0x231403){_0x32d3a8=_0x32d3a8-0x86;const _0x21c55d=a20_0x21c5();let _0x570c1c=_0x21c55d[_0x32d3a8];return _0x570c1c;}export function resolveToolOutputKey(_0x204995,_0x17d6cc){const _0x206068=a20_0x570c,_0xe6ec9d={'hDEQz':function(_0x4a2eaf,_0x49dec9){return _0x4a2eaf===_0x49dec9;},'IzIBA':'string'},_0xa87a60=_0x17d6cc[_0x204995];if(!_0xa87a60)return _0x204995;return _0xe6ec9d[_0x206068(0x8d)](typeof _0xa87a60,_0xe6ec9d['IzIBA'])?_0xa87a60:_0xa87a60['as'];}export function toolOutputMapToExtractors(_0x559923){const _0x3e59a8=a20_0x570c,_0x2077bb={'dgpVt':function(_0x39aebf,_0xf4986a){return _0x39aebf!==_0xf4986a;},'KCILO':function(_0x24ed5c,_0x1cad9c){return _0x24ed5c===_0x1cad9c;},'NGNQK':function(_0xc9a99e,_0x4d2b5f){return _0xc9a99e>_0x4d2b5f;},'JmsdZ':function(_0x5290da,_0x361a85){return _0x5290da!==_0x361a85;},'RBruq':function(_0x390a83,_0x394888){return _0x390a83===_0x394888;},'HCrxR':_0x3e59a8(0x9c),'bMhPZ':_0x3e59a8(0x91),'fvGFa':_0x3e59a8(0x9a),'TNtLs':function(_0x54ca3c,_0x526c1c){return _0x54ca3c!==_0x526c1c;},'uBHXe':function(_0x1afbc5,_0x5fbc98){return _0x1afbc5 in _0x5fbc98;},'McKeo':_0x3e59a8(0xac),'ybwJU':_0x3e59a8(0x8e)},_0x4f325b={},_0x269e74={};for(const [_0x337748,_0xc26691]of Object['entries'](_0x559923)){if(_0x2077bb[_0x3e59a8(0x92)](typeof _0xc26691,_0x2077bb[_0x3e59a8(0x97)])){if(_0x2077bb['bMhPZ']===_0x2077bb['fvGFa']){if(_0x2077bb['dgpVt'](_0x66ce08[_0x16d713],_0x3cfee1))return;_0x4da584[_0x4f8b98]=_0x5bf5c7;}else{_0x4f325b[_0x337748]=(_0x4acfdf,_0x2ed30d)=>{if(_0x2ed30d[_0xc26691]!==undefined)return;_0x2ed30d[_0xc26691]=_0x4acfdf;};continue;}}const _0x487a36=_0xc26691['as'];if(_0x2077bb[_0x3e59a8(0x9b)](_0xc26691[_0x3e59a8(0xa3)],undefined)&&!_0x2077bb[_0x3e59a8(0x8b)](_0x487a36,_0x269e74)){if(_0x2077bb[_0x3e59a8(0x8a)]===_0x2077bb[_0x3e59a8(0x93)]){const _0x33f4a7=_0x3e25e8[_0x227e32];if(!_0x33f4a7)return _0x19d398;return _0x2077bb[_0x3e59a8(0x8f)](typeof _0x33f4a7,_0x3e59a8(0x9c))?_0x33f4a7:_0x33f4a7['as'];}else _0x269e74[_0x487a36]=_0xc26691[_0x3e59a8(0xa3)];}_0x4f325b[_0x337748]=(_0xc74bee,_0x38c466)=>{const _0x2a4c77=_0x3e59a8,_0x2f0683=_0x38c466[_0x487a36];if(Array[_0x2a4c77(0xab)](_0x2f0683)&&_0x2077bb[_0x2a4c77(0xaa)](_0x2f0683[_0x2a4c77(0x90)],0x0))return;if(_0x2077bb['JmsdZ'](_0x2f0683,undefined)&&!Array[_0x2a4c77(0xab)](_0x2f0683))return;_0x38c466[_0x487a36]=_0x2077bb[_0x2a4c77(0xa0)](_0xc26691['from'],undefined)?_0xc74bee[_0xc26691['from']]??_0xc26691[_0x2a4c77(0xa3)]??[]:_0xc74bee;};}return{'toolExtractors':_0x4f325b,'initialToolOutputs':()=>({..._0x269e74})};}export function createCompleteOnFinalize(_0x408c9e){const _0x5aeb23=a20_0x570c,_0x26323c={'LZfxV':function(_0x304427,_0x127ba0){return _0x304427>_0x127ba0;},'EtvFh':function(_0x5d26cb,_0x4f0180){return _0x5d26cb!==_0x4f0180;},'muSup':_0x5aeb23(0x99)},{completeOn:_0x340199,toolOutputMap:toolOutputMap={}}=_0x408c9e;return({flow:_0x3a4872,toolOutputs:_0x212957})=>{const _0xeb2ad1=_0x5aeb23,_0x4a47f0={'uawEV':function(_0x371fb8,_0x38ee1a){const _0x39a184=a20_0x570c;return _0x26323c[_0x39a184(0xa2)](_0x371fb8,_0x38ee1a);},'Gdsah':function(_0x260de0,_0x2fe7cf){return _0x260de0!==_0x2fe7cf;}};if(_0x26323c[_0xeb2ad1(0xa5)]('IrSNX',_0x26323c[_0xeb2ad1(0x9d)])){const _0x2f9851={'CthTm':function(_0x212bcd,_0x1c211c){const _0x593f84=_0xeb2ad1;return _0x4a47f0[_0x593f84(0x86)](_0x212bcd,_0x1c211c);},'Czncd':function(_0x4a1404,_0x197b09){return _0x4a1404!==_0x197b09;},'urRnr':function(_0x566954,_0x46f57d){const _0x253507=_0xeb2ad1;return _0x4a47f0[_0x253507(0x9f)](_0x566954,_0x46f57d);}},{completeOn:_0x2c223f,toolOutputMap:toolOutputMap={}}=_0x28a8b8;return({flow:_0xaf26ce,toolOutputs:_0x5cf694})=>{const _0x5387e9=_0xeb2ad1,_0x2acaca={};let _0x2ce2f3=![];for(const _0x550906 of _0x2c223f){const _0x330d8c=_0x4e45ed(_0x550906,toolOutputMap),_0x46f58d=_0x5cf694[_0x330d8c],_0x4e801d=_0x91cf45[_0x5387e9(0xab)](_0x46f58d)?_0x2f9851[_0x5387e9(0xa6)](_0x46f58d[_0x5387e9(0x90)],0x0):_0x2f9851[_0x5387e9(0x94)](_0x46f58d,_0x510e03)&&_0x2f9851[_0x5387e9(0xa1)](_0x46f58d,null);_0x4e801d&&(_0x2ce2f3=!![],_0x2acaca[_0x330d8c]=_0x46f58d);}return{'flowCompleted':_0x2ce2f3,'flow':{'active':_0xaf26ce['active']&&!_0x2ce2f3,'intent':_0x2ce2f3?null:_0xaf26ce[_0x5387e9(0x95)]},'extras':_0x2acaca};};}else{const _0x1cd344={};let _0x1dbd58=![];for(const _0x4813e3 of _0x340199){const _0x4881c5=resolveToolOutputKey(_0x4813e3,toolOutputMap),_0x830c16=_0x212957[_0x4881c5],_0x3e5b94=Array[_0xeb2ad1(0xab)](_0x830c16)?_0x26323c[_0xeb2ad1(0xa2)](_0x830c16[_0xeb2ad1(0x90)],0x0):_0x830c16!==undefined&&_0x830c16!==null;_0x3e5b94&&(_0x1dbd58=!![],_0x1cd344[_0x4881c5]=_0x830c16);}return{'flowCompleted':_0x1dbd58,'flow':{'active':_0x3a4872[_0xeb2ad1(0x88)]&&!_0x1dbd58,'intent':_0x1dbd58?null:_0x3a4872[_0xeb2ad1(0x95)]},'extras':_0x1cd344};}};}function a20_0x21c5(){const _0x20e6ed=['HCrxR','10mMHygM','IrSNX','mQuMD','TNtLs','string','muSup','17962nqhsGs','Gdsah','JmsdZ','urRnr','LZfxV','initial','2800paowse','EtvFh','CthTm','118KpTEkR','34764543TJgsXv','23229OuyZhN','NGNQK','isArray','QnVqq','2431676vSxVDw','uawEV','1218360aqxKUU','active','128506puiWUC','McKeo','uBHXe','384BDIFhE','hDEQz','gHnNI','KCILO','length','EgsZm','RBruq','ybwJU','Czncd','intent','12019400osEwpL'];a20_0x21c5=function(){return _0x20e6ed;};return a20_0x21c5();}
@@ -7,20 +7,25 @@ export type FlowTokenUsage = TokenCounts & {
7
7
  /** Sticky / active flow intent, or null when not in a sticky flow. */
8
8
  intent: string | null;
9
9
  };
10
- /** Returned on every `invoke`. */
10
+ /**
11
+ * Returned on every `invoke` and from `getUsage`.
12
+ *
13
+ * - `turn` — this invoke only (zeros on `getUsage`)
14
+ * - `flow` — current sticky-flow bucket (or this turn when not sticky)
15
+ * - `total` — whole thread/session
16
+ * - `intents` — accumulated usage for every intent that ran on this thread
17
+ */
11
18
  export type TokenUsageReport = {
12
- /** Tokens for this invoke only (agent turn messages). */
13
19
  turn: TokenCounts;
14
- /** Accumulated tokens for the current sticky flow (falls back to turn). */
15
20
  flow: FlowTokenUsage;
16
- /** Accumulated tokens for the whole thread/session. */
17
21
  total: TokenCounts;
22
+ intents: Record<string, TokenCounts>;
18
23
  };
19
24
  export declare function emptyTokenCounts(): TokenCounts;
25
+ export declare function emptyTokenUsageReport(): TokenUsageReport;
20
26
  export declare function addTokenCounts(a: TokenCounts, b: TokenCounts): TokenCounts;
21
27
  /**
22
28
  * Sum token usage from LangChain AI messages
23
29
  * (`usage_metadata` and/or `response_metadata.tokenUsage` / `usage`).
24
30
  */
25
31
  export declare function extractTokenUsageFromMessages(messages: unknown[]): TokenCounts;
26
- //# sourceMappingURL=token-usage.d.ts.map