@scout9/app 1.0.0-alpha.0.6.4 → 1.0.0-alpha.0.6.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-e626085b.cjs");
3
+ var spirits = require("./spirits-9719ae4f.cjs");
4
4
  var require$$0$4 = require('util');
5
5
  var require$$0$3 = require('stream');
6
6
  var require$$1 = require('path');
@@ -21,7 +21,7 @@ var node_url = require('node:url');
21
21
  var node_events = require('node:events');
22
22
  var Stream = require('node:stream');
23
23
  var node_string_decoder = require('node:string_decoder');
24
- var macros = require("./macros-a37c4a77.cjs");
24
+ var macros = require("./macros-1a4fd407.cjs");
25
25
  var readline = require('node:readline');
26
26
  var process$2 = require('node:process');
27
27
  var node_os = require('node:os');
@@ -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-fee40f1c.js', document.baseURI).href))), 'utf-8');
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-df88036b.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,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var spirits = require("./spirits-e626085b.cjs");
4
- var dev = require("./dev-fee40f1c.cjs");
5
- var macros = require("./macros-a37c4a77.cjs");
3
+ var spirits = require("./spirits-9719ae4f.cjs");
4
+ var dev = require("./dev-df88036b.cjs");
5
+ var macros = require("./macros-1a4fd407.cjs");
6
6
  var require$$0 = require('fs');
7
7
  var require$$2$1 = require('events');
8
8
  var require$$1 = require('path');
@@ -29483,7 +29483,7 @@ class Body {
29483
29483
  }
