agent-swarm-kit 1.1.136 → 1.1.138

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
@@ -4613,6 +4613,12 @@ class ClientAgent {
4613
4613
  clientId: this.params.clientId,
4614
4614
  });
4615
4615
  }
4616
+ /**
4617
+ * Commits a developer message to the history, notifying the system via BusService without triggering execution.
4618
+ * Useful for logging developer notes or debugging information, coordinated with SessionConnectionService.
4619
+ * @param {string} message - The developer message to commit, trimmed before storage.
4620
+ * @returns {Promise<void>} Resolves when the message is committed and the event is emitted.
4621
+ */
4616
4622
  async commitDeveloperMessage(message) {
4617
4623
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
4618
4624
  this.params.logger.debug(`ClientAgent agentName=${this.params.agentName} clientId=${this.params.clientId} commitDeveloperMessage`, { message });
@@ -6356,7 +6362,6 @@ class ToolSchemaService {
6356
6362
 
6357
6363
  const AGENT_NEED_FETCH = Symbol("agent-need-fetch");
6358
6364
  const STACK_NEED_FETCH = Symbol("stack-need-fetch");
6359
- const SET_BUSY_FN = Symbol("set-busy-fn");
6360
6365
  /**
6361
6366
  * A no-operation (noop) agent that serves as a fallback when an agent is not found in the swarm.
6362
6367
  * Implements the {@link IAgent} interface and logs calls to its methods, indicating that the requested agent is unavailable,
@@ -6557,7 +6562,6 @@ class NoopAgent {
6557
6562
  const WAIT_FOR_OUTPUT_FN = async (self) => {
6558
6563
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
6559
6564
  self.params.logger.debug(`ClientSwarm swarmName=${self.params.swarmName} clientId=${self.params.clientId} waitForOutput`);
6560
- self[SET_BUSY_FN](true);
6561
6565
  const [awaiter, { resolve }] = functoolsKit.createAwaiter();
6562
6566
  const getOutput = functoolsKit.cancelable(async () => await Promise.race(self._agentList
6563
6567
  .map(async ([agentName, agent]) => ({
@@ -6595,7 +6599,6 @@ const WAIT_FOR_OUTPUT_FN = async (self) => {
6595
6599
  },
6596
6600
  clientId: self.params.clientId,
6597
6601
  });
6598
- self[SET_BUSY_FN](false);
6599
6602
  return output;
6600
6603
  };
6601
6604
  /**
@@ -6616,7 +6619,7 @@ class ClientSwarm {
6616
6619
  getCheckBusy() {
6617
6620
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
6618
6621
  this.params.logger.debug(`ClientSwarm swarmName=${this.params.swarmName} clientId=${this.params.clientId} getCheckBusy`);
6619
- return Promise.resolve(this._isBusy);
6622
+ return Promise.resolve(!!this._isBusy);
6620
6623
  }
6621
6624
  /**
6622
6625
  * Sets the busy state of the swarm.
@@ -6624,10 +6627,10 @@ class ClientSwarm {
6624
6627
  * Enables coordinated state management and debugging.
6625
6628
  * @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
6626
6629
  */
6627
- [SET_BUSY_FN](isBusy) {
6630
+ setBusy(isBusy) {
6628
6631
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
6629
- this.params.logger.debug(`ClientSwarm swarmName=${this.params.swarmName} clientId=${this.params.clientId} setCheckBusy`, { isBusy });
6630
- this._isBusy = isBusy;
6632
+ this.params.logger.debug(`ClientSwarm swarmName=${this.params.swarmName} clientId=${this.params.clientId} setBusy`, { isBusy });
6633
+ this._isBusy += isBusy ? 1 : -1;
6631
6634
  }
6632
6635
  /**
6633
6636
  * Getter for the list of agent name-agent pairs from the agent map (params.agentMap).
@@ -6644,7 +6647,7 @@ class ClientSwarm {
6644
6647
  */
6645
6648
  constructor(params) {
6646
6649
  this.params = params;
6647
- this._isBusy = false;
6650
+ this._isBusy = 0;
6648
6651
  /**
6649
6652
  * Subject that emits when an agent reference changes, providing the agent name and instance.
6650
6653
  * Used by setAgentRef to notify subscribers (e.g., waitForOutput) of updates to agent instances.
@@ -7005,6 +7008,19 @@ class SwarmConnectionService {
7005
7008
  this.loggerService.info(`swarmConnectionService getCheckBusy`);
7006
7009
  return await this.getSwarm(this.methodContextService.context.clientId, this.methodContextService.context.swarmName).getCheckBusy();
7007
7010
  };
7011
+ /**
7012
+ * Sets the busy state of the swarm.
7013
+ * Used to indicate whether the swarm is currently processing an operation, helping manage flow control and debugging.
7014
+ * Delegates to ClientSwarm.setBusy, using context from MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.
7015
+ * Mirrors SwarmPublicService’s setBusy, supporting ClientAgent’s busy state management.
7016
+ * @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
7017
+ * @returns {Promise<void>} A promise resolving when the busy state is set.
7018
+ */
7019
+ this.setBusy = async (isBusy) => {
7020
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7021
+ this.loggerService.info(`swarmConnectionService setBusy`, { isBusy });
7022
+ return await this.getSwarm(this.methodContextService.context.clientId, this.methodContextService.context.swarmName).setBusy(isBusy);
7023
+ };
7008
7024
  /**
7009
7025
  * Cancels the pending output by emitting an empty string, interrupting waitForOutput.
7010
7026
  * Delegates to ClientSwarm.cancelOutput, using context from MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.
@@ -7471,9 +7487,11 @@ class ClientSession {
7471
7487
  this.params.onExecute &&
7472
7488
  this.params.onExecute(this.params.clientId, this.params.swarmName, message, mode);
7473
7489
  const agent = await this.params.swarm.getAgent();
7490
+ this.params.swarm.setBusy(true);
7474
7491
  const outputAwaiter = this.params.swarm.waitForOutput();
7475
7492
  agent.execute(message, mode);
7476
7493
  const output = await outputAwaiter;
7494
+ this.params.swarm.setBusy(false);
7477
7495
  await swarm$1.executionValidationService.flushCount(this.params.clientId, this.params.swarmName);
7478
7496
  if (await functoolsKit.not(this.params.policy.validateOutput(output, this.params.clientId, this.params.swarmName))) {
7479
7497
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
@@ -9687,6 +9705,37 @@ class SwarmPublicService {
9687
9705
  computeName: "",
9688
9706
  });
9689
9707
  };
9708
+ /**
9709
+ * Sets the busy state of the swarm, indicating whether it is currently processing an operation.
9710
+ * Wraps SwarmConnectionService.setBusy with MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.
9711
+ * Used in ClientAgent (e.g., marking swarm busy during EXECUTE_FN) and SessionPublicService (e.g., managing swarm state in connect).
9712
+ * @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
9713
+ * @param {string} methodName - The method name for context and logging.
9714
+ * @param {string} clientId - The client ID, scoping the operation to a specific client.
9715
+ * @param {SwarmName} swarmName - The name of the swarm, used in SwarmMetaService context.
9716
+ * @returns {Promise<void>} A promise resolving when the busy state is set.
9717
+ */
9718
+ this.setBusy = async (isBusy, methodName, clientId, swarmName) => {
9719
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
9720
+ this.loggerService.info("swarmPublicService setBusy", {
9721
+ isBusy,
9722
+ clientId,
9723
+ swarmName,
9724
+ });
9725
+ return await MethodContextService.runInContext(async () => {
9726
+ return await this.swarmConnectionService.setBusy(isBusy);
9727
+ }, {
9728
+ methodName,
9729
+ clientId,
9730
+ swarmName,
9731
+ policyName: "",
9732
+ agentName: "",
9733
+ storageName: "",
9734
+ stateName: "",
9735
+ mcpName: "",
9736
+ computeName: "",
9737
+ });
9738
+ };
9690
9739
  /**
9691
9740
  * Cancels the await of output in the swarm by emitting an empty string, scoped to a client.
9692
9741
  * Wraps SwarmConnectionService.cancelOutput with MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.
package/build/index.mjs CHANGED
@@ -4611,6 +4611,12 @@ class ClientAgent {
4611
4611
  clientId: this.params.clientId,
4612
4612
  });
4613
4613
  }
4614
+ /**
4615
+ * Commits a developer message to the history, notifying the system via BusService without triggering execution.
4616
+ * Useful for logging developer notes or debugging information, coordinated with SessionConnectionService.
4617
+ * @param {string} message - The developer message to commit, trimmed before storage.
4618
+ * @returns {Promise<void>} Resolves when the message is committed and the event is emitted.
4619
+ */
4614
4620
  async commitDeveloperMessage(message) {
4615
4621
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
4616
4622
  this.params.logger.debug(`ClientAgent agentName=${this.params.agentName} clientId=${this.params.clientId} commitDeveloperMessage`, { message });
@@ -6354,7 +6360,6 @@ class ToolSchemaService {
6354
6360
 
6355
6361
  const AGENT_NEED_FETCH = Symbol("agent-need-fetch");
6356
6362
  const STACK_NEED_FETCH = Symbol("stack-need-fetch");
6357
- const SET_BUSY_FN = Symbol("set-busy-fn");
6358
6363
  /**
6359
6364
  * A no-operation (noop) agent that serves as a fallback when an agent is not found in the swarm.
6360
6365
  * Implements the {@link IAgent} interface and logs calls to its methods, indicating that the requested agent is unavailable,
@@ -6555,7 +6560,6 @@ class NoopAgent {
6555
6560
  const WAIT_FOR_OUTPUT_FN = async (self) => {
6556
6561
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
6557
6562
  self.params.logger.debug(`ClientSwarm swarmName=${self.params.swarmName} clientId=${self.params.clientId} waitForOutput`);
6558
- self[SET_BUSY_FN](true);
6559
6563
  const [awaiter, { resolve }] = createAwaiter();
6560
6564
  const getOutput = cancelable(async () => await Promise.race(self._agentList
6561
6565
  .map(async ([agentName, agent]) => ({
@@ -6593,7 +6597,6 @@ const WAIT_FOR_OUTPUT_FN = async (self) => {
6593
6597
  },
6594
6598
  clientId: self.params.clientId,
6595
6599
  });
6596
- self[SET_BUSY_FN](false);
6597
6600
  return output;
6598
6601
  };
6599
6602
  /**
@@ -6614,7 +6617,7 @@ class ClientSwarm {
6614
6617
  getCheckBusy() {
6615
6618
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
6616
6619
  this.params.logger.debug(`ClientSwarm swarmName=${this.params.swarmName} clientId=${this.params.clientId} getCheckBusy`);
6617
- return Promise.resolve(this._isBusy);
6620
+ return Promise.resolve(!!this._isBusy);
6618
6621
  }
6619
6622
  /**
6620
6623
  * Sets the busy state of the swarm.
@@ -6622,10 +6625,10 @@ class ClientSwarm {
6622
6625
  * Enables coordinated state management and debugging.
6623
6626
  * @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
6624
6627
  */
6625
- [SET_BUSY_FN](isBusy) {
6628
+ setBusy(isBusy) {
6626
6629
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
6627
- this.params.logger.debug(`ClientSwarm swarmName=${this.params.swarmName} clientId=${this.params.clientId} setCheckBusy`, { isBusy });
6628
- this._isBusy = isBusy;
6630
+ this.params.logger.debug(`ClientSwarm swarmName=${this.params.swarmName} clientId=${this.params.clientId} setBusy`, { isBusy });
6631
+ this._isBusy += isBusy ? 1 : -1;
6629
6632
  }
6630
6633
  /**
6631
6634
  * Getter for the list of agent name-agent pairs from the agent map (params.agentMap).
@@ -6642,7 +6645,7 @@ class ClientSwarm {
6642
6645
  */
6643
6646
  constructor(params) {
6644
6647
  this.params = params;
6645
- this._isBusy = false;
6648
+ this._isBusy = 0;
6646
6649
  /**
6647
6650
  * Subject that emits when an agent reference changes, providing the agent name and instance.
6648
6651
  * Used by setAgentRef to notify subscribers (e.g., waitForOutput) of updates to agent instances.
@@ -7003,6 +7006,19 @@ class SwarmConnectionService {
7003
7006
  this.loggerService.info(`swarmConnectionService getCheckBusy`);
7004
7007
  return await this.getSwarm(this.methodContextService.context.clientId, this.methodContextService.context.swarmName).getCheckBusy();
7005
7008
  };
7009
+ /**
7010
+ * Sets the busy state of the swarm.
7011
+ * Used to indicate whether the swarm is currently processing an operation, helping manage flow control and debugging.
7012
+ * Delegates to ClientSwarm.setBusy, using context from MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.
7013
+ * Mirrors SwarmPublicService’s setBusy, supporting ClientAgent’s busy state management.
7014
+ * @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
7015
+ * @returns {Promise<void>} A promise resolving when the busy state is set.
7016
+ */
7017
+ this.setBusy = async (isBusy) => {
7018
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
7019
+ this.loggerService.info(`swarmConnectionService setBusy`, { isBusy });
7020
+ return await this.getSwarm(this.methodContextService.context.clientId, this.methodContextService.context.swarmName).setBusy(isBusy);
7021
+ };
7006
7022
  /**
7007
7023
  * Cancels the pending output by emitting an empty string, interrupting waitForOutput.
7008
7024
  * Delegates to ClientSwarm.cancelOutput, using context from MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.
@@ -7469,9 +7485,11 @@ class ClientSession {
7469
7485
  this.params.onExecute &&
7470
7486
  this.params.onExecute(this.params.clientId, this.params.swarmName, message, mode);
7471
7487
  const agent = await this.params.swarm.getAgent();
7488
+ this.params.swarm.setBusy(true);
7472
7489
  const outputAwaiter = this.params.swarm.waitForOutput();
7473
7490
  agent.execute(message, mode);
7474
7491
  const output = await outputAwaiter;
7492
+ this.params.swarm.setBusy(false);
7475
7493
  await swarm$1.executionValidationService.flushCount(this.params.clientId, this.params.swarmName);
7476
7494
  if (await not(this.params.policy.validateOutput(output, this.params.clientId, this.params.swarmName))) {
7477
7495
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
@@ -9685,6 +9703,37 @@ class SwarmPublicService {
9685
9703
  computeName: "",
9686
9704
  });
9687
9705
  };
9706
+ /**
9707
+ * Sets the busy state of the swarm, indicating whether it is currently processing an operation.
9708
+ * Wraps SwarmConnectionService.setBusy with MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.
9709
+ * Used in ClientAgent (e.g., marking swarm busy during EXECUTE_FN) and SessionPublicService (e.g., managing swarm state in connect).
9710
+ * @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
9711
+ * @param {string} methodName - The method name for context and logging.
9712
+ * @param {string} clientId - The client ID, scoping the operation to a specific client.
9713
+ * @param {SwarmName} swarmName - The name of the swarm, used in SwarmMetaService context.
9714
+ * @returns {Promise<void>} A promise resolving when the busy state is set.
9715
+ */
9716
+ this.setBusy = async (isBusy, methodName, clientId, swarmName) => {
9717
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
9718
+ this.loggerService.info("swarmPublicService setBusy", {
9719
+ isBusy,
9720
+ clientId,
9721
+ swarmName,
9722
+ });
9723
+ return await MethodContextService.runInContext(async () => {
9724
+ return await this.swarmConnectionService.setBusy(isBusy);
9725
+ }, {
9726
+ methodName,
9727
+ clientId,
9728
+ swarmName,
9729
+ policyName: "",
9730
+ agentName: "",
9731
+ storageName: "",
9732
+ stateName: "",
9733
+ mcpName: "",
9734
+ computeName: "",
9735
+ });
9736
+ };
9688
9737
  /**
9689
9738
  * Cancels the await of output in the swarm by emitting an empty string, scoped to a client.
9690
9739
  * Wraps SwarmConnectionService.cancelOutput with MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.1.136",
3
+ "version": "1.1.138",
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
@@ -1330,6 +1330,14 @@ interface ISwarm {
1330
1330
  * @returns {Promise<boolean>} True if the swarm is busy, false otherwise.
1331
1331
  */
1332
1332
  getCheckBusy(): Promise<boolean>;
1333
+ /**
1334
+ * Sets the busy state of the swarm.
1335
+ * This method is used to indicate whether the swarm is currently processing an operation.
1336
+ * It helps manage flow control and debugging by signaling when the swarm is occupied.
1337
+ * @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
1338
+ * @throws {Error} If setting the busy state fails (e.g., due to internal errors).
1339
+ */
1340
+ setBusy(isBusy: boolean): void;
1333
1341
  }
1334
1342
  /**
1335
1343
  * Type representing the unique name of a swarm within the system.
@@ -4576,6 +4584,12 @@ declare class ClientAgent implements IAgent {
4576
4584
  * @returns {Promise<void>} Resolves when the message is committed and the event is emitted.
4577
4585
  */
4578
4586
  commitSystemMessage(message: string): Promise<void>;
4587
+ /**
4588
+ * Commits a developer message to the history, notifying the system via BusService without triggering execution.
4589
+ * Useful for logging developer notes or debugging information, coordinated with SessionConnectionService.
4590
+ * @param {string} message - The developer message to commit, trimmed before storage.
4591
+ * @returns {Promise<void>} Resolves when the message is committed and the event is emitted.
4592
+ */
4579
4593
  commitDeveloperMessage(message: string): Promise<void>;
4580
4594
  /**
4581
4595
  * Commits a tool request to the agent's history and emits an event via BusService.
@@ -5428,7 +5442,6 @@ declare class ToolSchemaService {
5428
5442
 
5429
5443
  declare const AGENT_NEED_FETCH: unique symbol;
5430
5444
  declare const STACK_NEED_FETCH: unique symbol;
5431
- declare const SET_BUSY_FN: unique symbol;
5432
5445
  /**
5433
5446
  * Manages a collection of agents within a swarm in the swarm system, implementing the ISwarm interface.
5434
5447
  * Handles agent switching, output waiting, and navigation stack management, with queued operations and event-driven updates via BusService.
@@ -5453,7 +5466,7 @@ declare class ClientSwarm implements ISwarm {
5453
5466
  * Enables coordinated state management and debugging.
5454
5467
  * @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
5455
5468
  */
5456
- [SET_BUSY_FN](isBusy: boolean): void;
5469
+ setBusy(isBusy: boolean): void;
5457
5470
  /**
5458
5471
  * Subject that emits when an agent reference changes, providing the agent name and instance.
5459
5472
  * Used by setAgentRef to notify subscribers (e.g., waitForOutput) of updates to agent instances.
@@ -5643,6 +5656,15 @@ declare class SwarmConnectionService implements ISwarm {
5643
5656
  * @returns {Promise<boolean>} True if the swarm is busy, false otherwise.
5644
5657
  */
5645
5658
  getCheckBusy: () => Promise<boolean>;
5659
+ /**
5660
+ * Sets the busy state of the swarm.
5661
+ * Used to indicate whether the swarm is currently processing an operation, helping manage flow control and debugging.
5662
+ * Delegates to ClientSwarm.setBusy, using context from MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.
5663
+ * Mirrors SwarmPublicService’s setBusy, supporting ClientAgent’s busy state management.
5664
+ * @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
5665
+ * @returns {Promise<void>} A promise resolving when the busy state is set.
5666
+ */
5667
+ setBusy: (isBusy: boolean) => Promise<void>;
5646
5668
  /**
5647
5669
  * Cancels the pending output by emitting an empty string, interrupting waitForOutput.
5648
5670
  * Delegates to ClientSwarm.cancelOutput, using context from MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.
@@ -6777,6 +6799,17 @@ declare class SwarmPublicService implements TSwarmConnectionService {
6777
6799
  * @returns {Promise<boolean>} True if the swarm is busy, false otherwise.
6778
6800
  */
6779
6801
  getCheckBusy: (methodName: string, clientId: string, swarmName: SwarmName) => Promise<boolean>;
6802
+ /**
6803
+ * Sets the busy state of the swarm, indicating whether it is currently processing an operation.
6804
+ * Wraps SwarmConnectionService.setBusy with MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.
6805
+ * Used in ClientAgent (e.g., marking swarm busy during EXECUTE_FN) and SessionPublicService (e.g., managing swarm state in connect).
6806
+ * @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
6807
+ * @param {string} methodName - The method name for context and logging.
6808
+ * @param {string} clientId - The client ID, scoping the operation to a specific client.
6809
+ * @param {SwarmName} swarmName - The name of the swarm, used in SwarmMetaService context.
6810
+ * @returns {Promise<void>} A promise resolving when the busy state is set.
6811
+ */
6812
+ setBusy: (isBusy: boolean, methodName: string, clientId: string, swarmName: SwarmName) => Promise<void>;
6780
6813
  /**
6781
6814
  * Cancels the await of output in the swarm by emitting an empty string, scoped to a client.
6782
6815
  * Wraps SwarmConnectionService.cancelOutput with MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.