wingbot 3.74.8 → 3.75.9-alpha.1
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/index.js +6 -1
- package/jsconfig.json +2 -1
- package/package.json +1 -1
- package/src/BuildRouter.js +43 -7
- package/src/GlobalIntents.js +198 -0
- package/src/LLM.js +19 -3
- package/src/LLMDispatcher.js +508 -0
- package/src/LLMMockProvider.js +44 -1
- package/src/LLMRouter.js +325 -0
- package/src/LLMSession.js +85 -14
- package/src/Processor.js +18 -14
- package/src/ReducerWrapper.js +24 -0
- package/src/Request.js +88 -231
- package/src/Responder.js +28 -8
- package/src/Router.js +21 -26
- package/src/Tester.js +43 -2
- package/src/prompt.js +138 -0
- package/src/resolvers/bounce.js +4 -2
- package/src/resolvers/expected.js +4 -3
- package/src/tools/routeToEvents.js +1 -0
- package/src/wingbot/CustomEntityDetectionModel.js +1 -1
- package/.claude/settings.local.json +0 -8
package/index.js
CHANGED
|
@@ -69,6 +69,8 @@ const LLM = require('./src/LLM');
|
|
|
69
69
|
const LLMSession = require('./src/LLMSession');
|
|
70
70
|
const LLMTool = require('./src/LLMTool');
|
|
71
71
|
const LLMType = require('./src/LLMType');
|
|
72
|
+
const LLMRouter = require('./src/LLMRouter');
|
|
73
|
+
const prompt = require('./src/prompt');
|
|
72
74
|
|
|
73
75
|
module.exports = {
|
|
74
76
|
|
|
@@ -162,5 +164,8 @@ module.exports = {
|
|
|
162
164
|
LLM,
|
|
163
165
|
LLMSession,
|
|
164
166
|
LLMTool,
|
|
165
|
-
LLMType
|
|
167
|
+
LLMType,
|
|
168
|
+
|
|
169
|
+
LLMRouter,
|
|
170
|
+
prompt
|
|
166
171
|
};
|
package/jsconfig.json
CHANGED
package/package.json
CHANGED
package/src/BuildRouter.js
CHANGED
|
@@ -21,12 +21,16 @@ const { shouldExecuteResolver } = require('./resolvers/resolverTags');
|
|
|
21
21
|
const MESSAGE_RESOLVER_NAME = 'botbuild.message';
|
|
22
22
|
const PLUGIN_RESOLVER_NAME = 'botbuild.customCode';
|
|
23
23
|
|
|
24
|
+
/** @typedef {import('./resolvers/bounce').BounceAllow} BounceAllow */
|
|
25
|
+
/** @typedef {import('./resolvers/bounce').BounceReturn} BounceReturn */
|
|
26
|
+
|
|
24
27
|
/** @typedef {import('./Router').BaseConfiguration} BaseConfiguration */
|
|
25
28
|
/**
|
|
26
29
|
* @typedef {object} BuildInfo
|
|
27
30
|
* @prop {boolean} [expectedToAddResolver]
|
|
28
31
|
* @prop {boolean} [attachedRouter]
|
|
29
32
|
* @prop {boolean} [notLastMessage]
|
|
33
|
+
* @prop {BounceAllow} [bounceAllowedTo]
|
|
30
34
|
*/
|
|
31
35
|
|
|
32
36
|
/**
|
|
@@ -46,9 +50,6 @@ const PLUGIN_RESOLVER_NAME = 'botbuild.customCode';
|
|
|
46
50
|
* @prop {string} [tag]
|
|
47
51
|
*/
|
|
48
52
|
|
|
49
|
-
/** @typedef {import('./resolvers/bounce').BounceAllow} BounceAllow */
|
|
50
|
-
/** @typedef {import('./resolvers/bounce').BounceReturn} BounceReturn */
|
|
51
|
-
|
|
52
53
|
/**
|
|
53
54
|
* @typedef {object} Route
|
|
54
55
|
* @prop {number} id
|
|
@@ -574,7 +575,10 @@ class BuildRouter extends Router {
|
|
|
574
575
|
if (this._prebuiltGlobalIntents !== null) {
|
|
575
576
|
this.globalIntents.clear();
|
|
576
577
|
this._prebuiltGlobalIntents.forEach(([k, v]) => this.globalIntents.set(k, v));
|
|
578
|
+
} else {
|
|
579
|
+
this.globalIntents.clear();
|
|
577
580
|
}
|
|
581
|
+
super.resetRouter();
|
|
578
582
|
}
|
|
579
583
|
|
|
580
584
|
/**
|
|
@@ -598,6 +602,7 @@ class BuildRouter extends Router {
|
|
|
598
602
|
this.globalIntents.clear();
|
|
599
603
|
this._prebuiltGlobalIntents.forEach(([k, v]) => this.globalIntents.set(k, v));
|
|
600
604
|
}
|
|
605
|
+
super.resetRouter();
|
|
601
606
|
|
|
602
607
|
if (this._prebuiltRoutesCount === null) {
|
|
603
608
|
this._prebuiltRoutesCount = this._routes.length;
|
|
@@ -816,9 +821,10 @@ class BuildRouter extends Router {
|
|
|
816
821
|
* @param {TransformedRoute} route
|
|
817
822
|
* @param {boolean} nextRouteIsSameResponder
|
|
818
823
|
* @param {string} includedBlockId
|
|
824
|
+
* @param {boolean} omitBounce
|
|
819
825
|
* @returns {Middleware<S,C>[]}
|
|
820
826
|
*/
|
|
821
|
-
_buildRouteHead (route, nextRouteIsSameResponder, includedBlockId) {
|
|
827
|
+
_buildRouteHead (route, nextRouteIsSameResponder, includedBlockId, omitBounce) {
|
|
822
828
|
const resolvers = [];
|
|
823
829
|
|
|
824
830
|
if (!route.isFallback) {
|
|
@@ -850,7 +856,9 @@ class BuildRouter extends Router {
|
|
|
850
856
|
|
|
851
857
|
if (route.isResponder) {
|
|
852
858
|
const referredRoutePath = this._linksMap.get(route.respondsToRouteId);
|
|
853
|
-
const bounceResolver =
|
|
859
|
+
const bounceResolver = omitBounce
|
|
860
|
+
? null
|
|
861
|
+
: bounce(route, nextRouteIsSameResponder, referredRoutePath);
|
|
854
862
|
if (bounceResolver) {
|
|
855
863
|
resolvers.push(bounceResolver);
|
|
856
864
|
}
|
|
@@ -885,22 +893,49 @@ class BuildRouter extends Router {
|
|
|
885
893
|
return;
|
|
886
894
|
}
|
|
887
895
|
|
|
896
|
+
const prevRoute = i > 0
|
|
897
|
+
? routes[i - 1]
|
|
898
|
+
: null;
|
|
888
899
|
const nextRoute = routes.length > (i + 1)
|
|
889
900
|
? routes[i + 1]
|
|
890
901
|
: null;
|
|
902
|
+
const nextNext = routes.length > (i + 2)
|
|
903
|
+
? routes[i + 2]
|
|
904
|
+
: null;
|
|
891
905
|
let nextRouteIsSameResponder = false;
|
|
892
906
|
|
|
893
907
|
if (nextRoute && route.isResponder && nextRoute.isResponder) {
|
|
894
908
|
nextRouteIsSameResponder = nextRoute.respondsToRouteId === route.respondsToRouteId;
|
|
895
909
|
}
|
|
896
910
|
|
|
911
|
+
const bounceWithExpectedSupportted = (r, prev, nxt) => r
|
|
912
|
+
&& prev
|
|
913
|
+
&& r.isResponder
|
|
914
|
+
&& r.respondsToRouteId === prev.id
|
|
915
|
+
&& r.bounceAllowedTo !== 'faq'
|
|
916
|
+
&& r.bounceReturn !== 'ifpos'
|
|
917
|
+
&& r.bounceReturn !== 'here'
|
|
918
|
+
&& (!nxt || !nxt.isResponder);
|
|
919
|
+
|
|
920
|
+
let bounceAllowedTo = null;
|
|
921
|
+
if (bounceWithExpectedSupportted(nextRoute, route, nextNext)) {
|
|
922
|
+
({ bounceAllowedTo } = nextRoute);
|
|
923
|
+
}
|
|
924
|
+
const omitBounce = bounceWithExpectedSupportted(route, prevRoute, nextRoute);
|
|
925
|
+
|
|
897
926
|
const buildInfo = {
|
|
927
|
+
bounceAllowedTo,
|
|
898
928
|
expectedToAddResolver: !!route.expectedPath,
|
|
899
929
|
attachedRouter: false
|
|
900
930
|
};
|
|
901
931
|
|
|
902
932
|
const resolvers = [
|
|
903
|
-
...this._buildRouteHead(
|
|
933
|
+
...this._buildRouteHead(
|
|
934
|
+
route,
|
|
935
|
+
nextRouteIsSameResponder,
|
|
936
|
+
includedBlockId,
|
|
937
|
+
omitBounce
|
|
938
|
+
),
|
|
904
939
|
...this.buildResolvers(route.resolvers, route, buildInfo)
|
|
905
940
|
];
|
|
906
941
|
|
|
@@ -910,7 +945,8 @@ class BuildRouter extends Router {
|
|
|
910
945
|
path: route.expectedPath,
|
|
911
946
|
attachedRouter: buildInfo.attachedRouter
|
|
912
947
|
}, {
|
|
913
|
-
isLastIndex: true
|
|
948
|
+
isLastIndex: true,
|
|
949
|
+
bounceAllowedTo
|
|
914
950
|
}));
|
|
915
951
|
}
|
|
916
952
|
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author David Menger
|
|
3
|
+
*/
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
/** @typedef {import('./Request')} Request */
|
|
7
|
+
/** @typedef {import('./Router').ResolvedReducer} ResolvedReducer */
|
|
8
|
+
/** @typedef {import('./AiMatching').Entity} Entity */
|
|
9
|
+
/** @typedef {import('./LLMDispatcher').ILLMRouter} ILLMRouter */
|
|
10
|
+
/** @typedef {import('./LLMRouter').GILLMExtension} GILLMExtension */
|
|
11
|
+
|
|
12
|
+
let uq = 1;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {object} MatcherResult
|
|
16
|
+
* @prop {object} [setState]
|
|
17
|
+
* @prop {boolean} aboveConfidence
|
|
18
|
+
* @prop {string} intent
|
|
19
|
+
* @prop {number} score
|
|
20
|
+
* @prop {Entity[]} [entities]
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @callback RequestMatcher
|
|
25
|
+
* @param {Request} req
|
|
26
|
+
* @returns {MatcherResult}
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @typedef {object} GlobalIntentProps
|
|
31
|
+
*
|
|
32
|
+
* @prop {number} id
|
|
33
|
+
* @prop {RequestMatcher} [matcher]
|
|
34
|
+
* @prop {string[]} [usedEntities]
|
|
35
|
+
* @prop {object} [entitiesSetState]
|
|
36
|
+
* @prop {boolean} [local]
|
|
37
|
+
* @prop {string} [action]
|
|
38
|
+
* @prop {string} [title]
|
|
39
|
+
* @prop {object} [meta]
|
|
40
|
+
* @prop {string} [classification]
|
|
41
|
+
* @prop {ILLMRouter} [router]
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @typedef {GlobalIntentProps & GILLMExtension} GlobalIntent
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @typedef {object} GlobalIntentExtension
|
|
50
|
+
* @prop {string} localPath
|
|
51
|
+
* @prop {object} meta
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @typedef {GlobalIntentExtension & GlobalIntent} GlobalIntentResolved
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @typedef {Map<number, GlobalIntent>} GlobalIntentsMap
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @typedef {Map<number, GlobalIntentResolved>} ResolvedGlobalIntentsMap
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @typedef {Omit<GlobalIntent, 'id'>} GlobalIntentOptions
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @typedef {object} MatchingResolver
|
|
72
|
+
* @prop {string} path
|
|
73
|
+
* @prop {GlobalIntentsMap} globalIntents
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @class GlobalIntents
|
|
78
|
+
*/
|
|
79
|
+
class GlobalIntents {
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
*
|
|
83
|
+
* @returns {number}
|
|
84
|
+
*/
|
|
85
|
+
static id () {
|
|
86
|
+
return uq++;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
* @param {string} path
|
|
92
|
+
* @param {GlobalIntentOptions} options
|
|
93
|
+
* @returns {MatchingResolver}
|
|
94
|
+
*/
|
|
95
|
+
static resolver (path, options) {
|
|
96
|
+
return {
|
|
97
|
+
path,
|
|
98
|
+
globalIntents: GlobalIntents.map(options)
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
*
|
|
104
|
+
* @param {GlobalIntentOptions} options
|
|
105
|
+
* @returns {GlobalIntentsMap}
|
|
106
|
+
*/
|
|
107
|
+
static map (options) {
|
|
108
|
+
const gi = GlobalIntents.create(options);
|
|
109
|
+
return new Map([[gi.id, gi]]);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
*
|
|
114
|
+
* @param {GlobalIntentOptions} [options]
|
|
115
|
+
* @param {number} [id]
|
|
116
|
+
* @returns {GlobalIntent}
|
|
117
|
+
*/
|
|
118
|
+
static create (
|
|
119
|
+
{
|
|
120
|
+
matcher = null,
|
|
121
|
+
usedEntities = [],
|
|
122
|
+
entitiesSetState = {},
|
|
123
|
+
title = null,
|
|
124
|
+
meta = {},
|
|
125
|
+
classification = null,
|
|
126
|
+
router = null,
|
|
127
|
+
local = false,
|
|
128
|
+
keepUserInInteractionsWithBounceAllowed
|
|
129
|
+
} = {},
|
|
130
|
+
id = GlobalIntents.id()
|
|
131
|
+
) {
|
|
132
|
+
return {
|
|
133
|
+
id,
|
|
134
|
+
matcher,
|
|
135
|
+
usedEntities,
|
|
136
|
+
entitiesSetState,
|
|
137
|
+
local,
|
|
138
|
+
action: '/*',
|
|
139
|
+
title,
|
|
140
|
+
meta,
|
|
141
|
+
classification,
|
|
142
|
+
router,
|
|
143
|
+
...(typeof keepUserInInteractionsWithBounceAllowed === 'boolean'
|
|
144
|
+
? { keepUserInInteractionsWithBounceAllowed }
|
|
145
|
+
: {}
|
|
146
|
+
)
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @typedef {object} PathContext
|
|
152
|
+
* @prop {string} path
|
|
153
|
+
* @prop {object} globalIntentsMeta
|
|
154
|
+
*/
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
*
|
|
158
|
+
* @param {ResolvedReducer[]} reducers
|
|
159
|
+
* @param {Map<number, GlobalIntentResolved>} target
|
|
160
|
+
* @param {PathContext} pathContext
|
|
161
|
+
*/
|
|
162
|
+
static mergeGlobalIntents (reducers, target, pathContext) {
|
|
163
|
+
reducers.forEach(({ globalIntents }) => {
|
|
164
|
+
for (const gi of globalIntents.values()) {
|
|
165
|
+
const {
|
|
166
|
+
id, matcher = null, action: intentPath, local, title,
|
|
167
|
+
entitiesSetState = {}, usedEntities, meta = {},
|
|
168
|
+
classification = null, router = null,
|
|
169
|
+
keepUserInInteractionsWithBounceAllowed
|
|
170
|
+
|
|
171
|
+
} = gi;
|
|
172
|
+
const action = intentPath === '/*'
|
|
173
|
+
? pathContext.path
|
|
174
|
+
: `${pathContext.path}${intentPath}`.replace(/^\/\*/, '');
|
|
175
|
+
|
|
176
|
+
target.set(id, {
|
|
177
|
+
id,
|
|
178
|
+
matcher,
|
|
179
|
+
usedEntities,
|
|
180
|
+
entitiesSetState,
|
|
181
|
+
action,
|
|
182
|
+
localPath: pathContext.path,
|
|
183
|
+
local,
|
|
184
|
+
title,
|
|
185
|
+
classification,
|
|
186
|
+
router,
|
|
187
|
+
meta: { ...pathContext.globalIntentsMeta, ...meta },
|
|
188
|
+
...(typeof keepUserInInteractionsWithBounceAllowed === 'boolean'
|
|
189
|
+
? { keepUserInInteractionsWithBounceAllowed }
|
|
190
|
+
: {})
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
module.exports = GlobalIntents;
|
package/src/LLM.js
CHANGED
|
@@ -99,6 +99,7 @@ const LLMSession = require('./LLMSession');
|
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
101
|
* @typedef {object} LLMProviderOptions
|
|
102
|
+
* @prop {string} [preset]
|
|
102
103
|
* @prop {string} [model]
|
|
103
104
|
* @prop {boolean} [parallelToolCalls]
|
|
104
105
|
* @prop {'auto'|'required'|'none'|ForcedFn|string} [toolChoice]
|
|
@@ -262,6 +263,7 @@ class LLM {
|
|
|
262
263
|
|
|
263
264
|
/** @type {LLMOptions} */
|
|
264
265
|
const defaultPreset = {
|
|
266
|
+
preset: 'default',
|
|
265
267
|
model,
|
|
266
268
|
transcriptFlag,
|
|
267
269
|
transcriptLength,
|
|
@@ -293,6 +295,14 @@ class LLM {
|
|
|
293
295
|
this._lastResult = null;
|
|
294
296
|
|
|
295
297
|
this.log = log;
|
|
298
|
+
|
|
299
|
+
this.req = null;
|
|
300
|
+
this.res = null;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
setReqRes (req, res) {
|
|
304
|
+
this.req = req;
|
|
305
|
+
this.res = res;
|
|
296
306
|
}
|
|
297
307
|
|
|
298
308
|
/**
|
|
@@ -318,15 +328,20 @@ class LLM {
|
|
|
318
328
|
}
|
|
319
329
|
|
|
320
330
|
/**
|
|
331
|
+
*
|
|
332
|
+
* @param {LLMCallPreset} [preset]
|
|
321
333
|
* @returns {LLMSession}
|
|
322
334
|
*/
|
|
323
|
-
session () {
|
|
324
|
-
return new LLMSession(this
|
|
335
|
+
session (preset) {
|
|
336
|
+
return new LLMSession(this, [], {
|
|
337
|
+
preset
|
|
338
|
+
});
|
|
325
339
|
}
|
|
326
340
|
|
|
327
341
|
/**
|
|
328
342
|
*
|
|
329
343
|
* @param {LLMCallPreset} [requestedPreset]
|
|
344
|
+
* @returns {LLMCallOptions}
|
|
330
345
|
*/
|
|
331
346
|
llmOptions (requestedPreset = LLM.PRESET_DEFAULT) {
|
|
332
347
|
let preset;
|
|
@@ -343,7 +358,8 @@ class LLM {
|
|
|
343
358
|
}
|
|
344
359
|
return {
|
|
345
360
|
...this._presets.get(preset),
|
|
346
|
-
...override
|
|
361
|
+
...override,
|
|
362
|
+
preset
|
|
347
363
|
};
|
|
348
364
|
}
|
|
349
365
|
|