botium-core 1.14.3 → 1.14.5
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/dist/botium-cjs.js +101 -71
- package/dist/botium-cjs.js.map +1 -1
- package/dist/botium-es.js +119 -89
- package/dist/botium-es.js.map +1 -1
- package/package.json +1 -1
- package/src/scripting/CompilerMarkdown.js +2 -1
- package/src/scripting/CompilerTxt.js +3 -6
- package/src/scripting/MatchFunctions.js +30 -8
- package/src/scripting/ScriptingProvider.js +17 -14
- package/src/scripting/helper.js +9 -3
- package/test/compiler/compilermarkdown.spec.js +3 -3
- package/test/compiler/compilertxt.spec.js +1 -1
- package/test/compiler/convos/txt/convos_emptyrow_just_emptyrow.convo.txt +1 -1
- package/test/scripting/asserters/convoStepParameters.spec.js +11 -0
- package/test/scripting/asserters/convos/convo_step_parameter_matchmode_failed_wer.convo.txt +9 -0
- package/test/scripting/logichooks/convos/scripting_memory_overwrite_and_check.convo.txt +2 -2
package/dist/botium-cjs.js
CHANGED
|
@@ -14,7 +14,7 @@ var randomatic = require('randomatic');
|
|
|
14
14
|
var lodash = require('lodash');
|
|
15
15
|
var boolean$1 = require('boolean');
|
|
16
16
|
var events = require('events');
|
|
17
|
-
var debug$
|
|
17
|
+
var debug$o = require('debug');
|
|
18
18
|
var isClass = require('is-class');
|
|
19
19
|
var crypto = require('crypto');
|
|
20
20
|
var globby = require('globby');
|
|
@@ -52,7 +52,7 @@ var randomatic__default = /*#__PURE__*/_interopDefaultLegacy(randomatic);
|
|
|
52
52
|
var lodash__default = /*#__PURE__*/_interopDefaultLegacy(lodash);
|
|
53
53
|
var boolean__default = /*#__PURE__*/_interopDefaultLegacy(boolean$1);
|
|
54
54
|
var events__default = /*#__PURE__*/_interopDefaultLegacy(events);
|
|
55
|
-
var debug__default = /*#__PURE__*/_interopDefaultLegacy(debug$
|
|
55
|
+
var debug__default = /*#__PURE__*/_interopDefaultLegacy(debug$o);
|
|
56
56
|
var isClass__default = /*#__PURE__*/_interopDefaultLegacy(isClass);
|
|
57
57
|
var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
|
|
58
58
|
var globby__default = /*#__PURE__*/_interopDefaultLegacy(globby);
|
|
@@ -77,7 +77,7 @@ var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
|
|
|
77
77
|
var bodyParser__default = /*#__PURE__*/_interopDefaultLegacy(bodyParser);
|
|
78
78
|
|
|
79
79
|
var name = "botium-core";
|
|
80
|
-
var version$1 = "1.14.
|
|
80
|
+
var version$1 = "1.14.5";
|
|
81
81
|
var description = "The Selenium for Chatbots";
|
|
82
82
|
var main = "index.js";
|
|
83
83
|
var module$1 = "dist/botium-es.js";
|
|
@@ -1104,7 +1104,7 @@ LogicHookConsts.DEFAULT_LOGIC_HOOKS;
|
|
|
1104
1104
|
LogicHookConsts.DEFAULT_USER_INPUTS;
|
|
1105
1105
|
LogicHookConsts.LOGIC_HOOK_EVENTS;
|
|
1106
1106
|
|
|
1107
|
-
const debug$
|
|
1107
|
+
const debug$n = debug__default["default"]('botium-core-asserterUtils');
|
|
1108
1108
|
const {
|
|
1109
1109
|
DEFAULT_ASSERTERS,
|
|
1110
1110
|
DEFAULT_LOGIC_HOOKS,
|
|
@@ -1156,7 +1156,7 @@ var LogicHookUtils_1 = class LogicHookUtils {
|
|
|
1156
1156
|
_fetchAsserters() {
|
|
1157
1157
|
this.caps[Capabilities.ASSERTERS].forEach(asserter => {
|
|
1158
1158
|
if (this.asserters[asserter.ref]) {
|
|
1159
|
-
debug$
|
|
1159
|
+
debug$n(`${asserter.ref} asserter already exists, overwriting.`);
|
|
1160
1160
|
}
|
|
1161
1161
|
this.asserters[asserter.ref] = this._loadClass(asserter, 'asserter');
|
|
1162
1162
|
if (asserter.global) {
|
|
@@ -1167,7 +1167,7 @@ var LogicHookUtils_1 = class LogicHookUtils {
|
|
|
1167
1167
|
_fetchLogicHooks() {
|
|
1168
1168
|
this.caps[Capabilities.LOGIC_HOOKS].forEach(logicHook => {
|
|
1169
1169
|
if (this.logicHooks[logicHook.ref]) {
|
|
1170
|
-
debug$
|
|
1170
|
+
debug$n(`${logicHook.ref} logic hook already exists, overwriting.`);
|
|
1171
1171
|
}
|
|
1172
1172
|
this.logicHooks[logicHook.ref] = this._loadClass(logicHook, 'logichook');
|
|
1173
1173
|
if (logicHook.global) {
|
|
@@ -1178,7 +1178,7 @@ var LogicHookUtils_1 = class LogicHookUtils {
|
|
|
1178
1178
|
_fetchUserInputs() {
|
|
1179
1179
|
this.caps[Capabilities.USER_INPUTS].forEach(userInput => {
|
|
1180
1180
|
if (this.userInputs[userInput.ref]) {
|
|
1181
|
-
debug$
|
|
1181
|
+
debug$n(`${userInput.ref} userinput already exists, overwriting.`);
|
|
1182
1182
|
}
|
|
1183
1183
|
this.userInputs[userInput.ref] = this._loadClass(userInput, 'userinput');
|
|
1184
1184
|
});
|
|
@@ -1364,7 +1364,7 @@ var LogicHookUtils_1 = class LogicHookUtils {
|
|
|
1364
1364
|
}
|
|
1365
1365
|
}
|
|
1366
1366
|
}
|
|
1367
|
-
loadErr.forEach(debug$
|
|
1367
|
+
loadErr.forEach(debug$n);
|
|
1368
1368
|
}
|
|
1369
1369
|
throw new Error(`${typeAsText} specification ${ref} ${hookType} from "${util__default["default"].inspect(src)}" invalid : no loader available`);
|
|
1370
1370
|
}
|
|
@@ -1575,10 +1575,11 @@ var Enums = {
|
|
|
1575
1575
|
};
|
|
1576
1576
|
Enums.E_SCRIPTING_MEMORY_COLUMN_MODE;
|
|
1577
1577
|
|
|
1578
|
-
const debug$
|
|
1578
|
+
const debug$m = debug__default["default"]('botium-core-scripting-helper');
|
|
1579
1579
|
const {
|
|
1580
1580
|
E_SCRIPTING_MEMORY_COLUMN_MODE: E_SCRIPTING_MEMORY_COLUMN_MODE$1
|
|
1581
1581
|
} = Enums;
|
|
1582
|
+
const WHITE_SPACES_EXCEPT_SPACE_CHAR_AT_THE_END = /[\n\t\r]+$/;
|
|
1582
1583
|
const normalizeText$1 = (str, doCleanup) => {
|
|
1583
1584
|
if (str && lodash__default["default"].isArray(str)) {
|
|
1584
1585
|
str = str.join(' ');
|
|
@@ -1820,7 +1821,7 @@ const linesToConvoStep$5 = (lines, sender, context, eol, singleLineMode = false)
|
|
|
1820
1821
|
if (eol === null) {
|
|
1821
1822
|
throw new Error('eol cant be null');
|
|
1822
1823
|
}
|
|
1823
|
-
convoStep.messageText = textLines.join(eol)
|
|
1824
|
+
convoStep.messageText = trimExceptSpaceEnd$1(textLines.join(eol));
|
|
1824
1825
|
}
|
|
1825
1826
|
}
|
|
1826
1827
|
} else {
|
|
@@ -1841,6 +1842,9 @@ const linesToConvoStep$5 = (lines, sender, context, eol, singleLineMode = false)
|
|
|
1841
1842
|
}
|
|
1842
1843
|
return convoStep;
|
|
1843
1844
|
};
|
|
1845
|
+
const trimExceptSpaceEnd$1 = string => {
|
|
1846
|
+
return string?.replace(WHITE_SPACES_EXCEPT_SPACE_CHAR_AT_THE_END, '');
|
|
1847
|
+
};
|
|
1844
1848
|
const convoStepToObject$1 = step => {
|
|
1845
1849
|
const result = [];
|
|
1846
1850
|
if (step.sender === 'me') {
|
|
@@ -2037,7 +2041,7 @@ const convoStepToLines$2 = step => {
|
|
|
2037
2041
|
lines.push(logicHook.name + _formatAppendArgs(logicHook.args));
|
|
2038
2042
|
});
|
|
2039
2043
|
}
|
|
2040
|
-
return lines
|
|
2044
|
+
return lines;
|
|
2041
2045
|
};
|
|
2042
2046
|
const linesToScriptingMemories$2 = (lines, columnMode = null) => {
|
|
2043
2047
|
const guessScriptingMemoryColumnMode = lines => {
|
|
@@ -2151,7 +2155,7 @@ const calculateWer$2 = (str, pattern) => {
|
|
|
2151
2155
|
errCount += err.filter(err => err === true).length;
|
|
2152
2156
|
allCount += err.length;
|
|
2153
2157
|
}
|
|
2154
|
-
debug$
|
|
2158
|
+
debug$m(`Word Error Rate Asserter - Compared Bot Message '${botMessage}' / '${utt}': ${(errCount / allCount).toFixed(2)}`);
|
|
2155
2159
|
return (errCount / allCount).toFixed(2);
|
|
2156
2160
|
};
|
|
2157
2161
|
const toPercent$1 = s => `${(s * 100).toFixed(0)}%`;
|
|
@@ -2170,7 +2174,8 @@ var helper = {
|
|
|
2170
2174
|
validateConvo: validateConvo$2,
|
|
2171
2175
|
linesToScriptingMemories: linesToScriptingMemories$2,
|
|
2172
2176
|
calculateWer: calculateWer$2,
|
|
2173
|
-
toPercent: toPercent$1
|
|
2177
|
+
toPercent: toPercent$1,
|
|
2178
|
+
trimExceptSpaceEnd: trimExceptSpaceEnd$1
|
|
2174
2179
|
};
|
|
2175
2180
|
|
|
2176
2181
|
const BotiumError$4 = class BotiumError extends Error {
|
|
@@ -2349,7 +2354,7 @@ var BotiumError_1 = {
|
|
|
2349
2354
|
botiumErrorFromList: botiumErrorFromList$2
|
|
2350
2355
|
};
|
|
2351
2356
|
|
|
2352
|
-
const debug$
|
|
2357
|
+
const debug$l = debug__default["default"]('botium-core-ScriptingMemory');
|
|
2353
2358
|
const {
|
|
2354
2359
|
v1: uuidv1
|
|
2355
2360
|
} = uuid__default["default"];
|
|
@@ -2609,7 +2614,7 @@ const extractVarNames = text => {
|
|
|
2609
2614
|
return (lodash__default["default"].isString(text) ? text.match(/\$[A-Za-z]\w+/g) : false) || [];
|
|
2610
2615
|
};
|
|
2611
2616
|
const fill = (container, scriptingMemory, result, utterance, scriptingEvents) => {
|
|
2612
|
-
debug$
|
|
2617
|
+
debug$l(`fill start: ${util__default["default"].inspect(scriptingMemory)}`);
|
|
2613
2618
|
let varRegex;
|
|
2614
2619
|
switch (container.caps[Capabilities.SCRIPTING_MEMORY_MATCHING_MODE]) {
|
|
2615
2620
|
case 'word':
|
|
@@ -2643,14 +2648,14 @@ const fill = (container, scriptingMemory, result, utterance, scriptingEvents) =>
|
|
|
2643
2648
|
if (i <= varMatches.length) {
|
|
2644
2649
|
const varName = varMatches[i - 1];
|
|
2645
2650
|
if (RESERVED_WORDS.indexOf(varName) >= 0) {
|
|
2646
|
-
debug$
|
|
2651
|
+
debug$l(`fill Variable "${varName}" is not overwritten, because it is reserved word. `);
|
|
2647
2652
|
} else {
|
|
2648
2653
|
scriptingMemory[varName] = resultMatches[i];
|
|
2649
2654
|
}
|
|
2650
2655
|
}
|
|
2651
2656
|
}
|
|
2652
2657
|
});
|
|
2653
|
-
debug$
|
|
2658
|
+
debug$l(`fill end: ${util__default["default"].inspect(scriptingMemory)}`);
|
|
2654
2659
|
}
|
|
2655
2660
|
};
|
|
2656
2661
|
var ScriptingMemory = {
|
|
@@ -2668,7 +2673,7 @@ ScriptingMemory.extractVarNames;
|
|
|
2668
2673
|
ScriptingMemory.RESERVED_WORDS;
|
|
2669
2674
|
ScriptingMemory.SCRIPTING_FUNCTIONS;
|
|
2670
2675
|
|
|
2671
|
-
const debug$
|
|
2676
|
+
const debug$k = debug__default["default"]('botium-core-Convo');
|
|
2672
2677
|
const {
|
|
2673
2678
|
BotiumError: BotiumError$2,
|
|
2674
2679
|
botiumErrorFromErr: botiumErrorFromErr$1,
|
|
@@ -2822,10 +2827,10 @@ class TranscriptError extends Error {
|
|
|
2822
2827
|
class Convo$6 {
|
|
2823
2828
|
constructor(context, fromJson = {}) {
|
|
2824
2829
|
if (fromJson instanceof Convo$6) {
|
|
2825
|
-
debug$
|
|
2830
|
+
debug$k('Illegal state!!! Parameter should be a JSON, but it is a Convo');
|
|
2826
2831
|
} else if (fromJson.beginAsserter) {
|
|
2827
2832
|
// beginAsserter is one of the fields which are lost
|
|
2828
|
-
debug$
|
|
2833
|
+
debug$k('Illegal state!!! Parameter should be a native JSON, but looks as a Convo converted to JSON');
|
|
2829
2834
|
}
|
|
2830
2835
|
this.scriptingEvents = context.scriptingEvents;
|
|
2831
2836
|
this.context = context;
|
|
@@ -2989,7 +2994,7 @@ class Convo$6 {
|
|
|
2989
2994
|
try {
|
|
2990
2995
|
params = JSON.parse(rawConvoStepParameters[0]);
|
|
2991
2996
|
} catch (e) {
|
|
2992
|
-
debug$
|
|
2997
|
+
debug$k(`${this.header.name}/${convoStep.stepTag}: Failed to parse convo step parameters from JSON ${rawConvoStepParameters[0]}`);
|
|
2993
2998
|
}
|
|
2994
2999
|
}
|
|
2995
3000
|
if (!params || !Object.keys(params).length) {
|
|
@@ -3002,7 +3007,7 @@ class Convo$6 {
|
|
|
3002
3007
|
const value = param.substring(semicolon + 1);
|
|
3003
3008
|
params[name] = value;
|
|
3004
3009
|
} catch (e) {
|
|
3005
|
-
debug$
|
|
3010
|
+
debug$k(`${this.header.name}/${convoStep.stepTag}: Failed to parse convo step parameter from arg ${param}`);
|
|
3006
3011
|
}
|
|
3007
3012
|
}
|
|
3008
3013
|
}
|
|
@@ -3018,7 +3023,7 @@ class Convo$6 {
|
|
|
3018
3023
|
}
|
|
3019
3024
|
}
|
|
3020
3025
|
if (Object.keys(convoStepParameters).length) {
|
|
3021
|
-
debug$
|
|
3026
|
+
debug$k(`${this.header.name}: using convo step parameters ${JSON.stringify(convoStepParameters)}`);
|
|
3022
3027
|
}
|
|
3023
3028
|
const currentStepIndex = i;
|
|
3024
3029
|
container.eventEmitter.emit(Events.CONVO_STEP_NEXT, container, convoStep, i);
|
|
@@ -3081,7 +3086,7 @@ class Convo$6 {
|
|
|
3081
3086
|
});
|
|
3082
3087
|
await this._checkBotRepliesConsumed(container);
|
|
3083
3088
|
const coreMsg = lodash__default["default"].omit(removeBuffers(meMsg), ['sourceData']);
|
|
3084
|
-
debug$
|
|
3089
|
+
debug$k(`${this.header.name}/${convoStep.stepTag}: user says (cleaned by binary and base64 data and sourceData) ${JSON.stringify(coreMsg, null, 2)}`);
|
|
3085
3090
|
await new Promise(resolve => {
|
|
3086
3091
|
if (container.caps[Capabilities.SIMULATE_WRITING_SPEED] && meMsg.messageText && meMsg.messageText.length) {
|
|
3087
3092
|
setTimeout(() => resolve(), container.caps[Capabilities.SIMULATE_WRITING_SPEED] * meMsg.messageText.length);
|
|
@@ -3117,7 +3122,7 @@ class Convo$6 {
|
|
|
3117
3122
|
});
|
|
3118
3123
|
continue;
|
|
3119
3124
|
} else {
|
|
3120
|
-
debug$
|
|
3125
|
+
debug$k(`${this.header.name}/${convoStep.stepTag}: message not found in #me section, message not sent to container ${util__default["default"].inspect(convoStep)}`);
|
|
3121
3126
|
transcriptStep.botEnd = new Date();
|
|
3122
3127
|
await this.scriptingEvents.onMeEnd({
|
|
3123
3128
|
convo: this,
|
|
@@ -3133,7 +3138,7 @@ class Convo$6 {
|
|
|
3133
3138
|
} catch (err) {
|
|
3134
3139
|
transcriptStep.botEnd = new Date();
|
|
3135
3140
|
const failErr = botiumErrorFromErr$1(`${this.header.name}/${convoStep.stepTag}: error sending to bot - ${err.message || err}`, err);
|
|
3136
|
-
debug$
|
|
3141
|
+
debug$k(failErr);
|
|
3137
3142
|
try {
|
|
3138
3143
|
this.scriptingEvents.fail && this.scriptingEvents.fail(failErr);
|
|
3139
3144
|
} catch (failErr) {}
|
|
@@ -3146,7 +3151,7 @@ class Convo$6 {
|
|
|
3146
3151
|
waitForBotSays = true;
|
|
3147
3152
|
}
|
|
3148
3153
|
try {
|
|
3149
|
-
debug$
|
|
3154
|
+
debug$k(`${this.header.name} wait for bot ${convoStep.channel || ''}`);
|
|
3150
3155
|
await this.scriptingEvents.onBotStart({
|
|
3151
3156
|
convo: this,
|
|
3152
3157
|
convoStep,
|
|
@@ -3162,11 +3167,11 @@ class Convo$6 {
|
|
|
3162
3167
|
transcriptStep.botEnd = new Date();
|
|
3163
3168
|
transcriptStep.actual = new BotiumMockMessage_1(botMsg);
|
|
3164
3169
|
const coreMsg = lodash__default["default"].omit(removeBuffers(botMsg), ['sourceData']);
|
|
3165
|
-
debug$
|
|
3170
|
+
debug$k(`${this.header.name}: bot says (cleaned by binary and base64 data and sourceData) ${JSON.stringify(coreMsg, null, 2)}`);
|
|
3166
3171
|
} catch (err) {
|
|
3167
3172
|
transcriptStep.botEnd = new Date();
|
|
3168
3173
|
const failErr = botiumErrorFromErr$1(`${this.header.name}/${convoStep.stepTag}: error waiting for bot - ${err.message}`, err);
|
|
3169
|
-
debug$
|
|
3174
|
+
debug$k(failErr);
|
|
3170
3175
|
try {
|
|
3171
3176
|
this.scriptingEvents.fail && this.scriptingEvents.fail(failErr, lastMeConvoStep);
|
|
3172
3177
|
} catch (failErr) {}
|
|
@@ -3185,11 +3190,11 @@ class Convo$6 {
|
|
|
3185
3190
|
if (prepared) {
|
|
3186
3191
|
transcriptStep.actual = new BotiumMockMessage_1(botMsg);
|
|
3187
3192
|
const coreMsg = lodash__default["default"].omit(removeBuffers(botMsg), ['sourceData']);
|
|
3188
|
-
debug$
|
|
3193
|
+
debug$k(`${this.header.name}: onBotPrepare (cleaned by binary and base64 data and sourceData) ${JSON.stringify(coreMsg, null, 2)}`);
|
|
3189
3194
|
}
|
|
3190
3195
|
} catch (err) {
|
|
3191
3196
|
const failErr = botiumErrorFromErr$1(`${this.header.name}/${convoStep.stepTag}: onBotPrepare error - ${err.message || err}`, err);
|
|
3192
|
-
debug$
|
|
3197
|
+
debug$k(failErr);
|
|
3193
3198
|
try {
|
|
3194
3199
|
this.scriptingEvents.fail && this.scriptingEvents.fail(failErr, lastMeConvoStep);
|
|
3195
3200
|
} catch (failErr) {}
|
|
@@ -3210,7 +3215,7 @@ class Convo$6 {
|
|
|
3210
3215
|
skipTranscriptStep = true;
|
|
3211
3216
|
if (endOfConditionalGroup && !conditionMetInGroup && !convoStep.optional) {
|
|
3212
3217
|
const failErr = new BotiumError$2(`${this.header.name}/${convoStep.stepTag}: Non of the conditions are met in ${conditionalGroupId ? `'${conditionalGroupId}' ` : ''}condition group`);
|
|
3213
|
-
debug$
|
|
3218
|
+
debug$k(failErr);
|
|
3214
3219
|
throw failErr;
|
|
3215
3220
|
}
|
|
3216
3221
|
if (endOfConditionalGroup) {
|
|
@@ -3230,7 +3235,7 @@ class Convo$6 {
|
|
|
3230
3235
|
}
|
|
3231
3236
|
if (!botMsg || !botMsg.messageText && !botMsg.media && !botMsg.buttons && !botMsg.cards && !botMsg.sourceData && !botMsg.nlp) {
|
|
3232
3237
|
const failErr = new BotiumError$2(`${this.header.name}/${convoStep.stepTag}: bot says nothing`);
|
|
3233
|
-
debug$
|
|
3238
|
+
debug$k(failErr);
|
|
3234
3239
|
try {
|
|
3235
3240
|
this.scriptingEvents.fail && this.scriptingEvents.fail(failErr, lastMeConvoStep);
|
|
3236
3241
|
} catch (failErr) {}
|
|
@@ -3242,7 +3247,7 @@ class Convo$6 {
|
|
|
3242
3247
|
const retryOn = convoStep.sender === 'bot' && retryConfig && retryConfig.timeout && retryConfig.mainAsserter;
|
|
3243
3248
|
if (convoStep.optional && nextConvoStep && nextConvoStep.sender === 'bot') {
|
|
3244
3249
|
if (retryOn) {
|
|
3245
|
-
debug$
|
|
3250
|
+
debug$k(`${this.header.name}/${convoStep.stepTag}: Retry failed asserter is ignored on optional convo`);
|
|
3246
3251
|
}
|
|
3247
3252
|
waitForBotSays = false;
|
|
3248
3253
|
skipTranscriptStep = true;
|
|
@@ -3255,11 +3260,11 @@ class Convo$6 {
|
|
|
3255
3260
|
const now = new Date().getTime();
|
|
3256
3261
|
const timeoutRemaining = retryBotMessageTimeoutEnd - now;
|
|
3257
3262
|
if (timeoutRemaining > 0) {
|
|
3258
|
-
debug$
|
|
3263
|
+
debug$k(`${this.header.name}/${convoStep.stepTag}: Convo step retry on, timeout remaining: ${timeoutRemaining}, error: "${err.message}"`);
|
|
3259
3264
|
retryBotMessageDropBotResponse = true;
|
|
3260
3265
|
return false;
|
|
3261
3266
|
} else {
|
|
3262
|
-
debug$
|
|
3267
|
+
debug$k(`${this.header.name}/${convoStep.stepTag}: Convo step retry on, but timeout is over. error: "${err.message}"`);
|
|
3263
3268
|
}
|
|
3264
3269
|
}
|
|
3265
3270
|
if (container.caps[Capabilities.SCRIPTING_ENABLE_MULTIPLE_ASSERT_ERRORS]) {
|
|
@@ -3343,14 +3348,14 @@ class Convo$6 {
|
|
|
3343
3348
|
const now = new Date().getTime();
|
|
3344
3349
|
const timeoutRemaining = retryOn && retryBotMessageTimeoutEnd - now;
|
|
3345
3350
|
if (retryOn && timeoutRemaining > 0) {
|
|
3346
|
-
debug$
|
|
3351
|
+
debug$k(`${this.header.name}/${convoStep.stepTag}: Convo step retry on, timeout remaining: ${timeoutRemaining}, error: "${err.message}"`);
|
|
3347
3352
|
retryBotMessageDropBotResponse = true;
|
|
3348
3353
|
} else {
|
|
3349
3354
|
if (retryOn && timeoutRemaining <= 0) {
|
|
3350
|
-
debug$
|
|
3355
|
+
debug$k(`${this.header.name}/${convoStep.stepTag}: Convo step retry on, but timeout is over. error: "${err.message}"`);
|
|
3351
3356
|
}
|
|
3352
3357
|
const failErr = botiumErrorFromErr$1(`${this.header.name}/${convoStep.stepTag}: assertion error - ${err.message || err}`, err);
|
|
3353
|
-
debug$
|
|
3358
|
+
debug$k(failErr);
|
|
3354
3359
|
try {
|
|
3355
3360
|
this.scriptingEvents.fail && this.scriptingEvents.fail(failErr, lastMeConvoStep);
|
|
3356
3361
|
} catch (failErr) {}
|
|
@@ -3374,7 +3379,7 @@ class Convo$6 {
|
|
|
3374
3379
|
}
|
|
3375
3380
|
} else {
|
|
3376
3381
|
const failErr = new BotiumError$2(`${this.header.name}/${convoStep.stepTag}: invalid sender - ${util__default["default"].inspect(convoStep.sender)}`);
|
|
3377
|
-
debug$
|
|
3382
|
+
debug$k(failErr);
|
|
3378
3383
|
try {
|
|
3379
3384
|
this.scriptingEvents.fail && this.scriptingEvents.fail(failErr);
|
|
3380
3385
|
} catch (failErr) {}
|
|
@@ -3580,7 +3585,7 @@ class Convo$6 {
|
|
|
3580
3585
|
throw new BotiumError$2(`Cant find partial convo with name ${includeLogicHook} (available partial convos: ${Object.keys(partialConvos).join(',')})`);
|
|
3581
3586
|
}
|
|
3582
3587
|
_getEffectiveConversationRecursive(partialConvo.conversation, [...parentPConvos, includeLogicHook], result, true);
|
|
3583
|
-
debug$
|
|
3588
|
+
debug$k(`Partial convo ${includeLogicHook} included`);
|
|
3584
3589
|
});
|
|
3585
3590
|
});
|
|
3586
3591
|
return result;
|
|
@@ -3601,7 +3606,7 @@ var Convo_1 = {
|
|
|
3601
3606
|
TranscriptError
|
|
3602
3607
|
};
|
|
3603
3608
|
|
|
3604
|
-
const debug$
|
|
3609
|
+
const debug$j = debug__default["default"]('botium-core-RetryHelper');
|
|
3605
3610
|
var RetryHelper_1 = class RetryHelper {
|
|
3606
3611
|
constructor(caps, section, options = {}) {
|
|
3607
3612
|
this.retryErrorPatterns = [];
|
|
@@ -3625,7 +3630,7 @@ var RetryHelper_1 = class RetryHelper {
|
|
|
3625
3630
|
minTimeout: caps[`RETRY_${section.toUpperCase()}_MINTIMEOUT`] || (lodash__default["default"].isNil(options.minTimeout) ? 1000 : options.minTimeout)
|
|
3626
3631
|
};
|
|
3627
3632
|
if (this.retrySettings.retries > 0) {
|
|
3628
|
-
debug$
|
|
3633
|
+
debug$j(`Retry for ${section} is enabled. Settings: ${JSON.stringify(this.retrySettings)} Patterns: ${JSON.stringify(this.retryErrorPatterns.map(r => r.toString()))}`);
|
|
3629
3634
|
}
|
|
3630
3635
|
}
|
|
3631
3636
|
shouldRetry(err) {
|
|
@@ -3639,26 +3644,36 @@ var RetryHelper_1 = class RetryHelper {
|
|
|
3639
3644
|
}
|
|
3640
3645
|
};
|
|
3641
3646
|
|
|
3647
|
+
const debug$i = debug__default["default"]('botium-core-MatchFunctions');
|
|
3642
3648
|
const {
|
|
3643
3649
|
toString,
|
|
3644
3650
|
quoteRegexpString,
|
|
3645
3651
|
calculateWer: calculateWer$1
|
|
3646
3652
|
} = helper;
|
|
3647
|
-
const _normalize = botresponse => {
|
|
3653
|
+
const _normalize = (botresponse, args, convoStepParameters) => {
|
|
3654
|
+
if (!convoStepParameters) {
|
|
3655
|
+
debug$i('Convo step parameters might be missing!');
|
|
3656
|
+
}
|
|
3648
3657
|
if (lodash__default["default"].isUndefined(botresponse) || lodash__default["default"].isNil(botresponse)) return '';
|
|
3649
3658
|
if (lodash__default["default"].isObject(botresponse) && lodash__default["default"].has(botresponse, 'messageText')) {
|
|
3650
3659
|
return toString(botresponse.messageText) || '';
|
|
3651
3660
|
}
|
|
3652
3661
|
return toString(botresponse);
|
|
3653
3662
|
};
|
|
3654
|
-
const regexp = ignoreCase => (botresponse, utterance) => {
|
|
3663
|
+
const regexp = ignoreCase => (botresponse, utterance, args, convoStepParameters) => {
|
|
3664
|
+
if (!convoStepParameters) {
|
|
3665
|
+
debug$i('Convo step parameters might be missing!');
|
|
3666
|
+
}
|
|
3655
3667
|
if (lodash__default["default"].isUndefined(botresponse)) return false;
|
|
3656
3668
|
utterance = toString(utterance);
|
|
3657
3669
|
botresponse = _normalize(botresponse);
|
|
3658
3670
|
const regexp = ignoreCase ? new RegExp(utterance, 'i') : new RegExp(utterance, '');
|
|
3659
3671
|
return regexp.test(botresponse);
|
|
3660
3672
|
};
|
|
3661
|
-
const wildcard = ignoreCase => (botresponse, utterance) => {
|
|
3673
|
+
const wildcard = ignoreCase => (botresponse, utterance, args, convoStepParameters) => {
|
|
3674
|
+
if (!convoStepParameters) {
|
|
3675
|
+
debug$i('Convo step parameters might be missing!');
|
|
3676
|
+
}
|
|
3662
3677
|
if (lodash__default["default"].isUndefined(botresponse)) {
|
|
3663
3678
|
if (utterance.trim() === '*') return true;else return false;
|
|
3664
3679
|
}
|
|
@@ -3672,7 +3687,10 @@ const wildcard = ignoreCase => (botresponse, utterance) => {
|
|
|
3672
3687
|
const regexp = ignoreCase ? new RegExp(utteranceRe, 'i') : new RegExp(utteranceRe, '');
|
|
3673
3688
|
return regexp.test(botresponse);
|
|
3674
3689
|
};
|
|
3675
|
-
const wildcardExact = ignoreCase => (botresponse, utterance) => {
|
|
3690
|
+
const wildcardExact = ignoreCase => (botresponse, utterance, args, convoStepParameters) => {
|
|
3691
|
+
if (!convoStepParameters) {
|
|
3692
|
+
debug$i('Convo step parameters might be missing!');
|
|
3693
|
+
}
|
|
3676
3694
|
if (lodash__default["default"].isUndefined(botresponse)) {
|
|
3677
3695
|
if (utterance.trim() === '*') return true;else return false;
|
|
3678
3696
|
}
|
|
@@ -3686,7 +3704,10 @@ const wildcardExact = ignoreCase => (botresponse, utterance) => {
|
|
|
3686
3704
|
const regexp = ignoreCase ? new RegExp(utteranceRe, 'i') : new RegExp(utteranceRe, '');
|
|
3687
3705
|
return regexp.test(botresponse);
|
|
3688
3706
|
};
|
|
3689
|
-
const include = ignoreCase => (botresponse, utterance) => {
|
|
3707
|
+
const include = ignoreCase => (botresponse, utterance, args, convoStepParameters) => {
|
|
3708
|
+
if (!convoStepParameters) {
|
|
3709
|
+
debug$i('Convo step parameters might be missing!');
|
|
3710
|
+
}
|
|
3690
3711
|
if (lodash__default["default"].isUndefined(botresponse)) return false;
|
|
3691
3712
|
utterance = toString(utterance);
|
|
3692
3713
|
botresponse = _normalize(botresponse);
|
|
@@ -3696,7 +3717,10 @@ const include = ignoreCase => (botresponse, utterance) => {
|
|
|
3696
3717
|
}
|
|
3697
3718
|
return botresponse.indexOf(utterance) >= 0;
|
|
3698
3719
|
};
|
|
3699
|
-
const equals = ignoreCase => (botresponse, utterance) => {
|
|
3720
|
+
const equals = ignoreCase => (botresponse, utterance, args, convoStepParameters) => {
|
|
3721
|
+
if (!convoStepParameters) {
|
|
3722
|
+
debug$i('Convo step parameters might be missing!');
|
|
3723
|
+
}
|
|
3700
3724
|
if (lodash__default["default"].isUndefined(botresponse)) return false;
|
|
3701
3725
|
utterance = toString(utterance);
|
|
3702
3726
|
botresponse = _normalize(botresponse);
|
|
@@ -3706,10 +3730,13 @@ const equals = ignoreCase => (botresponse, utterance) => {
|
|
|
3706
3730
|
}
|
|
3707
3731
|
return botresponse === utterance;
|
|
3708
3732
|
};
|
|
3709
|
-
const wer = () => (botresponse, utterance, args) => {
|
|
3733
|
+
const wer = () => (botresponse, utterance, args, convoStepParameters) => {
|
|
3734
|
+
if (!convoStepParameters) {
|
|
3735
|
+
debug$i('Convo step parameters might be missing!');
|
|
3736
|
+
}
|
|
3710
3737
|
botresponse = _normalize(botresponse || '');
|
|
3711
3738
|
utterance = toString(utterance || '');
|
|
3712
|
-
const threshold = [',', '.'].find(p => `${args[0]}`.includes(p)) ? parseFloat(args[0]) : parseInt(args[0]) / 100;
|
|
3739
|
+
const threshold = !lodash__default["default"].isNil(convoStepParameters?.matchingModeWer) ? convoStepParameters?.matchingModeWer / 100 : [',', '.'].find(p => `${args[0]}`.includes(p)) ? parseFloat(args[0]) : parseInt(args[0]) / 100;
|
|
3713
3740
|
return calculateWer$1(botresponse, utterance) <= threshold;
|
|
3714
3741
|
};
|
|
3715
3742
|
const getMatchFunction$1 = matchingMode => {
|
|
@@ -4844,7 +4871,8 @@ const {
|
|
|
4844
4871
|
convoStepToLines,
|
|
4845
4872
|
validateConvo,
|
|
4846
4873
|
validSenders: validSenders$2,
|
|
4847
|
-
linesToScriptingMemories: linesToScriptingMemories$1
|
|
4874
|
+
linesToScriptingMemories: linesToScriptingMemories$1,
|
|
4875
|
+
trimExceptSpaceEnd
|
|
4848
4876
|
} = helper;
|
|
4849
4877
|
var CompilerTxt_1 = class CompilerTxt extends CompilerBase_1 {
|
|
4850
4878
|
constructor(context, caps = {}) {
|
|
@@ -4868,7 +4896,7 @@ var CompilerTxt_1 = class CompilerTxt extends CompilerBase_1 {
|
|
|
4868
4896
|
Compile(scriptBuffer, scriptType = Constants.SCRIPTING_TYPE_CONVO) {
|
|
4869
4897
|
let scriptData = scriptBuffer;
|
|
4870
4898
|
if (Buffer.isBuffer(scriptBuffer)) scriptData = scriptData.toString();
|
|
4871
|
-
const lines =
|
|
4899
|
+
const lines = scriptData.split(this.eol);
|
|
4872
4900
|
if (scriptType === Constants.SCRIPTING_TYPE_CONVO) {
|
|
4873
4901
|
return this._compileConvo(lines, false);
|
|
4874
4902
|
} else if (scriptType === Constants.SCRIPTING_TYPE_PCONVO) {
|
|
@@ -4918,7 +4946,6 @@ var CompilerTxt_1 = class CompilerTxt extends CompilerBase_1 {
|
|
|
4918
4946
|
};
|
|
4919
4947
|
lines.forEach(line => {
|
|
4920
4948
|
currentLineIndex++;
|
|
4921
|
-
line = line.trim();
|
|
4922
4949
|
if (isValidTagLine(line)) {
|
|
4923
4950
|
pushPrev();
|
|
4924
4951
|
convoStepSender = line.substr(1).trim();
|
|
@@ -4945,8 +4972,8 @@ var CompilerTxt_1 = class CompilerTxt extends CompilerBase_1 {
|
|
|
4945
4972
|
_compileUtterances(lines) {
|
|
4946
4973
|
if (lines && lines.length > 0) {
|
|
4947
4974
|
const result = [new Utterance_1({
|
|
4948
|
-
name: lines[0],
|
|
4949
|
-
utterances: lines.length > 1 ? lines.slice(1) : []
|
|
4975
|
+
name: lines[0].trim(),
|
|
4976
|
+
utterances: lines.length > 1 ? lines.slice(1).map(line => trimExceptSpaceEnd(line)) : []
|
|
4950
4977
|
})];
|
|
4951
4978
|
this.context.AddUtterances(result);
|
|
4952
4979
|
return result;
|
|
@@ -5430,7 +5457,7 @@ var CompilerMarkdown_1 = class CompilerMarkdown extends CompilerBase_1 {
|
|
|
5430
5457
|
conversation.push(Object.assign({
|
|
5431
5458
|
sender,
|
|
5432
5459
|
stepTag: 'Line ' + (step.map[0] + 1)
|
|
5433
|
-
}, linesToConvoStep(step.children.map(child => child.content + (child.children ? ' ' + child.children.map(child => child.content).join('|') : '')), sender, this.context, this.eol)));
|
|
5460
|
+
}, linesToConvoStep(step.children.map(child => child.content + (child.children && child.children.length > 0 ? ' ' + child.children.map(child => child.content).join('|') : '')), sender, this.context, this.eol)));
|
|
5434
5461
|
} else {
|
|
5435
5462
|
debug$a(`Expected sender ${validSenders.map(s => `'${s}'`).join(' or ')} but found ${sender}`);
|
|
5436
5463
|
}
|
|
@@ -5731,25 +5758,26 @@ var ScriptingProvider_1 = class ScriptingProvider {
|
|
|
5731
5758
|
resolveEmptyIfUnknown
|
|
5732
5759
|
});
|
|
5733
5760
|
},
|
|
5734
|
-
assertBotResponse: (botresponse, tomatch, stepTag, meMsg, convoStepParameters) => {
|
|
5761
|
+
assertBotResponse: (botresponse, tomatch, stepTag, meMsg, convoStepParameters = {}) => {
|
|
5735
5762
|
if (!lodash__default["default"].isArray(tomatch)) {
|
|
5736
5763
|
tomatch = [tomatch];
|
|
5737
5764
|
}
|
|
5738
5765
|
debug$9(`assertBotResponse ${stepTag} ${meMsg ? `(${meMsg}) ` : ''}BOT: ${botresponse} = ${tomatch} ...`);
|
|
5739
5766
|
const matchFn = convoStepParameters.matchingMode ? getMatchFunction(convoStepParameters.matchingMode) || this.matchFn : this.matchFn;
|
|
5740
|
-
const found = lodash__default["default"].find(tomatch, utt => matchFn(botresponse, utt, this.caps[Capabilities.SCRIPTING_MATCHING_MODE_ARGS]));
|
|
5767
|
+
const found = lodash__default["default"].find(tomatch, utt => matchFn(botresponse, utt, this.caps[Capabilities.SCRIPTING_MATCHING_MODE_ARGS], convoStepParameters));
|
|
5741
5768
|
const asserterType = this.caps[Capabilities.SCRIPTING_MATCHING_MODE] === 'wer' ? 'Word Error Rate Asserter' : 'Text Match Asserter';
|
|
5742
5769
|
if (lodash__default["default"].isNil(found)) {
|
|
5743
|
-
|
|
5770
|
+
const matchingMode = convoStepParameters.matchingMode || this.caps[Capabilities.SCRIPTING_MATCHING_MODE];
|
|
5771
|
+
if (matchingMode === 'wer') {
|
|
5744
5772
|
const wer = calculateWer(botresponse, tomatch[0]);
|
|
5745
5773
|
const werArgs = this.caps[Capabilities.SCRIPTING_MATCHING_MODE_ARGS];
|
|
5746
|
-
const threshold = [',', '.'].find(p => `${werArgs[0]}`.includes(p)) ? parseFloat(werArgs[0]) : parseInt(werArgs[0]) / 100;
|
|
5774
|
+
const threshold = !lodash__default["default"].isNil(convoStepParameters.matchingModeWer) ? convoStepParameters.matchingModeWer / 100 : [',', '.'].find(p => `${werArgs[0]}`.includes(p)) ? parseFloat(werArgs[0]) : parseInt(werArgs[0]) / 100;
|
|
5747
5775
|
const message = `${stepTag}: Word Error Rate (${toPercent(wer)}) higher than accepted (${toPercent(threshold)})`;
|
|
5748
5776
|
throw new BotiumError$1(message, {
|
|
5749
5777
|
type: 'asserter',
|
|
5750
5778
|
source: asserterType,
|
|
5751
5779
|
params: {
|
|
5752
|
-
matchingMode
|
|
5780
|
+
matchingMode,
|
|
5753
5781
|
args: this.caps[Capabilities.SCRIPTING_MATCHING_MODE_ARGS] || null
|
|
5754
5782
|
},
|
|
5755
5783
|
context: {
|
|
@@ -5787,25 +5815,26 @@ var ScriptingProvider_1 = class ScriptingProvider {
|
|
|
5787
5815
|
}
|
|
5788
5816
|
}
|
|
5789
5817
|
},
|
|
5790
|
-
assertBotNotResponse: (botresponse, nottomatch, stepTag, meMsg, convoStepParameters) => {
|
|
5818
|
+
assertBotNotResponse: (botresponse, nottomatch, stepTag, meMsg, convoStepParameters = {}) => {
|
|
5791
5819
|
if (!lodash__default["default"].isArray(nottomatch)) {
|
|
5792
5820
|
nottomatch = [nottomatch];
|
|
5793
5821
|
}
|
|
5794
5822
|
debug$9(`assertBotNotResponse ${stepTag} ${meMsg ? `(${meMsg}) ` : ''}BOT: ${botresponse} != ${nottomatch} ...`);
|
|
5795
5823
|
const matchFn = convoStepParameters.matchingMode ? getMatchFunction(convoStepParameters.matchingMode) || this.matchFn : this.matchFn;
|
|
5796
|
-
const found = lodash__default["default"].find(nottomatch, utt => matchFn(botresponse, utt, this.caps[Capabilities.SCRIPTING_MATCHING_MODE_ARGS]));
|
|
5824
|
+
const found = lodash__default["default"].find(nottomatch, utt => matchFn(botresponse, utt, this.caps[Capabilities.SCRIPTING_MATCHING_MODE_ARGS], convoStepParameters));
|
|
5797
5825
|
const asserterType = this.caps[Capabilities.SCRIPTING_MATCHING_MODE] === 'wer' ? 'Word Error Rate Asserter' : 'Text Match Asserter';
|
|
5798
5826
|
if (!lodash__default["default"].isNil(found)) {
|
|
5799
|
-
|
|
5827
|
+
const matchingMode = convoStepParameters.matchingMode || this.caps[Capabilities.SCRIPTING_MATCHING_MODE];
|
|
5828
|
+
if (matchingMode === 'wer') {
|
|
5800
5829
|
const wer = calculateWer(botresponse, nottomatch[0]);
|
|
5801
5830
|
const werArgs = this.caps[Capabilities.SCRIPTING_MATCHING_MODE_ARGS];
|
|
5802
|
-
const threshold = [',', '.'].find(p => `${werArgs[0]}`.includes(p)) ? parseFloat(werArgs[0]) : parseInt(werArgs[0]) / 100;
|
|
5831
|
+
const threshold = !lodash__default["default"].isNil(convoStepParameters.matchingModeWer) ? convoStepParameters.matchingModeWer / 100 : [',', '.'].find(p => `${werArgs[0]}`.includes(p)) ? parseFloat(werArgs[0]) : parseInt(werArgs[0]) / 100;
|
|
5803
5832
|
const message = `${stepTag}: Word Error Rate (${toPercent(wer)}) lower than accepted (${toPercent(threshold)})`;
|
|
5804
5833
|
throw new BotiumError$1(message, {
|
|
5805
5834
|
type: 'asserter',
|
|
5806
5835
|
source: asserterType,
|
|
5807
5836
|
params: {
|
|
5808
|
-
matchingMode
|
|
5837
|
+
matchingMode,
|
|
5809
5838
|
args: this.caps[Capabilities.SCRIPTING_MATCHING_MODE_ARGS] || null
|
|
5810
5839
|
},
|
|
5811
5840
|
context: {
|
|
@@ -6915,18 +6944,19 @@ var ScriptingProvider_1 = class ScriptingProvider {
|
|
|
6915
6944
|
}
|
|
6916
6945
|
if (utterances) {
|
|
6917
6946
|
lodash__default["default"].forEach(utterances, utt => {
|
|
6918
|
-
const
|
|
6947
|
+
const uttName = utt.name?.trim();
|
|
6948
|
+
const eu = this.utterances[uttName];
|
|
6919
6949
|
if (eu) {
|
|
6920
6950
|
eu.utterances = lodash__default["default"].uniq(lodash__default["default"].concat(eu.utterances, utt.utterances));
|
|
6921
6951
|
} else {
|
|
6922
|
-
this.utterances[
|
|
6952
|
+
this.utterances[uttName] = utt;
|
|
6923
6953
|
}
|
|
6924
6954
|
const {
|
|
6925
6955
|
ambiguous,
|
|
6926
6956
|
expected
|
|
6927
|
-
} = findAmbiguous(this.utterances[
|
|
6957
|
+
} = findAmbiguous(this.utterances[uttName].utterances);
|
|
6928
6958
|
if (ambiguous && ambiguous.length > 0) {
|
|
6929
|
-
debug$9(`Ambigous utterance "${
|
|
6959
|
+
debug$9(`Ambigous utterance "${uttName}", expecting exact ${expected.length ? '"' + expected.join(', ') + '"' : '<none>'} scripting memory variables in following user examples: ${ambiguous.map(d => `"${d}"`).join(', ')}`);
|
|
6930
6960
|
}
|
|
6931
6961
|
});
|
|
6932
6962
|
}
|