@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/index7.js
CHANGED
|
@@ -1,96 +1,847 @@
|
|
|
1
|
+
import { ServerSigner, getAllHederaCorePlugins } from "hedera-agent-kit";
|
|
1
2
|
import { Logger } from "@hashgraphonline/standards-sdk";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { createAgent } from "./index9.js";
|
|
4
|
+
import { BrowserSigner } from "./index40.js";
|
|
5
|
+
import { LangChainProvider } from "./index10.js";
|
|
6
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
7
|
+
import { ChatAnthropic } from "@langchain/anthropic";
|
|
8
|
+
import { SystemMessage, HumanMessage, AIMessage } from "@langchain/core/messages";
|
|
9
|
+
import { HCS10Plugin } from "./index2.js";
|
|
10
|
+
import { HCS2Plugin } from "./index3.js";
|
|
11
|
+
import { InscribePlugin } from "./index4.js";
|
|
12
|
+
import { getWalletBridgeProvider } from "./index37.js";
|
|
13
|
+
import { OpenConvaiState, InscriberBuilder, SignerProviderRegistry } from "@hashgraphonline/standards-agent-kit";
|
|
14
|
+
import { HbarPlugin } from "./index5.js";
|
|
15
|
+
import { WebBrowserPlugin } from "./index41.js";
|
|
16
|
+
import { getSystemMessage } from "./index42.js";
|
|
17
|
+
import { ContentStoreManager } from "./index25.js";
|
|
18
|
+
import { SmartMemoryManager } from "./index19.js";
|
|
19
|
+
import "./index20.js";
|
|
20
|
+
import "./index21.js";
|
|
21
|
+
import "./index22.js";
|
|
22
|
+
import "crypto";
|
|
23
|
+
import { createEntityTools } from "./index35.js";
|
|
24
|
+
import { ParameterService } from "./index30.js";
|
|
25
|
+
import { FormatConverterRegistry } from "./index26.js";
|
|
26
|
+
import { TopicIdToHrlConverter } from "./index28.js";
|
|
27
|
+
import { StringNormalizationConverter } from "./index29.js";
|
|
28
|
+
const DEFAULT_MODEL_NAME = "gpt-4o";
|
|
29
|
+
const DEFAULT_OPENAI_MODEL = "gpt-4o-mini";
|
|
30
|
+
const DEFAULT_OPENROUTER_MODEL = "openai/gpt-4o-mini";
|
|
31
|
+
const DEFAULT_CLAUDE_MODEL = "claude-3-7-sonnet-latest";
|
|
32
|
+
const DEFAULT_TEMPERATURE = 0.1;
|
|
33
|
+
const DEFAULT_NETWORK = "testnet";
|
|
34
|
+
const DEFAULT_OPERATIONAL_MODE = "autonomous";
|
|
35
|
+
const _ConversationalAgent = class _ConversationalAgent {
|
|
36
|
+
constructor(options) {
|
|
37
|
+
this.options = options;
|
|
38
|
+
this.stateManager = options.stateManager || new OpenConvaiState();
|
|
39
|
+
this.hcs10Plugin = new HCS10Plugin();
|
|
40
|
+
this.hcs2Plugin = new HCS2Plugin();
|
|
41
|
+
this.inscribePlugin = new InscribePlugin();
|
|
42
|
+
this.hbarPlugin = new HbarPlugin();
|
|
43
|
+
this.webBrowserPlugin = new WebBrowserPlugin();
|
|
7
44
|
this.logger = new Logger({
|
|
8
|
-
module: "
|
|
9
|
-
silent:
|
|
45
|
+
module: "ConversationalAgent",
|
|
46
|
+
silent: options.disableLogging || false
|
|
10
47
|
});
|
|
48
|
+
if (this.options.entityMemoryEnabled !== false) {
|
|
49
|
+
if (!options.openAIApiKey) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
"OpenAI/Anthropic API key is required when entity memory is enabled"
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
this.memoryManager = new SmartMemoryManager(
|
|
55
|
+
this.options.entityMemoryConfig
|
|
56
|
+
);
|
|
57
|
+
this.logger.info("Entity memory initialized");
|
|
58
|
+
const provider = options.entityMemoryProvider || options.llmProvider || "openai";
|
|
59
|
+
let modelName = options.entityMemoryModelName;
|
|
60
|
+
if (!modelName) {
|
|
61
|
+
if (provider === "anthropic") {
|
|
62
|
+
modelName = DEFAULT_CLAUDE_MODEL;
|
|
63
|
+
} else if (provider === "openrouter") {
|
|
64
|
+
modelName = DEFAULT_OPENROUTER_MODEL;
|
|
65
|
+
} else {
|
|
66
|
+
modelName = DEFAULT_OPENAI_MODEL;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
let resolverLLM;
|
|
70
|
+
if (provider === "anthropic") {
|
|
71
|
+
resolverLLM = new ChatAnthropic({
|
|
72
|
+
apiKey: options.openAIApiKey,
|
|
73
|
+
model: modelName,
|
|
74
|
+
temperature: 0
|
|
75
|
+
});
|
|
76
|
+
} else if (provider === "openrouter") {
|
|
77
|
+
const baseURL = options.openRouterBaseURL || "https://openrouter.ai/api/v1";
|
|
78
|
+
const apiKey = options.openRouterApiKey || options.openAIApiKey;
|
|
79
|
+
resolverLLM = new ChatOpenAI({
|
|
80
|
+
apiKey,
|
|
81
|
+
model: modelName,
|
|
82
|
+
temperature: 0,
|
|
83
|
+
configuration: {
|
|
84
|
+
baseURL,
|
|
85
|
+
defaultHeaders: {
|
|
86
|
+
"HTTP-Referer": process.env.OPENROUTER_REFERRER || "https://hashgraphonline.com",
|
|
87
|
+
"X-Title": process.env.OPENROUTER_TITLE || "Hashgraph Online Conversational Agent"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
} else {
|
|
92
|
+
resolverLLM = new ChatOpenAI({
|
|
93
|
+
apiKey: options.openAIApiKey,
|
|
94
|
+
model: modelName,
|
|
95
|
+
temperature: 0
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
this.entityTools = createEntityTools(resolverLLM);
|
|
99
|
+
this.logger.info("LLM-based entity resolver tools initialized");
|
|
100
|
+
}
|
|
11
101
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Initialize the conversational agent with Hedera Hashgraph connection and AI configuration
|
|
104
|
+
* @throws {Error} If account ID or private key is missing
|
|
105
|
+
* @throws {Error} If initialization fails
|
|
106
|
+
*/
|
|
107
|
+
async initialize() {
|
|
108
|
+
const {
|
|
109
|
+
accountId,
|
|
110
|
+
privateKey,
|
|
111
|
+
network = DEFAULT_NETWORK,
|
|
112
|
+
openAIApiKey,
|
|
113
|
+
openAIModelName = DEFAULT_MODEL_NAME,
|
|
114
|
+
llmProvider = "openai"
|
|
115
|
+
} = this.options;
|
|
116
|
+
this.validateOptions(accountId, privateKey);
|
|
117
|
+
try {
|
|
118
|
+
const opMode = this.options.operationalMode || DEFAULT_OPERATIONAL_MODE;
|
|
119
|
+
const bytesMode = opMode !== "autonomous";
|
|
120
|
+
let signer;
|
|
121
|
+
try {
|
|
122
|
+
const IB = InscriberBuilder;
|
|
123
|
+
if (typeof IB.setPreferWalletOnly === "function") {
|
|
124
|
+
IB.setPreferWalletOnly(false);
|
|
125
|
+
}
|
|
126
|
+
} catch (e) {
|
|
127
|
+
this.logger.warn("Failed to set wallet-only preference", e);
|
|
128
|
+
}
|
|
129
|
+
if (!bytesMode) {
|
|
130
|
+
signer = new ServerSigner(
|
|
131
|
+
accountId,
|
|
132
|
+
privateKey,
|
|
133
|
+
network
|
|
134
|
+
);
|
|
135
|
+
} else {
|
|
136
|
+
const chain = String(network || "testnet") === "mainnet" ? "mainnet" : "testnet";
|
|
137
|
+
const effectiveAccount = this.options.userAccountId || accountId;
|
|
138
|
+
signer = new BrowserSigner(
|
|
139
|
+
effectiveAccount,
|
|
140
|
+
chain,
|
|
141
|
+
this.options.walletExecutor
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
this.logger.info("Signer configured", {
|
|
145
|
+
operationalMode: opMode,
|
|
146
|
+
bytesMode,
|
|
147
|
+
signerClass: Object.getPrototypeOf(signer)?.constructor?.name || "unknown"
|
|
23
148
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
149
|
+
try {
|
|
150
|
+
const bridge = getWalletBridgeProvider();
|
|
151
|
+
if (bridge) {
|
|
152
|
+
const IB = InscriberBuilder;
|
|
153
|
+
if (typeof IB.setWalletInfoResolver === "function") {
|
|
154
|
+
IB.setWalletInfoResolver(async () => {
|
|
155
|
+
const status = await bridge.status();
|
|
156
|
+
if (status.connected && status.accountId && status.network) {
|
|
157
|
+
return { accountId: status.accountId, network: status.network };
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
if (typeof IB.setWalletExecutor === "function") {
|
|
163
|
+
IB.setWalletExecutor(
|
|
164
|
+
async (base64, network2) => {
|
|
165
|
+
return await bridge.executeBytes(base64, network2);
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
if (typeof IB.setStartInscriptionDelegate === "function" && bridge.startInscription) {
|
|
170
|
+
IB.setStartInscriptionDelegate(
|
|
171
|
+
async (request, network2) => {
|
|
172
|
+
return await bridge.startInscription(request, network2);
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
const status = await bridge.status();
|
|
178
|
+
const enforceWallet = !!(bytesMode && status.connected);
|
|
179
|
+
SignerProviderRegistry.setWalletInfoResolver(async () => {
|
|
180
|
+
const s = await bridge.status();
|
|
181
|
+
if (s.connected && s.accountId && s.network) {
|
|
182
|
+
return {
|
|
183
|
+
accountId: s.accountId,
|
|
184
|
+
network: s.network
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
});
|
|
189
|
+
SignerProviderRegistry.setWalletExecutor(
|
|
190
|
+
async (base64, network2) => {
|
|
191
|
+
return await bridge.executeBytes(base64, network2);
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
const extended = bridge;
|
|
195
|
+
if (typeof extended?.startHCS === "function") {
|
|
196
|
+
SignerProviderRegistry.setStartHCSDelegate(
|
|
197
|
+
async (op, request, network2) => {
|
|
198
|
+
return await extended.startHCS(
|
|
199
|
+
op,
|
|
200
|
+
request,
|
|
201
|
+
network2
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
);
|
|
205
|
+
} else {
|
|
206
|
+
SignerProviderRegistry.setStartHCSDelegate(null);
|
|
207
|
+
}
|
|
208
|
+
SignerProviderRegistry.setPreferWalletOnly(enforceWallet);
|
|
209
|
+
const IB2 = InscriberBuilder;
|
|
210
|
+
if (typeof IB2.setPreferWalletOnly === "function") {
|
|
211
|
+
IB2.setPreferWalletOnly(enforceWallet);
|
|
212
|
+
}
|
|
213
|
+
} catch (sakWireErr) {
|
|
214
|
+
this.logger.warn(
|
|
215
|
+
"Failed to wire SAK SignerProviderRegistry wallet delegates",
|
|
216
|
+
sakWireErr
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
} catch (e) {
|
|
221
|
+
this.logger.warn(
|
|
222
|
+
"Failed to register wallet bridge providers",
|
|
223
|
+
e
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
let llm;
|
|
227
|
+
let providerInfo = { provider: llmProvider };
|
|
228
|
+
if (llmProvider === "anthropic") {
|
|
229
|
+
llm = new ChatAnthropic({
|
|
230
|
+
apiKey: openAIApiKey,
|
|
231
|
+
model: openAIModelName || DEFAULT_CLAUDE_MODEL,
|
|
232
|
+
temperature: DEFAULT_TEMPERATURE
|
|
233
|
+
});
|
|
234
|
+
providerInfo = {
|
|
235
|
+
...providerInfo,
|
|
236
|
+
model: openAIModelName || DEFAULT_CLAUDE_MODEL,
|
|
237
|
+
keyPresent: !!openAIApiKey
|
|
238
|
+
};
|
|
239
|
+
} else if (llmProvider === "openrouter") {
|
|
240
|
+
const baseURL = this.options.openRouterBaseURL || "https://openrouter.ai/api/v1";
|
|
241
|
+
const apiKey = this.options.openRouterApiKey || openAIApiKey;
|
|
242
|
+
const modelName = openAIModelName || "anthropic/claude-3-haiku-20240307";
|
|
243
|
+
llm = new ChatOpenAI({
|
|
244
|
+
apiKey,
|
|
245
|
+
model: modelName,
|
|
246
|
+
temperature: DEFAULT_TEMPERATURE,
|
|
247
|
+
configuration: {
|
|
248
|
+
baseURL,
|
|
249
|
+
defaultHeaders: {
|
|
250
|
+
"HTTP-Referer": process.env.OPENROUTER_REFERRER || "https://hashgraphonline.com",
|
|
251
|
+
"X-Title": process.env.OPENROUTER_TITLE || "Hashgraph Online Conversational Agent"
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
providerInfo = {
|
|
256
|
+
...providerInfo,
|
|
257
|
+
model: modelName,
|
|
258
|
+
baseURL,
|
|
259
|
+
keyPresent: !!apiKey
|
|
260
|
+
};
|
|
261
|
+
} else {
|
|
262
|
+
const modelName2 = openAIModelName || DEFAULT_OPENAI_MODEL;
|
|
263
|
+
const isGPT5Model = modelName2.toLowerCase().includes("gpt-5") || modelName2.toLowerCase().includes("gpt5");
|
|
264
|
+
llm = new ChatOpenAI({
|
|
265
|
+
apiKey: openAIApiKey,
|
|
266
|
+
model: modelName2,
|
|
267
|
+
...isGPT5Model ? { temperature: 1 } : { temperature: DEFAULT_TEMPERATURE }
|
|
268
|
+
});
|
|
269
|
+
providerInfo = {
|
|
270
|
+
...providerInfo,
|
|
271
|
+
model: modelName2,
|
|
272
|
+
keyPresent: !!openAIApiKey
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
this.logger.info("AI provider configured", providerInfo);
|
|
276
|
+
this.logger.info("Preparing plugins...");
|
|
277
|
+
const allPlugins = this.preparePlugins();
|
|
278
|
+
this.logger.info("Creating agent config...");
|
|
279
|
+
const agentConfig = this.createAgentConfig(
|
|
280
|
+
signer,
|
|
281
|
+
llm,
|
|
282
|
+
allPlugins
|
|
28
283
|
);
|
|
284
|
+
this.logger.info("Creating agent...");
|
|
285
|
+
this.agent = createAgent(agentConfig);
|
|
286
|
+
this.logger.info("Agent created");
|
|
287
|
+
this.logger.info("Configuring HCS10 plugin...");
|
|
288
|
+
this.configureHCS10Plugin(allPlugins);
|
|
289
|
+
this.logger.info("HCS10 plugin configured");
|
|
290
|
+
this.contentStoreManager = new ContentStoreManager();
|
|
291
|
+
await this.contentStoreManager.initialize();
|
|
292
|
+
this.logger.info(
|
|
293
|
+
"ContentStoreManager initialized for content reference support"
|
|
294
|
+
);
|
|
295
|
+
this.logger.info("About to call agent.boot()");
|
|
296
|
+
this.logger.info("🔥 About to call agent.boot()");
|
|
297
|
+
await this.agent.boot();
|
|
298
|
+
this.logger.info("agent.boot() completed");
|
|
299
|
+
this.logger.info("🔥 agent.boot() completed");
|
|
300
|
+
if (this.agent) {
|
|
301
|
+
try {
|
|
302
|
+
const registry = new FormatConverterRegistry();
|
|
303
|
+
registry.register(new TopicIdToHrlConverter());
|
|
304
|
+
registry.register(new StringNormalizationConverter());
|
|
305
|
+
const paramService = new ParameterService(
|
|
306
|
+
registry,
|
|
307
|
+
this.options.network || "testnet"
|
|
308
|
+
);
|
|
309
|
+
paramService.attachToAgent(this.agent, {
|
|
310
|
+
getEntities: async () => this.memoryManager?.getEntityAssociations() || []
|
|
311
|
+
});
|
|
312
|
+
this.logger.info(
|
|
313
|
+
"Parameter preprocessing callback attached (internal)"
|
|
314
|
+
);
|
|
315
|
+
} catch (e) {
|
|
316
|
+
this.logger.warn(
|
|
317
|
+
"Failed to attach internal parameter preprocessing callback",
|
|
318
|
+
e
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
const cfg = agentConfig;
|
|
322
|
+
cfg.filtering = cfg.filtering || {};
|
|
323
|
+
const originalPredicate = cfg.filtering.toolPredicate;
|
|
324
|
+
const userPredicate = this.options.toolFilter;
|
|
325
|
+
cfg.filtering.toolPredicate = (tool) => {
|
|
326
|
+
if (tool && tool.name === "hedera-account-transfer-hbar") {
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
if (tool && tool.name === "hedera-hts-airdrop-token") {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
if (originalPredicate && !originalPredicate(tool)) {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
if (userPredicate && !userPredicate(tool)) {
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
return true;
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
if (this.options.mcpServers && this.options.mcpServers.length > 0) {
|
|
342
|
+
this.connectMCP();
|
|
343
|
+
}
|
|
344
|
+
} catch (error) {
|
|
345
|
+
this.logger.error("Failed to initialize ConversationalAgent:", error);
|
|
346
|
+
throw error;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Get the HCS-10 plugin instance
|
|
351
|
+
* @returns {HCS10Plugin} The HCS-10 plugin instance
|
|
352
|
+
*/
|
|
353
|
+
getPlugin() {
|
|
354
|
+
return this.hcs10Plugin;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Get the state manager instance
|
|
358
|
+
* @returns {IStateManager} The state manager instance
|
|
359
|
+
*/
|
|
360
|
+
getStateManager() {
|
|
361
|
+
return this.stateManager;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Get the underlying agent instance
|
|
365
|
+
* @returns {ReturnType<typeof createAgent>} The agent instance
|
|
366
|
+
* @throws {Error} If agent is not initialized
|
|
367
|
+
*/
|
|
368
|
+
getAgent() {
|
|
369
|
+
if (!this.agent) {
|
|
370
|
+
throw new Error(_ConversationalAgent.NOT_INITIALIZED_ERROR);
|
|
371
|
+
}
|
|
372
|
+
return this.agent;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Get the conversational agent instance (alias for getAgent)
|
|
376
|
+
* @returns {ReturnType<typeof createAgent>} The agent instance
|
|
377
|
+
* @throws {Error} If agent is not initialized
|
|
378
|
+
*/
|
|
379
|
+
getConversationalAgent() {
|
|
380
|
+
return this.getAgent();
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Process a message through the conversational agent
|
|
384
|
+
* @param {string} message - The message to process
|
|
385
|
+
* @param {Array<{type: 'human' | 'ai'; content: string}>} chatHistory - Previous chat history
|
|
386
|
+
* @returns {Promise<ChatResponse>} The agent's response
|
|
387
|
+
* @throws {Error} If agent is not initialized
|
|
388
|
+
*/
|
|
389
|
+
async processMessage(message, chatHistory = []) {
|
|
390
|
+
if (!this.agent) {
|
|
391
|
+
throw new Error("Agent not initialized. Call initialize() first.");
|
|
392
|
+
}
|
|
393
|
+
try {
|
|
394
|
+
const resolvedMessage = message;
|
|
395
|
+
const messages = chatHistory.map((msg) => {
|
|
396
|
+
const content = msg.content;
|
|
397
|
+
if (msg.type === "system") {
|
|
398
|
+
return new SystemMessage(content);
|
|
399
|
+
}
|
|
400
|
+
return msg.type === "human" ? new HumanMessage(content) : new AIMessage(content);
|
|
401
|
+
});
|
|
402
|
+
const context = { messages };
|
|
403
|
+
const response = await this.agent.chat(resolvedMessage, context);
|
|
404
|
+
if (this.memoryManager && this.options.operationalMode !== "returnBytes") {
|
|
405
|
+
await this.extractAndStoreEntities(response, message);
|
|
406
|
+
}
|
|
407
|
+
this.logger.info("Message processed successfully");
|
|
408
|
+
return response;
|
|
409
|
+
} catch (error) {
|
|
410
|
+
this.logger.error("Error processing message:", error);
|
|
411
|
+
throw error;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Process form submission through the conversational agent
|
|
416
|
+
* @param {FormSubmission} submission - The form submission data
|
|
417
|
+
* @returns {Promise<ChatResponse>} The agent's response after processing the form
|
|
418
|
+
* @throws {Error} If agent is not initialized or doesn't support form processing
|
|
419
|
+
*/
|
|
420
|
+
async processFormSubmission(submission) {
|
|
421
|
+
if (!this.agent) {
|
|
422
|
+
throw new Error(_ConversationalAgent.NOT_INITIALIZED_ERROR);
|
|
423
|
+
}
|
|
424
|
+
try {
|
|
425
|
+
this.logger.info("Processing form submission:", {
|
|
426
|
+
formId: submission.formId,
|
|
427
|
+
toolName: submission.toolName,
|
|
428
|
+
parameterKeys: Object.keys(submission.parameters || {}),
|
|
429
|
+
hasContext: !!submission.context
|
|
430
|
+
});
|
|
431
|
+
const response = await this.agent.processFormSubmission(submission);
|
|
432
|
+
this.logger.info("Form submission processed successfully");
|
|
433
|
+
return response;
|
|
434
|
+
} catch (error) {
|
|
435
|
+
this.logger.error("Error processing form submission:", error);
|
|
436
|
+
throw error;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Validates initialization options and throws if required fields are missing.
|
|
441
|
+
*
|
|
442
|
+
* @param accountId - The Hedera account ID
|
|
443
|
+
* @param privateKey - The private key for the account
|
|
444
|
+
* @throws {Error} If required fields are missing
|
|
445
|
+
*/
|
|
446
|
+
validateOptions(accountId, privateKey) {
|
|
447
|
+
const opMode = this.options.operationalMode || DEFAULT_OPERATIONAL_MODE;
|
|
448
|
+
const bytesMode = opMode !== "autonomous";
|
|
449
|
+
if (!accountId) {
|
|
450
|
+
throw new Error("Account ID is required");
|
|
29
451
|
}
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
buildSystemPrompt() {
|
|
37
|
-
const parts = [];
|
|
38
|
-
const operatorId = this.config.signer.getAccountId().toString();
|
|
39
|
-
const userAccId = this.config.execution?.userAccountId;
|
|
40
|
-
if (this.config.messaging?.systemPreamble) {
|
|
41
|
-
parts.push(this.config.messaging.systemPreamble);
|
|
42
|
-
}
|
|
43
|
-
parts.push(
|
|
44
|
-
`You are a helpful Hedera assistant. Your primary operator account is ${operatorId}. You have tools to interact with the Hedera Hashgraph. When using any tool, provide all necessary parameters as defined by that tool's schema and description.`
|
|
45
|
-
);
|
|
46
|
-
parts.push(
|
|
47
|
-
`
|
|
48
|
-
METADATA QUALITY PRINCIPLES: When collecting user input for metadata creation across any tool:
|
|
49
|
-
• Prioritize meaningful, valuable content over technical file information
|
|
50
|
-
• Focus on attributes that add value for end users and collectors
|
|
51
|
-
• Avoid auto-generating meaningless technical attributes as user-facing metadata
|
|
52
|
-
• When fields are missing or inadequate, use forms to collect quality metadata
|
|
53
|
-
• Encourage descriptive names, collectible traits, and storytelling elements`
|
|
54
|
-
);
|
|
55
|
-
if (userAccId) {
|
|
56
|
-
parts.push(
|
|
57
|
-
`The user you are assisting has a personal Hedera account ID: ${userAccId}. IMPORTANT: When the user says things like "I want to send HBAR" or "transfer my tokens", you MUST use ${userAccId} as the sender/from account. For example, if user says "I want to send 2 HBAR to 0.0.800", you must set up a transfer where ${userAccId} sends the HBAR, not your operator account.`
|
|
452
|
+
if (!privateKey && !bytesMode) {
|
|
453
|
+
throw new Error("Private key is required in autonomous mode");
|
|
454
|
+
}
|
|
455
|
+
if (typeof accountId !== "string") {
|
|
456
|
+
throw new Error(
|
|
457
|
+
`Account ID must be a string, received ${typeof accountId}`
|
|
58
458
|
);
|
|
59
459
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
460
|
+
if (!bytesMode && typeof privateKey !== "string") {
|
|
461
|
+
throw new Error(
|
|
462
|
+
`Private key must be a string, received ${typeof privateKey}: ${JSON.stringify(
|
|
463
|
+
privateKey
|
|
464
|
+
)}`
|
|
65
465
|
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
466
|
+
}
|
|
467
|
+
if (!bytesMode && typeof privateKey === "string" && privateKey.length < 10) {
|
|
468
|
+
throw new Error("Private key appears to be invalid (too short)");
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Prepares the list of plugins to use based on configuration.
|
|
473
|
+
*
|
|
474
|
+
* @returns Array of plugins to initialize with the agent
|
|
475
|
+
*/
|
|
476
|
+
preparePlugins() {
|
|
477
|
+
const { additionalPlugins = [], enabledPlugins, disabledPlugins } = this.options;
|
|
478
|
+
const standardPlugins = [
|
|
479
|
+
this.hcs10Plugin,
|
|
480
|
+
this.hcs2Plugin,
|
|
481
|
+
this.inscribePlugin,
|
|
482
|
+
this.hbarPlugin
|
|
483
|
+
];
|
|
484
|
+
standardPlugins.push(this.webBrowserPlugin);
|
|
485
|
+
const corePlugins = getAllHederaCorePlugins();
|
|
486
|
+
let pluginPool = [...standardPlugins, ...corePlugins];
|
|
487
|
+
if (enabledPlugins) {
|
|
488
|
+
const enabledSet = new Set(enabledPlugins);
|
|
489
|
+
pluginPool = pluginPool.filter((plugin) => enabledSet.has(plugin.id));
|
|
490
|
+
}
|
|
491
|
+
if (disabledPlugins && disabledPlugins.length > 0) {
|
|
492
|
+
const disabledSet = new Set(disabledPlugins);
|
|
493
|
+
pluginPool = pluginPool.filter((plugin) => !disabledSet.has(plugin.id));
|
|
494
|
+
}
|
|
495
|
+
const additional = disabledPlugins && disabledPlugins.length > 0 ? additionalPlugins.filter((plugin) => !disabledPlugins.includes(plugin.id)) : additionalPlugins;
|
|
496
|
+
return [...pluginPool, ...additional];
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Creates the agent configuration object.
|
|
500
|
+
*
|
|
501
|
+
* @param signer - The signer instance
|
|
502
|
+
* @param llm - The language model instance
|
|
503
|
+
* @param allPlugins - Array of plugins to use
|
|
504
|
+
* @returns Configuration object for creating the agent
|
|
505
|
+
*/
|
|
506
|
+
createAgentConfig(signer, llm, allPlugins) {
|
|
507
|
+
const {
|
|
508
|
+
operationalMode = DEFAULT_OPERATIONAL_MODE,
|
|
509
|
+
userAccountId,
|
|
510
|
+
scheduleUserTransactionsInBytesMode,
|
|
511
|
+
customSystemMessagePreamble,
|
|
512
|
+
customSystemMessagePostamble,
|
|
513
|
+
verbose = false,
|
|
514
|
+
mirrorNodeConfig,
|
|
515
|
+
disableLogging,
|
|
516
|
+
accountId = ""
|
|
517
|
+
} = this.options;
|
|
518
|
+
return {
|
|
519
|
+
framework: "langchain",
|
|
520
|
+
signer,
|
|
521
|
+
execution: {
|
|
522
|
+
mode: operationalMode === "autonomous" ? "direct" : "bytes",
|
|
523
|
+
operationalMode,
|
|
524
|
+
...userAccountId && { userAccountId },
|
|
525
|
+
...scheduleUserTransactionsInBytesMode !== void 0 && {
|
|
526
|
+
scheduleUserTransactionsInBytesMode,
|
|
527
|
+
scheduleUserTransactions: scheduleUserTransactionsInBytesMode
|
|
528
|
+
}
|
|
529
|
+
},
|
|
530
|
+
ai: {
|
|
531
|
+
provider: new LangChainProvider(llm),
|
|
532
|
+
temperature: DEFAULT_TEMPERATURE
|
|
533
|
+
},
|
|
534
|
+
filtering: {
|
|
535
|
+
toolPredicate: (tool) => {
|
|
536
|
+
if (tool.name === "hedera-account-transfer-hbar") return false;
|
|
537
|
+
if (this.options.toolFilter && !this.options.toolFilter(tool)) {
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
},
|
|
543
|
+
messaging: {
|
|
544
|
+
systemPreamble: customSystemMessagePreamble || getSystemMessage(accountId),
|
|
545
|
+
...customSystemMessagePostamble && {
|
|
546
|
+
systemPostamble: customSystemMessagePostamble
|
|
547
|
+
},
|
|
548
|
+
conciseMode: true
|
|
549
|
+
},
|
|
550
|
+
extensions: {
|
|
551
|
+
plugins: allPlugins,
|
|
552
|
+
...mirrorNodeConfig && {
|
|
553
|
+
mirrorConfig: mirrorNodeConfig
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
...this.options.mcpServers && {
|
|
557
|
+
mcp: {
|
|
558
|
+
servers: this.options.mcpServers,
|
|
559
|
+
autoConnect: false
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
debug: {
|
|
563
|
+
verbose,
|
|
564
|
+
silent: disableLogging ?? false
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Configures the HCS-10 plugin with the state manager.
|
|
570
|
+
*
|
|
571
|
+
* @param allPlugins - Array of all plugins
|
|
572
|
+
*/
|
|
573
|
+
configureHCS10Plugin(allPlugins) {
|
|
574
|
+
const hcs10 = allPlugins.find((p) => p.id === "hcs-10");
|
|
575
|
+
if (hcs10) {
|
|
576
|
+
hcs10.appConfig = {
|
|
577
|
+
stateManager: this.stateManager
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Create a ConversationalAgent with specific plugins enabled
|
|
583
|
+
*/
|
|
584
|
+
static withPlugins(options, plugins) {
|
|
585
|
+
return new _ConversationalAgent({
|
|
586
|
+
...options,
|
|
587
|
+
enabledPlugins: plugins
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Create a ConversationalAgent with only HTS (Hedera Token Service) tools enabled
|
|
592
|
+
*/
|
|
593
|
+
static withHTS(options) {
|
|
594
|
+
return this.withPlugins(options, ["hts-token"]);
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Create a ConversationalAgent with only HCS-2 tools enabled
|
|
598
|
+
*/
|
|
599
|
+
static withHCS2(options) {
|
|
600
|
+
return this.withPlugins(options, ["hcs-2"]);
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Create a ConversationalAgent with only HCS-10 tools enabled
|
|
604
|
+
*/
|
|
605
|
+
static withHCS10(options) {
|
|
606
|
+
return this.withPlugins(options, ["hcs-10"]);
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Create a ConversationalAgent with only inscription tools enabled
|
|
610
|
+
*/
|
|
611
|
+
static withInscribe(options) {
|
|
612
|
+
return this.withPlugins(options, ["inscribe"]);
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Create a ConversationalAgent with only account management tools enabled
|
|
616
|
+
*/
|
|
617
|
+
static withAccount(options) {
|
|
618
|
+
return this.withPlugins(options, ["account"]);
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Create a ConversationalAgent with only file service tools enabled
|
|
622
|
+
*/
|
|
623
|
+
static withFileService(options) {
|
|
624
|
+
return this.withPlugins(options, ["file-service"]);
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Create a ConversationalAgent with only consensus service tools enabled
|
|
628
|
+
*/
|
|
629
|
+
static withConsensusService(options) {
|
|
630
|
+
return this.withPlugins(options, ["consensus-service"]);
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Create a ConversationalAgent with only smart contract tools enabled
|
|
634
|
+
*/
|
|
635
|
+
static withSmartContract(options) {
|
|
636
|
+
return this.withPlugins(options, ["smart-contract"]);
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Create a ConversationalAgent with all HCS standards plugins
|
|
640
|
+
*/
|
|
641
|
+
static withAllStandards(options) {
|
|
642
|
+
return this.withPlugins(options, ["hcs-10", "hcs-2", "inscribe"]);
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Create a ConversationalAgent with minimal Hedera tools (no HCS standards)
|
|
646
|
+
*/
|
|
647
|
+
static minimal(options) {
|
|
648
|
+
return this.withPlugins(options, []);
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Create a ConversationalAgent with MCP servers configured
|
|
652
|
+
*/
|
|
653
|
+
static withMCP(options, mcpServers) {
|
|
654
|
+
return new _ConversationalAgent({
|
|
655
|
+
...options,
|
|
656
|
+
mcpServers
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Extract and store entities from agent responses
|
|
661
|
+
* @param response - Agent response containing potential entity information
|
|
662
|
+
* @param originalMessage - Original user message for context
|
|
663
|
+
*/
|
|
664
|
+
async extractAndStoreEntities(response, originalMessage) {
|
|
665
|
+
if (!this.memoryManager || !this.entityTools) {
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
try {
|
|
669
|
+
this.logger.info("Starting LLM-based entity extraction");
|
|
670
|
+
const responseText = this.extractResponseText(response);
|
|
671
|
+
const entitiesJson = await this.entityTools.extractEntities.call({
|
|
672
|
+
response: responseText,
|
|
673
|
+
userMessage: originalMessage
|
|
674
|
+
});
|
|
675
|
+
try {
|
|
676
|
+
const entities = JSON.parse(entitiesJson);
|
|
677
|
+
for (const entity of entities) {
|
|
678
|
+
if (entity && typeof entity === "object" && "name" in entity && "type" in entity && "id" in entity) {
|
|
679
|
+
this.logger.info(
|
|
680
|
+
`Storing entity: ${entity.name} (${entity.type}) -> ${entity.id}`
|
|
681
|
+
);
|
|
682
|
+
const transactionId = this.extractTransactionId(response);
|
|
683
|
+
const idStr = String(entity.id);
|
|
684
|
+
const isHederaId = /^0\.0\.[0-9]+$/.test(idStr);
|
|
685
|
+
if (!isHederaId) {
|
|
686
|
+
this.logger.warn("Skipping non-ID entity from extraction", {
|
|
687
|
+
id: idStr,
|
|
688
|
+
name: String(entity.name),
|
|
689
|
+
type: String(entity.type)
|
|
690
|
+
});
|
|
691
|
+
} else {
|
|
692
|
+
this.memoryManager.storeEntityAssociation(
|
|
693
|
+
idStr,
|
|
694
|
+
String(entity.name),
|
|
695
|
+
String(entity.type),
|
|
696
|
+
transactionId
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
if (entities.length > 0) {
|
|
702
|
+
this.logger.info(
|
|
703
|
+
`Stored ${entities.length} entities via LLM extraction`
|
|
704
|
+
);
|
|
705
|
+
} else {
|
|
706
|
+
this.logger.info("No entities found in response via LLM extraction");
|
|
707
|
+
}
|
|
708
|
+
} catch (parseError) {
|
|
709
|
+
this.logger.error(
|
|
710
|
+
"Failed to parse extracted entities JSON:",
|
|
711
|
+
parseError
|
|
71
712
|
);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
713
|
+
throw parseError;
|
|
714
|
+
}
|
|
715
|
+
} catch (error) {
|
|
716
|
+
this.logger.error("Entity extraction failed:", error);
|
|
717
|
+
throw error;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Extract transaction ID from response if available
|
|
722
|
+
* @param response - Transaction response
|
|
723
|
+
* @returns Transaction ID or undefined
|
|
724
|
+
*/
|
|
725
|
+
extractTransactionId(response) {
|
|
726
|
+
try {
|
|
727
|
+
if (typeof response === "object" && response && "transactionId" in response) {
|
|
728
|
+
const responseWithTxId = response;
|
|
729
|
+
return typeof responseWithTxId.transactionId === "string" ? responseWithTxId.transactionId : void 0;
|
|
730
|
+
}
|
|
731
|
+
if (typeof response === "string") {
|
|
732
|
+
const match = response.match(
|
|
733
|
+
/transaction[\s\w]*ID[\s:"]*([0-9a-fA-F@._-]+)/i
|
|
76
734
|
);
|
|
735
|
+
return match ? match[1] : void 0;
|
|
77
736
|
}
|
|
737
|
+
return void 0;
|
|
738
|
+
} catch {
|
|
739
|
+
return void 0;
|
|
78
740
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Connect to MCP servers asynchronously
|
|
744
|
+
* @private
|
|
745
|
+
*/
|
|
746
|
+
connectMCP() {
|
|
747
|
+
if (!this.agent || !this.options.mcpServers) {
|
|
748
|
+
return;
|
|
83
749
|
}
|
|
84
|
-
|
|
85
|
-
|
|
750
|
+
this.agent.connectMCPServers().catch((e) => {
|
|
751
|
+
this.logger.error("Failed to connect MCP servers:", e);
|
|
752
|
+
}).then(() => {
|
|
753
|
+
this.logger.info("MCP servers connected successfully");
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Get MCP connection status for all servers
|
|
758
|
+
* @returns {Map<string, MCPConnectionStatus>} Connection status map
|
|
759
|
+
*/
|
|
760
|
+
getMCPConnectionStatus() {
|
|
761
|
+
if (this.agent) {
|
|
762
|
+
return this.agent.getMCPConnectionStatus();
|
|
86
763
|
}
|
|
87
|
-
return
|
|
764
|
+
return /* @__PURE__ */ new Map();
|
|
88
765
|
}
|
|
89
|
-
|
|
90
|
-
|
|
766
|
+
/**
|
|
767
|
+
* Check if a specific MCP server is connected
|
|
768
|
+
* @param {string} serverName - Name of the server to check
|
|
769
|
+
* @returns {boolean} True if connected, false otherwise
|
|
770
|
+
*/
|
|
771
|
+
isMCPServerConnected(serverName) {
|
|
772
|
+
if (this.agent) {
|
|
773
|
+
const statusMap = this.agent.getMCPConnectionStatus();
|
|
774
|
+
const status = statusMap.get(serverName);
|
|
775
|
+
return status?.connected ?? false;
|
|
776
|
+
}
|
|
777
|
+
return false;
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Clean up resources
|
|
781
|
+
*/
|
|
782
|
+
async cleanup() {
|
|
783
|
+
try {
|
|
784
|
+
this.logger.info("Cleaning up ConversationalAgent...");
|
|
785
|
+
if (this.memoryManager) {
|
|
786
|
+
try {
|
|
787
|
+
this.memoryManager.dispose();
|
|
788
|
+
this.logger.info("Memory manager cleaned up successfully");
|
|
789
|
+
} catch (error) {
|
|
790
|
+
this.logger.warn("Error cleaning up memory manager:", error);
|
|
791
|
+
}
|
|
792
|
+
this.memoryManager = void 0;
|
|
793
|
+
}
|
|
794
|
+
if (this.contentStoreManager) {
|
|
795
|
+
await this.contentStoreManager.dispose();
|
|
796
|
+
this.logger.info("ContentStoreManager cleaned up");
|
|
797
|
+
}
|
|
798
|
+
this.logger.info("ConversationalAgent cleanup completed");
|
|
799
|
+
} catch (error) {
|
|
800
|
+
this.logger.error("Error during cleanup:", error);
|
|
801
|
+
}
|
|
91
802
|
}
|
|
92
|
-
|
|
803
|
+
/**
|
|
804
|
+
* Switch operational mode
|
|
805
|
+
*/
|
|
806
|
+
switchMode(mode) {
|
|
807
|
+
if (this.agent?.switchMode) {
|
|
808
|
+
this.agent.switchMode(mode || "autonomous");
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Get usage statistics
|
|
813
|
+
*/
|
|
814
|
+
getUsageStats() {
|
|
815
|
+
return this.agent?.getUsageStats?.() ?? {};
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* Clear usage statistics
|
|
819
|
+
*/
|
|
820
|
+
clearUsageStats() {
|
|
821
|
+
if (this.agent?.clearUsageStats) {
|
|
822
|
+
this.agent.clearUsageStats();
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Shutdown the agent
|
|
827
|
+
*/
|
|
828
|
+
shutdown() {
|
|
829
|
+
return this.agent?.shutdown?.() ?? Promise.resolve();
|
|
830
|
+
}
|
|
831
|
+
extractResponseText(response) {
|
|
832
|
+
if (typeof response === "string") {
|
|
833
|
+
return response;
|
|
834
|
+
}
|
|
835
|
+
if (response && typeof response === "object" && "output" in response) {
|
|
836
|
+
const responseWithOutput = response;
|
|
837
|
+
return String(responseWithOutput.output);
|
|
838
|
+
}
|
|
839
|
+
return JSON.stringify(response);
|
|
840
|
+
}
|
|
841
|
+
};
|
|
842
|
+
_ConversationalAgent.NOT_INITIALIZED_ERROR = "Agent not initialized. Call initialize() first.";
|
|
843
|
+
let ConversationalAgent = _ConversationalAgent;
|
|
93
844
|
export {
|
|
94
|
-
|
|
845
|
+
ConversationalAgent
|
|
95
846
|
};
|
|
96
847
|
//# sourceMappingURL=index7.js.map
|