agent-swarm-kit 1.1.181 → 1.1.182
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 +491 -483
- package/build/index.mjs +492 -484
- package/package.json +1 -1
- package/types.d.ts +409 -482
package/build/index.cjs
CHANGED
|
@@ -442,7 +442,7 @@ async function writeFileAtomic(file, data, options = {}) {
|
|
|
442
442
|
}
|
|
443
443
|
}
|
|
444
444
|
|
|
445
|
-
var _a$4, _b$
|
|
445
|
+
var _a$4, _b$1, _c, _d;
|
|
446
446
|
/** @private Symbol for memoizing the wait-for-initialization operation in PersistBase*/
|
|
447
447
|
const BASE_WAIT_FOR_INIT_SYMBOL = Symbol("wait-for-init");
|
|
448
448
|
/** @private Symbol for creating a new key in a persistent list*/
|
|
@@ -549,7 +549,7 @@ const BASE_UNLINK_RETRY_DELAY = 1000;
|
|
|
549
549
|
* Attempts to remove a file if invalid JSON is detected during initialization.
|
|
550
550
|
* Retries the operation multiple times with delays to handle transient errors, ensuring robust setup.
|
|
551
551
|
* @private
|
|
552
|
-
*/
|
|
552
|
+
*/
|
|
553
553
|
const BASE_WAIT_FOR_INIT_UNLINK_FN = async (filePath) => functoolsKit.trycatch(functoolsKit.retry(async () => {
|
|
554
554
|
try {
|
|
555
555
|
await fs.unlink(filePath);
|
|
@@ -567,7 +567,7 @@ const BASE_WAIT_FOR_INIT_UNLINK_FN = async (filePath) => functoolsKit.trycatch(f
|
|
|
567
567
|
* Ensures the persistence layer is robust by cleaning up corrupted files during setup (e.g., for swarm or session data).
|
|
568
568
|
* @private
|
|
569
569
|
* @throws {Error} If directory creation or file validation fails (e.g., permissions or I/O errors).
|
|
570
|
-
*/
|
|
570
|
+
*/
|
|
571
571
|
const BASE_WAIT_FOR_INIT_FN = async (self) => {
|
|
572
572
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
573
573
|
swarm$1.loggerService.debug(BASE_WAIT_FOR_INIT_FN_METHOD_NAME, {
|
|
@@ -593,7 +593,7 @@ const BASE_WAIT_FOR_INIT_FN = async (self) => {
|
|
|
593
593
|
* Initializes the last count by scanning existing keys if not already set, used in `PersistList` for ordered storage.
|
|
594
594
|
* @private
|
|
595
595
|
* @throws {Error} If key generation fails due to underlying storage issues (e.g., directory access).
|
|
596
|
-
*/
|
|
596
|
+
*/
|
|
597
597
|
const LIST_CREATE_KEY_FN = async (self) => {
|
|
598
598
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
599
599
|
swarm$1.loggerService.debug(LIST_CREATE_KEY_FN_METHOD_NAME, {
|
|
@@ -618,7 +618,7 @@ const LIST_CREATE_KEY_FN = async (self) => {
|
|
|
618
618
|
* Uses the last key to fetch and delete the item atomically, ensuring consistency in list operations.
|
|
619
619
|
* @private
|
|
620
620
|
* @throws {Error} If reading or removing the item fails (e.g., file not found or permissions).
|
|
621
|
-
*/
|
|
621
|
+
*/
|
|
622
622
|
const LIST_POP_FN = async (self) => {
|
|
623
623
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
624
624
|
swarm$1.loggerService.debug(LIST_POP_FN_METHOD_NAME, {
|
|
@@ -648,7 +648,7 @@ const LIST_POP_FN = async (self) => {
|
|
|
648
648
|
* Determines the highest numeric key value for ordered list management (e.g., dequeuing events).
|
|
649
649
|
* @private
|
|
650
650
|
* @throws {Error} If key retrieval fails due to underlying storage issues (e.g., directory access).
|
|
651
|
-
*/
|
|
651
|
+
*/
|
|
652
652
|
const LIST_GET_LAST_KEY_FN = async (self) => {
|
|
653
653
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
654
654
|
swarm$1.loggerService.debug(LIST_GET_LAST_KEY_FN_METHOD_NAME, {
|
|
@@ -671,12 +671,12 @@ const LIST_GET_LAST_KEY_FN = async (self) => {
|
|
|
671
671
|
* Provides foundational methods for reading, writing, and managing entities as JSON files, supporting swarm utilities like `PersistAliveUtils`.
|
|
672
672
|
* @template EntityName - The type of entity name (e.g., `SwarmName`, `SessionId`), defaults to `string`, used as a subdirectory.
|
|
673
673
|
* @implements {IPersistBase}
|
|
674
|
-
*/
|
|
675
|
-
|
|
674
|
+
*/
|
|
675
|
+
class PersistBase {
|
|
676
676
|
/**
|
|
677
677
|
* Creates a new `PersistBase` instance for managing persistent storage of entities.
|
|
678
678
|
* Sets up the storage directory based on the entity name (e.g., `SwarmName` for swarm-specific data) and base directory.
|
|
679
|
-
|
|
679
|
+
*/
|
|
680
680
|
constructor(entityName, baseDir = path.join(process.cwd(), "logs/data")) {
|
|
681
681
|
this.entityName = entityName;
|
|
682
682
|
this.baseDir = baseDir;
|
|
@@ -684,7 +684,7 @@ const PersistBase = functoolsKit.makeExtendable(class {
|
|
|
684
684
|
* Memoized initialization function ensuring it runs only once per instance.
|
|
685
685
|
* Uses `singleshot` to prevent redundant initialization calls, critical for swarm setup efficiency.
|
|
686
686
|
* @private
|
|
687
|
-
|
|
687
|
+
*/
|
|
688
688
|
this[_a$4] = functoolsKit.singleshot(async () => await BASE_WAIT_FOR_INIT_FN(this));
|
|
689
689
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
690
690
|
swarm$1.loggerService.debug(PERSIST_BASE_METHOD_NAME_CTOR, {
|
|
@@ -696,7 +696,7 @@ const PersistBase = functoolsKit.makeExtendable(class {
|
|
|
696
696
|
/**
|
|
697
697
|
* Computes the full file path for an entity based on its ID.
|
|
698
698
|
* @private
|
|
699
|
-
|
|
699
|
+
*/
|
|
700
700
|
_getFilePath(entityId) {
|
|
701
701
|
return path.join(this.baseDir, this.entityName, `${entityId}.json`);
|
|
702
702
|
}
|
|
@@ -704,7 +704,7 @@ const PersistBase = functoolsKit.makeExtendable(class {
|
|
|
704
704
|
* Initializes the storage directory, creating it if it doesn’t exist, and validates existing entities.
|
|
705
705
|
* Removes invalid JSON files during initialization to ensure data integrity (e.g., for `SwarmName`-based alive status).
|
|
706
706
|
* @throws {Error} If directory creation or entity validation fails (e.g., permissions or I/O errors).
|
|
707
|
-
|
|
707
|
+
*/
|
|
708
708
|
async waitForInit(initial) {
|
|
709
709
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
710
710
|
swarm$1.loggerService.debug(PERSIST_BASE_METHOD_NAME_WAIT_FOR_INIT, {
|
|
@@ -717,7 +717,7 @@ const PersistBase = functoolsKit.makeExtendable(class {
|
|
|
717
717
|
* Retrieves the number of entities stored in the directory.
|
|
718
718
|
* Counts only files with a `.json` extension, useful for monitoring storage usage (e.g., active sessions).
|
|
719
719
|
* @throws {Error} If reading the directory fails (e.g., permissions or directory not found).
|
|
720
|
-
|
|
720
|
+
*/
|
|
721
721
|
async getCount() {
|
|
722
722
|
const files = await fs.readdir(this._directory);
|
|
723
723
|
const { length } = files.filter((file) => file.endsWith(".json"));
|
|
@@ -728,7 +728,7 @@ const PersistBase = functoolsKit.makeExtendable(class {
|
|
|
728
728
|
* Core method for retrieving persisted data (e.g., alive status for a `SessionId` in a `SwarmName` context).
|
|
729
729
|
* @template T - The specific type of the entity (e.g., `IPersistAliveData`), defaults to `IEntity`.
|
|
730
730
|
* @throws {Error} If the file is not found (`ENOENT`) or parsing fails (e.g., invalid JSON).
|
|
731
|
-
|
|
731
|
+
*/
|
|
732
732
|
async readValue(entityId) {
|
|
733
733
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
734
734
|
swarm$1.loggerService.debug(PERSIST_BASE_METHOD_NAME_READ_VALUE, {
|
|
@@ -751,7 +751,7 @@ const PersistBase = functoolsKit.makeExtendable(class {
|
|
|
751
751
|
* Checks if an entity exists in storage by its ID.
|
|
752
752
|
* Efficiently verifies presence without reading the full entity (e.g., checking if a `SessionId` has memory).
|
|
753
753
|
* @throws {Error} If checking existence fails for reasons other than the file not existing.
|
|
754
|
-
|
|
754
|
+
*/
|
|
755
755
|
async hasValue(entityId) {
|
|
756
756
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
757
757
|
swarm$1.loggerService.debug(PERSIST_BASE_METHOD_NAME_HAS_VALUE, {
|
|
@@ -775,7 +775,7 @@ const PersistBase = functoolsKit.makeExtendable(class {
|
|
|
775
775
|
* Uses atomic file writing via `writeFileAtomic` to ensure data integrity (e.g., persisting `AgentName` for a `SwarmName`).
|
|
776
776
|
* @template T - The specific type of the entity (e.g., `IPersistActiveAgentData`), defaults to `IEntity`.
|
|
777
777
|
* @throws {Error} If writing to the file system fails (e.g., permissions or disk space).
|
|
778
|
-
|
|
778
|
+
*/
|
|
779
779
|
async writeValue(entityId, entity) {
|
|
780
780
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
781
781
|
swarm$1.loggerService.debug(PERSIST_BASE_METHOD_NAME_WRITE_VALUE, {
|
|
@@ -795,7 +795,7 @@ const PersistBase = functoolsKit.makeExtendable(class {
|
|
|
795
795
|
* Removes an entity from storage by its ID.
|
|
796
796
|
* Deletes the corresponding JSON file, used for cleanup (e.g., removing a `SessionId`’s memory).
|
|
797
797
|
* @throws {Error} If the entity is not found (`ENOENT`) or deletion fails (e.g., permissions).
|
|
798
|
-
|
|
798
|
+
*/
|
|
799
799
|
async removeValue(entityId) {
|
|
800
800
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
801
801
|
swarm$1.loggerService.debug(PERSIST_BASE_METHOD_NAME_REMOVE_VALUE, {
|
|
@@ -817,7 +817,7 @@ const PersistBase = functoolsKit.makeExtendable(class {
|
|
|
817
817
|
* Removes all entities from storage under this entity name.
|
|
818
818
|
* Deletes all `.json` files in the directory, useful for resetting persistence (e.g., clearing a `SwarmName`’s data).
|
|
819
819
|
* @throws {Error} If reading the directory or deleting files fails (e.g., permissions).
|
|
820
|
-
|
|
820
|
+
*/
|
|
821
821
|
async removeAll() {
|
|
822
822
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
823
823
|
swarm$1.loggerService.debug(PERSIST_BASE_METHOD_NAME_REMOVE_ALL, {
|
|
@@ -839,7 +839,7 @@ const PersistBase = functoolsKit.makeExtendable(class {
|
|
|
839
839
|
* Yields entities in ascending order, useful for batch processing (e.g., listing all `SessionId`s in a `SwarmName`).
|
|
840
840
|
* @template T - The specific type of the entities (e.g., `IPersistAliveData`), defaults to `IEntity`.
|
|
841
841
|
* @throws {Error} If reading the directory or entity files fails (e.g., permissions or invalid JSON).
|
|
842
|
-
|
|
842
|
+
*/
|
|
843
843
|
async *values() {
|
|
844
844
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
845
845
|
swarm$1.loggerService.debug(PERSIST_BASE_METHOD_NAME_VALUES, {
|
|
@@ -867,7 +867,7 @@ const PersistBase = functoolsKit.makeExtendable(class {
|
|
|
867
867
|
* Iterates over all entity IDs in storage, sorted numerically.
|
|
868
868
|
* Yields IDs in ascending order, useful for key enumeration (e.g., listing `SessionId`s in a `SwarmName`).
|
|
869
869
|
* @throws {Error} If reading the directory fails (e.g., permissions or directory not found).
|
|
870
|
-
|
|
870
|
+
*/
|
|
871
871
|
async *keys() {
|
|
872
872
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
873
873
|
swarm$1.loggerService.debug(PERSIST_BASE_METHOD_NAME_KEYS, {
|
|
@@ -893,7 +893,7 @@ const PersistBase = functoolsKit.makeExtendable(class {
|
|
|
893
893
|
/**
|
|
894
894
|
* Implements the async iterator protocol for iterating over entities.
|
|
895
895
|
* Delegates to the `values` method for iteration, enabling `for await` loops over entities.
|
|
896
|
-
|
|
896
|
+
*/
|
|
897
897
|
async *[(_a$4 = BASE_WAIT_FOR_INIT_SYMBOL, Symbol.asyncIterator)]() {
|
|
898
898
|
for await (const entity of this.values()) {
|
|
899
899
|
yield entity;
|
|
@@ -904,7 +904,7 @@ const PersistBase = functoolsKit.makeExtendable(class {
|
|
|
904
904
|
* Useful for selective retrieval (e.g., finding online `SessionId`s in a `SwarmName`).
|
|
905
905
|
* @template T - The specific type of the entities (e.g., `IPersistAliveData`), defaults to `IEntity`.
|
|
906
906
|
* @throws {Error} If reading entities fails during iteration (e.g., invalid JSON).
|
|
907
|
-
|
|
907
|
+
*/
|
|
908
908
|
async *filter(predicate) {
|
|
909
909
|
for await (const entity of this.values()) {
|
|
910
910
|
if (predicate(entity)) {
|
|
@@ -917,7 +917,7 @@ const PersistBase = functoolsKit.makeExtendable(class {
|
|
|
917
917
|
* Stops yielding after reaching the specified total, useful for pagination (e.g., sampling `SessionId`s).
|
|
918
918
|
* @template T - The specific type of the entities (e.g., `IPersistStateData`), defaults to `IEntity`.
|
|
919
919
|
* @throws {Error} If reading entities fails during iteration (e.g., permissions).
|
|
920
|
-
|
|
920
|
+
*/
|
|
921
921
|
async *take(total, predicate) {
|
|
922
922
|
let count = 0;
|
|
923
923
|
if (predicate) {
|
|
@@ -942,86 +942,87 @@ const PersistBase = functoolsKit.makeExtendable(class {
|
|
|
942
942
|
}
|
|
943
943
|
}
|
|
944
944
|
}
|
|
945
|
-
}
|
|
945
|
+
}
|
|
946
|
+
// @ts-ignore
|
|
947
|
+
PersistBase = functoolsKit.makeExtendable(PersistBase);
|
|
946
948
|
/**
|
|
947
949
|
* Extends `PersistBase` to provide a persistent list structure with push/pop operations.
|
|
948
950
|
* Manages entities with numeric keys for ordered access, suitable for queues or logs in the swarm system.
|
|
949
951
|
* @template EntityName - The type of entity name (e.g., `SwarmName`), defaults to `string`, used as a subdirectory.
|
|
950
952
|
* @extends {PersistBase<EntityName>}
|
|
951
|
-
*/
|
|
952
|
-
|
|
953
|
+
*/
|
|
954
|
+
class PersistList extends PersistBase {
|
|
955
|
+
/**
|
|
956
|
+
* Creates a new `PersistList` instance for managing a persistent list of entities.
|
|
957
|
+
* Inherits directory setup from `PersistBase` and adds list-specific functionality (e.g., for `SwarmName`-based event logs).
|
|
958
|
+
*/
|
|
959
|
+
constructor(entityName, baseDir) {
|
|
960
|
+
super(entityName, baseDir);
|
|
961
|
+
/** @private Tracks the last used numeric key for the list, initialized to `null` until computed*/
|
|
962
|
+
this._lastCount = null;
|
|
953
963
|
/**
|
|
954
|
-
*
|
|
955
|
-
*
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
this._lastCount = null;
|
|
961
|
-
/**
|
|
962
|
-
* Queued function to create a new unique key for a list item.
|
|
963
|
-
* Ensures sequential key generation under concurrent calls using `queued` decorator.
|
|
964
|
-
* @private
|
|
965
|
-
* @throws {Error} If key generation fails due to underlying storage issues.
|
|
966
|
-
*/
|
|
967
|
-
this[_b$2] = functoolsKit.queued(async () => await LIST_CREATE_KEY_FN(this));
|
|
968
|
-
/**
|
|
969
|
-
* Retrieves the key of the last item in the list.
|
|
970
|
-
* Scans all keys to find the highest numeric value, used for pop operations (e.g., dequeuing from a `SwarmName` log).
|
|
971
|
-
* @private
|
|
972
|
-
* @throws {Error} If key retrieval fails due to underlying storage issues.
|
|
973
|
-
*/
|
|
974
|
-
this[_c$1] = async () => await LIST_GET_LAST_KEY_FN(this);
|
|
975
|
-
/**
|
|
976
|
-
* Queued function to remove and return the last item in the list.
|
|
977
|
-
* Ensures atomic pop operations under concurrent calls using `queued` decorator.
|
|
978
|
-
* @private
|
|
979
|
-
* @template T - The specific type of the entity (e.g., `IPersistStateData`), defaults to `IEntity`.
|
|
980
|
-
* @throws {Error} If reading or removing the item fails.
|
|
981
|
-
*/
|
|
982
|
-
this[_d$1] = functoolsKit.queued(async () => await LIST_POP_FN(this));
|
|
983
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
984
|
-
swarm$1.loggerService.debug(PERSIST_LIST_METHOD_NAME_CTOR, {
|
|
985
|
-
entityName: this.entityName,
|
|
986
|
-
baseDir,
|
|
987
|
-
});
|
|
988
|
-
}
|
|
964
|
+
* Queued function to create a new unique key for a list item.
|
|
965
|
+
* Ensures sequential key generation under concurrent calls using `queued` decorator.
|
|
966
|
+
* @private
|
|
967
|
+
* @throws {Error} If key generation fails due to underlying storage issues.
|
|
968
|
+
*/
|
|
969
|
+
this[_b$1] = functoolsKit.queued(async () => await LIST_CREATE_KEY_FN(this));
|
|
989
970
|
/**
|
|
990
|
-
*
|
|
991
|
-
*
|
|
992
|
-
* @
|
|
993
|
-
* @throws {Error} If
|
|
994
|
-
|
|
995
|
-
async
|
|
996
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
997
|
-
swarm$1.loggerService.debug(PERSIST_LIST_METHOD_NAME_PUSH, {
|
|
998
|
-
entityName: this.entityName,
|
|
999
|
-
});
|
|
1000
|
-
return await this.writeValue(await this[LIST_CREATE_KEY_SYMBOL](), entity);
|
|
1001
|
-
}
|
|
971
|
+
* Retrieves the key of the last item in the list.
|
|
972
|
+
* Scans all keys to find the highest numeric value, used for pop operations (e.g., dequeuing from a `SwarmName` log).
|
|
973
|
+
* @private
|
|
974
|
+
* @throws {Error} If key retrieval fails due to underlying storage issues.
|
|
975
|
+
*/
|
|
976
|
+
this[_c] = async () => await LIST_GET_LAST_KEY_FN(this);
|
|
1002
977
|
/**
|
|
1003
|
-
*
|
|
1004
|
-
*
|
|
978
|
+
* Queued function to remove and return the last item in the list.
|
|
979
|
+
* Ensures atomic pop operations under concurrent calls using `queued` decorator.
|
|
980
|
+
* @private
|
|
1005
981
|
* @template T - The specific type of the entity (e.g., `IPersistStateData`), defaults to `IEntity`.
|
|
1006
|
-
* @throws {Error} If reading or removing the
|
|
1007
|
-
|
|
1008
|
-
async
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
982
|
+
* @throws {Error} If reading or removing the item fails.
|
|
983
|
+
*/
|
|
984
|
+
this[_d] = functoolsKit.queued(async () => await LIST_POP_FN(this));
|
|
985
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
986
|
+
swarm$1.loggerService.debug(PERSIST_LIST_METHOD_NAME_CTOR, {
|
|
987
|
+
entityName: this.entityName,
|
|
988
|
+
baseDir,
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* Adds an entity to the end of the persistent list with a new unique numeric key.
|
|
993
|
+
* Useful for appending items like messages or events in swarm operations (e.g., within a `SwarmName`).
|
|
994
|
+
* @template T - The specific type of the entity (e.g., `IPersistStateData`), defaults to `IEntity`.
|
|
995
|
+
* @throws {Error} If writing to the file system fails (e.g., permissions or disk space).
|
|
996
|
+
*/
|
|
997
|
+
async push(entity) {
|
|
998
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
999
|
+
swarm$1.loggerService.debug(PERSIST_LIST_METHOD_NAME_PUSH, {
|
|
1000
|
+
entityName: this.entityName,
|
|
1001
|
+
});
|
|
1002
|
+
return await this.writeValue(await this[LIST_CREATE_KEY_SYMBOL](), entity);
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Removes and returns the last entity from the persistent list.
|
|
1006
|
+
* Useful for dequeuing items or retrieving recent entries (e.g., latest event in a `SwarmName` log).
|
|
1007
|
+
* @template T - The specific type of the entity (e.g., `IPersistStateData`), defaults to `IEntity`.
|
|
1008
|
+
* @throws {Error} If reading or removing the entity fails (e.g., file not found).
|
|
1009
|
+
*/
|
|
1010
|
+
async pop() {
|
|
1011
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1012
|
+
swarm$1.loggerService.debug(PERSIST_LIST_METHOD_NAME_POP, {
|
|
1013
|
+
entityName: this.entityName,
|
|
1014
|
+
});
|
|
1015
|
+
return await this[LIST_POP_SYMBOL]();
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
_b$1 = LIST_CREATE_KEY_SYMBOL, _c = LIST_GET_LAST_KEY_SYMBOL, _d = LIST_POP_SYMBOL;
|
|
1019
|
+
// @ts-ignore
|
|
1020
|
+
PersistList = functoolsKit.makeExtendable(PersistList);
|
|
1020
1021
|
/**
|
|
1021
1022
|
* Utility class for managing swarm-related persistence, including active agents and navigation stacks.
|
|
1022
1023
|
* Provides methods to get/set active agents and navigation stacks per client (`SessionId`) and swarm (`SwarmName`), with customizable adapters.
|
|
1023
1024
|
* @implements {IPersistSwarmControl}
|
|
1024
|
-
*/
|
|
1025
|
+
*/
|
|
1025
1026
|
class PersistSwarmUtils {
|
|
1026
1027
|
constructor() {
|
|
1027
1028
|
/** @private Default constructor for active agent persistence, defaults to `PersistBase`*/
|
|
@@ -1141,18 +1142,18 @@ class PersistSwarmUtils {
|
|
|
1141
1142
|
}
|
|
1142
1143
|
/**
|
|
1143
1144
|
* Singleton instance of `PersistSwarmUtils` for managing swarm persistence globally.
|
|
1144
|
-
*/
|
|
1145
|
+
*/
|
|
1145
1146
|
const PersistSwarmAdapter = new PersistSwarmUtils();
|
|
1146
1147
|
/**
|
|
1147
1148
|
* Exported singleton for swarm persistence operations, cast as the control interface.
|
|
1148
1149
|
* Provides a global point of access for managing active agents and navigation stacks tied to `SwarmName`.
|
|
1149
|
-
*/
|
|
1150
|
+
*/
|
|
1150
1151
|
const PersistSwarm = PersistSwarmAdapter;
|
|
1151
1152
|
/**
|
|
1152
1153
|
* Utility class for managing state persistence per client (`SessionId`) and state name (`StateName`) in the swarm system.
|
|
1153
1154
|
* Provides methods to get/set state data with a customizable persistence adapter.
|
|
1154
1155
|
* @implements {IPersistStateControl}
|
|
1155
|
-
*/
|
|
1156
|
+
*/
|
|
1156
1157
|
class PersistStateUtils {
|
|
1157
1158
|
constructor() {
|
|
1158
1159
|
/** @private Default constructor for state persistence, defaults to `PersistBase`*/
|
|
@@ -1217,18 +1218,18 @@ class PersistStateUtils {
|
|
|
1217
1218
|
}
|
|
1218
1219
|
/**
|
|
1219
1220
|
* Singleton instance of `PersistStateUtils` for managing state persistence globally.
|
|
1220
|
-
*/
|
|
1221
|
+
*/
|
|
1221
1222
|
const PersistStateAdapter = new PersistStateUtils();
|
|
1222
1223
|
/**
|
|
1223
1224
|
* Exported singleton for state persistence operations, cast as the control interface.
|
|
1224
1225
|
* Provides a global point of access for managing state persistence tied to `StateName` and `SessionId`.
|
|
1225
|
-
*/
|
|
1226
|
+
*/
|
|
1226
1227
|
const PersistState = PersistStateAdapter;
|
|
1227
1228
|
/**
|
|
1228
1229
|
* Utility class for managing storage persistence per client (`SessionId`) and storage name (`StorageName`) in the swarm system.
|
|
1229
1230
|
* Provides methods to get/set storage data with a customizable persistence adapter.
|
|
1230
1231
|
* @implements {IPersistStorageControl}
|
|
1231
|
-
*/
|
|
1232
|
+
*/
|
|
1232
1233
|
class PersistStorageUtils {
|
|
1233
1234
|
constructor() {
|
|
1234
1235
|
/** @private Default constructor for storage persistence, defaults to `PersistBase`*/
|
|
@@ -1293,18 +1294,18 @@ class PersistStorageUtils {
|
|
|
1293
1294
|
}
|
|
1294
1295
|
/**
|
|
1295
1296
|
* Singleton instance of `PersistStorageUtils` for managing storage persistence globally.
|
|
1296
|
-
*/
|
|
1297
|
+
*/
|
|
1297
1298
|
const PersistStorageAdapter = new PersistStorageUtils();
|
|
1298
1299
|
/**
|
|
1299
1300
|
* Exported singleton for storage persistence operations, cast as the control interface.
|
|
1300
1301
|
* Provides a global point of access for managing storage persistence tied to `StorageName` and `SessionId`.
|
|
1301
|
-
*/
|
|
1302
|
+
*/
|
|
1302
1303
|
const PersistStorage = PersistStorageAdapter;
|
|
1303
1304
|
/**
|
|
1304
1305
|
* Utility class for managing memory persistence per client (`SessionId`) in the swarm system.
|
|
1305
1306
|
* Provides methods to get/set memory data with a customizable persistence adapter.
|
|
1306
1307
|
* @implements {IPersistMemoryControl}
|
|
1307
|
-
*/
|
|
1308
|
+
*/
|
|
1308
1309
|
class PersistMemoryUtils {
|
|
1309
1310
|
constructor() {
|
|
1310
1311
|
/** @private Default constructor for memory persistence, defaults to `PersistBase`*/
|
|
@@ -1378,18 +1379,18 @@ class PersistMemoryUtils {
|
|
|
1378
1379
|
}
|
|
1379
1380
|
/**
|
|
1380
1381
|
* Singleton instance of `PersistMemoryUtils` for managing memory persistence globally.
|
|
1381
|
-
*/
|
|
1382
|
+
*/
|
|
1382
1383
|
const PersistMemoryAdapter = new PersistMemoryUtils();
|
|
1383
1384
|
/**
|
|
1384
1385
|
* Exported singleton for memory persistence operations, cast as the control interface.
|
|
1385
1386
|
* Provides a global point of access for managing memory persistence tied to `SessionId`.
|
|
1386
|
-
*/
|
|
1387
|
+
*/
|
|
1387
1388
|
const PersistMemory = PersistMemoryAdapter;
|
|
1388
1389
|
/**
|
|
1389
1390
|
* Utility class for managing alive status persistence per client (`SessionId`) in the swarm system.
|
|
1390
1391
|
* Provides methods to mark clients as online/offline and check their status within a `SwarmName`, with a customizable adapter.
|
|
1391
1392
|
* @implements {IPersistAliveControl}
|
|
1392
|
-
*/
|
|
1393
|
+
*/
|
|
1393
1394
|
class PersistAliveUtils {
|
|
1394
1395
|
constructor() {
|
|
1395
1396
|
/** @private Default constructor for alive status persistence, defaults to `PersistBase`*/
|
|
@@ -1475,18 +1476,18 @@ class PersistAliveUtils {
|
|
|
1475
1476
|
}
|
|
1476
1477
|
/**
|
|
1477
1478
|
* Singleton instance of `PersistAliveUtils` for managing alive status persistence globally.
|
|
1478
|
-
*/
|
|
1479
|
+
*/
|
|
1479
1480
|
const PersistAliveAdapter = new PersistAliveUtils();
|
|
1480
1481
|
/**
|
|
1481
1482
|
* Exported singleton for alive status persistence operations, cast as the control interface.
|
|
1482
1483
|
* Provides a global point of access for managing client online/offline status in the swarm.
|
|
1483
|
-
*/
|
|
1484
|
+
*/
|
|
1484
1485
|
const PersistAlive = PersistAliveAdapter;
|
|
1485
1486
|
/**
|
|
1486
1487
|
* Utility class for managing policy data persistence in the swarm system.
|
|
1487
1488
|
* Provides methods to get and set banned clients within a `SwarmName`, with a customizable adapter.
|
|
1488
1489
|
* @implements {IPersistPolicyControl}
|
|
1489
|
-
*/
|
|
1490
|
+
*/
|
|
1490
1491
|
class PersistPolicyUtils {
|
|
1491
1492
|
constructor() {
|
|
1492
1493
|
/** @private Default constructor for policy data persistence, defaults to `PersistBase`*/
|
|
@@ -1543,18 +1544,18 @@ class PersistPolicyUtils {
|
|
|
1543
1544
|
}
|
|
1544
1545
|
/**
|
|
1545
1546
|
* Singleton instance of `PersistPolicyUtils` for managing policy data persistence globally.
|
|
1546
|
-
*/
|
|
1547
|
+
*/
|
|
1547
1548
|
const PersistPolicyAdapter = new PersistPolicyUtils();
|
|
1548
1549
|
/**
|
|
1549
1550
|
* Exported singleton for policy persistence operations, cast as the control interface.
|
|
1550
1551
|
* Provides a global point of access for managing client bans in the swarm.
|
|
1551
|
-
*/
|
|
1552
|
+
*/
|
|
1552
1553
|
const PersistPolicy = PersistPolicyAdapter;
|
|
1553
1554
|
/**
|
|
1554
1555
|
* Utility class for managing embedding data persistence in the swarm system.
|
|
1555
1556
|
* Provides methods to read and write embedding vectors with a customizable adapter.
|
|
1556
1557
|
* @implements {IPersistEmbeddingControl}
|
|
1557
|
-
*/
|
|
1558
|
+
*/
|
|
1558
1559
|
class PersistEmbeddingUtils {
|
|
1559
1560
|
constructor() {
|
|
1560
1561
|
/** @private Default constructor for embedding data persistence, defaults to `PersistBase`*/
|
|
@@ -1611,15 +1612,15 @@ class PersistEmbeddingUtils {
|
|
|
1611
1612
|
}
|
|
1612
1613
|
/**
|
|
1613
1614
|
* Singleton instance of `PersistEmbeddingUtils` for managing embedding data persistence globally.
|
|
1614
|
-
*/
|
|
1615
|
+
*/
|
|
1615
1616
|
const PersistEmbeddingAdapter = new PersistEmbeddingUtils();
|
|
1616
1617
|
/**
|
|
1617
1618
|
* Exported singleton for embedding persistence operations, cast as the control interface.
|
|
1618
1619
|
* Provides a global point of access for managing embedding cache in the system.
|
|
1619
|
-
*/
|
|
1620
|
+
*/
|
|
1620
1621
|
const PersistEmbedding = PersistEmbeddingAdapter;
|
|
1621
1622
|
|
|
1622
|
-
var _a$3, _b
|
|
1623
|
+
var _a$3, _b;
|
|
1623
1624
|
/** @private Symbol for memoizing the waitForInit method in HistoryMemoryInstance*/
|
|
1624
1625
|
const HISTORY_MEMORY_INSTANCE_WAIT_FOR_INIT = Symbol("wait-for-init");
|
|
1625
1626
|
/** @private Symbol for memoizing the waitForInit method in HistoryPersistInstance*/
|
|
@@ -1667,7 +1668,7 @@ const METHOD_NAME_DISPOSE = "HistoryUtils.dispose";
|
|
|
1667
1668
|
/**
|
|
1668
1669
|
* Initializes the memory-based history instance by loading initial data.
|
|
1669
1670
|
* @private
|
|
1670
|
-
*/
|
|
1671
|
+
*/
|
|
1671
1672
|
const HISTORY_MEMORY_INSTANCE_WAIT_FOR_INIT_FN = async (agentName, self) => {
|
|
1672
1673
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1673
1674
|
swarm$1.loggerService.debug(HISTORY_MEMORY_INSTANCE_METHOD_NAME_WAIT_FOR_INIT, {
|
|
@@ -1681,7 +1682,7 @@ const HISTORY_MEMORY_INSTANCE_WAIT_FOR_INIT_FN = async (agentName, self) => {
|
|
|
1681
1682
|
/**
|
|
1682
1683
|
* Initializes the persistent history instance by loading data from storage.
|
|
1683
1684
|
* @private
|
|
1684
|
-
*/
|
|
1685
|
+
*/
|
|
1685
1686
|
const HISTORY_PERSIST_INSTANCE_WAIT_FOR_INIT_FN = async (agentName, self) => {
|
|
1686
1687
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1687
1688
|
swarm$1.loggerService.debug(HISTORY_PERSIST_INSTANCE_METHOD_NAME_WAIT_FOR_INIT, {
|
|
@@ -1696,73 +1697,52 @@ const HISTORY_PERSIST_INSTANCE_WAIT_FOR_INIT_FN = async (agentName, self) => {
|
|
|
1696
1697
|
/**
|
|
1697
1698
|
* Manages a persistent history of messages, storing them in memory and on disk.
|
|
1698
1699
|
* @implements {IHistoryInstance}
|
|
1699
|
-
*/
|
|
1700
|
-
|
|
1700
|
+
*/
|
|
1701
|
+
class HistoryPersistInstance {
|
|
1702
|
+
/**
|
|
1703
|
+
* Initializes the history for an agent, loading data from persistent storage if needed.
|
|
1704
|
+
*/
|
|
1705
|
+
async waitForInit(agentName) {
|
|
1706
|
+
return await this[HISTORY_PERSIST_INSTANCE_WAIT_FOR_INIT](agentName);
|
|
1707
|
+
}
|
|
1708
|
+
/**
|
|
1709
|
+
* Creates a new persistent history instance.
|
|
1710
|
+
* Invokes onInit and onRef callbacks if provided.
|
|
1711
|
+
*/
|
|
1712
|
+
constructor(clientId, callbacks) {
|
|
1713
|
+
this.clientId = clientId;
|
|
1714
|
+
this.callbacks = callbacks;
|
|
1715
|
+
/** @private The in-memory array of history messages*/
|
|
1716
|
+
this._array = [];
|
|
1701
1717
|
/**
|
|
1702
|
-
*
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1718
|
+
* Memoized initialization function to ensure it runs only once per agent.
|
|
1719
|
+
* @private
|
|
1720
|
+
*/
|
|
1721
|
+
this[_a$3] = functoolsKit.singleshot(async (agentName) => await HISTORY_PERSIST_INSTANCE_WAIT_FOR_INIT_FN(agentName, this));
|
|
1722
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1723
|
+
swarm$1.loggerService.debug(HISTORY_PERSIST_INSTANCE_METHOD_NAME_CTOR, {
|
|
1724
|
+
clientId: this.clientId,
|
|
1725
|
+
});
|
|
1726
|
+
this._persistStorage = new PersistList(this.clientId, `./logs/data/history`);
|
|
1727
|
+
if (callbacks.onInit) {
|
|
1728
|
+
callbacks.onInit(clientId);
|
|
1706
1729
|
}
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
* @private
|
|
1719
|
-
*/
|
|
1720
|
-
this[_a$3] = functoolsKit.singleshot(async (agentName) => await HISTORY_PERSIST_INSTANCE_WAIT_FOR_INIT_FN(agentName, this));
|
|
1721
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1722
|
-
swarm$1.loggerService.debug(HISTORY_PERSIST_INSTANCE_METHOD_NAME_CTOR, {
|
|
1723
|
-
clientId: this.clientId,
|
|
1724
|
-
});
|
|
1725
|
-
this._persistStorage = new PersistList(this.clientId, `./logs/data/history`);
|
|
1726
|
-
if (callbacks.onInit) {
|
|
1727
|
-
callbacks.onInit(clientId);
|
|
1728
|
-
}
|
|
1729
|
-
if (callbacks.onRef) {
|
|
1730
|
-
callbacks.onRef(this);
|
|
1731
|
-
}
|
|
1732
|
-
if (callbacks.filterCondition) {
|
|
1733
|
-
this.iterate = async function* (agentName) {
|
|
1734
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1735
|
-
swarm$1.loggerService.debug(HISTORY_PERSIST_INSTANCE_METHOD_NAME_ITERATE_CONDITION, {
|
|
1736
|
-
clientId: this.clientId,
|
|
1737
|
-
agentName,
|
|
1738
|
-
});
|
|
1739
|
-
if (this.callbacks.onRead) {
|
|
1740
|
-
this.callbacks.onReadBegin &&
|
|
1741
|
-
this.callbacks.onReadBegin(this.clientId, agentName);
|
|
1742
|
-
for (const item of this._array) {
|
|
1743
|
-
if (await this.callbacks.filterCondition(item, this.clientId, agentName)) {
|
|
1744
|
-
this.callbacks.onRead(item, this.clientId, agentName);
|
|
1745
|
-
yield item;
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1748
|
-
if (this.callbacks.getSystemPrompt) {
|
|
1749
|
-
for (const content of await this.callbacks.getSystemPrompt(this.clientId, agentName)) {
|
|
1750
|
-
yield {
|
|
1751
|
-
role: "system",
|
|
1752
|
-
content,
|
|
1753
|
-
agentName,
|
|
1754
|
-
mode: "tool",
|
|
1755
|
-
};
|
|
1756
|
-
}
|
|
1757
|
-
}
|
|
1758
|
-
this.callbacks.onReadEnd &&
|
|
1759
|
-
this.callbacks.onReadEnd(this.clientId, agentName);
|
|
1760
|
-
return;
|
|
1761
|
-
}
|
|
1730
|
+
if (callbacks.onRef) {
|
|
1731
|
+
callbacks.onRef(this);
|
|
1732
|
+
}
|
|
1733
|
+
if (callbacks.filterCondition) {
|
|
1734
|
+
this.iterate = async function* (agentName) {
|
|
1735
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1736
|
+
swarm$1.loggerService.debug(HISTORY_PERSIST_INSTANCE_METHOD_NAME_ITERATE_CONDITION, {
|
|
1737
|
+
clientId: this.clientId,
|
|
1738
|
+
agentName,
|
|
1739
|
+
});
|
|
1740
|
+
if (this.callbacks.onRead) {
|
|
1762
1741
|
this.callbacks.onReadBegin &&
|
|
1763
1742
|
this.callbacks.onReadBegin(this.clientId, agentName);
|
|
1764
1743
|
for (const item of this._array) {
|
|
1765
1744
|
if (await this.callbacks.filterCondition(item, this.clientId, agentName)) {
|
|
1745
|
+
this.callbacks.onRead(item, this.clientId, agentName);
|
|
1766
1746
|
yield item;
|
|
1767
1747
|
}
|
|
1768
1748
|
}
|
|
@@ -1778,171 +1758,172 @@ const HistoryPersistInstance = functoolsKit.makeExtendable((_b$1 = class {
|
|
|
1778
1758
|
}
|
|
1779
1759
|
this.callbacks.onReadEnd &&
|
|
1780
1760
|
this.callbacks.onReadEnd(this.clientId, agentName);
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
}
|
|
1784
|
-
/**
|
|
1785
|
-
* Iterates over history messages, applying filters and system prompts if configured.
|
|
1786
|
-
* Invokes onRead callbacks during iteration if provided.
|
|
1787
|
-
*/
|
|
1788
|
-
async *iterate(agentName) {
|
|
1789
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1790
|
-
swarm$1.loggerService.debug(HISTORY_PERSIST_INSTANCE_METHOD_NAME_ITERATE, {
|
|
1791
|
-
clientId: this.clientId,
|
|
1792
|
-
agentName,
|
|
1793
|
-
});
|
|
1794
|
-
if (this.callbacks.onRead) {
|
|
1761
|
+
return;
|
|
1762
|
+
}
|
|
1795
1763
|
this.callbacks.onReadBegin &&
|
|
1796
1764
|
this.callbacks.onReadBegin(this.clientId, agentName);
|
|
1797
1765
|
for (const item of this._array) {
|
|
1798
|
-
this.callbacks.
|
|
1799
|
-
|
|
1766
|
+
if (await this.callbacks.filterCondition(item, this.clientId, agentName)) {
|
|
1767
|
+
yield item;
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
if (this.callbacks.getSystemPrompt) {
|
|
1771
|
+
for (const content of await this.callbacks.getSystemPrompt(this.clientId, agentName)) {
|
|
1772
|
+
yield {
|
|
1773
|
+
role: "system",
|
|
1774
|
+
content,
|
|
1775
|
+
agentName,
|
|
1776
|
+
mode: "tool",
|
|
1777
|
+
};
|
|
1778
|
+
}
|
|
1800
1779
|
}
|
|
1801
1780
|
this.callbacks.onReadEnd &&
|
|
1802
1781
|
this.callbacks.onReadEnd(this.clientId, agentName);
|
|
1803
|
-
|
|
1804
|
-
|
|
1782
|
+
};
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* Iterates over history messages, applying filters and system prompts if configured.
|
|
1787
|
+
* Invokes onRead callbacks during iteration if provided.
|
|
1788
|
+
*/
|
|
1789
|
+
async *iterate(agentName) {
|
|
1790
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1791
|
+
swarm$1.loggerService.debug(HISTORY_PERSIST_INSTANCE_METHOD_NAME_ITERATE, {
|
|
1792
|
+
clientId: this.clientId,
|
|
1793
|
+
agentName,
|
|
1794
|
+
});
|
|
1795
|
+
if (this.callbacks.onRead) {
|
|
1805
1796
|
this.callbacks.onReadBegin &&
|
|
1806
1797
|
this.callbacks.onReadBegin(this.clientId, agentName);
|
|
1807
1798
|
for (const item of this._array) {
|
|
1799
|
+
this.callbacks.onRead(item, this.clientId, agentName);
|
|
1808
1800
|
yield item;
|
|
1809
1801
|
}
|
|
1810
|
-
if (this.callbacks.getSystemPrompt) {
|
|
1811
|
-
for (const content of await this.callbacks.getSystemPrompt(this.clientId, agentName)) {
|
|
1812
|
-
yield {
|
|
1813
|
-
role: "system",
|
|
1814
|
-
content,
|
|
1815
|
-
agentName,
|
|
1816
|
-
mode: "tool",
|
|
1817
|
-
};
|
|
1818
|
-
}
|
|
1819
|
-
}
|
|
1820
1802
|
this.callbacks.onReadEnd &&
|
|
1821
1803
|
this.callbacks.onReadEnd(this.clientId, agentName);
|
|
1804
|
+
return;
|
|
1822
1805
|
}
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
async push(value, agentName) {
|
|
1828
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1829
|
-
swarm$1.loggerService.debug(HISTORY_PERSIST_INSTANCE_METHOD_NAME_PUSH, {
|
|
1830
|
-
clientId: this.clientId,
|
|
1831
|
-
agentName,
|
|
1832
|
-
});
|
|
1833
|
-
this.callbacks.onPush &&
|
|
1834
|
-
this.callbacks.onPush(value, this.clientId, agentName);
|
|
1835
|
-
this._array.push(value);
|
|
1836
|
-
this.callbacks.onChange &&
|
|
1837
|
-
this.callbacks.onChange(this._array, this.clientId, agentName);
|
|
1838
|
-
await this._persistStorage.push(value);
|
|
1839
|
-
}
|
|
1840
|
-
/**
|
|
1841
|
-
* Removes and returns the last message from the history, updating persistent storage.
|
|
1842
|
-
* Invokes onPop and onChange callbacks if provided.
|
|
1843
|
-
*/
|
|
1844
|
-
async pop(agentName) {
|
|
1845
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1846
|
-
swarm$1.loggerService.debug(HISTORY_PERSIST_INSTANCE_METHOD_NAME_POP, {
|
|
1847
|
-
clientId: this.clientId,
|
|
1848
|
-
agentName,
|
|
1849
|
-
});
|
|
1850
|
-
const value = this._array.pop() ?? null;
|
|
1851
|
-
this.callbacks.onPop &&
|
|
1852
|
-
this.callbacks.onPop(value, this.clientId, agentName);
|
|
1853
|
-
this.callbacks.onChange &&
|
|
1854
|
-
this.callbacks.onChange(this._array, this.clientId, agentName);
|
|
1855
|
-
await this._persistStorage.pop();
|
|
1856
|
-
return value;
|
|
1806
|
+
this.callbacks.onReadBegin &&
|
|
1807
|
+
this.callbacks.onReadBegin(this.clientId, agentName);
|
|
1808
|
+
for (const item of this._array) {
|
|
1809
|
+
yield item;
|
|
1857
1810
|
}
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1864
|
-
swarm$1.loggerService.debug(HISTORY_PERSIST_INSTANCE_METHOD_NAME_DISPOSE, {
|
|
1865
|
-
clientId: this.clientId,
|
|
1811
|
+
if (this.callbacks.getSystemPrompt) {
|
|
1812
|
+
for (const content of await this.callbacks.getSystemPrompt(this.clientId, agentName)) {
|
|
1813
|
+
yield {
|
|
1814
|
+
role: "system",
|
|
1815
|
+
content,
|
|
1866
1816
|
agentName,
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
this.callbacks.onDispose && this.callbacks.onDispose(this.clientId);
|
|
1870
|
-
this._array = [];
|
|
1817
|
+
mode: "tool",
|
|
1818
|
+
};
|
|
1871
1819
|
}
|
|
1872
|
-
return;
|
|
1873
1820
|
}
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1821
|
+
this.callbacks.onReadEnd &&
|
|
1822
|
+
this.callbacks.onReadEnd(this.clientId, agentName);
|
|
1823
|
+
}
|
|
1824
|
+
/**
|
|
1825
|
+
* Adds a new message to the history, persisting it to storage.
|
|
1826
|
+
* Invokes onPush and onChange callbacks if provided.
|
|
1827
|
+
*/
|
|
1828
|
+
async push(value, agentName) {
|
|
1829
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1830
|
+
swarm$1.loggerService.debug(HISTORY_PERSIST_INSTANCE_METHOD_NAME_PUSH, {
|
|
1831
|
+
clientId: this.clientId,
|
|
1832
|
+
agentName,
|
|
1833
|
+
});
|
|
1834
|
+
this.callbacks.onPush &&
|
|
1835
|
+
this.callbacks.onPush(value, this.clientId, agentName);
|
|
1836
|
+
this._array.push(value);
|
|
1837
|
+
this.callbacks.onChange &&
|
|
1838
|
+
this.callbacks.onChange(this._array, this.clientId, agentName);
|
|
1839
|
+
await this._persistStorage.push(value);
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* Removes and returns the last message from the history, updating persistent storage.
|
|
1843
|
+
* Invokes onPop and onChange callbacks if provided.
|
|
1844
|
+
*/
|
|
1845
|
+
async pop(agentName) {
|
|
1846
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1847
|
+
swarm$1.loggerService.debug(HISTORY_PERSIST_INSTANCE_METHOD_NAME_POP, {
|
|
1848
|
+
clientId: this.clientId,
|
|
1849
|
+
agentName,
|
|
1850
|
+
});
|
|
1851
|
+
const value = this._array.pop() ?? null;
|
|
1852
|
+
this.callbacks.onPop &&
|
|
1853
|
+
this.callbacks.onPop(value, this.clientId, agentName);
|
|
1854
|
+
this.callbacks.onChange &&
|
|
1855
|
+
this.callbacks.onChange(this._array, this.clientId, agentName);
|
|
1856
|
+
await this._persistStorage.pop();
|
|
1857
|
+
return value;
|
|
1858
|
+
}
|
|
1859
|
+
/**
|
|
1860
|
+
* Disposes of the history, clearing all data if agentName is null.
|
|
1861
|
+
* Invokes onDispose callback if provided.
|
|
1862
|
+
*/
|
|
1863
|
+
async dispose(agentName) {
|
|
1864
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1865
|
+
swarm$1.loggerService.debug(HISTORY_PERSIST_INSTANCE_METHOD_NAME_DISPOSE, {
|
|
1866
|
+
clientId: this.clientId,
|
|
1867
|
+
agentName,
|
|
1868
|
+
});
|
|
1869
|
+
if (agentName === null) {
|
|
1870
|
+
this.callbacks.onDispose && this.callbacks.onDispose(this.clientId);
|
|
1871
|
+
this._array = [];
|
|
1872
|
+
}
|
|
1873
|
+
return;
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
_a$3 = HISTORY_PERSIST_INSTANCE_WAIT_FOR_INIT;
|
|
1877
|
+
// @ts-ignore
|
|
1878
|
+
HistoryPersistInstance = functoolsKit.makeExtendable(HistoryPersistInstance);
|
|
1877
1879
|
/**
|
|
1878
1880
|
* Manages an in-memory history of messages without persistence.
|
|
1879
1881
|
* @implements {IHistoryInstance}
|
|
1880
|
-
*/
|
|
1881
|
-
|
|
1882
|
+
*/
|
|
1883
|
+
class HistoryMemoryInstance {
|
|
1884
|
+
/**
|
|
1885
|
+
* Initializes the history for an agent, loading initial data if needed.
|
|
1886
|
+
*/
|
|
1887
|
+
async waitForInit(agentName) {
|
|
1888
|
+
return await this[HISTORY_MEMORY_INSTANCE_WAIT_FOR_INIT](agentName);
|
|
1889
|
+
}
|
|
1890
|
+
/**
|
|
1891
|
+
* Creates a new in-memory history instance.
|
|
1892
|
+
* Invokes onInit and onRef callbacks if provided.
|
|
1893
|
+
*/
|
|
1894
|
+
constructor(clientId, callbacks) {
|
|
1895
|
+
this.clientId = clientId;
|
|
1896
|
+
this.callbacks = callbacks;
|
|
1897
|
+
/** @private The in-memory array of history messages*/
|
|
1898
|
+
this._array = [];
|
|
1882
1899
|
/**
|
|
1883
|
-
*
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1900
|
+
* Memoized initialization function to ensure it runs only once per agent.
|
|
1901
|
+
* @private
|
|
1902
|
+
*/
|
|
1903
|
+
this[_b] = functoolsKit.singleshot(async (agentName) => await HISTORY_MEMORY_INSTANCE_WAIT_FOR_INIT_FN(agentName, this));
|
|
1904
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1905
|
+
swarm$1.loggerService.debug(HISTORY_MEMORY_INSTANCE_METHOD_NAME_CTOR, {
|
|
1906
|
+
clientId: this.clientId,
|
|
1907
|
+
});
|
|
1908
|
+
if (callbacks.onInit) {
|
|
1909
|
+
callbacks.onInit(clientId);
|
|
1887
1910
|
}
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
* @private
|
|
1900
|
-
*/
|
|
1901
|
-
this[_c] = functoolsKit.singleshot(async (agentName) => await HISTORY_MEMORY_INSTANCE_WAIT_FOR_INIT_FN(agentName, this));
|
|
1902
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1903
|
-
swarm$1.loggerService.debug(HISTORY_MEMORY_INSTANCE_METHOD_NAME_CTOR, {
|
|
1904
|
-
clientId: this.clientId,
|
|
1905
|
-
});
|
|
1906
|
-
if (callbacks.onInit) {
|
|
1907
|
-
callbacks.onInit(clientId);
|
|
1908
|
-
}
|
|
1909
|
-
if (callbacks.onRef) {
|
|
1910
|
-
callbacks.onRef(this);
|
|
1911
|
-
}
|
|
1912
|
-
if (callbacks.filterCondition) {
|
|
1913
|
-
this.iterate = async function* (agentName) {
|
|
1914
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1915
|
-
swarm$1.loggerService.debug(HISTORY_MEMORY_INSTANCE_METHOD_NAME_ITERATE_CONDITION, {
|
|
1916
|
-
clientId: this.clientId,
|
|
1917
|
-
agentName,
|
|
1918
|
-
});
|
|
1919
|
-
if (this.callbacks.onRead) {
|
|
1920
|
-
this.callbacks.onReadBegin &&
|
|
1921
|
-
this.callbacks.onReadBegin(this.clientId, agentName);
|
|
1922
|
-
for (const item of this._array) {
|
|
1923
|
-
if (await this.callbacks.filterCondition(item, this.clientId, agentName)) {
|
|
1924
|
-
this.callbacks.onRead(item, this.clientId, agentName);
|
|
1925
|
-
yield item;
|
|
1926
|
-
}
|
|
1927
|
-
}
|
|
1928
|
-
if (this.callbacks.getSystemPrompt) {
|
|
1929
|
-
for (const content of await this.callbacks.getSystemPrompt(this.clientId, agentName)) {
|
|
1930
|
-
yield {
|
|
1931
|
-
role: "system",
|
|
1932
|
-
content,
|
|
1933
|
-
agentName,
|
|
1934
|
-
mode: "tool",
|
|
1935
|
-
};
|
|
1936
|
-
}
|
|
1937
|
-
}
|
|
1938
|
-
this.callbacks.onReadEnd &&
|
|
1939
|
-
this.callbacks.onReadEnd(this.clientId, agentName);
|
|
1940
|
-
return;
|
|
1941
|
-
}
|
|
1911
|
+
if (callbacks.onRef) {
|
|
1912
|
+
callbacks.onRef(this);
|
|
1913
|
+
}
|
|
1914
|
+
if (callbacks.filterCondition) {
|
|
1915
|
+
this.iterate = async function* (agentName) {
|
|
1916
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1917
|
+
swarm$1.loggerService.debug(HISTORY_MEMORY_INSTANCE_METHOD_NAME_ITERATE_CONDITION, {
|
|
1918
|
+
clientId: this.clientId,
|
|
1919
|
+
agentName,
|
|
1920
|
+
});
|
|
1921
|
+
if (this.callbacks.onRead) {
|
|
1942
1922
|
this.callbacks.onReadBegin &&
|
|
1943
1923
|
this.callbacks.onReadBegin(this.clientId, agentName);
|
|
1944
1924
|
for (const item of this._array) {
|
|
1945
1925
|
if (await this.callbacks.filterCondition(item, this.clientId, agentName)) {
|
|
1926
|
+
this.callbacks.onRead(item, this.clientId, agentName);
|
|
1946
1927
|
yield item;
|
|
1947
1928
|
}
|
|
1948
1929
|
}
|
|
@@ -1958,106 +1939,128 @@ const HistoryMemoryInstance = functoolsKit.makeExtendable((_d = class {
|
|
|
1958
1939
|
}
|
|
1959
1940
|
this.callbacks.onReadEnd &&
|
|
1960
1941
|
this.callbacks.onReadEnd(this.clientId, agentName);
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
}
|
|
1964
|
-
/**
|
|
1965
|
-
* Iterates over history messages, applying filters and system prompts if configured.
|
|
1966
|
-
* Invokes onRead callbacks during iteration if provided.
|
|
1967
|
-
*/
|
|
1968
|
-
async *iterate(agentName) {
|
|
1969
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1970
|
-
swarm$1.loggerService.debug(HISTORY_MEMORY_INSTANCE_METHOD_NAME_ITERATE, {
|
|
1971
|
-
clientId: this.clientId,
|
|
1972
|
-
agentName,
|
|
1973
|
-
});
|
|
1974
|
-
if (this.callbacks.onRead) {
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1975
1944
|
this.callbacks.onReadBegin &&
|
|
1976
1945
|
this.callbacks.onReadBegin(this.clientId, agentName);
|
|
1977
1946
|
for (const item of this._array) {
|
|
1978
|
-
this.callbacks.
|
|
1979
|
-
|
|
1947
|
+
if (await this.callbacks.filterCondition(item, this.clientId, agentName)) {
|
|
1948
|
+
yield item;
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
if (this.callbacks.getSystemPrompt) {
|
|
1952
|
+
for (const content of await this.callbacks.getSystemPrompt(this.clientId, agentName)) {
|
|
1953
|
+
yield {
|
|
1954
|
+
role: "system",
|
|
1955
|
+
content,
|
|
1956
|
+
agentName,
|
|
1957
|
+
mode: "tool",
|
|
1958
|
+
};
|
|
1959
|
+
}
|
|
1980
1960
|
}
|
|
1981
1961
|
this.callbacks.onReadEnd &&
|
|
1982
1962
|
this.callbacks.onReadEnd(this.clientId, agentName);
|
|
1983
|
-
|
|
1984
|
-
|
|
1963
|
+
};
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
/**
|
|
1967
|
+
* Iterates over history messages, applying filters and system prompts if configured.
|
|
1968
|
+
* Invokes onRead callbacks during iteration if provided.
|
|
1969
|
+
*/
|
|
1970
|
+
async *iterate(agentName) {
|
|
1971
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1972
|
+
swarm$1.loggerService.debug(HISTORY_MEMORY_INSTANCE_METHOD_NAME_ITERATE, {
|
|
1973
|
+
clientId: this.clientId,
|
|
1974
|
+
agentName,
|
|
1975
|
+
});
|
|
1976
|
+
if (this.callbacks.onRead) {
|
|
1985
1977
|
this.callbacks.onReadBegin &&
|
|
1986
1978
|
this.callbacks.onReadBegin(this.clientId, agentName);
|
|
1987
1979
|
for (const item of this._array) {
|
|
1980
|
+
this.callbacks.onRead(item, this.clientId, agentName);
|
|
1988
1981
|
yield item;
|
|
1989
1982
|
}
|
|
1990
|
-
if (this.callbacks.getSystemPrompt) {
|
|
1991
|
-
for (const content of await this.callbacks.getSystemPrompt(this.clientId, agentName)) {
|
|
1992
|
-
yield {
|
|
1993
|
-
role: "system",
|
|
1994
|
-
content,
|
|
1995
|
-
agentName,
|
|
1996
|
-
mode: "tool",
|
|
1997
|
-
};
|
|
1998
|
-
}
|
|
1999
|
-
}
|
|
2000
1983
|
this.callbacks.onReadEnd &&
|
|
2001
1984
|
this.callbacks.onReadEnd(this.clientId, agentName);
|
|
1985
|
+
return;
|
|
2002
1986
|
}
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
async push(value, agentName) {
|
|
2008
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2009
|
-
swarm$1.loggerService.debug(HISTORY_MEMORY_INSTANCE_METHOD_NAME_PUSH, {
|
|
2010
|
-
clientId: this.clientId,
|
|
2011
|
-
agentName,
|
|
2012
|
-
});
|
|
2013
|
-
this.callbacks.onPush &&
|
|
2014
|
-
this.callbacks.onPush(value, this.clientId, agentName);
|
|
2015
|
-
this._array.push(value);
|
|
2016
|
-
this.callbacks.onChange &&
|
|
2017
|
-
this.callbacks.onChange(this._array, this.clientId, agentName);
|
|
2018
|
-
return Promise.resolve();
|
|
2019
|
-
}
|
|
2020
|
-
/**
|
|
2021
|
-
* Removes and returns the last message from the in-memory history.
|
|
2022
|
-
* Invokes onPop and onChange callbacks if provided.
|
|
2023
|
-
*/
|
|
2024
|
-
async pop(agentName) {
|
|
2025
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2026
|
-
swarm$1.loggerService.debug(HISTORY_MEMORY_INSTANCE_METHOD_NAME_POP, {
|
|
2027
|
-
clientId: this.clientId,
|
|
2028
|
-
agentName,
|
|
2029
|
-
});
|
|
2030
|
-
const value = this._array.pop() ?? null;
|
|
2031
|
-
this.callbacks.onPop &&
|
|
2032
|
-
this.callbacks.onPop(value, this.clientId, agentName);
|
|
2033
|
-
this.callbacks.onChange &&
|
|
2034
|
-
this.callbacks.onChange(this._array, this.clientId, agentName);
|
|
2035
|
-
return Promise.resolve(value);
|
|
1987
|
+
this.callbacks.onReadBegin &&
|
|
1988
|
+
this.callbacks.onReadBegin(this.clientId, agentName);
|
|
1989
|
+
for (const item of this._array) {
|
|
1990
|
+
yield item;
|
|
2036
1991
|
}
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2043
|
-
swarm$1.loggerService.debug(HISTORY_MEMORY_INSTANCE_METHOD_NAME_DISPOSE, {
|
|
2044
|
-
clientId: this.clientId,
|
|
1992
|
+
if (this.callbacks.getSystemPrompt) {
|
|
1993
|
+
for (const content of await this.callbacks.getSystemPrompt(this.clientId, agentName)) {
|
|
1994
|
+
yield {
|
|
1995
|
+
role: "system",
|
|
1996
|
+
content,
|
|
2045
1997
|
agentName,
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
this.callbacks.onDispose && this.callbacks.onDispose(this.clientId);
|
|
2049
|
-
this._array = [];
|
|
1998
|
+
mode: "tool",
|
|
1999
|
+
};
|
|
2050
2000
|
}
|
|
2051
|
-
return Promise.resolve();
|
|
2052
2001
|
}
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2002
|
+
this.callbacks.onReadEnd &&
|
|
2003
|
+
this.callbacks.onReadEnd(this.clientId, agentName);
|
|
2004
|
+
}
|
|
2005
|
+
/**
|
|
2006
|
+
* Adds a new message to the in-memory history.
|
|
2007
|
+
* Invokes onPush and onChange callbacks if provided.
|
|
2008
|
+
*/
|
|
2009
|
+
async push(value, agentName) {
|
|
2010
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2011
|
+
swarm$1.loggerService.debug(HISTORY_MEMORY_INSTANCE_METHOD_NAME_PUSH, {
|
|
2012
|
+
clientId: this.clientId,
|
|
2013
|
+
agentName,
|
|
2014
|
+
});
|
|
2015
|
+
this.callbacks.onPush &&
|
|
2016
|
+
this.callbacks.onPush(value, this.clientId, agentName);
|
|
2017
|
+
this._array.push(value);
|
|
2018
|
+
this.callbacks.onChange &&
|
|
2019
|
+
this.callbacks.onChange(this._array, this.clientId, agentName);
|
|
2020
|
+
return Promise.resolve();
|
|
2021
|
+
}
|
|
2022
|
+
/**
|
|
2023
|
+
* Removes and returns the last message from the in-memory history.
|
|
2024
|
+
* Invokes onPop and onChange callbacks if provided.
|
|
2025
|
+
*/
|
|
2026
|
+
async pop(agentName) {
|
|
2027
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2028
|
+
swarm$1.loggerService.debug(HISTORY_MEMORY_INSTANCE_METHOD_NAME_POP, {
|
|
2029
|
+
clientId: this.clientId,
|
|
2030
|
+
agentName,
|
|
2031
|
+
});
|
|
2032
|
+
const value = this._array.pop() ?? null;
|
|
2033
|
+
this.callbacks.onPop &&
|
|
2034
|
+
this.callbacks.onPop(value, this.clientId, agentName);
|
|
2035
|
+
this.callbacks.onChange &&
|
|
2036
|
+
this.callbacks.onChange(this._array, this.clientId, agentName);
|
|
2037
|
+
return Promise.resolve(value);
|
|
2038
|
+
}
|
|
2039
|
+
/**
|
|
2040
|
+
* Disposes of the history, clearing all data if agentName is null.
|
|
2041
|
+
* Invokes onDispose callback if provided.
|
|
2042
|
+
*/
|
|
2043
|
+
async dispose(agentName) {
|
|
2044
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2045
|
+
swarm$1.loggerService.debug(HISTORY_MEMORY_INSTANCE_METHOD_NAME_DISPOSE, {
|
|
2046
|
+
clientId: this.clientId,
|
|
2047
|
+
agentName,
|
|
2048
|
+
});
|
|
2049
|
+
if (agentName === null) {
|
|
2050
|
+
this.callbacks.onDispose && this.callbacks.onDispose(this.clientId);
|
|
2051
|
+
this._array = [];
|
|
2052
|
+
}
|
|
2053
|
+
return Promise.resolve();
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
_b = HISTORY_MEMORY_INSTANCE_WAIT_FOR_INIT;
|
|
2057
|
+
// @ts-ignore
|
|
2058
|
+
HistoryMemoryInstance = functoolsKit.makeExtendable(HistoryMemoryInstance);
|
|
2056
2059
|
/**
|
|
2057
2060
|
* Provides utilities for managing history instances, supporting both memory and persistent storage.
|
|
2058
2061
|
* @implements {IHistoryAdapter}
|
|
2059
2062
|
* @implements {IHistoryControl}
|
|
2060
|
-
*/
|
|
2063
|
+
*/
|
|
2061
2064
|
class HistoryUtils {
|
|
2062
2065
|
constructor() {
|
|
2063
2066
|
/** @private The configured lifecycle callbacks for history instances*/
|
|
@@ -2168,11 +2171,11 @@ class HistoryUtils {
|
|
|
2168
2171
|
}
|
|
2169
2172
|
/**
|
|
2170
2173
|
* Singleton instance of HistoryUtils implementing the history adapter interface.
|
|
2171
|
-
*/
|
|
2174
|
+
*/
|
|
2172
2175
|
const HistoryAdapter = new HistoryUtils();
|
|
2173
2176
|
/**
|
|
2174
2177
|
* Exported History Control interface for configuring history behavior.
|
|
2175
|
-
*/
|
|
2178
|
+
*/
|
|
2176
2179
|
const History = HistoryAdapter;
|
|
2177
2180
|
|
|
2178
2181
|
/**
|
|
@@ -2268,14 +2271,14 @@ const beginContext = (run) => (...args) => {
|
|
|
2268
2271
|
return fn();
|
|
2269
2272
|
};
|
|
2270
2273
|
|
|
2271
|
-
var _a$2
|
|
2274
|
+
var _a$2;
|
|
2272
2275
|
/** @private Symbol for memoizing the waitForInit method in LoggerInstance*/
|
|
2273
2276
|
const LOGGER_INSTANCE_WAIT_FOR_INIT = Symbol("wait-for-init");
|
|
2274
2277
|
/**
|
|
2275
2278
|
* Initializes the logger instance by invoking the onInit callback if provided.
|
|
2276
2279
|
* Ensures initialization runs asynchronously and is executed only once via singleshot.
|
|
2277
2280
|
* @private
|
|
2278
|
-
*/
|
|
2281
|
+
*/
|
|
2279
2282
|
const LOGGER_INSTANCE_WAIT_FOR_FN = async (self) => {
|
|
2280
2283
|
if (self.callbacks.onInit) {
|
|
2281
2284
|
self.callbacks.onInit(self.clientId);
|
|
@@ -2286,73 +2289,74 @@ const LOGGER_INSTANCE_WAIT_FOR_FN = async (self) => {
|
|
|
2286
2289
|
* Implements ILoggerInstance for client-specific logging with lifecycle management.
|
|
2287
2290
|
* Integrates with GLOBAL_CONFIG for console logging control and callbacks for custom behavior.
|
|
2288
2291
|
* @implements {ILoggerInstance}
|
|
2289
|
-
*/
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
/**
|
|
2298
|
-
* Memoized initialization function to ensure it runs only once using singleshot.
|
|
2299
|
-
* Invokes LOGGER_INSTANCE_WAIT_FOR_FN to handle onInit callback execution.
|
|
2300
|
-
* @private
|
|
2301
|
-
*/
|
|
2302
|
-
this[_a$2] = functoolsKit.singleshot(async () => await LOGGER_INSTANCE_WAIT_FOR_FN(this));
|
|
2303
|
-
}
|
|
2304
|
-
/**
|
|
2305
|
-
* Initializes the logger instance, invoking the onInit callback if provided.
|
|
2306
|
-
* Ensures initialization is performed only once, memoized via singleshot.
|
|
2307
|
-
*/
|
|
2308
|
-
async waitForInit() {
|
|
2309
|
-
return await this[LOGGER_INSTANCE_WAIT_FOR_INIT]();
|
|
2310
|
-
}
|
|
2292
|
+
*/
|
|
2293
|
+
class LoggerInstance {
|
|
2294
|
+
/**
|
|
2295
|
+
* Creates a new logger instance for a specific client.
|
|
2296
|
+
*/
|
|
2297
|
+
constructor(clientId, callbacks) {
|
|
2298
|
+
this.clientId = clientId;
|
|
2299
|
+
this.callbacks = callbacks;
|
|
2311
2300
|
/**
|
|
2312
|
-
*
|
|
2313
|
-
*
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2301
|
+
* Memoized initialization function to ensure it runs only once using singleshot.
|
|
2302
|
+
* Invokes LOGGER_INSTANCE_WAIT_FOR_FN to handle onInit callback execution.
|
|
2303
|
+
* @private
|
|
2304
|
+
*/
|
|
2305
|
+
this[_a$2] = functoolsKit.singleshot(async () => await LOGGER_INSTANCE_WAIT_FOR_FN(this));
|
|
2306
|
+
}
|
|
2307
|
+
/**
|
|
2308
|
+
* Initializes the logger instance, invoking the onInit callback if provided.
|
|
2309
|
+
* Ensures initialization is performed only once, memoized via singleshot.
|
|
2310
|
+
*/
|
|
2311
|
+
async waitForInit() {
|
|
2312
|
+
return await this[LOGGER_INSTANCE_WAIT_FOR_INIT]();
|
|
2313
|
+
}
|
|
2314
|
+
/**
|
|
2315
|
+
* Logs a message to the console (if enabled) and invokes the onLog callback if provided.
|
|
2316
|
+
* Controlled by GLOBAL_CONFIG.CC_LOGGER_ENABLE_CONSOLE for console output.
|
|
2317
|
+
*/
|
|
2318
|
+
log(topic, ...args) {
|
|
2319
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_CONSOLE &&
|
|
2320
|
+
console.log(`[clientId=${this.clientId}]`, topic, ...args);
|
|
2321
|
+
if (this.callbacks.onLog) {
|
|
2322
|
+
this.callbacks.onLog(this.clientId, topic, ...args);
|
|
2321
2323
|
}
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2324
|
+
}
|
|
2325
|
+
/**
|
|
2326
|
+
* Logs a debug message to the console (if enabled) and invokes the onDebug callback if provided.
|
|
2327
|
+
* Controlled by GLOBAL_CONFIG.CC_LOGGER_ENABLE_CONSOLE for console output.
|
|
2328
|
+
*/
|
|
2329
|
+
debug(topic, ...args) {
|
|
2330
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_CONSOLE &&
|
|
2331
|
+
console.debug(`[clientId=${this.clientId}]`, topic, ...args);
|
|
2332
|
+
if (this.callbacks.onDebug) {
|
|
2333
|
+
this.callbacks.onDebug(this.clientId, topic, ...args);
|
|
2332
2334
|
}
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2335
|
+
}
|
|
2336
|
+
/**
|
|
2337
|
+
* Logs an info message to the console (if enabled) and invokes the onInfo callback if provided.
|
|
2338
|
+
* Controlled by GLOBAL_CONFIG.CC_LOGGER_ENABLE_CONSOLE for console output.
|
|
2339
|
+
*/
|
|
2340
|
+
info(topic, ...args) {
|
|
2341
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_CONSOLE &&
|
|
2342
|
+
console.info(`[clientId=${this.clientId}]`, topic, ...args);
|
|
2343
|
+
if (this.callbacks.onInfo) {
|
|
2344
|
+
this.callbacks.onInfo(this.clientId, topic, ...args);
|
|
2343
2345
|
}
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2346
|
+
}
|
|
2347
|
+
/**
|
|
2348
|
+
* Disposes of the logger instance, invoking the onDispose callback if provided.
|
|
2349
|
+
* Performs synchronous cleanup without additional resource management.
|
|
2350
|
+
*/
|
|
2351
|
+
dispose() {
|
|
2352
|
+
if (this.callbacks.onDispose) {
|
|
2353
|
+
this.callbacks.onDispose(this.clientId);
|
|
2352
2354
|
}
|
|
2353
|
-
}
|
|
2354
|
-
|
|
2355
|
-
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
_a$2 = LOGGER_INSTANCE_WAIT_FOR_INIT;
|
|
2358
|
+
// @ts-ignore
|
|
2359
|
+
LoggerInstance = functoolsKit.makeExtendable(LoggerInstance);
|
|
2356
2360
|
/**
|
|
2357
2361
|
* Provides utilities for managing logger instances and common logging operations.
|
|
2358
2362
|
* Implements ILoggerAdapter for client-specific logging and ILoggerControl for configuration.
|
|
@@ -2360,7 +2364,7 @@ const LoggerInstance = functoolsKit.makeExtendable((_b = class {
|
|
|
2360
2364
|
* MethodContextService (execution context), and GLOBAL_CONFIG (logging control).
|
|
2361
2365
|
* @implements {ILoggerAdapter}
|
|
2362
2366
|
* @implements {ILoggerControl}
|
|
2363
|
-
*/
|
|
2367
|
+
*/
|
|
2364
2368
|
class LoggerUtils {
|
|
2365
2369
|
constructor() {
|
|
2366
2370
|
/** @private The custom logger instance constructor, defaults to LoggerInstance*/
|
|
@@ -2538,12 +2542,12 @@ class LoggerUtils {
|
|
|
2538
2542
|
/**
|
|
2539
2543
|
* Singleton instance of LoggerUtils implementing the logger adapter and control interfaces.
|
|
2540
2544
|
* Provides a centralized utility for client-specific and common logging operations.
|
|
2541
|
-
*/
|
|
2545
|
+
*/
|
|
2542
2546
|
const LoggerAdapter = new LoggerUtils();
|
|
2543
2547
|
/**
|
|
2544
2548
|
* Exported Logger Control interface for configuring logger behavior.
|
|
2545
2549
|
* Exposes LoggerUtils' control methods (useCommonAdapter, useClientCallbacks, useClientAdapter, etc.).
|
|
2546
|
-
*/
|
|
2550
|
+
*/
|
|
2547
2551
|
const Logger = LoggerAdapter;
|
|
2548
2552
|
|
|
2549
2553
|
/** @private Constant for logging the constructor in OperatorInstance*/
|
|
@@ -2570,17 +2574,17 @@ const METHOD_NAME_CONNECT_OPERATOR = "OperatorUtils.connectOperator";
|
|
|
2570
2574
|
* Operator instance implementation
|
|
2571
2575
|
* @class OperatorInstance
|
|
2572
2576
|
* @implements {IOperatorInstance}
|
|
2573
|
-
*/
|
|
2574
|
-
|
|
2577
|
+
*/
|
|
2578
|
+
class OperatorInstance {
|
|
2575
2579
|
/**
|
|
2576
2580
|
* Disposed flag for child class
|
|
2577
|
-
|
|
2581
|
+
*/
|
|
2578
2582
|
get isDisposed() {
|
|
2579
2583
|
return this._isDisposed;
|
|
2580
2584
|
}
|
|
2581
2585
|
/**
|
|
2582
2586
|
* Creates an OperatorInstance
|
|
2583
|
-
|
|
2587
|
+
*/
|
|
2584
2588
|
constructor(clientId, agentName, callbacks) {
|
|
2585
2589
|
this.clientId = clientId;
|
|
2586
2590
|
this.agentName = agentName;
|
|
@@ -2595,7 +2599,7 @@ const OperatorInstance = functoolsKit.makeExtendable(class {
|
|
|
2595
2599
|
}
|
|
2596
2600
|
/**
|
|
2597
2601
|
* Connects an answer subscription
|
|
2598
|
-
|
|
2602
|
+
*/
|
|
2599
2603
|
connectAnswer(next) {
|
|
2600
2604
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2601
2605
|
swarm$1.loggerService.debug(OPERATOR_INSTANCE_METHOD_NAME_CONNECT_ANSWER, {
|
|
@@ -2607,7 +2611,7 @@ const OperatorInstance = functoolsKit.makeExtendable(class {
|
|
|
2607
2611
|
}
|
|
2608
2612
|
/**
|
|
2609
2613
|
* Init the operator connection
|
|
2610
|
-
|
|
2614
|
+
*/
|
|
2611
2615
|
async init() {
|
|
2612
2616
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2613
2617
|
swarm$1.loggerService.debug(OPERATOR_INSTANCE_METHOD_NAME_INIT, {
|
|
@@ -2620,7 +2624,7 @@ const OperatorInstance = functoolsKit.makeExtendable(class {
|
|
|
2620
2624
|
}
|
|
2621
2625
|
/**
|
|
2622
2626
|
* Sends a notification
|
|
2623
|
-
|
|
2627
|
+
*/
|
|
2624
2628
|
async notify(content) {
|
|
2625
2629
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2626
2630
|
swarm$1.loggerService.debug(OPERATOR_INSTANCE_METHOD_NAME_NOTIFY, {
|
|
@@ -2637,7 +2641,7 @@ const OperatorInstance = functoolsKit.makeExtendable(class {
|
|
|
2637
2641
|
}
|
|
2638
2642
|
/**
|
|
2639
2643
|
* Sends an answer
|
|
2640
|
-
|
|
2644
|
+
*/
|
|
2641
2645
|
async answer(content) {
|
|
2642
2646
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2643
2647
|
swarm$1.loggerService.debug(OPERATOR_INSTANCE_METHOD_NAME_ANSWER, {
|
|
@@ -2660,7 +2664,7 @@ const OperatorInstance = functoolsKit.makeExtendable(class {
|
|
|
2660
2664
|
}
|
|
2661
2665
|
/**
|
|
2662
2666
|
* Receives a message
|
|
2663
|
-
|
|
2667
|
+
*/
|
|
2664
2668
|
async recieveMessage(message) {
|
|
2665
2669
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2666
2670
|
swarm$1.loggerService.debug(OPERATOR_INSTANCE_METHOD_NAME_RECEIVE_MESSAGE, {
|
|
@@ -2674,7 +2678,7 @@ const OperatorInstance = functoolsKit.makeExtendable(class {
|
|
|
2674
2678
|
}
|
|
2675
2679
|
/**
|
|
2676
2680
|
* Disposes the operator instance
|
|
2677
|
-
|
|
2681
|
+
*/
|
|
2678
2682
|
async dispose() {
|
|
2679
2683
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2680
2684
|
swarm$1.loggerService.debug(OPERATOR_INSTANCE_METHOD_NAME_DISPOSE, {
|
|
@@ -2687,12 +2691,14 @@ const OperatorInstance = functoolsKit.makeExtendable(class {
|
|
|
2687
2691
|
this._answerSubject.unsubscribeAll();
|
|
2688
2692
|
this._isDisposed = true;
|
|
2689
2693
|
}
|
|
2690
|
-
}
|
|
2694
|
+
}
|
|
2695
|
+
// @ts-ignore
|
|
2696
|
+
OperatorInstance = functoolsKit.makeExtendable(OperatorInstance);
|
|
2691
2697
|
/**
|
|
2692
2698
|
* Operator utilities class
|
|
2693
2699
|
* @class OperatorUtils
|
|
2694
2700
|
* @implements {IOperatorControl}
|
|
2695
|
-
*/
|
|
2701
|
+
*/
|
|
2696
2702
|
class OperatorUtils {
|
|
2697
2703
|
constructor() {
|
|
2698
2704
|
this.OperatorFactory = OperatorInstance;
|
|
@@ -23330,7 +23336,7 @@ const INACTIVITY_TIMEOUT = 15 * 60 * 1000;
|
|
|
23330
23336
|
/**
|
|
23331
23337
|
* @constant {Function} BEGIN_CHAT_FN
|
|
23332
23338
|
* Function to begin a chat session
|
|
23333
|
-
*/
|
|
23339
|
+
*/
|
|
23334
23340
|
const BEGIN_CHAT_FN = (self) => {
|
|
23335
23341
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
23336
23342
|
swarm$1.loggerService.debug("ChatInstance.beginChat", {
|
|
@@ -23345,11 +23351,11 @@ const BEGIN_CHAT_FN = (self) => {
|
|
|
23345
23351
|
* @class ChatInstance
|
|
23346
23352
|
* @implements {IChatInstance}
|
|
23347
23353
|
* Implementation of a single chat instance
|
|
23348
|
-
*/
|
|
23349
|
-
|
|
23354
|
+
*/
|
|
23355
|
+
class ChatInstance {
|
|
23350
23356
|
/**
|
|
23351
23357
|
* @constructor
|
|
23352
|
-
|
|
23358
|
+
*/
|
|
23353
23359
|
constructor(clientId, swarmName, onDispose, callbacks, payload) {
|
|
23354
23360
|
this.clientId = clientId;
|
|
23355
23361
|
this.swarmName = swarmName;
|
|
@@ -23362,7 +23368,7 @@ const ChatInstance = functoolsKit.makeExtendable(class {
|
|
|
23362
23368
|
this._lastActivity = Date.now();
|
|
23363
23369
|
/**
|
|
23364
23370
|
* Begins a chat session
|
|
23365
|
-
|
|
23371
|
+
*/
|
|
23366
23372
|
this.beginChat = functoolsKit.singleshot(async () => {
|
|
23367
23373
|
return await BEGIN_CHAT_FN(this);
|
|
23368
23374
|
});
|
|
@@ -23379,7 +23385,7 @@ const ChatInstance = functoolsKit.makeExtendable(class {
|
|
|
23379
23385
|
}
|
|
23380
23386
|
/**
|
|
23381
23387
|
* Checks if the chat has been active within the timeout period
|
|
23382
|
-
|
|
23388
|
+
*/
|
|
23383
23389
|
async checkLastActivity(now) {
|
|
23384
23390
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
23385
23391
|
swarm$1.loggerService.debug("ChatInstance.checkLastActivity", {
|
|
@@ -23393,7 +23399,7 @@ const ChatInstance = functoolsKit.makeExtendable(class {
|
|
|
23393
23399
|
}
|
|
23394
23400
|
/**
|
|
23395
23401
|
* Sends a message in the chat
|
|
23396
|
-
|
|
23402
|
+
*/
|
|
23397
23403
|
async sendMessage(content) {
|
|
23398
23404
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
23399
23405
|
swarm$1.loggerService.debug("ChatInstance.sendMessage", {
|
|
@@ -23409,7 +23415,7 @@ const ChatInstance = functoolsKit.makeExtendable(class {
|
|
|
23409
23415
|
}
|
|
23410
23416
|
/**
|
|
23411
23417
|
* Disposes of the chat instance
|
|
23412
|
-
|
|
23418
|
+
*/
|
|
23413
23419
|
async dispose() {
|
|
23414
23420
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
23415
23421
|
swarm$1.loggerService.debug("ChatInstance.dispose", {
|
|
@@ -23423,7 +23429,7 @@ const ChatInstance = functoolsKit.makeExtendable(class {
|
|
|
23423
23429
|
}
|
|
23424
23430
|
/**
|
|
23425
23431
|
* Adds a listener for dispose events
|
|
23426
|
-
|
|
23432
|
+
*/
|
|
23427
23433
|
listenDispose(fn) {
|
|
23428
23434
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
23429
23435
|
swarm$1.loggerService.debug("ChatInstance.listenDispose", {
|
|
@@ -23432,12 +23438,14 @@ const ChatInstance = functoolsKit.makeExtendable(class {
|
|
|
23432
23438
|
});
|
|
23433
23439
|
return this._disposeSubject.once(fn);
|
|
23434
23440
|
}
|
|
23435
|
-
}
|
|
23441
|
+
}
|
|
23442
|
+
//@ts-ignore
|
|
23443
|
+
ChatInstance = functoolsKit.makeExtendable(ChatInstance);
|
|
23436
23444
|
/**
|
|
23437
23445
|
* @class ChatUtils
|
|
23438
23446
|
* @implements {IChatControl}
|
|
23439
23447
|
* Utility class for managing multiple chat instances
|
|
23440
|
-
*/
|
|
23448
|
+
*/
|
|
23441
23449
|
class ChatUtils {
|
|
23442
23450
|
constructor() {
|
|
23443
23451
|
/** @private*/
|
|
@@ -23551,7 +23559,7 @@ class ChatUtils {
|
|
|
23551
23559
|
/**
|
|
23552
23560
|
* @constant {ChatUtils} Chat
|
|
23553
23561
|
* Singleton instance of ChatUtils
|
|
23554
|
-
*/
|
|
23562
|
+
*/
|
|
23555
23563
|
const Chat = new ChatUtils();
|
|
23556
23564
|
|
|
23557
23565
|
/** @private Constant for logging the take method in StorageUtils*/
|