@scout9/app 1.0.0-alpha.0.8.8 → 1.0.0-alpha.0.9.0

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.
@@ -1,1734 +0,0 @@
1
- 'use strict';
2
-
3
- function _iterableToArrayLimit(r, l) {
4
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
5
- if (null != t) {
6
- var e,
7
- n,
8
- i,
9
- u,
10
- a = [],
11
- f = !0,
12
- o = !1;
13
- try {
14
- if (i = (t = t.call(r)).next, 0 === l) {
15
- if (Object(t) !== t) return;
16
- f = !1;
17
- } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
18
- } catch (r) {
19
- o = !0, n = r;
20
- } finally {
21
- try {
22
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
23
- } finally {
24
- if (o) throw n;
25
- }
26
- }
27
- return a;
28
- }
29
- }
30
- function ownKeys(e, r) {
31
- var t = Object.keys(e);
32
- if (Object.getOwnPropertySymbols) {
33
- var o = Object.getOwnPropertySymbols(e);
34
- r && (o = o.filter(function (r) {
35
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
36
- })), t.push.apply(t, o);
37
- }
38
- return t;
39
- }
40
- function _objectSpread2(e) {
41
- for (var r = 1; r < arguments.length; r++) {
42
- var t = null != arguments[r] ? arguments[r] : {};
43
- r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
44
- _defineProperty(e, r, t[r]);
45
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
46
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
47
- });
48
- }
49
- return e;
50
- }
51
- function _regeneratorRuntime() {
52
- _regeneratorRuntime = function () {
53
- return e;
54
- };
55
- var t,
56
- e = {},
57
- r = Object.prototype,
58
- n = r.hasOwnProperty,
59
- o = Object.defineProperty || function (t, e, r) {
60
- t[e] = r.value;
61
- },
62
- i = "function" == typeof Symbol ? Symbol : {},
63
- a = i.iterator || "@@iterator",
64
- c = i.asyncIterator || "@@asyncIterator",
65
- u = i.toStringTag || "@@toStringTag";
66
- function define(t, e, r) {
67
- return Object.defineProperty(t, e, {
68
- value: r,
69
- enumerable: !0,
70
- configurable: !0,
71
- writable: !0
72
- }), t[e];
73
- }
74
- try {
75
- define({}, "");
76
- } catch (t) {
77
- define = function (t, e, r) {
78
- return t[e] = r;
79
- };
80
- }
81
- function wrap(t, e, r, n) {
82
- var i = e && e.prototype instanceof Generator ? e : Generator,
83
- a = Object.create(i.prototype),
84
- c = new Context(n || []);
85
- return o(a, "_invoke", {
86
- value: makeInvokeMethod(t, r, c)
87
- }), a;
88
- }
89
- function tryCatch(t, e, r) {
90
- try {
91
- return {
92
- type: "normal",
93
- arg: t.call(e, r)
94
- };
95
- } catch (t) {
96
- return {
97
- type: "throw",
98
- arg: t
99
- };
100
- }
101
- }
102
- e.wrap = wrap;
103
- var h = "suspendedStart",
104
- l = "suspendedYield",
105
- f = "executing",
106
- s = "completed",
107
- y = {};
108
- function Generator() {}
109
- function GeneratorFunction() {}
110
- function GeneratorFunctionPrototype() {}
111
- var p = {};
112
- define(p, a, function () {
113
- return this;
114
- });
115
- var d = Object.getPrototypeOf,
116
- v = d && d(d(values([])));
117
- v && v !== r && n.call(v, a) && (p = v);
118
- var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
119
- function defineIteratorMethods(t) {
120
- ["next", "throw", "return"].forEach(function (e) {
121
- define(t, e, function (t) {
122
- return this._invoke(e, t);
123
- });
124
- });
125
- }
126
- function AsyncIterator(t, e) {
127
- function invoke(r, o, i, a) {
128
- var c = tryCatch(t[r], t, o);
129
- if ("throw" !== c.type) {
130
- var u = c.arg,
131
- h = u.value;
132
- return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
133
- invoke("next", t, i, a);
134
- }, function (t) {
135
- invoke("throw", t, i, a);
136
- }) : e.resolve(h).then(function (t) {
137
- u.value = t, i(u);
138
- }, function (t) {
139
- return invoke("throw", t, i, a);
140
- });
141
- }
142
- a(c.arg);
143
- }
144
- var r;
145
- o(this, "_invoke", {
146
- value: function (t, n) {
147
- function callInvokeWithMethodAndArg() {
148
- return new e(function (e, r) {
149
- invoke(t, n, e, r);
150
- });
151
- }
152
- return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
153
- }
154
- });
155
- }
156
- function makeInvokeMethod(e, r, n) {
157
- var o = h;
158
- return function (i, a) {
159
- if (o === f) throw new Error("Generator is already running");
160
- if (o === s) {
161
- if ("throw" === i) throw a;
162
- return {
163
- value: t,
164
- done: !0
165
- };
166
- }
167
- for (n.method = i, n.arg = a;;) {
168
- var c = n.delegate;
169
- if (c) {
170
- var u = maybeInvokeDelegate(c, n);
171
- if (u) {
172
- if (u === y) continue;
173
- return u;
174
- }
175
- }
176
- if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
177
- if (o === h) throw o = s, n.arg;
178
- n.dispatchException(n.arg);
179
- } else "return" === n.method && n.abrupt("return", n.arg);
180
- o = f;
181
- var p = tryCatch(e, r, n);
182
- if ("normal" === p.type) {
183
- if (o = n.done ? s : l, p.arg === y) continue;
184
- return {
185
- value: p.arg,
186
- done: n.done
187
- };
188
- }
189
- "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
190
- }
191
- };
192
- }
193
- function maybeInvokeDelegate(e, r) {
194
- var n = r.method,
195
- o = e.iterator[n];
196
- if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
197
- var i = tryCatch(o, e.iterator, r.arg);
198
- if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
199
- var a = i.arg;
200
- return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
201
- }
202
- function pushTryEntry(t) {
203
- var e = {
204
- tryLoc: t[0]
205
- };
206
- 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
207
- }
208
- function resetTryEntry(t) {
209
- var e = t.completion || {};
210
- e.type = "normal", delete e.arg, t.completion = e;
211
- }
212
- function Context(t) {
213
- this.tryEntries = [{
214
- tryLoc: "root"
215
- }], t.forEach(pushTryEntry, this), this.reset(!0);
216
- }
217
- function values(e) {
218
- if (e || "" === e) {
219
- var r = e[a];
220
- if (r) return r.call(e);
221
- if ("function" == typeof e.next) return e;
222
- if (!isNaN(e.length)) {
223
- var o = -1,
224
- i = function next() {
225
- for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
226
- return next.value = t, next.done = !0, next;
227
- };
228
- return i.next = i;
229
- }
230
- }
231
- throw new TypeError(typeof e + " is not iterable");
232
- }
233
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
234
- value: GeneratorFunctionPrototype,
235
- configurable: !0
236
- }), o(GeneratorFunctionPrototype, "constructor", {
237
- value: GeneratorFunction,
238
- configurable: !0
239
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
240
- var e = "function" == typeof t && t.constructor;
241
- return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
242
- }, e.mark = function (t) {
243
- return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
244
- }, e.awrap = function (t) {
245
- return {
246
- __await: t
247
- };
248
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
249
- return this;
250
- }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
251
- void 0 === i && (i = Promise);
252
- var a = new AsyncIterator(wrap(t, r, n, o), i);
253
- return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
254
- return t.done ? t.value : a.next();
255
- });
256
- }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
257
- return this;
258
- }), define(g, "toString", function () {
259
- return "[object Generator]";
260
- }), e.keys = function (t) {
261
- var e = Object(t),
262
- r = [];
263
- for (var n in e) r.push(n);
264
- return r.reverse(), function next() {
265
- for (; r.length;) {
266
- var t = r.pop();
267
- if (t in e) return next.value = t, next.done = !1, next;
268
- }
269
- return next.done = !0, next;
270
- };
271
- }, e.values = values, Context.prototype = {
272
- constructor: Context,
273
- reset: function (e) {
274
- if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
275
- },
276
- stop: function () {
277
- this.done = !0;
278
- var t = this.tryEntries[0].completion;
279
- if ("throw" === t.type) throw t.arg;
280
- return this.rval;
281
- },
282
- dispatchException: function (e) {
283
- if (this.done) throw e;
284
- var r = this;
285
- function handle(n, o) {
286
- return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
287
- }
288
- for (var o = this.tryEntries.length - 1; o >= 0; --o) {
289
- var i = this.tryEntries[o],
290
- a = i.completion;
291
- if ("root" === i.tryLoc) return handle("end");
292
- if (i.tryLoc <= this.prev) {
293
- var c = n.call(i, "catchLoc"),
294
- u = n.call(i, "finallyLoc");
295
- if (c && u) {
296
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
297
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
298
- } else if (c) {
299
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
300
- } else {
301
- if (!u) throw new Error("try statement without catch or finally");
302
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
303
- }
304
- }
305
- }
306
- },
307
- abrupt: function (t, e) {
308
- for (var r = this.tryEntries.length - 1; r >= 0; --r) {
309
- var o = this.tryEntries[r];
310
- if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
311
- var i = o;
312
- break;
313
- }
314
- }
315
- i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
316
- var a = i ? i.completion : {};
317
- return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
318
- },
319
- complete: function (t, e) {
320
- if ("throw" === t.type) throw t.arg;
321
- return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
322
- },
323
- finish: function (t) {
324
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
325
- var r = this.tryEntries[e];
326
- if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
327
- }
328
- },
329
- catch: function (t) {
330
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
331
- var r = this.tryEntries[e];
332
- if (r.tryLoc === t) {
333
- var n = r.completion;
334
- if ("throw" === n.type) {
335
- var o = n.arg;
336
- resetTryEntry(r);
337
- }
338
- return o;
339
- }
340
- }
341
- throw new Error("illegal catch attempt");
342
- },
343
- delegateYield: function (e, r, n) {
344
- return this.delegate = {
345
- iterator: values(e),
346
- resultName: r,
347
- nextLoc: n
348
- }, "next" === this.method && (this.arg = t), y;
349
- }
350
- }, e;
351
- }
352
- function _toPrimitive(t, r) {
353
- if ("object" != typeof t || !t) return t;
354
- var e = t[Symbol.toPrimitive];
355
- if (void 0 !== e) {
356
- var i = e.call(t, r || "default");
357
- if ("object" != typeof i) return i;
358
- throw new TypeError("@@toPrimitive must return a primitive value.");
359
- }
360
- return ("string" === r ? String : Number)(t);
361
- }
362
- function _toPropertyKey(t) {
363
- var i = _toPrimitive(t, "string");
364
- return "symbol" == typeof i ? i : String(i);
365
- }
366
- function _typeof(o) {
367
- "@babel/helpers - typeof";
368
-
369
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
370
- return typeof o;
371
- } : function (o) {
372
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
373
- }, _typeof(o);
374
- }
375
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
376
- try {
377
- var info = gen[key](arg);
378
- var value = info.value;
379
- } catch (error) {
380
- reject(error);
381
- return;
382
- }
383
- if (info.done) {
384
- resolve(value);
385
- } else {
386
- Promise.resolve(value).then(_next, _throw);
387
- }
388
- }
389
- function _asyncToGenerator(fn) {
390
- return function () {
391
- var self = this,
392
- args = arguments;
393
- return new Promise(function (resolve, reject) {
394
- var gen = fn.apply(self, args);
395
- function _next(value) {
396
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
397
- }
398
- function _throw(err) {
399
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
400
- }
401
- _next(undefined);
402
- });
403
- };
404
- }
405
- function _classCallCheck(instance, Constructor) {
406
- if (!(instance instanceof Constructor)) {
407
- throw new TypeError("Cannot call a class as a function");
408
- }
409
- }
410
- function _defineProperties(target, props) {
411
- for (var i = 0; i < props.length; i++) {
412
- var descriptor = props[i];
413
- descriptor.enumerable = descriptor.enumerable || false;
414
- descriptor.configurable = true;
415
- if ("value" in descriptor) descriptor.writable = true;
416
- Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
417
- }
418
- }
419
- function _createClass(Constructor, protoProps, staticProps) {
420
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
421
- if (staticProps) _defineProperties(Constructor, staticProps);
422
- Object.defineProperty(Constructor, "prototype", {
423
- writable: false
424
- });
425
- return Constructor;
426
- }
427
- function _defineProperty(obj, key, value) {
428
- key = _toPropertyKey(key);
429
- if (key in obj) {
430
- Object.defineProperty(obj, key, {
431
- value: value,
432
- enumerable: true,
433
- configurable: true,
434
- writable: true
435
- });
436
- } else {
437
- obj[key] = value;
438
- }
439
- return obj;
440
- }
441
- function _objectWithoutPropertiesLoose(source, excluded) {
442
- if (source == null) return {};
443
- var target = {};
444
- var sourceKeys = Object.keys(source);
445
- var key, i;
446
- for (i = 0; i < sourceKeys.length; i++) {
447
- key = sourceKeys[i];
448
- if (excluded.indexOf(key) >= 0) continue;
449
- target[key] = source[key];
450
- }
451
- return target;
452
- }
453
- function _objectWithoutProperties(source, excluded) {
454
- if (source == null) return {};
455
- var target = _objectWithoutPropertiesLoose(source, excluded);
456
- var key, i;
457
- if (Object.getOwnPropertySymbols) {
458
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
459
- for (i = 0; i < sourceSymbolKeys.length; i++) {
460
- key = sourceSymbolKeys[i];
461
- if (excluded.indexOf(key) >= 0) continue;
462
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
463
- target[key] = source[key];
464
- }
465
- }
466
- return target;
467
- }
468
- function _slicedToArray(arr, i) {
469
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
470
- }
471
- function _toConsumableArray(arr) {
472
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
473
- }
474
- function _arrayWithoutHoles(arr) {
475
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
476
- }
477
- function _arrayWithHoles(arr) {
478
- if (Array.isArray(arr)) return arr;
479
- }
480
- function _iterableToArray(iter) {
481
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
482
- }
483
- function _unsupportedIterableToArray(o, minLen) {
484
- if (!o) return;
485
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
486
- var n = Object.prototype.toString.call(o).slice(8, -1);
487
- if (n === "Object" && o.constructor) n = o.constructor.name;
488
- if (n === "Map" || n === "Set") return Array.from(o);
489
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
490
- }
491
- function _arrayLikeToArray(arr, len) {
492
- if (len == null || len > arr.length) len = arr.length;
493
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
494
- return arr2;
495
- }
496
- function _nonIterableSpread() {
497
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
498
- }
499
- function _nonIterableRest() {
500
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
501
- }
502
- function _createForOfIteratorHelper(o, allowArrayLike) {
503
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
504
- if (!it) {
505
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
506
- if (it) o = it;
507
- var i = 0;
508
- var F = function () {};
509
- return {
510
- s: F,
511
- n: function () {
512
- if (i >= o.length) return {
513
- done: true
514
- };
515
- return {
516
- done: false,
517
- value: o[i++]
518
- };
519
- },
520
- e: function (e) {
521
- throw e;
522
- },
523
- f: F
524
- };
525
- }
526
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
527
- }
528
- var normalCompletion = true,
529
- didErr = false,
530
- err;
531
- return {
532
- s: function () {
533
- it = it.call(o);
534
- },
535
- n: function () {
536
- var step = it.next();
537
- normalCompletion = step.done;
538
- return step;
539
- },
540
- e: function (e) {
541
- didErr = true;
542
- err = e;
543
- },
544
- f: function () {
545
- try {
546
- if (!normalCompletion && it.return != null) it.return();
547
- } finally {
548
- if (didErr) throw err;
549
- }
550
- }
551
- };
552
- }
553
- function _classPrivateFieldGet(receiver, privateMap) {
554
- var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
555
- return _classApplyDescriptorGet(receiver, descriptor);
556
- }
557
- function _classPrivateFieldSet(receiver, privateMap, value) {
558
- var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set");
559
- _classApplyDescriptorSet(receiver, descriptor, value);
560
- return value;
561
- }
562
- function _classExtractFieldDescriptor(receiver, privateMap, action) {
563
- if (!privateMap.has(receiver)) {
564
- throw new TypeError("attempted to " + action + " private field on non-instance");
565
- }
566
- return privateMap.get(receiver);
567
- }
568
- function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) {
569
- _classCheckPrivateStaticAccess(receiver, classConstructor);
570
- _classCheckPrivateStaticFieldDescriptor(descriptor, "get");
571
- return _classApplyDescriptorGet(receiver, descriptor);
572
- }
573
- function _classApplyDescriptorGet(receiver, descriptor) {
574
- if (descriptor.get) {
575
- return descriptor.get.call(receiver);
576
- }
577
- return descriptor.value;
578
- }
579
- function _classApplyDescriptorSet(receiver, descriptor, value) {
580
- if (descriptor.set) {
581
- descriptor.set.call(receiver, value);
582
- } else {
583
- if (!descriptor.writable) {
584
- throw new TypeError("attempted to set read only private field");
585
- }
586
- descriptor.value = value;
587
- }
588
- }
589
- function _classCheckPrivateStaticAccess(receiver, classConstructor) {
590
- if (receiver !== classConstructor) {
591
- throw new TypeError("Private static access of wrong provenance");
592
- }
593
- }
594
- function _classCheckPrivateStaticFieldDescriptor(descriptor, action) {
595
- if (descriptor === undefined) {
596
- throw new TypeError("attempted to " + action + " private static field before its declaration");
597
- }
598
- }
599
- function _classPrivateMethodGet(receiver, privateSet, fn) {
600
- if (!privateSet.has(receiver)) {
601
- throw new TypeError("attempted to get private field on non-instance");
602
- }
603
- return fn;
604
- }
605
- function _checkPrivateRedeclaration(obj, privateCollection) {
606
- if (privateCollection.has(obj)) {
607
- throw new TypeError("Cannot initialize the same private elements twice on an object");
608
- }
609
- }
610
- function _classPrivateFieldInitSpec(obj, privateMap, value) {
611
- _checkPrivateRedeclaration(obj, privateMap);
612
- privateMap.set(obj, value);
613
- }
614
- function _classPrivateMethodInitSpec(obj, privateSet) {
615
- _checkPrivateRedeclaration(obj, privateSet);
616
- privateSet.add(obj);
617
- }
618
-
619
- var _excluded = ["keywords"];
620
- /**
621
- * @typedef {Object} Document
622
- * @property {string} id
623
- */
624
-
625
- /**
626
- * Represents a change with before and after states of a given type.
627
- * @template Type The type of the before and after properties.
628
- * @typedef {Object} Change
629
- * @property {Type} before - The state before the change.
630
- * @property {Type} after - The state after the change.
631
- */
632
-
633
- /**
634
- * @typedef {Object} ConversationData
635
- * @property {import('@scout9/app').Scout9ProjectBuildConfig} config - used to define generation and extract persona metadata
636
- * @property {import('@scout9/app').Conversation} conversation
637
- * @property {Array<import('@scout9/admin').Message>} messages
638
- * @property {import('@scout9/admin').Message} message - the message sent by the customer (should exist in messages)
639
- * @property {import('@scout9/app').Customer} customer
640
- * @property {import('@scout9/app').ConversationProgress} progress - progress checklist for manual/auto ingress workflows
641
- * @property {any} context - event context
642
- */
643
-
644
- /**
645
- * @typedef {Object} ParseOutput
646
- * @property {Array<import('@scout9/admin').Message>} messages
647
- * @property {import('@scout9/app').Conversation} conversation
648
- * @property {import('@scout9/admin').Message} message
649
- * @property {any} context
650
- */
651
-
652
- /**
653
- * @typedef {Object} WorkflowOutput
654
- * @property {Array<import('@scout9/app').WorkflowResponseSlot>} slots
655
- * @property {Array<import('@scout9/admin').Message>} messages
656
- * @property {import('@scout9/app').Conversation} conversation
657
- * @property {any} context
658
- */
659
-
660
- /**
661
- * @typedef {Object} GenerateOutput
662
- * @property {import('@scout9/admin').GenerateResponse | undefined} generate
663
- * @property {Array<import('@scout9/admin').Message>} messages
664
- * @property {import('@scout9/app').Conversation} conversation
665
- * @property {any} context
666
- */
667
-
668
- /**
669
- * @callback ParseFun
670
- * @param {string} message - message to send
671
- * @param {string | undefined} language - language to parse in, defaults to "en" for english
672
- * @returns {Promise<import('@scout9/admin').ParseResponse>}
673
- */
674
-
675
- /**
676
- * @callback ContextualizerFun
677
- * @param {Pick<import('@scout9/app').WorkflowEvent, 'messages' | 'conversation'>} args - message to send
678
- * @returns {Promise<import('@scout9/app').WorkflowEvent['messages']>}
679
- */
680
-
681
- /**
682
- * @callback WorkflowFun
683
- * @param {import('@scout9/app').WorkflowEvent} event - conversation data
684
- * @returns {Promise<import('@scout9/app').WorkflowResponse>}
685
- */
686
-
687
- /**
688
- * @callback GenerateFun
689
- * @param {import('@scout9/admin').GenerateRequestOneOf1} data - data to generate from
690
- * @returns {Promise<import('@scout9/admin').GenerateResponse>}
691
- */
692
-
693
- /**
694
- * @callback TransformerFun
695
- * @param {import('@scout9/admin').PmtTransformRequest} data - data to generate from
696
- * @returns {Promise<import('@scout9/admin').PmtTransformResponse>}
697
- */
698
-
699
- /**
700
- * @callback IdGeneratorFun
701
- * @param {import('@scout9/admin').Message['role']} prefix
702
- * @returns {string}
703
- */
704
-
705
- /**
706
- * @callback StatusCallback
707
- * @param {string} message
708
- * @param {'info' | 'warn' | 'error' | 'success' | undefined} [level]
709
- * @param {string | undefined} [type]
710
- * @param {any | undefined} [payload]
711
- * @returns {void}
712
- */
713
-
714
- /**
715
- * @typedef {Object} CustomerSpiritCallbacks
716
- * @property {ParseFun} parser
717
- * @property {ContextualizerFun} contextualizer
718
- * @property {WorkflowFun} workflow
719
- * @property {GenerateFun} generator
720
- * @property {TransformerFun} transformer
721
- * @property {IdGeneratorFun} idGenerator
722
- * @property {StatusCallback | undefined} [progress]
723
- */
724
-
725
- /**
726
- * @typedef {Object} ConversationEvent
727
- * @property {(Change<import('@scout9/app').Conversation> & {
728
- * forwardNote?: string;
729
- * forward?: import('@scout9/app').WorkflowResponseSlot['forward'];
730
- * })} conversation
731
- * @property {Change<Array<import('@scout9/admin').Message>>} messages
732
- * @property {Change<any>} context
733
- * @property {Change<import('@scout9/admin').Message>} message
734
- * @property {Array<import('@scout9/app').Followup>} followup
735
- * @property {Array<import('@scout9/app').EntityContextUpsert>} entityContextUpsert
736
- */
737
- var Spirits = {
738
- /**
739
- * Customer message
740
- * @param {ConversationData & CustomerSpiritCallbacks} input
741
- * @param {(error: Error) => void} onError
742
- * @returns {Promise<ConversationEvent>}
743
- */
744
- customer: function () {
745
- var _customer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
746
- var _recentUserMessage;
747
- var onError,
748
- customer,
749
- config,
750
- parser,
751
- contextualizer,
752
- workflow,
753
- generator,
754
- transformer,
755
- idGenerator,
756
- _input$progress,
757
- progress,
758
- messageBefore,
759
- contextBefore,
760
- messagesBefore,
761
- conversationBefore,
762
- conversation,
763
- messages,
764
- context,
765
- message,
766
- followup,
767
- entityContextUpsert,
768
- updateConversation,
769
- updateContext,
770
- userMessages,
771
- recentUserMessage,
772
- lockConversation,
773
- incrementLockAttempt,
774
- _addInstruction,
775
- addInstruction,
776
- persona,
777
- invalidRoles,
778
- parsePayload,
779
- index,
780
- _message,
781
- previousUserMessages,
782
- oldKeyCount,
783
- newKeyCount,
784
- noNewContext,
785
- _messages2,
786
- newContextMessages,
787
- _iterator,
788
- _step,
789
- _loop,
790
- slots,
791
- hasNoInstructions,
792
- hasNoCustomMessage,
793
- messagesToTransform,
794
- previousLockAttempt,
795
- resettedIntent,
796
- _forward,
797
- _forwardNote,
798
- _tasks,
799
- _iterator2,
800
- _step2,
801
- _step2$value,
802
- forward,
803
- forwardNote,
804
- instructions,
805
- removeInstructions,
806
- manualMessage,
807
- scheduled,
808
- resetIntent,
809
- secondsDelay,
810
- contextUpsert,
811
- anticipate,
812
- slotFollowup,
813
- slotEntityContextUpsert,
814
- tasks,
815
- _slots,
816
- map,
817
- i,
818
- _anticipate$i,
819
- keywords,
820
- _slot,
821
- slotId,
822
- _tasks2,
823
- _iterator5,
824
- _step5,
825
- instruction,
826
- _iterator6,
827
- _step6,
828
- _loop2,
829
- manualMessageObj,
830
- now,
831
- generatorInput,
832
- generatorPayload,
833
- _generatorPayload$err,
834
- _generatorPayload$err2,
835
- _generatorPayload$err3,
836
- _generatorPayload$mes,
837
- agentMessages,
838
- lastAgentMessage,
839
- addedMessages,
840
- _iterator3,
841
- _step3,
842
- newMessage,
843
- _iterator4,
844
- _step4,
845
- transformResponse,
846
- _agentMessages,
847
- _lastAgentMessage,
848
- _args3 = arguments;
849
- return _regeneratorRuntime().wrap(function _callee$(_context3) {
850
- while (1) switch (_context3.prev = _context3.next) {
851
- case 0:
852
- onError = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : function () {};
853
- customer = input.customer, config = input.config, 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, messageBefore = input.message, contextBefore = input.context, messagesBefore = input.messages, conversationBefore = input.conversation;
854
- conversation = input.conversation, messages = input.messages, context = input.context, message = input.message; // Storing post process events here
855
- followup = [];
856
- entityContextUpsert = []; // 0. Setup Helpers
857
- updateConversation = function updateConversation(previousConversation, conversationUpdates) {
858
- progress('Update conversation', 'info', 'UPDATE_CONVERSATION', conversationUpdates);
859
- return _objectSpread2(_objectSpread2({}, previousConversation), conversationUpdates);
860
- };
861
- updateContext = function updateContext(previousContext, newContext) {
862
- progress('Update context', 'info', 'UPDATE_CONTEXT', newContext);
863
- return _objectSpread2(_objectSpread2({}, previousContext), newContext);
864
- };
865
- userMessages = function userMessages(_messages) {
866
- return _messages.filter(function (m) {
867
- return m.role === 'customer' || m.role === 'user';
868
- });
869
- };
870
- recentUserMessage = function recentUserMessage(_messages) {
871
- var _userMessages = userMessages(_messages);
872
- return _userMessages[_userMessages.length - 1];
873
- };
874
- lockConversation = function lockConversation(_conversation, reason) {
875
- return updateConversation(_conversation, {
876
- locked: true,
877
- lockedReason: conversation.lockedReason || reason || 'Unknown'
878
- });
879
- };
880
- incrementLockAttempt = function incrementLockAttempt(_conversation, _config) {
881
- if (typeof _conversation.lockAttempts !== 'number') {
882
- _conversation.lockAttempts = 0;
883
- }
884
- _conversation.lockAttempts++;
885
- if (_conversation.lockAttempts > ((_config === null || _config === void 0 ? void 0 : _config.maxLockAttempts) || 3)) {
886
- _conversation.locked = true;
887
- _conversation.lockedReason = "Max lock attempts exceeded (".concat(_conversation.lockAttempts, " > ").concat((_config === null || _config === void 0 ? void 0 : _config.maxLockAttempts) || 3, ")");
888
- }
889
- progress('Incremented lock attempt', 'info', 'UPDATE_CONVERSATION', {
890
- lockAttempts: _conversation.lockAttempts,
891
- locked: _conversation.locked,
892
- lockedReason: _conversation.lockedReason || ''
893
- });
894
- return _conversation;
895
- };
896
- _addInstruction = function _addInstruction(instruction, _messages, _conversation, _config, previousLockAttempt, id) {
897
- var systemMessages = _messages.filter(function (m) {
898
- return m.role === 'system';
899
- });
900
- var lastSystemMessage = systemMessages[systemMessages.length - 1];
901
- var addedMessage = false;
902
- var changedConversation = false;
903
-
904
- // If instruction does not equal previous system message, add it, otherwise lock attempt
905
- if (!lastSystemMessage || instruction !== lastSystemMessage.content) {
906
- _messages.push({
907
- id: id,
908
- role: 'system',
909
- content: instruction,
910
- time: new Date().toISOString()
911
- });
912
- addedMessage = true;
913
- } else {
914
- // Handle repeated instruction
915
- // Increment lock attempt if instructions are repeated and we haven't already incremented lock attempt (for example if a forward is provided)
916
- if (previousLockAttempt === (conversation.lockAttempts || 0)) {
917
- _conversation = incrementLockAttempt(_conversation, _config);
918
- changedConversation = true;
919
- }
920
- }
921
- return {
922
- conversation: _conversation,
923
- messages: _messages,
924
- addedMessage: addedMessage,
925
- changedConversation: changedConversation
926
- };
927
- };
928
- addInstruction = function addInstruction(instruction, previousLockAttempt) {
929
- var id = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : idGenerator('sys');
930
- var _addInstruction2 = _addInstruction(instruction, messages, conversation, config, previousLockAttempt, id),
931
- newConversation = _addInstruction2.conversation,
932
- newMessages = _addInstruction2.messages,
933
- addedMessage = _addInstruction2.addedMessage,
934
- changedConversation = _addInstruction2.changedConversation;
935
- conversation = newConversation;
936
- messages = newMessages;
937
- if (addedMessage) {
938
- progress('Added instruction', 'info', 'ADD_MESSAGE', newMessages[newMessages.length - 1]);
939
- }
940
- if (changedConversation) {
941
- progress('Updated conversation', 'info', 'UPDATE_CONVERSATION', newConversation);
942
- }
943
- }; // 1. Check inputs
944
- if (conversation.$agent) {
945
- _context3.next = 15;
946
- break;
947
- }
948
- throw new Error("SpiritsError: No agent found in conversation, must define \".$agent\" in the conversation");
949
- case 15:
950
- persona = (config.persona || config.personas || config.agents).find(function (p) {
951
- return p.id === conversation.$agent;
952
- });
953
- if (persona) {
954
- _context3.next = 20;
955
- break;
956
- }
957
- if (!(config.persona || config.personas || config.agents).some(function (a) {
958
- return !a.id;
959
- })) {
960
- _context3.next = 19;
961
- break;
962
- }
963
- throw new Error("SpiritsError: No persona found (\"".concat(conversation.$agent, "\") in provided config, some persona's did not contain an \"id\" (Internal Mapping Error)"));
964
- case 19:
965
- throw new Error("SpiritsError: No persona found (\"".concat(conversation.$agent, "\") in provided config"));
966
- case 20:
967
- if (messages.every(function (m) {
968
- return !!m.id;
969
- })) {
970
- _context3.next = 22;
971
- break;
972
- }
973
- throw new Error("SpiritsError: Every message must have an \".id\", ensure all messages have an id assigned before running");
974
- case 22:
975
- if (messages.every(function (m) {
976
- return m.role === 'customer' || m.role === 'agent' || m.role === 'system' || m.role === 'tool';
977
- })) {
978
- _context3.next = 25;
979
- break;
980
- }
981
- invalidRoles = messages.filter(function (m) {
982
- return m.role !== 'customer' && m.role !== 'agent' && m.role !== 'system' && m.role !== 'tool';
983
- });
984
- throw new Error("SpiritsError: Every message must have a role of \"customer\", \"agent\", or \"system\". Got invalid roles: ".concat(invalidRoles.map(function (m) {
985
- return m.role;
986
- }).join(', ')));
987
- case 25:
988
- // if message is not in messages, then add it
989
- if (!messages.find(function (m) {
990
- return m.id === input.message.id;
991
- })) {
992
- messages.push(input.message);
993
- }
994
-
995
- // 2. Parse the message
996
- progress('Parsing message', 'info', 'SET_PROCESSING', 'user');
997
- _context3.next = 29;
998
- return parser(message.content, 'en');
999
- case 29:
1000
- parsePayload = _context3.sent;
1001
- if (parsePayload.intent) {
1002
- message.intent = parsePayload.intent;
1003
- }
1004
- if (typeof parsePayload.intentScore === 'number') {
1005
- message.intentScore = parsePayload.intentScore;
1006
- }
1007
- message.context = parsePayload.context;
1008
- message.entities = parsePayload.entities;
1009
- index = messages.findIndex(function (m) {
1010
- return m.content === message.content || m.id === message.id;
1011
- });
1012
- if (index === -1) {
1013
- _message = {
1014
- id: idGenerator('customer'),
1015
- role: 'customer',
1016
- content: message,
1017
- context: parsePayload.context,
1018
- entities: parsePayload.entities,
1019
- time: new Date().toISOString()
1020
- };
1021
- if (parsePayload.intent) {
1022
- _message.intent = parsePayload.intent;
1023
- }
1024
- if (typeof parsePayload.intentScore === 'number') {
1025
- _message.intentScore = parsePayload.intentScore;
1026
- }
1027
- message = _message;
1028
- messages.push(_message);
1029
- progress('Added message', 'info', 'ADD_MESSAGE', _message);
1030
- } else {
1031
- messages[index].context = parsePayload.context;
1032
- messages[index].entities = parsePayload.entities;
1033
- if (parsePayload.intent) {
1034
- messages[index].intent = parsePayload.intent;
1035
- }
1036
- if (typeof parsePayload.intentScore === 'number') {
1037
- messages[index].intentScore = parsePayload.intentScore;
1038
- }
1039
- message = messages[index];
1040
- progress('Parsed message', 'success', 'UPDATE_MESSAGE', message);
1041
- }
1042
- // If this is the first user message, then update conversations intent
1043
- previousUserMessages = messages.filter(function (m) {
1044
- return m.role === 'customer' && m.content !== message.content;
1045
- });
1046
- if (!conversation.intent || previousUserMessages.length === 0 && parsePayload.intent) {
1047
- conversation.intent = parsePayload.intent;
1048
- conversation.intentScore = (parsePayload === null || parsePayload === void 0 ? void 0 : parsePayload.intentScore) || 0;
1049
- progress('Updated conversation intent', 'info', 'UPDATE_CONVERSATION', {
1050
- intent: parsePayload.intent,
1051
- intentScore: (parsePayload === null || parsePayload === void 0 ? void 0 : parsePayload.intentScore) || 0
1052
- });
1053
- }
1054
- oldKeyCount = Object.keys(context).length;
1055
- context = updateContext(context, parsePayload.context);
1056
- newKeyCount = Object.keys(context).length;
1057
- if (!conversation.locked && newKeyCount > oldKeyCount) {
1058
- // Reset lock attempts
1059
- conversation.locked = false;
1060
- conversation.lockAttempts = 0;
1061
- conversation.lockedReason = '';
1062
- progress('Reset lock', 'info', 'UPDATE_CONVERSATION', {
1063
- locked: false,
1064
- lockAttempts: 0,
1065
- lockedReason: ''
1066
- });
1067
- }
1068
- noNewContext = Object.keys(parsePayload.context).length === 0; // upsert parse system messages
1069
- if (parsePayload.contextMessages.length) {
1070
- (_messages2 = messages).push.apply(_messages2, _toConsumableArray(parsePayload.contextMessages.reduce(function (accumulator, text) {
1071
- if (!messages.find(function (mes) {
1072
- return mes.content === text;
1073
- })) {
1074
- accumulator.push({
1075
- id: idGenerator('sys'),
1076
- role: 'system',
1077
- content: text,
1078
- time: new Date().toISOString()
1079
- });
1080
- } else {
1081
- progress("Already have system context, skipping", 'info');
1082
- }
1083
- return accumulator;
1084
- }, [])));
1085
- }
1086
-
1087
- // 3. Run the contextualizer
1088
- progress('Running contextualizer', 'info', 'SET_PROCESSING', 'system');
1089
- _context3.next = 47;
1090
- return contextualizer({
1091
- conversation: conversation,
1092
- messages: messages
1093
- });
1094
- case 47:
1095
- newContextMessages = _context3.sent;
1096
- _iterator = _createForOfIteratorHelper(newContextMessages);
1097
- _context3.prev = 49;
1098
- _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
1099
- var contextMessage;
1100
- return _regeneratorRuntime().wrap(function _loop$(_context) {
1101
- while (1) switch (_context.prev = _context.next) {
1102
- case 0:
1103
- contextMessage = _step.value;
1104
- if (!messages.find(function (mes) {
1105
- return mes.content === contextMessage.content;
1106
- })) {
1107
- messages.push(contextMessage);
1108
- progress("Added context", 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
1109
- } else {
1110
- progress("Already have system context, skipping", 'info');
1111
- }
1112
- case 2:
1113
- case "end":
1114
- return _context.stop();
1115
- }
1116
- }, _loop);
1117
- });
1118
- _iterator.s();
1119
- case 52:
1120
- if ((_step = _iterator.n()).done) {
1121
- _context3.next = 56;
1122
- break;
1123
- }
1124
- return _context3.delegateYield(_loop(), "t0", 54);
1125
- case 54:
1126
- _context3.next = 52;
1127
- break;
1128
- case 56:
1129
- _context3.next = 61;
1130
- break;
1131
- case 58:
1132
- _context3.prev = 58;
1133
- _context3.t1 = _context3["catch"](49);
1134
- _iterator.e(_context3.t1);
1135
- case 61:
1136
- _context3.prev = 61;
1137
- _iterator.f();
1138
- return _context3.finish(61);
1139
- case 64:
1140
- // 4. Run the workflow
1141
- progress('Running workflow', 'info', 'SET_PROCESSING', 'system');
1142
- _context3.next = 67;
1143
- return workflow({
1144
- messages: messages,
1145
- conversation: conversation,
1146
- context: context,
1147
- message: message,
1148
- agent: persona,
1149
- customer: customer,
1150
- intent: {
1151
- current: ((_recentUserMessage = recentUserMessage(messages)) === null || _recentUserMessage === void 0 ? void 0 : _recentUserMessage.intent) || null,
1152
- flow: messages.map(function (m) {
1153
- return m.intent;
1154
- }).filter(Boolean),
1155
- initial: conversation.intent || null
1156
- },
1157
- stagnationCount: conversation.lockAttempts || 0
1158
- }).then(function (res) {
1159
- return Array.isArray(res) ? res : [res];
1160
- }).then(function (slots) {
1161
- return slots.reduce(function (accumulator, slot) {
1162
- if ('toJSON' in slot) {
1163
- var slotJson = slot.toJSON();
1164
- accumulator.push.apply(accumulator, _toConsumableArray(Array.isArray(slotJson) ? slotJson : [slotJson]));
1165
- } else {
1166
- accumulator.push(slot);
1167
- }
1168
- return accumulator;
1169
- }, []);
1170
- });
1171
- case 67:
1172
- slots = _context3.sent;
1173
- hasNoInstructions = slots.every(function (s) {
1174
- return !s.instructions || Array.isArray(s.instructions) && s.instructions.length === 0;
1175
- });
1176
- hasNoCustomMessage = slots.every(function (s) {
1177
- return !s.message;
1178
- });
1179
- messagesToTransform = slots.filter(function (s) {
1180
- return !!s.message && _typeof(s.message) === 'object' && !!s.message.transform;
1181
- });
1182
- previousLockAttempt = conversation.lockAttempts || 0; // Used to track
1183
- if (hasNoInstructions && noNewContext) {
1184
- conversation = incrementLockAttempt(conversation, config);
1185
- } else {
1186
- conversation.lockAttempts = 0;
1187
- conversation.locked = false;
1188
- conversation.lockedReason = '';
1189
- progress('Reset lock', 'info', 'UPDATE_CONVERSATION', {
1190
- lockAttempts: 0,
1191
- locked: false,
1192
- lockedReason: ''
1193
- });
1194
- }
1195
- resettedIntent = false;
1196
- /** @type {Array<string> | undefined} */
1197
- _iterator2 = _createForOfIteratorHelper(slots);
1198
- _context3.prev = 75;
1199
- _iterator2.s();
1200
- case 77:
1201
- if ((_step2 = _iterator2.n()).done) {
1202
- _context3.next = 148;
1203
- break;
1204
- }
1205
- _step2$value = _step2.value, forward = _step2$value.forward, forwardNote = _step2$value.forwardNote, instructions = _step2$value.instructions, removeInstructions = _step2$value.removeInstructions, manualMessage = _step2$value.message, scheduled = _step2$value.scheduled, resetIntent = _step2$value.resetIntent, secondsDelay = _step2$value.secondsDelay, contextUpsert = _step2$value.contextUpsert, anticipate = _step2$value.anticipate, slotFollowup = _step2$value.followup, slotEntityContextUpsert = _step2$value.entityContextUpsert, tasks = _step2$value.tasks;
1206
- if (!anticipate) {
1207
- _context3.next = 92;
1208
- break;
1209
- }
1210
- if (!Array.isArray(anticipate)) {
1211
- _context3.next = 87;
1212
- break;
1213
- }
1214
- // 'literal' anticipation
1215
- _slots = {};
1216
- map = [];
1217
- for (i = 0; i < anticipate.length; i++) {
1218
- _anticipate$i = anticipate[i], keywords = _anticipate$i.keywords, _slot = _objectWithoutProperties(_anticipate$i, _excluded);
1219
- slotId = "".concat(i);
1220
- _slots[slotId] = _slot;
1221
- map.push({
1222
- slot: slotId,
1223
- keywords: keywords
1224
- });
1225
- }
1226
- updateConversation(conversation, {
1227
- type: 'literal',
1228
- slots: _slots,
1229
- map: map
1230
- });
1231
- _context3.next = 92;
1232
- break;
1233
- case 87:
1234
- if (!('yes' in anticipate && 'no' in anticipate && 'did' in anticipate)) {
1235
- _context3.next = 91;
1236
- break;
1237
- }
1238
- // "did" anticipation
1239
- updateConversation(conversation, {
1240
- type: 'did',
1241
- slots: {
1242
- yes: anticipate.yes,
1243
- no: anticipate.no
1244
- },
1245
- did: anticipate.did
1246
- });
1247
- _context3.next = 92;
1248
- break;
1249
- case 91:
1250
- throw new Error("Invalid anticipate payload \"".concat(JSON.stringify(anticipate), "\""));
1251
- case 92:
1252
- // tasks from auto/manual ingress to execute
1253
- if (!!tasks && Array.isArray(tasks) && !!tasks.length) {
1254
- if (!_tasks) _tasks = [];
1255
- (_tasks2 = _tasks).push.apply(_tasks2, _toConsumableArray(tasks));
1256
- }
1257
- if (slotFollowup) {
1258
- followup.push(slotFollowup);
1259
- }
1260
- if (slotEntityContextUpsert && slotEntityContextUpsert.length) {
1261
- entityContextUpsert.push.apply(entityContextUpsert, _toConsumableArray(slotEntityContextUpsert));
1262
- }
1263
-
1264
- // Forward to agent or other agent
1265
- if (forward) {
1266
- conversation = lockConversation(conversation, 'App instructed forward');
1267
- _forward = forward;
1268
- _forwardNote = forwardNote;
1269
- if (typeof forward === 'string') {
1270
- updateConversation(conversation, {
1271
- forwarded: forward
1272
- });
1273
- messages.push({
1274
- id: idGenerator('sys'),
1275
- role: 'system',
1276
- content: "forwarded to \"".concat(forward, "\""),
1277
- time: new Date().toISOString()
1278
- });
1279
- progress("Forwarded to \"".concat(forward, "\""), 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
1280
- } else if (typeof forward === 'boolean') {
1281
- updateConversation(conversation, {
1282
- forwarded: conversation.$agent
1283
- });
1284
- messages.push({
1285
- id: idGenerator('sys'),
1286
- role: 'system',
1287
- content: "forwarded to \"".concat(forward, "\""),
1288
- time: new Date().toISOString()
1289
- });
1290
- progress("Forwarded to agent", 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
1291
- } else {
1292
- messages.push({
1293
- id: idGenerator('sys'),
1294
- role: 'system',
1295
- content: "forwarded to \"".concat(forward.to, "\" ").concat(forward.mode ? ' (' + forward.mode + ')' : ''),
1296
- time: new Date().toISOString()
1297
- });
1298
- progress("Forwarded to \"".concat(forward.to, "\" ").concat(forward.mode ? ' (' + forward.mode + ')' : ''), 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
1299
- updateConversation(conversation, {
1300
- forwarded: forward.to
1301
- });
1302
- }
1303
- }
1304
-
1305
- // Insert instructions context
1306
- if (!instructions) {
1307
- _context3.next = 111;
1308
- break;
1309
- }
1310
- if (!(typeof instructions === 'string')) {
1311
- _context3.next = 101;
1312
- break;
1313
- }
1314
- addInstruction(instructions, previousLockAttempt);
1315
- _context3.next = 111;
1316
- break;
1317
- case 101:
1318
- if (!Array.isArray(instructions)) {
1319
- _context3.next = 106;
1320
- break;
1321
- }
1322
- _iterator5 = _createForOfIteratorHelper(instructions);
1323
- try {
1324
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1325
- instruction = _step5.value;
1326
- if (typeof instruction === 'string') {
1327
- addInstruction(instruction, previousLockAttempt);
1328
- } else {
1329
- addInstruction(instruction.content, previousLockAttempt, instruction.id);
1330
- }
1331
- }
1332
- } catch (err) {
1333
- _iterator5.e(err);
1334
- } finally {
1335
- _iterator5.f();
1336
- }
1337
- _context3.next = 111;
1338
- break;
1339
- case 106:
1340
- if (!(_typeof(instructions) === 'object' && 'content' in instructions)) {
1341
- _context3.next = 110;
1342
- break;
1343
- }
1344
- addInstruction(instructions.content, previousLockAttempt, instructions.id);
1345
- _context3.next = 111;
1346
- break;
1347
- case 110:
1348
- throw new Error("SpiritsError: instructions must be a string or array or {content: \"<instruction>\"}, got: ".concat(JSON.stringify(instructions)));
1349
- case 111:
1350
- if (!removeInstructions) {
1351
- _context3.next = 128;
1352
- break;
1353
- }
1354
- _iterator6 = _createForOfIteratorHelper(removeInstructions);
1355
- _context3.prev = 113;
1356
- _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
1357
- var instructionId, index;
1358
- return _regeneratorRuntime().wrap(function _loop2$(_context2) {
1359
- while (1) switch (_context2.prev = _context2.next) {
1360
- case 0:
1361
- instructionId = _step6.value;
1362
- index = messages.findIndex(function (m) {
1363
- return m.id === instructionId;
1364
- });
1365
- if (index > -1) {
1366
- messages.splice(index, 1);
1367
- progress('Remove instruction', 'info', 'REMOVE_MESSAGE', instructionId);
1368
- } else {
1369
- console.log("Instruction not found \"".concat(instructionId, "\", other ids: ").concat(messages.map(function (m) {
1370
- return "\"".concat(m.id, "\"");
1371
- }).join(', ')));
1372
- }
1373
- case 3:
1374
- case "end":
1375
- return _context2.stop();
1376
- }
1377
- }, _loop2);
1378
- });
1379
- _iterator6.s();
1380
- case 116:
1381
- if ((_step6 = _iterator6.n()).done) {
1382
- _context3.next = 120;
1383
- break;
1384
- }
1385
- return _context3.delegateYield(_loop2(), "t2", 118);
1386
- case 118:
1387
- _context3.next = 116;
1388
- break;
1389
- case 120:
1390
- _context3.next = 125;
1391
- break;
1392
- case 122:
1393
- _context3.prev = 122;
1394
- _context3.t3 = _context3["catch"](113);
1395
- _iterator6.e(_context3.t3);
1396
- case 125:
1397
- _context3.prev = 125;
1398
- _iterator6.f();
1399
- return _context3.finish(125);
1400
- case 128:
1401
- if (!manualMessage) {
1402
- _context3.next = 144;
1403
- break;
1404
- }
1405
- /** @type {import('@scout9/admin').Message} */
1406
- manualMessageObj = {
1407
- id: idGenerator('persona'),
1408
- role: 'agent',
1409
- // @TODO switch role to persona
1410
- content: '',
1411
- time: new Date().toISOString()
1412
- };
1413
- if (!(_typeof(manualMessage) === 'object')) {
1414
- _context3.next = 136;
1415
- break;
1416
- }
1417
- Object.assign(manualMessageObj, manualMessage);
1418
- manualMessageObj.role = 'agent';
1419
- manualMessageObj.time = new Date().toISOString();
1420
- _context3.next = 141;
1421
- break;
1422
- case 136:
1423
- if (!(typeof manualMessage === 'string')) {
1424
- _context3.next = 140;
1425
- break;
1426
- }
1427
- manualMessageObj.content = manualMessage;
1428
- _context3.next = 141;
1429
- break;
1430
- case 140:
1431
- throw new Error('Manual message must be of type "string" or "DirectMessage"');
1432
- case 141:
1433
- if (scheduled) {
1434
- manualMessageObj.time = new Date(scheduled * 1000).toISOString();
1435
- manualMessageObj.scheduled = manualMessageObj.time;
1436
- } else if (secondsDelay) {
1437
- now = new Date();
1438
- now.setSeconds(now.getSeconds() + secondsDelay);
1439
- manualMessageObj.time = now.toISOString();
1440
- manualMessageObj.delayInSeconds = secondsDelay;
1441
- }
1442
- messages.push(manualMessageObj);
1443
- progress('Added manual message', 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
1444
- case 144:
1445
- if (contextUpsert) {
1446
- context = updateContext(context, contextUpsert);
1447
- progress('Upserted context', 'info', 'UPDATE_CONTEXT', contextUpsert);
1448
- }
1449
- if (resetIntent) {
1450
- resettedIntent = true;
1451
- }
1452
- case 146:
1453
- _context3.next = 77;
1454
- break;
1455
- case 148:
1456
- _context3.next = 153;
1457
- break;
1458
- case 150:
1459
- _context3.prev = 150;
1460
- _context3.t4 = _context3["catch"](75);
1461
- _iterator2.e(_context3.t4);
1462
- case 153:
1463
- _context3.prev = 153;
1464
- _iterator2.f();
1465
- return _context3.finish(153);
1466
- case 156:
1467
- if (resettedIntent && !_forward) {
1468
- conversation.intent = null;
1469
- conversation.intentScore = null;
1470
- conversation.locked = false;
1471
- conversation.lockedReason = '';
1472
- conversation.lockAttempts = 0;
1473
- progress('Reset conversation intent', 'info', 'UPDATE_CONVERSATION', {
1474
- intent: null,
1475
- intentScore: null,
1476
- locked: false,
1477
- lockAttempts: 0,
1478
- lockedReason: ''
1479
- });
1480
- }
1481
-
1482
- // 5. Generate response
1483
- // If conversation previously locked, don't generate
1484
- if (input.conversation.locked) {
1485
- _context3.next = 208;
1486
- break;
1487
- }
1488
- if (!((!conversation.locked || !hasNoInstructions) && !!hasNoCustomMessage)) {
1489
- _context3.next = 174;
1490
- break;
1491
- }
1492
- _context3.prev = 159;
1493
- progress('Generating message', 'info', 'SET_PROCESSING', 'system');
1494
-
1495
- /** @type {import('@scout9/admin').GenerateRequestOneOf1} */
1496
- generatorInput = {
1497
- messages: messages,
1498
- persona: persona,
1499
- context: context,
1500
- llm: config.llm,
1501
- pmt: config.pmt
1502
- };
1503
- if (!!_tasks && Array.isArray(_tasks) && !!_tasks.length) {
1504
- generatorInput.tasks = _tasks;
1505
- }
1506
- _context3.next = 165;
1507
- return generator(generatorInput);
1508
- case 165:
1509
- generatorPayload = _context3.sent;
1510
- if (!generatorPayload.send) {
1511
- progress('Generated response', 'failed', undefined, {
1512
- error: ((_generatorPayload$err = generatorPayload.errors) === null || _generatorPayload$err === void 0 ? void 0 : _generatorPayload$err.join('\n\n')) || 'Unknown Reason'
1513
- });
1514
- console.error("Locking conversation, api returned send false: ".concat(generatorPayload.messages), ((_generatorPayload$err2 = generatorPayload.errors) === null || _generatorPayload$err2 === void 0 ? void 0 : _generatorPayload$err2.join('\n\n')) || generatorPayload.forwardNote || 'Unknown Reason');
1515
- conversation = lockConversation(conversation, 'API: ' + ((_generatorPayload$err3 = generatorPayload.errors) === null || _generatorPayload$err3 === void 0 ? void 0 : _generatorPayload$err3.join('\n\n')) || generatorPayload.forwardNote || 'Unknown Reason');
1516
- } else {
1517
- progress('Generated response', 'success', undefined, undefined);
1518
- // Check if already had message
1519
- agentMessages = messages.filter(function (m) {
1520
- return m.role === 'agent';
1521
- });
1522
- lastAgentMessage = agentMessages[agentMessages.length - 1]; // Build addedMessages from generatorPayload.messages
1523
- addedMessages = ((_generatorPayload$mes = generatorPayload === null || generatorPayload === void 0 ? void 0 : generatorPayload.messages) !== null && _generatorPayload$mes !== void 0 ? _generatorPayload$mes : []).map(function (message) {
1524
- // Normalize time → ISO string
1525
- var t = message.time;
1526
- var isoTime;
1527
- if (typeof t === "string") {
1528
- isoTime = t;
1529
- } else if (t instanceof Date) {
1530
- isoTime = t.toISOString();
1531
- } else if (t && typeof t.toDate === "function") {
1532
- // Firestore Timestamp
1533
- isoTime = t.toDate().toISOString();
1534
- } else {
1535
- progress("Message \"".concat(message.content, "\" wasn't given a usable timestamp (").concat(JSON.stringify(t), "), defaulting to now"));
1536
- isoTime = new Date().toISOString();
1537
- }
1538
-
1539
- // Base fields we guarantee
1540
- var base = {
1541
- role: message.role,
1542
- content: message.content,
1543
- id: idGenerator(message.role),
1544
- time: isoTime
1545
- };
1546
-
1547
- // Copy any other non-nullish fields without overwriting base
1548
- return Object.entries(message).reduce(function (acc, _ref) {
1549
- var _ref2 = _slicedToArray(_ref, 2),
1550
- key = _ref2[0],
1551
- value = _ref2[1];
1552
- if (!Object.prototype.hasOwnProperty.call(acc, key) && value != null) {
1553
- acc[key] = value;
1554
- }
1555
- return acc;
1556
- }, base);
1557
- })
1558
- // De-dupe by content (change the key if you want stricter uniqueness)
1559
- .reduce(function (acc, msg) {
1560
- var key = String(msg.content); // e.g. `${msg.role}::${msg.content}` for stronger uniqueness
1561
- if (!acc.seen.has(key)) {
1562
- acc.seen.add(key);
1563
- acc.items.push(msg);
1564
- }
1565
- return acc;
1566
- }, {
1567
- seen: new Set(),
1568
- items: []
1569
- }).items;
1570
- if (lastAgentMessage && lastAgentMessage.content && addedMessages.some(function (message) {
1571
- return message.content === lastAgentMessage.content;
1572
- })) {
1573
- // Error should not have happened
1574
- conversation = lockConversation(conversation, 'Duplicate message');
1575
- } else {
1576
- _iterator3 = _createForOfIteratorHelper(addedMessages);
1577
- try {
1578
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1579
- newMessage = _step3.value;
1580
- messages.push(newMessage);
1581
- progress('Added agent message', 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
1582
- }
1583
- } catch (err) {
1584
- _iterator3.e(err);
1585
- } finally {
1586
- _iterator3.f();
1587
- }
1588
- }
1589
-
1590
- // Check if conversation was marked for forward (generator message still allowed to be sent)
1591
- if (generatorPayload.forward) {
1592
- conversation = lockConversation(conversation, 'API: ' + generatorPayload.forwardNote || 'Forwarded by API');
1593
- if (!_forward) {
1594
- _forward = generatorPayload.forward;
1595
- _forwardNote = generatorPayload.forwardNote;
1596
- }
1597
- }
1598
- }
1599
- _context3.next = 174;
1600
- break;
1601
- case 169:
1602
- _context3.prev = 169;
1603
- _context3.t5 = _context3["catch"](159);
1604
- onError(_context3.t5);
1605
- console.error("Spirits: Locking conversation, error generating response: ".concat(_context3.t5.message));
1606
- conversation = lockConversation(conversation, 'API: ' + _context3.t5.message);
1607
- case 174:
1608
- if (!(messagesToTransform.length && transformer)) {
1609
- _context3.next = 207;
1610
- break;
1611
- }
1612
- _context3.prev = 175;
1613
- _iterator4 = _createForOfIteratorHelper(messagesToTransform);
1614
- _context3.prev = 177;
1615
- _iterator4.s();
1616
- case 179:
1617
- if ((_step4 = _iterator4.n()).done) {
1618
- _context3.next = 190;
1619
- break;
1620
- }
1621
- _step4.value;
1622
- _context3.next = 183;
1623
- return transformer({
1624
- message: messagesToTransform,
1625
- persona: persona,
1626
- customer: customer.id,
1627
- messages: messages,
1628
- context: context
1629
- });
1630
- case 183:
1631
- transformResponse = _context3.sent;
1632
- progress('Generated response', 'success', undefined, undefined);
1633
- // Check if already had message
1634
- _agentMessages = messages.filter(function (m) {
1635
- return m.role === 'agent';
1636
- });
1637
- _lastAgentMessage = _agentMessages[_agentMessages.length - 1];
1638
- if (_lastAgentMessage && _lastAgentMessage.content === transformResponse.message) {
1639
- // Error should not have happened
1640
- conversation = lockConversation(conversation, 'Duplicate message');
1641
- } else {
1642
- messages.push({
1643
- id: idGenerator('agent'),
1644
- role: 'agent',
1645
- content: transformResponse.message,
1646
- time: new Date().toISOString()
1647
- });
1648
- progress('Added agent message', 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
1649
- }
1650
- case 188:
1651
- _context3.next = 179;
1652
- break;
1653
- case 190:
1654
- _context3.next = 195;
1655
- break;
1656
- case 192:
1657
- _context3.prev = 192;
1658
- _context3.t6 = _context3["catch"](177);
1659
- _iterator4.e(_context3.t6);
1660
- case 195:
1661
- _context3.prev = 195;
1662
- _iterator4.f();
1663
- return _context3.finish(195);
1664
- case 198:
1665
- _context3.next = 205;
1666
- break;
1667
- case 200:
1668
- _context3.prev = 200;
1669
- _context3.t7 = _context3["catch"](175);
1670
- console.error("Locking conversation, error transforming response: ".concat(_context3.t7.message));
1671
- conversation = lockConversation(conversation, 'API: ' + _context3.t7.message);
1672
- onError(_context3.t7);
1673
- case 205:
1674
- _context3.next = 208;
1675
- break;
1676
- case 207:
1677
- if (messagesToTransform.length) {
1678
- console.warn("No transformer provided");
1679
- }
1680
- case 208:
1681
- progress('Parsing message', 'info', 'SET_PROCESSING', null);
1682
- return _context3.abrupt("return", {
1683
- conversation: {
1684
- before: conversationBefore,
1685
- after: conversation,
1686
- forward: _forward || null,
1687
- forwardNote: _forwardNote || ''
1688
- },
1689
- messages: {
1690
- before: messagesBefore,
1691
- after: messages
1692
- },
1693
- message: {
1694
- before: messageBefore,
1695
- after: message
1696
- },
1697
- context: {
1698
- before: contextBefore,
1699
- after: context
1700
- },
1701
- followup: followup,
1702
- entityContextUpsert: entityContextUpsert
1703
- });
1704
- case 210:
1705
- case "end":
1706
- return _context3.stop();
1707
- }
1708
- }, _callee, null, [[49, 58, 61, 64], [75, 150, 153, 156], [113, 122, 125, 128], [159, 169], [175, 200], [177, 192, 195, 198]]);
1709
- }));
1710
- function customer(_x) {
1711
- return _customer.apply(this, arguments);
1712
- }
1713
- return customer;
1714
- }()
1715
- };
1716
-
1717
- exports.Spirits = Spirits;
1718
- exports._asyncToGenerator = _asyncToGenerator;
1719
- exports._classCallCheck = _classCallCheck;
1720
- exports._classPrivateFieldGet = _classPrivateFieldGet;
1721
- exports._classPrivateFieldInitSpec = _classPrivateFieldInitSpec;
1722
- exports._classPrivateFieldSet = _classPrivateFieldSet;
1723
- exports._classPrivateMethodGet = _classPrivateMethodGet;
1724
- exports._classPrivateMethodInitSpec = _classPrivateMethodInitSpec;
1725
- exports._classStaticPrivateFieldSpecGet = _classStaticPrivateFieldSpecGet;
1726
- exports._createClass = _createClass;
1727
- exports._createForOfIteratorHelper = _createForOfIteratorHelper;
1728
- exports._defineProperty = _defineProperty;
1729
- exports._objectSpread2 = _objectSpread2;
1730
- exports._objectWithoutProperties = _objectWithoutProperties;
1731
- exports._regeneratorRuntime = _regeneratorRuntime;
1732
- exports._slicedToArray = _slicedToArray;
1733
- exports._toConsumableArray = _toConsumableArray;
1734
- exports._typeof = _typeof;