@botpress/cognitive 0.1.38 → 0.1.40
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/.turbo/turbo-build.log +7 -7
- package/dist/index.cjs +187 -207
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +6 -2
- package/dist/index.mjs +152 -172
- package/dist/index.mjs.map +2 -2
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -32,9 +32,8 @@ var require_options = __commonJS({
|
|
|
32
32
|
__assign = Object.assign || function(t) {
|
|
33
33
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
34
34
|
s = arguments[i];
|
|
35
|
-
for (var p in s)
|
|
36
|
-
|
|
37
|
-
t[p] = s[p];
|
|
35
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
36
|
+
t[p] = s[p];
|
|
38
37
|
}
|
|
39
38
|
return t;
|
|
40
39
|
};
|
|
@@ -116,7 +115,7 @@ var require_delay_base = __commonJS({
|
|
|
116
115
|
var jitter_factory_1 = require_jitter_factory();
|
|
117
116
|
var Delay = (
|
|
118
117
|
/** @class */
|
|
119
|
-
function() {
|
|
118
|
+
(function() {
|
|
120
119
|
function Delay2(options) {
|
|
121
120
|
this.options = options;
|
|
122
121
|
this.attempt = 0;
|
|
@@ -157,7 +156,7 @@ var require_delay_base = __commonJS({
|
|
|
157
156
|
configurable: true
|
|
158
157
|
});
|
|
159
158
|
return Delay2;
|
|
160
|
-
}()
|
|
159
|
+
})()
|
|
161
160
|
);
|
|
162
161
|
exports.Delay = Delay;
|
|
163
162
|
}
|
|
@@ -167,14 +166,12 @@ var require_delay_base = __commonJS({
|
|
|
167
166
|
var require_skip_first_delay = __commonJS({
|
|
168
167
|
"../../node_modules/.pnpm/exponential-backoff@3.1.1/node_modules/exponential-backoff/dist/delay/skip-first/skip-first.delay.js"(exports) {
|
|
169
168
|
"use strict";
|
|
170
|
-
var __extends = exports && exports.__extends || function() {
|
|
169
|
+
var __extends = exports && exports.__extends || /* @__PURE__ */ (function() {
|
|
171
170
|
var extendStatics = function(d, b) {
|
|
172
171
|
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
173
172
|
d2.__proto__ = b2;
|
|
174
173
|
} || function(d2, b2) {
|
|
175
|
-
for (var p in b2)
|
|
176
|
-
if (b2.hasOwnProperty(p))
|
|
177
|
-
d2[p] = b2[p];
|
|
174
|
+
for (var p in b2) if (b2.hasOwnProperty(p)) d2[p] = b2[p];
|
|
178
175
|
};
|
|
179
176
|
return extendStatics(d, b);
|
|
180
177
|
};
|
|
@@ -185,7 +182,7 @@ var require_skip_first_delay = __commonJS({
|
|
|
185
182
|
}
|
|
186
183
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
187
184
|
};
|
|
188
|
-
}();
|
|
185
|
+
})();
|
|
189
186
|
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
190
187
|
function adopt(value) {
|
|
191
188
|
return value instanceof P ? value : new P(function(resolve) {
|
|
@@ -215,8 +212,7 @@ var require_skip_first_delay = __commonJS({
|
|
|
215
212
|
};
|
|
216
213
|
var __generator = exports && exports.__generator || function(thisArg, body) {
|
|
217
214
|
var _ = { label: 0, sent: function() {
|
|
218
|
-
if (t[0] & 1)
|
|
219
|
-
throw t[1];
|
|
215
|
+
if (t[0] & 1) throw t[1];
|
|
220
216
|
return t[1];
|
|
221
217
|
}, trys: [], ops: [] }, f, y, t, g;
|
|
222
218
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
@@ -228,64 +224,58 @@ var require_skip_first_delay = __commonJS({
|
|
|
228
224
|
};
|
|
229
225
|
}
|
|
230
226
|
function step(op) {
|
|
231
|
-
if (f)
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
227
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
228
|
+
while (_) try {
|
|
229
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
230
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
231
|
+
switch (op[0]) {
|
|
232
|
+
case 0:
|
|
233
|
+
case 1:
|
|
234
|
+
t = op;
|
|
235
|
+
break;
|
|
236
|
+
case 4:
|
|
237
|
+
_.label++;
|
|
238
|
+
return { value: op[1], done: false };
|
|
239
|
+
case 5:
|
|
240
|
+
_.label++;
|
|
241
|
+
y = op[1];
|
|
242
|
+
op = [0];
|
|
243
|
+
continue;
|
|
244
|
+
case 7:
|
|
245
|
+
op = _.ops.pop();
|
|
246
|
+
_.trys.pop();
|
|
247
|
+
continue;
|
|
248
|
+
default:
|
|
249
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
250
|
+
_ = 0;
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
254
|
+
_.label = op[1];
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
258
|
+
_.label = t[1];
|
|
242
259
|
t = op;
|
|
243
260
|
break;
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
op = _.ops.pop();
|
|
254
|
-
_.trys.pop();
|
|
255
|
-
continue;
|
|
256
|
-
default:
|
|
257
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
258
|
-
_ = 0;
|
|
259
|
-
continue;
|
|
260
|
-
}
|
|
261
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
262
|
-
_.label = op[1];
|
|
263
|
-
break;
|
|
264
|
-
}
|
|
265
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
266
|
-
_.label = t[1];
|
|
267
|
-
t = op;
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
if (t && _.label < t[2]) {
|
|
271
|
-
_.label = t[2];
|
|
272
|
-
_.ops.push(op);
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
if (t[2])
|
|
276
|
-
_.ops.pop();
|
|
277
|
-
_.trys.pop();
|
|
278
|
-
continue;
|
|
279
|
-
}
|
|
280
|
-
op = body.call(thisArg, _);
|
|
281
|
-
} catch (e) {
|
|
282
|
-
op = [6, e];
|
|
283
|
-
y = 0;
|
|
284
|
-
} finally {
|
|
285
|
-
f = t = 0;
|
|
261
|
+
}
|
|
262
|
+
if (t && _.label < t[2]) {
|
|
263
|
+
_.label = t[2];
|
|
264
|
+
_.ops.push(op);
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
if (t[2]) _.ops.pop();
|
|
268
|
+
_.trys.pop();
|
|
269
|
+
continue;
|
|
286
270
|
}
|
|
287
|
-
|
|
288
|
-
|
|
271
|
+
op = body.call(thisArg, _);
|
|
272
|
+
} catch (e) {
|
|
273
|
+
op = [6, e];
|
|
274
|
+
y = 0;
|
|
275
|
+
} finally {
|
|
276
|
+
f = t = 0;
|
|
277
|
+
}
|
|
278
|
+
if (op[0] & 5) throw op[1];
|
|
289
279
|
return { value: op[0] ? op[1] : void 0, done: true };
|
|
290
280
|
}
|
|
291
281
|
};
|
|
@@ -293,7 +283,7 @@ var require_skip_first_delay = __commonJS({
|
|
|
293
283
|
var delay_base_1 = require_delay_base();
|
|
294
284
|
var SkipFirstDelay = (
|
|
295
285
|
/** @class */
|
|
296
|
-
function(_super) {
|
|
286
|
+
(function(_super) {
|
|
297
287
|
__extends(SkipFirstDelay2, _super);
|
|
298
288
|
function SkipFirstDelay2() {
|
|
299
289
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
@@ -320,7 +310,7 @@ var require_skip_first_delay = __commonJS({
|
|
|
320
310
|
configurable: true
|
|
321
311
|
});
|
|
322
312
|
return SkipFirstDelay2;
|
|
323
|
-
}(delay_base_1.Delay)
|
|
313
|
+
})(delay_base_1.Delay)
|
|
324
314
|
);
|
|
325
315
|
exports.SkipFirstDelay = SkipFirstDelay;
|
|
326
316
|
}
|
|
@@ -330,14 +320,12 @@ var require_skip_first_delay = __commonJS({
|
|
|
330
320
|
var require_always_delay = __commonJS({
|
|
331
321
|
"../../node_modules/.pnpm/exponential-backoff@3.1.1/node_modules/exponential-backoff/dist/delay/always/always.delay.js"(exports) {
|
|
332
322
|
"use strict";
|
|
333
|
-
var __extends = exports && exports.__extends || function() {
|
|
323
|
+
var __extends = exports && exports.__extends || /* @__PURE__ */ (function() {
|
|
334
324
|
var extendStatics = function(d, b) {
|
|
335
325
|
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
336
326
|
d2.__proto__ = b2;
|
|
337
327
|
} || function(d2, b2) {
|
|
338
|
-
for (var p in b2)
|
|
339
|
-
if (b2.hasOwnProperty(p))
|
|
340
|
-
d2[p] = b2[p];
|
|
328
|
+
for (var p in b2) if (b2.hasOwnProperty(p)) d2[p] = b2[p];
|
|
341
329
|
};
|
|
342
330
|
return extendStatics(d, b);
|
|
343
331
|
};
|
|
@@ -348,18 +336,18 @@ var require_always_delay = __commonJS({
|
|
|
348
336
|
}
|
|
349
337
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
350
338
|
};
|
|
351
|
-
}();
|
|
339
|
+
})();
|
|
352
340
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
353
341
|
var delay_base_1 = require_delay_base();
|
|
354
342
|
var AlwaysDelay = (
|
|
355
343
|
/** @class */
|
|
356
|
-
function(_super) {
|
|
344
|
+
(function(_super) {
|
|
357
345
|
__extends(AlwaysDelay2, _super);
|
|
358
346
|
function AlwaysDelay2() {
|
|
359
347
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
360
348
|
}
|
|
361
349
|
return AlwaysDelay2;
|
|
362
|
-
}(delay_base_1.Delay)
|
|
350
|
+
})(delay_base_1.Delay)
|
|
363
351
|
);
|
|
364
352
|
exports.AlwaysDelay = AlwaysDelay;
|
|
365
353
|
}
|
|
@@ -420,8 +408,7 @@ var require_backoff = __commonJS({
|
|
|
420
408
|
};
|
|
421
409
|
var __generator = exports && exports.__generator || function(thisArg, body) {
|
|
422
410
|
var _ = { label: 0, sent: function() {
|
|
423
|
-
if (t[0] & 1)
|
|
424
|
-
throw t[1];
|
|
411
|
+
if (t[0] & 1) throw t[1];
|
|
425
412
|
return t[1];
|
|
426
413
|
}, trys: [], ops: [] }, f, y, t, g;
|
|
427
414
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
@@ -433,64 +420,58 @@ var require_backoff = __commonJS({
|
|
|
433
420
|
};
|
|
434
421
|
}
|
|
435
422
|
function step(op) {
|
|
436
|
-
if (f)
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
423
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
424
|
+
while (_) try {
|
|
425
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
426
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
427
|
+
switch (op[0]) {
|
|
428
|
+
case 0:
|
|
429
|
+
case 1:
|
|
430
|
+
t = op;
|
|
431
|
+
break;
|
|
432
|
+
case 4:
|
|
433
|
+
_.label++;
|
|
434
|
+
return { value: op[1], done: false };
|
|
435
|
+
case 5:
|
|
436
|
+
_.label++;
|
|
437
|
+
y = op[1];
|
|
438
|
+
op = [0];
|
|
439
|
+
continue;
|
|
440
|
+
case 7:
|
|
441
|
+
op = _.ops.pop();
|
|
442
|
+
_.trys.pop();
|
|
443
|
+
continue;
|
|
444
|
+
default:
|
|
445
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
446
|
+
_ = 0;
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
450
|
+
_.label = op[1];
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
453
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
454
|
+
_.label = t[1];
|
|
447
455
|
t = op;
|
|
448
456
|
break;
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
op = _.ops.pop();
|
|
459
|
-
_.trys.pop();
|
|
460
|
-
continue;
|
|
461
|
-
default:
|
|
462
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
463
|
-
_ = 0;
|
|
464
|
-
continue;
|
|
465
|
-
}
|
|
466
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
467
|
-
_.label = op[1];
|
|
468
|
-
break;
|
|
469
|
-
}
|
|
470
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
471
|
-
_.label = t[1];
|
|
472
|
-
t = op;
|
|
473
|
-
break;
|
|
474
|
-
}
|
|
475
|
-
if (t && _.label < t[2]) {
|
|
476
|
-
_.label = t[2];
|
|
477
|
-
_.ops.push(op);
|
|
478
|
-
break;
|
|
479
|
-
}
|
|
480
|
-
if (t[2])
|
|
481
|
-
_.ops.pop();
|
|
482
|
-
_.trys.pop();
|
|
483
|
-
continue;
|
|
484
|
-
}
|
|
485
|
-
op = body.call(thisArg, _);
|
|
486
|
-
} catch (e) {
|
|
487
|
-
op = [6, e];
|
|
488
|
-
y = 0;
|
|
489
|
-
} finally {
|
|
490
|
-
f = t = 0;
|
|
457
|
+
}
|
|
458
|
+
if (t && _.label < t[2]) {
|
|
459
|
+
_.label = t[2];
|
|
460
|
+
_.ops.push(op);
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
if (t[2]) _.ops.pop();
|
|
464
|
+
_.trys.pop();
|
|
465
|
+
continue;
|
|
491
466
|
}
|
|
492
|
-
|
|
493
|
-
|
|
467
|
+
op = body.call(thisArg, _);
|
|
468
|
+
} catch (e) {
|
|
469
|
+
op = [6, e];
|
|
470
|
+
y = 0;
|
|
471
|
+
} finally {
|
|
472
|
+
f = t = 0;
|
|
473
|
+
}
|
|
474
|
+
if (op[0] & 5) throw op[1];
|
|
494
475
|
return { value: op[0] ? op[1] : void 0, done: true };
|
|
495
476
|
}
|
|
496
477
|
};
|
|
@@ -518,7 +499,7 @@ var require_backoff = __commonJS({
|
|
|
518
499
|
exports.backOff = backOff3;
|
|
519
500
|
var BackOff = (
|
|
520
501
|
/** @class */
|
|
521
|
-
function() {
|
|
502
|
+
(function() {
|
|
522
503
|
function BackOff2(request, options) {
|
|
523
504
|
this.request = request;
|
|
524
505
|
this.options = options;
|
|
@@ -530,8 +511,7 @@ var require_backoff = __commonJS({
|
|
|
530
511
|
return __generator(this, function(_a) {
|
|
531
512
|
switch (_a.label) {
|
|
532
513
|
case 0:
|
|
533
|
-
if (!!this.attemptLimitReached)
|
|
534
|
-
return [3, 7];
|
|
514
|
+
if (!!this.attemptLimitReached) return [3, 7];
|
|
535
515
|
_a.label = 1;
|
|
536
516
|
case 1:
|
|
537
517
|
_a.trys.push([1, 4, , 6]);
|
|
@@ -585,7 +565,7 @@ var require_backoff = __commonJS({
|
|
|
585
565
|
});
|
|
586
566
|
};
|
|
587
567
|
return BackOff2;
|
|
588
|
-
}()
|
|
568
|
+
})()
|
|
589
569
|
);
|
|
590
570
|
}
|
|
591
571
|
});
|
|
@@ -656,54 +636,57 @@ import axios from "axios";
|
|
|
656
636
|
var isBrowser = () => typeof window !== "undefined" && typeof window.fetch === "function";
|
|
657
637
|
var CognitiveBeta = class {
|
|
658
638
|
_axiosClient;
|
|
659
|
-
|
|
639
|
+
_apiUrl;
|
|
640
|
+
_timeout;
|
|
641
|
+
_withCredentials;
|
|
642
|
+
_headers;
|
|
660
643
|
constructor(props) {
|
|
661
|
-
this.
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
}
|
|
644
|
+
this._apiUrl = props.apiUrl || "https://api.botpress.cloud";
|
|
645
|
+
this._timeout = props.timeout || 60001;
|
|
646
|
+
this._withCredentials = props.withCredentials || false;
|
|
647
|
+
this._headers = { ...props.headers };
|
|
648
|
+
if (props.botId) {
|
|
649
|
+
this._headers["X-Bot-Id"] = props.botId;
|
|
650
|
+
}
|
|
651
|
+
if (props.token) {
|
|
652
|
+
this._headers["Authorization"] = `Bearer ${props.token}`;
|
|
653
|
+
}
|
|
668
654
|
this._axiosClient = axios.create({
|
|
669
|
-
headers:
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
...this._config.headers
|
|
673
|
-
},
|
|
674
|
-
baseURL: this._config.baseUrl
|
|
655
|
+
headers: this._headers,
|
|
656
|
+
withCredentials: this._withCredentials,
|
|
657
|
+
baseURL: this._apiUrl
|
|
675
658
|
});
|
|
676
659
|
}
|
|
677
660
|
async generateText(input, options = {}) {
|
|
678
|
-
const signal = options.signal ?? AbortSignal.timeout(this.
|
|
661
|
+
const signal = options.signal ?? AbortSignal.timeout(this._timeout);
|
|
679
662
|
const { data } = await this._withServerRetry(
|
|
680
|
-
() => this._axiosClient.post("/
|
|
663
|
+
() => this._axiosClient.post("/v2/cognitive/generate-text", input, {
|
|
681
664
|
signal,
|
|
682
|
-
timeout: options.timeout ?? this.
|
|
665
|
+
timeout: options.timeout ?? this._timeout
|
|
683
666
|
})
|
|
684
667
|
);
|
|
685
668
|
return data;
|
|
686
669
|
}
|
|
687
670
|
async listModels(input, options = {}) {
|
|
688
|
-
const signal = options.signal ?? AbortSignal.timeout(this.
|
|
671
|
+
const signal = options.signal ?? AbortSignal.timeout(this._timeout);
|
|
689
672
|
const { data } = await this._withServerRetry(
|
|
690
|
-
() => this._axiosClient.post("/
|
|
673
|
+
() => this._axiosClient.post("/v2/cognitive/models", input, {
|
|
691
674
|
signal,
|
|
692
|
-
timeout: options.timeout ?? this.
|
|
675
|
+
timeout: options.timeout ?? this._timeout
|
|
693
676
|
})
|
|
694
677
|
);
|
|
695
678
|
return data;
|
|
696
679
|
}
|
|
697
680
|
async *generateTextStream(request, options = {}) {
|
|
698
|
-
const signal = options.signal ?? AbortSignal.timeout(this.
|
|
681
|
+
const signal = options.signal ?? AbortSignal.timeout(this._timeout);
|
|
699
682
|
if (isBrowser()) {
|
|
700
|
-
const res2 = await fetch(`${this.
|
|
683
|
+
const res2 = await fetch(`${this._apiUrl}/v2/cognitive/generate-text-stream`, {
|
|
701
684
|
method: "POST",
|
|
702
685
|
headers: {
|
|
703
|
-
|
|
704
|
-
"X-Bot-Id": this._config.botId,
|
|
686
|
+
...this._headers,
|
|
705
687
|
"Content-Type": "application/json"
|
|
706
688
|
},
|
|
689
|
+
credentials: this._withCredentials ? "include" : "omit",
|
|
707
690
|
body: JSON.stringify({ ...request, stream: true }),
|
|
708
691
|
signal
|
|
709
692
|
});
|
|
@@ -718,7 +701,7 @@ var CognitiveBeta = class {
|
|
|
718
701
|
throw new Error("No response body received for streaming request");
|
|
719
702
|
}
|
|
720
703
|
const reader = body.getReader();
|
|
721
|
-
const iterable = async function* () {
|
|
704
|
+
const iterable = (async function* () {
|
|
722
705
|
for (; ; ) {
|
|
723
706
|
const { value, done } = await reader.read();
|
|
724
707
|
if (done) {
|
|
@@ -728,7 +711,7 @@ var CognitiveBeta = class {
|
|
|
728
711
|
yield value;
|
|
729
712
|
}
|
|
730
713
|
}
|
|
731
|
-
}();
|
|
714
|
+
})();
|
|
732
715
|
for await (const obj of this._ndjson(iterable)) {
|
|
733
716
|
yield obj;
|
|
734
717
|
}
|
|
@@ -741,7 +724,7 @@ var CognitiveBeta = class {
|
|
|
741
724
|
{
|
|
742
725
|
responseType: "stream",
|
|
743
726
|
signal,
|
|
744
|
-
timeout: options.timeout ?? this.
|
|
727
|
+
timeout: options.timeout ?? this._timeout
|
|
745
728
|
}
|
|
746
729
|
)
|
|
747
730
|
);
|
|
@@ -923,7 +906,7 @@ var getBestModels = (models, boosts = {}) => models.sort((a, b) => scoreModel(b,
|
|
|
923
906
|
var getFastModels = (models, boosts = {}) => models.sort((a, b) => scoreModel(b, "fast", boosts) - scoreModel(a, "fast", boosts));
|
|
924
907
|
var pickModel = (models, downtimes = []) => {
|
|
925
908
|
const copy = [...models];
|
|
926
|
-
const elasped = (date) => new Date().getTime() - new Date(date).getTime();
|
|
909
|
+
const elasped = (date) => (/* @__PURE__ */ new Date()).getTime() - new Date(date).getTime();
|
|
927
910
|
const DOWNTIME_THRESHOLD = 1e3 * 60 * DOWNTIME_THRESHOLD_MINUTES;
|
|
928
911
|
if (!copy.length) {
|
|
929
912
|
throw new Error("At least one model is required");
|
|
@@ -1037,7 +1020,7 @@ var RemoteModelProvider = class extends ModelProvider {
|
|
|
1037
1020
|
};
|
|
1038
1021
|
|
|
1039
1022
|
// src/client.ts
|
|
1040
|
-
var Cognitive = class {
|
|
1023
|
+
var Cognitive = class _Cognitive {
|
|
1041
1024
|
["$$IS_COGNITIVE"] = true;
|
|
1042
1025
|
static isCognitiveClient(obj) {
|
|
1043
1026
|
return obj?.$$IS_COGNITIVE === true;
|
|
@@ -1068,7 +1051,7 @@ var Cognitive = class {
|
|
|
1068
1051
|
return this._client;
|
|
1069
1052
|
}
|
|
1070
1053
|
clone() {
|
|
1071
|
-
const copy = new
|
|
1054
|
+
const copy = new _Cognitive({
|
|
1072
1055
|
client: this._client.clone(),
|
|
1073
1056
|
provider: this._provider,
|
|
1074
1057
|
timeout: this._timeoutMs,
|
|
@@ -1152,10 +1135,7 @@ var Cognitive = class {
|
|
|
1152
1135
|
if (!this._useBeta) {
|
|
1153
1136
|
return this._generateContent(input);
|
|
1154
1137
|
}
|
|
1155
|
-
const betaClient = new CognitiveBeta(
|
|
1156
|
-
headers: this._client.config.headers,
|
|
1157
|
-
baseUrl: this._client.config.apiUrl.includes(".cloud") ? "https://cognitive.botpress.cloud" : "https://cognitive.botpress.dev"
|
|
1158
|
-
});
|
|
1138
|
+
const betaClient = new CognitiveBeta(this._client.config);
|
|
1159
1139
|
const response = await betaClient.generateText(input);
|
|
1160
1140
|
return {
|
|
1161
1141
|
output: {
|
|
@@ -1237,7 +1217,7 @@ var Cognitive = class {
|
|
|
1237
1217
|
if (action === "fallback") {
|
|
1238
1218
|
this._downtimes.push({
|
|
1239
1219
|
ref: `${integration}:${model}`,
|
|
1240
|
-
startedAt: new Date().toISOString(),
|
|
1220
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1241
1221
|
reason: "Model is down"
|
|
1242
1222
|
});
|
|
1243
1223
|
this._cleanupOldDowntimes();
|