@hashgraphonline/conversational-agent 0.2.216 → 0.2.217
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/cli/readme.md +181 -0
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/SwarmPlugin.d.ts +17 -0
- package/dist/cjs/plugins/community/swarm/__tests__/SwarmPlugin.mocks.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/SwarmPlugin.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/CreatePostageStampTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/DownloadDataTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/DownloadFilesTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/ExtendPostageStampTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/GetPostageStampTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/ListPostageStampsTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/QueryUploadProgressTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/ReadFeedTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/SwarmTool.mocks.d.ts +14 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/UpdateFeedTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/UploadDataTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/UploadFileTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/UploadFolderTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/config.d.ts +6 -0
- package/dist/cjs/plugins/community/swarm/constants.d.ts +8 -0
- package/dist/cjs/plugins/community/swarm/index.d.ts +2 -0
- package/dist/cjs/plugins/community/swarm/model.d.ts +23 -0
- package/dist/cjs/plugins/community/swarm/tools/CreatePostageStampTool.d.ts +47 -0
- package/dist/cjs/plugins/community/swarm/tools/DownloadDataTool.d.ts +35 -0
- package/dist/cjs/plugins/community/swarm/tools/DownloadFilesTool.d.ts +41 -0
- package/dist/cjs/plugins/community/swarm/tools/ExtendPostageStampTool.d.ts +47 -0
- package/dist/cjs/plugins/community/swarm/tools/GetPostageStampTool.d.ts +35 -0
- package/dist/cjs/plugins/community/swarm/tools/ListPostageStampsTool.d.ts +53 -0
- package/dist/cjs/plugins/community/swarm/tools/QueryUploadProgressTool.d.ts +35 -0
- package/dist/cjs/plugins/community/swarm/tools/ReadFeedTool.d.ts +41 -0
- package/dist/cjs/plugins/community/swarm/tools/UpdateFeedTool.d.ts +47 -0
- package/dist/cjs/plugins/community/swarm/tools/UploadDataTool.d.ts +47 -0
- package/dist/cjs/plugins/community/swarm/tools/UploadFileTool.d.ts +53 -0
- package/dist/cjs/plugins/community/swarm/tools/UploadFolderTool.d.ts +47 -0
- package/dist/cjs/plugins/community/swarm/utils.d.ts +22 -0
- package/dist/cjs/plugins/index.d.ts +1 -0
- package/dist/esm/index.js +33 -31
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index10.js +13 -677
- package/dist/esm/index10.js.map +1 -1
- package/dist/esm/index11.js +601 -234
- package/dist/esm/index11.js.map +1 -1
- package/dist/esm/index12.js +296 -136
- package/dist/esm/index12.js.map +1 -1
- package/dist/esm/index13.js +127 -235
- package/dist/esm/index13.js.map +1 -1
- package/dist/esm/index14.js +247 -84
- package/dist/esm/index14.js.map +1 -1
- package/dist/esm/index15.js +81 -159
- package/dist/esm/index15.js.map +1 -1
- package/dist/esm/index16.js +155 -229
- package/dist/esm/index16.js.map +1 -1
- package/dist/esm/index17.js +238 -140
- package/dist/esm/index17.js.map +1 -1
- package/dist/esm/index18.js +139 -493
- package/dist/esm/index18.js.map +1 -1
- package/dist/esm/index19.js +479 -91
- package/dist/esm/index19.js.map +1 -1
- package/dist/esm/index20.js +88 -147
- package/dist/esm/index20.js.map +1 -1
- package/dist/esm/index21.js +127 -666
- package/dist/esm/index21.js.map +1 -1
- package/dist/esm/index22.js +698 -44
- package/dist/esm/index22.js.map +1 -1
- package/dist/esm/index23.js +45 -304
- package/dist/esm/index23.js.map +1 -1
- package/dist/esm/index24.js +303 -153
- package/dist/esm/index24.js.map +1 -1
- package/dist/esm/index25.js +150 -117
- package/dist/esm/index25.js.map +1 -1
- package/dist/esm/index26.js +154 -18
- package/dist/esm/index26.js.map +1 -1
- package/dist/esm/index27.js +18 -22
- package/dist/esm/index27.js.map +1 -1
- package/dist/esm/index28.js +15 -74
- package/dist/esm/index28.js.map +1 -1
- package/dist/esm/index29.js +70 -295
- package/dist/esm/index29.js.map +1 -1
- package/dist/esm/index30.js +279 -100
- package/dist/esm/index30.js.map +1 -1
- package/dist/esm/index31.js +86 -922
- package/dist/esm/index31.js.map +1 -1
- package/dist/esm/index32.js +904 -189
- package/dist/esm/index32.js.map +1 -1
- package/dist/esm/index33.js +185 -1169
- package/dist/esm/index33.js.map +1 -1
- package/dist/esm/index34.js +1218 -112
- package/dist/esm/index34.js.map +1 -1
- package/dist/esm/index35.js +111 -99
- package/dist/esm/index35.js.map +1 -1
- package/dist/esm/index36.js +113 -8
- package/dist/esm/index36.js.map +1 -1
- package/dist/esm/index37.js +8 -45
- package/dist/esm/index37.js.map +1 -1
- package/dist/esm/index38.js +41 -102
- package/dist/esm/index38.js.map +1 -1
- package/dist/esm/index39.js +96 -55
- package/dist/esm/index39.js.map +1 -1
- package/dist/esm/index4.js +1 -1
- package/dist/esm/index40.js +58 -71
- package/dist/esm/index40.js.map +1 -1
- package/dist/esm/index41.js +79 -21
- package/dist/esm/index41.js.map +1 -1
- package/dist/esm/index42.js +21 -5
- package/dist/esm/index42.js.map +1 -1
- package/dist/esm/index43.js +4 -11
- package/dist/esm/index43.js.map +1 -1
- package/dist/esm/index44.js +12 -322
- package/dist/esm/index44.js.map +1 -1
- package/dist/esm/index45.js +280 -142
- package/dist/esm/index45.js.map +1 -1
- package/dist/esm/index46.js +181 -24
- package/dist/esm/index46.js.map +1 -1
- package/dist/esm/index47.js +7 -95
- package/dist/esm/index47.js.map +1 -1
- package/dist/esm/index48.js +77 -7
- package/dist/esm/index48.js.map +1 -1
- package/dist/esm/index49.js +75 -0
- package/dist/esm/index49.js.map +1 -0
- package/dist/esm/index5.js +2 -2
- package/dist/esm/index50.js +57 -0
- package/dist/esm/index50.js.map +1 -0
- package/dist/esm/index51.js +103 -0
- package/dist/esm/index51.js.map +1 -0
- package/dist/esm/index52.js +79 -0
- package/dist/esm/index52.js.map +1 -0
- package/dist/esm/index53.js +75 -0
- package/dist/esm/index53.js.map +1 -0
- package/dist/esm/index54.js +124 -0
- package/dist/esm/index54.js.map +1 -0
- package/dist/esm/index55.js +58 -0
- package/dist/esm/index55.js.map +1 -0
- package/dist/esm/index56.js +83 -0
- package/dist/esm/index56.js.map +1 -0
- package/dist/esm/index57.js +100 -0
- package/dist/esm/index57.js.map +1 -0
- package/dist/esm/index58.js +118 -0
- package/dist/esm/index58.js.map +1 -0
- package/dist/esm/index59.js +108 -0
- package/dist/esm/index59.js.map +1 -0
- package/dist/esm/index6.js +132 -833
- package/dist/esm/index6.js.map +1 -1
- package/dist/esm/index60.js +30 -0
- package/dist/esm/index60.js.map +1 -0
- package/dist/esm/index61.js +98 -0
- package/dist/esm/index61.js.map +1 -0
- package/dist/esm/index62.js +131 -0
- package/dist/esm/index62.js.map +1 -0
- package/dist/esm/index63.js +19 -0
- package/dist/esm/index63.js.map +1 -0
- package/dist/esm/index7.js +826 -75
- package/dist/esm/index7.js.map +1 -1
- package/dist/esm/index8.js +91 -13
- package/dist/esm/index8.js.map +1 -1
- package/dist/esm/index9.js +13 -17
- package/dist/esm/index9.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/plugins/community/swarm/SwarmPlugin.d.ts +17 -0
- package/dist/types/plugins/community/swarm/__tests__/SwarmPlugin.mocks.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/SwarmPlugin.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/CreatePostageStampTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/DownloadDataTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/DownloadFilesTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/ExtendPostageStampTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/GetPostageStampTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/ListPostageStampsTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/QueryUploadProgressTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/ReadFeedTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/SwarmTool.mocks.d.ts +14 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/UpdateFeedTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/UploadDataTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/UploadFileTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/UploadFolderTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/config.d.ts +6 -0
- package/dist/types/plugins/community/swarm/constants.d.ts +8 -0
- package/dist/types/plugins/community/swarm/index.d.ts +2 -0
- package/dist/types/plugins/community/swarm/model.d.ts +23 -0
- package/dist/types/plugins/community/swarm/tools/CreatePostageStampTool.d.ts +47 -0
- package/dist/types/plugins/community/swarm/tools/DownloadDataTool.d.ts +35 -0
- package/dist/types/plugins/community/swarm/tools/DownloadFilesTool.d.ts +41 -0
- package/dist/types/plugins/community/swarm/tools/ExtendPostageStampTool.d.ts +47 -0
- package/dist/types/plugins/community/swarm/tools/GetPostageStampTool.d.ts +35 -0
- package/dist/types/plugins/community/swarm/tools/ListPostageStampsTool.d.ts +53 -0
- package/dist/types/plugins/community/swarm/tools/QueryUploadProgressTool.d.ts +35 -0
- package/dist/types/plugins/community/swarm/tools/ReadFeedTool.d.ts +41 -0
- package/dist/types/plugins/community/swarm/tools/UpdateFeedTool.d.ts +47 -0
- package/dist/types/plugins/community/swarm/tools/UploadDataTool.d.ts +47 -0
- package/dist/types/plugins/community/swarm/tools/UploadFileTool.d.ts +53 -0
- package/dist/types/plugins/community/swarm/tools/UploadFolderTool.d.ts +47 -0
- package/dist/types/plugins/community/swarm/utils.d.ts +22 -0
- package/dist/types/plugins/index.d.ts +1 -0
- package/package.json +36 -26
- package/src/index.ts +1 -0
- package/src/plugins/community/swarm/README.md +279 -0
- package/src/plugins/community/swarm/SwarmPlugin.ts +178 -0
- package/src/plugins/community/swarm/__tests__/SwarmPlugin.mocks.ts +105 -0
- package/src/plugins/community/swarm/__tests__/SwarmPlugin.test.ts +93 -0
- package/src/plugins/community/swarm/__tests__/tools/CreatePostageStampTool.test.ts +152 -0
- package/src/plugins/community/swarm/__tests__/tools/DownloadDataTool.test.ts +93 -0
- package/src/plugins/community/swarm/__tests__/tools/DownloadFilesTool.test.ts +163 -0
- package/src/plugins/community/swarm/__tests__/tools/ExtendPostageStampTool.test.ts +132 -0
- package/src/plugins/community/swarm/__tests__/tools/GetPostageStampTool.test.ts +83 -0
- package/src/plugins/community/swarm/__tests__/tools/ListPostageStampsTool.test.ts +219 -0
- package/src/plugins/community/swarm/__tests__/tools/QueryUploadProgressTool.test.ts +169 -0
- package/src/plugins/community/swarm/__tests__/tools/ReadFeedTool.test.ts +133 -0
- package/src/plugins/community/swarm/__tests__/tools/SwarmTool.mocks.ts +67 -0
- package/src/plugins/community/swarm/__tests__/tools/UpdateFeedTool.test.ts +148 -0
- package/src/plugins/community/swarm/__tests__/tools/UploadDataTool.test.ts +125 -0
- package/src/plugins/community/swarm/__tests__/tools/UploadFileTool.test.ts +194 -0
- package/src/plugins/community/swarm/__tests__/tools/UploadFolderTool.test.ts +118 -0
- package/src/plugins/community/swarm/config.ts +6 -0
- package/src/plugins/community/swarm/constants.ts +12 -0
- package/src/plugins/community/swarm/index.ts +2 -0
- package/src/plugins/community/swarm/model.ts +23 -0
- package/src/plugins/community/swarm/tools/CreatePostageStampTool.ts +137 -0
- package/src/plugins/community/swarm/tools/DownloadDataTool.ts +79 -0
- package/src/plugins/community/swarm/tools/DownloadFilesTool.ts +155 -0
- package/src/plugins/community/swarm/tools/ExtendPostageStampTool.ts +112 -0
- package/src/plugins/community/swarm/tools/GetPostageStampTool.ts +92 -0
- package/src/plugins/community/swarm/tools/ListPostageStampsTool.ts +124 -0
- package/src/plugins/community/swarm/tools/QueryUploadProgressTool.ts +109 -0
- package/src/plugins/community/swarm/tools/ReadFeedTool.ts +110 -0
- package/src/plugins/community/swarm/tools/UpdateFeedTool.ts +149 -0
- package/src/plugins/community/swarm/tools/UploadDataTool.ts +109 -0
- package/src/plugins/community/swarm/tools/UploadFileTool.ts +163 -0
- package/src/plugins/community/swarm/tools/UploadFolderTool.ts +150 -0
- package/src/plugins/community/swarm/utils.ts +172 -0
- package/src/plugins/index.ts +1 -0
- package/cli/dist/CLIApp.d.ts +0 -11
- package/cli/dist/CLIApp.d.ts.map +0 -1
- package/cli/dist/CLIApp.js +0 -128
- package/cli/dist/CLIApp.js.map +0 -1
- package/cli/dist/LocalConversationalAgent.d.ts +0 -37
- package/cli/dist/LocalConversationalAgent.js +0 -58
- package/cli/dist/app.d.ts +0 -18
- package/cli/dist/app.d.ts.map +0 -1
- package/cli/dist/app.js +0 -14
- package/cli/dist/app.js.map +0 -1
- package/cli/dist/cli.d.ts +0 -3
- package/cli/dist/cli.d.ts.map +0 -1
- package/cli/dist/cli.js +0 -87
- package/cli/dist/cli.js.map +0 -1
- package/cli/dist/components/AppContainer.d.ts +0 -16
- package/cli/dist/components/AppContainer.js +0 -24
- package/cli/dist/components/AppScreens.d.ts +0 -2
- package/cli/dist/components/AppScreens.js +0 -259
- package/cli/dist/components/ChatScreen.d.ts +0 -21
- package/cli/dist/components/ChatScreen.d.ts.map +0 -1
- package/cli/dist/components/ChatScreen.js +0 -40
- package/cli/dist/components/ChatScreen.js.map +0 -1
- package/cli/dist/components/DebugLoadingScreen.d.ts +0 -5
- package/cli/dist/components/DebugLoadingScreen.js +0 -31
- package/cli/dist/components/LoadingScreen.d.ts +0 -3
- package/cli/dist/components/LoadingScreen.d.ts.map +0 -1
- package/cli/dist/components/LoadingScreen.js +0 -17
- package/cli/dist/components/LoadingScreen.js.map +0 -1
- package/cli/dist/components/LoadingScreenDebug.d.ts +0 -5
- package/cli/dist/components/LoadingScreenDebug.js +0 -27
- package/cli/dist/components/MCPConfigScreen.d.ts +0 -28
- package/cli/dist/components/MCPConfigScreen.d.ts.map +0 -1
- package/cli/dist/components/MCPConfigScreen.js +0 -186
- package/cli/dist/components/MCPConfigScreen.js.map +0 -1
- package/cli/dist/components/ScreenRouter.d.ts +0 -13
- package/cli/dist/components/ScreenRouter.d.ts.map +0 -1
- package/cli/dist/components/ScreenRouter.js +0 -23
- package/cli/dist/components/ScreenRouter.js.map +0 -1
- package/cli/dist/components/SetupScreen.d.ts +0 -16
- package/cli/dist/components/SetupScreen.d.ts.map +0 -1
- package/cli/dist/components/SetupScreen.js +0 -67
- package/cli/dist/components/SetupScreen.js.map +0 -1
- package/cli/dist/components/SingleLoadingScreen.d.ts +0 -5
- package/cli/dist/components/SingleLoadingScreen.js +0 -27
- package/cli/dist/components/StatusBadge.d.ts +0 -10
- package/cli/dist/components/StatusBadge.d.ts.map +0 -1
- package/cli/dist/components/StatusBadge.js +0 -24
- package/cli/dist/components/StatusBadge.js.map +0 -1
- package/cli/dist/components/TerminalWindow.d.ts +0 -9
- package/cli/dist/components/TerminalWindow.d.ts.map +0 -1
- package/cli/dist/components/TerminalWindow.js +0 -19
- package/cli/dist/components/TerminalWindow.js.map +0 -1
- package/cli/dist/components/WelcomeScreen.d.ts +0 -12
- package/cli/dist/components/WelcomeScreen.d.ts.map +0 -1
- package/cli/dist/components/WelcomeScreen.js +0 -47
- package/cli/dist/components/WelcomeScreen.js.map +0 -1
- package/cli/dist/context/AppContext.d.ts +0 -68
- package/cli/dist/context/AppContext.js +0 -363
- package/cli/dist/headless-runner.d.ts +0 -17
- package/cli/dist/headless-runner.d.ts.map +0 -1
- package/cli/dist/headless-runner.js +0 -128
- package/cli/dist/headless-runner.js.map +0 -1
- package/cli/dist/hooks/useInitializeAgent.d.ts +0 -19
- package/cli/dist/hooks/useInitializeAgent.d.ts.map +0 -1
- package/cli/dist/hooks/useInitializeAgent.js +0 -29
- package/cli/dist/hooks/useInitializeAgent.js.map +0 -1
- package/cli/dist/hooks/useStableState.d.ts +0 -38
- package/cli/dist/hooks/useStableState.d.ts.map +0 -1
- package/cli/dist/hooks/useStableState.js +0 -69
- package/cli/dist/hooks/useStableState.js.map +0 -1
- package/cli/dist/managers/AgentManager.d.ts +0 -58
- package/cli/dist/managers/AgentManager.d.ts.map +0 -1
- package/cli/dist/managers/AgentManager.js +0 -121
- package/cli/dist/managers/AgentManager.js.map +0 -1
- package/cli/dist/managers/ConfigManager.d.ts +0 -54
- package/cli/dist/managers/ConfigManager.d.ts.map +0 -1
- package/cli/dist/managers/ConfigManager.js +0 -188
- package/cli/dist/managers/ConfigManager.js.map +0 -1
- package/cli/dist/types.d.ts +0 -52
- package/cli/dist/types.d.ts.map +0 -1
- package/cli/dist/types.js +0 -34
- package/cli/dist/types.js.map +0 -1
package/dist/esm/index19.js
CHANGED
|
@@ -1,124 +1,512 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
1
|
+
import { SystemMessage } from "@langchain/core/messages";
|
|
2
|
+
import { Logger } from "@hashgraphonline/standards-sdk";
|
|
3
|
+
import { MemoryWindow } from "./index21.js";
|
|
4
|
+
import { ContentStorage } from "./index22.js";
|
|
5
|
+
import { TokenCounter } from "./index20.js";
|
|
6
|
+
const IS_ENTITY_ASSOCIATION_FLAG = '"isEntityAssociation":true';
|
|
7
|
+
const _SmartMemoryManager = class _SmartMemoryManager {
|
|
8
|
+
constructor(config = {}) {
|
|
9
|
+
this.config = { ..._SmartMemoryManager.DEFAULT_CONFIG, ...config };
|
|
10
|
+
this.logger = new Logger({ module: "SmartMemoryManager" });
|
|
11
|
+
this.tokenCounter = new TokenCounter(this.config.modelName);
|
|
12
|
+
this._contentStorage = new ContentStorage(this.config.storageLimit);
|
|
13
|
+
this.memoryWindow = new MemoryWindow(
|
|
14
|
+
this.config.maxTokens,
|
|
15
|
+
this.config.reserveTokens,
|
|
16
|
+
this.tokenCounter
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get the content storage instance for file/content reference operations
|
|
21
|
+
* @returns ContentStorage instance
|
|
22
|
+
*/
|
|
23
|
+
get contentStorage() {
|
|
24
|
+
return this._contentStorage;
|
|
11
25
|
}
|
|
12
26
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @
|
|
27
|
+
* Add a message to the active memory window
|
|
28
|
+
* Automatically handles pruning and storage of displaced messages
|
|
29
|
+
* @param message - Message to add
|
|
16
30
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
31
|
+
addMessage(message) {
|
|
32
|
+
const result = this.memoryWindow.addMessage(message);
|
|
33
|
+
if (result.prunedMessages.length > 0) {
|
|
34
|
+
this._contentStorage.storeMessages(result.prunedMessages);
|
|
20
35
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get all active messages from the memory window
|
|
39
|
+
* @returns Array of active messages in chronological order
|
|
40
|
+
*/
|
|
41
|
+
getMessages() {
|
|
42
|
+
return this.memoryWindow.getMessages();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Clear active memory window
|
|
46
|
+
* @param clearStorage - Whether to also clear the content storage (default: false)
|
|
47
|
+
*/
|
|
48
|
+
clear(clearStorage = false) {
|
|
49
|
+
this.memoryWindow.clear();
|
|
50
|
+
if (clearStorage) {
|
|
51
|
+
this._contentStorage.clear();
|
|
26
52
|
}
|
|
27
53
|
}
|
|
28
54
|
/**
|
|
29
|
-
*
|
|
30
|
-
* @param
|
|
31
|
-
* @returns Number of tokens including message formatting overhead
|
|
55
|
+
* Set the system prompt for the memory window
|
|
56
|
+
* @param systemPrompt - System prompt text
|
|
32
57
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const roleTokens = this.countTokens(this.getMessageRole(message));
|
|
36
|
-
return contentTokens + roleTokens + _TokenCounter.MESSAGE_OVERHEAD + _TokenCounter.ROLE_OVERHEAD;
|
|
58
|
+
setSystemPrompt(systemPrompt) {
|
|
59
|
+
this.memoryWindow.setSystemPrompt(systemPrompt);
|
|
37
60
|
}
|
|
38
61
|
/**
|
|
39
|
-
*
|
|
40
|
-
* @
|
|
41
|
-
* @returns Total token count for all messages
|
|
62
|
+
* Get the current system prompt
|
|
63
|
+
* @returns Current system prompt text
|
|
42
64
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
65
|
+
getSystemPrompt() {
|
|
66
|
+
return this.memoryWindow.getSystemPrompt();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Search through stored message history
|
|
70
|
+
* @param query - Search term or pattern
|
|
71
|
+
* @param options - Search configuration
|
|
72
|
+
* @returns Array of matching messages from history
|
|
73
|
+
*/
|
|
74
|
+
searchHistory(query, options = {}) {
|
|
75
|
+
return this._contentStorage.searchMessages(query, options);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get recent messages from storage history
|
|
79
|
+
* @param count - Number of recent messages to retrieve
|
|
80
|
+
* @returns Array of recent messages from storage
|
|
81
|
+
*/
|
|
82
|
+
getRecentHistory(count) {
|
|
83
|
+
return this._contentStorage.getRecentMessages(count);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Check if a message can be added without exceeding limits
|
|
87
|
+
* @param message - Message to test
|
|
88
|
+
* @returns True if message can be added
|
|
89
|
+
*/
|
|
90
|
+
canAddMessage(message) {
|
|
91
|
+
return this.memoryWindow.canAddMessage(message);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get statistics about the active memory window
|
|
95
|
+
* @returns Memory usage statistics
|
|
96
|
+
*/
|
|
97
|
+
getMemoryStats() {
|
|
98
|
+
const windowStats = this.memoryWindow.getStats();
|
|
99
|
+
return {
|
|
100
|
+
totalActiveMessages: windowStats.totalMessages,
|
|
101
|
+
currentTokenCount: windowStats.currentTokens,
|
|
102
|
+
maxTokens: windowStats.maxTokens,
|
|
103
|
+
remainingCapacity: windowStats.remainingCapacity,
|
|
104
|
+
systemPromptTokens: windowStats.systemPromptTokens,
|
|
105
|
+
usagePercentage: windowStats.usagePercentage
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get statistics about the content storage
|
|
110
|
+
* @returns Storage usage statistics
|
|
111
|
+
*/
|
|
112
|
+
getStorageStats() {
|
|
113
|
+
return this._contentStorage.getStorageStats();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get combined statistics for both active memory and storage
|
|
117
|
+
* @returns Combined memory and storage statistics
|
|
118
|
+
*/
|
|
119
|
+
getOverallStats() {
|
|
120
|
+
const memoryStats = this.getMemoryStats();
|
|
121
|
+
const storageStats = this.getStorageStats();
|
|
122
|
+
return {
|
|
123
|
+
activeMemory: memoryStats,
|
|
124
|
+
storage: storageStats,
|
|
125
|
+
totalMessagesManaged: memoryStats.totalActiveMessages + storageStats.totalMessages,
|
|
126
|
+
activeMemoryUtilization: memoryStats.usagePercentage,
|
|
127
|
+
storageUtilization: storageStats.usagePercentage
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Update the configuration and apply changes
|
|
132
|
+
* @param newConfig - New configuration options
|
|
133
|
+
*/
|
|
134
|
+
updateConfig(newConfig) {
|
|
135
|
+
this.config = { ...this.config, ...newConfig };
|
|
136
|
+
if (newConfig.maxTokens !== void 0 || newConfig.reserveTokens !== void 0) {
|
|
137
|
+
this.memoryWindow.updateLimits(
|
|
138
|
+
this.config.maxTokens,
|
|
139
|
+
this.config.reserveTokens
|
|
140
|
+
);
|
|
46
141
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
total += this.countMessageTokens(message);
|
|
142
|
+
if (newConfig.storageLimit !== void 0) {
|
|
143
|
+
this._contentStorage.updateStorageLimit(this.config.storageLimit);
|
|
50
144
|
}
|
|
51
|
-
return total;
|
|
52
145
|
}
|
|
53
146
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* @param systemPrompt - The system prompt text
|
|
57
|
-
* @returns Estimated token count
|
|
147
|
+
* Get current configuration
|
|
148
|
+
* @returns Current configuration settings
|
|
58
149
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
150
|
+
getConfig() {
|
|
151
|
+
return { ...this.config };
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get messages from storage within a time range
|
|
155
|
+
* @param startTime - Start of time range
|
|
156
|
+
* @param endTime - End of time range
|
|
157
|
+
* @returns Messages within the specified time range
|
|
158
|
+
*/
|
|
159
|
+
getHistoryFromTimeRange(startTime, endTime) {
|
|
160
|
+
return this._contentStorage.getMessagesFromTimeRange(startTime, endTime);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Get messages from storage by message type
|
|
164
|
+
* @param messageType - Type of messages to retrieve ('human', 'ai', 'system', etc.)
|
|
165
|
+
* @param limit - Maximum number of messages to return
|
|
166
|
+
* @returns Messages of the specified type
|
|
167
|
+
*/
|
|
168
|
+
getHistoryByType(messageType, limit) {
|
|
169
|
+
return this._contentStorage.getMessagesByType(messageType, limit);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Get recent messages from storage within the last N minutes
|
|
173
|
+
* @param minutes - Number of minutes to look back
|
|
174
|
+
* @returns Messages from the last N minutes
|
|
175
|
+
*/
|
|
176
|
+
getRecentHistoryByTime(minutes) {
|
|
177
|
+
return this._contentStorage.getRecentMessagesByTime(minutes);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Export the current state for persistence or analysis
|
|
181
|
+
* @returns Serializable representation of memory state
|
|
182
|
+
*/
|
|
183
|
+
exportState() {
|
|
184
|
+
return {
|
|
185
|
+
config: this.config,
|
|
186
|
+
activeMessages: this.memoryWindow.getMessages().map((msg) => ({
|
|
187
|
+
content: msg.content,
|
|
188
|
+
type: msg._getType()
|
|
189
|
+
})),
|
|
190
|
+
systemPrompt: this.memoryWindow.getSystemPrompt(),
|
|
191
|
+
memoryStats: this.getMemoryStats(),
|
|
192
|
+
storageStats: this.getStorageStats(),
|
|
193
|
+
storedMessages: this._contentStorage.exportMessages()
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get a summary of conversation context for external use
|
|
198
|
+
* Useful for providing context to other systems or for logging
|
|
199
|
+
* @param includeStoredContext - Whether to include recent stored messages
|
|
200
|
+
* @returns Context summary object
|
|
201
|
+
*/
|
|
202
|
+
getContextSummary(includeStoredContext = false) {
|
|
203
|
+
const activeMessages = this.getMessages();
|
|
204
|
+
const summary = {
|
|
205
|
+
activeMessageCount: activeMessages.length,
|
|
206
|
+
systemPrompt: this.getSystemPrompt(),
|
|
207
|
+
recentMessages: activeMessages.slice(-5),
|
|
208
|
+
memoryUtilization: this.getMemoryStats().usagePercentage,
|
|
209
|
+
hasStoredHistory: this.getStorageStats().totalMessages > 0
|
|
210
|
+
};
|
|
211
|
+
if (includeStoredContext) {
|
|
212
|
+
return {
|
|
213
|
+
...summary,
|
|
214
|
+
recentStoredMessages: this.getRecentHistory(10),
|
|
215
|
+
storageStats: this.getStorageStats()
|
|
216
|
+
};
|
|
62
217
|
}
|
|
63
|
-
|
|
64
|
-
const roleTokens = this.countTokens("system");
|
|
65
|
-
return contentTokens + roleTokens + _TokenCounter.MESSAGE_OVERHEAD + _TokenCounter.ROLE_OVERHEAD;
|
|
218
|
+
return summary;
|
|
66
219
|
}
|
|
67
220
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
221
|
+
* Perform maintenance operations
|
|
222
|
+
* Optimizes storage and cleans up resources
|
|
223
|
+
*/
|
|
224
|
+
performMaintenance() {
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Store an entity association for later resolution
|
|
228
|
+
* @param entityId - The blockchain entity ID
|
|
229
|
+
* @param entityName - User-provided or derived friendly name
|
|
230
|
+
* @param entityType - Type of entity (token, account, topic, etc.)
|
|
231
|
+
* @param transactionId - Optional transaction ID that created this entity
|
|
232
|
+
*/
|
|
233
|
+
storeEntityAssociation(entityId, entityName, entityType, transactionId, sessionId) {
|
|
234
|
+
try {
|
|
235
|
+
if (!entityId || typeof entityId !== "string" || entityId.trim().length === 0) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (!entityName || typeof entityName !== "string" || entityName.trim().length === 0) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (!entityType || typeof entityType !== "string" || entityType.trim().length === 0) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const sanitizedEntityId = entityId.trim();
|
|
245
|
+
const sanitizedEntityName = entityName.trim().substring(0, 100);
|
|
246
|
+
const sanitizedEntityType = this.normalizeEntityType(entityType);
|
|
247
|
+
let usageHint = "";
|
|
248
|
+
if (sanitizedEntityType === "tokenid") {
|
|
249
|
+
usageHint = "Use this as tokenId for HTS operations";
|
|
250
|
+
} else if (sanitizedEntityType === "topicid") {
|
|
251
|
+
usageHint = "Can be used for HCS operations, HRLs for minting with the format hcs://1/<topicId>, etc.";
|
|
252
|
+
} else if (sanitizedEntityType === "accountid") {
|
|
253
|
+
usageHint = "Can be used for account based operations";
|
|
254
|
+
}
|
|
255
|
+
const association = {
|
|
256
|
+
entityId: sanitizedEntityId,
|
|
257
|
+
entityName: sanitizedEntityName,
|
|
258
|
+
entityType: sanitizedEntityType,
|
|
259
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
260
|
+
isEntityAssociation: true,
|
|
261
|
+
...usageHint ? { usage: usageHint } : {},
|
|
262
|
+
...sanitizedEntityType === "topicId" ? { hrl: `hcs://1/${sanitizedEntityId}` } : {},
|
|
263
|
+
...transactionId !== void 0 && transactionId !== null && transactionId.trim() !== "" ? { transactionId: transactionId.trim() } : {},
|
|
264
|
+
...sessionId && sessionId.trim() !== "" ? { sessionId: sessionId.trim() } : {}
|
|
265
|
+
};
|
|
266
|
+
const content = JSON.stringify(association);
|
|
267
|
+
const entityMessage = {
|
|
268
|
+
_getType: () => "system",
|
|
269
|
+
content,
|
|
270
|
+
id: `entity_${sanitizedEntityId}_${Date.now()}`,
|
|
271
|
+
name: "entity_association",
|
|
272
|
+
additional_kwargs: {
|
|
273
|
+
entityId: sanitizedEntityId,
|
|
274
|
+
entityName: sanitizedEntityName,
|
|
275
|
+
entityType: sanitizedEntityType,
|
|
276
|
+
isEntityAssociation: true,
|
|
277
|
+
...sessionId && sessionId.trim() !== "" ? { sessionId: sessionId.trim() } : {}
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
try {
|
|
281
|
+
this.memoryWindow.addMessage(new SystemMessage(content));
|
|
282
|
+
} catch {
|
|
283
|
+
}
|
|
284
|
+
this._contentStorage.storeMessages([entityMessage]);
|
|
285
|
+
} catch (error) {
|
|
286
|
+
this.logger.error("Failed to store entity association", {
|
|
287
|
+
entityId,
|
|
288
|
+
entityName,
|
|
289
|
+
entityType,
|
|
290
|
+
error: error instanceof Error ? error.message : String(error)
|
|
291
|
+
});
|
|
99
292
|
}
|
|
100
293
|
}
|
|
101
294
|
/**
|
|
102
|
-
*
|
|
103
|
-
* @returns The tiktoken model name
|
|
295
|
+
* Normalize various type aliases to canonical EntityFormat strings using a registry.
|
|
104
296
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
297
|
+
normalizeEntityType(input) {
|
|
298
|
+
const raw = (input || "").trim();
|
|
299
|
+
if (raw.length === 0) {
|
|
300
|
+
return "";
|
|
301
|
+
}
|
|
302
|
+
const key = raw.replace(/[^a-z]/gi, "").toLowerCase();
|
|
303
|
+
const REGISTRY = {
|
|
304
|
+
topic: "topicId",
|
|
305
|
+
topicid: "topicId",
|
|
306
|
+
token: "tokenId",
|
|
307
|
+
tokenid: "tokenId",
|
|
308
|
+
account: "accountId",
|
|
309
|
+
accountid: "accountId",
|
|
310
|
+
contract: "contractId",
|
|
311
|
+
contractid: "contractId",
|
|
312
|
+
file: "fileId",
|
|
313
|
+
fileid: "fileId",
|
|
314
|
+
schedule: "scheduleId",
|
|
315
|
+
scheduleid: "scheduleId"
|
|
316
|
+
};
|
|
317
|
+
if (Object.prototype.hasOwnProperty.call(REGISTRY, key)) {
|
|
318
|
+
return REGISTRY[key];
|
|
319
|
+
}
|
|
320
|
+
if (/^[a-z]+Id$/.test(raw)) {
|
|
321
|
+
return raw;
|
|
322
|
+
}
|
|
323
|
+
return raw;
|
|
107
324
|
}
|
|
108
325
|
/**
|
|
109
|
-
*
|
|
326
|
+
* Resolve entity references from natural language queries
|
|
327
|
+
* @param query - Search query (entity name or natural language reference)
|
|
328
|
+
* @param options - Resolution options for filtering and fuzzy matching
|
|
329
|
+
* @returns Array of matching entity associations
|
|
110
330
|
*/
|
|
111
|
-
|
|
331
|
+
resolveEntityReference(query, options = {}) {
|
|
112
332
|
try {
|
|
113
|
-
|
|
114
|
-
|
|
333
|
+
if (!query || typeof query !== "string") {
|
|
334
|
+
return [];
|
|
335
|
+
}
|
|
336
|
+
const sanitizedQuery = query.trim();
|
|
337
|
+
if (sanitizedQuery.length === 0) {
|
|
338
|
+
return [];
|
|
339
|
+
}
|
|
340
|
+
if (sanitizedQuery.length > 200) {
|
|
341
|
+
}
|
|
342
|
+
const { entityType, limit = 10, fuzzyMatch = true } = options;
|
|
343
|
+
const safeLimit = Math.max(1, Math.min(limit || 10, 100));
|
|
344
|
+
const isEntityIdQuery = /^0\.0\.\d+$/.test(sanitizedQuery);
|
|
345
|
+
const searchResults = this._contentStorage.searchMessages(
|
|
346
|
+
sanitizedQuery.substring(0, 200),
|
|
347
|
+
{
|
|
348
|
+
caseSensitive: false,
|
|
349
|
+
limit: safeLimit * 2
|
|
350
|
+
}
|
|
351
|
+
);
|
|
352
|
+
const associations = [];
|
|
353
|
+
for (const message of searchResults) {
|
|
354
|
+
try {
|
|
355
|
+
const content = message.content;
|
|
356
|
+
if (content.includes(IS_ENTITY_ASSOCIATION_FLAG) || content.includes("entityId")) {
|
|
357
|
+
const parsed = JSON.parse(content);
|
|
358
|
+
if (parsed.entityId && parsed.entityName && parsed.entityType) {
|
|
359
|
+
if (entityType && parsed.entityType !== entityType) {
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
if (isEntityIdQuery) {
|
|
363
|
+
if (parsed.entityId !== sanitizedQuery) {
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
associations.push(parsed);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
} catch {
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
if (fuzzyMatch && associations.length === 0 && !isEntityIdQuery) {
|
|
375
|
+
const fuzzyQueries = [
|
|
376
|
+
query.toLowerCase(),
|
|
377
|
+
`token`,
|
|
378
|
+
`account`,
|
|
379
|
+
entityType || ""
|
|
380
|
+
].filter(Boolean);
|
|
381
|
+
for (const fuzzyQuery of fuzzyQueries) {
|
|
382
|
+
if (fuzzyQuery === query.toLowerCase()) continue;
|
|
383
|
+
const fuzzyResults = this._contentStorage.searchMessages(fuzzyQuery, {
|
|
384
|
+
caseSensitive: false,
|
|
385
|
+
limit
|
|
386
|
+
});
|
|
387
|
+
for (const message of fuzzyResults) {
|
|
388
|
+
try {
|
|
389
|
+
const content = message.content;
|
|
390
|
+
if (content.includes(IS_ENTITY_ASSOCIATION_FLAG)) {
|
|
391
|
+
const parsed = JSON.parse(content);
|
|
392
|
+
if (parsed.entityId && parsed.entityName && parsed.entityType) {
|
|
393
|
+
if (entityType && parsed.entityType !== entityType) {
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
associations.push(parsed);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
} catch {
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
const uniqueAssociations = associations.filter(
|
|
406
|
+
(assoc, index, arr) => arr.findIndex((a) => a.entityId === assoc.entityId) === index
|
|
407
|
+
).sort(
|
|
408
|
+
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
|
|
409
|
+
);
|
|
410
|
+
const results = uniqueAssociations.slice(0, safeLimit);
|
|
411
|
+
return results;
|
|
412
|
+
} catch (error) {
|
|
413
|
+
this.logger.error("Failed to resolve entity reference", {
|
|
414
|
+
query,
|
|
415
|
+
options,
|
|
416
|
+
error: error instanceof Error ? error.message : String(error)
|
|
417
|
+
});
|
|
418
|
+
return [];
|
|
115
419
|
}
|
|
116
420
|
}
|
|
421
|
+
/**
|
|
422
|
+
* Get all entity associations, optionally filtered by type
|
|
423
|
+
* @param entityType - Optional filter by entity type
|
|
424
|
+
* @returns Array of entity associations
|
|
425
|
+
*/
|
|
426
|
+
getEntityAssociations(entityType) {
|
|
427
|
+
try {
|
|
428
|
+
const rawFilter = entityType ? entityType.trim() : void 0;
|
|
429
|
+
const filterCanonical = rawFilter ? this.normalizeEntityType(rawFilter) : void 0;
|
|
430
|
+
if (entityType && (!rawFilter || rawFilter.length === 0)) {
|
|
431
|
+
return [];
|
|
432
|
+
}
|
|
433
|
+
const SEARCH_ANY_ENTITY = "entityId";
|
|
434
|
+
const searchQuery = filterCanonical || SEARCH_ANY_ENTITY;
|
|
435
|
+
const searchResults = this._contentStorage.searchMessages(searchQuery, {
|
|
436
|
+
caseSensitive: false,
|
|
437
|
+
limit: 100
|
|
438
|
+
});
|
|
439
|
+
const associations = [];
|
|
440
|
+
for (const message of searchResults) {
|
|
441
|
+
try {
|
|
442
|
+
const content = message.content;
|
|
443
|
+
if (content.includes(IS_ENTITY_ASSOCIATION_FLAG)) {
|
|
444
|
+
const parsed = JSON.parse(content);
|
|
445
|
+
if (parsed.entityId && parsed.entityName && parsed.entityType) {
|
|
446
|
+
if (filterCanonical && parsed.entityType !== filterCanonical) {
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
if (parsed.createdAt && typeof parsed.createdAt === "string") {
|
|
450
|
+
parsed.createdAt = new Date(parsed.createdAt);
|
|
451
|
+
}
|
|
452
|
+
associations.push(parsed);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
} catch (parseError) {
|
|
456
|
+
this.logger.warn("Failed to parse entity association from message", {
|
|
457
|
+
messageContent: typeof message.content === "string" ? message.content.substring(0, 100) : "non-string",
|
|
458
|
+
error: parseError instanceof Error ? parseError.message : String(parseError)
|
|
459
|
+
});
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
const mergedById = /* @__PURE__ */ new Map();
|
|
464
|
+
const getTime = (d) => d instanceof Date ? d.getTime() : new Date(d).getTime();
|
|
465
|
+
for (const assoc of associations) {
|
|
466
|
+
const existing = mergedById.get(assoc.entityId);
|
|
467
|
+
if (!existing) {
|
|
468
|
+
mergedById.set(assoc.entityId, assoc);
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
const existingTime = getTime(existing.createdAt);
|
|
472
|
+
const currentTime = getTime(assoc.createdAt);
|
|
473
|
+
const preferCurrent = currentTime > existingTime || !!assoc.transactionId && !existing.transactionId;
|
|
474
|
+
if (preferCurrent) {
|
|
475
|
+
mergedById.set(assoc.entityId, {
|
|
476
|
+
...existing,
|
|
477
|
+
...assoc
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
const results = Array.from(mergedById.values()).sort(
|
|
482
|
+
(a, b) => getTime(b.createdAt) - getTime(a.createdAt)
|
|
483
|
+
);
|
|
484
|
+
return results;
|
|
485
|
+
} catch (error) {
|
|
486
|
+
this.logger.error("Failed to get entity associations", {
|
|
487
|
+
entityType,
|
|
488
|
+
error: error instanceof Error ? error.message : String(error)
|
|
489
|
+
});
|
|
490
|
+
return [];
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Clean up resources and dispose of components
|
|
495
|
+
*/
|
|
496
|
+
dispose() {
|
|
497
|
+
this.memoryWindow.dispose();
|
|
498
|
+
this._contentStorage.dispose();
|
|
499
|
+
this.tokenCounter.dispose();
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
_SmartMemoryManager.DEFAULT_CONFIG = {
|
|
503
|
+
maxTokens: 8e3,
|
|
504
|
+
reserveTokens: 1e3,
|
|
505
|
+
modelName: "gpt-4o",
|
|
506
|
+
storageLimit: 1e3
|
|
117
507
|
};
|
|
118
|
-
|
|
119
|
-
_TokenCounter.ROLE_OVERHEAD = 1;
|
|
120
|
-
let TokenCounter = _TokenCounter;
|
|
508
|
+
let SmartMemoryManager = _SmartMemoryManager;
|
|
121
509
|
export {
|
|
122
|
-
|
|
510
|
+
SmartMemoryManager
|
|
123
511
|
};
|
|
124
512
|
//# sourceMappingURL=index19.js.map
|