wingbot 3.35.1 → 3.36.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/package.json +1 -1
- package/src/Ai.js +45 -11
- package/src/Processor.js +1 -1
- package/src/utils/stateData.js +11 -0
package/package.json
CHANGED
package/src/Ai.js
CHANGED
|
@@ -40,6 +40,8 @@ let uq = 1;
|
|
|
40
40
|
|
|
41
41
|
/** @typedef {import('./Request').IntentAction} IntentAction */
|
|
42
42
|
/** @typedef {import('./Request')} Request */
|
|
43
|
+
/** @typedef {import('./Responder')} Responder */
|
|
44
|
+
/** @typedef {import('./wingbot/CachedModel').Result} Result */
|
|
43
45
|
/** @typedef {import('./wingbot/CustomEntityDetectionModel').Phrases} Phrases */
|
|
44
46
|
|
|
45
47
|
/**
|
|
@@ -348,13 +350,13 @@ class Ai {
|
|
|
348
350
|
const rules = this.matcher.preprocessRule(intent);
|
|
349
351
|
const matcher = this._createIntentMatcher(rules, usedEntities);
|
|
350
352
|
|
|
351
|
-
return async (req) => {
|
|
353
|
+
return async (req, res) => {
|
|
352
354
|
if (!req.isTextOrIntent()) {
|
|
353
355
|
return false;
|
|
354
356
|
}
|
|
355
357
|
|
|
356
358
|
if (!req.intents) {
|
|
357
|
-
await this._loadIntents(req);
|
|
359
|
+
await this._loadIntents(req, res);
|
|
358
360
|
}
|
|
359
361
|
|
|
360
362
|
const winningIntent = matcher(req);
|
|
@@ -523,9 +525,10 @@ class Ai {
|
|
|
523
525
|
/**
|
|
524
526
|
*
|
|
525
527
|
* @param {Request} req
|
|
528
|
+
* @param {Responder} [res]
|
|
526
529
|
* @returns {Promise}
|
|
527
530
|
*/
|
|
528
|
-
async preloadAi (req) {
|
|
531
|
+
async preloadAi (req, res = null) {
|
|
529
532
|
if (req.supportsFeature(req.FEATURE_PHRASES)) {
|
|
530
533
|
const model = this._getModelForRequest(req, false);
|
|
531
534
|
|
|
@@ -534,7 +537,7 @@ class Ai {
|
|
|
534
537
|
.catch(() => {});
|
|
535
538
|
}
|
|
536
539
|
}
|
|
537
|
-
return this._preloadIntent(req);
|
|
540
|
+
return this._preloadIntent(req, res);
|
|
538
541
|
}
|
|
539
542
|
|
|
540
543
|
/**
|
|
@@ -552,12 +555,43 @@ class Ai {
|
|
|
552
555
|
return CustomEntityDetectionModel.getEmptyPhrasesObject();
|
|
553
556
|
}
|
|
554
557
|
|
|
555
|
-
|
|
558
|
+
/**
|
|
559
|
+
*
|
|
560
|
+
* @param {Request} req
|
|
561
|
+
* @param {Responder} res
|
|
562
|
+
* @param {Result} result
|
|
563
|
+
* @returns {void}
|
|
564
|
+
*/
|
|
565
|
+
_setResultToReqRes (req, res, result) {
|
|
566
|
+
const { text = null, intents, entities = [] } = result;
|
|
567
|
+
Object.assign(req, { intents, entities, _anonymizedText: text });
|
|
568
|
+
|
|
569
|
+
if (!res) {
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
const entitiesObj = (entities || []).reduce((o, { entity, value }) => {
|
|
574
|
+
const list = o[entity] || [];
|
|
575
|
+
list.push(value);
|
|
576
|
+
return Object.assign(o, { [entity]: list });
|
|
577
|
+
}, {});
|
|
578
|
+
|
|
579
|
+
res.setData({
|
|
580
|
+
'@': entitiesObj
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
*
|
|
586
|
+
* @param {Request} req
|
|
587
|
+
* @param {Responder} [res]
|
|
588
|
+
* @returns {Promise}
|
|
589
|
+
*/
|
|
590
|
+
async _preloadIntent (req, res = null) {
|
|
556
591
|
const mockIntent = this._getMockIntent(req);
|
|
557
592
|
|
|
558
593
|
if (mockIntent) {
|
|
559
|
-
req
|
|
560
|
-
req.entities = mockIntent.entities;
|
|
594
|
+
this._setResultToReqRes(req, res, mockIntent);
|
|
561
595
|
return;
|
|
562
596
|
}
|
|
563
597
|
|
|
@@ -571,15 +605,15 @@ class Ai {
|
|
|
571
605
|
req.intents = [];
|
|
572
606
|
return;
|
|
573
607
|
}
|
|
574
|
-
await this._loadIntents(req, model);
|
|
608
|
+
await this._loadIntents(req, res, model);
|
|
575
609
|
} else {
|
|
576
610
|
req.intents = [];
|
|
577
611
|
}
|
|
578
612
|
}
|
|
579
613
|
|
|
580
|
-
async _loadIntents (req, model = null) {
|
|
581
|
-
const
|
|
582
|
-
|
|
614
|
+
async _loadIntents (req, res = null, model = null) {
|
|
615
|
+
const result = await this._queryModel(req, model);
|
|
616
|
+
this._setResultToReqRes(req, res, result);
|
|
583
617
|
}
|
|
584
618
|
|
|
585
619
|
async _queryModel (req, useModel = null) {
|
package/src/Processor.js
CHANGED
package/src/utils/stateData.js
CHANGED
|
@@ -3,8 +3,19 @@
|
|
|
3
3
|
*/
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
|
+
/** @typedef {import('../Request')} Request */
|
|
7
|
+
/** @typedef {import('../Responder')} Responder */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param {Request} req
|
|
12
|
+
* @param {Responder} res
|
|
13
|
+
* @param {object} configuration
|
|
14
|
+
* @returns {object}
|
|
15
|
+
*/
|
|
6
16
|
module.exports = function stateData (req, res = null, configuration = null) {
|
|
7
17
|
const c = configuration || req.configuration;
|
|
18
|
+
|
|
8
19
|
return {
|
|
9
20
|
...req.state,
|
|
10
21
|
...(res ? res.newState : {}),
|