@hashgraphonline/conversational-agent 0.1.217 → 0.1.218

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 (286) hide show
  1. package/cli/readme.md +181 -0
  2. package/dist/cjs/constants/entity-references.d.ts +18 -0
  3. package/dist/cjs/constants/form-priorities.d.ts +24 -0
  4. package/dist/cjs/constants/index.d.ts +4 -0
  5. package/dist/cjs/constants/messages.d.ts +19 -0
  6. package/dist/cjs/constants/test-constants.d.ts +42 -0
  7. package/dist/cjs/conversational-agent.d.ts +3 -8
  8. package/dist/cjs/core/{ToolRegistry.d.ts → tool-registry.d.ts} +10 -7
  9. package/dist/{types/execution/ExecutionPipeline.d.ts → cjs/execution/execution-pipeline.d.ts} +3 -3
  10. package/dist/cjs/forms/field-guidance-registry.d.ts +108 -0
  11. package/dist/cjs/forms/form-generator.d.ts +2 -7
  12. package/dist/cjs/forms/index.d.ts +3 -0
  13. package/dist/cjs/forms/types.d.ts +9 -1
  14. package/dist/cjs/index.cjs +1 -1
  15. package/dist/cjs/index.cjs.map +1 -1
  16. package/dist/cjs/index.d.ts +7 -12
  17. package/dist/cjs/langchain/external-tool-wrapper.d.ts +101 -0
  18. package/dist/{types/langchain/FormAwareAgentExecutor.d.ts → cjs/langchain/form-aware-agent-executor.d.ts} +19 -12
  19. package/dist/cjs/langchain/index.d.ts +2 -0
  20. package/dist/{types → cjs/langchain}/langchain-agent.d.ts +15 -7
  21. package/dist/cjs/mcp/adapters/index.d.ts +1 -0
  22. package/dist/cjs/mcp/adapters/langchain.d.ts +1 -1
  23. package/dist/{types/mcp/ContentProcessor.d.ts → cjs/mcp/content-processor.d.ts} +1 -1
  24. package/dist/cjs/mcp/index.d.ts +5 -0
  25. package/dist/{types/mcp/MCPClientManager.d.ts → cjs/mcp/mcp-client-manager.d.ts} +1 -1
  26. package/dist/cjs/memory/{ContentStorage.d.ts → content-storage.d.ts} +4 -4
  27. package/dist/cjs/memory/index.d.ts +5 -7
  28. package/dist/{types/memory/MemoryWindow.d.ts → cjs/memory/memory-window.d.ts} +1 -1
  29. package/dist/{types/memory/SmartMemoryManager.d.ts → cjs/memory/smart-memory-manager.d.ts} +1 -1
  30. package/dist/cjs/services/{ContentStoreManager.d.ts → content-store-manager.d.ts} +6 -6
  31. package/dist/cjs/services/context/resolution-context.d.ts +49 -0
  32. package/dist/cjs/services/entity-resolver.d.ts +58 -0
  33. package/dist/cjs/services/formatters/converters/index.d.ts +2 -0
  34. package/dist/cjs/services/formatters/converters/string-normalization-converter.d.ts +13 -0
  35. package/dist/cjs/services/formatters/converters/topic-id-to-hrl-converter.d.ts +17 -0
  36. package/dist/cjs/services/formatters/format-converter-registry.d.ts +66 -0
  37. package/dist/cjs/services/formatters/index.d.ts +3 -0
  38. package/dist/cjs/services/formatters/types.d.ts +29 -0
  39. package/dist/cjs/services/index.d.ts +3 -0
  40. package/dist/cjs/services/resolution/resolution-pipeline.d.ts +44 -0
  41. package/dist/cjs/tools/index.d.ts +1 -0
  42. package/dist/cjs/utils/index.d.ts +1 -0
  43. package/dist/esm/index.js +40 -16
  44. package/dist/esm/index.js.map +1 -1
  45. package/dist/esm/index10.js +669 -13
  46. package/dist/esm/index10.js.map +1 -1
  47. package/dist/esm/index11.js +310 -95
  48. package/dist/esm/index11.js.map +1 -1
  49. package/dist/esm/index12.js +130 -95
  50. package/dist/esm/index12.js.map +1 -1
  51. package/dist/esm/index13.js +262 -153
  52. package/dist/esm/index13.js.map +1 -1
  53. package/dist/esm/index14.js +100 -664
  54. package/dist/esm/index14.js.map +1 -1
  55. package/dist/esm/index15.js +135 -408
  56. package/dist/esm/index15.js.map +1 -1
  57. package/dist/esm/index16.js +240 -122
  58. package/dist/esm/index16.js.map +1 -1
  59. package/dist/esm/index17.js +147 -135
  60. package/dist/esm/index17.js.map +1 -1
  61. package/dist/esm/index18.js +376 -533
  62. package/dist/esm/index18.js.map +1 -1
  63. package/dist/esm/index19.js +87 -214
  64. package/dist/esm/index19.js.map +1 -1
  65. package/dist/esm/index2.js +21 -4
  66. package/dist/esm/index2.js.map +1 -1
  67. package/dist/esm/index20.js +158 -92
  68. package/dist/esm/index20.js.map +1 -1
  69. package/dist/esm/index21.js +717 -44
  70. package/dist/esm/index21.js.map +1 -1
  71. package/dist/esm/index22.js +58 -96
  72. package/dist/esm/index22.js.map +1 -1
  73. package/dist/esm/index23.js +324 -34
  74. package/dist/esm/index23.js.map +1 -1
  75. package/dist/esm/index24.js +125 -712
  76. package/dist/esm/index24.js.map +1 -1
  77. package/dist/esm/index25.js +113 -133
  78. package/dist/esm/index25.js.map +1 -1
  79. package/dist/esm/index26.js +18 -152
  80. package/dist/esm/index26.js.map +1 -1
  81. package/dist/esm/index27.js +14 -210
  82. package/dist/esm/index27.js.map +1 -1
  83. package/dist/esm/index28.js +70 -173
  84. package/dist/esm/index28.js.map +1 -1
  85. package/dist/esm/index29.js +811 -224
  86. package/dist/esm/index29.js.map +1 -1
  87. package/dist/esm/index30.js +1245 -122
  88. package/dist/esm/index30.js.map +1 -1
  89. package/dist/esm/index31.js +126 -56
  90. package/dist/esm/index31.js.map +1 -1
  91. package/dist/esm/index32.js +111 -24
  92. package/dist/esm/index32.js.map +1 -1
  93. package/dist/esm/index33.js +41 -87
  94. package/dist/esm/index33.js.map +1 -1
  95. package/dist/esm/index34.js +88 -227
  96. package/dist/esm/index34.js.map +1 -1
  97. package/dist/esm/index35.js +24 -0
  98. package/dist/esm/index35.js.map +1 -0
  99. package/dist/esm/index36.js +15 -0
  100. package/dist/esm/index36.js.map +1 -0
  101. package/dist/esm/index37.js +10 -0
  102. package/dist/esm/index37.js.map +1 -0
  103. package/dist/esm/index38.js +8 -0
  104. package/dist/esm/index38.js.map +1 -0
  105. package/dist/esm/index39.js +227 -0
  106. package/dist/esm/index39.js.map +1 -0
  107. package/dist/esm/index40.js +187 -0
  108. package/dist/esm/index40.js.map +1 -0
  109. package/dist/esm/index41.js +30 -0
  110. package/dist/esm/index41.js.map +1 -0
  111. package/dist/esm/index42.js +95 -0
  112. package/dist/esm/index42.js.map +1 -0
  113. package/dist/esm/index5.js +2 -2
  114. package/dist/esm/index5.js.map +1 -1
  115. package/dist/esm/index6.js +44 -67
  116. package/dist/esm/index6.js.map +1 -1
  117. package/dist/esm/index7.js +9 -0
  118. package/dist/esm/index7.js.map +1 -1
  119. package/dist/esm/index8.js +13 -1095
  120. package/dist/esm/index8.js.map +1 -1
  121. package/dist/esm/index9.js +17 -13
  122. package/dist/esm/index9.js.map +1 -1
  123. package/dist/types/constants/entity-references.d.ts +18 -0
  124. package/dist/types/constants/form-priorities.d.ts +24 -0
  125. package/dist/types/constants/index.d.ts +4 -0
  126. package/dist/types/constants/messages.d.ts +19 -0
  127. package/dist/types/constants/test-constants.d.ts +42 -0
  128. package/dist/types/conversational-agent.d.ts +3 -8
  129. package/dist/types/core/{ToolRegistry.d.ts → tool-registry.d.ts} +10 -7
  130. package/dist/{cjs/execution/ExecutionPipeline.d.ts → types/execution/execution-pipeline.d.ts} +3 -3
  131. package/dist/types/forms/field-guidance-registry.d.ts +108 -0
  132. package/dist/types/forms/form-generator.d.ts +2 -7
  133. package/dist/types/forms/index.d.ts +3 -0
  134. package/dist/types/forms/types.d.ts +9 -1
  135. package/dist/types/index.d.ts +7 -12
  136. package/dist/types/langchain/external-tool-wrapper.d.ts +101 -0
  137. package/dist/{cjs/langchain/FormAwareAgentExecutor.d.ts → types/langchain/form-aware-agent-executor.d.ts} +19 -12
  138. package/dist/types/langchain/index.d.ts +2 -0
  139. package/dist/{cjs → types/langchain}/langchain-agent.d.ts +15 -7
  140. package/dist/types/mcp/adapters/index.d.ts +1 -0
  141. package/dist/types/mcp/adapters/langchain.d.ts +1 -1
  142. package/dist/{cjs/mcp/ContentProcessor.d.ts → types/mcp/content-processor.d.ts} +1 -1
  143. package/dist/types/mcp/index.d.ts +5 -0
  144. package/dist/{cjs/mcp/MCPClientManager.d.ts → types/mcp/mcp-client-manager.d.ts} +1 -1
  145. package/dist/types/memory/{ContentStorage.d.ts → content-storage.d.ts} +4 -4
  146. package/dist/types/memory/index.d.ts +5 -7
  147. package/dist/{cjs/memory/MemoryWindow.d.ts → types/memory/memory-window.d.ts} +1 -1
  148. package/dist/{cjs/memory/SmartMemoryManager.d.ts → types/memory/smart-memory-manager.d.ts} +1 -1
  149. package/dist/types/services/{ContentStoreManager.d.ts → content-store-manager.d.ts} +6 -6
  150. package/dist/types/services/context/resolution-context.d.ts +49 -0
  151. package/dist/types/services/entity-resolver.d.ts +58 -0
  152. package/dist/types/services/formatters/converters/index.d.ts +2 -0
  153. package/dist/types/services/formatters/converters/string-normalization-converter.d.ts +13 -0
  154. package/dist/types/services/formatters/converters/topic-id-to-hrl-converter.d.ts +17 -0
  155. package/dist/types/services/formatters/format-converter-registry.d.ts +66 -0
  156. package/dist/types/services/formatters/index.d.ts +3 -0
  157. package/dist/types/services/formatters/types.d.ts +29 -0
  158. package/dist/types/services/index.d.ts +3 -0
  159. package/dist/types/services/resolution/resolution-pipeline.d.ts +44 -0
  160. package/dist/types/tools/index.d.ts +1 -0
  161. package/dist/types/utils/index.d.ts +1 -0
  162. package/package.json +30 -27
  163. package/src/agent-factory.ts +1 -1
  164. package/src/base-agent.ts +9 -0
  165. package/src/config/system-message.ts +2 -15
  166. package/src/constants/entity-references.ts +23 -0
  167. package/src/constants/form-priorities.ts +25 -0
  168. package/src/constants/index.ts +4 -0
  169. package/src/constants/messages.ts +20 -0
  170. package/src/constants/test-constants.ts +49 -0
  171. package/src/conversational-agent.ts +42 -69
  172. package/src/core/{ToolRegistry.ts → tool-registry.ts} +70 -44
  173. package/src/examples/external-tool-wrapper-example.ts +56 -0
  174. package/src/execution/{ExecutionPipeline.ts → execution-pipeline.ts} +3 -3
  175. package/src/forms/field-guidance-registry.ts +415 -0
  176. package/src/forms/field-type-registry.ts +49 -48
  177. package/src/forms/{FormEngine.ts → form-engine.ts} +66 -43
  178. package/src/forms/form-generator.ts +91 -17
  179. package/src/forms/index.ts +4 -1
  180. package/src/forms/types.ts +9 -1
  181. package/src/index.ts +7 -37
  182. package/src/langchain/external-tool-wrapper.ts +90 -0
  183. package/src/langchain/{FormAwareAgentExecutor.ts → form-aware-agent-executor.ts} +579 -351
  184. package/src/langchain/index.ts +2 -0
  185. package/src/{langchain-agent.ts → langchain/langchain-agent.ts} +389 -113
  186. package/src/mcp/adapters/index.ts +1 -0
  187. package/src/mcp/adapters/langchain.ts +27 -18
  188. package/src/mcp/{ContentProcessor.ts → content-processor.ts} +71 -47
  189. package/src/mcp/index.ts +5 -0
  190. package/src/mcp/{MCPClientManager.ts → mcp-client-manager.ts} +2 -2
  191. package/src/memory/{ContentStorage.ts → content-storage.ts} +263 -167
  192. package/src/memory/index.ts +5 -8
  193. package/src/memory/{MemoryWindow.ts → memory-window.ts} +47 -24
  194. package/src/memory/{SmartMemoryManager.ts → smart-memory-manager.ts} +49 -22
  195. package/src/plugins/hbar/HbarPlugin.ts +1 -1
  196. package/src/plugins/hcs-10/HCS10Plugin.ts +46 -28
  197. package/src/scripts/test-external-tool-wrapper.ts +6 -6
  198. package/src/scripts/test-inscribe-form-generation.ts +22 -21
  199. package/src/scripts/test-inscribe-wrapper-verification.ts +5 -4
  200. package/src/services/{ContentStoreManager.ts → content-store-manager.ts} +75 -33
  201. package/src/services/context/resolution-context.ts +80 -0
  202. package/src/services/entity-resolver.ts +425 -0
  203. package/src/services/formatters/converters/index.ts +2 -0
  204. package/src/services/formatters/converters/string-normalization-converter.ts +106 -0
  205. package/src/services/formatters/converters/topic-id-to-hrl-converter.ts +25 -0
  206. package/src/services/formatters/format-converter-registry.ts +229 -0
  207. package/src/services/formatters/index.ts +3 -0
  208. package/src/services/formatters/types.ts +31 -0
  209. package/src/services/index.ts +3 -0
  210. package/src/services/resolution/resolution-pipeline.ts +106 -0
  211. package/src/tools/index.ts +1 -0
  212. package/src/types/content-reference.ts +87 -60
  213. package/src/utils/index.ts +1 -0
  214. package/cli/dist/CLIApp.d.ts +0 -9
  215. package/cli/dist/CLIApp.js +0 -127
  216. package/cli/dist/LocalConversationalAgent.d.ts +0 -37
  217. package/cli/dist/LocalConversationalAgent.js +0 -58
  218. package/cli/dist/app.d.ts +0 -16
  219. package/cli/dist/app.js +0 -13
  220. package/cli/dist/cli.d.ts +0 -2
  221. package/cli/dist/cli.js +0 -51
  222. package/cli/dist/components/AppContainer.d.ts +0 -16
  223. package/cli/dist/components/AppContainer.js +0 -24
  224. package/cli/dist/components/AppScreens.d.ts +0 -2
  225. package/cli/dist/components/AppScreens.js +0 -259
  226. package/cli/dist/components/ChatScreen.d.ts +0 -15
  227. package/cli/dist/components/ChatScreen.js +0 -39
  228. package/cli/dist/components/DebugLoadingScreen.d.ts +0 -5
  229. package/cli/dist/components/DebugLoadingScreen.js +0 -31
  230. package/cli/dist/components/LoadingScreen.d.ts +0 -2
  231. package/cli/dist/components/LoadingScreen.js +0 -16
  232. package/cli/dist/components/LoadingScreenDebug.d.ts +0 -5
  233. package/cli/dist/components/LoadingScreenDebug.js +0 -27
  234. package/cli/dist/components/MCPConfigScreen.d.ts +0 -28
  235. package/cli/dist/components/MCPConfigScreen.js +0 -168
  236. package/cli/dist/components/ScreenRouter.d.ts +0 -12
  237. package/cli/dist/components/ScreenRouter.js +0 -22
  238. package/cli/dist/components/SetupScreen.d.ts +0 -15
  239. package/cli/dist/components/SetupScreen.js +0 -65
  240. package/cli/dist/components/SingleLoadingScreen.d.ts +0 -5
  241. package/cli/dist/components/SingleLoadingScreen.js +0 -27
  242. package/cli/dist/components/StatusBadge.d.ts +0 -7
  243. package/cli/dist/components/StatusBadge.js +0 -28
  244. package/cli/dist/components/TerminalWindow.d.ts +0 -8
  245. package/cli/dist/components/TerminalWindow.js +0 -24
  246. package/cli/dist/components/WelcomeScreen.d.ts +0 -11
  247. package/cli/dist/components/WelcomeScreen.js +0 -47
  248. package/cli/dist/context/AppContext.d.ts +0 -68
  249. package/cli/dist/context/AppContext.js +0 -363
  250. package/cli/dist/hooks/useInitializeAgent.d.ts +0 -19
  251. package/cli/dist/hooks/useInitializeAgent.js +0 -28
  252. package/cli/dist/hooks/useStableState.d.ts +0 -38
  253. package/cli/dist/hooks/useStableState.js +0 -68
  254. package/cli/dist/managers/AgentManager.d.ts +0 -57
  255. package/cli/dist/managers/AgentManager.js +0 -119
  256. package/cli/dist/managers/ConfigManager.d.ts +0 -53
  257. package/cli/dist/managers/ConfigManager.js +0 -173
  258. package/cli/dist/types.d.ts +0 -31
  259. package/cli/dist/types.js +0 -19
  260. package/dist/cjs/context/ReferenceContextManager.d.ts +0 -84
  261. package/dist/cjs/context/ReferenceResponseProcessor.d.ts +0 -76
  262. package/dist/cjs/langchain/FormValidatingToolWrapper.d.ts +0 -81
  263. package/dist/cjs/services/EntityResolver.d.ts +0 -26
  264. package/dist/types/context/ReferenceContextManager.d.ts +0 -84
  265. package/dist/types/context/ReferenceResponseProcessor.d.ts +0 -76
  266. package/dist/types/langchain/FormValidatingToolWrapper.d.ts +0 -81
  267. package/dist/types/services/EntityResolver.d.ts +0 -26
  268. package/src/context/ReferenceContextManager.ts +0 -350
  269. package/src/context/ReferenceResponseProcessor.ts +0 -295
  270. package/src/langchain/FormValidatingToolWrapper.ts +0 -355
  271. package/src/scripts/test-hedera-kit-wrapper.ts +0 -265
  272. package/src/services/EntityResolver.ts +0 -128
  273. /package/dist/cjs/forms/{FormEngine.d.ts → form-engine.d.ts} +0 -0
  274. /package/dist/cjs/memory/{ReferenceIdGenerator.d.ts → reference-id-generator.d.ts} +0 -0
  275. /package/dist/cjs/memory/{TokenCounter.d.ts → token-counter.d.ts} +0 -0
  276. /package/dist/cjs/tools/{EntityResolverTool.d.ts → entity-resolver-tool.d.ts} +0 -0
  277. /package/dist/cjs/utils/{ResponseFormatter.d.ts → response-formatter.d.ts} +0 -0
  278. /package/dist/types/forms/{FormEngine.d.ts → form-engine.d.ts} +0 -0
  279. /package/dist/types/memory/{ReferenceIdGenerator.d.ts → reference-id-generator.d.ts} +0 -0
  280. /package/dist/types/memory/{TokenCounter.d.ts → token-counter.d.ts} +0 -0
  281. /package/dist/types/tools/{EntityResolverTool.d.ts → entity-resolver-tool.d.ts} +0 -0
  282. /package/dist/types/utils/{ResponseFormatter.d.ts → response-formatter.d.ts} +0 -0
  283. /package/src/memory/{ReferenceIdGenerator.ts → reference-id-generator.ts} +0 -0
  284. /package/src/memory/{TokenCounter.ts → token-counter.ts} +0 -0
  285. /package/src/tools/{EntityResolverTool.ts → entity-resolver-tool.ts} +0 -0
  286. /package/src/utils/{ResponseFormatter.ts → response-formatter.ts} +0 -0
