agent-swarm-kit 1.0.31 → 1.0.33
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 +253 -25
- package/build/index.mjs +253 -26
- package/package.json +1 -1
- package/types.d.ts +332 -179
package/build/index.cjs
CHANGED
|
@@ -456,11 +456,16 @@ var ClientAgent = /** @class */ (function () {
|
|
|
456
456
|
if ((validation = _a.sent())) {
|
|
457
457
|
throw new Error("agent-swarm-kit ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " model ressurect failed: ").concat(validation));
|
|
458
458
|
}
|
|
459
|
+
this.params.onOutput &&
|
|
460
|
+
this.params.onOutput(this.params.clientId, this.params.agentName, result_1);
|
|
459
461
|
return [4 /*yield*/, this._outputSubject.next(result_1)];
|
|
460
462
|
case 4:
|
|
461
463
|
_a.sent();
|
|
462
464
|
return [2 /*return*/];
|
|
463
|
-
case 5:
|
|
465
|
+
case 5:
|
|
466
|
+
this.params.onOutput &&
|
|
467
|
+
this.params.onOutput(this.params.clientId, this.params.agentName, result);
|
|
468
|
+
return [4 /*yield*/, this._outputSubject.next(result)];
|
|
464
469
|
case 6:
|
|
465
470
|
_a.sent();
|
|
466
471
|
return [2 /*return*/];
|
|
@@ -479,9 +484,11 @@ var ClientAgent = /** @class */ (function () {
|
|
|
479
484
|
switch (_a.label) {
|
|
480
485
|
case 0:
|
|
481
486
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel"));
|
|
487
|
+
this.params.onResurrect &&
|
|
488
|
+
this.params.onResurrect(this.params.clientId, this.params.agentName, mode, reason);
|
|
482
489
|
return [4 /*yield*/, this.params.history.push({
|
|
483
490
|
role: "resque",
|
|
484
|
-
mode:
|
|
491
|
+
mode: "tool",
|
|
485
492
|
agentName: this.params.agentName,
|
|
486
493
|
content: reason || "Unknown error",
|
|
487
494
|
})];
|
|
@@ -489,7 +496,7 @@ var ClientAgent = /** @class */ (function () {
|
|
|
489
496
|
_a.sent();
|
|
490
497
|
return [4 /*yield*/, this.params.history.push({
|
|
491
498
|
role: "user",
|
|
492
|
-
mode:
|
|
499
|
+
mode: "tool",
|
|
493
500
|
agentName: this.params.agentName,
|
|
494
501
|
content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_PROMPT,
|
|
495
502
|
})];
|
|
@@ -508,7 +515,7 @@ var ClientAgent = /** @class */ (function () {
|
|
|
508
515
|
return [4 /*yield*/, this.params.history.push({
|
|
509
516
|
agentName: this.params.agentName,
|
|
510
517
|
role: "assistant",
|
|
511
|
-
mode:
|
|
518
|
+
mode: "tool",
|
|
512
519
|
content: content,
|
|
513
520
|
})];
|
|
514
521
|
case 5:
|
|
@@ -540,7 +547,7 @@ var ClientAgent = /** @class */ (function () {
|
|
|
540
547
|
* @returns {Promise<IModelMessage>}
|
|
541
548
|
*/
|
|
542
549
|
this.getCompletion = function (mode) { return __awaiter(_this, void 0, void 0, function () {
|
|
543
|
-
var messages;
|
|
550
|
+
var messages, args, output;
|
|
544
551
|
var _a;
|
|
545
552
|
return __generator(this, function (_b) {
|
|
546
553
|
switch (_b.label) {
|
|
@@ -549,16 +556,21 @@ var ClientAgent = /** @class */ (function () {
|
|
|
549
556
|
return [4 /*yield*/, this.params.history.toArrayForAgent(this.params.prompt, this.params.system)];
|
|
550
557
|
case 1:
|
|
551
558
|
messages = _b.sent();
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
559
|
+
args = {
|
|
560
|
+
clientId: this.params.clientId,
|
|
561
|
+
agentName: this.params.agentName,
|
|
562
|
+
messages: messages,
|
|
563
|
+
mode: mode,
|
|
564
|
+
tools: (_a = this.params.tools) === null || _a === void 0 ? void 0 : _a.map(function (t) {
|
|
565
|
+
return lodashEs.omit(t, "toolName", "call", "validate", "onCall", "onValidate");
|
|
566
|
+
}),
|
|
567
|
+
};
|
|
568
|
+
return [4 /*yield*/, this.params.completion.getCompletion(args)];
|
|
569
|
+
case 2:
|
|
570
|
+
output = _b.sent();
|
|
571
|
+
this.params.completion.onComplete &&
|
|
572
|
+
this.params.completion.onComplete(args, output);
|
|
573
|
+
return [2 /*return*/, output];
|
|
562
574
|
}
|
|
563
575
|
});
|
|
564
576
|
}); };
|
|
@@ -571,11 +583,13 @@ var ClientAgent = /** @class */ (function () {
|
|
|
571
583
|
return __generator(this, function (_a) {
|
|
572
584
|
switch (_a.label) {
|
|
573
585
|
case 0:
|
|
574
|
-
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitUserMessage"));
|
|
586
|
+
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitUserMessage"), { message: message });
|
|
587
|
+
this.params.onUserMessage &&
|
|
588
|
+
this.params.onUserMessage(this.params.clientId, this.params.agentName, message);
|
|
575
589
|
return [4 /*yield*/, this.params.history.push({
|
|
576
590
|
role: "user",
|
|
577
591
|
agentName: this.params.agentName,
|
|
578
|
-
mode:
|
|
592
|
+
mode: "user",
|
|
579
593
|
content: message.trim(),
|
|
580
594
|
})];
|
|
581
595
|
case 1:
|
|
@@ -584,6 +598,29 @@ var ClientAgent = /** @class */ (function () {
|
|
|
584
598
|
}
|
|
585
599
|
});
|
|
586
600
|
}); };
|
|
601
|
+
/**
|
|
602
|
+
* Commits flush of agent history
|
|
603
|
+
* @returns {Promise<void>}
|
|
604
|
+
*/
|
|
605
|
+
this.commitFlush = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
606
|
+
return __generator(this, function (_a) {
|
|
607
|
+
switch (_a.label) {
|
|
608
|
+
case 0:
|
|
609
|
+
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitFlush"));
|
|
610
|
+
this.params.onFlush &&
|
|
611
|
+
this.params.onFlush(this.params.clientId, this.params.agentName);
|
|
612
|
+
return [4 /*yield*/, this.params.history.push({
|
|
613
|
+
role: "flush",
|
|
614
|
+
agentName: this.params.agentName,
|
|
615
|
+
mode: "tool",
|
|
616
|
+
content: "",
|
|
617
|
+
})];
|
|
618
|
+
case 1:
|
|
619
|
+
_a.sent();
|
|
620
|
+
return [2 /*return*/];
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
}); };
|
|
587
624
|
/**
|
|
588
625
|
* Commits a system message to the history.
|
|
589
626
|
* @param {string} message - The system message to commit.
|
|
@@ -593,11 +630,13 @@ var ClientAgent = /** @class */ (function () {
|
|
|
593
630
|
return __generator(this, function (_a) {
|
|
594
631
|
switch (_a.label) {
|
|
595
632
|
case 0:
|
|
596
|
-
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitSystemMessage"));
|
|
633
|
+
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitSystemMessage"), { message: message });
|
|
634
|
+
this.params.onSystemMessage &&
|
|
635
|
+
this.params.onSystemMessage(this.params.clientId, this.params.agentName, message);
|
|
597
636
|
return [4 /*yield*/, this.params.history.push({
|
|
598
637
|
role: "system",
|
|
599
638
|
agentName: this.params.agentName,
|
|
600
|
-
mode:
|
|
639
|
+
mode: "tool",
|
|
601
640
|
content: message.trim(),
|
|
602
641
|
})];
|
|
603
642
|
case 1:
|
|
@@ -615,11 +654,13 @@ var ClientAgent = /** @class */ (function () {
|
|
|
615
654
|
return __generator(this, function (_a) {
|
|
616
655
|
switch (_a.label) {
|
|
617
656
|
case 0:
|
|
618
|
-
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitToolOutput
|
|
657
|
+
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitToolOutput"), { content: content });
|
|
658
|
+
this.params.onToolOutput &&
|
|
659
|
+
this.params.onToolOutput(this.params.clientId, this.params.agentName, content);
|
|
619
660
|
return [4 /*yield*/, this.params.history.push({
|
|
620
661
|
role: "tool",
|
|
621
662
|
agentName: this.params.agentName,
|
|
622
|
-
mode:
|
|
663
|
+
mode: "tool",
|
|
623
664
|
content: content,
|
|
624
665
|
})];
|
|
625
666
|
case 1:
|
|
@@ -644,6 +685,8 @@ var ClientAgent = /** @class */ (function () {
|
|
|
644
685
|
switch (_e.label) {
|
|
645
686
|
case 0:
|
|
646
687
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute begin"), { incoming: incoming, mode: mode });
|
|
688
|
+
this.params.onExecute &&
|
|
689
|
+
this.params.onExecute(this.params.clientId, this.params.agentName, incoming, mode);
|
|
647
690
|
return [4 /*yield*/, this.params.history.push({
|
|
648
691
|
role: "user",
|
|
649
692
|
mode: mode,
|
|
@@ -676,7 +719,9 @@ var ClientAgent = /** @class */ (function () {
|
|
|
676
719
|
case 3:
|
|
677
720
|
_f.sent();
|
|
678
721
|
return [2 /*return*/, { value: void 0 }];
|
|
679
|
-
case 4:
|
|
722
|
+
case 4:
|
|
723
|
+
targetFn.onValidate && targetFn.onValidate(this_1.params.clientId, this_1.params.agentName, tool.function.arguments);
|
|
724
|
+
return [4 /*yield*/, functoolsKit.not(targetFn.validate(this_1.params.clientId, this_1.params.agentName, tool.function.arguments))];
|
|
680
725
|
case 5:
|
|
681
726
|
if (!_f.sent()) return [3 /*break*/, 8];
|
|
682
727
|
this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool validation not passed"));
|
|
@@ -689,6 +734,8 @@ var ClientAgent = /** @class */ (function () {
|
|
|
689
734
|
_f.sent();
|
|
690
735
|
return [2 /*return*/, { value: void 0 }];
|
|
691
736
|
case 8:
|
|
737
|
+
targetFn.onCall &&
|
|
738
|
+
targetFn.onCall(this_1.params.clientId, this_1.params.agentName, tool.function.arguments);
|
|
692
739
|
/**
|
|
693
740
|
* @description Do not await to avoid deadlock! The tool can send the message to other agents by emulating user messages
|
|
694
741
|
*/
|
|
@@ -795,7 +842,7 @@ var AgentConnectionService = /** @class */ (function () {
|
|
|
795
842
|
var _b = __read(_a, 2), clientId = _b[0], agentName = _b[1];
|
|
796
843
|
return "".concat(clientId, "-").concat(agentName);
|
|
797
844
|
}, function (clientId, agentName) {
|
|
798
|
-
var _a = _this.agentSchemaService.get(agentName), prompt = _a.prompt, system = _a.system, tools = _a.tools, completionName = _a.completion, _b = _a.validate, validate = _b === void 0 ? validateDefault : _b;
|
|
845
|
+
var _a = _this.agentSchemaService.get(agentName), prompt = _a.prompt, system = _a.system, tools = _a.tools, onExecute = _a.onExecute, onOutput = _a.onOutput, onResurrect = _a.onResurrect, onSystemMessage = _a.onSystemMessage, onToolOutput = _a.onToolOutput, onUserMessage = _a.onUserMessage, completionName = _a.completion, _b = _a.validate, validate = _b === void 0 ? validateDefault : _b;
|
|
799
846
|
var completion = _this.completionSchemaService.get(completionName);
|
|
800
847
|
_this.sessionValidationService.addAgentUsage(clientId, agentName);
|
|
801
848
|
return new ClientAgent({
|
|
@@ -808,6 +855,12 @@ var AgentConnectionService = /** @class */ (function () {
|
|
|
808
855
|
system: system,
|
|
809
856
|
tools: tools === null || tools === void 0 ? void 0 : tools.map(_this.toolSchemaService.get),
|
|
810
857
|
completion: completion,
|
|
858
|
+
onExecute: onExecute,
|
|
859
|
+
onOutput: onOutput,
|
|
860
|
+
onResurrect: onResurrect,
|
|
861
|
+
onSystemMessage: onSystemMessage,
|
|
862
|
+
onToolOutput: onToolOutput,
|
|
863
|
+
onUserMessage: onUserMessage,
|
|
811
864
|
});
|
|
812
865
|
});
|
|
813
866
|
/**
|
|
@@ -899,6 +952,22 @@ var AgentConnectionService = /** @class */ (function () {
|
|
|
899
952
|
}
|
|
900
953
|
});
|
|
901
954
|
}); };
|
|
955
|
+
/**
|
|
956
|
+
* Commits flush of agent history
|
|
957
|
+
* @returns {Promise<any>} The commit result.
|
|
958
|
+
*/
|
|
959
|
+
this.commitFlush = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
960
|
+
return __generator(this, function (_a) {
|
|
961
|
+
switch (_a.label) {
|
|
962
|
+
case 0:
|
|
963
|
+
this.loggerService.log("agentConnectionService commitFlush", {
|
|
964
|
+
context: this.contextService.context,
|
|
965
|
+
});
|
|
966
|
+
return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).commitFlush()];
|
|
967
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
968
|
+
}
|
|
969
|
+
});
|
|
970
|
+
}); };
|
|
902
971
|
/**
|
|
903
972
|
* Disposes of the agent connection.
|
|
904
973
|
* @returns {Promise<void>} The dispose result.
|
|
@@ -1028,6 +1097,11 @@ var ClientHistory = /** @class */ (function () {
|
|
|
1028
1097
|
systemMessagesRaw.splice(0, systemMessagesRaw.length);
|
|
1029
1098
|
return [3 /*break*/, 4];
|
|
1030
1099
|
}
|
|
1100
|
+
if (message.role === "flush") {
|
|
1101
|
+
commonMessagesRaw.splice(0, commonMessagesRaw.length);
|
|
1102
|
+
systemMessagesRaw.splice(0, systemMessagesRaw.length);
|
|
1103
|
+
return [3 /*break*/, 4];
|
|
1104
|
+
}
|
|
1031
1105
|
if (message.role === "system") {
|
|
1032
1106
|
systemMessagesRaw.push(message);
|
|
1033
1107
|
}
|
|
@@ -1417,7 +1491,7 @@ var SwarmConnectionService = /** @class */ (function () {
|
|
|
1417
1491
|
return "".concat(clientId, "-").concat(swarmName);
|
|
1418
1492
|
}, function (clientId, swarmName) {
|
|
1419
1493
|
var e_1, _a;
|
|
1420
|
-
var _b = _this.swarmSchemaService.get(swarmName), agentList = _b.agentList, defaultAgent = _b.defaultAgent;
|
|
1494
|
+
var _b = _this.swarmSchemaService.get(swarmName), agentList = _b.agentList, defaultAgent = _b.defaultAgent, onAgentChanged = _b.onAgentChanged;
|
|
1421
1495
|
var agentMap = {};
|
|
1422
1496
|
try {
|
|
1423
1497
|
for (var agentList_1 = __values(agentList), agentList_1_1 = agentList_1.next(); !agentList_1_1.done; agentList_1_1 = agentList_1.next()) {
|
|
@@ -1442,7 +1516,9 @@ var SwarmConnectionService = /** @class */ (function () {
|
|
|
1442
1516
|
return __awaiter(this, void 0, void 0, function () {
|
|
1443
1517
|
return __generator(this, function (_a) {
|
|
1444
1518
|
switch (_a.label) {
|
|
1445
|
-
case 0:
|
|
1519
|
+
case 0:
|
|
1520
|
+
onAgentChanged && onAgentChanged(clientId, agentName, swarmName);
|
|
1521
|
+
return [4 /*yield*/, GLOBAL_CONFIG.CC_SWARM_AGENT_CHANGED(clientId, agentName, swarmName)];
|
|
1446
1522
|
case 1:
|
|
1447
1523
|
_a.sent();
|
|
1448
1524
|
return [2 /*return*/];
|
|
@@ -1637,6 +1713,8 @@ var ClientSession = /** @class */ (function () {
|
|
|
1637
1713
|
this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " emit"), {
|
|
1638
1714
|
message: message,
|
|
1639
1715
|
});
|
|
1716
|
+
this.params.onEmit &&
|
|
1717
|
+
this.params.onEmit(this.params.clientId, this.params.swarmName, message);
|
|
1640
1718
|
return [4 /*yield*/, this._emitSubject.next(message)];
|
|
1641
1719
|
case 1:
|
|
1642
1720
|
_a.sent();
|
|
@@ -1659,6 +1737,8 @@ var ClientSession = /** @class */ (function () {
|
|
|
1659
1737
|
message: message,
|
|
1660
1738
|
mode: mode,
|
|
1661
1739
|
});
|
|
1740
|
+
this.params.onExecute &&
|
|
1741
|
+
this.params.onExecute(this.params.clientId, this.params.swarmName, message, mode);
|
|
1662
1742
|
return [4 /*yield*/, this.params.swarm.getAgent()];
|
|
1663
1743
|
case 1:
|
|
1664
1744
|
agent = _a.sent();
|
|
@@ -1713,6 +1793,24 @@ var ClientSession = /** @class */ (function () {
|
|
|
1713
1793
|
}
|
|
1714
1794
|
});
|
|
1715
1795
|
}); };
|
|
1796
|
+
/**
|
|
1797
|
+
* Commits flush of agent history
|
|
1798
|
+
* @returns {Promise<void>}
|
|
1799
|
+
*/
|
|
1800
|
+
this.commitFlush = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1801
|
+
var agent;
|
|
1802
|
+
return __generator(this, function (_a) {
|
|
1803
|
+
switch (_a.label) {
|
|
1804
|
+
case 0:
|
|
1805
|
+
this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " commitFlush"));
|
|
1806
|
+
return [4 /*yield*/, this.params.swarm.getAgent()];
|
|
1807
|
+
case 1:
|
|
1808
|
+
agent = _a.sent();
|
|
1809
|
+
return [4 /*yield*/, agent.commitFlush()];
|
|
1810
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
1811
|
+
}
|
|
1812
|
+
});
|
|
1813
|
+
}); };
|
|
1716
1814
|
/**
|
|
1717
1815
|
* Commits a system message.
|
|
1718
1816
|
* @param {string} message - The system message to commit.
|
|
@@ -1741,6 +1839,8 @@ var ClientSession = /** @class */ (function () {
|
|
|
1741
1839
|
*/
|
|
1742
1840
|
this.connect = function (connector) {
|
|
1743
1841
|
_this.params.logger.debug("ClientSession clientId=".concat(_this.params.clientId, " connect"));
|
|
1842
|
+
_this.params.onConnect &&
|
|
1843
|
+
_this.params.onConnect(_this.params.clientId, _this.params.swarmName);
|
|
1744
1844
|
_this._emitSubject.subscribe(function (data) { return __awaiter(_this, void 0, void 0, function () {
|
|
1745
1845
|
var _a;
|
|
1746
1846
|
var _b;
|
|
@@ -1799,6 +1899,7 @@ var SessionConnectionService = /** @class */ (function () {
|
|
|
1799
1899
|
this.loggerService = inject(TYPES.loggerService);
|
|
1800
1900
|
this.contextService = inject(TYPES.contextService);
|
|
1801
1901
|
this.swarmConnectionService = inject(TYPES.swarmConnectionService);
|
|
1902
|
+
this.swarmSchemaService = inject(TYPES.swarmSchemaService);
|
|
1802
1903
|
/**
|
|
1803
1904
|
* Retrieves a memoized session based on clientId and swarmName.
|
|
1804
1905
|
* @param {string} clientId - The client ID.
|
|
@@ -1809,10 +1910,15 @@ var SessionConnectionService = /** @class */ (function () {
|
|
|
1809
1910
|
var _b = __read(_a, 2), clientId = _b[0], swarmName = _b[1];
|
|
1810
1911
|
return "".concat(clientId, "-").concat(swarmName);
|
|
1811
1912
|
}, function (clientId, swarmName) {
|
|
1913
|
+
var _a = _this.swarmSchemaService.get(swarmName), onConnect = _a.onConnect, onEmit = _a.onEmit, onExecute = _a.onExecute;
|
|
1812
1914
|
return new ClientSession({
|
|
1813
1915
|
clientId: clientId,
|
|
1814
1916
|
logger: _this.loggerService,
|
|
1815
1917
|
swarm: _this.swarmConnectionService.getSwarm(clientId, swarmName),
|
|
1918
|
+
swarmName: swarmName,
|
|
1919
|
+
onConnect: onConnect,
|
|
1920
|
+
onEmit: onEmit,
|
|
1921
|
+
onExecute: onExecute,
|
|
1816
1922
|
});
|
|
1817
1923
|
});
|
|
1818
1924
|
/**
|
|
@@ -1873,6 +1979,7 @@ var SessionConnectionService = /** @class */ (function () {
|
|
|
1873
1979
|
case 0:
|
|
1874
1980
|
this.loggerService.log("sessionConnectionService commitToolOutput", {
|
|
1875
1981
|
context: this.contextService.context,
|
|
1982
|
+
content: content,
|
|
1876
1983
|
});
|
|
1877
1984
|
return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitToolOutput(content)];
|
|
1878
1985
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1890,6 +1997,7 @@ var SessionConnectionService = /** @class */ (function () {
|
|
|
1890
1997
|
case 0:
|
|
1891
1998
|
this.loggerService.log("sessionConnectionService commitSystemMessage", {
|
|
1892
1999
|
context: this.contextService.context,
|
|
2000
|
+
message: message,
|
|
1893
2001
|
});
|
|
1894
2002
|
return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitSystemMessage(message)];
|
|
1895
2003
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1907,12 +2015,30 @@ var SessionConnectionService = /** @class */ (function () {
|
|
|
1907
2015
|
case 0:
|
|
1908
2016
|
this.loggerService.log("sessionConnectionService commitUserMessage", {
|
|
1909
2017
|
context: this.contextService.context,
|
|
2018
|
+
message: message,
|
|
1910
2019
|
});
|
|
1911
2020
|
return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitUserMessage(message)];
|
|
1912
2021
|
case 1: return [2 /*return*/, _a.sent()];
|
|
1913
2022
|
}
|
|
1914
2023
|
});
|
|
1915
2024
|
}); };
|
|
2025
|
+
/**
|
|
2026
|
+
* Commits user message to the agent without answer.
|
|
2027
|
+
* @param {string} message - The message to commit.
|
|
2028
|
+
* @returns {Promise<void>} A promise that resolves when the message is committed.
|
|
2029
|
+
*/
|
|
2030
|
+
this.commitFlush = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2031
|
+
return __generator(this, function (_a) {
|
|
2032
|
+
switch (_a.label) {
|
|
2033
|
+
case 0:
|
|
2034
|
+
this.loggerService.log("sessionConnectionService commitFlush", {
|
|
2035
|
+
context: this.contextService.context,
|
|
2036
|
+
});
|
|
2037
|
+
return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitFlush()];
|
|
2038
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
2039
|
+
}
|
|
2040
|
+
});
|
|
2041
|
+
}); };
|
|
1916
2042
|
/**
|
|
1917
2043
|
* Disposes of the session connection service.
|
|
1918
2044
|
* @returns {Promise<void>} A promise that resolves when the service is disposed.
|
|
@@ -2133,6 +2259,37 @@ var AgentPublicService = /** @class */ (function () {
|
|
|
2133
2259
|
}
|
|
2134
2260
|
});
|
|
2135
2261
|
}); };
|
|
2262
|
+
/**
|
|
2263
|
+
* Commits flush of agent history
|
|
2264
|
+
* @param {string} clientId - The client ID.
|
|
2265
|
+
* @param {AgentName} agentName - The name of the agent.
|
|
2266
|
+
* @returns {Promise<unknown>} The commit result.
|
|
2267
|
+
*/
|
|
2268
|
+
this.commitFlush = function (clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
2269
|
+
var _this = this;
|
|
2270
|
+
return __generator(this, function (_a) {
|
|
2271
|
+
switch (_a.label) {
|
|
2272
|
+
case 0:
|
|
2273
|
+
this.loggerService.log("agentPublicService commitFlush", {
|
|
2274
|
+
clientId: clientId,
|
|
2275
|
+
agentName: agentName,
|
|
2276
|
+
});
|
|
2277
|
+
return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2278
|
+
return __generator(this, function (_a) {
|
|
2279
|
+
switch (_a.label) {
|
|
2280
|
+
case 0: return [4 /*yield*/, this.agentConnectionService.commitFlush()];
|
|
2281
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
2282
|
+
}
|
|
2283
|
+
});
|
|
2284
|
+
}); }, {
|
|
2285
|
+
clientId: clientId,
|
|
2286
|
+
agentName: agentName,
|
|
2287
|
+
swarmName: "",
|
|
2288
|
+
})];
|
|
2289
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
2290
|
+
}
|
|
2291
|
+
});
|
|
2292
|
+
}); };
|
|
2136
2293
|
/**
|
|
2137
2294
|
* Disposes of the agent.
|
|
2138
2295
|
* @param {string} clientId - The client ID.
|
|
@@ -2530,6 +2687,37 @@ var SessionPublicService = /** @class */ (function () {
|
|
|
2530
2687
|
}
|
|
2531
2688
|
});
|
|
2532
2689
|
}); };
|
|
2690
|
+
/**
|
|
2691
|
+
* Commits flush of agent history
|
|
2692
|
+
* @param {string} clientId - The client ID.
|
|
2693
|
+
* @param {SwarmName} swarmName - The swarm name.
|
|
2694
|
+
* @returns {Promise<void>}
|
|
2695
|
+
*/
|
|
2696
|
+
this.commitFlush = function (clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
|
|
2697
|
+
var _this = this;
|
|
2698
|
+
return __generator(this, function (_a) {
|
|
2699
|
+
switch (_a.label) {
|
|
2700
|
+
case 0:
|
|
2701
|
+
this.loggerService.log("sessionPublicService commitFlush", {
|
|
2702
|
+
clientId: clientId,
|
|
2703
|
+
swarmName: swarmName,
|
|
2704
|
+
});
|
|
2705
|
+
return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2706
|
+
return __generator(this, function (_a) {
|
|
2707
|
+
switch (_a.label) {
|
|
2708
|
+
case 0: return [4 /*yield*/, this.sessionConnectionService.commitFlush()];
|
|
2709
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
2710
|
+
}
|
|
2711
|
+
});
|
|
2712
|
+
}); }, {
|
|
2713
|
+
clientId: clientId,
|
|
2714
|
+
swarmName: swarmName,
|
|
2715
|
+
agentName: "",
|
|
2716
|
+
})];
|
|
2717
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
2718
|
+
}
|
|
2719
|
+
});
|
|
2720
|
+
}); };
|
|
2533
2721
|
/**
|
|
2534
2722
|
* Disposes of the session.
|
|
2535
2723
|
* @param {string} clientId - The client ID.
|
|
@@ -3995,6 +4183,45 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
|
|
|
3995
4183
|
});
|
|
3996
4184
|
}); };
|
|
3997
4185
|
|
|
4186
|
+
/**
|
|
4187
|
+
* Commits flush of agent history
|
|
4188
|
+
*
|
|
4189
|
+
* @param {string} clientId - The ID of the client.
|
|
4190
|
+
* @param {string} agentName - The name of the agent.
|
|
4191
|
+
* @returns {Promise<void>} - A promise that resolves when the message is committed.
|
|
4192
|
+
*/
|
|
4193
|
+
var commitFlush = function (clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
4194
|
+
var swarmName, currentAgentName;
|
|
4195
|
+
return __generator(this, function (_a) {
|
|
4196
|
+
switch (_a.label) {
|
|
4197
|
+
case 0:
|
|
4198
|
+
swarm.loggerService.log('function commitFlush', {
|
|
4199
|
+
clientId: clientId,
|
|
4200
|
+
agentName: agentName,
|
|
4201
|
+
});
|
|
4202
|
+
swarm.agentValidationService.validate(agentName, "commitFlush");
|
|
4203
|
+
swarm.sessionValidationService.validate(clientId, "commitFlush");
|
|
4204
|
+
swarmName = swarm.sessionValidationService.getSwarm(clientId);
|
|
4205
|
+
swarm.swarmValidationService.validate(swarmName, "commitFlush");
|
|
4206
|
+
return [4 /*yield*/, swarm.swarmPublicService.getAgentName(clientId, swarmName)];
|
|
4207
|
+
case 1:
|
|
4208
|
+
currentAgentName = _a.sent();
|
|
4209
|
+
if (currentAgentName !== agentName) {
|
|
4210
|
+
swarm.loggerService.log('function "commitFlush" skipped due to the agent change', {
|
|
4211
|
+
currentAgentName: currentAgentName,
|
|
4212
|
+
agentName: agentName,
|
|
4213
|
+
clientId: clientId,
|
|
4214
|
+
});
|
|
4215
|
+
return [2 /*return*/];
|
|
4216
|
+
}
|
|
4217
|
+
return [4 /*yield*/, swarm.sessionPublicService.commitFlush(clientId, swarmName)];
|
|
4218
|
+
case 2:
|
|
4219
|
+
_a.sent();
|
|
4220
|
+
return [2 /*return*/];
|
|
4221
|
+
}
|
|
4222
|
+
});
|
|
4223
|
+
}); };
|
|
4224
|
+
|
|
3998
4225
|
/**
|
|
3999
4226
|
* Send the message to the active agent in the swarm content like it income from client side
|
|
4000
4227
|
* Should be used to review tool output and initiate conversation from the model side to client
|
|
@@ -4267,6 +4494,7 @@ exports.addCompletion = addCompletion;
|
|
|
4267
4494
|
exports.addSwarm = addSwarm;
|
|
4268
4495
|
exports.addTool = addTool;
|
|
4269
4496
|
exports.changeAgent = changeAgent;
|
|
4497
|
+
exports.commitFlush = commitFlush;
|
|
4270
4498
|
exports.commitSystemMessage = commitSystemMessage;
|
|
4271
4499
|
exports.commitToolOutput = commitToolOutput;
|
|
4272
4500
|
exports.commitUserMessage = commitUserMessage;
|