agent-swarm-kit 1.0.185 → 1.0.187

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
@@ -470,6 +470,13 @@ const PERSIST_STATE_UTILS_METHOD_NAME_USE_PERSIST_STATE_ADAPTER = "PersistStateU
470
470
  const PERSIST_STATE_UTILS_METHOD_NAME_SET_STATE = "PersistStateUtils.setState";
471
471
  /** @private Constant for logging the getState method in PersistStateUtils */
472
472
  const PERSIST_STATE_UTILS_METHOD_NAME_GET_STATE = "PersistStateUtils.getState";
473
+ // Logging method names for PersistEmbeddingUtils
474
+ /** @private Constant for logging the usePersistEmbeddingAdapter method in PersistEmbeddingUtils */
475
+ const PERSIST_EMBEDDING_UTILS_METHOD_NAME_USE_PERSIST_EMBEDDING_ADAPTER = "PersistEmbeddingUtils.usePersistEmbeddingAdapter";
476
+ /** @private Constant for logging the readEmbeddingCache method in PersistEmbeddingUtils */
477
+ const PERSIST_EMBEDDING_UTILS_METHOD_NAME_READ_EMBEDDING_CACHE = "PersistEmbeddingUtils.readEmbeddingCache";
478
+ /** @private Constant for logging the writeEmbeddingCache method in PersistEmbeddingUtils */
479
+ const PERSIST_EMBEDDING_UTILS_METHOD_NAME_WRITE_EMBEDDING_CACHE = "PersistEmbeddingUtils.writeEmbeddingCache";
473
480
  // Logging method names for PersistMemoryUtils
474
481
  /** @private Constant for logging the usePersistMemoryAdapter method in PersistMemoryUtils */
475
482
  const PERSIST_MEMORY_UTILS_METHOD_NAME_USE_PERSIST_MEMORY_ADAPTER = "PersistMemoryUtils.usePersistMemoryAdapter";
@@ -1645,6 +1652,86 @@ const PersistPolicyAdapter = new PersistPolicyUtils();
1645
1652
  * @type {IPersistPolicyControl}
1646
1653
  */
1647
1654
  const PersistPolicy = PersistPolicyAdapter;
1655
+ /**
1656
+ * Utility class for managing embedding data persistence in the swarm system.
1657
+ * Provides methods to read and write embedding vectors with a customizable adapter.
1658
+ * @implements {IPersistEmbeddingControl}
1659
+ */
1660
+ class PersistEmbeddingUtils {
1661
+ constructor() {
1662
+ /** @private Default constructor for embedding data persistence, defaults to `PersistBase` */
1663
+ this.PersistEmbeddingFactory = PersistBase;
1664
+ /**
1665
+ * Memoized function to create or retrieve storage for specific embedding data.
1666
+ * Ensures a single persistence instance per embedding name, optimizing resource use.
1667
+ * @private
1668
+ * @param embeddingName - The identifier of the embedding type.
1669
+ * @returns A persistence instance for the embedding data, rooted at `./logs/data/embedding/`.
1670
+ */
1671
+ this.getEmbeddingStorage = functoolsKit.memoize(([embeddingName]) => `${embeddingName}`, (embeddingName) => Reflect.construct(this.PersistEmbeddingFactory, [
1672
+ embeddingName,
1673
+ `./logs/data/embedding/`,
1674
+ ]));
1675
+ /**
1676
+ * Retrieves the embedding vector for a specific string hash, returning null if not found.
1677
+ * Used to check if a precomputed embedding exists in the cache.
1678
+ * @param embeddingName - The identifier of the embedding type.
1679
+ * @param stringHash - The hash of the string for which the embedding was generated.
1680
+ * @returns A promise resolving to the embedding vector or null if not cached.
1681
+ * @throws {Error} If reading from storage fails (e.g., file corruption).
1682
+ */
1683
+ this.readEmbeddingCache = async (embeddingName, stringHash) => {
1684
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
1685
+ swarm$1.loggerService.log(PERSIST_EMBEDDING_UTILS_METHOD_NAME_READ_EMBEDDING_CACHE);
1686
+ const isInitial = this.getEmbeddingStorage.has(embeddingName);
1687
+ const stateStorage = this.getEmbeddingStorage(embeddingName);
1688
+ await stateStorage.waitForInit(isInitial);
1689
+ if (await stateStorage.hasValue(stringHash)) {
1690
+ const { embeddings } = await stateStorage.readValue(stringHash);
1691
+ return embeddings;
1692
+ }
1693
+ return null;
1694
+ };
1695
+ /**
1696
+ * Stores an embedding vector for a specific string hash, persisting it for future retrieval.
1697
+ * Used to cache computed embeddings to avoid redundant processing.
1698
+ * @param embeddings - Array of numerical values representing the embedding vector.
1699
+ * @param embeddingName - The identifier of the embedding type.
1700
+ * @param stringHash - The hash of the string for which the embedding was generated.
1701
+ * @returns A promise that resolves when the embedding vector is persisted.
1702
+ * @throws {Error} If writing to storage fails (e.g., permissions or disk space).
1703
+ */
1704
+ this.writeEmbeddingCache = async (embeddings, embeddingName, stringHash) => {
1705
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
1706
+ swarm$1.loggerService.log(PERSIST_EMBEDDING_UTILS_METHOD_NAME_WRITE_EMBEDDING_CACHE);
1707
+ const isInitial = this.getEmbeddingStorage.has(embeddingName);
1708
+ const stateStorage = this.getEmbeddingStorage(embeddingName);
1709
+ await stateStorage.waitForInit(isInitial);
1710
+ await stateStorage.writeValue(stringHash, { embeddings });
1711
+ };
1712
+ }
1713
+ /**
1714
+ * Configures a custom constructor for embedding data persistence, overriding the default `PersistBase`.
1715
+ * Enables advanced tracking (e.g., in-memory or database-backed persistence).
1716
+ * @param Ctor - The constructor to use for embedding data storage, implementing `IPersistBase`.
1717
+ */
1718
+ usePersistEmbeddingAdapter(Ctor) {
1719
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
1720
+ swarm$1.loggerService.log(PERSIST_EMBEDDING_UTILS_METHOD_NAME_USE_PERSIST_EMBEDDING_ADAPTER);
1721
+ this.PersistEmbeddingFactory = Ctor;
1722
+ }
1723
+ }
1724
+ /**
1725
+ * Singleton instance of `PersistEmbeddingUtils` for managing embedding data persistence globally.
1726
+ * @type {PersistEmbeddingUtils}
1727
+ */
1728
+ const PersistEmbeddingAdapter = new PersistEmbeddingUtils();
1729
+ /**
1730
+ * Exported singleton for embedding persistence operations, cast as the control interface.
1731
+ * Provides a global point of access for managing embedding cache in the system.
1732
+ * @type {IPersistEmbeddingControl}
1733
+ */
1734
+ const PersistEmbedding = PersistEmbeddingAdapter;
1648
1735
 
