agent-swarm-kit 1.0.39 → 1.0.40

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 CHANGED
@@ -700,6 +700,7 @@ var ClientAgent = /** @class */ (function () {
700
700
  this.execute = functoolsKit.queued(function (incoming, mode) { return __awaiter(_this, void 0, void 0, function () {
701
701
  var message, toolCalls, _loop_1, this_1, toolCalls_1, toolCalls_1_1, tool, state_1, e_1_1, result, validation, result1;
702
702
  var e_1, _a;
703
+ var _this = this;
703
704
  var _b, _c, _d, _e, _f, _g;
704
705
  return __generator(this, function (_h) {
705
706
  switch (_h.label) {
@@ -763,12 +764,16 @@ var ClientAgent = /** @class */ (function () {
763
764
  _j.sent();
764
765
  return [2 /*return*/, { value: void 0 }];
765
766
  case 7:
766
- ((_e = targetFn.callbacks) === null || _e === void 0 ? void 0 : _e.onCall) &&
767
- ((_f = targetFn.callbacks) === null || _f === void 0 ? void 0 : _f.onCall(this_1.params.clientId, this_1.params.agentName, tool.function.arguments));
767
+ ((_e = targetFn.callbacks) === null || _e === void 0 ? void 0 : _e.onBeforeCall) &&
768
+ ((_f = targetFn.callbacks) === null || _f === void 0 ? void 0 : _f.onBeforeCall(tool.id, this_1.params.clientId, this_1.params.agentName, tool.function.arguments));
768
769
  /**
769
770
  * @description Do not await to avoid deadlock! The tool can send the message to other agents by emulating user messages
770
771
  */
771
- targetFn.call(tool.id, this_1.params.clientId, this_1.params.agentName, tool.function.arguments);
772
+ Promise.resolve(targetFn.call(tool.id, this_1.params.clientId, this_1.params.agentName, tool.function.arguments)).then(function () {
773
+ var _a, _b;
774
+ ((_a = targetFn.callbacks) === null || _a === void 0 ? void 0 : _a.onAfterCall) &&
775
+ ((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onAfterCall(tool.id, _this.params.clientId, _this.params.agentName, tool.function.arguments));
776
+ });
772
777
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool call executing"));
773
778
  return [4 /*yield*/, Promise.race([
774
779
  this_1._toolCommitSubject.toPromise(),
package/build/index.mjs CHANGED
@@ -698,6 +698,7 @@ var ClientAgent = /** @class */ (function () {
698
698
  this.execute = queued(function (incoming, mode) { return __awaiter(_this, void 0, void 0, function () {
699
699
  var message, toolCalls, _loop_1, this_1, toolCalls_1, toolCalls_1_1, tool, state_1, e_1_1, result, validation, result1;
700
700
  var e_1, _a;
701
+ var _this = this;
701
702
  var _b, _c, _d, _e, _f, _g;
702
703
  return __generator(this, function (_h) {
703
704
  switch (_h.label) {
@@ -761,12 +762,16 @@ var ClientAgent = /** @class */ (function () {
761
762
  _j.sent();
762
763
  return [2 /*return*/, { value: void 0 }];
763
764
  case 7:
764
- ((_e = targetFn.callbacks) === null || _e === void 0 ? void 0 : _e.onCall) &&
765
- ((_f = targetFn.callbacks) === null || _f === void 0 ? void 0 : _f.onCall(this_1.params.clientId, this_1.params.agentName, tool.function.arguments));
765
+ ((_e = targetFn.callbacks) === null || _e === void 0 ? void 0 : _e.onBeforeCall) &&
766
+ ((_f = targetFn.callbacks) === null || _f === void 0 ? void 0 : _f.onBeforeCall(tool.id, this_1.params.clientId, this_1.params.agentName, tool.function.arguments));
766
767
  /**
767
768
  * @description Do not await to avoid deadlock! The tool can send the message to other agents by emulating user messages
768
769
  */
769
- targetFn.call(tool.id, this_1.params.clientId, this_1.params.agentName, tool.function.arguments);
770
+ Promise.resolve(targetFn.call(tool.id, this_1.params.clientId, this_1.params.agentName, tool.function.arguments)).then(function () {
771
+ var _a, _b;
772
+ ((_a = targetFn.callbacks) === null || _a === void 0 ? void 0 : _a.onAfterCall) &&
773
+ ((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onAfterCall(tool.id, _this.params.clientId, _this.params.agentName, tool.function.arguments));
774
+ });
770
775
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool call executing"));
771
776
  return [4 /*yield*/, Promise.race([
772
777
  this_1._toolCommitSubject.toPromise(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.39",
3
+ "version": "1.0.40",
4
4
  "description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
package/types.d.ts CHANGED
@@ -497,13 +497,23 @@ type CompletionName = string;
497
497
  */
498
498
  interface IAgentToolCallbacks<T = Record<string, unknown>> {
499
499
  /**
500
- * Callback triggered when the tool is called.
500
+ * Callback triggered before the tool is called.
501
+ * @param toolId - The `tool_call_id` for openai history
501
502
  * @param clientId - The ID of the client.
502
503
  * @param agentName - The name of the agent.
503
504
  * @param params - The parameters for the tool.
504
505
  * @returns A promise that resolves when the tool call is complete.
505
506
  */
506
- onCall?: (clientId: string, agentName: AgentName, params: T) => Promise<void>;
507
+ onBeforeCall?: (toolId: string, clientId: string, agentName: AgentName, params: T) => Promise<void>;
508
+ /**
509
+ * Callback triggered after the tool is called.
510
+ * @param toolId - The `tool_call_id` for openai history
511
+ * @param clientId - The ID of the client.
512
+ * @param agentName - The name of the agent.
513
+ * @param params - The parameters for the tool.
514
+ * @returns A promise that resolves when the tool call is complete.
515
+ */
516
+ onAfterCall?: (toolId: string, clientId: string, agentName: AgentName, params: T) => Promise<void>;
507
517
  /**
508
518
  * Callback triggered when the tool parameters are validated.
509
519
  * @param clientId - The ID of the client.
@@ -522,6 +532,7 @@ interface IAgentTool<T = Record<string, unknown>> extends ITool {
522
532
  toolName: ToolName;
523
533
  /**
524
534
  * Calls the tool with the specified parameters.
535
+ * @param toolId - The `tool_call_id` for openai history
525
536
  * @param clientId - The ID of the client.
526
537
  * @param agentName - The name of the agent.
527
538
  * @param params - The parameters for the tool.