@scout9/app 1.0.0-alpha.0.5.7 → 1.0.0-alpha.0.5.9

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,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var spirits = require("./spirits-2ab4d673.cjs");
4
- var dev = require("./dev-cd37b736.cjs");
5
- var macros = require("./macros-f855de63.cjs");
3
+ var spirits = require("./spirits-82575cd5.cjs");
4
+ var dev = require("./dev-8ed1e379.cjs");
5
+ var macros = require("./macros-4bff92c7.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-473467a4.cjs"); });
29486
+ } = await Promise.resolve().then(function () { return require("./multipart-parser-8f894f70.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-2dbf44c5.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-4f698e67.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-2dbf44c5.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-4f698e67.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-2dbf44c5.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-4f698e67.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-2dbf44c5.cjs");
6
- var dev = require("./dev-cd37b736.cjs");
7
- require("./spirits-2ab4d673.cjs");
8
- require("./macros-f855de63.cjs");
5
+ var index = require("./index-4f698e67.cjs");
6
+ var dev = require("./dev-8ed1e379.cjs");
7
+ require("./spirits-82575cd5.cjs");
8
+ require("./macros-4bff92c7.cjs");
9
9
  require('fs');
10
10
  require('events');
11
11
  require('path');
@@ -4113,7 +4113,12 @@ var AgentSchema = z.object({
4113
4113
  })).optional(),
4114
4114
  model: z["enum"](['Scout9', 'bard', 'openai']).optional()["default"]('openai'),
4115
4115
  transcripts: z.array(z.array(MessageSchema)).optional(),
4116
- audios: z.array(z.any()).optional()
4116
+ audios: z.array(z.any()).optional(),
4117
+ pmt: z.object({
4118
+ tag: z.string().optional(),
4119
+ ingress: z["enum"](["auto", "manual", "app", "workflow"]),
4120
+ llm: z.string().optional()
4121
+ }).optional()
4117
4122
  });
4118
4123
  var PersonaSchema = AgentSchema;
