@hashgraphonline/conversational-agent 0.2.216 → 0.2.218

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +26 -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 +66 -173
  113. package/dist/esm/index45.js.map +1 -1
  114. package/dist/esm/index46.js +69 -24
  115. package/dist/esm/index46.js.map +1 -1
  116. package/dist/esm/index47.js +47 -88
  117. package/dist/esm/index47.js.map +1 -1
  118. package/dist/esm/index48.js +100 -7
  119. package/dist/esm/index48.js.map +1 -1
  120. package/dist/esm/index49.js +79 -0
  121. package/dist/esm/index49.js.map +1 -0
  122. package/dist/esm/index5.js +2 -2
  123. package/dist/esm/index50.js +75 -0
  124. package/dist/esm/index50.js.map +1 -0
  125. package/dist/esm/index51.js +124 -0
  126. package/dist/esm/index51.js.map +1 -0
  127. package/dist/esm/index52.js +58 -0
  128. package/dist/esm/index52.js.map +1 -0
  129. package/dist/esm/index53.js +83 -0
  130. package/dist/esm/index53.js.map +1 -0
  131. package/dist/esm/index54.js +100 -0
  132. package/dist/esm/index54.js.map +1 -0
  133. package/dist/esm/index55.js +118 -0
  134. package/dist/esm/index55.js.map +1 -0
  135. package/dist/esm/index56.js +108 -0
  136. package/dist/esm/index56.js.map +1 -0
  137. package/dist/esm/index57.js +8 -0
  138. package/dist/esm/index57.js.map +1 -0
  139. package/dist/esm/index58.js +325 -0
  140. package/dist/esm/index58.js.map +1 -0
  141. package/dist/esm/index59.js +187 -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 +10 -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 +37 -27
  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,157 +1,190 @@
