@scout9/app 1.0.0-alpha.0.4.3 → 1.0.0-alpha.0.4.5
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/dist/{dev-195686a8.cjs → dev-c50734b5.cjs} +83 -2
- package/dist/{index-ec0cd08d.cjs → index-e34c4224.cjs} +5 -5
- package/dist/index.cjs +2 -2
- package/dist/{multipart-parser-a2f207ea.cjs → multipart-parser-cb97a19f.cjs} +2 -2
- package/dist/testing-tools.cjs +1 -1
- package/package.json +1 -1
- package/src/runtime/macros/event.js +72 -0
- package/src/runtime/macros/globals.js +9 -0
|
@@ -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-c50734b5.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);
|
|
@@ -35787,14 +35787,25 @@ var MacroGlobals = /*#__PURE__*/function () {
|
|
|
35787
35787
|
}
|
|
35788
35788
|
spirits._createClass(MacroGlobals, null, [{
|
|
35789
35789
|
key: "$convo",
|
|
35790
|
-
value:
|
|
35790
|
+
value:
|
|
35791
|
+
/**
|
|
35792
|
+
* @returns {string}
|
|
35793
|
+
*/
|
|
35794
|
+
function $convo() {
|
|
35791
35795
|
var _globalThis$SCOUT;
|
|
35792
35796
|
var $convo = globalThis === null || globalThis === void 0 || (_globalThis$SCOUT = globalThis.SCOUT9) === null || _globalThis$SCOUT === void 0 ? void 0 : _globalThis$SCOUT.$convo;
|
|
35793
35797
|
if (!$convo) {
|
|
35794
35798
|
throw new Error("$convo not found in runtime context, ".concat(spirits._classStaticPrivateFieldSpecGet(MacroGlobals, MacroGlobals, _hint)));
|
|
35795
35799
|
}
|
|
35800
|
+
if (typeof $convo !== 'string') {
|
|
35801
|
+
throw new Error("$convo not a type string, $convo=".concat(JSON.stringify($convo)));
|
|
35802
|
+
}
|
|
35796
35803
|
return $convo;
|
|
35797
35804
|
}
|
|
35805
|
+
|
|
35806
|
+
/**
|
|
35807
|
+
* @returns {WorkflowEvent}
|
|
35808
|
+
*/
|
|
35798
35809
|
}, {
|
|
35799
35810
|
key: "event",
|
|
35800
35811
|
value: function event() {
|
|
@@ -35872,18 +35883,41 @@ var _excluded$1 = ["success"];
|
|
|
35872
35883
|
* @property {WorkflowResponseSlotBaseWithKeywords[]} withoutCondition.instruction - Array of slots with keywords.
|
|
35873
35884
|
*/
|
|
35874
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
|
+
|
|
35875
35903
|
/**
|
|
35876
35904
|
* Event macros to be used inside your scout9 auto reply workflows
|
|
35877
35905
|
* @typedef {Object} EventMacros
|
|
35878
35906
|
* @property {function(Record<string, any>): EventMacros} upsert
|
|
35879
35907
|
* @property {function(string, (Date | string | OptionsFollowup)): EventMacros} followup
|
|
35880
35908
|
* @property {AnticipateFunction} anticipate
|
|
35909
|
+
* @property {function(): EventMacros} resetIntent
|
|
35910
|
+
* @property {function(string | string[], boolean?): EventMacros} instructRemove
|
|
35911
|
+
* @property {function(string, (OptionsInstruct & OptionsForward & {stagnationLimit?: number})?): EventMacros} instructSafe
|
|
35881
35912
|
* @property {function(string, OptionsInstruct?): EventMacros} instruct
|
|
35882
35913
|
* @property {function(string, OptionsReply?): EventMacros} reply
|
|
35883
35914
|
* @property {function(string?, OptionsForward?): EventMacros} forward
|
|
35884
35915
|
* @property {function(boolean?): Array<WorkflowResponseSlot>} toJSON
|
|
35885
35916
|
*/
|
|
35886
35917
|
function EventMacrosFactory() {
|
|
35918
|
+
/**
|
|
35919
|
+
* @type {Array<WorkflowResponseSlot>}
|
|
35920
|
+
*/
|
|
35887
35921
|
var slots = [];
|
|
35888
35922
|
return {
|
|
35889
35923
|
/**
|
|
@@ -36025,6 +36059,53 @@ function EventMacrosFactory() {
|
|
|
36025
36059
|
}
|
|
36026
36060
|
return this;
|
|
36027
36061
|
},
|
|
36062
|
+
resetIntent: function resetIntent() {
|
|
36063
|
+
/** @type {WorkflowResponseSlot} */
|
|
36064
|
+
var slot = {
|
|
36065
|
+
resetIntent: true
|
|
36066
|
+
};
|
|
36067
|
+
try {
|
|
36068
|
+
slots.push(macros.WorkflowResponseSlotSchema.parse(slot));
|
|
36069
|
+
} catch (e) {
|
|
36070
|
+
throw simplifyError(e, 'Invalid instruct() input');
|
|
36071
|
+
}
|
|
36072
|
+
return this;
|
|
36073
|
+
},
|
|
36074
|
+
/**
|
|
36075
|
+
* Removes an instruction from the system
|
|
36076
|
+
* @param {string | string[]} idOrIds - the instruction ids to remove
|
|
36077
|
+
* @param {boolean} [strict] - if true, throw error if no id exists
|
|
36078
|
+
*/
|
|
36079
|
+
instructRemove: function instructRemove(idOrIds) {
|
|
36080
|
+
var strict = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
36081
|
+
/** @type {WorkflowResponseSlot} */
|
|
36082
|
+
var slot = {};
|
|
36083
|
+
var ids = Array.isArray(idOrIds) ? idOrIds : typeof idOrIds === 'string' ? [idOrIds] : [];
|
|
36084
|
+
if (!ids.length) {
|
|
36085
|
+
throw new Error("Given an empty or invalid value for instructRemove, given: ".concat(JSON.stringify(idOrIds), ", expect a type string or type Array<string>"));
|
|
36086
|
+
}
|
|
36087
|
+
var event = MacroGlobals.event(); // Check the event to eval ids to remove
|
|
36088
|
+
ids.forEach(function (id) {
|
|
36089
|
+
var message = event.messages.find(function (m) {
|
|
36090
|
+
return m.id === id;
|
|
36091
|
+
});
|
|
36092
|
+
if (!message) {
|
|
36093
|
+
var msg = "Cannot remove \"".concat(id, "\", no instruction found");
|
|
36094
|
+
if (strict) {
|
|
36095
|
+
throw new Error(msg);
|
|
36096
|
+
} else {
|
|
36097
|
+
console.warn(msg);
|
|
36098
|
+
}
|
|
36099
|
+
}
|
|
36100
|
+
});
|
|
36101
|
+
slot.removeInstructions = ids;
|
|
36102
|
+
try {
|
|
36103
|
+
slots.push(macros.WorkflowResponseSlotSchema.parse(slot));
|
|
36104
|
+
} catch (e) {
|
|
36105
|
+
throw simplifyError(e, 'Invalid instruct() input');
|
|
36106
|
+
}
|
|
36107
|
+
return this;
|
|
36108
|
+
},
|
|
36028
36109
|
/**
|
|
36029
36110
|
* If conversation is not stagnant, return instructions to guide next auto reply response, otherwise it will forward the conversation
|
|
36030
36111
|
* @param {string} instruction
|
|
@@ -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-c50734b5.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-cb97a19f.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-e34c4224.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);
|
|
@@ -43157,7 +43157,7 @@ var ProjectFiles = /*#__PURE__*/function () {
|
|
|
43157
43157
|
return ProjectFiles;
|
|
43158
43158
|
}();
|
|
43159
43159
|
|
|
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-
|
|
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-e34c4224.js', document.baseURI).href)));
|
|
43161
43161
|
var __dirname$1 = path__default["default"].dirname(__filename$1);
|
|
43162
43162
|
function zipDirectory(source, out) {
|
|
43163
43163
|
var archive = archiver$1('tar', {
|
|
@@ -43372,7 +43372,7 @@ function _buildApp() {
|
|
|
43372
43372
|
case 11:
|
|
43373
43373
|
_context4.t0 = JSON;
|
|
43374
43374
|
_context4.next = 14;
|
|
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-
|
|
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-e34c4224.js', document.baseURI).href))), 'utf-8');
|
|
43376
43376
|
case 14:
|
|
43377
43377
|
_context4.t1 = _context4.sent;
|
|
43378
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-
|
|
6
|
-
var dev = require("./dev-
|
|
5
|
+
var index = require("./index-e34c4224.cjs");
|
|
6
|
+
var dev = require("./dev-c50734b5.cjs");
|
|
7
7
|
require("./spirits-5c9243a1.cjs");
|
|
8
8
|
require("./macros-e4105c56.cjs");
|
|
9
9
|
require('fs');
|
|
@@ -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-e34c4224.cjs");
|
|
6
6
|
require("./spirits-5c9243a1.cjs");
|
|
7
|
-
require("./dev-
|
|
7
|
+
require("./dev-c50734b5.cjs");
|
|
8
8
|
require('util');
|
|
9
9
|
require('stream');
|
|
10
10
|
require('path');
|
package/dist/testing-tools.cjs
CHANGED
package/package.json
CHANGED
|
@@ -62,12 +62,33 @@ import MacroGlobals from './globals.js';
|
|
|
62
62
|
* @property {WorkflowResponseSlotBaseWithKeywords[]} withoutCondition.instruction - Array of slots with keywords.
|
|
63
63
|
*/
|
|
64
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
|
+
|
|
65
83
|
/**
|
|
66
84
|
* Event macros to be used inside your scout9 auto reply workflows
|
|
67
85
|
* @typedef {Object} EventMacros
|
|
68
86
|
* @property {function(Record<string, any>): EventMacros} upsert
|
|
69
87
|
* @property {function(string, (Date | string | OptionsFollowup)): EventMacros} followup
|
|
70
88
|
* @property {AnticipateFunction} anticipate
|
|
89
|
+
* @property {function(): EventMacros} resetIntent
|
|
90
|
+
* @property {function(string | string[], boolean?): EventMacros} instructRemove
|
|
91
|
+
* @property {function(string, (OptionsInstruct & OptionsForward & {stagnationLimit?: number})?): EventMacros} instructSafe
|
|
71
92
|
* @property {function(string, OptionsInstruct?): EventMacros} instruct
|
|
72
93
|
* @property {function(string, OptionsReply?): EventMacros} reply
|
|
73
94
|
* @property {function(string?, OptionsForward?): EventMacros} forward
|
|
@@ -75,6 +96,9 @@ import MacroGlobals from './globals.js';
|
|
|
75
96
|
*/
|
|
76
97
|
function EventMacrosFactory() {
|
|
77
98
|
|
|
99
|
+
/**
|
|
100
|
+
* @type {Array<WorkflowResponseSlot>}
|
|
101
|
+
*/
|
|
78
102
|
let slots = [];
|
|
79
103
|
|
|
80
104
|
return {
|
|
@@ -215,6 +239,50 @@ function EventMacrosFactory() {
|
|
|
215
239
|
return this;
|
|
216
240
|
},
|
|
217
241
|
|
|
242
|
+
resetIntent() {
|
|
243
|
+
/** @type {WorkflowResponseSlot} */
|
|
244
|
+
const slot = {resetIntent: true};
|
|
245
|
+
try {
|
|
246
|
+
slots.push(WorkflowResponseSlotSchema.parse(slot));
|
|
247
|
+
} catch (e) {
|
|
248
|
+
throw simplifyError(e, 'Invalid instruct() input');
|
|
249
|
+
}
|
|
250
|
+
return this;
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Removes an instruction from the system
|
|
255
|
+
* @param {string | string[]} idOrIds - the instruction ids to remove
|
|
256
|
+
* @param {boolean} [strict] - if true, throw error if no id exists
|
|
257
|
+
*/
|
|
258
|
+
instructRemove(idOrIds, strict = false) {
|
|
259
|
+
/** @type {WorkflowResponseSlot} */
|
|
260
|
+
const slot = {};
|
|
261
|
+
const ids = Array.isArray(idOrIds) ? idOrIds : typeof idOrIds === 'string' ? [idOrIds] : [];
|
|
262
|
+
if (!ids.length) {
|
|
263
|
+
throw new Error(`Given an empty or invalid value for instructRemove, given: ${JSON.stringify(idOrIds)}, expect a type string or type Array<string>`);
|
|
264
|
+
}
|
|
265
|
+
const event = MacroGlobals.event(); // Check the event to eval ids to remove
|
|
266
|
+
ids.forEach((id) => {
|
|
267
|
+
const message = event.messages.find(m => m.id === id);
|
|
268
|
+
if (!message) {
|
|
269
|
+
const msg = `Cannot remove "${id}", no instruction found`;
|
|
270
|
+
if (strict) {
|
|
271
|
+
throw new Error(msg);
|
|
272
|
+
} else {
|
|
273
|
+
console.warn(msg);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
slot.removeInstructions = ids;
|
|
278
|
+
try {
|
|
279
|
+
slots.push(WorkflowResponseSlotSchema.parse(slot));
|
|
280
|
+
} catch (e) {
|
|
281
|
+
throw simplifyError(e, 'Invalid instruct() input');
|
|
282
|
+
}
|
|
283
|
+
return this;
|
|
284
|
+
},
|
|
285
|
+
|
|
218
286
|
/**
|
|
219
287
|
* If conversation is not stagnant, return instructions to guide next auto reply response, otherwise it will forward the conversation
|
|
220
288
|
* @param {string} instruction
|
|
@@ -231,6 +299,7 @@ function EventMacrosFactory() {
|
|
|
231
299
|
}
|
|
232
300
|
},
|
|
233
301
|
|
|
302
|
+
|
|
234
303
|
/**
|
|
235
304
|
* Return instructions to guide next auto reply response
|
|
236
305
|
* @param {string} instruction
|
|
@@ -260,6 +329,7 @@ function EventMacrosFactory() {
|
|
|
260
329
|
}
|
|
261
330
|
return this;
|
|
262
331
|
},
|
|
332
|
+
|
|
263
333
|
/**
|
|
264
334
|
* If a manual message must be sent, you can use the `reply` macro
|
|
265
335
|
* @param {string} message - the message to manually send to the user
|
|
@@ -289,6 +359,7 @@ function EventMacrosFactory() {
|
|
|
289
359
|
}
|
|
290
360
|
return this;
|
|
291
361
|
},
|
|
362
|
+
|
|
292
363
|
/**
|
|
293
364
|
* This macro ends the conversation and forwards it the owner of the persona to manually handle the flow. If your app returns undefined or no event, then a default forward is generated.
|
|
294
365
|
* @param {string} [message] - the message to forward to owner of persona
|
|
@@ -324,6 +395,7 @@ function EventMacrosFactory() {
|
|
|
324
395
|
}
|
|
325
396
|
return this;
|
|
326
397
|
},
|
|
398
|
+
|
|
327
399
|
/**
|
|
328
400
|
* Returns event payload
|
|
329
401
|
* @param {boolean} flush - if true, will reset the data payload
|
|
@@ -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) {
|