4119
4124
  var AgentConfigurationSchema = AgentSchema.extend({
@@ -4301,7 +4306,8 @@ var WorkflowEventSchema = z.object({
4301
4306
  includedLocations: true,
4302
4307
  excludedLocations: true,
4303
4308
  model: true,
4304
- context: true
4309
+ context: true,
4310
+ pmt: true
4305
4311
  }),
4306
4312
  customer: CustomerSchema,
4307
4313
  intent: IntentWorkflowEventSchema,
@@ -4321,7 +4327,10 @@ var WorkflowResponseSlotBaseSchema = z.object({
4321
4327
  }).optional(),
4322
4328
  instructions: InstructionSchema.optional(),
4323
4329
  removeInstructions: z.array(z.string()).optional(),
4324
- message: z.string().optional(),
4330
+ message: z.union([z.string(), z.object({
4331
+ content: z.string(),
4332
+ transform: z["boolean"]().optional()
4333
+ })]).optional(),
4325
4334
  secondsDelay: z.number().optional(),
4326
4335
  scheduled: z.number().optional(),
4327
4336
  contextUpsert: ConversationContext.optional(),
@@ -2,9 +2,9 @@
2
2
 
3
3
  require('node:fs');
4
4
  require('node:path');
5
- var index = require("./index-2dbf44c5.cjs");
6
- require("./spirits-2ab4d673.cjs");
7
- require("./dev-cd37b736.cjs");
5
+ var index = require("./index-4f698e67.cjs");
6
+ require("./spirits-82575cd5.cjs");
7
+ require("./dev-8ed1e379.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-f855de63.cjs");
26
+ require("./macros-4bff92c7.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-f855de63.cjs");
5
+ var macros = require("./macros-4bff92c7.cjs");
6
6
 
7
7
 
8
8
 
@@ -683,6 +683,12 @@ var _excluded = ["keywords"];
683
683
  * @returns {Promise<import('@scout9/admin').GenerateResponse>}
684
684
  */
685
685
 
686
+ /**
687
+ * @callback TransformerFun
688
+ * @param {import('@scout9/admin').PmtTransformRequest} data - data to generate from
689
+ * @returns {Promise<import('@scout9/admin').PmtTransformResponse>}
690
+ */
691
+
686
692
  /**
687
693
  * @callback IdGeneratorFun
688
694
  * @param {import('@scout9/app').Message['role']} prefix
@@ -702,6 +708,7 @@ var _excluded = ["keywords"];
702
708
  * @property {ParseFun} parser
703
709
  * @property {WorkflowFun} workflow
704
710
  * @property {GenerateFun} generator
711
+ * @property {TransformerFun} transformer
705
712
  * @property {IdGeneratorFun} idGenerator
706
713
  * @property {StatusCallback | undefined} [progress]
707
714
  */
@@ -723,11 +730,11 @@ var Spirits = {
723
730
  customer: function () {
724
731
  var _customer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
725
732
  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, _iterator2, _step2, instruction, _iterator3, _step3, _loop, manualMessageObj, now, generatorPayload, agentMessages, lastAgentMessage;
733
+ 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
734
  return _regeneratorRuntime().wrap(function _callee$(_context2) {
728
735
  while (1) switch (_context2.prev = _context2.next) {
729
736
  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;
737
+ 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
738
  conversation = input.conversation, messages = input.messages, context = input.context, message = input.message;
732
739
  followup = []; // 0. Setup Helpers
733
740
  updateConversation = function updateConversation(previousConversation, conversationUpdates) {
@@ -977,6 +984,9 @@ var Spirits = {
977
984
  hasNoCustomMessage = slots.every(function (s) {
978
985
  return !s.message;
979
986
  });
987
+ messagesToTransform = slots.filter(function (s) {
988
+ return !!s.message && _typeof(s.message) === 'object' && !!s.message.transform;
989
+ });
980
990
  previousLockAttempt = conversation.lockAttempts || 0; // Used to track
981
991
  if (hasNoInstructions && noNewContext) {
982
992
  conversation = incrementLockAttempt(conversation, config);
@@ -992,20 +1002,20 @@ var Spirits = {
992
1002
  }
993
1003
  resettedIntent = false;
994
1004
  _iterator = _createForOfIteratorHelper(slots);
995
- _context2.prev = 50;
1005
+ _context2.prev = 51;
996
1006
  _iterator.s();
997
- case 52:
1007
+ case 53:
998
1008
  if ((_step = _iterator.n()).done) {
999
- _context2.next = 112;
1009
+ _context2.next = 113;
1000
1010
  break;
1001
1011
  }
1002
1012
  _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
1013
  if (!anticipate) {
1004
- _context2.next = 67;
1014
+ _context2.next = 68;
1005
1015
  break;
1006
1016
  }
1007
1017
  if (!Array.isArray(anticipate)) {
1008
- _context2.next = 62;
1018
+ _context2.next = 63;
1009
1019
  break;
1010
1020
  }
1011
1021
  // 'literal' anticipation
@@ -1025,11 +1035,11 @@ var Spirits = {
1025
1035
  slots: _slots,
1026
1036
  map: map
1027
1037
  });
1028
- _context2.next = 67;
1038
+ _context2.next = 68;
1029
1039
  break;
1030
- case 62:
1040
+ case 63:
1031
1041
  if (!('yes' in anticipate && 'no' in anticipate && 'did' in anticipate)) {
1032
- _context2.next = 66;
1042
+ _context2.next = 67;
1033
1043
  break;
1034
1044
  }
1035
1045
  // "did" anticipation
@@ -1041,11 +1051,11 @@ var Spirits = {
1041
1051
  },
1042
1052
  did: anticipate.did
1043
1053
  });
1044
- _context2.next = 67;
1054
+ _context2.next = 68;
1045
1055
  break;
1046
- case 66:
1047
- throw new Error("Invalid anticipate payload \"".concat(JSON.stringify(anticipate), "\""));
1048
1056
  case 67:
1057
+ throw new Error("Invalid anticipate payload \"".concat(JSON.stringify(anticipate), "\""));
1058
+ case 68:
1049
1059
  if (slotFollowup) {
1050
1060
  followup.push(slotFollowup);
1051
1061
  }
@@ -1093,25 +1103,25 @@ var Spirits = {
1093
1103
 
1094
1104
  // Insert instructions context
1095
1105
  if (!instructions) {
1096
- _context2.next = 84;
1106
+ _context2.next = 85;
1097
1107
  break;
1098
1108
  }
1099
1109
  if (!(typeof instructions === 'string')) {
1100
- _context2.next = 74;
1110
+ _context2.next = 75;
1101
1111
  break;
1102
1112
  }
1103
1113
  addInstruction(instructions, previousLockAttempt);
1104
- _context2.next = 84;
1114
+ _context2.next = 85;
1105
1115
  break;
1106
- case 74:
1116
+ case 75:
1107
1117
  if (!Array.isArray(instructions)) {
1108
- _context2.next = 79;
1118
+ _context2.next = 80;
1109
1119
  break;
1110
1120
  }
1111
- _iterator2 = _createForOfIteratorHelper(instructions);
1121
+ _iterator3 = _createForOfIteratorHelper(instructions);
1112
1122
  try {
1113
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1114
- instruction = _step2.value;
1123
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1124
+ instruction = _step3.value;
1115
1125
  if (typeof instruction === 'string') {
1116
1126
  addInstruction(instruction, previousLockAttempt);
1117
1127
  } else {
@@ -1119,35 +1129,35 @@ var Spirits = {
1119
1129
  }
1120
1130
  }
1121
1131
  } catch (err) {
1122
- _iterator2.e(err);
1132
+ _iterator3.e(err);
1123
1133
  } finally {
1124
- _iterator2.f();
1134
+ _iterator3.f();
1125
1135
  }
1126
- _context2.next = 84;
1136
+ _context2.next = 85;
1127
1137
  break;
1128
- case 79:
1138
+ case 80:
1129
1139
  if (!(_typeof(instructions) === 'object' && 'content' in instructions)) {
1130
- _context2.next = 83;
1140
+ _context2.next = 84;
1131
1141
  break;
1132
1142
  }
1133
1143
  addInstruction(instructions.content, previousLockAttempt, instructions.id);
1134
- _context2.next = 84;
1144
+ _context2.next = 85;
1135
1145
  break;
1136
- case 83:
1137
- throw new Error("SpiritsError: instructions must be a string or array or {content: \"<instruction>\"}, got: ".concat(JSON.stringify(instructions)));
1138
1146
  case 84:
1147
+ throw new Error("SpiritsError: instructions must be a string or array or {content: \"<instruction>\"}, got: ".concat(JSON.stringify(instructions)));
1148
+ case 85:
1139
1149
  if (!removeInstructions) {
1140
- _context2.next = 101;
1150
+ _context2.next = 102;
1141
1151
  break;
1142
1152
  }
1143
- _iterator3 = _createForOfIteratorHelper(removeInstructions);
1144
- _context2.prev = 86;
1153
+ _iterator4 = _createForOfIteratorHelper(removeInstructions);
1154
+ _context2.prev = 87;
1145
1155
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
1146
1156
  var instructionId, index;
1147
1157
  return _regeneratorRuntime().wrap(function _loop$(_context) {
1148
1158
  while (1) switch (_context.prev = _context.next) {
1149
1159
  case 0:
1150
- instructionId = _step3.value;
1160
+ instructionId = _step4.value;
1151
1161
  index = messages.findIndex(function (m) {
1152
1162
  return m.id === instructionId;
1153
1163
  });
@@ -1165,30 +1175,30 @@ var Spirits = {
1165
1175
  }
1166
1176
  }, _loop);
1167
1177
  });
1168
- _iterator3.s();
1169
- case 89:
1170
- if ((_step3 = _iterator3.n()).done) {
1171
- _context2.next = 93;
1178
+ _iterator4.s();
1179
+ case 90:
1180
+ if ((_step4 = _iterator4.n()).done) {
1181
+ _context2.next = 94;
1172
1182
  break;
1173
1183
  }
1174
- return _context2.delegateYield(_loop(), "t0", 91);
1175
- case 91:
1176
- _context2.next = 89;
1184
+ return _context2.delegateYield(_loop(), "t0", 92);
1185
+ case 92:
1186
+ _context2.next = 90;
1177
1187
  break;
1178
- case 93:
1179
- _context2.next = 98;
1188
+ case 94:
1189
+ _context2.next = 99;
1180
1190
  break;
1181
- case 95:
1182
- _context2.prev = 95;
1183
- _context2.t1 = _context2["catch"](86);
1184
- _iterator3.e(_context2.t1);
1185
- case 98:
1186
- _context2.prev = 98;
1187
- _iterator3.f();
1188
- return _context2.finish(98);
1189
- case 101:
1191
+ case 96:
1192
+ _context2.prev = 96;
1193
+ _context2.t1 = _context2["catch"](87);
1194
+ _iterator4.e(_context2.t1);
1195
+ case 99:
1196
+ _context2.prev = 99;
1197
+ _iterator4.f();
1198
+ return _context2.finish(99);
1199
+ case 102:
1190
1200
  if (!manualMessage) {
1191
- _context2.next = 108;
1201
+ _context2.next = 109;
1192
1202
  break;
1193
1203
  }
1194
1204
  manualMessageObj = {
@@ -1198,11 +1208,11 @@ var Spirits = {
1198
1208
  time: new Date().toISOString()
1199
1209
  };
1200
1210
  if (!(typeof manualMessage !== 'string')) {
1201
- _context2.next = 105;
1211
+ _context2.next = 106;
1202
1212
  break;
1203
1213
  }
1204
1214
  throw new Error('Manual message must be of type "string"');
1205
- case 105:
1215
+ case 106:
1206
1216
  if (scheduled) {
1207
1217
  manualMessageObj.time = new Date(scheduled * 1000).toISOString();
1208
1218
  manualMessageObj.scheduled = manualMessageObj.time;
@@ -1214,7 +1224,7 @@ var Spirits = {
1214
1224
  }
1215
1225
  messages.push(manualMessageObj);
1216
1226
  progress('Added manual message', 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
1217
- case 108:
1227
+ case 109:
1218
1228
  if (contextUpsert) {
1219
1229
  context = updateContext(context, contextUpsert);
1220
1230
  progress('Upserted context', 'info', 'UPDATE_CONTEXT', contextUpsert);
@@ -1222,21 +1232,21 @@ var Spirits = {
1222
1232
  if (resetIntent) {
1223
1233
  resettedIntent = true;
1224
1234
  }
1225
- case 110:
1226
- _context2.next = 52;
1235
+ case 111:
1236
+ _context2.next = 53;
1227
1237
  break;
1228
- case 112:
1229
- _context2.next = 117;
1238
+ case 113:
1239
+ _context2.next = 118;
1230
1240
  break;
1231
- case 114:
1232
- _context2.prev = 114;
1233
- _context2.t2 = _context2["catch"](50);
1241
+ case 115:
1242
+ _context2.prev = 115;
1243
+ _context2.t2 = _context2["catch"](51);
1234
1244
  _iterator.e(_context2.t2);
1235
- case 117:
1236
- _context2.prev = 117;
1245
+ case 118:
1246
+ _context2.prev = 118;
1237
1247
  _iterator.f();
1238
- return _context2.finish(117);
1239
- case 120:
1248
+ return _context2.finish(118);
1249
+ case 121:
1240
1250
  if (resettedIntent && !_forward) {
1241
1251
  conversation.intent = null;
1242
1252
  conversation.intentScore = null;
@@ -1255,16 +1265,16 @@ var Spirits = {
1255
1265
  // 4. Generate response
1256
1266
  // If conversation previously locked, don't generate
1257
1267
  if (input.conversation.locked) {
1258
- _context2.next = 135;
1268
+ _context2.next = 169;
1259
1269
  break;
1260
1270
  }
1261
1271
  if (!((!conversation.locked || !hasNoInstructions) && !!hasNoCustomMessage)) {
1262
- _context2.next = 135;
1272
+ _context2.next = 136;
1263
1273
  break;
1264
1274
  }
1265
- _context2.prev = 123;
1275
+ _context2.prev = 124;
1266
1276
  progress('Parsing message', 'info', 'SET_PROCESSING', 'system');
1267
- _context2.next = 127;
1277
+ _context2.next = 128;
1268
1278
  return generator({
1269
1279
  messages: messages,
1270
1280
  persona: persona,
@@ -1272,7 +1282,7 @@ var Spirits = {
1272
1282
  llm: config.llm,
1273
1283
  pmt: config.pmt
1274
1284
  });
1275
- case 127:
1285
+ case 128:
1276
1286
  generatorPayload = _context2.sent;
1277
1287
  if (!generatorPayload.send) {
1278
1288
  progress('Generated response', 'failed', undefined, {
@@ -1309,14 +1319,86 @@ var Spirits = {
1309
1319
  }
1310
1320
  }
1311
1321
  }
1312
- _context2.next = 135;
1322
+ _context2.next = 136;
1313
1323
  break;
1314
- case 131:
1315
- _context2.prev = 131;
1316
- _context2.t3 = _context2["catch"](123);
1324
+ case 132:
1325
+ _context2.prev = 132;
1326
+ _context2.t3 = _context2["catch"](124);
1317
1327
  console.error("Locking conversation, error generating response: ".concat(_context2.t3.message));
1318
1328
  conversation = lockConversation(conversation, 'API: ' + _context2.t3.message);
1319
- case 135:
1329
+ case 136:
1330
+ if (!(messagesToTransform.length && transformer)) {
1331
+ _context2.next = 168;
1332
+ break;
1333
+ }
1334
+ _context2.prev = 137;
1335
+ _iterator2 = _createForOfIteratorHelper(messagesToTransform);
1336
+ _context2.prev = 139;
1337
+ _iterator2.s();
1338
+ case 141:
1339
+ if ((_step2 = _iterator2.n()).done) {
1340
+ _context2.next = 152;
1341
+ break;
1342
+ }
1343
+ _step2.value;
1344
+ _context2.next = 145;
1345
+ return transformer({
1346
+ message: messagesToTransform,
1347
+ persona: persona,
1348
+ customer: customer.id,
1349
+ messages: messages,
1350
+ context: context
1351
+ });
1352
+ case 145:
1353
+ transformResponse = _context2.sent;
1354
+ progress('Generated response', 'success', undefined, undefined);
1355
+ // Check if already had message
1356
+ _agentMessages = messages.filter(function (m) {
1357
+ return m.role === 'agent';
1358
+ });
1359
+ _lastAgentMessage = _agentMessages[_agentMessages.length - 1];
1360
+ if (_lastAgentMessage && _lastAgentMessage.content === transformResponse.message) {
1361
+ // Error should not have happened
1362
+ conversation = lockConversation(conversation, 'Duplicate message');
1363
+ } else {
1364
+ messages.push({
1365
+ id: idGenerator('agent'),
1366
+ role: 'agent',
1367
+ content: transformResponse.message,
1368
+ time: new Date().toISOString()
1369
+ });
1370
+ progress('Added agent message', 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
1371
+ }
1372
+ case 150:
1373
+ _context2.next = 141;
1374
+ break;
1375
+ case 152:
1376
+ _context2.next = 157;
1377
+ break;
1378
+ case 154:
1379
+ _context2.prev = 154;
1380
+ _context2.t4 = _context2["catch"](139);
1381
+ _iterator2.e(_context2.t4);
1382
+ case 157:
1383
+ _context2.prev = 157;
1384
+ _iterator2.f();
1385
+ return _context2.finish(157);
1386
+ case 160:
1387
+ _context2.next = 166;
1388
+ break;
1389
+ case 162:
1390
+ _context2.prev = 162;
1391
+ _context2.t5 = _context2["catch"](137);
1392
+ console.error("Locking conversation, error transforming response: ".concat(_context2.t5.message));
1393
+ conversation = lockConversation(conversation, 'API: ' + _context2.t5.message);
1394
+ case 166:
1395
+ _context2.next = 169;
1396
+ break;
1397
+ case 168:
1398
+ if (messagesToTransform.length) {
1399
+ console.warn("No transformer provided");
1400
+ }
1401
+ case 169:
1320
1402
  progress('Parsing message', 'info', 'SET_PROCESSING', null);
1321
1403
  return _context2.abrupt("return", {
1322
1404
  conversation: {
@@ -1339,11 +1421,11 @@ var Spirits = {
1339
1421
  },
1340
1422
  followup: followup
1341
1423
  });
1342
- case 137:
1424
+ case 171:
1343
1425
  case "end":
1344
1426
  return _context2.stop();
1345
1427
  }
1346
- }, _callee, null, [[50, 114, 117, 120], [86, 95, 98, 101], [123, 131]]);
1428
+ }, _callee, null, [[51, 115, 118, 121], [87, 96, 99, 102], [124, 132], [137, 162], [139, 154, 157, 160]]);
1347
1429
  }));
1348
1430
  function customer(_x) {
1349
1431
  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-2ab4d673.cjs");
5
+ var spirits = require("./spirits-82575cd5.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-cd37b736.cjs");
6
- require("./spirits-2ab4d673.cjs");
5
+ var dev = require("./dev-8ed1e379.cjs");
6
+ require("./spirits-82575cd5.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-f855de63.cjs");
27
+ require("./macros-4bff92c7.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.5.7",
3
+ "version": "1.0.0-alpha.0.5.9",
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
  },