agent-swarm-kit 1.0.17 → 1.0.18
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 +113 -12
- package/build/index.mjs +113 -14
- package/package.json +2 -1
- package/types.d.ts +21 -1
package/build/index.cjs
CHANGED
|
@@ -277,6 +277,22 @@ var CC_EMPTY_OUTPUT_PLACEHOLDERS = [
|
|
|
277
277
|
"I didn’t hear you properly. Can you say that again?",
|
|
278
278
|
"Could you please repeat that? I didn’t catch it.",
|
|
279
279
|
];
|
|
280
|
+
var CC_SWARM_AGENT_CHANGED = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
281
|
+
switch (_a.label) {
|
|
282
|
+
case 0: return [4 /*yield*/, functoolsKit.sleep(100)];
|
|
283
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
284
|
+
}
|
|
285
|
+
}); }); };
|
|
286
|
+
var CC_SWARM_DEFAULT_AGENT = function (_a, _b, defaultAgent_1) { return __awaiter(void 0, [_a, _b, defaultAgent_1], void 0, function (_c, _d, defaultAgent) {
|
|
287
|
+
return __generator(this, function (_e) {
|
|
288
|
+
switch (_e.label) {
|
|
289
|
+
case 0: return [4 /*yield*/, functoolsKit.sleep(100)];
|
|
290
|
+
case 1:
|
|
291
|
+
_e.sent();
|
|
292
|
+
return [2 /*return*/, defaultAgent];
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}); };
|
|
280
296
|
var CC_KEEP_MESSAGES = 5;
|
|
281
297
|
var CC_ANSWER_TIMEOUT_SECONDS = 120000;
|
|
282
298
|
var CC_GET_AGENT_HISTORY = function () { return new functoolsKit.PubsubArrayAdapter(); };
|
|
@@ -286,6 +302,8 @@ var GLOBAL_CONFIG = {
|
|
|
286
302
|
CC_KEEP_MESSAGES: CC_KEEP_MESSAGES,
|
|
287
303
|
CC_ANSWER_TIMEOUT_SECONDS: CC_ANSWER_TIMEOUT_SECONDS,
|
|
288
304
|
CC_GET_AGENT_HISTORY: CC_GET_AGENT_HISTORY,
|
|
305
|
+
CC_SWARM_AGENT_CHANGED: CC_SWARM_AGENT_CHANGED,
|
|
306
|
+
CC_SWARM_DEFAULT_AGENT: CC_SWARM_DEFAULT_AGENT,
|
|
289
307
|
};
|
|
290
308
|
var setConfig = function (config) {
|
|
291
309
|
Object.assign(GLOBAL_CONFIG, config);
|
|
@@ -1201,7 +1219,8 @@ var ToolSchemaService = /** @class */ (function () {
|
|
|
1201
1219
|
return ToolSchemaService;
|
|
1202
1220
|
}());
|
|
1203
1221
|
|
|
1204
|
-
var AGENT_REF_CHANGED = Symbol(
|
|
1222
|
+
var AGENT_REF_CHANGED = Symbol("agent-ref-changed");
|
|
1223
|
+
var AGENT_NEED_FETCH = Symbol("agent-need-fetch");
|
|
1205
1224
|
/**
|
|
1206
1225
|
* ClientSwarm class implements the ISwarm interface and manages agents within a swarm.
|
|
1207
1226
|
*/
|
|
@@ -1214,6 +1233,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1214
1233
|
var _this = this;
|
|
1215
1234
|
this.params = params;
|
|
1216
1235
|
this._agentChangedSubject = new functoolsKit.Subject();
|
|
1236
|
+
this._activeAgent = AGENT_NEED_FETCH;
|
|
1217
1237
|
/**
|
|
1218
1238
|
* Waits for output from the active agent.
|
|
1219
1239
|
* @returns {Promise<string>} - The output from the active agent.
|
|
@@ -1240,13 +1260,13 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1240
1260
|
case 0:
|
|
1241
1261
|
_c = [agentName];
|
|
1242
1262
|
return [4 /*yield*/, agent.waitForOutput()];
|
|
1243
|
-
case 1: return [2 /*return*/, _c.concat([
|
|
1244
|
-
_e.sent()
|
|
1245
|
-
])];
|
|
1263
|
+
case 1: return [2 /*return*/, _c.concat([_e.sent()])];
|
|
1246
1264
|
}
|
|
1247
1265
|
});
|
|
1248
1266
|
}); })), false), [
|
|
1249
|
-
this._agentChangedSubject
|
|
1267
|
+
this._agentChangedSubject
|
|
1268
|
+
.toPromise()
|
|
1269
|
+
.then(function () { return [AGENT_REF_CHANGED]; }),
|
|
1250
1270
|
], false))];
|
|
1251
1271
|
case 2:
|
|
1252
1272
|
_a = __read.apply(void 0, [_c.sent(), 2]), agentName = _a[0], output = _a[1];
|
|
@@ -1269,9 +1289,19 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1269
1289
|
* @returns {Promise<AgentName>} - The name of the active agent.
|
|
1270
1290
|
*/
|
|
1271
1291
|
this.getAgentName = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1292
|
+
var _a;
|
|
1293
|
+
return __generator(this, function (_b) {
|
|
1294
|
+
switch (_b.label) {
|
|
1295
|
+
case 0:
|
|
1296
|
+
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " getAgentName"));
|
|
1297
|
+
if (!(this._activeAgent === AGENT_NEED_FETCH)) return [3 /*break*/, 2];
|
|
1298
|
+
_a = this;
|
|
1299
|
+
return [4 /*yield*/, GLOBAL_CONFIG.CC_SWARM_DEFAULT_AGENT(this.params.clientId, this.params.swarmName, this.params.defaultAgent)];
|
|
1300
|
+
case 1:
|
|
1301
|
+
_a._activeAgent = _b.sent();
|
|
1302
|
+
_b.label = 2;
|
|
1303
|
+
case 2: return [2 /*return*/, this._activeAgent];
|
|
1304
|
+
}
|
|
1275
1305
|
});
|
|
1276
1306
|
}); };
|
|
1277
1307
|
/**
|
|
@@ -1319,15 +1349,20 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1319
1349
|
*/
|
|
1320
1350
|
this.setAgentName = function (agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1321
1351
|
return __generator(this, function (_a) {
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1352
|
+
switch (_a.label) {
|
|
1353
|
+
case 0:
|
|
1354
|
+
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " setAgentName agentName=").concat(agentName));
|
|
1355
|
+
this._activeAgent = agentName;
|
|
1356
|
+
return [4 /*yield*/, this.params.onAgentChanged(this.params.clientId, agentName, this.params.swarmName)];
|
|
1357
|
+
case 1:
|
|
1358
|
+
_a.sent();
|
|
1359
|
+
return [2 /*return*/];
|
|
1360
|
+
}
|
|
1325
1361
|
});
|
|
1326
1362
|
}); };
|
|
1327
1363
|
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " CTOR"), {
|
|
1328
1364
|
params: params,
|
|
1329
1365
|
});
|
|
1330
|
-
this._activeAgent = params.defaultAgent;
|
|
1331
1366
|
}
|
|
1332
1367
|
return ClientSwarm;
|
|
1333
1368
|
}());
|
|
@@ -1375,6 +1410,18 @@ var SwarmConnectionService = /** @class */ (function () {
|
|
|
1375
1410
|
defaultAgent: defaultAgent,
|
|
1376
1411
|
swarmName: swarmName,
|
|
1377
1412
|
logger: _this.loggerService,
|
|
1413
|
+
onAgentChanged: function (clientId, agentName, swarmName) {
|
|
1414
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1415
|
+
return __generator(this, function (_a) {
|
|
1416
|
+
switch (_a.label) {
|
|
1417
|
+
case 0: return [4 /*yield*/, GLOBAL_CONFIG.CC_SWARM_AGENT_CHANGED(clientId, agentName, swarmName)];
|
|
1418
|
+
case 1:
|
|
1419
|
+
_a.sent();
|
|
1420
|
+
return [2 /*return*/];
|
|
1421
|
+
}
|
|
1422
|
+
});
|
|
1423
|
+
});
|
|
1424
|
+
},
|
|
1378
1425
|
});
|
|
1379
1426
|
});
|
|
1380
1427
|
/**
|
|
@@ -4078,6 +4125,58 @@ var getAssistantHistory = function (clientId) { return __awaiter(void 0, void 0,
|
|
|
4078
4125
|
});
|
|
4079
4126
|
}); };
|
|
4080
4127
|
|
|
4128
|
+
/**
|
|
4129
|
+
* Retrieves the last message sent by the assistant from the client's message history.
|
|
4130
|
+
*
|
|
4131
|
+
* @param {string} clientId - The ID of the client whose message history is being retrieved.
|
|
4132
|
+
* @returns {Promise<string | null>} - The content of the last assistant message, or null if no user message is found.
|
|
4133
|
+
*/
|
|
4134
|
+
var getLastAssistantMessage = function (clientId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
4135
|
+
var history, last;
|
|
4136
|
+
return __generator(this, function (_a) {
|
|
4137
|
+
switch (_a.label) {
|
|
4138
|
+
case 0:
|
|
4139
|
+
swarm.loggerService.log("function getLastAssistantMessage", {
|
|
4140
|
+
clientId: clientId,
|
|
4141
|
+
});
|
|
4142
|
+
return [4 /*yield*/, getRawHistory(clientId)];
|
|
4143
|
+
case 1:
|
|
4144
|
+
history = _a.sent();
|
|
4145
|
+
last = history.findLast(function (_a) {
|
|
4146
|
+
var role = _a.role;
|
|
4147
|
+
return role === "assistant";
|
|
4148
|
+
});
|
|
4149
|
+
return [2 /*return*/, last ? last.content : null];
|
|
4150
|
+
}
|
|
4151
|
+
});
|
|
4152
|
+
}); };
|
|
4153
|
+
|
|
4154
|
+
/**
|
|
4155
|
+
* Retrieves the last message sent by the system from the client's message history.
|
|
4156
|
+
*
|
|
4157
|
+
* @param {string} clientId - The ID of the client whose message history is being retrieved.
|
|
4158
|
+
* @returns {Promise<string | null>} - The content of the last system message, or null if no user message is found.
|
|
4159
|
+
*/
|
|
4160
|
+
var getLastSystemMessage = function (clientId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
4161
|
+
var history, last;
|
|
4162
|
+
return __generator(this, function (_a) {
|
|
4163
|
+
switch (_a.label) {
|
|
4164
|
+
case 0:
|
|
4165
|
+
swarm.loggerService.log("function getLastSystemMessage", {
|
|
4166
|
+
clientId: clientId,
|
|
4167
|
+
});
|
|
4168
|
+
return [4 /*yield*/, getRawHistory(clientId)];
|
|
4169
|
+
case 1:
|
|
4170
|
+
history = _a.sent();
|
|
4171
|
+
last = history.findLast(function (_a) {
|
|
4172
|
+
var role = _a.role;
|
|
4173
|
+
return role === "system";
|
|
4174
|
+
});
|
|
4175
|
+
return [2 /*return*/, last ? last.content : null];
|
|
4176
|
+
}
|
|
4177
|
+
});
|
|
4178
|
+
}); };
|
|
4179
|
+
|
|
4081
4180
|
exports.ContextService = ContextService;
|
|
4082
4181
|
exports.addAgent = addAgent;
|
|
4083
4182
|
exports.addCompletion = addCompletion;
|
|
@@ -4094,6 +4193,8 @@ exports.execute = execute;
|
|
|
4094
4193
|
exports.getAgentHistory = getAgentHistory;
|
|
4095
4194
|
exports.getAgentName = getAgentName;
|
|
4096
4195
|
exports.getAssistantHistory = getAssistantHistory;
|
|
4196
|
+
exports.getLastAssistantMessage = getLastAssistantMessage;
|
|
4197
|
+
exports.getLastSystemMessage = getLastSystemMessage;
|
|
4097
4198
|
exports.getLastUserMessage = getLastUserMessage;
|
|
4098
4199
|
exports.getRawHistory = getRawHistory;
|
|
4099
4200
|
exports.getUserHistory = getUserHistory;
|
package/build/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { scoped } from 'di-scoped';
|
|
2
|
-
import { ToolRegistry, PubsubArrayAdapter, Subject, queued, not, trycatch, memoize, schedule, ttl, singleshot } from 'functools-kit';
|
|
2
|
+
import { ToolRegistry, sleep, PubsubArrayAdapter, Subject, queued, not, trycatch, memoize, schedule, ttl, singleshot } from 'functools-kit';
|
|
3
3
|
import { createActivator } from 'di-kit';
|
|
4
4
|
import { omit } from 'lodash-es';
|
|
5
5
|
import xml2js from 'xml2js';
|
|
@@ -275,6 +275,22 @@ var CC_EMPTY_OUTPUT_PLACEHOLDERS = [
|
|
|
275
275
|
"I didn’t hear you properly. Can you say that again?",
|
|
276
276
|
"Could you please repeat that? I didn’t catch it.",
|
|
277
277
|
];
|
|
278
|
+
var CC_SWARM_AGENT_CHANGED = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
279
|
+
switch (_a.label) {
|
|
280
|
+
case 0: return [4 /*yield*/, sleep(100)];
|
|
281
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
282
|
+
}
|
|
283
|
+
}); }); };
|
|
284
|
+
var CC_SWARM_DEFAULT_AGENT = function (_a, _b, defaultAgent_1) { return __awaiter(void 0, [_a, _b, defaultAgent_1], void 0, function (_c, _d, defaultAgent) {
|
|
285
|
+
return __generator(this, function (_e) {
|
|
286
|
+
switch (_e.label) {
|
|
287
|
+
case 0: return [4 /*yield*/, sleep(100)];
|
|
288
|
+
case 1:
|
|
289
|
+
_e.sent();
|
|
290
|
+
return [2 /*return*/, defaultAgent];
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}); };
|
|
278
294
|
var CC_KEEP_MESSAGES = 5;
|
|
279
295
|
var CC_ANSWER_TIMEOUT_SECONDS = 120000;
|
|
280
296
|
var CC_GET_AGENT_HISTORY = function () { return new PubsubArrayAdapter(); };
|
|
@@ -284,6 +300,8 @@ var GLOBAL_CONFIG = {
|
|
|
284
300
|
CC_KEEP_MESSAGES: CC_KEEP_MESSAGES,
|
|
285
301
|
CC_ANSWER_TIMEOUT_SECONDS: CC_ANSWER_TIMEOUT_SECONDS,
|
|
286
302
|
CC_GET_AGENT_HISTORY: CC_GET_AGENT_HISTORY,
|
|
303
|
+
CC_SWARM_AGENT_CHANGED: CC_SWARM_AGENT_CHANGED,
|
|
304
|
+
CC_SWARM_DEFAULT_AGENT: CC_SWARM_DEFAULT_AGENT,
|
|
287
305
|
};
|
|
288
306
|
var setConfig = function (config) {
|
|
289
307
|
Object.assign(GLOBAL_CONFIG, config);
|
|
@@ -1199,7 +1217,8 @@ var ToolSchemaService = /** @class */ (function () {
|
|
|
1199
1217
|
return ToolSchemaService;
|
|
1200
1218
|
}());
|
|
1201
1219
|
|
|
1202
|
-
var AGENT_REF_CHANGED = Symbol(
|
|
1220
|
+
var AGENT_REF_CHANGED = Symbol("agent-ref-changed");
|
|
1221
|
+
var AGENT_NEED_FETCH = Symbol("agent-need-fetch");
|
|
1203
1222
|
/**
|
|
1204
1223
|
* ClientSwarm class implements the ISwarm interface and manages agents within a swarm.
|
|
1205
1224
|
*/
|
|
@@ -1212,6 +1231,7 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1212
1231
|
var _this = this;
|
|
1213
1232
|
this.params = params;
|
|
1214
1233
|
this._agentChangedSubject = new Subject();
|
|
1234
|
+
this._activeAgent = AGENT_NEED_FETCH;
|
|
1215
1235
|
/**
|
|
1216
1236
|
* Waits for output from the active agent.
|
|
1217
1237
|
* @returns {Promise<string>} - The output from the active agent.
|
|
@@ -1238,13 +1258,13 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1238
1258
|
case 0:
|
|
1239
1259
|
_c = [agentName];
|
|
1240
1260
|
return [4 /*yield*/, agent.waitForOutput()];
|
|
1241
|
-
case 1: return [2 /*return*/, _c.concat([
|
|
1242
|
-
_e.sent()
|
|
1243
|
-
])];
|
|
1261
|
+
case 1: return [2 /*return*/, _c.concat([_e.sent()])];
|
|
1244
1262
|
}
|
|
1245
1263
|
});
|
|
1246
1264
|
}); })), false), [
|
|
1247
|
-
this._agentChangedSubject
|
|
1265
|
+
this._agentChangedSubject
|
|
1266
|
+
.toPromise()
|
|
1267
|
+
.then(function () { return [AGENT_REF_CHANGED]; }),
|
|
1248
1268
|
], false))];
|
|
1249
1269
|
case 2:
|
|
1250
1270
|
_a = __read.apply(void 0, [_c.sent(), 2]), agentName = _a[0], output = _a[1];
|
|
@@ -1267,9 +1287,19 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1267
1287
|
* @returns {Promise<AgentName>} - The name of the active agent.
|
|
1268
1288
|
*/
|
|
1269
1289
|
this.getAgentName = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1290
|
+
var _a;
|
|
1291
|
+
return __generator(this, function (_b) {
|
|
1292
|
+
switch (_b.label) {
|
|
1293
|
+
case 0:
|
|
1294
|
+
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " getAgentName"));
|
|
1295
|
+
if (!(this._activeAgent === AGENT_NEED_FETCH)) return [3 /*break*/, 2];
|
|
1296
|
+
_a = this;
|
|
1297
|
+
return [4 /*yield*/, GLOBAL_CONFIG.CC_SWARM_DEFAULT_AGENT(this.params.clientId, this.params.swarmName, this.params.defaultAgent)];
|
|
1298
|
+
case 1:
|
|
1299
|
+
_a._activeAgent = _b.sent();
|
|
1300
|
+
_b.label = 2;
|
|
1301
|
+
case 2: return [2 /*return*/, this._activeAgent];
|
|
1302
|
+
}
|
|
1273
1303
|
});
|
|
1274
1304
|
}); };
|
|
1275
1305
|
/**
|
|
@@ -1317,15 +1347,20 @@ var ClientSwarm = /** @class */ (function () {
|
|
|
1317
1347
|
*/
|
|
1318
1348
|
this.setAgentName = function (agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
1319
1349
|
return __generator(this, function (_a) {
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1350
|
+
switch (_a.label) {
|
|
1351
|
+
case 0:
|
|
1352
|
+
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " setAgentName agentName=").concat(agentName));
|
|
1353
|
+
this._activeAgent = agentName;
|
|
1354
|
+
return [4 /*yield*/, this.params.onAgentChanged(this.params.clientId, agentName, this.params.swarmName)];
|
|
1355
|
+
case 1:
|
|
1356
|
+
_a.sent();
|
|
1357
|
+
return [2 /*return*/];
|
|
1358
|
+
}
|
|
1323
1359
|
});
|
|
1324
1360
|
}); };
|
|
1325
1361
|
this.params.logger.debug("ClientSwarm swarmName=".concat(this.params.swarmName, " clientId=").concat(this.params.clientId, " CTOR"), {
|
|
1326
1362
|
params: params,
|
|
1327
1363
|
});
|
|
1328
|
-
this._activeAgent = params.defaultAgent;
|
|
1329
1364
|
}
|
|
1330
1365
|
return ClientSwarm;
|
|
1331
1366
|
}());
|
|
@@ -1373,6 +1408,18 @@ var SwarmConnectionService = /** @class */ (function () {
|
|
|
1373
1408
|
defaultAgent: defaultAgent,
|
|
1374
1409
|
swarmName: swarmName,
|
|
1375
1410
|
logger: _this.loggerService,
|
|
1411
|
+
onAgentChanged: function (clientId, agentName, swarmName) {
|
|
1412
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1413
|
+
return __generator(this, function (_a) {
|
|
1414
|
+
switch (_a.label) {
|
|
1415
|
+
case 0: return [4 /*yield*/, GLOBAL_CONFIG.CC_SWARM_AGENT_CHANGED(clientId, agentName, swarmName)];
|
|
1416
|
+
case 1:
|
|
1417
|
+
_a.sent();
|
|
1418
|
+
return [2 /*return*/];
|
|
1419
|
+
}
|
|
1420
|
+
});
|
|
1421
|
+
});
|
|
1422
|
+
},
|
|
1376
1423
|
});
|
|
1377
1424
|
});
|
|
1378
1425
|
/**
|
|
@@ -4076,4 +4123,56 @@ var getAssistantHistory = function (clientId) { return __awaiter(void 0, void 0,
|
|
|
4076
4123
|
});
|
|
4077
4124
|
}); };
|
|
4078
4125
|
|
|
4079
|
-
|
|
4126
|
+
/**
|
|
4127
|
+
* Retrieves the last message sent by the assistant from the client's message history.
|
|
4128
|
+
*
|
|
4129
|
+
* @param {string} clientId - The ID of the client whose message history is being retrieved.
|
|
4130
|
+
* @returns {Promise<string | null>} - The content of the last assistant message, or null if no user message is found.
|
|
4131
|
+
*/
|
|
4132
|
+
var getLastAssistantMessage = function (clientId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
4133
|
+
var history, last;
|
|
4134
|
+
return __generator(this, function (_a) {
|
|
4135
|
+
switch (_a.label) {
|
|
4136
|
+
case 0:
|
|
4137
|
+
swarm.loggerService.log("function getLastAssistantMessage", {
|
|
4138
|
+
clientId: clientId,
|
|
4139
|
+
});
|
|
4140
|
+
return [4 /*yield*/, getRawHistory(clientId)];
|
|
4141
|
+
case 1:
|
|
4142
|
+
history = _a.sent();
|
|
4143
|
+
last = history.findLast(function (_a) {
|
|
4144
|
+
var role = _a.role;
|
|
4145
|
+
return role === "assistant";
|
|
4146
|
+
});
|
|
4147
|
+
return [2 /*return*/, last ? last.content : null];
|
|
4148
|
+
}
|
|
4149
|
+
});
|
|
4150
|
+
}); };
|
|
4151
|
+
|
|
4152
|
+
/**
|
|
4153
|
+
* Retrieves the last message sent by the system from the client's message history.
|
|
4154
|
+
*
|
|
4155
|
+
* @param {string} clientId - The ID of the client whose message history is being retrieved.
|
|
4156
|
+
* @returns {Promise<string | null>} - The content of the last system message, or null if no user message is found.
|
|
4157
|
+
*/
|
|
4158
|
+
var getLastSystemMessage = function (clientId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
4159
|
+
var history, last;
|
|
4160
|
+
return __generator(this, function (_a) {
|
|
4161
|
+
switch (_a.label) {
|
|
4162
|
+
case 0:
|
|
4163
|
+
swarm.loggerService.log("function getLastSystemMessage", {
|
|
4164
|
+
clientId: clientId,
|
|
4165
|
+
});
|
|
4166
|
+
return [4 /*yield*/, getRawHistory(clientId)];
|
|
4167
|
+
case 1:
|
|
4168
|
+
history = _a.sent();
|
|
4169
|
+
last = history.findLast(function (_a) {
|
|
4170
|
+
var role = _a.role;
|
|
4171
|
+
return role === "system";
|
|
4172
|
+
});
|
|
4173
|
+
return [2 /*return*/, last ? last.content : null];
|
|
4174
|
+
}
|
|
4175
|
+
});
|
|
4176
|
+
}); };
|
|
4177
|
+
|
|
4178
|
+
export { ContextService, addAgent, addCompletion, addSwarm, addTool, changeAgent, commitSystemMessage, commitToolOutput, commitUserMessage, complete, disposeConnection, emit, execute, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getUserHistory, makeConnection, session, setConfig, swarm };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-swarm-kit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
4
4
|
"description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Petr Tripolsky",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "rollup -c",
|
|
41
41
|
"test": "npm run build && node ./test/index.mjs",
|
|
42
|
+
"benchmark": "npm run build && node ./benchmark/index.mjs",
|
|
42
43
|
"build:docs": "rimraf docs && mkdir docs && node ./scripts/dts-docs.cjs ./types.d.ts ./docs",
|
|
43
44
|
"docs:gpt": "npm run build && node ./scripts/gpt-docs.mjs",
|
|
44
45
|
"repl": "dotenv -e .env -- npm run build && node -e \"import('./scripts/repl.mjs')\" --interactive"
|
package/types.d.ts
CHANGED
|
@@ -340,6 +340,8 @@ interface ISwarmParams extends Omit<ISwarmSchema, keyof {
|
|
|
340
340
|
logger: ILogger;
|
|
341
341
|
/** Map of agent names to agent instances */
|
|
342
342
|
agentMap: Record<AgentName, IAgent>;
|
|
343
|
+
/** Emit the callback on agent change */
|
|
344
|
+
onAgentChanged(clientId: string, agentName: AgentName, swarmName: SwarmName): Promise<void>;
|
|
343
345
|
}
|
|
344
346
|
/**
|
|
345
347
|
* Schema for defining a swarm.
|
|
@@ -1727,13 +1729,31 @@ declare const getUserHistory: (clientId: string) => Promise<IModelMessage[]>;
|
|
|
1727
1729
|
*/
|
|
1728
1730
|
declare const getAssistantHistory: (clientId: string) => Promise<IModelMessage[]>;
|
|
1729
1731
|
|
|
1732
|
+
/**
|
|
1733
|
+
* Retrieves the last message sent by the assistant from the client's message history.
|
|
1734
|
+
*
|
|
1735
|
+
* @param {string} clientId - The ID of the client whose message history is being retrieved.
|
|
1736
|
+
* @returns {Promise<string | null>} - The content of the last assistant message, or null if no user message is found.
|
|
1737
|
+
*/
|
|
1738
|
+
declare const getLastAssistantMessage: (clientId: string) => Promise<string>;
|
|
1739
|
+
|
|
1740
|
+
/**
|
|
1741
|
+
* Retrieves the last message sent by the system from the client's message history.
|
|
1742
|
+
*
|
|
1743
|
+
* @param {string} clientId - The ID of the client whose message history is being retrieved.
|
|
1744
|
+
* @returns {Promise<string | null>} - The content of the last system message, or null if no user message is found.
|
|
1745
|
+
*/
|
|
1746
|
+
declare const getLastSystemMessage: (clientId: string) => Promise<string>;
|
|
1747
|
+
|
|
1730
1748
|
declare const GLOBAL_CONFIG: {
|
|
1731
1749
|
CC_TOOL_CALL_EXCEPTION_PROMPT: string;
|
|
1732
1750
|
CC_EMPTY_OUTPUT_PLACEHOLDERS: string[];
|
|
1733
1751
|
CC_KEEP_MESSAGES: number;
|
|
1734
1752
|
CC_ANSWER_TIMEOUT_SECONDS: number;
|
|
1735
1753
|
CC_GET_AGENT_HISTORY: (clientId: string, agentName: AgentName) => IPubsubArray<IModelMessage>;
|
|
1754
|
+
CC_SWARM_AGENT_CHANGED: (clientId: string, agentName: AgentName, swarmName: SwarmName) => Promise<void>;
|
|
1755
|
+
CC_SWARM_DEFAULT_AGENT: (clientId: string, swarmName: SwarmName, defaultAgent: AgentName) => Promise<AgentName>;
|
|
1736
1756
|
};
|
|
1737
1757
|
declare const setConfig: (config: typeof GLOBAL_CONFIG) => void;
|
|
1738
1758
|
|
|
1739
|
-
export { ContextService, type IAgentSchema, type IAgentTool, type ICompletionSchema, type IIncomingMessage, type IModelMessage, type IOutgoingMessage, type ISwarmSchema, type ITool, type IToolCall, type ReceiveMessageFn, type SendMessageFn$1 as SendMessageFn, addAgent, addCompletion, addSwarm, addTool, changeAgent, commitSystemMessage, commitToolOutput, commitUserMessage, complete, disposeConnection, emit, execute, getAgentHistory, getAgentName, getAssistantHistory, getLastUserMessage, getRawHistory, getUserHistory, makeConnection, session, setConfig, swarm };
|
|
1759
|
+
export { ContextService, type IAgentSchema, type IAgentTool, type ICompletionSchema, type IIncomingMessage, type IModelMessage, type IOutgoingMessage, type ISwarmSchema, type ITool, type IToolCall, type ReceiveMessageFn, type SendMessageFn$1 as SendMessageFn, addAgent, addCompletion, addSwarm, addTool, changeAgent, commitSystemMessage, commitToolOutput, commitUserMessage, complete, disposeConnection, emit, execute, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getUserHistory, makeConnection, session, setConfig, swarm };
|