@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index50.js","sources":["../../src/plugins/community/swarm/tools/DownloadDataTool.ts"],"sourcesContent":["import { Bee } from \"@ethersphere/bee-js\";\r\nimport { z } from \"zod\";\r\nimport { errorHasStatus, getErrorMessage, getResponseWithStructuredContent, ToolResponse } from \"../utils\";\r\nimport { BaseHederaQueryTool, GenericPluginContext, HederaAgentKit } from \"hedera-agent-kit\";\r\nimport { SwarmConfig } from \"../config\";\r\nimport { BAD_REQUEST_STATUS } from \"../constants\";\r\n\r\nconst DownloadDataSchema = z.object({\r\n reference: z.string(),\r\n});\r\n\r\nexport class DownloadDataTool extends BaseHederaQueryTool<typeof DownloadDataSchema> {\r\n name = \"swarm-download-data\";\r\n description = `\r\n Downloads immutable data from a Swarm content address hash.\r\n reference: Swarm reference hash.\r\n `;\r\n namespace = \"swarm\";\r\n specificInputSchema = DownloadDataSchema;\r\n bee: Bee;\r\n config: SwarmConfig;\r\n \r\n constructor(params: {\r\n hederaKit: HederaAgentKit;\r\n config: SwarmConfig;\r\n logger?: GenericPluginContext['logger'];\r\n bee: Bee;\r\n }) {\r\n const { bee, config, ...rest } = params;\r\n super(rest);\r\n this.bee = bee;\r\n this.config = config;\r\n }\r\n\r\n protected async executeQuery(\r\n input: z.infer<typeof DownloadDataSchema>\r\n ): Promise<ToolResponse | string> {\r\n const { reference } = input;\r\n\r\n if (!reference) {\r\n this.logger.error(\r\n 'Missing required parameter: reference.'\r\n );\r\n\r\n throw new Error(\"Missing required parameter: reference.\");\r\n }\r\n\r\n const isRefNotSwarmHash =\r\n reference.length !== 64 && reference.length !== 66;\r\n\r\n if (isRefNotSwarmHash) {\r\n this.logger.error(\r\n 'Invalid Swarm content address hash value for reference.'\r\n );\r\n\r\n throw new Error(\"Invalid Swarm content address hash value for reference.\");\r\n }\r\n\r\n let data;\r\n try {\r\n data = await this.bee.downloadData(reference);\r\n } catch (error) {\r\n let errorMessage = 'Downloading data failed.';\r\n\r\n if (errorHasStatus(error, BAD_REQUEST_STATUS)) {\r\n errorMessage = getErrorMessage(error);\r\n }\r\n\r\n this.logger.error(errorMessage, error);\r\n throw new Error(errorMessage);\r\n }\r\n\r\n const textData = data.toUtf8();\r\n\r\n return getResponseWithStructuredContent({\r\n textData,\r\n });\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;AAOA,MAAM,qBAAqB,EAAE,OAAO;AAAA,EAClC,WAAW,EAAE,OAAA;AACf,CAAC;AAEM,MAAM,yBAAyB,oBAA+C;AAAA,EAWnF,YAAY,QAKT;AACD,UAAM,EAAE,KAAK,QAAQ,GAAG,SAAS;AACjC,UAAM,IAAI;AAjBZ,SAAA,OAAO;AACP,SAAA,cAAc;AAAA;AAAA;AAAA;AAId,SAAA,YAAY;AACZ,SAAA,sBAAsB;AAYpB,SAAK,MAAM;AACX,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAgB,aACZ,OAC8B;AAChC,UAAM,EAAE,cAAc;AAEtB,QAAI,CAAC,WAAW;AACd,WAAK,OAAO;AAAA,QACV;AAAA,MAAA;AAGF,YAAM,IAAI,MAAM,wCAAwC;AAAA,IAC1D;AAEA,UAAM,oBACJ,UAAU,WAAW,MAAM,UAAU,WAAW;AAElD,QAAI,mBAAmB;AACrB,WAAK,OAAO;AAAA,QACV;AAAA,MAAA;AAGF,YAAM,IAAI,MAAM,yDAAyD;AAAA,IAC3E;AAEA,QAAI;AACJ,QAAI;AACF,aAAO,MAAM,KAAK,IAAI,aAAa,SAAS;AAAA,IAC9C,SAAS,OAAO;AACd,UAAI,eAAe;AAEnB,UAAI,eAAe,OAAO,kBAAkB,GAAG;AAC7C,uBAAe,gBAAgB,KAAK;AAAA,MACtC;AAEA,WAAK,OAAO,MAAM,cAAc,KAAK;AACrC,YAAM,IAAI,MAAM,YAAY;AAAA,IAC9B;AAEA,UAAM,WAAW,KAAK,OAAA;AAEtB,WAAO,iCAAiC;AAAA,MACtC;AAAA,IAAA,CACD;AAAA,EACH;AACF;"}
@@ -0,0 +1,103 @@
1
+ import { BaseHederaQueryTool } from "hedera-agent-kit";
2
+ import { Size, Duration } from "@ethersphere/bee-js";
3
+ import { z } from "zod";
4
+ import { makeDate, runWithTimeout, errorHasStatus, getErrorMessage } from "./index62.js";
5
+ import { CALL_TIMEOUT, POSTAGE_CREATE_TIMEOUT_MESSAGE, GATEWAY_STAMP_ERROR_MESSAGE, NOT_FOUND_STATUS, BAD_REQUEST_STATUS } from "./index63.js";
6
+ const CreatePostageStampSchema = z.object({
7
+ size: z.number(),
8
+ duration: z.string(),
9
+ label: z.string().optional()
10
+ });
11
+ class CreatePostageStampTool extends BaseHederaQueryTool {
12
+ constructor(params) {
13
+ const { bee, config, ...rest } = params;
14
+ super(rest);
15
+ this.name = "swarm-create-postage-stamp";
16
+ this.description = `
17
+ Buy postage stamp based on size in megabytes and duration.
18
+ size: The storage size in MB (Megabytes). These other size units convert like this to MB: 1 byte = 0.000001 MB, 1 KB = 0.001 MB, 1GB= 1000MB.
19
+ duration: Duration for which the data should be stored. Time to live of the postage stamp, e.g. 1d - 1 day, 1w - 1 week, 1month - 1 month.
20
+ label: Sets label for the postage batch (omit if the user didn't ask for one). Do not set a label with with specific capacity values because they can get misleading.
21
+ `;
22
+ this.namespace = "swarm";
23
+ this.specificInputSchema = CreatePostageStampSchema;
24
+ this.bee = bee;
25
+ this.config = config;
26
+ }
27
+ async executeQuery(input) {
28
+ const { size, duration, label } = input;
29
+ if (!size) {
30
+ this.logger.error(
31
+ "Missing required parameter: size."
32
+ );
33
+ throw new Error("Missing required parameter: size.");
34
+ } else if (!duration) {
35
+ this.logger.error(
36
+ "Missing required parameter: duration."
37
+ );
38
+ throw new Error("Missing required parameter: duration.");
39
+ }
40
+ let durationMs;
41
+ try {
42
+ durationMs = makeDate(duration);
43
+ } catch (makeDateError) {
44
+ this.logger.error(
45
+ "Invalid parameter: duration."
46
+ );
47
+ throw new Error("Invalid parameter: duration.");
48
+ }
49
+ let buyStorageResponse;
50
+ try {
51
+ let options = {};
52
+ if (label !== void 0) {
53
+ options = {
54
+ label
55
+ };
56
+ }
57
+ const buyStoragePromise = this.bee.buyStorage(
58
+ Size.fromMegabytes(size),
59
+ Duration.fromMilliseconds(durationMs),
60
+ options
61
+ );
62
+ const [response, hasTimedOut] = await runWithTimeout(
63
+ buyStoragePromise,
64
+ CALL_TIMEOUT
65
+ );
66
+ if (hasTimedOut) {
67
+ return JSON.stringify({
68
+ content: [
69
+ {
70
+ type: "text",
71
+ text: POSTAGE_CREATE_TIMEOUT_MESSAGE
72
+ }
73
+ ]
74
+ });
75
+ }
76
+ buyStorageResponse = response;
77
+ } catch (error) {
78
+ let errorMessage = "Unable to buy storage.";
79
+ if (errorHasStatus(error, NOT_FOUND_STATUS)) {
80
+ errorMessage = GATEWAY_STAMP_ERROR_MESSAGE;
81
+ } else if (errorHasStatus(error, BAD_REQUEST_STATUS)) {
82
+ errorMessage = getErrorMessage(error);
83
+ }
84
+ this.logger.error(
85
+ errorMessage,
86
+ error
87
+ );
88
+ throw new Error(errorMessage);
89
+ }
90
+ return {
91
+ content: [
92
+ {
93
+ type: "text",
94
+ text: `Postage batch ID: ${buyStorageResponse.toHex()}`
95
+ }
96
+ ]
97
+ };
98
+ }
99
+ }
100
+ export {
101
+ CreatePostageStampTool
102
+ };
103
+ //# sourceMappingURL=index51.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index51.js","sources":["../../src/plugins/community/swarm/tools/CreatePostageStampTool.ts"],"sourcesContent":["import {\r\n BaseHederaQueryTool,\r\n HederaAgentKit,\r\n type GenericPluginContext,\r\n} from \"hedera-agent-kit\";\r\nimport { BatchId, Bee, Duration, Size } from \"@ethersphere/bee-js\";\r\nimport { z } from \"zod\";\r\nimport {\r\n errorHasStatus,\r\n getErrorMessage,\r\n makeDate,\r\n runWithTimeout,\r\n ToolResponse,\r\n} from \"../utils\";\r\nimport { BAD_REQUEST_STATUS, CALL_TIMEOUT, GATEWAY_STAMP_ERROR_MESSAGE, NOT_FOUND_STATUS, POSTAGE_CREATE_TIMEOUT_MESSAGE } from \"../constants\";\r\nimport { SwarmConfig } from \"../config\";\r\n\r\nconst CreatePostageStampSchema = z.object({\r\n size: z.number(),\r\n duration: z.string(),\r\n label: z.string().optional(),\r\n});\r\n\r\nexport class CreatePostageStampTool extends BaseHederaQueryTool<typeof CreatePostageStampSchema> {\r\n name = \"swarm-create-postage-stamp\";\r\n description = `\r\n Buy postage stamp based on size in megabytes and duration.\r\n size: The storage size in MB (Megabytes). These other size units convert like this to MB: 1 byte = 0.000001 MB, 1 KB = 0.001 MB, 1GB= 1000MB.\r\n duration: Duration for which the data should be stored. Time to live of the postage stamp, e.g. 1d - 1 day, 1w - 1 week, 1month - 1 month.\r\n label: Sets label for the postage batch (omit if the user didn't ask for one). Do not set a label with with specific capacity values because they can get misleading.\r\n `;\r\n namespace = \"swarm\";\r\n specificInputSchema = CreatePostageStampSchema;\r\n bee: Bee;\r\n config: SwarmConfig;\r\n \r\n constructor(params: {\r\n hederaKit: HederaAgentKit;\r\n config: SwarmConfig;\r\n logger?: GenericPluginContext['logger'];\r\n bee: Bee;\r\n }) {\r\n const { bee, config, ...rest } = params;\r\n super(rest);\r\n this.bee = bee;\r\n this.config = config;\r\n }\r\n \r\n protected async executeQuery(\r\n input: z.infer<typeof CreatePostageStampSchema>\r\n ): Promise<ToolResponse | string> {\r\n const { size, duration, label } = input;\r\n\r\n if (!size) {\r\n this.logger.error(\r\n 'Missing required parameter: size.'\r\n );\r\n \r\n throw new Error('Missing required parameter: size.');\r\n } else if (!duration) {\r\n this.logger.error(\r\n 'Missing required parameter: duration.'\r\n );\r\n \r\n throw new Error('Missing required parameter: duration.');\r\n }\r\n\r\n let durationMs;\r\n\r\n try {\r\n durationMs = makeDate(duration);\r\n } catch (makeDateError) {\r\n this.logger.error(\r\n 'Invalid parameter: duration.'\r\n );\r\n\r\n throw new Error('Invalid parameter: duration.');\r\n }\r\n\r\n let buyStorageResponse: BatchId;\r\n\r\n try {\r\n let options = {};\r\n if (label !== undefined) {\r\n options = {\r\n label\r\n };\r\n }\r\n const buyStoragePromise = this.bee.buyStorage(\r\n Size.fromMegabytes(size),\r\n Duration.fromMilliseconds(durationMs),\r\n options\r\n );\r\n const [response, hasTimedOut] = await runWithTimeout(\r\n buyStoragePromise,\r\n CALL_TIMEOUT\r\n );\r\n\r\n if (hasTimedOut) {\r\n return JSON.stringify({\r\n content: [\r\n {\r\n type: 'text',\r\n text: POSTAGE_CREATE_TIMEOUT_MESSAGE,\r\n },\r\n ],\r\n });\r\n }\r\n\r\n buyStorageResponse = response as BatchId;\r\n } catch (error) {\r\n let errorMessage = 'Unable to buy storage.';\r\n\r\n if (errorHasStatus(error, NOT_FOUND_STATUS)) {\r\n errorMessage = GATEWAY_STAMP_ERROR_MESSAGE;\r\n } else if (errorHasStatus(error, BAD_REQUEST_STATUS)) {\r\n errorMessage = getErrorMessage(error);\r\n }\r\n\r\n this.logger.error(\r\n errorMessage,\r\n error\r\n );\r\n\r\n throw new Error(errorMessage);\r\n }\r\n\r\n return {\r\n content: [\r\n {\r\n type: 'text',\r\n text: `Postage batch ID: ${buyStorageResponse.toHex()}`,\r\n },\r\n ],\r\n };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AACf,eAAO,KAAK,UAAU;AAAA,UACpB,SAAS;AAAA,YACP;AAAA,cACE,MAAM;AAAA,cACN,MAAM;AAAA,YAAA;AAAA,UACR;AAAA,QACF,CACD;AAAA,MACH;AAEA,2BAAqB;AAAA,IACvB,SAAS,OAAO;AACd,UAAI,eAAe;AAEnB,UAAI,eAAe,OAAO,gBAAgB,GAAG;AAC3C,uBAAe;AAAA,MACjB,WAAW,eAAe,OAAO,kBAAkB,GAAG;AACpD,uBAAe,gBAAgB,KAAK;AAAA,MACtC;AAEA,WAAK,OAAO;AAAA,QACV;AAAA,QACA;AAAA,MAAA;AAGF,YAAM,IAAI,MAAM,YAAY;AAAA,IAC9B;AAEA,WAAO;AAAA,MACL,SAAS;AAAA,QACP;AAAA,UACE,MAAM;AAAA,UACN,MAAM,qBAAqB,mBAAmB,MAAA,CAAO;AAAA,QAAA;AAAA,MACvD;AAAA,IACF;AAAA,EAEJ;AACF;"}
@@ -0,0 +1,79 @@
1
+ import { BaseHederaQueryTool } from "hedera-agent-kit";
2
+ import { Size, Duration } from "@ethersphere/bee-js";
3
+ import { z } from "zod";
4
+ import { makeDate, errorHasStatus, getErrorMessage, getResponseWithStructuredContent } from "./index62.js";
5
+ import { NOT_FOUND_STATUS, GATEWAY_STAMP_ERROR_MESSAGE, BAD_REQUEST_STATUS } from "./index63.js";
6
+ const ExtendPostageStampSchema = z.object({
7
+ postageBatchId: z.string(),
8
+ duration: z.string().optional(),
9
+ size: z.number().optional()
10
+ });
11
+ class ExtendPostageStampTool extends BaseHederaQueryTool {
12
+ constructor(params) {
13
+ const { bee, config, ...rest } = params;
14
+ super(rest);
15
+ this.name = "swarm-extend-postage-stamp";
16
+ this.description = `Increase the duration (relative to current duration) or size (in megabytes) of a postage stamp.
17
+ postageBatchId: The id of the batch for which extend is performed.
18
+ size: The storage size in MB (Megabytes). These other size units convert like this to MB: 1 byte = 0.000001 MB, 1 KB = 0.001 MB, 1GB= 1000MB.
19
+ duration: Duration for which the data should be stored. Time to live of the postage stamp, e.g. 1d - 1 day, 1w - 1 week, 1month - 1 month.
20
+ `;
21
+ this.namespace = "swarm";
22
+ this.specificInputSchema = ExtendPostageStampSchema;
23
+ this.bee = bee;
24
+ this.config = config;
25
+ }
26
+ async executeQuery(input) {
27
+ const { postageBatchId, duration, size } = input;
28
+ if (!postageBatchId) {
29
+ this.logger.error(
30
+ "Missing required parameter: postageBatchId."
31
+ );
32
+ throw new Error("Missing required parameter: postageBatchId.");
33
+ } else if (!duration && !size) {
34
+ this.logger.error(
35
+ "You need at least one parameter from duration and size."
36
+ );
37
+ throw new Error("You need at least one parameter from duration and size.");
38
+ }
39
+ const extendSize = !!size ? Size.fromMegabytes(size) : Size.fromBytes(1);
40
+ let extendDuration = Duration.ZERO;
41
+ try {
42
+ if (duration) {
43
+ extendDuration = Duration.fromMilliseconds(makeDate(duration));
44
+ }
45
+ } catch (makeDateError) {
46
+ this.logger.error(
47
+ "Invalid parameter: duration."
48
+ );
49
+ throw new Error("Invalid parameter: duration.");
50
+ }
51
+ let extendStorageResponse;
52
+ try {
53
+ extendStorageResponse = await this.bee.extendStorage(
54
+ postageBatchId,
55
+ extendSize,
56
+ extendDuration
57
+ );
58
+ } catch (error) {
59
+ let errorMessage = "Extend failed.";
60
+ if (errorHasStatus(error, NOT_FOUND_STATUS)) {
61
+ errorMessage = GATEWAY_STAMP_ERROR_MESSAGE;
62
+ } else if (errorHasStatus(error, BAD_REQUEST_STATUS)) {
63
+ errorMessage = getErrorMessage(error);
64
+ }
65
+ this.logger.error(
66
+ errorMessage,
67
+ error
68
+ );
69
+ throw new Error(errorMessage);
70
+ }
71
+ return getResponseWithStructuredContent({
72
+ postageBatchId: extendStorageResponse.toHex()
73
+ });
74
+ }
75
+ }
76
+ export {
77
+ ExtendPostageStampTool
78
+ };
79
+ //# sourceMappingURL=index52.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index52.js","sources":["../../src/plugins/community/swarm/tools/ExtendPostageStampTool.ts"],"sourcesContent":["import {\r\n BaseHederaQueryTool,\r\n HederaAgentKit,\r\n type GenericPluginContext,\r\n} from \"hedera-agent-kit\";\r\nimport { BatchId, Bee, Duration, Size } from \"@ethersphere/bee-js\";\r\nimport { z } from \"zod\";\r\nimport {\r\n errorHasStatus,\r\n getErrorMessage,\r\n getResponseWithStructuredContent,\r\n makeDate,\r\n ToolResponse,\r\n} from \"../utils\";\r\nimport { BAD_REQUEST_STATUS, GATEWAY_STAMP_ERROR_MESSAGE, NOT_FOUND_STATUS } from \"../constants\";\r\nimport { SwarmConfig } from \"../config\";\r\n\r\nconst ExtendPostageStampSchema = z.object({\r\n postageBatchId: z.string(),\r\n duration: z.string().optional(),\r\n size: z.number().optional(),\r\n});\r\n\r\nexport class ExtendPostageStampTool extends BaseHederaQueryTool<typeof ExtendPostageStampSchema> {\r\n name = \"swarm-extend-postage-stamp\";\r\n description = `Increase the duration (relative to current duration) or size (in megabytes) of a postage stamp.\r\n postageBatchId: The id of the batch for which extend is performed.\r\n size: The storage size in MB (Megabytes). These other size units convert like this to MB: 1 byte = 0.000001 MB, 1 KB = 0.001 MB, 1GB= 1000MB.\r\n duration: Duration for which the data should be stored. Time to live of the postage stamp, e.g. 1d - 1 day, 1w - 1 week, 1month - 1 month.\r\n `;\r\n namespace = \"swarm\";\r\n specificInputSchema = ExtendPostageStampSchema;\r\n bee: Bee;\r\n config: SwarmConfig;\r\n \r\n constructor(params: {\r\n hederaKit: HederaAgentKit;\r\n config: SwarmConfig;\r\n logger?: GenericPluginContext['logger'];\r\n bee: Bee;\r\n }) {\r\n const { bee, config, ...rest } = params;\r\n super(rest);\r\n this.bee = bee;\r\n this.config = config;\r\n }\r\n \r\n protected async executeQuery(\r\n input: z.infer<typeof ExtendPostageStampSchema>\r\n ): Promise<ToolResponse | string> {\r\n const { postageBatchId, duration, size } = input;\r\n\r\n if (!postageBatchId) {\r\n this.logger.error(\r\n 'Missing required parameter: postageBatchId.'\r\n );\r\n\r\n throw new Error('Missing required parameter: postageBatchId.');\r\n } else if (!duration && !size) {\r\n this.logger.error(\r\n 'You need at least one parameter from duration and size.'\r\n );\r\n\r\n throw new Error('You need at least one parameter from duration and size.');\r\n }\r\n\r\n // If size is missing, Size.fromBytes(1) will get smallest depth and not increase size.\r\n const extendSize = !!size ? Size.fromMegabytes(size) : Size.fromBytes(1); \r\n let extendDuration = Duration.ZERO;\r\n\r\n try {\r\n if (duration) {\r\n extendDuration = Duration.fromMilliseconds(makeDate(duration));\r\n }\r\n } catch (makeDateError) {\r\n this.logger.error(\r\n 'Invalid parameter: duration.'\r\n );\r\n\r\n throw new Error('Invalid parameter: duration.');\r\n }\r\n\r\n let extendStorageResponse;\r\n\r\n try {\r\n extendStorageResponse = await this.bee.extendStorage(\r\n postageBatchId,\r\n extendSize,\r\n extendDuration\r\n );\r\n } catch (error) {\r\n let errorMessage = 'Extend failed.';\r\n\r\n if (errorHasStatus(error, NOT_FOUND_STATUS)) {\r\n errorMessage = GATEWAY_STAMP_ERROR_MESSAGE;\r\n } else if (errorHasStatus(error, BAD_REQUEST_STATUS)) {\r\n errorMessage = getErrorMessage(error);\r\n }\r\n\r\n this.logger.error(\r\n errorMessage,\r\n error\r\n );\r\n\r\n throw new Error(errorMessage);\r\n }\r\n\r\n return getResponseWithStructuredContent({\r\n postageBatchId: extendStorageResponse.toHex(),\r\n });\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;;AAiBA,MAAM,2BAA2B,EAAE,OAAO;AAAA,EACxC,gBAAgB,EAAE,OAAA;AAAA,EAClB,UAAU,EAAE,OAAA,EAAS,SAAA;AAAA,EACrB,MAAM,EAAE,OAAA,EAAS,SAAA;AACnB,CAAC;AAEM,MAAM,+BAA+B,oBAAqD;AAAA,EAY/F,YAAY,QAKT;AACD,UAAM,EAAE,KAAK,QAAQ,GAAG,SAAS;AACjC,UAAM,IAAI;AAlBZ,SAAA,OAAO;AACP,SAAA,cAAc;AAAA;AAAA;AAAA;AAAA;AAKd,SAAA,YAAY;AACZ,SAAA,sB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} from "./index62.js";
4
+ import { GATEWAY_TAG_ERROR_MESSAGE } from "./index63.js";
5
+ const QueryUploadProgressSchema = z.object({
6
+ tagId: z.string()
7
+ });
8
+ class QueryUploadProgressTool extends BaseHederaQueryTool {
9
+ constructor(params) {
10
+ const { bee, config, ...rest } = params;
11
+ super(rest);
12
+ this.name = "swarm-query-upload-progress";
13
+ this.description = `Query upload progress for a specific upload session identified with the returned Tag ID.
14
+ tagId: Tag ID returned by swarm-upload-file and swarm-upload-folder tools to track upload progress.
15
+ `;
16
+ this.namespace = "swarm";
17
+ this.specificInputSchema = QueryUploadProgressSchema;
18
+ this.bee = bee;
19
+ this.config = config;
20
+ }
21
+ async executeQuery(input) {
22
+ if (!input?.tagId) {
23
+ this.logger.error(
24
+ "Missing required parameter: tagId."
25
+ );
26
+ throw new Error("Missing required parameter: tagId.");
27
+ }
28
+ const tagUid = Number.parseInt(input.tagId, 10);
29
+ if (Number.isNaN(tagUid)) {
30
+ this.logger.error(
31
+ "Invalid tagId format. Expected a numeric string."
32
+ );
33
+ throw new Error("Invalid tagId format. Expected a numeric string.");
34
+ }
35
+ try {
36
+ const tag = await this.bee.retrieveTag(tagUid);
37
+ const synced = tag.synced ?? 0;
38
+ const seen = tag.seen ?? 0;
39
+ const processed = synced + seen;
40
+ const total = tag.split ?? 0;
41
+ const startedAt = tag.startedAt;
42
+ const processedPercentage = total > 0 ? Math.round(processed / total * 100) : 0;
43
+ const isComplete = processedPercentage === 100;
44
+ let tagDeleted = false;
45
+ if (isComplete) {
46
+ try {
47
+ await this.bee.deleteTag(tagUid);
48
+ tagDeleted = true;
49
+ } catch {
50
+ }
51
+ }
52
+ return getResponseWithStructuredContent({
53
+ processedPercentage,
54
+ message: isComplete ? "Upload completed successfully." : `Upload progress: ${processedPercentage}% processed`,
55
+ startedAt,
56
+ tagAddress: tag.address
57
+ });
58
+ } catch (error) {
59
+ let errorMessage = `Failed to retrieve upload progress: ${error?.message ?? "Unknown error"}`;
60
+ const status = error?.status ?? error?.response?.status;
61
+ if (status === 404) {
62
+ errorMessage = `Tag with ID ${input.tagId} does not exist or has been deleted. ` + GATEWAY_TAG_ERROR_MESSAGE;
63
+ }
64
+ this.logger.error(
65
+ errorMessage,
66
+ error
67
+ );
68
+ throw new Error(errorMessage);
69
+ }
70
+ }
71
+ }
72
+ export {
73
+ QueryUploadProgressTool
74
+ };
75
+ //# sourceMappingURL=index53.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index53.js","sources":["../../src/plugins/community/swarm/tools/QueryUploadProgressTool.ts"],"sourcesContent":["import {\r\n type GenericPluginContext,\r\n BaseHederaQueryTool,\r\n type HederaAgentKit,\r\n} from \"hedera-agent-kit\";\r\nimport { Bee } from \"@ethersphere/bee-js\";\r\nimport { z } from \"zod\";\r\nimport {\r\n errorHasStatus,\r\n getResponseWithStructuredContent,\r\n ToolResponse,\r\n} from \"../utils\";\r\nimport { GATEWAY_TAG_ERROR_MESSAGE } from \"../constants\";\r\nimport { SwarmConfig } from \"../config\";\r\n\r\nconst QueryUploadProgressSchema = z.object({\r\n tagId: z.string(),\r\n});\r\n\r\nexport class QueryUploadProgressTool extends BaseHederaQueryTool<typeof QueryUploadProgressSchema> {\r\n name = \"swarm-query-upload-progress\";\r\n description = `Query upload progress for a specific upload session identified with the returned Tag ID.\r\n tagId: Tag ID returned by swarm-upload-file and swarm-upload-folder tools to track upload progress.\r\n `;\r\n namespace = \"swarm\";\r\n specificInputSchema = QueryUploadProgressSchema;\r\n bee: Bee;\r\n config: SwarmConfig;\r\n \r\n constructor(params: {\r\n hederaKit: HederaAgentKit;\r\n config: SwarmConfig;\r\n logger?: GenericPluginContext['logger'];\r\n bee: Bee;\r\n }) {\r\n const { bee, config, ...rest } = params;\r\n super(rest);\r\n this.bee = bee;\r\n this.config = config;\r\n }\r\n\r\n protected async executeQuery(\r\n input: z.infer<typeof QueryUploadProgressSchema>\r\n ): Promise<ToolResponse | string> {\r\n if (!input?.tagId) {\r\n this.logger.error(\r\n 'Missing required parameter: tagId.'\r\n );\r\n\r\n throw new Error('Missing required parameter: tagId.');\r\n }\r\n\r\n const tagUid = Number.parseInt(input.tagId, 10);\r\n if (Number.isNaN(tagUid)) {\r\n this.logger.error(\r\n 'Invalid tagId format. Expected a numeric string.'\r\n );\r\n\r\n throw new Error('Invalid tagId format. Expected a numeric string.');\r\n }\r\n\r\n try {\r\n const tag = await this.bee.retrieveTag(tagUid);\r\n\r\n const synced = tag.synced ?? 0;\r\n const seen = tag.seen ?? 0;\r\n const processed = synced + seen;\r\n const total = tag.split ?? 0;\r\n const startedAt = tag.startedAt;\r\n\r\n const processedPercentage =\r\n total > 0 ? Math.round((processed / total) * 100) : 0;\r\n const isComplete = processedPercentage === 100;\r\n\r\n let tagDeleted = false;\r\n if (isComplete) {\r\n try {\r\n await this.bee.deleteTag(tagUid);\r\n tagDeleted = true;\r\n } catch {\r\n // Non-fatal: if deletion fails we still return progress\r\n }\r\n }\r\n\r\n return getResponseWithStructuredContent({\r\n processedPercentage,\r\n message: isComplete\r\n ? \"Upload completed successfully.\"\r\n : `Upload progress: ${processedPercentage}% processed`,\r\n startedAt,\r\n tagAddress: tag.address,\r\n });\r\n } catch (error: any) {\r\n let errorMessage = `Failed to retrieve upload progress: ${error?.message ?? \"Unknown error\"}`;\r\n \r\n const status = error?.status ?? error?.response?.status;\r\n if (status === 404) {\r\n errorMessage = `Tag with ID ${input.tagId} does not exist or has been deleted. ` + GATEWAY_TAG_ERROR_MESSAGE;\r\n }\r\n \r\n this.logger.error(\r\n errorMessage,\r\n error\r\n );\r\n \r\n throw new Error(errorMessage);\r\n }\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;AAeA,MAAM,4BAA4B,EAAE,OAAO;AAAA,EACzC,OAAO,EAAE,OAAA;AACX,CAAC;AAEM,MAAM,gCAAgC,oBAAsD;AAAA,EAUjG,YAAY,QAKT;AACD,UAAM,EAAE,KAAK,QAAQ,GAAG,SAAS;AACjC,UAAM,IAAI;AAhBZ,SAAA,OAA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;AAAA,MAAA;AAGF,YAAM,IAAI,MAAM,YAAY;AAAA,IAC9B;AAAA,EACF;AACF;"}
@@ -0,0 +1,124 @@
1
+ import { MantarayNode } from "@ethersphere/bee-js";
2
+ import { z } from "zod";
3
+ import fs from "fs";
4
+ import path from "path";
5
+ import { BaseHederaQueryTool } from "hedera-agent-kit";
6
+ import { promisify } from "util";
7
+ const DownloadFilesSchema = z.object({
8
+ reference: z.string(),
9
+ filePath: z.string().optional()
10
+ });
11
+ class DownloadFilesTool extends BaseHederaQueryTool {
12
+ constructor(params) {
13
+ const { bee, config, ...rest } = params;
14
+ super(rest);
15
+ this.name = "swarm-download-files";
16
+ this.description = `Download folder, files from a Swarm reference and save to file path or return file list of the reference.
17
+ Prioritizes this tool over swarm-download-data if there is no assumption about the data type.
18
+ reference: Swarm reference hash.
19
+ filePath: Optional file path to save the downloaded content (only available in stdio mode). If not provided list of files in the manifest will be returned.
20
+ `;
21
+ this.namespace = "swarm";
22
+ this.specificInputSchema = DownloadFilesSchema;
23
+ this.bee = bee;
24
+ this.config = config;
25
+ }
26
+ async executeQuery(input) {
27
+ const { reference, filePath } = input;
28
+ if (!reference) {
29
+ this.logger.error(
30
+ "Missing required parameter: reference."
31
+ );
32
+ throw new Error("Missing required parameter: reference.");
33
+ }
34
+ this.logger.info(`[API] Downloading folder from Swarm with reference: ${reference}.`);
35
+ let isManifest = false;
36
+ let node;
37
+ try {
38
+ node = await MantarayNode.unmarshal(this.bee, reference);
39
+ await node.loadRecursively(this.bee);
40
+ isManifest = true;
41
+ } catch (error) {
42
+ }
43
+ if (isManifest) {
44
+ if (filePath) {
45
+ const destinationFolder = filePath;
46
+ if (!fs.existsSync(destinationFolder)) {
47
+ await promisify(fs.mkdir)(destinationFolder, { recursive: true });
48
+ }
49
+ const nodes = node.collect();
50
+ if (nodes.length === 1) {
51
+ const node2 = nodes[0];
52
+ const data = await this.bee.downloadData(node2.targetAddress);
53
+ await promisify(fs.writeFile)(
54
+ path.join(
55
+ destinationFolder,
56
+ node2.fullPathString.split("\\").slice(-1)[0]
57
+ ),
58
+ data.toUint8Array()
59
+ );
60
+ } else {
61
+ for (const node2 of nodes) {
62
+ const parsedPath = path.parse(node2.fullPathString);
63
+ const nodeDestFolder = path.join(destinationFolder, parsedPath.dir);
64
+ if (!fs.existsSync(nodeDestFolder)) {
65
+ await promisify(fs.mkdir)(nodeDestFolder, { recursive: true });
66
+ }
67
+ const data = await this.bee.downloadData(node2.targetAddress);
68
+ await promisify(fs.writeFile)(
69
+ path.join(destinationFolder, node2.fullPathString),
70
+ data.toUint8Array()
71
+ );
72
+ }
73
+ }
74
+ return {
75
+ content: [
76
+ {
77
+ type: "text",
78
+ text: JSON.stringify(
79
+ {
80
+ reference,
81
+ manifestNodeCount: nodes.length,
82
+ savedTo: destinationFolder,
83
+ message: `Manifest content (${nodes.length} files) successfully downloaded to ${destinationFolder}`
84
+ },
85
+ null,
86
+ 2
87
+ )
88
+ }
89
+ ]
90
+ };
91
+ } else {
92
+ const nodes = node.collect();
93
+ const filesList = nodes.map((node2) => ({
94
+ path: node2.fullPathString || "/",
95
+ targetAddress: Array.from(node2.targetAddress).map((e) => e.toString(16).padStart(2, "0")).join(""),
96
+ metadata: node2.metadata
97
+ }));
98
+ return {
99
+ content: [
100
+ {
101
+ type: "text",
102
+ text: JSON.stringify(
103
+ {
104
+ reference,
105
+ type: "manifest",
106
+ files: filesList,
107
+ message: "This is a manifest with multiple files. Provide a filePath to download all files or download individual files using their specific references."
108
+ },
109
+ null,
110
+ 2
111
+ )
112
+ }
113
+ ]
114
+ };
115
+ }
116
+ } else {
117
+ return "Try swarm-download-data tool instead since the given reference is not a manifest.";
118
+ }
119
+ }
120
+ }
121
+ export {
122
+ DownloadFilesTool
123
+ };
124
+ //# sourceMappingURL=index54.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index54.js","sources":["../../src/plugins/community/swarm/tools/DownloadFilesTool.ts"],"sourcesContent":["import { Bee, MantarayNode } from \"@ethersphere/bee-js\";\r\nimport { z } from \"zod\";\r\nimport fs from \"fs\";\r\nimport path from \"path\";\r\nimport { BaseHederaQueryTool, GenericPluginContext, HederaAgentKit } from \"hedera-agent-kit\";\r\nimport { promisify } from \"util\";\r\nimport { ToolResponse } from \"../utils\";\r\nimport { SwarmConfig } from \"../config\";\r\n\r\nconst DownloadFilesSchema = z.object({\r\n reference: z.string(),\r\n filePath: z.string().optional()\r\n});\r\n\r\nexport class DownloadFilesTool extends BaseHederaQueryTool<typeof DownloadFilesSchema> {\r\n name = \"swarm-download-files\";\r\n description = `Download folder, files from a Swarm reference and save to file path or return file list of the reference.\r\n Prioritizes this tool over swarm-download-data if there is no assumption about the data type.\r\n reference: Swarm reference hash.\r\n filePath: Optional file path to save the downloaded content (only available in stdio mode). If not provided list of files in the manifest will be returned.\r\n `;\r\n namespace = \"swarm\";\r\n specificInputSchema = DownloadFilesSchema;\r\n bee: Bee; \r\n config: SwarmConfig;\r\n\r\n constructor(params: {\r\n hederaKit: HederaAgentKit;\r\n config: SwarmConfig;\r\n logger?: GenericPluginContext['logger'];\r\n bee: Bee;\r\n }) {\r\n const { bee, config, ...rest } = params;\r\n super(rest);\r\n this.bee = bee;\r\n this.config = config;\r\n }\r\n\r\n protected async executeQuery(\r\n input: z.infer<typeof DownloadFilesSchema>\r\n ): Promise<ToolResponse | string> {\r\n const { reference, filePath } = input;\r\n \r\n if (!reference) {\r\n this.logger.error(\r\n 'Missing required parameter: reference.'\r\n );\r\n \r\n throw new Error(\"Missing required parameter: reference.\");\r\n }\r\n\r\n this.logger.info(`[API] Downloading folder from Swarm with reference: ${reference}.`);\r\n\r\n // Check if the reference is a manifest\r\n let isManifest = false;\r\n let node: MantarayNode;\r\n\r\n try {\r\n node = await MantarayNode.unmarshal(this.bee, reference);\r\n await node.loadRecursively(this.bee);\r\n isManifest = true;\r\n } catch (error) {\r\n // ignore\r\n }\r\n\r\n if (isManifest) {\r\n if (filePath) {\r\n const destinationFolder = filePath;\r\n\r\n if (!fs.existsSync(destinationFolder)) {\r\n await promisify(fs.mkdir)(destinationFolder, { recursive: true });\r\n }\r\n\r\n const nodes = node!.collect();\r\n\r\n if (nodes.length === 1) {\r\n const node = nodes[0];\r\n const data = await this.bee.downloadData(node.targetAddress);\r\n await promisify(fs.writeFile)(\r\n path.join(\r\n destinationFolder,\r\n node.fullPathString.split(\"\\\\\").slice(-1)[0]\r\n ),\r\n data.toUint8Array()\r\n );\r\n } else {\r\n // Download each node\r\n for (const node of nodes) {\r\n const parsedPath = path.parse(node.fullPathString);\r\n const nodeDestFolder = path.join(destinationFolder, parsedPath.dir);\r\n // Create subdirectories if necessary\r\n if (!fs.existsSync(nodeDestFolder)) {\r\n await promisify(fs.mkdir)(nodeDestFolder, { recursive: true });\r\n }\r\n\r\n const data = await this.bee.downloadData(node.targetAddress);\r\n await promisify(fs.writeFile)(\r\n path.join(destinationFolder, node.fullPathString),\r\n data.toUint8Array()\r\n );\r\n }\r\n }\r\n\r\n return {\r\n content: [\r\n {\r\n type: \"text\",\r\n text: JSON.stringify(\r\n {\r\n reference: reference,\r\n manifestNodeCount: nodes.length,\r\n savedTo: destinationFolder,\r\n message: `Manifest content (${nodes.length} files) successfully downloaded to ${destinationFolder}`,\r\n },\r\n null,\r\n 2\r\n ),\r\n },\r\n ],\r\n };\r\n } else {\r\n // regular file\r\n const nodes = node!.collect();\r\n const filesList = nodes.map((node) => ({\r\n path: node.fullPathString || \"/\",\r\n targetAddress: Array.from(node.targetAddress)\r\n .map((e) => e.toString(16).padStart(2, \"0\"))\r\n .join(\"\"),\r\n metadata: node.metadata,\r\n }));\r\n\r\n return {\r\n content: [\r\n {\r\n type: \"text\",\r\n text: JSON.stringify(\r\n {\r\n reference: reference,\r\n type: \"manifest\",\r\n files: filesList,\r\n message:\r\n \"This is a manifest with multiple files. Provide a filePath to download all files or download individual files using their specific references.\",\r\n },\r\n null,\r\n 2\r\n ),\r\n },\r\n ],\r\n };\r\n }\r\n } else {\r\n return \"Try swarm-download-data tool instead since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,cACN,MAAM,KAAK;AAAA,gBACT;AAAA,kBACE;AAAA,kBACA,MAAM;AAAA,kBACN,OAAO;AAAA,kBACP,SACE;AAAA,gBAAA;AAAA,gBAEJ;AAAA,gBACA;AAAA,cAAA;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MAEJ;AAAA,IACF,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AACF;"}
@@ -0,0 +1,58 @@
1
+ import { BaseHederaQueryTool } from "hedera-agent-kit";
2
+ import { z } from "zod";
3
+ import { errorHasStatus, getBatchSummary, getResponseWithStructuredContent } from "./index62.js";
4
+ import { NOT_FOUND_STATUS, GATEWAY_STAMP_ERROR_MESSAGE } from "./index63.js";
5
+ const GetPostageStampSchema = z.object({
6
+ postageBatchId: z.string()
7
+ });
8
+ class GetPostageStampTool extends BaseHederaQueryTool {
9
+ constructor(params) {
10
+ const { bee, config, ...rest } = params;
11
+ super(rest);
12
+ this.name = "swarm-get-postage-stamp";
13
+ this.description = `Get a specific postage stamp based on postageBatchId.
14
+ postageBatchId: The id of the stamp which is requested.
15
+ `;
16
+ this.namespace = "swarm";
17
+ this.specificInputSchema = GetPostageStampSchema;
18
+ this.bee = bee;
19
+ this.config = config;
20
+ }
21
+ async executeQuery(input) {
22
+ const { postageBatchId } = input;
23
+ if (!postageBatchId) {
24
+ this.logger.error(
25
+ "Missing required parameter: postageBatchId."
26
+ );
27
+ throw new Error("Missing required parameter: postageBatchId.");
28
+ }
29
+ let rawPostageBatch;
30
+ try {
31
+ rawPostageBatch = await this.bee.getPostageBatch(postageBatchId);
32
+ } catch (error) {
33
+ let errorMessage = "Retrieval of postage batch failed.";
34
+ if (errorHasStatus(error, NOT_FOUND_STATUS)) {
35
+ errorMessage = GATEWAY_STAMP_ERROR_MESSAGE;
36
+ }
37
+ this.logger.error(
38
+ errorMessage,
39
+ error
40
+ );
41
+ throw new Error(errorMessage);
42
+ }
43
+ const batch = {
44
+ ...rawPostageBatch,
45
+ batchID: rawPostageBatch.batchID.toHex()
46
+ };
47
+ const batchSummary = getBatchSummary(rawPostageBatch);
48
+ const content = {
49
+ raw: batch,
50
+ summary: batchSummary
51
+ };
52
+ return getResponseWithStructuredContent(content);
53
+ }
54
+ }
55
+ export {
56
+ GetPostageStampTool
57
+ };
58
+ //# sourceMappingURL=index55.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index55.js","sources":["../../src/plugins/community/swarm/tools/GetPostageStampTool.ts"],"sourcesContent":["import {\r\n type GenericPluginContext,\r\n BaseHederaQueryTool,\r\n type HederaAgentKit,\r\n} from \"hedera-agent-kit\";\r\nimport { Bee } from \"@ethersphere/bee-js\";\r\nimport { z } from \"zod\";\r\nimport {\r\n PostageBatchCurated,\r\n PostageBatchSummary,\r\n ResponseContent,\r\n} from \"../model\";\r\nimport {\r\n errorHasStatus,\r\n getBatchSummary,\r\n getResponseWithStructuredContent,\r\n ToolResponse,\r\n} from \"../utils\";\r\nimport { GATEWAY_STAMP_ERROR_MESSAGE, NOT_FOUND_STATUS } from \"../constants\";\r\nimport { SwarmConfig } from \"../config\";\r\n\r\nconst GetPostageStampSchema = z.object({\r\n postageBatchId: z.string(),\r\n});\r\n\r\nexport class GetPostageStampTool extends BaseHederaQueryTool<typeof GetPostageStampSchema> {\r\n name = \"swarm-get-postage-stamp\";\r\n description = `Get a specific postage stamp based on postageBatchId.\r\n postageBatchId: The id of the stamp which is requested.\r\n `;\r\n namespace = \"swarm\";\r\n specificInputSchema = GetPostageStampSchema;\r\n bee: Bee;\r\n config: SwarmConfig;\r\n \r\n constructor(params: {\r\n hederaKit: HederaAgentKit;\r\n config: SwarmConfig;\r\n logger?: GenericPluginContext['logger'];\r\n bee: Bee;\r\n }) {\r\n const { bee, config, ...rest } = params;\r\n super(rest);\r\n this.bee = bee;\r\n this.config = config;\r\n }\r\n\r\n protected async executeQuery(\r\n input: z.infer<typeof GetPostageStampSchema>\r\n ): Promise<ToolResponse | string> {\r\n const { postageBatchId } = input;\r\n if (!postageBatchId) {\r\n this.logger.error(\r\n 'Missing required parameter: postageBatchId.'\r\n );\r\n\r\n throw new Error(\"Missing required parameter: postageBatchId.\");\r\n }\r\n\r\n let rawPostageBatch;\r\n\r\n try {\r\n rawPostageBatch = await this.bee.getPostageBatch(postageBatchId);\r\n } catch (error) {\r\n let errorMessage = 'Retrieval of postage batch failed.';\r\n \r\n if (errorHasStatus(error, NOT_FOUND_STATUS)) {\r\n errorMessage = GATEWAY_STAMP_ERROR_MESSAGE;\r\n }\r\n\r\n this.logger.error(\r\n errorMessage,\r\n error\r\n );\r\n\r\n throw new Error(errorMessage);\r\n }\r\n\r\n const batch: PostageBatchCurated = {\r\n ...rawPostageBatch,\r\n batchID: rawPostageBatch.batchID.toHex(),\r\n };\r\n const batchSummary: PostageBatchSummary = getBatchSummary(rawPostageBatch);\r\n\r\n const content: ResponseContent<PostageBatchCurated, PostageBatchSummary> = {\r\n raw: batch,\r\n summary: batchSummary,\r\n };\r\n\r\n return getResponseWithStructuredContent(content);\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;AAqBA,MAAM,wBAAwB,EAAE,OAAO;AAAA,EACrC,gBAAgB,EAAE,OAAA;AACpB,CAAC;AAEM,MAAM,4BAA4B,oBAAkD;AAAA,EAUzF,YAAY,QAKT;AACD,UAAM,EAAE,KAAK,QAAQ,GAAG,SAAS;AACjC,UAAM,IAAI;AAhBZ,SAAA,OAAO;AACP,SAAA,cAAc;AAAA;AAAA;AAGd,SAAA,YAAY;AACZ,SAAA,sBAAsB;AAYpB,SAAK,MAAM;AACX,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAgB,aACZ,OAC8B;AAChC,UAAM,EAAE,mBAAmB;AAC3B,QAAI,CAAC,gBAAgB;AACnB,WAAK,OAAO;AAAA,QACV;AAAA,MAAA;AAGF,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AAEA,QAAI;AAEJ,QAAI;AACF,wBAAkB,MAAM,KAAK,IAAI,gBAAgB,cAAc;AAAA,IACjE,SAAS,OAAO;AACd,UAAI,eAAe;AAEnB,UAAI,eAAe,OAAO,gBAAgB,GAAG;AAC3C,uBAAe;AAAA,MACjB;AAEA,WAAK,OAAO;AAAA,QACV;AAAA,QACA;AAAA,MAAA;AAGF,YAAM,IAAI,MAAM,YAAY;AAAA,IAC9B;AAEA,UAAM,QAA6B;AAAA,MACjC,GAAG;AAAA,MACH,SAAS,gBAAgB,QAAQ,MAAA;AAAA,IAAM;AAEzC,UAAM,eAAoC,gBAAgB,eAAe;AAEzE,UAAM,UAAqE;AAAA,MACzE,KAAK;AAAA,MACL,SAAS;AAAA,IAAA;AAGX,WAAO,iCAAiC,OAAO;AAAA,EACjD;AACF;"}
@@ -0,0 +1,83 @@
1
+ import { Wallet } from "@ethereumjs/wallet";
2
+ import { z } from "zod";
3
+ import crypto from "crypto";
4
+ import { hexToBytes, errorHasStatus, getErrorMessage, getResponseWithStructuredContent } from "./index62.js";
5
+ import { BaseHederaQueryTool } from "hedera-agent-kit";
6
+ import { BAD_REQUEST_STATUS } from "./index63.js";
7
+ const ReadFeedSchema = z.object({
8
+ memoryTopic: z.string(),
9
+ owner: z.string().optional()
10
+ });
11
+ class ReadFeedTool extends BaseHederaQueryTool {
12
+ constructor(params) {
13
+ const { bee, config, ...rest } = params;
14
+ super(rest);
15
+ this.name = "swarm-read-feed";
16
+ this.description = `Retrieve the latest data from the feed of a given topic.
17
+ memoryTopic: Feed topic.
18
+ owner: When accessing external memory or feed, ethereum address of the owner must be set.
19
+ `;
20
+ this.namespace = "swarm";
21
+ this.specificInputSchema = ReadFeedSchema;
22
+ this.bee = bee;
23
+ this.config = config;
24
+ }
25
+ async executeQuery(input) {
26
+ const { memoryTopic, owner } = input;
27
+ if (!memoryTopic) {
28
+ this.logger.error(
29
+ "Missing required parameter: memoryTopic."
30
+ );
31
+ throw new Error("Missing required parameter: memoryTopic.");
32
+ }
33
+ this.logger.info(`[API] Downloading text from Swarm feed with topic: ${memoryTopic}.`);
34
+ if (!this.config.beeFeedPK) {
35
+ this.logger.error("Feed private key not configured.");
36
+ throw new Error("Feed private key not configured.");
37
+ }
38
+ let topic = memoryTopic;
39
+ if (topic.startsWith("0x")) {
40
+ topic = topic.slice(2);
41
+ }
42
+ const isHexString = /^[0-9a-fA-F]{64}$/.test(topic);
43
+ if (!isHexString) {
44
+ const hash = crypto.createHash("sha256").update(memoryTopic).digest("hex");
45
+ topic = hash;
46
+ }
47
+ const topicBytes = hexToBytes(topic);
48
+ let feedOwner = owner;
49
+ if (!feedOwner) {
50
+ const feedPrivateKey = hexToBytes(this.config.beeFeedPK);
51
+ const signer = new Wallet(feedPrivateKey);
52
+ feedOwner = signer.getAddressString().slice(2);
53
+ } else {
54
+ if (feedOwner.startsWith("0x")) {
55
+ feedOwner = feedOwner.slice(2);
56
+ }
57
+ if (feedOwner.length !== 40) {
58
+ this.logger.error("Owner must be a valid Ethereum address.");
59
+ throw new Error("Owner must be a valid Ethereum address.");
60
+ }
61
+ }
62
+ let textData;
63
+ try {
64
+ const feedReader = this.bee.makeFeedReader(topicBytes, feedOwner);
65
+ const latestUpdate = await feedReader.downloadPayload();
66
+ textData = latestUpdate.payload.toUtf8();
67
+ } catch (error) {
68
+ let errorMessage = "Reading feed failed.";
69
+ if (errorHasStatus(error, BAD_REQUEST_STATUS)) {
70
+ errorMessage = getErrorMessage(error);
71
+ }
72
+ this.logger.error(errorMessage, error);
73
+ throw new Error(errorMessage);
74
+ }
75
+ return getResponseWithStructuredContent({
76
+ textData
77
+ });
78
+ }
79
+ }
80
+ export {
81
+ ReadFeedTool
82
+ };
83
+ //# sourceMappingURL=index56.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index56.js","sources":["../../src/plugins/community/swarm/tools/ReadFeedTool.ts"],"sourcesContent":["import { Bee } from \"@ethersphere/bee-js\";\r\nimport { Wallet } from \"@ethereumjs/wallet\";\r\nimport { z } from \"zod\";\r\nimport crypto from \"crypto\";\r\nimport { errorHasStatus, getErrorMessage, getResponseWithStructuredContent, hexToBytes, ToolResponse } from \"../utils\";\r\nimport { BaseHederaQueryTool, GenericPluginContext, HederaAgentKit } from \"hedera-agent-kit\";\r\nimport { SwarmConfig } from \"../config\";\r\nimport { BAD_REQUEST_STATUS } from \"../constants\";\r\n\r\nconst ReadFeedSchema = z.object({\r\n memoryTopic: z.string(),\r\n owner: z.string().optional()\r\n});\r\n\r\nexport class ReadFeedTool extends BaseHederaQueryTool<typeof ReadFeedSchema> {\r\n name = \"swarm-read-feed\";\r\n description = `Retrieve the latest data from the feed of a given topic.\r\n memoryTopic: Feed topic.\r\n owner: When accessing external memory or feed, ethereum address of the owner must be set.\r\n `;\r\n namespace = \"swarm\";\r\n specificInputSchema = ReadFeedSchema;\r\n bee: Bee;\r\n config: SwarmConfig;\r\n \r\n constructor(params: {\r\n hederaKit: HederaAgentKit;\r\n config: SwarmConfig;\r\n logger?: GenericPluginContext['logger'];\r\n bee: Bee;\r\n }) {\r\n const { bee, config, ...rest } = params;\r\n super(rest);\r\n this.bee = bee;\r\n this.config = config;\r\n }\r\n\r\n protected async executeQuery(\r\n input: z.infer<typeof ReadFeedSchema>\r\n ): Promise<ToolResponse | string> {\r\n const { memoryTopic, owner } = input;\r\n\r\n if (!memoryTopic) {\r\n this.logger.error(\r\n 'Missing required parameter: memoryTopic.'\r\n );\r\n\r\n throw new Error('Missing required parameter: memoryTopic.');\r\n }\r\n\r\n this.logger.info(`[API] Downloading text from Swarm feed with topic: ${memoryTopic}.`);\r\n\r\n if (!this.config.beeFeedPK) {\r\n this.logger.error('Feed private key not configured.');\r\n\r\n throw new Error('Feed private key not configured.');\r\n }\r\n\r\n // Process topic - if not a hex string, hash it\r\n let topic = memoryTopic;\r\n if (topic.startsWith(\"0x\")) {\r\n topic = topic.slice(2);\r\n }\r\n const isHexString = /^[0-9a-fA-F]{64}$/.test(topic);\r\n\r\n if (!isHexString) {\r\n // Hash the topic string using SHA-256\r\n const hash = crypto.createHash(\"sha256\").update(memoryTopic).digest(\"hex\");\r\n topic = hash;\r\n }\r\n\r\n // Convert topic string to bytes\r\n const topicBytes = hexToBytes(topic);\r\n\r\n let feedOwner = owner;\r\n if (!feedOwner) {\r\n const feedPrivateKey = hexToBytes(this.config.beeFeedPK);\r\n const signer = new Wallet(feedPrivateKey);\r\n feedOwner = signer.getAddressString().slice(2);\r\n } else {\r\n if (feedOwner.startsWith(\"0x\")) {\r\n feedOwner = feedOwner.slice(2);\r\n }\r\n if (feedOwner.length !== 40) {\r\n this.logger.error('Owner must be a valid Ethereum address.');\r\n\r\n throw new Error('Owner must be a valid Ethereum address.');\r\n }\r\n }\r\n\r\n let textData;\r\n \r\n try {\r\n const feedReader = this.bee.makeFeedReader(topicBytes, feedOwner);\r\n const latestUpdate = await feedReader.downloadPayload();\r\n textData = latestUpdate.payload.toUtf8();\r\n } catch (error) {\r\n let errorMessage = 'Reading feed failed.';\r\n if (errorHasStatus(error, BAD_REQUEST_STATUS)) {\r\n errorMessage = getErrorMessage(error);\r\n }\r\n this.logger.error(errorMessage, error);\r\n throw new Error(errorMessage);\r\n }\r\n \r\n return getResponseWithStructuredContent({\r\n textData,\r\n });\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;;;AASA,MAAM,iBAAiB,EAAE,OAAO;AAAA,EAC9B,aAAa,EAAE,OAAA;AAAA,EACf,OAAO,EAAE,OAAA,EAAS,SAAA;AACpB,CAAC;AAEM,MAAM,qBAAqB,oBAA2C;AAAA,EAW3E,YAAY,QAKT;AACD,UAAM,EAAE,KAAK,QAAQ,GAAG,SAAS;AACjC,UAAM,IAAI;AAjBZ,SAAA,OAAO;AACP,SAAA,cAAc;AAAA;AAAA;AAAA;AAId,SAAA,YAAY;AACZ,SAAA,sBAAsB;AAYpB,SAAK,MAAM;AACX,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAgB,aACZ,OAC8B;AACjC,UAAM,EAAE,aAAa,MAAA,IAAU;AAE9B,QAAI,CAAC,aAAa;AAChB,WAAK,OAAO;AAAA,QACV;AAAA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