@scout9/app 1.0.0-alpha.0.5.8 → 1.0.0-alpha.0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{dev-ccf05f24.cjs → dev-32a9a0c8.cjs} +155 -9
- package/dist/{index-b329d3e5.cjs → index-d94326d3.cjs} +7 -7
- package/dist/index.cjs +4 -4
- package/dist/{macros-f855de63.cjs → macros-621210f1.cjs} +25 -4
- package/dist/{multipart-parser-5819fcfd.cjs → multipart-parser-6ba4e92d.cjs} +4 -4
- package/dist/schemas.cjs +2 -1
- package/dist/{spirits-2ab4d673.cjs → spirits-8819b1c9.cjs} +173 -78
- package/dist/spirits.cjs +1 -1
- package/dist/testing-tools.cjs +3 -3
- package/package.json +2 -1
- package/src/core/templates/app.js +277 -178
- package/src/public.d.ts +18 -3
- package/src/runtime/schemas/message.js +10 -1
- package/src/runtime/schemas/users.js +9 -1
- package/src/runtime/schemas/workflow.js +6 -2
- package/src/testing-tools/spirits.js +59 -0
- package/types/index.d.ts +1974 -164
- package/types/index.d.ts.map +3 -1
|
@@ -637,6 +637,7 @@ var _excluded = ["keywords"];
|
|
|
637
637
|
* @property {Array<import('@scout9/app').Message>} messages
|
|
638
638
|
* @property {import('@scout9/app').Message} message - the message sent by the customer (should exist in messages)
|
|
639
639
|
* @property {import('@scout9/app').Customer} customer
|
|
640
|
+
* @property {import('@scout9/app').ConversationProgress} progress - progress checklist for manual/auto ingress workflows (needed if conversation progress is not managed by external webhooks or @scout9 apps (ingress app/webhook)
|
|
640
641
|
* @property {any} context
|
|
641
642
|
*/
|
|
642
643
|
|
|
@@ -664,6 +665,14 @@ var _excluded = ["keywords"];
|
|
|
664
665
|
* @property {any} context
|
|
665
666
|
*/
|
|
666
667
|
|
|
668
|
+
/**
|
|
669
|
+
* @typedef {Object} GenerateOutput
|
|
670
|
+
* @property {import('@scout9/admin').GenerateResponse | undefined} generate
|
|
671
|
+
* @property {Array<import('@scout9/app').Message>} messages
|
|
672
|
+
* @property {import('@scout9/app').Conversation} conversation
|
|
673
|
+
* @property {any} context
|
|
674
|
+
*/
|
|
675
|
+
|
|
667
676
|
/**
|
|
668
677
|
* @callback ParseFun
|
|
669
678
|
* @param {string} message - message to send
|
|
@@ -683,11 +692,18 @@ var _excluded = ["keywords"];
|
|
|
683
692
|
* @returns {Promise<import('@scout9/admin').GenerateResponse>}
|
|
684
693
|
*/
|
|
685
694
|
|
|
695
|
+
/**
|
|
696
|
+
* @callback TransformerFun
|
|
697
|
+
* @param {import('@scout9/admin').PmtTransformRequest} data - data to generate from
|
|
698
|
+
* @returns {Promise<import('@scout9/admin').PmtTransformResponse>}
|
|
699
|
+
*/
|
|
700
|
+
|
|
686
701
|
/**
|
|
687
702
|
* @callback IdGeneratorFun
|
|
688
703
|
* @param {import('@scout9/app').Message['role']} prefix
|
|
689
704
|
* @returns {string}
|
|
690
705
|
*/
|
|
706
|
+
|
|
691
707
|
/**
|
|
692
708
|
* @callback StatusCallback
|
|
693
709
|
* @param {string} message
|
|
@@ -702,6 +718,7 @@ var _excluded = ["keywords"];
|
|
|
702
718
|
* @property {ParseFun} parser
|
|
703
719
|
* @property {WorkflowFun} workflow
|
|
704
720
|
* @property {GenerateFun} generator
|
|
721
|
+
* @property {TransformerFun} transformer
|
|
705
722
|
* @property {IdGeneratorFun} idGenerator
|
|
706
723
|
* @property {StatusCallback | undefined} [progress]
|
|
707
724
|
*/
|
|
@@ -723,11 +740,11 @@ var Spirits = {
|
|
|
723
740
|
customer: function () {
|
|
724
741
|
var _customer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
|
|
725
742
|
var _recentUserMessage;
|
|
726
|
-
var customer, config, parser, workflow, generator, idGenerator, _input$progress, progress, messageBefore, contextBefore, messagesBefore, conversationBefore, conversation, messages, context, message, followup, updateConversation, updateContext, userMessages, recentUserMessage, lockConversation, incrementLockAttempt, _addInstruction, addInstruction, persona, invalidRoles, parsePayload, index, _message, previousUserMessages, oldKeyCount, newKeyCount, noNewContext, slots, hasNoInstructions, hasNoCustomMessage, previousLockAttempt, resettedIntent, _forward, _forwardNote, _iterator, _step, _step$value, forward, forwardNote, instructions, removeInstructions, manualMessage, scheduled, resetIntent, secondsDelay, contextUpsert, anticipate, slotFollowup, _slots, map, i, _anticipate$i, keywords, _slot, slotId,
|
|
743
|
+
var customer, config, parser, workflow, generator, transformer, idGenerator, _input$progress, progress, messageBefore, contextBefore, messagesBefore, conversationBefore, conversation, messages, context, message, followup, updateConversation, updateContext, userMessages, recentUserMessage, lockConversation, incrementLockAttempt, _addInstruction, addInstruction, persona, invalidRoles, parsePayload, index, _message, previousUserMessages, oldKeyCount, newKeyCount, noNewContext, slots, hasNoInstructions, hasNoCustomMessage, messagesToTransform, previousLockAttempt, resettedIntent, _forward, _forwardNote, _iterator, _step, _step$value, forward, forwardNote, instructions, removeInstructions, manualMessage, scheduled, resetIntent, secondsDelay, contextUpsert, anticipate, slotFollowup, _slots, map, i, _anticipate$i, keywords, _slot, slotId, _iterator3, _step3, instruction, _iterator4, _step4, _loop, manualMessageObj, now, generatorPayload, agentMessages, lastAgentMessage, _iterator2, _step2, transformResponse, _agentMessages, _lastAgentMessage;
|
|
727
744
|
return _regeneratorRuntime().wrap(function _callee$(_context2) {
|
|
728
745
|
while (1) switch (_context2.prev = _context2.next) {
|
|
729
746
|
case 0:
|
|
730
|
-
customer = input.customer, config = input.config, parser = input.parser, workflow = input.workflow, generator = input.generator, 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;
|
|
747
|
+
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;
|
|
731
748
|
conversation = input.conversation, messages = input.messages, context = input.context, message = input.message;
|
|
732
749
|
followup = []; // 0. Setup Helpers
|
|
733
750
|
updateConversation = function updateConversation(previousConversation, conversationUpdates) {
|
|
@@ -881,6 +898,7 @@ var Spirits = {
|
|
|
881
898
|
message.intentScore = parsePayload.intentScore;
|
|
882
899
|
}
|
|
883
900
|
message.context = parsePayload.context;
|
|
901
|
+
message.entities = parsePayload.entities;
|
|
884
902
|
index = messages.findIndex(function (m) {
|
|
885
903
|
return m.content === message.content || m.id === message.id;
|
|
886
904
|
});
|
|
@@ -890,6 +908,7 @@ var Spirits = {
|
|
|
890
908
|
role: 'customer',
|
|
891
909
|
content: message,
|
|
892
910
|
context: parsePayload.context,
|
|
911
|
+
entities: parsePayload.entities,
|
|
893
912
|
time: new Date().toISOString()
|
|
894
913
|
};
|
|
895
914
|
if (parsePayload.intent) {
|
|
@@ -903,6 +922,7 @@ var Spirits = {
|
|
|
903
922
|
progress('Added message', 'info', 'ADD_MESSAGE', _message);
|
|
904
923
|
} else {
|
|
905
924
|
messages[index].context = parsePayload.context;
|
|
925
|
+
messages[index].entities = parsePayload.entities;
|
|
906
926
|
if (parsePayload.intent) {
|
|
907
927
|
messages[index].intent = parsePayload.intent;
|
|
908
928
|
}
|
|
@@ -940,7 +960,7 @@ var Spirits = {
|
|
|
940
960
|
}
|
|
941
961
|
noNewContext = Object.keys(parsePayload.context).length === 0; // 3. Run the workflow
|
|
942
962
|
progress('Running workflow', 'info', 'SET_PROCESSING', 'system');
|
|
943
|
-
_context2.next =
|
|
963
|
+
_context2.next = 44;
|
|
944
964
|
return workflow({
|
|
945
965
|
messages: messages,
|
|
946
966
|
conversation: conversation,
|
|
@@ -969,7 +989,7 @@ var Spirits = {
|
|
|
969
989
|
return accumulator;
|
|
970
990
|
}, []);
|
|
971
991
|
});
|
|
972
|
-
case
|
|
992
|
+
case 44:
|
|
973
993
|
slots = _context2.sent;
|
|
974
994
|
hasNoInstructions = slots.every(function (s) {
|
|
975
995
|
return !s.instructions || Array.isArray(s.instructions) && s.instructions.length === 0;
|
|
@@ -977,6 +997,9 @@ var Spirits = {
|
|
|
977
997
|
hasNoCustomMessage = slots.every(function (s) {
|
|
978
998
|
return !s.message;
|
|
979
999
|
});
|
|
1000
|
+
messagesToTransform = slots.filter(function (s) {
|
|
1001
|
+
return !!s.message && _typeof(s.message) === 'object' && !!s.message.transform;
|
|
1002
|
+
});
|
|
980
1003
|
previousLockAttempt = conversation.lockAttempts || 0; // Used to track
|
|
981
1004
|
if (hasNoInstructions && noNewContext) {
|
|
982
1005
|
conversation = incrementLockAttempt(conversation, config);
|
|
@@ -992,20 +1015,20 @@ var Spirits = {
|
|
|
992
1015
|
}
|
|
993
1016
|
resettedIntent = false;
|
|
994
1017
|
_iterator = _createForOfIteratorHelper(slots);
|
|
995
|
-
_context2.prev =
|
|
1018
|
+
_context2.prev = 52;
|
|
996
1019
|
_iterator.s();
|
|
997
|
-
case
|
|
1020
|
+
case 54:
|
|
998
1021
|
if ((_step = _iterator.n()).done) {
|
|
999
|
-
_context2.next =
|
|
1022
|
+
_context2.next = 114;
|
|
1000
1023
|
break;
|
|
1001
1024
|
}
|
|
1002
1025
|
_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;
|
|
1003
1026
|
if (!anticipate) {
|
|
1004
|
-
_context2.next =
|
|
1027
|
+
_context2.next = 69;
|
|
1005
1028
|
break;
|
|
1006
1029
|
}
|
|
1007
1030
|
if (!Array.isArray(anticipate)) {
|
|
1008
|
-
_context2.next =
|
|
1031
|
+
_context2.next = 64;
|
|
1009
1032
|
break;
|
|
1010
1033
|
}
|
|
1011
1034
|
// 'literal' anticipation
|
|
@@ -1025,11 +1048,11 @@ var Spirits = {
|
|
|
1025
1048
|
slots: _slots,
|
|
1026
1049
|
map: map
|
|
1027
1050
|
});
|
|
1028
|
-
_context2.next =
|
|
1051
|
+
_context2.next = 69;
|
|
1029
1052
|
break;
|
|
1030
|
-
case
|
|
1053
|
+
case 64:
|
|
1031
1054
|
if (!('yes' in anticipate && 'no' in anticipate && 'did' in anticipate)) {
|
|
1032
|
-
_context2.next =
|
|
1055
|
+
_context2.next = 68;
|
|
1033
1056
|
break;
|
|
1034
1057
|
}
|
|
1035
1058
|
// "did" anticipation
|
|
@@ -1041,11 +1064,11 @@ var Spirits = {
|
|
|
1041
1064
|
},
|
|
1042
1065
|
did: anticipate.did
|
|
1043
1066
|
});
|
|
1044
|
-
_context2.next =
|
|
1067
|
+
_context2.next = 69;
|
|
1045
1068
|
break;
|
|
1046
|
-
case
|
|
1069
|
+
case 68:
|
|
1047
1070
|
throw new Error("Invalid anticipate payload \"".concat(JSON.stringify(anticipate), "\""));
|
|
1048
|
-
case
|
|
1071
|
+
case 69:
|
|
1049
1072
|
if (slotFollowup) {
|
|
1050
1073
|
followup.push(slotFollowup);
|
|
1051
1074
|
}
|
|
@@ -1093,25 +1116,25 @@ var Spirits = {
|
|
|
1093
1116
|
|
|
1094
1117
|
// Insert instructions context
|
|
1095
1118
|
if (!instructions) {
|
|
1096
|
-
_context2.next =
|
|
1119
|
+
_context2.next = 86;
|
|
1097
1120
|
break;
|
|
1098
1121
|
}
|
|
1099
1122
|
if (!(typeof instructions === 'string')) {
|
|
1100
|
-
_context2.next =
|
|
1123
|
+
_context2.next = 76;
|
|
1101
1124
|
break;
|
|
1102
1125
|
}
|
|
1103
1126
|
addInstruction(instructions, previousLockAttempt);
|
|
1104
|
-
_context2.next =
|
|
1127
|
+
_context2.next = 86;
|
|
1105
1128
|
break;
|
|
1106
|
-
case
|
|
1129
|
+
case 76:
|
|
1107
1130
|
if (!Array.isArray(instructions)) {
|
|
1108
|
-
_context2.next =
|
|
1131
|
+
_context2.next = 81;
|
|
1109
1132
|
break;
|
|
1110
1133
|
}
|
|
1111
|
-
|
|
1134
|
+
_iterator3 = _createForOfIteratorHelper(instructions);
|
|
1112
1135
|
try {
|
|
1113
|
-
for (
|
|
1114
|
-
instruction =
|
|
1136
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
1137
|
+
instruction = _step3.value;
|
|
1115
1138
|
if (typeof instruction === 'string') {
|
|
1116
1139
|
addInstruction(instruction, previousLockAttempt);
|
|
1117
1140
|
} else {
|
|
@@ -1119,35 +1142,35 @@ var Spirits = {
|
|
|
1119
1142
|
}
|
|
1120
1143
|
}
|
|
1121
1144
|
} catch (err) {
|
|
1122
|
-
|
|
1145
|
+
_iterator3.e(err);
|
|
1123
1146
|
} finally {
|
|
1124
|
-
|
|
1147
|
+
_iterator3.f();
|
|
1125
1148
|
}
|
|
1126
|
-
_context2.next =
|
|
1149
|
+
_context2.next = 86;
|
|
1127
1150
|
break;
|
|
1128
|
-
case
|
|
1151
|
+
case 81:
|
|
1129
1152
|
if (!(_typeof(instructions) === 'object' && 'content' in instructions)) {
|
|
1130
|
-
_context2.next =
|
|
1153
|
+
_context2.next = 85;
|
|
1131
1154
|
break;
|
|
1132
1155
|
}
|
|
1133
1156
|
addInstruction(instructions.content, previousLockAttempt, instructions.id);
|
|
1134
|
-
_context2.next =
|
|
1157
|
+
_context2.next = 86;
|
|
1135
1158
|
break;
|
|
1136
|
-
case
|
|
1159
|
+
case 85:
|
|
1137
1160
|
throw new Error("SpiritsError: instructions must be a string or array or {content: \"<instruction>\"}, got: ".concat(JSON.stringify(instructions)));
|
|
1138
|
-
case
|
|
1161
|
+
case 86:
|
|
1139
1162
|
if (!removeInstructions) {
|
|
1140
|
-
_context2.next =
|
|
1163
|
+
_context2.next = 103;
|
|
1141
1164
|
break;
|
|
1142
1165
|
}
|
|
1143
|
-
|
|
1144
|
-
_context2.prev =
|
|
1166
|
+
_iterator4 = _createForOfIteratorHelper(removeInstructions);
|
|
1167
|
+
_context2.prev = 88;
|
|
1145
1168
|
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
1146
1169
|
var instructionId, index;
|
|
1147
1170
|
return _regeneratorRuntime().wrap(function _loop$(_context) {
|
|
1148
1171
|
while (1) switch (_context.prev = _context.next) {
|
|
1149
1172
|
case 0:
|
|
1150
|
-
instructionId =
|
|
1173
|
+
instructionId = _step4.value;
|
|
1151
1174
|
index = messages.findIndex(function (m) {
|
|
1152
1175
|
return m.id === instructionId;
|
|
1153
1176
|
});
|
|
@@ -1165,30 +1188,30 @@ var Spirits = {
|
|
|
1165
1188
|
}
|
|
1166
1189
|
}, _loop);
|
|
1167
1190
|
});
|
|
1168
|
-
|
|
1169
|
-
case
|
|
1170
|
-
if ((
|
|
1171
|
-
_context2.next =
|
|
1191
|
+
_iterator4.s();
|
|
1192
|
+
case 91:
|
|
1193
|
+
if ((_step4 = _iterator4.n()).done) {
|
|
1194
|
+
_context2.next = 95;
|
|
1172
1195
|
break;
|
|
1173
1196
|
}
|
|
1174
|
-
return _context2.delegateYield(_loop(), "t0",
|
|
1175
|
-
case 91:
|
|
1176
|
-
_context2.next = 89;
|
|
1177
|
-
break;
|
|
1197
|
+
return _context2.delegateYield(_loop(), "t0", 93);
|
|
1178
1198
|
case 93:
|
|
1179
|
-
_context2.next =
|
|
1199
|
+
_context2.next = 91;
|
|
1180
1200
|
break;
|
|
1181
1201
|
case 95:
|
|
1182
|
-
_context2.
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
_context2.
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1202
|
+
_context2.next = 100;
|
|
1203
|
+
break;
|
|
1204
|
+
case 97:
|
|
1205
|
+
_context2.prev = 97;
|
|
1206
|
+
_context2.t1 = _context2["catch"](88);
|
|
1207
|
+
_iterator4.e(_context2.t1);
|
|
1208
|
+
case 100:
|
|
1209
|
+
_context2.prev = 100;
|
|
1210
|
+
_iterator4.f();
|
|
1211
|
+
return _context2.finish(100);
|
|
1212
|
+
case 103:
|
|
1190
1213
|
if (!manualMessage) {
|
|
1191
|
-
_context2.next =
|
|
1214
|
+
_context2.next = 110;
|
|
1192
1215
|
break;
|
|
1193
1216
|
}
|
|
1194
1217
|
manualMessageObj = {
|
|
@@ -1198,11 +1221,11 @@ var Spirits = {
|
|
|
1198
1221
|
time: new Date().toISOString()
|
|
1199
1222
|
};
|
|
1200
1223
|
if (!(typeof manualMessage !== 'string')) {
|
|
1201
|
-
_context2.next =
|
|
1224
|
+
_context2.next = 107;
|
|
1202
1225
|
break;
|
|
1203
1226
|
}
|
|
1204
1227
|
throw new Error('Manual message must be of type "string"');
|
|
1205
|
-
case
|
|
1228
|
+
case 107:
|
|
1206
1229
|
if (scheduled) {
|
|
1207
1230
|
manualMessageObj.time = new Date(scheduled * 1000).toISOString();
|
|
1208
1231
|
manualMessageObj.scheduled = manualMessageObj.time;
|
|
@@ -1214,7 +1237,7 @@ var Spirits = {
|
|
|
1214
1237
|
}
|
|
1215
1238
|
messages.push(manualMessageObj);
|
|
1216
1239
|
progress('Added manual message', 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
|
|
1217
|
-
case
|
|
1240
|
+
case 110:
|
|
1218
1241
|
if (contextUpsert) {
|
|
1219
1242
|
context = updateContext(context, contextUpsert);
|
|
1220
1243
|
progress('Upserted context', 'info', 'UPDATE_CONTEXT', contextUpsert);
|
|
@@ -1222,21 +1245,21 @@ var Spirits = {
|
|
|
1222
1245
|
if (resetIntent) {
|
|
1223
1246
|
resettedIntent = true;
|
|
1224
1247
|
}
|
|
1225
|
-
case 110:
|
|
1226
|
-
_context2.next = 52;
|
|
1227
|
-
break;
|
|
1228
1248
|
case 112:
|
|
1229
|
-
_context2.next =
|
|
1249
|
+
_context2.next = 54;
|
|
1230
1250
|
break;
|
|
1231
1251
|
case 114:
|
|
1232
|
-
_context2.
|
|
1233
|
-
|
|
1252
|
+
_context2.next = 119;
|
|
1253
|
+
break;
|
|
1254
|
+
case 116:
|
|
1255
|
+
_context2.prev = 116;
|
|
1256
|
+
_context2.t2 = _context2["catch"](52);
|
|
1234
1257
|
_iterator.e(_context2.t2);
|
|
1235
|
-
case
|
|
1236
|
-
_context2.prev =
|
|
1258
|
+
case 119:
|
|
1259
|
+
_context2.prev = 119;
|
|
1237
1260
|
_iterator.f();
|
|
1238
|
-
return _context2.finish(
|
|
1239
|
-
case
|
|
1261
|
+
return _context2.finish(119);
|
|
1262
|
+
case 122:
|
|
1240
1263
|
if (resettedIntent && !_forward) {
|
|
1241
1264
|
conversation.intent = null;
|
|
1242
1265
|
conversation.intentScore = null;
|
|
@@ -1255,16 +1278,16 @@ var Spirits = {
|
|
|
1255
1278
|
// 4. Generate response
|
|
1256
1279
|
// If conversation previously locked, don't generate
|
|
1257
1280
|
if (input.conversation.locked) {
|
|
1258
|
-
_context2.next =
|
|
1281
|
+
_context2.next = 170;
|
|
1259
1282
|
break;
|
|
1260
1283
|
}
|
|
1261
1284
|
if (!((!conversation.locked || !hasNoInstructions) && !!hasNoCustomMessage)) {
|
|
1262
|
-
_context2.next =
|
|
1285
|
+
_context2.next = 137;
|
|
1263
1286
|
break;
|
|
1264
1287
|
}
|
|
1265
|
-
_context2.prev =
|
|
1288
|
+
_context2.prev = 125;
|
|
1266
1289
|
progress('Parsing message', 'info', 'SET_PROCESSING', 'system');
|
|
1267
|
-
_context2.next =
|
|
1290
|
+
_context2.next = 129;
|
|
1268
1291
|
return generator({
|
|
1269
1292
|
messages: messages,
|
|
1270
1293
|
persona: persona,
|
|
@@ -1272,7 +1295,7 @@ var Spirits = {
|
|
|
1272
1295
|
llm: config.llm,
|
|
1273
1296
|
pmt: config.pmt
|
|
1274
1297
|
});
|
|
1275
|
-
case
|
|
1298
|
+
case 129:
|
|
1276
1299
|
generatorPayload = _context2.sent;
|
|
1277
1300
|
if (!generatorPayload.send) {
|
|
1278
1301
|
progress('Generated response', 'failed', undefined, {
|
|
@@ -1309,14 +1332,86 @@ var Spirits = {
|
|
|
1309
1332
|
}
|
|
1310
1333
|
}
|
|
1311
1334
|
}
|
|
1312
|
-
_context2.next =
|
|
1335
|
+
_context2.next = 137;
|
|
1313
1336
|
break;
|
|
1314
|
-
case
|
|
1315
|
-
_context2.prev =
|
|
1316
|
-
_context2.t3 = _context2["catch"](
|
|
1337
|
+
case 133:
|
|
1338
|
+
_context2.prev = 133;
|
|
1339
|
+
_context2.t3 = _context2["catch"](125);
|
|
1317
1340
|
console.error("Locking conversation, error generating response: ".concat(_context2.t3.message));
|
|
1318
1341
|
conversation = lockConversation(conversation, 'API: ' + _context2.t3.message);
|
|
1319
|
-
case
|
|
1342
|
+
case 137:
|
|
1343
|
+
if (!(messagesToTransform.length && transformer)) {
|
|
1344
|
+
_context2.next = 169;
|
|
1345
|
+
break;
|
|
1346
|
+
}
|
|
1347
|
+
_context2.prev = 138;
|
|
1348
|
+
_iterator2 = _createForOfIteratorHelper(messagesToTransform);
|
|
1349
|
+
_context2.prev = 140;
|
|
1350
|
+
_iterator2.s();
|
|
1351
|
+
case 142:
|
|
1352
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
1353
|
+
_context2.next = 153;
|
|
1354
|
+
break;
|
|
1355
|
+
}
|
|
1356
|
+
_step2.value;
|
|
1357
|
+
_context2.next = 146;
|
|
1358
|
+
return transformer({
|
|
1359
|
+
message: messagesToTransform,
|
|
1360
|
+
persona: persona,
|
|
1361
|
+
customer: customer.id,
|
|
1362
|
+
messages: messages,
|
|
1363
|
+
context: context
|
|
1364
|
+
});
|
|
1365
|
+
case 146:
|
|
1366
|
+
transformResponse = _context2.sent;
|
|
1367
|
+
progress('Generated response', 'success', undefined, undefined);
|
|
1368
|
+
// Check if already had message
|
|
1369
|
+
_agentMessages = messages.filter(function (m) {
|
|
1370
|
+
return m.role === 'agent';
|
|
1371
|
+
});
|
|
1372
|
+
_lastAgentMessage = _agentMessages[_agentMessages.length - 1];
|
|
1373
|
+
if (_lastAgentMessage && _lastAgentMessage.content === transformResponse.message) {
|
|
1374
|
+
// Error should not have happened
|
|
1375
|
+
conversation = lockConversation(conversation, 'Duplicate message');
|
|
1376
|
+
} else {
|
|
1377
|
+
messages.push({
|
|
1378
|
+
id: idGenerator('agent'),
|
|
1379
|
+
role: 'agent',
|
|
1380
|
+
content: transformResponse.message,
|
|
1381
|
+
time: new Date().toISOString()
|
|
1382
|
+
});
|
|
1383
|
+
progress('Added agent message', 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
|
|
1384
|
+
}
|
|
1385
|
+
case 151:
|
|
1386
|
+
_context2.next = 142;
|
|
1387
|
+
break;
|
|
1388
|
+
case 153:
|
|
1389
|
+
_context2.next = 158;
|
|
1390
|
+
break;
|
|
1391
|
+
case 155:
|
|
1392
|
+
_context2.prev = 155;
|
|
1393
|
+
_context2.t4 = _context2["catch"](140);
|
|
1394
|
+
_iterator2.e(_context2.t4);
|
|
1395
|
+
case 158:
|
|
1396
|
+
_context2.prev = 158;
|
|
1397
|
+
_iterator2.f();
|
|
1398
|
+
return _context2.finish(158);
|
|
1399
|
+
case 161:
|
|
1400
|
+
_context2.next = 167;
|
|
1401
|
+
break;
|
|
1402
|
+
case 163:
|
|
1403
|
+
_context2.prev = 163;
|
|
1404
|
+
_context2.t5 = _context2["catch"](138);
|
|
1405
|
+
console.error("Locking conversation, error transforming response: ".concat(_context2.t5.message));
|
|
1406
|
+
conversation = lockConversation(conversation, 'API: ' + _context2.t5.message);
|
|
1407
|
+
case 167:
|
|
1408
|
+
_context2.next = 170;
|
|
1409
|
+
break;
|
|
1410
|
+
case 169:
|
|
1411
|
+
if (messagesToTransform.length) {
|
|
1412
|
+
console.warn("No transformer provided");
|
|
1413
|
+
}
|
|
1414
|
+
case 170:
|
|
1320
1415
|
progress('Parsing message', 'info', 'SET_PROCESSING', null);
|
|
1321
1416
|
return _context2.abrupt("return", {
|
|
1322
1417
|
conversation: {
|
|
@@ -1339,11 +1434,11 @@ var Spirits = {
|
|
|
1339
1434
|
},
|
|
1340
1435
|
followup: followup
|
|
1341
1436
|
});
|
|
1342
|
-
case
|
|
1437
|
+
case 172:
|
|
1343
1438
|
case "end":
|
|
1344
1439
|
return _context2.stop();
|
|
1345
1440
|
}
|
|
1346
|
-
}, _callee, null, [[
|
|
1441
|
+
}, _callee, null, [[52, 116, 119, 122], [88, 97, 100, 103], [125, 133], [138, 163], [140, 155, 158, 161]]);
|
|
1347
1442
|
}));
|
|
1348
1443
|
function customer(_x) {
|
|
1349
1444
|
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-32a9a0c8.cjs");
|
|
6
|
+
require("./spirits-8819b1c9.cjs");
|
|
7
7
|
require('util');
|
|
8
8
|
require('stream');
|
|
9
9
|
require('path');
|
|
@@ -24,7 +24,7 @@ require('node:url');
|
|
|
24
24
|
require('node:events');
|
|
25
25
|
require('node:stream');
|
|
26
26
|
require('node:string_decoder');
|
|
27
|
-
require("./macros-
|
|
27
|
+
require("./macros-621210f1.cjs");
|
|
28
28
|
require('node:readline');
|
|
29
29
|
require('node:process');
|
|
30
30
|
require('node:os');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scout9/app",
|
|
3
|
-
"version": "1.0.0-alpha.0.
|
|
3
|
+
"version": "1.0.0-alpha.0.6.0",
|
|
4
4
|
"description": "Build and deploy your Scout9 app for SMS auto replies",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -100,6 +100,7 @@
|
|
|
100
100
|
"polka": "^0.5.2",
|
|
101
101
|
"sade": "^1.8.1",
|
|
102
102
|
"sirv": "^2.0.4",
|
|
103
|
+
"ws": "^8.18.0",
|
|
103
104
|
"zod": "^3.22.4",
|
|
104
105
|
"zod-validation-error": "^3.4.0"
|
|
105
106
|
},
|