@xpert-ai/plugin-sdk 3.7.1 → 3.7.2

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/index.cjs.js CHANGED
@@ -4,6 +4,7 @@ var common = require('@nestjs/common');
4
4
  var constants = require('@nestjs/common/constants');
5
5
  var lodashEs = require('lodash-es');
6
6
  var core = require('@nestjs/core');
7
+ var rxjs = require('rxjs');
7
8
  var contracts = require('@metad/contracts');
8
9
  var node_async_hooks = require('node:async_hooks');
9
10
  var passportJwt = require('passport-jwt');
@@ -20,6 +21,8 @@ var path = require('path');
20
21
  var i18next = require('i18next');
21
22
  var FsBackend = require('i18next-fs-backend');
22
23
  var yaml = require('yaml');
24
+ var Ajv = require('ajv');
25
+ var schemaDraft04 = require('ajv/dist/refs/json-schema-draft-06.json');
23
26
  var _axios = require('axios');
24
27
  var openai = require('@langchain/openai');
25
28
  var documents = require('@langchain/core/documents');
@@ -122,44 +125,6 @@ function createPluginLogger(scope, baseMeta = {}) {
122
125
  const INTEGRATION_STRATEGY = 'INTEGRATION_STRATEGY';
123
126
  const IntegrationStrategyKey = (provider)=>common.applyDecorators(common.SetMetadata(INTEGRATION_STRATEGY, provider), common.SetMetadata(STRATEGY_META_KEY, INTEGRATION_STRATEGY));
124
127
 
125
- /******************************************************************************
126
- Copyright (c) Microsoft Corporation.
127
-
128
- Permission to use, copy, modify, and/or distribute this software for any
129
- purpose with or without fee is hereby granted.
130
-
131
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
132
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
133
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
134
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
135
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
136
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
137
- PERFORMANCE OF THIS SOFTWARE.
138
- ***************************************************************************** */ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */ function _instanceof$2(left, right) {
139
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
140
- return !!right[Symbol.hasInstance](left);
141
- } else {
142
- return left instanceof right;
143
- }
144
- }
145
- var extendStatics = function extendStatics1(d, b) {
146
- extendStatics = Object.setPrototypeOf || _instanceof$2({
147
- __proto__: []
148
- }, Array) && function(d, b) {
149
- d.__proto__ = b;
150
- } || function(d, b) {
151
- for(var p in b)if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
152
- };
153
- return extendStatics(d, b);
154
- };
155
- function __extends(d, b) {
156
- if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
157
- extendStatics(d, b);
158
- function __() {
159
- this.constructor = d;
160
- }
161
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
162
- }
163
128
  function __decorate(decorators, target, key, desc) {
164
129
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
165
130
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -169,763 +134,11 @@ function __decorate(decorators, target, key, desc) {
169
134
  function __metadata(metadataKey, metadataValue) {
170
135
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
171
136
  }
172
- function __values(o) {
173
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
174
- if (m) return m.call(o);
175
- if (o && typeof o.length === "number") return {
176
- next: function next() {
177
- if (o && i >= o.length) o = void 0;
178
- return {
179
- value: o && o[i++],
180
- done: !o
181
- };
182
- }
183
- };
184
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
185
- }
186
- function __read(o, n) {
187
- var m = typeof Symbol === "function" && o[Symbol.iterator];
188
- if (!m) return o;
189
- var i = m.call(o), r, ar = [], e;
190
- try {
191
- while((n === void 0 || n-- > 0) && !(r = i.next()).done)ar.push(r.value);
192
- } catch (error) {
193
- e = {
194
- error: error
195
- };
196
- } finally{
197
- try {
198
- if (r && !r.done && (m = i["return"])) m.call(i);
199
- } finally{
200
- if (e) throw e.error;
201
- }
202
- }
203
- return ar;
204
- }
205
- function __spreadArray(to, from, pack) {
206
- if (pack || arguments.length === 2) for(var i = 0, l = from.length, ar; i < l; i++){
207
- if (ar || !(i in from)) {
208
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
209
- ar[i] = from[i];
210
- }
211
- }
212
- return to.concat(ar || Array.prototype.slice.call(from));
213
- }
214
137
  typeof SuppressedError === "function" ? SuppressedError : function _SuppressedError(error, suppressed, message) {
215
138
  var e = new Error(message);
216
139
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
217
140
  };
218
141
 
219
- function isFunction(value) {
220
- return typeof value === "function";
221
- }
222
-
223
- function createErrorClass(createImpl) {
224
- var _super = function _super(instance) {
225
- Error.call(instance);
226
- instance.stack = new Error().stack;
227
- };
228
- var ctorFunc = createImpl(_super);
229
- ctorFunc.prototype = Object.create(Error.prototype);
230
- ctorFunc.prototype.constructor = ctorFunc;
231
- return ctorFunc;
232
- }
233
-
234
- var UnsubscriptionError = createErrorClass(function(_super) {
235
- return function UnsubscriptionErrorImpl(errors) {
236
- _super(this);
237
- this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function(err, i) {
238
- return i + 1 + ") " + err.toString();
239
- }).join("\n ") : "";
240
- this.name = "UnsubscriptionError";
241
- this.errors = errors;
242
- };
243
- });
244
-
245
- function arrRemove(arr, item) {
246
- if (arr) {
247
- var index = arr.indexOf(item);
248
- 0 <= index && arr.splice(index, 1);
249
- }
250
- }
251
-
252
- function _instanceof$1(left, right) {
253
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
254
- return !!right[Symbol.hasInstance](left);
255
- } else {
256
- return left instanceof right;
257
- }
258
- }
259
- var Subscription = function() {
260
- function Subscription(initialTeardown) {
261
- this.initialTeardown = initialTeardown;
262
- this.closed = false;
263
- this._parentage = null;
264
- this._finalizers = null;
265
- }
266
- Subscription.prototype.unsubscribe = function() {
267
- var e_1, _a, e_2, _b;
268
- var errors;
269
- if (!this.closed) {
270
- this.closed = true;
271
- var _parentage = this._parentage;
272
- if (_parentage) {
273
- this._parentage = null;
274
- if (Array.isArray(_parentage)) {
275
- try {
276
- for(var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()){
277
- var parent_1 = _parentage_1_1.value;
278
- parent_1.remove(this);
279
- }
280
- } catch (e_1_1) {
281
- e_1 = {
282
- error: e_1_1
283
- };
284
- } finally{
285
- try {
286
- if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
287
- } finally{
288
- if (e_1) throw e_1.error;
289
- }
290
- }
291
- } else {
292
- _parentage.remove(this);
293
- }
294
- }
295
- var initialFinalizer = this.initialTeardown;
296
- if (isFunction(initialFinalizer)) {
297
- try {
298
- initialFinalizer();
299
- } catch (e) {
300
- errors = _instanceof$1(e, UnsubscriptionError) ? e.errors : [
301
- e
302
- ];
303
- }
304
- }
305
- var _finalizers = this._finalizers;
306
- if (_finalizers) {
307
- this._finalizers = null;
308
- try {
309
- for(var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()){
310
- var finalizer = _finalizers_1_1.value;
311
- try {
312
- execFinalizer(finalizer);
313
- } catch (err) {
314
- errors = errors !== null && errors !== void 0 ? errors : [];
315
- if (_instanceof$1(err, UnsubscriptionError)) {
316
- errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
317
- } else {
318
- errors.push(err);
319
- }
320
- }
321
- }
322
- } catch (e_2_1) {
323
- e_2 = {
324
- error: e_2_1
325
- };
326
- } finally{
327
- try {
328
- if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return)) _b.call(_finalizers_1);
329
- } finally{
330
- if (e_2) throw e_2.error;
331
- }
332
- }
333
- }
334
- if (errors) {
335
- throw new UnsubscriptionError(errors);
336
- }
337
- }
338
- };
339
- Subscription.prototype.add = function(teardown) {
340
- var _a;
341
- if (teardown && teardown !== this) {
342
- if (this.closed) {
343
- execFinalizer(teardown);
344
- } else {
345
- if (_instanceof$1(teardown, Subscription)) {
346
- if (teardown.closed || teardown._hasParent(this)) {
347
- return;
348
- }
349
- teardown._addParent(this);
350
- }
351
- (this._finalizers = (_a = this._finalizers) !== null && _a !== void 0 ? _a : []).push(teardown);
352
- }
353
- }
354
- };
355
- Subscription.prototype._hasParent = function(parent) {
356
- var _parentage = this._parentage;
357
- return _parentage === parent || Array.isArray(_parentage) && _parentage.includes(parent);
358
- };
359
- Subscription.prototype._addParent = function(parent) {
360
- var _parentage = this._parentage;
361
- this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [
362
- _parentage,
363
- parent
364
- ] : parent;
365
- };
366
- Subscription.prototype._removeParent = function(parent) {
367
- var _parentage = this._parentage;
368
- if (_parentage === parent) {
369
- this._parentage = null;
370
- } else if (Array.isArray(_parentage)) {
371
- arrRemove(_parentage, parent);
372
- }
373
- };
374
- Subscription.prototype.remove = function(teardown) {
375
- var _finalizers = this._finalizers;
376
- _finalizers && arrRemove(_finalizers, teardown);
377
- if (_instanceof$1(teardown, Subscription)) {
378
- teardown._removeParent(this);
379
- }
380
- };
381
- Subscription.EMPTY = function() {
382
- var empty = new Subscription();
383
- empty.closed = true;
384
- return empty;
385
- }();
386
- return Subscription;
387
- }();
388
- var EMPTY_SUBSCRIPTION = Subscription.EMPTY;
389
- function isSubscription(value) {
390
- return _instanceof$1(value, Subscription) || value && "closed" in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe);
391
- }
392
- function execFinalizer(finalizer) {
393
- if (isFunction(finalizer)) {
394
- finalizer();
395
- } else {
396
- finalizer.unsubscribe();
397
- }
398
- }
399
-
400
- var config = {
401
- Promise: undefined};
402
-
403
- var timeoutProvider = {
404
- setTimeout: function setTimeout1(handler, timeout) {
405
- var args = [];
406
- for(var _i = 2; _i < arguments.length; _i++){
407
- args[_i - 2] = arguments[_i];
408
- }
409
- return setTimeout.apply(void 0, __spreadArray([
410
- handler,
411
- timeout
412
- ], __read(args)));
413
- },
414
- clearTimeout: function clearTimeout1(handle) {
415
- return (clearTimeout)(handle);
416
- },
417
- delegate: undefined
418
- };
419
-
420
- function reportUnhandledError(err) {
421
- timeoutProvider.setTimeout(function() {
422
- {
423
- throw err;
424
- }
425
- });
426
- }
427
-
428
- function noop() {}
429
-
430
- function errorContext(cb) {
431
- {
432
- cb();
433
- }
434
- }
435
-
436
- var Subscriber = function(_super) {
437
- __extends(Subscriber, _super);
438
- function Subscriber(destination) {
439
- var _this = _super.call(this) || this;
440
- _this.isStopped = false;
441
- if (destination) {
442
- _this.destination = destination;
443
- if (isSubscription(destination)) {
444
- destination.add(_this);
445
- }
446
- } else {
447
- _this.destination = EMPTY_OBSERVER;
448
- }
449
- return _this;
450
- }
451
- Subscriber.create = function(next, error, complete) {
452
- return new SafeSubscriber(next, error, complete);
453
- };
454
- Subscriber.prototype.next = function(value) {
455
- if (this.isStopped) ; else {
456
- this._next(value);
457
- }
458
- };
459
- Subscriber.prototype.error = function(err) {
460
- if (this.isStopped) ; else {
461
- this.isStopped = true;
462
- this._error(err);
463
- }
464
- };
465
- Subscriber.prototype.complete = function() {
466
- if (this.isStopped) ; else {
467
- this.isStopped = true;
468
- this._complete();
469
- }
470
- };
471
- Subscriber.prototype.unsubscribe = function() {
472
- if (!this.closed) {
473
- this.isStopped = true;
474
- _super.prototype.unsubscribe.call(this);
475
- this.destination = null;
476
- }
477
- };
478
- Subscriber.prototype._next = function(value) {
479
- this.destination.next(value);
480
- };
481
- Subscriber.prototype._error = function(err) {
482
- try {
483
- this.destination.error(err);
484
- } finally{
485
- this.unsubscribe();
486
- }
487
- };
488
- Subscriber.prototype._complete = function() {
489
- try {
490
- this.destination.complete();
491
- } finally{
492
- this.unsubscribe();
493
- }
494
- };
495
- return Subscriber;
496
- }(Subscription);
497
- var ConsumerObserver = function() {
498
- function ConsumerObserver(partialObserver) {
499
- this.partialObserver = partialObserver;
500
- }
501
- ConsumerObserver.prototype.next = function(value) {
502
- var partialObserver = this.partialObserver;
503
- if (partialObserver.next) {
504
- try {
505
- partialObserver.next(value);
506
- } catch (error) {
507
- handleUnhandledError(error);
508
- }
509
- }
510
- };
511
- ConsumerObserver.prototype.error = function(err) {
512
- var partialObserver = this.partialObserver;
513
- if (partialObserver.error) {
514
- try {
515
- partialObserver.error(err);
516
- } catch (error) {
517
- handleUnhandledError(error);
518
- }
519
- } else {
520
- handleUnhandledError(err);
521
- }
522
- };
523
- ConsumerObserver.prototype.complete = function() {
524
- var partialObserver = this.partialObserver;
525
- if (partialObserver.complete) {
526
- try {
527
- partialObserver.complete();
528
- } catch (error) {
529
- handleUnhandledError(error);
530
- }
531
- }
532
- };
533
- return ConsumerObserver;
534
- }();
535
- var SafeSubscriber = function(_super) {
536
- __extends(SafeSubscriber, _super);
537
- function SafeSubscriber(observerOrNext, error, complete) {
538
- var _this = _super.call(this) || this;
539
- var partialObserver;
540
- if (isFunction(observerOrNext) || !observerOrNext) {
541
- partialObserver = {
542
- next: observerOrNext !== null && observerOrNext !== void 0 ? observerOrNext : undefined,
543
- error: error !== null && error !== void 0 ? error : undefined,
544
- complete: complete !== null && complete !== void 0 ? complete : undefined
545
- };
546
- } else {
547
- {
548
- partialObserver = observerOrNext;
549
- }
550
- }
551
- _this.destination = new ConsumerObserver(partialObserver);
552
- return _this;
553
- }
554
- return SafeSubscriber;
555
- }(Subscriber);
556
- function handleUnhandledError(error) {
557
- {
558
- reportUnhandledError(error);
559
- }
560
- }
561
- function defaultErrorHandler(err) {
562
- throw err;
563
- }
564
- var EMPTY_OBSERVER = {
565
- closed: true,
566
- next: noop,
567
- error: defaultErrorHandler,
568
- complete: noop
569
- };
570
-
571
- var observable = function() {
572
- return typeof Symbol === "function" && Symbol.observable || "@@observable";
573
- }();
574
-
575
- function identity(x) {
576
- return x;
577
- }
578
-
579
- function pipeFromArray(fns) {
580
- if (fns.length === 0) {
581
- return identity;
582
- }
583
- if (fns.length === 1) {
584
- return fns[0];
585
- }
586
- return function piped(input) {
587
- return fns.reduce(function(prev, fn) {
588
- return fn(prev);
589
- }, input);
590
- };
591
- }
592
-
593
- function _instanceof(left, right) {
594
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
595
- return !!right[Symbol.hasInstance](left);
596
- } else {
597
- return left instanceof right;
598
- }
599
- }
600
- var Observable = function() {
601
- function Observable(subscribe) {
602
- if (subscribe) {
603
- this._subscribe = subscribe;
604
- }
605
- }
606
- Observable.prototype.lift = function(operator) {
607
- var observable = new Observable();
608
- observable.source = this;
609
- observable.operator = operator;
610
- return observable;
611
- };
612
- Observable.prototype.subscribe = function(observerOrNext, error, complete) {
613
- var _this = this;
614
- var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
615
- errorContext(function() {
616
- var _a = _this, operator = _a.operator, source = _a.source;
617
- subscriber.add(operator ? operator.call(subscriber, source) : source ? _this._subscribe(subscriber) : _this._trySubscribe(subscriber));
618
- });
619
- return subscriber;
620
- };
621
- Observable.prototype._trySubscribe = function(sink) {
622
- try {
623
- return this._subscribe(sink);
624
- } catch (err) {
625
- sink.error(err);
626
- }
627
- };
628
- Observable.prototype.forEach = function(next, promiseCtor) {
629
- var _this = this;
630
- promiseCtor = getPromiseCtor(promiseCtor);
631
- return new promiseCtor(function(resolve, reject) {
632
- var subscriber = new SafeSubscriber({
633
- next: function next1(value) {
634
- try {
635
- next(value);
636
- } catch (err) {
637
- reject(err);
638
- subscriber.unsubscribe();
639
- }
640
- },
641
- error: reject,
642
- complete: resolve
643
- });
644
- _this.subscribe(subscriber);
645
- });
646
- };
647
- Observable.prototype._subscribe = function(subscriber) {
648
- var _a;
649
- return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
650
- };
651
- Observable.prototype[observable] = function() {
652
- return this;
653
- };
654
- Observable.prototype.pipe = function() {
655
- var operations = [];
656
- for(var _i = 0; _i < arguments.length; _i++){
657
- operations[_i] = arguments[_i];
658
- }
659
- return pipeFromArray(operations)(this);
660
- };
661
- Observable.prototype.toPromise = function(promiseCtor) {
662
- var _this = this;
663
- promiseCtor = getPromiseCtor(promiseCtor);
664
- return new promiseCtor(function(resolve, reject) {
665
- var value;
666
- _this.subscribe(function(x) {
667
- return value = x;
668
- }, function(err) {
669
- return reject(err);
670
- }, function() {
671
- return resolve(value);
672
- });
673
- });
674
- };
675
- Observable.create = function(subscribe) {
676
- return new Observable(subscribe);
677
- };
678
- return Observable;
679
- }();
680
- function getPromiseCtor(promiseCtor) {
681
- var _a;
682
- return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise;
683
- }
684
- function isObserver(value) {
685
- return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
686
- }
687
- function isSubscriber(value) {
688
- return value && _instanceof(value, Subscriber) || isObserver(value) && isSubscription(value);
689
- }
690
-
691
- function hasLift(source) {
692
- return isFunction(source === null || source === void 0 ? void 0 : source.lift);
693
- }
694
- function operate(init) {
695
- return function(source) {
696
- if (hasLift(source)) {
697
- return source.lift(function(liftedSource) {
698
- try {
699
- return init(liftedSource, this);
700
- } catch (err) {
701
- this.error(err);
702
- }
703
- });
704
- }
705
- throw new TypeError("Unable to lift unknown Observable type");
706
- };
707
- }
708
-
709
- function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
710
- return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
711
- }
712
- var OperatorSubscriber = function(_super) {
713
- __extends(OperatorSubscriber, _super);
714
- function OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
715
- var _this = _super.call(this, destination) || this;
716
- _this.onFinalize = onFinalize;
717
- _this.shouldUnsubscribe = shouldUnsubscribe;
718
- _this._next = onNext ? function(value) {
719
- try {
720
- onNext(value);
721
- } catch (err) {
722
- destination.error(err);
723
- }
724
- } : _super.prototype._next;
725
- _this._error = onError ? function(err) {
726
- try {
727
- onError(err);
728
- } catch (err) {
729
- destination.error(err);
730
- } finally{
731
- this.unsubscribe();
732
- }
733
- } : _super.prototype._error;
734
- _this._complete = onComplete ? function() {
735
- try {
736
- onComplete();
737
- } catch (err) {
738
- destination.error(err);
739
- } finally{
740
- this.unsubscribe();
741
- }
742
- } : _super.prototype._complete;
743
- return _this;
744
- }
745
- OperatorSubscriber.prototype.unsubscribe = function() {
746
- var _a;
747
- if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
748
- var closed_1 = this.closed;
749
- _super.prototype.unsubscribe.call(this);
750
- !closed_1 && ((_a = this.onFinalize) === null || _a === void 0 ? void 0 : _a.call(this));
751
- }
752
- };
753
- return OperatorSubscriber;
754
- }(Subscriber);
755
-
756
- var ObjectUnsubscribedError = createErrorClass(function(_super) {
757
- return function ObjectUnsubscribedErrorImpl() {
758
- _super(this);
759
- this.name = "ObjectUnsubscribedError";
760
- this.message = "object unsubscribed";
761
- };
762
- });
763
-
764
- var Subject = function(_super) {
765
- __extends(Subject, _super);
766
- function Subject() {
767
- var _this = _super.call(this) || this;
768
- _this.closed = false;
769
- _this.currentObservers = null;
770
- _this.observers = [];
771
- _this.isStopped = false;
772
- _this.hasError = false;
773
- _this.thrownError = null;
774
- return _this;
775
- }
776
- Subject.prototype.lift = function(operator) {
777
- var subject = new AnonymousSubject(this, this);
778
- subject.operator = operator;
779
- return subject;
780
- };
781
- Subject.prototype._throwIfClosed = function() {
782
- if (this.closed) {
783
- throw new ObjectUnsubscribedError();
784
- }
785
- };
786
- Subject.prototype.next = function(value) {
787
- var _this = this;
788
- errorContext(function() {
789
- var e_1, _a;
790
- _this._throwIfClosed();
791
- if (!_this.isStopped) {
792
- if (!_this.currentObservers) {
793
- _this.currentObservers = Array.from(_this.observers);
794
- }
795
- try {
796
- for(var _b = __values(_this.currentObservers), _c = _b.next(); !_c.done; _c = _b.next()){
797
- var observer = _c.value;
798
- observer.next(value);
799
- }
800
- } catch (e_1_1) {
801
- e_1 = {
802
- error: e_1_1
803
- };
804
- } finally{
805
- try {
806
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
807
- } finally{
808
- if (e_1) throw e_1.error;
809
- }
810
- }
811
- }
812
- });
813
- };
814
- Subject.prototype.error = function(err) {
815
- var _this = this;
816
- errorContext(function() {
817
- _this._throwIfClosed();
818
- if (!_this.isStopped) {
819
- _this.hasError = _this.isStopped = true;
820
- _this.thrownError = err;
821
- var observers = _this.observers;
822
- while(observers.length){
823
- observers.shift().error(err);
824
- }
825
- }
826
- });
827
- };
828
- Subject.prototype.complete = function() {
829
- var _this = this;
830
- errorContext(function() {
831
- _this._throwIfClosed();
832
- if (!_this.isStopped) {
833
- _this.isStopped = true;
834
- var observers = _this.observers;
835
- while(observers.length){
836
- observers.shift().complete();
837
- }
838
- }
839
- });
840
- };
841
- Subject.prototype.unsubscribe = function() {
842
- this.isStopped = this.closed = true;
843
- this.observers = this.currentObservers = null;
844
- };
845
- Object.defineProperty(Subject.prototype, "observed", {
846
- get: function get() {
847
- var _a;
848
- return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
849
- },
850
- enumerable: false,
851
- configurable: true
852
- });
853
- Subject.prototype._trySubscribe = function(subscriber) {
854
- this._throwIfClosed();
855
- return _super.prototype._trySubscribe.call(this, subscriber);
856
- };
857
- Subject.prototype._subscribe = function(subscriber) {
858
- this._throwIfClosed();
859
- this._checkFinalizedStatuses(subscriber);
860
- return this._innerSubscribe(subscriber);
861
- };
862
- Subject.prototype._innerSubscribe = function(subscriber) {
863
- var _this = this;
864
- var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
865
- if (hasError || isStopped) {
866
- return EMPTY_SUBSCRIPTION;
867
- }
868
- this.currentObservers = null;
869
- observers.push(subscriber);
870
- return new Subscription(function() {
871
- _this.currentObservers = null;
872
- arrRemove(observers, subscriber);
873
- });
874
- };
875
- Subject.prototype._checkFinalizedStatuses = function(subscriber) {
876
- var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
877
- if (hasError) {
878
- subscriber.error(thrownError);
879
- } else if (isStopped) {
880
- subscriber.complete();
881
- }
882
- };
883
- Subject.prototype.asObservable = function() {
884
- var observable = new Observable();
885
- observable.source = this;
886
- return observable;
887
- };
888
- Subject.create = function(destination, source) {
889
- return new AnonymousSubject(destination, source);
890
- };
891
- return Subject;
892
- }(Observable);
893
- var AnonymousSubject = function(_super) {
894
- __extends(AnonymousSubject, _super);
895
- function AnonymousSubject(destination, source) {
896
- var _this = _super.call(this) || this;
897
- _this.destination = destination;
898
- _this.source = source;
899
- return _this;
900
- }
901
- AnonymousSubject.prototype.next = function(value) {
902
- var _a, _b;
903
- (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.next) === null || _b === void 0 ? void 0 : _b.call(_a, value);
904
- };
905
- AnonymousSubject.prototype.error = function(err) {
906
- var _a, _b;
907
- (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.call(_a, err);
908
- };
909
- AnonymousSubject.prototype.complete = function() {
910
- var _a, _b;
911
- (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.complete) === null || _b === void 0 ? void 0 : _b.call(_a);
912
- };
913
- AnonymousSubject.prototype._subscribe = function(subscriber) {
914
- var _a, _b;
915
- return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : EMPTY_SUBSCRIPTION;
916
- };
917
- return AnonymousSubject;
918
- }(Subject);
919
-
920
- function filter(predicate, thisArg) {
921
- return operate(function(source, subscriber) {
922
- var index = 0;
923
- source.subscribe(createOperatorSubscriber(subscriber, function(value) {
924
- return predicate.call(thisArg, value, index++) && subscriber.next(value);
925
- }));
926
- });
927
- }
928
-
929
142
  // request-context.ts
930
143
  class RequestContext {
931
144
  static currentRequestContext() {
@@ -1158,7 +371,7 @@ exports.StrategyBus = class StrategyBus {
1158
371
  });
1159
372
  }
1160
373
  constructor(){
1161
- this.subject = new Subject();
374
+ this.subject = new rxjs.Subject();
1162
375
  this.events$ = this.subject.asObservable();
1163
376
  }
1164
377
  };
