@scout9/app 1.0.0-alpha.1.0.5 → 1.0.0-alpha.1.0.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,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var _rollupPluginBabelHelpers = require("./_rollupPluginBabelHelpers-9c73c95c.cjs");
4
- var spirits = require("./spirits-ab87b546.cjs");
4
+ var spirits = require("./spirits-b3f15e97.cjs");
5
5
  var require$$0$4 = require('util');
6
6
  var require$$0$3 = require('stream');
7
7
  var require$$1 = require('path');
@@ -35307,7 +35307,7 @@ function _loadUserPackageJson() {
35307
35307
  targetPkgUrl = isTest ? packageTestJsonUrl : packageJsonUrl;
35308
35308
  _context2.t0 = JSON;
35309
35309
  _context2.next = 10;
35310
- 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-8c238c7b.js', document.baseURI).href))), 'utf-8');
35310
+ 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-767919ab.js', document.baseURI).href))), 'utf-8');
35311
35311
  case 10:
35312
35312
  _context2.t1 = _context2.sent;
35313
35313
  pkg = _context2.t0.parse.call(_context2.t0, _context2.t1);
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var _rollupPluginBabelHelpers = require("./_rollupPluginBabelHelpers-9c73c95c.cjs");
4
- var dev = require("./dev-8c238c7b.cjs");
4
+ var dev = require("./dev-767919ab.cjs");
5
5
  var macros = require("./macros-c0acaa02.cjs");
6
- var spirits = require("./spirits-ab87b546.cjs");
6
+ var spirits = require("./spirits-b3f15e97.cjs");
7
7
  var require$$0 = require('fs');
8
8
  var require$$2$1 = require('events');
9
9
  var require$$1 = require('path');
@@ -29484,7 +29484,7 @@ class Body {
29484
29484
  }
29485
29485
  const {
29486
29486
  toFormData
29487
- } = await Promise.resolve().then(function () { return require("./multipart-parser-4f099bcf.cjs"); });
29487
+ } = await Promise.resolve().then(function () { return require("./multipart-parser-3054b741.cjs"); });
29488
29488
  return toFormData(this.body, ct);
29489
29489
  }
29490
29490
 
