@scout9/app 1.0.0-alpha.0.7.0 → 1.0.0-alpha.0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{dev-d74b94c8.cjs → dev-b1573a91.cjs} +2 -2
- package/dist/{index-ddb54eed.cjs → index-ee8d473f.cjs} +6 -6
- package/dist/index.cjs +3 -3
- package/dist/{multipart-parser-8ce4a465.cjs → multipart-parser-5a398f28.cjs} +3 -3
- package/dist/{spirits-59475def.cjs → spirits-8ee2b3b6.cjs} +206 -111
- package/dist/spirits.cjs +1 -1
- package/dist/testing-tools.cjs +2 -2
- package/package.json +1 -1
- package/src/testing-tools/spirits.js +8 -2
- package/types/index.d.ts +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var spirits = require("./spirits-
|
|
3
|
+
var spirits = require("./spirits-8ee2b3b6.cjs");
|
|
4
4
|
var require$$0$4 = require('util');
|
|
5
5
|
var require$$0$3 = require('stream');
|
|
6
6
|
var require$$1 = require('path');
|
|
@@ -35241,7 +35241,7 @@ function _loadUserPackageJson() {
|
|
|
35241
35241
|
targetPkgUrl = isTest ? packageTestJsonUrl : packageJsonUrl;
|
|
35242
35242
|
_context2.t0 = JSON;
|
|
35243
35243
|
_context2.next = 10;
|
|
35244
|
-
return fs__default["default"].readFile(new URL(targetPkgUrl, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('dev-
|
|
35244
|
+
return fs__default["default"].readFile(new URL(targetPkgUrl, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('dev-b1573a91.js', document.baseURI).href))), 'utf-8');
|
|
35245
35245
|
case 10:
|
|
35246
35246
|
_context2.t1 = _context2.sent;
|
|
35247
35247
|
pkg = _context2.t0.parse.call(_context2.t0, _context2.t1);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var spirits = require("./spirits-
|
|
4
|
-
var dev = require("./dev-
|
|
3
|
+
var spirits = require("./spirits-8ee2b3b6.cjs");
|
|
4
|
+
var dev = require("./dev-b1573a91.cjs");
|
|
5
5
|
var macros = require("./macros-22b2e0b8.cjs");
|
|
6
6
|
var require$$0 = require('fs');
|
|
7
7
|
var require$$2$1 = require('events');
|
|
@@ -29483,7 +29483,7 @@ class Body {
|
|
|
29483
29483
|
}
|
|
29484
29484
|
const {
|
|
29485
29485
|
toFormData
|
|
29486
|
-
} = await Promise.resolve().then(function () { return require("./multipart-parser-
|
|
29486
|
+
} = await Promise.resolve().then(function () { return require("./multipart-parser-5a398f28.cjs"); });
|
|
29487
29487
|
return toFormData(this.body, ct);
|
|
29488
29488
|
}
|
|
29489
29489
|
|
|
@@ -41884,7 +41884,7 @@ function _loadUserPackageJson() {
|
|
|
41884
41884
|
targetPkgUrl = isTest ? packageTestJsonUrl : packageJsonUrl;
|
|
41885
41885
|
_context.t0 = JSON;
|
|
41886
41886
|
_context.next = 10;
|
|
41887
|
-
return fs__default["default"].readFile(new URL(targetPkgUrl, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-
|
|
41887
|
+
return fs__default["default"].readFile(new URL(targetPkgUrl, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-ee8d473f.js', document.baseURI).href))), 'utf-8');
|
|
41888
41888
|
case 10:
|
|
41889
41889
|
_context.t1 = _context.sent;
|
|
41890
41890
|
pkg = _context.t0.parse.call(_context.t0, _context.t1);
|
|
@@ -43176,7 +43176,7 @@ var ProjectFiles = /*#__PURE__*/function () {
|
|
|
43176
43176
|
return ProjectFiles;
|
|
43177
43177
|
}();
|
|
43178
43178
|
|
|
43179
|
-
var __filename$1 = node_url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-
|
|
43179
|
+
var __filename$1 = node_url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-ee8d473f.js', document.baseURI).href)));
|
|
43180
43180
|
var __dirname$1 = path__default["default"].dirname(__filename$1);
|
|
43181
43181
|
function zipDirectory(source, out) {
|
|
43182
43182
|
var archive = archiver$1('tar', {
|
|
@@ -43391,7 +43391,7 @@ function _buildApp() {
|
|
|
43391
43391
|
case 11:
|
|
43392
43392
|
_context4.t0 = JSON;
|
|
43393
43393
|
_context4.next = 14;
|
|
43394
|
-
return fs__default["default"].readFile(new URL(templatePackagePath, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-
|
|
43394
|
+
return fs__default["default"].readFile(new URL(templatePackagePath, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-ee8d473f.js', document.baseURI).href))), 'utf-8');
|
|
43395
43395
|
case 14:
|
|
43396
43396
|
_context4.t1 = _context4.sent;
|
|
43397
43397
|
packageTemplate = _context4.t0.parse.call(_context4.t0, _context4.t1);
|
package/dist/index.cjs
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require("./index-
|
|
6
|
-
var dev = require("./dev-
|
|
7
|
-
require("./spirits-
|
|
5
|
+
var index = require("./index-ee8d473f.cjs");
|
|
6
|
+
var dev = require("./dev-b1573a91.cjs");
|
|
7
|
+
require("./spirits-8ee2b3b6.cjs");
|
|
8
8
|
require("./macros-22b2e0b8.cjs");
|
|
9
9
|
require('fs');
|
|
10
10
|
require('events');
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
require('node:fs');
|
|
4
4
|
require('node:path');
|
|
5
|
-
var index = require("./index-
|
|
6
|
-
require("./spirits-
|
|
7
|
-
require("./dev-
|
|
5
|
+
var index = require("./index-ee8d473f.cjs");
|
|
6
|
+
require("./spirits-8ee2b3b6.cjs");
|
|
7
|
+
require("./dev-b1573a91.cjs");
|
|
8
8
|
require('util');
|
|
9
9
|
require('stream');
|
|
10
10
|
require('path');
|
|
@@ -731,15 +731,106 @@ var Spirits = {
|
|
|
731
731
|
/**
|
|
732
732
|
* Customer message
|
|
733
733
|
* @param {ConversationData & CustomerSpiritCallbacks} input
|
|
734
|
+
* @param {(error: Error) => void} onError
|
|
734
735
|
* @returns {Promise<ConversationEvent>}
|
|
735
736
|
*/
|
|
736
737
|
customer: function () {
|
|
737
738
|
var _customer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
|
|
738
739
|
var _recentUserMessage;
|
|
739
|
-
var
|
|
740
|
+
var onError,
|
|
741
|
+
customer,
|
|
742
|
+
config,
|
|
743
|
+
parser,
|
|
744
|
+
workflow,
|
|
745
|
+
generator,
|
|
746
|
+
transformer,
|
|
747
|
+
idGenerator,
|
|
748
|
+
_input$progress,
|
|
749
|
+
progress,
|
|
750
|
+
messageBefore,
|
|
751
|
+
contextBefore,
|
|
752
|
+
messagesBefore,
|
|
753
|
+
conversationBefore,
|
|
754
|
+
conversation,
|
|
755
|
+
messages,
|
|
756
|
+
context,
|
|
757
|
+
message,
|
|
758
|
+
followup,
|
|
759
|
+
entityContextUpsert,
|
|
760
|
+
updateConversation,
|
|
761
|
+
updateContext,
|
|
762
|
+
userMessages,
|
|
763
|
+
recentUserMessage,
|
|
764
|
+
lockConversation,
|
|
765
|
+
incrementLockAttempt,
|
|
766
|
+
_addInstruction,
|
|
767
|
+
addInstruction,
|
|
768
|
+
persona,
|
|
769
|
+
invalidRoles,
|
|
770
|
+
parsePayload,
|
|
771
|
+
index,
|
|
772
|
+
_message,
|
|
773
|
+
previousUserMessages,
|
|
774
|
+
oldKeyCount,
|
|
775
|
+
newKeyCount,
|
|
776
|
+
noNewContext,
|
|
777
|
+
slots,
|
|
778
|
+
hasNoInstructions,
|
|
779
|
+
hasNoCustomMessage,
|
|
780
|
+
messagesToTransform,
|
|
781
|
+
previousLockAttempt,
|
|
782
|
+
resettedIntent,
|
|
783
|
+
_forward,
|
|
784
|
+
_forwardNote,
|
|
785
|
+
_tasks,
|
|
786
|
+
_iterator,
|
|
787
|
+
_step,
|
|
788
|
+
_step$value,
|
|
789
|
+
forward,
|
|
790
|
+
forwardNote,
|
|
791
|
+
instructions,
|
|
792
|
+
removeInstructions,
|
|
793
|
+
manualMessage,
|
|
794
|
+
scheduled,
|
|
795
|
+
resetIntent,
|
|
796
|
+
secondsDelay,
|
|
797
|
+
contextUpsert,
|
|
798
|
+
anticipate,
|
|
799
|
+
slotFollowup,
|
|
800
|
+
slotEntityContextUpsert,
|
|
801
|
+
tasks,
|
|
802
|
+
_slots,
|
|
803
|
+
map,
|
|
804
|
+
i,
|
|
805
|
+
_anticipate$i,
|
|
806
|
+
keywords,
|
|
807
|
+
_slot,
|
|
808
|
+
slotId,
|
|
809
|
+
_tasks2,
|
|
810
|
+
_iterator3,
|
|
811
|
+
_step3,
|
|
812
|
+
instruction,
|
|
813
|
+
_iterator4,
|
|
814
|
+
_step4,
|
|
815
|
+
_loop,
|
|
816
|
+
manualMessageObj,
|
|
817
|
+
now,
|
|
818
|
+
generatorInput,
|
|
819
|
+
generatorPayload,
|
|
820
|
+
agentMessages,
|
|
821
|
+
lastAgentMessage,
|
|
822
|
+
_generatorPayload$ent,
|
|
823
|
+
_generatorPayload$con,
|
|
824
|
+
_iterator2,
|
|
825
|
+
_step2,
|
|
826
|
+
transformResponse,
|
|
827
|
+
_agentMessages,
|
|
828
|
+
_lastAgentMessage,
|
|
829
|
+
_args2 = arguments;
|
|
740
830
|
return _regeneratorRuntime().wrap(function _callee$(_context2) {
|
|
741
831
|
while (1) switch (_context2.prev = _context2.next) {
|
|
742
832
|
case 0:
|
|
833
|
+
onError = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : function () {};
|
|
743
834
|
customer = input.customer, config = input.config, parser = input.parser, workflow = input.workflow, generator = input.generator, transformer = input.transformer, idGenerator = input.idGenerator, _input$progress = input.progress, progress = _input$progress === void 0 ? function (message, level, type, payload) {} : _input$progress, messageBefore = input.message, contextBefore = input.context, messagesBefore = input.messages, conversationBefore = input.conversation;
|
|
744
835
|
conversation = input.conversation, messages = input.messages, context = input.context, message = input.message; // Storing post process events here
|
|
745
836
|
followup = [];
|
|
@@ -832,40 +923,40 @@ var Spirits = {
|
|
|
832
923
|
}
|
|
833
924
|
}; // 1. Check inputs
|
|
834
925
|
if (conversation.$agent) {
|
|
835
|
-
_context2.next =
|
|
926
|
+
_context2.next = 15;
|
|
836
927
|
break;
|
|
837
928
|
}
|
|
838
929
|
throw new Error("SpiritsError: No agent found in conversation, must define \".$agent\" in the conversation");
|
|
839
|
-
case
|
|
930
|
+
case 15:
|
|
840
931
|
persona = (config.persona || config.personas || config.agents).find(function (p) {
|
|
841
932
|
return p.id === conversation.$agent;
|
|
842
933
|
});
|
|
843
934
|
if (persona) {
|
|
844
|
-
_context2.next =
|
|
935
|
+
_context2.next = 20;
|
|
845
936
|
break;
|
|
846
937
|
}
|
|
847
938
|
if (!(config.persona || config.personas || config.agents).some(function (a) {
|
|
848
939
|
return !a.id;
|
|
849
940
|
})) {
|
|
850
|
-
_context2.next =
|
|
941
|
+
_context2.next = 19;
|
|
851
942
|
break;
|
|
852
943
|
}
|
|
853
944
|
throw new Error("SpiritsError: No persona found (\"".concat(conversation.$agent, "\") in provided config, some persona's did not contain an \"id\" (Internal Mapping Error)"));
|
|
854
|
-
case 18:
|
|
855
|
-
throw new Error("SpiritsError: No persona found (\"".concat(conversation.$agent, "\") in provided config"));
|
|
856
945
|
case 19:
|
|
946
|
+
throw new Error("SpiritsError: No persona found (\"".concat(conversation.$agent, "\") in provided config"));
|
|
947
|
+
case 20:
|
|
857
948
|
if (messages.every(function (m) {
|
|
858
949
|
return !!m.id;
|
|
859
950
|
})) {
|
|
860
|
-
_context2.next =
|
|
951
|
+
_context2.next = 22;
|
|
861
952
|
break;
|
|
862
953
|
}
|
|
863
954
|
throw new Error("SpiritsError: Every message must have an \".id\", ensure all messages have an id assigned before running");
|
|
864
|
-
case
|
|
955
|
+
case 22:
|
|
865
956
|
if (messages.every(function (m) {
|
|
866
957
|
return m.role === 'customer' || m.role === 'agent' || m.role === 'system';
|
|
867
958
|
})) {
|
|
868
|
-
_context2.next =
|
|
959
|
+
_context2.next = 25;
|
|
869
960
|
break;
|
|
870
961
|
}
|
|
871
962
|
invalidRoles = messages.filter(function (m) {
|
|
@@ -874,7 +965,7 @@ var Spirits = {
|
|
|
874
965
|
throw new Error("SpiritsError: Every message must have a role of \"customer\", \"agent\", or \"system\". Got invalid roles: ".concat(invalidRoles.map(function (m) {
|
|
875
966
|
return m.role;
|
|
876
967
|
}).join(', ')));
|
|
877
|
-
case
|
|
968
|
+
case 25:
|
|
878
969
|
// if message is not in messages, then add it
|
|
879
970
|
if (!messages.find(function (m) {
|
|
880
971
|
return m.id === input.message.id;
|
|
@@ -884,9 +975,9 @@ var Spirits = {
|
|
|
884
975
|
|
|
885
976
|
// 2. Parse the message
|
|
886
977
|
progress('Parsing message', 'info', 'SET_PROCESSING', 'user');
|
|
887
|
-
_context2.next =
|
|
978
|
+
_context2.next = 29;
|
|
888
979
|
return parser(message.content, 'en');
|
|
889
|
-
case
|
|
980
|
+
case 29:
|
|
890
981
|
parsePayload = _context2.sent;
|
|
891
982
|
if (parsePayload.intent) {
|
|
892
983
|
message.intent = parsePayload.intent;
|
|
@@ -957,7 +1048,7 @@ var Spirits = {
|
|
|
957
1048
|
}
|
|
958
1049
|
noNewContext = Object.keys(parsePayload.context).length === 0; // 3. Run the workflow
|
|
959
1050
|
progress('Running workflow', 'info', 'SET_PROCESSING', 'system');
|
|
960
|
-
_context2.next =
|
|
1051
|
+
_context2.next = 46;
|
|
961
1052
|
return workflow({
|
|
962
1053
|
messages: messages,
|
|
963
1054
|
conversation: conversation,
|
|
@@ -986,7 +1077,7 @@ var Spirits = {
|
|
|
986
1077
|
return accumulator;
|
|
987
1078
|
}, []);
|
|
988
1079
|
});
|
|
989
|
-
case
|
|
1080
|
+
case 46:
|
|
990
1081
|
slots = _context2.sent;
|
|
991
1082
|
hasNoInstructions = slots.every(function (s) {
|
|
992
1083
|
return !s.instructions || Array.isArray(s.instructions) && s.instructions.length === 0;
|
|
@@ -1013,20 +1104,20 @@ var Spirits = {
|
|
|
1013
1104
|
resettedIntent = false;
|
|
1014
1105
|
/** @type {Array<string> | undefined} */
|
|
1015
1106
|
_iterator = _createForOfIteratorHelper(slots);
|
|
1016
|
-
_context2.prev =
|
|
1107
|
+
_context2.prev = 54;
|
|
1017
1108
|
_iterator.s();
|
|
1018
|
-
case
|
|
1109
|
+
case 56:
|
|
1019
1110
|
if ((_step = _iterator.n()).done) {
|
|
1020
|
-
_context2.next =
|
|
1111
|
+
_context2.next = 127;
|
|
1021
1112
|
break;
|
|
1022
1113
|
}
|
|
1023
1114
|
_step$value = _step.value, forward = _step$value.forward, forwardNote = _step$value.forwardNote, instructions = _step$value.instructions, removeInstructions = _step$value.removeInstructions, manualMessage = _step$value.message, scheduled = _step$value.scheduled, resetIntent = _step$value.resetIntent, secondsDelay = _step$value.secondsDelay, contextUpsert = _step$value.contextUpsert, anticipate = _step$value.anticipate, slotFollowup = _step$value.followup, slotEntityContextUpsert = _step$value.entityContextUpsert, tasks = _step$value.tasks;
|
|
1024
1115
|
if (!anticipate) {
|
|
1025
|
-
_context2.next =
|
|
1116
|
+
_context2.next = 71;
|
|
1026
1117
|
break;
|
|
1027
1118
|
}
|
|
1028
1119
|
if (!Array.isArray(anticipate)) {
|
|
1029
|
-
_context2.next =
|
|
1120
|
+
_context2.next = 66;
|
|
1030
1121
|
break;
|
|
1031
1122
|
}
|
|
1032
1123
|
// 'literal' anticipation
|
|
@@ -1046,11 +1137,11 @@ var Spirits = {
|
|
|
1046
1137
|
slots: _slots,
|
|
1047
1138
|
map: map
|
|
1048
1139
|
});
|
|
1049
|
-
_context2.next =
|
|
1140
|
+
_context2.next = 71;
|
|
1050
1141
|
break;
|
|
1051
|
-
case
|
|
1142
|
+
case 66:
|
|
1052
1143
|
if (!('yes' in anticipate && 'no' in anticipate && 'did' in anticipate)) {
|
|
1053
|
-
_context2.next =
|
|
1144
|
+
_context2.next = 70;
|
|
1054
1145
|
break;
|
|
1055
1146
|
}
|
|
1056
1147
|
// "did" anticipation
|
|
@@ -1062,11 +1153,11 @@ var Spirits = {
|
|
|
1062
1153
|
},
|
|
1063
1154
|
did: anticipate.did
|
|
1064
1155
|
});
|
|
1065
|
-
_context2.next =
|
|
1156
|
+
_context2.next = 71;
|
|
1066
1157
|
break;
|
|
1067
|
-
case 69:
|
|
1068
|
-
throw new Error("Invalid anticipate payload \"".concat(JSON.stringify(anticipate), "\""));
|
|
1069
1158
|
case 70:
|
|
1159
|
+
throw new Error("Invalid anticipate payload \"".concat(JSON.stringify(anticipate), "\""));
|
|
1160
|
+
case 71:
|
|
1070
1161
|
// tasks from auto/manual ingress to execute
|
|
1071
1162
|
if (!!tasks && Array.isArray(tasks) && !!tasks.length) {
|
|
1072
1163
|
if (!_tasks) _tasks = [];
|
|
@@ -1122,19 +1213,19 @@ var Spirits = {
|
|
|
1122
1213
|
|
|
1123
1214
|
// Insert instructions context
|
|
1124
1215
|
if (!instructions) {
|
|
1125
|
-
_context2.next =
|
|
1216
|
+
_context2.next = 90;
|
|
1126
1217
|
break;
|
|
1127
1218
|
}
|
|
1128
1219
|
if (!(typeof instructions === 'string')) {
|
|
1129
|
-
_context2.next =
|
|
1220
|
+
_context2.next = 80;
|
|
1130
1221
|
break;
|
|
1131
1222
|
}
|
|
1132
1223
|
addInstruction(instructions, previousLockAttempt);
|
|
1133
|
-
_context2.next =
|
|
1224
|
+
_context2.next = 90;
|
|
1134
1225
|
break;
|
|
1135
|
-
case
|
|
1226
|
+
case 80:
|
|
1136
1227
|
if (!Array.isArray(instructions)) {
|
|
1137
|
-
_context2.next =
|
|
1228
|
+
_context2.next = 85;
|
|
1138
1229
|
break;
|
|
1139
1230
|
}
|
|
1140
1231
|
_iterator3 = _createForOfIteratorHelper(instructions);
|
|
@@ -1152,25 +1243,25 @@ var Spirits = {
|
|
|
1152
1243
|
} finally {
|
|
1153
1244
|
_iterator3.f();
|
|
1154
1245
|
}
|
|
1155
|
-
_context2.next =
|
|
1246
|
+
_context2.next = 90;
|
|
1156
1247
|
break;
|
|
1157
|
-
case
|
|
1248
|
+
case 85:
|
|
1158
1249
|
if (!(_typeof(instructions) === 'object' && 'content' in instructions)) {
|
|
1159
|
-
_context2.next =
|
|
1250
|
+
_context2.next = 89;
|
|
1160
1251
|
break;
|
|
1161
1252
|
}
|
|
1162
1253
|
addInstruction(instructions.content, previousLockAttempt, instructions.id);
|
|
1163
|
-
_context2.next =
|
|
1254
|
+
_context2.next = 90;
|
|
1164
1255
|
break;
|
|
1165
|
-
case 88:
|
|
1166
|
-
throw new Error("SpiritsError: instructions must be a string or array or {content: \"<instruction>\"}, got: ".concat(JSON.stringify(instructions)));
|
|
1167
1256
|
case 89:
|
|
1257
|
+
throw new Error("SpiritsError: instructions must be a string or array or {content: \"<instruction>\"}, got: ".concat(JSON.stringify(instructions)));
|
|
1258
|
+
case 90:
|
|
1168
1259
|
if (!removeInstructions) {
|
|
1169
|
-
_context2.next =
|
|
1260
|
+
_context2.next = 107;
|
|
1170
1261
|
break;
|
|
1171
1262
|
}
|
|
1172
1263
|
_iterator4 = _createForOfIteratorHelper(removeInstructions);
|
|
1173
|
-
_context2.prev =
|
|
1264
|
+
_context2.prev = 92;
|
|
1174
1265
|
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
1175
1266
|
var instructionId, index;
|
|
1176
1267
|
return _regeneratorRuntime().wrap(function _loop$(_context) {
|
|
@@ -1195,29 +1286,29 @@ var Spirits = {
|
|
|
1195
1286
|
}, _loop);
|
|
1196
1287
|
});
|
|
1197
1288
|
_iterator4.s();
|
|
1198
|
-
case
|
|
1289
|
+
case 95:
|
|
1199
1290
|
if ((_step4 = _iterator4.n()).done) {
|
|
1200
|
-
_context2.next =
|
|
1291
|
+
_context2.next = 99;
|
|
1201
1292
|
break;
|
|
1202
1293
|
}
|
|
1203
|
-
return _context2.delegateYield(_loop(), "t0",
|
|
1204
|
-
case
|
|
1205
|
-
_context2.next =
|
|
1294
|
+
return _context2.delegateYield(_loop(), "t0", 97);
|
|
1295
|
+
case 97:
|
|
1296
|
+
_context2.next = 95;
|
|
1206
1297
|
break;
|
|
1207
|
-
case
|
|
1208
|
-
_context2.next =
|
|
1298
|
+
case 99:
|
|
1299
|
+
_context2.next = 104;
|
|
1209
1300
|
break;
|
|
1210
|
-
case
|
|
1211
|
-
_context2.prev =
|
|
1212
|
-
_context2.t1 = _context2["catch"](
|
|
1301
|
+
case 101:
|
|
1302
|
+
_context2.prev = 101;
|
|
1303
|
+
_context2.t1 = _context2["catch"](92);
|
|
1213
1304
|
_iterator4.e(_context2.t1);
|
|
1214
|
-
case
|
|
1215
|
-
_context2.prev =
|
|
1305
|
+
case 104:
|
|
1306
|
+
_context2.prev = 104;
|
|
1216
1307
|
_iterator4.f();
|
|
1217
|
-
return _context2.finish(
|
|
1218
|
-
case
|
|
1308
|
+
return _context2.finish(104);
|
|
1309
|
+
case 107:
|
|
1219
1310
|
if (!manualMessage) {
|
|
1220
|
-
_context2.next =
|
|
1311
|
+
_context2.next = 123;
|
|
1221
1312
|
break;
|
|
1222
1313
|
}
|
|
1223
1314
|
/** @type {import('@scout9/app').Message} */
|
|
@@ -1229,25 +1320,25 @@ var Spirits = {
|
|
|
1229
1320
|
time: new Date().toISOString()
|
|
1230
1321
|
};
|
|
1231
1322
|
if (!(_typeof(manualMessage) === 'object')) {
|
|
1232
|
-
_context2.next =
|
|
1323
|
+
_context2.next = 115;
|
|
1233
1324
|
break;
|
|
1234
1325
|
}
|
|
1235
1326
|
Object.assign(manualMessageObj, manualMessage);
|
|
1236
1327
|
manualMessageObj.role = 'agent';
|
|
1237
1328
|
manualMessageObj.time = new Date().toISOString();
|
|
1238
|
-
_context2.next =
|
|
1329
|
+
_context2.next = 120;
|
|
1239
1330
|
break;
|
|
1240
|
-
case
|
|
1331
|
+
case 115:
|
|
1241
1332
|
if (!(typeof manualMessage === 'string')) {
|
|
1242
|
-
_context2.next =
|
|
1333
|
+
_context2.next = 119;
|
|
1243
1334
|
break;
|
|
1244
1335
|
}
|
|
1245
1336
|
manualMessageObj.content = manualMessage;
|
|
1246
|
-
_context2.next =
|
|
1337
|
+
_context2.next = 120;
|
|
1247
1338
|
break;
|
|
1248
|
-
case 118:
|
|
1249
|
-
throw new Error('Manual message must be of type "string" or "DirectMessage"');
|
|
1250
1339
|
case 119:
|
|
1340
|
+
throw new Error('Manual message must be of type "string" or "DirectMessage"');
|
|
1341
|
+
case 120:
|
|
1251
1342
|
if (scheduled) {
|
|
1252
1343
|
manualMessageObj.time = new Date(scheduled * 1000).toISOString();
|
|
1253
1344
|
manualMessageObj.scheduled = manualMessageObj.time;
|
|
@@ -1259,7 +1350,7 @@ var Spirits = {
|
|
|
1259
1350
|
}
|
|
1260
1351
|
messages.push(manualMessageObj);
|
|
1261
1352
|
progress('Added manual message', 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
|
|
1262
|
-
case
|
|
1353
|
+
case 123:
|
|
1263
1354
|
if (contextUpsert) {
|
|
1264
1355
|
context = updateContext(context, contextUpsert);
|
|
1265
1356
|
progress('Upserted context', 'info', 'UPDATE_CONTEXT', contextUpsert);
|
|
@@ -1267,21 +1358,21 @@ var Spirits = {
|
|
|
1267
1358
|
if (resetIntent) {
|
|
1268
1359
|
resettedIntent = true;
|
|
1269
1360
|
}
|
|
1270
|
-
case
|
|
1271
|
-
_context2.next =
|
|
1361
|
+
case 125:
|
|
1362
|
+
_context2.next = 56;
|
|
1272
1363
|
break;
|
|
1273
|
-
case
|
|
1274
|
-
_context2.next =
|
|
1364
|
+
case 127:
|
|
1365
|
+
_context2.next = 132;
|
|
1275
1366
|
break;
|
|
1276
|
-
case
|
|
1277
|
-
_context2.prev =
|
|
1278
|
-
_context2.t2 = _context2["catch"](
|
|
1367
|
+
case 129:
|
|
1368
|
+
_context2.prev = 129;
|
|
1369
|
+
_context2.t2 = _context2["catch"](54);
|
|
1279
1370
|
_iterator.e(_context2.t2);
|
|
1280
|
-
case
|
|
1281
|
-
_context2.prev =
|
|
1371
|
+
case 132:
|
|
1372
|
+
_context2.prev = 132;
|
|
1282
1373
|
_iterator.f();
|
|
1283
|
-
return _context2.finish(
|
|
1284
|
-
case
|
|
1374
|
+
return _context2.finish(132);
|
|
1375
|
+
case 135:
|
|
1285
1376
|
if (resettedIntent && !_forward) {
|
|
1286
1377
|
conversation.intent = null;
|
|
1287
1378
|
conversation.intentScore = null;
|
|
@@ -1300,15 +1391,17 @@ var Spirits = {
|
|
|
1300
1391
|
// 4. Generate response
|
|
1301
1392
|
// If conversation previously locked, don't generate
|
|
1302
1393
|
if (input.conversation.locked) {
|
|
1303
|
-
_context2.next =
|
|
1394
|
+
_context2.next = 187;
|
|
1304
1395
|
break;
|
|
1305
1396
|
}
|
|
1306
1397
|
if (!((!conversation.locked || !hasNoInstructions) && !!hasNoCustomMessage)) {
|
|
1307
|
-
_context2.next =
|
|
1398
|
+
_context2.next = 153;
|
|
1308
1399
|
break;
|
|
1309
1400
|
}
|
|
1310
|
-
_context2.prev =
|
|
1401
|
+
_context2.prev = 138;
|
|
1311
1402
|
progress('Generating message', 'info', 'SET_PROCESSING', 'system');
|
|
1403
|
+
|
|
1404
|
+
/** @type {import('@scout9/admin').GenerateRequestOneOf1} */
|
|
1312
1405
|
generatorInput = {
|
|
1313
1406
|
messages: messages,
|
|
1314
1407
|
persona: persona,
|
|
@@ -1319,9 +1412,9 @@ var Spirits = {
|
|
|
1319
1412
|
if (!!_tasks && Array.isArray(_tasks) && !!_tasks.length) {
|
|
1320
1413
|
generatorInput.tasks = _tasks;
|
|
1321
1414
|
}
|
|
1322
|
-
_context2.next =
|
|
1415
|
+
_context2.next = 144;
|
|
1323
1416
|
return generator(generatorInput);
|
|
1324
|
-
case
|
|
1417
|
+
case 144:
|
|
1325
1418
|
generatorPayload = _context2.sent;
|
|
1326
1419
|
if (!generatorPayload.send) {
|
|
1327
1420
|
progress('Generated response', 'failed', undefined, {
|
|
@@ -1360,29 +1453,30 @@ var Spirits = {
|
|
|
1360
1453
|
}
|
|
1361
1454
|
}
|
|
1362
1455
|
}
|
|
1363
|
-
_context2.next =
|
|
1456
|
+
_context2.next = 153;
|
|
1364
1457
|
break;
|
|
1365
|
-
case
|
|
1366
|
-
_context2.prev =
|
|
1367
|
-
_context2.t3 = _context2["catch"](
|
|
1368
|
-
|
|
1458
|
+
case 148:
|
|
1459
|
+
_context2.prev = 148;
|
|
1460
|
+
_context2.t3 = _context2["catch"](138);
|
|
1461
|
+
onError(_context2.t3);
|
|
1462
|
+
console.error("Spirits: Locking conversation, error generating response: ".concat(_context2.t3.message));
|
|
1369
1463
|
conversation = lockConversation(conversation, 'API: ' + _context2.t3.message);
|
|
1370
|
-
case
|
|
1464
|
+
case 153:
|
|
1371
1465
|
if (!(messagesToTransform.length && transformer)) {
|
|
1372
|
-
_context2.next =
|
|
1466
|
+
_context2.next = 186;
|
|
1373
1467
|
break;
|
|
1374
1468
|
}
|
|
1375
|
-
_context2.prev = 152;
|
|
1376
|
-
_iterator2 = _createForOfIteratorHelper(messagesToTransform);
|
|
1377
1469
|
_context2.prev = 154;
|
|
1470
|
+
_iterator2 = _createForOfIteratorHelper(messagesToTransform);
|
|
1471
|
+
_context2.prev = 156;
|
|
1378
1472
|
_iterator2.s();
|
|
1379
|
-
case
|
|
1473
|
+
case 158:
|
|
1380
1474
|
if ((_step2 = _iterator2.n()).done) {
|
|
1381
|
-
_context2.next =
|
|
1475
|
+
_context2.next = 169;
|
|
1382
1476
|
break;
|
|
1383
1477
|
}
|
|
1384
1478
|
_step2.value;
|
|
1385
|
-
_context2.next =
|
|
1479
|
+
_context2.next = 162;
|
|
1386
1480
|
return transformer({
|
|
1387
1481
|
message: messagesToTransform,
|
|
1388
1482
|
persona: persona,
|
|
@@ -1390,7 +1484,7 @@ var Spirits = {
|
|
|
1390
1484
|
messages: messages,
|
|
1391
1485
|
context: context
|
|
1392
1486
|
});
|
|
1393
|
-
case
|
|
1487
|
+
case 162:
|
|
1394
1488
|
transformResponse = _context2.sent;
|
|
1395
1489
|
progress('Generated response', 'success', undefined, undefined);
|
|
1396
1490
|
// Check if already had message
|
|
@@ -1410,36 +1504,37 @@ var Spirits = {
|
|
|
1410
1504
|
});
|
|
1411
1505
|
progress('Added agent message', 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
|
|
1412
1506
|
}
|
|
1413
|
-
case 165:
|
|
1414
|
-
_context2.next = 156;
|
|
1415
|
-
break;
|
|
1416
1507
|
case 167:
|
|
1417
|
-
_context2.next =
|
|
1508
|
+
_context2.next = 158;
|
|
1418
1509
|
break;
|
|
1419
1510
|
case 169:
|
|
1420
|
-
_context2.
|
|
1421
|
-
|
|
1511
|
+
_context2.next = 174;
|
|
1512
|
+
break;
|
|
1513
|
+
case 171:
|
|
1514
|
+
_context2.prev = 171;
|
|
1515
|
+
_context2.t4 = _context2["catch"](156);
|
|
1422
1516
|
_iterator2.e(_context2.t4);
|
|
1423
|
-
case
|
|
1424
|
-
_context2.prev =
|
|
1517
|
+
case 174:
|
|
1518
|
+
_context2.prev = 174;
|
|
1425
1519
|
_iterator2.f();
|
|
1426
|
-
return _context2.finish(
|
|
1427
|
-
case 175:
|
|
1428
|
-
_context2.next = 181;
|
|
1429
|
-
break;
|
|
1520
|
+
return _context2.finish(174);
|
|
1430
1521
|
case 177:
|
|
1431
|
-
_context2.
|
|
1432
|
-
|
|
1522
|
+
_context2.next = 184;
|
|
1523
|
+
break;
|
|
1524
|
+
case 179:
|
|
1525
|
+
_context2.prev = 179;
|
|
1526
|
+
_context2.t5 = _context2["catch"](154);
|
|
1433
1527
|
console.error("Locking conversation, error transforming response: ".concat(_context2.t5.message));
|
|
1434
1528
|
conversation = lockConversation(conversation, 'API: ' + _context2.t5.message);
|
|
1435
|
-
|
|
1436
|
-
|
|
1529
|
+
onError(_context2.t5);
|
|
1530
|
+
case 184:
|
|
1531
|
+
_context2.next = 187;
|
|
1437
1532
|
break;
|
|
1438
|
-
case
|
|
1533
|
+
case 186:
|
|
1439
1534
|
if (messagesToTransform.length) {
|
|
1440
1535
|
console.warn("No transformer provided");
|
|
1441
1536
|
}
|
|
1442
|
-
case
|
|
1537
|
+
case 187:
|
|
1443
1538
|
progress('Parsing message', 'info', 'SET_PROCESSING', null);
|
|
1444
1539
|
return _context2.abrupt("return", {
|
|
1445
1540
|
conversation: {
|
|
@@ -1463,11 +1558,11 @@ var Spirits = {
|
|
|
1463
1558
|
followup: followup,
|
|
1464
1559
|
entityContextUpsert: entityContextUpsert
|
|
1465
1560
|
});
|
|
1466
|
-
case
|
|
1561
|
+
case 189:
|
|
1467
1562
|
case "end":
|
|
1468
1563
|
return _context2.stop();
|
|
1469
1564
|
}
|
|
1470
|
-
}, _callee, null, [[
|
|
1565
|
+
}, _callee, null, [[54, 129, 132, 135], [92, 101, 104, 107], [138, 148], [154, 179], [156, 171, 174, 177]]);
|
|
1471
1566
|
}));
|
|
1472
1567
|
function customer(_x) {
|
|
1473
1568
|
return _customer.apply(this, arguments);
|
package/dist/spirits.cjs
CHANGED
package/dist/testing-tools.cjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var dev = require("./dev-
|
|
6
|
-
require("./spirits-
|
|
5
|
+
var dev = require("./dev-b1573a91.cjs");
|
|
6
|
+
require("./spirits-8ee2b3b6.cjs");
|
|
7
7
|
require('util');
|
|
8
8
|
require('stream');
|
|
9
9
|
require('path');
|
package/package.json
CHANGED
|
@@ -114,9 +114,10 @@ export const Spirits = {
|
|
|
114
114
|
/**
|
|
115
115
|
* Customer message
|
|
116
116
|
* @param {ConversationData & CustomerSpiritCallbacks} input
|
|
117
|
+
* @param {(error: Error) => void} onError
|
|
117
118
|
* @returns {Promise<ConversationEvent>}
|
|
118
119
|
*/
|
|
119
|
-
customer: async function (input) {
|
|
120
|
+
customer: async function (input, onError = () => {}) {
|
|
120
121
|
const {
|
|
121
122
|
customer,
|
|
122
123
|
config,
|
|
@@ -591,6 +592,8 @@ export const Spirits = {
|
|
|
591
592
|
if ((!conversation.locked || !hasNoInstructions) && !!hasNoCustomMessage) {
|
|
592
593
|
try {
|
|
593
594
|
progress('Generating message', 'info', 'SET_PROCESSING', 'system');
|
|
595
|
+
|
|
596
|
+
/** @type {import('@scout9/admin').GenerateRequestOneOf1} */
|
|
594
597
|
const generatorInput = {
|
|
595
598
|
messages,
|
|
596
599
|
persona,
|
|
@@ -598,6 +601,7 @@ export const Spirits = {
|
|
|
598
601
|
llm: config.llm,
|
|
599
602
|
pmt: config.pmt
|
|
600
603
|
}
|
|
604
|
+
|
|
601
605
|
if (!!_tasks && Array.isArray(_tasks) && !!_tasks.length) {
|
|
602
606
|
generatorInput.tasks = _tasks;
|
|
603
607
|
}
|
|
@@ -643,7 +647,8 @@ export const Spirits = {
|
|
|
643
647
|
}
|
|
644
648
|
|
|
645
649
|
} catch (e) {
|
|
646
|
-
|
|
650
|
+
onError(e);
|
|
651
|
+
console.error(`Spirits: Locking conversation, error generating response: ${e.message}`);
|
|
647
652
|
conversation = lockConversation(conversation, 'API: ' + e.message);
|
|
648
653
|
}
|
|
649
654
|
}
|
|
@@ -680,6 +685,7 @@ export const Spirits = {
|
|
|
680
685
|
} catch (e) {
|
|
681
686
|
console.error(`Locking conversation, error transforming response: ${e.message}`);
|
|
682
687
|
conversation = lockConversation(conversation, 'API: ' + e.message);
|
|
688
|
+
onError(e);
|
|
683
689
|
}
|
|
684
690
|
} else if (messagesToTransform.length) {
|
|
685
691
|
console.warn(`No transformer provided`)
|
package/types/index.d.ts
CHANGED
|
@@ -883,7 +883,7 @@ declare module '@scout9/app/testing-tools' {
|
|
|
883
883
|
|
|
884
884
|
declare module '@scout9/app/spirits' {
|
|
885
885
|
export namespace Spirits {
|
|
886
|
-
function customer(input: ConversationData & CustomerSpiritCallbacks): Promise<ConversationEvent>;
|
|
886
|
+
function customer(input: ConversationData & CustomerSpiritCallbacks, onError?: (error: Error) => void): Promise<ConversationEvent>;
|
|
887
887
|
}
|
|
888
888
|
export type Document = {
|
|
889
889
|
id: string;
|