@scout9/app 1.0.0-alpha.0.4.9 → 1.0.0-alpha.0.5.1

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-8225c9fd.cjs");
3
+ var spirits = require("./spirits-2ab4d673.cjs");
4
4
  var require$$0$4 = require('util');
5
5
  var require$$0$3 = require('stream');
6
6
  var require$$1 = require('path');
@@ -23,7 +23,7 @@ var Stream = require('node:stream');
23
23
  var node_string_decoder = require('node:string_decoder');
24
24
  var readline = require('node:readline');
25
25
  var process$2 = require('node:process');
26
- var macros = require("./macros-c9b4654d.cjs");
26
+ var macros = require("./macros-2f21c706.cjs");
27
27
  var node_os = require('node:os');
28
28
  var promises = require('fs/promises');
29
29
 
@@ -35164,7 +35164,7 @@ function _loadUserPackageJson() {
35164
35164
  targetPkgUrl = isTest ? packageTestJsonUrl : packageJsonUrl;
35165
35165
  _context2.t0 = JSON;
35166
35166
  _context2.next = 10;
35167
- 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-51604173.js', document.baseURI).href))), 'utf-8');
35167
+ 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-65b97c9d.js', document.baseURI).href))), 'utf-8');
35168
35168
  case 10:
35169
35169
  _context2.t1 = _context2.sent;
35170
35170
  pkg = _context2.t0.parse.call(_context2.t0, _context2.t1);
@@ -37779,6 +37779,57 @@ function _loadWorkflowsConfig() {
37779
37779
  return _loadWorkflowsConfig.apply(this, arguments);
37780
37780
  }
37781
37781
 
37782
+ /**
37783
+ * @returns {Promise<CommandConfiguration[]>}
37784
+ */
37785
+ function loadCommandsConfig() {
37786
+ return _loadCommandsConfig.apply(this, arguments);
37787
+ }
37788
+ function _loadCommandsConfig() {
37789
+ _loadCommandsConfig = spirits._asyncToGenerator( /*#__PURE__*/spirits._regeneratorRuntime().mark(function _callee() {
37790
+ var _ref,
37791
+ _ref$cwd,
37792
+ cwd,
37793
+ _ref$src,
37794
+ src,
37795
+ config,
37796
+ _args = arguments;
37797
+ return spirits._regeneratorRuntime().wrap(function _callee$(_context) {
37798
+ while (1) switch (_context.prev = _context.next) {
37799
+ case 0:
37800
+ _ref = _args.length > 0 && _args[0] !== undefined ? _args[0] : {}, _ref$cwd = _ref.cwd, cwd = _ref$cwd === void 0 ? process.cwd() : _ref$cwd, _ref$src = _ref.src, src = _ref$src === void 0 ? 'src' : _ref$src, _ref.cb;
37801
+ // const config = globSync(path.resolve(cwd, `${src}/workflows/**/workflow.{ts,js}`), {cwd, absolute: true})
37802
+ config = globSync("".concat(src, "/commands/**/{index,command,*.command}.{ts,js}"), {
37803
+ cwd: cwd,
37804
+ absolute: false
37805
+ }).map(function (path) {
37806
+ var dir = path$2.dirname(path);
37807
+ var entity = path$2.basename(path).replace(/\..*$/, ''); // Removes any "."'s
37808
+ if (!entity) {
37809
+ throw new Error("Invalid command path \"".concat(path, "\""));
37810
+ }
37811
+ switch (entity) {
37812
+ case "index":
37813
+ case "command":
37814
+ entity = path$2.basename(dir);
37815
+ break;
37816
+ }
37817
+ return {
37818
+ entity: entity,
37819
+ path: path.split(src + '/commands/')[1]
37820
+ };
37821
+ }); // Validate the config
37822
+ macros.CommandsSchema.parse(config);
37823
+ return _context.abrupt("return", config);
37824
+ case 4:
37825
+ case "end":
37826
+ return _context.stop();
37827
+ }
37828
+ }, _callee);
37829
+ }));
37830
+ return _loadCommandsConfig.apply(this, arguments);
37831
+ }
37832
+
37782
37833
  function loadEnvConfig() {
37783
37834
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
37784
37835
  _ref$cwd = _ref.cwd,
@@ -37831,6 +37882,7 @@ function _loadConfig() {
37831
37882
  entitiesConfig,
37832
37883
  agentsConfig,
37833
37884
  workflowsConfig,
37885
+ commandsConfig,
37834
37886
  projectConfig,
37835
37887
  result,
37836
37888
  _args = arguments;
@@ -37886,24 +37938,35 @@ function _loadConfig() {
37886
37938
  });
37887
37939
  case 13:
37888
37940
  workflowsConfig = _context.sent;
37941
+ _context.next = 16;
37942
+ return loadCommandsConfig({
37943
+ cwd: cwd,
37944
+ src: src,
37945
+ logger: logger,
37946
+ deploying: deploying,
37947
+ cb: cb
37948
+ });
37949
+ case 16:
37950
+ commandsConfig = _context.sent;
37889
37951
  /**
37890
37952
  * @type {Scout9ProjectBuildConfig}
37891
37953
  */
37892
37954
  projectConfig = spirits._objectSpread2(spirits._objectSpread2({}, baseProjectConfig), {}, {
37893
37955
  entities: entitiesConfig,
37894
37956
  agents: agentsConfig,
37895
- workflows: workflowsConfig
37957
+ workflows: workflowsConfig,
37958
+ commands: commandsConfig
37896
37959
  }); // Validate the config
37897
37960
  result = macros.Scout9ProjectBuildConfigSchema.safeParse(projectConfig);
37898
37961
  if (result.success) {
37899
- _context.next = 19;
37962
+ _context.next = 22;
37900
37963
  break;
37901
37964
  }
37902
37965
  result.error.source = "".concat(src, "/index.js");
37903
37966
  throw result.error;
37904
- case 19:
37967
+ case 22:
37905
37968
  return _context.abrupt("return", projectConfig);
37906
- case 20:
37969
+ case 23:
37907
37970
  case "end":
37908
37971
  return _context.stop();
37909
37972
  }
@@ -42546,7 +42609,18 @@ var createMockWorkflowEvent = function createMockWorkflowEvent(message) {
42546
42609
  /**
42547
42610
  * Testing tool kit, used to handle Scout9 operations such as parsing, workflow, and generating responses
42548
42611
  */
42612
+ var _project = /*#__PURE__*/new WeakMap();
42613
+ var _app = /*#__PURE__*/new WeakMap();
42614
+ var _command = /*#__PURE__*/new WeakMap();
42615
+ var _api = /*#__PURE__*/new WeakMap();
42616
+ var _cwd = /*#__PURE__*/new WeakMap();
42617
+ var _src = /*#__PURE__*/new WeakMap();
42618
+ var _mode = /*#__PURE__*/new WeakMap();
42619
+ var _loaded = /*#__PURE__*/new WeakMap();
42620
+ var _personaId = /*#__PURE__*/new WeakMap();
42549
42621
  var _defaultLog = /*#__PURE__*/new WeakMap();
42622
+ var _loadApp = /*#__PURE__*/new WeakSet();
42623
+ var _loadCommand = /*#__PURE__*/new WeakSet();
42550
42624
  var Scout9Test = /*#__PURE__*/function () {
42551
42625
  /**
42552
42626
  * Mimics a customer message to your app (useful for testing)
@@ -42585,6 +42659,12 @@ var Scout9Test = /*#__PURE__*/function () {
42585
42659
  _ref$log = _ref.log,
42586
42660
  log = _ref$log === void 0 ? false : _ref$log;
42587
42661
  spirits._classCallCheck(this, Scout9Test);
42662
+ /**
42663
+ * @param {string} command
42664
+ * @returns {Promise<void>}
42665
+ */
42666
+ spirits._classPrivateMethodInitSpec(this, _loadCommand);
42667
+ spirits._classPrivateMethodInitSpec(this, _loadApp);
42588
42668
  /**
42589
42669
  * @type {import('@scout9/app').Customer}
42590
42670
  */
@@ -42605,64 +42685,62 @@ var Scout9Test = /*#__PURE__*/function () {
42605
42685
  * @type {import('@scout9/app').ConversationContext}
42606
42686
  */
42607
42687
  spirits._defineProperty(this, "context", void 0);
42608
- /**
42609
- * @private
42610
- * @type {import('@scout9/app').Scout9ProjectBuildConfig | null}
42611
- */
42612
- spirits._defineProperty(this, "_project", null);
42613
- /**
42614
- * @private
42615
- * @type {import('@scout9/app').WorkflowFunction | null}
42616
- */
42617
- spirits._defineProperty(this, "_app", null);
42618
- /**
42619
- * @private
42620
- * @type {import('@scout9/admin').Scout9Api | null}
42621
- */
42622
- spirits._defineProperty(this, "_api", null);
42623
- /**
42624
- * @private
42625
- */
42626
- spirits._defineProperty(this, "_cwd", void 0);
42627
- /**
42628
- * @private
42629
- */
42630
- spirits._defineProperty(this, "_src", void 0);
42631
- /**
42632
- * @private
42633
- */
42634
- spirits._defineProperty(this, "_mode", void 0);
42635
- /**
42636
- * @private
42637
- */
42638
- spirits._defineProperty(this, "_loaded", void 0);
42639
- /**
42640
- * @private
42641
- */
42642
- spirits._defineProperty(this, "_personaId", void 0);
42643
- /**
42644
- * @private
42645
- */
42688
+ spirits._classPrivateFieldInitSpec(this, _project, {
42689
+ writable: true,
42690
+ value: null
42691
+ });
42692
+ spirits._classPrivateFieldInitSpec(this, _app, {
42693
+ writable: true,
42694
+ value: null
42695
+ });
42696
+ spirits._classPrivateFieldInitSpec(this, _command, {
42697
+ writable: true,
42698
+ value: null
42699
+ });
42700
+ spirits._classPrivateFieldInitSpec(this, _api, {
42701
+ writable: true,
42702
+ value: null
42703
+ });
42704
+ spirits._classPrivateFieldInitSpec(this, _cwd, {
42705
+ writable: true,
42706
+ value: void 0
42707
+ });
42708
+ spirits._classPrivateFieldInitSpec(this, _src, {
42709
+ writable: true,
42710
+ value: void 0
42711
+ });
42712
+ spirits._classPrivateFieldInitSpec(this, _mode, {
42713
+ writable: true,
42714
+ value: void 0
42715
+ });
42716
+ spirits._classPrivateFieldInitSpec(this, _loaded, {
42717
+ writable: true,
42718
+ value: void 0
42719
+ });
42720
+ spirits._classPrivateFieldInitSpec(this, _personaId, {
42721
+ writable: true,
42722
+ value: void 0
42723
+ });
42646
42724
  spirits._classPrivateFieldInitSpec(this, _defaultLog, {
42647
42725
  writable: true,
42648
42726
  value: void 0
42649
42727
  });
42650
42728
  this.messages = [];
42651
- this._cwd = cwd;
42652
- this._src = src;
42653
- this._mode = mode;
42729
+ spirits._classPrivateFieldSet(this, _cwd, cwd);
42730
+ spirits._classPrivateFieldSet(this, _src, src);
42731
+ spirits._classPrivateFieldSet(this, _mode, mode);
42654
42732
  this.context = spirits._objectSpread2(spirits._objectSpread2({}, context || {}), {}, {
42655
42733
  __no_cache: true
42656
42734
  });
42657
42735
  this.conversation = conversation;
42658
42736
  if (api) {
42659
- this._api = api;
42737
+ spirits._classPrivateFieldSet(this, _api, api);
42660
42738
  }
42661
42739
  if (app) {
42662
- this._app = app;
42740
+ spirits._classPrivateFieldSet(this, _app, app);
42663
42741
  }
42664
42742
  if (project) {
42665
- this._project = project;
42743
+ spirits._classPrivateFieldSet(this, _project, project);
42666
42744
  }
42667
42745
  if (!customer) {
42668
42746
  customer = {
@@ -42677,7 +42755,7 @@ var Scout9Test = /*#__PURE__*/function () {
42677
42755
  }
42678
42756
  this.customer = customer;
42679
42757
  this.context.customer = customer;
42680
- this._personaId = persona;
42758
+ spirits._classPrivateFieldSet(this, _personaId, persona);
42681
42759
  spirits._classPrivateFieldSet(this, _defaultLog, !!log);
42682
42760
  }
42683
42761
 
@@ -42698,57 +42776,65 @@ var Scout9Test = /*#__PURE__*/function () {
42698
42776
  while (1) switch (_context.prev = _context.next) {
42699
42777
  case 0:
42700
42778
  override = _args.length > 0 && _args[0] !== undefined ? _args[0] : false;
42701
- if (!(override || !this._app)) {
42702
- _context.next = 5;
42779
+ if (!(override || !spirits._classPrivateFieldGet(this, _app))) {
42780
+ _context.next = 9;
42703
42781
  break;
42704
42782
  }
42705
- _context.next = 4;
42706
- return this._loadApp();
42707
- case 4:
42708
- this._app = _context.sent;
42709
- case 5:
42710
- if (!(override || !this._project)) {
42711
- _context.next = 9;
42783
+ _context.t0 = spirits._classPrivateFieldSet;
42784
+ _context.t1 = this;
42785
+ _context.t2 = _app;
42786
+ _context.next = 7;
42787
+ return spirits._classPrivateMethodGet(this, _loadApp, _loadApp2).call(this);
42788
+ case 7:
42789
+ _context.t3 = _context.sent;
42790
+ (0, _context.t0)(_context.t1, _context.t2, _context.t3);
42791
+ case 9:
42792
+ if (!(override || !spirits._classPrivateFieldGet(this, _project))) {
42793
+ _context.next = 17;
42712
42794
  break;
42713
42795
  }
42714
- _context.next = 8;
42796
+ _context.t4 = spirits._classPrivateFieldSet;
42797
+ _context.t5 = this;
42798
+ _context.t6 = _project;
42799
+ _context.next = 15;
42715
42800
  return loadConfig({
42716
- cwd: this._cwd,
42717
- src: this._src,
42718
- mode: this._mode
42801
+ cwd: spirits._classPrivateFieldGet(this, _cwd),
42802
+ src: spirits._classPrivateFieldGet(this, _src),
42803
+ mode: spirits._classPrivateFieldGet(this, _mode)
42719
42804
  });
42720
- case 8:
42721
- this._project = _context.sent;
42722
- case 9:
42723
- if (override || !this._api) {
42724
- this._api = new build.Scout9Api(new build.Configuration({
42805
+ case 15:
42806
+ _context.t7 = _context.sent;
42807
+ (0, _context.t4)(_context.t5, _context.t6, _context.t7);
42808
+ case 17:
42809
+ if (override || !spirits._classPrivateFieldGet(this, _api)) {
42810
+ spirits._classPrivateFieldSet(this, _api, new build.Scout9Api(new build.Configuration({
42725
42811
  apiKey: process.env.SCOUT9_API_KEY
42726
- }));
42812
+ })));
42727
42813
  }
42728
- if (this._personaId) {
42729
- _context.next = 14;
42814
+ if (spirits._classPrivateFieldGet(this, _personaId)) {
42815
+ _context.next = 22;
42730
42816
  break;
42731
42817
  }
42732
- this._personaId = (_ref2 = this._project.persona || this._project.agents) === null || _ref2 === void 0 || (_ref2 = _ref2[0]) === null || _ref2 === void 0 ? void 0 : _ref2.id;
42733
- if (this._personaId) {
42734
- _context.next = 14;
42818
+ spirits._classPrivateFieldSet(this, _personaId, (_ref2 = spirits._classPrivateFieldGet(this, _project).persona || spirits._classPrivateFieldGet(this, _project).agents) === null || _ref2 === void 0 || (_ref2 = _ref2[0]) === null || _ref2 === void 0 ? void 0 : _ref2.id);
42819
+ if (spirits._classPrivateFieldGet(this, _personaId)) {
42820
+ _context.next = 22;
42735
42821
  break;
42736
42822
  }
42737
42823
  throw new Error("No persona found in config, please specify a persona id");
42738
- case 14:
42739
- this.conversation.$agent = this._personaId;
42740
- this.persona = (this._project.persona || this._project.agents).find(function (p) {
42741
- return p.id === _this._personaId;
42824
+ case 22:
42825
+ this.conversation.$agent = spirits._classPrivateFieldGet(this, _personaId);
42826
+ this.persona = (spirits._classPrivateFieldGet(this, _project).persona || spirits._classPrivateFieldGet(this, _project).agents).find(function (p) {
42827
+ return p.id === spirits._classPrivateFieldGet(_this, _personaId);
42742
42828
  });
42743
42829
  if (this.persona) {
42744
- _context.next = 18;
42830
+ _context.next = 26;
42745
42831
  break;
42746
42832
  }
42747
- throw new Error("Could not find persona with id: ".concat(this._personaId, ", ensure your project is sync'd by running \"scout9 sync\" or you are using the correct persona id"));
42748
- case 18:
42833
+ throw new Error("Could not find persona with id: ".concat(spirits._classPrivateFieldGet(this, _personaId), ", ensure your project is sync'd by running \"scout9 sync\" or you are using the correct persona id"));
42834
+ case 26:
42749
42835
  this.context.agent = this.persona;
42750
- this._loaded = true;
42751
- case 20:
42836
+ spirits._classPrivateFieldSet(this, _loaded, true);
42837
+ case 28:
42752
42838
  case "end":
42753
42839
  return _context.stop();
42754
42840
  }
@@ -42766,10 +42852,10 @@ var Scout9Test = /*#__PURE__*/function () {
42766
42852
  }, {
42767
42853
  key: "teardown",
42768
42854
  value: function teardown() {
42769
- this._loaded = false;
42770
- this._api = null;
42771
- this._project = null;
42772
- this._app = null;
42855
+ spirits._classPrivateFieldSet(this, _loaded, false);
42856
+ spirits._classPrivateFieldSet(this, _api, null);
42857
+ spirits._classPrivateFieldSet(this, _project, null);
42858
+ spirits._classPrivateFieldSet(this, _app, null);
42773
42859
  }
42774
42860
 
42775
42861
  /**
@@ -42784,6 +42870,8 @@ var Scout9Test = /*#__PURE__*/function () {
42784
42870
  var _send = spirits._asyncToGenerator( /*#__PURE__*/spirits._regeneratorRuntime().mark(function _callee4(message) {
42785
42871
  var _this2 = this;
42786
42872
  var progress,
42873
+ target,
42874
+ commandToSwitchTo,
42787
42875
  defaultProgressLogger,
42788
42876
  progressInput,
42789
42877
  _message,
@@ -42795,13 +42883,34 @@ var Scout9Test = /*#__PURE__*/function () {
42795
42883
  while (1) switch (_context4.prev = _context4.next) {
42796
42884
  case 0:
42797
42885
  progress = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : spirits._classPrivateFieldGet(this, _defaultLog);
42798
- if (this._loaded) {
42886
+ if (spirits._classPrivateFieldGet(this, _loaded)) {
42799
42887
  _context4.next = 4;
42800
42888
  break;
42801
42889
  }
42802
42890
  _context4.next = 4;
42803
42891
  return this.load();
42804
42892
  case 4:
42893
+ // Check if it's a command
42894
+ target = message.toLowerCase().trim();
42895
+ commandToSwitchTo = spirits._classPrivateFieldGet(this, _project).commands.find(function (command) {
42896
+ return command.entity === target;
42897
+ });
42898
+ if (!commandToSwitchTo) {
42899
+ _context4.next = 15;
42900
+ break;
42901
+ }
42902
+ _context4.t0 = spirits._classPrivateFieldSet;
42903
+ _context4.t1 = this;
42904
+ _context4.t2 = _command;
42905
+ _context4.next = 12;
42906
+ return spirits._classPrivateMethodGet(this, _loadCommand, _loadCommand2).call(this, commandToSwitchTo.entity);
42907
+ case 12:
42908
+ _context4.t3 = _context4.sent;
42909
+ (0, _context4.t0)(_context4.t1, _context4.t2, _context4.t3);
42910
+ Object.assign(this.context, {
42911
+ __command: commandToSwitchTo.entity
42912
+ });
42913
+ case 15:
42805
42914
  defaultProgressLogger = function defaultProgressLogger(message) {
42806
42915
  var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'info';
42807
42916
  var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
@@ -42820,18 +42929,19 @@ var Scout9Test = /*#__PURE__*/function () {
42820
42929
 
42821
42930
  /**
42822
42931
  * @type {import('@scout9/app').Message}
42932
+ * If we are switching to a command instance, we would want the first message to be system invoke
42823
42933
  */
42824
42934
  _message = {
42825
42935
  id: 'user_mock_' + Math.random().toString(36).slice(2, 11),
42826
- role: 'customer',
42827
- content: message,
42936
+ role: commandToSwitchTo ? 'system' : 'customer',
42937
+ content: commandToSwitchTo ? "Start by gathering/asking the user for relevant \"".concat(commandToSwitchTo.entity, "\" parameters") : message,
42828
42938
  time: new Date().toISOString()
42829
42939
  };
42830
42940
  this.messages.push(_message);
42831
- _context4.next = 11;
42941
+ _context4.next = 22;
42832
42942
  return spirits.Spirits.customer({
42833
42943
  customer: this.customer,
42834
- config: this._project,
42944
+ config: spirits._classPrivateFieldGet(this, _project),
42835
42945
  parser: function () {
42836
42946
  var _parser = spirits._asyncToGenerator( /*#__PURE__*/spirits._regeneratorRuntime().mark(function _callee2(_msg, _lng) {
42837
42947
  var detectableEntities;
@@ -42839,11 +42949,11 @@ var Scout9Test = /*#__PURE__*/function () {
42839
42949
  while (1) switch (_context2.prev = _context2.next) {
42840
42950
  case 0:
42841
42951
  // @TODO can't do this for HUGE data sets
42842
- detectableEntities = _this2._project.entities.filter(function (e) {
42952
+ detectableEntities = spirits._classPrivateFieldGet(_this2, _project).entities.filter(function (e) {
42843
42953
  var _e$training, _e$definitions;
42844
42954
  return ((_e$training = e.training) === null || _e$training === void 0 ? void 0 : _e$training.length) > 0 && ((_e$definitions = e.definitions) === null || _e$definitions === void 0 ? void 0 : _e$definitions.length) > 0;
42845
42955
  });
42846
- return _context2.abrupt("return", _this2._api.parse({
42956
+ return _context2.abrupt("return", spirits._classPrivateFieldGet(_this2, _api).parse({
42847
42957
  message: _msg,
42848
42958
  language: _lng,
42849
42959
  entities: detectableEntities
@@ -42863,13 +42973,20 @@ var Scout9Test = /*#__PURE__*/function () {
42863
42973
  }(),
42864
42974
  workflow: function () {
42865
42975
  var _workflow = spirits._asyncToGenerator( /*#__PURE__*/spirits._regeneratorRuntime().mark(function _callee3(event) {
42976
+ var _this2$conversation$$;
42866
42977
  return spirits._regeneratorRuntime().wrap(function _callee3$(_context3) {
42867
42978
  while (1) switch (_context3.prev = _context3.next) {
42868
42979
  case 0:
42869
42980
  globalThis.SCOUT9 = spirits._objectSpread2(spirits._objectSpread2({}, event), {}, {
42870
- $convo: _this2.conversation.$id
42981
+ $convo: (_this2$conversation$$ = _this2.conversation.$id) !== null && _this2$conversation$$ !== void 0 ? _this2$conversation$$ : 'test_convo'
42871
42982
  });
42872
- return _context3.abrupt("return", _this2._app(event));
42983
+ return _context3.abrupt("return", (spirits._classPrivateFieldGet(_this2, _command) ? spirits._classPrivateFieldGet(_this2, _command) : spirits._classPrivateFieldGet(_this2, _app))(event).then(function (response) {
42984
+ if ('toJSON' in response) {
42985
+ return response.toJSON();
42986
+ } else {
42987
+ return response;
42988
+ }
42989
+ }).then(macros.WorkflowResponseSchema.parse));
42873
42990
  case 2:
42874
42991
  case "end":
42875
42992
  return _context3.stop();
@@ -42882,7 +42999,7 @@ var Scout9Test = /*#__PURE__*/function () {
42882
42999
  return workflow;
42883
43000
  }(),
42884
43001
  generator: function generator(request) {
42885
- return _this2._api.generate(request).then(function (_res) {
43002
+ return spirits._classPrivateFieldGet(_this2, _api).generate(request).then(function (_res) {
42886
43003
  return _res.data;
42887
43004
  });
42888
43005
  },
@@ -42895,7 +43012,7 @@ var Scout9Test = /*#__PURE__*/function () {
42895
43012
  messages: this.messages,
42896
43013
  conversation: this.conversation
42897
43014
  });
42898
- case 11:
43015
+ case 22:
42899
43016
  result = _context4.sent;
42900
43017
  this.context = result.context.after;
42901
43018
  this.messages = result.messages.after;
@@ -42923,7 +43040,7 @@ var Scout9Test = /*#__PURE__*/function () {
42923
43040
  console.error("Message not found in result.messages.after", result.message.after.id);
42924
43041
  }
42925
43042
  return _context4.abrupt("return", result);
42926
- case 18:
43043
+ case 29:
42927
43044
  case "end":
42928
43045
  return _context4.stop();
42929
43046
  }
@@ -42951,16 +43068,16 @@ var Scout9Test = /*#__PURE__*/function () {
42951
43068
  while (1) switch (_context5.prev = _context5.next) {
42952
43069
  case 0:
42953
43070
  language = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : 'en';
42954
- if (this._project) {
43071
+ if (spirits._classPrivateFieldGet(this, _project)) {
42955
43072
  _context5.next = 3;
42956
43073
  break;
42957
43074
  }
42958
43075
  throw new Error("Config is not defined");
42959
43076
  case 3:
42960
- return _context5.abrupt("return", this._api.parse({
43077
+ return _context5.abrupt("return", spirits._classPrivateFieldGet(this, _api).parse({
42961
43078
  message: message,
42962
43079
  language: language,
42963
- entities: this._project.entities
43080
+ entities: spirits._classPrivateFieldGet(this, _project).entities
42964
43081
  }).then(function (_res) {
42965
43082
  return _res.data;
42966
43083
  }));
@@ -42992,7 +43109,7 @@ var Scout9Test = /*#__PURE__*/function () {
42992
43109
  while (1) switch (_context6.prev = _context6.next) {
42993
43110
  case 0:
42994
43111
  event = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
42995
- if (this._app) {
43112
+ if (spirits._classPrivateFieldGet(this, _app)) {
42996
43113
  _context6.next = 3;
42997
43114
  break;
42998
43115
  }
@@ -43001,7 +43118,7 @@ var Scout9Test = /*#__PURE__*/function () {
43001
43118
  if (event.hasOwnProperty('message')) {
43002
43119
  console.warn("WARNING: inserting a \"event.message\" will overwrite your \"message\" argument");
43003
43120
  }
43004
- return _context6.abrupt("return", this._app(spirits._objectSpread2(spirits._objectSpread2({}, createMockWorkflowEvent(message)), event)));
43121
+ return _context6.abrupt("return", spirits._classPrivateFieldGet(this, _app).call(this, spirits._objectSpread2(spirits._objectSpread2({}, createMockWorkflowEvent(message)), event)));
43005
43122
  case 5:
43006
43123
  case "end":
43007
43124
  return _context6.stop();
@@ -43031,20 +43148,20 @@ var Scout9Test = /*#__PURE__*/function () {
43031
43148
  return spirits._regeneratorRuntime().wrap(function _callee7$(_context7) {
43032
43149
  while (1) switch (_context7.prev = _context7.next) {
43033
43150
  case 0:
43034
- _ref3$personaId = _ref3.personaId, personaId = _ref3$personaId === void 0 ? this._personaId : _ref3$personaId, _ref3$conversation = _ref3.conversation, conversation = _ref3$conversation === void 0 ? {} : _ref3$conversation, _ref3$messages = _ref3.messages, messages = _ref3$messages === void 0 ? this.messages : _ref3$messages, _ref3$context = _ref3.context, context = _ref3$context === void 0 ? this.context : _ref3$context;
43035
- if (this._api) {
43151
+ _ref3$personaId = _ref3.personaId, personaId = _ref3$personaId === void 0 ? spirits._classPrivateFieldGet(this, _personaId) : _ref3$personaId, _ref3$conversation = _ref3.conversation, conversation = _ref3$conversation === void 0 ? {} : _ref3$conversation, _ref3$messages = _ref3.messages, messages = _ref3$messages === void 0 ? this.messages : _ref3$messages, _ref3$context = _ref3.context, context = _ref3$context === void 0 ? this.context : _ref3$context;
43152
+ if (spirits._classPrivateFieldGet(this, _api)) {
43036
43153
  _context7.next = 3;
43037
43154
  break;
43038
43155
  }
43039
43156
  throw new Error("Scout9 API is not loaded or found - make sure to run \".load()\" before calling \".generate()\"");
43040
43157
  case 3:
43041
- if (this._project) {
43158
+ if (spirits._classPrivateFieldGet(this, _project)) {
43042
43159
  _context7.next = 5;
43043
43160
  break;
43044
43161
  }
43045
43162
  throw new Error("Config is not defined - make sure to run \".load()\" before calling \".generate()\"");
43046
43163
  case 5:
43047
- persona = (this._project.persona || this._project.agents).find(function (p) {
43164
+ persona = (spirits._classPrivateFieldGet(this, _project).persona || spirits._classPrivateFieldGet(this, _project).agents).find(function (p) {
43048
43165
  return p.id === personaId;
43049
43166
  });
43050
43167
  if (persona) {
@@ -43053,7 +43170,7 @@ var Scout9Test = /*#__PURE__*/function () {
43053
43170
  }
43054
43171
  throw new Error("Could not find persona with id: ".concat(personaId, ", ensure your project is sync'd by running \"scout9 sync\""));
43055
43172
  case 8:
43056
- return _context7.abrupt("return", this._api.generate({
43173
+ return _context7.abrupt("return", spirits._classPrivateFieldGet(this, _api).generate({
43057
43174
  convo: spirits._objectSpread2(spirits._objectSpread2({
43058
43175
  $customer: this.customer.id,
43059
43176
  environment: this.conversation.environment,
@@ -43064,8 +43181,8 @@ var Scout9Test = /*#__PURE__*/function () {
43064
43181
  messages: messages,
43065
43182
  context: context,
43066
43183
  persona: persona,
43067
- llm: this._project.llm,
43068
- pmt: this._project.pmt
43184
+ llm: spirits._classPrivateFieldGet(this, _project).llm,
43185
+ pmt: spirits._classPrivateFieldGet(this, _project).pmt
43069
43186
  }).then(function (_res) {
43070
43187
  return _res.data;
43071
43188
  }));
@@ -43089,52 +43206,99 @@ var Scout9Test = /*#__PURE__*/function () {
43089
43206
  set: function set(ctx) {
43090
43207
  this.context = spirits._objectSpread2(spirits._objectSpread2({}, this.context), ctx);
43091
43208
  }
43092
-
43093
- /**
43094
- * @private
43095
- */
43096
- }, {
43097
- key: "_loadApp",
43098
- value: (function () {
43099
- var _loadApp2 = spirits._asyncToGenerator( /*#__PURE__*/spirits._regeneratorRuntime().mark(function _callee8() {
43100
- var paths, _paths, appFilePath;
43101
- return spirits._regeneratorRuntime().wrap(function _callee8$(_context8) {
43102
- while (1) switch (_context8.prev = _context8.next) {
43103
- case 0:
43104
- paths = globSync("".concat(this._src, "/app.{ts,cjs,mjs,js}"), {
43105
- cwd: this._cwd,
43106
- absolute: true
43107
- });
43108
- if (!(paths.length === 0)) {
43109
- _context8.next = 5;
43110
- break;
43111
- }
43112
- throw new Error("Missing main project entry file ".concat(this._src, "/app.{js|ts|cjs|mjs}"));
43113
- case 5:
43114
- if (!(paths.length > 1)) {
43115
- _context8.next = 7;
43116
- break;
43117
- }
43118
- throw new Error("Multiple main project entry files found ".concat(this._src, "/app.{js|ts|cjs|mjs}"));
43119
- case 7:
43120
- _paths = spirits._slicedToArray(paths, 1), appFilePath = _paths[0];
43121
- return _context8.abrupt("return", requireProjectFile(appFilePath).then(function (mod) {
43122
- return mod["default"];
43123
- }));
43124
- case 9:
43125
- case "end":
43126
- return _context8.stop();
43127
- }
43128
- }, _callee8, this);
43129
- }));
43130
- function _loadApp() {
43131
- return _loadApp2.apply(this, arguments);
43132
- }
43133
- return _loadApp;
43134
- }())
43135
43209
  }]);
43136
43210
  return Scout9Test;
43137
43211
  }();
43212
+ function _loadApp2() {
43213
+ return _loadApp3.apply(this, arguments);
43214
+ }
43215
+ function _loadApp3() {
43216
+ _loadApp3 = spirits._asyncToGenerator( /*#__PURE__*/spirits._regeneratorRuntime().mark(function _callee8() {
43217
+ var paths, _paths, appFilePath;
43218
+ return spirits._regeneratorRuntime().wrap(function _callee8$(_context8) {
43219
+ while (1) switch (_context8.prev = _context8.next) {
43220
+ case 0:
43221
+ paths = globSync("".concat(spirits._classPrivateFieldGet(this, _src), "/app.{ts,cjs,mjs,js}"), {
43222
+ cwd: spirits._classPrivateFieldGet(this, _cwd),
43223
+ absolute: true
43224
+ });
43225
+ if (!(paths.length === 0)) {
43226
+ _context8.next = 5;
43227
+ break;
43228
+ }
43229
+ throw new Error("Missing main project entry file ".concat(spirits._classPrivateFieldGet(this, _src), "/app.{js|ts|cjs|mjs}"));
43230
+ case 5:
43231
+ if (!(paths.length > 1)) {
43232
+ _context8.next = 7;
43233
+ break;
43234
+ }
43235
+ throw new Error("Multiple main project entry files found ".concat(spirits._classPrivateFieldGet(this, _src), "/app.{js|ts|cjs|mjs}"));
43236
+ case 7:
43237
+ _paths = spirits._slicedToArray(paths, 1), appFilePath = _paths[0];
43238
+ return _context8.abrupt("return", requireProjectFile(appFilePath).then(function (mod) {
43239
+ return mod["default"];
43240
+ }));
43241
+ case 9:
43242
+ case "end":
43243
+ return _context8.stop();
43244
+ }
43245
+ }, _callee8, this);
43246
+ }));
43247
+ return _loadApp3.apply(this, arguments);
43248
+ }
43249
+ function _loadCommand2(_x8) {
43250
+ return _loadCommand3.apply(this, arguments);
43251
+ }
43252
+ function _loadCommand3() {
43253
+ _loadCommand3 = spirits._asyncToGenerator( /*#__PURE__*/spirits._regeneratorRuntime().mark(function _callee9(command) {
43254
+ var commandsDir, commandConfig, commandFilePath, mod;
43255
+ return spirits._regeneratorRuntime().wrap(function _callee9$(_context9) {
43256
+ while (1) switch (_context9.prev = _context9.next) {
43257
+ case 0:
43258
+ if (spirits._classPrivateFieldGet(this, _project)) {
43259
+ _context9.next = 2;
43260
+ break;
43261
+ }
43262
+ throw new Error("Must load #project before running #loadCommand");
43263
+ case 2:
43264
+ commandsDir = path$2.resolve(spirits._classPrivateFieldGet(this, _src), "./commands");
43265
+ commandConfig = spirits._classPrivateFieldGet(this, _project).commands.find(function (command) {
43266
+ return command.entity === command || command.path === command;
43267
+ });
43268
+ if (commandConfig) {
43269
+ _context9.next = 6;
43270
+ break;
43271
+ }
43272
+ throw new Error("Unable to find command \"".concat(command, "\""));
43273
+ case 6:
43274
+ commandFilePath = path$2.resolve(commandsDir, commandConfig.path);
43275
+ _context9.prev = 7;
43276
+ _context9.next = 10;
43277
+ return (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(commandFilePath);
43278
+ case 10:
43279
+ mod = _context9.sent;
43280
+ _context9.next = 16;
43281
+ break;
43282
+ case 13:
43283
+ _context9.prev = 13;
43284
+ _context9.t0 = _context9["catch"](7);
43285
+ throw new Error("Unable to resolve command ".concat(command, " at ").concat(commandFilePath));
43286
+ case 16:
43287
+ if (!(!mod || !mod["default"])) {
43288
+ _context9.next = 18;
43289
+ break;
43290
+ }
43291
+ throw new Error("Unable to run command ".concat(command, " at ").concat(commandFilePath, " - must return a default function that returns a WorkflowEvent payload"));
43292
+ case 18:
43293
+ return _context9.abrupt("return", mod["default"]);
43294
+ case 19:
43295
+ case "end":
43296
+ return _context9.stop();
43297
+ }
43298
+ }, _callee9, this, [[7, 13]]);
43299
+ }));
43300
+ return _loadCommand3.apply(this, arguments);
43301
+ }
43138
43302
 
43139
43303
  exports.$ = $$1;
43140
43304
  exports.MacroGlobals = MacroGlobals;