botium-core 1.13.1 → 1.13.4
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/.eslintrc.js +6 -3
- package/dist/botium-cjs.js +291 -86
- package/dist/botium-cjs.js.map +1 -1
- package/dist/botium-es.js +290 -86
- package/dist/botium-es.js.map +1 -1
- package/package.json +3 -1
- package/src/Capabilities.js +4 -1
- package/src/Defaults.js +4 -0
- package/src/containers/plugins/SimpleRestContainer.js +23 -16
- package/src/grid/inbound/proxy.js +2 -1
- package/src/mocks/BotiumMockScripting.js +1 -0
- package/src/scripting/Convo.js +16 -10
- package/src/scripting/MatchFunctions.js +10 -0
- package/src/scripting/ScriptingProvider.js +162 -69
- package/src/scripting/logichook/LogicHookConsts.js +1 -1
- package/src/scripting/logichook/asserter/WerAsserter.js +59 -0
- package/src/scripting/logichook/logichooks/UpdateCustomLogicHook.js +3 -2
- package/test/compiler/compilercsv.spec.js +104 -3
- package/test/compiler/compilerjson.spec.js +0 -2
- package/test/compiler/compilerxlsx.spec.js +1 -1
- package/test/compiler/convos/csv/utterances_liveperson2.csv +12 -0
- package/test/connectors/simplerest.spec.js +1012 -969
- package/test/convo/fillAndApplyScriptingMemory.spec.js +804 -785
- package/test/convo/partialconvo.spec.js +345 -339
- package/test/driver/capabilities.spec.js +156 -151
- package/test/logichooks/hookfromsrc.spec.js +79 -73
- package/test/plugins/plugins.spec.js +44 -42
- package/test/scripting/asserters/buttonsAsserter.spec.js +257 -240
- package/test/scripting/asserters/cardsAsserter.spec.js +214 -212
- package/test/scripting/asserters/convos/wer_threshold_nok.yml +7 -0
- package/test/scripting/asserters/convos/wer_threshold_ok.yml +7 -0
- package/test/scripting/asserters/intentConfidenceAsserter.spec.js +34 -35
- package/test/scripting/asserters/jsonpathAsserter.spec.js +307 -308
- package/test/scripting/asserters/mediaAsserter.spec.js +236 -234
- package/test/scripting/asserters/werAsserter.spec.js +51 -0
- package/test/scripting/logichooks/setClearScriptingMemory.spec.js +202 -192
- package/test/scripting/matching/matchingmode.spec.js +306 -258
- package/test/scripting/scriptingProvider.spec.js +720 -630
- package/test/scripting/scriptingmemory/fillScriptingMemoryFromFile.spec.js +299 -281
- package/test/scripting/scriptingmemory/useScriptingMemoryForAssertion.spec.js +94 -80
- package/test/scripting/userinputs/defaultUserInputs.spec.js +233 -127
- package/test/scripting/userinputs/mediaInputConvos.spec.js +409 -403
- package/test/scripting/utteranceexpansion/associateByIndex.spec.js +259 -0
- package/test/scripting/utteranceexpansion/convos/associate_utterances_by_index.json +33 -0
- package/test/scripting/utteranceexpansion/convos/media.convo.txt +19 -0
- package/test/scripting/utteranceexpansion/files/step0voice0.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step0voice1.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step0voice2.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step1voice0.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice0.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice1.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice2.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice4.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice5.wav +0 -0
- package/test/security/allowUnsafe.spec.js +274 -268
- package/test/utils.spec.js +40 -38
package/dist/botium-es.js
CHANGED
|
@@ -20,6 +20,7 @@ import promise from 'promise.allsettled';
|
|
|
20
20
|
import uuid from 'uuid';
|
|
21
21
|
import jsonpath from 'jsonpath';
|
|
22
22
|
import isJson$1 from 'is-json';
|
|
23
|
+
import wordErrorRate from 'word-error-rate';
|
|
23
24
|
import esprima from 'esprima';
|
|
24
25
|
import markdownIt from 'markdown-it';
|
|
25
26
|
import xlsx from 'xlsx';
|
|
@@ -36,7 +37,7 @@ import express from 'express';
|
|
|
36
37
|
import bodyParser from 'body-parser';
|
|
37
38
|
|
|
38
39
|
var name = "botium-core";
|
|
39
|
-
var version$1 = "1.13.
|
|
40
|
+
var version$1 = "1.13.4";
|
|
40
41
|
var description = "The Selenium for Chatbots";
|
|
41
42
|
var main = "index.js";
|
|
42
43
|
var module = "dist/botium-es.js";
|
|
@@ -102,6 +103,7 @@ var dependencies = {
|
|
|
102
103
|
"swagger-ui-express": "^4.4.0",
|
|
103
104
|
uuid: "^8.3.2",
|
|
104
105
|
vm2: "^3.9.10",
|
|
106
|
+
"word-error-rate": "0.0.7",
|
|
105
107
|
"write-yaml": "^1.0.0",
|
|
106
108
|
xlsx: "^0.18.5",
|
|
107
109
|
xregexp: "^5.1.1",
|
|
@@ -118,6 +120,7 @@ var devDependencies = {
|
|
|
118
120
|
eslint: "^8.19.0",
|
|
119
121
|
"eslint-config-standard": "^17.0.0",
|
|
120
122
|
"eslint-plugin-import": "^2.26.0",
|
|
123
|
+
"eslint-plugin-mocha": "^10.1.0",
|
|
121
124
|
"eslint-plugin-n": "^15.2.4",
|
|
122
125
|
"eslint-plugin-promise": "^6.0.0",
|
|
123
126
|
"eslint-plugin-standard": "^4.1.0",
|
|
@@ -297,12 +300,15 @@ var Capabilities = {
|
|
|
297
300
|
SCRIPTING_ENABLE_MULTIPLE_ASSERT_ERRORS: 'SCRIPTING_ENABLE_MULTIPLE_ASSERT_ERRORS',
|
|
298
301
|
SCRIPTING_ENABLE_SKIP_ASSERT_ERRORS: 'SCRIPTING_ENABLE_SKIP_ASSERT_ERRORS',
|
|
299
302
|
SCRIPTING_FORCE_BOT_CONSUMED: 'SCRIPTING_FORCE_BOT_CONSUMED',
|
|
300
|
-
// regexp, regexpIgnoreCase, wildcard, wildcardIgnoreCase, wildcardExact, wildcardExactIgnoreCase, include, includeIgnoreCase, equals, equalsIgnoreCase
|
|
303
|
+
// regexp, regexpIgnoreCase, wildcard, wildcardIgnoreCase, wildcardExact, wildcardExactIgnoreCase, include, includeIgnoreCase, equals, equalsIgnoreCase, wer
|
|
301
304
|
SCRIPTING_MATCHING_MODE: 'SCRIPTING_MATCHING_MODE',
|
|
305
|
+
SCRIPTING_MATCHING_MODE_ARGS: 'SCRIPTING_MATCHING_MODE_ARGS',
|
|
302
306
|
// all, first, random
|
|
303
307
|
SCRIPTING_UTTEXPANSION_MODE: 'SCRIPTING_UTTEXPANSION_MODE',
|
|
304
308
|
SCRIPTING_UTTEXPANSION_RANDOM_COUNT: 'SCRIPTING_UTTEXPANSION_RANDOM_COUNT',
|
|
305
309
|
SCRIPTING_UTTEXPANSION_INCOMPREHENSION: 'SCRIPTING_UTTEXPANSION_INCOMPREHENSION',
|
|
310
|
+
SCRIPTING_UTTEXPANSION_INCOMPREHENSIONINTENTS: 'SCRIPTING_UTTEXPANSION_INCOMPREHENSIONINTENTS',
|
|
311
|
+
SCRIPTING_UTTEXPANSION_INCOMPREHENSIONUTTS: 'SCRIPTING_UTTEXPANSION_INCOMPREHENSIONUTTS',
|
|
306
312
|
SCRIPTING_UTTEXPANSION_USENAMEASINTENT: 'SCRIPTING_UTTEXPANSION_USENAMEASINTENT',
|
|
307
313
|
// justLineTag, utterance
|
|
308
314
|
SCRIPTING_UTTEXPANSION_NAMING_MODE: 'SCRIPTING_UTTEXPANSION_NAMING_MODE',
|
|
@@ -452,9 +458,12 @@ Capabilities.SCRIPTING_ENABLE_MULTIPLE_ASSERT_ERRORS;
|
|
|
452
458
|
Capabilities.SCRIPTING_ENABLE_SKIP_ASSERT_ERRORS;
|
|
453
459
|
Capabilities.SCRIPTING_FORCE_BOT_CONSUMED;
|
|
454
460
|
Capabilities.SCRIPTING_MATCHING_MODE;
|
|
461
|
+
Capabilities.SCRIPTING_MATCHING_MODE_ARGS;
|
|
455
462
|
Capabilities.SCRIPTING_UTTEXPANSION_MODE;
|
|
456
463
|
Capabilities.SCRIPTING_UTTEXPANSION_RANDOM_COUNT;
|
|
457
464
|
Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSION;
|
|
465
|
+
Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSIONINTENTS;
|
|
466
|
+
Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSIONUTTS;
|
|
458
467
|
Capabilities.SCRIPTING_UTTEXPANSION_USENAMEASINTENT;
|
|
459
468
|
Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE;
|
|
460
469
|
Capabilities.SCRIPTING_UTTEXPANSION_NAMING_UTTERANCE_MAX;
|
|
@@ -539,6 +548,10 @@ var Defaults$1 = {
|
|
|
539
548
|
[Capabilities.SCRIPTING_UTTEXPANSION_RANDOM_COUNT]: 1,
|
|
540
549
|
[Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE]: 'justLineTag',
|
|
541
550
|
[Capabilities.SCRIPTING_UTTEXPANSION_NAMING_UTTERANCE_MAX]: '16',
|
|
551
|
+
[Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSION]: null,
|
|
552
|
+
[Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSIONINTENTS]: [],
|
|
553
|
+
[Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSIONUTTS]: [],
|
|
554
|
+
[Capabilities.SCRIPTING_UTTEXPANSION_USENAMEASINTENT]: false,
|
|
542
555
|
[Capabilities.SCRIPTING_MEMORYEXPANSION_KEEP_ORIG]: false,
|
|
543
556
|
[Capabilities.SCRIPTING_ENABLE_SKIP_ASSERT_ERRORS]: false,
|
|
544
557
|
[Capabilities.SCRIPTING_FORCE_BOT_CONSUMED]: false,
|
|
@@ -1137,6 +1150,9 @@ var LogicHookConsts = {
|
|
|
1137
1150
|
}, {
|
|
1138
1151
|
name: 'TEXT_IC',
|
|
1139
1152
|
className: 'TextEqualsAnyICAsserter'
|
|
1153
|
+
}, {
|
|
1154
|
+
name: 'TEXT_WER',
|
|
1155
|
+
className: 'WerAsserter'
|
|
1140
1156
|
}, {
|
|
1141
1157
|
name: 'BOT_CONSUMED',
|
|
1142
1158
|
className: 'BotRepliesConsumedAsserter'
|
|
@@ -1673,6 +1689,7 @@ class BotiumMockAsserter$1 {
|
|
|
1673
1689
|
constructor(fromJson = {}) {
|
|
1674
1690
|
this.name = fromJson.name;
|
|
1675
1691
|
this.args = lodash.cloneDeep(fromJson.args);
|
|
1692
|
+
this.not = fromJson.not;
|
|
1676
1693
|
}
|
|
1677
1694
|
|
|
1678
1695
|
}
|
|
@@ -2839,7 +2856,7 @@ class ConvoStep$1 {
|
|
|
2839
2856
|
}
|
|
2840
2857
|
|
|
2841
2858
|
toString() {
|
|
2842
|
-
return (this.stepTag ? this.stepTag + ': ' : '') + '#' + this.sender + ' - ' + (this.optional ? '?' : '') + (this.not ? '!' : '') + (this.messageText || '') + (this.asserters && this.asserters.length > 0 ? ' ' + this.asserters.map(a => a.toString()).join('
|
|
2859
|
+
return (this.stepTag ? this.stepTag + ': ' : '') + '#' + this.sender + ' - ' + (this.optional ? '?' : '') + (this.not ? '!' : '') + (this.messageText || '') + (this.asserters && this.asserters.length > 0 ? ' ' + this.asserters.map(a => a.toString()).join(' ') : '') + (this.logicHooks && this.logicHooks.length > 0 ? ' ' + this.logicHooks.map(l => l.toString()).join(' ') : '') + (this.userInputs && this.userInputs.length > 0 ? ' ' + this.userInputs.map(u => u.toString()).join(' ') : '');
|
|
2843
2860
|
}
|
|
2844
2861
|
|
|
2845
2862
|
}
|
|
@@ -2874,6 +2891,16 @@ class Transcript {
|
|
|
2874
2891
|
|
|
2875
2892
|
}
|
|
2876
2893
|
|
|
2894
|
+
class TranscriptAttachment {
|
|
2895
|
+
constructor(fromJson = {}) {
|
|
2896
|
+
this.name = fromJson.name;
|
|
2897
|
+
this.mimeType = fromJson.mimeType;
|
|
2898
|
+
this.base64 = fromJson.base64;
|
|
2899
|
+
this.href = fromJson.href;
|
|
2900
|
+
}
|
|
2901
|
+
|
|
2902
|
+
}
|
|
2903
|
+
|
|
2877
2904
|
class TranscriptStep {
|
|
2878
2905
|
constructor({
|
|
2879
2906
|
expected,
|
|
@@ -3654,9 +3681,16 @@ class Convo$6 {
|
|
|
3654
3681
|
}
|
|
3655
3682
|
|
|
3656
3683
|
var Convo_1 = {
|
|
3657
|
-
ConvoHeader: ConvoHeader$1,
|
|
3658
3684
|
Convo: Convo$6,
|
|
3659
|
-
|
|
3685
|
+
ConvoHeader: ConvoHeader$1,
|
|
3686
|
+
ConvoStep: ConvoStep$1,
|
|
3687
|
+
ConvoStepAssert,
|
|
3688
|
+
ConvoStepLogicHook,
|
|
3689
|
+
ConvoStepUserInput,
|
|
3690
|
+
Transcript,
|
|
3691
|
+
TranscriptAttachment,
|
|
3692
|
+
TranscriptStep,
|
|
3693
|
+
TranscriptError
|
|
3660
3694
|
};
|
|
3661
3695
|
|
|
3662
3696
|
const {
|
|
@@ -3744,6 +3778,12 @@ const equals = ignoreCase => (botresponse, utterance) => {
|
|
|
3744
3778
|
return botresponse === utterance;
|
|
3745
3779
|
};
|
|
3746
3780
|
|
|
3781
|
+
const wer = () => (botresponse, utterance, args) => {
|
|
3782
|
+
botresponse = _normalize(botresponse || '');
|
|
3783
|
+
utterance = toString(utterance || '');
|
|
3784
|
+
return wordErrorRate.wordErrorRate(botresponse, utterance) <= args[0];
|
|
3785
|
+
};
|
|
3786
|
+
|
|
3747
3787
|
const getMatchFunction$1 = matchingMode => {
|
|
3748
3788
|
if (matchingMode === 'regexp' || matchingMode === 'regexpIgnoreCase') {
|
|
3749
3789
|
return regexp(matchingMode === 'regexpIgnoreCase');
|
|
@@ -3755,6 +3795,8 @@ const getMatchFunction$1 = matchingMode => {
|
|
|
3755
3795
|
return include(matchingMode === 'includeIgnoreCase' || matchingMode === 'includeLowerCase');
|
|
3756
3796
|
} else if (matchingMode === 'equals' || matchingMode === 'equalsIgnoreCase') {
|
|
3757
3797
|
return equals(matchingMode === 'equalsIgnoreCase');
|
|
3798
|
+
} else if (matchingMode === 'wer') {
|
|
3799
|
+
return wer();
|
|
3758
3800
|
} else {
|
|
3759
3801
|
return equals(false);
|
|
3760
3802
|
}
|
|
@@ -3766,6 +3808,7 @@ var MatchFunctions = {
|
|
|
3766
3808
|
wildcardExact,
|
|
3767
3809
|
include,
|
|
3768
3810
|
equals,
|
|
3811
|
+
wer,
|
|
3769
3812
|
getMatchFunction: getMatchFunction$1
|
|
3770
3813
|
};
|
|
3771
3814
|
|
|
@@ -6130,7 +6173,9 @@ var ScriptingProvider_1 = class ScriptingProvider {
|
|
|
6130
6173
|
|
|
6131
6174
|
debug$9(`assertBotResponse ${stepTag} ${meMsg ? `(${meMsg}) ` : ''}BOT: ${botresponse} = ${tomatch} ...`);
|
|
6132
6175
|
|
|
6133
|
-
const found = lodash.find(tomatch, utt => this.matchFn(botresponse, utt));
|
|
6176
|
+
const found = lodash.find(tomatch, utt => this.matchFn(botresponse, utt, this.caps[Capabilities.SCRIPTING_MATCHING_MODE_ARGS]));
|
|
6177
|
+
|
|
6178
|
+
const asserterType = this.caps[Capabilities.SCRIPTING_MATCHING_MODE] === 'wer' ? 'WerAsserter' : 'TextMatchAsserter';
|
|
6134
6179
|
|
|
6135
6180
|
if (lodash.isNil(found)) {
|
|
6136
6181
|
let message = `${stepTag}: Bot response `;
|
|
@@ -6141,7 +6186,7 @@ var ScriptingProvider_1 = class ScriptingProvider {
|
|
|
6141
6186
|
message += `${tomatch.map(e => e ? '"' + e + '"' : '<any response>').join(', ')}`;
|
|
6142
6187
|
throw new BotiumError$2(message, {
|
|
6143
6188
|
type: 'asserter',
|
|
6144
|
-
source:
|
|
6189
|
+
source: asserterType,
|
|
6145
6190
|
context: {
|
|
6146
6191
|
stepTag
|
|
6147
6192
|
},
|
|
@@ -6160,7 +6205,9 @@ var ScriptingProvider_1 = class ScriptingProvider {
|
|
|
6160
6205
|
|
|
6161
6206
|
debug$9(`assertBotNotResponse ${stepTag} ${meMsg ? `(${meMsg}) ` : ''}BOT: ${botresponse} != ${nottomatch} ...`);
|
|
6162
6207
|
|
|
6163
|
-
const found = lodash.find(nottomatch, utt => this.matchFn(botresponse, utt));
|
|
6208
|
+
const found = lodash.find(nottomatch, utt => this.matchFn(botresponse, utt, this.caps[Capabilities.SCRIPTING_MATCHING_MODE_ARGS]));
|
|
6209
|
+
|
|
6210
|
+
const asserterType = this.caps[Capabilities.SCRIPTING_MATCHING_MODE] === 'wer' ? 'WerAsserter' : 'TextMatchAsserter';
|
|
6164
6211
|
|
|
6165
6212
|
if (!lodash.isNil(found)) {
|
|
6166
6213
|
let message = `${stepTag}: Bot response `;
|
|
@@ -6171,7 +6218,7 @@ var ScriptingProvider_1 = class ScriptingProvider {
|
|
|
6171
6218
|
message += `${nottomatch.map(e => e ? '"' + e + '"' : '<any response>').join(', ')}`;
|
|
6172
6219
|
throw new BotiumError$2(message, {
|
|
6173
6220
|
type: 'asserter',
|
|
6174
|
-
source:
|
|
6221
|
+
source: asserterType,
|
|
6175
6222
|
context: {
|
|
6176
6223
|
stepTag
|
|
6177
6224
|
},
|
|
@@ -6418,7 +6465,7 @@ var ScriptingProvider_1 = class ScriptingProvider {
|
|
|
6418
6465
|
}
|
|
6419
6466
|
|
|
6420
6467
|
Match(botresponse, utterance) {
|
|
6421
|
-
return this.matchFn(botresponse, utterance);
|
|
6468
|
+
return this.matchFn(botresponse, utterance, this.caps[Capabilities.SCRIPTING_MATCHING_MODE_ARGS]);
|
|
6422
6469
|
}
|
|
6423
6470
|
|
|
6424
6471
|
Compile(scriptBuffer, scriptFormat, scriptType) {
|
|
@@ -6850,6 +6897,8 @@ var ScriptingProvider_1 = class ScriptingProvider {
|
|
|
6850
6897
|
|
|
6851
6898
|
ExpandUtterancesToConvos({
|
|
6852
6899
|
useNameAsIntent,
|
|
6900
|
+
incomprehensionIntents,
|
|
6901
|
+
incomprehensionUtts,
|
|
6853
6902
|
incomprehensionUtt
|
|
6854
6903
|
} = {}) {
|
|
6855
6904
|
const expandedConvos = [];
|
|
@@ -6858,26 +6907,81 @@ var ScriptingProvider_1 = class ScriptingProvider {
|
|
|
6858
6907
|
useNameAsIntent = !!this.caps[Capabilities.SCRIPTING_UTTEXPANSION_USENAMEASINTENT];
|
|
6859
6908
|
}
|
|
6860
6909
|
|
|
6910
|
+
if (lodash.isUndefined(incomprehensionIntents)) {
|
|
6911
|
+
incomprehensionIntents = this.caps[Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSIONINTENTS];
|
|
6912
|
+
}
|
|
6913
|
+
|
|
6914
|
+
if (lodash.isUndefined(incomprehensionUtts)) {
|
|
6915
|
+
incomprehensionUtts = this.caps[Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSIONUTTS];
|
|
6916
|
+
}
|
|
6917
|
+
|
|
6861
6918
|
if (lodash.isUndefined(incomprehensionUtt)) {
|
|
6862
6919
|
incomprehensionUtt = this.caps[Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSION];
|
|
6863
6920
|
}
|
|
6864
6921
|
|
|
6865
|
-
if (
|
|
6866
|
-
throw new Error(
|
|
6922
|
+
if (incomprehensionUtt && (!incomprehensionUtts || incomprehensionUtts.length === 0) && !this.utterances[incomprehensionUtt]) {
|
|
6923
|
+
throw new Error(`ExpandUtterancesToConvos - incomprehension utterance '${incomprehensionUtt}' undefined (and no user examples given)`);
|
|
6867
6924
|
}
|
|
6868
6925
|
|
|
6869
|
-
if (
|
|
6870
|
-
|
|
6926
|
+
if (incomprehensionUtts && incomprehensionUtts.length > 0) {
|
|
6927
|
+
if (!incomprehensionUtt) {
|
|
6928
|
+
incomprehensionUtt = 'UTT_INCOMPREHENSION';
|
|
6929
|
+
}
|
|
6930
|
+
|
|
6931
|
+
if (this.utterances[incomprehensionUtt]) {
|
|
6932
|
+
this.utterances[incomprehensionUtt].utterances.push(...incomprehensionUtts);
|
|
6933
|
+
} else {
|
|
6934
|
+
this.utterances[incomprehensionUtt] = {
|
|
6935
|
+
name: incomprehensionUtt,
|
|
6936
|
+
utterances: [...incomprehensionUtts]
|
|
6937
|
+
};
|
|
6938
|
+
}
|
|
6871
6939
|
}
|
|
6872
6940
|
|
|
6873
6941
|
if (useNameAsIntent) {
|
|
6874
6942
|
debug$9('ExpandUtterancesToConvos - Using utterance name as NLU intent');
|
|
6875
|
-
}
|
|
6876
|
-
|
|
6943
|
+
}
|
|
6944
|
+
|
|
6945
|
+
if (incomprehensionIntents && incomprehensionIntents.length > 0) {
|
|
6946
|
+
debug$9(`ExpandUtterancesToConvos - Using ${incomprehensionIntents.length} incomprehension NLU intent(s)`);
|
|
6947
|
+
}
|
|
6948
|
+
|
|
6949
|
+
if (incomprehensionUtt) {
|
|
6950
|
+
debug$9(`ExpandUtterancesToConvos - Using incomprehension utterance expansion mode: ${incomprehensionUtt}, ${this.utterances[incomprehensionUtt].utterances.length} user example(s)`);
|
|
6877
6951
|
}
|
|
6878
6952
|
|
|
6879
6953
|
lodash.keys(this.utterances).filter(u => u !== incomprehensionUtt).forEach(uttName => {
|
|
6880
6954
|
const utt = this.utterances[uttName];
|
|
6955
|
+
const responseStep = {
|
|
6956
|
+
sender: 'bot',
|
|
6957
|
+
messageText: '',
|
|
6958
|
+
asserters: [],
|
|
6959
|
+
stepTag: 'Step 2 - check bot response',
|
|
6960
|
+
not: false
|
|
6961
|
+
};
|
|
6962
|
+
|
|
6963
|
+
if (useNameAsIntent) {
|
|
6964
|
+
responseStep.asserters.push({
|
|
6965
|
+
name: 'INTENT',
|
|
6966
|
+
args: [utt.name]
|
|
6967
|
+
});
|
|
6968
|
+
}
|
|
6969
|
+
|
|
6970
|
+
if (incomprehensionIntents && incomprehensionIntents.length > 0) {
|
|
6971
|
+
incomprehensionIntents.forEach(ii => {
|
|
6972
|
+
responseStep.asserters.push({
|
|
6973
|
+
name: 'INTENT',
|
|
6974
|
+
args: [ii],
|
|
6975
|
+
not: true
|
|
6976
|
+
});
|
|
6977
|
+
});
|
|
6978
|
+
}
|
|
6979
|
+
|
|
6980
|
+
if (incomprehensionUtt) {
|
|
6981
|
+
responseStep.messageText = incomprehensionUtt;
|
|
6982
|
+
responseStep.not = true;
|
|
6983
|
+
}
|
|
6984
|
+
|
|
6881
6985
|
expandedConvos.push(new Convo(this._buildScriptContext(), {
|
|
6882
6986
|
header: {
|
|
6883
6987
|
name: utt.name,
|
|
@@ -6890,25 +6994,7 @@ var ScriptingProvider_1 = class ScriptingProvider {
|
|
|
6890
6994
|
}],
|
|
6891
6995
|
messageText: utt.name,
|
|
6892
6996
|
stepTag: 'Step 1 - tell utterance'
|
|
6893
|
-
},
|
|
6894
|
-
sender: 'bot',
|
|
6895
|
-
asserters: [{
|
|
6896
|
-
name: 'INTENT',
|
|
6897
|
-
args: [utt.name]
|
|
6898
|
-
}],
|
|
6899
|
-
stepTag: 'Step 2 - check intent',
|
|
6900
|
-
not: false
|
|
6901
|
-
} : incomprehensionUtt ? {
|
|
6902
|
-
sender: 'bot',
|
|
6903
|
-
messageText: incomprehensionUtt,
|
|
6904
|
-
stepTag: 'Step 2 - check incomprehension',
|
|
6905
|
-
not: true
|
|
6906
|
-
} : {
|
|
6907
|
-
sender: 'bot',
|
|
6908
|
-
messageText: '',
|
|
6909
|
-
stepTag: 'Step 2 - check bot response',
|
|
6910
|
-
not: false
|
|
6911
|
-
}],
|
|
6997
|
+
}, responseStep],
|
|
6912
6998
|
sourceTag: Object.assign({}, utt.sourceTag, {
|
|
6913
6999
|
origUttName: utt.name
|
|
6914
7000
|
})
|
|
@@ -6938,11 +7024,12 @@ var ScriptingProvider_1 = class ScriptingProvider {
|
|
|
6938
7024
|
* @param currentConvo
|
|
6939
7025
|
* @param convoStepIndex
|
|
6940
7026
|
* @param convoStepsStack list of ConvoSteps
|
|
7027
|
+
* @param context {width: }
|
|
6941
7028
|
* @private
|
|
6942
7029
|
*/
|
|
6943
7030
|
|
|
6944
7031
|
|
|
6945
|
-
_expandConvo(expandedConvos, currentConvo, convoStepIndex = 0, convoStepsStack = []) {
|
|
7032
|
+
_expandConvo(expandedConvos, currentConvo, convoStepIndex = 0, convoStepsStack = [], context = {}) {
|
|
6946
7033
|
const utterancePostfix = (lineTag, uttOrUserInput) => {
|
|
6947
7034
|
const naming = this.caps[Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE] || Defaults$1.capabilities[Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE];
|
|
6948
7035
|
|
|
@@ -6969,7 +7056,7 @@ var ScriptingProvider_1 = class ScriptingProvider {
|
|
|
6969
7056
|
const currentStepsStack = convoStepsStack.slice();
|
|
6970
7057
|
currentStepsStack.push(lodash.cloneDeep(currentStep));
|
|
6971
7058
|
|
|
6972
|
-
this._expandConvo(expandedConvos, currentConvo, convoStepIndex + 1, currentStepsStack);
|
|
7059
|
+
this._expandConvo(expandedConvos, currentConvo, convoStepIndex + 1, currentStepsStack, context);
|
|
6973
7060
|
} else if (currentStep.sender === 'me') {
|
|
6974
7061
|
let useUnexpanded = true;
|
|
6975
7062
|
|
|
@@ -6990,39 +7077,87 @@ var ScriptingProvider_1 = class ScriptingProvider {
|
|
|
6990
7077
|
|
|
6991
7078
|
if (this.utterances[uttName]) {
|
|
6992
7079
|
const allutterances = this.utterances[uttName].utterances;
|
|
6993
|
-
let sampleutterances = allutterances;
|
|
6994
|
-
|
|
6995
|
-
if (this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE] === 'first') {
|
|
6996
|
-
sampleutterances = [allutterances[0]];
|
|
6997
|
-
} else if (this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE] === 'random') {
|
|
6998
|
-
sampleutterances = allutterances.map(x => ({
|
|
6999
|
-
x,
|
|
7000
|
-
r: Math.random()
|
|
7001
|
-
})).sort((a, b) => a.r - b.r).map(a => a.x).slice(0, this.caps[Capabilities.SCRIPTING_UTTEXPANSION_RANDOM_COUNT]);
|
|
7002
|
-
}
|
|
7003
7080
|
|
|
7004
|
-
sampleutterances
|
|
7005
|
-
|
|
7081
|
+
const processSampleUtterances = (sampleutterances, myContext) => {
|
|
7082
|
+
sampleutterances.forEach((utt, index) => {
|
|
7083
|
+
processSampleUtterance(utt, sampleutterances.length, index, Object.assign({
|
|
7084
|
+
indexExpansionModeIndex: index
|
|
7085
|
+
}, myContext || context));
|
|
7086
|
+
});
|
|
7087
|
+
};
|
|
7088
|
+
|
|
7089
|
+
const processSampleUtterance = (sampleutterance, length, index, myContext) => {
|
|
7090
|
+
const lineTag = `${index + 1}`.padStart(`${length}`.length, '0');
|
|
7006
7091
|
const currentStepsStack = convoStepsStack.slice();
|
|
7007
7092
|
|
|
7008
7093
|
if (uttArgs) {
|
|
7009
|
-
|
|
7094
|
+
sampleutterance = util.format(sampleutterance, ...uttArgs);
|
|
7010
7095
|
}
|
|
7011
7096
|
|
|
7012
7097
|
currentStepsStack.push(Object.assign(lodash.cloneDeep(currentStep), {
|
|
7013
|
-
messageText:
|
|
7098
|
+
messageText: sampleutterance
|
|
7014
7099
|
}));
|
|
7015
7100
|
|
|
7016
7101
|
const currentConvoLabeled = lodash.cloneDeep(currentConvo);
|
|
7017
7102
|
|
|
7018
7103
|
Object.assign(currentConvoLabeled.header, {
|
|
7019
|
-
name: `${currentConvo.header.name}/${uttName}-${utterancePostfix(lineTag,
|
|
7104
|
+
name: `${currentConvo.header.name}/${uttName}-${utterancePostfix(lineTag, sampleutterance)}`
|
|
7020
7105
|
});
|
|
7021
7106
|
if (!currentConvoLabeled.sourceTag) currentConvoLabeled.sourceTag = {};
|
|
7022
7107
|
if (!currentConvoLabeled.sourceTag.origConvoName) currentConvoLabeled.sourceTag.origConvoName = currentConvo.header.name;
|
|
7023
7108
|
|
|
7024
|
-
this._expandConvo(expandedConvos, currentConvoLabeled, convoStepIndex + 1, currentStepsStack);
|
|
7025
|
-
}
|
|
7109
|
+
this._expandConvo(expandedConvos, currentConvoLabeled, convoStepIndex + 1, currentStepsStack, myContext || context);
|
|
7110
|
+
};
|
|
7111
|
+
|
|
7112
|
+
if (this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE] === 'index') {
|
|
7113
|
+
if (lodash.isNil(context.indexExpansionModeWidth)) {
|
|
7114
|
+
// executed for the first found utterance
|
|
7115
|
+
processSampleUtterances(allutterances, Object.assign({}, context, {
|
|
7116
|
+
indexExpansionModeWidth: allutterances.length
|
|
7117
|
+
}));
|
|
7118
|
+
} else {
|
|
7119
|
+
if (lodash.isNil(context.indexExpansionModeIndex)) {
|
|
7120
|
+
throw new Error('indexExpansionModeIndex must be set!');
|
|
7121
|
+
} // executing the current 'thread', if current utterance has no example to current index, fallback to the last one
|
|
7122
|
+
|
|
7123
|
+
|
|
7124
|
+
const localIndex = Math.min(context.indexExpansionModeIndex, allutterances.length - 1);
|
|
7125
|
+
|
|
7126
|
+
if (localIndex < context.indexExpansionModeIndex && context.indexExpansionModeIndex === context.indexExpansionModeWidth - 1) {
|
|
7127
|
+
debug$9(`While expanding convos by index found in utterance "${uttName}" less examples (${allutterances.length}) as expected (${context.indexExpansionModeWidth})`);
|
|
7128
|
+
}
|
|
7129
|
+
|
|
7130
|
+
const myContext = Object.assign({}, context, {
|
|
7131
|
+
indexExpansionModeWidth: Math.max(allutterances.length, context.indexExpansionModeWidth)
|
|
7132
|
+
});
|
|
7133
|
+
processSampleUtterance(allutterances[localIndex], allutterances.length, localIndex, myContext);
|
|
7134
|
+
|
|
7135
|
+
if (allutterances.length > context.indexExpansionModeWidth && context.indexExpansionModeIndex + 1 === context.indexExpansionModeWidth) {
|
|
7136
|
+
debug$9(`While expanding convos by index found in utterance "${uttName}" more examples (${allutterances.length}) as expected (${context.indexExpansionModeWidth})`);
|
|
7137
|
+
|
|
7138
|
+
for (let i = context.indexExpansionModeWidth; i < allutterances.length; i++) {
|
|
7139
|
+
// if we found a utterance with more examples as any utterances before, we have to start new 'thread'
|
|
7140
|
+
const myContext = Object.assign({}, context, {
|
|
7141
|
+
indexExpansionModeWidth: allutterances.length,
|
|
7142
|
+
indexExpansionModeIndex: i
|
|
7143
|
+
});
|
|
7144
|
+
processSampleUtterance(allutterances[i], allutterances.length, i, myContext);
|
|
7145
|
+
}
|
|
7146
|
+
}
|
|
7147
|
+
}
|
|
7148
|
+
} else {
|
|
7149
|
+
if (this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE] === 'first') {
|
|
7150
|
+
processSampleUtterances([allutterances[0]]);
|
|
7151
|
+
} else if (this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE] === 'random') {
|
|
7152
|
+
processSampleUtterances(allutterances.map(x => ({
|
|
7153
|
+
x,
|
|
7154
|
+
r: Math.random()
|
|
7155
|
+
})).sort((a, b) => a.r - b.r).map(a => a.x).slice(0, this.caps[Capabilities.SCRIPTING_UTTEXPANSION_RANDOM_COUNT]));
|
|
7156
|
+
} else {
|
|
7157
|
+
processSampleUtterances(allutterances);
|
|
7158
|
+
}
|
|
7159
|
+
}
|
|
7160
|
+
|
|
7026
7161
|
useUnexpanded = false;
|
|
7027
7162
|
}
|
|
7028
7163
|
}
|
|
@@ -7039,19 +7174,17 @@ var ScriptingProvider_1 = class ScriptingProvider {
|
|
|
7039
7174
|
});
|
|
7040
7175
|
|
|
7041
7176
|
if (expandedUserInputs && expandedUserInputs.length > 0) {
|
|
7042
|
-
let sampleinputs = expandedUserInputs
|
|
7043
|
-
|
|
7044
|
-
|
|
7045
|
-
|
|
7046
|
-
|
|
7047
|
-
|
|
7048
|
-
|
|
7049
|
-
|
|
7050
|
-
})).sort((a, b) => a.r - b.r).map(a => a.x).slice(0, this.caps[Capabilities.SCRIPTING_UTTEXPANSION_RANDOM_COUNT]);
|
|
7051
|
-
}
|
|
7177
|
+
// let sampleinputs = expandedUserInputs
|
|
7178
|
+
const processSampleInputs = (sampleinputs, myContext, uiIndex) => {
|
|
7179
|
+
sampleinputs.forEach((input, index) => {
|
|
7180
|
+
processSampleInput(input, sampleinputs.length, index, Object.assign({
|
|
7181
|
+
indexExpansionModeIndex: index
|
|
7182
|
+
}, myContext || context), uiIndex);
|
|
7183
|
+
});
|
|
7184
|
+
};
|
|
7052
7185
|
|
|
7053
|
-
|
|
7054
|
-
const lineTag = `${index + 1}`.padStart(`${
|
|
7186
|
+
const processSampleInput = (sampleinput, length, index, myContext, uiIndex) => {
|
|
7187
|
+
const lineTag = `${index + 1}`.padStart(`${length}`.length, '0');
|
|
7055
7188
|
const currentStepsStack = convoStepsStack.slice();
|
|
7056
7189
|
|
|
7057
7190
|
const currentStepMod = lodash.cloneDeep(currentStep);
|
|
@@ -7065,8 +7198,56 @@ var ScriptingProvider_1 = class ScriptingProvider {
|
|
|
7065
7198
|
name: `${currentConvo.header.name}/${ui.name}-${utterancePostfix(lineTag, sampleinput.args && sampleinput.args.length ? sampleinput.args.join(', ') : 'no-args')}`
|
|
7066
7199
|
});
|
|
7067
7200
|
|
|
7068
|
-
this._expandConvo(expandedConvos, currentConvoLabeled, convoStepIndex + 1, currentStepsStack);
|
|
7069
|
-
}
|
|
7201
|
+
this._expandConvo(expandedConvos, currentConvoLabeled, convoStepIndex + 1, currentStepsStack, myContext || context);
|
|
7202
|
+
};
|
|
7203
|
+
|
|
7204
|
+
if (this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE] === 'index') {
|
|
7205
|
+
if (lodash.isNil(context.indexExpansionModeWidth)) {
|
|
7206
|
+
processSampleInputs(expandedUserInputs, Object.assign({}, context, {
|
|
7207
|
+
indexExpansionModeWidth: expandedUserInputs.length
|
|
7208
|
+
}), uiIndex);
|
|
7209
|
+
} else {
|
|
7210
|
+
if (lodash.isNil(context.indexExpansionModeIndex)) {
|
|
7211
|
+
throw new Error('indexExpansionModeIndex must be set!');
|
|
7212
|
+
} // executing the current 'thread', if current utterance has no example to current index, fallback to the last one
|
|
7213
|
+
|
|
7214
|
+
|
|
7215
|
+
const localIndex = Math.min(context.indexExpansionModeIndex, expandedUserInputs.length - 1);
|
|
7216
|
+
|
|
7217
|
+
if (localIndex < context.indexExpansionModeIndex && context.indexExpansionModeIndex === context.indexExpansionModeWidth - 1) {
|
|
7218
|
+
debug$9(`While expanding convos by index found user input "${ui.name}, ${ui.args}" less examples (${expandedUserInputs.length}) as expected (${context.indexExpansionModeWidth})`);
|
|
7219
|
+
}
|
|
7220
|
+
|
|
7221
|
+
const myContext = Object.assign({}, context, {
|
|
7222
|
+
indexExpansionModeWidth: Math.max(expandedUserInputs.length, context.indexExpansionModeWidth)
|
|
7223
|
+
});
|
|
7224
|
+
processSampleInput(expandedUserInputs[localIndex], expandedUserInputs.length, localIndex, myContext, uiIndex);
|
|
7225
|
+
|
|
7226
|
+
if (expandedUserInputs.length > context.indexExpansionModeWidth && context.indexExpansionModeIndex + 1 === context.indexExpansionModeWidth) {
|
|
7227
|
+
debug$9(`While expanding convos by index found user input "${ui.name}, ${ui.args}" more examples (${expandedUserInputs.length}) as expected (${context.indexExpansionModeWidth})`);
|
|
7228
|
+
|
|
7229
|
+
for (let i = context.indexExpansionModeWidth; i < expandedUserInputs.length; i++) {
|
|
7230
|
+
const myContext = Object.assign({}, context, {
|
|
7231
|
+
indexExpansionModeWidth: expandedUserInputs.length,
|
|
7232
|
+
indexExpansionModeIndex: i
|
|
7233
|
+
});
|
|
7234
|
+
processSampleInput(expandedUserInputs[i], expandedUserInputs.length, i, myContext, uiIndex);
|
|
7235
|
+
}
|
|
7236
|
+
}
|
|
7237
|
+
}
|
|
7238
|
+
} else {
|
|
7239
|
+
if (this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE] === 'first') {
|
|
7240
|
+
processSampleInputs([expandedUserInputs[0]], context, uiIndex);
|
|
7241
|
+
} else if (this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE] === 'random') {
|
|
7242
|
+
processSampleInputs(expandedUserInputs.map(x => ({
|
|
7243
|
+
x,
|
|
7244
|
+
r: Math.random()
|
|
7245
|
+
})).sort((a, b) => a.r - b.r).map(a => a.x).slice(0, this.caps[Capabilities.SCRIPTING_UTTEXPANSION_RANDOM_COUNT]), context, uiIndex);
|
|
7246
|
+
} else {
|
|
7247
|
+
processSampleInputs(expandedUserInputs, context, uiIndex);
|
|
7248
|
+
}
|
|
7249
|
+
}
|
|
7250
|
+
|
|
7070
7251
|
useUnexpanded = false;
|
|
7071
7252
|
}
|
|
7072
7253
|
}
|
|
@@ -7077,7 +7258,7 @@ var ScriptingProvider_1 = class ScriptingProvider {
|
|
|
7077
7258
|
const currentStepsStack = convoStepsStack.slice();
|
|
7078
7259
|
currentStepsStack.push(lodash.cloneDeep(currentStep));
|
|
7079
7260
|
|
|
7080
|
-
this._expandConvo(expandedConvos, currentConvo, convoStepIndex + 1, currentStepsStack);
|
|
7261
|
+
this._expandConvo(expandedConvos, currentConvo, convoStepIndex + 1, currentStepsStack, context);
|
|
7081
7262
|
}
|
|
7082
7263
|
}
|
|
7083
7264
|
} else {
|
|
@@ -8133,7 +8314,8 @@ const setupEndpoints = ({
|
|
|
8133
8314
|
processEvent({
|
|
8134
8315
|
originalUrl: req.originalUrl,
|
|
8135
8316
|
originalMethod: req.method,
|
|
8136
|
-
body: req.body
|
|
8317
|
+
body: req.body,
|
|
8318
|
+
headers: req.headers
|
|
8137
8319
|
});
|
|
8138
8320
|
res.status(200).json({}).end();
|
|
8139
8321
|
} else {
|
|
@@ -8238,7 +8420,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8238
8420
|
});
|
|
8239
8421
|
|
|
8240
8422
|
for (const event of sortedEvents) {
|
|
8241
|
-
setTimeout(() => this._processBodyAsync(event.body, true, !!this.caps[Capabilities.SIMPLEREST_INBOUND_UPDATE_CONTEXT]), 0);
|
|
8423
|
+
setTimeout(() => this._processBodyAsync(event.body, event.headers, true, !!this.caps[Capabilities.SIMPLEREST_INBOUND_UPDATE_CONTEXT]), 0);
|
|
8242
8424
|
}
|
|
8243
8425
|
}, debounceTimeout);
|
|
8244
8426
|
}
|
|
@@ -8333,12 +8515,15 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8333
8515
|
this._startPolling().then(() => startPollingComplete()).catch(startPollingComplete);
|
|
8334
8516
|
}, pingComplete => {
|
|
8335
8517
|
if (this.caps[Capabilities.SIMPLEREST_PING_URL]) {
|
|
8336
|
-
this._makeCall('SIMPLEREST_PING').then(
|
|
8518
|
+
this._makeCall('SIMPLEREST_PING').then(({
|
|
8519
|
+
body,
|
|
8520
|
+
headers
|
|
8521
|
+
}) => {
|
|
8337
8522
|
if (this.caps[Capabilities.SIMPLEREST_PING_UPDATE_CONTEXT] || this.caps[Capabilities.SIMPLEREST_PING_PROCESS_RESPONSE]) {
|
|
8338
8523
|
return this._parseResponseBody(body).then(body => {
|
|
8339
8524
|
if (body) {
|
|
8340
8525
|
debug$4(`Ping Uri ${this.caps[Capabilities.SIMPLEREST_PING_URL]} returned JSON response: ${Utils.shortenJsonString(body)}`);
|
|
8341
|
-
return this._processBodyAsync(body, !!this.caps[Capabilities.SIMPLEREST_PING_PROCESS_RESPONSE], !!this.caps[Capabilities.SIMPLEREST_PING_UPDATE_CONTEXT]);
|
|
8526
|
+
return this._processBodyAsync(body, headers, !!this.caps[Capabilities.SIMPLEREST_PING_PROCESS_RESPONSE], !!this.caps[Capabilities.SIMPLEREST_PING_UPDATE_CONTEXT]);
|
|
8342
8527
|
} else {
|
|
8343
8528
|
debug$4(`Ping Uri ${this.caps[Capabilities.SIMPLEREST_PING_URL]} didn't return JSON response, ignoring it.`);
|
|
8344
8529
|
}
|
|
@@ -8366,12 +8551,15 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8366
8551
|
this.processInbound = true;
|
|
8367
8552
|
|
|
8368
8553
|
if (this.caps[Capabilities.SIMPLEREST_START_URL]) {
|
|
8369
|
-
this._makeCall('SIMPLEREST_START').then(
|
|
8554
|
+
this._makeCall('SIMPLEREST_START').then(({
|
|
8555
|
+
body,
|
|
8556
|
+
headers
|
|
8557
|
+
}) => {
|
|
8370
8558
|
if (this.caps[Capabilities.SIMPLEREST_START_UPDATE_CONTEXT] || this.caps[Capabilities.SIMPLEREST_START_PROCESS_RESPONSE]) {
|
|
8371
8559
|
return this._parseResponseBody(body).then(body => {
|
|
8372
8560
|
if (body) {
|
|
8373
8561
|
debug$4(`Start Uri ${this.caps[Capabilities.SIMPLEREST_START_URL]} returned JSON response: ${Utils.shortenJsonString(body)}`);
|
|
8374
|
-
return this._processBodyAsync(body, !!this.caps[Capabilities.SIMPLEREST_START_PROCESS_RESPONSE], !!this.caps[Capabilities.SIMPLEREST_START_UPDATE_CONTEXT]);
|
|
8562
|
+
return this._processBodyAsync(body, headers, !!this.caps[Capabilities.SIMPLEREST_START_PROCESS_RESPONSE], !!this.caps[Capabilities.SIMPLEREST_START_UPDATE_CONTEXT]);
|
|
8375
8563
|
} else {
|
|
8376
8564
|
debug$4(`Start Uri ${this.caps[Capabilities.SIMPLEREST_START_URL]} didn't return JSON response, ignoring it.`);
|
|
8377
8565
|
}
|
|
@@ -8423,10 +8611,10 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8423
8611
|
} // Separated just for better module testing
|
|
8424
8612
|
|
|
8425
8613
|
|
|
8426
|
-
async _processBodyAsync(body, isFromUser, updateContext) {
|
|
8614
|
+
async _processBodyAsync(body, headers, isFromUser, updateContext) {
|
|
8427
8615
|
const p = async () => {
|
|
8428
8616
|
try {
|
|
8429
|
-
const results = await this._processBodyAsyncImpl(body, isFromUser, updateContext);
|
|
8617
|
+
const results = await this._processBodyAsyncImpl(body, headers, isFromUser, updateContext);
|
|
8430
8618
|
|
|
8431
8619
|
if (results) {
|
|
8432
8620
|
for (const result of results) {
|
|
@@ -8457,7 +8645,12 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8457
8645
|
} // Separated just for better module testing
|
|
8458
8646
|
|
|
8459
8647
|
|
|
8460
|
-
async _processBodyAsyncImpl(body, isFromUser, updateContext) {
|
|
8648
|
+
async _processBodyAsyncImpl(body, headers, isFromUser, updateContext) {
|
|
8649
|
+
this.view.response = {
|
|
8650
|
+
body,
|
|
8651
|
+
headers
|
|
8652
|
+
};
|
|
8653
|
+
|
|
8461
8654
|
if (updateContext) {
|
|
8462
8655
|
const mergeMode = this.caps[Capabilities.SIMPLEREST_CONTEXT_MERGE_OR_REPLACE];
|
|
8463
8656
|
const jsonPathsContext = getAllCapValues(Capabilities.SIMPLEREST_CONTEXT_JSONPATH, this.caps);
|
|
@@ -8667,7 +8860,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8667
8860
|
}
|
|
8668
8861
|
|
|
8669
8862
|
if (body) {
|
|
8670
|
-
debug$4(`got response code: ${response.statusCode}, body: ${Utils.shortenJsonString(body)}`);
|
|
8863
|
+
debug$4(`got response code: ${response.statusCode}, body: ${Utils.shortenJsonString(body)}, headers: ${Utils.shortenJsonString(response.headers)}`);
|
|
8671
8864
|
|
|
8672
8865
|
this._storeCookiesFromResponse(response);
|
|
8673
8866
|
|
|
@@ -8683,7 +8876,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8683
8876
|
}
|
|
8684
8877
|
|
|
8685
8878
|
if (body) {
|
|
8686
|
-
this._processBodyAsync(body, isFromUser, updateContext).then(() => resolve(this)).then(() => this._emptyWaitProcessQueue());
|
|
8879
|
+
this._processBodyAsync(body, response.headers, isFromUser, updateContext).then(() => resolve(this)).then(() => this._emptyWaitProcessQueue());
|
|
8687
8880
|
} else {
|
|
8688
8881
|
debug$4('ignoring response body (no string and no JSON object)');
|
|
8689
8882
|
resolve(this);
|
|
@@ -8745,6 +8938,10 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8745
8938
|
try {
|
|
8746
8939
|
requestOptions.body = this._getMustachedCap(Capabilities.SIMPLEREST_BODY_TEMPLATE, !bodyRaw);
|
|
8747
8940
|
requestOptions.json = !bodyRaw;
|
|
8941
|
+
|
|
8942
|
+
if (requestOptions.json && (!requestOptions.body || Object.keys(requestOptions.body).length === 0)) {
|
|
8943
|
+
debug$4(`warning: requestOptions.body content seems to be empty - ${requestOptions.body} - capability: "${this.caps[Capabilities.SIMPLEREST_BODY_TEMPLATE]}"`);
|
|
8944
|
+
}
|
|
8748
8945
|
} catch (err) {
|
|
8749
8946
|
throw new Error(`composing body from SIMPLEREST_BODY_TEMPLATE failed (${err.message})`);
|
|
8750
8947
|
}
|
|
@@ -8843,10 +9040,13 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8843
9040
|
this._storeCookiesFromResponse(response);
|
|
8844
9041
|
|
|
8845
9042
|
if (debug$4.enabled && body) {
|
|
8846
|
-
debug$4(Utils.shortenJsonString(body));
|
|
9043
|
+
debug$4(`body: ${Utils.shortenJsonString(body)}, headers: ${Utils.shortenJsonString(response.headers)}`);
|
|
8847
9044
|
}
|
|
8848
9045
|
|
|
8849
|
-
return
|
|
9046
|
+
return {
|
|
9047
|
+
body,
|
|
9048
|
+
headers: response.headers
|
|
9049
|
+
};
|
|
8850
9050
|
}
|
|
8851
9051
|
}
|
|
8852
9052
|
}
|
|
@@ -8890,7 +9090,11 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8890
9090
|
try {
|
|
8891
9091
|
return JSON.parse(raw);
|
|
8892
9092
|
} catch (err) {
|
|
8893
|
-
|
|
9093
|
+
if (debug$4.enabled) {
|
|
9094
|
+
debug$4(`JSON parsing failed (${err.message}) for: ${Utils.shortenJsonString(raw)}`);
|
|
9095
|
+
}
|
|
9096
|
+
|
|
9097
|
+
throw new Error(`JSON parsing failed - try to use {{#fnc.jsonify}}{{xxx}}{{/fnc.jsonify}} to escape JSON special characters (ERR: ${err.message})`);
|
|
8894
9098
|
}
|
|
8895
9099
|
} else {
|
|
8896
9100
|
return raw;
|
|
@@ -8935,7 +9139,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8935
9139
|
|
|
8936
9140
|
this._processOrderedInboundEventsArrayAsync();
|
|
8937
9141
|
} else {
|
|
8938
|
-
setTimeout(() => this._processBodyAsync(event.body, true, !!this.caps[Capabilities.SIMPLEREST_INBOUND_UPDATE_CONTEXT]), 0);
|
|
9142
|
+
setTimeout(() => this._processBodyAsync(event.body, event.headers, true, !!this.caps[Capabilities.SIMPLEREST_INBOUND_UPDATE_CONTEXT]), 0);
|
|
8939
9143
|
}
|
|
8940
9144
|
}
|
|
8941
9145
|
|
|
@@ -9076,7 +9280,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
9076
9280
|
debug$4(Utils.shortenJsonString(body));
|
|
9077
9281
|
}
|
|
9078
9282
|
} else if (body) {
|
|
9079
|
-
debug$4(`_runPolling: got response code: ${response.statusCode}, body: ${Utils.shortenJsonString(body)}`);
|
|
9283
|
+
debug$4(`_runPolling: got response code: ${response.statusCode}, body: ${Utils.shortenJsonString(body)}, headers: ${Utils.shortenJsonString(response.headers)}`);
|
|
9080
9284
|
|
|
9081
9285
|
this._storeCookiesFromResponse(response);
|
|
9082
9286
|
|
|
@@ -9088,7 +9292,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
9088
9292
|
}
|
|
9089
9293
|
|
|
9090
9294
|
if (body) {
|
|
9091
|
-
setTimeout(() => this._processBodyAsync(body, true, !!this.caps[Capabilities.SIMPLEREST_POLL_UPDATE_CONTEXT]), 0);
|
|
9295
|
+
setTimeout(() => this._processBodyAsync(body, response.headers, true, !!this.caps[Capabilities.SIMPLEREST_POLL_UPDATE_CONTEXT]), 0);
|
|
9092
9296
|
} else {
|
|
9093
9297
|
debug$4('_runPolling: ignoring response body (no string and no JSON object)');
|
|
9094
9298
|
}
|