1
- import { EntityFormat } from "./index26.js";
2
- import { Logger, HederaMirrorNode } from "@hashgraphonline/standards-sdk";
3
- class FormatConverterRegistry {
4
- constructor() {
5
- this.converters = /* @__PURE__ */ new Map();
6
- this.entityTypeCache = /* @__PURE__ */ new Map();
7
- this.logger = new Logger({ module: "FormatConverterRegistry" });
8
- this.defaultCacheTTL = 5 * 60 * 1e3;
1
+ import { ContentStorage } from "./index22.js";
2
+ import { Logger, ContentStoreService, ContentResolverRegistry, shouldUseReference, extractReferenceId } from "@hashgraphonline/standards-sdk";
3
+ class ContentStorageAdapter {
4
+ constructor(storage) {
5
+ this.storage = storage;
9
6
  }
10
- /**
11
- * Register a format converter
12
- */
13
- register(converter) {
14
- const key = `${converter.sourceFormat}→${converter.targetFormat}`;
15
- this.converters.set(key, converter);
16
- }
17
- /**
18
- * Find a converter for the given source and target formats
19
- */
20
- findConverter(source, target) {
21
- const key = `${source}→${target}`;
22
- return this.converters.get(key) || null;
7
+ async storeContent(content, metadata) {
8
+ const storeMetadata = {
9
+ contentType: "binary",
10
+ sizeBytes: content.length,
11
+ source: "system",
12
+ ...metadata
13
+ };
14
+ const contentRef = await this.storage.storeContent(content, storeMetadata);
15
+ return contentRef.referenceId;
23
16
  }
24
- /**
25
- * Convert an entity to the target format
26
- */
27
- async convertEntity(entity, target, context) {
28
- const sourceFormat = await this.detectFormatWithFallback(entity, context);
29
- if (sourceFormat === target) {
30
- return entity;
31
- }
32
- const converter = this.findConverter(sourceFormat, target);
33
- if (!converter) {
34
- throw new Error(`No converter found for ${sourceFormat} → ${target}`);
35
- }
36
- if (!converter.canConvert(entity, context)) {
37
- throw new Error(`Converter cannot handle entity: ${entity}`);
17
+ async resolveReference(referenceId) {
18
+ const result = await this.storage.resolveReference(referenceId);
19
+ if (result.success && result.content) {
20
+ const response = {
21
+ content: result.content
22
+ };
23
+ if (result.metadata) {
24
+ response.metadata = {
25
+ ...result.metadata.mimeType !== void 0 && {
26
+ mimeType: result.metadata.mimeType
27
+ },
28
+ ...result.metadata.fileName !== void 0 && {
29
+ fileName: result.metadata.fileName
30
+ },
31
+ originalSize: result.metadata.sizeBytes
32
+ };
33
+ }
34
+ return response;
35
+ } else {
36
+ throw new Error(result.error || "Reference not found");
38
37
  }
39
- const result = await converter.convert(entity, context);
40
- return result;
38
+ }
39
+ async hasReference(referenceId) {
40
+ return await this.storage.hasReference(referenceId);
41
+ }
42
+ async cleanupReference(referenceId) {
43
+ await this.storage.cleanupReference(referenceId);
44
+ }
45
+ async getStats() {
46
+ return await this.storage.getStats();
47
+ }
48
+ async updateConfig(config) {
49
+ const referenceConfig = {
50
+ sizeThresholdBytes: config.maxSize || 10240,
51
+ enableAutoCleanup: config.enableCompression || true,
52
+ ...config
53
+ };
54
+ return await this.storage.updateConfig(referenceConfig);
55
+ }
56
+ async performCleanup() {
57
+ await this.storage.performCleanup();
58
+ }
59
+ async dispose() {
60
+ return Promise.resolve(this.storage.dispose());
61
+ }
62
+ }
63
+ class ContentResolver {
64
+ constructor(adapter) {
65
+ this.adapter = adapter;
66
+ }
67
+ async resolveReference(referenceId) {
68
+ return await this.adapter.resolveReference(referenceId);
69
+ }
70
+ shouldUseReference(content) {
71
+ return shouldUseReference(content);
72
+ }
73
+ extractReferenceId(input) {
74
+ return extractReferenceId(input);
75
+ }
76
+ }
77
+ class ContentStoreManager {
78
+ constructor(maxMessageStorage = 1e3, referenceConfig, logger) {
79
+ this.isRegistered = false;
80
+ this.logger = logger || new Logger({ module: "ContentStoreManager" });
81
+ this.contentStorage = new ContentStorage(
82
+ maxMessageStorage,
83
+ referenceConfig
84
+ );
85
+ this.adapter = new ContentStorageAdapter(this.contentStorage);
86
+ this.resolver = new ContentResolver(this.adapter);
41
87
  }
42
88
  /**
43
- * Detect the format of an entity string with API-based verification and fallback
89
+ * Initialize and register content storage for cross-package access
44
90
  */
45
- async detectFormatWithFallback(entity, context) {
46
- if (entity.startsWith("hcs://")) {
47
- return EntityFormat.HRL;
91
+ async initialize() {
92
+ if (this.isRegistered) {
93
+ this.logger.warn("ContentStoreManager is already initialized");
94
+ return;
48
95
  }
49
- if (/^0\.0\.\d+$/.test(entity)) {
50
- const cached = this.getCachedFormat(entity);
51
- if (cached) {
52
- return cached;
96
+ try {
97
+ if (ContentStoreService && typeof ContentStoreService.setInstance === "function") {
98
+ await ContentStoreService.setInstance(
99
+ this.adapter
100
+ );
101
+ } else {
102
+ this.logger.warn("ContentStoreService.setInstance is unavailable; skipping registration");
53
103
  }
54
- try {
55
- const detected = await this.detectFormat(entity, context || {});
56
- if (detected !== EntityFormat.ANY) {
57
- this.setCachedFormat(entity, detected);
58
- return detected;
59
- }
60
- } catch (error) {
61
- this.logger.warn(
62
- `Entity detection failed for ${entity}, using fallback: ${error.message}`
104
+ if (ContentResolverRegistry && typeof ContentResolverRegistry.register === "function") {
105
+ ContentResolverRegistry.register(
106
+ this.resolver
63
107
  );
108
+ } else {
109
+ this.logger.warn("ContentResolverRegistry.register is unavailable; skipping registration");
64
110
  }
65
- return EntityFormat.ANY;
111
+ this.isRegistered = true;
112
+ this.logger.info(
113
+ "ContentStoreManager initialized and registered for cross-package access"
114
+ );
115
+ } catch (error) {
116
+ this.logger.error("Failed to initialize ContentStoreManager:", error);
117
+ throw error;
66
118
  }
67
- return EntityFormat.ANY;
68
- }
69
- /**
70
- * Public helper: detect entity format (ACCOUNT_ID, TOKEN_ID, TOPIC_ID, HRL, or ANY)
71
- */
72
- async detectEntityFormat(entity, context) {
73
- return this.detectFormatWithFallback(entity, context);
74
119
  }
75
120
  /**
76
- * Detect entity format via Hedera Mirror Node API calls
121
+ * Get the underlying ContentStorage instance
77
122
  */
78
- async detectFormat(entity, context) {
79
- const networkType = context.networkType || "testnet";
80
- const mirrorNode = new HederaMirrorNode(networkType, this.logger);
81
- mirrorNode.configureRetry({
82
- maxRetries: 3,
83
- maxDelayMs: 1e3
84
- });
85
- const checks = await Promise.allSettled([
86
- mirrorNode.getAccountBalance(entity).then((result) => result !== null ? EntityFormat.ACCOUNT_ID : null).catch(() => null),
87
- mirrorNode.getTokenInfo(entity).then((result) => result !== null ? EntityFormat.TOKEN_ID : null).catch(() => null),
88
- mirrorNode.getTopicInfo(entity).then((result) => result !== null ? EntityFormat.TOPIC_ID : null).catch(() => null),
89
- mirrorNode.getContract(entity).then((result) => result !== null ? EntityFormat.CONTRACT_ID : null).catch(() => null)
90
- ]);
91
- const successful = checks.find(
92
- (result) => result.status === "fulfilled" && result.value !== null
93
- );
94
- return successful && successful.status === "fulfilled" ? successful.value : EntityFormat.ANY;
123
+ getContentStorage() {
124
+ return this.contentStorage;
95
125
  }
96
126
  /**
97
- * Get cached entity format if valid
127
+ * Get storage statistics
98
128
  */
99
- getCachedFormat(entity) {
100
- const entry = this.entityTypeCache.get(entity);
101
- if (!entry || this.isCacheExpired(entry)) {
102
- this.entityTypeCache.delete(entity);
103
- return null;
104
- }
105
- return entry.format;
129
+ async getStats() {
130
+ return await this.contentStorage.getStats();
106
131
  }
107
132
  /**
108
- * Set cached entity format
133
+ * Update configuration
109
134
  */
110
- setCachedFormat(entity, format) {
111
- this.entityTypeCache.set(entity, {
112
- format,
113
- timestamp: Date.now(),
114
- ttl: this.defaultCacheTTL
115
- });
135
+ async updateConfig(config) {
136
+ return await this.contentStorage.updateConfig(config);
116
137
  }
117
138
  /**
118
- * Check if cache entry is expired
139
+ * Perform manual cleanup
119
140
  */
120
- isCacheExpired(entry) {
121
- return Date.now() - entry.timestamp > entry.ttl;
141
+ async performCleanup() {
142
+ return await this.contentStorage.performCleanup();
122
143
  }
123
144
  /**
124
- * Get all registered converters
145
+ * Check if content should be stored as reference
125
146
  */
126
- getRegisteredConverters() {
127
- return Array.from(this.converters.keys()).map((key) => {
128
- const [source, target] = key.split("→");
129
- return {
130
- source,
131
- target
132
- };
133
- });
147
+ shouldUseReference(content) {
148
+ return this.contentStorage.shouldUseReference(content);
134
149
  }
135
150
  /**
136
- * Check if a converter exists for the given formats
151
+ * Store content if it's large enough
137
152
  */
138
- hasConverter(source, target) {
139
- return this.findConverter(source, target) !== null;
153
+ async storeContentIfLarge(content, metadata) {
154
+ const storeMetadata = {
155
+ source: "system",
156
+ contentType: "binary",
157
+ ...metadata
158
+ };
159
+ return await this.contentStorage.storeContentIfLarge(
160
+ content,
161
+ storeMetadata
162
+ );
140
163
  }
141
164
  /**
142
- * Clear all registered converters
165
+ * Cleanup and unregister
143
166
  */
144
- clear() {
145
- this.converters.clear();
167
+ async dispose() {
168
+ if (this.isRegistered) {
169
+ this.contentStorage.dispose();
170
+ if (ContentStoreService && typeof ContentStoreService.dispose === "function") {
171
+ ContentStoreService.dispose();
172
+ }
173
+ if (ContentResolverRegistry && typeof ContentResolverRegistry.unregister === "function") {
174
+ ContentResolverRegistry.unregister();
175
+ }
176
+ this.isRegistered = false;
177
+ this.logger.info("ContentStoreManager disposed and unregistered");
178
+ }
146
179
  }
147
180
  /**
148
- * Clear entity type cache
181
+ * Check if the manager is initialized
149
182
  */
150
- clearCache() {
151
- this.entityTypeCache.clear();
183
+ isInitialized() {
184
+ return this.isRegistered;
152
185
  }
153
186
  }
154
187
  export {
155
- FormatConverterRegistry
188
+ ContentStoreManager
156
189
  };
157
190
  //# sourceMappingURL=index25.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index25.js","sources":["../../src/services/formatters/format-converter-registry.ts"],"sourcesContent":["import { EntityFormat, FormatConverter, ConversionContext } from './types';\nimport {\n HederaMirrorNode,\n Logger,\n NetworkType,\n} from '@hashgraphonline/standards-sdk';\n\ninterface CacheEntry {\n format: EntityFormat;\n timestamp: number;\n ttl: number;\n}\n\n/**\n * Registry for format converters that handles entity transformation\n */\nexport class FormatConverterRegistry {\n private converters = new Map<string, FormatConverter<unknown, unknown>>();\n private entityTypeCache = new Map<string, CacheEntry>();\n private logger = new Logger({ module: 'FormatConverterRegistry' });\n private defaultCacheTTL = 5 * 60 * 1000;\n\n /**\n * Register a format converter\n */\n register<TSource, TTarget>(\n converter: FormatConverter<TSource, TTarget>\n ): void {\n const key = `${converter.sourceFormat}→${converter.targetFormat}`;\n this.converters.set(key, converter as FormatConverter<unknown, unknown>);\n }\n\n /**\n * Find a converter for the given source and target formats\n */\n findConverter(\n source: EntityFormat,\n target: EntityFormat\n ): FormatConverter<unknown, unknown> | null {\n const key = `${source}→${target}`;\n return this.converters.get(key) || null;\n }\n\n /**\n * Convert an entity to the target format\n */\n async convertEntity(\n entity: string,\n target: EntityFormat,\n context: ConversionContext\n ): Promise<string> {\n const sourceFormat = await this.detectFormatWithFallback(entity, context);\n if (sourceFormat === target) {\n return entity;\n }\n\n const converter = this.findConverter(sourceFormat, target);\n if (!converter) {\n throw new Error(`No converter found for ${sourceFormat} → ${target}`);\n }\n\n if (!converter.canConvert(entity, context)) {\n throw new Error(`Converter cannot handle entity: ${entity}`);\n }\n\n const result = await converter.convert(entity, context);\n return result as string;\n }\n\n /**\n * Detect the format of an entity string with API-based verification and fallback\n */\n private async detectFormatWithFallback(\n entity: string,\n context?: ConversionContext\n ): Promise<EntityFormat> {\n if (entity.startsWith('hcs://')) {\n return EntityFormat.HRL;\n }\n\n if (/^0\\.0\\.\\d+$/.test(entity)) {\n const cached = this.getCachedFormat(entity);\n if (cached) {\n return cached;\n }\n\n try {\n const detected = await this.detectFormat(entity, context || {});\n if (detected !== EntityFormat.ANY) {\n this.setCachedFormat(entity, detected);\n return detected;\n }\n } catch (error) {\n this.logger.warn(\n `Entity detection failed for ${entity}, using fallback: ${\n (error as Error).message\n }`\n );\n }\n\n return EntityFormat.ANY;\n }\n\n return EntityFormat.ANY;\n }\n\n /**\n * Public helper: detect entity format (ACCOUNT_ID, TOKEN_ID, TOPIC_ID, HRL, or ANY)\n */\n async detectEntityFormat(\n entity: string,\n context?: ConversionContext\n ): Promise<EntityFormat> {\n return this.detectFormatWithFallback(entity, context);\n }\n\n /**\n * Detect entity format via Hedera Mirror Node API calls\n */\n private async detectFormat(\n entity: string,\n context: ConversionContext\n ): Promise<EntityFormat> {\n const networkType = (context.networkType as NetworkType) || 'testnet';\n const mirrorNode = new HederaMirrorNode(networkType, this.logger);\n\n mirrorNode.configureRetry({\n maxRetries: 3,\n maxDelayMs: 1000,\n });\n\n const checks = await Promise.allSettled([\n mirrorNode\n .getAccountBalance(entity)\n .then((result) => (result !== null ? EntityFormat.ACCOUNT_ID : null))\n .catch(() => null),\n\n mirrorNode\n .getTokenInfo(entity)\n .then((result) => (result !== null ? EntityFormat.TOKEN_ID : null))\n .catch(() => null),\n\n mirrorNode\n .getTopicInfo(entity)\n .then((result) => (result !== null ? EntityFormat.TOPIC_ID : null))\n .catch(() => null),\n\n mirrorNode\n .getContract(entity)\n .then((result) => (result !== null ? EntityFormat.CONTRACT_ID : null))\n .catch(() => null),\n ]);\n\n const successful = checks.find(\n (result) => result.status === 'fulfilled' && result.value !== null\n );\n\n return successful && successful.status === 'fulfilled'\n ? (successful.value as EntityFormat)\n : EntityFormat.ANY;\n }\n\n /**\n * Get cached entity format if valid\n */\n private getCachedFormat(entity: string): EntityFormat | null {\n const entry = this.entityTypeCache.get(entity);\n if (!entry || this.isCacheExpired(entry)) {\n this.entityTypeCache.delete(entity);\n return null;\n }\n return entry.format;\n }\n\n /**\n * Set cached entity format\n */\n private setCachedFormat(entity: string, format: EntityFormat): void {\n this.entityTypeCache.set(entity, {\n format,\n timestamp: Date.now(),\n ttl: this.defaultCacheTTL,\n });\n }\n\n /**\n * Check if cache entry is expired\n */\n private isCacheExpired(entry: CacheEntry): boolean {\n return Date.now() - entry.timestamp > entry.ttl;\n }\n\n /**\n * Get all registered converters\n */\n getRegisteredConverters(): Array<{\n source: EntityFormat;\n target: EntityFormat;\n }> {\n return Array.from(this.converters.keys()).map((key) => {\n const [source, target] = key.split('→');\n return {\n source: source as EntityFormat,\n target: target as EntityFormat,\n };\n });\n }\n\n /**\n * Check if a converter exists for the given formats\n */\n hasConverter(source: EntityFormat, target: EntityFormat): boolean {\n return this.findConverter(source, target) !== null;\n }\n\n /**\n * Clear all registered converters\n */\n clear(): void {\n this.converters.clear();\n }\n\n /**\n * Clear entity type cache\n */\n clearCache(): void {\n this.entityTypeCache.clear();\n }\n}\n"],"names":[],"mappings":";;AAgBO,MAAM,wBAAwB;AAAA,EAA9B,cAAA;AACL,SAAQ,iCAAiB,IAAA;AACzB,SAAQ,sCAAsB,IAAA;AAC9B,SAAQ,SAAS,IAAI,OAAO,EAAE,QAAQ,2BAA2B;AACjE,SAAQ,kBAAkB,IAAI,KAAK;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAKnC,SACE,WACM;AACN,UAAM,MAAM,GAAG,UAAU,YAAY,IAAI,UAAU,YAAY;AAC/D,SAAK,WAAW,IAAI,KAAK,SAA8C;AAAA,EACzE;AAAA;AAAA;AAAA;AAAA,EAKA,cACE,QACA,QAC0C;AAC1C,UAAM,MAAM,GAAG,MAAM,IAAI,MAAM;AAC/B,WAAO,KAAK,WAAW,IAAI,GAAG,KAAK;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cACJ,QACA,QACA,SACiB;AACjB,UAAM,eAAe,MAAM,KAAK,yBAAyB,QAAQ,OAAO;AACxE,QAAI,iBAAiB,QAAQ;AAC3B,a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CAAC,QAAQ;AACrD,YAAM,CAAC,QAAQ,MAAM,IAAI,IAAI,MAAM,GAAG;AACtC,aAAO;AAAA,QACL;AAAA,QACA;AAAA,MAAA;AAAA,IAEJ,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,aAAa,QAAsB,QAA+B;AAChE,WAAO,KAAK,cAAc,QAAQ,MAAM,MAAM;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA,EAKA,QAAc;AACZ,SAAK,WAAW,MAAA;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA,EAKA,aAAmB;AACjB,SAAK,gBAAgB,MAAA;AAAA,EACvB;AACF;"}
1
+ {"version":3,"file":"index25.js","sources":["../../src/services/content-store-manager.ts"],"sourcesContent":["import { ContentStorage } from '../memory/content-storage';\nimport {\n ContentStoreService,\n extractReferenceId,\n shouldUseReference,\n ContentResolverRegistry,\n type ContentStoreInterface,\n type ContentResolverInterface,\n type ReferenceResolutionResult,\n} from '@hashgraphonline/standards-sdk';\nimport type {\n ContentReference,\n ContentReferenceConfig,\n ContentReferenceStats,\n} from '../types/content-reference';\nimport { Logger } from '@hashgraphonline/standards-sdk';\n\n/**\n * Content metadata interface for adapter compatibility\n */\ninterface AdapterContentMetadata {\n mimeType?: string;\n fileName?: string;\n sizeBytes?: number;\n [key: string]: unknown;\n}\n\n/**\n * Configuration interface for content storage\n */\ninterface ContentStoreConfig {\n maxSize?: number;\n enableCompression?: boolean;\n [key: string]: unknown;\n}\n\n/**\n * Adapter to make ContentStorage compatible with ContentStoreInterface\n */\nclass ContentStorageAdapter implements ContentStoreInterface {\n constructor(private storage: ContentStorage) {}\n\n async storeContent(\n content: Buffer,\n metadata: AdapterContentMetadata\n ): Promise<string> {\n const storeMetadata = {\n contentType: 'binary' as const,\n sizeBytes: content.length,\n source: 'system' as const,\n ...metadata,\n };\n const contentRef = await this.storage.storeContent(content, storeMetadata);\n return contentRef.referenceId;\n }\n\n async resolveReference(\n referenceId: string\n ): Promise<ReferenceResolutionResult> {\n const result = await this.storage.resolveReference(referenceId);\n if (result.success && result.content) {\n const response: ReferenceResolutionResult = {\n content: result.content,\n };\n if (result.metadata) {\n response.metadata = {\n ...(result.metadata.mimeType !== undefined && {\n mimeType: result.metadata.mimeType,\n }),\n ...(result.metadata.fileName !== undefined && {\n fileName: result.metadata.fileName,\n }),\n originalSize: result.metadata.sizeBytes,\n };\n }\n return response;\n } else {\n throw new Error(result.error || 'Reference not found');\n }\n }\n\n async hasReference(referenceId: string): Promise<boolean> {\n return await this.storage.hasReference(referenceId);\n }\n\n async cleanupReference(referenceId: string): Promise<void> {\n await this.storage.cleanupReference(referenceId);\n }\n\n async getStats(): Promise<unknown> {\n return await this.storage.getStats();\n }\n\n async updateConfig(config: ContentStoreConfig): Promise<void> {\n const referenceConfig = {\n sizeThresholdBytes: config.maxSize || 10240,\n enableAutoCleanup: config.enableCompression || true,\n ...config,\n };\n return await this.storage.updateConfig(referenceConfig);\n }\n\n async performCleanup(): Promise<void> {\n await this.storage.performCleanup();\n }\n\n async dispose(): Promise<void> {\n return Promise.resolve(this.storage.dispose());\n }\n}\n\n/**\n * Content resolver implementation for dependency injection\n */\nclass ContentResolver implements ContentResolverInterface {\n constructor(private adapter: ContentStorageAdapter) {}\n\n async resolveReference(\n referenceId: string\n ): Promise<ReferenceResolutionResult> {\n return await this.adapter.resolveReference(referenceId);\n }\n\n shouldUseReference(content: string | Buffer): boolean {\n return shouldUseReference(content);\n }\n\n extractReferenceId(input: string): string | null {\n return extractReferenceId(input);\n }\n}\n\n/**\n * Manages content store lifecycle and cross-package registration\n */\nexport class ContentStoreManager {\n private contentStorage: ContentStorage;\n private adapter: ContentStorageAdapter;\n private resolver: ContentResolver;\n private logger: Logger;\n protected isRegistered = false;\n\n constructor(\n maxMessageStorage: number = 1000,\n referenceConfig?: Partial<ContentReferenceConfig>,\n logger?: Logger\n ) {\n this.logger = logger || new Logger({ module: 'ContentStoreManager' });\n\n this.contentStorage = new ContentStorage(\n maxMessageStorage,\n referenceConfig\n );\n this.adapter = new ContentStorageAdapter(this.contentStorage);\n this.resolver = new ContentResolver(this.adapter);\n }\n\n /**\n * Initialize and register content storage for cross-package access\n */\n async initialize(): Promise<void> {\n if (this.isRegistered) {\n this.logger.warn('ContentStoreManager is already initialized');\n return;\n }\n\n try {\n if (\n ContentStoreService &&\n typeof (ContentStoreService as unknown as { setInstance?: Function }).setInstance === 'function'\n ) {\n await (ContentStoreService as unknown as { setInstance: (adapter: unknown) => Promise<void> }).setInstance(\n this.adapter\n );\n } else {\n this.logger.warn('ContentStoreService.setInstance is unavailable; skipping registration');\n }\n if (\n ContentResolverRegistry &&\n typeof (ContentResolverRegistry as unknown as { register?: Function }).register === 'function'\n ) {\n (ContentResolverRegistry as unknown as { register: (resolver: unknown) => void }).register(\n this.resolver\n );\n } else {\n this.logger.warn('ContentResolverRegistry.register is unavailable; skipping registration');\n }\n this.isRegistered = true;\n this.logger.info(\n 'ContentStoreManager initialized and registered for cross-package access'\n );\n } catch (error) {\n this.logger.error('Failed to initialize ContentStoreManager:', error);\n throw error;\n }\n }\n\n /**\n * Get the underlying ContentStorage instance\n */\n getContentStorage(): ContentStorage {\n return this.contentStorage;\n }\n\n /**\n * Get storage statistics\n */\n async getStats(): Promise<ContentReferenceStats> {\n return await this.contentStorage.getStats();\n }\n\n /**\n * Update configuration\n */\n async updateConfig(config: Partial<ContentReferenceConfig>): Promise<void> {\n return await this.contentStorage.updateConfig(config);\n }\n\n /**\n * Perform manual cleanup\n */\n async performCleanup(): Promise<{ cleanedUp: number; errors: string[] }> {\n return await this.contentStorage.performCleanup();\n }\n\n /**\n * Check if content should be stored as reference\n */\n shouldUseReference(content: Buffer | string): boolean {\n return this.contentStorage.shouldUseReference(content);\n }\n\n /**\n * Store content if it's large enough\n */\n async storeContentIfLarge(\n content: Buffer | string,\n metadata: AdapterContentMetadata\n ): Promise<ContentReference | null> {\n const storeMetadata = {\n source: 'system' as const,\n contentType: 'binary' as const,\n ...metadata,\n };\n return await this.contentStorage.storeContentIfLarge(\n content,\n storeMetadata\n );\n }\n\n /**\n * Cleanup and unregister\n */\n async dispose(): Promise<void> {\n if (this.isRegistered) {\n this.contentStorage.dispose();\n if (\n ContentStoreService &&\n typeof (ContentStoreService as unknown as { dispose?: Function }).dispose === 'function'\n ) {\n (ContentStoreService as unknown as { dispose: () => void }).dispose();\n }\n if (\n ContentResolverRegistry &&\n typeof (ContentResolverRegistry as unknown as { unregister?: Function }).unregister === 'function'\n ) {\n (ContentResolverRegistry as unknown as { unregister: () => void }).unregister();\n }\n this.isRegistered = false;\n this.logger.info('ContentStoreManager disposed and unregistered');\n }\n }\n\n /**\n * Check if the manager is initialized\n */\n isInitialized(): boolean {\n return this.isRegistered;\n }\n}\n"],"names":[],"mappings":";;AAuCA,MAAM,sBAAuD;AAAA,EAC3D,YAAoB,SAAyB;AAAzB,SAAA,UAAA;AAAA,EAA0B;AAAA,EAE9C,MAAM,aACJ,SACA,UACiB;AACjB,UAAM,gBAAgB;AAAA,MACpB,aAAa;AAAA,MACb,WAAW,QAAQ;AAAA,MACnB,QAAQ;AAAA,MACR,GAAG;AAAA,IAAA;AAEL,UAAM,aAAa,MAAM,KAAK,QAAQ,aAAa,SAAS,aAAa;AACzE,WAAO,WAAW;AAAA,EACpB;AAAA,EAEA,MAAM,iBACJ,aACoC;AACpC,UAAM,SAAS,MAAM,KAAK,QAAQ,iBAAiB,WAAW;AAC9D,QAAI,OAAO,WAAW,OAAO,SAAS;AACpC,YAAM,WAAsC;AAAA,QAC1C,SAAS,OAAO;AAAA,MAAA;AAElB,UAAI,OAAO,UAAU;AACnB,iBAAS,WAAW;AAAA,UAClB,GAAI,OAAO,SAAS,aAAa,UAAa;AAAA,YAC5C,UAAU,OAAO,SAAS;AAAA,UAAA;AAAA,UAE5B,GAAI,OAAO,SAAS,aAAa,UAAa;AAAA,YAC5C,UAAU,OAAO,SAAS;AAAA,UAAA;AAAA,UAE5B,cAAc,OAAO,SAAS;AAAA,QAAA;AAAA,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AAA,MACR,aAAa;AAAA,MACb,GAAG;AAAA,IAAA;AAEL,WAAO,MAAM,KAAK,eAAe;AAAA,MAC/B;AAAA,MACA;AAAA,IAAA;AAAA,EAEJ;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,UAAyB;AAC7B,QAAI,KAAK,cAAc;AACrB,WAAK,eAAe,QAAA;AACpB,UACE,uBACA,OAAQ,oBAA0D,YAAY,YAC9E;AACC,4BAA2D,QAAA;AAAA,MAC9D;AACA,UACE,2BACA,OAAQ,wBAAiE,eAAe,YACxF;AACC,gCAAkE,WAAA;AAAA,MACrE;AACA,WAAK,eAAe;AACpB,WAAK,OAAO,KAAK,+CAA+C;AAAA,IAClE;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAyB;AACvB,WAAO,KAAK;AAAA,EACd;AACF;"}
@@ -1,21 +1,157 @@
1
- var EntityFormat = /* @__PURE__ */ ((EntityFormat2) => {
2
- EntityFormat2["TOPIC_ID"] = "topicId";
3
- EntityFormat2["HRL"] = "hrl";
4
- EntityFormat2["SCHEDULE_ID"] = "scheduleId";
5
- EntityFormat2["TOKEN_ID"] = "tokenId";
6
- EntityFormat2["ADDRESS"] = "address";
7
- EntityFormat2["SYMBOL"] = "symbol";
8
- EntityFormat2["SERIAL_NUMBER"] = "serialNumber";
9
- EntityFormat2["METADATA"] = "metadata";
10
- EntityFormat2["ACCOUNT_ID"] = "accountId";
11
- EntityFormat2["ALIAS"] = "alias";
12
- EntityFormat2["EVM_ADDRESS"] = "evmAddress";
13
- EntityFormat2["CONTRACT_ID"] = "contractId";
14
- EntityFormat2["FILE_ID"] = "fileId";
15
- EntityFormat2["ANY"] = "any";
16
- return EntityFormat2;
17
- })(EntityFormat || {});
1
+ import { EntityFormat } from "./index27.js";
2
+ import { Logger, HederaMirrorNode } from "@hashgraphonline/standards-sdk";
3
+ class FormatConverterRegistry {
4
+ constructor() {
5
+ this.converters = /* @__PURE__ */ new Map();
6
+ this.entityTypeCache = /* @__PURE__ */ new Map();
7
+ this.logger = new Logger({ module: "FormatConverterRegistry" });
8
+ this.defaultCacheTTL = 5 * 60 * 1e3;
9
+ }
10
+ /**
11
+ * Register a format converter
12
+ */
13
+ register(converter) {
14
+ const key = `${converter.sourceFormat}→${converter.targetFormat}`;
15
+ this.converters.set(key, converter);
16
+ }
17
+ /**
18
+ * Find a converter for the given source and target formats
19
+ */
20
+ findConverter(source, target) {
21
+ const key = `${source}→${target}`;
22
+ return this.converters.get(key) || null;
23
+ }
24
+ /**
25
+ * Convert an entity to the target format
26
+ */
27
+ async convertEntity(entity, target, context) {
28
+ const sourceFormat = await this.detectFormatWithFallback(entity, context);
29
+ if (sourceFormat === target) {
30
+ return entity;
31
+ }
32
+ const converter = this.findConverter(sourceFormat, target);
33
+ if (!converter) {
34
+ throw new Error(`No converter found for ${sourceFormat} → ${target}`);
35
+ }
36
+ if (!converter.canConvert(entity, context)) {
37
+ throw new Error(`Converter cannot handle entity: ${entity}`);
38
+ }
39
+ const result = await converter.convert(entity, context);
40
+ return result;
41
+ }
42
+ /**
43
+ * Detect the format of an entity string with API-based verification and fallback
44
+ */
45
+ async detectFormatWithFallback(entity, context) {
46
+ if (entity.startsWith("hcs://")) {
47
+ return EntityFormat.HRL;
48
+ }
49
+ if (/^0\.0\.\d+$/.test(entity)) {
50
+ const cached = this.getCachedFormat(entity);
51
+ if (cached) {
52
+ return cached;
53
+ }
54
+ try {
55
+ const detected = await this.detectFormat(entity, context || {});
56
+ if (detected !== EntityFormat.ANY) {
57
+ this.setCachedFormat(entity, detected);
58
+ return detected;
59
+ }
60
+ } catch (error) {
61
+ this.logger.warn(
62
+ `Entity detection failed for ${entity}, using fallback: ${error.message}`
63
+ );
64
+ }
65
+ return EntityFormat.ANY;
66
+ }
67
+ return EntityFormat.ANY;
68
+ }
69
+ /**
70
+ * Public helper: detect entity format (ACCOUNT_ID, TOKEN_ID, TOPIC_ID, HRL, or ANY)
71
+ */
72
+ async detectEntityFormat(entity, context) {
73
+ return this.detectFormatWithFallback(entity, context);
74
+ }
75
+ /**
76
+ * Detect entity format via Hedera Mirror Node API calls
77
+ */
78
+ async detectFormat(entity, context) {
79
+ const networkType = context.networkType || "testnet";
80
+ const mirrorNode = new HederaMirrorNode(networkType, this.logger);
81
+ mirrorNode.configureRetry({
82
+ maxRetries: 3,
83
+ maxDelayMs: 1e3
84
+ });
85
+ const checks = await Promise.allSettled([
86
+ mirrorNode.getAccountBalance(entity).then((result) => result !== null ? EntityFormat.ACCOUNT_ID : null).catch(() => null),
87
+ mirrorNode.getTokenInfo(entity).then((result) => result !== null ? EntityFormat.TOKEN_ID : null).catch(() => null),
88
+ mirrorNode.getTopicInfo(entity).then((result) => result !== null ? EntityFormat.TOPIC_ID : null).catch(() => null),
89
+ mirrorNode.getContract(entity).then((result) => result !== null ? EntityFormat.CONTRACT_ID : null).catch(() => null)
90
+ ]);
91
+ const successful = checks.find(
92
+ (result) => result.status === "fulfilled" && result.value !== null
93
+ );
94
+ return successful && successful.status === "fulfilled" ? successful.value : EntityFormat.ANY;
95
+ }
96
+ /**
97
+ * Get cached entity format if valid
98
+ */
99
+ getCachedFormat(entity) {
100
+ const entry = this.entityTypeCache.get(entity);
101
+ if (!entry || this.isCacheExpired(entry)) {
102
+ this.entityTypeCache.delete(entity);
103
+ return null;
104
+ }
105
+ return entry.format;
106
+ }
107
+ /**
108
+ * Set cached entity format
109
+ */
110
+ setCachedFormat(entity, format) {
111
+ this.entityTypeCache.set(entity, {
112
+ format,
113
+ timestamp: Date.now(),
114
+ ttl: this.defaultCacheTTL
115
+ });
116
+ }
117
+ /**
118
+ * Check if cache entry is expired
119
+ */
120
+ isCacheExpired(entry) {
121
+ return Date.now() - entry.timestamp > entry.ttl;
122
+ }
123
+ /**
124
+ * Get all registered converters
125
+ */
126
+ getRegisteredConverters() {
127
+ return Array.from(this.converters.keys()).map((key) => {
128
+ const [source, target] = key.split("→");
129
+ return {
130
+ source,
131
+ target
132
+ };
133
+ });
134
+ }
135
+ /**
136
+ * Check if a converter exists for the given formats
137
+ */
138
+ hasConverter(source, target) {
139
+ return this.findConverter(source, target) !== null;
140
+ }
141
+ /**
142
+ * Clear all registered converters
143
+ */
144
+ clear() {
145
+ this.converters.clear();
146
+ }
147
+ /**
148
+ * Clear entity type cache
149
+ */
150
+ clearCache() {
151
+ this.entityTypeCache.clear();
152
+ }
153
+ }
18
154
  export {
19
- EntityFormat
155
+ FormatConverterRegistry
20
156
  };
21
157
  //# sourceMappingURL=index26.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index26.js","sources":["../../src/services/formatters/types.ts"],"sourcesContent":["import { NetworkType } from '@hashgraphonline/standards-sdk';\n\nexport enum EntityFormat {\n TOPIC_ID = 'topicId',\n HRL = 'hrl',\n SCHEDULE_ID = 'scheduleId',\n TOKEN_ID = 'tokenId',\n ADDRESS = 'address',\n SYMBOL = 'symbol',\n SERIAL_NUMBER = 'serialNumber',\n METADATA = 'metadata',\n ACCOUNT_ID = 'accountId',\n ALIAS = 'alias',\n EVM_ADDRESS = 'evmAddress',\n CONTRACT_ID = 'contractId',\n FILE_ID = 'fileId',\n ANY = 'any'\n}\n\nexport interface ConversionContext {\n networkType?: NetworkType;\n sessionId?: string;\n toolName?: string;\n toolPreferences?: Record<string, string>;\n [key: string]: unknown;\n}\n\nexport interface FormatConverter<TSource = string, TTarget = string> {\n sourceFormat: EntityFormat;\n targetFormat: EntityFormat;\n canConvert(source: string, context: ConversionContext): boolean;\n convert(entity: TSource, context: ConversionContext): Promise<TTarget>;\n}"],"names":["EntityFormat"],"mappings":"AAEO,IAAK,iCAAAA,kBAAL;AACLA,gBAAA,UAAA,IAAW;AACXA,gBAAA,KAAA,IAAM;AACNA,gBAAA,aAAA,IAAc;AACdA,gBAAA,UAAA,IAAW;AACXA,gBAAA,SAAA,IAAU;AACVA,gBAAA,QAAA,IAAS;AACTA,gBAAA,eAAA,IAAgB;AAChBA,gBAAA,UAAA,IAAW;AACXA,gBAAA,YAAA,IAAa;AACbA,gBAAA,OAAA,IAAQ;AACRA,gBAAA,aAAA,IAAc;AACdA,gBAAA,aAAA,IAAc;AACdA,gBAAA,SAAA,IAAU;AACVA,gBAAA,KAAA,IAAM;AAdI,SAAAA;AAAA,GAAA,gBAAA,CAAA,CAAA;"}
1
+ {"version":3,"file":"index26.js","sources":["../../src/services/formatters/format-converter-registry.ts"],"sourcesContent":["import { EntityFormat, FormatConverter, ConversionContext } from './types';\nimport {\n HederaMirrorNode,\n Logger,\n NetworkType,\n} from '@hashgraphonline/standards-sdk';\n\ninterface CacheEntry {\n format: EntityFormat;\n timestamp: number;\n ttl: number;\n}\n\n/**\n * Registry for format converters that handles entity transformation\n */\nexport class FormatConverterRegistry {\n private converters = new Map<string, FormatConverter<unknown, unknown>>();\n private entityTypeCache = new Map<string, CacheEntry>();\n private logger = new Logger({ module: 'FormatConverterRegistry' });\n private defaultCacheTTL = 5 * 60 * 1000;\n\n /**\n * Register a format converter\n */\n register<TSource, TTarget>(\n converter: FormatConverter<TSource, TTarget>\n ): void {\n const key = `${converter.sourceFormat}→${converter.targetFormat}`;\n this.converters.set(key, converter as FormatConverter<unknown, unknown>);\n }\n\n /**\n * Find a converter for the given source and target formats\n */\n findConverter(\n source: EntityFormat,\n target: EntityFormat\n ): FormatConverter<unknown, unknown> | null {\n const key = `${source}→${target}`;\n return this.converters.get(key) || null;\n }\n\n /**\n * Convert an entity to the target format\n */\n async convertEntity(\n entity: string,\n target: EntityFormat,\n context: ConversionContext\n ): Promise<string> {\n const sourceFormat = await this.detectFormatWithFallback(entity, context);\n if (sourceFormat === target) {\n return entity;\n }\n\n const converter = this.findConverter(sourceFormat, target);\n if (!converter) {\n throw new Error(`No converter found for ${sourceFormat} → ${target}`);\n }\n\n if (!converter.canConvert(entity, context)) {\n throw new Error(`Converter cannot handle entity: ${entity}`);\n }\n\n const result = await converter.convert(entity, context);\n return result as string;\n }\n\n /**\n * Detect the format of an entity string with API-based verification and fallback\n */\n private async detectFormatWithFallback(\n entity: string,\n context?: ConversionContext\n ): Promise<EntityFormat> {\n if (entity.startsWith('hcs://')) {\n return EntityFormat.HRL;\n }\n\n if (/^0\\.0\\.\\d+$/.test(entity)) {\n const cached = this.getCachedFormat(entity);\n if (cached) {\n return cached;\n }\n\n try {\n const detected = await this.detectFormat(entity, context || {});\n if (detected !== EntityFormat.ANY) {\n this.setCachedFormat(entity, detected);\n return detected;\n }\n } catch (error) {\n this.logger.warn(\n `Entity detection failed for ${entity}, using fallback: ${\n (error as Error).message\n }`\n );\n }\n\n return EntityFormat.ANY;\n }\n\n return EntityFormat.ANY;\n }\n\n /**\n * Public helper: detect entity format (ACCOUNT_ID, TOKEN_ID, TOPIC_ID, HRL, or ANY)\n */\n async detectEntityFormat(\n entity: string,\n context?: ConversionContext\n ): Promise<EntityFormat> {\n return this.detectFormatWithFallback(entity, context);\n }\n\n /**\n * Detect entity format via Hedera Mirror Node API calls\n */\n private async detectFormat(\n entity: string,\n context: ConversionContext\n ): Promise<EntityFormat> {\n const networkType = (context.networkType as NetworkType) || 'testnet';\n const mirrorNode = new HederaMirrorNode(networkType, this.logger);\n\n mirrorNode.configureRetry({\n maxRetries: 3,\n maxDelayMs: 1000,\n });\n\n const checks = await Promise.allSettled([\n mirrorNode\n .getAccountBalance(entity)\n .then((result) => (result !== null ? EntityFormat.ACCOUNT_ID : null))\n .catch(() => null),\n\n mirrorNode\n .getTokenInfo(entity)\n .then((result) => (result !== null ? EntityFormat.TOKEN_ID : null))\n .catch(() => null),\n\n mirrorNode\n .getTopicInfo(entity)\n .then((result) => (result !== null ? EntityFormat.TOPIC_ID : null))\n .catch(() => null),\n\n mirrorNode\n .getContract(entity)\n .then((result) => (result !== null ? EntityFormat.CONTRACT_ID : null))\n .catch(() => null),\n ]);\n\n const successful = checks.find(\n (result) => result.status === 'fulfilled' && result.value !== null\n );\n\n return successful && successful.status === 'fulfilled'\n ? (successful.value as EntityFormat)\n : EntityFormat.ANY;\n }\n\n /**\n * Get cached entity format if valid\n */\n private getCachedFormat(entity: string): EntityFormat | null {\n const entry = this.entityTypeCache.get(entity);\n if (!entry || this.isCacheExpired(entry)) {\n this.entityTypeCache.delete(entity);\n return null;\n }\n return entry.format;\n }\n\n /**\n * Set cached entity format\n */\n private setCachedFormat(entity: string, format: EntityFormat): void {\n this.entityTypeCache.set(entity, {\n format,\n timestamp: Date.now(),\n ttl: this.defaultCacheTTL,\n });\n }\n\n /**\n * Check if cache entry is expired\n */\n private isCacheExpired(entry: CacheEntry): boolean {\n return Date.now() - entry.timestamp > entry.ttl;\n }\n\n /**\n * Get all registered converters\n */\n getRegisteredConverters(): Array<{\n source: EntityFormat;\n target: EntityFormat;\n }> {\n return Array.from(this.converters.keys()).map((key) => {\n const [source, target] = key.split('→');\n return {\n source: source as EntityFormat,\n target: target as EntityFormat,\n };\n });\n }\n\n /**\n * Check if a converter exists for the given formats\n */\n hasConverter(source: EntityFormat, target: EntityFormat): boolean {\n return this.findConverter(source, target) !== null;\n }\n\n /**\n * Clear all registered converters\n */\n clear(): void {\n this.converters.clear();\n }\n\n /**\n * Clear entity type cache\n */\n clearCache(): void {\n this.entityTypeCache.clear();\n }\n}\n"],"names":[],"mappings":";;AAgBO,MAAM,wBAAwB;AAAA,EAA9B,cAAA;AACL,SAAQ,iCAAiB,IAAA;AACzB,SAAQ,sCAAsB,IAAA;AAC9B,SAAQ,SAAS,IAAI,OAAO,EAAE,QAAQ,2BAA2B;AACjE,SAAQ,kBAAkB,IAAI,KAAK;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAKnC,SACE,WACM;AACN,UAAM,MAAM,GAAG,UAAU,YAAY,IAAI,UAAU,YAAY;AAC/D,SAAK,WAAW,IAAI,KAAK,SAA8C;AAAA,EACzE;AAAA;AAAA;AAAA;AAAA,EAKA,cACE,QACA,QAC0C;AAC1C,UAAM,MAAM,GAAG,MAAM,IAAI,MAAM;AAC/B,WAAO,KAAK,WAAW,IAAI,GAAG,KAAK;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA,EAKA,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YAAY,MAAM;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA,EAKA,0BAGG;AACD,WAAO,MAAM,KAAK,KAAK,WAAW,MAAM,EAAE,IAAI,CAAC,QAAQ;AACrD,YAAM,CAAC,QAAQ,MAAM,IAAI,IAAI,MAAM,GAAG;AACtC,aAAO;AAAA,QACL;AAAA,QACA;AAAA,MAAA;AAAA,IAEJ,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,aAAa,QAAsB,QAA+B;AAChE,WAAO,KAAK,cAAc,QAAQ,MAAM,MAAM;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA,EAKA,QAAc;AACZ,SAAK,WAAW,MAAA;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA,EAKA,aAAmB;AACjB,SAAK,gBAAgB,MAAA;AAAA,EACvB;AACF;"}
@@ -1,25 +1,21 @@
1
- import { EntityFormat } from "./index26.js";
2
- class TopicIdToHrlConverter {
3
- constructor() {
4
- this.sourceFormat = EntityFormat.TOPIC_ID;
5
- this.targetFormat = EntityFormat.HRL;
6
- }
7
- /**
8
- * Check if the source string is a valid topic ID
9
- */
10
- canConvert(source, _context) {
11
- return /^0\.0\.\d+$/.test(source);
12
- }
13
- /**
14
- * Convert topic ID to HRL format based on network type
15
- */
16
- async convert(topicId, context) {
17
- const networkType = context.networkType || "testnet";
18
- const networkId = networkType === "mainnet" ? "0" : "1";
19
- return `hcs://${networkId}/${topicId}`;
20
- }
21
- }
1
+ var EntityFormat = /* @__PURE__ */ ((EntityFormat2) => {
2
+ EntityFormat2["TOPIC_ID"] = "topicId";
3
+ EntityFormat2["HRL"] = "hrl";
4
+ EntityFormat2["SCHEDULE_ID"] = "scheduleId";
5
+ EntityFormat2["TOKEN_ID"] = "tokenId";
6
+ EntityFormat2["ADDRESS"] = "address";
7
+ EntityFormat2["SYMBOL"] = "symbol";
8
+ EntityFormat2["SERIAL_NUMBER"] = "serialNumber";
9
+ EntityFormat2["METADATA"] = "metadata";
10
+ EntityFormat2["ACCOUNT_ID"] = "accountId";
11
+ EntityFormat2["ALIAS"] = "alias";
12
+ EntityFormat2["EVM_ADDRESS"] = "evmAddress";
13
+ EntityFormat2["CONTRACT_ID"] = "contractId";
14
+ EntityFormat2["FILE_ID"] = "fileId";
15
+ EntityFormat2["ANY"] = "any";
16
+ return EntityFormat2;
17
+ })(EntityFormat || {});
22
18
  export {
23
- TopicIdToHrlConverter
19
+ EntityFormat
24
20
  };
25
21
  //# sourceMappingURL=index27.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index27.js","sources":["../../src/services/formatters/converters/topic-id-to-hrl-converter.ts"],"sourcesContent":["import { EntityFormat, FormatConverter, ConversionContext } from '../types';\n\n/**\n * Converts Hedera topic IDs to HRL format for consensus service messages\n */\nexport class TopicIdToHrlConverter implements FormatConverter<string, string> {\n sourceFormat = EntityFormat.TOPIC_ID;\n targetFormat = EntityFormat.HRL;\n\n /**\n * Check if the source string is a valid topic ID\n */\n canConvert(source: string, _context: ConversionContext): boolean {\n return /^0\\.0\\.\\d+$/.test(source);\n }\n\n /**\n * Convert topic ID to HRL format based on network type\n */\n async convert(topicId: string, context: ConversionContext): Promise<string> {\n const networkType = context.networkType || 'testnet';\n const networkId = networkType === 'mainnet' ? '0' : '1';\n return `hcs://${networkId}/${topicId}`;\n }\n}\n"],"names":[],"mappings":";AAKO,MAAM,sBAAiE;AAAA,EAAvE,cAAA;AACL,SAAA,eAAe,aAAa;AAC5B,SAAA,eAAe,aAAa;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAK5B,WAAW,QAAgB,UAAsC;AAC/D,WAAO,cAAc,KAAK,MAAM;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAQ,SAAiB,SAA6C;AAC1E,UAAM,cAAc,QAAQ,eAAe;AAC3C,UAAM,YAAY,gBAAgB,YAAY,MAAM;AACpD,WAAO,SAAS,SAAS,IAAI,OAAO;AAAA,EACtC;AACF;"}
1
+ {"version":3,"file":"index27.js","sources":["../../src/services/formatters/types.ts"],"sourcesContent":["import { NetworkType } from '@hashgraphonline/standards-sdk';\n\nexport enum EntityFormat {\n TOPIC_ID = 'topicId',\n HRL = 'hrl',\n SCHEDULE_ID = 'scheduleId',\n TOKEN_ID = 'tokenId',\n ADDRESS = 'address',\n SYMBOL = 'symbol',\n SERIAL_NUMBER = 'serialNumber',\n METADATA = 'metadata',\n ACCOUNT_ID = 'accountId',\n ALIAS = 'alias',\n EVM_ADDRESS = 'evmAddress',\n CONTRACT_ID = 'contractId',\n FILE_ID = 'fileId',\n ANY = 'any'\n}\n\nexport interface ConversionContext {\n networkType?: NetworkType;\n sessionId?: string;\n toolName?: string;\n toolPreferences?: Record<string, string>;\n [key: string]: unknown;\n}\n\nexport interface FormatConverter<TSource = string, TTarget = string> {\n sourceFormat: EntityFormat;\n targetFormat: EntityFormat;\n canConvert(source: string, context: ConversionContext): boolean;\n convert(entity: TSource, context: ConversionContext): Promise<TTarget>;\n}"],"names":["EntityFormat"],"mappings":"AAEO,IAAK,iCAAAA,kBAAL;AACLA,gBAAA,UAAA,IAAW;AACXA,gBAAA,KAAA,IAAM;AACNA,gBAAA,aAAA,IAAc;AACdA,gBAAA,UAAA,IAAW;AACXA,gBAAA,SAAA,IAAU;AACVA,gBAAA,QAAA,IAAS;AACTA,gBAAA,eAAA,IAAgB;AAChBA,gBAAA,UAAA,IAAW;AACXA,gBAAA,YAAA,IAAa;AACbA,gBAAA,OAAA,IAAQ;AACRA,gBAAA,aAAA,IAAc;AACdA,gBAAA,aAAA,IAAc;AACdA,gBAAA,SAAA,IAAU;AACVA,gBAAA,KAAA,IAAM;AAdI,SAAAA;AAAA,GAAA,gBAAA,CAAA,CAAA;"}