agent-swarm-kit 1.0.228 → 1.0.229

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
@@ -8757,16 +8757,34 @@ const CREATE_EMBEDDING_FN = async (item, self) => {
8757
8757
  id: item.id,
8758
8758
  });
8759
8759
  const index = await self.params.createIndex(item);
8760
- const hash = createSHA256Hash(index);
8761
- let embeddings = await self.params.readEmbeddingCache(self.params.embedding, hash);
8762
- if (!embeddings) {
8763
- embeddings = await self.params.createEmbedding(index, self.params.embedding);
8764
- await self.params.writeEmbeddingCache(embeddings, self.params.embedding, hash);
8760
+ const result = [];
8761
+ if (typeof index === "string") {
8762
+ const hash = createSHA256Hash(index);
8763
+ let embeddings = await self.params.readEmbeddingCache(self.params.embedding, hash);
8764
+ if (!embeddings) {
8765
+ embeddings = await self.params.createEmbedding(index, self.params.embedding);
8766
+ await self.params.writeEmbeddingCache(embeddings, self.params.embedding, hash);
8767
+ }
8768
+ if (self.params.onCreate) {
8769
+ self.params.onCreate(index, embeddings, self.params.clientId, self.params.embedding);
8770
+ }
8771
+ result.push([embeddings, index]);
8765
8772
  }
8766
- if (self.params.onCreate) {
8767
- self.params.onCreate(index, embeddings, self.params.clientId, self.params.embedding);
8773
+ else {
8774
+ for (const value of Object.values(index)) {
8775
+ const hash = createSHA256Hash(value);
8776
+ let embeddings = await self.params.readEmbeddingCache(self.params.embedding, hash);
8777
+ if (!embeddings) {
8778
+ embeddings = await self.params.createEmbedding(value, self.params.embedding);
8779
+ await self.params.writeEmbeddingCache(embeddings, self.params.embedding, hash);
8780
+ }
8781
+ if (self.params.onCreate) {
8782
+ self.params.onCreate(value, embeddings, self.params.clientId, self.params.embedding);
8783
+ }
8784
+ result.push([embeddings, value]);
8785
+ }
8768
8786
  }
8769
- return [embeddings, index];
8787
+ return result;
8770
8788
  };
8771
8789
  /**
8772
8790
  * Waits for the ClientStorage instance to initialize by loading initial data and creating embeddings.
@@ -8992,12 +9010,15 @@ class ClientStorage {
8992
9010
  this.params.onCreate(search, searchEmbeddings, this.params.clientId, this.params.embedding);
8993
9011
  }
8994
9012
  await Promise.all(Array.from(this._itemMap.values()).map(functoolsKit.execpool(async (item) => {
8995
- const [targetEmbeddings, index] = await this._createEmbedding(item);
8996
- const score = await this.params.calculateSimilarity(searchEmbeddings, targetEmbeddings);
8997
- if (this.params.onCompare) {
8998
- this.params.onCompare(search, index, score, this.params.clientId, this.params.embedding);
9013
+ let maxScore = Number.NEGATIVE_INFINITY;
9014
+ for (const [targetEmbeddings, index] of await this._createEmbedding(item)) {
9015
+ const score = await this.params.calculateSimilarity(searchEmbeddings, targetEmbeddings);
9016
+ if (this.params.onCompare) {
9017
+ this.params.onCompare(search, index, score, this.params.clientId, this.params.embedding);
9018
+ }
9019
+ maxScore = Math.max(score, maxScore);
8999
9020
  }
9000
- indexed.push(item, score);
9021
+ indexed.push(item, maxScore);
9001
9022
  }, {
9002
9023
  delay: 10,
9003
9024
  maxExec: GLOBAL_CONFIG.CC_STORAGE_SEARCH_POOL,
package/build/index.mjs CHANGED
@@ -8755,16 +8755,34 @@ const CREATE_EMBEDDING_FN = async (item, self) => {
8755
8755
  id: item.id,
8756
8756
  });
8757
8757
  const index = await self.params.createIndex(item);
8758
- const hash = createSHA256Hash(index);
8759
- let embeddings = await self.params.readEmbeddingCache(self.params.embedding, hash);
8760
- if (!embeddings) {
8761
- embeddings = await self.params.createEmbedding(index, self.params.embedding);
8762
- await self.params.writeEmbeddingCache(embeddings, self.params.embedding, hash);
8758
+ const result = [];
8759
+ if (typeof index === "string") {
8760
+ const hash = createSHA256Hash(index);
8761
+ let embeddings = await self.params.readEmbeddingCache(self.params.embedding, hash);
8762
+ if (!embeddings) {
8763
+ embeddings = await self.params.createEmbedding(index, self.params.embedding);
8764
+ await self.params.writeEmbeddingCache(embeddings, self.params.embedding, hash);
8765
+ }
8766
+ if (self.params.onCreate) {
8767
+ self.params.onCreate(index, embeddings, self.params.clientId, self.params.embedding);
8768
+ }
8769
+ result.push([embeddings, index]);
8763
8770
  }
8764
- if (self.params.onCreate) {
8765
- self.params.onCreate(index, embeddings, self.params.clientId, self.params.embedding);
8771
+ else {
8772
+ for (const value of Object.values(index)) {
8773
+ const hash = createSHA256Hash(value);
8774
+ let embeddings = await self.params.readEmbeddingCache(self.params.embedding, hash);
8775
+ if (!embeddings) {
8776
+ embeddings = await self.params.createEmbedding(value, self.params.embedding);
8777
+ await self.params.writeEmbeddingCache(embeddings, self.params.embedding, hash);
8778
+ }
8779
+ if (self.params.onCreate) {
8780
+ self.params.onCreate(value, embeddings, self.params.clientId, self.params.embedding);
8781
+ }
8782
+ result.push([embeddings, value]);
8783
+ }
8766
8784
  }
8767
- return [embeddings, index];
8785
+ return result;
8768
8786
  };
8769
8787
  /**
8770
8788
  * Waits for the ClientStorage instance to initialize by loading initial data and creating embeddings.
@@ -8990,12 +9008,15 @@ class ClientStorage {
8990
9008
  this.params.onCreate(search, searchEmbeddings, this.params.clientId, this.params.embedding);
8991
9009
  }
8992
9010
  await Promise.all(Array.from(this._itemMap.values()).map(execpool(async (item) => {
8993
- const [targetEmbeddings, index] = await this._createEmbedding(item);
8994
- const score = await this.params.calculateSimilarity(searchEmbeddings, targetEmbeddings);
8995
- if (this.params.onCompare) {
8996
- this.params.onCompare(search, index, score, this.params.clientId, this.params.embedding);
9011
+ let maxScore = Number.NEGATIVE_INFINITY;
9012
+ for (const [targetEmbeddings, index] of await this._createEmbedding(item)) {
9013
+ const score = await this.params.calculateSimilarity(searchEmbeddings, targetEmbeddings);
9014
+ if (this.params.onCompare) {
9015
+ this.params.onCompare(search, index, score, this.params.clientId, this.params.embedding);
9016
+ }
9017
+ maxScore = Math.max(score, maxScore);
8997
9018
  }
8998
- indexed.push(item, score);
9019
+ indexed.push(item, maxScore);
8999
9020
  }, {
9000
9021
  delay: 10,
9001
9022
  maxExec: GLOBAL_CONFIG.CC_STORAGE_SEARCH_POOL,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.228",
3
+ "version": "1.0.229",
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
@@ -220,7 +220,7 @@ interface IStorageSchema<T extends IStorageData = IStorageData> {
220
220
  * @param {T} item - The storage item to index.
221
221
  * @returns {Promise<string> | string} The index string for the item, synchronously or asynchronously.
222
222
  */
223
- createIndex(item: T): Promise<string> | string;
223
+ createIndex(item: T): Promise<string> | string | Record<string, string> | Promise<Record<string, string>>;
224
224
  /** The name of the embedding mechanism used for indexing and searching storage data. */
225
225
  embedding: EmbeddingName;
226
226
  /** The unique name of the storage within the swarm. */
@@ -6006,7 +6006,7 @@ declare class ClientStorage<T extends IStorageData = IStorageData> implements IS
6006
6006
  * @returns {Promise<readonly [Embeddings, string]>} A tuple of embeddings (from Embedding.interface) and index string.
6007
6007
  * @private
6008
6008
  */
6009
- _createEmbedding: ((item: T) => Promise<readonly [Embeddings, string]>) & functools_kit.IClearableMemoize<string | number> & functools_kit.IControlMemoize<string | number, Promise<readonly [Embeddings, string]>>;
6009
+ _createEmbedding: ((item: T) => Promise<readonly [Embeddings, string][]>) & functools_kit.IClearableMemoize<string | number> & functools_kit.IControlMemoize<string | number, Promise<readonly [Embeddings, string][]>>;
6010
6010
  /**
6011
6011
  * Waits for the initialization of the storage, loading initial data and creating embeddings via WAIT_FOR_INIT_FN.
6012
6012
  * Ensures initialization happens only once using singleshot, supporting StorageConnectionService’s lifecycle.