@@ -1,265 +0,0 @@
1
- import { StructuredTool } from '@langchain/core/tools';
2
- import { Logger } from '@hashgraphonline/standards-sdk';
3
- import {
4
- wrapExternalToolWithRenderConfig,
5
- renderConfigs,
6
- hederaToolConfigs,
7
- ExternalToolWrapper
8
- } from '../langchain/external-tool-wrapper';
9
- import { FormValidatingToolWrapper, wrapToolWithFormValidation } from '../langchain/FormValidatingToolWrapper';
10
- import { FormGenerator } from '../forms/form-generator';
11
- import { z } from 'zod';
12
-
13
- /**
14
- * Mock Hedera tool that simulates the structure of hedera-agent-kit tools
15
- */
16
- class MockHederaGetAccountInfoTool extends StructuredTool {
17
- name = 'hedera_get_account_info';
18
- description = 'Get comprehensive information about a Hedera account including balance, tokens, and recent activity';
19
-
20
- schema = z.object({
21
- accountId: z.string().describe('The Hedera account ID in format 0.0.accountNum'),
22
- includeBalances: z.boolean().optional().describe('Whether to include token balances'),
23
- includeTransactions: z.boolean().optional().describe('Whether to include recent transactions'),
24
- maxTransactions: z.number().optional().describe('Maximum number of recent transactions to include')
25
- });
26
-
27
- protected async _call(
28
- input: z.infer<typeof this.schema>
29
- ): Promise<string> {
30
-
31
- return JSON.stringify({
32
- success: true,
33
- accountId: input.accountId,
34
- balance: '100.50 HBAR',
35
- tokens: input.includeBalances ? ['0.0.123456', '0.0.789012'] : [],
36
- transactions: input.includeTransactions ? ['0.0.111@1234567890.000000000'] : [],
37
- message: `Mock account info for ${input.accountId}`
38
- });
39
- }
40
- }
41
-
42
- /**
43
- * Mock Hedera HBAR transfer tool
44
- */
45
- class MockHederaTransferHbarTool extends StructuredTool {
46
- name = 'hedera_transfer_hbar';
47
- description = 'Transfer HBAR from one account to another';
48
-
49
- schema = z.object({
50
- fromAccountId: z.string().describe('Source account ID'),
51
- toAccountId: z.string().describe('Destination account ID'),
52
- amount: z.number().describe('Amount of HBAR to transfer'),
53
- memo: z.string().optional().describe('Optional transaction memo')
54
- });
55
-
56
- protected async _call(
57
- input: z.infer<typeof this.schema>
58
- ): Promise<string> {
59
- return JSON.stringify({
60
- success: true,
61
- transactionId: '0.0.123@1234567890.000000000',
62
- from: input.fromAccountId,
63
- to: input.toAccountId,
64
- amount: input.amount,
65
- memo: input.memo || '',
66
- message: `Mock transfer of ${input.amount} HBAR from ${input.fromAccountId} to ${input.toAccountId}`
67
- });
68
- }
69
- }
70
-
71
- /**
72
- * Test script to validate external tool wrapper functionality with hedera-agent-kit tools
73
- *
74
- * This test demonstrates that the external-tool-wrapper solution works successfully with
75
- * hedera-agent-kit tools by:
76
- *
77
- * 1. Creating mock tools that simulate hedera-agent-kit tool structure
78
- * 2. Wrapping them with render configurations using wrapExternalToolWithRenderConfig
79
- * 3. Integrating wrapped tools with FormValidatingToolWrapper
80
- * 4. Verifying form generation works with missing fields
81
- * 5. Testing batch wrapping with predefined configurations
82
- * 6. Confirming TypeScript type safety is maintained
83
- * 7. Validating tool delegation functionality is preserved
84
- *
85
- * Expected Output:
86
- * ✅ External tool wrapping with render configs works
87
- * ✅ Integration with FormValidatingToolWrapper works
88
- * ✅ Form generation for missing fields works
89
- * ✅ Batch wrapping with predefined configs works
90
- * ✅ TypeScript type safety maintained
91
- * ✅ Tool delegation functionality preserved
92
- *
93
- * Acceptance Criteria Met:
94
- * - Test runs successfully ✅
95
- * - Uses realistic hedera-agent-kit tool structure ✅
96
- * - Demonstrates external tool wrapping works ✅
97
- * - No TypeScript errors or linting violations ✅
98
- * - Shows form generation integration ✅
99
- * - Validates render config enhancement ✅
100
- */
101
- async function testHederaKitWrapper(): Promise<void> {
102
- const logger = new Logger({ module: 'TestHederaKitWrapper' });
103
-
104
- try {
105
- logger.info('🚀 Starting Hedera Agent Kit external tool wrapper test');
106
-
107
- const originalTool = new MockHederaGetAccountInfoTool();
108
- const transferTool = new MockHederaTransferHbarTool();
109
- logger.info(`📋 Testing with tool: ${originalTool.name}`);
110
- logger.info(`📝 Original tool description: ${originalTool.description}`);
111
-
112
- logger.info('\n🔧 Test 1: Wrapping external tool with render configs');
113
-
114
- const wrappedTool = wrapExternalToolWithRenderConfig(originalTool, {
115
- ui: {
116
- label: 'Enhanced Account Info Tool',
117
- description: 'Get comprehensive Hedera account information with enhanced UI'
118
- },
119
- fieldConfigs: {
120
- accountId: renderConfigs.accountId('Account ID'),
121
- includeBalances: renderConfigs.checkbox('Include Token Balances', 'Show all token balances for the account'),
122
- includeTransactions: renderConfigs.checkbox('Include Recent Transactions', 'Show recent transaction history')
123
- }
124
- });
125
-
126
- logger.info(`✅ Wrapped tool name: ${wrappedTool.name}`);
127
- logger.info(`✅ Wrapped tool description: ${wrappedTool.description}`);
128
- logger.info(`✅ Wrapped tool type: ${wrappedTool.constructor.name}`);
129
-
130
- const enhancedSchema = wrappedTool.schema;
131
- const hasRenderConfig = !!((enhancedSchema as unknown as { _renderConfig?: unknown })._renderConfig);
132
- logger.info(`✅ Has tool-level render config: ${hasRenderConfig}`);
133
-
134
- logger.info('\n🔧 Test 2: Integration with FormValidatingToolWrapper');
135
-
136
- const formGenerator = new FormGenerator();
137
- const formValidatingTool = wrapToolWithFormValidation(
138
- wrappedTool,
139
- formGenerator,
140
- {
141
- requireAllFields: true,
142
- skipFields: ['includeTransactions'] // Make this field optional
143
- }
144
- );
145
-
146
- logger.info(`✅ Form validating tool created: ${formValidatingTool.name}`);
147
- logger.info(`✅ Form validating tool type: ${formValidatingTool.constructor.name}`);
148
-
149
- logger.info('\n🔧 Test 3: Testing form generation with incomplete input');
150
-
151
- const incompleteInput = {
152
-
153
- includeBalances: true
154
- };
155
-
156
- try {
157
- const result = await (formValidatingTool as any)._call(incompleteInput as z.infer<typeof originalTool.schema>);
158
- const parsedResult = JSON.parse(result);
159
-
160
- if (parsedResult.requiresForm) {
161
- logger.info('✅ Form generation triggered for incomplete input');
162
- logger.info(`✅ Form message type: ${parsedResult.formMessage?.type}`);
163
- logger.info(`✅ Form has fields: ${!!parsedResult.formMessage?.fields?.length}`);
164
- logger.info(`✅ Partial input preserved: ${!!parsedResult.formMessage?.partialInput}`);
165
- } else {
166
- logger.warn('⚠️ Form generation was not triggered as expected');
167
- }
168
- } catch (error) {
169
- logger.error('❌ Form generation test failed:', error);
170
- }
171
-
172
- logger.info('\n🔧 Test 4: Testing batch wrapping with predefined configs');
173
-
174
- const batchWrappedTools = [
175
- {
176
- tool: transferTool,
177
- config: hederaToolConfigs.hbarTransfer()
178
- }
179
- ].map(({ tool, config }) => wrapExternalToolWithRenderConfig(tool, config));
180
-
181
- logger.info(`✅ Batch wrapped ${batchWrappedTools.length} tools`);
182
- logger.info(`✅ Batch wrapped tool: ${batchWrappedTools[0].name}`);
183
-
184
- logger.info('\n🔧 Test 5: Testing TypeScript type safety');
185
-
186
- const typedWrapper: ExternalToolWrapper<z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny>> = wrappedTool;
187
- const typedFormWrapper: FormValidatingToolWrapper<z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny>> = formValidatingTool;
188
-
189
- logger.info('✅ TypeScript type safety verified');
190
- logger.info(`✅ External wrapper type: ${typedWrapper.constructor.name}`);
191
- logger.info(`✅ Form wrapper type: ${typedFormWrapper.constructor.name}`);
192
-
193
- logger.info('\n🔧 Test 6: Testing tool delegation');
194
-
195
- logger.info(`✅ Original tool callable: ${typeof (originalTool as any)._call === 'function'}`);
196
- logger.info(`✅ Wrapped tool callable: ${typeof (wrappedTool as any)._call === 'function'}`);
197
- logger.info(`✅ Form tool callable: ${typeof (formValidatingTool as any)._call === 'function'}`);
198
-
199
- logger.info('\n🎉 All external tool wrapper tests completed successfully!');
200
-
201
- logger.info('\n📊 Test Summary:');
202
- logger.info('✅ External tool wrapping with render configs works');
203
- logger.info('✅ Integration with FormValidatingToolWrapper works');
204
- logger.info('✅ Form generation for missing fields works');
205
- logger.info('✅ Batch wrapping with predefined configs works');
206
- logger.info('✅ TypeScript type safety maintained');
207
- logger.info('✅ Tool delegation functionality preserved');
208
- logger.info('\n🔧 The external tool wrapper successfully enhances hedera-agent-kit tools!');
209
-
210
- } catch (error) {
211
- logger.error('❌ Test failed:', error);
212
- if (error instanceof Error) {
213
- logger.error('Error message:', error.message);
214
- logger.error('Error stack:', error.stack);
215
- }
216
- process.exit(1);
217
- }
218
- }
219
-
220
- /**
221
- * Demonstrate specific render config scenarios
222
- */
223
- function demonstrateRenderConfigs(): void {
224
- const logger = new Logger({ module: 'RenderConfigDemo' });
225
-
226
- logger.info('\n🎨 Demonstrating available render configurations:');
227
-
228
- logger.info('\n👤 Account Configurations:');
229
- const accountConfig = renderConfigs.accountId('Target Account');
230
- logger.info(`- Account ID: ${JSON.stringify(accountConfig, null, 2)}`);
231
-
232
- logger.info('\n💰 Currency Configurations:');
233
- const currencyConfig = renderConfigs.currency('Transfer Amount', 'HBAR', 0.00000001, 1000);
234
- logger.info(`- Currency: ${JSON.stringify(currencyConfig, null, 2)}`);
235
-
236
- logger.info('\n🪙 Token Configurations:');
237
- const tokenConfig = renderConfigs.tokenId('Token to Transfer');
238
- logger.info(`- Token ID: ${JSON.stringify(tokenConfig, null, 2)}`);
239
-
240
- logger.info('\n📝 Form Control Configurations:');
241
- const textConfig = renderConfigs.text('Transaction Memo', 'Enter memo', 'Optional transaction memo');
242
- const selectConfig = renderConfigs.select('Network', [
243
- { value: 'mainnet', label: 'Mainnet' },
244
- { value: 'testnet', label: 'Testnet' },
245
- { value: 'previewnet', label: 'Previewnet' }
246
- ]);
247
- logger.info(`- Text: ${JSON.stringify(textConfig, null, 2)}`);
248
- logger.info(`- Select: ${JSON.stringify(selectConfig, null, 2)}`);
249
-
250
- logger.info('\n✨ These configurations enhance hedera-agent-kit tools with rich UI metadata!');
251
- }
252
-
253
- if (import.meta.url === `file://${process.argv[1]}`) {
254
- testHederaKitWrapper()
255
- .then(() => {
256
- demonstrateRenderConfigs();
257
- process.exit(0);
258
- })
259
- .catch((error) => {
260
- console.error('Test execution failed:', error);
261
- process.exit(1);
262
- });
263
- }
264
-
265
- export { testHederaKitWrapper, demonstrateRenderConfigs };
@@ -1,128 +0,0 @@
1
- import { ChatOpenAI } from '@langchain/openai';
2
- import type { EntityAssociation } from '../memory/SmartMemoryManager';
3
-
4
- export interface EntityResolverConfig {
5
- apiKey: string;
6
- modelName?: string;
7
- }
8
-
9
- /**
10
- * LLM-based entity resolver that replaces brittle regex patterns
11
- */
12
- export class EntityResolver {
13
- private llm: ChatOpenAI;
14
-
15
- constructor(config: EntityResolverConfig) {
16
- this.llm = new ChatOpenAI({
17
- apiKey: config.apiKey,
18
- modelName: config.modelName || 'gpt-4o-mini',
19
- temperature: 0,
20
- });
21
- }
22
-
23
- /**
24
- * Resolve entity references using LLM instead of regex
25
- */
26
- async resolveReferences(
27
- message: string,
28
- entities: EntityAssociation[]
29
- ): Promise<string> {
30
- if (!entities || entities.length === 0) {
31
- return message;
32
- }
33
-
34
- const byType = entities.reduce((acc, e) => {
35
- if (!acc[e.entityType]) acc[e.entityType] = [];
36
- acc[e.entityType].push(e);
37
- return acc;
38
- }, {} as Record<string, EntityAssociation[]>);
39
-
40
- let context = 'Available entities in memory:\n';
41
- for (const [type, list] of Object.entries(byType)) {
42
- const recent = list[0];
43
- context += `Most recent ${type}: "${recent.entityName}" = ${recent.entityId}\n`;
44
- if (list.length > 1) {
45
- context += ` (${list.length - 1} other ${type}s in memory)\n`;
46
- }
47
- }
48
-
49
- const prompt = `Task: Replace entity references with their IDs from memory.
50
-
51
- ${context}
52
-
53
- User message: "${message}"
54
-
55
- Instructions:
56
- - If the user says "the topic" or "that topic" → replace with the most recent topic ID
57
- - If the user says "the token" or "that token" → replace with the most recent token ID
58
- - If the user says "it" or "that" after an action verb → replace with the most recent entity ID
59
- - Examples:
60
- * "submit on the topic" → "submit on 0.0.6543472"
61
- * "airdrop the token" → "airdrop 0.0.123456"
62
- * "send a message to it" → "send a message to 0.0.6543472"
63
-
64
- Return ONLY the message with replacements made. Do not add any explanations.
65
- Resolved message:`;
66
-
67
- try {
68
- const response = await this.llm.invoke(prompt);
69
- const resolved = (response.content as string).trim();
70
-
71
- if (resolved !== message && resolved.includes('0.0.')) {
72
- return resolved;
73
- }
74
-
75
- return message;
76
- } catch {
77
- return message;
78
- }
79
- }
80
-
81
- /**
82
- * Extract entities from agent response using LLM
83
- */
84
- async extractEntities(
85
- response: unknown,
86
- userMessage: string
87
- ): Promise<
88
- Array<{ id: string; name: string; type: string; transactionId?: string }>
89
- > {
90
- const text =
91
- typeof response === 'string' ? response : JSON.stringify(response);
92
-
93
- const prompt = `Analyze this agent response and extract ONLY newly created entities.
94
-
95
- User asked: "${userMessage.substring(0, 200)}"
96
-
97
- Agent response: ${text.substring(0, 3000)}
98
-
99
- Look for:
100
- 1. Success messages with entity IDs (e.g., "Successfully created topic 0.0.6543472")
101
- 2. Transaction confirmations that created new entities
102
- 3. Entity IDs that appear after words like "created", "new", "successfully"
103
-
104
- DO NOT include:
105
- - Account IDs that already existed (like sender/receiver accounts)
106
- - Entity IDs that were parameters to the operation
107
- - Failed operations
108
-
109
- Return a JSON array of newly created entities:
110
- [{"id": "0.0.XXX", "name": "descriptive_name", "type": "topic|token|account"}]
111
-
112
- If no entities were created, return: []
113
-
114
- JSON:`;
115
-
116
- try {
117
- const response = await this.llm.invoke(prompt);
118
- const content = response.content as string;
119
- const match = content.match(/\[[\s\S]*?\]/);
120
- if (match) {
121
- const entities = JSON.parse(match[0]);
122
- return entities;
123
- }
124
- } catch {
125
- }
126
- return [];
127
- }
128
- }