agent-swarm-kit 1.0.44 → 1.0.46
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 +39 -4
- package/build/index.mjs +39 -4
- package/package.json +1 -1
- package/types.d.ts +14 -2
package/build/index.cjs
CHANGED
|
@@ -34,6 +34,18 @@ var __assign = function() {
|
|
|
34
34
|
return __assign.apply(this, arguments);
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
function __rest(s, e) {
|
|
38
|
+
var t = {};
|
|
39
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
40
|
+
t[p] = s[p];
|
|
41
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
42
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
43
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
44
|
+
t[p[i]] = s[p[i]];
|
|
45
|
+
}
|
|
46
|
+
return t;
|
|
47
|
+
}
|
|
48
|
+
|
|
37
49
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
38
50
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
39
51
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -768,7 +780,12 @@ var ClientAgent = /** @class */ (function () {
|
|
|
768
780
|
case 3:
|
|
769
781
|
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onValidate) &&
|
|
770
782
|
((_c = targetFn.callbacks) === null || _c === void 0 ? void 0 : _c.onValidate(this_1.params.clientId, this_1.params.agentName, tool.function.arguments));
|
|
771
|
-
return [4 /*yield*/, functoolsKit.not(targetFn.validate(
|
|
783
|
+
return [4 /*yield*/, functoolsKit.not(targetFn.validate({
|
|
784
|
+
clientId: this_1.params.clientId,
|
|
785
|
+
agentName: this_1.params.agentName,
|
|
786
|
+
params: tool.function.arguments,
|
|
787
|
+
toolCalls: toolCalls,
|
|
788
|
+
}))];
|
|
772
789
|
case 4:
|
|
773
790
|
if (!_h.sent()) return [3 /*break*/, 7];
|
|
774
791
|
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"));
|
|
@@ -786,7 +803,14 @@ var ClientAgent = /** @class */ (function () {
|
|
|
786
803
|
/**
|
|
787
804
|
* @description Do not await to avoid deadlock! The tool can send the message to other agents by emulating user messages
|
|
788
805
|
*/
|
|
789
|
-
Promise.resolve(targetFn.call(
|
|
806
|
+
Promise.resolve(targetFn.call({
|
|
807
|
+
toolId: tool.id,
|
|
808
|
+
clientId: this_1.params.clientId,
|
|
809
|
+
agentName: this_1.params.agentName,
|
|
810
|
+
params: tool.function.arguments,
|
|
811
|
+
isLast: idx === toolCalls.length - 1,
|
|
812
|
+
toolCalls: toolCalls,
|
|
813
|
+
})).then(function () {
|
|
790
814
|
var _a, _b;
|
|
791
815
|
((_a = targetFn.callbacks) === null || _a === void 0 ? void 0 : _a.onAfterCall) &&
|
|
792
816
|
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onAfterCall(tool.id, _this.params.clientId, _this.params.agentName, tool.function.arguments));
|
|
@@ -1117,7 +1141,7 @@ var ClientHistory = /** @class */ (function () {
|
|
|
1117
1141
|
* @returns {Promise<IModelMessage[]>} - The array of messages for the agent.
|
|
1118
1142
|
*/
|
|
1119
1143
|
this.toArrayForAgent = function (prompt, system) { return __awaiter(_this, void 0, void 0, function () {
|
|
1120
|
-
var commonMessagesRaw, systemMessagesRaw, _a, _b, _c, content, message, e_2_1, systemMessages, commonMessages, promptMessages;
|
|
1144
|
+
var commonMessagesRaw, systemMessagesRaw, _a, _b, _c, content, message, e_2_1, systemMessages, commonMessages, assistantToolCallSet, assistantMessages, promptMessages;
|
|
1121
1145
|
var _this = this;
|
|
1122
1146
|
var _d, e_2, _e, _f;
|
|
1123
1147
|
var _g;
|
|
@@ -1184,6 +1208,17 @@ var ClientHistory = /** @class */ (function () {
|
|
|
1184
1208
|
commonMessages = commonMessagesRaw
|
|
1185
1209
|
.filter(this._filterCondition)
|
|
1186
1210
|
.slice(-GLOBAL_CONFIG.CC_KEEP_MESSAGES);
|
|
1211
|
+
assistantToolCallSet = new Set(commonMessages.map(function (_a) {
|
|
1212
|
+
var tool_call_id = _a.tool_call_id;
|
|
1213
|
+
return tool_call_id;
|
|
1214
|
+
}));
|
|
1215
|
+
assistantMessages = commonMessages.map(function (_a) {
|
|
1216
|
+
var tool_calls = _a.tool_calls, message = __rest(_a, ["tool_calls"]);
|
|
1217
|
+
return (__assign(__assign({}, message), { tool_calls: tool_calls === null || tool_calls === void 0 ? void 0 : tool_calls.filter(function (_a) {
|
|
1218
|
+
var id = _a.id;
|
|
1219
|
+
return assistantToolCallSet.has(id);
|
|
1220
|
+
}) }));
|
|
1221
|
+
});
|
|
1187
1222
|
promptMessages = [];
|
|
1188
1223
|
{
|
|
1189
1224
|
promptMessages.push({
|
|
@@ -1209,7 +1244,7 @@ var ClientHistory = /** @class */ (function () {
|
|
|
1209
1244
|
});
|
|
1210
1245
|
});
|
|
1211
1246
|
}
|
|
1212
|
-
return [2 /*return*/, __spreadArray(__spreadArray(__spreadArray([], __read(promptMessages), false), __read(systemMessages), false), __read(
|
|
1247
|
+
return [2 /*return*/, __spreadArray(__spreadArray(__spreadArray([], __read(promptMessages), false), __read(systemMessages), false), __read(assistantMessages), false)];
|
|
1213
1248
|
}
|
|
1214
1249
|
});
|
|
1215
1250
|
}); };
|
package/build/index.mjs
CHANGED
|
@@ -32,6 +32,18 @@ var __assign = function() {
|
|
|
32
32
|
return __assign.apply(this, arguments);
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
function __rest(s, e) {
|
|
36
|
+
var t = {};
|
|
37
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
38
|
+
t[p] = s[p];
|
|
39
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
40
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
41
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
42
|
+
t[p[i]] = s[p[i]];
|
|
43
|
+
}
|
|
44
|
+
return t;
|
|
45
|
+
}
|
|
46
|
+
|
|
35
47
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
36
48
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
49
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -766,7 +778,12 @@ var ClientAgent = /** @class */ (function () {
|
|
|
766
778
|
case 3:
|
|
767
779
|
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onValidate) &&
|
|
768
780
|
((_c = targetFn.callbacks) === null || _c === void 0 ? void 0 : _c.onValidate(this_1.params.clientId, this_1.params.agentName, tool.function.arguments));
|
|
769
|
-
return [4 /*yield*/, not(targetFn.validate(
|
|
781
|
+
return [4 /*yield*/, not(targetFn.validate({
|
|
782
|
+
clientId: this_1.params.clientId,
|
|
783
|
+
agentName: this_1.params.agentName,
|
|
784
|
+
params: tool.function.arguments,
|
|
785
|
+
toolCalls: toolCalls,
|
|
786
|
+
}))];
|
|
770
787
|
case 4:
|
|
771
788
|
if (!_h.sent()) return [3 /*break*/, 7];
|
|
772
789
|
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"));
|
|
@@ -784,7 +801,14 @@ var ClientAgent = /** @class */ (function () {
|
|
|
784
801
|
/**
|
|
785
802
|
* @description Do not await to avoid deadlock! The tool can send the message to other agents by emulating user messages
|
|
786
803
|
*/
|
|
787
|
-
Promise.resolve(targetFn.call(
|
|
804
|
+
Promise.resolve(targetFn.call({
|
|
805
|
+
toolId: tool.id,
|
|
806
|
+
clientId: this_1.params.clientId,
|
|
807
|
+
agentName: this_1.params.agentName,
|
|
808
|
+
params: tool.function.arguments,
|
|
809
|
+
isLast: idx === toolCalls.length - 1,
|
|
810
|
+
toolCalls: toolCalls,
|
|
811
|
+
})).then(function () {
|
|
788
812
|
var _a, _b;
|
|
789
813
|
((_a = targetFn.callbacks) === null || _a === void 0 ? void 0 : _a.onAfterCall) &&
|
|
790
814
|
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onAfterCall(tool.id, _this.params.clientId, _this.params.agentName, tool.function.arguments));
|
|
@@ -1115,7 +1139,7 @@ var ClientHistory = /** @class */ (function () {
|
|
|
1115
1139
|
* @returns {Promise<IModelMessage[]>} - The array of messages for the agent.
|
|
1116
1140
|
*/
|
|
1117
1141
|
this.toArrayForAgent = function (prompt, system) { return __awaiter(_this, void 0, void 0, function () {
|
|
1118
|
-
var commonMessagesRaw, systemMessagesRaw, _a, _b, _c, content, message, e_2_1, systemMessages, commonMessages, promptMessages;
|
|
1142
|
+
var commonMessagesRaw, systemMessagesRaw, _a, _b, _c, content, message, e_2_1, systemMessages, commonMessages, assistantToolCallSet, assistantMessages, promptMessages;
|
|
1119
1143
|
var _this = this;
|
|
1120
1144
|
var _d, e_2, _e, _f;
|
|
1121
1145
|
var _g;
|
|
@@ -1182,6 +1206,17 @@ var ClientHistory = /** @class */ (function () {
|
|
|
1182
1206
|
commonMessages = commonMessagesRaw
|
|
1183
1207
|
.filter(this._filterCondition)
|
|
1184
1208
|
.slice(-GLOBAL_CONFIG.CC_KEEP_MESSAGES);
|
|
1209
|
+
assistantToolCallSet = new Set(commonMessages.map(function (_a) {
|
|
1210
|
+
var tool_call_id = _a.tool_call_id;
|
|
1211
|
+
return tool_call_id;
|
|
1212
|
+
}));
|
|
1213
|
+
assistantMessages = commonMessages.map(function (_a) {
|
|
1214
|
+
var tool_calls = _a.tool_calls, message = __rest(_a, ["tool_calls"]);
|
|
1215
|
+
return (__assign(__assign({}, message), { tool_calls: tool_calls === null || tool_calls === void 0 ? void 0 : tool_calls.filter(function (_a) {
|
|
1216
|
+
var id = _a.id;
|
|
1217
|
+
return assistantToolCallSet.has(id);
|
|
1218
|
+
}) }));
|
|
1219
|
+
});
|
|
1185
1220
|
promptMessages = [];
|
|
1186
1221
|
{
|
|
1187
1222
|
promptMessages.push({
|
|
@@ -1207,7 +1242,7 @@ var ClientHistory = /** @class */ (function () {
|
|
|
1207
1242
|
});
|
|
1208
1243
|
});
|
|
1209
1244
|
}
|
|
1210
|
-
return [2 /*return*/, __spreadArray(__spreadArray(__spreadArray([], __read(promptMessages), false), __read(systemMessages), false), __read(
|
|
1245
|
+
return [2 /*return*/, __spreadArray(__spreadArray(__spreadArray([], __read(promptMessages), false), __read(systemMessages), false), __read(assistantMessages), false)];
|
|
1211
1246
|
}
|
|
1212
1247
|
});
|
|
1213
1248
|
}); };
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -538,7 +538,14 @@ interface IAgentTool<T = Record<string, unknown>> extends ITool {
|
|
|
538
538
|
* @param params - The parameters for the tool.
|
|
539
539
|
* @returns A promise that resolves when the tool call is complete.
|
|
540
540
|
*/
|
|
541
|
-
call(
|
|
541
|
+
call(dto: {
|
|
542
|
+
toolId: string;
|
|
543
|
+
clientId: string;
|
|
544
|
+
agentName: AgentName;
|
|
545
|
+
params: T;
|
|
546
|
+
toolCalls: IToolCall[];
|
|
547
|
+
isLast: boolean;
|
|
548
|
+
}): Promise<void>;
|
|
542
549
|
/**
|
|
543
550
|
* Validates the parameters for the tool.
|
|
544
551
|
* @param clientId - The ID of the client.
|
|
@@ -546,7 +553,12 @@ interface IAgentTool<T = Record<string, unknown>> extends ITool {
|
|
|
546
553
|
* @param params - The parameters for the tool.
|
|
547
554
|
* @returns A promise that resolves to a boolean indicating whether the parameters are valid, or a boolean.
|
|
548
555
|
*/
|
|
549
|
-
validate(
|
|
556
|
+
validate(dto: {
|
|
557
|
+
clientId: string;
|
|
558
|
+
agentName: AgentName;
|
|
559
|
+
toolCalls: IToolCall[];
|
|
560
|
+
params: T;
|
|
561
|
+
}): Promise<boolean> | boolean;
|
|
550
562
|
/** The name of the tool. */
|
|
551
563
|
callbacks?: Partial<IAgentToolCallbacks>;
|
|
552
564
|
}
|