@scout9/app 1.0.0-alpha.0.6.4 → 1.0.0-alpha.0.6.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-fee40f1c.cjs → dev-6e60a643.cjs} +3 -3
- package/dist/{index-b59a82b2.cjs → index-bf3ce1b6.cjs} +7 -7
- package/dist/index.cjs +4 -4
- package/dist/{macros-a37c4a77.cjs → macros-1a4fd407.cjs} +7 -1
- package/dist/{multipart-parser-06b501ee.cjs → multipart-parser-13478cb7.cjs} +4 -4
- package/dist/schemas.cjs +1 -1
- package/dist/{spirits-e626085b.cjs → spirits-985e6711.cjs} +112 -106
- package/dist/spirits.cjs +1 -1
- package/dist/testing-tools.cjs +3 -3
- package/package.json +1 -1
- package/src/public.d.ts +77 -1
- package/src/runtime/schemas/message.js +3 -1
- package/src/testing-tools/spirits.js +9 -1
- package/types/index.d.ts +228 -6
- package/types/index.d.ts.map +3 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var spirits = require("./spirits-
|
|
3
|
+
var spirits = require("./spirits-985e6711.cjs");
|
|
4
4
|
var require$$0$4 = require('util');
|
|
5
5
|
var require$$0$3 = require('stream');
|
|
6
6
|
var require$$1 = require('path');
|
|
@@ -21,7 +21,7 @@ var node_url = require('node:url');
|
|
|
21
21
|
var node_events = require('node:events');
|
|
22
22
|
var Stream = require('node:stream');
|
|
23
23
|
var node_string_decoder = require('node:string_decoder');
|
|
24
|
-
var macros = require("./macros-
|
|
24
|
+
var macros = require("./macros-1a4fd407.cjs");
|
|
25
25
|
var readline = require('node:readline');
|
|
26
26
|
var process$2 = require('node:process');
|
|
27
27
|
var node_os = require('node:os');
|
|
@@ -35241,7 +35241,7 @@ function _loadUserPackageJson() {
|
|
|
35241
35241
|
targetPkgUrl = isTest ? packageTestJsonUrl : packageJsonUrl;
|
|
35242
35242
|
_context2.t0 = JSON;
|
|
35243
35243
|
_context2.next = 10;
|
|
35244
|
-
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-
|
|
35244
|
+
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-6e60a643.js', document.baseURI).href))), 'utf-8');
|
|
35245
35245
|
case 10:
|
|
35246
35246
|
_context2.t1 = _context2.sent;
|
|
35247
35247
|
pkg = _context2.t0.parse.call(_context2.t0, _context2.t1);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var spirits = require("./spirits-
|
|
4
|
-
var dev = require("./dev-
|
|
5
|
-
var macros = require("./macros-
|
|
3
|
+
var spirits = require("./spirits-985e6711.cjs");
|
|
4
|
+
var dev = require("./dev-6e60a643.cjs");
|
|
5
|
+
var macros = require("./macros-1a4fd407.cjs");
|
|
6
6
|
var require$$0 = require('fs');
|
|
7
7
|
var require$$2$1 = require('events');
|
|
8
8
|
var require$$1 = require('path');
|
|
@@ -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-13478cb7.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-bf3ce1b6.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);
|
|
@@ -43176,7 +43176,7 @@ var ProjectFiles = /*#__PURE__*/function () {
|
|
|
43176
43176
|
return ProjectFiles;
|
|
43177
43177
|
}();
|
|
43178
43178
|
|
|
43179
|
-
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-
|
|
43179
|
+
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-bf3ce1b6.js', document.baseURI).href)));
|
|
43180
43180
|
var __dirname$1 = path__default["default"].dirname(__filename$1);
|
|
43181
43181
|
function zipDirectory(source, out) {
|
|
43182
43182
|
var archive = archiver$1('tar', {
|
|
@@ -43391,7 +43391,7 @@ function _buildApp() {
|
|
|
43391
43391
|
case 11:
|
|
43392
43392
|
_context4.t0 = JSON;
|
|
43393
43393
|
_context4.next = 14;
|
|
43394
|
-
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-
|
|
43394
|
+
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-bf3ce1b6.js', document.baseURI).href))), 'utf-8');
|
|
43395
43395
|
case 14:
|
|
43396
43396
|
_context4.t1 = _context4.sent;
|
|
43397
43397
|
packageTemplate = _context4.t0.parse.call(_context4.t0, _context4.t1);
|
package/dist/index.cjs
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require("./index-
|
|
6
|
-
var dev = require("./dev-
|
|
7
|
-
require("./spirits-
|
|
8
|
-
require("./macros-
|
|
5
|
+
var index = require("./index-bf3ce1b6.cjs");
|
|
6
|
+
var dev = require("./dev-6e60a643.cjs");
|
|
7
|
+
require("./spirits-985e6711.cjs");
|
|
8
|
+
require("./macros-1a4fd407.cjs");
|
|
9
9
|
require('fs');
|
|
10
10
|
require('events');
|
|
11
11
|
require('path');
|
|
@@ -4047,7 +4047,13 @@ var MessageSchema = z.object({
|
|
|
4047
4047
|
delayInSeconds: z.number({
|
|
4048
4048
|
description: 'How long to delay the message manually in seconds'
|
|
4049
4049
|
}).nullable().optional(),
|
|
4050
|
-
entities: z.array(MessageEntitySchema).optional().nullable()
|
|
4050
|
+
entities: z.array(MessageEntitySchema).optional().nullable(),
|
|
4051
|
+
ignoreTransform: z["boolean"]({
|
|
4052
|
+
description: 'If set to true, the PMT will not transform, message will be sent as is'
|
|
4053
|
+
}).optional(),
|
|
4054
|
+
mediaUrls: z.array(z.string(), {
|
|
4055
|
+
description: 'Media urls to attach to the transported message'
|
|
4056
|
+
}).optional().nullable()
|
|
4051
4057
|
});
|
|
4052
4058
|
|
|
4053
4059
|
var CustomerValueSchema = z.union([z["boolean"](), z.number(), z.string()]);
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
require('node:fs');
|
|
4
4
|
require('node:path');
|
|
5
|
-
var index = require("./index-
|
|
6
|
-
require("./spirits-
|
|
7
|
-
require("./dev-
|
|
5
|
+
var index = require("./index-bf3ce1b6.cjs");
|
|
6
|
+
require("./spirits-985e6711.cjs");
|
|
7
|
+
require("./dev-6e60a643.cjs");
|
|
8
8
|
require('util');
|
|
9
9
|
require('stream');
|
|
10
10
|
require('path');
|
|
@@ -23,7 +23,7 @@ require('node:url');
|
|
|
23
23
|
require('node:events');
|
|
24
24
|
require('node:stream');
|
|
25
25
|
require('node:string_decoder');
|
|
26
|
-
require("./macros-
|
|
26
|
+
require("./macros-1a4fd407.cjs");
|
|
27
27
|
require('node:readline');
|
|
28
28
|
require('node:process');
|
|
29
29
|
require('node:os');
|
package/dist/schemas.cjs
CHANGED
|
@@ -730,6 +730,7 @@ var _excluded = ["keywords"];
|
|
|
730
730
|
* @property {Change<any>} context
|
|
731
731
|
* @property {Change<import('@scout9/app').Message>} message
|
|
732
732
|
* @property {Array<import('@scout9/app').Followup>} followup
|
|
733
|
+
* @property {Array<import('@scout9/app').EntityContextUpsert>} entityContextUpsert
|
|
733
734
|
*/
|
|
734
735
|
var Spirits = {
|
|
735
736
|
/**
|
|
@@ -740,13 +741,14 @@ var Spirits = {
|
|
|
740
741
|
customer: function () {
|
|
741
742
|
var _customer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
|
|
742
743
|
var _recentUserMessage;
|
|
743
|
-
var customer, config, parser, workflow, generator, transformer, idGenerator, _input$progress, progress, messageBefore, contextBefore, messagesBefore, conversationBefore, conversation, messages, context, message, followup, updateConversation, updateContext, userMessages, recentUserMessage, lockConversation, incrementLockAttempt, _addInstruction, addInstruction, persona, invalidRoles, parsePayload, index, _message, previousUserMessages, oldKeyCount, newKeyCount, noNewContext, slots, hasNoInstructions, hasNoCustomMessage, messagesToTransform, previousLockAttempt, resettedIntent, _forward, _forwardNote, _iterator, _step, _step$value, forward, forwardNote, instructions, removeInstructions, manualMessage, scheduled, resetIntent, secondsDelay, contextUpsert, anticipate, slotFollowup, _slots, map, i, _anticipate$i, keywords, _slot, slotId, _iterator3, _step3, instruction, _iterator4, _step4, _loop, manualMessageObj, now, generatorPayload, agentMessages, lastAgentMessage, _generatorPayload$ent, _generatorPayload$con, _iterator2, _step2, transformResponse, _agentMessages, _lastAgentMessage;
|
|
744
|
+
var customer, config, parser, workflow, generator, transformer, idGenerator, _input$progress, progress, messageBefore, contextBefore, messagesBefore, conversationBefore, conversation, messages, context, message, followup, entityContextUpsert, updateConversation, updateContext, userMessages, recentUserMessage, lockConversation, incrementLockAttempt, _addInstruction, addInstruction, persona, invalidRoles, parsePayload, index, _message, previousUserMessages, oldKeyCount, newKeyCount, noNewContext, slots, hasNoInstructions, hasNoCustomMessage, messagesToTransform, previousLockAttempt, resettedIntent, _forward, _forwardNote, _iterator, _step, _step$value, forward, forwardNote, instructions, removeInstructions, manualMessage, scheduled, resetIntent, secondsDelay, contextUpsert, anticipate, slotFollowup, slotEntityContextUpsert, _slots, map, i, _anticipate$i, keywords, _slot, slotId, _iterator3, _step3, instruction, _iterator4, _step4, _loop, manualMessageObj, now, generatorPayload, agentMessages, lastAgentMessage, _generatorPayload$ent, _generatorPayload$con, _iterator2, _step2, transformResponse, _agentMessages, _lastAgentMessage;
|
|
744
745
|
return _regeneratorRuntime().wrap(function _callee$(_context2) {
|
|
745
746
|
while (1) switch (_context2.prev = _context2.next) {
|
|
746
747
|
case 0:
|
|
747
748
|
customer = input.customer, config = input.config, parser = input.parser, workflow = input.workflow, generator = input.generator, transformer = input.transformer, idGenerator = input.idGenerator, _input$progress = input.progress, progress = _input$progress === void 0 ? function (message, level, type, payload) {} : _input$progress, messageBefore = input.message, contextBefore = input.context, messagesBefore = input.messages, conversationBefore = input.conversation;
|
|
748
749
|
conversation = input.conversation, messages = input.messages, context = input.context, message = input.message;
|
|
749
|
-
followup = [];
|
|
750
|
+
followup = [];
|
|
751
|
+
entityContextUpsert = []; // 0. Setup Helpers
|
|
750
752
|
updateConversation = function updateConversation(previousConversation, conversationUpdates) {
|
|
751
753
|
progress('Update conversation', 'info', 'UPDATE_CONVERSATION', conversationUpdates);
|
|
752
754
|
return _objectSpread2(_objectSpread2({}, previousConversation), conversationUpdates);
|
|
@@ -835,40 +837,40 @@ var Spirits = {
|
|
|
835
837
|
}
|
|
836
838
|
}; // 1. Check inputs
|
|
837
839
|
if (conversation.$agent) {
|
|
838
|
-
_context2.next =
|
|
840
|
+
_context2.next = 14;
|
|
839
841
|
break;
|
|
840
842
|
}
|
|
841
843
|
throw new Error("SpiritsError: No agent found in conversation, must define \".$agent\" in the conversation");
|
|
842
|
-
case
|
|
844
|
+
case 14:
|
|
843
845
|
persona = (config.persona || config.personas || config.agents).find(function (p) {
|
|
844
846
|
return p.id === conversation.$agent;
|
|
845
847
|
});
|
|
846
848
|
if (persona) {
|
|
847
|
-
_context2.next =
|
|
849
|
+
_context2.next = 19;
|
|
848
850
|
break;
|
|
849
851
|
}
|
|
850
852
|
if (!(config.persona || config.personas || config.agents).some(function (a) {
|
|
851
853
|
return !a.id;
|
|
852
854
|
})) {
|
|
853
|
-
_context2.next =
|
|
855
|
+
_context2.next = 18;
|
|
854
856
|
break;
|
|
855
857
|
}
|
|
856
858
|
throw new Error("SpiritsError: No persona found (\"".concat(conversation.$agent, "\") in provided config, some persona's did not contain an \"id\" (Internal Mapping Error)"));
|
|
857
|
-
case 17:
|
|
858
|
-
throw new Error("SpiritsError: No persona found (\"".concat(conversation.$agent, "\") in provided config"));
|
|
859
859
|
case 18:
|
|
860
|
+
throw new Error("SpiritsError: No persona found (\"".concat(conversation.$agent, "\") in provided config"));
|
|
861
|
+
case 19:
|
|
860
862
|
if (messages.every(function (m) {
|
|
861
863
|
return !!m.id;
|
|
862
864
|
})) {
|
|
863
|
-
_context2.next =
|
|
865
|
+
_context2.next = 21;
|
|
864
866
|
break;
|
|
865
867
|
}
|
|
866
868
|
throw new Error("SpiritsError: Every message must have an \".id\", ensure all messages have an id assigned before running");
|
|
867
|
-
case
|
|
869
|
+
case 21:
|
|
868
870
|
if (messages.every(function (m) {
|
|
869
871
|
return m.role === 'customer' || m.role === 'agent' || m.role === 'system';
|
|
870
872
|
})) {
|
|
871
|
-
_context2.next =
|
|
873
|
+
_context2.next = 24;
|
|
872
874
|
break;
|
|
873
875
|
}
|
|
874
876
|
invalidRoles = messages.filter(function (m) {
|
|
@@ -877,7 +879,7 @@ var Spirits = {
|
|
|
877
879
|
throw new Error("SpiritsError: Every message must have a role of \"customer\", \"agent\", or \"system\". Got invalid roles: ".concat(invalidRoles.map(function (m) {
|
|
878
880
|
return m.role;
|
|
879
881
|
}).join(', ')));
|
|
880
|
-
case
|
|
882
|
+
case 24:
|
|
881
883
|
// if message is not in messages, then add it
|
|
882
884
|
if (!messages.find(function (m) {
|
|
883
885
|
return m.id === input.message.id;
|
|
@@ -887,9 +889,9 @@ var Spirits = {
|
|
|
887
889
|
|
|
888
890
|
// 2. Parse the message
|
|
889
891
|
progress('Parsing message', 'info', 'SET_PROCESSING', 'user');
|
|
890
|
-
_context2.next =
|
|
892
|
+
_context2.next = 28;
|
|
891
893
|
return parser(message.content, 'en');
|
|
892
|
-
case
|
|
894
|
+
case 28:
|
|
893
895
|
parsePayload = _context2.sent;
|
|
894
896
|
if (parsePayload.intent) {
|
|
895
897
|
message.intent = parsePayload.intent;
|
|
@@ -960,7 +962,7 @@ var Spirits = {
|
|
|
960
962
|
}
|
|
961
963
|
noNewContext = Object.keys(parsePayload.context).length === 0; // 3. Run the workflow
|
|
962
964
|
progress('Running workflow', 'info', 'SET_PROCESSING', 'system');
|
|
963
|
-
_context2.next =
|
|
965
|
+
_context2.next = 45;
|
|
964
966
|
return workflow({
|
|
965
967
|
messages: messages,
|
|
966
968
|
conversation: conversation,
|
|
@@ -989,7 +991,7 @@ var Spirits = {
|
|
|
989
991
|
return accumulator;
|
|
990
992
|
}, []);
|
|
991
993
|
});
|
|
992
|
-
case
|
|
994
|
+
case 45:
|
|
993
995
|
slots = _context2.sent;
|
|
994
996
|
hasNoInstructions = slots.every(function (s) {
|
|
995
997
|
return !s.instructions || Array.isArray(s.instructions) && s.instructions.length === 0;
|
|
@@ -1015,20 +1017,20 @@ var Spirits = {
|
|
|
1015
1017
|
}
|
|
1016
1018
|
resettedIntent = false;
|
|
1017
1019
|
_iterator = _createForOfIteratorHelper(slots);
|
|
1018
|
-
_context2.prev =
|
|
1020
|
+
_context2.prev = 53;
|
|
1019
1021
|
_iterator.s();
|
|
1020
|
-
case
|
|
1022
|
+
case 55:
|
|
1021
1023
|
if ((_step = _iterator.n()).done) {
|
|
1022
|
-
_context2.next =
|
|
1024
|
+
_context2.next = 116;
|
|
1023
1025
|
break;
|
|
1024
1026
|
}
|
|
1025
|
-
_step$value = _step.value, forward = _step$value.forward, forwardNote = _step$value.forwardNote, instructions = _step$value.instructions, removeInstructions = _step$value.removeInstructions, manualMessage = _step$value.message, scheduled = _step$value.scheduled, resetIntent = _step$value.resetIntent, secondsDelay = _step$value.secondsDelay, contextUpsert = _step$value.contextUpsert, anticipate = _step$value.anticipate, slotFollowup = _step$value.followup;
|
|
1027
|
+
_step$value = _step.value, forward = _step$value.forward, forwardNote = _step$value.forwardNote, instructions = _step$value.instructions, removeInstructions = _step$value.removeInstructions, manualMessage = _step$value.message, scheduled = _step$value.scheduled, resetIntent = _step$value.resetIntent, secondsDelay = _step$value.secondsDelay, contextUpsert = _step$value.contextUpsert, anticipate = _step$value.anticipate, slotFollowup = _step$value.followup, slotEntityContextUpsert = _step$value.entityContextUpsert;
|
|
1026
1028
|
if (!anticipate) {
|
|
1027
|
-
_context2.next =
|
|
1029
|
+
_context2.next = 70;
|
|
1028
1030
|
break;
|
|
1029
1031
|
}
|
|
1030
1032
|
if (!Array.isArray(anticipate)) {
|
|
1031
|
-
_context2.next =
|
|
1033
|
+
_context2.next = 65;
|
|
1032
1034
|
break;
|
|
1033
1035
|
}
|
|
1034
1036
|
// 'literal' anticipation
|
|
@@ -1048,11 +1050,11 @@ var Spirits = {
|
|
|
1048
1050
|
slots: _slots,
|
|
1049
1051
|
map: map
|
|
1050
1052
|
});
|
|
1051
|
-
_context2.next =
|
|
1053
|
+
_context2.next = 70;
|
|
1052
1054
|
break;
|
|
1053
|
-
case
|
|
1055
|
+
case 65:
|
|
1054
1056
|
if (!('yes' in anticipate && 'no' in anticipate && 'did' in anticipate)) {
|
|
1055
|
-
_context2.next =
|
|
1057
|
+
_context2.next = 69;
|
|
1056
1058
|
break;
|
|
1057
1059
|
}
|
|
1058
1060
|
// "did" anticipation
|
|
@@ -1064,14 +1066,17 @@ var Spirits = {
|
|
|
1064
1066
|
},
|
|
1065
1067
|
did: anticipate.did
|
|
1066
1068
|
});
|
|
1067
|
-
_context2.next =
|
|
1069
|
+
_context2.next = 70;
|
|
1068
1070
|
break;
|
|
1069
|
-
case 68:
|
|
1070
|
-
throw new Error("Invalid anticipate payload \"".concat(JSON.stringify(anticipate), "\""));
|
|
1071
1071
|
case 69:
|
|
1072
|
+
throw new Error("Invalid anticipate payload \"".concat(JSON.stringify(anticipate), "\""));
|
|
1073
|
+
case 70:
|
|
1072
1074
|
if (slotFollowup) {
|
|
1073
1075
|
followup.push(slotFollowup);
|
|
1074
1076
|
}
|
|
1077
|
+
if (slotEntityContextUpsert && slotEntityContextUpsert.length) {
|
|
1078
|
+
entityContextUpsert.push.apply(entityContextUpsert, _toConsumableArray(slotEntityContextUpsert));
|
|
1079
|
+
}
|
|
1075
1080
|
|
|
1076
1081
|
// Forward to agent or other agent
|
|
1077
1082
|
if (forward) {
|
|
@@ -1116,19 +1121,19 @@ var Spirits = {
|
|
|
1116
1121
|
|
|
1117
1122
|
// Insert instructions context
|
|
1118
1123
|
if (!instructions) {
|
|
1119
|
-
_context2.next =
|
|
1124
|
+
_context2.next = 88;
|
|
1120
1125
|
break;
|
|
1121
1126
|
}
|
|
1122
1127
|
if (!(typeof instructions === 'string')) {
|
|
1123
|
-
_context2.next =
|
|
1128
|
+
_context2.next = 78;
|
|
1124
1129
|
break;
|
|
1125
1130
|
}
|
|
1126
1131
|
addInstruction(instructions, previousLockAttempt);
|
|
1127
|
-
_context2.next =
|
|
1132
|
+
_context2.next = 88;
|
|
1128
1133
|
break;
|
|
1129
|
-
case
|
|
1134
|
+
case 78:
|
|
1130
1135
|
if (!Array.isArray(instructions)) {
|
|
1131
|
-
_context2.next =
|
|
1136
|
+
_context2.next = 83;
|
|
1132
1137
|
break;
|
|
1133
1138
|
}
|
|
1134
1139
|
_iterator3 = _createForOfIteratorHelper(instructions);
|
|
@@ -1146,25 +1151,25 @@ var Spirits = {
|
|
|
1146
1151
|
} finally {
|
|
1147
1152
|
_iterator3.f();
|
|
1148
1153
|
}
|
|
1149
|
-
_context2.next =
|
|
1154
|
+
_context2.next = 88;
|
|
1150
1155
|
break;
|
|
1151
|
-
case
|
|
1156
|
+
case 83:
|
|
1152
1157
|
if (!(_typeof(instructions) === 'object' && 'content' in instructions)) {
|
|
1153
|
-
_context2.next =
|
|
1158
|
+
_context2.next = 87;
|
|
1154
1159
|
break;
|
|
1155
1160
|
}
|
|
1156
1161
|
addInstruction(instructions.content, previousLockAttempt, instructions.id);
|
|
1157
|
-
_context2.next =
|
|
1162
|
+
_context2.next = 88;
|
|
1158
1163
|
break;
|
|
1159
|
-
case
|
|
1164
|
+
case 87:
|
|
1160
1165
|
throw new Error("SpiritsError: instructions must be a string or array or {content: \"<instruction>\"}, got: ".concat(JSON.stringify(instructions)));
|
|
1161
|
-
case
|
|
1166
|
+
case 88:
|
|
1162
1167
|
if (!removeInstructions) {
|
|
1163
|
-
_context2.next =
|
|
1168
|
+
_context2.next = 105;
|
|
1164
1169
|
break;
|
|
1165
1170
|
}
|
|
1166
1171
|
_iterator4 = _createForOfIteratorHelper(removeInstructions);
|
|
1167
|
-
_context2.prev =
|
|
1172
|
+
_context2.prev = 90;
|
|
1168
1173
|
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
1169
1174
|
var instructionId, index;
|
|
1170
1175
|
return _regeneratorRuntime().wrap(function _loop$(_context) {
|
|
@@ -1189,29 +1194,29 @@ var Spirits = {
|
|
|
1189
1194
|
}, _loop);
|
|
1190
1195
|
});
|
|
1191
1196
|
_iterator4.s();
|
|
1192
|
-
case
|
|
1197
|
+
case 93:
|
|
1193
1198
|
if ((_step4 = _iterator4.n()).done) {
|
|
1194
|
-
_context2.next =
|
|
1199
|
+
_context2.next = 97;
|
|
1195
1200
|
break;
|
|
1196
1201
|
}
|
|
1197
|
-
return _context2.delegateYield(_loop(), "t0",
|
|
1198
|
-
case 93:
|
|
1199
|
-
_context2.next = 91;
|
|
1200
|
-
break;
|
|
1202
|
+
return _context2.delegateYield(_loop(), "t0", 95);
|
|
1201
1203
|
case 95:
|
|
1202
|
-
_context2.next =
|
|
1204
|
+
_context2.next = 93;
|
|
1203
1205
|
break;
|
|
1204
1206
|
case 97:
|
|
1205
|
-
_context2.
|
|
1206
|
-
|
|
1207
|
+
_context2.next = 102;
|
|
1208
|
+
break;
|
|
1209
|
+
case 99:
|
|
1210
|
+
_context2.prev = 99;
|
|
1211
|
+
_context2.t1 = _context2["catch"](90);
|
|
1207
1212
|
_iterator4.e(_context2.t1);
|
|
1208
|
-
case
|
|
1209
|
-
_context2.prev =
|
|
1213
|
+
case 102:
|
|
1214
|
+
_context2.prev = 102;
|
|
1210
1215
|
_iterator4.f();
|
|
1211
|
-
return _context2.finish(
|
|
1212
|
-
case
|
|
1216
|
+
return _context2.finish(102);
|
|
1217
|
+
case 105:
|
|
1213
1218
|
if (!manualMessage) {
|
|
1214
|
-
_context2.next =
|
|
1219
|
+
_context2.next = 112;
|
|
1215
1220
|
break;
|
|
1216
1221
|
}
|
|
1217
1222
|
manualMessageObj = {
|
|
@@ -1221,11 +1226,11 @@ var Spirits = {
|
|
|
1221
1226
|
time: new Date().toISOString()
|
|
1222
1227
|
};
|
|
1223
1228
|
if (!(typeof manualMessage !== 'string')) {
|
|
1224
|
-
_context2.next =
|
|
1229
|
+
_context2.next = 109;
|
|
1225
1230
|
break;
|
|
1226
1231
|
}
|
|
1227
1232
|
throw new Error('Manual message must be of type "string"');
|
|
1228
|
-
case
|
|
1233
|
+
case 109:
|
|
1229
1234
|
if (scheduled) {
|
|
1230
1235
|
manualMessageObj.time = new Date(scheduled * 1000).toISOString();
|
|
1231
1236
|
manualMessageObj.scheduled = manualMessageObj.time;
|
|
@@ -1237,7 +1242,7 @@ var Spirits = {
|
|
|
1237
1242
|
}
|
|
1238
1243
|
messages.push(manualMessageObj);
|
|
1239
1244
|
progress('Added manual message', 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
|
|
1240
|
-
case
|
|
1245
|
+
case 112:
|
|
1241
1246
|
if (contextUpsert) {
|
|
1242
1247
|
context = updateContext(context, contextUpsert);
|
|
1243
1248
|
progress('Upserted context', 'info', 'UPDATE_CONTEXT', contextUpsert);
|
|
@@ -1245,21 +1250,21 @@ var Spirits = {
|
|
|
1245
1250
|
if (resetIntent) {
|
|
1246
1251
|
resettedIntent = true;
|
|
1247
1252
|
}
|
|
1248
|
-
case 112:
|
|
1249
|
-
_context2.next = 54;
|
|
1250
|
-
break;
|
|
1251
1253
|
case 114:
|
|
1252
|
-
_context2.next =
|
|
1254
|
+
_context2.next = 55;
|
|
1253
1255
|
break;
|
|
1254
1256
|
case 116:
|
|
1255
|
-
_context2.
|
|
1256
|
-
|
|
1257
|
+
_context2.next = 121;
|
|
1258
|
+
break;
|
|
1259
|
+
case 118:
|
|
1260
|
+
_context2.prev = 118;
|
|
1261
|
+
_context2.t2 = _context2["catch"](53);
|
|
1257
1262
|
_iterator.e(_context2.t2);
|
|
1258
|
-
case
|
|
1259
|
-
_context2.prev =
|
|
1263
|
+
case 121:
|
|
1264
|
+
_context2.prev = 121;
|
|
1260
1265
|
_iterator.f();
|
|
1261
|
-
return _context2.finish(
|
|
1262
|
-
case
|
|
1266
|
+
return _context2.finish(121);
|
|
1267
|
+
case 124:
|
|
1263
1268
|
if (resettedIntent && !_forward) {
|
|
1264
1269
|
conversation.intent = null;
|
|
1265
1270
|
conversation.intentScore = null;
|
|
@@ -1278,16 +1283,16 @@ var Spirits = {
|
|
|
1278
1283
|
// 4. Generate response
|
|
1279
1284
|
// If conversation previously locked, don't generate
|
|
1280
1285
|
if (input.conversation.locked) {
|
|
1281
|
-
_context2.next =
|
|
1286
|
+
_context2.next = 172;
|
|
1282
1287
|
break;
|
|
1283
1288
|
}
|
|
1284
1289
|
if (!((!conversation.locked || !hasNoInstructions) && !!hasNoCustomMessage)) {
|
|
1285
|
-
_context2.next =
|
|
1290
|
+
_context2.next = 139;
|
|
1286
1291
|
break;
|
|
1287
1292
|
}
|
|
1288
|
-
_context2.prev =
|
|
1293
|
+
_context2.prev = 127;
|
|
1289
1294
|
progress('Generating message', 'info', 'SET_PROCESSING', 'system');
|
|
1290
|
-
_context2.next =
|
|
1295
|
+
_context2.next = 131;
|
|
1291
1296
|
return generator({
|
|
1292
1297
|
messages: messages,
|
|
1293
1298
|
persona: persona,
|
|
@@ -1295,7 +1300,7 @@ var Spirits = {
|
|
|
1295
1300
|
llm: config.llm,
|
|
1296
1301
|
pmt: config.pmt
|
|
1297
1302
|
});
|
|
1298
|
-
case
|
|
1303
|
+
case 131:
|
|
1299
1304
|
generatorPayload = _context2.sent;
|
|
1300
1305
|
if (!generatorPayload.send) {
|
|
1301
1306
|
progress('Generated response', 'failed', undefined, {
|
|
@@ -1334,29 +1339,29 @@ var Spirits = {
|
|
|
1334
1339
|
}
|
|
1335
1340
|
}
|
|
1336
1341
|
}
|
|
1337
|
-
_context2.next =
|
|
1342
|
+
_context2.next = 139;
|
|
1338
1343
|
break;
|
|
1339
|
-
case
|
|
1340
|
-
_context2.prev =
|
|
1341
|
-
_context2.t3 = _context2["catch"](
|
|
1344
|
+
case 135:
|
|
1345
|
+
_context2.prev = 135;
|
|
1346
|
+
_context2.t3 = _context2["catch"](127);
|
|
1342
1347
|
console.error("Locking conversation, error generating response: ".concat(_context2.t3.message));
|
|
1343
1348
|
conversation = lockConversation(conversation, 'API: ' + _context2.t3.message);
|
|
1344
|
-
case
|
|
1349
|
+
case 139:
|
|
1345
1350
|
if (!(messagesToTransform.length && transformer)) {
|
|
1346
|
-
_context2.next =
|
|
1351
|
+
_context2.next = 171;
|
|
1347
1352
|
break;
|
|
1348
1353
|
}
|
|
1349
|
-
_context2.prev = 138;
|
|
1350
|
-
_iterator2 = _createForOfIteratorHelper(messagesToTransform);
|
|
1351
1354
|
_context2.prev = 140;
|
|
1355
|
+
_iterator2 = _createForOfIteratorHelper(messagesToTransform);
|
|
1356
|
+
_context2.prev = 142;
|
|
1352
1357
|
_iterator2.s();
|
|
1353
|
-
case
|
|
1358
|
+
case 144:
|
|
1354
1359
|
if ((_step2 = _iterator2.n()).done) {
|
|
1355
|
-
_context2.next =
|
|
1360
|
+
_context2.next = 155;
|
|
1356
1361
|
break;
|
|
1357
1362
|
}
|
|
1358
1363
|
_step2.value;
|
|
1359
|
-
_context2.next =
|
|
1364
|
+
_context2.next = 148;
|
|
1360
1365
|
return transformer({
|
|
1361
1366
|
message: messagesToTransform,
|
|
1362
1367
|
persona: persona,
|
|
@@ -1364,7 +1369,7 @@ var Spirits = {
|
|
|
1364
1369
|
messages: messages,
|
|
1365
1370
|
context: context
|
|
1366
1371
|
});
|
|
1367
|
-
case
|
|
1372
|
+
case 148:
|
|
1368
1373
|
transformResponse = _context2.sent;
|
|
1369
1374
|
progress('Generated response', 'success', undefined, undefined);
|
|
1370
1375
|
// Check if already had message
|
|
@@ -1384,36 +1389,36 @@ var Spirits = {
|
|
|
1384
1389
|
});
|
|
1385
1390
|
progress('Added agent message', 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
|
|
1386
1391
|
}
|
|
1387
|
-
case 151:
|
|
1388
|
-
_context2.next = 142;
|
|
1389
|
-
break;
|
|
1390
1392
|
case 153:
|
|
1391
|
-
_context2.next =
|
|
1393
|
+
_context2.next = 144;
|
|
1392
1394
|
break;
|
|
1393
1395
|
case 155:
|
|
1394
|
-
_context2.
|
|
1395
|
-
|
|
1396
|
+
_context2.next = 160;
|
|
1397
|
+
break;
|
|
1398
|
+
case 157:
|
|
1399
|
+
_context2.prev = 157;
|
|
1400
|
+
_context2.t4 = _context2["catch"](142);
|
|
1396
1401
|
_iterator2.e(_context2.t4);
|
|
1397
|
-
case
|
|
1398
|
-
_context2.prev =
|
|
1402
|
+
case 160:
|
|
1403
|
+
_context2.prev = 160;
|
|
1399
1404
|
_iterator2.f();
|
|
1400
|
-
return _context2.finish(
|
|
1401
|
-
case 161:
|
|
1402
|
-
_context2.next = 167;
|
|
1403
|
-
break;
|
|
1405
|
+
return _context2.finish(160);
|
|
1404
1406
|
case 163:
|
|
1405
|
-
_context2.
|
|
1406
|
-
|
|
1407
|
+
_context2.next = 169;
|
|
1408
|
+
break;
|
|
1409
|
+
case 165:
|
|
1410
|
+
_context2.prev = 165;
|
|
1411
|
+
_context2.t5 = _context2["catch"](140);
|
|
1407
1412
|
console.error("Locking conversation, error transforming response: ".concat(_context2.t5.message));
|
|
1408
1413
|
conversation = lockConversation(conversation, 'API: ' + _context2.t5.message);
|
|
1409
|
-
case 167:
|
|
1410
|
-
_context2.next = 170;
|
|
1411
|
-
break;
|
|
1412
1414
|
case 169:
|
|
1415
|
+
_context2.next = 172;
|
|
1416
|
+
break;
|
|
1417
|
+
case 171:
|
|
1413
1418
|
if (messagesToTransform.length) {
|
|
1414
1419
|
console.warn("No transformer provided");
|
|
1415
1420
|
}
|
|
1416
|
-
case
|
|
1421
|
+
case 172:
|
|
1417
1422
|
progress('Parsing message', 'info', 'SET_PROCESSING', null);
|
|
1418
1423
|
return _context2.abrupt("return", {
|
|
1419
1424
|
conversation: {
|
|
@@ -1434,13 +1439,14 @@ var Spirits = {
|
|
|
1434
1439
|
before: contextBefore,
|
|
1435
1440
|
after: context
|
|
1436
1441
|
},
|
|
1437
|
-
followup: followup
|
|
1442
|
+
followup: followup,
|
|
1443
|
+
entityContextUpsert: entityContextUpsert
|
|
1438
1444
|
});
|
|
1439
|
-
case
|
|
1445
|
+
case 174:
|
|
1440
1446
|
case "end":
|
|
1441
1447
|
return _context2.stop();
|
|
1442
1448
|
}
|
|
1443
|
-
}, _callee, null, [[
|
|
1449
|
+
}, _callee, null, [[53, 118, 121, 124], [90, 99, 102, 105], [127, 135], [140, 165], [142, 157, 160, 163]]);
|
|
1444
1450
|
}));
|
|
1445
1451
|
function customer(_x) {
|
|
1446
1452
|
return _customer.apply(this, arguments);
|
package/dist/spirits.cjs
CHANGED
package/dist/testing-tools.cjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var dev = require("./dev-
|
|
6
|
-
require("./spirits-
|
|
5
|
+
var dev = require("./dev-6e60a643.cjs");
|
|
6
|
+
require("./spirits-985e6711.cjs");
|
|
7
7
|
require('util');
|
|
8
8
|
require('stream');
|
|
9
9
|
require('path');
|
|
@@ -24,7 +24,7 @@ require('node:url');
|
|
|
24
24
|
require('node:events');
|
|
25
25
|
require('node:stream');
|
|
26
26
|
require('node:string_decoder');
|
|
27
|
-
require("./macros-
|
|
27
|
+
require("./macros-1a4fd407.cjs");
|
|
28
28
|
require('node:readline');
|
|
29
29
|
require('node:process');
|
|
30
30
|
require('node:os');
|