agent-swarm-kit 1.1.94 → 1.1.97

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
@@ -7346,6 +7346,7 @@ class ClientSession {
7346
7346
  const outputAwaiter = this.params.swarm.waitForOutput();
7347
7347
  agent.execute(message, mode);
7348
7348
  const output = await outputAwaiter;
7349
+ await swarm$1.executionValidationService.flushCount(this.params.clientId, this.params.swarmName);
7349
7350
  if (await functoolsKit.not(this.params.policy.validateOutput(output, this.params.clientId, this.params.swarmName))) {
7350
7351
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
7351
7352
  this.params.logger.debug(`ClientSession clientId=${this.params.clientId} execution output emit canceled due to the banhammer of a client`, {
@@ -7610,6 +7611,7 @@ class ClientSession {
7610
7611
  clientId: this.params.clientId,
7611
7612
  });
7612
7613
  this._notifySubject.subscribe(async (data) => {
7614
+ await swarm$1.executionValidationService.flushCount(this.params.clientId, this.params.swarmName);
7613
7615
  await connector({
7614
7616
  data,
7615
7617
  agentName: await this.params.swarm.getAgentName(),
@@ -7620,6 +7622,7 @@ class ClientSession {
7620
7622
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
7621
7623
  this.params.logger.debug(`ClientSession clientId=${this.params.clientId} connect call`);
7622
7624
  const data = await this.execute(incoming.data, "user");
7625
+ await swarm$1.executionValidationService.flushCount(this.params.clientId, this.params.swarmName);
7623
7626
  if (!data) {
7624
7627
  return "";
7625
7628
  }
@@ -17796,7 +17799,10 @@ class ExecutionValidationService {
17796
17799
  * @param {SwarmName} swarmName - The name of the swarm associated with the client.
17797
17800
  * @returns {Set<ExecutionId>} A set containing execution IDs for the client and swarm.
17798
17801
  */
17799
- this.getExecutionCount = functoolsKit.memoize(([clientId, swarmName]) => `${clientId}-${swarmName}`, () => new Set());
17802
+ this.getExecutionCount = functoolsKit.memoize(([clientId, swarmName]) => `${clientId}-${swarmName}`, () => ({
17803
+ executionSet: new Set(),
17804
+ executionIgnore: new functoolsKit.LimitedSet(GLOBAL_CONFIG.CC_MAX_NESTED_EXECUTIONS),
17805
+ }));
17800
17806
  /**
17801
17807
  * Increments the execution count for a client and checks for excessive nested executions.
17802
17808
  * @param {string} executionId - The unique identifier for the execution.
@@ -17815,7 +17821,11 @@ class ExecutionValidationService {
17815
17821
  return;
17816
17822
  }
17817
17823
  const swarmName = this.sessionValidationService.getSwarm(clientId);
17818
- const executionSet = this.getExecutionCount(clientId, swarmName).add(executionId);
17824
+ const { executionSet, executionIgnore } = this.getExecutionCount(clientId, swarmName);
17825
+ if (!executionIgnore.has(executionId)) {
17826
+ executionSet.add(executionId);
17827
+ executionIgnore.add(executionId);
17828
+ }
17819
17829
  if (executionSet.size >= GLOBAL_CONFIG.CC_MAX_NESTED_EXECUTIONS) {
17820
17830
  const ids = [...executionSet].join(",");
17821
17831
  const msg = `agent-swarm recursive execution prevented for clientId=${clientId} swarmName=${swarmName} executionId=${executionId} size=${executionSet.size} ids=${ids}`;
@@ -17840,7 +17850,30 @@ class ExecutionValidationService {
17840
17850
  if (!this.sessionValidationService.hasSession(clientId)) {
17841
17851
  return;
17842
17852
  }
17843
- this.getExecutionCount(clientId, swarmName).delete(executionId);
17853
+ const { executionSet, executionIgnore } = this.getExecutionCount(clientId, swarmName);
17854
+ executionSet.delete(executionId);
17855
+ executionIgnore.add(executionId);
17856
+ };
17857
+ /**
17858
+ * Clears all tracked execution IDs for a specific client and swarm.
17859
+ * This effectively resets the execution count for the given client and swarm context,
17860
+ * but does not remove the memoized entry itself.
17861
+ *
17862
+ * @param {string} clientId - The unique identifier for the client.
17863
+ * @param {SwarmName} swarmName - The name of the swarm associated with the client.
17864
+ * @returns {void}
17865
+ */
17866
+ this.flushCount = (clientId, swarmName) => {
17867
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
17868
+ this.loggerService.info("executionValidationService dispose", {
17869
+ clientId,
17870
+ swarmName,
17871
+ });
17872
+ if (!this.sessionValidationService.hasSession(clientId)) {
17873
+ return;
17874
+ }
17875
+ const { executionSet } = this.getExecutionCount(clientId, swarmName);
17876
+ executionSet.clear();
17844
17877
  };
17845
17878
  /**
17846
17879
  * Clears the memoized execution count for a specific client and swarm.
package/build/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { scoped } from 'di-scoped';
2
2
  import { createActivator } from 'di-kit';
3
- import { trycatch, makeExtendable, singleshot, getErrorMessage, not, queued, memoize, retry, Subject, str, randomString, ToolRegistry, createAwaiter, sleep, errorData, isObject as isObject$1, cancelable, CANCELED_PROMISE_SYMBOL, SortedArray, execpool, ttl, compose, Source, and, singlerun, schedule, rate } from 'functools-kit';
3
+ import { trycatch, makeExtendable, singleshot, getErrorMessage, not, queued, memoize, retry, Subject, str, randomString, ToolRegistry, createAwaiter, sleep, errorData, isObject as isObject$1, cancelable, CANCELED_PROMISE_SYMBOL, SortedArray, execpool, ttl, compose, LimitedSet, Source, and, singlerun, schedule, rate } from 'functools-kit';
4
4
  import xml2js from 'xml2js';
5
5
  import fs, { access, mkdir } from 'fs/promises';
6
6
  import path, { join } from 'path';
@@ -7344,6 +7344,7 @@ class ClientSession {
7344
7344
  const outputAwaiter = this.params.swarm.waitForOutput();
7345
7345
  agent.execute(message, mode);
7346
7346
  const output = await outputAwaiter;
7347
+ await swarm$1.executionValidationService.flushCount(this.params.clientId, this.params.swarmName);
7347
7348
  if (await not(this.params.policy.validateOutput(output, this.params.clientId, this.params.swarmName))) {
7348
7349
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
7349
7350
  this.params.logger.debug(`ClientSession clientId=${this.params.clientId} execution output emit canceled due to the banhammer of a client`, {
@@ -7608,6 +7609,7 @@ class ClientSession {
7608
7609
  clientId: this.params.clientId,
7609
7610
  });
7610
7611
  this._notifySubject.subscribe(async (data) => {
7612
+ await swarm$1.executionValidationService.flushCount(this.params.clientId, this.params.swarmName);
7611
7613
  await connector({
7612
7614
  data,
7613
7615
  agentName: await this.params.swarm.getAgentName(),
@@ -7618,6 +7620,7 @@ class ClientSession {
7618
7620
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
7619
7621
  this.params.logger.debug(`ClientSession clientId=${this.params.clientId} connect call`);
7620
7622
  const data = await this.execute(incoming.data, "user");
7623
+ await swarm$1.executionValidationService.flushCount(this.params.clientId, this.params.swarmName);
7621
7624
  if (!data) {
7622
7625
  return "";
7623
7626
  }
@@ -17794,7 +17797,10 @@ class ExecutionValidationService {
17794
17797
  * @param {SwarmName} swarmName - The name of the swarm associated with the client.
17795
17798
  * @returns {Set<ExecutionId>} A set containing execution IDs for the client and swarm.
17796
17799
  */
17797
- this.getExecutionCount = memoize(([clientId, swarmName]) => `${clientId}-${swarmName}`, () => new Set());
17800
+ this.getExecutionCount = memoize(([clientId, swarmName]) => `${clientId}-${swarmName}`, () => ({
17801
+ executionSet: new Set(),
17802
+ executionIgnore: new LimitedSet(GLOBAL_CONFIG.CC_MAX_NESTED_EXECUTIONS),
17803
+ }));
17798
17804
  /**
17799
17805
  * Increments the execution count for a client and checks for excessive nested executions.
17800
17806
  * @param {string} executionId - The unique identifier for the execution.
@@ -17813,7 +17819,11 @@ class ExecutionValidationService {
17813
17819
  return;
17814
17820
  }
17815
17821
  const swarmName = this.sessionValidationService.getSwarm(clientId);
17816
- const executionSet = this.getExecutionCount(clientId, swarmName).add(executionId);
17822
+ const { executionSet, executionIgnore } = this.getExecutionCount(clientId, swarmName);
17823
+ if (!executionIgnore.has(executionId)) {
17824
+ executionSet.add(executionId);
17825
+ executionIgnore.add(executionId);
17826
+ }
17817
17827
  if (executionSet.size >= GLOBAL_CONFIG.CC_MAX_NESTED_EXECUTIONS) {
17818
17828
  const ids = [...executionSet].join(",");
17819
17829
  const msg = `agent-swarm recursive execution prevented for clientId=${clientId} swarmName=${swarmName} executionId=${executionId} size=${executionSet.size} ids=${ids}`;
@@ -17838,7 +17848,30 @@ class ExecutionValidationService {
17838
17848
  if (!this.sessionValidationService.hasSession(clientId)) {
17839
17849
  return;
17840
17850
  }
17841
- this.getExecutionCount(clientId, swarmName).delete(executionId);
17851
+ const { executionSet, executionIgnore } = this.getExecutionCount(clientId, swarmName);
17852
+ executionSet.delete(executionId);
17853
+ executionIgnore.add(executionId);
17854
+ };
17855
+ /**
17856
+ * Clears all tracked execution IDs for a specific client and swarm.
17857
+ * This effectively resets the execution count for the given client and swarm context,
17858
+ * but does not remove the memoized entry itself.
17859
+ *
17860
+ * @param {string} clientId - The unique identifier for the client.
17861
+ * @param {SwarmName} swarmName - The name of the swarm associated with the client.
17862
+ * @returns {void}
17863
+ */
17864
+ this.flushCount = (clientId, swarmName) => {
17865
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
17866
+ this.loggerService.info("executionValidationService dispose", {
17867
+ clientId,
17868
+ swarmName,
17869
+ });
17870
+ if (!this.sessionValidationService.hasSession(clientId)) {
17871
+ return;
17872
+ }
17873
+ const { executionSet } = this.getExecutionCount(clientId, swarmName);
17874
+ executionSet.clear();
17842
17875
  };
17843
17876
  /**
17844
17877
  * Clears the memoized execution count for a specific client and swarm.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.1.94",
3
+ "version": "1.1.97",
4
4
  "description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
@@ -81,7 +81,7 @@
81
81
  "dependencies": {
82
82
  "di-kit": "^1.0.18",
83
83
  "di-scoped": "^1.0.20",
84
- "functools-kit": "^1.0.82",
84
+ "functools-kit": "^1.0.85",
85
85
  "get-moment-stamp": "^1.1.1",
86
86
  "lodash-es": "4.17.21",
87
87
  "xml2js": "0.6.2"
package/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as functools_kit from 'functools-kit';
2
- import { SortedArray, TSubject, Subject, ToolRegistry } from 'functools-kit';
2
+ import { SortedArray, TSubject, Subject, ToolRegistry, LimitedSet } from 'functools-kit';
3
3
  import * as di_scoped from 'di-scoped';
4
4
 
5
5
  /**
@@ -10641,7 +10641,13 @@ declare class ExecutionValidationService {
10641
10641
  * @param {SwarmName} swarmName - The name of the swarm associated with the client.
10642
10642
  * @returns {Set<ExecutionId>} A set containing execution IDs for the client and swarm.
10643
10643
  */
10644
- getExecutionCount: ((clientId: string, swarmName: SwarmName) => Set<ExecutionId>) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, Set<string>>;
10644
+ getExecutionCount: ((clientId: string, swarmName: SwarmName) => {
10645
+ executionSet: Set<ExecutionId>;
10646
+ executionIgnore: LimitedSet<ExecutionId>;
10647
+ }) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, {
10648
+ executionSet: Set<ExecutionId>;
10649
+ executionIgnore: LimitedSet<ExecutionId>;
10650
+ }>;
10645
10651
  /**
10646
10652
  * Increments the execution count for a client and checks for excessive nested executions.
10647
10653
  * @param {string} executionId - The unique identifier for the execution.
@@ -10659,6 +10665,16 @@ declare class ExecutionValidationService {
10659
10665
  * @returns {void}
10660
10666
  */
10661
10667
  decrementCount: (executionId: string, clientId: string, swarmName: SwarmName) => void;
10668
+ /**
10669
+ * Clears all tracked execution IDs for a specific client and swarm.
10670
+ * This effectively resets the execution count for the given client and swarm context,
10671
+ * but does not remove the memoized entry itself.
10672
+ *
10673
+ * @param {string} clientId - The unique identifier for the client.
10674
+ * @param {SwarmName} swarmName - The name of the swarm associated with the client.
10675
+ * @returns {void}
10676
+ */
10677
+ flushCount: (clientId: string, swarmName: SwarmName) => void;
10662
10678
  /**
10663
10679
  * Clears the memoized execution count for a specific client and swarm.
10664
10680
  * @param {string} clientId - The unique identifier for the client.