botium-core 1.13.3 → 1.13.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.
@@ -81,7 +81,7 @@ var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
81
81
  var bodyParser__default = /*#__PURE__*/_interopDefaultLegacy(bodyParser);
82
82
 
83
83
  var name = "botium-core";
84
- var version$1 = "1.13.3";
84
+ var version$1 = "1.13.5";
85
85
  var description = "The Selenium for Chatbots";
86
86
  var main = "index.js";
87
87
  var module$1 = "dist/botium-es.js";
@@ -113,7 +113,7 @@ var bugs = {
113
113
  };
114
114
  var homepage = "https://www.botium.ai";
115
115
  var dependencies = {
116
- "@babel/runtime": "^7.18.6",
116
+ "@babel/runtime": "^7.19.0",
117
117
  async: "^3.2.4",
118
118
  "body-parser": "^1.20.0",
119
119
  boolean: "^3.2.0",
@@ -123,7 +123,7 @@ var dependencies = {
123
123
  esprima: "^4.0.1",
124
124
  express: "^4.18.1",
125
125
  globby: "11.0.4",
126
- ioredis: "^5.1.0",
126
+ ioredis: "^5.2.3",
127
127
  "is-class": "^0.0.9",
128
128
  "is-json": "^2.0.1",
129
129
  jsonpath: "^1.1.1",
@@ -140,13 +140,13 @@ var dependencies = {
140
140
  rimraf: "^3.0.2",
141
141
  "sanitize-filename": "^1.6.3",
142
142
  slugify: "^1.6.5",
143
- "socket.io": "^4.5.1",
144
- "socket.io-client": "^4.5.1",
143
+ "socket.io": "^4.5.2",
144
+ "socket.io-client": "^4.5.2",
145
145
  "socketio-auth": "^0.1.1",
146
- "swagger-jsdoc": "^6.2.1",
147
- "swagger-ui-express": "^4.4.0",
148
- uuid: "^8.3.2",
149
- vm2: "^3.9.10",
146
+ "swagger-jsdoc": "^6.2.5",
147
+ "swagger-ui-express": "^4.5.0",
148
+ uuid: "^9.0.0",
149
+ vm2: "^3.9.11",
150
150
  "word-error-rate": "0.0.7",
151
151
  "write-yaml": "^1.0.0",
152
152
  xlsx: "^0.18.5",
@@ -154,27 +154,27 @@ var dependencies = {
154
154
  yaml: "^2.1.1"
155
155
  };
156
156
  var devDependencies = {
157
- "@babel/core": "^7.18.6",
158
- "@babel/node": "^7.18.6",
159
- "@babel/plugin-transform-runtime": "^7.18.6",
160
- "@babel/preset-env": "^7.18.6",
157
+ "@babel/core": "^7.19.3",
158
+ "@babel/node": "^7.19.1",
159
+ "@babel/plugin-transform-runtime": "^7.19.1",
160
+ "@babel/preset-env": "^7.19.3",
161
161
  chai: "^4.3.6",
162
162
  "chai-as-promised": "^7.1.1",
163
163
  "cross-env": "^7.0.3",
164
- eslint: "^8.19.0",
164
+ eslint: "^8.24.0",
165
165
  "eslint-config-standard": "^17.0.0",
166
166
  "eslint-plugin-import": "^2.26.0",
167
167
  "eslint-plugin-mocha": "^10.1.0",
168
- "eslint-plugin-n": "^15.2.4",
169
- "eslint-plugin-promise": "^6.0.0",
168
+ "eslint-plugin-n": "^15.3.0",
169
+ "eslint-plugin-promise": "^6.0.1",
170
170
  "eslint-plugin-standard": "^4.1.0",
171
171
  "license-checker": "^25.0.1",
172
172
  "license-compatibility-checker": "^0.3.5",
173
173
  mocha: "^10.0.0",
174
- nock: "^13.2.8",
175
- "npm-check-updates": "^15.2.6",
174
+ nock: "^13.2.9",
175
+ "npm-check-updates": "^16.3.4",
176
176
  nyc: "^15.1.0",
177
- rollup: "^2.76.0",
177
+ rollup: "^2.79.1",
178
178
  "rollup-plugin-babel": "^4.4.0",
179
179
  "rollup-plugin-commonjs": "^10.1.0",
180
180
  "rollup-plugin-json": "^4.0.0",
@@ -351,6 +351,8 @@ var Capabilities = {
351
351
  SCRIPTING_UTTEXPANSION_MODE: 'SCRIPTING_UTTEXPANSION_MODE',
352
352
  SCRIPTING_UTTEXPANSION_RANDOM_COUNT: 'SCRIPTING_UTTEXPANSION_RANDOM_COUNT',
353
353
  SCRIPTING_UTTEXPANSION_INCOMPREHENSION: 'SCRIPTING_UTTEXPANSION_INCOMPREHENSION',
354
+ SCRIPTING_UTTEXPANSION_INCOMPREHENSIONINTENTS: 'SCRIPTING_UTTEXPANSION_INCOMPREHENSIONINTENTS',
355
+ SCRIPTING_UTTEXPANSION_INCOMPREHENSIONUTTS: 'SCRIPTING_UTTEXPANSION_INCOMPREHENSIONUTTS',
354
356
  SCRIPTING_UTTEXPANSION_USENAMEASINTENT: 'SCRIPTING_UTTEXPANSION_USENAMEASINTENT',
355
357
  // justLineTag, utterance
356
358
  SCRIPTING_UTTEXPANSION_NAMING_MODE: 'SCRIPTING_UTTEXPANSION_NAMING_MODE',
@@ -504,6 +506,8 @@ Capabilities.SCRIPTING_MATCHING_MODE_ARGS;
504
506
  Capabilities.SCRIPTING_UTTEXPANSION_MODE;
505
507
  Capabilities.SCRIPTING_UTTEXPANSION_RANDOM_COUNT;
506
508
  Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSION;
509
+ Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSIONINTENTS;
510
+ Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSIONUTTS;
507
511
  Capabilities.SCRIPTING_UTTEXPANSION_USENAMEASINTENT;
508
512
  Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE;
509
513
  Capabilities.SCRIPTING_UTTEXPANSION_NAMING_UTTERANCE_MAX;
@@ -588,6 +592,10 @@ var Defaults$1 = {
588
592
  [Capabilities.SCRIPTING_UTTEXPANSION_RANDOM_COUNT]: 1,
589
593
  [Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE]: 'justLineTag',
590
594
  [Capabilities.SCRIPTING_UTTEXPANSION_NAMING_UTTERANCE_MAX]: '16',
595
+ [Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSION]: null,
596
+ [Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSIONINTENTS]: [],
597
+ [Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSIONUTTS]: [],
598
+ [Capabilities.SCRIPTING_UTTEXPANSION_USENAMEASINTENT]: false,
591
599
  [Capabilities.SCRIPTING_MEMORYEXPANSION_KEEP_ORIG]: false,
592
600
  [Capabilities.SCRIPTING_ENABLE_SKIP_ASSERT_ERRORS]: false,
593
601
  [Capabilities.SCRIPTING_FORCE_BOT_CONSUMED]: false,
@@ -1725,6 +1733,7 @@ class BotiumMockAsserter$1 {
1725
1733
  constructor(fromJson = {}) {
1726
1734
  this.name = fromJson.name;
1727
1735
  this.args = lodash__default["default"].cloneDeep(fromJson.args);
1736
+ this.not = fromJson.not;
1728
1737
  }
1729
1738
 
1730
1739
  }
@@ -2306,6 +2315,8 @@ const convoStepToLines$2 = step => {
2306
2315
  lines.push('MEDIA ' + step.media[0].mediaUri);
2307
2316
  } else if (step.messageText) {
2308
2317
  lines.push(step.messageText);
2318
+ } else if (step.sourceData) {
2319
+ lines.push(JSON.stringify(step.sourceData, null, 2));
2309
2320
  }
2310
2321
 
2311
2322
  step.userInputs && step.userInputs.forEach(userInput => {
@@ -2498,6 +2509,34 @@ const SCRIPTING_FUNCTIONS_RAW = {
2498
2509
  $timestamp: () => {
2499
2510
  return Date.now();
2500
2511
  },
2512
+ $tomorrow: pattern => {
2513
+ if (pattern) {
2514
+ return moment__default["default"]().add(1, 'day').format(pattern);
2515
+ }
2516
+
2517
+ return moment__default["default"]().add(1, 'day').toDate().toLocaleDateString();
2518
+ },
2519
+ $yesterday: pattern => {
2520
+ if (pattern) {
2521
+ return moment__default["default"]().subtract(1, 'day').format(pattern);
2522
+ }
2523
+
2524
+ return moment__default["default"]().subtract(1, 'day').toDate().toLocaleDateString();
2525
+ },
2526
+ $date_add: (amount, unit, pattern) => {
2527
+ if (pattern) {
2528
+ return moment__default["default"]().add(amount, unit).format(pattern);
2529
+ }
2530
+
2531
+ return moment__default["default"]().add(amount, unit).toDate().toLocaleDateString();
2532
+ },
2533
+ $date_subtract: (amount, unit, pattern) => {
2534
+ if (pattern) {
2535
+ return moment__default["default"]().subtract(amount, unit).format(pattern);
2536
+ }
2537
+
2538
+ return moment__default["default"]().subtract(amount, unit).toDate().toLocaleDateString();
2539
+ },
2501
2540
  $year: () => {
2502
2541
  return new Date().getFullYear();
2503
2542
  },
@@ -2589,7 +2628,8 @@ const SCRIPTING_FUNCTIONS_RAW = {
2589
2628
  require: false,
2590
2629
  env: caps[Capabilities.SECURITY_ALLOW_UNSAFE] ? process.env : {},
2591
2630
  sandbox: {
2592
- caps
2631
+ caps,
2632
+ moment: moment__default["default"]
2593
2633
  }
2594
2634
  });
2595
2635
  return vm.run(`module.exports = (${code})`);
@@ -2667,7 +2707,22 @@ const _apply = (scriptingMemory, str, caps, mockMsg) => {
2667
2707
  for (const match of matches) {
2668
2708
  if (match.indexOf('(') > 0) {
2669
2709
  const arg = match.substring(match.indexOf('(') + 1, match.lastIndexOf(')')).replace(/\\\)/g, ')');
2670
- str = str.replace(match, SCRIPTING_FUNCTIONS$1[key].handler(caps, arg, mockMsg));
2710
+ let args = [arg];
2711
+
2712
+ if (SCRIPTING_FUNCTIONS$1[key].numberOfArguments > 1) {
2713
+ args = arg.split(',');
2714
+ }
2715
+
2716
+ args = args.map(arg => {
2717
+ arg = arg.trim();
2718
+
2719
+ if (arg.startsWith('"') && arg.endsWith('"')) {
2720
+ return arg.substring(1, arg.length - 1);
2721
+ } else {
2722
+ return arg;
2723
+ }
2724
+ });
2725
+ str = str.replace(match, SCRIPTING_FUNCTIONS$1[key].handler(caps, ...args, mockMsg));
2671
2726
  } else {
2672
2727
  str = str.replace(match, SCRIPTING_FUNCTIONS$1[key].handler(caps));
2673
2728
  }
@@ -4866,7 +4921,8 @@ var CompilerXlsx_1 = class CompilerXlsx extends CompilerBase_1 {
4866
4921
  convoResults.forEach(convo => {
4867
4922
  if (!convo.header.name) {
4868
4923
  convo.header.name = `${convo.header.sheetname}-${this.colnames[convo.header.colindex]}${formatRowIndex(convo.header.rowindex)}`;
4869
- }
4924
+ } // it is not used anymore?
4925
+
4870
4926
 
4871
4927
  convo.header.sort = convo.header.name;
4872
4928
  scriptResults.push(convo);
@@ -6932,6 +6988,8 @@ var ScriptingProvider_1 = class ScriptingProvider {
6932
6988
 
6933
6989
  ExpandUtterancesToConvos({
6934
6990
  useNameAsIntent,
6991
+ incomprehensionIntents,
6992
+ incomprehensionUtts,
6935
6993
  incomprehensionUtt
6936
6994
  } = {}) {
6937
6995
  const expandedConvos = [];
@@ -6940,26 +6998,81 @@ var ScriptingProvider_1 = class ScriptingProvider {
6940
6998
  useNameAsIntent = !!this.caps[Capabilities.SCRIPTING_UTTEXPANSION_USENAMEASINTENT];
6941
6999
  }
6942
7000
 
7001
+ if (lodash__default["default"].isUndefined(incomprehensionIntents)) {
7002
+ incomprehensionIntents = this.caps[Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSIONINTENTS];
7003
+ }
7004
+
7005
+ if (lodash__default["default"].isUndefined(incomprehensionUtts)) {
7006
+ incomprehensionUtts = this.caps[Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSIONUTTS];
7007
+ }
7008
+
6943
7009
  if (lodash__default["default"].isUndefined(incomprehensionUtt)) {
6944
7010
  incomprehensionUtt = this.caps[Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSION];
6945
7011
  }
6946
7012
 
6947
- if (useNameAsIntent && incomprehensionUtt) {
6948
- throw new Error('ExpandUtterancesToConvos - SCRIPTING_UTTEXPANSION_USENAMEASINTENT and SCRIPTING_UTTEXPANSION_INCOMPREHENSION are incompatible');
7013
+ if (incomprehensionUtt && (!incomprehensionUtts || incomprehensionUtts.length === 0) && !this.utterances[incomprehensionUtt]) {
7014
+ throw new Error(`ExpandUtterancesToConvos - incomprehension utterance '${incomprehensionUtt}' undefined (and no user examples given)`);
6949
7015
  }
6950
7016
 
6951
- if (incomprehensionUtt && !this.utterances[incomprehensionUtt]) {
6952
- throw new Error(`ExpandUtterancesToConvos - incomprehension utterance '${incomprehensionUtt}' undefined`);
7017
+ if (incomprehensionUtts && incomprehensionUtts.length > 0) {
7018
+ if (!incomprehensionUtt) {
7019
+ incomprehensionUtt = 'UTT_INCOMPREHENSION';
7020
+ }
7021
+
7022
+ if (this.utterances[incomprehensionUtt]) {
7023
+ this.utterances[incomprehensionUtt].utterances.push(...incomprehensionUtts);
7024
+ } else {
7025
+ this.utterances[incomprehensionUtt] = {
7026
+ name: incomprehensionUtt,
7027
+ utterances: [...incomprehensionUtts]
7028
+ };
7029
+ }
6953
7030
  }
6954
7031
 
6955
7032
  if (useNameAsIntent) {
6956
7033
  debug$9('ExpandUtterancesToConvos - Using utterance name as NLU intent');
6957
- } else if (incomprehensionUtt) {
6958
- debug$9(`ExpandUtterancesToConvos - Using incomprehension utterance expansion mode: ${incomprehensionUtt}`);
7034
+ }
7035
+
7036
+ if (incomprehensionIntents && incomprehensionIntents.length > 0) {
7037
+ debug$9(`ExpandUtterancesToConvos - Using ${incomprehensionIntents.length} incomprehension NLU intent(s)`);
7038
+ }
7039
+
7040
+ if (incomprehensionUtt) {
7041
+ debug$9(`ExpandUtterancesToConvos - Using incomprehension utterance expansion mode: ${incomprehensionUtt}, ${this.utterances[incomprehensionUtt].utterances.length} user example(s)`);
6959
7042
  }
6960
7043
 
6961
7044
  lodash__default["default"].keys(this.utterances).filter(u => u !== incomprehensionUtt).forEach(uttName => {
6962
7045
  const utt = this.utterances[uttName];
7046
+ const responseStep = {
7047
+ sender: 'bot',
7048
+ messageText: '',
7049
+ asserters: [],
7050
+ stepTag: 'Step 2 - check bot response',
7051
+ not: false
7052
+ };
7053
+
7054
+ if (useNameAsIntent) {
7055
+ responseStep.asserters.push({
7056
+ name: 'INTENT',
7057
+ args: [utt.name]
7058
+ });
7059
+ }
7060
+
7061
+ if (incomprehensionIntents && incomprehensionIntents.length > 0) {
7062
+ incomprehensionIntents.forEach(ii => {
7063
+ responseStep.asserters.push({
7064
+ name: 'INTENT',
7065
+ args: [ii],
7066
+ not: true
7067
+ });
7068
+ });
7069
+ }
7070
+
7071
+ if (incomprehensionUtt) {
7072
+ responseStep.messageText = incomprehensionUtt;
7073
+ responseStep.not = true;
7074
+ }
7075
+
6963
7076
  expandedConvos.push(new Convo(this._buildScriptContext(), {
6964
7077
  header: {
6965
7078
  name: utt.name,
@@ -6972,25 +7085,7 @@ var ScriptingProvider_1 = class ScriptingProvider {
6972
7085
  }],
6973
7086
  messageText: utt.name,
6974
7087
  stepTag: 'Step 1 - tell utterance'
6975
- }, useNameAsIntent ? {
6976
- sender: 'bot',
6977
- asserters: [{
6978
- name: 'INTENT',
6979
- args: [utt.name]
6980
- }],
6981
- stepTag: 'Step 2 - check intent',
6982
- not: false
6983
- } : incomprehensionUtt ? {
6984
- sender: 'bot',
6985
- messageText: incomprehensionUtt,
6986
- stepTag: 'Step 2 - check incomprehension',
6987
- not: true
6988
- } : {
6989
- sender: 'bot',
6990
- messageText: '',
6991
- stepTag: 'Step 2 - check bot response',
6992
- not: false
6993
- }],
7088
+ }, responseStep],
6994
7089
  sourceTag: Object.assign({}, utt.sourceTag, {
6995
7090
  origUttName: utt.name
6996
7091
  })
@@ -7002,30 +7097,77 @@ var ScriptingProvider_1 = class ScriptingProvider {
7002
7097
  this._sortConvos();
7003
7098
  }
7004
7099
 
7005
- ExpandConvos() {
7100
+ ExpandConvos(options = {}) {
7101
+ options = Object.assign({
7102
+ // use skip and keep, or justHeader
7103
+ justHeader: false,
7104
+ // drop unwanted convos
7105
+ convoFilter: null
7106
+ }, options);
7107
+ const context = {
7108
+ count: 0
7109
+ };
7006
7110
  const expandedConvos = [];
7007
7111
  debug$9(`ExpandConvos - Using utterances expansion mode: ${this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE]}`);
7008
7112
  this.convos.forEach(convo => {
7009
7113
  convo.expandPartialConvos();
7010
7114
 
7011
- this._expandConvo(expandedConvos, convo);
7115
+ for (const expanded of this._expandConvo(convo, options, context)) {
7116
+ expanded.header.assertionCount = this.GetAssertionCount(expanded);
7117
+
7118
+ if (options.justHeader) {
7119
+ const ConvoWithOnlyHeader = {
7120
+ header: {
7121
+ name: expanded.header.name,
7122
+ assertionCount: expanded.header.assertionCount
7123
+ }
7124
+ };
7125
+ expandedConvos.push(ConvoWithOnlyHeader);
7126
+ } else {
7127
+ expandedConvos.push(expanded);
7128
+ }
7129
+ }
7012
7130
  });
7013
7131
  this.convos = expandedConvos;
7014
7132
 
7015
- this._sortConvos();
7133
+ if (!options.justHeader) {
7134
+ this._sortConvos();
7135
+ } else {
7136
+ this._updateConvos();
7137
+ }
7138
+ }
7139
+
7140
+ ExpandConvosIterable(options = {}) {
7141
+ options = Object.assign({
7142
+ // drop unwanted convos
7143
+ convoFilter: null
7144
+ }, options);
7145
+ debug$9(`ExpandConvos - Using utterances expansion mode: ${this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE]}`); // creating a nested generator, calling the other.
7146
+ // We hope this.convos does not changes while this iterator is used
7147
+
7148
+ const _convosIterable = function* (options) {
7149
+ const context = {
7150
+ count: 0
7151
+ };
7152
+
7153
+ for (const convo of this.convos) {
7154
+ convo.expandPartialConvos();
7155
+ yield* this._expandConvo(convo, options, context);
7156
+ }
7157
+ }.bind(this);
7158
+
7159
+ this.convosIterable = _convosIterable(options);
7016
7160
  }
7017
7161
  /**
7018
- *
7019
- * @param expandedConvos
7162
+ * This is a generator function with yield
7020
7163
  * @param currentConvo
7021
7164
  * @param convoStepIndex
7022
7165
  * @param convoStepsStack list of ConvoSteps
7023
- * @param context {width: }
7024
7166
  * @private
7025
7167
  */
7026
7168
 
7027
7169
 
7028
- _expandConvo(expandedConvos, currentConvo, convoStepIndex = 0, convoStepsStack = [], context = {}) {
7170
+ *_expandConvo(currentConvo, options, context, convoStepIndex = 0, convoStepsStack = []) {
7029
7171
  const utterancePostfix = (lineTag, uttOrUserInput) => {
7030
7172
  const naming = this.caps[Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE] || Defaults$1.capabilities[Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE];
7031
7173
 
@@ -7051,8 +7193,7 @@ var ScriptingProvider_1 = class ScriptingProvider {
7051
7193
  if (currentStep.sender === 'bot' || currentStep.sender === 'begin' || currentStep.sender === 'end') {
7052
7194
  const currentStepsStack = convoStepsStack.slice();
7053
7195
  currentStepsStack.push(lodash__default["default"].cloneDeep(currentStep));
7054
-
7055
- this._expandConvo(expandedConvos, currentConvo, convoStepIndex + 1, currentStepsStack, context);
7196
+ yield* this._expandConvo(currentConvo, options, context, convoStepIndex + 1, currentStepsStack);
7056
7197
  } else if (currentStep.sender === 'me') {
7057
7198
  let useUnexpanded = true;
7058
7199
 
@@ -7074,16 +7215,15 @@ var ScriptingProvider_1 = class ScriptingProvider {
7074
7215
  if (this.utterances[uttName]) {
7075
7216
  const allutterances = this.utterances[uttName].utterances;
7076
7217
 
7077
- const processSampleUtterances = (sampleutterances, myContext) => {
7078
- sampleutterances.forEach((utt, index) => {
7079
- processSampleUtterance(utt, sampleutterances.length, index, Object.assign({
7218
+ const processSampleUtterances = function* (sampleutterances, myContext) {
7219
+ for (let index = 0; index < sampleutterances.length; index++) {
7220
+ yield* processSampleUtterance(sampleutterances[index], sampleutterances.length, index, Object.assign({
7080
7221
  indexExpansionModeIndex: index
7081
7222
  }, myContext || context));
7082
- });
7223
+ }
7083
7224
  };
7084
7225
 
7085
- const processSampleUtterance = (sampleutterance, length, index, myContext) => {
7086
- const lineTag = `${index + 1}`.padStart(`${length}`.length, '0');
7226
+ const processSampleUtterance = function* (sampleutterance, length, index, myContext) {
7087
7227
  const currentStepsStack = convoStepsStack.slice();
7088
7228
 
7089
7229
  if (uttArgs) {
@@ -7096,19 +7236,24 @@ var ScriptingProvider_1 = class ScriptingProvider {
7096
7236
 
7097
7237
  const currentConvoLabeled = lodash__default["default"].cloneDeep(currentConvo);
7098
7238
 
7099
- Object.assign(currentConvoLabeled.header, {
7100
- name: `${currentConvo.header.name}/${uttName}-${utterancePostfix(lineTag, sampleutterance)}`
7101
- });
7239
+ if (length > 1) {
7240
+ const lineTag = `${index + 1}`.padStart(`${length}`.length, '0');
7241
+ Object.assign(currentConvoLabeled.header, {
7242
+ name: `${currentConvo.header.name}/${uttName}-${utterancePostfix(lineTag, sampleutterance)}`
7243
+ });
7244
+ }
7245
+
7102
7246
  if (!currentConvoLabeled.sourceTag) currentConvoLabeled.sourceTag = {};
7103
7247
  if (!currentConvoLabeled.sourceTag.origConvoName) currentConvoLabeled.sourceTag.origConvoName = currentConvo.header.name;
7248
+ yield* this._expandConvo(currentConvoLabeled, options, myContext || context, convoStepIndex + 1, currentStepsStack);
7249
+ }.bind(this);
7104
7250
 
7105
- this._expandConvo(expandedConvos, currentConvoLabeled, convoStepIndex + 1, currentStepsStack, myContext || context);
7106
- };
7107
-
7108
- if (this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE] === 'index') {
7251
+ if (allutterances.length === 1) {
7252
+ yield* processSampleUtterances([allutterances[0]], context);
7253
+ } else if (this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE] === 'index') {
7109
7254
  if (lodash__default["default"].isNil(context.indexExpansionModeWidth)) {
7110
7255
  // executed for the first found utterance
7111
- processSampleUtterances(allutterances, Object.assign({}, context, {
7256
+ yield* processSampleUtterances(allutterances, Object.assign({}, context, {
7112
7257
  indexExpansionModeWidth: allutterances.length
7113
7258
  }));
7114
7259
  } else {
@@ -7126,7 +7271,7 @@ var ScriptingProvider_1 = class ScriptingProvider {
7126
7271
  const myContext = Object.assign({}, context, {
7127
7272
  indexExpansionModeWidth: Math.max(allutterances.length, context.indexExpansionModeWidth)
7128
7273
  });
7129
- processSampleUtterance(allutterances[localIndex], allutterances.length, localIndex, myContext);
7274
+ yield* processSampleUtterance(allutterances[localIndex], allutterances.length, localIndex, myContext);
7130
7275
 
7131
7276
  if (allutterances.length > context.indexExpansionModeWidth && context.indexExpansionModeIndex + 1 === context.indexExpansionModeWidth) {
7132
7277
  debug$9(`While expanding convos by index found in utterance "${uttName}" more examples (${allutterances.length}) as expected (${context.indexExpansionModeWidth})`);
@@ -7137,20 +7282,20 @@ var ScriptingProvider_1 = class ScriptingProvider {
7137
7282
  indexExpansionModeWidth: allutterances.length,
7138
7283
  indexExpansionModeIndex: i
7139
7284
  });
7140
- processSampleUtterance(allutterances[i], allutterances.length, i, myContext);
7285
+ yield* processSampleUtterance(allutterances[i], allutterances.length, i, myContext);
7141
7286
  }
7142
7287
  }
7143
7288
  }
7144
7289
  } else {
7145
7290
  if (this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE] === 'first') {
7146
- processSampleUtterances([allutterances[0]]);
7291
+ yield* processSampleUtterances([allutterances[0]], context);
7147
7292
  } else if (this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE] === 'random') {
7148
- processSampleUtterances(allutterances.map(x => ({
7293
+ yield* processSampleUtterances(allutterances.map(x => ({
7149
7294
  x,
7150
7295
  r: Math.random()
7151
- })).sort((a, b) => a.r - b.r).map(a => a.x).slice(0, this.caps[Capabilities.SCRIPTING_UTTEXPANSION_RANDOM_COUNT]));
7296
+ })).sort((a, b) => a.r - b.r).map(a => a.x).slice(0, this.caps[Capabilities.SCRIPTING_UTTEXPANSION_RANDOM_COUNT]), context);
7152
7297
  } else {
7153
- processSampleUtterances(allutterances);
7298
+ yield* processSampleUtterances(allutterances, context);
7154
7299
  }
7155
7300
  }
7156
7301
 
@@ -7159,7 +7304,8 @@ var ScriptingProvider_1 = class ScriptingProvider {
7159
7304
  }
7160
7305
 
7161
7306
  if (currentStep.userInputs && currentStep.userInputs.length > 0) {
7162
- currentStep.userInputs.forEach((ui, uiIndex) => {
7307
+ for (let uiIndex = 0; uiIndex < currentStep.userInputs.length; uiIndex++) {
7308
+ const ui = currentStep.userInputs[uiIndex];
7163
7309
  const userInput = this.userInputs[ui.name];
7164
7310
 
7165
7311
  if (userInput && userInput.expandConvo) {
@@ -7171,16 +7317,15 @@ var ScriptingProvider_1 = class ScriptingProvider {
7171
7317
 
7172
7318
  if (expandedUserInputs && expandedUserInputs.length > 0) {
7173
7319
  // let sampleinputs = expandedUserInputs
7174
- const processSampleInputs = (sampleinputs, myContext, uiIndex) => {
7175
- sampleinputs.forEach((input, index) => {
7176
- processSampleInput(input, sampleinputs.length, index, Object.assign({
7320
+ const processSampleInputs = function* (sampleinputs, myContext, uiIndex) {
7321
+ for (let index = 0; index < sampleinputs.length; index++) {
7322
+ yield* processSampleInput(sampleinputs[index], sampleinputs.length, index, Object.assign({
7177
7323
  indexExpansionModeIndex: index
7178
7324
  }, myContext || context), uiIndex);
7179
- });
7325
+ }
7180
7326
  };
7181
7327
 
7182
- const processSampleInput = (sampleinput, length, index, myContext, uiIndex) => {
7183
- const lineTag = `${index + 1}`.padStart(`${length}`.length, '0');
7328
+ const processSampleInput = function* (sampleinput, length, index, myContext, uiIndex) {
7184
7329
  const currentStepsStack = convoStepsStack.slice();
7185
7330
 
7186
7331
  const currentStepMod = lodash__default["default"].cloneDeep(currentStep);
@@ -7190,16 +7335,27 @@ var ScriptingProvider_1 = class ScriptingProvider {
7190
7335
 
7191
7336
  const currentConvoLabeled = lodash__default["default"].cloneDeep(currentConvo);
7192
7337
 
7193
- Object.assign(currentConvoLabeled.header, {
7194
- name: `${currentConvo.header.name}/${ui.name}-${utterancePostfix(lineTag, sampleinput.args && sampleinput.args.length ? sampleinput.args.join(', ') : 'no-args')}`
7195
- });
7338
+ if (length > 1) {
7339
+ if (sampleinput.convoPostfix) {
7340
+ Object.assign(currentConvoLabeled.header, {
7341
+ name: `${currentConvo.header.name}/${ui.name}-${sampleinput.convoPostfix}`
7342
+ });
7343
+ } else {
7344
+ const lineTag = `${index + 1}`.padStart(`${length}`.length, '0');
7345
+ Object.assign(currentConvoLabeled.header, {
7346
+ name: `${currentConvo.header.name}/${ui.name}-${utterancePostfix(lineTag, sampleinput.args && sampleinput.args.length ? sampleinput.args.join(', ') : 'no-args')}`
7347
+ });
7348
+ }
7349
+ }
7196
7350
 
7197
- this._expandConvo(expandedConvos, currentConvoLabeled, convoStepIndex + 1, currentStepsStack, myContext || context);
7198
- };
7351
+ yield* this._expandConvo(currentConvoLabeled, options, myContext || context, convoStepIndex + 1, currentStepsStack);
7352
+ }.bind(this);
7199
7353
 
7200
- if (this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE] === 'index') {
7354
+ if (expandedUserInputs.length === 1) {
7355
+ yield* processSampleInputs([expandedUserInputs[0]], context, uiIndex);
7356
+ } else if (this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE] === 'index') {
7201
7357
  if (lodash__default["default"].isNil(context.indexExpansionModeWidth)) {
7202
- processSampleInputs(expandedUserInputs, Object.assign({}, context, {
7358
+ yield* processSampleInputs(expandedUserInputs, Object.assign({}, context, {
7203
7359
  indexExpansionModeWidth: expandedUserInputs.length
7204
7360
  }), uiIndex);
7205
7361
  } else {
@@ -7217,7 +7373,7 @@ var ScriptingProvider_1 = class ScriptingProvider {
7217
7373
  const myContext = Object.assign({}, context, {
7218
7374
  indexExpansionModeWidth: Math.max(expandedUserInputs.length, context.indexExpansionModeWidth)
7219
7375
  });
7220
- processSampleInput(expandedUserInputs[localIndex], expandedUserInputs.length, localIndex, myContext, uiIndex);
7376
+ yield* processSampleInput(expandedUserInputs[localIndex], expandedUserInputs.length, localIndex, myContext, uiIndex);
7221
7377
 
7222
7378
  if (expandedUserInputs.length > context.indexExpansionModeWidth && context.indexExpansionModeIndex + 1 === context.indexExpansionModeWidth) {
7223
7379
  debug$9(`While expanding convos by index found user input "${ui.name}, ${ui.args}" more examples (${expandedUserInputs.length}) as expected (${context.indexExpansionModeWidth})`);
@@ -7227,55 +7383,72 @@ var ScriptingProvider_1 = class ScriptingProvider {
7227
7383
  indexExpansionModeWidth: expandedUserInputs.length,
7228
7384
  indexExpansionModeIndex: i
7229
7385
  });
7230
- processSampleInput(expandedUserInputs[i], expandedUserInputs.length, i, myContext, uiIndex);
7386
+ yield* processSampleInput(expandedUserInputs[i], expandedUserInputs.length, i, myContext, uiIndex);
7231
7387
  }
7232
7388
  }
7233
7389
  }
7234
7390
  } else {
7235
7391
  if (this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE] === 'first') {
7236
- processSampleInputs([expandedUserInputs[0]], context, uiIndex);
7392
+ yield* processSampleInputs([expandedUserInputs[0]], context, uiIndex);
7237
7393
  } else if (this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE] === 'random') {
7238
- processSampleInputs(expandedUserInputs.map(x => ({
7394
+ yield* processSampleInputs(expandedUserInputs.map(x => ({
7239
7395
  x,
7240
7396
  r: Math.random()
7241
7397
  })).sort((a, b) => a.r - b.r).map(a => a.x).slice(0, this.caps[Capabilities.SCRIPTING_UTTEXPANSION_RANDOM_COUNT]), context, uiIndex);
7242
7398
  } else {
7243
- processSampleInputs(expandedUserInputs, context, uiIndex);
7399
+ yield* processSampleInputs(expandedUserInputs, context, uiIndex);
7244
7400
  }
7245
7401
  }
7246
7402
 
7247
7403
  useUnexpanded = false;
7248
7404
  }
7249
7405
  }
7250
- });
7406
+ }
7251
7407
  }
7252
7408
 
7253
7409
  if (useUnexpanded) {
7254
7410
  const currentStepsStack = convoStepsStack.slice();
7255
7411
  currentStepsStack.push(lodash__default["default"].cloneDeep(currentStep));
7256
-
7257
- this._expandConvo(expandedConvos, currentConvo, convoStepIndex + 1, currentStepsStack, context);
7412
+ yield* this._expandConvo(currentConvo, options, context, convoStepIndex + 1, currentStepsStack);
7258
7413
  }
7259
7414
  }
7260
7415
  } else {
7261
- expandedConvos.push(Object.assign(lodash__default["default"].cloneDeep(currentConvo), {
7416
+ const expanded = Object.assign(lodash__default["default"].cloneDeep(currentConvo), {
7262
7417
  conversation: lodash__default["default"].cloneDeep(convoStepsStack)
7263
- }));
7418
+ });
7419
+
7420
+ if (!options.convoFilter || options.convoFilter(expanded)) {
7421
+ context.count++;
7422
+ const logPerEntry = context.count < 10 ? 1 : context.count < 100 ? 10 : context.count < 1000 ? 100 : context.count < 10000 ? 1000 : 10000;
7423
+
7424
+ if (context.count % logPerEntry === 0) {
7425
+ debug$9(`Convo #${context.count} expanded (${expanded.header.name})`);
7426
+ }
7427
+
7428
+ yield expanded;
7429
+ }
7264
7430
  }
7265
7431
  }
7266
7432
 
7267
7433
  _sortConvos() {
7268
7434
  this.convos = lodash__default["default"].sortBy(this.convos, [convo => convo.header.sort || convo.header.name]);
7435
+
7436
+ this._updateConvos();
7437
+ }
7438
+
7439
+ _updateConvos() {
7269
7440
  let i = 0;
7270
7441
  this.convos.forEach(convo => {
7271
- convo.header.order = ++i;
7442
+ if (convo) {
7443
+ convo.header.order = ++i;
7272
7444
 
7273
- if (!convo.header.projectname) {
7274
- convo.header.projectname = this.caps[Capabilities.PROJECTNAME];
7275
- }
7445
+ if (!convo.header.projectname) {
7446
+ convo.header.projectname = this.caps[Capabilities.PROJECTNAME];
7447
+ }
7276
7448
 
7277
- if (!convo.header.testsessionname) {
7278
- convo.header.testsessionname = this.caps[Capabilities.TESTSESSIONNAME];
7449
+ if (!convo.header.testsessionname) {
7450
+ convo.header.testsessionname = this.caps[Capabilities.TESTSESSIONNAME];
7451
+ }
7279
7452
  }
7280
7453
  });
7281
7454
  }
@@ -7287,7 +7460,11 @@ var ScriptingProvider_1 = class ScriptingProvider {
7287
7460
  this.convos.push(convos);
7288
7461
  }
7289
7462
 
7290
- this._sortConvos();
7463
+ if (this.convos.filter(c => lodash__default["default"].isNil(c))) {
7464
+ this._updateConvos();
7465
+ } else {
7466
+ this._sortConvos();
7467
+ }
7291
7468
  }
7292
7469
 
7293
7470
  AddUtterances(utterances) {
@@ -7563,6 +7740,37 @@ var ScriptingProvider_1 = class ScriptingProvider {
7563
7740
  return ['digraph {', ...nodes, ...lines, '}'].join('\r\n');
7564
7741
  }
7565
7742
 
7743
+ GetAssertionCount(convo) {
7744
+ if (!convo) {
7745
+ return 0;
7746
+ }
7747
+
7748
+ let counter = 0;
7749
+
7750
+ for (const step of convo.conversation) {
7751
+ if (step.sender === 'bot') {
7752
+ let stepCounter = step.asserters ? step.asserters.length : 0;
7753
+
7754
+ if (step.messageText) {
7755
+ stepCounter++;
7756
+ }
7757
+
7758
+ stepCounter = stepCounter === 0 ? 1 : stepCounter;
7759
+ counter += stepCounter;
7760
+ }
7761
+ }
7762
+
7763
+ if (convo.convoBegin && convo.convoBegin.asserters) {
7764
+ counter += convo.convoBegin.asserters.length;
7765
+ }
7766
+
7767
+ if (convo.convoEnd && convo.convoEnd.asserters) {
7768
+ counter += convo.convoEnd.asserters.length;
7769
+ }
7770
+
7771
+ return counter === 0 ? 1 : counter;
7772
+ }
7773
+
7566
7774
  };
7567
7775
 
7568
7776
  var BaseRepo_1 = class BaseRepo {