@hashgraphonline/conversational-agent 0.1.208 → 0.1.210

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 (117) hide show
  1. package/bin/conversational-agent-cli.js +30 -0
  2. package/cli/readme.md +181 -0
  3. package/dist/cjs/base-agent.d.ts +3 -1
  4. package/dist/cjs/conversational-agent.d.ts +64 -13
  5. package/dist/cjs/index.cjs +1 -1
  6. package/dist/cjs/index.cjs.map +1 -1
  7. package/dist/cjs/index.d.ts +6 -3
  8. package/dist/cjs/langchain-agent.d.ts +11 -0
  9. package/dist/cjs/memory/SmartMemoryManager.d.ts +65 -22
  10. package/dist/cjs/memory/TokenCounter.d.ts +1 -1
  11. package/dist/cjs/memory/index.d.ts +1 -1
  12. package/dist/cjs/plugins/hbar/AirdropToolWrapper.d.ts +43 -0
  13. package/dist/{types/plugins/hbar-transfer/HbarTransferPlugin.d.ts → cjs/plugins/hbar/HbarPlugin.d.ts} +2 -1
  14. package/dist/{types/plugins/hbar-transfer → cjs/plugins/hbar}/TransferHbarTool.d.ts +1 -1
  15. package/dist/cjs/plugins/hbar/index.d.ts +3 -0
  16. package/dist/cjs/plugins/index.d.ts +2 -1
  17. package/dist/cjs/services/EntityResolver.d.ts +26 -0
  18. package/dist/cjs/tools/EntityResolverTool.d.ts +104 -0
  19. package/dist/cjs/types/inscription.d.ts +37 -0
  20. package/dist/esm/index.js +16 -2
  21. package/dist/esm/index.js.map +1 -1
  22. package/dist/esm/index12.js +121 -46
  23. package/dist/esm/index12.js.map +1 -1
  24. package/dist/esm/index13.js +177 -13
  25. package/dist/esm/index13.js.map +1 -1
  26. package/dist/esm/index14.js +599 -100
  27. package/dist/esm/index14.js.map +1 -1
  28. package/dist/esm/index15.js +426 -9
  29. package/dist/esm/index15.js.map +1 -1
  30. package/dist/esm/index16.js +119 -160
  31. package/dist/esm/index16.js.map +1 -1
  32. package/dist/esm/index17.js +140 -150
  33. package/dist/esm/index17.js.map +1 -1
  34. package/dist/esm/index18.js +44 -231
  35. package/dist/esm/index18.js.map +1 -1
  36. package/dist/esm/index19.js +86 -643
  37. package/dist/esm/index19.js.map +1 -1
  38. package/dist/esm/index2.js +22 -13
  39. package/dist/esm/index2.js.map +1 -1
  40. package/dist/esm/index20.js +20 -230
  41. package/dist/esm/index20.js.map +1 -1
  42. package/dist/esm/index21.js +9 -179
  43. package/dist/esm/index21.js.map +1 -1
  44. package/dist/esm/index22.js +140 -89
  45. package/dist/esm/index22.js.map +1 -1
  46. package/dist/esm/index23.js +141 -81
  47. package/dist/esm/index23.js.map +1 -1
  48. package/dist/esm/index24.js +4 -4
  49. package/dist/esm/index24.js.map +1 -1
  50. package/dist/esm/index25.js +0 -8
  51. package/dist/esm/index25.js.map +1 -1
  52. package/dist/esm/index26.js +95 -0
  53. package/dist/esm/index26.js.map +1 -0
  54. package/dist/esm/index27.js +242 -0
  55. package/dist/esm/index27.js.map +1 -0
  56. package/dist/esm/index5.js +32 -19
  57. package/dist/esm/index5.js.map +1 -1
  58. package/dist/esm/index6.js +276 -37
  59. package/dist/esm/index6.js.map +1 -1
  60. package/dist/esm/index7.js +2 -2
  61. package/dist/esm/index7.js.map +1 -1
  62. package/dist/esm/index8.js +124 -18
  63. package/dist/esm/index8.js.map +1 -1
  64. package/dist/types/base-agent.d.ts +3 -1
  65. package/dist/types/conversational-agent.d.ts +64 -13
  66. package/dist/types/index.d.ts +6 -3
  67. package/dist/types/langchain-agent.d.ts +11 -0
  68. package/dist/types/memory/SmartMemoryManager.d.ts +65 -22
  69. package/dist/types/memory/TokenCounter.d.ts +1 -1
  70. package/dist/types/memory/index.d.ts +1 -1
  71. package/dist/types/plugins/hbar/AirdropToolWrapper.d.ts +43 -0
  72. package/dist/{cjs/plugins/hbar-transfer/HbarTransferPlugin.d.ts → types/plugins/hbar/HbarPlugin.d.ts} +2 -1
  73. package/dist/{cjs/plugins/hbar-transfer → types/plugins/hbar}/TransferHbarTool.d.ts +1 -1
  74. package/dist/types/plugins/hbar/index.d.ts +3 -0
  75. package/dist/types/plugins/index.d.ts +2 -1
  76. package/dist/types/services/EntityResolver.d.ts +26 -0
  77. package/dist/types/tools/EntityResolverTool.d.ts +104 -0
  78. package/dist/types/types/inscription.d.ts +37 -0
  79. package/package.json +13 -4
  80. package/src/base-agent.ts +14 -9
  81. package/src/config/system-message.ts +11 -2
  82. package/src/context/ReferenceContextManager.ts +10 -5
  83. package/src/context/ReferenceResponseProcessor.ts +3 -4
  84. package/src/conversational-agent.ts +372 -57
  85. package/src/index.ts +19 -3
  86. package/src/langchain/ContentAwareAgentExecutor.ts +0 -1
  87. package/src/langchain-agent.ts +168 -33
  88. package/src/mcp/ContentProcessor.ts +11 -3
  89. package/src/mcp/adapters/langchain.ts +1 -10
  90. package/src/memory/ContentStorage.ts +2 -55
  91. package/src/memory/MemoryWindow.ts +4 -17
  92. package/src/memory/ReferenceIdGenerator.ts +4 -8
  93. package/src/memory/SmartMemoryManager.ts +375 -47
  94. package/src/memory/TokenCounter.ts +15 -22
  95. package/src/memory/index.ts +1 -1
  96. package/src/plugins/hbar/AirdropToolWrapper.ts +157 -0
  97. package/src/plugins/hbar/HbarPlugin.ts +86 -0
  98. package/src/plugins/{hbar-transfer → hbar}/TransferHbarTool.ts +3 -3
  99. package/src/plugins/hbar/index.ts +3 -0
  100. package/src/plugins/hcs-10/HCS10Plugin.ts +44 -14
  101. package/src/plugins/index.ts +2 -1
  102. package/src/services/ContentStoreManager.ts +0 -3
  103. package/src/services/EntityResolver.ts +135 -0
  104. package/src/tools/EntityResolverTool.ts +170 -0
  105. package/src/types/content-reference.ts +8 -8
  106. package/src/types/index.ts +0 -1
  107. package/src/types/inscription.ts +40 -0
  108. package/dist/cjs/plugins/hbar-transfer/index.d.ts +0 -1
  109. package/dist/types/plugins/hbar-transfer/index.d.ts +0 -1
  110. package/src/plugins/hbar-transfer/HbarTransferPlugin.ts +0 -66
  111. package/src/plugins/hbar-transfer/index.ts +0 -1
  112. /package/dist/cjs/plugins/{hbar-transfer → hbar}/AccountBuilder.d.ts +0 -0
  113. /package/dist/cjs/plugins/{hbar-transfer → hbar}/types.d.ts +0 -0
  114. /package/dist/types/plugins/{hbar-transfer → hbar}/AccountBuilder.d.ts +0 -0
  115. /package/dist/types/plugins/{hbar-transfer → hbar}/types.d.ts +0 -0
  116. /package/src/plugins/{hbar-transfer → hbar}/AccountBuilder.ts +0 -0
  117. /package/src/plugins/{hbar-transfer → hbar}/types.ts +0 -0
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * CLI executable for Conversational Agent
5
+ * This file enables running the CLI via npx
6
+ */
7
+
8
+ import { spawn } from 'child_process';
9
+ import { fileURLToPath } from 'url';
10
+ import { dirname, join } from 'path';
11
+
12
+ const __filename = fileURLToPath(import.meta.url);
13
+ const __dirname = dirname(__filename);
14
+
15
+ // Run the actual CLI from the cli directory
16
+ const cliPath = join(__dirname, '..', 'cli', 'dist', 'cli.js');
17
+
18
+ const child = spawn('node', [cliPath, ...process.argv.slice(2)], {
19
+ stdio: 'inherit',
20
+ shell: false
21
+ });
22
+
23
+ child.on('exit', (code) => {
24
+ process.exit(code || 0);
25
+ });
26
+
27
+ child.on('error', (err) => {
28
+ console.error('Failed to start CLI:', err);
29
+ process.exit(1);
30
+ });
package/cli/readme.md ADDED
@@ -0,0 +1,181 @@
1
+ # Hedera Conversational Agent CLI
2
+
3
+ A beautiful command-line interface for the Hedera Conversational Agent, built with [Ink](https://github.com/vadimdemedes/ink) and styled following Hashgraph Online design patterns.
4
+
5
+ ## Features
6
+
7
+ - 🎨 **Beautiful Terminal UI** - Styled with HCS improvement proposals design patterns
8
+ - 💬 **Interactive Chat** - Chat with your Hedera agent in a clean terminal interface
9
+ - 🔐 **Secure Configuration** - Masked input for sensitive credentials
10
+ - 🌈 **Gradient Text & Colors** - Brand-consistent color scheme
11
+ - 🚀 **Fast & Responsive** - Built with React for smooth interactions
12
+ - 📊 **Transaction Details** - See transaction IDs and network responses
13
+ - 🎯 **HCS-10 Support** - Full support for agent connections and messaging
14
+ - 🔧 **MCP Integration** - Configure Model Context Protocol servers for extended capabilities
15
+ - 📁 **File Operations** - Built-in filesystem MCP server for file management
16
+ - ⚙️ **Custom MCP Servers** - Add your own MCP servers for specialized tools
17
+
18
+ ## Installation
19
+
20
+ For local development, the CLI uses the actual ConversationalAgent from the parent package:
21
+
22
+ ```bash
23
+ # 1. Build the parent package first
24
+ cd /path/to/conversational-agent
25
+ pnpm install
26
+ pnpm build
27
+
28
+ # 2. The CLI will be built automatically via postinstall hook
29
+ # Or build manually:
30
+ cd cli
31
+ pnpm install
32
+ pnpm build
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ ### Interactive Mode (Recommended)
38
+
39
+ ```bash
40
+ # From the parent conversational-agent directory
41
+ pnpm cli
42
+
43
+ # This automatically builds if needed and runs the CLI
44
+ ```
45
+
46
+ ### With Command Line Arguments
47
+
48
+ ```bash
49
+ conversational-agent \
50
+ --account-id=0.0.12345 \
51
+ --private-key=your-private-key \
52
+ --network=testnet \
53
+ --openai-api-key=sk-...
54
+ ```
55
+
56
+ ### Using Environment Variables
57
+
58
+ The CLI automatically loads configuration from `.env` in the conversational-agent root:
59
+
60
+ ```bash
61
+ # .env file in conversational-agent directory
62
+ HEDERA_ACCOUNT_ID=0.0.12345
63
+ HEDERA_PRIVATE_KEY=your-private-key
64
+ HEDERA_NETWORK=testnet
65
+ OPENAI_API_KEY=sk-...
66
+ MCP_SERVERS=[{"name":"filesystem","command":"npx","args":["-y","@modelcontextprotocol/server-filesystem","/tmp"]}]
67
+ ```
68
+
69
+ Then simply run: `pnpm cli`
70
+
71
+ ## Interface Overview
72
+
73
+ ### Welcome Screen
74
+ - Beautiful ASCII art logo with gradient colors
75
+ - Simple menu navigation with arrow keys
76
+ - Options: Start Chat, Configure, MCP Servers, Exit
77
+
78
+ ### Configuration Screen
79
+ - Terminal-style window with macOS-like controls
80
+ - Secure input masking for sensitive data
81
+ - Tab navigation between fields
82
+ - Real-time validation
83
+
84
+ ### MCP Servers Screen
85
+ - Configure Model Context Protocol servers
86
+ - Enable/disable filesystem server with custom path
87
+ - Add custom MCP servers with command and arguments
88
+ - Live preview of available tools
89
+ - Save configuration to environment
90
+
91
+ ### Chat Interface
92
+ - Clean terminal aesthetic with prompt symbols
93
+ - Color-coded messages (user, assistant, system)
94
+ - Loading indicators with spinners
95
+ - Transaction ID display
96
+ - MCP server status and available tools
97
+ - Escape key to return to menu
98
+
99
+ ## Design Features
100
+
101
+ The CLI follows Hashgraph Online's design system:
102
+
103
+ - **Brand Colors**: Primary blue (#5599fe), Green (#48df7b), Purple (#b56cff)
104
+ - **Hedera Colors**: Purple (#8259ef), Blue (#2d84eb), Green (#3ec878)
105
+ - **Terminal Window**: Rounded borders with window control dots
106
+ - **Status Badges**: Color-coded status indicators
107
+ - **Typography**: Monospace throughout with clear hierarchy
108
+
109
+ ## Keyboard Shortcuts
110
+
111
+ - `↑/↓` - Navigate menus
112
+ - `Enter` - Select/Submit
113
+ - `Tab` - Next field (in configuration)
114
+ - `Escape` - Return to main menu (from chat)
115
+ - `Ctrl+C` - Exit application
116
+
117
+ ## Development
118
+
119
+ ```bash
120
+ # Watch mode for development
121
+ pnpm dev
122
+
123
+ # Run tests
124
+ pnpm test
125
+
126
+ # Build for production
127
+ pnpm build
128
+ ```
129
+
130
+ ## Examples
131
+
132
+ ### Basic Chat Interaction
133
+
134
+ ```
135
+ $ Find all AI agents on the network
136
+ → I'll search for AI agents registered on the Hedera network...
137
+
138
+ [INFO] Found 5 agents with AI capabilities
139
+ → Here are the AI agents I found:
140
+ 1. Agent: 0.0.12345 - "GPT Assistant"
141
+ 2. Agent: 0.0.23456 - "Code Helper"
142
+ ...
143
+
144
+ $ Connect to agent 0.0.12345
145
+ → Initiating connection to agent 0.0.12345...
146
+ [INFO] Transaction ID: 0.0.98765@1234567890.123
147
+ → Successfully connected! You can now send messages to this agent.
148
+ ```
149
+
150
+ ### MCP File Operations
151
+
152
+ With filesystem MCP server enabled:
153
+
154
+ ```
155
+ $ Create a new file called notes.txt with my meeting notes
156
+ → I'll create a notes.txt file for you with meeting notes...
157
+
158
+ [INFO] MCP servers enabled: filesystem
159
+ → I've created notes.txt in your configured directory with the meeting notes.
160
+
161
+ $ List all files in the current directory
162
+ → Here are the files in /tmp:
163
+ - notes.txt (created just now)
164
+ - data.json
165
+ - config.yaml
166
+ ```
167
+
168
+ ### Custom MCP Server
169
+
170
+ ```
171
+ $ Add GitHub repository operations
172
+ → I can help you interact with GitHub repositories...
173
+
174
+ [INFO] MCP servers enabled: filesystem, github
175
+ → I now have access to GitHub operations. I can help you create issues,
176
+ manage repositories, and work with pull requests.
177
+ ```
178
+
179
+ ## License
180
+
181
+ Apache-2.0
@@ -4,7 +4,7 @@ import { TransactionReceipt } from '@hashgraph/sdk';
4
4
  import { HederaAgentKit, ServerSigner, TokenUsageCallbackHandler, TokenUsage, BasePlugin, CostCalculation } from 'hedera-agent-kit';
5
5
  import { AIProvider, VercelAIProvider, BAMLProvider } from './providers';
6
6
  import { Logger } from '@hashgraphonline/standards-sdk';
7
- import { MCPServerConfig } from './mcp/types';
7
+ import { MCPServerConfig, MCPConnectionStatus } from './mcp/types';
8
8
 
9
9
  export interface ToolFilterConfig {
10
10
  namespaceWhitelist?: string[];
@@ -93,6 +93,8 @@ export declare abstract class BaseAgent {
93
93
  abstract getUsageStats(): UsageStats;
94
94
  abstract getUsageLog(): UsageStats[];
95
95
  abstract clearUsageStats(): void;
96
+ abstract connectMCPServers(): Promise<void>;
97
+ abstract getMCPConnectionStatus(): Map<string, MCPConnectionStatus>;
96
98
  getCore(): HederaAgentKit | undefined;
97
99
  protected filterTools(tools: StructuredTool[]): StructuredTool[];
98
100
  protected buildSystemPrompt(): string;
@@ -1,20 +1,33 @@
1
1
  import { BasePlugin, AgentOperationalMode, MirrorNodeConfig } from 'hedera-agent-kit';
2
- import { NetworkType } from '@hashgraphonline/standards-sdk';
2
+ import { Logger, NetworkType } from '@hashgraphonline/standards-sdk';
3
3
  import { createAgent } from './agent-factory';
4
4
  import { ChatResponse } from './base-agent';
5
5
  import { HCS10Plugin } from './plugins/hcs-10/HCS10Plugin';
6
6
  import { HCS2Plugin } from './plugins/hcs-2/HCS2Plugin';
7
7
  import { InscribePlugin } from './plugins/inscribe/InscribePlugin';
8
- import { HbarTransferPlugin } from './plugins/hbar-transfer/HbarTransferPlugin';
8
+ import { HbarPlugin } from './plugins/hbar/HbarPlugin';
9
9
  import { IStateManager } from '@hashgraphonline/standards-agent-kit';
10
- import { MCPServerConfig } from './mcp/types';
10
+ import { MCPServerConfig, MCPConnectionStatus } from './mcp/types';
11
+ import { ContentStoreManager } from './services/ContentStoreManager';
12
+ import { SmartMemoryManager, SmartMemoryConfig } from './memory';
11
13
 
14
+ export type ToolDescriptor = {
15
+ name: string;
16
+ namespace?: string;
17
+ };
18
+ export type ChatHistoryItem = {
19
+ type: 'human' | 'ai';
20
+ content: string;
21
+ };
22
+ export type AgentInstance = ReturnType<typeof createAgent>;
23
+ export type MirrorNetwork = 'testnet' | 'mainnet' | 'previewnet';
12
24
  export interface ConversationalAgentOptions {
13
25
  accountId: string;
14
26
  privateKey: string;
15
27
  network?: NetworkType;
16
28
  openAIApiKey: string;
17
29
  openAIModelName?: string;
30
+ llmProvider?: 'openai' | 'anthropic';
18
31
  verbose?: boolean;
19
32
  operationalMode?: AgentOperationalMode;
20
33
  userAccountId?: string;
@@ -31,6 +44,10 @@ export interface ConversationalAgentOptions {
31
44
  namespace?: string;
32
45
  }) => boolean;
33
46
  mcpServers?: MCPServerConfig[];
47
+ /** Enable automatic entity memory functionality (default: true) */
48
+ entityMemoryEnabled?: boolean;
49
+ /** Configuration for entity memory system */
50
+ entityMemoryConfig?: SmartMemoryConfig;
34
51
  }
35
52
  /**
36
53
  * The ConversationalAgent class is an optional wrapper around the HederaConversationalAgent class,
@@ -42,18 +59,20 @@ export interface ConversationalAgentOptions {
42
59
  * @returns A new instance of the ConversationalAgent class.
43
60
  */
44
61
  export declare class ConversationalAgent {
45
- private agent?;
62
+ protected agent?: AgentInstance;
46
63
  hcs10Plugin: HCS10Plugin;
47
64
  hcs2Plugin: HCS2Plugin;
48
65
  inscribePlugin: InscribePlugin;
49
- hbarTransferPlugin: HbarTransferPlugin;
66
+ hbarPlugin: HbarPlugin;
50
67
  stateManager: IStateManager;
51
68
  private options;
52
- private logger;
53
- private contentStoreManager?;
69
+ logger: Logger;
70
+ protected contentStoreManager?: ContentStoreManager;
71
+ memoryManager?: SmartMemoryManager | undefined;
72
+ private entityTools?;
54
73
  constructor(options: ConversationalAgentOptions);
55
74
  /**
56
- * Initialize the conversational agent with Hedera network connection and AI configuration
75
+ * Initialize the conversational agent with Hedera Hashgraph connection and AI configuration
57
76
  * @throws {Error} If account ID or private key is missing
58
77
  * @throws {Error} If initialization fails
59
78
  */
@@ -87,10 +106,7 @@ export declare class ConversationalAgent {
87
106
  * @returns {Promise<ChatResponse>} The agent's response
88
107
  * @throws {Error} If agent is not initialized
89
108
  */
90
- processMessage(message: string, chatHistory?: {
91
- type: 'human' | 'ai';
92
- content: string;
93
- }[]): Promise<ChatResponse>;
109
+ processMessage(message: string, chatHistory?: ChatHistoryItem[]): Promise<ChatResponse>;
94
110
  /**
95
111
  * Validates initialization options and throws if required fields are missing.
96
112
  *
@@ -172,12 +188,47 @@ export declare class ConversationalAgent {
172
188
  * Detect the private key type by querying the account info from mirror node
173
189
  * @param {string} accountId - The Hedera account ID
174
190
  * @param {string} privateKey - The private key string
175
- * @param {NetworkType} network - The Hedera network
191
+ * @param {NetworkType} network - The Hedera Hashgraph
176
192
  * @returns {Promise<PrivateKey>} The appropriate PrivateKey instance
177
193
  */
178
194
  private detectPrivateKeyType;
195
+ /**
196
+ * Resolve entity references using LLM-based resolver
197
+ * @param content - Message content to resolve
198
+ * @returns Resolved message content with entity IDs replaced
199
+ */
200
+ private resolveEntitiesInMessage;
201
+ /**
202
+ * Extract and store entities from agent responses
203
+ * @param response - Agent response containing potential entity information
204
+ * @param originalMessage - Original user message for context
205
+ */
206
+ private extractAndStoreEntities;
207
+ /**
208
+ * Extract transaction ID from response if available
209
+ * @param response - Transaction response
210
+ * @returns Transaction ID or undefined
211
+ */
212
+ private extractTransactionId;
213
+ /**
214
+ * Connect to MCP servers asynchronously
215
+ * @private
216
+ */
217
+ private connectMCP;
218
+ /**
219
+ * Get MCP connection status for all servers
220
+ * @returns {Map<string, MCPConnectionStatus>} Connection status map
221
+ */
222
+ getMCPConnectionStatus(): Map<string, MCPConnectionStatus>;
223
+ /**
224
+ * Check if a specific MCP server is connected
225
+ * @param {string} serverName - Name of the server to check
226
+ * @returns {boolean} True if connected, false otherwise
227
+ */
228
+ isMCPServerConnected(serverName: string): boolean;
179
229
  /**
180
230
  * Clean up resources
181
231
  */
182
232
  cleanup(): Promise<void>;
233
+ private extractResponseText;
183
234
  }