agent-swarm-kit 1.0.191 → 1.0.193

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
@@ -16630,84 +16630,43 @@ const METHOD_NAME_CALL = "RoundRobin.call";
16630
16630
  /** @private Constant for logging the create method in RoundRobin */
16631
16631
  const METHOD_NAME_CREATE = "RoundRobin.create";
16632
16632
  /**
16633
- * A generic RoundRobin implementation that distributes calls across a set of tokens
16634
- * using a factory function to create instances.
16635
- * @template T The type of instances created by the factory
16636
- * @template Token The type of tokens to cycle through
16637
- * @template A The type of arguments passed to the factory (extends any[])
16633
+ * A generic RoundRobin implementation that cycles through token-based instance creators.
16634
+ * @template T The type of instances created
16635
+ * @template Token The type of tokens
16636
+ * @template A The type of arguments (extends any[])
16638
16637
  */
16639
16638
  class RoundRobin {
16640
- /**
16641
- * Creates a new RoundRobin instance
16642
- * @private
16643
- * @param tokens - Array of tokens to cycle through
16644
- * @param factory - Function that creates instances given a token and arguments
16645
- * @throws {Error} If the tokens array is empty
16646
- */
16647
16639
  constructor(tokens, factory) {
16648
- if (tokens.length === 0) {
16649
- throw new Error("agent-swarm RoundRobin cannot be created with an empty tokens array");
16650
- }
16651
- this.tokens = tokens;
16652
- this.factory = factory;
16653
- this.instances = new Map();
16654
16640
  this.currentIndex = 0;
16641
+ this.tokens = tokens;
16642
+ this.instances = new Map(tokens.map((token) => [token, factory(token)]));
16655
16643
  }
16656
16644
  /**
16657
16645
  * Creates a RoundRobin function that cycles through tokens
16658
- * @template T The type of instances created by the factory
16659
- * @template Token The type of tokens to cycle through
16660
- * @template A The type of arguments passed to the factory
16661
- * @param tokens - Array of tokens to cycle through
16662
- * @param factory - Function that creates instances given a token and arguments
16663
- * @returns A function that returns the next instance in the rotation
16664
- * @throws {Error} If the tokens array is empty
16665
- * @example
16666
- * const rr = RoundRobin.create(['a', 'b'], (token) => ({ id: token }));
16667
- * const instance1 = rr(); // { id: 'a' }
16668
- * const instance2 = rr(); // { id: 'b' }
16669
16646
  * @example
16670
- * const rr2 = RoundRobin.create<number[]>([[1], [2]], (token) => token[0]);
16671
- * const num1 = rr2(); // 1
16672
- * const num2 = rr2(); // 2
16647
+ * const rr = RoundRobin.create(['a', 'b'], (t) => () => ({ id: t }));
16673
16648
  */
16674
16649
  static create(tokens, factory) {
16675
16650
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16676
16651
  swarm$1.loggerService.log(METHOD_NAME_CREATE, {
16677
16652
  tokenCount: tokens.length,
16678
16653
  });
16679
- const roundRobin = new RoundRobin(tokens.filter((value) => !!value), factory);
16680
- return (...args) => roundRobin.call(...args);
16654
+ return new RoundRobin(tokens, factory).call.bind(new RoundRobin(tokens, factory));
16681
16655
  }
16682
- /**
16683
- * Gets the next instance in the rotation, creating it if necessary
16684
- * @private
16685
- * @param args - Arguments to pass to the factory function
16686
- * @returns The next instance in the rotation
16687
- */
16688
16656
  call(...args) {
16689
- // Log the call
16690
16657
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16691
16658
  swarm$1.loggerService.log(METHOD_NAME_CALL, {
16692
16659
  currentIndex: this.currentIndex,
16693
16660
  tokenCount: this.tokens.length,
16694
16661
  });
16695
- // Get the current token
16696
- const token = this.tokens[this.currentIndex];
16697
- // Generate a map key (strings and symbols can be used directly, objects are stringified)
16698
- const key = typeof token === "object" && token !== null
16699
- ? JSON.stringify(token)
16700
- : token;
16701
- // Create instance if it doesn't exist
16702
- if (!this.instances.has(key)) {
16703
- const instance = this.factory(token, ...args);
16704
- this.instances.set(key, instance);
16662
+ if (!this.tokens.length) {
16663
+ throw new Error("agent-swarm RoundRobin requires non-empty tokens array");
16705
16664
  }
16706
- // Get the instance
16707
- const instance = this.instances.get(key);
16708
- // Update index for next call
16665
+ const token = this.tokens[this.currentIndex];
16666
+ const instance = this.instances.get(token);
16667
+ const value = instance(...args);
16709
16668
  this.currentIndex = (this.currentIndex + 1) % this.tokens.length;
16710
- return instance;
16669
+ return value;
16711
16670
  }
16712
16671
  }
16713
16672
 
package/build/index.mjs CHANGED
@@ -16628,84 +16628,43 @@ const METHOD_NAME_CALL = "RoundRobin.call";
16628
16628
  /** @private Constant for logging the create method in RoundRobin */
16629
16629
  const METHOD_NAME_CREATE = "RoundRobin.create";
16630
16630
  /**
16631
- * A generic RoundRobin implementation that distributes calls across a set of tokens
16632
- * using a factory function to create instances.
16633
- * @template T The type of instances created by the factory
16634
- * @template Token The type of tokens to cycle through
16635
- * @template A The type of arguments passed to the factory (extends any[])
16631
+ * A generic RoundRobin implementation that cycles through token-based instance creators.
16632
+ * @template T The type of instances created
16633
+ * @template Token The type of tokens
16634
+ * @template A The type of arguments (extends any[])
16636
16635
  */
16637
16636
  class RoundRobin {
16638
- /**
16639
- * Creates a new RoundRobin instance
16640
- * @private
16641
- * @param tokens - Array of tokens to cycle through
16642
- * @param factory - Function that creates instances given a token and arguments
16643
- * @throws {Error} If the tokens array is empty
16644
- */
16645
16637
  constructor(tokens, factory) {
16646
- if (tokens.length === 0) {
16647
- throw new Error("agent-swarm RoundRobin cannot be created with an empty tokens array");
16648
- }
16649
- this.tokens = tokens;
16650
- this.factory = factory;
16651
- this.instances = new Map();
16652
16638
  this.currentIndex = 0;
16639
+ this.tokens = tokens;
16640
+ this.instances = new Map(tokens.map((token) => [token, factory(token)]));
16653
16641
  }
16654
16642
  /**
16655
16643
  * Creates a RoundRobin function that cycles through tokens
16656
- * @template T The type of instances created by the factory
16657
- * @template Token The type of tokens to cycle through
16658
- * @template A The type of arguments passed to the factory
16659
- * @param tokens - Array of tokens to cycle through
16660
- * @param factory - Function that creates instances given a token and arguments
16661
- * @returns A function that returns the next instance in the rotation
16662
- * @throws {Error} If the tokens array is empty
16663
- * @example
16664
- * const rr = RoundRobin.create(['a', 'b'], (token) => ({ id: token }));
16665
- * const instance1 = rr(); // { id: 'a' }
16666
- * const instance2 = rr(); // { id: 'b' }
16667
16644
  * @example
16668
- * const rr2 = RoundRobin.create<number[]>([[1], [2]], (token) => token[0]);
16669
- * const num1 = rr2(); // 1
16670
- * const num2 = rr2(); // 2
16645
+ * const rr = RoundRobin.create(['a', 'b'], (t) => () => ({ id: t }));
16671
16646
  */
16672
16647
  static create(tokens, factory) {
16673
16648
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16674
16649
  swarm$1.loggerService.log(METHOD_NAME_CREATE, {
16675
16650
  tokenCount: tokens.length,
16676
16651
  });
16677
- const roundRobin = new RoundRobin(tokens.filter((value) => !!value), factory);
16678
- return (...args) => roundRobin.call(...args);
16652
+ return new RoundRobin(tokens, factory).call.bind(new RoundRobin(tokens, factory));
16679
16653
  }
16680
- /**
16681
- * Gets the next instance in the rotation, creating it if necessary
16682
- * @private
16683
- * @param args - Arguments to pass to the factory function
16684
- * @returns The next instance in the rotation
16685
- */
16686
16654
  call(...args) {
16687
- // Log the call
16688
16655
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16689
16656
  swarm$1.loggerService.log(METHOD_NAME_CALL, {
16690
16657
  currentIndex: this.currentIndex,
16691
16658
  tokenCount: this.tokens.length,
16692
16659
  });
16693
- // Get the current token
16694
- const token = this.tokens[this.currentIndex];
16695
- // Generate a map key (strings and symbols can be used directly, objects are stringified)
16696
- const key = typeof token === "object" && token !== null
16697
- ? JSON.stringify(token)
16698
- : token;
16699
- // Create instance if it doesn't exist
16700
- if (!this.instances.has(key)) {
16701
- const instance = this.factory(token, ...args);
16702
- this.instances.set(key, instance);
16660
+ if (!this.tokens.length) {
16661
+ throw new Error("agent-swarm RoundRobin requires non-empty tokens array");
16703
16662
  }
16704
- // Get the instance
16705
- const instance = this.instances.get(key);
16706
- // Update index for next call
16663
+ const token = this.tokens[this.currentIndex];
16664
+ const instance = this.instances.get(token);
16665
+ const value = instance(...args);
16707
16666
  this.currentIndex = (this.currentIndex + 1) % this.tokens.length;
16708
- return instance;
16667
+ return value;
16709
16668
  }
16710
16669
  }
16711
16670
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.191",
3
+ "version": "1.0.193",
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
@@ -10257,58 +10257,26 @@ declare const GLOBAL_CONFIG: IGlobalConfig;
10257
10257
  declare const setConfig: (config: Partial<IGlobalConfig>) => void;
10258
10258
 
10259
10259
  /**
10260
- * A generic RoundRobin implementation that distributes calls across a set of tokens
10261
- * using a factory function to create instances.
10262
- * @template T The type of instances created by the factory
10263
- * @template Token The type of tokens to cycle through
10264
- * @template A The type of arguments passed to the factory (extends any[])
10260
+ * A generic RoundRobin implementation that cycles through token-based instance creators.
10261
+ * @template T The type of instances created
10262
+ * @template Token The type of tokens
10263
+ * @template A The type of arguments (extends any[])
10265
10264
  */
10266
10265
  declare class RoundRobin<T, Token = string | symbol | {
10267
10266
  [key: string]: any;
10268
10267
  }, A extends any[] = any[]> {
10269
- /** @private Array of tokens to cycle through */
10270
10268
  private tokens;
10271
- /** @private Factory function that creates instances from tokens and arguments */
10272
- private factory;
10273
- /** @private Map storing created instances with string or symbol keys */
10274
10269
  private instances;
10275
- /** @private Current index position in the token rotation */
10276
10270
  private currentIndex;
10277
- /**
10278
- * Creates a new RoundRobin instance
10279
- * @private
10280
- * @param tokens - Array of tokens to cycle through
10281
- * @param factory - Function that creates instances given a token and arguments
10282
- * @throws {Error} If the tokens array is empty
10283
- */
10284
10271
  private constructor();
10285
10272
  /**
10286
10273
  * Creates a RoundRobin function that cycles through tokens
10287
- * @template T The type of instances created by the factory
10288
- * @template Token The type of tokens to cycle through
10289
- * @template A The type of arguments passed to the factory
10290
- * @param tokens - Array of tokens to cycle through
10291
- * @param factory - Function that creates instances given a token and arguments
10292
- * @returns A function that returns the next instance in the rotation
10293
- * @throws {Error} If the tokens array is empty
10294
- * @example
10295
- * const rr = RoundRobin.create(['a', 'b'], (token) => ({ id: token }));
10296
- * const instance1 = rr(); // { id: 'a' }
10297
- * const instance2 = rr(); // { id: 'b' }
10298
10274
  * @example
10299
- * const rr2 = RoundRobin.create<number[]>([[1], [2]], (token) => token[0]);
10300
- * const num1 = rr2(); // 1
10301
- * const num2 = rr2(); // 2
10275
+ * const rr = RoundRobin.create(['a', 'b'], (t) => () => ({ id: t }));
10302
10276
  */
10303
10277
  static create<T, Token = string | symbol | {
10304
10278
  [key: string]: any;
10305
- }, A extends any[] = any[]>(tokens: Token[], factory: (token: Token, ...args: A) => T): (...args: A) => T;
10306
- /**
10307
- * Gets the next instance in the rotation, creating it if necessary
10308
- * @private
10309
- * @param args - Arguments to pass to the factory function
10310
- * @returns The next instance in the rotation
10311
- */
10279
+ }, A extends any[] = any[]>(tokens: Token[], factory: (token: Token) => (...args: A) => T): (...args: A) => T;
10312
10280
  private call;
10313
10281
  }
10314
10282