@scout9/app 1.0.0-alpha.0.4.1 → 1.0.0-alpha.0.4.3
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.
- package/README.md +6 -17
- package/dist/{dev-0876e8d1.cjs → dev-195686a8.cjs} +68 -3
- package/dist/{index-9280182b.cjs → index-ec0cd08d.cjs} +114 -71
- package/dist/index.cjs +4 -2
- package/dist/{multipart-parser-1d947388.cjs → multipart-parser-a2f207ea.cjs} +2 -2
- package/dist/testing-tools.cjs +1 -1
- package/package.json +2 -2
- package/src/core/templates/app.js +14 -8
- package/src/runtime/macros/builder.js +56 -9
- package/src/runtime/macros/event.js +31 -1
package/README.md
CHANGED
|
@@ -1,33 +1,22 @@
|
|
|
1
1
|
# @scout9/app
|
|
2
|
+
*(soon to be renamed to @scout9/pmt)*
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
Application runtime to deploy and drive your [PMT's](https://scout9.com) custom conversational logic.
|
|
4
5
|
|
|
5
6
|
`npm create scout9@latest my-app`
|
|
6
7
|
|
|
7
|
-
### Alpha (Not Released)
|
|
8
|
-
|
|
9
8
|
* Chatbots 🤮
|
|
10
9
|
* One on One Communication 😎
|
|
11
10
|
* Scale? 🤷
|
|
12
|
-
* 💎 [Scout9](https://scout9.com)
|
|
11
|
+
* 💎 [Scout9's PMT](https://scout9.com)
|
|
13
12
|
|
|
14
|
-
Scout9's Persona Model
|
|
13
|
+
Scout9's Persona Model Transform (PMT) **guarantees** to craft auto generated messages into your words, so that you can spend less time typing repetitive messages and more time on more pressing customer interactions.
|
|
15
14
|
|
|
16
|
-
**
|
|
15
|
+
**Note**: If your PMT cannot guarantee to transform a particular message in your own words, it will forward the conversation to you to handle personally.
|
|
17
16
|
|
|
18
17
|
### Commands
|
|
19
18
|
* `npm install -g scout9`
|
|
20
19
|
* `scout9 dev`
|
|
21
20
|
* `scout9 build`
|
|
22
21
|
* `scout9 deploy`
|
|
23
|
-
* `scout9 sync` (coming soon)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
#### Thanks to our early backers using Scout9 to improve their customer experience
|
|
28
|
-
* [REI](https://rei.com): Supply chain procurement SMS auto replies
|
|
29
|
-
* [Microsoft](https://microsoft.com): Azure customer account support SMS auto replies
|
|
30
|
-
* [Accenture](https://accenture.com): Improving sales pipelines
|
|
31
|
-
* [Paco Equip](https://pacoequip.com): Improve customer contact and support speed
|
|
32
|
-
* [Campbells](https://cambells.com): Bill and lading confirmation SMS auto replies
|
|
33
|
-
* [WelcomeHome](https://getwelocomehome.com): Dedicated House Manager text to maintenance
|
|
22
|
+
* `scout9 sync` *(coming soon)*
|
|
@@ -29824,7 +29824,7 @@ common.createRequestFunction = createRequestFunction;
|
|
|
29824
29824
|
var configuration = {};
|
|
29825
29825
|
|
|
29826
29826
|
var name$1 = "@scout9/admin";
|
|
29827
|
-
var version$2 = "1.0.0-alpha.0.0.
|
|
29827
|
+
var version$2 = "1.0.0-alpha.0.0.51";
|
|
29828
29828
|
var description$1 = "";
|
|
29829
29829
|
var main$2 = "./build/index.js";
|
|
29830
29830
|
var types$1 = "./build/index.d.ts";
|
|
@@ -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-
|
|
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-195686a8.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,37 @@ 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: function $convo() {
|
|
35791
|
+
var _globalThis$SCOUT;
|
|
35792
|
+
var $convo = globalThis === null || globalThis === void 0 || (_globalThis$SCOUT = globalThis.SCOUT9) === null || _globalThis$SCOUT === void 0 ? void 0 : _globalThis$SCOUT.$convo;
|
|
35793
|
+
if (!$convo) {
|
|
35794
|
+
throw new Error("$convo not found in runtime context, ".concat(spirits._classStaticPrivateFieldSpecGet(MacroGlobals, MacroGlobals, _hint)));
|
|
35795
|
+
}
|
|
35796
|
+
return $convo;
|
|
35797
|
+
}
|
|
35798
|
+
}, {
|
|
35799
|
+
key: "event",
|
|
35800
|
+
value: function event() {
|
|
35801
|
+
var event = globalThis === null || globalThis === void 0 ? void 0 : globalThis.SCOUT9;
|
|
35802
|
+
if (!event) {
|
|
35803
|
+
throw new Error("No runtime context, ".concat(spirits._classStaticPrivateFieldSpecGet(MacroGlobals, MacroGlobals, _hint)));
|
|
35804
|
+
}
|
|
35805
|
+
return event;
|
|
35806
|
+
}
|
|
35807
|
+
}]);
|
|
35808
|
+
return MacroGlobals;
|
|
35809
|
+
}();
|
|
35810
|
+
var _hint = {
|
|
35811
|
+
writable: true,
|
|
35812
|
+
value: "make sure the context is properly instantiated before running workflow."
|
|
35813
|
+
};
|
|
35814
|
+
|
|
35784
35815
|
var _excluded$1 = ["success"];
|
|
35785
35816
|
|
|
35786
35817
|
/**
|
|
@@ -35994,6 +36025,25 @@ function EventMacrosFactory() {
|
|
|
35994
36025
|
}
|
|
35995
36026
|
return this;
|
|
35996
36027
|
},
|
|
36028
|
+
/**
|
|
36029
|
+
* If conversation is not stagnant, return instructions to guide next auto reply response, otherwise it will forward the conversation
|
|
36030
|
+
* @param {string} instruction
|
|
36031
|
+
* @param {OptionsInstruct & OptionsForward & {stagnationLimit?: number}} [options] - stagnationCountLimit, defaults to 2
|
|
36032
|
+
* @return {EventMacros}
|
|
36033
|
+
*/
|
|
36034
|
+
instructSafe: function instructSafe(instruction) {
|
|
36035
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
36036
|
+
stagnationLimit: 2
|
|
36037
|
+
};
|
|
36038
|
+
var _options$stagnationLi = options.stagnationLimit,
|
|
36039
|
+
stagnationLimit = _options$stagnationLi === void 0 ? 2 : _options$stagnationLi;
|
|
36040
|
+
var event = MacroGlobals.event(); // Check the event to eval stagnation
|
|
36041
|
+
if (event.stagnationCount < stagnationLimit) {
|
|
36042
|
+
return this.instruct(instruction, options);
|
|
36043
|
+
} else {
|
|
36044
|
+
return this.forward("Instruct Exceeds event.stagnationCount >= ".concat(stagnationLimit, ": ").concat(instruction), options);
|
|
36045
|
+
}
|
|
36046
|
+
},
|
|
35997
36047
|
/**
|
|
35998
36048
|
* Return instructions to guide next auto reply response
|
|
35999
36049
|
* @param {string} instruction
|
|
@@ -36110,7 +36160,7 @@ function EventMacrosFactory() {
|
|
|
36110
36160
|
var eventMacros = EventMacrosFactory();
|
|
36111
36161
|
|
|
36112
36162
|
/**
|
|
36113
|
-
* Return instructions to guide next
|
|
36163
|
+
* Return instructions to guide next response
|
|
36114
36164
|
* @param {string} instruction - the instruction to send to the
|
|
36115
36165
|
* @param {OptionsInstruct} [options]
|
|
36116
36166
|
* @return {EventMacros}
|
|
@@ -36121,6 +36171,19 @@ var eventMacros = EventMacrosFactory();
|
|
|
36121
36171
|
*/
|
|
36122
36172
|
var instruct = eventMacros.instruct.bind(eventMacros);
|
|
36123
36173
|
|
|
36174
|
+
/**
|
|
36175
|
+
* If conversation is not stagnant, return instructions to guide next auto reply response, otherwise it will forward the conversation
|
|
36176
|
+
* @param {string} instruction - the instruction to send to the
|
|
36177
|
+
* @param {OptionsInstruct} [options]
|
|
36178
|
+
* @return {EventMacros}
|
|
36179
|
+
*
|
|
36180
|
+
* @example instructSafe("Ask user if they are looking to order a pizza");
|
|
36181
|
+
* @example instructSafe("Ask user if they are looking to order a pizza", {stagnationLimit: 3}); // Allows for 3 stagnate messages before forwarding
|
|
36182
|
+
*
|
|
36183
|
+
* @type {(message: string, options?: OptionsInstruct) => EventMacros}
|
|
36184
|
+
*/
|
|
36185
|
+
var instructSafe = eventMacros.instructSafe.bind(eventMacros);
|
|
36186
|
+
|
|
36124
36187
|
/**
|
|
36125
36188
|
* Forwards conversation back to you or owner of workflow.
|
|
36126
36189
|
*
|
|
@@ -42828,6 +42891,7 @@ var Scout9Test = /*#__PURE__*/function () {
|
|
|
42828
42891
|
}();
|
|
42829
42892
|
|
|
42830
42893
|
exports.$ = $$1;
|
|
42894
|
+
exports.MacroGlobals = MacroGlobals;
|
|
42831
42895
|
exports.ProgressLogger = ProgressLogger;
|
|
42832
42896
|
exports.Scout9Test = Scout9Test;
|
|
42833
42897
|
exports.balancedMatch = balancedMatch;
|
|
@@ -42846,6 +42910,7 @@ exports.getAugmentedNamespace = getAugmentedNamespace;
|
|
|
42846
42910
|
exports.getDefaultExportFromCjs = getDefaultExportFromCjs;
|
|
42847
42911
|
exports.globSync = globSync;
|
|
42848
42912
|
exports.instruct = instruct;
|
|
42913
|
+
exports.instructSafe = instructSafe;
|
|
42849
42914
|
exports.loadConfig = loadConfig;
|
|
42850
42915
|
exports.loadEnvConfig = loadEnvConfig;
|
|
42851
42916
|
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-
|
|
4
|
+
var dev = require("./dev-195686a8.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-
|
|
29486
|
+
} = await Promise.resolve().then(function () { return require("./multipart-parser-a2f207ea.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-
|
|
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-ec0cd08d.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,7 @@ var EventResponse = /*#__PURE__*/function () {
|
|
|
41966
41966
|
return EventResponse;
|
|
41967
41967
|
}();
|
|
41968
41968
|
|
|
41969
|
-
var
|
|
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
|
-
|
|
41969
|
+
var _excluded = ["event"];
|
|
42000
41970
|
function handleAxiosResponse(res) {
|
|
42001
41971
|
if (res.status === 200) {
|
|
42002
41972
|
return res.data;
|
|
@@ -42007,6 +41977,20 @@ function handleAxiosResponse(res) {
|
|
|
42007
41977
|
}
|
|
42008
41978
|
}
|
|
42009
41979
|
|
|
41980
|
+
/**
|
|
41981
|
+
* Util function to prevent macros sending event payloads larger than x kilobytes
|
|
41982
|
+
*/
|
|
41983
|
+
function processPayload(payload) {
|
|
41984
|
+
var maxKb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 250;
|
|
41985
|
+
if (Buffer.byteLength(JSON.stringify(payload.event), 'utf8') / 1024 > maxKb) {
|
|
41986
|
+
payload.event;
|
|
41987
|
+
var rest = spirits._objectWithoutProperties(payload, _excluded); // Remove event from payload, too large
|
|
41988
|
+
return rest;
|
|
41989
|
+
} else {
|
|
41990
|
+
return payload;
|
|
41991
|
+
}
|
|
41992
|
+
}
|
|
41993
|
+
|
|
42010
41994
|
/**
|
|
42011
41995
|
* The `did` macro takes a given prompt and infers a binary `true` or `false` result in relation to the prompt's subject actor and the prompt's inquiry.
|
|
42012
41996
|
* @param {string} prompt
|
|
@@ -42016,6 +42000,57 @@ function did(_x) {
|
|
|
42016
42000
|
return _did.apply(this, arguments);
|
|
42017
42001
|
}
|
|
42018
42002
|
|
|
42003
|
+
/**
|
|
42004
|
+
* The `does` macro takes a given prompt and infers a binary `true` or `false` result in relation to the prompt's subject actor and the prompt's inquiry for the given immediate message
|
|
42005
|
+
*
|
|
42006
|
+
* Only use this if you want to evaluate the latest message, otherwise use did() which uses all messages
|
|
42007
|
+
* @param {string} prompt
|
|
42008
|
+
* @param {'customer' | 'agent'} [relation]
|
|
42009
|
+
* @return {Promise<boolean>}
|
|
42010
|
+
*/
|
|
42011
|
+
function _did() {
|
|
42012
|
+
_did = spirits._asyncToGenerator( /*#__PURE__*/spirits._regeneratorRuntime().mark(function _callee(prompt) {
|
|
42013
|
+
var convoId, event, _yield$Scout9Api$did$, value;
|
|
42014
|
+
return spirits._regeneratorRuntime().wrap(function _callee$(_context2) {
|
|
42015
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
42016
|
+
case 0:
|
|
42017
|
+
convoId = dev.MacroGlobals.$convo();
|
|
42018
|
+
event = dev.MacroGlobals.event();
|
|
42019
|
+
event.conversation.$id = convoId;
|
|
42020
|
+
event.conversation.id = convoId;
|
|
42021
|
+
if (convoId) {
|
|
42022
|
+
_context2.next = 6;
|
|
42023
|
+
break;
|
|
42024
|
+
}
|
|
42025
|
+
throw new Error("Internal: Unable to contextualize did response for \"".concat(prompt, "\""));
|
|
42026
|
+
case 6:
|
|
42027
|
+
_context2.next = 8;
|
|
42028
|
+
return new dev.build.Scout9Api(new dev.build.Configuration({
|
|
42029
|
+
apiKey: process.env.SCOUT9_API_KEY
|
|
42030
|
+
})).did(processPayload({
|
|
42031
|
+
prompt: prompt,
|
|
42032
|
+
convoId: convoId,
|
|
42033
|
+
event: event
|
|
42034
|
+
})).then(handleAxiosResponse)["catch"](function (err) {
|
|
42035
|
+
console.error('Error in did macro', err);
|
|
42036
|
+
throw err;
|
|
42037
|
+
});
|
|
42038
|
+
case 8:
|
|
42039
|
+
_yield$Scout9Api$did$ = _context2.sent;
|
|
42040
|
+
value = _yield$Scout9Api$did$.value;
|
|
42041
|
+
return _context2.abrupt("return", value);
|
|
42042
|
+
case 11:
|
|
42043
|
+
case "end":
|
|
42044
|
+
return _context2.stop();
|
|
42045
|
+
}
|
|
42046
|
+
}, _callee);
|
|
42047
|
+
}));
|
|
42048
|
+
return _did.apply(this, arguments);
|
|
42049
|
+
}
|
|
42050
|
+
function does(_x2) {
|
|
42051
|
+
return _does.apply(this, arguments);
|
|
42052
|
+
}
|
|
42053
|
+
|
|
42019
42054
|
/**
|
|
42020
42055
|
* @typedef {import('@scout9/admin').MacroContextInputExamples} ContextExamples
|
|
42021
42056
|
* @typedef {import('@scout9/admin').MacroContextValue} ContextOutput
|
|
@@ -42038,85 +42073,92 @@ function did(_x) {
|
|
|
42038
42073
|
* @param {ContextExamples} [examples] - Examples to the macro to ensure a consistent data structure.
|
|
42039
42074
|
* @return {Promise<ContextOutput>}
|
|
42040
42075
|
*/
|
|
42041
|
-
function
|
|
42042
|
-
|
|
42043
|
-
var
|
|
42044
|
-
|
|
42045
|
-
|
|
42076
|
+
function _does() {
|
|
42077
|
+
_does = spirits._asyncToGenerator( /*#__PURE__*/spirits._regeneratorRuntime().mark(function _callee2(prompt) {
|
|
42078
|
+
var relation,
|
|
42079
|
+
convoId,
|
|
42080
|
+
event,
|
|
42081
|
+
_yield$Scout9Api$does,
|
|
42082
|
+
value,
|
|
42083
|
+
_args2 = arguments;
|
|
42084
|
+
return spirits._regeneratorRuntime().wrap(function _callee2$(_context3) {
|
|
42085
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
42046
42086
|
case 0:
|
|
42047
|
-
|
|
42048
|
-
|
|
42087
|
+
relation = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : 'customer';
|
|
42088
|
+
convoId = dev.MacroGlobals.$convo();
|
|
42089
|
+
event = dev.MacroGlobals.event();
|
|
42049
42090
|
event.conversation.$id = convoId;
|
|
42050
42091
|
event.conversation.id = convoId;
|
|
42051
42092
|
if (convoId) {
|
|
42052
|
-
|
|
42093
|
+
_context3.next = 7;
|
|
42053
42094
|
break;
|
|
42054
42095
|
}
|
|
42055
|
-
throw new Error("Internal: Unable to contextualize
|
|
42056
|
-
case
|
|
42057
|
-
|
|
42096
|
+
throw new Error("Internal: Unable to contextualize does response for \"".concat(prompt, "\""));
|
|
42097
|
+
case 7:
|
|
42098
|
+
_context3.next = 9;
|
|
42058
42099
|
return new dev.build.Scout9Api(new dev.build.Configuration({
|
|
42059
42100
|
apiKey: process.env.SCOUT9_API_KEY
|
|
42060
|
-
})).
|
|
42101
|
+
})).does(processPayload({
|
|
42061
42102
|
prompt: prompt,
|
|
42062
42103
|
convoId: convoId,
|
|
42104
|
+
role: relation,
|
|
42063
42105
|
event: event
|
|
42064
|
-
}).then(handleAxiosResponse)["catch"](function (err) {
|
|
42106
|
+
})).then(handleAxiosResponse)["catch"](function (err) {
|
|
42065
42107
|
console.error('Error in did macro', err);
|
|
42066
42108
|
throw err;
|
|
42067
42109
|
});
|
|
42068
|
-
case
|
|
42069
|
-
_yield$Scout9Api$
|
|
42070
|
-
value = _yield$Scout9Api$
|
|
42071
|
-
return
|
|
42072
|
-
case
|
|
42110
|
+
case 9:
|
|
42111
|
+
_yield$Scout9Api$does = _context3.sent;
|
|
42112
|
+
value = _yield$Scout9Api$does.value;
|
|
42113
|
+
return _context3.abrupt("return", value);
|
|
42114
|
+
case 12:
|
|
42073
42115
|
case "end":
|
|
42074
|
-
return
|
|
42116
|
+
return _context3.stop();
|
|
42075
42117
|
}
|
|
42076
|
-
},
|
|
42118
|
+
}, _callee2);
|
|
42077
42119
|
}));
|
|
42078
|
-
return
|
|
42120
|
+
return _does.apply(this, arguments);
|
|
42079
42121
|
}
|
|
42080
|
-
function context(
|
|
42122
|
+
function context(_x3, _x4) {
|
|
42081
42123
|
return _context.apply(this, arguments);
|
|
42082
42124
|
}
|
|
42083
42125
|
function _context() {
|
|
42084
|
-
_context = spirits._asyncToGenerator( /*#__PURE__*/spirits._regeneratorRuntime().mark(function
|
|
42126
|
+
_context = spirits._asyncToGenerator( /*#__PURE__*/spirits._regeneratorRuntime().mark(function _callee3(prompt, examples) {
|
|
42085
42127
|
var convoId, event, _yield$Scout9Api$capt, value;
|
|
42086
|
-
return spirits._regeneratorRuntime().wrap(function
|
|
42087
|
-
while (1) switch (
|
|
42128
|
+
return spirits._regeneratorRuntime().wrap(function _callee3$(_context4) {
|
|
42129
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
42088
42130
|
case 0:
|
|
42089
|
-
convoId = MacroGlobals.$convo();
|
|
42090
|
-
event = MacroGlobals.event();
|
|
42131
|
+
convoId = dev.MacroGlobals.$convo();
|
|
42132
|
+
event = dev.MacroGlobals.event();
|
|
42091
42133
|
event.conversation.$id = convoId;
|
|
42092
42134
|
event.conversation.id = convoId;
|
|
42093
42135
|
if (convoId) {
|
|
42094
|
-
|
|
42136
|
+
_context4.next = 6;
|
|
42095
42137
|
break;
|
|
42096
42138
|
}
|
|
42097
42139
|
throw new Error("Internal: Unable to contextualize did response for \"".concat(prompt, "\""));
|
|
42098
42140
|
case 6:
|
|
42099
|
-
|
|
42141
|
+
_context4.next = 8;
|
|
42100
42142
|
return new dev.build.Scout9Api(new dev.build.Configuration({
|
|
42101
42143
|
apiKey: process.env.SCOUT9_API_KEY
|
|
42102
|
-
})).captureContext({
|
|
42144
|
+
})).captureContext(processPayload({
|
|
42103
42145
|
prompt: prompt,
|
|
42104
42146
|
examples: examples,
|
|
42105
42147
|
convoId: convoId,
|
|
42106
42148
|
event: event
|
|
42107
|
-
}).then(handleAxiosResponse)["catch"](function (err) {
|
|
42149
|
+
})).then(handleAxiosResponse)["catch"](function (err) {
|
|
42108
42150
|
console.error('Error in context macro', err);
|
|
42109
42151
|
throw err;
|
|
42110
42152
|
});
|
|
42111
42153
|
case 8:
|
|
42112
|
-
_yield$Scout9Api$capt =
|
|
42154
|
+
_yield$Scout9Api$capt = _context4.sent;
|
|
42113
42155
|
value = _yield$Scout9Api$capt.value;
|
|
42114
|
-
return
|
|
42156
|
+
return _context4.abrupt("return", value);
|
|
42115
42157
|
case 11:
|
|
42116
42158
|
case "end":
|
|
42117
|
-
return
|
|
42159
|
+
return _context4.stop();
|
|
42118
42160
|
}
|
|
42119
|
-
},
|
|
42161
|
+
}, _callee3);
|
|
42120
42162
|
}));
|
|
42121
42163
|
return _context.apply(this, arguments);
|
|
42122
42164
|
}
|
|
@@ -43115,7 +43157,7 @@ var ProjectFiles = /*#__PURE__*/function () {
|
|
|
43115
43157
|
return ProjectFiles;
|
|
43116
43158
|
}();
|
|
43117
43159
|
|
|
43118
|
-
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-
|
|
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-ec0cd08d.js', document.baseURI).href)));
|
|
43119
43161
|
var __dirname$1 = path__default["default"].dirname(__filename$1);
|
|
43120
43162
|
function zipDirectory(source, out) {
|
|
43121
43163
|
var archive = archiver$1('tar', {
|
|
@@ -43330,7 +43372,7 @@ function _buildApp() {
|
|
|
43330
43372
|
case 11:
|
|
43331
43373
|
_context4.t0 = JSON;
|
|
43332
43374
|
_context4.next = 14;
|
|
43333
|
-
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-
|
|
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-ec0cd08d.js', document.baseURI).href))), 'utf-8');
|
|
43334
43376
|
case 14:
|
|
43335
43377
|
_context4.t1 = _context4.sent;
|
|
43336
43378
|
packageTemplate = _context4.t0.parse.call(_context4.t0, _context4.t1);
|
|
@@ -44553,6 +44595,7 @@ exports.File = File;
|
|
|
44553
44595
|
exports.FormData = FormData;
|
|
44554
44596
|
exports.context = context;
|
|
44555
44597
|
exports.did = did;
|
|
44598
|
+
exports.does = does;
|
|
44556
44599
|
exports.json = json;
|
|
44557
44600
|
exports.run = run;
|
|
44558
44601
|
exports.sendEvent = sendEvent;
|
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-
|
|
6
|
-
var dev = require("./dev-
|
|
5
|
+
var index = require("./index-ec0cd08d.cjs");
|
|
6
|
+
var dev = require("./dev-195686a8.cjs");
|
|
7
7
|
require("./spirits-5c9243a1.cjs");
|
|
8
8
|
require("./macros-e4105c56.cjs");
|
|
9
9
|
require('fs');
|
|
@@ -45,6 +45,7 @@ require('node:process');
|
|
|
45
45
|
exports.EventResponse = index.EventResponse;
|
|
46
46
|
exports.context = index.context;
|
|
47
47
|
exports.did = index.did;
|
|
48
|
+
exports.does = index.does;
|
|
48
49
|
exports.json = index.json;
|
|
49
50
|
exports.run = index.run;
|
|
50
51
|
exports.sendEvent = index.sendEvent;
|
|
@@ -56,4 +57,5 @@ exports.createMockMessage = dev.createMockMessage;
|
|
|
56
57
|
exports.createMockWorkflowEvent = dev.createMockWorkflowEvent;
|
|
57
58
|
exports.forward = dev.forward;
|
|
58
59
|
exports.instruct = dev.instruct;
|
|
60
|
+
exports.instructSafe = dev.instructSafe;
|
|
59
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-
|
|
5
|
+
var index = require("./index-ec0cd08d.cjs");
|
|
6
6
|
require("./spirits-5c9243a1.cjs");
|
|
7
|
-
require("./dev-
|
|
7
|
+
require("./dev-195686a8.cjs");
|
|
8
8
|
require('util');
|
|
9
9
|
require('stream');
|
|
10
10
|
require('path');
|
package/dist/testing-tools.cjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scout9/app",
|
|
3
|
-
"version": "1.0.0-alpha.0.4.
|
|
3
|
+
"version": "1.0.0-alpha.0.4.3",
|
|
4
4
|
"description": "Build and deploy your Scout9 app for SMS auto replies",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"zod-to-ts": "^1.2.0"
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@scout9/admin": "^1.0.0-alpha.0.0.
|
|
88
|
+
"@scout9/admin": "^1.0.0-alpha.0.0.51",
|
|
89
89
|
"@scout9/crm": "^1.0.0-alpha.0.0.4",
|
|
90
90
|
"archiver": "^6.0.1",
|
|
91
91
|
"body-parser": "^1.20.2",
|
|
@@ -646,13 +646,19 @@ app.listen(process.env.PORT || 8080, err => {
|
|
|
646
646
|
|\\_________\\|_______|\\|_______|\\|_______| \\|__| \\|_______|
|
|
647
647
|
\\|_________|
|
|
648
648
|
`;
|
|
649
|
-
const
|
|
650
|
-
|
|
651
|
-
/
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
649
|
+
const art_pmt = `
|
|
650
|
+
_______ __ __ ________
|
|
651
|
+
| \ | \ / \| \
|
|
652
|
+
| $$$$$$$\| $$\ / $$ \$$$$$$$$
|
|
653
|
+
| $$__/ $$| $$$\ / $$$ | $$
|
|
654
|
+
| $$ $$| $$$$\ $$$$ | $$
|
|
655
|
+
| $$$$$$$ | $$\$$ $$ $$ | $$
|
|
656
|
+
| $$ | $$ \$$$| $$ | $$
|
|
657
|
+
| $$ | $$ \$ | $$ | $$
|
|
658
|
+
\$$ \$$ \$$ \$$
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
656
662
|
`;
|
|
657
663
|
const protocol = process.env.PROTOCOL || 'http';
|
|
658
664
|
const host = process.env.HOST || 'localhost';
|
|
@@ -660,7 +666,7 @@ app.listen(process.env.PORT || 8080, err => {
|
|
|
660
666
|
const fullUrl = `${protocol}://${host}:${port}`;
|
|
661
667
|
if (dev) {
|
|
662
668
|
console.log(colors.bold(colors.green(art_scout9)));
|
|
663
|
-
console.log(colors.bold(colors.cyan(
|
|
669
|
+
console.log(colors.bold(colors.cyan(art_pmt)));
|
|
664
670
|
console.log(`${colors.grey(`${colors.cyan('>')} Running ${colors.bold(colors.white('Scout9'))}`)} ${colors.bold(
|
|
665
671
|
colors.red(colors.bgBlack('auto-reply')))} ${colors.grey('dev environment on')} ${fullUrl}`);
|
|
666
672
|
} else {
|
|
@@ -11,10 +11,23 @@ function handleAxiosResponse(res) {
|
|
|
11
11
|
} else {
|
|
12
12
|
// @TODO remove log
|
|
13
13
|
console.error('Macro Failed To Run', res.status, res.statusText, res.data);
|
|
14
|
-
throw new Error(`${res.status} ${res.statusText}`)
|
|
14
|
+
throw new Error(`${res.status} ${res.statusText}`);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Util function to prevent macros sending event payloads larger than x kilobytes
|
|
20
|
+
*/
|
|
21
|
+
function processPayload(payload, maxKb = 250) {
|
|
22
|
+
if ((Buffer.byteLength(JSON.stringify(payload.event), 'utf8') / 1024) > maxKb) {
|
|
23
|
+
const {event, ...rest} = payload; // Remove event from payload, too large
|
|
24
|
+
return rest;
|
|
25
|
+
} else {
|
|
26
|
+
return payload;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
18
31
|
/**
|
|
19
32
|
* The `did` macro takes a given prompt and infers a binary `true` or `false` result in relation to the prompt's subject actor and the prompt's inquiry.
|
|
20
33
|
* @param {string} prompt
|
|
@@ -28,11 +41,44 @@ export async function did(prompt) {
|
|
|
28
41
|
if (!convoId) {
|
|
29
42
|
throw new Error(`Internal: Unable to contextualize did response for "${prompt}"`);
|
|
30
43
|
}
|
|
31
|
-
const {value} = (await (new Scout9Api(new Configuration({apiKey: process.env.SCOUT9_API_KEY}))).did({
|
|
44
|
+
const {value} = (await (new Scout9Api(new Configuration({apiKey: process.env.SCOUT9_API_KEY}))).did(processPayload({
|
|
32
45
|
prompt,
|
|
33
46
|
convoId,
|
|
34
47
|
event
|
|
35
|
-
})
|
|
48
|
+
}))
|
|
49
|
+
.then(handleAxiosResponse)
|
|
50
|
+
.catch((err) => {
|
|
51
|
+
console.error('Error in did macro', err);
|
|
52
|
+
throw err;
|
|
53
|
+
}));
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The `does` macro takes a given prompt and infers a binary `true` or `false` result in relation to the prompt's subject actor and the prompt's inquiry for the given immediate message
|
|
59
|
+
*
|
|
60
|
+
* Only use this if you want to evaluate the latest message, otherwise use did() which uses all messages
|
|
61
|
+
* @param {string} prompt
|
|
62
|
+
* @param {'customer' | 'agent'} [relation]
|
|
63
|
+
* @return {Promise<boolean>}
|
|
64
|
+
*/
|
|
65
|
+
export async function does(prompt, relation = 'customer') {
|
|
66
|
+
const convoId = MacroGlobals.$convo();
|
|
67
|
+
const event = MacroGlobals.event();
|
|
68
|
+
event.conversation.$id = convoId;
|
|
69
|
+
event.conversation.id = convoId;
|
|
70
|
+
if (!convoId) {
|
|
71
|
+
throw new Error(`Internal: Unable to contextualize does response for "${prompt}"`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const {value} = (await (new Scout9Api(new Configuration({apiKey: process.env.SCOUT9_API_KEY}))).does(
|
|
75
|
+
processPayload({
|
|
76
|
+
prompt,
|
|
77
|
+
convoId,
|
|
78
|
+
role: relation,
|
|
79
|
+
event
|
|
80
|
+
})
|
|
81
|
+
)
|
|
36
82
|
.then(handleAxiosResponse)
|
|
37
83
|
.catch((err) => {
|
|
38
84
|
console.error('Error in did macro', err);
|
|
@@ -71,12 +117,13 @@ export async function context(prompt, examples) {
|
|
|
71
117
|
if (!convoId) {
|
|
72
118
|
throw new Error(`Internal: Unable to contextualize did response for "${prompt}"`);
|
|
73
119
|
}
|
|
74
|
-
const {value} = (await (new Scout9Api(new Configuration({apiKey: process.env.SCOUT9_API_KEY}))).captureContext(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
120
|
+
const {value} = (await (new Scout9Api(new Configuration({apiKey: process.env.SCOUT9_API_KEY}))).captureContext(
|
|
121
|
+
processPayload({
|
|
122
|
+
prompt,
|
|
123
|
+
examples,
|
|
124
|
+
convoId,
|
|
125
|
+
event
|
|
126
|
+
}))
|
|
80
127
|
.then(handleAxiosResponse)
|
|
81
128
|
.catch((err) => {
|
|
82
129
|
console.error('Error in context macro', err);
|
|
@@ -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
|
/**
|
|
@@ -214,6 +215,22 @@ function EventMacrosFactory() {
|
|
|
214
215
|
return this;
|
|
215
216
|
},
|
|
216
217
|
|
|
218
|
+
/**
|
|
219
|
+
* If conversation is not stagnant, return instructions to guide next auto reply response, otherwise it will forward the conversation
|
|
220
|
+
* @param {string} instruction
|
|
221
|
+
* @param {OptionsInstruct & OptionsForward & {stagnationLimit?: number}} [options] - stagnationCountLimit, defaults to 2
|
|
222
|
+
* @return {EventMacros}
|
|
223
|
+
*/
|
|
224
|
+
instructSafe(instruction, options = {stagnationLimit: 2}) {
|
|
225
|
+
const {stagnationLimit = 2} = options;
|
|
226
|
+
const event = MacroGlobals.event(); // Check the event to eval stagnation
|
|
227
|
+
if (event.stagnationCount < stagnationLimit) {
|
|
228
|
+
return this.instruct(instruction, options);
|
|
229
|
+
} else {
|
|
230
|
+
return this.forward(`Instruct Exceeds event.stagnationCount >= ${stagnationLimit}: ${instruction}`, options);
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
|
|
217
234
|
/**
|
|
218
235
|
* Return instructions to guide next auto reply response
|
|
219
236
|
* @param {string} instruction
|
|
@@ -327,7 +344,7 @@ function EventMacrosFactory() {
|
|
|
327
344
|
const eventMacros = EventMacrosFactory();
|
|
328
345
|
|
|
329
346
|
/**
|
|
330
|
-
* Return instructions to guide next
|
|
347
|
+
* Return instructions to guide next response
|
|
331
348
|
* @param {string} instruction - the instruction to send to the
|
|
332
349
|
* @param {OptionsInstruct} [options]
|
|
333
350
|
* @return {EventMacros}
|
|
@@ -338,6 +355,19 @@ const eventMacros = EventMacrosFactory();
|
|
|
338
355
|
*/
|
|
339
356
|
export const instruct = eventMacros.instruct.bind(eventMacros);
|
|
340
357
|
|
|
358
|
+
/**
|
|
359
|
+
* If conversation is not stagnant, return instructions to guide next auto reply response, otherwise it will forward the conversation
|
|
360
|
+
* @param {string} instruction - the instruction to send to the
|
|
361
|
+
* @param {OptionsInstruct} [options]
|
|
362
|
+
* @return {EventMacros}
|
|
363
|
+
*
|
|
364
|
+
* @example instructSafe("Ask user if they are looking to order a pizza");
|
|
365
|
+
* @example instructSafe("Ask user if they are looking to order a pizza", {stagnationLimit: 3}); // Allows for 3 stagnate messages before forwarding
|
|
366
|
+
*
|
|
367
|
+
* @type {(message: string, options?: OptionsInstruct) => EventMacros}
|
|
368
|
+
*/
|
|
369
|
+
export const instructSafe = eventMacros.instructSafe.bind(eventMacros);
|
|
370
|
+
|
|
341
371
|
/**
|
|
342
372
|
* Forwards conversation back to you or owner of workflow.
|
|
343
373
|
*
|