@hashgraphonline/conversational-agent 0.1.210 → 0.1.213

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.
Files changed (55) hide show
  1. package/cli/dist/CLIApp.d.ts +9 -0
  2. package/cli/dist/CLIApp.js +127 -0
  3. package/cli/dist/LocalConversationalAgent.d.ts +37 -0
  4. package/cli/dist/LocalConversationalAgent.js +58 -0
  5. package/cli/dist/app.d.ts +16 -0
  6. package/cli/dist/app.js +13 -0
  7. package/cli/dist/cli.d.ts +2 -0
  8. package/cli/dist/cli.js +51 -0
  9. package/cli/dist/components/AppContainer.d.ts +16 -0
  10. package/cli/dist/components/AppContainer.js +24 -0
  11. package/cli/dist/components/AppScreens.d.ts +2 -0
  12. package/cli/dist/components/AppScreens.js +259 -0
  13. package/cli/dist/components/ChatScreen.d.ts +15 -0
  14. package/cli/dist/components/ChatScreen.js +39 -0
  15. package/cli/dist/components/DebugLoadingScreen.d.ts +5 -0
  16. package/cli/dist/components/DebugLoadingScreen.js +31 -0
  17. package/cli/dist/components/LoadingScreen.d.ts +2 -0
  18. package/cli/dist/components/LoadingScreen.js +16 -0
  19. package/cli/dist/components/LoadingScreenDebug.d.ts +5 -0
  20. package/cli/dist/components/LoadingScreenDebug.js +27 -0
  21. package/cli/dist/components/MCPConfigScreen.d.ts +28 -0
  22. package/cli/dist/components/MCPConfigScreen.js +168 -0
  23. package/cli/dist/components/ScreenRouter.d.ts +12 -0
  24. package/cli/dist/components/ScreenRouter.js +22 -0
  25. package/cli/dist/components/SetupScreen.d.ts +15 -0
  26. package/cli/dist/components/SetupScreen.js +65 -0
  27. package/cli/dist/components/SingleLoadingScreen.d.ts +5 -0
  28. package/cli/dist/components/SingleLoadingScreen.js +27 -0
  29. package/cli/dist/components/StatusBadge.d.ts +7 -0
  30. package/cli/dist/components/StatusBadge.js +28 -0
  31. package/cli/dist/components/TerminalWindow.d.ts +8 -0
  32. package/cli/dist/components/TerminalWindow.js +24 -0
  33. package/cli/dist/components/WelcomeScreen.d.ts +11 -0
  34. package/cli/dist/components/WelcomeScreen.js +47 -0
  35. package/cli/dist/context/AppContext.d.ts +68 -0
  36. package/cli/dist/context/AppContext.js +363 -0
  37. package/cli/dist/hooks/useInitializeAgent.d.ts +19 -0
  38. package/cli/dist/hooks/useInitializeAgent.js +28 -0
  39. package/cli/dist/hooks/useStableState.d.ts +38 -0
  40. package/cli/dist/hooks/useStableState.js +68 -0
  41. package/cli/dist/managers/AgentManager.d.ts +57 -0
  42. package/cli/dist/managers/AgentManager.js +119 -0
  43. package/cli/dist/managers/ConfigManager.d.ts +53 -0
  44. package/cli/dist/managers/ConfigManager.js +173 -0
  45. package/cli/dist/types.d.ts +31 -0
  46. package/cli/dist/types.js +19 -0
  47. package/dist/cjs/conversational-agent.d.ts +1 -9
  48. package/dist/cjs/index.cjs +1 -1
  49. package/dist/cjs/index.cjs.map +1 -1
  50. package/dist/esm/index6.js +11 -25
  51. package/dist/esm/index6.js.map +1 -1
  52. package/dist/types/conversational-agent.d.ts +1 -9
  53. package/package.json +27 -29
  54. package/src/conversational-agent.ts +15 -31
  55. package/cli/readme.md +0 -181
