@hashgraphonline/conversational-agent 0.2.216 → 0.2.217

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (312) hide show
  1. package/cli/readme.md +181 -0
  2. package/dist/cjs/index.cjs +1 -1
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs/index.d.ts +1 -0
  5. package/dist/cjs/plugins/community/swarm/SwarmPlugin.d.ts +17 -0
  6. package/dist/cjs/plugins/community/swarm/__tests__/SwarmPlugin.mocks.d.ts +1 -0
  7. package/dist/cjs/plugins/community/swarm/__tests__/SwarmPlugin.test.d.ts +1 -0
  8. package/dist/cjs/plugins/community/swarm/__tests__/tools/CreatePostageStampTool.test.d.ts +1 -0
  9. package/dist/cjs/plugins/community/swarm/__tests__/tools/DownloadDataTool.test.d.ts +1 -0
  10. package/dist/cjs/plugins/community/swarm/__tests__/tools/DownloadFilesTool.test.d.ts +1 -0
  11. package/dist/cjs/plugins/community/swarm/__tests__/tools/ExtendPostageStampTool.test.d.ts +1 -0
  12. package/dist/cjs/plugins/community/swarm/__tests__/tools/GetPostageStampTool.test.d.ts +1 -0
  13. package/dist/cjs/plugins/community/swarm/__tests__/tools/ListPostageStampsTool.test.d.ts +1 -0
  14. package/dist/cjs/plugins/community/swarm/__tests__/tools/QueryUploadProgressTool.test.d.ts +1 -0
  15. package/dist/cjs/plugins/community/swarm/__tests__/tools/ReadFeedTool.test.d.ts +1 -0
  16. package/dist/cjs/plugins/community/swarm/__tests__/tools/SwarmTool.mocks.d.ts +14 -0
  17. package/dist/cjs/plugins/community/swarm/__tests__/tools/UpdateFeedTool.test.d.ts +1 -0
  18. package/dist/cjs/plugins/community/swarm/__tests__/tools/UploadDataTool.test.d.ts +1 -0
  19. package/dist/cjs/plugins/community/swarm/__tests__/tools/UploadFileTool.test.d.ts +1 -0
  20. package/dist/cjs/plugins/community/swarm/__tests__/tools/UploadFolderTool.test.d.ts +1 -0
  21. package/dist/cjs/plugins/community/swarm/config.d.ts +6 -0
  22. package/dist/cjs/plugins/community/swarm/constants.d.ts +8 -0
  23. package/dist/cjs/plugins/community/swarm/index.d.ts +2 -0
  24. package/dist/cjs/plugins/community/swarm/model.d.ts +23 -0
  25. package/dist/cjs/plugins/community/swarm/tools/CreatePostageStampTool.d.ts +47 -0
  26. package/dist/cjs/plugins/community/swarm/tools/DownloadDataTool.d.ts +35 -0
  27. package/dist/cjs/plugins/community/swarm/tools/DownloadFilesTool.d.ts +41 -0
  28. package/dist/cjs/plugins/community/swarm/tools/ExtendPostageStampTool.d.ts +47 -0
  29. package/dist/cjs/plugins/community/swarm/tools/GetPostageStampTool.d.ts +35 -0
  30. package/dist/cjs/plugins/community/swarm/tools/ListPostageStampsTool.d.ts +53 -0
  31. package/dist/cjs/plugins/community/swarm/tools/QueryUploadProgressTool.d.ts +35 -0
  32. package/dist/cjs/plugins/community/swarm/tools/ReadFeedTool.d.ts +41 -0
  33. package/dist/cjs/plugins/community/swarm/tools/UpdateFeedTool.d.ts +47 -0
  34. package/dist/cjs/plugins/community/swarm/tools/UploadDataTool.d.ts +47 -0
  35. package/dist/cjs/plugins/community/swarm/tools/UploadFileTool.d.ts +53 -0
  36. package/dist/cjs/plugins/community/swarm/tools/UploadFolderTool.d.ts +47 -0
  37. package/dist/cjs/plugins/community/swarm/utils.d.ts +22 -0
  38. package/dist/cjs/plugins/index.d.ts +1 -0
  39. package/dist/esm/index.js +33 -31
  40. package/dist/esm/index.js.map +1 -1
  41. package/dist/esm/index10.js +13 -677
  42. package/dist/esm/index10.js.map +1 -1
  43. package/dist/esm/index11.js +601 -234
  44. package/dist/esm/index11.js.map +1 -1
  45. package/dist/esm/index12.js +296 -136
  46. package/dist/esm/index12.js.map +1 -1
  47. package/dist/esm/index13.js +127 -235
  48. package/dist/esm/index13.js.map +1 -1
  49. package/dist/esm/index14.js +247 -84
  50. package/dist/esm/index14.js.map +1 -1
  51. package/dist/esm/index15.js +81 -159
  52. package/dist/esm/index15.js.map +1 -1
  53. package/dist/esm/index16.js +155 -229
  54. package/dist/esm/index16.js.map +1 -1
  55. package/dist/esm/index17.js +238 -140
  56. package/dist/esm/index17.js.map +1 -1
  57. package/dist/esm/index18.js +139 -493
  58. package/dist/esm/index18.js.map +1 -1
  59. package/dist/esm/index19.js +479 -91
  60. package/dist/esm/index19.js.map +1 -1
  61. package/dist/esm/index20.js +88 -147
  62. package/dist/esm/index20.js.map +1 -1
  63. package/dist/esm/index21.js +127 -666
  64. package/dist/esm/index21.js.map +1 -1
  65. package/dist/esm/index22.js +698 -44
  66. package/dist/esm/index22.js.map +1 -1
  67. package/dist/esm/index23.js +45 -304
  68. package/dist/esm/index23.js.map +1 -1
  69. package/dist/esm/index24.js +303 -153
  70. package/dist/esm/index24.js.map +1 -1
  71. package/dist/esm/index25.js +150 -117
  72. package/dist/esm/index25.js.map +1 -1
  73. package/dist/esm/index26.js +154 -18
  74. package/dist/esm/index26.js.map +1 -1
  75. package/dist/esm/index27.js +18 -22
  76. package/dist/esm/index27.js.map +1 -1
  77. package/dist/esm/index28.js +15 -74
  78. package/dist/esm/index28.js.map +1 -1
  79. package/dist/esm/index29.js +70 -295
  80. package/dist/esm/index29.js.map +1 -1
  81. package/dist/esm/index30.js +279 -100
  82. package/dist/esm/index30.js.map +1 -1
  83. package/dist/esm/index31.js +86 -922
  84. package/dist/esm/index31.js.map +1 -1
  85. package/dist/esm/index32.js +904 -189
  86. package/dist/esm/index32.js.map +1 -1
  87. package/dist/esm/index33.js +185 -1169
  88. package/dist/esm/index33.js.map +1 -1
  89. package/dist/esm/index34.js +1218 -112
  90. package/dist/esm/index34.js.map +1 -1
  91. package/dist/esm/index35.js +111 -99
  92. package/dist/esm/index35.js.map +1 -1
  93. package/dist/esm/index36.js +113 -8
  94. package/dist/esm/index36.js.map +1 -1
  95. package/dist/esm/index37.js +8 -45
  96. package/dist/esm/index37.js.map +1 -1
  97. package/dist/esm/index38.js +41 -102
  98. package/dist/esm/index38.js.map +1 -1
  99. package/dist/esm/index39.js +96 -55
  100. package/dist/esm/index39.js.map +1 -1
  101. package/dist/esm/index4.js +1 -1
  102. package/dist/esm/index40.js +58 -71
  103. package/dist/esm/index40.js.map +1 -1
  104. package/dist/esm/index41.js +79 -21
  105. package/dist/esm/index41.js.map +1 -1
  106. package/dist/esm/index42.js +21 -5
  107. package/dist/esm/index42.js.map +1 -1
  108. package/dist/esm/index43.js +4 -11
  109. package/dist/esm/index43.js.map +1 -1
  110. package/dist/esm/index44.js +12 -322
  111. package/dist/esm/index44.js.map +1 -1
  112. package/dist/esm/index45.js +280 -142
  113. package/dist/esm/index45.js.map +1 -1
  114. package/dist/esm/index46.js +181 -24
  115. package/dist/esm/index46.js.map +1 -1
  116. package/dist/esm/index47.js +7 -95
  117. package/dist/esm/index47.js.map +1 -1
  118. package/dist/esm/index48.js +77 -7
  119. package/dist/esm/index48.js.map +1 -1
  120. package/dist/esm/index49.js +75 -0
  121. package/dist/esm/index49.js.map +1 -0
  122. package/dist/esm/index5.js +2 -2
  123. package/dist/esm/index50.js +57 -0
  124. package/dist/esm/index50.js.map +1 -0
  125. package/dist/esm/index51.js +103 -0
  126. package/dist/esm/index51.js.map +1 -0
  127. package/dist/esm/index52.js +79 -0
  128. package/dist/esm/index52.js.map +1 -0
  129. package/dist/esm/index53.js +75 -0
  130. package/dist/esm/index53.js.map +1 -0
  131. package/dist/esm/index54.js +124 -0
  132. package/dist/esm/index54.js.map +1 -0
  133. package/dist/esm/index55.js +58 -0
  134. package/dist/esm/index55.js.map +1 -0
  135. package/dist/esm/index56.js +83 -0
  136. package/dist/esm/index56.js.map +1 -0
  137. package/dist/esm/index57.js +100 -0
  138. package/dist/esm/index57.js.map +1 -0
  139. package/dist/esm/index58.js +118 -0
  140. package/dist/esm/index58.js.map +1 -0
  141. package/dist/esm/index59.js +108 -0
  142. package/dist/esm/index59.js.map +1 -0
  143. package/dist/esm/index6.js +132 -833
  144. package/dist/esm/index6.js.map +1 -1
  145. package/dist/esm/index60.js +30 -0
  146. package/dist/esm/index60.js.map +1 -0
  147. package/dist/esm/index61.js +98 -0
  148. package/dist/esm/index61.js.map +1 -0
  149. package/dist/esm/index62.js +131 -0
  150. package/dist/esm/index62.js.map +1 -0
  151. package/dist/esm/index63.js +19 -0
  152. package/dist/esm/index63.js.map +1 -0
  153. package/dist/esm/index7.js +826 -75
  154. package/dist/esm/index7.js.map +1 -1
  155. package/dist/esm/index8.js +91 -13
  156. package/dist/esm/index8.js.map +1 -1
  157. package/dist/esm/index9.js +13 -17
  158. package/dist/esm/index9.js.map +1 -1
  159. package/dist/types/index.d.ts +1 -0
  160. package/dist/types/plugins/community/swarm/SwarmPlugin.d.ts +17 -0
  161. package/dist/types/plugins/community/swarm/__tests__/SwarmPlugin.mocks.d.ts +1 -0
  162. package/dist/types/plugins/community/swarm/__tests__/SwarmPlugin.test.d.ts +1 -0
  163. package/dist/types/plugins/community/swarm/__tests__/tools/CreatePostageStampTool.test.d.ts +1 -0
  164. package/dist/types/plugins/community/swarm/__tests__/tools/DownloadDataTool.test.d.ts +1 -0
  165. package/dist/types/plugins/community/swarm/__tests__/tools/DownloadFilesTool.test.d.ts +1 -0
  166. package/dist/types/plugins/community/swarm/__tests__/tools/ExtendPostageStampTool.test.d.ts +1 -0
  167. package/dist/types/plugins/community/swarm/__tests__/tools/GetPostageStampTool.test.d.ts +1 -0
  168. package/dist/types/plugins/community/swarm/__tests__/tools/ListPostageStampsTool.test.d.ts +1 -0
  169. package/dist/types/plugins/community/swarm/__tests__/tools/QueryUploadProgressTool.test.d.ts +1 -0
  170. package/dist/types/plugins/community/swarm/__tests__/tools/ReadFeedTool.test.d.ts +1 -0
  171. package/dist/types/plugins/community/swarm/__tests__/tools/SwarmTool.mocks.d.ts +14 -0
  172. package/dist/types/plugins/community/swarm/__tests__/tools/UpdateFeedTool.test.d.ts +1 -0
  173. package/dist/types/plugins/community/swarm/__tests__/tools/UploadDataTool.test.d.ts +1 -0
  174. package/dist/types/plugins/community/swarm/__tests__/tools/UploadFileTool.test.d.ts +1 -0
  175. package/dist/types/plugins/community/swarm/__tests__/tools/UploadFolderTool.test.d.ts +1 -0
  176. package/dist/types/plugins/community/swarm/config.d.ts +6 -0
  177. package/dist/types/plugins/community/swarm/constants.d.ts +8 -0
  178. package/dist/types/plugins/community/swarm/index.d.ts +2 -0
  179. package/dist/types/plugins/community/swarm/model.d.ts +23 -0
  180. package/dist/types/plugins/community/swarm/tools/CreatePostageStampTool.d.ts +47 -0
  181. package/dist/types/plugins/community/swarm/tools/DownloadDataTool.d.ts +35 -0
  182. package/dist/types/plugins/community/swarm/tools/DownloadFilesTool.d.ts +41 -0
  183. package/dist/types/plugins/community/swarm/tools/ExtendPostageStampTool.d.ts +47 -0
  184. package/dist/types/plugins/community/swarm/tools/GetPostageStampTool.d.ts +35 -0
  185. package/dist/types/plugins/community/swarm/tools/ListPostageStampsTool.d.ts +53 -0
  186. package/dist/types/plugins/community/swarm/tools/QueryUploadProgressTool.d.ts +35 -0
  187. package/dist/types/plugins/community/swarm/tools/ReadFeedTool.d.ts +41 -0
  188. package/dist/types/plugins/community/swarm/tools/UpdateFeedTool.d.ts +47 -0
  189. package/dist/types/plugins/community/swarm/tools/UploadDataTool.d.ts +47 -0
  190. package/dist/types/plugins/community/swarm/tools/UploadFileTool.d.ts +53 -0
  191. package/dist/types/plugins/community/swarm/tools/UploadFolderTool.d.ts +47 -0
  192. package/dist/types/plugins/community/swarm/utils.d.ts +22 -0
  193. package/dist/types/plugins/index.d.ts +1 -0
  194. package/package.json +36 -26
  195. package/src/index.ts +1 -0
  196. package/src/plugins/community/swarm/README.md +279 -0
  197. package/src/plugins/community/swarm/SwarmPlugin.ts +178 -0
  198. package/src/plugins/community/swarm/__tests__/SwarmPlugin.mocks.ts +105 -0
  199. package/src/plugins/community/swarm/__tests__/SwarmPlugin.test.ts +93 -0
  200. package/src/plugins/community/swarm/__tests__/tools/CreatePostageStampTool.test.ts +152 -0
  201. package/src/plugins/community/swarm/__tests__/tools/DownloadDataTool.test.ts +93 -0
  202. package/src/plugins/community/swarm/__tests__/tools/DownloadFilesTool.test.ts +163 -0
  203. package/src/plugins/community/swarm/__tests__/tools/ExtendPostageStampTool.test.ts +132 -0
  204. package/src/plugins/community/swarm/__tests__/tools/GetPostageStampTool.test.ts +83 -0
  205. package/src/plugins/community/swarm/__tests__/tools/ListPostageStampsTool.test.ts +219 -0
  206. package/src/plugins/community/swarm/__tests__/tools/QueryUploadProgressTool.test.ts +169 -0
  207. package/src/plugins/community/swarm/__tests__/tools/ReadFeedTool.test.ts +133 -0
  208. package/src/plugins/community/swarm/__tests__/tools/SwarmTool.mocks.ts +67 -0
  209. package/src/plugins/community/swarm/__tests__/tools/UpdateFeedTool.test.ts +148 -0
  210. package/src/plugins/community/swarm/__tests__/tools/UploadDataTool.test.ts +125 -0
  211. package/src/plugins/community/swarm/__tests__/tools/UploadFileTool.test.ts +194 -0
  212. package/src/plugins/community/swarm/__tests__/tools/UploadFolderTool.test.ts +118 -0
  213. package/src/plugins/community/swarm/config.ts +6 -0
  214. package/src/plugins/community/swarm/constants.ts +12 -0
  215. package/src/plugins/community/swarm/index.ts +2 -0
  216. package/src/plugins/community/swarm/model.ts +23 -0
  217. package/src/plugins/community/swarm/tools/CreatePostageStampTool.ts +137 -0
  218. package/src/plugins/community/swarm/tools/DownloadDataTool.ts +79 -0
  219. package/src/plugins/community/swarm/tools/DownloadFilesTool.ts +155 -0
  220. package/src/plugins/community/swarm/tools/ExtendPostageStampTool.ts +112 -0
  221. package/src/plugins/community/swarm/tools/GetPostageStampTool.ts +92 -0
  222. package/src/plugins/community/swarm/tools/ListPostageStampsTool.ts +124 -0
  223. package/src/plugins/community/swarm/tools/QueryUploadProgressTool.ts +109 -0
  224. package/src/plugins/community/swarm/tools/ReadFeedTool.ts +110 -0
  225. package/src/plugins/community/swarm/tools/UpdateFeedTool.ts +149 -0
  226. package/src/plugins/community/swarm/tools/UploadDataTool.ts +109 -0
  227. package/src/plugins/community/swarm/tools/UploadFileTool.ts +163 -0
  228. package/src/plugins/community/swarm/tools/UploadFolderTool.ts +150 -0
  229. package/src/plugins/community/swarm/utils.ts +172 -0
  230. package/src/plugins/index.ts +1 -0
  231. package/cli/dist/CLIApp.d.ts +0 -11
  232. package/cli/dist/CLIApp.d.ts.map +0 -1
  233. package/cli/dist/CLIApp.js +0 -128
  234. package/cli/dist/CLIApp.js.map +0 -1
  235. package/cli/dist/LocalConversationalAgent.d.ts +0 -37
  236. package/cli/dist/LocalConversationalAgent.js +0 -58
  237. package/cli/dist/app.d.ts +0 -18
  238. package/cli/dist/app.d.ts.map +0 -1
  239. package/cli/dist/app.js +0 -14
  240. package/cli/dist/app.js.map +0 -1
  241. package/cli/dist/cli.d.ts +0 -3
  242. package/cli/dist/cli.d.ts.map +0 -1
  243. package/cli/dist/cli.js +0 -87
  244. package/cli/dist/cli.js.map +0 -1
  245. package/cli/dist/components/AppContainer.d.ts +0 -16
  246. package/cli/dist/components/AppContainer.js +0 -24
  247. package/cli/dist/components/AppScreens.d.ts +0 -2
  248. package/cli/dist/components/AppScreens.js +0 -259
  249. package/cli/dist/components/ChatScreen.d.ts +0 -21
  250. package/cli/dist/components/ChatScreen.d.ts.map +0 -1
  251. package/cli/dist/components/ChatScreen.js +0 -40
  252. package/cli/dist/components/ChatScreen.js.map +0 -1
  253. package/cli/dist/components/DebugLoadingScreen.d.ts +0 -5
  254. package/cli/dist/components/DebugLoadingScreen.js +0 -31
  255. package/cli/dist/components/LoadingScreen.d.ts +0 -3
  256. package/cli/dist/components/LoadingScreen.d.ts.map +0 -1
  257. package/cli/dist/components/LoadingScreen.js +0 -17
  258. package/cli/dist/components/LoadingScreen.js.map +0 -1
  259. package/cli/dist/components/LoadingScreenDebug.d.ts +0 -5
  260. package/cli/dist/components/LoadingScreenDebug.js +0 -27
  261. package/cli/dist/components/MCPConfigScreen.d.ts +0 -28
  262. package/cli/dist/components/MCPConfigScreen.d.ts.map +0 -1
  263. package/cli/dist/components/MCPConfigScreen.js +0 -186
  264. package/cli/dist/components/MCPConfigScreen.js.map +0 -1
  265. package/cli/dist/components/ScreenRouter.d.ts +0 -13
  266. package/cli/dist/components/ScreenRouter.d.ts.map +0 -1
  267. package/cli/dist/components/ScreenRouter.js +0 -23
  268. package/cli/dist/components/ScreenRouter.js.map +0 -1
  269. package/cli/dist/components/SetupScreen.d.ts +0 -16
  270. package/cli/dist/components/SetupScreen.d.ts.map +0 -1
  271. package/cli/dist/components/SetupScreen.js +0 -67
  272. package/cli/dist/components/SetupScreen.js.map +0 -1
  273. package/cli/dist/components/SingleLoadingScreen.d.ts +0 -5
  274. package/cli/dist/components/SingleLoadingScreen.js +0 -27
  275. package/cli/dist/components/StatusBadge.d.ts +0 -10
  276. package/cli/dist/components/StatusBadge.d.ts.map +0 -1
  277. package/cli/dist/components/StatusBadge.js +0 -24
  278. package/cli/dist/components/StatusBadge.js.map +0 -1
  279. package/cli/dist/components/TerminalWindow.d.ts +0 -9
  280. package/cli/dist/components/TerminalWindow.d.ts.map +0 -1
  281. package/cli/dist/components/TerminalWindow.js +0 -19
  282. package/cli/dist/components/TerminalWindow.js.map +0 -1
  283. package/cli/dist/components/WelcomeScreen.d.ts +0 -12
  284. package/cli/dist/components/WelcomeScreen.d.ts.map +0 -1
  285. package/cli/dist/components/WelcomeScreen.js +0 -47
  286. package/cli/dist/components/WelcomeScreen.js.map +0 -1
  287. package/cli/dist/context/AppContext.d.ts +0 -68
  288. package/cli/dist/context/AppContext.js +0 -363
  289. package/cli/dist/headless-runner.d.ts +0 -17
  290. package/cli/dist/headless-runner.d.ts.map +0 -1
  291. package/cli/dist/headless-runner.js +0 -128
  292. package/cli/dist/headless-runner.js.map +0 -1
  293. package/cli/dist/hooks/useInitializeAgent.d.ts +0 -19
  294. package/cli/dist/hooks/useInitializeAgent.d.ts.map +0 -1
  295. package/cli/dist/hooks/useInitializeAgent.js +0 -29
  296. package/cli/dist/hooks/useInitializeAgent.js.map +0 -1
  297. package/cli/dist/hooks/useStableState.d.ts +0 -38
  298. package/cli/dist/hooks/useStableState.d.ts.map +0 -1
  299. package/cli/dist/hooks/useStableState.js +0 -69
  300. package/cli/dist/hooks/useStableState.js.map +0 -1
  301. package/cli/dist/managers/AgentManager.d.ts +0 -58
  302. package/cli/dist/managers/AgentManager.d.ts.map +0 -1
  303. package/cli/dist/managers/AgentManager.js +0 -121
  304. package/cli/dist/managers/AgentManager.js.map +0 -1
  305. package/cli/dist/managers/ConfigManager.d.ts +0 -54
  306. package/cli/dist/managers/ConfigManager.d.ts.map +0 -1
  307. package/cli/dist/managers/ConfigManager.js +0 -188
  308. package/cli/dist/managers/ConfigManager.js.map +0 -1
  309. package/cli/dist/types.d.ts +0 -52
  310. package/cli/dist/types.d.ts.map +0 -1
  311. package/cli/dist/types.js +0 -34
  312. package/cli/dist/types.js.map +0 -1
