agent-swarm-kit 1.0.83 → 1.0.85
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/build/index.cjs +432 -96
- package/build/index.cjs.map +1 -0
- package/build/index.mjs +431 -97
- package/build/index.mjs.map +1 -0
- package/package.json +1 -1
- package/types.d.ts +84 -1
package/build/index.mjs
CHANGED
|
@@ -193,6 +193,10 @@ var schemaServices$1 = {
|
|
|
193
193
|
storageSchemaService: Symbol('storageSchemaService'),
|
|
194
194
|
stateSchemaService: Symbol('stateSchemaService'),
|
|
195
195
|
};
|
|
196
|
+
var metaServices$1 = {
|
|
197
|
+
agentMetaService: Symbol('agentMetaService'),
|
|
198
|
+
swarmMetaService: Symbol('swarmMetaService'),
|
|
199
|
+
};
|
|
196
200
|
var publicServices$1 = {
|
|
197
201
|
agentPublicService: Symbol('agentPublicService'),
|
|
198
202
|
historyPublicService: Symbol('historyPublicService'),
|
|
@@ -210,7 +214,7 @@ var validationServices$1 = {
|
|
|
210
214
|
embeddingValidationService: Symbol('embeddingValidationService'),
|
|
211
215
|
storageValidationService: Symbol('storageValidationService'),
|
|
212
216
|
};
|
|
213
|
-
var TYPES = __assign(__assign(__assign(__assign(__assign(__assign({}, baseServices$1), contextServices$1), schemaServices$1), connectionServices$1), publicServices$1), validationServices$1);
|
|
217
|
+
var TYPES = __assign(__assign(__assign(__assign(__assign(__assign(__assign({}, baseServices$1), contextServices$1), schemaServices$1), connectionServices$1), publicServices$1), validationServices$1), metaServices$1);
|
|
214
218
|
|
|
215
219
|
/**
|
|
216
220
|
* Service providing execution context information.
|
|
@@ -394,89 +398,161 @@ var HistoryInstance = /** @class */ (function () {
|
|
|
394
398
|
if (callbacks.filterCondition) {
|
|
395
399
|
this.iterate = function (agentName) {
|
|
396
400
|
return __asyncGenerator(this, arguments, function () {
|
|
397
|
-
var _b, _c, item, e_1_1, _d, _e, item,
|
|
398
|
-
var e_1,
|
|
399
|
-
return __generator(this, function (
|
|
400
|
-
switch (
|
|
401
|
+
var _b, _c, item, e_1_1, _d, _e, content, e_2_1, _f, _g, item, e_3_1, _h, _j, content, e_4_1;
|
|
402
|
+
var e_1, _k, e_2, _l, e_3, _m, e_4, _o;
|
|
403
|
+
return __generator(this, function (_p) {
|
|
404
|
+
switch (_p.label) {
|
|
401
405
|
case 0:
|
|
402
406
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
403
407
|
swarm$1.loggerService.debug(INSTANCE_METHOD_NAME_ITERATE_CONDITION, {
|
|
404
408
|
clientId: this.clientId,
|
|
405
409
|
agentName: agentName,
|
|
406
410
|
});
|
|
407
|
-
if (!this.callbacks.onRead) return [3 /*break*/,
|
|
411
|
+
if (!this.callbacks.onRead) return [3 /*break*/, 22];
|
|
408
412
|
this.callbacks.onReadBegin &&
|
|
409
413
|
this.callbacks.onReadBegin(this.clientId, agentName);
|
|
410
|
-
|
|
414
|
+
_p.label = 1;
|
|
411
415
|
case 1:
|
|
412
|
-
|
|
416
|
+
_p.trys.push([1, 8, 9, 10]);
|
|
413
417
|
_b = __values(this._array), _c = _b.next();
|
|
414
|
-
|
|
418
|
+
_p.label = 2;
|
|
415
419
|
case 2:
|
|
416
420
|
if (!!_c.done) return [3 /*break*/, 7];
|
|
417
421
|
item = _c.value;
|
|
418
422
|
return [4 /*yield*/, __await(this.callbacks.filterCondition(item, this.clientId, agentName))];
|
|
419
423
|
case 3:
|
|
420
|
-
if (!
|
|
424
|
+
if (!_p.sent()) return [3 /*break*/, 6];
|
|
421
425
|
this.callbacks.onRead(item, this.clientId, agentName);
|
|
422
426
|
return [4 /*yield*/, __await(item)];
|
|
423
|
-
case 4: return [4 /*yield*/,
|
|
427
|
+
case 4: return [4 /*yield*/, _p.sent()];
|
|
424
428
|
case 5:
|
|
425
|
-
|
|
426
|
-
|
|
429
|
+
_p.sent();
|
|
430
|
+
_p.label = 6;
|
|
427
431
|
case 6:
|
|
428
432
|
_c = _b.next();
|
|
429
433
|
return [3 /*break*/, 2];
|
|
430
434
|
case 7: return [3 /*break*/, 10];
|
|
431
435
|
case 8:
|
|
432
|
-
e_1_1 =
|
|
436
|
+
e_1_1 = _p.sent();
|
|
433
437
|
e_1 = { error: e_1_1 };
|
|
434
438
|
return [3 /*break*/, 10];
|
|
435
439
|
case 9:
|
|
436
440
|
try {
|
|
437
|
-
if (_c && !_c.done && (
|
|
441
|
+
if (_c && !_c.done && (_k = _b.return)) _k.call(_b);
|
|
438
442
|
}
|
|
439
443
|
finally { if (e_1) throw e_1.error; }
|
|
440
444
|
return [7 /*endfinally*/];
|
|
441
445
|
case 10:
|
|
442
|
-
this.callbacks.
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
+
if (!this.callbacks.getSystemPrompt) return [3 /*break*/, 20];
|
|
447
|
+
_p.label = 11;
|
|
448
|
+
case 11:
|
|
449
|
+
_p.trys.push([11, 18, 19, 20]);
|
|
450
|
+
return [4 /*yield*/, __await(this.callbacks.getSystemPrompt(this.clientId, agentName))];
|
|
446
451
|
case 12:
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
_h.label = 13;
|
|
452
|
+
_d = __values.apply(void 0, [_p.sent()]), _e = _d.next();
|
|
453
|
+
_p.label = 13;
|
|
450
454
|
case 13:
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
455
|
+
if (!!_e.done) return [3 /*break*/, 17];
|
|
456
|
+
content = _e.value;
|
|
457
|
+
return [4 /*yield*/, __await({
|
|
458
|
+
role: "system",
|
|
459
|
+
content: content,
|
|
460
|
+
agentName: agentName,
|
|
461
|
+
mode: "tool"
|
|
462
|
+
})];
|
|
463
|
+
case 14: return [4 /*yield*/, _p.sent()];
|
|
458
464
|
case 15:
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
case 16:
|
|
462
|
-
case 17:
|
|
463
|
-
_h.sent();
|
|
464
|
-
_h.label = 18;
|
|
465
|
-
case 18:
|
|
465
|
+
_p.sent();
|
|
466
|
+
_p.label = 16;
|
|
467
|
+
case 16:
|
|
466
468
|
_e = _d.next();
|
|
467
|
-
return [3 /*break*/,
|
|
468
|
-
case
|
|
469
|
-
case
|
|
470
|
-
e_2_1 =
|
|
469
|
+
return [3 /*break*/, 13];
|
|
470
|
+
case 17: return [3 /*break*/, 20];
|
|
471
|
+
case 18:
|
|
472
|
+
e_2_1 = _p.sent();
|
|
471
473
|
e_2 = { error: e_2_1 };
|
|
472
|
-
return [3 /*break*/,
|
|
473
|
-
case
|
|
474
|
+
return [3 /*break*/, 20];
|
|
475
|
+
case 19:
|
|
474
476
|
try {
|
|
475
|
-
if (_e && !_e.done && (
|
|
477
|
+
if (_e && !_e.done && (_l = _d.return)) _l.call(_d);
|
|
476
478
|
}
|
|
477
479
|
finally { if (e_2) throw e_2.error; }
|
|
478
480
|
return [7 /*endfinally*/];
|
|
481
|
+
case 20:
|
|
482
|
+
this.callbacks.onReadEnd &&
|
|
483
|
+
this.callbacks.onReadEnd(this.clientId, agentName);
|
|
484
|
+
return [4 /*yield*/, __await(void 0)];
|
|
485
|
+
case 21: return [2 /*return*/, _p.sent()];
|
|
479
486
|
case 22:
|
|
487
|
+
this.callbacks.onReadBegin &&
|
|
488
|
+
this.callbacks.onReadBegin(this.clientId, agentName);
|
|
489
|
+
_p.label = 23;
|
|
490
|
+
case 23:
|
|
491
|
+
_p.trys.push([23, 30, 31, 32]);
|
|
492
|
+
_f = __values(this._array), _g = _f.next();
|
|
493
|
+
_p.label = 24;
|
|
494
|
+
case 24:
|
|
495
|
+
if (!!_g.done) return [3 /*break*/, 29];
|
|
496
|
+
item = _g.value;
|
|
497
|
+
return [4 /*yield*/, __await(this.callbacks.filterCondition(item, this.clientId, agentName))];
|
|
498
|
+
case 25:
|
|
499
|
+
if (!_p.sent()) return [3 /*break*/, 28];
|
|
500
|
+
return [4 /*yield*/, __await(item)];
|
|
501
|
+
case 26: return [4 /*yield*/, _p.sent()];
|
|
502
|
+
case 27:
|
|
503
|
+
_p.sent();
|
|
504
|
+
_p.label = 28;
|
|
505
|
+
case 28:
|
|
506
|
+
_g = _f.next();
|
|
507
|
+
return [3 /*break*/, 24];
|
|
508
|
+
case 29: return [3 /*break*/, 32];
|
|
509
|
+
case 30:
|
|
510
|
+
e_3_1 = _p.sent();
|
|
511
|
+
e_3 = { error: e_3_1 };
|
|
512
|
+
return [3 /*break*/, 32];
|
|
513
|
+
case 31:
|
|
514
|
+
try {
|
|
515
|
+
if (_g && !_g.done && (_m = _f.return)) _m.call(_f);
|
|
516
|
+
}
|
|
517
|
+
finally { if (e_3) throw e_3.error; }
|
|
518
|
+
return [7 /*endfinally*/];
|
|
519
|
+
case 32:
|
|
520
|
+
if (!this.callbacks.getSystemPrompt) return [3 /*break*/, 42];
|
|
521
|
+
_p.label = 33;
|
|
522
|
+
case 33:
|
|
523
|
+
_p.trys.push([33, 40, 41, 42]);
|
|
524
|
+
return [4 /*yield*/, __await(this.callbacks.getSystemPrompt(this.clientId, agentName))];
|
|
525
|
+
case 34:
|
|
526
|
+
_h = __values.apply(void 0, [_p.sent()]), _j = _h.next();
|
|
527
|
+
_p.label = 35;
|
|
528
|
+
case 35:
|
|
529
|
+
if (!!_j.done) return [3 /*break*/, 39];
|
|
530
|
+
content = _j.value;
|
|
531
|
+
return [4 /*yield*/, __await({
|
|
532
|
+
role: "system",
|
|
533
|
+
content: content,
|
|
534
|
+
agentName: agentName,
|
|
535
|
+
mode: "tool"
|
|
536
|
+
})];
|
|
537
|
+
case 36: return [4 /*yield*/, _p.sent()];
|
|
538
|
+
case 37:
|
|
539
|
+
_p.sent();
|
|
540
|
+
_p.label = 38;
|
|
541
|
+
case 38:
|
|
542
|
+
_j = _h.next();
|
|
543
|
+
return [3 /*break*/, 35];
|
|
544
|
+
case 39: return [3 /*break*/, 42];
|
|
545
|
+
case 40:
|
|
546
|
+
e_4_1 = _p.sent();
|
|
547
|
+
e_4 = { error: e_4_1 };
|
|
548
|
+
return [3 /*break*/, 42];
|
|
549
|
+
case 41:
|
|
550
|
+
try {
|
|
551
|
+
if (_j && !_j.done && (_o = _h.return)) _o.call(_h);
|
|
552
|
+
}
|
|
553
|
+
finally { if (e_4) throw e_4.error; }
|
|
554
|
+
return [7 /*endfinally*/];
|
|
555
|
+
case 42:
|
|
480
556
|
this.callbacks.onReadEnd &&
|
|
481
557
|
this.callbacks.onReadEnd(this.clientId, agentName);
|
|
482
558
|
return [2 /*return*/];
|
|
@@ -507,10 +583,10 @@ var HistoryInstance = /** @class */ (function () {
|
|
|
507
583
|
*/
|
|
508
584
|
HistoryInstance.prototype.iterate = function (agentName) {
|
|
509
585
|
return __asyncGenerator(this, arguments, function iterate_1() {
|
|
510
|
-
var _b, _c, item,
|
|
511
|
-
var
|
|
512
|
-
return __generator(this, function (
|
|
513
|
-
switch (
|
|
586
|
+
var _b, _c, item, e_5_1, _d, _e, item, e_6_1, _f, _g, content, e_7_1;
|
|
587
|
+
var e_5, _h, e_6, _j, e_7, _k;
|
|
588
|
+
return __generator(this, function (_l) {
|
|
589
|
+
switch (_l.label) {
|
|
514
590
|
case 0:
|
|
515
591
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
516
592
|
swarm$1.loggerService.debug(INSTANCE_METHOD_NAME_ITERATE, {
|
|
@@ -520,70 +596,106 @@ var HistoryInstance = /** @class */ (function () {
|
|
|
520
596
|
if (!this.callbacks.onRead) return [3 /*break*/, 11];
|
|
521
597
|
this.callbacks.onReadBegin &&
|
|
522
598
|
this.callbacks.onReadBegin(this.clientId, agentName);
|
|
523
|
-
|
|
599
|
+
_l.label = 1;
|
|
524
600
|
case 1:
|
|
525
|
-
|
|
601
|
+
_l.trys.push([1, 7, 8, 9]);
|
|
526
602
|
_b = __values(this._array), _c = _b.next();
|
|
527
|
-
|
|
603
|
+
_l.label = 2;
|
|
528
604
|
case 2:
|
|
529
605
|
if (!!_c.done) return [3 /*break*/, 6];
|
|
530
606
|
item = _c.value;
|
|
531
607
|
this.callbacks.onRead(item, this.clientId, agentName);
|
|
532
608
|
return [4 /*yield*/, __await(item)];
|
|
533
|
-
case 3: return [4 /*yield*/,
|
|
609
|
+
case 3: return [4 /*yield*/, _l.sent()];
|
|
534
610
|
case 4:
|
|
535
|
-
|
|
536
|
-
|
|
611
|
+
_l.sent();
|
|
612
|
+
_l.label = 5;
|
|
537
613
|
case 5:
|
|
538
614
|
_c = _b.next();
|
|
539
615
|
return [3 /*break*/, 2];
|
|
540
616
|
case 6: return [3 /*break*/, 9];
|
|
541
617
|
case 7:
|
|
542
|
-
|
|
543
|
-
|
|
618
|
+
e_5_1 = _l.sent();
|
|
619
|
+
e_5 = { error: e_5_1 };
|
|
544
620
|
return [3 /*break*/, 9];
|
|
545
621
|
case 8:
|
|
546
622
|
try {
|
|
547
|
-
if (_c && !_c.done && (
|
|
623
|
+
if (_c && !_c.done && (_h = _b.return)) _h.call(_b);
|
|
548
624
|
}
|
|
549
|
-
finally { if (
|
|
625
|
+
finally { if (e_5) throw e_5.error; }
|
|
550
626
|
return [7 /*endfinally*/];
|
|
551
627
|
case 9:
|
|
552
628
|
this.callbacks.onReadEnd &&
|
|
553
629
|
this.callbacks.onReadEnd(this.clientId, agentName);
|
|
554
630
|
return [4 /*yield*/, __await(void 0)];
|
|
555
|
-
case 10: return [2 /*return*/,
|
|
631
|
+
case 10: return [2 /*return*/, _l.sent()];
|
|
556
632
|
case 11:
|
|
557
633
|
this.callbacks.onReadBegin &&
|
|
558
634
|
this.callbacks.onReadBegin(this.clientId, agentName);
|
|
559
|
-
|
|
635
|
+
_l.label = 12;
|
|
560
636
|
case 12:
|
|
561
|
-
|
|
637
|
+
_l.trys.push([12, 18, 19, 20]);
|
|
562
638
|
_d = __values(this._array), _e = _d.next();
|
|
563
|
-
|
|
639
|
+
_l.label = 13;
|
|
564
640
|
case 13:
|
|
565
641
|
if (!!_e.done) return [3 /*break*/, 17];
|
|
566
642
|
item = _e.value;
|
|
567
643
|
return [4 /*yield*/, __await(item)];
|
|
568
|
-
case 14: return [4 /*yield*/,
|
|
644
|
+
case 14: return [4 /*yield*/, _l.sent()];
|
|
569
645
|
case 15:
|
|
570
|
-
|
|
571
|
-
|
|
646
|
+
_l.sent();
|
|
647
|
+
_l.label = 16;
|
|
572
648
|
case 16:
|
|
573
649
|
_e = _d.next();
|
|
574
650
|
return [3 /*break*/, 13];
|
|
575
651
|
case 17: return [3 /*break*/, 20];
|
|
576
652
|
case 18:
|
|
577
|
-
|
|
578
|
-
|
|
653
|
+
e_6_1 = _l.sent();
|
|
654
|
+
e_6 = { error: e_6_1 };
|
|
579
655
|
return [3 /*break*/, 20];
|
|
580
656
|
case 19:
|
|
581
657
|
try {
|
|
582
|
-
if (_e && !_e.done && (
|
|
658
|
+
if (_e && !_e.done && (_j = _d.return)) _j.call(_d);
|
|
583
659
|
}
|
|
584
|
-
finally { if (
|
|
660
|
+
finally { if (e_6) throw e_6.error; }
|
|
585
661
|
return [7 /*endfinally*/];
|
|
586
662
|
case 20:
|
|
663
|
+
if (!this.callbacks.getSystemPrompt) return [3 /*break*/, 30];
|
|
664
|
+
_l.label = 21;
|
|
665
|
+
case 21:
|
|
666
|
+
_l.trys.push([21, 28, 29, 30]);
|
|
667
|
+
return [4 /*yield*/, __await(this.callbacks.getSystemPrompt(this.clientId, agentName))];
|
|
668
|
+
case 22:
|
|
669
|
+
_f = __values.apply(void 0, [_l.sent()]), _g = _f.next();
|
|
670
|
+
_l.label = 23;
|
|
671
|
+
case 23:
|
|
672
|
+
if (!!_g.done) return [3 /*break*/, 27];
|
|
673
|
+
content = _g.value;
|
|
674
|
+
return [4 /*yield*/, __await({
|
|
675
|
+
role: "system",
|
|
676
|
+
content: content,
|
|
677
|
+
agentName: agentName,
|
|
678
|
+
mode: "tool"
|
|
679
|
+
})];
|
|
680
|
+
case 24: return [4 /*yield*/, _l.sent()];
|
|
681
|
+
case 25:
|
|
682
|
+
_l.sent();
|
|
683
|
+
_l.label = 26;
|
|
684
|
+
case 26:
|
|
685
|
+
_g = _f.next();
|
|
686
|
+
return [3 /*break*/, 23];
|
|
687
|
+
case 27: return [3 /*break*/, 30];
|
|
688
|
+
case 28:
|
|
689
|
+
e_7_1 = _l.sent();
|
|
690
|
+
e_7 = { error: e_7_1 };
|
|
691
|
+
return [3 /*break*/, 30];
|
|
692
|
+
case 29:
|
|
693
|
+
try {
|
|
694
|
+
if (_g && !_g.done && (_k = _f.return)) _k.call(_f);
|
|
695
|
+
}
|
|
696
|
+
finally { if (e_7) throw e_7.error; }
|
|
697
|
+
return [7 /*endfinally*/];
|
|
698
|
+
case 30:
|
|
587
699
|
this.callbacks.onReadEnd &&
|
|
588
700
|
this.callbacks.onReadEnd(this.clientId, agentName);
|
|
589
701
|
return [2 /*return*/];
|
|
@@ -736,8 +848,8 @@ var HistoryUtils = /** @class */ (function () {
|
|
|
736
848
|
*/
|
|
737
849
|
HistoryUtils.prototype.iterate = function (clientId, agentName) {
|
|
738
850
|
return __asyncGenerator(this, arguments, function iterate_2() {
|
|
739
|
-
var isInitial, history, _b, _c, _d, item,
|
|
740
|
-
var _e,
|
|
851
|
+
var isInitial, history, _b, _c, _d, item, e_8_1;
|
|
852
|
+
var _e, e_8, _f, _g;
|
|
741
853
|
return __generator(this, function (_h) {
|
|
742
854
|
switch (_h.label) {
|
|
743
855
|
case 0:
|
|
@@ -774,8 +886,8 @@ var HistoryUtils = /** @class */ (function () {
|
|
|
774
886
|
return [3 /*break*/, 4];
|
|
775
887
|
case 9: return [3 /*break*/, 16];
|
|
776
888
|
case 10:
|
|
777
|
-
|
|
778
|
-
|
|
889
|
+
e_8_1 = _h.sent();
|
|
890
|
+
e_8 = { error: e_8_1 };
|
|
779
891
|
return [3 /*break*/, 16];
|
|
780
892
|
case 11:
|
|
781
893
|
_h.trys.push([11, , 14, 15]);
|
|
@@ -786,7 +898,7 @@ var HistoryUtils = /** @class */ (function () {
|
|
|
786
898
|
_h.label = 13;
|
|
787
899
|
case 13: return [3 /*break*/, 15];
|
|
788
900
|
case 14:
|
|
789
|
-
if (
|
|
901
|
+
if (e_8) throw e_8.error;
|
|
790
902
|
return [7 /*endfinally*/];
|
|
791
903
|
case 15: return [7 /*endfinally*/];
|
|
792
904
|
case 16: return [2 /*return*/];
|
|
@@ -4823,6 +4935,7 @@ var AgentValidationService = /** @class */ (function () {
|
|
|
4823
4935
|
this.completionValidationService = inject(TYPES.completionValidationService);
|
|
4824
4936
|
this.storageValidationService = inject(TYPES.storageValidationService);
|
|
4825
4937
|
this._agentMap = new Map();
|
|
4938
|
+
this._agentDepsMap = new Map();
|
|
4826
4939
|
/**
|
|
4827
4940
|
* Retrieves the storages used by the agent
|
|
4828
4941
|
* @param {agentName} agentName - The name of the swarm.
|
|
@@ -4863,6 +4976,9 @@ var AgentValidationService = /** @class */ (function () {
|
|
|
4863
4976
|
throw new Error("agent-swarm agent ".concat(agentName, " already exist"));
|
|
4864
4977
|
}
|
|
4865
4978
|
_this._agentMap.set(agentName, agentSchema);
|
|
4979
|
+
if (agentSchema.dependsOn) {
|
|
4980
|
+
_this._agentDepsMap.set(agentName, agentSchema.dependsOn);
|
|
4981
|
+
}
|
|
4866
4982
|
};
|
|
4867
4983
|
/**
|
|
4868
4984
|
* Check if agent got registered storage
|
|
@@ -4882,6 +4998,23 @@ var AgentValidationService = /** @class */ (function () {
|
|
|
4882
4998
|
var _a = _this._agentMap.get(agentName).storages, storages = _a === void 0 ? [] : _a;
|
|
4883
4999
|
return storages.includes(storageName);
|
|
4884
5000
|
});
|
|
5001
|
+
/**
|
|
5002
|
+
* Check if agent got registered dependency
|
|
5003
|
+
*/
|
|
5004
|
+
this.hasDependency = memoize(function (_a) {
|
|
5005
|
+
var _b = __read(_a, 2), targetAgentName = _b[0], depAgentName = _b[1];
|
|
5006
|
+
return "".concat(targetAgentName, "-").concat(depAgentName);
|
|
5007
|
+
}, function (targetAgentName, depAgentName) {
|
|
5008
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
|
|
5009
|
+
_this.loggerService.info("agentValidationService hasDependency", {
|
|
5010
|
+
targetAgentName: targetAgentName,
|
|
5011
|
+
depAgentName: depAgentName,
|
|
5012
|
+
});
|
|
5013
|
+
if (_this._agentDepsMap.has(targetAgentName)) {
|
|
5014
|
+
return _this._agentDepsMap.get(targetAgentName).includes(depAgentName);
|
|
5015
|
+
}
|
|
5016
|
+
return true;
|
|
5017
|
+
});
|
|
4885
5018
|
/**
|
|
4886
5019
|
* Check if agent got registered state
|
|
4887
5020
|
*/
|
|
@@ -7079,6 +7212,162 @@ var BusService = /** @class */ (function () {
|
|
|
7079
7212
|
return BusService;
|
|
7080
7213
|
}());
|
|
7081
7214
|
|
|
7215
|
+
var MAX_NESTING = 10;
|
|
7216
|
+
var UML_STEP = "\t";
|
|
7217
|
+
var UML_BULLET = "•";
|
|
7218
|
+
/**
|
|
7219
|
+
* Creates a function to serialize meta nodes to UML format.
|
|
7220
|
+
* @returns {Function} A function that takes an array of IMetaNode and returns a string in UML format.
|
|
7221
|
+
*/
|
|
7222
|
+
var createSerialize = function () { return function (nodes) {
|
|
7223
|
+
var lines = [];
|
|
7224
|
+
var process = function (nodes, level, seen) {
|
|
7225
|
+
var e_1, _a;
|
|
7226
|
+
var _b;
|
|
7227
|
+
if (level === void 0) { level = 0; }
|
|
7228
|
+
if (seen === void 0) { seen = new Set(); }
|
|
7229
|
+
try {
|
|
7230
|
+
for (var nodes_1 = __values(nodes), nodes_1_1 = nodes_1.next(); !nodes_1_1.done; nodes_1_1 = nodes_1.next()) {
|
|
7231
|
+
var node = nodes_1_1.value;
|
|
7232
|
+
var space = __spreadArray([], __read(new Array(level)), false).fill(UML_STEP).join("");
|
|
7233
|
+
if (seen.has(node.name)) {
|
|
7234
|
+
lines.push("".concat(space).concat(String(node.name), ": \"\""));
|
|
7235
|
+
}
|
|
7236
|
+
else if (((_b = node.child) === null || _b === void 0 ? void 0 : _b.length) && level < MAX_NESTING) {
|
|
7237
|
+
lines.push("".concat(space).concat(String(node.name), ":"));
|
|
7238
|
+
lines.push("".concat(space).concat(UML_STEP).concat(UML_BULLET, " ").concat(String(node.name), ": \"\""));
|
|
7239
|
+
process(node.child, level + 1, seen.add(node.name));
|
|
7240
|
+
}
|
|
7241
|
+
else {
|
|
7242
|
+
lines.push("".concat(space).concat(String(node.name), ": \"\""));
|
|
7243
|
+
}
|
|
7244
|
+
}
|
|
7245
|
+
}
|
|
7246
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
7247
|
+
finally {
|
|
7248
|
+
try {
|
|
7249
|
+
if (nodes_1_1 && !nodes_1_1.done && (_a = nodes_1.return)) _a.call(nodes_1);
|
|
7250
|
+
}
|
|
7251
|
+
finally { if (e_1) throw e_1.error; }
|
|
7252
|
+
}
|
|
7253
|
+
};
|
|
7254
|
+
process(nodes);
|
|
7255
|
+
var result = __spreadArray(__spreadArray(["@startyaml"], __read(lines), false), ["@endyaml"], false).join("\n");
|
|
7256
|
+
return result;
|
|
7257
|
+
}; };
|
|
7258
|
+
/**
|
|
7259
|
+
* Service class for managing agent meta nodes and converting them to UML format.
|
|
7260
|
+
*/
|
|
7261
|
+
var AgentMetaService = /** @class */ (function () {
|
|
7262
|
+
function AgentMetaService() {
|
|
7263
|
+
var _this = this;
|
|
7264
|
+
this.loggerService = inject(TYPES.loggerService);
|
|
7265
|
+
this.agentSchemaService = inject(TYPES.agentSchemaService);
|
|
7266
|
+
this.serialize = createSerialize();
|
|
7267
|
+
/**
|
|
7268
|
+
* Creates a meta node for the given agent.
|
|
7269
|
+
* @param {AgentName} agentName - The name of the agent.
|
|
7270
|
+
* @param {Set<AgentName>} seen - A set of seen agent names to avoid circular dependencies.
|
|
7271
|
+
* @returns {IMetaNode} The created meta node.
|
|
7272
|
+
*/
|
|
7273
|
+
this.makeAgentNode = function (agentName, seen) {
|
|
7274
|
+
if (seen === void 0) { seen = new Set(); }
|
|
7275
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
|
|
7276
|
+
_this.loggerService.info("agentMetaService makeAgentNode", {
|
|
7277
|
+
agentName: agentName,
|
|
7278
|
+
});
|
|
7279
|
+
var _a = _this.agentSchemaService.get(agentName), dependsOn = _a.dependsOn, states = _a.states, storages = _a.storages, tools = _a.tools;
|
|
7280
|
+
var childSeen = seen.add(agentName);
|
|
7281
|
+
var agentTree = [];
|
|
7282
|
+
if (dependsOn && !seen.has(agentName)) {
|
|
7283
|
+
agentTree.push({
|
|
7284
|
+
name: "Agents (".concat(agentName, ")"),
|
|
7285
|
+
child: dependsOn.map(function (dep) { return _this.makeAgentNode(dep, childSeen); }),
|
|
7286
|
+
});
|
|
7287
|
+
}
|
|
7288
|
+
if (states) {
|
|
7289
|
+
agentTree.push({
|
|
7290
|
+
name: "States (".concat(agentName, ")"),
|
|
7291
|
+
child: states.map(function (name) { return ({ name: name }); }),
|
|
7292
|
+
});
|
|
7293
|
+
}
|
|
7294
|
+
if (storages) {
|
|
7295
|
+
agentTree.push({
|
|
7296
|
+
name: "Storages (".concat(agentName, ")"),
|
|
7297
|
+
child: storages.map(function (name) { return ({ name: name }); }),
|
|
7298
|
+
});
|
|
7299
|
+
}
|
|
7300
|
+
if (tools) {
|
|
7301
|
+
agentTree.push({
|
|
7302
|
+
name: "Tools (".concat(agentName, ")"),
|
|
7303
|
+
child: tools.map(function (name) { return ({ name: name }); }),
|
|
7304
|
+
});
|
|
7305
|
+
}
|
|
7306
|
+
return {
|
|
7307
|
+
name: agentName,
|
|
7308
|
+
child: agentTree,
|
|
7309
|
+
};
|
|
7310
|
+
};
|
|
7311
|
+
/**
|
|
7312
|
+
* Converts the meta nodes of the given agent to UML format.
|
|
7313
|
+
* @param {AgentName} agentName - The name of the agent.
|
|
7314
|
+
* @returns {string} The UML representation of the agent's meta nodes.
|
|
7315
|
+
*/
|
|
7316
|
+
this.toUML = function (agentName) {
|
|
7317
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
|
|
7318
|
+
_this.loggerService.info("agentMetaService toUML", {
|
|
7319
|
+
agentName: agentName,
|
|
7320
|
+
});
|
|
7321
|
+
var rootNode = _this.makeAgentNode(agentName);
|
|
7322
|
+
return _this.serialize([rootNode]);
|
|
7323
|
+
};
|
|
7324
|
+
}
|
|
7325
|
+
return AgentMetaService;
|
|
7326
|
+
}());
|
|
7327
|
+
|
|
7328
|
+
/**
|
|
7329
|
+
* Service for handling swarm metadata.
|
|
7330
|
+
*/
|
|
7331
|
+
var SwarmMetaService = /** @class */ (function () {
|
|
7332
|
+
function SwarmMetaService() {
|
|
7333
|
+
var _this = this;
|
|
7334
|
+
this.loggerService = inject(TYPES.loggerService);
|
|
7335
|
+
this.swarmSchemaService = inject(TYPES.swarmSchemaService);
|
|
7336
|
+
this.agentMetaService = inject(TYPES.agentMetaService);
|
|
7337
|
+
this.serialize = createSerialize();
|
|
7338
|
+
/**
|
|
7339
|
+
* Creates a swarm node with the given swarm name.
|
|
7340
|
+
* @param {SwarmName} swarmName - The name of the swarm.
|
|
7341
|
+
* @returns {IMetaNode} The metadata node of the swarm.
|
|
7342
|
+
*/
|
|
7343
|
+
this.makeSwarmNode = function (swarmName) {
|
|
7344
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
|
|
7345
|
+
_this.loggerService.info("swarmMetaService makeSwarmNode", {
|
|
7346
|
+
swarmName: swarmName,
|
|
7347
|
+
});
|
|
7348
|
+
var agentList = _this.swarmSchemaService.get(swarmName).agentList;
|
|
7349
|
+
return {
|
|
7350
|
+
name: swarmName,
|
|
7351
|
+
child: agentList.map(function (dep) { return _this.agentMetaService.makeAgentNode(dep); }),
|
|
7352
|
+
};
|
|
7353
|
+
};
|
|
7354
|
+
/**
|
|
7355
|
+
* Converts the swarm metadata to UML format.
|
|
7356
|
+
* @param {SwarmName} swarmName - The name of the swarm.
|
|
7357
|
+
* @returns {string} The UML representation of the swarm.
|
|
7358
|
+
*/
|
|
7359
|
+
this.toUML = function (swarmName) {
|
|
7360
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
|
|
7361
|
+
_this.loggerService.info("swarmMetaService toUML", {
|
|
7362
|
+
swarmName: swarmName,
|
|
7363
|
+
});
|
|
7364
|
+
var rootNode = _this.makeSwarmNode(swarmName);
|
|
7365
|
+
return _this.serialize([rootNode]);
|
|
7366
|
+
};
|
|
7367
|
+
}
|
|
7368
|
+
return SwarmMetaService;
|
|
7369
|
+
}());
|
|
7370
|
+
|
|
7082
7371
|
{
|
|
7083
7372
|
provide(TYPES.busService, function () { return new BusService(); });
|
|
7084
7373
|
provide(TYPES.loggerService, function () { return new LoggerService(); });
|
|
@@ -7112,6 +7401,10 @@ var BusService = /** @class */ (function () {
|
|
|
7112
7401
|
provide(TYPES.storagePublicService, function () { return new StoragePublicService(); });
|
|
7113
7402
|
provide(TYPES.statePublicService, function () { return new StatePublicService(); });
|
|
7114
7403
|
}
|
|
7404
|
+
{
|
|
7405
|
+
provide(TYPES.swarmMetaService, function () { return new SwarmMetaService(); });
|
|
7406
|
+
provide(TYPES.agentMetaService, function () { return new AgentMetaService(); });
|
|
7407
|
+
}
|
|
7115
7408
|
{
|
|
7116
7409
|
provide(TYPES.agentPublicService, function () { return new AgentPublicService(); });
|
|
7117
7410
|
provide(TYPES.historyPublicService, function () { return new HistoryPublicService(); });
|
|
@@ -7161,6 +7454,10 @@ var publicServices = {
|
|
|
7161
7454
|
storagePublicService: inject(TYPES.storagePublicService),
|
|
7162
7455
|
statePublicService: inject(TYPES.statePublicService),
|
|
7163
7456
|
};
|
|
7457
|
+
var metaServices = {
|
|
7458
|
+
agentMetaService: inject(TYPES.agentMetaService),
|
|
7459
|
+
swarmMetaService: inject(TYPES.swarmMetaService),
|
|
7460
|
+
};
|
|
7164
7461
|
var validationServices = {
|
|
7165
7462
|
agentValidationService: inject(TYPES.agentValidationService),
|
|
7166
7463
|
toolValidationService: inject(TYPES.toolValidationService),
|
|
@@ -7170,10 +7467,42 @@ var validationServices = {
|
|
|
7170
7467
|
storageValidationService: inject(TYPES.storageValidationService),
|
|
7171
7468
|
embeddingValidationService: inject(TYPES.embeddingValidationService),
|
|
7172
7469
|
};
|
|
7173
|
-
var swarm = __assign(__assign(__assign(__assign(__assign(__assign({}, baseServices), contextServices), connectionServices), schemaServices), publicServices), validationServices);
|
|
7470
|
+
var swarm = __assign(__assign(__assign(__assign(__assign(__assign(__assign({}, baseServices), contextServices), connectionServices), schemaServices), publicServices), metaServices), validationServices);
|
|
7174
7471
|
init();
|
|
7175
7472
|
var swarm$1 = swarm;
|
|
7176
7473
|
|
|
7474
|
+
var METHOD_NAME$E = "function.dumpAgent";
|
|
7475
|
+
/**
|
|
7476
|
+
* Dumps the agent information into PlantUML format.
|
|
7477
|
+
*
|
|
7478
|
+
* @param {SwarmName} swarmName - The name of the swarm to be dumped.
|
|
7479
|
+
* @returns {string} The UML representation of the swarm.
|
|
7480
|
+
*/
|
|
7481
|
+
var dumpAgent = function (agentName) {
|
|
7482
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
7483
|
+
swarm$1.loggerService.log(METHOD_NAME$E, {
|
|
7484
|
+
agentName: agentName,
|
|
7485
|
+
});
|
|
7486
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$E);
|
|
7487
|
+
return swarm$1.agentMetaService.toUML(agentName);
|
|
7488
|
+
};
|
|
7489
|
+
|
|
7490
|
+
var METHOD_NAME$D = "function.dumpSwarm";
|
|
7491
|
+
/**
|
|
7492
|
+
* Dumps the swarm information into PlantUML format.
|
|
7493
|
+
*
|
|
7494
|
+
* @param {SwarmName} swarmName - The name of the swarm to be dumped.
|
|
7495
|
+
* @returns {string} The UML representation of the swarm.
|
|
7496
|
+
*/
|
|
7497
|
+
var dumpSwarm = function (swarmName) {
|
|
7498
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
7499
|
+
swarm$1.loggerService.log(METHOD_NAME$D, {
|
|
7500
|
+
swarmName: swarmName,
|
|
7501
|
+
});
|
|
7502
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$D);
|
|
7503
|
+
return swarm$1.swarmMetaService.toUML(swarmName);
|
|
7504
|
+
};
|
|
7505
|
+
|
|
7177
7506
|
var METHOD_NAME$C = "function.addAgent";
|
|
7178
7507
|
/**
|
|
7179
7508
|
* Adds a new agent to the agent registry. The swarm takes only those agents which was registered
|
|
@@ -7508,26 +7837,22 @@ var CHANGE_AGENT_GC = 60 * 1000;
|
|
|
7508
7837
|
* @returns {TChangeAgentRun} - The change agent function.
|
|
7509
7838
|
*/
|
|
7510
7839
|
var createChangeAgent = ttl(function (clientId) {
|
|
7511
|
-
return queued(function (methodName, agentName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
7512
|
-
var
|
|
7840
|
+
return queued(function (methodName, agentName, swarmName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
7841
|
+
var _a, _b, _c;
|
|
7513
7842
|
return __generator(this, function (_d) {
|
|
7514
7843
|
switch (_d.label) {
|
|
7515
|
-
case 0:
|
|
7516
|
-
|
|
7517
|
-
|
|
7518
|
-
|
|
7519
|
-
|
|
7520
|
-
|
|
7521
|
-
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
return [2 /*return*/];
|
|
7528
|
-
}
|
|
7529
|
-
});
|
|
7530
|
-
}); }))];
|
|
7844
|
+
case 0: return [4 /*yield*/, Promise.all(swarm$1.swarmValidationService
|
|
7845
|
+
.getAgentList(swarmName)
|
|
7846
|
+
.map(function (agentName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
7847
|
+
return __generator(this, function (_a) {
|
|
7848
|
+
switch (_a.label) {
|
|
7849
|
+
case 0: return [4 /*yield*/, swarm$1.agentPublicService.commitAgentChange(methodName, clientId, agentName)];
|
|
7850
|
+
case 1:
|
|
7851
|
+
_a.sent();
|
|
7852
|
+
return [2 /*return*/];
|
|
7853
|
+
}
|
|
7854
|
+
});
|
|
7855
|
+
}); }))];
|
|
7531
7856
|
case 1:
|
|
7532
7857
|
_d.sent();
|
|
7533
7858
|
return [4 /*yield*/, swarm$1.agentPublicService.dispose(methodName, clientId, agentName)];
|
|
@@ -7579,7 +7904,7 @@ var createGc$1 = singleshot(function () { return __awaiter(void 0, void 0, void
|
|
|
7579
7904
|
* @returns {Promise<void>} - A promise that resolves when the agent is changed.
|
|
7580
7905
|
*/
|
|
7581
7906
|
var changeAgent = function (agentName, clientId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
7582
|
-
var run;
|
|
7907
|
+
var swarmName, activeAgent, run;
|
|
7583
7908
|
return __generator(this, function (_a) {
|
|
7584
7909
|
switch (_a.label) {
|
|
7585
7910
|
case 0:
|
|
@@ -7588,12 +7913,21 @@ var changeAgent = function (agentName, clientId) { return __awaiter(void 0, void
|
|
|
7588
7913
|
agentName: agentName,
|
|
7589
7914
|
clientId: clientId,
|
|
7590
7915
|
});
|
|
7591
|
-
|
|
7916
|
+
swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
7917
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$s);
|
|
7918
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$s);
|
|
7919
|
+
return [4 /*yield*/, swarm$1.swarmPublicService.getAgentName(METHOD_NAME$s, clientId, swarmName)];
|
|
7592
7920
|
case 1:
|
|
7921
|
+
activeAgent = _a.sent();
|
|
7922
|
+
if (!swarm$1.agentValidationService.hasDependency(activeAgent, agentName)) {
|
|
7923
|
+
console.error("agent-swarm missing dependency detected for activeAgent=".concat(activeAgent, " dependencyAgent=").concat(agentName));
|
|
7924
|
+
}
|
|
7925
|
+
return [4 /*yield*/, createChangeAgent(clientId)];
|
|
7926
|
+
case 2:
|
|
7593
7927
|
run = _a.sent();
|
|
7594
7928
|
createGc$1();
|
|
7595
|
-
return [4 /*yield*/, run(METHOD_NAME$s, agentName)];
|
|
7596
|
-
case
|
|
7929
|
+
return [4 /*yield*/, run(METHOD_NAME$s, agentName, swarmName)];
|
|
7930
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
7597
7931
|
}
|
|
7598
7932
|
});
|
|
7599
7933
|
}); };
|
|
@@ -9426,4 +9760,4 @@ var SchemaUtils = /** @class */ (function () {
|
|
|
9426
9760
|
*/
|
|
9427
9761
|
var Schema = new SchemaUtils();
|
|
9428
9762
|
|
|
9429
|
-
export { ExecutionContextService, History, HistoryAdapter, HistoryInstance, Logger, LoggerAdapter, LoggerInstance, MethodContextService, Schema, State, Storage, addAgent, addCompletion, addEmbedding, addState, addStorage, addSwarm, addTool, cancelOutput, cancelOutputForce, changeAgent, commitFlush, commitFlushForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, session, setConfig, swarm };
|
|
9763
|
+
export { ExecutionContextService, History, HistoryAdapter, HistoryInstance, Logger, LoggerAdapter, LoggerInstance, MethodContextService, Schema, State, Storage, addAgent, addCompletion, addEmbedding, addState, addStorage, addSwarm, addTool, cancelOutput, cancelOutputForce, changeAgent, commitFlush, commitFlushForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, session, setConfig, swarm };
|