29484
29484
  const {
29485
29485
  toFormData
29486
- } = await Promise.resolve().then(function () { return require("./multipart-parser-06b501ee.cjs"); });
29486
+ } = await Promise.resolve().then(function () { return require("./multipart-parser-17ab0a54.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-b59a82b2.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-33d77bc4.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-b59a82b2.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-33d77bc4.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-b59a82b2.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-33d77bc4.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,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require("./index-b59a82b2.cjs");
6
- var dev = require("./dev-fee40f1c.cjs");
7
- require("./spirits-e626085b.cjs");
8
- require("./macros-a37c4a77.cjs");
5
+ var index = require("./index-33d77bc4.cjs");
6
+ var dev = require("./dev-df88036b.cjs");
7
+ require("./spirits-9719ae4f.cjs");
8
+ require("./macros-1a4fd407.cjs");
9
9
  require('fs');
10
10
  require('events');
11
11
  require('path');
@@ -4047,7 +4047,13 @@ var MessageSchema = z.object({
4047
4047
  delayInSeconds: z.number({
4048
4048
  description: 'How long to delay the message manually in seconds'
4049
4049
  }).nullable().optional(),
4050
- entities: z.array(MessageEntitySchema).optional().nullable()
4050
+ entities: z.array(MessageEntitySchema).optional().nullable(),
4051
+ ignoreTransform: z["boolean"]({
4052
+ description: 'If set to true, the PMT will not transform, message will be sent as is'
4053
+ }).optional(),
4054
+ mediaUrls: z.array(z.string(), {
4055
+ description: 'Media urls to attach to the transported message'
4056
+ }).optional().nullable()
4051
4057
  });
4052
4058
 
4053
4059
  var CustomerValueSchema = z.union([z["boolean"](), z.number(), z.string()]);
@@ -2,9 +2,9 @@
2
2
 
3
3
  require('node:fs');
4
4
  require('node:path');
5
- var index = require("./index-b59a82b2.cjs");
6
- require("./spirits-e626085b.cjs");
7
- require("./dev-fee40f1c.cjs");
5
+ var index = require("./index-33d77bc4.cjs");
6
+ require("./spirits-9719ae4f.cjs");
7
+ require("./dev-df88036b.cjs");
8
8
  require('util');
9
9
  require('stream');
10
10
  require('path');
@@ -23,7 +23,7 @@ require('node:url');
23
23
  require('node:events');
24
24
  require('node:stream');
25
25
  require('node:string_decoder');
26
- require("./macros-a37c4a77.cjs");
26
+ require("./macros-1a4fd407.cjs");
27
27
  require('node:readline');
28
28
  require('node:process');
29
29
  require('node:os');
package/dist/schemas.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var macros = require("./macros-a37c4a77.cjs");
5
+ var macros = require("./macros-1a4fd407.cjs");
6
6
 
7
7
 
8
8
 
@@ -730,6 +730,7 @@ var _excluded = ["keywords"];
730
730
  * @property {Change<any>} context
731
731
  * @property {Change<import('@scout9/app').Message>} message
732
732
  * @property {Array<import('@scout9/app').Followup>} followup
733
+ * @property {Array<import('@scout9/app').EntityContextUpsert>} entityContextUpsert
733
734
  */
734
735
  var Spirits = {
735
736
  /**
@@ -740,13 +741,14 @@ var Spirits = {
740
741
  customer: function () {
741
742
  var _customer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
742
743
  var _recentUserMessage;
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, _generatorPayload$ent, _generatorPayload$con, _iterator2, _step2, transformResponse, _agentMessages, _lastAgentMessage;
744
+ var customer, config, parser, workflow, generator, transformer, idGenerator, _input$progress, progress, messageBefore, contextBefore, messagesBefore, conversationBefore, conversation, messages, context, message, followup, entityContextUpsert, 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, slotEntityContextUpsert, _slots, map, i, _anticipate$i, keywords, _slot, slotId, _iterator3, _step3, instruction, _iterator4, _step4, _loop, manualMessageObj, now, generatorPayload, agentMessages, lastAgentMessage, _generatorPayload$ent, _generatorPayload$con, _iterator2, _step2, transformResponse, _agentMessages, _lastAgentMessage;
744
745
  return _regeneratorRuntime().wrap(function _callee$(_context2) {
745
746
  while (1) switch (_context2.prev = _context2.next) {
746
747
  case 0:
747
748
  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;
748
- conversation = input.conversation, messages = input.messages, context = input.context, message = input.message;
749
- followup = []; // 0. Setup Helpers
749
+ conversation = input.conversation, messages = input.messages, context = input.context, message = input.message; // Storing post process events here
750
+ followup = [];
751
+ entityContextUpsert = []; // 0. Setup Helpers
750
752
  updateConversation = function updateConversation(previousConversation, conversationUpdates) {
751
753
  progress('Update conversation', 'info', 'UPDATE_CONVERSATION', conversationUpdates);
752
754
  return _objectSpread2(_objectSpread2({}, previousConversation), conversationUpdates);
@@ -835,40 +837,40 @@ var Spirits = {
835
837
  }
836
838
  }; // 1. Check inputs
837
839
  if (conversation.$agent) {
838
- _context2.next = 13;
840
+ _context2.next = 14;
839
841
  break;
840
842
  }
841
843
  throw new Error("SpiritsError: No agent found in conversation, must define \".$agent\" in the conversation");
842
- case 13:
844
+ case 14:
843
845
  persona = (config.persona || config.personas || config.agents).find(function (p) {
844
846
  return p.id === conversation.$agent;
845
847
  });
846
848
  if (persona) {
847
- _context2.next = 18;
849
+ _context2.next = 19;
848
850
  break;
849
851
  }
850
852
  if (!(config.persona || config.personas || config.agents).some(function (a) {
851
853
  return !a.id;
852
854
  })) {
853
- _context2.next = 17;
855
+ _context2.next = 18;
854
856
  break;
855
857
  }
856
858
  throw new Error("SpiritsError: No persona found (\"".concat(conversation.$agent, "\") in provided config, some persona's did not contain an \"id\" (Internal Mapping Error)"));
857
- case 17:
858
- throw new Error("SpiritsError: No persona found (\"".concat(conversation.$agent, "\") in provided config"));
859
859
  case 18:
860
+ throw new Error("SpiritsError: No persona found (\"".concat(conversation.$agent, "\") in provided config"));
861
+ case 19:
860
862
  if (messages.every(function (m) {
861
863
  return !!m.id;
862
864
  })) {
863
- _context2.next = 20;
865
+ _context2.next = 21;
864
866
  break;
865
867
  }
866
868
  throw new Error("SpiritsError: Every message must have an \".id\", ensure all messages have an id assigned before running");
867
- case 20:
869
+ case 21:
868
870
  if (messages.every(function (m) {
869
871
  return m.role === 'customer' || m.role === 'agent' || m.role === 'system';
870
872
  })) {
871
- _context2.next = 23;
873
+ _context2.next = 24;
872
874
  break;
873
875
  }
874
876
  invalidRoles = messages.filter(function (m) {
@@ -877,7 +879,7 @@ var Spirits = {
877
879
  throw new Error("SpiritsError: Every message must have a role of \"customer\", \"agent\", or \"system\". Got invalid roles: ".concat(invalidRoles.map(function (m) {
878
880
  return m.role;
879
881
  }).join(', ')));
880
- case 23:
882
+ case 24:
881
883
  // if message is not in messages, then add it
882
884
  if (!messages.find(function (m) {
883
885
  return m.id === input.message.id;
@@ -887,9 +889,9 @@ var Spirits = {
887
889
 
888
890
  // 2. Parse the message
889
891
  progress('Parsing message', 'info', 'SET_PROCESSING', 'user');
890
- _context2.next = 27;
892
+ _context2.next = 28;
891
893
  return parser(message.content, 'en');
892
- case 27:
894
+ case 28:
893
895
  parsePayload = _context2.sent;
894
896
  if (parsePayload.intent) {
895
897
  message.intent = parsePayload.intent;
@@ -960,7 +962,7 @@ var Spirits = {
960
962
  }
961
963
  noNewContext = Object.keys(parsePayload.context).length === 0; // 3. Run the workflow
962
964
  progress('Running workflow', 'info', 'SET_PROCESSING', 'system');
963
- _context2.next = 44;
965
+ _context2.next = 45;
964
966
  return workflow({
965
967
  messages: messages,
966
968
  conversation: conversation,
@@ -989,7 +991,7 @@ var Spirits = {
989
991
  return accumulator;
990
992
  }, []);
991
993
  });
992
- case 44:
994
+ case 45:
993
995
  slots = _context2.sent;
994
996
  hasNoInstructions = slots.every(function (s) {
995
997
  return !s.instructions || Array.isArray(s.instructions) && s.instructions.length === 0;
@@ -1015,20 +1017,20 @@ var Spirits = {
1015
1017
  }
1016
1018
  resettedIntent = false;
1017
1019
  _iterator = _createForOfIteratorHelper(slots);
1018
- _context2.prev = 52;
1020
+ _context2.prev = 53;
1019
1021
  _iterator.s();
1020
- case 54:
1022
+ case 55:
1021
1023
  if ((_step = _iterator.n()).done) {
1022
- _context2.next = 114;
1024
+ _context2.next = 125;
1023
1025
  break;
1024
1026
  }
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;
1027
+ _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;
1026
1028
  if (!anticipate) {
1027
- _context2.next = 69;
1029
+ _context2.next = 70;
1028
1030
  break;
1029
1031
  }
1030
1032
  if (!Array.isArray(anticipate)) {
1031
- _context2.next = 64;
1033
+ _context2.next = 65;
1032
1034
  break;
1033
1035
  }
1034
1036
  // 'literal' anticipation
@@ -1048,11 +1050,11 @@ var Spirits = {
1048
1050
  slots: _slots,
1049
1051
  map: map
1050
1052
  });
1051
- _context2.next = 69;
1053
+ _context2.next = 70;
1052
1054
  break;
1053
- case 64:
1055
+ case 65:
1054
1056
  if (!('yes' in anticipate && 'no' in anticipate && 'did' in anticipate)) {
1055
- _context2.next = 68;
1057
+ _context2.next = 69;
1056
1058
  break;
1057
1059
  }
1058
1060
  // "did" anticipation
@@ -1064,14 +1066,17 @@ var Spirits = {
1064
1066
  },
1065
1067
  did: anticipate.did
1066
1068
  });
1067
- _context2.next = 69;
1069
+ _context2.next = 70;
1068
1070
  break;
1069
- case 68:
1070
- throw new Error("Invalid anticipate payload \"".concat(JSON.stringify(anticipate), "\""));
1071
1071
  case 69:
1072
+ throw new Error("Invalid anticipate payload \"".concat(JSON.stringify(anticipate), "\""));
1073
+ case 70:
1072
1074
  if (slotFollowup) {
1073
1075
  followup.push(slotFollowup);
1074
1076
  }
1077
+ if (slotEntityContextUpsert && slotEntityContextUpsert.length) {
1078
+ entityContextUpsert.push.apply(entityContextUpsert, _toConsumableArray(slotEntityContextUpsert));
1079
+ }
1075
1080
 
1076
1081
  // Forward to agent or other agent
1077
1082
  if (forward) {
@@ -1116,19 +1121,19 @@ var Spirits = {
1116
1121
 
1117
1122
  // Insert instructions context
1118
1123
  if (!instructions) {
1119
- _context2.next = 86;
1124
+ _context2.next = 88;
1120
1125
  break;
1121
1126
  }
1122
1127
  if (!(typeof instructions === 'string')) {
1123
- _context2.next = 76;
1128
+ _context2.next = 78;
1124
1129
  break;
1125
1130
  }
1126
1131
  addInstruction(instructions, previousLockAttempt);
1127
- _context2.next = 86;
1132
+ _context2.next = 88;
1128
1133
  break;
1129
- case 76:
1134
+ case 78:
1130
1135
  if (!Array.isArray(instructions)) {
1131
- _context2.next = 81;
1136
+ _context2.next = 83;
1132
1137
  break;
1133
1138
  }
1134
1139
  _iterator3 = _createForOfIteratorHelper(instructions);
@@ -1146,25 +1151,25 @@ var Spirits = {
1146
1151
  } finally {
1147
1152
  _iterator3.f();
1148
1153
  }
1149
- _context2.next = 86;
1154
+ _context2.next = 88;
1150
1155
  break;
1151
- case 81:
1156
+ case 83:
1152
1157
  if (!(_typeof(instructions) === 'object' && 'content' in instructions)) {
1153
- _context2.next = 85;
1158
+ _context2.next = 87;
1154
1159
  break;
1155
1160
  }
1156
1161
  addInstruction(instructions.content, previousLockAttempt, instructions.id);
1157
- _context2.next = 86;
1162
+ _context2.next = 88;
1158
1163
  break;
1159
- case 85:
1164
+ case 87:
1160
1165
  throw new Error("SpiritsError: instructions must be a string or array or {content: \"<instruction>\"}, got: ".concat(JSON.stringify(instructions)));
1161
- case 86:
1166
+ case 88:
1162
1167
  if (!removeInstructions) {
1163
- _context2.next = 103;
1168
+ _context2.next = 105;
1164
1169
  break;
1165
1170
  }
1166
1171
  _iterator4 = _createForOfIteratorHelper(removeInstructions);
1167
- _context2.prev = 88;
1172
+ _context2.prev = 90;
1168
1173
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
1169
1174
  var instructionId, index;
1170
1175
  return _regeneratorRuntime().wrap(function _loop$(_context) {
@@ -1189,43 +1194,59 @@ var Spirits = {
1189
1194
  }, _loop);
1190
1195
  });
1191
1196
  _iterator4.s();
1192
- case 91:
1197
+ case 93:
1193
1198
  if ((_step4 = _iterator4.n()).done) {
1194
- _context2.next = 95;
1199
+ _context2.next = 97;
1195
1200
  break;
1196
1201
  }
1197
- return _context2.delegateYield(_loop(), "t0", 93);
1198
- case 93:
1199
- _context2.next = 91;
1200
- break;
1202
+ return _context2.delegateYield(_loop(), "t0", 95);
1201
1203
  case 95:
1202
- _context2.next = 100;
1204
+ _context2.next = 93;
1203
1205
  break;
1204
1206
  case 97:
1205
- _context2.prev = 97;
1206
- _context2.t1 = _context2["catch"](88);
1207
+ _context2.next = 102;
1208
+ break;
1209
+ case 99:
1210
+ _context2.prev = 99;
1211
+ _context2.t1 = _context2["catch"](90);
1207
1212
  _iterator4.e(_context2.t1);
1208
- case 100:
1209
- _context2.prev = 100;
1213
+ case 102:
1214
+ _context2.prev = 102;
1210
1215
  _iterator4.f();
1211
- return _context2.finish(100);
1212
- case 103:
1216
+ return _context2.finish(102);
1217
+ case 105:
1213
1218
  if (!manualMessage) {
1214
- _context2.next = 110;
1219
+ _context2.next = 121;
1215
1220
  break;
1216
1221
  }
1222
+ /** @type {import('@scout9/app').Message} */
1217
1223
  manualMessageObj = {
1218
- id: idGenerator('agent'),
1224
+ id: idGenerator('persona'),
1219
1225
  role: 'agent',
1220
- content: manualMessage,
1226
+ // @TODO switch role to persona
1227
+ content: '',
1221
1228
  time: new Date().toISOString()
1222
1229
  };
1223
- if (!(typeof manualMessage !== 'string')) {
1224
- _context2.next = 107;
1230
+ if (!(_typeof(manualMessage) === 'object')) {
1231
+ _context2.next = 113;
1225
1232
  break;
1226
1233
  }
1227
- throw new Error('Manual message must be of type "string"');
1228
- case 107:
1234
+ Object.assign(manualMessageObj, manualMessage);
1235
+ manualMessageObj.role = 'agent';
1236
+ manualMessageObj.time = new Date().toISOString();
1237
+ _context2.next = 118;
1238
+ break;
1239
+ case 113:
1240
+ if (!(typeof manualMessage === 'string')) {
1241
+ _context2.next = 117;
1242
+ break;
1243
+ }
1244
+ manualMessageObj.content = manualMessage;
1245
+ _context2.next = 118;
1246
+ break;
1247
+ case 117:
1248
+ throw new Error('Manual message must be of type "string" or "DirectMessage"');
1249
+ case 118:
1229
1250
  if (scheduled) {
1230
1251
  manualMessageObj.time = new Date(scheduled * 1000).toISOString();
1231
1252
  manualMessageObj.scheduled = manualMessageObj.time;
@@ -1237,7 +1258,7 @@ var Spirits = {
1237
1258
  }
1238
1259
  messages.push(manualMessageObj);
1239
1260
  progress('Added manual message', 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
1240
- case 110:
1261
+ case 121:
1241
1262
  if (contextUpsert) {
1242
1263
  context = updateContext(context, contextUpsert);
1243
1264
  progress('Upserted context', 'info', 'UPDATE_CONTEXT', contextUpsert);
@@ -1245,21 +1266,21 @@ var Spirits = {
1245
1266
  if (resetIntent) {
1246
1267
  resettedIntent = true;
1247
1268
  }
1248
- case 112:
1249
- _context2.next = 54;
1269
+ case 123:
1270
+ _context2.next = 55;
1250
1271
  break;
1251
- case 114:
1252
- _context2.next = 119;
1272
+ case 125:
1273
+ _context2.next = 130;
1253
1274
  break;
1254
- case 116:
1255
- _context2.prev = 116;
1256
- _context2.t2 = _context2["catch"](52);
1275
+ case 127:
1276
+ _context2.prev = 127;
1277
+ _context2.t2 = _context2["catch"](53);
1257
1278
  _iterator.e(_context2.t2);
1258
- case 119:
1259
- _context2.prev = 119;
1279
+ case 130:
1280
+ _context2.prev = 130;
1260
1281
  _iterator.f();
1261
- return _context2.finish(119);
1262
- case 122:
1282
+ return _context2.finish(130);
1283
+ case 133:
1263
1284
  if (resettedIntent && !_forward) {
1264
1285
  conversation.intent = null;
1265
1286
  conversation.intentScore = null;
@@ -1278,16 +1299,16 @@ var Spirits = {
1278
1299
  // 4. Generate response
1279
1300
  // If conversation previously locked, don't generate
1280
1301
  if (input.conversation.locked) {
1281
- _context2.next = 170;
1302
+ _context2.next = 181;
1282
1303
  break;
1283
1304
  }
1284
1305
  if (!((!conversation.locked || !hasNoInstructions) && !!hasNoCustomMessage)) {
1285
- _context2.next = 137;
1306
+ _context2.next = 148;
1286
1307
  break;
1287
1308
  }
1288
- _context2.prev = 125;
1309
+ _context2.prev = 136;
1289
1310
  progress('Generating message', 'info', 'SET_PROCESSING', 'system');
1290
- _context2.next = 129;
1311
+ _context2.next = 140;
1291
1312
  return generator({
1292
1313
  messages: messages,
1293
1314
  persona: persona,
@@ -1295,7 +1316,7 @@ var Spirits = {
1295
1316
  llm: config.llm,
1296
1317
  pmt: config.pmt
1297
1318
  });
1298
- case 129:
1319
+ case 140:
1299
1320
  generatorPayload = _context2.sent;
1300
1321
  if (!generatorPayload.send) {
1301
1322
  progress('Generated response', 'failed', undefined, {
@@ -1334,29 +1355,29 @@ var Spirits = {
1334
1355
  }
1335
1356
  }
1336
1357
  }
1337
- _context2.next = 137;
1358
+ _context2.next = 148;
1338
1359
  break;
1339
- case 133:
1340
- _context2.prev = 133;
1341
- _context2.t3 = _context2["catch"](125);
1360
+ case 144:
1361
+ _context2.prev = 144;
1362
+ _context2.t3 = _context2["catch"](136);
1342
1363
  console.error("Locking conversation, error generating response: ".concat(_context2.t3.message));
1343
1364
  conversation = lockConversation(conversation, 'API: ' + _context2.t3.message);
1344
- case 137:
1365
+ case 148:
1345
1366
  if (!(messagesToTransform.length && transformer)) {
1346
- _context2.next = 169;
1367
+ _context2.next = 180;
1347
1368
  break;
1348
1369
  }
1349
- _context2.prev = 138;
1370
+ _context2.prev = 149;
1350
1371
  _iterator2 = _createForOfIteratorHelper(messagesToTransform);
1351
- _context2.prev = 140;
1372
+ _context2.prev = 151;
1352
1373
  _iterator2.s();
1353
- case 142:
1374
+ case 153:
1354
1375
  if ((_step2 = _iterator2.n()).done) {
1355
- _context2.next = 153;
1376
+ _context2.next = 164;
1356
1377
  break;
1357
1378
  }
1358
1379
  _step2.value;
1359
- _context2.next = 146;
1380
+ _context2.next = 157;
1360
1381
  return transformer({
1361
1382
  message: messagesToTransform,
1362
1383
  persona: persona,
@@ -1364,7 +1385,7 @@ var Spirits = {
1364
1385
  messages: messages,
1365
1386
  context: context
1366
1387
  });
1367
- case 146:
1388
+ case 157:
1368
1389
  transformResponse = _context2.sent;
1369
1390
  progress('Generated response', 'success', undefined, undefined);
1370
1391
  // Check if already had message
@@ -1384,36 +1405,36 @@ var Spirits = {
1384
1405
  });
1385
1406
  progress('Added agent message', 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
1386
1407
  }
1387
- case 151:
1388
- _context2.next = 142;
1408
+ case 162:
1409
+ _context2.next = 153;
1389
1410
  break;
1390
- case 153:
1391
- _context2.next = 158;
1411
+ case 164:
1412
+ _context2.next = 169;
1392
1413
  break;
1393
- case 155:
1394
- _context2.prev = 155;
1395
- _context2.t4 = _context2["catch"](140);
1414
+ case 166:
1415
+ _context2.prev = 166;
1416
+ _context2.t4 = _context2["catch"](151);
1396
1417
  _iterator2.e(_context2.t4);
1397
- case 158:
1398
- _context2.prev = 158;
1418
+ case 169:
1419
+ _context2.prev = 169;
1399
1420
  _iterator2.f();
1400
- return _context2.finish(158);
1401
- case 161:
1402
- _context2.next = 167;
1421
+ return _context2.finish(169);
1422
+ case 172:
1423
+ _context2.next = 178;
1403
1424
  break;
1404
- case 163:
1405
- _context2.prev = 163;
1406
- _context2.t5 = _context2["catch"](138);
1425
+ case 174:
1426
+ _context2.prev = 174;
1427
+ _context2.t5 = _context2["catch"](149);
1407
1428
  console.error("Locking conversation, error transforming response: ".concat(_context2.t5.message));
1408
1429
  conversation = lockConversation(conversation, 'API: ' + _context2.t5.message);
1409
- case 167:
1410
- _context2.next = 170;
1430
+ case 178:
1431
+ _context2.next = 181;
1411
1432
  break;
1412
- case 169:
1433
+ case 180:
1413
1434
  if (messagesToTransform.length) {
1414
1435
  console.warn("No transformer provided");
1415
1436
  }
1416
- case 170:
1437
+ case 181:
1417
1438
  progress('Parsing message', 'info', 'SET_PROCESSING', null);
1418
1439
  return _context2.abrupt("return", {
1419
1440
  conversation: {
@@ -1434,13 +1455,14 @@ var Spirits = {
1434
1455
  before: contextBefore,
1435
1456
  after: context
1436
1457
  },
1437
- followup: followup
1458
+ followup: followup,
1459
+ entityContextUpsert: entityContextUpsert
1438
1460
  });
1439
- case 172:
1461
+ case 183:
1440
1462
  case "end":
1441
1463
  return _context2.stop();
1442
1464
  }
1443
- }, _callee, null, [[52, 116, 119, 122], [88, 97, 100, 103], [125, 133], [138, 163], [140, 155, 158, 161]]);
1465
+ }, _callee, null, [[53, 127, 130, 133], [90, 99, 102, 105], [136, 144], [149, 174], [151, 166, 169, 172]]);
1444
1466
  }));
1445
1467
  function customer(_x) {
1446
1468
  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-e626085b.cjs");
5
+ var spirits = require("./spirits-9719ae4f.cjs");
6
6
 
7
7
 
8
8