agent-swarm-kit 1.0.11 → 1.0.13
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 +210 -15
- package/build/index.mjs +210 -15
- package/package.json +1 -1
- package/types.d.ts +6 -0
package/build/index.cjs
CHANGED
|
@@ -425,7 +425,7 @@ var ClientAgent = /** @class */ (function () {
|
|
|
425
425
|
case 1:
|
|
426
426
|
_f.sent();
|
|
427
427
|
if (!!targetFn) return [3 /*break*/, 4];
|
|
428
|
-
this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool function not found"));
|
|
428
|
+
this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool function not found"), this_1.params.tools);
|
|
429
429
|
return [4 /*yield*/, this_1._resurrectModel("No target function for ".concat(tool.function.name))];
|
|
430
430
|
case 2:
|
|
431
431
|
result_2 = _f.sent();
|
|
@@ -522,7 +522,9 @@ var ClientAgent = /** @class */ (function () {
|
|
|
522
522
|
}
|
|
523
523
|
});
|
|
524
524
|
}); });
|
|
525
|
-
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " CTOR")
|
|
525
|
+
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " CTOR"), {
|
|
526
|
+
params: params,
|
|
527
|
+
});
|
|
526
528
|
}
|
|
527
529
|
return ClientAgent;
|
|
528
530
|
}());
|
|
@@ -848,7 +850,9 @@ var ClientHistory = /** @class */ (function () {
|
|
|
848
850
|
}
|
|
849
851
|
});
|
|
850
852
|
}); };
|
|
851
|
-
this.params.logger.debug("ClientHistory agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " CTOR")
|
|
853
|
+
this.params.logger.debug("ClientHistory agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " CTOR"), {
|
|
854
|
+
params: params,
|
|
855
|
+
});
|
|
852
856
|
}
|
|
853
857
|
return ClientHistory;
|
|
854
858
|
}());
|
|
@@ -951,10 +955,12 @@ var ToolSchemaService = /** @class */ (function () {
|
|
|
951
955
|
return ToolSchemaService;
|
|
952
956
|
}());
|
|
953
957
|
|
|
958
|
+
var AGENT_REF_CHANGED = Symbol('agent-ref-changed');
|
|
954
959
|
var ClientSwarm = /** @class */ (function () {
|
|
955
960
|
function ClientSwarm(params) {
|
|
956
961
|
var _this = this;
|
|
957
962
|
this.params = params;
|
|
963
|
+
this._agentChangedSubject = new functoolsKit.Subject();
|
|
958
964
|
this.waitForOutput = functoolsKit.queued(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
959
965
|
var START_TIME, _a, agentName, output, _b;
|
|
960
966
|
var _this = this;
|
|
@@ -968,7 +974,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
968
974
|
if (Date.now() - START_TIME >= GLOBAL_CONFIG.CC_ANSWER_TIMEOUT_SECONDS) {
|
|
969
975
|
throw new Error("agent-swarm ClientSwarm waitForOutput timeout reached for ".concat(this.params.swarmName));
|
|
970
976
|
}
|
|
971
|
-
return [4 /*yield*/, Promise.race(Object.entries(this.params.agentMap).map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
977
|
+
return [4 /*yield*/, Promise.race(__spreadArray(__spreadArray([], __read(Object.entries(this.params.agentMap).map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
972
978
|
var _c;
|
|
973
979
|
var _d = __read(_b, 2), agentName = _d[0], agent = _d[1];
|
|
974
980
|
return __generator(this, function (_e) {
|
|
@@ -981,9 +987,14 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
981
987
|
])];
|
|
982
988
|
}
|
|
983
989
|
});
|
|
984
|
-
}); }))
|
|
990
|
+
}); })), false), [
|
|
991
|
+
this._agentChangedSubject.toPromise().then(function () { return [AGENT_REF_CHANGED]; }),
|
|
992
|
+
], false))];
|
|
985
993
|
case 2:
|
|
986
994
|
_a = __read.apply(void 0, [_c.sent(), 2]), agentName = _a[0], output = _a[1];
|
|
995
|
+
if (agentName === AGENT_REF_CHANGED) {
|
|
996
|
+
return [3 /*break*/, 1];
|
|
997
|
+
}
|
|
987
998
|
_b = agentName;
|
|
988
999
|
return [4 /*yield*/, this.getAgentName()];
|
|
989
1000
|
case 3:
|
|
@@ -1014,6 +1025,22 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1014
1025
|
}
|
|
1015
1026
|
});
|
|
1016
1027
|
}); };
|
|
1028
|
+
this.setAgentRef = function (agentName, agent) { return __awaiter(_this, void 0, void 0, function () {
|
|
1029
|
+
return __generator(this, function (_a) {
|
|
1030
|
+
switch (_a.label) {
|
|
1031
|
+
case 0:
|
|
1032
|
+
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " setAgentRef agentName=").concat(agentName));
|
|
1033
|
+
if (!this.params.agentMap[agentName]) {
|
|
1034
|
+
throw new Error("agent-swarm agent ".concat(agentName, " not in the swarm"));
|
|
1035
|
+
}
|
|
1036
|
+
this.params.agentMap[agentName] = agent;
|
|
1037
|
+
return [4 /*yield*/, this._agentChangedSubject.next()];
|
|
1038
|
+
case 1:
|
|
1039
|
+
_a.sent();
|
|
1040
|
+
return [2 /*return*/];
|
|
1041
|
+
}
|
|
1042
|
+
});
|
|
1043
|
+
}); };
|
|
1017
1044
|
this.setAgentName = function (agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1018
1045
|
return __generator(this, function (_a) {
|
|
1019
1046
|
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " setAgentName agentName=").concat(agentName));
|
|
@@ -1021,7 +1048,9 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1021
1048
|
return [2 /*return*/];
|
|
1022
1049
|
});
|
|
1023
1050
|
}); };
|
|
1024
|
-
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " CTOR")
|
|
1051
|
+
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " CTOR"), {
|
|
1052
|
+
params: params,
|
|
1053
|
+
});
|
|
1025
1054
|
this._activeAgent = params.defaultAgent;
|
|
1026
1055
|
}
|
|
1027
1056
|
return ClientSwarm;
|
|
@@ -1098,6 +1127,18 @@ var SwarmConnectionService = /** @class */ (function () {
|
|
|
1098
1127
|
}
|
|
1099
1128
|
});
|
|
1100
1129
|
}); };
|
|
1130
|
+
this.setAgentRef = function (agentName, agent) { return __awaiter(_this, void 0, void 0, function () {
|
|
1131
|
+
return __generator(this, function (_a) {
|
|
1132
|
+
switch (_a.label) {
|
|
1133
|
+
case 0:
|
|
1134
|
+
this.loggerService.log("swarmConnectionService setAgentRef", {
|
|
1135
|
+
context: this.contextService.context,
|
|
1136
|
+
});
|
|
1137
|
+
return [4 /*yield*/, this.getSwarm(this.contextService.context.clientId, this.contextService.context.swarmName).setAgentRef(agentName, agent)];
|
|
1138
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1139
|
+
}
|
|
1140
|
+
});
|
|
1141
|
+
}); };
|
|
1101
1142
|
this.setAgentName = function (agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1102
1143
|
return __generator(this, function (_a) {
|
|
1103
1144
|
switch (_a.label) {
|
|
@@ -1273,7 +1314,9 @@ var ClientSession = /** @class */ (function () {
|
|
|
1273
1314
|
});
|
|
1274
1315
|
}); };
|
|
1275
1316
|
};
|
|
1276
|
-
this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " CTOR")
|
|
1317
|
+
this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " CTOR"), {
|
|
1318
|
+
params: params,
|
|
1319
|
+
});
|
|
1277
1320
|
}
|
|
1278
1321
|
return ClientSession;
|
|
1279
1322
|
}());
|
|
@@ -1354,6 +1397,31 @@ var AgentPublicService = /** @class */ (function () {
|
|
|
1354
1397
|
var _this = this;
|
|
1355
1398
|
this.loggerService = inject(TYPES.loggerService);
|
|
1356
1399
|
this.agentConnectionService = inject(TYPES.agentConnectionService);
|
|
1400
|
+
this.createAgentRef = function (clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1401
|
+
var _this = this;
|
|
1402
|
+
return __generator(this, function (_a) {
|
|
1403
|
+
switch (_a.label) {
|
|
1404
|
+
case 0:
|
|
1405
|
+
this.loggerService.log("agentPublicService createAgentRef", {
|
|
1406
|
+
clientId: clientId,
|
|
1407
|
+
agentName: agentName,
|
|
1408
|
+
});
|
|
1409
|
+
return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1410
|
+
return __generator(this, function (_a) {
|
|
1411
|
+
switch (_a.label) {
|
|
1412
|
+
case 0: return [4 /*yield*/, this.agentConnectionService.getAgent(clientId, agentName)];
|
|
1413
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1414
|
+
}
|
|
1415
|
+
});
|
|
1416
|
+
}); }, {
|
|
1417
|
+
clientId: clientId,
|
|
1418
|
+
agentName: agentName,
|
|
1419
|
+
swarmName: "",
|
|
1420
|
+
})];
|
|
1421
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1422
|
+
}
|
|
1423
|
+
});
|
|
1424
|
+
}); };
|
|
1357
1425
|
this.execute = function (input, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1358
1426
|
var _this = this;
|
|
1359
1427
|
return __generator(this, function (_a) {
|
|
@@ -1830,6 +1898,33 @@ var SwarmPublicService = /** @class */ (function () {
|
|
|
1830
1898
|
}
|
|
1831
1899
|
});
|
|
1832
1900
|
}); };
|
|
1901
|
+
this.setAgentRef = function (clientId, swarmName, agentName, agent) { return __awaiter(_this, void 0, void 0, function () {
|
|
1902
|
+
var _this = this;
|
|
1903
|
+
return __generator(this, function (_a) {
|
|
1904
|
+
switch (_a.label) {
|
|
1905
|
+
case 0:
|
|
1906
|
+
this.loggerService.log("swarmPublicService setAgentRef", {
|
|
1907
|
+
agentName: agentName,
|
|
1908
|
+
agent: agent,
|
|
1909
|
+
clientId: clientId,
|
|
1910
|
+
swarmName: swarmName,
|
|
1911
|
+
});
|
|
1912
|
+
return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1913
|
+
return __generator(this, function (_a) {
|
|
1914
|
+
switch (_a.label) {
|
|
1915
|
+
case 0: return [4 /*yield*/, this.swarmConnectionService.setAgentRef(agentName, agent)];
|
|
1916
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1917
|
+
}
|
|
1918
|
+
});
|
|
1919
|
+
}); }, {
|
|
1920
|
+
clientId: clientId,
|
|
1921
|
+
swarmName: swarmName,
|
|
1922
|
+
agentName: "",
|
|
1923
|
+
})];
|
|
1924
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1925
|
+
}
|
|
1926
|
+
});
|
|
1927
|
+
}); };
|
|
1833
1928
|
this.setAgentName = function (agentName, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1834
1929
|
var _this = this;
|
|
1835
1930
|
return __generator(this, function (_a) {
|
|
@@ -2231,30 +2326,46 @@ var swarm = __assign(__assign(__assign(__assign(__assign({}, baseServices), conn
|
|
|
2231
2326
|
init();
|
|
2232
2327
|
|
|
2233
2328
|
var addAgent = function (agentSchema) {
|
|
2329
|
+
swarm.loggerService.log('function addAgent', {
|
|
2330
|
+
agentSchema: agentSchema
|
|
2331
|
+
});
|
|
2234
2332
|
swarm.agentValidationService.addAgent(agentSchema.agentName, agentSchema);
|
|
2235
2333
|
swarm.agentSchemaService.register(agentSchema.agentName, agentSchema);
|
|
2236
2334
|
return agentSchema.agentName;
|
|
2237
2335
|
};
|
|
2238
2336
|
|
|
2239
2337
|
var addCompletion = function (completionSchema) {
|
|
2338
|
+
swarm.loggerService.log('function addCompletion', {
|
|
2339
|
+
completionSchema: completionSchema,
|
|
2340
|
+
});
|
|
2240
2341
|
swarm.completionValidationService.addCompletion(completionSchema.completionName);
|
|
2241
2342
|
swarm.completionSchemaService.register(completionSchema.completionName, completionSchema);
|
|
2242
2343
|
return completionSchema.completionName;
|
|
2243
2344
|
};
|
|
2244
2345
|
|
|
2245
2346
|
var addSwarm = function (swarmSchema) {
|
|
2347
|
+
swarm.loggerService.log('function addSwarm', {
|
|
2348
|
+
swarmSchema: swarmSchema,
|
|
2349
|
+
});
|
|
2246
2350
|
swarm.swarmValidationService.addSwarm(swarmSchema.swarmName, swarmSchema);
|
|
2247
2351
|
swarm.swarmSchemaService.register(swarmSchema.swarmName, swarmSchema);
|
|
2248
2352
|
return swarmSchema.swarmName;
|
|
2249
2353
|
};
|
|
2250
2354
|
|
|
2251
2355
|
var addTool = function (toolSchema) {
|
|
2356
|
+
swarm.loggerService.log('function addTool', {
|
|
2357
|
+
toolSchema: toolSchema,
|
|
2358
|
+
});
|
|
2252
2359
|
swarm.toolValidationService.addTool(toolSchema.toolName, toolSchema);
|
|
2253
2360
|
swarm.toolSchemaService.register(toolSchema.toolName, toolSchema);
|
|
2254
2361
|
return toolSchema.toolName;
|
|
2255
2362
|
};
|
|
2256
2363
|
|
|
2257
2364
|
var makeConnection = function (connector, clientId, swarmName) {
|
|
2365
|
+
swarm.loggerService.log("function makeConnection", {
|
|
2366
|
+
clientId: clientId,
|
|
2367
|
+
swarmName: swarmName,
|
|
2368
|
+
});
|
|
2258
2369
|
swarm.swarmValidationService.validate(swarmName, "makeConnection");
|
|
2259
2370
|
swarm.sessionValidationService.addSession(clientId, swarmName);
|
|
2260
2371
|
var send = swarm.sessionPublicService.connect(connector, clientId, swarmName);
|
|
@@ -2279,18 +2390,66 @@ var makeConnection = function (connector, clientId, swarmName) {
|
|
|
2279
2390
|
}); });
|
|
2280
2391
|
};
|
|
2281
2392
|
|
|
2393
|
+
var CHANGE_AGENT_TTL = 15 * 60 * 1000;
|
|
2394
|
+
var CHANGE_AGENT_GC = 60 * 1000;
|
|
2395
|
+
var createChangeAgent = functoolsKit.ttl(function (clientId) {
|
|
2396
|
+
return functoolsKit.queued(function (agentName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2397
|
+
var swarmName, _a, _b, _c;
|
|
2398
|
+
return __generator(this, function (_d) {
|
|
2399
|
+
switch (_d.label) {
|
|
2400
|
+
case 0:
|
|
2401
|
+
swarm.sessionValidationService.validate(clientId, "changeAgent");
|
|
2402
|
+
swarm.agentValidationService.validate(agentName, "changeAgent");
|
|
2403
|
+
swarmName = swarm.sessionValidationService.getSwarm(clientId);
|
|
2404
|
+
return [4 /*yield*/, swarm.agentPublicService.dispose(clientId, agentName)];
|
|
2405
|
+
case 1:
|
|
2406
|
+
_d.sent();
|
|
2407
|
+
return [4 /*yield*/, swarm.historyPublicService.dispose(clientId, agentName)];
|
|
2408
|
+
case 2:
|
|
2409
|
+
_d.sent();
|
|
2410
|
+
_b = (_a = swarm.swarmPublicService).setAgentRef;
|
|
2411
|
+
_c = [clientId,
|
|
2412
|
+
swarmName,
|
|
2413
|
+
agentName];
|
|
2414
|
+
return [4 /*yield*/, swarm.agentPublicService.createAgentRef(clientId, agentName)];
|
|
2415
|
+
case 3: return [4 /*yield*/, _b.apply(_a, _c.concat([_d.sent()]))];
|
|
2416
|
+
case 4:
|
|
2417
|
+
_d.sent();
|
|
2418
|
+
return [4 /*yield*/, swarm.swarmPublicService.setAgentName(agentName, clientId, swarmName)];
|
|
2419
|
+
case 5:
|
|
2420
|
+
_d.sent();
|
|
2421
|
+
return [2 /*return*/];
|
|
2422
|
+
}
|
|
2423
|
+
});
|
|
2424
|
+
}); });
|
|
2425
|
+
}, {
|
|
2426
|
+
key: function (_a) {
|
|
2427
|
+
var _b = __read(_a, 1), clientId = _b[0];
|
|
2428
|
+
return "".concat(clientId);
|
|
2429
|
+
},
|
|
2430
|
+
timeout: CHANGE_AGENT_TTL,
|
|
2431
|
+
});
|
|
2432
|
+
var createGc$1 = functoolsKit.singleshot(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2433
|
+
return __generator(this, function (_a) {
|
|
2434
|
+
setInterval(createChangeAgent.gc, CHANGE_AGENT_GC);
|
|
2435
|
+
return [2 /*return*/];
|
|
2436
|
+
});
|
|
2437
|
+
}); });
|
|
2282
2438
|
var changeAgent = function (agentName, clientId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2283
|
-
var
|
|
2439
|
+
var run;
|
|
2284
2440
|
return __generator(this, function (_a) {
|
|
2285
2441
|
switch (_a.label) {
|
|
2286
2442
|
case 0:
|
|
2287
|
-
swarm.
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2443
|
+
swarm.loggerService.log('function changeAgent', {
|
|
2444
|
+
agentName: agentName,
|
|
2445
|
+
clientId: clientId,
|
|
2446
|
+
});
|
|
2447
|
+
return [4 /*yield*/, createChangeAgent(clientId)];
|
|
2291
2448
|
case 1:
|
|
2292
|
-
_a.sent();
|
|
2293
|
-
|
|
2449
|
+
run = _a.sent();
|
|
2450
|
+
createGc$1();
|
|
2451
|
+
return [4 /*yield*/, run(agentName)];
|
|
2452
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
2294
2453
|
}
|
|
2295
2454
|
});
|
|
2296
2455
|
}); };
|
|
@@ -2299,6 +2458,10 @@ var disposeConnection = function (clientId, swarmName) { return __awaiter(void 0
|
|
|
2299
2458
|
return __generator(this, function (_a) {
|
|
2300
2459
|
switch (_a.label) {
|
|
2301
2460
|
case 0:
|
|
2461
|
+
swarm.loggerService.log("function disposeConnection", {
|
|
2462
|
+
clientId: clientId,
|
|
2463
|
+
swarmName: swarmName,
|
|
2464
|
+
});
|
|
2302
2465
|
swarm.swarmValidationService.validate(swarmName, "disposeConnection");
|
|
2303
2466
|
swarm.sessionValidationService.removeSession(clientId);
|
|
2304
2467
|
return [4 /*yield*/, swarm.sessionPublicService.dispose(clientId, swarmName)];
|
|
@@ -2368,7 +2531,13 @@ var complete = function (content, clientId, swarmName) { return __awaiter(void 0
|
|
|
2368
2531
|
var run;
|
|
2369
2532
|
return __generator(this, function (_a) {
|
|
2370
2533
|
switch (_a.label) {
|
|
2371
|
-
case 0:
|
|
2534
|
+
case 0:
|
|
2535
|
+
swarm.loggerService.log("function complete", {
|
|
2536
|
+
content: content,
|
|
2537
|
+
clientId: clientId,
|
|
2538
|
+
swarmName: swarmName,
|
|
2539
|
+
});
|
|
2540
|
+
return [4 /*yield*/, createComplete(clientId, swarmName)];
|
|
2372
2541
|
case 1:
|
|
2373
2542
|
run = _a.sent();
|
|
2374
2543
|
createGc();
|
|
@@ -2379,6 +2548,10 @@ var complete = function (content, clientId, swarmName) { return __awaiter(void 0
|
|
|
2379
2548
|
}); };
|
|
2380
2549
|
|
|
2381
2550
|
var session = function (clientId, swarmName) {
|
|
2551
|
+
swarm.loggerService.log("function session", {
|
|
2552
|
+
clientId: clientId,
|
|
2553
|
+
swarmName: swarmName,
|
|
2554
|
+
});
|
|
2382
2555
|
swarm.swarmValidationService.validate(swarmName, "session");
|
|
2383
2556
|
swarm.sessionValidationService.addSession(clientId, swarmName);
|
|
2384
2557
|
return {
|
|
@@ -2408,6 +2581,9 @@ var getRawHistory = function (clientId) { return __awaiter(void 0, void 0, void
|
|
|
2408
2581
|
return __generator(this, function (_a) {
|
|
2409
2582
|
switch (_a.label) {
|
|
2410
2583
|
case 0:
|
|
2584
|
+
swarm.loggerService.log("function getRawHistory", {
|
|
2585
|
+
clientId: clientId,
|
|
2586
|
+
});
|
|
2411
2587
|
swarm.sessionValidationService.validate(clientId, "getRawHistory");
|
|
2412
2588
|
swarmName = swarm.sessionValidationService.getSwarm(clientId);
|
|
2413
2589
|
swarm.swarmValidationService.validate(swarmName, "getRawHistory");
|
|
@@ -2427,6 +2603,10 @@ var getAgentHistory = function (clientId, agentName) { return __awaiter(void 0,
|
|
|
2427
2603
|
return __generator(this, function (_a) {
|
|
2428
2604
|
switch (_a.label) {
|
|
2429
2605
|
case 0:
|
|
2606
|
+
swarm.loggerService.log("function getAgentHistory", {
|
|
2607
|
+
clientId: clientId,
|
|
2608
|
+
agentName: agentName,
|
|
2609
|
+
});
|
|
2430
2610
|
swarm.agentValidationService.validate(agentName, "getAgentHistory");
|
|
2431
2611
|
prompt = swarm.agentSchemaService.get(agentName).prompt;
|
|
2432
2612
|
return [4 /*yield*/, swarm.historyPublicService.toArrayForAgent(prompt, clientId, agentName)];
|
|
@@ -2442,6 +2622,11 @@ var commitToolOutput = function (content, clientId, agentName) { return __awaite
|
|
|
2442
2622
|
return __generator(this, function (_a) {
|
|
2443
2623
|
switch (_a.label) {
|
|
2444
2624
|
case 0:
|
|
2625
|
+
swarm.loggerService.log('function commitToolOutput', {
|
|
2626
|
+
content: content,
|
|
2627
|
+
clientId: clientId,
|
|
2628
|
+
agentName: agentName,
|
|
2629
|
+
});
|
|
2445
2630
|
swarm.agentValidationService.validate(agentName, "commitSystemMessage");
|
|
2446
2631
|
swarm.sessionValidationService.validate(clientId, "commitToolOutput");
|
|
2447
2632
|
swarmName = swarm.sessionValidationService.getSwarm(clientId);
|
|
@@ -2470,6 +2655,11 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
|
|
|
2470
2655
|
return __generator(this, function (_a) {
|
|
2471
2656
|
switch (_a.label) {
|
|
2472
2657
|
case 0:
|
|
2658
|
+
swarm.loggerService.log('function commitSystemMessage', {
|
|
2659
|
+
content: content,
|
|
2660
|
+
clientId: clientId,
|
|
2661
|
+
agentName: agentName,
|
|
2662
|
+
});
|
|
2473
2663
|
swarm.agentValidationService.validate(agentName, "commitSystemMessage");
|
|
2474
2664
|
swarm.sessionValidationService.validate(clientId, "commitSystemMessage");
|
|
2475
2665
|
swarmName = swarm.sessionValidationService.getSwarm(clientId);
|
|
@@ -2498,6 +2688,11 @@ var execute = function (content, clientId, agentName) { return __awaiter(void 0,
|
|
|
2498
2688
|
return __generator(this, function (_a) {
|
|
2499
2689
|
switch (_a.label) {
|
|
2500
2690
|
case 0:
|
|
2691
|
+
swarm.loggerService.log("function execute", {
|
|
2692
|
+
content: content,
|
|
2693
|
+
clientId: clientId,
|
|
2694
|
+
agentName: agentName,
|
|
2695
|
+
});
|
|
2501
2696
|
swarm.agentValidationService.validate(agentName, "commitSystemMessage");
|
|
2502
2697
|
swarm.sessionValidationService.validate(clientId, "execute");
|
|
2503
2698
|
swarmName = swarm.sessionValidationService.getSwarm(clientId);
|
package/build/index.mjs
CHANGED
|
@@ -423,7 +423,7 @@ var ClientAgent = /** @class */ (function () {
|
|
|
423
423
|
case 1:
|
|
424
424
|
_f.sent();
|
|
425
425
|
if (!!targetFn) return [3 /*break*/, 4];
|
|
426
|
-
this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool function not found"));
|
|
426
|
+
this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool function not found"), this_1.params.tools);
|
|
427
427
|
return [4 /*yield*/, this_1._resurrectModel("No target function for ".concat(tool.function.name))];
|
|
428
428
|
case 2:
|
|
429
429
|
result_2 = _f.sent();
|
|
@@ -520,7 +520,9 @@ var ClientAgent = /** @class */ (function () {
|
|
|
520
520
|
}
|
|
521
521
|
});
|
|
522
522
|
}); });
|
|
523
|
-
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " CTOR")
|
|
523
|
+
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " CTOR"), {
|
|
524
|
+
params: params,
|
|
525
|
+
});
|
|
524
526
|
}
|
|
525
527
|
return ClientAgent;
|
|
526
528
|
}());
|
|
@@ -846,7 +848,9 @@ var ClientHistory = /** @class */ (function () {
|
|
|
846
848
|
}
|
|
847
849
|
});
|
|
848
850
|
}); };
|
|
849
|
-
this.params.logger.debug("ClientHistory agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " CTOR")
|
|
851
|
+
this.params.logger.debug("ClientHistory agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " CTOR"), {
|
|
852
|
+
params: params,
|
|
853
|
+
});
|
|
850
854
|
}
|
|
851
855
|
return ClientHistory;
|
|
852
856
|
}());
|
|
@@ -949,10 +953,12 @@ var ToolSchemaService = /** @class */ (function () {
|
|
|
949
953
|
return ToolSchemaService;
|
|
950
954
|
}());
|
|
951
955
|
|
|
956
|
+
var AGENT_REF_CHANGED = Symbol('agent-ref-changed');
|
|
952
957
|
var ClientSwarm = /** @class */ (function () {
|
|
953
958
|
function ClientSwarm(params) {
|
|
954
959
|
var _this = this;
|
|
955
960
|
this.params = params;
|
|
961
|
+
this._agentChangedSubject = new Subject();
|
|
956
962
|
this.waitForOutput = queued(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
957
963
|
var START_TIME, _a, agentName, output, _b;
|
|
958
964
|
var _this = this;
|
|
@@ -966,7 +972,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
966
972
|
if (Date.now() - START_TIME >= GLOBAL_CONFIG.CC_ANSWER_TIMEOUT_SECONDS) {
|
|
967
973
|
throw new Error("agent-swarm ClientSwarm waitForOutput timeout reached for ".concat(this.params.swarmName));
|
|
968
974
|
}
|
|
969
|
-
return [4 /*yield*/, Promise.race(Object.entries(this.params.agentMap).map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
975
|
+
return [4 /*yield*/, Promise.race(__spreadArray(__spreadArray([], __read(Object.entries(this.params.agentMap).map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
970
976
|
var _c;
|
|
971
977
|
var _d = __read(_b, 2), agentName = _d[0], agent = _d[1];
|
|
972
978
|
return __generator(this, function (_e) {
|
|
@@ -979,9 +985,14 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
979
985
|
])];
|
|
980
986
|
}
|
|
981
987
|
});
|
|
982
|
-
}); }))
|
|
988
|
+
}); })), false), [
|
|
989
|
+
this._agentChangedSubject.toPromise().then(function () { return [AGENT_REF_CHANGED]; }),
|
|
990
|
+
], false))];
|
|
983
991
|
case 2:
|
|
984
992
|
_a = __read.apply(void 0, [_c.sent(), 2]), agentName = _a[0], output = _a[1];
|
|
993
|
+
if (agentName === AGENT_REF_CHANGED) {
|
|
994
|
+
return [3 /*break*/, 1];
|
|
995
|
+
}
|
|
985
996
|
_b = agentName;
|
|
986
997
|
return [4 /*yield*/, this.getAgentName()];
|
|
987
998
|
case 3:
|
|
@@ -1012,6 +1023,22 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1012
1023
|
}
|
|
1013
1024
|
});
|
|
1014
1025
|
}); };
|
|
1026
|
+
this.setAgentRef = function (agentName, agent) { return __awaiter(_this, void 0, void 0, function () {
|
|
1027
|
+
return __generator(this, function (_a) {
|
|
1028
|
+
switch (_a.label) {
|
|
1029
|
+
case 0:
|
|
1030
|
+
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " setAgentRef agentName=").concat(agentName));
|
|
1031
|
+
if (!this.params.agentMap[agentName]) {
|
|
1032
|
+
throw new Error("agent-swarm agent ".concat(agentName, " not in the swarm"));
|
|
1033
|
+
}
|
|
1034
|
+
this.params.agentMap[agentName] = agent;
|
|
1035
|
+
return [4 /*yield*/, this._agentChangedSubject.next()];
|
|
1036
|
+
case 1:
|
|
1037
|
+
_a.sent();
|
|
1038
|
+
return [2 /*return*/];
|
|
1039
|
+
}
|
|
1040
|
+
});
|
|
1041
|
+
}); };
|
|
1015
1042
|
this.setAgentName = function (agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1016
1043
|
return __generator(this, function (_a) {
|
|
1017
1044
|
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " setAgentName agentName=").concat(agentName));
|
|
@@ -1019,7 +1046,9 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1019
1046
|
return [2 /*return*/];
|
|
1020
1047
|
});
|
|
1021
1048
|
}); };
|
|
1022
|
-
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " CTOR")
|
|
1049
|
+
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " CTOR"), {
|
|
1050
|
+
params: params,
|
|
1051
|
+
});
|
|
1023
1052
|
this._activeAgent = params.defaultAgent;
|
|
1024
1053
|
}
|
|
1025
1054
|
return ClientSwarm;
|
|
@@ -1096,6 +1125,18 @@ var SwarmConnectionService = /** @class */ (function () {
|
|
|
1096
1125
|
}
|
|
1097
1126
|
});
|
|
1098
1127
|
}); };
|
|
1128
|
+
this.setAgentRef = function (agentName, agent) { return __awaiter(_this, void 0, void 0, function () {
|
|
1129
|
+
return __generator(this, function (_a) {
|
|
1130
|
+
switch (_a.label) {
|
|
1131
|
+
case 0:
|
|
1132
|
+
this.loggerService.log("swarmConnectionService setAgentRef", {
|
|
1133
|
+
context: this.contextService.context,
|
|
1134
|
+
});
|
|
1135
|
+
return [4 /*yield*/, this.getSwarm(this.contextService.context.clientId, this.contextService.context.swarmName).setAgentRef(agentName, agent)];
|
|
1136
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1137
|
+
}
|
|
1138
|
+
});
|
|
1139
|
+
}); };
|
|
1099
1140
|
this.setAgentName = function (agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1100
1141
|
return __generator(this, function (_a) {
|
|
1101
1142
|
switch (_a.label) {
|
|
@@ -1271,7 +1312,9 @@ var ClientSession = /** @class */ (function () {
|
|
|
1271
1312
|
});
|
|
1272
1313
|
}); };
|
|
1273
1314
|
};
|
|
1274
|
-
this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " CTOR")
|
|
1315
|
+
this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " CTOR"), {
|
|
1316
|
+
params: params,
|
|
1317
|
+
});
|
|
1275
1318
|
}
|
|
1276
1319
|
return ClientSession;
|
|
1277
1320
|
}());
|
|
@@ -1352,6 +1395,31 @@ var AgentPublicService = /** @class */ (function () {
|
|
|
1352
1395
|
var _this = this;
|
|
1353
1396
|
this.loggerService = inject(TYPES.loggerService);
|
|
1354
1397
|
this.agentConnectionService = inject(TYPES.agentConnectionService);
|
|
1398
|
+
this.createAgentRef = function (clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1399
|
+
var _this = this;
|
|
1400
|
+
return __generator(this, function (_a) {
|
|
1401
|
+
switch (_a.label) {
|
|
1402
|
+
case 0:
|
|
1403
|
+
this.loggerService.log("agentPublicService createAgentRef", {
|
|
1404
|
+
clientId: clientId,
|
|
1405
|
+
agentName: agentName,
|
|
1406
|
+
});
|
|
1407
|
+
return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1408
|
+
return __generator(this, function (_a) {
|
|
1409
|
+
switch (_a.label) {
|
|
1410
|
+
case 0: return [4 /*yield*/, this.agentConnectionService.getAgent(clientId, agentName)];
|
|
1411
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1412
|
+
}
|
|
1413
|
+
});
|
|
1414
|
+
}); }, {
|
|
1415
|
+
clientId: clientId,
|
|
1416
|
+
agentName: agentName,
|
|
1417
|
+
swarmName: "",
|
|
1418
|
+
})];
|
|
1419
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1420
|
+
}
|
|
1421
|
+
});
|
|
1422
|
+
}); };
|
|
1355
1423
|
this.execute = function (input, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1356
1424
|
var _this = this;
|
|
1357
1425
|
return __generator(this, function (_a) {
|
|
@@ -1828,6 +1896,33 @@ var SwarmPublicService = /** @class */ (function () {
|
|
|
1828
1896
|
}
|
|
1829
1897
|
});
|
|
1830
1898
|
}); };
|
|
1899
|
+
this.setAgentRef = function (clientId, swarmName, agentName, agent) { return __awaiter(_this, void 0, void 0, function () {
|
|
1900
|
+
var _this = this;
|
|
1901
|
+
return __generator(this, function (_a) {
|
|
1902
|
+
switch (_a.label) {
|
|
1903
|
+
case 0:
|
|
1904
|
+
this.loggerService.log("swarmPublicService setAgentRef", {
|
|
1905
|
+
agentName: agentName,
|
|
1906
|
+
agent: agent,
|
|
1907
|
+
clientId: clientId,
|
|
1908
|
+
swarmName: swarmName,
|
|
1909
|
+
});
|
|
1910
|
+
return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1911
|
+
return __generator(this, function (_a) {
|
|
1912
|
+
switch (_a.label) {
|
|
1913
|
+
case 0: return [4 /*yield*/, this.swarmConnectionService.setAgentRef(agentName, agent)];
|
|
1914
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1915
|
+
}
|
|
1916
|
+
});
|
|
1917
|
+
}); }, {
|
|
1918
|
+
clientId: clientId,
|
|
1919
|
+
swarmName: swarmName,
|
|
1920
|
+
agentName: "",
|
|
1921
|
+
})];
|
|
1922
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1923
|
+
}
|
|
1924
|
+
});
|
|
1925
|
+
}); };
|
|
1831
1926
|
this.setAgentName = function (agentName, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1832
1927
|
var _this = this;
|
|
1833
1928
|
return __generator(this, function (_a) {
|
|
@@ -2229,30 +2324,46 @@ var swarm = __assign(__assign(__assign(__assign(__assign({}, baseServices), conn
|
|
|
2229
2324
|
init();
|
|
2230
2325
|
|
|
2231
2326
|
var addAgent = function (agentSchema) {
|
|
2327
|
+
swarm.loggerService.log('function addAgent', {
|
|
2328
|
+
agentSchema: agentSchema
|
|
2329
|
+
});
|
|
2232
2330
|
swarm.agentValidationService.addAgent(agentSchema.agentName, agentSchema);
|
|
2233
2331
|
swarm.agentSchemaService.register(agentSchema.agentName, agentSchema);
|
|
2234
2332
|
return agentSchema.agentName;
|
|
2235
2333
|
};
|
|
2236
2334
|
|
|
2237
2335
|
var addCompletion = function (completionSchema) {
|
|
2336
|
+
swarm.loggerService.log('function addCompletion', {
|
|
2337
|
+
completionSchema: completionSchema,
|
|
2338
|
+
});
|
|
2238
2339
|
swarm.completionValidationService.addCompletion(completionSchema.completionName);
|
|
2239
2340
|
swarm.completionSchemaService.register(completionSchema.completionName, completionSchema);
|
|
2240
2341
|
return completionSchema.completionName;
|
|
2241
2342
|
};
|
|
2242
2343
|
|
|
2243
2344
|
var addSwarm = function (swarmSchema) {
|
|
2345
|
+
swarm.loggerService.log('function addSwarm', {
|
|
2346
|
+
swarmSchema: swarmSchema,
|
|
2347
|
+
});
|
|
2244
2348
|
swarm.swarmValidationService.addSwarm(swarmSchema.swarmName, swarmSchema);
|
|
2245
2349
|
swarm.swarmSchemaService.register(swarmSchema.swarmName, swarmSchema);
|
|
2246
2350
|
return swarmSchema.swarmName;
|
|
2247
2351
|
};
|
|
2248
2352
|
|
|
2249
2353
|
var addTool = function (toolSchema) {
|
|
2354
|
+
swarm.loggerService.log('function addTool', {
|
|
2355
|
+
toolSchema: toolSchema,
|
|
2356
|
+
});
|
|
2250
2357
|
swarm.toolValidationService.addTool(toolSchema.toolName, toolSchema);
|
|
2251
2358
|
swarm.toolSchemaService.register(toolSchema.toolName, toolSchema);
|
|
2252
2359
|
return toolSchema.toolName;
|
|
2253
2360
|
};
|
|
2254
2361
|
|
|
2255
2362
|
var makeConnection = function (connector, clientId, swarmName) {
|
|
2363
|
+
swarm.loggerService.log("function makeConnection", {
|
|
2364
|
+
clientId: clientId,
|
|
2365
|
+
swarmName: swarmName,
|
|
2366
|
+
});
|
|
2256
2367
|
swarm.swarmValidationService.validate(swarmName, "makeConnection");
|
|
2257
2368
|
swarm.sessionValidationService.addSession(clientId, swarmName);
|
|
2258
2369
|
var send = swarm.sessionPublicService.connect(connector, clientId, swarmName);
|
|
@@ -2277,18 +2388,66 @@ var makeConnection = function (connector, clientId, swarmName) {
|
|
|
2277
2388
|
}); });
|
|
2278
2389
|
};
|
|
2279
2390
|
|
|
2391
|
+
var CHANGE_AGENT_TTL = 15 * 60 * 1000;
|
|
2392
|
+
var CHANGE_AGENT_GC = 60 * 1000;
|
|
2393
|
+
var createChangeAgent = ttl(function (clientId) {
|
|
2394
|
+
return queued(function (agentName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2395
|
+
var swarmName, _a, _b, _c;
|
|
2396
|
+
return __generator(this, function (_d) {
|
|
2397
|
+
switch (_d.label) {
|
|
2398
|
+
case 0:
|
|
2399
|
+
swarm.sessionValidationService.validate(clientId, "changeAgent");
|
|
2400
|
+
swarm.agentValidationService.validate(agentName, "changeAgent");
|
|
2401
|
+
swarmName = swarm.sessionValidationService.getSwarm(clientId);
|
|
2402
|
+
return [4 /*yield*/, swarm.agentPublicService.dispose(clientId, agentName)];
|
|
2403
|
+
case 1:
|
|
2404
|
+
_d.sent();
|
|
2405
|
+
return [4 /*yield*/, swarm.historyPublicService.dispose(clientId, agentName)];
|
|
2406
|
+
case 2:
|
|
2407
|
+
_d.sent();
|
|
2408
|
+
_b = (_a = swarm.swarmPublicService).setAgentRef;
|
|
2409
|
+
_c = [clientId,
|
|
2410
|
+
swarmName,
|
|
2411
|
+
agentName];
|
|
2412
|
+
return [4 /*yield*/, swarm.agentPublicService.createAgentRef(clientId, agentName)];
|
|
2413
|
+
case 3: return [4 /*yield*/, _b.apply(_a, _c.concat([_d.sent()]))];
|
|
2414
|
+
case 4:
|
|
2415
|
+
_d.sent();
|
|
2416
|
+
return [4 /*yield*/, swarm.swarmPublicService.setAgentName(agentName, clientId, swarmName)];
|
|
2417
|
+
case 5:
|
|
2418
|
+
_d.sent();
|
|
2419
|
+
return [2 /*return*/];
|
|
2420
|
+
}
|
|
2421
|
+
});
|
|
2422
|
+
}); });
|
|
2423
|
+
}, {
|
|
2424
|
+
key: function (_a) {
|
|
2425
|
+
var _b = __read(_a, 1), clientId = _b[0];
|
|
2426
|
+
return "".concat(clientId);
|
|
2427
|
+
},
|
|
2428
|
+
timeout: CHANGE_AGENT_TTL,
|
|
2429
|
+
});
|
|
2430
|
+
var createGc$1 = singleshot(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2431
|
+
return __generator(this, function (_a) {
|
|
2432
|
+
setInterval(createChangeAgent.gc, CHANGE_AGENT_GC);
|
|
2433
|
+
return [2 /*return*/];
|
|
2434
|
+
});
|
|
2435
|
+
}); });
|
|
2280
2436
|
var changeAgent = function (agentName, clientId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2281
|
-
var
|
|
2437
|
+
var run;
|
|
2282
2438
|
return __generator(this, function (_a) {
|
|
2283
2439
|
switch (_a.label) {
|
|
2284
2440
|
case 0:
|
|
2285
|
-
swarm.
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2441
|
+
swarm.loggerService.log('function changeAgent', {
|
|
2442
|
+
agentName: agentName,
|
|
2443
|
+
clientId: clientId,
|
|
2444
|
+
});
|
|
2445
|
+
return [4 /*yield*/, createChangeAgent(clientId)];
|
|
2289
2446
|
case 1:
|
|
2290
|
-
_a.sent();
|
|
2291
|
-
|
|
2447
|
+
run = _a.sent();
|
|
2448
|
+
createGc$1();
|
|
2449
|
+
return [4 /*yield*/, run(agentName)];
|
|
2450
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
2292
2451
|
}
|
|
2293
2452
|
});
|
|
2294
2453
|
}); };
|
|
@@ -2297,6 +2456,10 @@ var disposeConnection = function (clientId, swarmName) { return __awaiter(void 0
|
|
|
2297
2456
|
return __generator(this, function (_a) {
|
|
2298
2457
|
switch (_a.label) {
|
|
2299
2458
|
case 0:
|
|
2459
|
+
swarm.loggerService.log("function disposeConnection", {
|
|
2460
|
+
clientId: clientId,
|
|
2461
|
+
swarmName: swarmName,
|
|
2462
|
+
});
|
|
2300
2463
|
swarm.swarmValidationService.validate(swarmName, "disposeConnection");
|
|
2301
2464
|
swarm.sessionValidationService.removeSession(clientId);
|
|
2302
2465
|
return [4 /*yield*/, swarm.sessionPublicService.dispose(clientId, swarmName)];
|
|
@@ -2366,7 +2529,13 @@ var complete = function (content, clientId, swarmName) { return __awaiter(void 0
|
|
|
2366
2529
|
var run;
|
|
2367
2530
|
return __generator(this, function (_a) {
|
|
2368
2531
|
switch (_a.label) {
|
|
2369
|
-
case 0:
|
|
2532
|
+
case 0:
|
|
2533
|
+
swarm.loggerService.log("function complete", {
|
|
2534
|
+
content: content,
|
|
2535
|
+
clientId: clientId,
|
|
2536
|
+
swarmName: swarmName,
|
|
2537
|
+
});
|
|
2538
|
+
return [4 /*yield*/, createComplete(clientId, swarmName)];
|
|
2370
2539
|
case 1:
|
|
2371
2540
|
run = _a.sent();
|
|
2372
2541
|
createGc();
|
|
@@ -2377,6 +2546,10 @@ var complete = function (content, clientId, swarmName) { return __awaiter(void 0
|
|
|
2377
2546
|
}); };
|
|
2378
2547
|
|
|
2379
2548
|
var session = function (clientId, swarmName) {
|
|
2549
|
+
swarm.loggerService.log("function session", {
|
|
2550
|
+
clientId: clientId,
|
|
2551
|
+
swarmName: swarmName,
|
|
2552
|
+
});
|
|
2380
2553
|
swarm.swarmValidationService.validate(swarmName, "session");
|
|
2381
2554
|
swarm.sessionValidationService.addSession(clientId, swarmName);
|
|
2382
2555
|
return {
|
|
@@ -2406,6 +2579,9 @@ var getRawHistory = function (clientId) { return __awaiter(void 0, void 0, void
|
|
|
2406
2579
|
return __generator(this, function (_a) {
|
|
2407
2580
|
switch (_a.label) {
|
|
2408
2581
|
case 0:
|
|
2582
|
+
swarm.loggerService.log("function getRawHistory", {
|
|
2583
|
+
clientId: clientId,
|
|
2584
|
+
});
|
|
2409
2585
|
swarm.sessionValidationService.validate(clientId, "getRawHistory");
|
|
2410
2586
|
swarmName = swarm.sessionValidationService.getSwarm(clientId);
|
|
2411
2587
|
swarm.swarmValidationService.validate(swarmName, "getRawHistory");
|
|
@@ -2425,6 +2601,10 @@ var getAgentHistory = function (clientId, agentName) { return __awaiter(void 0,
|
|
|
2425
2601
|
return __generator(this, function (_a) {
|
|
2426
2602
|
switch (_a.label) {
|
|
2427
2603
|
case 0:
|
|
2604
|
+
swarm.loggerService.log("function getAgentHistory", {
|
|
2605
|
+
clientId: clientId,
|
|
2606
|
+
agentName: agentName,
|
|
2607
|
+
});
|
|
2428
2608
|
swarm.agentValidationService.validate(agentName, "getAgentHistory");
|
|
2429
2609
|
prompt = swarm.agentSchemaService.get(agentName).prompt;
|
|
2430
2610
|
return [4 /*yield*/, swarm.historyPublicService.toArrayForAgent(prompt, clientId, agentName)];
|
|
@@ -2440,6 +2620,11 @@ var commitToolOutput = function (content, clientId, agentName) { return __awaite
|
|
|
2440
2620
|
return __generator(this, function (_a) {
|
|
2441
2621
|
switch (_a.label) {
|
|
2442
2622
|
case 0:
|
|
2623
|
+
swarm.loggerService.log('function commitToolOutput', {
|
|
2624
|
+
content: content,
|
|
2625
|
+
clientId: clientId,
|
|
2626
|
+
agentName: agentName,
|
|
2627
|
+
});
|
|
2443
2628
|
swarm.agentValidationService.validate(agentName, "commitSystemMessage");
|
|
2444
2629
|
swarm.sessionValidationService.validate(clientId, "commitToolOutput");
|
|
2445
2630
|
swarmName = swarm.sessionValidationService.getSwarm(clientId);
|
|
@@ -2468,6 +2653,11 @@ var commitSystemMessage = function (content, clientId, agentName) { return __awa
|
|
|
2468
2653
|
return __generator(this, function (_a) {
|
|
2469
2654
|
switch (_a.label) {
|
|
2470
2655
|
case 0:
|
|
2656
|
+
swarm.loggerService.log('function commitSystemMessage', {
|
|
2657
|
+
content: content,
|
|
2658
|
+
clientId: clientId,
|
|
2659
|
+
agentName: agentName,
|
|
2660
|
+
});
|
|
2471
2661
|
swarm.agentValidationService.validate(agentName, "commitSystemMessage");
|
|
2472
2662
|
swarm.sessionValidationService.validate(clientId, "commitSystemMessage");
|
|
2473
2663
|
swarmName = swarm.sessionValidationService.getSwarm(clientId);
|
|
@@ -2496,6 +2686,11 @@ var execute = function (content, clientId, agentName) { return __awaiter(void 0,
|
|
|
2496
2686
|
return __generator(this, function (_a) {
|
|
2497
2687
|
switch (_a.label) {
|
|
2498
2688
|
case 0:
|
|
2689
|
+
swarm.loggerService.log("function execute", {
|
|
2690
|
+
content: content,
|
|
2691
|
+
clientId: clientId,
|
|
2692
|
+
agentName: agentName,
|
|
2693
|
+
});
|
|
2499
2694
|
swarm.agentValidationService.validate(agentName, "commitSystemMessage");
|
|
2500
2695
|
swarm.sessionValidationService.validate(clientId, "execute");
|
|
2501
2696
|
swarmName = swarm.sessionValidationService.getSwarm(clientId);
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -125,6 +125,7 @@ interface ISwarm {
|
|
|
125
125
|
waitForOutput(): Promise<string>;
|
|
126
126
|
getAgentName(): Promise<AgentName>;
|
|
127
127
|
getAgent(): Promise<IAgent>;
|
|
128
|
+
setAgentRef(agentName: AgentName, agent: IAgent): Promise<void>;
|
|
128
129
|
setAgentName(agentName: AgentName): Promise<void>;
|
|
129
130
|
}
|
|
130
131
|
type SwarmName = string;
|
|
@@ -215,11 +216,13 @@ declare class ToolSchemaService {
|
|
|
215
216
|
|
|
216
217
|
declare class ClientSwarm implements ISwarm {
|
|
217
218
|
readonly params: ISwarmParams;
|
|
219
|
+
private _agentChangedSubject;
|
|
218
220
|
private _activeAgent;
|
|
219
221
|
constructor(params: ISwarmParams);
|
|
220
222
|
waitForOutput: () => Promise<string>;
|
|
221
223
|
getAgentName: () => Promise<AgentName>;
|
|
222
224
|
getAgent: () => Promise<IAgent>;
|
|
225
|
+
setAgentRef: (agentName: AgentName, agent: IAgent) => Promise<void>;
|
|
223
226
|
setAgentName: (agentName: AgentName) => Promise<void>;
|
|
224
227
|
}
|
|
225
228
|
|
|
@@ -232,6 +235,7 @@ declare class SwarmConnectionService implements ISwarm {
|
|
|
232
235
|
waitForOutput: () => Promise<string>;
|
|
233
236
|
getAgentName: () => Promise<string>;
|
|
234
237
|
getAgent: () => Promise<IAgent>;
|
|
238
|
+
setAgentRef: (agentName: AgentName, agent: IAgent) => Promise<void>;
|
|
235
239
|
setAgentName: (agentName: AgentName) => Promise<void>;
|
|
236
240
|
dispose: () => Promise<void>;
|
|
237
241
|
}
|
|
@@ -311,6 +315,7 @@ type TAgentConnectionService = {
|
|
|
311
315
|
declare class AgentPublicService implements TAgentConnectionService {
|
|
312
316
|
private readonly loggerService;
|
|
313
317
|
private readonly agentConnectionService;
|
|
318
|
+
createAgentRef: (clientId: string, agentName: AgentName) => Promise<ClientAgent>;
|
|
314
319
|
execute: (input: string, clientId: string, agentName: AgentName) => Promise<void>;
|
|
315
320
|
waitForOutput: (clientId: string, agentName: AgentName) => Promise<string>;
|
|
316
321
|
commitToolOutput: (content: string, clientId: string, agentName: AgentName) => Promise<void>;
|
|
@@ -368,6 +373,7 @@ declare class SwarmPublicService implements TSwarmConnectionService {
|
|
|
368
373
|
waitForOutput: (clientId: string, swarmName: SwarmName) => Promise<string>;
|
|
369
374
|
getAgentName: (clientId: string, swarmName: SwarmName) => Promise<string>;
|
|
370
375
|
getAgent: (clientId: string, swarmName: SwarmName) => Promise<IAgent>;
|
|
376
|
+
setAgentRef: (clientId: string, swarmName: SwarmName, agentName: AgentName, agent: IAgent) => Promise<void>;
|
|
371
377
|
setAgentName: (agentName: AgentName, clientId: string, swarmName: SwarmName) => Promise<void>;
|
|
372
378
|
dispose: (clientId: string, swarmName: SwarmName) => Promise<void>;
|
|
373
379
|
}
|