@@ -0,0 +1,119 @@
1
+ import { ConversationalAgent, MCPServers, } from '@hashgraphonline/conversational-agent';
2
+ export class AgentManager {
3
+ static instance;
4
+ agent = null;
5
+ initializing = false;
6
+ initialized = false;
7
+ constructor() { }
8
+ static getInstance() {
9
+ if (!AgentManager.instance) {
10
+ AgentManager.instance = new AgentManager();
11
+ }
12
+ return AgentManager.instance;
13
+ }
14
+ /**
15
+ * Initialize the conversational agent
16
+ */
17
+ async initialize(config, mcpConfig) {
18
+ if (this.agent && this.initialized) {
19
+ return {
20
+ agent: this.agent,
21
+ welcomeMessages: this.getWelcomeMessages(config, []),
22
+ };
23
+ }
24
+ if (this.initializing) {
25
+ throw new Error('Agent is already initializing');
26
+ }
27
+ this.initializing = true;
28
+ try {
29
+ const mcpServers = [];
30
+ if (mcpConfig.enableFilesystem && mcpConfig.filesystemPath) {
31
+ mcpServers.push(MCPServers.filesystem(mcpConfig.filesystemPath));
32
+ }
33
+ mcpServers.push(...mcpConfig.customServers);
34
+ const agentConfig = {
35
+ accountId: config.accountId,
36
+ privateKey: config.privateKey,
37
+ network: config.network,
38
+ openAIApiKey: config.openAIApiKey,
39
+ openAIModelName: 'gpt-4o-mini',
40
+ verbose: false,
41
+ disableLogging: true,
42
+ ...(mcpServers.length > 0 && { mcpServers }),
43
+ };
44
+ const conversationalAgent = new ConversationalAgent(agentConfig);
45
+ await conversationalAgent.initialize();
46
+ this.agent = conversationalAgent;
47
+ this.initialized = true;
48
+ const welcomeMessages = this.getWelcomeMessages(config, mcpServers);
49
+ return { agent: conversationalAgent, welcomeMessages };
50
+ }
51
+ finally {
52
+ this.initializing = false;
53
+ }
54
+ }
55
+ /**
56
+ * Get welcome messages
57
+ */
58
+ getWelcomeMessages(config, mcpServers) {
59
+ const welcomeMessages = [
60
+ {
61
+ role: 'system',
62
+ content: `Connected to Hedera ${config.network}`,
63
+ timestamp: new Date(),
64
+ },
65
+ ];
66
+ if (mcpServers.length > 0) {
67
+ welcomeMessages.push({
68
+ role: 'system',
69
+ content: `MCP servers enabled: ${mcpServers
70
+ .map(s => s.name)
71
+ .join(', ')}`,
72
+ timestamp: new Date(),
73
+ });
74
+ }
75
+ welcomeMessages.push({
76
+ role: 'assistant',
77
+ content: mcpServers.length > 0
78
+ ? "Hello! I'm your Conversational Agent powered by Hashgraph Online, with extended MCP capabilities. I can help you with:\n\n• HCS-10 agent registrations and HCS-11 profiles\n• Sending messages through HCS standards\n• Creating accounts, transferring HBAR, and managing tokens\n• Deploying smart contracts and interacting with them\n• Managing NFTs, token swaps, and staking operations\n• Scheduling transactions and consensus submissions\n• File operations and external tool integration\n\nHow can I assist you today?"
79
+ : "Hello! I'm your Conversational Agent powered by Hashgraph Online. I can help you with:\n\n• HCS-10 agent registrations and HCS-11 profiles\n• Sending messages through HCS standards\n• Creating accounts, transferring HBAR, and managing tokens\n• Deploying smart contracts and interacting with them\n• Managing NFTs, token swaps, and staking operations\n• Scheduling transactions and consensus submissions\n\nHow can I assist you today?",
80
+ timestamp: new Date(),
81
+ });
82
+ return welcomeMessages;
83
+ }
84
+ /**
85
+ * Send message to agent
86
+ */
87
+ async sendMessage(message, chatHistory) {
88
+ if (!this.agent) {
89
+ throw new Error('Agent not initialized');
90
+ }
91
+ return this.agent.processMessage(message, chatHistory);
92
+ }
93
+ /**
94
+ * Get current agent
95
+ */
96
+ getAgent() {
97
+ return this.agent;
98
+ }
99
+ /**
100
+ * Check if agent is initialized
101
+ */
102
+ isInitialized() {
103
+ return this.initialized;
104
+ }
105
+ /**
106
+ * Check if agent is initializing
107
+ */
108
+ isInitializing() {
109
+ return this.initializing;
110
+ }
111
+ /**
112
+ * Reset agent (for testing)
113
+ */
114
+ reset() {
115
+ this.agent = null;
116
+ this.initialized = false;
117
+ this.initializing = false;
118
+ }
119
+ }
@@ -0,0 +1,53 @@
1
+ import { type MCPServerConfig } from '@hashgraphonline/conversational-agent';
2
+ import { type Config } from '../types';
3
+ export declare class ConfigManager {
4
+ private static instance;
5
+ private _config;
6
+ private _mcpServers;
7
+ private constructor();
8
+ static getInstance(): ConfigManager;
9
+ /**
10
+ * Get MCP config file path
11
+ */
12
+ private getMCPConfigPath;
13
+ /**
14
+ * Load MCP configuration from file
15
+ */
16
+ private loadMCPConfig;
17
+ /**
18
+ * Save MCP configuration to file
19
+ */
20
+ saveMCPConfig(servers: MCPServerConfig[]): void;
21
+ /**
22
+ * Load config from .env file
23
+ */
24
+ private loadConfigFromEnv;
25
+ /**
26
+ * Save config to .env file
27
+ */
28
+ saveConfig(configToSave: Config): void;
29
+ /**
30
+ * Get complete config (cached)
31
+ */
32
+ getConfig(props?: Partial<Config>): Config & {
33
+ mcpServers: MCPServerConfig[];
34
+ };
35
+ /**
36
+ * Update config and save
37
+ */
38
+ updateConfig(updates: Partial<Config>): Config & {
39
+ mcpServers: MCPServerConfig[];
40
+ };
41
+ /**
42
+ * Get MCP servers
43
+ */
44
+ getMCPServers(): MCPServerConfig[];
45
+ /**
46
+ * Get MCP config path for display
47
+ */
48
+ getMCPConfigPathForDisplay(): string;
49
+ /**
50
+ * Reset cache (for testing)
51
+ */
52
+ resetCache(): void;
53
+ }
@@ -0,0 +1,173 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { MCPServers } from '@hashgraphonline/conversational-agent';
4
+ export class ConfigManager {
5
+ static instance;
6
+ _config = null;
7
+ _mcpServers = null;
8
+ constructor() { }
9
+ static getInstance() {
10
+ if (!ConfigManager.instance) {
11
+ ConfigManager.instance = new ConfigManager();
12
+ }
13
+ return ConfigManager.instance;
14
+ }
15
+ /**
16
+ * Get MCP config file path
17
+ */
18
+ getMCPConfigPath() {
19
+ const projectRoot = process.env['CONVERSATIONAL_AGENT_ROOT'] || path.resolve('./../../');
20
+ return path.join(projectRoot, 'mcp-config.json');
21
+ }
22
+ /**
23
+ * Load MCP configuration from file
24
+ */
25
+ loadMCPConfig() {
26
+ if (this._mcpServers)
27
+ return this._mcpServers;
28
+ const configPath = this.getMCPConfigPath();
29
+ try {
30
+ if (fs.existsSync(configPath)) {
31
+ const configContent = fs.readFileSync(configPath, 'utf-8');
32
+ const config = JSON.parse(configContent);
33
+ this._mcpServers = Object.values(config.mcpServers || {});
34
+ return this._mcpServers;
35
+ }
36
+ }
37
+ catch (err) {
38
+ console.error('Failed to load MCP config:', err);
39
+ }
40
+ const defaultServers = [MCPServers.filesystem(process.cwd())];
41
+ this.saveMCPConfig(defaultServers);
42
+ this._mcpServers = defaultServers;
43
+ return defaultServers;
44
+ }
45
+ /**
46
+ * Save MCP configuration to file
47
+ */
48
+ saveMCPConfig(servers) {
49
+ const configPath = this.getMCPConfigPath();
50
+ try {
51
+ const mcpServers = {};
52
+ servers.forEach(server => {
53
+ mcpServers[server.name] = server;
54
+ });
55
+ const config = { mcpServers };
56
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
57
+ this._mcpServers = servers;
58
+ }
59
+ catch (err) {
60
+ console.error('Failed to save MCP config:', err);
61
+ }
62
+ }
63
+ /**
64
+ * Load config from .env file
65
+ */
66
+ loadConfigFromEnv() {
67
+ const projectRoot = process.env['CONVERSATIONAL_AGENT_ROOT'] || path.resolve('./../../');
68
+ const envPath = path.join(projectRoot, '.env');
69
+ try {
70
+ if (fs.existsSync(envPath)) {
71
+ const envContent = fs.readFileSync(envPath, 'utf-8');
72
+ const envVars = {};
73
+ envContent.split('\n').forEach(line => {
74
+ const trimmedLine = line.trim();
75
+ if (trimmedLine && !trimmedLine.startsWith('#')) {
76
+ const [key, ...valueParts] = trimmedLine.split('=');
77
+ if (key && valueParts.length > 0) {
78
+ envVars[key] = valueParts.join('=');
79
+ }
80
+ }
81
+ });
82
+ return {
83
+ accountId: envVars['HEDERA_ACCOUNT_ID'] || '',
84
+ privateKey: envVars['HEDERA_PRIVATE_KEY'] || '',
85
+ network: envVars['HEDERA_NETWORK'] || 'testnet',
86
+ openAIApiKey: envVars['OPENAI_API_KEY'] || '',
87
+ };
88
+ }
89
+ }
90
+ catch (err) { }
91
+ return {
92
+ accountId: '',
93
+ privateKey: '',
94
+ network: 'testnet',
95
+ openAIApiKey: '',
96
+ };
97
+ }
98
+ /**
99
+ * Save config to .env file
100
+ */
101
+ saveConfig(configToSave) {
102
+ const projectRoot = process.env['CONVERSATIONAL_AGENT_ROOT'] || path.resolve('./../../');
103
+ const envPath = path.join(projectRoot, '.env');
104
+ try {
105
+ let envContent = '';
106
+ if (fs.existsSync(envPath)) {
107
+ envContent = fs.readFileSync(envPath, 'utf-8');
108
+ }
109
+ const updateEnvVar = (key, value) => {
110
+ const regex = new RegExp(`^${key}=.*$`, 'gm');
111
+ if (regex.test(envContent)) {
112
+ envContent = envContent.replace(regex, `${key}=${value}`);
113
+ }
114
+ else {
115
+ envContent += `${envContent ? '\n' : ''}${key}=${value}`;
116
+ }
117
+ };
118
+ updateEnvVar('HEDERA_ACCOUNT_ID', configToSave.accountId);
119
+ updateEnvVar('HEDERA_PRIVATE_KEY', configToSave.privateKey);
120
+ updateEnvVar('HEDERA_NETWORK', configToSave.network);
121
+ updateEnvVar('OPENAI_API_KEY', configToSave.openAIApiKey);
122
+ fs.writeFileSync(envPath, envContent);
123
+ this._config = null;
124
+ }
125
+ catch (err) { }
126
+ }
127
+ /**
128
+ * Get complete config (cached)
129
+ */
130
+ getConfig(props = {}) {
131
+ if (!this._config) {
132
+ const envConfig = this.loadConfigFromEnv();
133
+ const mcpServers = this.loadMCPConfig();
134
+ this._config = {
135
+ accountId: props.accountId || envConfig.accountId,
136
+ privateKey: props.privateKey || envConfig.privateKey,
137
+ network: props.network || envConfig.network,
138
+ openAIApiKey: props.openAIApiKey || envConfig.openAIApiKey,
139
+ mcpServers,
140
+ };
141
+ }
142
+ return this._config;
143
+ }
144
+ /**
145
+ * Update config and save
146
+ */
147
+ updateConfig(updates) {
148
+ const current = this.getConfig();
149
+ const updated = { ...current, ...updates };
150
+ this.saveConfig(updated);
151
+ this._config = updated;
152
+ return updated;
153
+ }
154
+ /**
155
+ * Get MCP servers
156
+ */
157
+ getMCPServers() {
158
+ return this.loadMCPConfig();
159
+ }
160
+ /**
161
+ * Get MCP config path for display
162
+ */
163
+ getMCPConfigPathForDisplay() {
164
+ return this.getMCPConfigPath();
165
+ }
166
+ /**
167
+ * Reset cache (for testing)
168
+ */
169
+ resetCache() {
170
+ this._config = null;
171
+ this._mcpServers = null;
172
+ }
173
+ }
@@ -0,0 +1,31 @@
1
+ export type Screen = 'welcome' | 'setup' | 'mcp-config' | 'chat' | 'loading';
2
+ export interface Message {
3
+ role: 'user' | 'assistant' | 'system';
4
+ content: string;
5
+ timestamp: Date;
6
+ }
7
+ export interface Config {
8
+ accountId: string;
9
+ privateKey: string;
10
+ network: string;
11
+ openAIApiKey: string;
12
+ }
13
+ export declare const BRAND_COLORS: {
14
+ blue: string;
15
+ green: string;
16
+ purple: string;
17
+ dark: string;
18
+ white: string;
19
+ hedera: {
20
+ purple: string;
21
+ blue: string;
22
+ green: string;
23
+ charcoal: string;
24
+ smoke: string;
25
+ };
26
+ keywords: string;
27
+ functions: string;
28
+ strings: string;
29
+ variables: string;
30
+ comments: string;
31
+ };
@@ -0,0 +1,19 @@
1
+ export const BRAND_COLORS = {
2
+ blue: '#5599fe',
3
+ green: '#48df7b',
4
+ purple: '#b56cff',
5
+ dark: '#3f4174',
6
+ white: '#ffffff',
7
+ hedera: {
8
+ purple: '#8259ef',
9
+ blue: '#2d84eb',
10
+ green: '#3ec878',
11
+ charcoal: '#464646',
12
+ smoke: '#8c8c8c',
13
+ },
14
+ keywords: '#3f4174',
15
+ functions: '#5599fe',
16
+ strings: '#48df7b',
17
+ variables: '#b56cff',
18
+ comments: '#6b7280',
19
+ };
@@ -67,7 +67,7 @@ export declare class ConversationalAgent {
67
67
  stateManager: IStateManager;
68
68
  private options;
69
69
  logger: Logger;
70
- protected contentStoreManager?: ContentStoreManager;
70
+ contentStoreManager?: ContentStoreManager;
71
71
  memoryManager?: SmartMemoryManager | undefined;
72
72
  private entityTools?;
73
73
  constructor(options: ConversationalAgentOptions);
@@ -184,14 +184,6 @@ export declare class ConversationalAgent {
184
184
  * Create a ConversationalAgent with MCP servers configured
185
185
  */
186
186
  static withMCP(options: ConversationalAgentOptions, mcpServers: MCPServerConfig[]): ConversationalAgent;
187
- /**
188
- * Detect the private key type by querying the account info from mirror node
189
- * @param {string} accountId - The Hedera account ID
190
- * @param {string} privateKey - The private key string
191
- * @param {NetworkType} network - The Hedera Hashgraph
192
- * @returns {Promise<PrivateKey>} The appropriate PrivateKey instance
193
- */
194
- private detectPrivateKeyType;
195
187
  /**
196
188
  * Resolve entity references using LLM-based resolver
197
189
  * @param content - Message content to resolve