@hashgraphonline/conversational-agent 0.2.103 → 0.2.105
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/README.md +64 -27
- package/cli/dist/CLIApp.d.ts +11 -0
- package/cli/dist/CLIApp.d.ts.map +1 -0
- package/cli/dist/CLIApp.js +128 -0
- package/cli/dist/CLIApp.js.map +1 -0
- package/cli/dist/LocalConversationalAgent.d.ts +37 -0
- package/cli/dist/LocalConversationalAgent.js +58 -0
- package/cli/dist/app.d.ts +18 -0
- package/cli/dist/app.d.ts.map +1 -0
- package/cli/dist/app.js +14 -0
- package/cli/dist/app.js.map +1 -0
- package/cli/dist/cli.d.ts +3 -0
- package/cli/dist/cli.d.ts.map +1 -0
- package/cli/dist/cli.js +87 -0
- package/cli/dist/cli.js.map +1 -0
- package/cli/dist/components/AppContainer.d.ts +16 -0
- package/cli/dist/components/AppContainer.js +24 -0
- package/cli/dist/components/AppScreens.d.ts +2 -0
- package/cli/dist/components/AppScreens.js +259 -0
- package/cli/dist/components/ChatScreen.d.ts +21 -0
- package/cli/dist/components/ChatScreen.d.ts.map +1 -0
- package/cli/dist/components/ChatScreen.js +40 -0
- package/cli/dist/components/ChatScreen.js.map +1 -0
- package/cli/dist/components/DebugLoadingScreen.d.ts +5 -0
- package/cli/dist/components/DebugLoadingScreen.js +31 -0
- package/cli/dist/components/LoadingScreen.d.ts +3 -0
- package/cli/dist/components/LoadingScreen.d.ts.map +1 -0
- package/cli/dist/components/LoadingScreen.js +17 -0
- package/cli/dist/components/LoadingScreen.js.map +1 -0
- package/cli/dist/components/LoadingScreenDebug.d.ts +5 -0
- package/cli/dist/components/LoadingScreenDebug.js +27 -0
- package/cli/dist/components/MCPConfigScreen.d.ts +28 -0
- package/cli/dist/components/MCPConfigScreen.d.ts.map +1 -0
- package/cli/dist/components/MCPConfigScreen.js +186 -0
- package/cli/dist/components/MCPConfigScreen.js.map +1 -0
- package/cli/dist/components/ScreenRouter.d.ts +13 -0
- package/cli/dist/components/ScreenRouter.d.ts.map +1 -0
- package/cli/dist/components/ScreenRouter.js +23 -0
- package/cli/dist/components/ScreenRouter.js.map +1 -0
- package/cli/dist/components/SetupScreen.d.ts +16 -0
- package/cli/dist/components/SetupScreen.d.ts.map +1 -0
- package/cli/dist/components/SetupScreen.js +67 -0
- package/cli/dist/components/SetupScreen.js.map +1 -0
- package/cli/dist/components/SingleLoadingScreen.d.ts +5 -0
- package/cli/dist/components/SingleLoadingScreen.js +27 -0
- package/cli/dist/components/StatusBadge.d.ts +10 -0
- package/cli/dist/components/StatusBadge.d.ts.map +1 -0
- package/cli/dist/components/StatusBadge.js +24 -0
- package/cli/dist/components/StatusBadge.js.map +1 -0
- package/cli/dist/components/TerminalWindow.d.ts +9 -0
- package/cli/dist/components/TerminalWindow.d.ts.map +1 -0
- package/cli/dist/components/TerminalWindow.js +19 -0
- package/cli/dist/components/TerminalWindow.js.map +1 -0
- package/cli/dist/components/WelcomeScreen.d.ts +12 -0
- package/cli/dist/components/WelcomeScreen.d.ts.map +1 -0
- package/cli/dist/components/WelcomeScreen.js +47 -0
- package/cli/dist/components/WelcomeScreen.js.map +1 -0
- package/cli/dist/context/AppContext.d.ts +68 -0
- package/cli/dist/context/AppContext.js +363 -0
- package/cli/dist/headless-runner.d.ts +17 -0
- package/cli/dist/headless-runner.d.ts.map +1 -0
- package/cli/dist/headless-runner.js +128 -0
- package/cli/dist/headless-runner.js.map +1 -0
- package/cli/dist/hooks/useInitializeAgent.d.ts +19 -0
- package/cli/dist/hooks/useInitializeAgent.d.ts.map +1 -0
- package/cli/dist/hooks/useInitializeAgent.js +29 -0
- package/cli/dist/hooks/useInitializeAgent.js.map +1 -0
- package/cli/dist/hooks/useStableState.d.ts +38 -0
- package/cli/dist/hooks/useStableState.d.ts.map +1 -0
- package/cli/dist/hooks/useStableState.js +69 -0
- package/cli/dist/hooks/useStableState.js.map +1 -0
- package/cli/dist/managers/AgentManager.d.ts +58 -0
- package/cli/dist/managers/AgentManager.d.ts.map +1 -0
- package/cli/dist/managers/AgentManager.js +121 -0
- package/cli/dist/managers/AgentManager.js.map +1 -0
- package/cli/dist/managers/ConfigManager.d.ts +54 -0
- package/cli/dist/managers/ConfigManager.d.ts.map +1 -0
- package/cli/dist/managers/ConfigManager.js +188 -0
- package/cli/dist/managers/ConfigManager.js.map +1 -0
- package/cli/dist/types.d.ts +52 -0
- package/cli/dist/types.d.ts.map +1 -0
- package/cli/dist/types.js +34 -0
- package/cli/dist/types.js.map +1 -0
- package/dist/cjs/config/system-message.d.ts +1 -1
- package/dist/cjs/conversational-agent.d.ts +30 -2
- package/dist/cjs/core/tool-registry.d.ts +29 -0
- package/dist/cjs/forms/field-guidance-registry.d.ts +33 -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/mcp/types.d.ts +14 -3
- package/dist/cjs/plugins/index.d.ts +1 -0
- package/dist/cjs/plugins/inscribe/InscribePlugin.d.ts +1 -0
- package/dist/cjs/plugins/web-browser/WebBrowserPlugin.d.ts +14 -0
- package/dist/cjs/runtime/wallet-bridge.d.ts +26 -0
- package/dist/cjs/services/attachment-processor.d.ts +1 -2
- package/dist/cjs/services/content-store-manager.d.ts +1 -1
- package/dist/cjs/services/formatters/types.d.ts +3 -1
- package/dist/cjs/services/index.d.ts +1 -1
- package/dist/cjs/signers/browser-signer.d.ts +32 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index10.js +13 -5
- package/dist/esm/index10.js.map +1 -1
- package/dist/esm/index13.js +157 -179
- package/dist/esm/index13.js.map +1 -1
- package/dist/esm/index15.js +9 -4
- package/dist/esm/index15.js.map +1 -1
- package/dist/esm/index18.js.map +1 -1
- package/dist/esm/index2.js +25 -27
- package/dist/esm/index2.js.map +1 -1
- package/dist/esm/index21.js +1 -1
- package/dist/esm/index21.js.map +1 -1
- package/dist/esm/index23.js +3 -3
- package/dist/esm/index24.js.map +1 -1
- package/dist/esm/index26.js.map +1 -1
- package/dist/esm/index3.js.map +1 -1
- package/dist/esm/index30.js.map +1 -1
- package/dist/esm/index31.js +6 -3
- package/dist/esm/index31.js.map +1 -1
- package/dist/esm/index33.js +5 -5
- package/dist/esm/index33.js.map +1 -1
- package/dist/esm/index36.js +8 -45
- package/dist/esm/index36.js.map +1 -1
- package/dist/esm/index37.js +41 -102
- package/dist/esm/index37.js.map +1 -1
- package/dist/esm/index38.js +107 -21
- package/dist/esm/index38.js.map +1 -1
- package/dist/esm/index39.js +66 -12
- package/dist/esm/index39.js.map +1 -1
- package/dist/esm/index4.js +43 -0
- package/dist/esm/index4.js.map +1 -1
- package/dist/esm/index40.js +79 -7
- package/dist/esm/index40.js.map +1 -1
- package/dist/esm/index41.js +21 -5
- package/dist/esm/index41.js.map +1 -1
- package/dist/esm/index42.js +5 -255
- package/dist/esm/index42.js.map +1 -1
- package/dist/esm/index43.js +12 -184
- package/dist/esm/index43.js.map +1 -1
- package/dist/esm/index44.js +309 -79
- package/dist/esm/index44.js.map +1 -1
- package/dist/esm/index45.js +181 -24
- package/dist/esm/index45.js.map +1 -1
- package/dist/esm/index46.js +30 -0
- package/dist/esm/index46.js.map +1 -0
- package/dist/esm/index47.js +10 -0
- package/dist/esm/index47.js.map +1 -0
- package/dist/esm/index48.js +98 -0
- package/dist/esm/index48.js.map +1 -0
- package/dist/esm/index5.js +2 -2
- package/dist/esm/index6.js +231 -52
- package/dist/esm/index6.js.map +1 -1
- package/dist/types/config/system-message.d.ts +1 -1
- package/dist/types/conversational-agent.d.ts +30 -2
- package/dist/types/core/tool-registry.d.ts +29 -0
- package/dist/types/forms/field-guidance-registry.d.ts +33 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/mcp/types.d.ts +14 -3
- package/dist/types/plugins/index.d.ts +1 -0
- package/dist/types/plugins/inscribe/InscribePlugin.d.ts +1 -0
- package/dist/types/plugins/web-browser/WebBrowserPlugin.d.ts +14 -0
- package/dist/types/runtime/wallet-bridge.d.ts +26 -0
- package/dist/types/services/attachment-processor.d.ts +1 -2
- package/dist/types/services/content-store-manager.d.ts +1 -1
- package/dist/types/services/formatters/types.d.ts +3 -1
- package/dist/types/services/index.d.ts +1 -1
- package/dist/types/signers/browser-signer.d.ts +32 -0
- package/package.json +40 -37
- package/src/config/system-message.ts +3 -3
- package/src/conversational-agent.ts +356 -61
- package/src/core/tool-registry.ts +85 -0
- package/src/forms/field-guidance-registry.ts +213 -188
- package/src/forms/form-generator.ts +28 -12
- package/src/index.ts +1 -0
- package/src/langchain/form-aware-agent-executor.ts +6 -6
- package/src/langchain/langchain-agent.ts +1 -1
- package/src/mcp/mcp-client-manager.ts +12 -5
- package/src/mcp/types.ts +15 -3
- package/src/memory/content-storage.ts +19 -6
- package/src/memory/smart-memory-manager.ts +0 -1
- package/src/plugins/hbar/AccountBuilder.ts +16 -16
- package/src/plugins/hcs-10/HCS10Plugin.ts +38 -38
- package/src/plugins/hcs-2/HCS2Plugin.ts +2 -2
- package/src/plugins/index.ts +2 -1
- package/src/plugins/inscribe/InscribePlugin.ts +46 -2
- package/src/plugins/web-browser/WebBrowserPlugin.ts +128 -0
- package/src/runtime/wallet-bridge.ts +46 -0
- package/src/services/attachment-processor.ts +1 -1
- package/src/services/content-store-manager.ts +1 -1
- package/src/services/formatters/types.ts +3 -1
- package/src/services/index.ts +1 -1
- package/src/signers/browser-signer.ts +111 -0
- package/cli/readme.md +0 -181
package/dist/esm/index6.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { ServerSigner, getAllHederaCorePlugins } from "hedera-agent-kit";
|
|
2
2
|
import { Logger } from "@hashgraphonline/standards-sdk";
|
|
3
3
|
import { createAgent } from "./index8.js";
|
|
4
|
+
import { BrowserSigner } from "./index39.js";
|
|
4
5
|
import { LangChainProvider } from "./index9.js";
|
|
5
6
|
import { ChatOpenAI } from "@langchain/openai";
|
|
6
|
-
import OpenAI from "openai";
|
|
7
7
|
import { ChatAnthropic } from "@langchain/anthropic";
|
|
8
8
|
import { SystemMessage, HumanMessage, AIMessage } from "@langchain/core/messages";
|
|
9
9
|
import { HCS10Plugin } from "./index2.js";
|
|
10
10
|
import { HCS2Plugin } from "./index3.js";
|
|
11
11
|
import { InscribePlugin } from "./index4.js";
|
|
12
|
+
import { getWalletBridgeProvider } from "./index36.js";
|
|
13
|
+
import { OpenConvaiState, InscriberBuilder, SignerProviderRegistry } from "@hashgraphonline/standards-agent-kit";
|
|
12
14
|
import { HbarPlugin } from "./index5.js";
|
|
13
|
-
import {
|
|
14
|
-
import { getSystemMessage } from "./
|
|
15
|
+
import { WebBrowserPlugin } from "./index40.js";
|
|
16
|
+
import { getSystemMessage } from "./index41.js";
|
|
15
17
|
import { ContentStoreManager } from "./index24.js";
|
|
16
18
|
import { SmartMemoryManager } from "./index18.js";
|
|
17
19
|
import "./index19.js";
|
|
@@ -19,7 +21,14 @@ import "./index20.js";
|
|
|
19
21
|
import "./index21.js";
|
|
20
22
|
import "crypto";
|
|
21
23
|
import { createEntityTools } from "./index34.js";
|
|
24
|
+
import { ParameterService } from "./index29.js";
|
|
25
|
+
import { FormatConverterRegistry } from "./index25.js";
|
|
26
|
+
import { TopicIdToHrlConverter } from "./index27.js";
|
|
27
|
+
import { StringNormalizationConverter } from "./index28.js";
|
|
22
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";
|
|
23
32
|
const DEFAULT_TEMPERATURE = 0.1;
|
|
24
33
|
const DEFAULT_NETWORK = "testnet";
|
|
25
34
|
const DEFAULT_OPERATIONAL_MODE = "autonomous";
|
|
@@ -31,6 +40,7 @@ const _ConversationalAgent = class _ConversationalAgent {
|
|
|
31
40
|
this.hcs2Plugin = new HCS2Plugin();
|
|
32
41
|
this.inscribePlugin = new InscribePlugin();
|
|
33
42
|
this.hbarPlugin = new HbarPlugin();
|
|
43
|
+
this.webBrowserPlugin = new WebBrowserPlugin();
|
|
34
44
|
this.logger = new Logger({
|
|
35
45
|
module: "ConversationalAgent",
|
|
36
46
|
silent: options.disableLogging || false
|
|
@@ -46,7 +56,16 @@ const _ConversationalAgent = class _ConversationalAgent {
|
|
|
46
56
|
);
|
|
47
57
|
this.logger.info("Entity memory initialized");
|
|
48
58
|
const provider = options.entityMemoryProvider || options.llmProvider || "openai";
|
|
49
|
-
|
|
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
|
+
}
|
|
50
69
|
let resolverLLM;
|
|
51
70
|
if (provider === "anthropic") {
|
|
52
71
|
resolverLLM = new ChatAnthropic({
|
|
@@ -57,19 +76,17 @@ const _ConversationalAgent = class _ConversationalAgent {
|
|
|
57
76
|
} else if (provider === "openrouter") {
|
|
58
77
|
const baseURL = options.openRouterBaseURL || "https://openrouter.ai/api/v1";
|
|
59
78
|
const apiKey = options.openRouterApiKey || options.openAIApiKey;
|
|
60
|
-
const client = new OpenAI({
|
|
61
|
-
apiKey,
|
|
62
|
-
baseURL,
|
|
63
|
-
defaultHeaders: {
|
|
64
|
-
Referer: process.env.OPENROUTER_REFERRER || "https://hashgraphonline.com",
|
|
65
|
-
"HTTP-Referer": process.env.OPENROUTER_REFERRER || "https://hashgraphonline.com",
|
|
66
|
-
"X-Title": process.env.OPENROUTER_TITLE || "Hashgraph Online Conversational Agent"
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
79
|
resolverLLM = new ChatOpenAI({
|
|
70
|
-
|
|
80
|
+
apiKey,
|
|
71
81
|
model: modelName,
|
|
72
|
-
temperature: 0
|
|
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
|
+
}
|
|
73
90
|
});
|
|
74
91
|
} else {
|
|
75
92
|
resolverLLM = new ChatOpenAI({
|
|
@@ -98,41 +115,142 @@ const _ConversationalAgent = class _ConversationalAgent {
|
|
|
98
115
|
} = this.options;
|
|
99
116
|
this.validateOptions(accountId, privateKey);
|
|
100
117
|
try {
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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"
|
|
148
|
+
});
|
|
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
|
+
}
|
|
106
226
|
let llm;
|
|
107
227
|
let providerInfo = { provider: llmProvider };
|
|
108
228
|
if (llmProvider === "anthropic") {
|
|
109
229
|
llm = new ChatAnthropic({
|
|
110
230
|
apiKey: openAIApiKey,
|
|
111
|
-
model: openAIModelName ||
|
|
231
|
+
model: openAIModelName || DEFAULT_CLAUDE_MODEL,
|
|
112
232
|
temperature: DEFAULT_TEMPERATURE
|
|
113
233
|
});
|
|
114
234
|
providerInfo = {
|
|
115
235
|
...providerInfo,
|
|
116
|
-
model: openAIModelName ||
|
|
236
|
+
model: openAIModelName || DEFAULT_CLAUDE_MODEL,
|
|
117
237
|
keyPresent: !!openAIApiKey
|
|
118
238
|
};
|
|
119
239
|
} else if (llmProvider === "openrouter") {
|
|
120
240
|
const baseURL = this.options.openRouterBaseURL || "https://openrouter.ai/api/v1";
|
|
121
241
|
const apiKey = this.options.openRouterApiKey || openAIApiKey;
|
|
122
242
|
const modelName = openAIModelName || "anthropic/claude-3-haiku-20240307";
|
|
123
|
-
const client = new OpenAI({
|
|
124
|
-
apiKey,
|
|
125
|
-
baseURL,
|
|
126
|
-
defaultHeaders: {
|
|
127
|
-
Referer: process.env.OPENROUTER_REFERRER || "https://hashgraphonline.com",
|
|
128
|
-
"HTTP-Referer": process.env.OPENROUTER_REFERRER || "https://hashgraphonline.com",
|
|
129
|
-
"X-Title": process.env.OPENROUTER_TITLE || "Hashgraph Online Conversational Agent"
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
243
|
llm = new ChatOpenAI({
|
|
133
|
-
|
|
244
|
+
apiKey,
|
|
134
245
|
model: modelName,
|
|
135
|
-
temperature: DEFAULT_TEMPERATURE
|
|
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
|
+
}
|
|
136
254
|
});
|
|
137
255
|
providerInfo = {
|
|
138
256
|
...providerInfo,
|
|
@@ -141,16 +259,16 @@ const _ConversationalAgent = class _ConversationalAgent {
|
|
|
141
259
|
keyPresent: !!apiKey
|
|
142
260
|
};
|
|
143
261
|
} else {
|
|
144
|
-
const
|
|
145
|
-
const isGPT5Model =
|
|
262
|
+
const modelName2 = openAIModelName || DEFAULT_OPENAI_MODEL;
|
|
263
|
+
const isGPT5Model = modelName2.toLowerCase().includes("gpt-5") || modelName2.toLowerCase().includes("gpt5");
|
|
146
264
|
llm = new ChatOpenAI({
|
|
147
265
|
apiKey: openAIApiKey,
|
|
148
|
-
model:
|
|
266
|
+
model: modelName2,
|
|
149
267
|
...isGPT5Model ? { temperature: 1 } : { temperature: DEFAULT_TEMPERATURE }
|
|
150
268
|
});
|
|
151
269
|
providerInfo = {
|
|
152
270
|
...providerInfo,
|
|
153
|
-
model:
|
|
271
|
+
model: modelName2,
|
|
154
272
|
keyPresent: !!openAIApiKey
|
|
155
273
|
};
|
|
156
274
|
}
|
|
@@ -158,7 +276,11 @@ const _ConversationalAgent = class _ConversationalAgent {
|
|
|
158
276
|
this.logger.info("Preparing plugins...");
|
|
159
277
|
const allPlugins = this.preparePlugins();
|
|
160
278
|
this.logger.info("Creating agent config...");
|
|
161
|
-
const agentConfig = this.createAgentConfig(
|
|
279
|
+
const agentConfig = this.createAgentConfig(
|
|
280
|
+
signer,
|
|
281
|
+
llm,
|
|
282
|
+
allPlugins
|
|
283
|
+
);
|
|
162
284
|
this.logger.info("Creating agent...");
|
|
163
285
|
this.agent = createAgent(agentConfig);
|
|
164
286
|
this.logger.info("Agent created");
|
|
@@ -176,6 +298,26 @@ const _ConversationalAgent = class _ConversationalAgent {
|
|
|
176
298
|
this.logger.info("agent.boot() completed");
|
|
177
299
|
this.logger.info("🔥 agent.boot() completed");
|
|
178
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
|
+
}
|
|
179
321
|
const cfg = agentConfig;
|
|
180
322
|
cfg.filtering = cfg.filtering || {};
|
|
181
323
|
const originalPredicate = cfg.filtering.toolPredicate;
|
|
@@ -302,22 +444,27 @@ const _ConversationalAgent = class _ConversationalAgent {
|
|
|
302
444
|
* @throws {Error} If required fields are missing
|
|
303
445
|
*/
|
|
304
446
|
validateOptions(accountId, privateKey) {
|
|
305
|
-
|
|
306
|
-
|
|
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");
|
|
451
|
+
}
|
|
452
|
+
if (!privateKey && !bytesMode) {
|
|
453
|
+
throw new Error("Private key is required in autonomous mode");
|
|
307
454
|
}
|
|
308
455
|
if (typeof accountId !== "string") {
|
|
309
456
|
throw new Error(
|
|
310
457
|
`Account ID must be a string, received ${typeof accountId}`
|
|
311
458
|
);
|
|
312
459
|
}
|
|
313
|
-
if (typeof privateKey !== "string") {
|
|
460
|
+
if (!bytesMode && typeof privateKey !== "string") {
|
|
314
461
|
throw new Error(
|
|
315
462
|
`Private key must be a string, received ${typeof privateKey}: ${JSON.stringify(
|
|
316
463
|
privateKey
|
|
317
464
|
)}`
|
|
318
465
|
);
|
|
319
466
|
}
|
|
320
|
-
if (privateKey.length < 10) {
|
|
467
|
+
if (!bytesMode && typeof privateKey === "string" && privateKey.length < 10) {
|
|
321
468
|
throw new Error("Private key appears to be invalid (too short)");
|
|
322
469
|
}
|
|
323
470
|
}
|
|
@@ -327,32 +474,36 @@ const _ConversationalAgent = class _ConversationalAgent {
|
|
|
327
474
|
* @returns Array of plugins to initialize with the agent
|
|
328
475
|
*/
|
|
329
476
|
preparePlugins() {
|
|
330
|
-
const { additionalPlugins = [], enabledPlugins } = this.options;
|
|
477
|
+
const { additionalPlugins = [], enabledPlugins, disabledPlugins } = this.options;
|
|
331
478
|
const standardPlugins = [
|
|
332
479
|
this.hcs10Plugin,
|
|
333
480
|
this.hcs2Plugin,
|
|
334
481
|
this.inscribePlugin,
|
|
335
482
|
this.hbarPlugin
|
|
336
483
|
];
|
|
484
|
+
standardPlugins.push(this.webBrowserPlugin);
|
|
337
485
|
const corePlugins = getAllHederaCorePlugins();
|
|
486
|
+
let pluginPool = [...standardPlugins, ...corePlugins];
|
|
338
487
|
if (enabledPlugins) {
|
|
339
488
|
const enabledSet = new Set(enabledPlugins);
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
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));
|
|
344
494
|
}
|
|
345
|
-
|
|
495
|
+
const additional = disabledPlugins && disabledPlugins.length > 0 ? additionalPlugins.filter((plugin) => !disabledPlugins.includes(plugin.id)) : additionalPlugins;
|
|
496
|
+
return [...pluginPool, ...additional];
|
|
346
497
|
}
|
|
347
498
|
/**
|
|
348
499
|
* Creates the agent configuration object.
|
|
349
500
|
*
|
|
350
|
-
* @param
|
|
501
|
+
* @param signer - The signer instance
|
|
351
502
|
* @param llm - The language model instance
|
|
352
503
|
* @param allPlugins - Array of plugins to use
|
|
353
504
|
* @returns Configuration object for creating the agent
|
|
354
505
|
*/
|
|
355
|
-
createAgentConfig(
|
|
506
|
+
createAgentConfig(signer, llm, allPlugins) {
|
|
356
507
|
const {
|
|
357
508
|
operationalMode = DEFAULT_OPERATIONAL_MODE,
|
|
358
509
|
userAccountId,
|
|
@@ -366,7 +517,7 @@ const _ConversationalAgent = class _ConversationalAgent {
|
|
|
366
517
|
} = this.options;
|
|
367
518
|
return {
|
|
368
519
|
framework: "langchain",
|
|
369
|
-
signer
|
|
520
|
+
signer,
|
|
370
521
|
execution: {
|
|
371
522
|
mode: operationalMode === "autonomous" ? "direct" : "bytes",
|
|
372
523
|
operationalMode,
|
|
@@ -579,7 +730,7 @@ const _ConversationalAgent = class _ConversationalAgent {
|
|
|
579
730
|
}
|
|
580
731
|
if (typeof response === "string") {
|
|
581
732
|
const match = response.match(
|
|
582
|
-
/transaction[\s\w]*ID[\s:"]*([0-9a-fA-F
|
|
733
|
+
/transaction[\s\w]*ID[\s:"]*([0-9a-fA-F@._-]+)/i
|
|
583
734
|
);
|
|
584
735
|
return match ? match[1] : void 0;
|
|
585
736
|
}
|
|
@@ -649,6 +800,34 @@ const _ConversationalAgent = class _ConversationalAgent {
|
|
|
649
800
|
this.logger.error("Error during cleanup:", error);
|
|
650
801
|
}
|
|
651
802
|
}
|
|
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
|
+
}
|
|
652
831
|
extractResponseText(response) {
|
|
653
832
|
if (typeof response === "string") {
|
|
654
833
|
return response;
|