@@ -1,512 +1,158 @@
1
- import { SystemMessage } from "@langchain/core/messages";
2
- import { Logger } from "@hashgraphonline/standards-sdk";
3
- import { MemoryWindow } from "./index20.js";
4
- import { ContentStorage } from "./index21.js";
5
- import { TokenCounter } from "./index19.js";
6
- const IS_ENTITY_ASSOCIATION_FLAG = '"isEntityAssociation":true';
7
- const _SmartMemoryManager = class _SmartMemoryManager {
8
- constructor(config = {}) {
9
- this.config = { ..._SmartMemoryManager.DEFAULT_CONFIG, ...config };
10
- this.logger = new Logger({ module: "SmartMemoryManager" });
11
- this.tokenCounter = new TokenCounter(this.config.modelName);
12
- this._contentStorage = new ContentStorage(this.config.storageLimit);
13
- this.memoryWindow = new MemoryWindow(
14
- this.config.maxTokens,
15
- this.config.reserveTokens,
16
- this.tokenCounter
17
- );
18
- }
19
- /**
20
- * Get the content storage instance for file/content reference operations
21
- * @returns ContentStorage instance
22
- */
23
- get contentStorage() {
24
- return this._contentStorage;
25
- }
26
- /**
27
- * Add a message to the active memory window
28
- * Automatically handles pruning and storage of displaced messages
29
- * @param message - Message to add
30
- */
31
- addMessage(message) {
32
- const result = this.memoryWindow.addMessage(message);
33
- if (result.prunedMessages.length > 0) {
34
- this._contentStorage.storeMessages(result.prunedMessages);
35
- }
36
- }
37
- /**
38
- * Get all active messages from the memory window
39
- * @returns Array of active messages in chronological order
40
- */
41
- getMessages() {
42
- return this.memoryWindow.getMessages();
43
- }
44
- /**
45
- * Clear active memory window
46
- * @param clearStorage - Whether to also clear the content storage (default: false)
47
- */
48
- clear(clearStorage = false) {
49
- this.memoryWindow.clear();
50
- if (clearStorage) {
51
- this._contentStorage.clear();
52
- }
53
- }
54
- /**
55
- * Set the system prompt for the memory window
56
- * @param systemPrompt - System prompt text
57
- */
58
- setSystemPrompt(systemPrompt) {
59
- this.memoryWindow.setSystemPrompt(systemPrompt);
60
- }
61
- /**
62
- * Get the current system prompt
63
- * @returns Current system prompt text
64
- */
65
- getSystemPrompt() {
66
- return this.memoryWindow.getSystemPrompt();
67
- }
68
- /**
69
- * Search through stored message history
70
- * @param query - Search term or pattern
71
- * @param options - Search configuration
72
- * @returns Array of matching messages from history
73
- */
74
- searchHistory(query, options = {}) {
75
- return this._contentStorage.searchMessages(query, options);
76
- }
77
- /**
78
- * Get recent messages from storage history
79
- * @param count - Number of recent messages to retrieve
80
- * @returns Array of recent messages from storage
81
- */
82
- getRecentHistory(count) {
83
- return this._contentStorage.getRecentMessages(count);
84
- }
85
- /**
86
- * Check if a message can be added without exceeding limits
87
- * @param message - Message to test
88
- * @returns True if message can be added
89
- */
90
- canAddMessage(message) {
91
- return this.memoryWindow.canAddMessage(message);
92
- }
93
- /**
94
- * Get statistics about the active memory window
95
- * @returns Memory usage statistics
96
- */
97
- getMemoryStats() {
98
- const windowStats = this.memoryWindow.getStats();
99
- return {
100
- totalActiveMessages: windowStats.totalMessages,
101
- currentTokenCount: windowStats.currentTokens,
102
- maxTokens: windowStats.maxTokens,
103
- remainingCapacity: windowStats.remainingCapacity,
104
- systemPromptTokens: windowStats.systemPromptTokens,
105
- usagePercentage: windowStats.usagePercentage
106
- };
107
- }
108
- /**
109
- * Get statistics about the content storage
110
- * @returns Storage usage statistics
111
- */
112
- getStorageStats() {
113
- return this._contentStorage.getStorageStats();
114
- }
115
- /**
116
- * Get combined statistics for both active memory and storage
117
- * @returns Combined memory and storage statistics
118
- */
119
- getOverallStats() {
120
- const memoryStats = this.getMemoryStats();
121
- const storageStats = this.getStorageStats();
122
- return {
123
- activeMemory: memoryStats,
124
- storage: storageStats,
125
- totalMessagesManaged: memoryStats.totalActiveMessages + storageStats.totalMessages,
126
- activeMemoryUtilization: memoryStats.usagePercentage,
127
- storageUtilization: storageStats.usagePercentage
128
- };
129
- }
130
- /**
131
- * Update the configuration and apply changes
132
- * @param newConfig - New configuration options
133
- */
134
- updateConfig(newConfig) {
135
- this.config = { ...this.config, ...newConfig };
136
- if (newConfig.maxTokens !== void 0 || newConfig.reserveTokens !== void 0) {
137
- this.memoryWindow.updateLimits(
138
- this.config.maxTokens,
139
- this.config.reserveTokens
140
- );
141
- }
142
- if (newConfig.storageLimit !== void 0) {
143
- this._contentStorage.updateStorageLimit(this.config.storageLimit);
144
- }
145
- }
146
- /**
147
- * Get current configuration
148
- * @returns Current configuration settings
149
- */
150
- getConfig() {
151
- return { ...this.config };
152
- }
153
- /**
154
- * Get messages from storage within a time range
155
- * @param startTime - Start of time range
156
- * @param endTime - End of time range
157
- * @returns Messages within the specified time range
158
- */
159
- getHistoryFromTimeRange(startTime, endTime) {
160
- return this._contentStorage.getMessagesFromTimeRange(startTime, endTime);
161
- }
162
- /**
163
- * Get messages from storage by message type
164
- * @param messageType - Type of messages to retrieve ('human', 'ai', 'system', etc.)
165
- * @param limit - Maximum number of messages to return
166
- * @returns Messages of the specified type
167
- */
168
- getHistoryByType(messageType, limit) {
169
- return this._contentStorage.getMessagesByType(messageType, limit);
170
- }
171
- /**
172
- * Get recent messages from storage within the last N minutes
173
- * @param minutes - Number of minutes to look back
174
- * @returns Messages from the last N minutes
175
- */
176
- getRecentHistoryByTime(minutes) {
177
- return this._contentStorage.getRecentMessagesByTime(minutes);
178
- }
179
- /**
180
- * Export the current state for persistence or analysis
181
- * @returns Serializable representation of memory state
182
- */
183
- exportState() {
184
- return {
185
- config: this.config,
186
- activeMessages: this.memoryWindow.getMessages().map((msg) => ({
187
- content: msg.content,
188
- type: msg._getType()
189
- })),
190
- systemPrompt: this.memoryWindow.getSystemPrompt(),
191
- memoryStats: this.getMemoryStats(),
192
- storageStats: this.getStorageStats(),
193
- storedMessages: this._contentStorage.exportMessages()
194
- };
195
- }
196
- /**
197
- * Get a summary of conversation context for external use
198
- * Useful for providing context to other systems or for logging
199
- * @param includeStoredContext - Whether to include recent stored messages
200
- * @returns Context summary object
201
- */
202
- getContextSummary(includeStoredContext = false) {
203
- const activeMessages = this.getMessages();
204
- const summary = {
205
- activeMessageCount: activeMessages.length,
206
- systemPrompt: this.getSystemPrompt(),
207
- recentMessages: activeMessages.slice(-5),
208
- memoryUtilization: this.getMemoryStats().usagePercentage,
209
- hasStoredHistory: this.getStorageStats().totalMessages > 0
210
- };
211
- if (includeStoredContext) {
212
- return {
213
- ...summary,
214
- recentStoredMessages: this.getRecentHistory(10),
215
- storageStats: this.getStorageStats()
216
- };
217
- }
218
- return summary;
219
- }
220
- /**
221
- * Perform maintenance operations
222
- * Optimizes storage and cleans up resources
223
- */
224
- performMaintenance() {
225
- }
226
- /**
227
- * Store an entity association for later resolution
228
- * @param entityId - The blockchain entity ID
229
- * @param entityName - User-provided or derived friendly name
230
- * @param entityType - Type of entity (token, account, topic, etc.)
231
- * @param transactionId - Optional transaction ID that created this entity
232
- */
233
- storeEntityAssociation(entityId, entityName, entityType, transactionId, sessionId) {
234
- try {
235
- if (!entityId || typeof entityId !== "string" || entityId.trim().length === 0) {
236
- return;
237
- }
238
- if (!entityName || typeof entityName !== "string" || entityName.trim().length === 0) {
239
- return;
240
- }
241
- if (!entityType || typeof entityType !== "string" || entityType.trim().length === 0) {
242
- return;
243
- }
244
- const sanitizedEntityId = entityId.trim();
245
- const sanitizedEntityName = entityName.trim().substring(0, 100);
246
- const sanitizedEntityType = this.normalizeEntityType(entityType);
247
- let usageHint = "";
248
- if (sanitizedEntityType === "tokenid") {
249
- usageHint = "Use this as tokenId for HTS operations";
250
- } else if (sanitizedEntityType === "topicid") {
251
- usageHint = "Can be used for HCS operations, HRLs for minting with the format hcs://1/<topicId>, etc.";
252
- } else if (sanitizedEntityType === "accountid") {
253
- usageHint = "Can be used for account based operations";
254
- }
255
- const association = {
256
- entityId: sanitizedEntityId,
257
- entityName: sanitizedEntityName,
258
- entityType: sanitizedEntityType,
259
- createdAt: /* @__PURE__ */ new Date(),
260
- isEntityAssociation: true,
261
- ...usageHint ? { usage: usageHint } : {},
262
- ...sanitizedEntityType === "topicId" ? { hrl: `hcs://1/${sanitizedEntityId}` } : {},
263
- ...transactionId !== void 0 && transactionId !== null && transactionId.trim() !== "" ? { transactionId: transactionId.trim() } : {},
264
- ...sessionId && sessionId.trim() !== "" ? { sessionId: sessionId.trim() } : {}
265
- };
266
- const content = JSON.stringify(association);
267
- const entityMessage = {
268
- _getType: () => "system",
269
- content,
270
- id: `entity_${sanitizedEntityId}_${Date.now()}`,
271
- name: "entity_association",
272
- additional_kwargs: {
273
- entityId: sanitizedEntityId,
274
- entityName: sanitizedEntityName,
275
- entityType: sanitizedEntityType,
276
- isEntityAssociation: true,
277
- ...sessionId && sessionId.trim() !== "" ? { sessionId: sessionId.trim() } : {}
278
- }
279
- };
1
+ import { DynamicStructuredTool } from "@langchain/core/tools";
2
+ import { z } from "zod";
3
+ import { shouldUseReference, ContentStoreService } from "@hashgraphonline/standards-sdk";
4
+ function convertMCPToolToLangChain(tool, mcpManager, serverConfig) {
5
+ const zodSchema = jsonSchemaToZod(tool.inputSchema);
6
+ const sanitizedName = `${tool.serverName}_${tool.name}`.replace(
7
+ /[^a-zA-Z0-9_]/g,
8
+ "_"
9
+ );
10
+ let description = tool.description || `MCP tool ${tool.name} from ${tool.serverName}`;
11
+ if (serverConfig?.toolDescriptions?.[tool.name]) {
12
+ description = `${description}
13
+
14
+ ${serverConfig.toolDescriptions[tool.name]}`;
15
+ }
16
+ if (serverConfig?.additionalContext) {
17
+ description = `${description}
18
+
19
+ Context: ${serverConfig.additionalContext}`;
20
+ }
21
+ return new DynamicStructuredTool({
22
+ name: sanitizedName,
23
+ description,
24
+ schema: zodSchema,
25
+ func: async (input) => {
280
26
  try {
281
- this.memoryWindow.addMessage(new SystemMessage(content));
282
- } catch {
283
- }
284
- this._contentStorage.storeMessages([entityMessage]);
285
- } catch (error) {
286
- this.logger.error("Failed to store entity association", {
287
- entityId,
288
- entityName,
289
- entityType,
290
- error: error instanceof Error ? error.message : String(error)
291
- });
292
- }
293
- }
294
- /**
295
- * Normalize various type aliases to canonical EntityFormat strings using a registry.
296
- */
297
- normalizeEntityType(input) {
298
- const raw = (input || "").trim();
299
- if (raw.length === 0) {
300
- return "";
301
- }
302
- const key = raw.replace(/[^a-z]/gi, "").toLowerCase();
303
- const REGISTRY = {
304
- topic: "topicId",
305
- topicid: "topicId",
306
- token: "tokenId",
307
- tokenid: "tokenId",
308
- account: "accountId",
309
- accountid: "accountId",
310
- contract: "contractId",
311
- contractid: "contractId",
312
- file: "fileId",
313
- fileid: "fileId",
314
- schedule: "scheduleId",
315
- scheduleid: "scheduleId"
316
- };
317
- if (Object.prototype.hasOwnProperty.call(REGISTRY, key)) {
318
- return REGISTRY[key];
319
- }
320
- if (/^[a-z]+Id$/.test(raw)) {
321
- return raw;
322
- }
323
- return raw;
324
- }
325
- /**
326
- * Resolve entity references from natural language queries
327
- * @param query - Search query (entity name or natural language reference)
328
- * @param options - Resolution options for filtering and fuzzy matching
329
- * @returns Array of matching entity associations
330
- */
331
- resolveEntityReference(query, options = {}) {
332
- try {
333
- if (!query || typeof query !== "string") {
334
- return [];
335
- }
336
- const sanitizedQuery = query.trim();
337
- if (sanitizedQuery.length === 0) {
338
- return [];
339
- }
340
- if (sanitizedQuery.length > 200) {
341
- }
342
- const { entityType, limit = 10, fuzzyMatch = true } = options;
343
- const safeLimit = Math.max(1, Math.min(limit || 10, 100));
344
- const isEntityIdQuery = /^0\.0\.\d+$/.test(sanitizedQuery);
345
- const searchResults = this._contentStorage.searchMessages(
346
- sanitizedQuery.substring(0, 200),
347
- {
348
- caseSensitive: false,
349
- limit: safeLimit * 2
350
- }
351
- );
352
- const associations = [];
353
- for (const message of searchResults) {
354
- try {
355
- const content = message.content;
356
- if (content.includes(IS_ENTITY_ASSOCIATION_FLAG) || content.includes("entityId")) {
357
- const parsed = JSON.parse(content);
358
- if (parsed.entityId && parsed.entityName && parsed.entityType) {
359
- if (entityType && parsed.entityType !== entityType) {
360
- continue;
361
- }
362
- if (isEntityIdQuery) {
363
- if (parsed.entityId !== sanitizedQuery) {
364
- continue;
365
- }
366
- }
367
- associations.push(parsed);
368
- }
27
+ const result = await mcpManager.executeTool(
28
+ tool.serverName,
29
+ tool.name,
30
+ input
31
+ );
32
+ let responseText = "";
33
+ if (typeof result === "string") {
34
+ responseText = result;
35
+ } else if (result && typeof result === "object" && "content" in result) {
36
+ const content = result.content;
37
+ if (Array.isArray(content)) {
38
+ const textParts = content.filter(
39
+ (item) => typeof item === "object" && item !== null && "type" in item && item.type === "text" && "text" in item
40
+ ).map((item) => item.text);
41
+ responseText = textParts.join("\n");
42
+ } else {
43
+ responseText = JSON.stringify(content);
369
44
  }
370
- } catch {
371
- continue;
45
+ } else {
46
+ responseText = JSON.stringify(result);
372
47
  }
373
- }
374
- if (fuzzyMatch && associations.length === 0 && !isEntityIdQuery) {
375
- const fuzzyQueries = [
376
- query.toLowerCase(),
377
- `token`,
378
- `account`,
379
- entityType || ""
380
- ].filter(Boolean);
381
- for (const fuzzyQuery of fuzzyQueries) {
382
- if (fuzzyQuery === query.toLowerCase()) continue;
383
- const fuzzyResults = this._contentStorage.searchMessages(fuzzyQuery, {
384
- caseSensitive: false,
385
- limit
386
- });
387
- for (const message of fuzzyResults) {
48
+ const responseBuffer = Buffer.from(responseText, "utf8");
49
+ const MCP_REFERENCE_THRESHOLD = 10 * 1024;
50
+ const shouldStoreMCPContent = responseBuffer.length > MCP_REFERENCE_THRESHOLD;
51
+ if (shouldStoreMCPContent || shouldUseReference(responseBuffer)) {
52
+ const contentStore = ContentStoreService.getInstance();
53
+ if (contentStore) {
388
54
  try {
389
- const content = message.content;
390
- if (content.includes(IS_ENTITY_ASSOCIATION_FLAG)) {
391
- const parsed = JSON.parse(content);
392
- if (parsed.entityId && parsed.entityName && parsed.entityType) {
393
- if (entityType && parsed.entityType !== entityType) {
394
- continue;
395
- }
396
- associations.push(parsed);
55
+ const referenceId = await contentStore.storeContent(
56
+ responseBuffer,
57
+ {
58
+ contentType: "text",
59
+ source: "mcp",
60
+ mcpToolName: `${tool.serverName}_${tool.name}`,
61
+ originalSize: responseBuffer.length
397
62
  }
398
- }
63
+ );
64
+ return `content-ref:${referenceId}`;
399
65
  } catch {
400
- continue;
401
66
  }
402
67
  }
403
68
  }
69
+ return responseText;
70
+ } catch (error) {
71
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
72
+ return `Error executing MCP tool ${tool.name}: ${errorMessage}`;
404
73
  }
405
- const uniqueAssociations = associations.filter(
406
- (assoc, index, arr) => arr.findIndex((a) => a.entityId === assoc.entityId) === index
407
- ).sort(
408
- (a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
409
- );
410
- const results = uniqueAssociations.slice(0, safeLimit);
411
- return results;
412
- } catch (error) {
413
- this.logger.error("Failed to resolve entity reference", {
414
- query,
415
- options,
416
- error: error instanceof Error ? error.message : String(error)
417
- });
418
- return [];
419
74
  }
420
- }
421
- /**
422
- * Get all entity associations, optionally filtered by type
423
- * @param entityType - Optional filter by entity type
424
- * @returns Array of entity associations
425
- */
426
- getEntityAssociations(entityType) {
427
- try {
428
- const rawFilter = entityType ? entityType.trim() : void 0;
429
- const filterCanonical = rawFilter ? this.normalizeEntityType(rawFilter) : void 0;
430
- if (entityType && (!rawFilter || rawFilter.length === 0)) {
431
- return [];
75
+ });
76
+ }
77
+ function jsonSchemaToZod(schema) {
78
+ if (!schema || typeof schema !== "object") {
79
+ return z.object({});
80
+ }
81
+ const schemaObj = schema;
82
+ if (schemaObj.type && schemaObj.type !== "object") {
83
+ return convertType(schemaObj);
84
+ }
85
+ if (!schemaObj.properties || typeof schemaObj.properties !== "object") {
86
+ return z.object({});
87
+ }
88
+ const shape = {};
89
+ for (const [key, value] of Object.entries(schemaObj.properties)) {
90
+ let zodType = convertType(value);
91
+ const isRequired = Array.isArray(schemaObj.required) && schemaObj.required.includes(key);
92
+ if (!isRequired) {
93
+ zodType = zodType.optional();
94
+ }
95
+ shape[key] = zodType;
96
+ }
97
+ return z.object(shape);
98
+ }
99
+ function convertType(schema) {
100
+ if (!schema || typeof schema !== "object" || !("type" in schema)) {
101
+ return z.unknown();
102
+ }
103
+ const schemaObj = schema;
104
+ let zodType;
105
+ switch (schemaObj.type) {
106
+ case "string":
107
+ zodType = z.string();
108
+ if (schemaObj.enum && Array.isArray(schemaObj.enum)) {
109
+ zodType = z.enum(schemaObj.enum);
432
110
  }
433
- const SEARCH_ANY_ENTITY = "entityId";
434
- const searchQuery = filterCanonical || SEARCH_ANY_ENTITY;
435
- const searchResults = this._contentStorage.searchMessages(searchQuery, {
436
- caseSensitive: false,
437
- limit: 100
438
- });
439
- const associations = [];
440
- for (const message of searchResults) {
441
- try {
442
- const content = message.content;
443
- if (content.includes(IS_ENTITY_ASSOCIATION_FLAG)) {
444
- const parsed = JSON.parse(content);
445
- if (parsed.entityId && parsed.entityName && parsed.entityType) {
446
- if (filterCanonical && parsed.entityType !== filterCanonical) {
447
- continue;
448
- }
449
- if (parsed.createdAt && typeof parsed.createdAt === "string") {
450
- parsed.createdAt = new Date(parsed.createdAt);
451
- }
452
- associations.push(parsed);
453
- }
454
- }
455
- } catch (parseError) {
456
- this.logger.warn("Failed to parse entity association from message", {
457
- messageContent: typeof message.content === "string" ? message.content.substring(0, 100) : "non-string",
458
- error: parseError instanceof Error ? parseError.message : String(parseError)
459
- });
460
- continue;
461
- }
111
+ break;
112
+ case "number":
113
+ zodType = z.number();
114
+ if ("minimum" in schemaObj && typeof schemaObj.minimum === "number") {
115
+ zodType = zodType.min(schemaObj.minimum);
462
116
  }
463
- const mergedById = /* @__PURE__ */ new Map();
464
- const getTime = (d) => d instanceof Date ? d.getTime() : new Date(d).getTime();
465
- for (const assoc of associations) {
466
- const existing = mergedById.get(assoc.entityId);
467
- if (!existing) {
468
- mergedById.set(assoc.entityId, assoc);
469
- continue;
470
- }
471
- const existingTime = getTime(existing.createdAt);
472
- const currentTime = getTime(assoc.createdAt);
473
- const preferCurrent = currentTime > existingTime || !!assoc.transactionId && !existing.transactionId;
474
- if (preferCurrent) {
475
- mergedById.set(assoc.entityId, {
476
- ...existing,
477
- ...assoc
478
- });
479
- }
117
+ if ("maximum" in schemaObj && typeof schemaObj.maximum === "number") {
118
+ zodType = zodType.max(schemaObj.maximum);
480
119
  }
481
- const results = Array.from(mergedById.values()).sort(
482
- (a, b) => getTime(b.createdAt) - getTime(a.createdAt)
483
- );
484
- return results;
485
- } catch (error) {
486
- this.logger.error("Failed to get entity associations", {
487
- entityType,
488
- error: error instanceof Error ? error.message : String(error)
489
- });
490
- return [];
491
- }
120
+ break;
121
+ case "integer":
122
+ zodType = z.number().int();
123
+ if ("minimum" in schemaObj && typeof schemaObj.minimum === "number") {
124
+ zodType = zodType.min(schemaObj.minimum);
125
+ }
126
+ if ("maximum" in schemaObj && typeof schemaObj.maximum === "number") {
127
+ zodType = zodType.max(schemaObj.maximum);
128
+ }
129
+ break;
130
+ case "boolean":
131
+ zodType = z.boolean();
132
+ break;
133
+ case "array":
134
+ if (schemaObj.items) {
135
+ zodType = z.array(convertType(schemaObj.items));
136
+ } else {
137
+ zodType = z.array(z.unknown());
138
+ }
139
+ break;
140
+ case "object":
141
+ if ("properties" in schemaObj) {
142
+ zodType = jsonSchemaToZod(schemaObj);
143
+ } else {
144
+ zodType = z.object({}).passthrough();
145
+ }
146
+ break;
147
+ default:
148
+ zodType = z.unknown();
492
149
  }
493
- /**
494
- * Clean up resources and dispose of components
495
- */
496
- dispose() {
497
- this.memoryWindow.dispose();
498
- this._contentStorage.dispose();
499
- this.tokenCounter.dispose();
150
+ if ("description" in schemaObj && typeof schemaObj.description === "string") {
151
+ zodType = zodType.describe(schemaObj.description);
500
152
  }
501
- };
502
- _SmartMemoryManager.DEFAULT_CONFIG = {
503
- maxTokens: 8e3,
504
- reserveTokens: 1e3,
505
- modelName: "gpt-4o",
506
- storageLimit: 1e3
507
- };
508
- let SmartMemoryManager = _SmartMemoryManager;
153
+ return zodType;
154
+ }
509
155
  export {
510
- SmartMemoryManager
156
+ convertMCPToolToLangChain
511
157
  };
512
158
  //# sourceMappingURL=index18.js.map