@scout9/app 1.0.0-alpha.0.8.5 → 1.0.0-alpha.0.8.6

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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var spirits = require("./spirits-c67815ee.cjs");
3
+ var spirits = require("./spirits-011bdf25.cjs");
4
4
  var require$$0$4 = require('util');
5
5
  var require$$0$3 = require('stream');
6
6
  var require$$1 = require('path');
@@ -35337,7 +35337,7 @@ function _loadUserPackageJson() {
35337
35337
  targetPkgUrl = isTest ? packageTestJsonUrl : packageJsonUrl;
35338
35338
  _context2.t0 = JSON;
35339
35339
  _context2.next = 10;
35340
- 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-1918d4f5.js', document.baseURI).href))), 'utf-8');
35340
+ 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-5557cad7.js', document.baseURI).href))), 'utf-8');
35341
35341
  case 10:
35342
35342
  _context2.t1 = _context2.sent;
35343
35343
  pkg = _context2.t0.parse.call(_context2.t0, _context2.t1);
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var spirits = require("./spirits-c67815ee.cjs");
4
- var dev = require("./dev-1918d4f5.cjs");
3
+ var spirits = require("./spirits-011bdf25.cjs");
4
+ var dev = require("./dev-5557cad7.cjs");
5
5
  var macros = require("./macros-f62cceac.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-3818211a.cjs"); });
