@scout9/app 1.0.0-alpha.0.4.0 → 1.0.0-alpha.0.4.2
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-89d0d9da.cjs} +2 -2
- package/dist/{index-9822d519.cjs → index-d60f8919.cjs} +111 -37
- package/dist/index.cjs +3 -2
- package/dist/{multipart-parser-d7d5d504.cjs → multipart-parser-6df56089.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 +60 -13
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-89d0d9da.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);
|
|
@@ -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-89d0d9da.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-6df56089.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-d60f8919.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);
|
|
@@ -41997,6 +41997,7 @@ var _hint = {
|
|
|
41997
41997
|
value: "make sure the context is properly instantiated before running workflow."
|
|
41998
41998
|
};
|
|
41999
41999
|
|
|
42000
|
+
var _excluded = ["event"];
|
|
42000
42001
|
function handleAxiosResponse(res) {
|
|
42001
42002
|
if (res.status === 200) {
|
|
42002
42003
|
return res.data;
|
|
@@ -42007,6 +42008,20 @@ function handleAxiosResponse(res) {
|
|
|
42007
42008
|
}
|
|
42008
42009
|
}
|
|
42009
42010
|
|
|
42011
|
+
/**
|
|
42012
|
+
* Util function to prevent macros sending event payloads larger than x kilobytes
|
|
42013
|
+
*/
|
|
42014
|
+
function processPayload(payload) {
|
|
42015
|
+
var maxKb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 250;
|
|
42016
|
+
if (Buffer.byteLength(JSON.stringify(payload.event), 'utf8') / 1024 > maxKb) {
|
|
42017
|
+
payload.event;
|
|
42018
|
+
var rest = spirits._objectWithoutProperties(payload, _excluded); // Remove event from payload, too large
|
|
42019
|
+
return rest;
|
|
42020
|
+
} else {
|
|
42021
|
+
return payload;
|
|
42022
|
+
}
|
|
42023
|
+
}
|
|
42024
|
+
|
|
42010
42025
|
/**
|
|
42011
42026
|
* 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
42027
|
* @param {string} prompt
|
|
@@ -42016,6 +42031,57 @@ function did(_x) {
|
|
|
42016
42031
|
return _did.apply(this, arguments);
|
|
42017
42032
|
}
|
|
42018
42033
|
|
|
42034
|
+
/**
|
|
42035
|
+
* 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
|
|
42036
|
+
*
|
|
42037
|
+
* Only use this if you want to evaluate the latest message, otherwise use did() which uses all messages
|
|
42038
|
+
* @param {string} prompt
|
|
42039
|
+
* @param {'customer' | 'agent'} [relation]
|
|
42040
|
+
* @return {Promise<boolean>}
|
|
42041
|
+
*/
|
|
42042
|
+
function _did() {
|
|
42043
|
+
_did = spirits._asyncToGenerator( /*#__PURE__*/spirits._regeneratorRuntime().mark(function _callee(prompt) {
|
|
42044
|
+
var convoId, event, _yield$Scout9Api$did$, value;
|
|
42045
|
+
return spirits._regeneratorRuntime().wrap(function _callee$(_context2) {
|
|
42046
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
42047
|
+
case 0:
|
|
42048
|
+
convoId = MacroGlobals.$convo();
|
|
42049
|
+
event = MacroGlobals.event();
|
|
42050
|
+
event.conversation.$id = convoId;
|
|
42051
|
+
event.conversation.id = convoId;
|
|
42052
|
+
if (convoId) {
|
|
42053
|
+
_context2.next = 6;
|
|
42054
|
+
break;
|
|
42055
|
+
}
|
|
42056
|
+
throw new Error("Internal: Unable to contextualize did response for \"".concat(prompt, "\""));
|
|
42057
|
+
case 6:
|
|
42058
|
+
_context2.next = 8;
|
|
42059
|
+
return new dev.build.Scout9Api(new dev.build.Configuration({
|
|
42060
|
+
apiKey: process.env.SCOUT9_API_KEY
|
|
42061
|
+
})).did(processPayload({
|
|
42062
|
+
prompt: prompt,
|
|
42063
|
+
convoId: convoId,
|
|
42064
|
+
event: event
|
|
42065
|
+
})).then(handleAxiosResponse)["catch"](function (err) {
|
|
42066
|
+
console.error('Error in did macro', err);
|
|
42067
|
+
throw err;
|
|
42068
|
+
});
|
|
42069
|
+
case 8:
|
|
42070
|
+
_yield$Scout9Api$did$ = _context2.sent;
|
|
42071
|
+
value = _yield$Scout9Api$did$.value;
|
|
42072
|
+
return _context2.abrupt("return", value);
|
|
42073
|
+
case 11:
|
|
42074
|
+
case "end":
|
|
42075
|
+
return _context2.stop();
|
|
42076
|
+
}
|
|
42077
|
+
}, _callee);
|
|
42078
|
+
}));
|
|
42079
|
+
return _did.apply(this, arguments);
|
|
42080
|
+
}
|
|
42081
|
+
function does(_x2) {
|
|
42082
|
+
return _does.apply(this, arguments);
|
|
42083
|
+
}
|
|
42084
|
+
|
|
42019
42085
|
/**
|
|
42020
42086
|
* @typedef {import('@scout9/admin').MacroContextInputExamples} ContextExamples
|
|
42021
42087
|
* @typedef {import('@scout9/admin').MacroContextValue} ContextOutput
|
|
@@ -42038,85 +42104,92 @@ function did(_x) {
|
|
|
42038
42104
|
* @param {ContextExamples} [examples] - Examples to the macro to ensure a consistent data structure.
|
|
42039
42105
|
* @return {Promise<ContextOutput>}
|
|
42040
42106
|
*/
|
|
42041
|
-
function
|
|
42042
|
-
|
|
42043
|
-
var
|
|
42044
|
-
|
|
42045
|
-
|
|
42107
|
+
function _does() {
|
|
42108
|
+
_does = spirits._asyncToGenerator( /*#__PURE__*/spirits._regeneratorRuntime().mark(function _callee2(prompt) {
|
|
42109
|
+
var relation,
|
|
42110
|
+
convoId,
|
|
42111
|
+
event,
|
|
42112
|
+
_yield$Scout9Api$does,
|
|
42113
|
+
value,
|
|
42114
|
+
_args2 = arguments;
|
|
42115
|
+
return spirits._regeneratorRuntime().wrap(function _callee2$(_context3) {
|
|
42116
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
42046
42117
|
case 0:
|
|
42118
|
+
relation = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : 'customer';
|
|
42047
42119
|
convoId = MacroGlobals.$convo();
|
|
42048
42120
|
event = MacroGlobals.event();
|
|
42049
42121
|
event.conversation.$id = convoId;
|
|
42050
42122
|
event.conversation.id = convoId;
|
|
42051
42123
|
if (convoId) {
|
|
42052
|
-
|
|
42124
|
+
_context3.next = 7;
|
|
42053
42125
|
break;
|
|
42054
42126
|
}
|
|
42055
|
-
throw new Error("Internal: Unable to contextualize
|
|
42056
|
-
case
|
|
42057
|
-
|
|
42127
|
+
throw new Error("Internal: Unable to contextualize does response for \"".concat(prompt, "\""));
|
|
42128
|
+
case 7:
|
|
42129
|
+
_context3.next = 9;
|
|
42058
42130
|
return new dev.build.Scout9Api(new dev.build.Configuration({
|
|
42059
42131
|
apiKey: process.env.SCOUT9_API_KEY
|
|
42060
|
-
})).
|
|
42132
|
+
})).does(processPayload({
|
|
42061
42133
|
prompt: prompt,
|
|
42062
42134
|
convoId: convoId,
|
|
42135
|
+
role: relation,
|
|
42063
42136
|
event: event
|
|
42064
|
-
}).then(handleAxiosResponse)
|
|
42065
|
-
case 8:
|
|
42066
|
-
_yield$Scout9Api$did$ = _context2.sent["catch"](function (err) {
|
|
42137
|
+
})).then(handleAxiosResponse)["catch"](function (err) {
|
|
42067
42138
|
console.error('Error in did macro', err);
|
|
42068
42139
|
throw err;
|
|
42069
42140
|
});
|
|
42070
|
-
|
|
42071
|
-
|
|
42072
|
-
|
|
42141
|
+
case 9:
|
|
42142
|
+
_yield$Scout9Api$does = _context3.sent;
|
|
42143
|
+
value = _yield$Scout9Api$does.value;
|
|
42144
|
+
return _context3.abrupt("return", value);
|
|
42145
|
+
case 12:
|
|
42073
42146
|
case "end":
|
|
42074
|
-
return
|
|
42147
|
+
return _context3.stop();
|
|
42075
42148
|
}
|
|
42076
|
-
},
|
|
42149
|
+
}, _callee2);
|
|
42077
42150
|
}));
|
|
42078
|
-
return
|
|
42151
|
+
return _does.apply(this, arguments);
|
|
42079
42152
|
}
|
|
42080
|
-
function context(
|
|
42153
|
+
function context(_x3, _x4) {
|
|
42081
42154
|
return _context.apply(this, arguments);
|
|
42082
42155
|
}
|
|
42083
42156
|
function _context() {
|
|
42084
|
-
_context = spirits._asyncToGenerator( /*#__PURE__*/spirits._regeneratorRuntime().mark(function
|
|
42157
|
+
_context = spirits._asyncToGenerator( /*#__PURE__*/spirits._regeneratorRuntime().mark(function _callee3(prompt, examples) {
|
|
42085
42158
|
var convoId, event, _yield$Scout9Api$capt, value;
|
|
42086
|
-
return spirits._regeneratorRuntime().wrap(function
|
|
42087
|
-
while (1) switch (
|
|
42159
|
+
return spirits._regeneratorRuntime().wrap(function _callee3$(_context4) {
|
|
42160
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
42088
42161
|
case 0:
|
|
42089
42162
|
convoId = MacroGlobals.$convo();
|
|
42090
42163
|
event = MacroGlobals.event();
|
|
42091
42164
|
event.conversation.$id = convoId;
|
|
42092
42165
|
event.conversation.id = convoId;
|
|
42093
42166
|
if (convoId) {
|
|
42094
|
-
|
|
42167
|
+
_context4.next = 6;
|
|
42095
42168
|
break;
|
|
42096
42169
|
}
|
|
42097
42170
|
throw new Error("Internal: Unable to contextualize did response for \"".concat(prompt, "\""));
|
|
42098
42171
|
case 6:
|
|
42099
|
-
|
|
42172
|
+
_context4.next = 8;
|
|
42100
42173
|
return new dev.build.Scout9Api(new dev.build.Configuration({
|
|
42101
42174
|
apiKey: process.env.SCOUT9_API_KEY
|
|
42102
|
-
})).captureContext({
|
|
42175
|
+
})).captureContext(processPayload({
|
|
42103
42176
|
prompt: prompt,
|
|
42104
42177
|
examples: examples,
|
|
42105
42178
|
convoId: convoId,
|
|
42106
42179
|
event: event
|
|
42107
|
-
}).then(handleAxiosResponse)
|
|
42108
|
-
case 8:
|
|
42109
|
-
_yield$Scout9Api$capt = _context3.sent["catch"](function (err) {
|
|
42180
|
+
})).then(handleAxiosResponse)["catch"](function (err) {
|
|
42110
42181
|
console.error('Error in context macro', err);
|
|
42111
42182
|
throw err;
|
|
42112
42183
|
});
|
|
42184
|
+
case 8:
|
|
42185
|
+
_yield$Scout9Api$capt = _context4.sent;
|
|
42113
42186
|
value = _yield$Scout9Api$capt.value;
|
|
42114
|
-
return
|
|
42187
|
+
return _context4.abrupt("return", value);
|
|
42115
42188
|
case 11:
|
|
42116
42189
|
case "end":
|
|
42117
|
-
return
|
|
42190
|
+
return _context4.stop();
|
|
42118
42191
|
}
|
|
42119
|
-
},
|
|
42192
|
+
}, _callee3);
|
|
42120
42193
|
}));
|
|
42121
42194
|
return _context.apply(this, arguments);
|
|
42122
42195
|
}
|
|
@@ -43115,7 +43188,7 @@ var ProjectFiles = /*#__PURE__*/function () {
|
|
|
43115
43188
|
return ProjectFiles;
|
|
43116
43189
|
}();
|
|
43117
43190
|
|
|
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-
|
|
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)));
|
|
43119
43192
|
var __dirname$1 = path__default["default"].dirname(__filename$1);
|
|
43120
43193
|
function zipDirectory(source, out) {
|
|
43121
43194
|
var archive = archiver$1('tar', {
|
|
@@ -43330,7 +43403,7 @@ function _buildApp() {
|
|
|
43330
43403
|
case 11:
|
|
43331
43404
|
_context4.t0 = JSON;
|
|
43332
43405
|
_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-
|
|
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');
|
|
43334
43407
|
case 14:
|
|
43335
43408
|
_context4.t1 = _context4.sent;
|
|
43336
43409
|
packageTemplate = _context4.t0.parse.call(_context4.t0, _context4.t1);
|
|
@@ -44553,6 +44626,7 @@ exports.File = File;
|
|
|
44553
44626
|
exports.FormData = FormData;
|
|
44554
44627
|
exports.context = context;
|
|
44555
44628
|
exports.did = did;
|
|
44629
|
+
exports.does = does;
|
|
44556
44630
|
exports.json = json;
|
|
44557
44631
|
exports.run = run;
|
|
44558
44632
|
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-d60f8919.cjs");
|
|
6
|
+
var dev = require("./dev-89d0d9da.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;
|
|
@@ -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-d60f8919.cjs");
|
|
6
6
|
require("./spirits-5c9243a1.cjs");
|
|
7
|
-
require("./dev-
|
|
7
|
+
require("./dev-89d0d9da.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.2",
|
|
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,16 +41,49 @@ 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
|
-
})
|
|
36
|
-
.then(handleAxiosResponse)
|
|
48
|
+
}))
|
|
49
|
+
.then(handleAxiosResponse)
|
|
37
50
|
.catch((err) => {
|
|
38
51
|
console.error('Error in did macro', err);
|
|
39
52
|
throw err;
|
|
40
|
-
});
|
|
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
|
+
)
|
|
82
|
+
.then(handleAxiosResponse)
|
|
83
|
+
.catch((err) => {
|
|
84
|
+
console.error('Error in did macro', err);
|
|
85
|
+
throw err;
|
|
86
|
+
}));
|
|
41
87
|
return value;
|
|
42
88
|
}
|
|
43
89
|
|
|
@@ -71,16 +117,17 @@ 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
|
-
|
|
80
|
-
|
|
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
|
+
}))
|
|
127
|
+
.then(handleAxiosResponse)
|
|
81
128
|
.catch((err) => {
|
|
82
129
|
console.error('Error in context macro', err);
|
|
83
130
|
throw err;
|
|
84
|
-
});
|
|
131
|
+
}));
|
|
85
132
|
return value;
|
|
86
133
|
}
|