@@ -1168,8 +381,7 @@ exports.StrategyBus = __decorate([
1168
381
 
1169
382
  class BaseStrategyRegistry {
1170
383
  onModuleInit() {
1171
- this.bus.events$.pipe(filter((event)=>!event.strategyType || event.strategyType === this.strategyKey)).subscribe((evt)=>{
1172
- this.logger.debug(`Received strategy bus event: ${JSON.stringify(evt)}`);
384
+ this.bus.events$.pipe(rxjs.filter((event)=>!event.strategyType || event.strategyType === this.strategyKey)).subscribe((evt)=>{
1173
385
  if (evt.type === 'UPSERT') {
1174
386
  this.upsert(evt.entry.instance);
1175
387
  } else if (evt.type === 'REMOVE') {
@@ -1818,6 +1030,28 @@ function getErrorMessage(err) {
1818
1030
  }
1819
1031
  return error;
1820
1032
  }
1033
+ class JsonSchemaValidator {
1034
+ parseAndValidate(schemaStr) {
1035
+ if (!schemaStr) return undefined;
1036
+ let schema;
1037
+ try {
1038
+ schema = JSON.parse(schemaStr);
1039
+ } catch (e) {
1040
+ throw new Error('Schema is not valid JSON');
1041
+ }
1042
+ const validate = this.ajv.getSchema(schemaDraft04.$id);
1043
+ if (!validate(schema)) {
1044
+ throw new Error('Invalid JSON Schema: ' + this.ajv.errorsText(validate.errors));
1045
+ }
1046
+ return schema;
1047
+ }
1048
+ constructor(){
1049
+ this.ajv = new Ajv({
1050
+ strict: false
1051
+ });
1052
+ this.ajv.addMetaSchema(schemaDraft04);
1053
+ }
1054
+ }
1821
1055
 
1822
1056
  const DATASOURCE_STRATEGY = 'DATASOURCE_STRATEGY';
1823
1057
  const DataSourceStrategy = (provider)=>common.applyDecorators(common.SetMetadata(DATASOURCE_STRATEGY, provider), common.SetMetadata(STRATEGY_META_KEY, DATASOURCE_STRATEGY));
@@ -2425,6 +1659,46 @@ const PARAMETER_RULE_TEMPLATE = {
2425
1659
  }
2426
1660
  };
2427
1661
 
1662
+ const CommonParameterRules = [
1663
+ {
1664
+ name: 'temperature',
1665
+ label: {
1666
+ zh_Hans: '温度',
1667
+ en_US: `Temperature`
1668
+ },
1669
+ type: contracts.ParameterType.FLOAT,
1670
+ help: {
1671
+ zh_Hans: '控制模型输出的随机性。较高的值(例如 1.0)使响应更具创意,而较低的值(例如 0.1)使响应更具确定性和重点性。',
1672
+ en_US: `Controls the randomness of the model's output. A higher value (e.g., 1.0) makes responses more creative, while a lower value (e.g., 0.1) makes them more deterministic and focused.`
1673
+ },
1674
+ required: false,
1675
+ default: 0.2,
1676
+ min: 0,
1677
+ max: 1,
1678
+ precision: 0.1
1679
+ },
1680
+ {
1681
+ label: {
1682
+ zh_Hans: '最大尝试次数',
1683
+ en_US: 'The maximum number of attempts'
1684
+ },
1685
+ type: contracts.ParameterType.INT,
1686
+ help: {
1687
+ zh_Hans: '如果请求由于网络超时或速率限制等问题而失败,系统将尝试重新发送请求的最大次数',
1688
+ en_US: 'The maximum number of attempts the system will make to resend a request if it fails due to issues like network timeouts or rate limits'
1689
+ },
1690
+ required: false,
1691
+ default: 6,
1692
+ min: 0,
1693
+ max: 10,
1694
+ precision: 0,
1695
+ name: 'maxRetries'
1696
+ }
1697
+ ];
1698
+ function mergeCredentials(credentials, modelProperties) {
1699
+ return _extends({}, credentials != null ? credentials : {}, modelProperties != null ? modelProperties : {});
1700
+ }
1701
+
2428
1702
  let AIModel = class AIModel {
2429
1703
  getChatModel(copilotModel, options) {
2430
1704
  throw new Error(`Unsupport chat model!`);
@@ -2568,6 +1842,15 @@ let AIModel = class AIModel {
2568
1842
  ...parameterRules.filter((_)=>!CommonParameterRules.some((r)=>r.name === _.name))
2569
1843
  ];
2570
1844
  }
1845
+ getModelProfile(model, credentials) {
1846
+ var _modelSchema_model_properties, _modelSchema_features, _modelSchema_features1, _modelSchema_features2, _modelSchema_features3;
1847
+ const modelSchema = this.getModelSchema(model, credentials);
1848
+ return modelSchema && {
1849
+ maxInputTokens: (_modelSchema_model_properties = modelSchema.model_properties) == null ? void 0 : _modelSchema_model_properties.context_size,
1850
+ toolCalling: ((_modelSchema_features = modelSchema.features) == null ? void 0 : _modelSchema_features.includes(contracts.ModelFeature.TOOL_CALL)) || ((_modelSchema_features1 = modelSchema.features) == null ? void 0 : _modelSchema_features1.includes(contracts.ModelFeature.MULTI_TOOL_CALL)) || ((_modelSchema_features2 = modelSchema.features) == null ? void 0 : _modelSchema_features2.includes(contracts.ModelFeature.STREAM_TOOL_CALL)),
1851
+ structuredOutput: (_modelSchema_features3 = modelSchema.features) == null ? void 0 : _modelSchema_features3.includes(contracts.ModelFeature.STRUCTURED_OUTPUT)
1852
+ };
1853
+ }
2571
1854
  constructor(modelProvider, modelType){
2572
1855
  this.modelProvider = modelProvider;
2573
1856
  this.modelType = modelType;
@@ -2607,46 +1890,6 @@ class RerankModel extends AIModel {
2607
1890
  }
2608
1891
  }
2609
1892
 
2610
- const CommonParameterRules = [
2611
- {
2612
- name: 'temperature',
2613
- label: {
2614
- zh_Hans: '温度',
2615
- en_US: `Temperature`
2616
- },
2617
- type: contracts.ParameterType.FLOAT,
2618
- help: {
2619
- zh_Hans: '控制模型输出的随机性。较高的值(例如 1.0)使响应更具创意,而较低的值(例如 0.1)使响应更具确定性和重点性。',
2620
- en_US: `Controls the randomness of the model's output. A higher value (e.g., 1.0) makes responses more creative, while a lower value (e.g., 0.1) makes them more deterministic and focused.`
2621
- },
2622
- required: false,
2623
- default: 0.2,
2624
- min: 0,
2625
- max: 1,
2626
- precision: 0.1
2627
- },
2628
- {
2629
- label: {
2630
- zh_Hans: '最大尝试次数',
2631
- en_US: 'The maximum number of attempts'
2632
- },
2633
- type: contracts.ParameterType.INT,
2634
- help: {
2635
- zh_Hans: '如果请求由于网络超时或速率限制等问题而失败,系统将尝试重新发送请求的最大次数',
2636
- en_US: 'The maximum number of attempts the system will make to resend a request if it fails due to issues like network timeouts or rate limits'
2637
- },
2638
- required: false,
2639
- default: 6,
2640
- min: 0,
2641
- max: 10,
2642
- precision: 0,
2643
- name: 'maxRetries'
2644
- }
2645
- ];
2646
- function mergeCredentials(credentials, modelProperties) {
2647
- return _extends({}, credentials != null ? credentials : {}, modelProperties != null ? modelProperties : {});
2648
- }
2649
-
2650
1893
  class SpeechToTextModel extends AIModel {
2651
1894
  }
2652
1895
 
@@ -2973,7 +2216,7 @@ class OpenAICompatibleReranker {
2973
2216
  if (!Array.isArray(output)) {
2974
2217
  throw new Error('Invalid response format: missing results array');
2975
2218
  }
2976
- // 收集原始分数并进行归一化处理
2219
+ // Collect raw scores and normalize them.
2977
2220
  const scores = output.map((r)=>r.relevance_score);
2978
2221
  const minScore = Math.min(...scores);
2979
2222
  const maxScore = Math.max(...scores);
@@ -3122,6 +2365,7 @@ exports.INTEGRATION_STRATEGY = INTEGRATION_STRATEGY;
3122
2365
  exports.ImageUnderstandingStrategy = ImageUnderstandingStrategy;
3123
2366
  exports.IntegrationStrategyKey = IntegrationStrategyKey;
3124
2367
  exports.JUMP_TO_TARGETS = JUMP_TO_TARGETS;
2368
+ exports.JsonSchemaValidator = JsonSchemaValidator;
3125
2369
  exports.KNOWLEDGE_STRATEGY = KNOWLEDGE_STRATEGY;
3126
2370
  exports.KnowledgeStrategyKey = KnowledgeStrategyKey;
3127
2371
  exports.LLMUsage = LLMUsage;