29486
+ } = await Promise.resolve().then(function () { return require("./multipart-parser-92961749.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-eac339bf.js', document.baseURI).href))), 'utf-8');
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-a444f2c0.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-eac339bf.js', document.baseURI).href)));
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-a444f2c0.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-eac339bf.js', document.baseURI).href))), 'utf-8');
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-a444f2c0.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-eac339bf.cjs");
6
- var dev = require("./dev-1918d4f5.cjs");
7
- require("./spirits-c67815ee.cjs");
5
+ var index = require("./index-a444f2c0.cjs");
6
+ var dev = require("./dev-5557cad7.cjs");
7
+ require("./spirits-011bdf25.cjs");
8
8
  require("./macros-f62cceac.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-eac339bf.cjs");
6
- require("./spirits-c67815ee.cjs");
7
- require("./dev-1918d4f5.cjs");
5
+ var index = require("./index-a444f2c0.cjs");
6
+ require("./spirits-011bdf25.cjs");
7
+ require("./dev-5557cad7.cjs");
8
8
  require('util');
9
9
  require('stream');
10
10
  require('path');
@@ -786,7 +786,7 @@ var Spirits = {
786
786
  newContextMessages,
787
787
  _iterator,
788
788
  _step,
789
- contextMessage,
789
+ _loop,
790
790
  slots,
791
791
  hasNoInstructions,
792
792
  hasNoCustomMessage,
@@ -825,7 +825,7 @@ var Spirits = {
825
825
  instruction,
826
826
  _iterator6,
827
827
  _step6,
828
- _loop,
828
+ _loop2,
829
829
  manualMessageObj,
830
830
  now,
831
831
  generatorInput,
@@ -844,11 +844,11 @@ var Spirits = {
844
844
  transformResponse,
845
845
  _agentMessages,
846
846
  _lastAgentMessage,
847
- _args2 = arguments;
848
- return _regeneratorRuntime().wrap(function _callee$(_context2) {
849
- while (1) switch (_context2.prev = _context2.next) {
847
+ _args3 = arguments;
848
+ return _regeneratorRuntime().wrap(function _callee$(_context3) {
849
+ while (1) switch (_context3.prev = _context3.next) {
850
850
  case 0:
851
- onError = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : function () {};
851
+ onError = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : function () {};
852
852
  customer = input.customer, config = input.config, parser = input.parser, contextualizer = input.contextualizer, 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;
853
853
  conversation = input.conversation, messages = input.messages, context = input.context, message = input.message; // Storing post process events here
854
854
  followup = [];
@@ -941,7 +941,7 @@ var Spirits = {
941
941
  }
942
942
  }; // 1. Check inputs
943
943
  if (conversation.$agent) {
944
- _context2.next = 15;
944
+ _context3.next = 15;
945
945
  break;
946
946
  }
947
947
  throw new Error("SpiritsError: No agent found in conversation, must define \".$agent\" in the conversation");
@@ -950,13 +950,13 @@ var Spirits = {
950
950
  return p.id === conversation.$agent;
951
951
  });
952
952
  if (persona) {
953
- _context2.next = 20;
953
+ _context3.next = 20;
954
954
  break;
955
955
  }
956
956
  if (!(config.persona || config.personas || config.agents).some(function (a) {
957
957
  return !a.id;
958
958
  })) {
959
- _context2.next = 19;
959
+ _context3.next = 19;
960
960
  break;
961
961
  }
962
962
  throw new Error("SpiritsError: No persona found (\"".concat(conversation.$agent, "\") in provided config, some persona's did not contain an \"id\" (Internal Mapping Error)"));
@@ -966,7 +966,7 @@ var Spirits = {
966
966
  if (messages.every(function (m) {
967
967
  return !!m.id;
968
968
  })) {
969
- _context2.next = 22;
969
+ _context3.next = 22;
970
970
  break;
971
971
  }
972
972
  throw new Error("SpiritsError: Every message must have an \".id\", ensure all messages have an id assigned before running");
@@ -974,7 +974,7 @@ var Spirits = {
974
974
  if (messages.every(function (m) {
975
975
  return m.role === 'customer' || m.role === 'agent' || m.role === 'system' || m.role === 'tool';
976
976
  })) {
977
- _context2.next = 25;
977
+ _context3.next = 25;
978
978
  break;
979
979
  }
980
980
  invalidRoles = messages.filter(function (m) {
@@ -993,10 +993,10 @@ var Spirits = {
993
993
 
994
994
  // 2. Parse the message
995
995
  progress('Parsing message', 'info', 'SET_PROCESSING', 'user');
996
- _context2.next = 29;
996
+ _context3.next = 29;
997
997
  return parser(message.content, 'en');
998
998
  case 29:
999
- parsePayload = _context2.sent;
999
+ parsePayload = _context3.sent;
1000
1000
  if (parsePayload.intent) {
1001
1001
  message.intent = parsePayload.intent;
1002
1002
  }
@@ -1066,43 +1066,79 @@ var Spirits = {
1066
1066
  }
1067
1067
  noNewContext = Object.keys(parsePayload.context).length === 0; // upsert parse system messages
1068
1068
  if (parsePayload.contextMessages.length) {
1069
- (_messages2 = messages).push.apply(_messages2, _toConsumableArray(parsePayload.contextMessages.map(function (text) {
1070
- return {
1071
- id: idGenerator('sys'),
1072
- role: 'system',
1073
- content: text,
1074
- time: new Date().toISOString()
1075
- };
1076
- })));
1069
+ (_messages2 = messages).push.apply(_messages2, _toConsumableArray(parsePayload.contextMessages.reduce(function (accumulator, text) {
1070
+ if (!messages.find(function (mes) {
1071
+ return mes.content === text;
1072
+ })) {
1073
+ accumulator.push({
1074
+ id: idGenerator('sys'),
1075
+ role: 'system',
1076
+ content: text,
1077
+ time: new Date().toISOString()
1078
+ });
1079
+ } else {
1080
+ progress("Already have system context, skipping", 'info');
1081
+ }
1082
+ return accumulator;
1083
+ }, [])));
1077
1084
  }
1078
1085
 
1079
1086
  // 3. Run the contextualizer
1080
1087
  progress('Running contextualizer', 'info', 'SET_PROCESSING', 'system');
1081
- _context2.next = 47;
1088
+ _context3.next = 47;
1082
1089
  return contextualizer({
1083
1090
  conversation: conversation,
1084
1091
  messages: messages
1085
1092
  });
1086
1093
  case 47:
1087
- newContextMessages = _context2.sent;
1094
+ newContextMessages = _context3.sent;
1088
1095
  _iterator = _createForOfIteratorHelper(newContextMessages);
1089
- try {
1090
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
1091
- contextMessage = _step.value;
1092
- if (contextMessage.entities.length) {
1093
- messages.push(contextMessage);
1094
- progress("Added context", 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
1096
+ _context3.prev = 49;
1097
+ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
1098
+ var contextMessage;
1099
+ return _regeneratorRuntime().wrap(function _loop$(_context) {
1100
+ while (1) switch (_context.prev = _context.next) {
1101
+ case 0:
1102
+ contextMessage = _step.value;
1103
+ if (!messages.find(function (mes) {
1104
+ return mes.content === contextMessage.content;
1105
+ })) {
1106
+ messages.push(contextMessage);
1107
+ progress("Added context", 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
1108
+ } else {
1109
+ progress("Already have system context, skipping", 'info');
1110
+ }
1111
+ case 2:
1112
+ case "end":
1113
+ return _context.stop();
1095
1114
  }
1096
- }
1097
-
1098
- // 4. Run the workflow
1099
- } catch (err) {
1100
- _iterator.e(err);
1101
- } finally {
1102
- _iterator.f();
1115
+ }, _loop);
1116
+ });
1117
+ _iterator.s();
1118
+ case 52:
1119
+ if ((_step = _iterator.n()).done) {
1120
+ _context3.next = 56;
1121
+ break;
1103
1122
  }
1123
+ return _context3.delegateYield(_loop(), "t0", 54);
1124
+ case 54:
1125
+ _context3.next = 52;
1126
+ break;
1127
+ case 56:
1128
+ _context3.next = 61;
1129
+ break;
1130
+ case 58:
1131
+ _context3.prev = 58;
1132
+ _context3.t1 = _context3["catch"](49);
1133
+ _iterator.e(_context3.t1);
1134
+ case 61:
1135
+ _context3.prev = 61;
1136
+ _iterator.f();
1137
+ return _context3.finish(61);
1138
+ case 64:
1139
+ // 4. Run the workflow
1104
1140
  progress('Running workflow', 'info', 'SET_PROCESSING', 'system');
1105
- _context2.next = 53;
1141
+ _context3.next = 67;
1106
1142
  return workflow({
1107
1143
  messages: messages,
1108
1144
  conversation: conversation,
@@ -1131,8 +1167,8 @@ var Spirits = {
1131
1167
  return accumulator;
1132
1168
  }, []);
1133
1169
  });
1134
- case 53:
1135
- slots = _context2.sent;
1170
+ case 67:
1171
+ slots = _context3.sent;
1136
1172
  hasNoInstructions = slots.every(function (s) {
1137
1173
  return !s.instructions || Array.isArray(s.instructions) && s.instructions.length === 0;
1138
1174
  });
@@ -1158,20 +1194,20 @@ var Spirits = {
1158
1194
  resettedIntent = false;
1159
1195
  /** @type {Array<string> | undefined} */
1160
1196
  _iterator2 = _createForOfIteratorHelper(slots);
1161
- _context2.prev = 61;
1197
+ _context3.prev = 75;
1162
1198
  _iterator2.s();
1163
- case 63:
1199
+ case 77:
1164
1200
  if ((_step2 = _iterator2.n()).done) {
1165
- _context2.next = 134;
1201
+ _context3.next = 148;
1166
1202
  break;
1167
1203
  }
1168
1204
  _step2$value = _step2.value, forward = _step2$value.forward, forwardNote = _step2$value.forwardNote, instructions = _step2$value.instructions, removeInstructions = _step2$value.removeInstructions, manualMessage = _step2$value.message, scheduled = _step2$value.scheduled, resetIntent = _step2$value.resetIntent, secondsDelay = _step2$value.secondsDelay, contextUpsert = _step2$value.contextUpsert, anticipate = _step2$value.anticipate, slotFollowup = _step2$value.followup, slotEntityContextUpsert = _step2$value.entityContextUpsert, tasks = _step2$value.tasks;
1169
1205
  if (!anticipate) {
1170
- _context2.next = 78;
1206
+ _context3.next = 92;
1171
1207
  break;
1172
1208
  }
1173
1209
  if (!Array.isArray(anticipate)) {
1174
- _context2.next = 73;
1210
+ _context3.next = 87;
1175
1211
  break;
1176
1212
  }
1177
1213
  // 'literal' anticipation
@@ -1191,11 +1227,11 @@ var Spirits = {
1191
1227
  slots: _slots,
1192
1228
  map: map
1193
1229
  });
1194
- _context2.next = 78;
1230
+ _context3.next = 92;
1195
1231
  break;
1196
- case 73:
1232
+ case 87:
1197
1233
  if (!('yes' in anticipate && 'no' in anticipate && 'did' in anticipate)) {
1198
- _context2.next = 77;
1234
+ _context3.next = 91;
1199
1235
  break;
1200
1236
  }
1201
1237
  // "did" anticipation
@@ -1207,11 +1243,11 @@ var Spirits = {
1207
1243
  },
1208
1244
  did: anticipate.did
1209
1245
  });
1210
- _context2.next = 78;
1246
+ _context3.next = 92;
1211
1247
  break;
1212
- case 77:
1248
+ case 91:
1213
1249
  throw new Error("Invalid anticipate payload \"".concat(JSON.stringify(anticipate), "\""));
1214
- case 78:
1250
+ case 92:
1215
1251
  // tasks from auto/manual ingress to execute
1216
1252
  if (!!tasks && Array.isArray(tasks) && !!tasks.length) {
1217
1253
  if (!_tasks) _tasks = [];
@@ -1267,19 +1303,19 @@ var Spirits = {
1267
1303
 
1268
1304
  // Insert instructions context
1269
1305
  if (!instructions) {
1270
- _context2.next = 97;
1306
+ _context3.next = 111;
1271
1307
  break;
1272
1308
  }
1273
1309
  if (!(typeof instructions === 'string')) {
1274
- _context2.next = 87;
1310
+ _context3.next = 101;
1275
1311
  break;
1276
1312
  }
1277
1313
  addInstruction(instructions, previousLockAttempt);
1278
- _context2.next = 97;
1314
+ _context3.next = 111;
1279
1315
  break;
1280
- case 87:
1316
+ case 101:
1281
1317
  if (!Array.isArray(instructions)) {
1282
- _context2.next = 92;
1318
+ _context3.next = 106;
1283
1319
  break;
1284
1320
  }
1285
1321
  _iterator5 = _createForOfIteratorHelper(instructions);
@@ -1297,29 +1333,29 @@ var Spirits = {
1297
1333
  } finally {
1298
1334
  _iterator5.f();
1299
1335
  }
1300
- _context2.next = 97;
1336
+ _context3.next = 111;
1301
1337
  break;
1302
- case 92:
1338
+ case 106:
1303
1339
  if (!(_typeof(instructions) === 'object' && 'content' in instructions)) {
1304
- _context2.next = 96;
1340
+ _context3.next = 110;
1305
1341
  break;
1306
1342
  }
1307
1343
  addInstruction(instructions.content, previousLockAttempt, instructions.id);
1308
- _context2.next = 97;
1344
+ _context3.next = 111;
1309
1345
  break;
1310
- case 96:
1346
+ case 110:
1311
1347
  throw new Error("SpiritsError: instructions must be a string or array or {content: \"<instruction>\"}, got: ".concat(JSON.stringify(instructions)));
1312
- case 97:
1348
+ case 111:
1313
1349
  if (!removeInstructions) {
1314
- _context2.next = 114;
1350
+ _context3.next = 128;
1315
1351
  break;
1316
1352
  }
1317
1353
  _iterator6 = _createForOfIteratorHelper(removeInstructions);
1318
- _context2.prev = 99;
1319
- _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
1354
+ _context3.prev = 113;
1355
+ _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
1320
1356
  var instructionId, index;
1321
- return _regeneratorRuntime().wrap(function _loop$(_context) {
1322
- while (1) switch (_context.prev = _context.next) {
1357
+ return _regeneratorRuntime().wrap(function _loop2$(_context2) {
1358
+ while (1) switch (_context2.prev = _context2.next) {
1323
1359
  case 0:
1324
1360
  instructionId = _step6.value;
1325
1361
  index = messages.findIndex(function (m) {
@@ -1335,34 +1371,34 @@ var Spirits = {
1335
1371
  }
1336
1372
  case 3:
1337
1373
  case "end":
1338
- return _context.stop();
1374
+ return _context2.stop();
1339
1375
  }
1340
- }, _loop);
1376
+ }, _loop2);
1341
1377
  });
1342
1378
  _iterator6.s();
1343
- case 102:
1379
+ case 116:
1344
1380
  if ((_step6 = _iterator6.n()).done) {
1345
- _context2.next = 106;
1381
+ _context3.next = 120;
1346
1382
  break;
1347
1383
  }
1348
- return _context2.delegateYield(_loop(), "t0", 104);
1349
- case 104:
1350
- _context2.next = 102;
1384
+ return _context3.delegateYield(_loop2(), "t2", 118);
1385
+ case 118:
1386
+ _context3.next = 116;
1351
1387
  break;
1352
- case 106:
1353
- _context2.next = 111;
1388
+ case 120:
1389
+ _context3.next = 125;
1354
1390
  break;
1355
- case 108:
1356
- _context2.prev = 108;
1357
- _context2.t1 = _context2["catch"](99);
1358
- _iterator6.e(_context2.t1);
1359
- case 111:
1360
- _context2.prev = 111;
1391
+ case 122:
1392
+ _context3.prev = 122;
1393
+ _context3.t3 = _context3["catch"](113);
1394
+ _iterator6.e(_context3.t3);
1395
+ case 125:
1396
+ _context3.prev = 125;
1361
1397
  _iterator6.f();
1362
- return _context2.finish(111);
1363
- case 114:
1398
+ return _context3.finish(125);
1399
+ case 128:
1364
1400
  if (!manualMessage) {
1365
- _context2.next = 130;
1401
+ _context3.next = 144;
1366
1402
  break;
1367
1403
  }
1368
1404
  /** @type {import('@scout9/admin').Message} */
@@ -1374,25 +1410,25 @@ var Spirits = {
1374
1410
  time: new Date().toISOString()
1375
1411
  };
1376
1412
  if (!(_typeof(manualMessage) === 'object')) {
1377
- _context2.next = 122;
1413
+ _context3.next = 136;
1378
1414
  break;
1379
1415
  }
1380
1416
  Object.assign(manualMessageObj, manualMessage);
1381
1417
  manualMessageObj.role = 'agent';
1382
1418
  manualMessageObj.time = new Date().toISOString();
1383
- _context2.next = 127;
1419
+ _context3.next = 141;
1384
1420
  break;
1385
- case 122:
1421
+ case 136:
1386
1422
  if (!(typeof manualMessage === 'string')) {
1387
- _context2.next = 126;
1423
+ _context3.next = 140;
1388
1424
  break;
1389
1425
  }
1390
1426
  manualMessageObj.content = manualMessage;
1391
- _context2.next = 127;
1427
+ _context3.next = 141;
1392
1428
  break;
1393
- case 126:
1429
+ case 140:
1394
1430
  throw new Error('Manual message must be of type "string" or "DirectMessage"');
1395
- case 127:
1431
+ case 141:
1396
1432
  if (scheduled) {
1397
1433
  manualMessageObj.time = new Date(scheduled * 1000).toISOString();
1398
1434
  manualMessageObj.scheduled = manualMessageObj.time;
@@ -1404,7 +1440,7 @@ var Spirits = {
1404
1440
  }
1405
1441
  messages.push(manualMessageObj);
1406
1442
  progress('Added manual message', 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
1407
- case 130:
1443
+ case 144:
1408
1444
  if (contextUpsert) {
1409
1445
  context = updateContext(context, contextUpsert);
1410
1446
  progress('Upserted context', 'info', 'UPDATE_CONTEXT', contextUpsert);
@@ -1412,21 +1448,21 @@ var Spirits = {
1412
1448
  if (resetIntent) {
1413
1449
  resettedIntent = true;
1414
1450
  }
1415
- case 132:
1416
- _context2.next = 63;
1451
+ case 146:
1452
+ _context3.next = 77;
1417
1453
  break;
1418
- case 134:
1419
- _context2.next = 139;
1454
+ case 148:
1455
+ _context3.next = 153;
1420
1456
  break;
1421
- case 136:
1422
- _context2.prev = 136;
1423
- _context2.t2 = _context2["catch"](61);
1424
- _iterator2.e(_context2.t2);
1425
- case 139:
1426
- _context2.prev = 139;
1457
+ case 150:
1458
+ _context3.prev = 150;
1459
+ _context3.t4 = _context3["catch"](75);
1460
+ _iterator2.e(_context3.t4);
1461
+ case 153:
1462
+ _context3.prev = 153;
1427
1463
  _iterator2.f();
1428
- return _context2.finish(139);
1429
- case 142:
1464
+ return _context3.finish(153);
1465
+ case 156:
1430
1466
  if (resettedIntent && !_forward) {
1431
1467
  conversation.intent = null;
1432
1468
  conversation.intentScore = null;
@@ -1445,14 +1481,14 @@ var Spirits = {
1445
1481
  // 5. Generate response
1446
1482
  // If conversation previously locked, don't generate
1447
1483
  if (input.conversation.locked) {
1448
- _context2.next = 194;
1484
+ _context3.next = 208;
1449
1485
  break;
1450
1486
  }
1451
1487
  if (!((!conversation.locked || !hasNoInstructions) && !!hasNoCustomMessage)) {
1452
- _context2.next = 160;
1488
+ _context3.next = 174;
1453
1489
  break;
1454
1490
  }
1455
- _context2.prev = 145;
1491
+ _context3.prev = 159;
1456
1492
  progress('Generating message', 'info', 'SET_PROCESSING', 'system');
1457
1493
 
1458
1494
  /** @type {import('@scout9/admin').GenerateRequestOneOf1} */
@@ -1466,10 +1502,10 @@ var Spirits = {
1466
1502
  if (!!_tasks && Array.isArray(_tasks) && !!_tasks.length) {
1467
1503
  generatorInput.tasks = _tasks;
1468
1504
  }
1469
- _context2.next = 151;
1505
+ _context3.next = 165;
1470
1506
  return generator(generatorInput);
1471
- case 151:
1472
- generatorPayload = _context2.sent;
1507
+ case 165:
1508
+ generatorPayload = _context3.sent;
1473
1509
  if (!generatorPayload.send) {
1474
1510
  progress('Generated response', 'failed', undefined, {
1475
1511
  error: ((_generatorPayload$err = generatorPayload.errors) === null || _generatorPayload$err === void 0 ? void 0 : _generatorPayload$err.join('\n\n')) || 'Unknown Reason'
@@ -1542,30 +1578,30 @@ var Spirits = {
1542
1578
  }
1543
1579
  }
1544
1580
  }
1545
- _context2.next = 160;
1581
+ _context3.next = 174;
1546
1582
  break;
1547
- case 155:
1548
- _context2.prev = 155;
1549
- _context2.t3 = _context2["catch"](145);
1550
- onError(_context2.t3);
1551
- console.error("Spirits: Locking conversation, error generating response: ".concat(_context2.t3.message));
1552
- conversation = lockConversation(conversation, 'API: ' + _context2.t3.message);
1553
- case 160:
1583
+ case 169:
1584
+ _context3.prev = 169;
1585
+ _context3.t5 = _context3["catch"](159);
1586
+ onError(_context3.t5);
1587
+ console.error("Spirits: Locking conversation, error generating response: ".concat(_context3.t5.message));
1588
+ conversation = lockConversation(conversation, 'API: ' + _context3.t5.message);
1589
+ case 174:
1554
1590
  if (!(messagesToTransform.length && transformer)) {
1555
- _context2.next = 193;
1591
+ _context3.next = 207;
1556
1592
  break;
1557
1593
  }
1558
- _context2.prev = 161;
1594
+ _context3.prev = 175;
1559
1595
  _iterator4 = _createForOfIteratorHelper(messagesToTransform);
1560
- _context2.prev = 163;
1596
+ _context3.prev = 177;
1561
1597
  _iterator4.s();
1562
- case 165:
1598
+ case 179:
1563
1599
  if ((_step4 = _iterator4.n()).done) {
1564
- _context2.next = 176;
1600
+ _context3.next = 190;
1565
1601
  break;
1566
1602
  }
1567
1603
  _step4.value;
1568
- _context2.next = 169;
1604
+ _context3.next = 183;
1569
1605
  return transformer({
1570
1606
  message: messagesToTransform,
1571
1607
  persona: persona,
@@ -1573,8 +1609,8 @@ var Spirits = {
1573
1609
  messages: messages,
1574
1610
  context: context
1575
1611
  });
1576
- case 169:
1577
- transformResponse = _context2.sent;
1612
+ case 183:
1613
+ transformResponse = _context3.sent;
1578
1614
  progress('Generated response', 'success', undefined, undefined);
1579
1615
  // Check if already had message
1580
1616
  _agentMessages = messages.filter(function (m) {
@@ -1593,39 +1629,39 @@ var Spirits = {
1593
1629
  });
1594
1630
  progress('Added agent message', 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
1595
1631
  }
1596
- case 174:
1597
- _context2.next = 165;
1632
+ case 188:
1633
+ _context3.next = 179;
1598
1634
  break;
1599
- case 176:
1600
- _context2.next = 181;
1635
+ case 190:
1636
+ _context3.next = 195;
1601
1637
  break;
1602
- case 178:
1603
- _context2.prev = 178;
1604
- _context2.t4 = _context2["catch"](163);
1605
- _iterator4.e(_context2.t4);
1606
- case 181:
1607
- _context2.prev = 181;
1638
+ case 192:
1639
+ _context3.prev = 192;
1640
+ _context3.t6 = _context3["catch"](177);
1641
+ _iterator4.e(_context3.t6);
1642
+ case 195:
1643
+ _context3.prev = 195;
1608
1644
  _iterator4.f();
1609
- return _context2.finish(181);
1610
- case 184:
1611
- _context2.next = 191;
1645
+ return _context3.finish(195);
1646
+ case 198:
1647
+ _context3.next = 205;
1612
1648
  break;
1613
- case 186:
1614
- _context2.prev = 186;
1615
- _context2.t5 = _context2["catch"](161);
1616
- console.error("Locking conversation, error transforming response: ".concat(_context2.t5.message));
1617
- conversation = lockConversation(conversation, 'API: ' + _context2.t5.message);
1618
- onError(_context2.t5);
1619
- case 191:
1620
- _context2.next = 194;
1649
+ case 200:
1650
+ _context3.prev = 200;
1651
+ _context3.t7 = _context3["catch"](175);
1652
+ console.error("Locking conversation, error transforming response: ".concat(_context3.t7.message));
1653
+ conversation = lockConversation(conversation, 'API: ' + _context3.t7.message);
1654
+ onError(_context3.t7);
1655
+ case 205:
1656
+ _context3.next = 208;
1621
1657
  break;
1622
- case 193:
1658
+ case 207:
1623
1659
  if (messagesToTransform.length) {
1624
1660
  console.warn("No transformer provided");
1625
1661
  }
1626
- case 194:
1662
+ case 208:
1627
1663
  progress('Parsing message', 'info', 'SET_PROCESSING', null);
1628
- return _context2.abrupt("return", {
1664
+ return _context3.abrupt("return", {
1629
1665
  conversation: {
1630
1666
  before: conversationBefore,
1631
1667
  after: conversation,
@@ -1647,11 +1683,11 @@ var Spirits = {
1647
1683
  followup: followup,
1648
1684
  entityContextUpsert: entityContextUpsert
1649
1685
  });
1650
- case 196:
1686
+ case 210:
1651
1687
  case "end":
1652
- return _context2.stop();
1688
+ return _context3.stop();
1653
1689
  }
1654
- }, _callee, null, [[61, 136, 139, 142], [99, 108, 111, 114], [145, 155], [161, 186], [163, 178, 181, 184]]);
1690
+ }, _callee, null, [[49, 58, 61, 64], [75, 150, 153, 156], [113, 122, 125, 128], [159, 169], [175, 200], [177, 192, 195, 198]]);
1655
1691
  }));
1656
1692
  function customer(_x) {
1657
1693
  return _customer.apply(this, arguments);
package/dist/spirits.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var spirits = require("./spirits-c67815ee.cjs");
5
+ var spirits = require("./spirits-011bdf25.cjs");
6
6
 
7
7
 
8
8
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dev = require("./dev-1918d4f5.cjs");
6
- require("./spirits-c67815ee.cjs");
5
+ var dev = require("./dev-5557cad7.cjs");
6
+ require("./spirits-011bdf25.cjs");
7
7
  require('util');
8
8
  require('stream');
9
9
  require('path');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scout9/app",
3
- "version": "1.0.0-alpha.0.8.5",
3
+ "version": "1.0.0-alpha.0.8.6",
4
4
  "description": "Build and deploy your Scout9 app for SMS auto replies",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -352,21 +352,31 @@ export const Spirits = {
352
352
 
353
353
  // upsert parse system messages
354
354
  if (parsePayload.contextMessages.length) {
355
- messages.push(...parsePayload.contextMessages.map((text) => ({
356
- id: idGenerator('sys'),
357
- role: 'system',
358
- content: text,
359
- time: new Date().toISOString()
360
- })));
355
+ messages.push(
356
+ ...parsePayload.contextMessages.reduce((accumulator, text) => {
357
+ if (!messages.find(mes => mes.content === text)) {
358
+ accumulator.push({
359
+ id: idGenerator('sys'),
360
+ role: 'system',
361
+ content: text,
362
+ time: new Date().toISOString()
363
+ });
364
+ } else {
365
+ progress(`Already have system context, skipping`, 'info');
366
+ }
367
+ return accumulator;
368
+ }, []));
361
369
  }
362
370
 
363
371
  // 3. Run the contextualizer
364
- progress('Running contextualizer', 'info', 'SET_PROCESSING', 'system')
372
+ progress('Running contextualizer', 'info', 'SET_PROCESSING', 'system');
365
373
  const newContextMessages = await contextualizer({conversation, messages});
366
374
  for (const contextMessage of newContextMessages) {
367
- if (contextMessage.entities.length) {
375
+ if (!messages.find(mes => mes.content === contextMessage.content)) {
368
376
  messages.push(contextMessage);
369
377
  progress(`Added context`, 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
378
+ } else {
379
+ progress(`Already have system context, skipping`, 'info');
370
380
  }
371
381
  }
372
382
 
@@ -638,7 +648,12 @@ export const Spirits = {
638
648
  }
639
649
  const generatorPayload = await generator(generatorInput);
640
650
  if (!generatorPayload.send) {
641
- progress('Generated response', 'failed', undefined, {error: generatorPayload.errors?.join('\n\n') || 'Unknown Reason'});
651
+ progress(
652
+ 'Generated response',
653
+ 'failed',
654
+ undefined,
655
+ {error: generatorPayload.errors?.join('\n\n') || 'Unknown Reason'}
656
+ );
642
657
  console.error(
643
658
  `Locking conversation, api returned send false: ${generatorPayload.messages}`,
644
659
  generatorPayload.errors?.join('\n\n') || generatorPayload.forwardNote || 'Unknown Reason'
@@ -672,14 +687,15 @@ export const Spirits = {
672
687
  }
673
688
 
674
689
  return ({
675
- id: idGenerator(message.role),
676
- content: message.content,
677
- role: message.role,
678
- time,
679
- entities: message.entities ?? {},
680
- context: message.context ?? {},
681
- mediaUrls: message.mediaUrls
682
- })})
690
+ id: idGenerator(message.role),
691
+ content: message.content,
692
+ role: message.role,
693
+ time,
694
+ entities: message.entities ?? {},
695
+ context: message.context ?? {},
696
+ mediaUrls: message.mediaUrls
697
+ });
698
+ })
683
699
  ]
684
700
  .reduce((accumulator, message) => {
685
701
  if (!accumulator.find(m => m.content === message.content)) accumulator.push(message);