agent-swarm-kit 1.1.139 → 1.1.141
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 +35 -2
- package/build/index.mjs +35 -2
- package/package.json +1 -1
- package/types.d.ts +9 -0
package/build/index.cjs
CHANGED
|
@@ -6632,6 +6632,18 @@ class ClientSwarm {
|
|
|
6632
6632
|
this.params.logger.debug(`ClientSwarm swarmName=${this.params.swarmName} clientId=${this.params.clientId} setBusy`, { isBusy });
|
|
6633
6633
|
this._isBusy += isBusy ? 1 : -1;
|
|
6634
6634
|
}
|
|
6635
|
+
/**
|
|
6636
|
+
* Getter for the busy state of the swarm.
|
|
6637
|
+
* Used internally for optimizing performance and flow control.
|
|
6638
|
+
* Returns true if the swarm is currently busy with an operation, false otherwise.
|
|
6639
|
+
* Supports debugging and flow control in client applications.
|
|
6640
|
+
* @returns {boolean} True if the swarm is busy, false otherwise.
|
|
6641
|
+
*/
|
|
6642
|
+
getBusy() {
|
|
6643
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
6644
|
+
this.params.logger.debug(`ClientSwarm swarmName=${this.params.swarmName} clientId=${this.params.clientId} getBusy`);
|
|
6645
|
+
return !!this._isBusy;
|
|
6646
|
+
}
|
|
6635
6647
|
/**
|
|
6636
6648
|
* Getter for the list of agent name-agent pairs from the agent map (params.agentMap).
|
|
6637
6649
|
* Provides a snapshot of available agents, used internally by waitForOutput to monitor outputs.
|
|
@@ -7381,6 +7393,22 @@ class CompletionSchemaService {
|
|
|
7381
7393
|
}
|
|
7382
7394
|
}
|
|
7383
7395
|
|
|
7396
|
+
const BUSY_DELAY = 100;
|
|
7397
|
+
const AQUIRE_LOCK_FN = async (self) => {
|
|
7398
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
7399
|
+
self.params.logger.debug(`ClientSession clientId=${self.params.clientId} AQUIRE_LOCK_FN`);
|
|
7400
|
+
const swarm = self.params.swarm;
|
|
7401
|
+
while (swarm.getBusy()) {
|
|
7402
|
+
await functoolsKit.sleep(BUSY_DELAY);
|
|
7403
|
+
}
|
|
7404
|
+
swarm.setBusy(true);
|
|
7405
|
+
};
|
|
7406
|
+
const RELEASE_LOCK_FN = async (self) => {
|
|
7407
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
7408
|
+
self.params.logger.debug(`ClientSession clientId=${self.params.clientId} RELEASE_LOCK_FN`);
|
|
7409
|
+
const swarm = self.params.swarm;
|
|
7410
|
+
swarm.setBusy(false);
|
|
7411
|
+
};
|
|
7384
7412
|
/**
|
|
7385
7413
|
* Represents a client session in the swarm system, implementing the ISession interface.
|
|
7386
7414
|
* Manages message execution, emission, and agent interactions for a client within a swarm, with policy enforcement via ClientPolicy
|
|
@@ -7398,6 +7426,7 @@ class ClientSession {
|
|
|
7398
7426
|
constructor(params) {
|
|
7399
7427
|
this.params = params;
|
|
7400
7428
|
this._notifySubject = new functoolsKit.Subject();
|
|
7429
|
+
this.AQUIRE_LOCK = functoolsKit.queued(AQUIRE_LOCK_FN);
|
|
7401
7430
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
7402
7431
|
this.params.logger.debug(`ClientSession clientId=${this.params.clientId} CTOR`, {
|
|
7403
7432
|
params,
|
|
@@ -7487,7 +7516,9 @@ class ClientSession {
|
|
|
7487
7516
|
this.params.onExecute &&
|
|
7488
7517
|
this.params.onExecute(this.params.clientId, this.params.swarmName, message, mode);
|
|
7489
7518
|
const agent = await this.params.swarm.getAgent();
|
|
7490
|
-
|
|
7519
|
+
if (mode === "user") {
|
|
7520
|
+
await this.AQUIRE_LOCK(this);
|
|
7521
|
+
}
|
|
7491
7522
|
const outputAwaiter = this.params.swarm.waitForOutput();
|
|
7492
7523
|
agent.execute(message, mode);
|
|
7493
7524
|
let output = "";
|
|
@@ -7495,7 +7526,9 @@ class ClientSession {
|
|
|
7495
7526
|
output = await outputAwaiter;
|
|
7496
7527
|
}
|
|
7497
7528
|
finally {
|
|
7498
|
-
|
|
7529
|
+
if (mode === "user") {
|
|
7530
|
+
await RELEASE_LOCK_FN(this);
|
|
7531
|
+
}
|
|
7499
7532
|
}
|
|
7500
7533
|
await swarm$1.executionValidationService.flushCount(this.params.clientId, this.params.swarmName);
|
|
7501
7534
|
if (await functoolsKit.not(this.params.policy.validateOutput(output, this.params.clientId, this.params.swarmName))) {
|
package/build/index.mjs
CHANGED
|
@@ -6630,6 +6630,18 @@ class ClientSwarm {
|
|
|
6630
6630
|
this.params.logger.debug(`ClientSwarm swarmName=${this.params.swarmName} clientId=${this.params.clientId} setBusy`, { isBusy });
|
|
6631
6631
|
this._isBusy += isBusy ? 1 : -1;
|
|
6632
6632
|
}
|
|
6633
|
+
/**
|
|
6634
|
+
* Getter for the busy state of the swarm.
|
|
6635
|
+
* Used internally for optimizing performance and flow control.
|
|
6636
|
+
* Returns true if the swarm is currently busy with an operation, false otherwise.
|
|
6637
|
+
* Supports debugging and flow control in client applications.
|
|
6638
|
+
* @returns {boolean} True if the swarm is busy, false otherwise.
|
|
6639
|
+
*/
|
|
6640
|
+
getBusy() {
|
|
6641
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
6642
|
+
this.params.logger.debug(`ClientSwarm swarmName=${this.params.swarmName} clientId=${this.params.clientId} getBusy`);
|
|
6643
|
+
return !!this._isBusy;
|
|
6644
|
+
}
|
|
6633
6645
|
/**
|
|
6634
6646
|
* Getter for the list of agent name-agent pairs from the agent map (params.agentMap).
|
|
6635
6647
|
* Provides a snapshot of available agents, used internally by waitForOutput to monitor outputs.
|
|
@@ -7379,6 +7391,22 @@ class CompletionSchemaService {
|
|
|
7379
7391
|
}
|
|
7380
7392
|
}
|
|
7381
7393
|
|
|
7394
|
+
const BUSY_DELAY = 100;
|
|
7395
|
+
const AQUIRE_LOCK_FN = async (self) => {
|
|
7396
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
7397
|
+
self.params.logger.debug(`ClientSession clientId=${self.params.clientId} AQUIRE_LOCK_FN`);
|
|
7398
|
+
const swarm = self.params.swarm;
|
|
7399
|
+
while (swarm.getBusy()) {
|
|
7400
|
+
await sleep(BUSY_DELAY);
|
|
7401
|
+
}
|
|
7402
|
+
swarm.setBusy(true);
|
|
7403
|
+
};
|
|
7404
|
+
const RELEASE_LOCK_FN = async (self) => {
|
|
7405
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
7406
|
+
self.params.logger.debug(`ClientSession clientId=${self.params.clientId} RELEASE_LOCK_FN`);
|
|
7407
|
+
const swarm = self.params.swarm;
|
|
7408
|
+
swarm.setBusy(false);
|
|
7409
|
+
};
|
|
7382
7410
|
/**
|
|
7383
7411
|
* Represents a client session in the swarm system, implementing the ISession interface.
|
|
7384
7412
|
* Manages message execution, emission, and agent interactions for a client within a swarm, with policy enforcement via ClientPolicy
|
|
@@ -7396,6 +7424,7 @@ class ClientSession {
|
|
|
7396
7424
|
constructor(params) {
|
|
7397
7425
|
this.params = params;
|
|
7398
7426
|
this._notifySubject = new Subject();
|
|
7427
|
+
this.AQUIRE_LOCK = queued(AQUIRE_LOCK_FN);
|
|
7399
7428
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
7400
7429
|
this.params.logger.debug(`ClientSession clientId=${this.params.clientId} CTOR`, {
|
|
7401
7430
|
params,
|
|
@@ -7485,7 +7514,9 @@ class ClientSession {
|
|
|
7485
7514
|
this.params.onExecute &&
|
|
7486
7515
|
this.params.onExecute(this.params.clientId, this.params.swarmName, message, mode);
|
|
7487
7516
|
const agent = await this.params.swarm.getAgent();
|
|
7488
|
-
|
|
7517
|
+
if (mode === "user") {
|
|
7518
|
+
await this.AQUIRE_LOCK(this);
|
|
7519
|
+
}
|
|
7489
7520
|
const outputAwaiter = this.params.swarm.waitForOutput();
|
|
7490
7521
|
agent.execute(message, mode);
|
|
7491
7522
|
let output = "";
|
|
@@ -7493,7 +7524,9 @@ class ClientSession {
|
|
|
7493
7524
|
output = await outputAwaiter;
|
|
7494
7525
|
}
|
|
7495
7526
|
finally {
|
|
7496
|
-
|
|
7527
|
+
if (mode === "user") {
|
|
7528
|
+
await RELEASE_LOCK_FN(this);
|
|
7529
|
+
}
|
|
7497
7530
|
}
|
|
7498
7531
|
await swarm$1.executionValidationService.flushCount(this.params.clientId, this.params.swarmName);
|
|
7499
7532
|
if (await not(this.params.policy.validateOutput(output, this.params.clientId, this.params.swarmName))) {
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -5467,6 +5467,14 @@ declare class ClientSwarm implements ISwarm {
|
|
|
5467
5467
|
* @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
|
|
5468
5468
|
*/
|
|
5469
5469
|
setBusy(isBusy: boolean): void;
|
|
5470
|
+
/**
|
|
5471
|
+
* Getter for the busy state of the swarm.
|
|
5472
|
+
* Used internally for optimizing performance and flow control.
|
|
5473
|
+
* Returns true if the swarm is currently busy with an operation, false otherwise.
|
|
5474
|
+
* Supports debugging and flow control in client applications.
|
|
5475
|
+
* @returns {boolean} True if the swarm is busy, false otherwise.
|
|
5476
|
+
*/
|
|
5477
|
+
getBusy(): boolean;
|
|
5470
5478
|
/**
|
|
5471
5479
|
* Subject that emits when an agent reference changes, providing the agent name and instance.
|
|
5472
5480
|
* Used by setAgentRef to notify subscribers (e.g., waitForOutput) of updates to agent instances.
|
|
@@ -5900,6 +5908,7 @@ declare class CompletionSchemaService {
|
|
|
5900
5908
|
declare class ClientSession implements ISession {
|
|
5901
5909
|
readonly params: ISessionParams;
|
|
5902
5910
|
private _notifySubject;
|
|
5911
|
+
private AQUIRE_LOCK;
|
|
5903
5912
|
/**
|
|
5904
5913
|
* Constructs a new ClientSession instance with the provided parameters.
|
|
5905
5914
|
* Invokes the onInit callback if defined and logs construction if debugging is enabled.
|