@scout9/app 1.0.0-alpha.0.4.2 → 1.0.0-alpha.0.4.4

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.
@@ -35049,7 +35049,7 @@ function _loadUserPackageJson() {
35049
35049
  targetPkgUrl = isTest ? packageTestJsonUrl : packageJsonUrl;
35050
35050
  _context2.t0 = JSON;
35051
35051
  _context2.next = 10;
35052
- 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-89d0d9da.js', document.baseURI).href))), 'utf-8');
35052
+ 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-bee5e8fd.js', document.baseURI).href))), 'utf-8');
35053
35053
  case 10:
35054
35054
  _context2.t1 = _context2.sent;
35055
35055
  pkg = _context2.t0.parse.call(_context2.t0, _context2.t1);
@@ -35781,6 +35781,48 @@ function MacroUtilsFactory() {
35781
35781
  }
35782
35782
  var MacroUtils = MacroUtilsFactory();
35783
35783
 
35784
+ var MacroGlobals = /*#__PURE__*/function () {
35785
+ function MacroGlobals() {
35786
+ spirits._classCallCheck(this, MacroGlobals);
35787
+ }
35788
+ spirits._createClass(MacroGlobals, null, [{
35789
+ key: "$convo",
35790
+ value:
35791
+ /**
35792
+ * @returns {string}
35793
+ */
35794
+ function $convo() {
35795
+ var _globalThis$SCOUT;
35796
+ var $convo = globalThis === null || globalThis === void 0 || (_globalThis$SCOUT = globalThis.SCOUT9) === null || _globalThis$SCOUT === void 0 ? void 0 : _globalThis$SCOUT.$convo;
35797
+ if (!$convo) {
35798
+ throw new Error("$convo not found in runtime context, ".concat(spirits._classStaticPrivateFieldSpecGet(MacroGlobals, MacroGlobals, _hint)));
35799
+ }
35800
+ if (typeof $convo !== 'string') {
35801
+ throw new Error("$convo not a type string, $convo=".concat(JSON.stringify($convo)));
35802
+ }
35803
+ return $convo;
35804
+ }
35805
+
35806
+ /**
35807
+ * @returns {WorkflowEvent}
35808
+ */
35809
+ }, {
35810
+ key: "event",
35811
+ value: function event() {
35812
+ var event = globalThis === null || globalThis === void 0 ? void 0 : globalThis.SCOUT9;
35813
+ if (!event) {
35814
+ throw new Error("No runtime context, ".concat(spirits._classStaticPrivateFieldSpecGet(MacroGlobals, MacroGlobals, _hint)));
35815
+ }
35816
+ return event;
35817
+ }
35818
+ }]);
35819
+ return MacroGlobals;
35820
+ }();
35821
+ var _hint = {
35822
+ writable: true,
35823
+ value: "make sure the context is properly instantiated before running workflow."
35824
+ };
35825
+
35784
35826
  var _excluded$1 = ["success"];
35785
35827
 
35786
35828
  /**
@@ -35841,6 +35883,23 @@ var _excluded$1 = ["success"];
35841
35883
  * @property {WorkflowResponseSlotBaseWithKeywords[]} withoutCondition.instruction - Array of slots with keywords.
35842
35884
  */
35843
35885
 
35886
+ // export type WorkflowResponseSlotBase = {
35887
+ // /** Forward input information of a conversation */
35888
+ // forward?: Forward | undefined;
35889
+ // /** Note to provide to the agent, recommend using forward object api instead */
35890
+ // forwardNote?: string | undefined;
35891
+ // instructions?: Instruction[] | undefined;
35892
+ // removeInstructions?: string[] | undefined;
35893
+ // message?: string | undefined;
35894
+ // secondsDelay?: number | undefined;
35895
+ // scheduled?: number | undefined;
35896
+ // contextUpsert?: {
35897
+ // [x: string]: any;
35898
+ // } | undefined;
35899
+ // resetIntent?: boolean | undefined;
35900
+ // followup?: Followup | undefined;
35901
+ // };
35902
+
35844
35903
  /**
35845
35904
  * Event macros to be used inside your scout9 auto reply workflows
35846
35905
  * @typedef {Object} EventMacros
@@ -35853,6 +35912,9 @@ var _excluded$1 = ["success"];
35853
35912
  * @property {function(boolean?): Array<WorkflowResponseSlot>} toJSON
35854
35913
  */
35855
35914
  function EventMacrosFactory() {
35915
+ /**
35916
+ * @type {Array<WorkflowResponseSlot>}
35917
+ */
35856
35918
  var slots = [];
35857
35919
  return {
35858
35920
  /**
@@ -35994,6 +36056,72 @@ function EventMacrosFactory() {
35994
36056
  }
35995
36057
  return this;
35996
36058
  },
36059
+ resetIntent: function resetIntent() {
36060
+ /** @type {WorkflowResponseSlot} */
36061
+ var slot = {
36062
+ resetIntent: true
36063
+ };
36064
+ try {
36065
+ slots.push(macros.WorkflowResponseSlotSchema.parse(slot));
36066
+ } catch (e) {
36067
+ throw simplifyError(e, 'Invalid instruct() input');
36068
+ }
36069
+ return this;
36070
+ },
36071
+ /**
36072
+ * Removes an instruction from the system
36073
+ * @param {string | string[]} idOrIds - the instruction ids to remove
36074
+ * @param {boolean} [strict] - if true, throw error if no id exists
36075
+ */
36076
+ instructRemove: function instructRemove(idOrIds) {
36077
+ var strict = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
36078
+ /** @type {WorkflowResponseSlot} */
36079
+ var slot = {};
36080
+ var ids = Array.isArray(idOrIds) ? idOrIds : typeof idOrIds === 'string' ? [idOrIds] : [];
36081
+ if (!ids.length) {
36082
+ throw new Error("Given an empty or invalid value for instructRemove, given: ".concat(JSON.stringify(idOrIds), ", expect a type string or type Array<string>"));
36083
+ }
36084
+ var event = MacroGlobals.event(); // Check the event to eval ids to remove
36085
+ ids.forEach(function (id) {
36086
+ var message = event.messages.find(function (m) {
36087
+ return m.id === id;
36088
+ });
36089
+ if (!message) {
36090
+ var msg = "Cannot remove \"".concat(id, "\", no instruction found");
36091
+ if (strict) {
36092
+ throw new Error(msg);
36093
+ } else {
36094
+ console.warn(msg);
36095
+ }
36096
+ }
36097
+ });
36098
+ slot.removeInstructions = ids;
36099
+ try {
36100
+ slots.push(macros.WorkflowResponseSlotSchema.parse(slot));
36101
+ } catch (e) {
36102
+ throw simplifyError(e, 'Invalid instruct() input');
36103
+ }
36104
+ return this;
36105
+ },
36106
+ /**
36107
+ * If conversation is not stagnant, return instructions to guide next auto reply response, otherwise it will forward the conversation
36108
+ * @param {string} instruction
36109
+ * @param {OptionsInstruct & OptionsForward & {stagnationLimit?: number}} [options] - stagnationCountLimit, defaults to 2
36110
+ * @return {EventMacros}
36111
+ */
36112
+ instructSafe: function instructSafe(instruction) {
36113
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
36114
+ stagnationLimit: 2
36115
+ };
36116
+ var _options$stagnationLi = options.stagnationLimit,
36117
+ stagnationLimit = _options$stagnationLi === void 0 ? 2 : _options$stagnationLi;
36118
+ var event = MacroGlobals.event(); // Check the event to eval stagnation
36119
+ if (event.stagnationCount < stagnationLimit) {
36120
+ return this.instruct(instruction, options);
36121
+ } else {
36122
+ return this.forward("Instruct Exceeds event.stagnationCount >= ".concat(stagnationLimit, ": ").concat(instruction), options);
36123
+ }
36124
+ },
35997
36125
  /**
35998
36126
  * Return instructions to guide next auto reply response
35999
36127
  * @param {string} instruction
@@ -36110,7 +36238,7 @@ function EventMacrosFactory() {
36110
36238
  var eventMacros = EventMacrosFactory();
36111
36239
 
36112
36240
  /**
36113
- * Return instructions to guide next auto reply response
36241
+ * Return instructions to guide next response
36114
36242
  * @param {string} instruction - the instruction to send to the
36115
36243
  * @param {OptionsInstruct} [options]
36116
36244
  * @return {EventMacros}
@@ -36121,6 +36249,19 @@ var eventMacros = EventMacrosFactory();
36121
36249
  */
36122
36250
  var instruct = eventMacros.instruct.bind(eventMacros);
36123
36251
 
36252
+ /**
36253
+ * If conversation is not stagnant, return instructions to guide next auto reply response, otherwise it will forward the conversation
36254
+ * @param {string} instruction - the instruction to send to the
36255
+ * @param {OptionsInstruct} [options]
36256
+ * @return {EventMacros}
36257
+ *
36258
+ * @example instructSafe("Ask user if they are looking to order a pizza");
36259
+ * @example instructSafe("Ask user if they are looking to order a pizza", {stagnationLimit: 3}); // Allows for 3 stagnate messages before forwarding
36260
+ *
36261
+ * @type {(message: string, options?: OptionsInstruct) => EventMacros}
36262
+ */
36263
+ var instructSafe = eventMacros.instructSafe.bind(eventMacros);
36264
+
36124
36265
  /**
36125
36266
  * Forwards conversation back to you or owner of workflow.
36126
36267
  *
@@ -42828,6 +42969,7 @@ var Scout9Test = /*#__PURE__*/function () {
42828
42969
  }();
42829
42970
 
42830
42971
  exports.$ = $$1;
42972
+ exports.MacroGlobals = MacroGlobals;
42831
42973
  exports.ProgressLogger = ProgressLogger;
42832
42974
  exports.Scout9Test = Scout9Test;
42833
42975
  exports.balancedMatch = balancedMatch;
@@ -42846,6 +42988,7 @@ exports.getAugmentedNamespace = getAugmentedNamespace;
42846
42988
  exports.getDefaultExportFromCjs = getDefaultExportFromCjs;
42847
42989
  exports.globSync = globSync;
42848
42990
  exports.instruct = instruct;
42991
+ exports.instructSafe = instructSafe;
42849
42992
  exports.loadConfig = loadConfig;
42850
42993
  exports.loadEnvConfig = loadEnvConfig;
42851
42994
  exports.loadUserPackageJson = loadUserPackageJson;
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var spirits = require("./spirits-5c9243a1.cjs");
4
- var dev = require("./dev-89d0d9da.cjs");
4
+ var dev = require("./dev-bee5e8fd.cjs");
5
5
  var macros = require("./macros-e4105c56.cjs");
6
6
  var require$$0 = require('fs');
7
7
  var require$$2$1 = require('events');
@@ -29483,7 +29483,7 @@ class Body {
29483
29483
  }
29484
29484
  const {
29485
29485
  toFormData
29486
- } = await Promise.resolve().then(function () { return require("./multipart-parser-6df56089.cjs"); });
29486
+ } = await Promise.resolve().then(function () { return require("./multipart-parser-f2044b7e.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-d60f8919.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-d96ba879.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);
@@ -41966,37 +41966,6 @@ var EventResponse = /*#__PURE__*/function () {
41966
41966
  return EventResponse;
41967
41967
  }();
41968
41968
 
41969
- var MacroGlobals = /*#__PURE__*/function () {
41970
- function MacroGlobals() {
41971
- spirits._classCallCheck(this, MacroGlobals);
41972
- }
41973
- spirits._createClass(MacroGlobals, null, [{
41974
- key: "$convo",
41975
- value: function $convo() {
41976
- var _globalThis$SCOUT;
41977
- var $convo = globalThis === null || globalThis === void 0 || (_globalThis$SCOUT = globalThis.SCOUT9) === null || _globalThis$SCOUT === void 0 ? void 0 : _globalThis$SCOUT.$convo;
41978
- if (!$convo) {
41979
- throw new Error("$convo not found in runtime context, ".concat(spirits._classStaticPrivateFieldSpecGet(MacroGlobals, MacroGlobals, _hint)));
41980
- }
41981
- return $convo;
41982
- }
41983
- }, {
41984
- key: "event",
41985
- value: function event() {
41986
- var event = globalThis === null || globalThis === void 0 ? void 0 : globalThis.SCOUT9;
41987
- if (!event) {
41988
- throw new Error("No runtime context, ".concat(spirits._classStaticPrivateFieldSpecGet(MacroGlobals, MacroGlobals, _hint)));
41989
- }
41990
- return event;
41991
- }
41992
- }]);
41993
- return MacroGlobals;
41994
- }();
41995
- var _hint = {
41996
- writable: true,
41997
- value: "make sure the context is properly instantiated before running workflow."
41998
- };
41999
-
42000
41969
  var _excluded = ["event"];
42001
41970
  function handleAxiosResponse(res) {
42002
41971
  if (res.status === 200) {
@@ -42045,8 +42014,8 @@ function _did() {
42045
42014
  return spirits._regeneratorRuntime().wrap(function _callee$(_context2) {
42046
42015
  while (1) switch (_context2.prev = _context2.next) {
42047
42016
  case 0:
42048
- convoId = MacroGlobals.$convo();
42049
- event = MacroGlobals.event();
42017
+ convoId = dev.MacroGlobals.$convo();
42018
+ event = dev.MacroGlobals.event();
42050
42019
  event.conversation.$id = convoId;
42051
42020
  event.conversation.id = convoId;
42052
42021
  if (convoId) {
@@ -42116,8 +42085,8 @@ function _does() {
42116
42085
  while (1) switch (_context3.prev = _context3.next) {
42117
42086
  case 0:
42118
42087
  relation = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : 'customer';
42119
- convoId = MacroGlobals.$convo();
42120
- event = MacroGlobals.event();
42088
+ convoId = dev.MacroGlobals.$convo();
42089
+ event = dev.MacroGlobals.event();
42121
42090
  event.conversation.$id = convoId;
42122
42091
  event.conversation.id = convoId;
42123
42092
  if (convoId) {
@@ -42159,8 +42128,8 @@ function _context() {
42159
42128
  return spirits._regeneratorRuntime().wrap(function _callee3$(_context4) {
42160
42129
  while (1) switch (_context4.prev = _context4.next) {
42161
42130
  case 0:
42162
- convoId = MacroGlobals.$convo();
42163
- event = MacroGlobals.event();
42131
+ convoId = dev.MacroGlobals.$convo();
42132
+ event = dev.MacroGlobals.event();
42164
42133
  event.conversation.$id = convoId;
42165
42134
  event.conversation.id = convoId;
42166
42135
  if (convoId) {
@@ -43188,7 +43157,7 @@ var ProjectFiles = /*#__PURE__*/function () {
43188
43157
  return ProjectFiles;
43189
43158
  }();
43190
43159
 
43191
- 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-d60f8919.js', document.baseURI).href)));
43160
+ 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-d96ba879.js', document.baseURI).href)));
43192
43161
  var __dirname$1 = path__default["default"].dirname(__filename$1);
43193
43162
  function zipDirectory(source, out) {
43194
43163
  var archive = archiver$1('tar', {
@@ -43403,7 +43372,7 @@ function _buildApp() {
43403
43372
  case 11:
43404
43373
  _context4.t0 = JSON;
43405
43374
  _context4.next = 14;
43406
- 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-d60f8919.js', document.baseURI).href))), 'utf-8');
43375
+ 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-d96ba879.js', document.baseURI).href))), 'utf-8');
43407
43376
  case 14:
43408
43377
  _context4.t1 = _context4.sent;
43409
43378
  packageTemplate = _context4.t0.parse.call(_context4.t0, _context4.t1);
package/dist/index.cjs CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require("./index-d60f8919.cjs");
6
- var dev = require("./dev-89d0d9da.cjs");
5
+ var index = require("./index-d96ba879.cjs");
6
+ var dev = require("./dev-bee5e8fd.cjs");
7
7
  require("./spirits-5c9243a1.cjs");
8
8
  require("./macros-e4105c56.cjs");
9
9
  require('fs');
@@ -57,4 +57,5 @@ exports.createMockMessage = dev.createMockMessage;
57
57
  exports.createMockWorkflowEvent = dev.createMockWorkflowEvent;
58
58
  exports.forward = dev.forward;
59
59
  exports.instruct = dev.instruct;
60
+ exports.instructSafe = dev.instructSafe;
60
61
  exports.reply = dev.reply;
@@ -2,9 +2,9 @@
2
2
 
3
3
  require('node:fs');
4
4
  require('node:path');
5
- var index = require("./index-d60f8919.cjs");
5
+ var index = require("./index-d96ba879.cjs");
6
6
  require("./spirits-5c9243a1.cjs");
7
- require("./dev-89d0d9da.cjs");
7
+ require("./dev-bee5e8fd.cjs");
8
8
  require('util');
9
9
  require('stream');
10
10
  require('path');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dev = require("./dev-89d0d9da.cjs");
5
+ var dev = require("./dev-bee5e8fd.cjs");
6
6
  require("./spirits-5c9243a1.cjs");
7
7
  require('util');
8
8
  require('stream');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scout9/app",
3
- "version": "1.0.0-alpha.0.4.2",
3
+ "version": "1.0.0-alpha.0.4.4",
4
4
  "description": "Build and deploy your Scout9 app for SMS auto replies",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,6 +1,7 @@
1
1
  import { WorkflowResponseSlotBaseSchema, WorkflowResponseSlotSchema } from '../schemas/workflow.js';
2
2
  import { MacroUtils } from './utils.js';
3
3
  import { simplifyError } from '../../utils/index.js';
4
+ import MacroGlobals from './globals.js';
4
5
 
5
6
 
6
7
  /**
@@ -61,6 +62,25 @@ import { simplifyError } from '../../utils/index.js';
61
62
  * @property {WorkflowResponseSlotBaseWithKeywords[]} withoutCondition.instruction - Array of slots with keywords.
62
63
  */
63
64
 
65
+ // export type WorkflowResponseSlotBase = {
66
+ // /** Forward input information of a conversation */
67
+ // forward?: Forward | undefined;
68
+ // /** Note to provide to the agent, recommend using forward object api instead */
69
+ // forwardNote?: string | undefined;
70
+ // instructions?: Instruction[] | undefined;
71
+ // removeInstructions?: string[] | undefined;
72
+ // message?: string | undefined;
73
+ // secondsDelay?: number | undefined;
74
+ // scheduled?: number | undefined;
75
+ // contextUpsert?: {
76
+ // [x: string]: any;
77
+ // } | undefined;
78
+ // resetIntent?: boolean | undefined;
79
+ // followup?: Followup | undefined;
80
+ // };
81
+
82
+
83
+
64
84
  /**
65
85
  * Event macros to be used inside your scout9 auto reply workflows
66
86
  * @typedef {Object} EventMacros
@@ -74,6 +94,9 @@ import { simplifyError } from '../../utils/index.js';
74
94
  */
75
95
  function EventMacrosFactory() {
76
96
 
97
+ /**
98
+ * @type {Array<WorkflowResponseSlot>}
99
+ */
77
100
  let slots = [];
78
101
 
79
102
  return {
@@ -214,6 +237,68 @@ function EventMacrosFactory() {
214
237
  return this;
215
238
  },
216
239
 
240
+ resetIntent() {
241
+ /** @type {WorkflowResponseSlot} */
242
+ const slot = {resetIntent: true};
243
+ try {
244
+ slots.push(WorkflowResponseSlotSchema.parse(slot));
245
+ } catch (e) {
246
+ throw simplifyError(e, 'Invalid instruct() input');
247
+ }
248
+ return this;
249
+ },
250
+
251
+ /**
252
+ * Removes an instruction from the system
253
+ * @param {string | string[]} idOrIds - the instruction ids to remove
254
+ * @param {boolean} [strict] - if true, throw error if no id exists
255
+ */
256
+ instructRemove(idOrIds, strict = false) {
257
+ /** @type {WorkflowResponseSlot} */
258
+ const slot = {};
259
+ const ids = Array.isArray(idOrIds) ? idOrIds : typeof idOrIds === 'string' ? [idOrIds] : [];
260
+ if (!ids.length) {
261
+ throw new Error(`Given an empty or invalid value for instructRemove, given: ${JSON.stringify(idOrIds)}, expect a type string or type Array<string>`);
262
+ }
263
+ const event = MacroGlobals.event(); // Check the event to eval ids to remove
264
+ ids.forEach((id) => {
265
+ const message = event.messages.find(m => m.id === id);
266
+ if (!message) {
267
+ const msg = `Cannot remove "${id}", no instruction found`
268
+ if (strict) {
269
+ throw new Error(msg);
270
+ } else {
271
+ console.warn(msg);
272
+ }
273
+ }
274
+ });
275
+ slot.removeInstructions = ids;
276
+ try {
277
+ slots.push(WorkflowResponseSlotSchema.parse(slot));
278
+ } catch (e) {
279
+ throw simplifyError(e, 'Invalid instruct() input');
280
+ }
281
+ return this;
282
+ },
283
+
284
+ /**
285
+ * If conversation is not stagnant, return instructions to guide next auto reply response, otherwise it will forward the conversation
286
+ * @param {string} instruction
287
+ * @param {OptionsInstruct & OptionsForward & {stagnationLimit?: number}} [options] - stagnationCountLimit, defaults to 2
288
+ * @return {EventMacros}
289
+ */
290
+ instructSafe(instruction, options = {stagnationLimit: 2}) {
291
+ const {stagnationLimit = 2} = options;
292
+ const event = MacroGlobals.event(); // Check the event to eval stagnation
293
+ if (event.stagnationCount < stagnationLimit) {
294
+ return this.instruct(instruction, options);
295
+ } else {
296
+ return this.forward(`Instruct Exceeds event.stagnationCount >= ${stagnationLimit}: ${instruction}`, options);
297
+ }
298
+ },
299
+
300
+
301
+
217
302
  /**
218
303
  * Return instructions to guide next auto reply response
219
304
  * @param {string} instruction
@@ -327,7 +412,7 @@ function EventMacrosFactory() {
327
412
  const eventMacros = EventMacrosFactory();
328
413
 
329
414
  /**
330
- * Return instructions to guide next auto reply response
415
+ * Return instructions to guide next response
331
416
  * @param {string} instruction - the instruction to send to the
332
417
  * @param {OptionsInstruct} [options]
333
418
  * @return {EventMacros}
@@ -338,6 +423,19 @@ const eventMacros = EventMacrosFactory();
338
423
  */
339
424
  export const instruct = eventMacros.instruct.bind(eventMacros);
340
425
 
426
+ /**
427
+ * If conversation is not stagnant, return instructions to guide next auto reply response, otherwise it will forward the conversation
428
+ * @param {string} instruction - the instruction to send to the
429
+ * @param {OptionsInstruct} [options]
430
+ * @return {EventMacros}
431
+ *
432
+ * @example instructSafe("Ask user if they are looking to order a pizza");
433
+ * @example instructSafe("Ask user if they are looking to order a pizza", {stagnationLimit: 3}); // Allows for 3 stagnate messages before forwarding
434
+ *
435
+ * @type {(message: string, options?: OptionsInstruct) => EventMacros}
436
+ */
437
+ export const instructSafe = eventMacros.instructSafe.bind(eventMacros);
438
+
341
439
  /**
342
440
  * Forwards conversation back to you or owner of workflow.
343
441
  *
@@ -2,14 +2,23 @@
2
2
 
3
3
  export default class MacroGlobals {
4
4
 
5
+ /**
6
+ * @returns {string}
7
+ */
5
8
  static $convo() {
6
9
  const $convo = globalThis?.SCOUT9?.$convo;
7
10
  if (!$convo) {
8
11
  throw new Error(`$convo not found in runtime context, ${MacroGlobals.#hint}`);
9
12
  }
13
+ if (typeof $convo !== 'string') {
14
+ throw new Error(`$convo not a type string, $convo=${JSON.stringify($convo)}`);
15
+ }
10
16
  return $convo;
11
17
  }
12
18
 
19
+ /**
20
+ * @returns {WorkflowEvent}
21
+ */
13
22
  static event() {
14
23
  const event = globalThis?.SCOUT9;
15
24
  if (!event) {