@@ -41885,7 +41885,7 @@ function _loadUserPackageJson() {
41885
41885
  targetPkgUrl = isTest ? packageTestJsonUrl : packageJsonUrl;
41886
41886
  _context.t0 = JSON;
41887
41887
  _context.next = 10;
41888
- 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-57129cdc.js', document.baseURI).href))), 'utf-8');
41888
+ 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-81dce472.js', document.baseURI).href))), 'utf-8');
41889
41889
  case 10:
41890
41890
  _context.t1 = _context.sent;
41891
41891
  pkg = _context.t0.parse.call(_context.t0, _context.t1);
@@ -43177,7 +43177,7 @@ var ProjectFiles = /*#__PURE__*/function () {
43177
43177
  return ProjectFiles;
43178
43178
  }();
43179
43179
 
43180
- 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-57129cdc.js', document.baseURI).href)));
43180
+ 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-81dce472.js', document.baseURI).href)));
43181
43181
  var __dirname$1 = path__default["default"].dirname(__filename$1);
43182
43182
  function zipDirectory(source, out) {
43183
43183
  var archive = archiver$1('tar', {
@@ -43392,7 +43392,7 @@ function _buildApp() {
43392
43392
  case 11:
43393
43393
  _context4.t0 = JSON;
43394
43394
  _context4.next = 14;
43395
- 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-57129cdc.js', document.baseURI).href))), 'utf-8');
43395
+ 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-81dce472.js', document.baseURI).href))), 'utf-8');
43396
43396
  case 14:
43397
43397
  _context4.t1 = _context4.sent;
43398
43398
  packageTemplate = _context4.t0.parse.call(_context4.t0, _context4.t1);
package/dist/index.cjs CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require("./index-57129cdc.cjs");
6
- var dev = require("./dev-8c238c7b.cjs");
5
+ var index = require("./index-81dce472.cjs");
6
+ var dev = require("./dev-767919ab.cjs");
7
7
  require("./_rollupPluginBabelHelpers-9c73c95c.cjs");
8
8
  require("./macros-c0acaa02.cjs");
9
- require("./spirits-ab87b546.cjs");
9
+ require("./spirits-b3f15e97.cjs");
10
10
  require('fs');
11
11
  require('events');
12
12
  require('path');
@@ -2,10 +2,10 @@
2
2
 
3
3
  require('node:fs');
4
4
  require('node:path');
5
- var index = require("./index-57129cdc.cjs");
5
+ var index = require("./index-81dce472.cjs");
6
6
  require("./_rollupPluginBabelHelpers-9c73c95c.cjs");
7
- require("./dev-8c238c7b.cjs");
8
- require("./spirits-ab87b546.cjs");
7
+ require("./dev-767919ab.cjs");
8
+ require("./spirits-b3f15e97.cjs");
9
9
  require('util');
10
10
  require('stream');
11
11
  require('path');
@@ -4934,6 +4934,8 @@ var Spirits = {
4934
4934
  messages,
4935
4935
  context,
4936
4936
  message,
4937
+ elapsedSeconds,
4938
+ rootStart,
4937
4939
  err,
4938
4940
  followup,
4939
4941
  entityContextUpsert,
@@ -5038,6 +5040,11 @@ var Spirits = {
5038
5040
  onError = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : function () {};
5039
5041
  customer = input.customer, config = input.config, messageBefore = input.message, contextBefore = input.context, messagesBefore = input.messages, conversationBefore = input.conversation, 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, _input$onSetContext = input.onSetContext, onSetContext = _input$onSetContext === void 0 ? function (_ctx) {} : _input$onSetContext, _input$onUpdateContex = input.onUpdateContext, onUpdateContext = _input$onUpdateContex === void 0 ? function (_patch) {} : _input$onUpdateContex, _input$onSetConversat = input.onSetConversation, onSetConversation = _input$onSetConversat === void 0 ? function (_conv) {} : _input$onSetConversat, _input$onUpdateConver = input.onUpdateConversation, onUpdateConversation = _input$onUpdateConver === void 0 ? function (_patch) {} : _input$onUpdateConver, input.onChunkMessage, _input$onAddMessage = input.onAddMessage, onAddMessage = _input$onAddMessage === void 0 ? function (_msg) {} : _input$onAddMessage, _input$onUpdateMessag = input.onUpdateMessage, onUpdateMessage = _input$onUpdateMessag === void 0 ? function (_patch) {} : _input$onUpdateMessag, _input$onDeleteMessag = input.onDeleteMessage, onDeleteMessage = _input$onDeleteMessag === void 0 ? function (_id) {} : _input$onDeleteMessag;
5040
5042
  conversation = input.conversation, messages = input.messages, context = input.context, message = input.message;
5043
+ elapsedSeconds = function elapsedSeconds(start) {
5044
+ return ((performance.now() - start) / 1000).toFixed(2);
5045
+ };
5046
+ rootStart = performance.now();
5047
+ progress("Spirits.customer start", 'info', undefined, undefined);
5041
5048
  if (typeof message.content !== 'string') {
5042
5049
  err = new Error("Spirits: customer message.content is not string (id=".concat(message.id, ", type=").concat(_rollupPluginBabelHelpers._typeof(message.content), ")"));
5043
5050
  progress('customer message.content is not string', 'error', 'INVALID_CUSTOMER_MESSAGE', {
@@ -5283,8 +5290,7 @@ var Spirits = {
5283
5290
  wrapStep = /*#__PURE__*/function () {
5284
5291
  var _ref2 = _rollupPluginBabelHelpers._asyncToGenerator( /*#__PURE__*/_rollupPluginBabelHelpers._regeneratorRuntime().mark(function _callee(prom, step) {
5285
5292
  var stepAction,
5286
- start,
5287
- elapsedSeconds,
5293
+ stepStart,
5288
5294
  result,
5289
5295
  msg,
5290
5296
  _args2 = arguments;
@@ -5292,71 +5298,68 @@ var Spirits = {
5292
5298
  while (1) switch (_context.prev = _context.next) {
5293
5299
  case 0:
5294
5300
  stepAction = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : step;
5295
- start = performance.now();
5296
- elapsedSeconds = function elapsedSeconds() {
5297
- return ((performance.now() - start) / 1000).toFixed(2);
5298
- };
5299
- _context.prev = 3;
5301
+ stepStart = performance.now();
5302
+ _context.prev = 2;
5300
5303
  progress("".concat(stepAction, " start"), 'info', undefined, undefined);
5301
- _context.next = 7;
5304
+ _context.next = 6;
5302
5305
  return prom;
5303
- case 7:
5306
+ case 6:
5304
5307
  result = _context.sent;
5305
- progress("".concat(stepAction, " succeeded in ").concat(elapsedSeconds(), "s"), 'success', undefined, undefined);
5308
+ progress("".concat(stepAction, " succeeded in ").concat(elapsedSeconds(stepStart), "s"), 'success', undefined, undefined);
5306
5309
  return _context.abrupt("return", result);
5307
- case 12:
5308
- _context.prev = 12;
5309
- _context.t0 = _context["catch"](3);
5310
+ case 11:
5311
+ _context.prev = 11;
5312
+ _context.t0 = _context["catch"](2);
5310
5313
  msg = (_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message) || 'UNHANDLED ERROR';
5311
- progress("".concat(stepAction, " failed in ").concat(elapsedSeconds(), "s"), 'error', undefined, {
5314
+ progress("".concat(stepAction, " failed in ").concat(elapsedSeconds(stepStart), "s"), 'error', undefined, {
5312
5315
  error: msg
5313
5316
  });
5314
5317
  throw SpiritError.fromError(_context.t0, step);
5315
- case 17:
5318
+ case 16:
5316
5319
  case "end":
5317
5320
  return _context.stop();
5318
5321
  }
5319
- }, _callee, null, [[3, 12]]);
5322
+ }, _callee, null, [[2, 11]]);
5320
5323
  }));
5321
5324
  return function wrapStep(_x2, _x3) {
5322
5325
  return _ref2.apply(this, arguments);
5323
5326
  };
5324
5327
  }(); // 1. Check inputs
5325
5328
  if (conversation.$agent) {
5326
- _context5.next = 30;
5329
+ _context5.next = 33;
5327
5330
  break;
5328
5331
  }
5329
5332
  throw new Error("SpiritsError: No agent found in conversation, must define \".$agent\" in the conversation");
5330
- case 30:
5333
+ case 33:
5331
5334
  persona = (config.persona || config.personas || config.agents).find(function (p) {
5332
5335
  return p.id === conversation.$agent;
5333
5336
  });
5334
5337
  if (persona) {
5335
- _context5.next = 35;
5338
+ _context5.next = 38;
5336
5339
  break;
5337
5340
  }
5338
5341
  if (!(config.persona || config.personas || config.agents).some(function (a) {
5339
5342
  return !a.id;
5340
5343
  })) {
5341
- _context5.next = 34;
5344
+ _context5.next = 37;
5342
5345
  break;
5343
5346
  }
5344
5347
  throw new Error("SpiritsError: No persona found (\"".concat(conversation.$agent, "\") in provided config, some persona's did not contain an \"id\" (Internal Mapping Error)"));
5345
- case 34:
5348
+ case 37:
5346
5349
  throw new Error("SpiritsError: No persona found (\"".concat(conversation.$agent, "\") in provided config"));
5347
- case 35:
5350
+ case 38:
5348
5351
  if (messages.every(function (m) {
5349
5352
  return !!m.id;
5350
5353
  })) {
5351
- _context5.next = 37;
5354
+ _context5.next = 40;
5352
5355
  break;
5353
5356
  }
5354
5357
  throw new Error("SpiritsError: Every message must have an \".id\", ensure all messages have an id assigned before running");
5355
- case 37:
5358
+ case 40:
5356
5359
  if (messages.every(function (m) {
5357
5360
  return m.role === 'customer' || m.role === 'agent' || m.role === 'system' || m.role === 'tool';
5358
5361
  })) {
5359
- _context5.next = 40;
5362
+ _context5.next = 43;
5360
5363
  break;
5361
5364
  }
5362
5365
  invalidRoles = messages.filter(function (m) {
@@ -5365,7 +5368,7 @@ var Spirits = {
5365
5368
  throw new Error("SpiritsError: Every message must have a role of \"customer\", \"agent\", or \"system\". Got invalid roles: ".concat(invalidRoles.map(function (m) {
5366
5369
  return m.role;
5367
5370
  }).join(', ')));
5368
- case 40:
5371
+ case 43:
5369
5372
  // Normalize existing message times ONCE at the start
5370
5373
  enforceMonotonicWithEmits(messages, 1);
5371
5374
 
@@ -5381,9 +5384,9 @@ var Spirits = {
5381
5384
  }
5382
5385
 
5383
5386
  // 2. Parse the message
5384
- _context5.next = 46;
5387
+ _context5.next = 49;
5385
5388
  return wrapStep(parser(message.content, 'en'), 'parse', 'parsing message');
5386
- case 46:
5389
+ case 49:
5387
5390
  parsePayload = _context5.sent;
5388
5391
  if (parsePayload.intent) {
5389
5392
  message.intent = parsePayload.intent;
@@ -5506,15 +5509,15 @@ var Spirits = {
5506
5509
 
5507
5510
  // 3. Run the contextualizer
5508
5511
  // progress('Running contextualizer', 'info', 'SET_PROCESSING', 'system');
5509
- _context5.next = 63;
5512
+ _context5.next = 66;
5510
5513
  return wrapStep(contextualizer({
5511
5514
  conversation: conversation,
5512
5515
  messages: messages
5513
5516
  }), 'contextualize', 'contextualizing');
5514
- case 63:
5517
+ case 66:
5515
5518
  newContextMessages = _context5.sent;
5516
5519
  _iterator6 = _rollupPluginBabelHelpers._createForOfIteratorHelper(newContextMessages);
5517
- _context5.prev = 65;
5520
+ _context5.prev = 68;
5518
5521
  _loop2 = /*#__PURE__*/_rollupPluginBabelHelpers._regeneratorRuntime().mark(function _loop2() {
5519
5522
  var contextMessage;
5520
5523
  return _rollupPluginBabelHelpers._regeneratorRuntime().wrap(function _loop2$(_context3) {
@@ -5541,28 +5544,28 @@ var Spirits = {
5541
5544
  }, _loop2);
5542
5545
  });
5543
5546
  _iterator6.s();
5544
- case 68:
5547
+ case 71:
5545
5548
  if ((_step6 = _iterator6.n()).done) {
5546
- _context5.next = 72;
5549
+ _context5.next = 75;
5547
5550
  break;
5548
5551
  }
5549
- return _context5.delegateYield(_loop2(), "t0", 70);
5550
- case 70:
5551
- _context5.next = 68;
5552
+ return _context5.delegateYield(_loop2(), "t0", 73);
5553
+ case 73:
5554
+ _context5.next = 71;
5552
5555
  break;
5553
- case 72:
5554
- _context5.next = 77;
5556
+ case 75:
5557
+ _context5.next = 80;
5555
5558
  break;
5556
- case 74:
5557
- _context5.prev = 74;
5558
- _context5.t1 = _context5["catch"](65);
5559
- _iterator6.e(_context5.t1);
5560
5559
  case 77:
5561
5560
  _context5.prev = 77;
5562
- _iterator6.f();
5563
- return _context5.finish(77);
5561
+ _context5.t1 = _context5["catch"](68);
5562
+ _iterator6.e(_context5.t1);
5564
5563
  case 80:
5565
- _context5.next = 82;
5564
+ _context5.prev = 80;
5565
+ _iterator6.f();
5566
+ return _context5.finish(80);
5567
+ case 83:
5568
+ _context5.next = 85;
5566
5569
  return wrapStep(workflow({
5567
5570
  messages: messages,
5568
5571
  conversation: conversation,
@@ -5591,7 +5594,7 @@ var Spirits = {
5591
5594
  return accumulator;
5592
5595
  }, []);
5593
5596
  });
5594
- case 82:
5597
+ case 85:
5595
5598
  slots = _context5.sent;
5596
5599
  hasNoInstructions = slots.every(function (s) {
5597
5600
  return !s.instructions || Array.isArray(s.instructions) && s.instructions.length === 0;
@@ -5667,20 +5670,20 @@ var Spirits = {
5667
5670
  resettedIntent = false;
5668
5671
  /** @type {Array<string> | undefined} */
5669
5672
  _iterator7 = _rollupPluginBabelHelpers._createForOfIteratorHelper(slots);
5670
- _context5.prev = 91;
5673
+ _context5.prev = 94;
5671
5674
  _iterator7.s();
5672
- case 93:
5675
+ case 96:
5673
5676
  if ((_step7 = _iterator7.n()).done) {
5674
- _context5.next = 148;
5677
+ _context5.next = 151;
5675
5678
  break;
5676
5679
  }
5677
5680
  _step7$value = _step7.value, forward = _step7$value.forward, forwardNote = _step7$value.forwardNote, instructions = _step7$value.instructions, removeInstructions = _step7$value.removeInstructions, _step7$value.message, _step7$value.scheduled, resetIntent = _step7$value.resetIntent, _step7$value.secondsDelay, contextUpsert = _step7$value.contextUpsert, anticipate = _step7$value.anticipate, slotFollowup = _step7$value.followup, slotEntityContextUpsert = _step7$value.entityContextUpsert, tasks = _step7$value.tasks;
5678
5681
  if (!anticipate) {
5679
- _context5.next = 108;
5682
+ _context5.next = 111;
5680
5683
  break;
5681
5684
  }
5682
5685
  if (!Array.isArray(anticipate)) {
5683
- _context5.next = 103;
5686
+ _context5.next = 106;
5684
5687
  break;
5685
5688
  }
5686
5689
  // 'literal' anticipation
@@ -5700,11 +5703,11 @@ var Spirits = {
5700
5703
  slots: _slots,
5701
5704
  map: map
5702
5705
  });
5703
- _context5.next = 108;
5706
+ _context5.next = 111;
5704
5707
  break;
5705
- case 103:
5708
+ case 106:
5706
5709
  if (!('yes' in anticipate && 'no' in anticipate && 'did' in anticipate)) {
5707
- _context5.next = 107;
5710
+ _context5.next = 110;
5708
5711
  break;
5709
5712
  }
5710
5713
  // "did" anticipation
@@ -5716,11 +5719,11 @@ var Spirits = {
5716
5719
  },
5717
5720
  did: anticipate.did
5718
5721
  });
5719
- _context5.next = 108;
5722
+ _context5.next = 111;
5720
5723
  break;
5721
- case 107:
5724
+ case 110:
5722
5725
  throw new Error("Invalid anticipate payload \"".concat(JSON.stringify(anticipate), "\""));
5723
- case 108:
5726
+ case 111:
5724
5727
  // tasks from auto/manual ingress to execute
5725
5728
  if (!!tasks && Array.isArray(tasks) && !!tasks.length) {
5726
5729
  if (!_tasks) _tasks = [];
@@ -5776,19 +5779,19 @@ var Spirits = {
5776
5779
 
5777
5780
  // Insert instructions context
5778
5781
  if (!instructions) {
5779
- _context5.next = 127;
5782
+ _context5.next = 130;
5780
5783
  break;
5781
5784
  }
5782
5785
  if (!(typeof instructions === 'string')) {
5783
- _context5.next = 117;
5786
+ _context5.next = 120;
5784
5787
  break;
5785
5788
  }
5786
5789
  addInstruction(instructions, previousLockAttempt);
5787
- _context5.next = 127;
5790
+ _context5.next = 130;
5788
5791
  break;
5789
- case 117:
5792
+ case 120:
5790
5793
  if (!Array.isArray(instructions)) {
5791
- _context5.next = 122;
5794
+ _context5.next = 125;
5792
5795
  break;
5793
5796
  }
5794
5797
  _iterator10 = _rollupPluginBabelHelpers._createForOfIteratorHelper(instructions);
@@ -5806,25 +5809,25 @@ var Spirits = {
5806
5809
  } finally {
5807
5810
  _iterator10.f();
5808
5811
  }
5809
- _context5.next = 127;
5812
+ _context5.next = 130;
5810
5813
  break;
5811
- case 122:
5814
+ case 125:
5812
5815
  if (!(_rollupPluginBabelHelpers._typeof(instructions) === 'object' && 'content' in instructions)) {
5813
- _context5.next = 126;
5816
+ _context5.next = 129;
5814
5817
  break;
5815
5818
  }
5816
5819
  addInstruction(instructions.content, previousLockAttempt, instructions.id);
5817
- _context5.next = 127;
5820
+ _context5.next = 130;
5818
5821
  break;
5819
- case 126:
5822
+ case 129:
5820
5823
  throw new Error("SpiritsError: instructions must be a string or array or {content: \"<instruction>\"}, got: ".concat(JSON.stringify(instructions)));
5821
- case 127:
5824
+ case 130:
5822
5825
  if (!removeInstructions) {
5823
- _context5.next = 144;
5826
+ _context5.next = 147;
5824
5827
  break;
5825
5828
  }
5826
5829
  _iterator11 = _rollupPluginBabelHelpers._createForOfIteratorHelper(removeInstructions);
5827
- _context5.prev = 129;
5830
+ _context5.prev = 132;
5828
5831
  _loop3 = /*#__PURE__*/_rollupPluginBabelHelpers._regeneratorRuntime().mark(function _loop3() {
5829
5832
  var instructionId, index, removed;
5830
5833
  return _rollupPluginBabelHelpers._regeneratorRuntime().wrap(function _loop3$(_context4) {
@@ -5850,27 +5853,27 @@ var Spirits = {
5850
5853
  }, _loop3);
5851
5854
  });
5852
5855
  _iterator11.s();
5853
- case 132:
5856
+ case 135:
5854
5857
  if ((_step11 = _iterator11.n()).done) {
5855
- _context5.next = 136;
5858
+ _context5.next = 139;
5856
5859
  break;
5857
5860
  }
5858
- return _context5.delegateYield(_loop3(), "t2", 134);
5859
- case 134:
5860
- _context5.next = 132;
5861
+ return _context5.delegateYield(_loop3(), "t2", 137);
5862
+ case 137:
5863
+ _context5.next = 135;
5861
5864
  break;
5862
- case 136:
5863
- _context5.next = 141;
5865
+ case 139:
5866
+ _context5.next = 144;
5864
5867
  break;
5865
- case 138:
5866
- _context5.prev = 138;
5867
- _context5.t3 = _context5["catch"](129);
5868
- _iterator11.e(_context5.t3);
5869
5868
  case 141:
5870
5869
  _context5.prev = 141;
5871
- _iterator11.f();
5872
- return _context5.finish(141);
5870
+ _context5.t3 = _context5["catch"](132);
5871
+ _iterator11.e(_context5.t3);
5873
5872
  case 144:
5873
+ _context5.prev = 144;
5874
+ _iterator11.f();
5875
+ return _context5.finish(144);
5876
+ case 147:
5874
5877
  // @TODO this logic is now handled at messagesToTransform's initialization, maybe move back down here
5875
5878
  // if (manualMessage) {
5876
5879
 
@@ -5913,21 +5916,21 @@ var Spirits = {
5913
5916
  if (resetIntent) {
5914
5917
  resettedIntent = true;
5915
5918
  }
5916
- case 146:
5917
- _context5.next = 93;
5919
+ case 149:
5920
+ _context5.next = 96;
5918
5921
  break;
5919
- case 148:
5920
- _context5.next = 153;
5922
+ case 151:
5923
+ _context5.next = 156;
5921
5924
  break;
5922
- case 150:
5923
- _context5.prev = 150;
5924
- _context5.t4 = _context5["catch"](91);
5925
- _iterator7.e(_context5.t4);
5926
5925
  case 153:
5927
5926
  _context5.prev = 153;
5928
- _iterator7.f();
5929
- return _context5.finish(153);
5927
+ _context5.t4 = _context5["catch"](94);
5928
+ _iterator7.e(_context5.t4);
5930
5929
  case 156:
5930
+ _context5.prev = 156;
5931
+ _iterator7.f();
5932
+ return _context5.finish(156);
5933
+ case 159:
5931
5934
  enforceMonotonicWithEmits(messages, 1);
5932
5935
  if (resettedIntent && !_forward) {
5933
5936
  conversation = updateConversation(conversation, {
@@ -5949,14 +5952,14 @@ var Spirits = {
5949
5952
  // 5. Generate response
5950
5953
  // If conversation previously locked, don't generate
5951
5954
  if (input.conversation.locked) {
5952
- _context5.next = 211;
5955
+ _context5.next = 214;
5953
5956
  break;
5954
5957
  }
5955
5958
  if (!((!conversation.locked || !hasNoInstructions) && !!hasNoCustomMessage)) {
5956
- _context5.next = 176;
5959
+ _context5.next = 179;
5957
5960
  break;
5958
5961
  }
5959
- _context5.prev = 160;
5962
+ _context5.prev = 163;
5960
5963
  // progress('Generating message', 'info', 'SET_PROCESSING', 'system');
5961
5964
  /** @type {import('@scout9/admin').GenerateRequestOneOf1} */
5962
5965
  generatorInput = {
@@ -5969,9 +5972,9 @@ var Spirits = {
5969
5972
  if (!!_tasks && Array.isArray(_tasks) && !!_tasks.length) {
5970
5973
  generatorInput.tasks = _tasks;
5971
5974
  }
5972
- _context5.next = 165;
5975
+ _context5.next = 168;
5973
5976
  return wrapStep(generator(generatorInput), 'generate');
5974
- case 165:
5977
+ case 168:
5975
5978
  generatorPayload = _context5.sent;
5976
5979
  if (!generatorPayload.send) {
5977
5980
  progress('Generated response send rejected', 'error', undefined, {
@@ -6076,26 +6079,26 @@ var Spirits = {
6076
6079
  }
6077
6080
  }
6078
6081
  }
6079
- _context5.next = 174;
6082
+ _context5.next = 177;
6080
6083
  break;
6081
- case 169:
6082
- _context5.prev = 169;
6083
- _context5.t5 = _context5["catch"](160);
6084
+ case 172:
6085
+ _context5.prev = 172;
6086
+ _context5.t5 = _context5["catch"](163);
6084
6087
  onError(_context5.t5);
6085
6088
  console.error("Spirits: Locking conversation, error generating response: ".concat(_context5.t5.message));
6086
6089
  conversation = lockConversation(conversation, 'API: ' + _context5.t5.message);
6087
- case 174:
6088
- _context5.next = 177;
6090
+ case 177:
6091
+ _context5.next = 180;
6089
6092
  break;
6090
- case 176:
6093
+ case 179:
6091
6094
  onStatus('generate', 'ignored');
6092
- case 177:
6095
+ case 180:
6093
6096
  if (!(messagesToTransform.length && transformer)) {
6094
- _context5.next = 208;
6097
+ _context5.next = 211;
6095
6098
  break;
6096
6099
  }
6097
- _context5.prev = 178;
6098
- _context5.next = 181;
6100
+ _context5.prev = 181;
6101
+ _context5.next = 184;
6099
6102
  return wrapStep(transformer({
6100
6103
  // message: messagesToTransform,
6101
6104
  addedMessages: messagesToTransform,
@@ -6104,7 +6107,7 @@ var Spirits = {
6104
6107
  messages: messages,
6105
6108
  context: context
6106
6109
  }), 'transform');
6107
- case 181:
6110
+ case 184:
6108
6111
  transformResponse = _context5.sent;
6109
6112
  // @TODO check for duplicates, or have already sent the message
6110
6113
  transformedMessages = (_transformResponse$me = transformResponse.messages) !== null && _transformResponse$me !== void 0 && _transformResponse$me.length ? transformResponse.messages : [{
@@ -6112,7 +6115,7 @@ var Spirits = {
6112
6115
  content: transformResponse.message
6113
6116
  }];
6114
6117
  _iterator9 = _rollupPluginBabelHelpers._createForOfIteratorHelper(transformedMessages);
6115
- _context5.prev = 184;
6118
+ _context5.prev = 187;
6116
6119
  _loop = /*#__PURE__*/_rollupPluginBabelHelpers._regeneratorRuntime().mark(function _loop() {
6117
6120
  var message, adjusted, prior, _adjusted$contentGene2, _adjusted$contentTran, appended;
6118
6121
  return _rollupPluginBabelHelpers._regeneratorRuntime().wrap(function _loop$(_context2) {
@@ -6151,52 +6154,52 @@ var Spirits = {
6151
6154
  }, _loop);
6152
6155
  });
6153
6156
  _iterator9.s();
6154
- case 187:
6157
+ case 190:
6155
6158
  if ((_step9 = _iterator9.n()).done) {
6156
- _context5.next = 191;
6159
+ _context5.next = 194;
6157
6160
  break;
6158
6161
  }
6159
- return _context5.delegateYield(_loop(), "t6", 189);
6160
- case 189:
6161
- _context5.next = 187;
6162
+ return _context5.delegateYield(_loop(), "t6", 192);
6163
+ case 192:
6164
+ _context5.next = 190;
6162
6165
  break;
6163
- case 191:
6164
- _context5.next = 196;
6166
+ case 194:
6167
+ _context5.next = 199;
6165
6168
  break;
6166
- case 193:
6167
- _context5.prev = 193;
6168
- _context5.t7 = _context5["catch"](184);
6169
- _iterator9.e(_context5.t7);
6170
6169
  case 196:
6171
6170
  _context5.prev = 196;
6172
- _iterator9.f();
6173
- return _context5.finish(196);
6171
+ _context5.t7 = _context5["catch"](187);
6172
+ _iterator9.e(_context5.t7);
6174
6173
  case 199:
6175
- _context5.next = 206;
6174
+ _context5.prev = 199;
6175
+ _iterator9.f();
6176
+ return _context5.finish(199);
6177
+ case 202:
6178
+ _context5.next = 209;
6176
6179
  break;
6177
- case 201:
6178
- _context5.prev = 201;
6179
- _context5.t8 = _context5["catch"](178);
6180
+ case 204:
6181
+ _context5.prev = 204;
6182
+ _context5.t8 = _context5["catch"](181);
6180
6183
  console.error("Spirits: Locking conversation, error transforming response: ".concat(_context5.t8.message));
6181
6184
  conversation = lockConversation(conversation, 'API: ' + _context5.t8.message);
6182
6185
  onError(_context5.t8);
6183
- case 206:
6184
- _context5.next = 209;
6186
+ case 209:
6187
+ _context5.next = 212;
6185
6188
  break;
6186
- case 208:
6189
+ case 211:
6187
6190
  if (messagesToTransform.length) {
6188
6191
  console.warn("Spirits: No transformer provided");
6189
6192
  onStatus('transform', 'ignored');
6190
6193
  } else {
6191
6194
  onStatus('transform', 'ignored');
6192
6195
  }
6193
- case 209:
6194
- _context5.next = 213;
6196
+ case 212:
6197
+ _context5.next = 216;
6195
6198
  break;
6196
- case 211:
6199
+ case 214:
6197
6200
  onStatus('generate', 'ignored');
6198
6201
  onStatus('transform', 'ignored');
6199
- case 213:
6202
+ case 216:
6200
6203
  emptySystemMessages = messages.filter(isEmptySystemMessage);
6201
6204
  if (emptySystemMessages.length) {
6202
6205
  progress('Empty system messages detected post-run', 'error', 'EMPTY_SYSTEM_MESSAGE_FINAL', {
@@ -6208,6 +6211,7 @@ var Spirits = {
6208
6211
  console.error('Spirits: Empty system messages detected', emptySystemMessages);
6209
6212
  }
6210
6213
  logToolPairingIssues(messages, 'final');
6214
+ progress("Spirits.customer start ended in ".concat(elapsedSeconds(rootStart), "s"), 'success', undefined, undefined);
6211
6215
  return _context5.abrupt("return", {
6212
6216
  conversation: {
6213
6217
  before: conversationBefore,
@@ -6230,11 +6234,11 @@ var Spirits = {
6230
6234
  followup: followup,
6231
6235
  entityContextUpsert: entityContextUpsert
6232
6236
  });
6233
- case 217:
6237
+ case 221:
6234
6238
  case "end":
6235
6239
  return _context5.stop();
6236
6240
  }
6237
- }, _callee2, null, [[65, 74, 77, 80], [91, 150, 153, 156], [129, 138, 141, 144], [160, 169], [178, 201], [184, 193, 196, 199]]);
6241
+ }, _callee2, null, [[68, 77, 80, 83], [94, 153, 156, 159], [132, 141, 144, 147], [163, 172], [181, 204], [187, 196, 199, 202]]);
6238
6242
  }));
6239
6243
  function customer(_x) {
6240
6244
  return _customer.apply(this, arguments);
package/dist/spirits.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  require("./_rollupPluginBabelHelpers-9c73c95c.cjs");
6
- var spirits = require("./spirits-ab87b546.cjs");
6
+ var spirits = require("./spirits-b3f15e97.cjs");
7
7
 
8
8
 
9
9
 
@@ -2,9 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dev = require("./dev-8c238c7b.cjs");
5
+ var dev = require("./dev-767919ab.cjs");
6
6
  require("./_rollupPluginBabelHelpers-9c73c95c.cjs");
7
- require("./spirits-ab87b546.cjs");
7
+ require("./spirits-b3f15e97.cjs");
8
8
  require('util');
9
9
  require('stream');
10
10
  require('path');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scout9/app",
3
- "version": "1.0.0-alpha.1.0.5",
3
+ "version": "1.0.0-alpha.1.0.6",
4
4
  "description": "Build and deploy your Scout9 app for SMS auto replies",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -232,6 +232,9 @@ export const Spirits = {
232
232
  onDeleteMessage = (_id) => { },
233
233
  } = input;
234
234
  let { conversation, messages, context, message } = input;
235
+ const elapsedSeconds = (start) => ((performance.now() - start) / 1000).toFixed(2);
236
+ const rootStart = performance.now();
237
+ progress(`Spirits.customer start`, 'info', undefined, undefined);
235
238
 
236
239
  if (typeof message.content !== 'string') {
237
240
  const err = new Error(
@@ -454,18 +457,17 @@ export const Spirits = {
454
457
  * @param {string} stepAction - overrides step name in logs
455
458
  */
456
459
  const wrapStep = async (prom, step, stepAction = step) => {
457
- const start = performance.now();
458
- const elapsedSeconds = () => ((performance.now() - start) / 1000).toFixed(2);
460
+ const stepStart = performance.now();
459
461
 
460
462
  try {
461
463
  progress(`${stepAction} start`, 'info', undefined, undefined);
462
464
  const result = await prom;
463
- progress(`${stepAction} succeeded in ${elapsedSeconds()}s`, 'success', undefined, undefined);
465
+ progress(`${stepAction} succeeded in ${elapsedSeconds(stepStart)}s`, 'success', undefined, undefined);
464
466
  return result;
465
467
  } catch (error) {
466
468
  const msg = error?.message || 'UNHANDLED ERROR';
467
469
  progress(
468
- `${stepAction} failed in ${elapsedSeconds()}s`,
470
+ `${stepAction} failed in ${elapsedSeconds(stepStart)}s`,
469
471
  'error',
470
472
  undefined,
471
473
  { error: msg }
@@ -1157,6 +1159,8 @@ export const Spirits = {
1157
1159
  }
1158
1160
 
1159
1161
  logToolPairingIssues(messages, 'final');
1162
+
1163
+ progress(`Spirits.customer start ended in ${elapsedSeconds(rootStart)}s`, 'success', undefined, undefined);
1160
1164
 
1161
1165
  return {
1162
1166
  conversation: {