1649
1736
  var _a$1, _b$1, _c, _d;
1650
1737
  /** @private Symbol for memoizing the waitForInit method in HistoryMemoryInstance */
@@ -2735,6 +2822,25 @@ const CC_PERSIST_ENABLED_BY_DEFAULT = true;
2735
2822
  const CC_PERSIST_MEMORY_STORAGE = true;
2736
2823
  const CC_AUTOBAN_ENABLED_BY_DEFAULT = false;
2737
2824
  const CC_SKIP_POSIX_RENAME = false;
2825
+ /**
2826
+ * Retrieves the embedding vector for a specific string hash, returning null if not found.
2827
+ * Used to check if a precomputed embedding exists in the cache.
2828
+ * @param embeddingName - The identifier of the embedding type.
2829
+ * @param stringHash - The hash of the string for which the embedding was generated.
2830
+ * @returns A promise resolving to the embedding vector or null if not cached.
2831
+ * @throws {Error} If reading from storage fails (e.g., file corruption).
2832
+ */
2833
+ const CC_DEFAULT_READ_EMBEDDING_CACHE = (embeddingName, stringHash) => Promise.resolve(null);
2834
+ /**
2835
+ * Stores an embedding vector for a specific string hash, persisting it for future retrieval.
2836
+ * Used to cache computed embeddings to avoid redundant processing.
2837
+ * @param embeddings - Array of numerical values representing the embedding vector.
2838
+ * @param embeddingName - The identifier of the embedding type.
2839
+ * @param stringHash - The hash of the string for which the embedding was generated.
2840
+ * @returns A promise that resolves when the embedding vector is persisted.
2841
+ * @throws {Error} If writing to storage fails (e.g., permissions or disk space).
2842
+ */
2843
+ const CC_DEFAULT_WRITE_EMBEDDING_CACHE = (embeddings, embeddingName, stringHash) => Promise.resolve();
2738
2844
  const GLOBAL_CONFIG = {
2739
2845
  CC_TOOL_CALL_EXCEPTION_FLUSH_PROMPT,
2740
2846
  CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT,
@@ -2778,6 +2884,8 @@ const GLOBAL_CONFIG = {
2778
2884
  CC_DEFAULT_STORAGE_SET,
2779
2885
  CC_SKIP_POSIX_RENAME,
2780
2886
  CC_PERSIST_MEMORY_STORAGE,
2887
+ CC_DEFAULT_READ_EMBEDDING_CACHE,
2888
+ CC_DEFAULT_WRITE_EMBEDDING_CACHE,
2781
2889
  };
2782
2890
  GLOBAL_CONFIG.CC_RESQUE_STRATEGY = "flush";
2783
2891
  const setConfig = (config) => {
@@ -8324,6 +8432,19 @@ class StorageSchemaService {
8324
8432
  }
8325
8433
  }
8326
8434
 
8435
+ /**
8436
+ * Creates a SHA-256 hash of the provided string.
8437
+ *
8438
+ * @param {string} string - The input string to be hashed.
8439
+ * @returns {string} A hexadecimal representation of the SHA-256 hash.
8440
+ *
8441
+ * @example
8442
+ * // Returns "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3"
8443
+ * createSHA256Hash("Hello, world!");
8444
+ */
8445
+ function createSHA256Hash(string) {
8446
+ return crypto.createHash("sha256").update(string).digest("hex");
8447
+ }
8327
8448
  /**
8328
8449
  * Creates embeddings and an index for a given item, memoized by item ID in _createEmbedding.
8329
8450
  * Invokes the onCreate callback if provided, supporting EmbeddingSchemaService’s embedding generation.
@@ -8339,7 +8460,12 @@ const CREATE_EMBEDDING_FN = async (item, self) => {
8339
8460
  id: item.id,
8340
8461
  });
8341
8462
  const index = await self.params.createIndex(item);
8342
- const embeddings = await self.params.createEmbedding(index);
8463
+ const hash = createSHA256Hash(index);
8464
+ let embeddings = await self.params.readEmbeddingCache(self.params.embedding, hash);
8465
+ if (!embeddings) {
8466
+ embeddings = await self.params.createEmbedding(index, self.params.embedding);
8467
+ await self.params.writeEmbeddingCache(embeddings, self.params.embedding, hash);
8468
+ }
8343
8469
  if (self.params.onCreate) {
8344
8470
  self.params.onCreate(index, embeddings, self.params.clientId, self.params.embedding);
8345
8471
  }
@@ -8561,7 +8687,10 @@ class ClientStorage {
8561
8687
  total,
8562
8688
  });
8563
8689
  const indexed = new functoolsKit.SortedArray();
8564
- const searchEmbeddings = await this.params.createEmbedding(search);
8690
+ let searchEmbeddings = await this.params.readEmbeddingCache(this.params.embedding, createSHA256Hash(search));
8691
+ if (!searchEmbeddings) {
8692
+ searchEmbeddings = await this.params.createEmbedding(search, this.params.embedding);
8693
+ }
8565
8694
  if (this.params.onCreate) {
8566
8695
  this.params.onCreate(search, searchEmbeddings, this.params.clientId, this.params.embedding);
8567
8696
  }
@@ -8803,11 +8932,17 @@ class StorageConnectionService {
8803
8932
  this._sharedStorageSet.add(storageName);
8804
8933
  return this.sharedStorageConnectionService.getStorage(storageName);
8805
8934
  }
8806
- const { calculateSimilarity, createEmbedding, callbacks: embedding, } = this.embeddingSchemaService.get(embeddingName);
8935
+ const { persist: p = GLOBAL_CONFIG.CC_PERSIST_ENABLED_BY_DEFAULT, writeEmbeddingCache = p
8936
+ ? PersistEmbeddingAdapter.writeEmbeddingCache
8937
+ : GLOBAL_CONFIG.CC_DEFAULT_WRITE_EMBEDDING_CACHE, readEmbeddingCache = p
8938
+ ? PersistEmbeddingAdapter.readEmbeddingCache
8939
+ : GLOBAL_CONFIG.CC_DEFAULT_READ_EMBEDDING_CACHE, calculateSimilarity, createEmbedding, callbacks: embedding, } = this.embeddingSchemaService.get(embeddingName);
8807
8940
  return new ClientStorage({
8808
8941
  clientId,
8809
8942
  storageName,
8810
8943
  embedding: embeddingName,
8944
+ writeEmbeddingCache,
8945
+ readEmbeddingCache,
8811
8946
  calculateSimilarity,
8812
8947
  createEmbedding,
8813
8948
  createIndex,
@@ -10997,11 +11132,17 @@ class SharedStorageConnectionService {
10997
11132
  if (!shared) {
10998
11133
  throw new Error(`agent-swarm storage not shared storageName=${storageName}`);
10999
11134
  }
11000
- const { calculateSimilarity, createEmbedding, callbacks: embedding, } = this.embeddingSchemaService.get(embeddingName);
11135
+ const { persist: p = GLOBAL_CONFIG.CC_PERSIST_ENABLED_BY_DEFAULT, writeEmbeddingCache = p
11136
+ ? PersistEmbeddingAdapter.writeEmbeddingCache
11137
+ : GLOBAL_CONFIG.CC_DEFAULT_WRITE_EMBEDDING_CACHE, readEmbeddingCache = p
11138
+ ? PersistEmbeddingAdapter.readEmbeddingCache
11139
+ : GLOBAL_CONFIG.CC_DEFAULT_READ_EMBEDDING_CACHE, calculateSimilarity, createEmbedding, callbacks: embedding, } = this.embeddingSchemaService.get(embeddingName);
11001
11140
  return new ClientStorage({
11002
11141
  clientId: "shared",
11003
11142
  storageName,
11004
11143
  embedding: embeddingName,
11144
+ writeEmbeddingCache,
11145
+ readEmbeddingCache,
11005
11146
  calculateSimilarity,
11006
11147
  createEmbedding,
11007
11148
  createIndex,
@@ -14577,6 +14718,7 @@ const makeConnection = (connector, clientId, swarmName) => {
14577
14718
  const online = functoolsKit.singlerun(async () => {
14578
14719
  await markOnline(clientId, swarmName);
14579
14720
  });
14721
+ online();
14580
14722
  return beginContext(async (content, payload = null) => {
14581
14723
  await online();
14582
14724
  if (payload) {
@@ -14611,6 +14753,7 @@ makeConnection.scheduled = (connector, clientId, swarmName, { delay = SCHEDULED_
14611
14753
  const online = functoolsKit.singlerun(async () => {
14612
14754
  await markOnline(clientId, swarmName);
14613
14755
  });
14756
+ online();
14614
14757
  const wrappedSend = functoolsKit.schedule(beginContext(async (content, payload) => {
14615
14758
  if (!swarm$1.sessionValidationService.hasSession(clientId)) {
14616
14759
  return;
@@ -14668,6 +14811,7 @@ makeConnection.rate = (connector, clientId, swarmName, { delay = RATE_DELAY } =
14668
14811
  const online = functoolsKit.singlerun(async () => {
14669
14812
  await markOnline(clientId, swarmName);
14670
14813
  });
14814
+ online();
14671
14815
  const wrappedSend = functoolsKit.rate(beginContext(async (content, payload) => {
14672
14816
  if (!swarm$1.sessionValidationService.hasSession(clientId)) {
14673
14817
  return;
@@ -14894,6 +15038,7 @@ const session = (clientId, swarmName, { onDispose } = {}) => {
14894
15038
  const online = functoolsKit.singlerun(async () => {
14895
15039
  await markOnline(clientId, swarmName);
14896
15040
  });
15041
+ online();
14897
15042
  return {
14898
15043
  complete: beginContext(async (content, payload = null) => {
14899
15044
  if (!isMounted) {
@@ -14941,6 +15086,7 @@ session.scheduled = (clientId, swarmName, { delay = SCHEDULED_DELAY, onDispose }
14941
15086
  const online = functoolsKit.singlerun(async () => {
14942
15087
  await markOnline(clientId, swarmName);
14943
15088
  });
15089
+ online();
14944
15090
  const wrappedComplete = functoolsKit.schedule(beginContext(async (content, payload) => {
14945
15091
  if (!isMounted) {
14946
15092
  return;
@@ -15008,6 +15154,7 @@ session.rate = (clientId, swarmName, { delay = SCHEDULED_DELAY, onDispose } = {}
15008
15154
  const online = functoolsKit.singlerun(async () => {
15009
15155
  await markOnline(clientId, swarmName);
15010
15156
  });
15157
+ online();
15011
15158
  const wrappedComplete = functoolsKit.rate(beginContext(async (content, payload) => {
15012
15159
  if (!isMounted) {
15013
15160
  return;
@@ -17354,6 +17501,7 @@ const Utils = {
17354
17501
  PersistMemoryUtils,
17355
17502
  PersistAliveUtils,
17356
17503
  PersistPolicyUtils,
17504
+ PersistEmbeddingUtils,
17357
17505
  };
17358
17506
 
17359
17507
  exports.Adapter = Adapter;
@@ -17367,6 +17515,7 @@ exports.MethodContextService = MethodContextService;
17367
17515
  exports.PayloadContextService = PayloadContextService;
17368
17516
  exports.PersistAlive = PersistAlive;
17369
17517
  exports.PersistBase = PersistBase;
17518
+ exports.PersistEmbedding = PersistEmbedding;
17370
17519
  exports.PersistList = PersistList;
17371
17520
  exports.PersistMemory = PersistMemory;
17372
17521
  exports.PersistPolicy = PersistPolicy;
package/build/index.mjs CHANGED
@@ -4,7 +4,7 @@ import { trycatch, makeExtendable, singleshot, getErrorMessage, not, queued, mem
4
4
  import xml2js from 'xml2js';
5
5
  import fs, { access, mkdir } from 'fs/promises';
6
6
  import path, { join } from 'path';
7
- import crypto from 'crypto';
7
+ import crypto, { createHash } from 'crypto';
8
8
  import os from 'os';
9
9
  import { AsyncResource } from 'async_hooks';
10
10
  import { omit } from 'lodash-es';
@@ -468,6 +468,13 @@ const PERSIST_STATE_UTILS_METHOD_NAME_USE_PERSIST_STATE_ADAPTER = "PersistStateU
468
468
  const PERSIST_STATE_UTILS_METHOD_NAME_SET_STATE = "PersistStateUtils.setState";
469
469
  /** @private Constant for logging the getState method in PersistStateUtils */
470
470
  const PERSIST_STATE_UTILS_METHOD_NAME_GET_STATE = "PersistStateUtils.getState";
471
+ // Logging method names for PersistEmbeddingUtils
472
+ /** @private Constant for logging the usePersistEmbeddingAdapter method in PersistEmbeddingUtils */
473
+ const PERSIST_EMBEDDING_UTILS_METHOD_NAME_USE_PERSIST_EMBEDDING_ADAPTER = "PersistEmbeddingUtils.usePersistEmbeddingAdapter";
474
+ /** @private Constant for logging the readEmbeddingCache method in PersistEmbeddingUtils */
475
+ const PERSIST_EMBEDDING_UTILS_METHOD_NAME_READ_EMBEDDING_CACHE = "PersistEmbeddingUtils.readEmbeddingCache";
476
+ /** @private Constant for logging the writeEmbeddingCache method in PersistEmbeddingUtils */
477
+ const PERSIST_EMBEDDING_UTILS_METHOD_NAME_WRITE_EMBEDDING_CACHE = "PersistEmbeddingUtils.writeEmbeddingCache";
471
478
  // Logging method names for PersistMemoryUtils
472
479
  /** @private Constant for logging the usePersistMemoryAdapter method in PersistMemoryUtils */
473
480
  const PERSIST_MEMORY_UTILS_METHOD_NAME_USE_PERSIST_MEMORY_ADAPTER = "PersistMemoryUtils.usePersistMemoryAdapter";
@@ -1643,6 +1650,86 @@ const PersistPolicyAdapter = new PersistPolicyUtils();
1643
1650
  * @type {IPersistPolicyControl}
1644
1651
  */
1645
1652
  const PersistPolicy = PersistPolicyAdapter;
1653
+ /**
1654
+ * Utility class for managing embedding data persistence in the swarm system.
1655
+ * Provides methods to read and write embedding vectors with a customizable adapter.
1656
+ * @implements {IPersistEmbeddingControl}
1657
+ */
1658
+ class PersistEmbeddingUtils {
1659
+ constructor() {
1660
+ /** @private Default constructor for embedding data persistence, defaults to `PersistBase` */
1661
+ this.PersistEmbeddingFactory = PersistBase;
1662
+ /**
1663
+ * Memoized function to create or retrieve storage for specific embedding data.
1664
+ * Ensures a single persistence instance per embedding name, optimizing resource use.
1665
+ * @private
1666
+ * @param embeddingName - The identifier of the embedding type.
1667
+ * @returns A persistence instance for the embedding data, rooted at `./logs/data/embedding/`.
1668
+ */
1669
+ this.getEmbeddingStorage = memoize(([embeddingName]) => `${embeddingName}`, (embeddingName) => Reflect.construct(this.PersistEmbeddingFactory, [
1670
+ embeddingName,
1671
+ `./logs/data/embedding/`,
1672
+ ]));
1673
+ /**
1674
+ * Retrieves the embedding vector for a specific string hash, returning null if not found.
1675
+ * Used to check if a precomputed embedding exists in the cache.
1676
+ * @param embeddingName - The identifier of the embedding type.
1677
+ * @param stringHash - The hash of the string for which the embedding was generated.
1678
+ * @returns A promise resolving to the embedding vector or null if not cached.
1679
+ * @throws {Error} If reading from storage fails (e.g., file corruption).
1680
+ */
1681
+ this.readEmbeddingCache = async (embeddingName, stringHash) => {
1682
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
1683
+ swarm$1.loggerService.log(PERSIST_EMBEDDING_UTILS_METHOD_NAME_READ_EMBEDDING_CACHE);
1684
+ const isInitial = this.getEmbeddingStorage.has(embeddingName);
1685
+ const stateStorage = this.getEmbeddingStorage(embeddingName);
1686
+ await stateStorage.waitForInit(isInitial);
1687
+ if (await stateStorage.hasValue(stringHash)) {
1688
+ const { embeddings } = await stateStorage.readValue(stringHash);
1689
+ return embeddings;
1690
+ }
1691
+ return null;
1692
+ };
1693
+ /**
1694
+ * Stores an embedding vector for a specific string hash, persisting it for future retrieval.
1695
+ * Used to cache computed embeddings to avoid redundant processing.
1696
+ * @param embeddings - Array of numerical values representing the embedding vector.
1697
+ * @param embeddingName - The identifier of the embedding type.
1698
+ * @param stringHash - The hash of the string for which the embedding was generated.
1699
+ * @returns A promise that resolves when the embedding vector is persisted.
1700
+ * @throws {Error} If writing to storage fails (e.g., permissions or disk space).
1701
+ */
1702
+ this.writeEmbeddingCache = async (embeddings, embeddingName, stringHash) => {
1703
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
1704
+ swarm$1.loggerService.log(PERSIST_EMBEDDING_UTILS_METHOD_NAME_WRITE_EMBEDDING_CACHE);
1705
+ const isInitial = this.getEmbeddingStorage.has(embeddingName);
1706
+ const stateStorage = this.getEmbeddingStorage(embeddingName);
1707
+ await stateStorage.waitForInit(isInitial);
1708
+ await stateStorage.writeValue(stringHash, { embeddings });
1709
+ };
1710
+ }
1711
+ /**
1712
+ * Configures a custom constructor for embedding data persistence, overriding the default `PersistBase`.
1713
+ * Enables advanced tracking (e.g., in-memory or database-backed persistence).
1714
+ * @param Ctor - The constructor to use for embedding data storage, implementing `IPersistBase`.
1715
+ */
1716
+ usePersistEmbeddingAdapter(Ctor) {
1717
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
1718
+ swarm$1.loggerService.log(PERSIST_EMBEDDING_UTILS_METHOD_NAME_USE_PERSIST_EMBEDDING_ADAPTER);
1719
+ this.PersistEmbeddingFactory = Ctor;
1720
+ }
1721
+ }
1722
+ /**
1723
+ * Singleton instance of `PersistEmbeddingUtils` for managing embedding data persistence globally.
1724
+ * @type {PersistEmbeddingUtils}
1725
+ */
1726
+ const PersistEmbeddingAdapter = new PersistEmbeddingUtils();
1727
+ /**
1728
+ * Exported singleton for embedding persistence operations, cast as the control interface.
1729
+ * Provides a global point of access for managing embedding cache in the system.
1730
+ * @type {IPersistEmbeddingControl}
1731
+ */
1732
+ const PersistEmbedding = PersistEmbeddingAdapter;
1646
1733
 
1647
1734
  var _a$1, _b$1, _c, _d;
1648
1735
  /** @private Symbol for memoizing the waitForInit method in HistoryMemoryInstance */
@@ -2733,6 +2820,25 @@ const CC_PERSIST_ENABLED_BY_DEFAULT = true;
2733
2820
  const CC_PERSIST_MEMORY_STORAGE = true;
2734
2821
  const CC_AUTOBAN_ENABLED_BY_DEFAULT = false;
2735
2822
  const CC_SKIP_POSIX_RENAME = false;
2823
+ /**
2824
+ * Retrieves the embedding vector for a specific string hash, returning null if not found.
2825
+ * Used to check if a precomputed embedding exists in the cache.
2826
+ * @param embeddingName - The identifier of the embedding type.
2827
+ * @param stringHash - The hash of the string for which the embedding was generated.
2828
+ * @returns A promise resolving to the embedding vector or null if not cached.
2829
+ * @throws {Error} If reading from storage fails (e.g., file corruption).
2830
+ */
2831
+ const CC_DEFAULT_READ_EMBEDDING_CACHE = (embeddingName, stringHash) => Promise.resolve(null);
2832
+ /**
2833
+ * Stores an embedding vector for a specific string hash, persisting it for future retrieval.
2834
+ * Used to cache computed embeddings to avoid redundant processing.
2835
+ * @param embeddings - Array of numerical values representing the embedding vector.
2836
+ * @param embeddingName - The identifier of the embedding type.
2837
+ * @param stringHash - The hash of the string for which the embedding was generated.
2838
+ * @returns A promise that resolves when the embedding vector is persisted.
2839
+ * @throws {Error} If writing to storage fails (e.g., permissions or disk space).
2840
+ */
2841
+ const CC_DEFAULT_WRITE_EMBEDDING_CACHE = (embeddings, embeddingName, stringHash) => Promise.resolve();
2736
2842
  const GLOBAL_CONFIG = {
2737
2843
  CC_TOOL_CALL_EXCEPTION_FLUSH_PROMPT,
2738
2844
  CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT,
@@ -2776,6 +2882,8 @@ const GLOBAL_CONFIG = {
2776
2882
  CC_DEFAULT_STORAGE_SET,
2777
2883
  CC_SKIP_POSIX_RENAME,
2778
2884
  CC_PERSIST_MEMORY_STORAGE,
2885
+ CC_DEFAULT_READ_EMBEDDING_CACHE,
2886
+ CC_DEFAULT_WRITE_EMBEDDING_CACHE,
2779
2887
  };
2780
2888
  GLOBAL_CONFIG.CC_RESQUE_STRATEGY = "flush";
2781
2889
  const setConfig = (config) => {
@@ -8322,6 +8430,19 @@ class StorageSchemaService {
8322
8430
  }
8323
8431
  }
8324
8432
 
8433
+ /**
8434
+ * Creates a SHA-256 hash of the provided string.
8435
+ *
8436
+ * @param {string} string - The input string to be hashed.
8437
+ * @returns {string} A hexadecimal representation of the SHA-256 hash.
8438
+ *
8439
+ * @example
8440
+ * // Returns "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3"
8441
+ * createSHA256Hash("Hello, world!");
8442
+ */
8443
+ function createSHA256Hash(string) {
8444
+ return createHash("sha256").update(string).digest("hex");
8445
+ }
8325
8446
  /**
8326
8447
  * Creates embeddings and an index for a given item, memoized by item ID in _createEmbedding.
8327
8448
  * Invokes the onCreate callback if provided, supporting EmbeddingSchemaService’s embedding generation.
@@ -8337,7 +8458,12 @@ const CREATE_EMBEDDING_FN = async (item, self) => {
8337
8458
  id: item.id,
8338
8459
  });
8339
8460
  const index = await self.params.createIndex(item);
8340
- const embeddings = await self.params.createEmbedding(index);
8461
+ const hash = createSHA256Hash(index);
8462
+ let embeddings = await self.params.readEmbeddingCache(self.params.embedding, hash);
8463
+ if (!embeddings) {
8464
+ embeddings = await self.params.createEmbedding(index, self.params.embedding);
8465
+ await self.params.writeEmbeddingCache(embeddings, self.params.embedding, hash);
8466
+ }
8341
8467
  if (self.params.onCreate) {
8342
8468
  self.params.onCreate(index, embeddings, self.params.clientId, self.params.embedding);
8343
8469
  }
@@ -8559,7 +8685,10 @@ class ClientStorage {
8559
8685
  total,
8560
8686
  });
8561
8687
  const indexed = new SortedArray();
8562
- const searchEmbeddings = await this.params.createEmbedding(search);
8688
+ let searchEmbeddings = await this.params.readEmbeddingCache(this.params.embedding, createSHA256Hash(search));
8689
+ if (!searchEmbeddings) {
8690
+ searchEmbeddings = await this.params.createEmbedding(search, this.params.embedding);
8691
+ }
8563
8692
  if (this.params.onCreate) {
8564
8693
  this.params.onCreate(search, searchEmbeddings, this.params.clientId, this.params.embedding);
8565
8694
  }
@@ -8801,11 +8930,17 @@ class StorageConnectionService {
8801
8930
  this._sharedStorageSet.add(storageName);
8802
8931
  return this.sharedStorageConnectionService.getStorage(storageName);
8803
8932
  }
8804
- const { calculateSimilarity, createEmbedding, callbacks: embedding, } = this.embeddingSchemaService.get(embeddingName);
8933
+ const { persist: p = GLOBAL_CONFIG.CC_PERSIST_ENABLED_BY_DEFAULT, writeEmbeddingCache = p
8934
+ ? PersistEmbeddingAdapter.writeEmbeddingCache
8935
+ : GLOBAL_CONFIG.CC_DEFAULT_WRITE_EMBEDDING_CACHE, readEmbeddingCache = p
8936
+ ? PersistEmbeddingAdapter.readEmbeddingCache
8937
+ : GLOBAL_CONFIG.CC_DEFAULT_READ_EMBEDDING_CACHE, calculateSimilarity, createEmbedding, callbacks: embedding, } = this.embeddingSchemaService.get(embeddingName);
8805
8938
  return new ClientStorage({
8806
8939
  clientId,
8807
8940
  storageName,
8808
8941
  embedding: embeddingName,
8942
+ writeEmbeddingCache,
8943
+ readEmbeddingCache,
8809
8944
  calculateSimilarity,
8810
8945
  createEmbedding,
8811
8946
  createIndex,
@@ -10995,11 +11130,17 @@ class SharedStorageConnectionService {
10995
11130
  if (!shared) {
10996
11131
  throw new Error(`agent-swarm storage not shared storageName=${storageName}`);
10997
11132
  }
10998
- const { calculateSimilarity, createEmbedding, callbacks: embedding, } = this.embeddingSchemaService.get(embeddingName);
11133
+ const { persist: p = GLOBAL_CONFIG.CC_PERSIST_ENABLED_BY_DEFAULT, writeEmbeddingCache = p
11134
+ ? PersistEmbeddingAdapter.writeEmbeddingCache
11135
+ : GLOBAL_CONFIG.CC_DEFAULT_WRITE_EMBEDDING_CACHE, readEmbeddingCache = p
11136
+ ? PersistEmbeddingAdapter.readEmbeddingCache
11137
+ : GLOBAL_CONFIG.CC_DEFAULT_READ_EMBEDDING_CACHE, calculateSimilarity, createEmbedding, callbacks: embedding, } = this.embeddingSchemaService.get(embeddingName);
10999
11138
  return new ClientStorage({
11000
11139
  clientId: "shared",
11001
11140
  storageName,
11002
11141
  embedding: embeddingName,
11142
+ writeEmbeddingCache,
11143
+ readEmbeddingCache,
11003
11144
  calculateSimilarity,
11004
11145
  createEmbedding,
11005
11146
  createIndex,
@@ -14575,6 +14716,7 @@ const makeConnection = (connector, clientId, swarmName) => {
14575
14716
  const online = singlerun(async () => {
14576
14717
  await markOnline(clientId, swarmName);
14577
14718
  });
14719
+ online();
14578
14720
  return beginContext(async (content, payload = null) => {
14579
14721
  await online();
14580
14722
  if (payload) {
@@ -14609,6 +14751,7 @@ makeConnection.scheduled = (connector, clientId, swarmName, { delay = SCHEDULED_
14609
14751
  const online = singlerun(async () => {
14610
14752
  await markOnline(clientId, swarmName);
14611
14753
  });
14754
+ online();
14612
14755
  const wrappedSend = schedule(beginContext(async (content, payload) => {
14613
14756
  if (!swarm$1.sessionValidationService.hasSession(clientId)) {
14614
14757
  return;
@@ -14666,6 +14809,7 @@ makeConnection.rate = (connector, clientId, swarmName, { delay = RATE_DELAY } =
14666
14809
  const online = singlerun(async () => {
14667
14810
  await markOnline(clientId, swarmName);
14668
14811
  });
14812
+ online();
14669
14813
  const wrappedSend = rate(beginContext(async (content, payload) => {
14670
14814
  if (!swarm$1.sessionValidationService.hasSession(clientId)) {
14671
14815
  return;
@@ -14892,6 +15036,7 @@ const session = (clientId, swarmName, { onDispose } = {}) => {
14892
15036
  const online = singlerun(async () => {
14893
15037
  await markOnline(clientId, swarmName);
14894
15038
  });
15039
+ online();
14895
15040
  return {
14896
15041
  complete: beginContext(async (content, payload = null) => {
14897
15042
  if (!isMounted) {
@@ -14939,6 +15084,7 @@ session.scheduled = (clientId, swarmName, { delay = SCHEDULED_DELAY, onDispose }
14939
15084
  const online = singlerun(async () => {
14940
15085
  await markOnline(clientId, swarmName);
14941
15086
  });
15087
+ online();
14942
15088
  const wrappedComplete = schedule(beginContext(async (content, payload) => {
14943
15089
  if (!isMounted) {
14944
15090
  return;
@@ -15006,6 +15152,7 @@ session.rate = (clientId, swarmName, { delay = SCHEDULED_DELAY, onDispose } = {}
15006
15152
  const online = singlerun(async () => {
15007
15153
  await markOnline(clientId, swarmName);
15008
15154
  });
15155
+ online();
15009
15156
  const wrappedComplete = rate(beginContext(async (content, payload) => {
15010
15157
  if (!isMounted) {
15011
15158
  return;
@@ -17352,6 +17499,7 @@ const Utils = {
17352
17499
  PersistMemoryUtils,
17353
17500
  PersistAliveUtils,
17354
17501
  PersistPolicyUtils,
17502
+ PersistEmbeddingUtils,
17355
17503
  };
17356
17504
 
17357
- export { Adapter, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, Logger, LoggerInstance, MethodContextService, PayloadContextService, PersistAlive, PersistBase, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, Schema, SharedState, SharedStorage, State, Storage, Utils, addAgent, addCompletion, addEmbedding, addPolicy, addState, addStorage, addSwarm, addTool, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpClientPerformance, dumpDocs, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getPayload, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, runStateless, runStatelessForce, session, setConfig, swarm };
17505
+ export { Adapter, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, Logger, LoggerInstance, MethodContextService, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, Schema, SharedState, SharedStorage, State, Storage, Utils, addAgent, addCompletion, addEmbedding, addPolicy, addState, addStorage, addSwarm, addTool, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpClientPerformance, dumpDocs, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getPayload, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, runStateless, runStatelessForce, session, setConfig, swarm };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.185",
3
+ "version": "1.0.187",
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
@@ -183,6 +183,8 @@ interface IEmbeddingCallbacks {
183
183
  * Defines how embeddings are created and compared within the swarm.
184
184
  */
185
185
  interface IEmbeddingSchema {
186
+ /** Optional flag to enable serialization of navigation stack and active agent state to persistent storage (e.g., hard drive). */
187
+ persist?: boolean;
186
188
  /** The unique name of the embedding mechanism within the swarm. */
187
189
  embeddingName: EmbeddingName;
188
190
  /**
@@ -192,7 +194,7 @@ interface IEmbeddingSchema {
192
194
  * @returns {Promise<Embeddings>} A promise resolving to the generated embedding as an array of numbers.
193
195
  * @throws {Error} If embedding creation fails (e.g., due to invalid text or model errors).
194
196
  */
195
- createEmbedding(text: string): Promise<Embeddings>;
197
+ createEmbedding(text: string, embeddingName: EmbeddingName): Promise<Embeddings>;
196
198
  /**
197
199
  * Calculates the similarity between two embeddings.
198
200
  * Commonly used for search or ranking operations (e.g., cosine similarity).
@@ -202,6 +204,25 @@ interface IEmbeddingSchema {
202
204
  * @throws {Error} If similarity calculation fails (e.g., due to invalid embeddings or computation errors).
203
205
  */
204
206
  calculateSimilarity(a: Embeddings, b: Embeddings): Promise<number>;
207
+ /**
208
+ * Stores an embedding vector for a specific string hash, persisting it for future retrieval.
209
+ * Used to cache computed embeddings to avoid redundant processing.
210
+ * @param embeddings - Array of numerical values representing the embedding vector.
211
+ * @param embeddingName - The identifier of the embedding type.
212
+ * @param stringHash - The hash of the string for which the embedding was generated.
213
+ * @returns A promise that resolves when the embedding vector is persisted.
214
+ * @throws {Error} If writing to storage fails (e.g., permissions or disk space).
215
+ */
216
+ writeEmbeddingCache?: (embeddings: number[], embeddingName: EmbeddingName, stringHash: string) => Promise<void> | void;
217
+ /**
218
+ * Retrieves the embedding vector for a specific string hash, returning null if not found.
219
+ * Used to check if a precomputed embedding exists in the cache.
220
+ * @param embeddingName - The identifier of the embedding type.
221
+ * @param stringHash - The hash of the string for which the embedding was generated.
222
+ * @returns A promise resolving to the embedding vector or null if not cached.
223
+ * @throws {Error} If reading from storage fails (e.g., file corruption).
224
+ */
225
+ readEmbeddingCache?: (embeddingName: EmbeddingName, stringHash: string) => Promise<number[] | null> | number[] | null;
205
226
  /** Optional partial set of callbacks for embedding events, allowing customization of creation and comparison. */
206
227
  callbacks?: Partial<IEmbeddingCallbacks>;
207
228
  }
@@ -325,6 +346,25 @@ interface IStorageParams<T extends IStorageData = IStorageData> extends IStorage
325
346
  * Used for search operations.
326
347
  */
327
348
  calculateSimilarity: IEmbeddingSchema["calculateSimilarity"];
349
+ /**
350
+ * Stores an embedding vector for a specific string hash, persisting it for future retrieval.
351
+ * Used to cache computed embeddings to avoid redundant processing.
352
+ * @param embeddings - Array of numerical values representing the embedding vector.
353
+ * @param embeddingName - The identifier of the embedding type.
354
+ * @param stringHash - The hash of the string for which the embedding was generated.
355
+ * @returns A promise that resolves when the embedding vector is persisted.
356
+ * @throws {Error} If writing to storage fails (e.g., permissions or disk space).
357
+ */
358
+ writeEmbeddingCache: IEmbeddingSchema["writeEmbeddingCache"];
359
+ /**
360
+ * Retrieves the embedding vector for a specific string hash, returning null if not found.
361
+ * Used to check if a precomputed embedding exists in the cache.
362
+ * @param embeddingName - The identifier of the embedding type.
363
+ * @param stringHash - The hash of the string for which the embedding was generated.
364
+ * @returns A promise resolving to the embedding vector or null if not cached.
365
+ * @throws {Error} If reading from storage fails (e.g., file corruption).
366
+ */
367
+ readEmbeddingCache: IEmbeddingSchema["readEmbeddingCache"];
328
368
  /**
329
369
  * Function to create an embedding for storage items, inherited from the embedding schema.
330
370
  * Used for indexing.
@@ -2363,6 +2403,76 @@ declare class PersistPolicyUtils implements IPersistPolicyControl {
2363
2403
  * @type {IPersistPolicyControl}
2364
2404
  */
2365
2405
  declare const PersistPolicy: IPersistPolicyControl;
2406
+ /**
2407
+ * Defines the structure for embedding data persistence in the swarm system.
2408
+ * Stores numerical embeddings for a `stringHash` within an `EmbeddingName`.
2409
+ * @interface IPersistEmbeddingData
2410
+ */
2411
+ interface IPersistEmbeddingData {
2412
+ /** Array of numerical values representing the embedding vector */
2413
+ embeddings: number[];
2414
+ }
2415
+ /**
2416
+ * Defines control methods for customizing embedding persistence operations.
2417
+ * Allows injection of a custom persistence adapter for embedding data tied to `EmbeddingName`.
2418
+ * @interface IPersistEmbeddingControl
2419
+ */
2420
+ interface IPersistEmbeddingControl {
2421
+ /**
2422
+ * Sets a custom persistence adapter for embedding data storage.
2423
+ * Overrides the default `PersistBase` implementation for specialized behavior (e.g., in-memory tracking for `SwarmName`).
2424
+ * @param {TPersistBaseCtor<SwarmName, IPersistEmbeddingData>} Ctor - The constructor for the embedding data persistence adapter.
2425
+ */
2426
+ usePersistEmbeddingAdapter(Ctor: TPersistBaseCtor<SwarmName, IPersistEmbeddingData>): void;
2427
+ }
2428
+ /**
2429
+ * Utility class for managing embedding data persistence in the swarm system.
2430
+ * Provides methods to read and write embedding vectors with a customizable adapter.
2431
+ * @implements {IPersistEmbeddingControl}
2432
+ */
2433
+ declare class PersistEmbeddingUtils implements IPersistEmbeddingControl {
2434
+ /** @private Default constructor for embedding data persistence, defaults to `PersistBase` */
2435
+ private PersistEmbeddingFactory;
2436
+ /**
2437
+ * Memoized function to create or retrieve storage for specific embedding data.
2438
+ * Ensures a single persistence instance per embedding name, optimizing resource use.
2439
+ * @private
2440
+ * @param embeddingName - The identifier of the embedding type.
2441
+ * @returns A persistence instance for the embedding data, rooted at `./logs/data/embedding/`.
2442
+ */
2443
+ private getEmbeddingStorage;
2444
+ /**
2445
+ * Configures a custom constructor for embedding data persistence, overriding the default `PersistBase`.
2446
+ * Enables advanced tracking (e.g., in-memory or database-backed persistence).
2447
+ * @param Ctor - The constructor to use for embedding data storage, implementing `IPersistBase`.
2448
+ */
2449
+ usePersistEmbeddingAdapter(Ctor: TPersistBaseCtor<SwarmName, IPersistEmbeddingData>): void;
2450
+ /**
2451
+ * Retrieves the embedding vector for a specific string hash, returning null if not found.
2452
+ * Used to check if a precomputed embedding exists in the cache.
2453
+ * @param embeddingName - The identifier of the embedding type.
2454
+ * @param stringHash - The hash of the string for which the embedding was generated.
2455
+ * @returns A promise resolving to the embedding vector or null if not cached.
2456
+ * @throws {Error} If reading from storage fails (e.g., file corruption).
2457
+ */
2458
+ readEmbeddingCache: (embeddingName: EmbeddingName, stringHash: string) => Promise<number[] | null>;
2459
+ /**
2460
+ * Stores an embedding vector for a specific string hash, persisting it for future retrieval.
2461
+ * Used to cache computed embeddings to avoid redundant processing.
2462
+ * @param embeddings - Array of numerical values representing the embedding vector.
2463
+ * @param embeddingName - The identifier of the embedding type.
2464
+ * @param stringHash - The hash of the string for which the embedding was generated.
2465
+ * @returns A promise that resolves when the embedding vector is persisted.
2466
+ * @throws {Error} If writing to storage fails (e.g., permissions or disk space).
2467
+ */
2468
+ writeEmbeddingCache: (embeddings: number[], embeddingName: EmbeddingName, stringHash: string) => Promise<void>;
2469
+ }
2470
+ /**
2471
+ * Exported singleton for embedding persistence operations, cast as the control interface.
2472
+ * Provides a global point of access for managing embedding cache in the system.
2473
+ * @type {IPersistEmbeddingControl}
2474
+ */
2475
+ declare const PersistEmbedding: IPersistEmbeddingControl;
2366
2476
 
2367
2477
  /**
2368
2478
  * Callbacks for managing history instance lifecycle and message handling.
@@ -10100,6 +10210,25 @@ interface IGlobalConfig {
10100
10210
  * @type {boolean}
10101
10211
  */
10102
10212
  CC_PERSIST_MEMORY_STORAGE: boolean;
10213
+ /**
10214
+ * Retrieves the embedding vector for a specific string hash, returning null if not found.
10215
+ * Used to check if a precomputed embedding exists in the cache.
10216
+ * @param embeddingName - The identifier of the embedding type.
10217
+ * @param stringHash - The hash of the string for which the embedding was generated.
10218
+ * @returns A promise resolving to the embedding vector or null if not cached.
10219
+ * @throws {Error} If reading from storage fails (e.g., file corruption).
10220
+ */
10221
+ CC_DEFAULT_READ_EMBEDDING_CACHE: (embeddingName: EmbeddingName, stringHash: string) => Promise<number[] | null> | number[] | null;
10222
+ /**
10223
+ * Stores an embedding vector for a specific string hash, persisting it for future retrieval.
10224
+ * Used to cache computed embeddings to avoid redundant processing.
10225
+ * @param embeddings - Array of numerical values representing the embedding vector.
10226
+ * @param embeddingName - The identifier of the embedding type.
10227
+ * @param stringHash - The hash of the string for which the embedding was generated.
10228
+ * @returns A promise that resolves when the embedding vector is persisted.
10229
+ * @throws {Error} If writing to storage fails (e.g., permissions or disk space).
10230
+ */
10231
+ CC_DEFAULT_WRITE_EMBEDDING_CACHE: (embeddings: number[], embeddingName: EmbeddingName, stringHash: string) => Promise<void> | void;
10103
10232
  }
10104
10233
 
10105
10234
  declare const GLOBAL_CONFIG: IGlobalConfig;
@@ -10642,6 +10771,7 @@ declare const Utils: {
10642
10771
  PersistMemoryUtils: typeof PersistMemoryUtils;
10643
10772
  PersistAliveUtils: typeof PersistAliveUtils;
10644
10773
  PersistPolicyUtils: typeof PersistPolicyUtils;
10774
+ PersistEmbeddingUtils: typeof PersistEmbeddingUtils;
10645
10775
  };
10646
10776
 
10647
- export { Adapter, type EventSource, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type ICompletionArgs, type ICompletionSchema, type ICustomEvent, type IEmbeddingSchema, type IGlobalConfig, type IHistoryAdapter, type IHistoryControl, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type IPersistActiveAgentData, type IPersistAliveData, type IPersistBase, type IPersistMemoryData, type IPersistNavigationStackData, type IPersistPolicyData, type IPersistStateData, type IPersistStorageData, type IPolicySchema, type ISessionConfig, type IStateSchema, type IStorageData, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, Logger, LoggerInstance, MethodContextService, PayloadContextService, PersistAlive, PersistBase, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, type ReceiveMessageFn, Schema, type SendMessageFn, SharedState, SharedStorage, State, Storage, type THistoryInstanceCtor, type THistoryMemoryInstance, type THistoryPersistInstance, type TLoggerInstance, type TPersistBase, type TPersistBaseCtor, type TPersistList, Utils, addAgent, addCompletion, addEmbedding, addPolicy, addState, addStorage, addSwarm, addTool, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpClientPerformance, dumpDocs, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getPayload, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, runStateless, runStatelessForce, session, setConfig, swarm };
10777
+ export { Adapter, type EventSource, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type ICompletionArgs, type ICompletionSchema, type ICustomEvent, type IEmbeddingSchema, type IGlobalConfig, type IHistoryAdapter, type IHistoryControl, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type IPersistActiveAgentData, type IPersistAliveData, type IPersistBase, type IPersistEmbeddingData, type IPersistMemoryData, type IPersistNavigationStackData, type IPersistPolicyData, type IPersistStateData, type IPersistStorageData, type IPolicySchema, type ISessionConfig, type IStateSchema, type IStorageData, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, Logger, LoggerInstance, MethodContextService, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, type ReceiveMessageFn, Schema, type SendMessageFn, SharedState, SharedStorage, State, Storage, type THistoryInstanceCtor, type THistoryMemoryInstance, type THistoryPersistInstance, type TLoggerInstance, type TPersistBase, type TPersistBaseCtor, type TPersistList, Utils, addAgent, addCompletion, addEmbedding, addPolicy, addState, addStorage, addSwarm, addTool, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpClientPerformance, dumpDocs, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getPayload, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, runStateless, runStatelessForce, session, setConfig, swarm };