@scout9/app 1.0.0-alpha.1.0.5 → 1.0.0-alpha.1.0.7
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-8c238c7b.cjs → dev-74c0ba94.cjs} +2 -2
- package/dist/{index-57129cdc.cjs → index-37eb47ef.cjs} +6 -6
- package/dist/index.cjs +3 -3
- package/dist/{multipart-parser-4f099bcf.cjs → multipart-parser-531d0e35.cjs} +3 -3
- package/dist/{spirits-ab87b546.cjs → spirits-c773fc77.cjs} +196 -194
- package/dist/spirits.cjs +1 -1
- package/dist/testing-tools.cjs +2 -2
- package/package.json +1 -1
- package/src/testing-tools/spirits.js +48 -48
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var _rollupPluginBabelHelpers = require("./_rollupPluginBabelHelpers-9c73c95c.cjs");
|
|
4
|
-
var spirits = require("./spirits-
|
|
4
|
+
var spirits = require("./spirits-c773fc77.cjs");
|
|
5
5
|
var require$$0$4 = require('util');
|
|
6
6
|
var require$$0$3 = require('stream');
|
|
7
7
|
var require$$1 = require('path');
|
|
@@ -35307,7 +35307,7 @@ function _loadUserPackageJson() {
|
|
|
35307
35307
|
targetPkgUrl = isTest ? packageTestJsonUrl : packageJsonUrl;
|
|
35308
35308
|
_context2.t0 = JSON;
|
|
35309
35309
|
_context2.next = 10;
|
|
35310
|
-
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-
|
|
35310
|
+
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-74c0ba94.js', document.baseURI).href))), 'utf-8');
|
|
35311
35311
|
case 10:
|
|
35312
35312
|
_context2.t1 = _context2.sent;
|
|
35313
35313
|
pkg = _context2.t0.parse.call(_context2.t0, _context2.t1);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var _rollupPluginBabelHelpers = require("./_rollupPluginBabelHelpers-9c73c95c.cjs");
|
|
4
|
-
var dev = require("./dev-
|
|
4
|
+
var dev = require("./dev-74c0ba94.cjs");
|
|
5
5
|
var macros = require("./macros-c0acaa02.cjs");
|
|
6
|
-
var spirits = require("./spirits-
|
|
6
|
+
var spirits = require("./spirits-c773fc77.cjs");
|
|
7
7
|
var require$$0 = require('fs');
|
|
8
8
|
var require$$2$1 = require('events');
|
|
9
9
|
var require$$1 = require('path');
|
|
@@ -29484,7 +29484,7 @@ class Body {
|
|
|
29484
29484
|
}
|
|
29485
29485
|
const {
|
|
29486
29486
|
toFormData
|
|
29487
|
-
} = await Promise.resolve().then(function () { return require("./multipart-parser-
|
|
29487
|
+
} = await Promise.resolve().then(function () { return require("./multipart-parser-531d0e35.cjs"); });
|
|
29488
29488
|
return toFormData(this.body, ct);
|
|
29489
29489
|
}
|
|
29490
29490
|
|
|
@@ -41885,7 +41885,7 @@ function _loadUserPackageJson() {
|
|
|
41885
41885
|
targetPkgUrl = isTest ? packageTestJsonUrl : packageJsonUrl;
|
|
41886
41886
|
_context.t0 = JSON;
|
|
41887
41887
|
_context.next = 10;
|
|
41888
|
-
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-
|
|
41888
|
+
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-37eb47ef.js', document.baseURI).href))), 'utf-8');
|
|
41889
41889
|
case 10:
|
|
41890
41890
|
_context.t1 = _context.sent;
|
|
41891
41891
|
pkg = _context.t0.parse.call(_context.t0, _context.t1);
|
|
@@ -43177,7 +43177,7 @@ var ProjectFiles = /*#__PURE__*/function () {
|
|
|
43177
43177
|
return ProjectFiles;
|
|
43178
43178
|
}();
|
|
43179
43179
|
|
|
43180
|
-
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-
|
|
43180
|
+
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-37eb47ef.js', document.baseURI).href)));
|
|
43181
43181
|
var __dirname$1 = path__default["default"].dirname(__filename$1);
|
|
43182
43182
|
function zipDirectory(source, out) {
|
|
43183
43183
|
var archive = archiver$1('tar', {
|
|
@@ -43392,7 +43392,7 @@ function _buildApp() {
|
|
|
43392
43392
|
case 11:
|
|
43393
43393
|
_context4.t0 = JSON;
|
|
43394
43394
|
_context4.next = 14;
|
|
43395
|
-
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-
|
|
43395
|
+
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-37eb47ef.js', document.baseURI).href))), 'utf-8');
|
|
43396
43396
|
case 14:
|
|
43397
43397
|
_context4.t1 = _context4.sent;
|
|
43398
43398
|
packageTemplate = _context4.t0.parse.call(_context4.t0, _context4.t1);
|
package/dist/index.cjs
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
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-37eb47ef.cjs");
|
|
6
|
+
var dev = require("./dev-74c0ba94.cjs");
|
|
7
7
|
require("./_rollupPluginBabelHelpers-9c73c95c.cjs");
|
|
8
8
|
require("./macros-c0acaa02.cjs");
|
|
9
|
-
require("./spirits-
|
|
9
|
+
require("./spirits-c773fc77.cjs");
|
|
10
10
|
require('fs');
|
|
11
11
|
require('events');
|
|
12
12
|
require('path');
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
require('node:fs');
|
|
4
4
|
require('node:path');
|
|
5
|
-
var index = require("./index-
|
|
5
|
+
var index = require("./index-37eb47ef.cjs");
|
|
6
6
|
require("./_rollupPluginBabelHelpers-9c73c95c.cjs");
|
|
7
|
-
require("./dev-
|
|
8
|
-
require("./spirits-
|
|
7
|
+
require("./dev-74c0ba94.cjs");
|
|
8
|
+
require("./spirits-c773fc77.cjs");
|
|
9
9
|
require('util');
|
|
10
10
|
require('stream');
|
|
11
11
|
require('path');
|
|
@@ -4692,7 +4692,8 @@ function enforceMonotonicInPlace(arr) {
|
|
|
4692
4692
|
}
|
|
4693
4693
|
}
|
|
4694
4694
|
|
|
4695
|
-
var _excluded = ["
|
|
4695
|
+
var _excluded = ["id"],
|
|
4696
|
+
_excluded2 = ["keywords"];
|
|
4696
4697
|
|
|
4697
4698
|
/**
|
|
4698
4699
|
* @typedef {Object} Document
|
|
@@ -4934,6 +4935,8 @@ var Spirits = {
|
|
|
4934
4935
|
messages,
|
|
4935
4936
|
context,
|
|
4936
4937
|
message,
|
|
4938
|
+
elapsedSeconds,
|
|
4939
|
+
rootStart,
|
|
4937
4940
|
err,
|
|
4938
4941
|
followup,
|
|
4939
4942
|
entityContextUpsert,
|
|
@@ -4955,6 +4958,7 @@ var Spirits = {
|
|
|
4955
4958
|
lockConversation,
|
|
4956
4959
|
incrementLockAttempt,
|
|
4957
4960
|
_addInstruction,
|
|
4961
|
+
instructionsAdded,
|
|
4958
4962
|
addInstruction,
|
|
4959
4963
|
onStatus,
|
|
4960
4964
|
wrapStep,
|
|
@@ -4963,6 +4967,9 @@ var Spirits = {
|
|
|
4963
4967
|
parsePayload,
|
|
4964
4968
|
index,
|
|
4965
4969
|
_message,
|
|
4970
|
+
patch,
|
|
4971
|
+
id,
|
|
4972
|
+
updatedFields,
|
|
4966
4973
|
previousUserMessages,
|
|
4967
4974
|
oldKeyCount,
|
|
4968
4975
|
newKeyCount,
|
|
@@ -5027,6 +5034,7 @@ var Spirits = {
|
|
|
5027
5034
|
_transformResponse$me,
|
|
5028
5035
|
transformResponse,
|
|
5029
5036
|
transformedMessages,
|
|
5037
|
+
appendedList,
|
|
5030
5038
|
_iterator9,
|
|
5031
5039
|
_step9,
|
|
5032
5040
|
_loop,
|
|
@@ -5038,6 +5046,11 @@ var Spirits = {
|
|
|
5038
5046
|
onError = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : function () {};
|
|
5039
5047
|
customer = input.customer, config = input.config, messageBefore = input.message, contextBefore = input.context, messagesBefore = input.messages, conversationBefore = input.conversation, parser = input.parser, contextualizer = input.contextualizer, 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, _input$onSetContext = input.onSetContext, onSetContext = _input$onSetContext === void 0 ? function (_ctx) {} : _input$onSetContext, _input$onUpdateContex = input.onUpdateContext, onUpdateContext = _input$onUpdateContex === void 0 ? function (_patch) {} : _input$onUpdateContex, _input$onSetConversat = input.onSetConversation, onSetConversation = _input$onSetConversat === void 0 ? function (_conv) {} : _input$onSetConversat, _input$onUpdateConver = input.onUpdateConversation, onUpdateConversation = _input$onUpdateConver === void 0 ? function (_patch) {} : _input$onUpdateConver, input.onChunkMessage, _input$onAddMessage = input.onAddMessage, onAddMessage = _input$onAddMessage === void 0 ? function (_msg) {} : _input$onAddMessage, _input$onUpdateMessag = input.onUpdateMessage, onUpdateMessage = _input$onUpdateMessag === void 0 ? function (_patch) {} : _input$onUpdateMessag, _input$onDeleteMessag = input.onDeleteMessage, onDeleteMessage = _input$onDeleteMessag === void 0 ? function (_id) {} : _input$onDeleteMessag;
|
|
5040
5048
|
conversation = input.conversation, messages = input.messages, context = input.context, message = input.message;
|
|
5049
|
+
elapsedSeconds = function elapsedSeconds(start) {
|
|
5050
|
+
return ((performance.now() - start) / 1000).toFixed(2);
|
|
5051
|
+
};
|
|
5052
|
+
rootStart = performance.now();
|
|
5053
|
+
progress("Spirits.customer start", 'info', undefined, undefined);
|
|
5041
5054
|
if (typeof message.content !== 'string') {
|
|
5042
5055
|
err = new Error("Spirits: customer message.content is not string (id=".concat(message.id, ", type=").concat(_rollupPluginBabelHelpers._typeof(message.content), ")"));
|
|
5043
5056
|
progress('customer message.content is not string', 'error', 'INVALID_CUSTOMER_MESSAGE', {
|
|
@@ -5172,13 +5185,15 @@ var Spirits = {
|
|
|
5172
5185
|
isEmptySystemMessage = function isEmptySystemMessage(m) {
|
|
5173
5186
|
return (m === null || m === void 0 ? void 0 : m.role) === 'system' && (typeof m.content !== 'string' || m.content.trim() === '');
|
|
5174
5187
|
};
|
|
5175
|
-
updateConversation = function updateConversation(previousConversation, conversationUpdates) {
|
|
5176
|
-
|
|
5188
|
+
updateConversation = function updateConversation(previousConversation, conversationUpdates, note) {
|
|
5189
|
+
var _note = ["Updated conversation fields", note].filter(Boolean).join(', ');
|
|
5190
|
+
progress("".concat(_note, ": ").concat(JSON.stringify(Object.keys(conversationUpdates))), 'info', 'UPDATE_CONVERSATION', conversationUpdates);
|
|
5177
5191
|
emitUpdateConversation(conversationUpdates);
|
|
5178
5192
|
return _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, previousConversation), conversationUpdates);
|
|
5179
5193
|
};
|
|
5180
|
-
updateContext = function updateContext(previousContext, newContext) {
|
|
5181
|
-
|
|
5194
|
+
updateContext = function updateContext(previousContext, newContext, note) {
|
|
5195
|
+
var _note = ["Updated context fields", note].filter(Boolean).join(', ');
|
|
5196
|
+
progress("".concat(_note, ": ").concat(JSON.stringify(Object.keys(newContext))), 'info', 'UPDATE_CONTEXT', newContext);
|
|
5182
5197
|
emitUpdateContext(newContext);
|
|
5183
5198
|
return _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, previousContext), newContext);
|
|
5184
5199
|
};
|
|
@@ -5195,7 +5210,7 @@ var Spirits = {
|
|
|
5195
5210
|
return updateConversation(_conversation, {
|
|
5196
5211
|
locked: true,
|
|
5197
5212
|
lockedReason: _conversation.lockedReason || reason || 'Unknown'
|
|
5198
|
-
});
|
|
5213
|
+
}, 'lock conversation');
|
|
5199
5214
|
};
|
|
5200
5215
|
incrementLockAttempt = function incrementLockAttempt(_conversation, _config) {
|
|
5201
5216
|
var max = (_config === null || _config === void 0 ? void 0 : _config.maxLockAttempts) || 3;
|
|
@@ -5210,8 +5225,11 @@ var Spirits = {
|
|
|
5210
5225
|
patch.locked = true;
|
|
5211
5226
|
patch.lockedReason = "Max lock attempts exceeded (".concat(next, " > ").concat(max, ")");
|
|
5212
5227
|
}
|
|
5213
|
-
var updated = updateConversation(_conversation, patch);
|
|
5214
|
-
return
|
|
5228
|
+
var updated = updateConversation(_conversation, patch, 'increment lock');
|
|
5229
|
+
return {
|
|
5230
|
+
updated: updated,
|
|
5231
|
+
patch: patch
|
|
5232
|
+
};
|
|
5215
5233
|
};
|
|
5216
5234
|
_addInstruction = function _addInstruction(instruction, _messages, _conversation, _config, previousLockAttempt, id) {
|
|
5217
5235
|
var systemMessages = _messages.filter(function (m) {
|
|
@@ -5219,7 +5237,7 @@ var Spirits = {
|
|
|
5219
5237
|
});
|
|
5220
5238
|
var lastSystemMessage = systemMessages[systemMessages.length - 1];
|
|
5221
5239
|
var addedMessage = false;
|
|
5222
|
-
var changedConversation =
|
|
5240
|
+
var changedConversation = [];
|
|
5223
5241
|
|
|
5224
5242
|
// If instruction does not equal previous system message, add it, otherwise lock attempt
|
|
5225
5243
|
if (!lastSystemMessage || instruction !== lastSystemMessage.content) {
|
|
@@ -5242,8 +5260,11 @@ var Spirits = {
|
|
|
5242
5260
|
// Handle repeated instruction
|
|
5243
5261
|
// Increment lock attempt if instructions are repeated and we haven't already incremented lock attempt (for example if a forward is provided)
|
|
5244
5262
|
if (previousLockAttempt === (_conversation.lockAttempts || 0)) {
|
|
5245
|
-
|
|
5246
|
-
|
|
5263
|
+
var _incrementLockAttempt = incrementLockAttempt(_conversation, _config),
|
|
5264
|
+
updated = _incrementLockAttempt.updated,
|
|
5265
|
+
patch = _incrementLockAttempt.patch;
|
|
5266
|
+
_conversation = updated;
|
|
5267
|
+
changedConversation = Object.keys(patch);
|
|
5247
5268
|
}
|
|
5248
5269
|
}
|
|
5249
5270
|
return {
|
|
@@ -5253,6 +5274,7 @@ var Spirits = {
|
|
|
5253
5274
|
changedConversation: changedConversation
|
|
5254
5275
|
};
|
|
5255
5276
|
};
|
|
5277
|
+
instructionsAdded = 0;
|
|
5256
5278
|
addInstruction = function addInstruction(instruction, previousLockAttempt) {
|
|
5257
5279
|
var id = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : idGenerator('sys');
|
|
5258
5280
|
var _addInstruction2 = _addInstruction(instruction, messages, conversation, config, previousLockAttempt, id),
|
|
@@ -5263,10 +5285,11 @@ var Spirits = {
|
|
|
5263
5285
|
conversation = newConversation;
|
|
5264
5286
|
messages = newMessages;
|
|
5265
5287
|
if (addedMessage) {
|
|
5266
|
-
|
|
5288
|
+
instructionsAdded++;
|
|
5289
|
+
progress("Added ".concat(instructionsAdded, " instruction").concat(instructionsAdded === 1 ? '' : 's'), 'info', 'ADD_MESSAGE', newMessages[newMessages.length - 1]);
|
|
5267
5290
|
}
|
|
5268
|
-
if (changedConversation) {
|
|
5269
|
-
progress(
|
|
5291
|
+
if (changedConversation.length) {
|
|
5292
|
+
progress("Updated conversation fields: ".concat(JSON.stringify(changedConversation)), 'info', 'UPDATE_CONVERSATION', newConversation);
|
|
5270
5293
|
}
|
|
5271
5294
|
};
|
|
5272
5295
|
onStatus = function onStatus(statusType) {
|
|
@@ -5283,8 +5306,7 @@ var Spirits = {
|
|
|
5283
5306
|
wrapStep = /*#__PURE__*/function () {
|
|
5284
5307
|
var _ref2 = _rollupPluginBabelHelpers._asyncToGenerator( /*#__PURE__*/_rollupPluginBabelHelpers._regeneratorRuntime().mark(function _callee(prom, step) {
|
|
5285
5308
|
var stepAction,
|
|
5286
|
-
|
|
5287
|
-
elapsedSeconds,
|
|
5309
|
+
stepStart,
|
|
5288
5310
|
result,
|
|
5289
5311
|
msg,
|
|
5290
5312
|
_args2 = arguments;
|
|
@@ -5292,71 +5314,68 @@ var Spirits = {
|
|
|
5292
5314
|
while (1) switch (_context.prev = _context.next) {
|
|
5293
5315
|
case 0:
|
|
5294
5316
|
stepAction = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : step;
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
return ((performance.now() - start) / 1000).toFixed(2);
|
|
5298
|
-
};
|
|
5299
|
-
_context.prev = 3;
|
|
5317
|
+
stepStart = performance.now();
|
|
5318
|
+
_context.prev = 2;
|
|
5300
5319
|
progress("".concat(stepAction, " start"), 'info', undefined, undefined);
|
|
5301
|
-
_context.next =
|
|
5320
|
+
_context.next = 6;
|
|
5302
5321
|
return prom;
|
|
5303
|
-
case
|
|
5322
|
+
case 6:
|
|
5304
5323
|
result = _context.sent;
|
|
5305
|
-
progress("".concat(stepAction, " succeeded in ").concat(elapsedSeconds(), "s"), 'success', undefined, undefined);
|
|
5324
|
+
progress("".concat(stepAction, " succeeded in ").concat(elapsedSeconds(stepStart), "s"), 'success', undefined, undefined);
|
|
5306
5325
|
return _context.abrupt("return", result);
|
|
5307
|
-
case
|
|
5308
|
-
_context.prev =
|
|
5309
|
-
_context.t0 = _context["catch"](
|
|
5326
|
+
case 11:
|
|
5327
|
+
_context.prev = 11;
|
|
5328
|
+
_context.t0 = _context["catch"](2);
|
|
5310
5329
|
msg = (_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message) || 'UNHANDLED ERROR';
|
|
5311
|
-
progress("".concat(stepAction, " failed in ").concat(elapsedSeconds(), "s"), 'error', undefined, {
|
|
5330
|
+
progress("".concat(stepAction, " failed in ").concat(elapsedSeconds(stepStart), "s"), 'error', undefined, {
|
|
5312
5331
|
error: msg
|
|
5313
5332
|
});
|
|
5314
5333
|
throw SpiritError.fromError(_context.t0, step);
|
|
5315
|
-
case
|
|
5334
|
+
case 16:
|
|
5316
5335
|
case "end":
|
|
5317
5336
|
return _context.stop();
|
|
5318
5337
|
}
|
|
5319
|
-
}, _callee, null, [[
|
|
5338
|
+
}, _callee, null, [[2, 11]]);
|
|
5320
5339
|
}));
|
|
5321
5340
|
return function wrapStep(_x2, _x3) {
|
|
5322
5341
|
return _ref2.apply(this, arguments);
|
|
5323
5342
|
};
|
|
5324
5343
|
}(); // 1. Check inputs
|
|
5325
5344
|
if (conversation.$agent) {
|
|
5326
|
-
_context5.next =
|
|
5345
|
+
_context5.next = 34;
|
|
5327
5346
|
break;
|
|
5328
5347
|
}
|
|
5329
5348
|
throw new Error("SpiritsError: No agent found in conversation, must define \".$agent\" in the conversation");
|
|
5330
|
-
case
|
|
5349
|
+
case 34:
|
|
5331
5350
|
persona = (config.persona || config.personas || config.agents).find(function (p) {
|
|
5332
5351
|
return p.id === conversation.$agent;
|
|
5333
5352
|
});
|
|
5334
5353
|
if (persona) {
|
|
5335
|
-
_context5.next =
|
|
5354
|
+
_context5.next = 39;
|
|
5336
5355
|
break;
|
|
5337
5356
|
}
|
|
5338
5357
|
if (!(config.persona || config.personas || config.agents).some(function (a) {
|
|
5339
5358
|
return !a.id;
|
|
5340
5359
|
})) {
|
|
5341
|
-
_context5.next =
|
|
5360
|
+
_context5.next = 38;
|
|
5342
5361
|
break;
|
|
5343
5362
|
}
|
|
5344
5363
|
throw new Error("SpiritsError: No persona found (\"".concat(conversation.$agent, "\") in provided config, some persona's did not contain an \"id\" (Internal Mapping Error)"));
|
|
5345
|
-
case
|
|
5364
|
+
case 38:
|
|
5346
5365
|
throw new Error("SpiritsError: No persona found (\"".concat(conversation.$agent, "\") in provided config"));
|
|
5347
|
-
case
|
|
5366
|
+
case 39:
|
|
5348
5367
|
if (messages.every(function (m) {
|
|
5349
5368
|
return !!m.id;
|
|
5350
5369
|
})) {
|
|
5351
|
-
_context5.next =
|
|
5370
|
+
_context5.next = 41;
|
|
5352
5371
|
break;
|
|
5353
5372
|
}
|
|
5354
5373
|
throw new Error("SpiritsError: Every message must have an \".id\", ensure all messages have an id assigned before running");
|
|
5355
|
-
case
|
|
5374
|
+
case 41:
|
|
5356
5375
|
if (messages.every(function (m) {
|
|
5357
5376
|
return m.role === 'customer' || m.role === 'agent' || m.role === 'system' || m.role === 'tool';
|
|
5358
5377
|
})) {
|
|
5359
|
-
_context5.next =
|
|
5378
|
+
_context5.next = 44;
|
|
5360
5379
|
break;
|
|
5361
5380
|
}
|
|
5362
5381
|
invalidRoles = messages.filter(function (m) {
|
|
@@ -5365,7 +5384,7 @@ var Spirits = {
|
|
|
5365
5384
|
throw new Error("SpiritsError: Every message must have a role of \"customer\", \"agent\", or \"system\". Got invalid roles: ".concat(invalidRoles.map(function (m) {
|
|
5366
5385
|
return m.role;
|
|
5367
5386
|
}).join(', ')));
|
|
5368
|
-
case
|
|
5387
|
+
case 44:
|
|
5369
5388
|
// Normalize existing message times ONCE at the start
|
|
5370
5389
|
enforceMonotonicWithEmits(messages, 1);
|
|
5371
5390
|
|
|
@@ -5381,9 +5400,9 @@ var Spirits = {
|
|
|
5381
5400
|
}
|
|
5382
5401
|
|
|
5383
5402
|
// 2. Parse the message
|
|
5384
|
-
_context5.next =
|
|
5403
|
+
_context5.next = 50;
|
|
5385
5404
|
return wrapStep(parser(message.content, 'en'), 'parse', 'parsing message');
|
|
5386
|
-
case
|
|
5405
|
+
case 50:
|
|
5387
5406
|
parsePayload = _context5.sent;
|
|
5388
5407
|
if (parsePayload.intent) {
|
|
5389
5408
|
message.intent = parsePayload.intent;
|
|
@@ -5415,7 +5434,7 @@ var Spirits = {
|
|
|
5415
5434
|
message = _message;
|
|
5416
5435
|
message = pushMessage(messages, _message);
|
|
5417
5436
|
emitAddMessage(message);
|
|
5418
|
-
progress(
|
|
5437
|
+
progress("Added \"".concat(_message.role, "\" message"), 'info', 'ADD_MESSAGE', _message);
|
|
5419
5438
|
} else {
|
|
5420
5439
|
messages[index].context = parsePayload.context;
|
|
5421
5440
|
messages[index].entities = parsePayload.entities;
|
|
@@ -5426,7 +5445,7 @@ var Spirits = {
|
|
|
5426
5445
|
messages[index].intentScore = parsePayload.intentScore;
|
|
5427
5446
|
}
|
|
5428
5447
|
message = messages[index];
|
|
5429
|
-
|
|
5448
|
+
patch = _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({
|
|
5430
5449
|
id: messages[index].id,
|
|
5431
5450
|
context: parsePayload.context,
|
|
5432
5451
|
entities: parsePayload.entities
|
|
@@ -5434,8 +5453,10 @@ var Spirits = {
|
|
|
5434
5453
|
intent: parsePayload.intent
|
|
5435
5454
|
} : {}), typeof parsePayload.intentScore === 'number' ? {
|
|
5436
5455
|
intentScore: parsePayload.intentScore
|
|
5437
|
-
} : {})
|
|
5438
|
-
|
|
5456
|
+
} : {});
|
|
5457
|
+
emitUpdateMessage(patch);
|
|
5458
|
+
id = patch.id, updatedFields = _rollupPluginBabelHelpers._objectWithoutProperties(patch, _excluded);
|
|
5459
|
+
progress("updated ".concat(id, " message fields ").concat(JSON.stringify(Object.keys(updatedFields))), 'info', 'UPDATE_MESSAGE', message);
|
|
5439
5460
|
}
|
|
5440
5461
|
// If this is the first user message, then update conversations intent
|
|
5441
5462
|
previousUserMessages = messages.filter(function (m) {
|
|
@@ -5445,11 +5466,7 @@ var Spirits = {
|
|
|
5445
5466
|
conversation = updateConversation(conversation, {
|
|
5446
5467
|
intent: parsePayload.intent,
|
|
5447
5468
|
intentScore: (parsePayload === null || parsePayload === void 0 ? void 0 : parsePayload.intentScore) || 0
|
|
5448
|
-
});
|
|
5449
|
-
progress('Updated conversation intent', 'info', 'UPDATE_CONVERSATION', {
|
|
5450
|
-
intent: parsePayload.intent,
|
|
5451
|
-
intentScore: (parsePayload === null || parsePayload === void 0 ? void 0 : parsePayload.intentScore) || 0
|
|
5452
|
-
});
|
|
5469
|
+
}, 'intent mapping');
|
|
5453
5470
|
}
|
|
5454
5471
|
oldKeyCount = Object.keys(context).length;
|
|
5455
5472
|
context = updateContext(context, parsePayload.context);
|
|
@@ -5460,12 +5477,7 @@ var Spirits = {
|
|
|
5460
5477
|
locked: false,
|
|
5461
5478
|
lockAttempts: 0,
|
|
5462
5479
|
lockedReason: ''
|
|
5463
|
-
});
|
|
5464
|
-
progress('Reset lock', 'info', 'UPDATE_CONVERSATION', {
|
|
5465
|
-
locked: false,
|
|
5466
|
-
lockAttempts: 0,
|
|
5467
|
-
lockedReason: ''
|
|
5468
|
-
});
|
|
5480
|
+
}, 'reset lock attempts');
|
|
5469
5481
|
}
|
|
5470
5482
|
noNewContext = Object.keys(parsePayload.context).length === 0; // upsert parse system messages
|
|
5471
5483
|
if (parsePayload.contextMessages.length) {
|
|
@@ -5506,15 +5518,15 @@ var Spirits = {
|
|
|
5506
5518
|
|
|
5507
5519
|
// 3. Run the contextualizer
|
|
5508
5520
|
// progress('Running contextualizer', 'info', 'SET_PROCESSING', 'system');
|
|
5509
|
-
_context5.next =
|
|
5521
|
+
_context5.next = 67;
|
|
5510
5522
|
return wrapStep(contextualizer({
|
|
5511
5523
|
conversation: conversation,
|
|
5512
5524
|
messages: messages
|
|
5513
5525
|
}), 'contextualize', 'contextualizing');
|
|
5514
|
-
case
|
|
5526
|
+
case 67:
|
|
5515
5527
|
newContextMessages = _context5.sent;
|
|
5516
5528
|
_iterator6 = _rollupPluginBabelHelpers._createForOfIteratorHelper(newContextMessages);
|
|
5517
|
-
_context5.prev =
|
|
5529
|
+
_context5.prev = 69;
|
|
5518
5530
|
_loop2 = /*#__PURE__*/_rollupPluginBabelHelpers._regeneratorRuntime().mark(function _loop2() {
|
|
5519
5531
|
var contextMessage;
|
|
5520
5532
|
return _rollupPluginBabelHelpers._regeneratorRuntime().wrap(function _loop2$(_context3) {
|
|
@@ -5530,7 +5542,7 @@ var Spirits = {
|
|
|
5530
5542
|
return messageKey(mes) === messageKey(contextMessage);
|
|
5531
5543
|
})) {
|
|
5532
5544
|
emitAddMessage(pushMessage(messages, contextMessage));
|
|
5533
|
-
progress("Added context", 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
|
|
5545
|
+
progress("Added context ".concat(message.role, " message"), 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
|
|
5534
5546
|
} else {
|
|
5535
5547
|
progress("Already have system context, skipping", 'info');
|
|
5536
5548
|
}
|
|
@@ -5541,28 +5553,28 @@ var Spirits = {
|
|
|
5541
5553
|
}, _loop2);
|
|
5542
5554
|
});
|
|
5543
5555
|
_iterator6.s();
|
|
5544
|
-
case
|
|
5556
|
+
case 72:
|
|
5545
5557
|
if ((_step6 = _iterator6.n()).done) {
|
|
5546
|
-
_context5.next =
|
|
5558
|
+
_context5.next = 76;
|
|
5547
5559
|
break;
|
|
5548
5560
|
}
|
|
5549
|
-
return _context5.delegateYield(_loop2(), "t0",
|
|
5550
|
-
case
|
|
5551
|
-
_context5.next =
|
|
5561
|
+
return _context5.delegateYield(_loop2(), "t0", 74);
|
|
5562
|
+
case 74:
|
|
5563
|
+
_context5.next = 72;
|
|
5552
5564
|
break;
|
|
5553
|
-
case
|
|
5554
|
-
_context5.next =
|
|
5565
|
+
case 76:
|
|
5566
|
+
_context5.next = 81;
|
|
5555
5567
|
break;
|
|
5556
|
-
case
|
|
5557
|
-
_context5.prev =
|
|
5558
|
-
_context5.t1 = _context5["catch"](
|
|
5568
|
+
case 78:
|
|
5569
|
+
_context5.prev = 78;
|
|
5570
|
+
_context5.t1 = _context5["catch"](69);
|
|
5559
5571
|
_iterator6.e(_context5.t1);
|
|
5560
|
-
case
|
|
5561
|
-
_context5.prev =
|
|
5572
|
+
case 81:
|
|
5573
|
+
_context5.prev = 81;
|
|
5562
5574
|
_iterator6.f();
|
|
5563
|
-
return _context5.finish(
|
|
5564
|
-
case
|
|
5565
|
-
_context5.next =
|
|
5575
|
+
return _context5.finish(81);
|
|
5576
|
+
case 84:
|
|
5577
|
+
_context5.next = 86;
|
|
5566
5578
|
return wrapStep(workflow({
|
|
5567
5579
|
messages: messages,
|
|
5568
5580
|
conversation: conversation,
|
|
@@ -5591,7 +5603,7 @@ var Spirits = {
|
|
|
5591
5603
|
return accumulator;
|
|
5592
5604
|
}, []);
|
|
5593
5605
|
});
|
|
5594
|
-
case
|
|
5606
|
+
case 86:
|
|
5595
5607
|
slots = _context5.sent;
|
|
5596
5608
|
hasNoInstructions = slots.every(function (s) {
|
|
5597
5609
|
return !s.instructions || Array.isArray(s.instructions) && s.instructions.length === 0;
|
|
@@ -5651,43 +5663,38 @@ var Spirits = {
|
|
|
5651
5663
|
enforceMonotonicWithEmits(messagesToTransform, 1);
|
|
5652
5664
|
previousLockAttempt = conversation.lockAttempts || 0; // Used to track
|
|
5653
5665
|
if (hasNoInstructions && noNewContext) {
|
|
5654
|
-
conversation = incrementLockAttempt(conversation, config);
|
|
5666
|
+
conversation = incrementLockAttempt(conversation, config).updated;
|
|
5655
5667
|
} else {
|
|
5656
5668
|
conversation = updateConversation(conversation, {
|
|
5657
5669
|
lockAttempts: 0,
|
|
5658
5670
|
locked: false,
|
|
5659
5671
|
lockedReason: ''
|
|
5660
|
-
});
|
|
5661
|
-
progress('Reset lock', 'info', 'UPDATE_CONVERSATION', {
|
|
5662
|
-
lockAttempts: 0,
|
|
5663
|
-
locked: false,
|
|
5664
|
-
lockedReason: ''
|
|
5665
|
-
});
|
|
5672
|
+
}, 'reset lock');
|
|
5666
5673
|
}
|
|
5667
5674
|
resettedIntent = false;
|
|
5668
5675
|
/** @type {Array<string> | undefined} */
|
|
5669
5676
|
_iterator7 = _rollupPluginBabelHelpers._createForOfIteratorHelper(slots);
|
|
5670
|
-
_context5.prev =
|
|
5677
|
+
_context5.prev = 95;
|
|
5671
5678
|
_iterator7.s();
|
|
5672
|
-
case
|
|
5679
|
+
case 97:
|
|
5673
5680
|
if ((_step7 = _iterator7.n()).done) {
|
|
5674
|
-
_context5.next =
|
|
5681
|
+
_context5.next = 152;
|
|
5675
5682
|
break;
|
|
5676
5683
|
}
|
|
5677
5684
|
_step7$value = _step7.value, forward = _step7$value.forward, forwardNote = _step7$value.forwardNote, instructions = _step7$value.instructions, removeInstructions = _step7$value.removeInstructions, _step7$value.message, _step7$value.scheduled, resetIntent = _step7$value.resetIntent, _step7$value.secondsDelay, contextUpsert = _step7$value.contextUpsert, anticipate = _step7$value.anticipate, slotFollowup = _step7$value.followup, slotEntityContextUpsert = _step7$value.entityContextUpsert, tasks = _step7$value.tasks;
|
|
5678
5685
|
if (!anticipate) {
|
|
5679
|
-
_context5.next =
|
|
5686
|
+
_context5.next = 112;
|
|
5680
5687
|
break;
|
|
5681
5688
|
}
|
|
5682
5689
|
if (!Array.isArray(anticipate)) {
|
|
5683
|
-
_context5.next =
|
|
5690
|
+
_context5.next = 107;
|
|
5684
5691
|
break;
|
|
5685
5692
|
}
|
|
5686
5693
|
// 'literal' anticipation
|
|
5687
5694
|
_slots = {};
|
|
5688
5695
|
map = [];
|
|
5689
5696
|
for (i = 0; i < anticipate.length; i++) {
|
|
5690
|
-
_anticipate$i = anticipate[i], keywords = _anticipate$i.keywords, _slot = _rollupPluginBabelHelpers._objectWithoutProperties(_anticipate$i,
|
|
5697
|
+
_anticipate$i = anticipate[i], keywords = _anticipate$i.keywords, _slot = _rollupPluginBabelHelpers._objectWithoutProperties(_anticipate$i, _excluded2);
|
|
5691
5698
|
slotId = "".concat(i);
|
|
5692
5699
|
_slots[slotId] = _slot;
|
|
5693
5700
|
map.push({
|
|
@@ -5699,12 +5706,12 @@ var Spirits = {
|
|
|
5699
5706
|
type: 'literal',
|
|
5700
5707
|
slots: _slots,
|
|
5701
5708
|
map: map
|
|
5702
|
-
});
|
|
5703
|
-
_context5.next =
|
|
5709
|
+
}, 'anticipation slots');
|
|
5710
|
+
_context5.next = 112;
|
|
5704
5711
|
break;
|
|
5705
|
-
case
|
|
5712
|
+
case 107:
|
|
5706
5713
|
if (!('yes' in anticipate && 'no' in anticipate && 'did' in anticipate)) {
|
|
5707
|
-
_context5.next =
|
|
5714
|
+
_context5.next = 111;
|
|
5708
5715
|
break;
|
|
5709
5716
|
}
|
|
5710
5717
|
// "did" anticipation
|
|
@@ -5715,12 +5722,12 @@ var Spirits = {
|
|
|
5715
5722
|
no: anticipate.no
|
|
5716
5723
|
},
|
|
5717
5724
|
did: anticipate.did
|
|
5718
|
-
});
|
|
5719
|
-
_context5.next =
|
|
5725
|
+
}, 'anticipation slots');
|
|
5726
|
+
_context5.next = 112;
|
|
5720
5727
|
break;
|
|
5721
|
-
case
|
|
5728
|
+
case 111:
|
|
5722
5729
|
throw new Error("Invalid anticipate payload \"".concat(JSON.stringify(anticipate), "\""));
|
|
5723
|
-
case
|
|
5730
|
+
case 112:
|
|
5724
5731
|
// tasks from auto/manual ingress to execute
|
|
5725
5732
|
if (!!tasks && Array.isArray(tasks) && !!tasks.length) {
|
|
5726
5733
|
if (!_tasks) _tasks = [];
|
|
@@ -5741,7 +5748,7 @@ var Spirits = {
|
|
|
5741
5748
|
if (typeof forward === 'string') {
|
|
5742
5749
|
conversation = updateConversation(conversation, {
|
|
5743
5750
|
forwarded: forward
|
|
5744
|
-
});
|
|
5751
|
+
}, 'forward');
|
|
5745
5752
|
emitAddMessage(pushMessage(messages, {
|
|
5746
5753
|
id: idGenerator("sys"),
|
|
5747
5754
|
role: "system",
|
|
@@ -5752,7 +5759,7 @@ var Spirits = {
|
|
|
5752
5759
|
} else if (typeof forward === 'boolean') {
|
|
5753
5760
|
conversation = updateConversation(conversation, {
|
|
5754
5761
|
forwarded: conversation.$agent
|
|
5755
|
-
});
|
|
5762
|
+
}, 'forward');
|
|
5756
5763
|
emitAddMessage(pushMessage(messages, {
|
|
5757
5764
|
id: idGenerator("sys"),
|
|
5758
5765
|
role: "system",
|
|
@@ -5763,7 +5770,7 @@ var Spirits = {
|
|
|
5763
5770
|
} else {
|
|
5764
5771
|
conversation = updateConversation(conversation, {
|
|
5765
5772
|
forwarded: forward.to
|
|
5766
|
-
});
|
|
5773
|
+
}, 'forward');
|
|
5767
5774
|
emitAddMessage(pushMessage(messages, {
|
|
5768
5775
|
id: idGenerator("sys"),
|
|
5769
5776
|
role: "system",
|
|
@@ -5776,19 +5783,19 @@ var Spirits = {
|
|
|
5776
5783
|
|
|
5777
5784
|
// Insert instructions context
|
|
5778
5785
|
if (!instructions) {
|
|
5779
|
-
_context5.next =
|
|
5786
|
+
_context5.next = 131;
|
|
5780
5787
|
break;
|
|
5781
5788
|
}
|
|
5782
5789
|
if (!(typeof instructions === 'string')) {
|
|
5783
|
-
_context5.next =
|
|
5790
|
+
_context5.next = 121;
|
|
5784
5791
|
break;
|
|
5785
5792
|
}
|
|
5786
5793
|
addInstruction(instructions, previousLockAttempt);
|
|
5787
|
-
_context5.next =
|
|
5794
|
+
_context5.next = 131;
|
|
5788
5795
|
break;
|
|
5789
|
-
case
|
|
5796
|
+
case 121:
|
|
5790
5797
|
if (!Array.isArray(instructions)) {
|
|
5791
|
-
_context5.next =
|
|
5798
|
+
_context5.next = 126;
|
|
5792
5799
|
break;
|
|
5793
5800
|
}
|
|
5794
5801
|
_iterator10 = _rollupPluginBabelHelpers._createForOfIteratorHelper(instructions);
|
|
@@ -5806,25 +5813,25 @@ var Spirits = {
|
|
|
5806
5813
|
} finally {
|
|
5807
5814
|
_iterator10.f();
|
|
5808
5815
|
}
|
|
5809
|
-
_context5.next =
|
|
5816
|
+
_context5.next = 131;
|
|
5810
5817
|
break;
|
|
5811
|
-
case
|
|
5818
|
+
case 126:
|
|
5812
5819
|
if (!(_rollupPluginBabelHelpers._typeof(instructions) === 'object' && 'content' in instructions)) {
|
|
5813
|
-
_context5.next =
|
|
5820
|
+
_context5.next = 130;
|
|
5814
5821
|
break;
|
|
5815
5822
|
}
|
|
5816
5823
|
addInstruction(instructions.content, previousLockAttempt, instructions.id);
|
|
5817
|
-
_context5.next =
|
|
5824
|
+
_context5.next = 131;
|
|
5818
5825
|
break;
|
|
5819
|
-
case
|
|
5826
|
+
case 130:
|
|
5820
5827
|
throw new Error("SpiritsError: instructions must be a string or array or {content: \"<instruction>\"}, got: ".concat(JSON.stringify(instructions)));
|
|
5821
|
-
case
|
|
5828
|
+
case 131:
|
|
5822
5829
|
if (!removeInstructions) {
|
|
5823
|
-
_context5.next =
|
|
5830
|
+
_context5.next = 148;
|
|
5824
5831
|
break;
|
|
5825
5832
|
}
|
|
5826
5833
|
_iterator11 = _rollupPluginBabelHelpers._createForOfIteratorHelper(removeInstructions);
|
|
5827
|
-
_context5.prev =
|
|
5834
|
+
_context5.prev = 133;
|
|
5828
5835
|
_loop3 = /*#__PURE__*/_rollupPluginBabelHelpers._regeneratorRuntime().mark(function _loop3() {
|
|
5829
5836
|
var instructionId, index, removed;
|
|
5830
5837
|
return _rollupPluginBabelHelpers._regeneratorRuntime().wrap(function _loop3$(_context4) {
|
|
@@ -5850,27 +5857,27 @@ var Spirits = {
|
|
|
5850
5857
|
}, _loop3);
|
|
5851
5858
|
});
|
|
5852
5859
|
_iterator11.s();
|
|
5853
|
-
case
|
|
5860
|
+
case 136:
|
|
5854
5861
|
if ((_step11 = _iterator11.n()).done) {
|
|
5855
|
-
_context5.next =
|
|
5862
|
+
_context5.next = 140;
|
|
5856
5863
|
break;
|
|
5857
5864
|
}
|
|
5858
|
-
return _context5.delegateYield(_loop3(), "t2",
|
|
5859
|
-
case
|
|
5860
|
-
_context5.next =
|
|
5865
|
+
return _context5.delegateYield(_loop3(), "t2", 138);
|
|
5866
|
+
case 138:
|
|
5867
|
+
_context5.next = 136;
|
|
5861
5868
|
break;
|
|
5862
|
-
case
|
|
5863
|
-
_context5.next =
|
|
5869
|
+
case 140:
|
|
5870
|
+
_context5.next = 145;
|
|
5864
5871
|
break;
|
|
5865
|
-
case
|
|
5866
|
-
_context5.prev =
|
|
5867
|
-
_context5.t3 = _context5["catch"](
|
|
5872
|
+
case 142:
|
|
5873
|
+
_context5.prev = 142;
|
|
5874
|
+
_context5.t3 = _context5["catch"](133);
|
|
5868
5875
|
_iterator11.e(_context5.t3);
|
|
5869
|
-
case
|
|
5870
|
-
_context5.prev =
|
|
5876
|
+
case 145:
|
|
5877
|
+
_context5.prev = 145;
|
|
5871
5878
|
_iterator11.f();
|
|
5872
|
-
return _context5.finish(
|
|
5873
|
-
case
|
|
5879
|
+
return _context5.finish(145);
|
|
5880
|
+
case 148:
|
|
5874
5881
|
// @TODO this logic is now handled at messagesToTransform's initialization, maybe move back down here
|
|
5875
5882
|
// if (manualMessage) {
|
|
5876
5883
|
|
|
@@ -5908,26 +5915,25 @@ var Spirits = {
|
|
|
5908
5915
|
|
|
5909
5916
|
if (contextUpsert) {
|
|
5910
5917
|
context = updateContext(context, contextUpsert);
|
|
5911
|
-
progress('Upserted context', 'info', 'UPDATE_CONTEXT', contextUpsert);
|
|
5912
5918
|
}
|
|
5913
5919
|
if (resetIntent) {
|
|
5914
5920
|
resettedIntent = true;
|
|
5915
5921
|
}
|
|
5916
|
-
case
|
|
5917
|
-
_context5.next =
|
|
5922
|
+
case 150:
|
|
5923
|
+
_context5.next = 97;
|
|
5918
5924
|
break;
|
|
5919
|
-
case
|
|
5920
|
-
_context5.next =
|
|
5925
|
+
case 152:
|
|
5926
|
+
_context5.next = 157;
|
|
5921
5927
|
break;
|
|
5922
|
-
case
|
|
5923
|
-
_context5.prev =
|
|
5924
|
-
_context5.t4 = _context5["catch"](
|
|
5928
|
+
case 154:
|
|
5929
|
+
_context5.prev = 154;
|
|
5930
|
+
_context5.t4 = _context5["catch"](95);
|
|
5925
5931
|
_iterator7.e(_context5.t4);
|
|
5926
|
-
case
|
|
5927
|
-
_context5.prev =
|
|
5932
|
+
case 157:
|
|
5933
|
+
_context5.prev = 157;
|
|
5928
5934
|
_iterator7.f();
|
|
5929
|
-
return _context5.finish(
|
|
5930
|
-
case
|
|
5935
|
+
return _context5.finish(157);
|
|
5936
|
+
case 160:
|
|
5931
5937
|
enforceMonotonicWithEmits(messages, 1);
|
|
5932
5938
|
if (resettedIntent && !_forward) {
|
|
5933
5939
|
conversation = updateConversation(conversation, {
|
|
@@ -5936,27 +5942,20 @@ var Spirits = {
|
|
|
5936
5942
|
locked: false,
|
|
5937
5943
|
lockedReason: '',
|
|
5938
5944
|
lockAttempts: 0
|
|
5939
|
-
});
|
|
5940
|
-
progress('Reset conversation intent', 'info', 'UPDATE_CONVERSATION', {
|
|
5941
|
-
intent: null,
|
|
5942
|
-
intentScore: null,
|
|
5943
|
-
locked: false,
|
|
5944
|
-
lockAttempts: 0,
|
|
5945
|
-
lockedReason: ''
|
|
5946
|
-
});
|
|
5945
|
+
}, 'reset conversation intent');
|
|
5947
5946
|
}
|
|
5948
5947
|
|
|
5949
5948
|
// 5. Generate response
|
|
5950
5949
|
// If conversation previously locked, don't generate
|
|
5951
5950
|
if (input.conversation.locked) {
|
|
5952
|
-
_context5.next =
|
|
5951
|
+
_context5.next = 217;
|
|
5953
5952
|
break;
|
|
5954
5953
|
}
|
|
5955
5954
|
if (!((!conversation.locked || !hasNoInstructions) && !!hasNoCustomMessage)) {
|
|
5956
|
-
_context5.next =
|
|
5955
|
+
_context5.next = 180;
|
|
5957
5956
|
break;
|
|
5958
5957
|
}
|
|
5959
|
-
_context5.prev =
|
|
5958
|
+
_context5.prev = 164;
|
|
5960
5959
|
// progress('Generating message', 'info', 'SET_PROCESSING', 'system');
|
|
5961
5960
|
/** @type {import('@scout9/admin').GenerateRequestOneOf1} */
|
|
5962
5961
|
generatorInput = {
|
|
@@ -5969,9 +5968,9 @@ var Spirits = {
|
|
|
5969
5968
|
if (!!_tasks && Array.isArray(_tasks) && !!_tasks.length) {
|
|
5970
5969
|
generatorInput.tasks = _tasks;
|
|
5971
5970
|
}
|
|
5972
|
-
_context5.next =
|
|
5971
|
+
_context5.next = 169;
|
|
5973
5972
|
return wrapStep(generator(generatorInput), 'generate');
|
|
5974
|
-
case
|
|
5973
|
+
case 169:
|
|
5975
5974
|
generatorPayload = _context5.sent;
|
|
5976
5975
|
if (!generatorPayload.send) {
|
|
5977
5976
|
progress('Generated response send rejected', 'error', undefined, {
|
|
@@ -6076,26 +6075,26 @@ var Spirits = {
|
|
|
6076
6075
|
}
|
|
6077
6076
|
}
|
|
6078
6077
|
}
|
|
6079
|
-
_context5.next =
|
|
6078
|
+
_context5.next = 178;
|
|
6080
6079
|
break;
|
|
6081
|
-
case
|
|
6082
|
-
_context5.prev =
|
|
6083
|
-
_context5.t5 = _context5["catch"](
|
|
6080
|
+
case 173:
|
|
6081
|
+
_context5.prev = 173;
|
|
6082
|
+
_context5.t5 = _context5["catch"](164);
|
|
6084
6083
|
onError(_context5.t5);
|
|
6085
6084
|
console.error("Spirits: Locking conversation, error generating response: ".concat(_context5.t5.message));
|
|
6086
6085
|
conversation = lockConversation(conversation, 'API: ' + _context5.t5.message);
|
|
6087
|
-
case
|
|
6088
|
-
_context5.next =
|
|
6086
|
+
case 178:
|
|
6087
|
+
_context5.next = 181;
|
|
6089
6088
|
break;
|
|
6090
|
-
case
|
|
6089
|
+
case 180:
|
|
6091
6090
|
onStatus('generate', 'ignored');
|
|
6092
|
-
case
|
|
6091
|
+
case 181:
|
|
6093
6092
|
if (!(messagesToTransform.length && transformer)) {
|
|
6094
|
-
_context5.next =
|
|
6093
|
+
_context5.next = 214;
|
|
6095
6094
|
break;
|
|
6096
6095
|
}
|
|
6097
|
-
_context5.prev =
|
|
6098
|
-
_context5.next =
|
|
6096
|
+
_context5.prev = 182;
|
|
6097
|
+
_context5.next = 185;
|
|
6099
6098
|
return wrapStep(transformer({
|
|
6100
6099
|
// message: messagesToTransform,
|
|
6101
6100
|
addedMessages: messagesToTransform,
|
|
@@ -6104,15 +6103,16 @@ var Spirits = {
|
|
|
6104
6103
|
messages: messages,
|
|
6105
6104
|
context: context
|
|
6106
6105
|
}), 'transform');
|
|
6107
|
-
case
|
|
6106
|
+
case 185:
|
|
6108
6107
|
transformResponse = _context5.sent;
|
|
6109
6108
|
// @TODO check for duplicates, or have already sent the message
|
|
6110
6109
|
transformedMessages = (_transformResponse$me = transformResponse.messages) !== null && _transformResponse$me !== void 0 && _transformResponse$me.length ? transformResponse.messages : [{
|
|
6111
6110
|
role: 'agent',
|
|
6112
6111
|
content: transformResponse.message
|
|
6113
6112
|
}];
|
|
6113
|
+
appendedList = [];
|
|
6114
6114
|
_iterator9 = _rollupPluginBabelHelpers._createForOfIteratorHelper(transformedMessages);
|
|
6115
|
-
_context5.prev =
|
|
6115
|
+
_context5.prev = 189;
|
|
6116
6116
|
_loop = /*#__PURE__*/_rollupPluginBabelHelpers._regeneratorRuntime().mark(function _loop() {
|
|
6117
6117
|
var message, adjusted, prior, _adjusted$contentGene2, _adjusted$contentTran, appended;
|
|
6118
6118
|
return _rollupPluginBabelHelpers._regeneratorRuntime().wrap(function _loop$(_context2) {
|
|
@@ -6142,7 +6142,7 @@ var Spirits = {
|
|
|
6142
6142
|
adjusted.contentTransformed = adjusted.content;
|
|
6143
6143
|
}
|
|
6144
6144
|
appended = pushMessage(messages, adjusted);
|
|
6145
|
-
|
|
6145
|
+
appendedList.push(appended);
|
|
6146
6146
|
emitAddMessage(appended);
|
|
6147
6147
|
case 7:
|
|
6148
6148
|
case "end":
|
|
@@ -6151,52 +6151,53 @@ var Spirits = {
|
|
|
6151
6151
|
}, _loop);
|
|
6152
6152
|
});
|
|
6153
6153
|
_iterator9.s();
|
|
6154
|
-
case
|
|
6154
|
+
case 192:
|
|
6155
6155
|
if ((_step9 = _iterator9.n()).done) {
|
|
6156
|
-
_context5.next =
|
|
6156
|
+
_context5.next = 196;
|
|
6157
6157
|
break;
|
|
6158
6158
|
}
|
|
6159
|
-
return _context5.delegateYield(_loop(), "t6",
|
|
6160
|
-
case
|
|
6161
|
-
_context5.next =
|
|
6159
|
+
return _context5.delegateYield(_loop(), "t6", 194);
|
|
6160
|
+
case 194:
|
|
6161
|
+
_context5.next = 192;
|
|
6162
6162
|
break;
|
|
6163
|
-
case 191:
|
|
6164
|
-
_context5.next = 196;
|
|
6165
|
-
break;
|
|
6166
|
-
case 193:
|
|
6167
|
-
_context5.prev = 193;
|
|
6168
|
-
_context5.t7 = _context5["catch"](184);
|
|
6169
|
-
_iterator9.e(_context5.t7);
|
|
6170
6163
|
case 196:
|
|
6171
|
-
_context5.
|
|
6172
|
-
_iterator9.f();
|
|
6173
|
-
return _context5.finish(196);
|
|
6174
|
-
case 199:
|
|
6175
|
-
_context5.next = 206;
|
|
6164
|
+
_context5.next = 201;
|
|
6176
6165
|
break;
|
|
6166
|
+
case 198:
|
|
6167
|
+
_context5.prev = 198;
|
|
6168
|
+
_context5.t7 = _context5["catch"](189);
|
|
6169
|
+
_iterator9.e(_context5.t7);
|
|
6177
6170
|
case 201:
|
|
6178
6171
|
_context5.prev = 201;
|
|
6179
|
-
|
|
6172
|
+
_iterator9.f();
|
|
6173
|
+
return _context5.finish(201);
|
|
6174
|
+
case 204:
|
|
6175
|
+
progress("Added ".concat(appendedList.length, " persona message").concat(appendedList.length === 1 ? '' : 's'), "info", "ADD_MESSAGES", appendedList);
|
|
6176
|
+
_context5.next = 212;
|
|
6177
|
+
break;
|
|
6178
|
+
case 207:
|
|
6179
|
+
_context5.prev = 207;
|
|
6180
|
+
_context5.t8 = _context5["catch"](182);
|
|
6180
6181
|
console.error("Spirits: Locking conversation, error transforming response: ".concat(_context5.t8.message));
|
|
6181
6182
|
conversation = lockConversation(conversation, 'API: ' + _context5.t8.message);
|
|
6182
6183
|
onError(_context5.t8);
|
|
6183
|
-
case
|
|
6184
|
-
_context5.next =
|
|
6184
|
+
case 212:
|
|
6185
|
+
_context5.next = 215;
|
|
6185
6186
|
break;
|
|
6186
|
-
case
|
|
6187
|
+
case 214:
|
|
6187
6188
|
if (messagesToTransform.length) {
|
|
6188
6189
|
console.warn("Spirits: No transformer provided");
|
|
6189
6190
|
onStatus('transform', 'ignored');
|
|
6190
6191
|
} else {
|
|
6191
6192
|
onStatus('transform', 'ignored');
|
|
6192
6193
|
}
|
|
6193
|
-
case
|
|
6194
|
-
_context5.next =
|
|
6194
|
+
case 215:
|
|
6195
|
+
_context5.next = 219;
|
|
6195
6196
|
break;
|
|
6196
|
-
case
|
|
6197
|
+
case 217:
|
|
6197
6198
|
onStatus('generate', 'ignored');
|
|
6198
6199
|
onStatus('transform', 'ignored');
|
|
6199
|
-
case
|
|
6200
|
+
case 219:
|
|
6200
6201
|
emptySystemMessages = messages.filter(isEmptySystemMessage);
|
|
6201
6202
|
if (emptySystemMessages.length) {
|
|
6202
6203
|
progress('Empty system messages detected post-run', 'error', 'EMPTY_SYSTEM_MESSAGE_FINAL', {
|
|
@@ -6208,6 +6209,7 @@ var Spirits = {
|
|
|
6208
6209
|
console.error('Spirits: Empty system messages detected', emptySystemMessages);
|
|
6209
6210
|
}
|
|
6210
6211
|
logToolPairingIssues(messages, 'final');
|
|
6212
|
+
progress("Spirits.customer executed in ".concat(elapsedSeconds(rootStart), "s total"), 'success', undefined, undefined);
|
|
6211
6213
|
return _context5.abrupt("return", {
|
|
6212
6214
|
conversation: {
|
|
6213
6215
|
before: conversationBefore,
|
|
@@ -6230,11 +6232,11 @@ var Spirits = {
|
|
|
6230
6232
|
followup: followup,
|
|
6231
6233
|
entityContextUpsert: entityContextUpsert
|
|
6232
6234
|
});
|
|
6233
|
-
case
|
|
6235
|
+
case 224:
|
|
6234
6236
|
case "end":
|
|
6235
6237
|
return _context5.stop();
|
|
6236
6238
|
}
|
|
6237
|
-
}, _callee2, null, [[
|
|
6239
|
+
}, _callee2, null, [[69, 78, 81, 84], [95, 154, 157, 160], [133, 142, 145, 148], [164, 173], [182, 207], [189, 198, 201, 204]]);
|
|
6238
6240
|
}));
|
|
6239
6241
|
function customer(_x) {
|
|
6240
6242
|
return _customer.apply(this, arguments);
|
package/dist/spirits.cjs
CHANGED
package/dist/testing-tools.cjs
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var dev = require("./dev-
|
|
5
|
+
var dev = require("./dev-74c0ba94.cjs");
|
|
6
6
|
require("./_rollupPluginBabelHelpers-9c73c95c.cjs");
|
|
7
|
-
require("./spirits-
|
|
7
|
+
require("./spirits-c773fc77.cjs");
|
|
8
8
|
require('util');
|
|
9
9
|
require('stream');
|
|
10
10
|
require('path');
|
package/package.json
CHANGED
|
@@ -232,6 +232,9 @@ export const Spirits = {
|
|
|
232
232
|
onDeleteMessage = (_id) => { },
|
|
233
233
|
} = input;
|
|
234
234
|
let { conversation, messages, context, message } = input;
|
|
235
|
+
const elapsedSeconds = (start) => ((performance.now() - start) / 1000).toFixed(2);
|
|
236
|
+
const rootStart = performance.now();
|
|
237
|
+
progress(`Spirits.customer start`, 'info', undefined, undefined);
|
|
235
238
|
|
|
236
239
|
if (typeof message.content !== 'string') {
|
|
237
240
|
const err = new Error(
|
|
@@ -326,8 +329,9 @@ export const Spirits = {
|
|
|
326
329
|
m?.role === 'system' &&
|
|
327
330
|
(typeof m.content !== 'string' || m.content.trim() === '');
|
|
328
331
|
|
|
329
|
-
const updateConversation = (previousConversation, conversationUpdates) => {
|
|
330
|
-
|
|
332
|
+
const updateConversation = (previousConversation, conversationUpdates, note) => {
|
|
333
|
+
const _note = [`Updated conversation fields`, note].filter(Boolean).join(', ')
|
|
334
|
+
progress(`${_note}: ${JSON.stringify(Object.keys(conversationUpdates))}`, 'info', 'UPDATE_CONVERSATION', conversationUpdates);
|
|
331
335
|
emitUpdateConversation(conversationUpdates);
|
|
332
336
|
return {
|
|
333
337
|
...previousConversation,
|
|
@@ -335,8 +339,9 @@ export const Spirits = {
|
|
|
335
339
|
};
|
|
336
340
|
};
|
|
337
341
|
|
|
338
|
-
const updateContext = (previousContext, newContext) => {
|
|
339
|
-
|
|
342
|
+
const updateContext = (previousContext, newContext, note) => {
|
|
343
|
+
const _note = [`Updated context fields`, note].filter(Boolean).join(', ')
|
|
344
|
+
progress(`${_note}: ${JSON.stringify(Object.keys(newContext))}`, 'info', 'UPDATE_CONTEXT', newContext);
|
|
340
345
|
emitUpdateContext(newContext);
|
|
341
346
|
return {
|
|
342
347
|
...previousContext,
|
|
@@ -356,7 +361,8 @@ export const Spirits = {
|
|
|
356
361
|
const lockConversation = (_conversation, reason) => {
|
|
357
362
|
return updateConversation(
|
|
358
363
|
_conversation,
|
|
359
|
-
{ locked: true, lockedReason: _conversation.lockedReason || reason || 'Unknown' }
|
|
364
|
+
{ locked: true, lockedReason: _conversation.lockedReason || reason || 'Unknown' },
|
|
365
|
+
'lock conversation'
|
|
360
366
|
);
|
|
361
367
|
};
|
|
362
368
|
|
|
@@ -372,8 +378,8 @@ export const Spirits = {
|
|
|
372
378
|
patch.locked = true;
|
|
373
379
|
patch.lockedReason = `Max lock attempts exceeded (${next} > ${max})`;
|
|
374
380
|
}
|
|
375
|
-
const updated = updateConversation(_conversation, patch);
|
|
376
|
-
return updated
|
|
381
|
+
const updated = updateConversation(_conversation, patch, 'increment lock');
|
|
382
|
+
return {updated, patch}
|
|
377
383
|
};
|
|
378
384
|
|
|
379
385
|
const _addInstruction = (
|
|
@@ -387,7 +393,7 @@ export const Spirits = {
|
|
|
387
393
|
const systemMessages = _messages.filter(m => m.role === 'system');
|
|
388
394
|
const lastSystemMessage = systemMessages[systemMessages.length - 1];
|
|
389
395
|
let addedMessage = false;
|
|
390
|
-
let changedConversation =
|
|
396
|
+
let changedConversation = [];
|
|
391
397
|
|
|
392
398
|
// If instruction does not equal previous system message, add it, otherwise lock attempt
|
|
393
399
|
if (!lastSystemMessage || instruction !== lastSystemMessage.content) {
|
|
@@ -410,8 +416,9 @@ export const Spirits = {
|
|
|
410
416
|
// Handle repeated instruction
|
|
411
417
|
// Increment lock attempt if instructions are repeated and we haven't already incremented lock attempt (for example if a forward is provided)
|
|
412
418
|
if (previousLockAttempt === (_conversation.lockAttempts || 0)) {
|
|
413
|
-
|
|
414
|
-
|
|
419
|
+
const {updated, patch} = incrementLockAttempt(_conversation, _config);
|
|
420
|
+
_conversation = updated;
|
|
421
|
+
changedConversation = Object.keys(patch);
|
|
415
422
|
}
|
|
416
423
|
}
|
|
417
424
|
return {
|
|
@@ -422,6 +429,7 @@ export const Spirits = {
|
|
|
422
429
|
};
|
|
423
430
|
};
|
|
424
431
|
|
|
432
|
+
let instructionsAdded = 0;
|
|
425
433
|
const addInstruction = (instruction, previousLockAttempt, id = idGenerator('sys')) => {
|
|
426
434
|
const {
|
|
427
435
|
conversation: newConversation,
|
|
@@ -432,10 +440,11 @@ export const Spirits = {
|
|
|
432
440
|
conversation = newConversation;
|
|
433
441
|
messages = newMessages;
|
|
434
442
|
if (addedMessage) {
|
|
435
|
-
|
|
443
|
+
instructionsAdded++;
|
|
444
|
+
progress(`Added ${instructionsAdded} instruction${instructionsAdded === 1 ? '' : 's'}`, 'info', 'ADD_MESSAGE', newMessages[newMessages.length - 1]);
|
|
436
445
|
}
|
|
437
|
-
if (changedConversation) {
|
|
438
|
-
progress(
|
|
446
|
+
if (changedConversation.length) {
|
|
447
|
+
progress(`Updated conversation fields: ${JSON.stringify(changedConversation)}`, 'info', 'UPDATE_CONVERSATION', newConversation);
|
|
439
448
|
}
|
|
440
449
|
};
|
|
441
450
|
|
|
@@ -454,18 +463,17 @@ export const Spirits = {
|
|
|
454
463
|
* @param {string} stepAction - overrides step name in logs
|
|
455
464
|
*/
|
|
456
465
|
const wrapStep = async (prom, step, stepAction = step) => {
|
|
457
|
-
const
|
|
458
|
-
const elapsedSeconds = () => ((performance.now() - start) / 1000).toFixed(2);
|
|
466
|
+
const stepStart = performance.now();
|
|
459
467
|
|
|
460
468
|
try {
|
|
461
469
|
progress(`${stepAction} start`, 'info', undefined, undefined);
|
|
462
470
|
const result = await prom;
|
|
463
|
-
progress(`${stepAction} succeeded in ${elapsedSeconds()}s`, 'success', undefined, undefined);
|
|
471
|
+
progress(`${stepAction} succeeded in ${elapsedSeconds(stepStart)}s`, 'success', undefined, undefined);
|
|
464
472
|
return result;
|
|
465
473
|
} catch (error) {
|
|
466
474
|
const msg = error?.message || 'UNHANDLED ERROR';
|
|
467
475
|
progress(
|
|
468
|
-
`${stepAction} failed in ${elapsedSeconds()}s`,
|
|
476
|
+
`${stepAction} failed in ${elapsedSeconds(stepStart)}s`,
|
|
469
477
|
'error',
|
|
470
478
|
undefined,
|
|
471
479
|
{ error: msg }
|
|
@@ -537,7 +545,7 @@ export const Spirits = {
|
|
|
537
545
|
message = _message;
|
|
538
546
|
message = pushMessage(messages, _message);
|
|
539
547
|
emitAddMessage(message);
|
|
540
|
-
progress(
|
|
548
|
+
progress(`Added "${_message.role}" message`, 'info', 'ADD_MESSAGE', _message);
|
|
541
549
|
} else {
|
|
542
550
|
messages[index].context = parsePayload.context;
|
|
543
551
|
messages[index].entities = parsePayload.entities;
|
|
@@ -548,14 +556,16 @@ export const Spirits = {
|
|
|
548
556
|
messages[index].intentScore = parsePayload.intentScore;
|
|
549
557
|
}
|
|
550
558
|
message = messages[index];
|
|
551
|
-
|
|
559
|
+
const patch = {
|
|
552
560
|
id: messages[index].id,
|
|
553
561
|
context: parsePayload.context,
|
|
554
562
|
entities: parsePayload.entities,
|
|
555
563
|
...(parsePayload.intent ? { intent: parsePayload.intent } : {}),
|
|
556
564
|
...(typeof parsePayload.intentScore === 'number' ? { intentScore: parsePayload.intentScore } : {}),
|
|
557
|
-
}
|
|
558
|
-
|
|
565
|
+
};
|
|
566
|
+
emitUpdateMessage(patch);
|
|
567
|
+
const {id, ...updatedFields} = patch;
|
|
568
|
+
progress(`updated ${id} message fields ${JSON.stringify(Object.keys(updatedFields))}`, 'info', 'UPDATE_MESSAGE', message);
|
|
559
569
|
}
|
|
560
570
|
// If this is the first user message, then update conversations intent
|
|
561
571
|
const previousUserMessages = messages.filter(m => m.role === 'customer' && m.content !== message.content);
|
|
@@ -563,13 +573,7 @@ export const Spirits = {
|
|
|
563
573
|
conversation = updateConversation(conversation, {
|
|
564
574
|
intent: parsePayload.intent,
|
|
565
575
|
intentScore: parsePayload?.intentScore || 0,
|
|
566
|
-
});
|
|
567
|
-
progress(
|
|
568
|
-
'Updated conversation intent',
|
|
569
|
-
'info',
|
|
570
|
-
'UPDATE_CONVERSATION',
|
|
571
|
-
{ intent: parsePayload.intent, intentScore: parsePayload?.intentScore || 0 }
|
|
572
|
-
);
|
|
576
|
+
}, 'intent mapping');
|
|
573
577
|
}
|
|
574
578
|
const oldKeyCount = Object.keys(context).length;
|
|
575
579
|
context = updateContext(context, parsePayload.context);
|
|
@@ -581,8 +585,7 @@ export const Spirits = {
|
|
|
581
585
|
locked: false,
|
|
582
586
|
lockAttempts: 0,
|
|
583
587
|
lockedReason: '',
|
|
584
|
-
});
|
|
585
|
-
progress('Reset lock', 'info', 'UPDATE_CONVERSATION', { locked: false, lockAttempts: 0, lockedReason: '' });
|
|
588
|
+
}, 'reset lock attempts');
|
|
586
589
|
}
|
|
587
590
|
|
|
588
591
|
const noNewContext = Object.keys(parsePayload.context).length === 0;
|
|
@@ -624,7 +627,7 @@ export const Spirits = {
|
|
|
624
627
|
});
|
|
625
628
|
} else if (!messages.find(mes => messageKey(mes) === messageKey(contextMessage))) {
|
|
626
629
|
emitAddMessage(pushMessage(messages, contextMessage));
|
|
627
|
-
progress(`Added context`, 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
|
|
630
|
+
progress(`Added context ${message.role} message`, 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
|
|
628
631
|
} else {
|
|
629
632
|
progress(`Already have system context, skipping`, 'info');
|
|
630
633
|
}
|
|
@@ -716,14 +719,13 @@ export const Spirits = {
|
|
|
716
719
|
const previousLockAttempt = conversation.lockAttempts || 0; // Used to track
|
|
717
720
|
|
|
718
721
|
if (hasNoInstructions && noNewContext) {
|
|
719
|
-
conversation = incrementLockAttempt(conversation, config);
|
|
722
|
+
conversation = incrementLockAttempt(conversation, config).updated;
|
|
720
723
|
} else {
|
|
721
724
|
conversation = updateConversation(conversation, {
|
|
722
725
|
lockAttempts: 0,
|
|
723
726
|
locked: false,
|
|
724
727
|
lockedReason: '',
|
|
725
|
-
});
|
|
726
|
-
progress('Reset lock', 'info', 'UPDATE_CONVERSATION', { lockAttempts: 0, locked: false, lockedReason: '' });
|
|
728
|
+
}, 'reset lock');
|
|
727
729
|
}
|
|
728
730
|
|
|
729
731
|
let resettedIntent = false;
|
|
@@ -768,7 +770,7 @@ export const Spirits = {
|
|
|
768
770
|
type: 'literal',
|
|
769
771
|
slots,
|
|
770
772
|
map
|
|
771
|
-
});
|
|
773
|
+
}, 'anticipation slots');
|
|
772
774
|
} else if ('yes' in anticipate && 'no' in anticipate && 'did' in anticipate) {
|
|
773
775
|
// "did" anticipation
|
|
774
776
|
conversation = updateConversation(conversation, {
|
|
@@ -778,7 +780,7 @@ export const Spirits = {
|
|
|
778
780
|
no: anticipate.no
|
|
779
781
|
},
|
|
780
782
|
did: anticipate.did
|
|
781
|
-
});
|
|
783
|
+
}, 'anticipation slots');
|
|
782
784
|
} else {
|
|
783
785
|
throw new Error(`Invalid anticipate payload "${JSON.stringify(anticipate)}"`);
|
|
784
786
|
}
|
|
@@ -804,7 +806,7 @@ export const Spirits = {
|
|
|
804
806
|
_forward = forward;
|
|
805
807
|
_forwardNote = forwardNote;
|
|
806
808
|
if (typeof forward === 'string') {
|
|
807
|
-
conversation = updateConversation(conversation, { forwarded: forward });
|
|
809
|
+
conversation = updateConversation(conversation, { forwarded: forward }, 'forward');
|
|
808
810
|
emitAddMessage(pushMessage(messages, {
|
|
809
811
|
id: idGenerator("sys"),
|
|
810
812
|
role: "system",
|
|
@@ -813,7 +815,7 @@ export const Spirits = {
|
|
|
813
815
|
}));
|
|
814
816
|
progress(`Forwarded to "${forward}"`, 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
|
|
815
817
|
} else if (typeof forward === 'boolean') {
|
|
816
|
-
conversation = updateConversation(conversation, { forwarded: conversation.$agent });
|
|
818
|
+
conversation = updateConversation(conversation, { forwarded: conversation.$agent }, 'forward');
|
|
817
819
|
emitAddMessage(pushMessage(messages, {
|
|
818
820
|
id: idGenerator("sys"),
|
|
819
821
|
role: "system",
|
|
@@ -823,7 +825,7 @@ export const Spirits = {
|
|
|
823
825
|
progress(`Forwarded to agent`, 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
|
|
824
826
|
|
|
825
827
|
} else {
|
|
826
|
-
conversation = updateConversation(conversation, { forwarded: forward.to });
|
|
828
|
+
conversation = updateConversation(conversation, { forwarded: forward.to }, 'forward');
|
|
827
829
|
emitAddMessage(pushMessage(messages, {
|
|
828
830
|
id: idGenerator("sys"),
|
|
829
831
|
role: "system",
|
|
@@ -912,7 +914,6 @@ export const Spirits = {
|
|
|
912
914
|
|
|
913
915
|
if (contextUpsert) {
|
|
914
916
|
context = updateContext(context, contextUpsert);
|
|
915
|
-
progress('Upserted context', 'info', 'UPDATE_CONTEXT', contextUpsert);
|
|
916
917
|
}
|
|
917
918
|
|
|
918
919
|
if (resetIntent) {
|
|
@@ -930,13 +931,7 @@ export const Spirits = {
|
|
|
930
931
|
locked: false,
|
|
931
932
|
lockedReason: '',
|
|
932
933
|
lockAttempts: 0,
|
|
933
|
-
});
|
|
934
|
-
progress(
|
|
935
|
-
'Reset conversation intent',
|
|
936
|
-
'info',
|
|
937
|
-
'UPDATE_CONVERSATION',
|
|
938
|
-
{ intent: null, intentScore: null, locked: false, lockAttempts: 0, lockedReason: '' }
|
|
939
|
-
);
|
|
934
|
+
}, 'reset conversation intent');
|
|
940
935
|
}
|
|
941
936
|
|
|
942
937
|
// 5. Generate response
|
|
@@ -1101,6 +1096,7 @@ export const Spirits = {
|
|
|
1101
1096
|
? transformResponse.messages
|
|
1102
1097
|
: [{ role: 'agent', content: transformResponse.message }];
|
|
1103
1098
|
|
|
1099
|
+
const appendedList = [];
|
|
1104
1100
|
for (const message of transformedMessages) {
|
|
1105
1101
|
const adjusted = {
|
|
1106
1102
|
id: idGenerator('agent'),
|
|
@@ -1127,10 +1123,12 @@ export const Spirits = {
|
|
|
1127
1123
|
}
|
|
1128
1124
|
|
|
1129
1125
|
const appended = pushMessage(messages, adjusted);
|
|
1130
|
-
|
|
1126
|
+
appendedList.push(appended);
|
|
1131
1127
|
emitAddMessage(appended);
|
|
1132
1128
|
}
|
|
1133
1129
|
|
|
1130
|
+
progress(`Added ${appendedList.length} persona message${appendedList.length === 1 ? '' : 's'}`, "info", "ADD_MESSAGES", appendedList);
|
|
1131
|
+
|
|
1134
1132
|
} catch (e) {
|
|
1135
1133
|
console.error(`Spirits: Locking conversation, error transforming response: ${e.message}`);
|
|
1136
1134
|
conversation = lockConversation(conversation, 'API: ' + e.message);
|
|
@@ -1158,6 +1156,8 @@ export const Spirits = {
|
|
|
1158
1156
|
|
|
1159
1157
|
logToolPairingIssues(messages, 'final');
|
|
1160
1158
|
|
|
1159
|
+
progress(`Spirits.customer executed in ${elapsedSeconds(rootStart)}s total`, 'success', undefined, undefined);
|
|
1160
|
+
|
|
1161
1161
|
return {
|
|
1162
1162
|
conversation: {
|
|
1163
1163
|
before: conversationBefore,
|