@hashgraphonline/conversational-agent 0.2.215 → 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 (310) 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/index48.js +67 -85
  117. package/dist/esm/index48.js.map +1 -1
  118. package/dist/esm/index49.js +75 -0
  119. package/dist/esm/index49.js.map +1 -0
  120. package/dist/esm/index5.js +2 -2
  121. package/dist/esm/index50.js +57 -0
  122. package/dist/esm/index50.js.map +1 -0
  123. package/dist/esm/index51.js +103 -0
  124. package/dist/esm/index51.js.map +1 -0
  125. package/dist/esm/index52.js +79 -0
  126. package/dist/esm/index52.js.map +1 -0
  127. package/dist/esm/index53.js +75 -0
  128. package/dist/esm/index53.js.map +1 -0
  129. package/dist/esm/index54.js +124 -0
  130. package/dist/esm/index54.js.map +1 -0
  131. package/dist/esm/index55.js +58 -0
  132. package/dist/esm/index55.js.map +1 -0
  133. package/dist/esm/index56.js +83 -0
  134. package/dist/esm/index56.js.map +1 -0
  135. package/dist/esm/index57.js +100 -0
  136. package/dist/esm/index57.js.map +1 -0
  137. package/dist/esm/index58.js +118 -0
  138. package/dist/esm/index58.js.map +1 -0
  139. package/dist/esm/index59.js +108 -0
  140. package/dist/esm/index59.js.map +1 -0
  141. package/dist/esm/index6.js +132 -833
  142. package/dist/esm/index6.js.map +1 -1
  143. package/dist/esm/index60.js +30 -0
  144. package/dist/esm/index60.js.map +1 -0
  145. package/dist/esm/index61.js +98 -0
  146. package/dist/esm/index61.js.map +1 -0
  147. package/dist/esm/index62.js +131 -0
  148. package/dist/esm/index62.js.map +1 -0
  149. package/dist/esm/index63.js +19 -0
  150. package/dist/esm/index63.js.map +1 -0
  151. package/dist/esm/index7.js +826 -75
  152. package/dist/esm/index7.js.map +1 -1
  153. package/dist/esm/index8.js +91 -13
  154. package/dist/esm/index8.js.map +1 -1
  155. package/dist/esm/index9.js +13 -17
  156. package/dist/esm/index9.js.map +1 -1
  157. package/dist/types/index.d.ts +1 -0
  158. package/dist/types/plugins/community/swarm/SwarmPlugin.d.ts +17 -0
  159. package/dist/types/plugins/community/swarm/__tests__/SwarmPlugin.mocks.d.ts +1 -0
  160. package/dist/types/plugins/community/swarm/__tests__/SwarmPlugin.test.d.ts +1 -0
  161. package/dist/types/plugins/community/swarm/__tests__/tools/CreatePostageStampTool.test.d.ts +1 -0
  162. package/dist/types/plugins/community/swarm/__tests__/tools/DownloadDataTool.test.d.ts +1 -0
  163. package/dist/types/plugins/community/swarm/__tests__/tools/DownloadFilesTool.test.d.ts +1 -0
  164. package/dist/types/plugins/community/swarm/__tests__/tools/ExtendPostageStampTool.test.d.ts +1 -0
  165. package/dist/types/plugins/community/swarm/__tests__/tools/GetPostageStampTool.test.d.ts +1 -0
  166. package/dist/types/plugins/community/swarm/__tests__/tools/ListPostageStampsTool.test.d.ts +1 -0
  167. package/dist/types/plugins/community/swarm/__tests__/tools/QueryUploadProgressTool.test.d.ts +1 -0
  168. package/dist/types/plugins/community/swarm/__tests__/tools/ReadFeedTool.test.d.ts +1 -0
  169. package/dist/types/plugins/community/swarm/__tests__/tools/SwarmTool.mocks.d.ts +14 -0
  170. package/dist/types/plugins/community/swarm/__tests__/tools/UpdateFeedTool.test.d.ts +1 -0
  171. package/dist/types/plugins/community/swarm/__tests__/tools/UploadDataTool.test.d.ts +1 -0
  172. package/dist/types/plugins/community/swarm/__tests__/tools/UploadFileTool.test.d.ts +1 -0
  173. package/dist/types/plugins/community/swarm/__tests__/tools/UploadFolderTool.test.d.ts +1 -0
  174. package/dist/types/plugins/community/swarm/config.d.ts +6 -0
  175. package/dist/types/plugins/community/swarm/constants.d.ts +8 -0
  176. package/dist/types/plugins/community/swarm/index.d.ts +2 -0
  177. package/dist/types/plugins/community/swarm/model.d.ts +23 -0
  178. package/dist/types/plugins/community/swarm/tools/CreatePostageStampTool.d.ts +47 -0
  179. package/dist/types/plugins/community/swarm/tools/DownloadDataTool.d.ts +35 -0
  180. package/dist/types/plugins/community/swarm/tools/DownloadFilesTool.d.ts +41 -0
  181. package/dist/types/plugins/community/swarm/tools/ExtendPostageStampTool.d.ts +47 -0
  182. package/dist/types/plugins/community/swarm/tools/GetPostageStampTool.d.ts +35 -0
  183. package/dist/types/plugins/community/swarm/tools/ListPostageStampsTool.d.ts +53 -0
  184. package/dist/types/plugins/community/swarm/tools/QueryUploadProgressTool.d.ts +35 -0
  185. package/dist/types/plugins/community/swarm/tools/ReadFeedTool.d.ts +41 -0
  186. package/dist/types/plugins/community/swarm/tools/UpdateFeedTool.d.ts +47 -0
  187. package/dist/types/plugins/community/swarm/tools/UploadDataTool.d.ts +47 -0
  188. package/dist/types/plugins/community/swarm/tools/UploadFileTool.d.ts +53 -0
  189. package/dist/types/plugins/community/swarm/tools/UploadFolderTool.d.ts +47 -0
  190. package/dist/types/plugins/community/swarm/utils.d.ts +22 -0
  191. package/dist/types/plugins/index.d.ts +1 -0
  192. package/package.json +37 -27
  193. package/src/index.ts +1 -0
  194. package/src/plugins/community/swarm/README.md +279 -0
  195. package/src/plugins/community/swarm/SwarmPlugin.ts +178 -0
  196. package/src/plugins/community/swarm/__tests__/SwarmPlugin.mocks.ts +105 -0
  197. package/src/plugins/community/swarm/__tests__/SwarmPlugin.test.ts +93 -0
  198. package/src/plugins/community/swarm/__tests__/tools/CreatePostageStampTool.test.ts +152 -0
  199. package/src/plugins/community/swarm/__tests__/tools/DownloadDataTool.test.ts +93 -0
  200. package/src/plugins/community/swarm/__tests__/tools/DownloadFilesTool.test.ts +163 -0
  201. package/src/plugins/community/swarm/__tests__/tools/ExtendPostageStampTool.test.ts +132 -0
  202. package/src/plugins/community/swarm/__tests__/tools/GetPostageStampTool.test.ts +83 -0
  203. package/src/plugins/community/swarm/__tests__/tools/ListPostageStampsTool.test.ts +219 -0
  204. package/src/plugins/community/swarm/__tests__/tools/QueryUploadProgressTool.test.ts +169 -0
  205. package/src/plugins/community/swarm/__tests__/tools/ReadFeedTool.test.ts +133 -0
  206. package/src/plugins/community/swarm/__tests__/tools/SwarmTool.mocks.ts +67 -0
  207. package/src/plugins/community/swarm/__tests__/tools/UpdateFeedTool.test.ts +148 -0
  208. package/src/plugins/community/swarm/__tests__/tools/UploadDataTool.test.ts +125 -0
  209. package/src/plugins/community/swarm/__tests__/tools/UploadFileTool.test.ts +194 -0
  210. package/src/plugins/community/swarm/__tests__/tools/UploadFolderTool.test.ts +118 -0
  211. package/src/plugins/community/swarm/config.ts +6 -0
  212. package/src/plugins/community/swarm/constants.ts +12 -0
  213. package/src/plugins/community/swarm/index.ts +2 -0
  214. package/src/plugins/community/swarm/model.ts +23 -0
  215. package/src/plugins/community/swarm/tools/CreatePostageStampTool.ts +137 -0
  216. package/src/plugins/community/swarm/tools/DownloadDataTool.ts +79 -0
  217. package/src/plugins/community/swarm/tools/DownloadFilesTool.ts +155 -0
  218. package/src/plugins/community/swarm/tools/ExtendPostageStampTool.ts +112 -0
  219. package/src/plugins/community/swarm/tools/GetPostageStampTool.ts +92 -0
  220. package/src/plugins/community/swarm/tools/ListPostageStampsTool.ts +124 -0
  221. package/src/plugins/community/swarm/tools/QueryUploadProgressTool.ts +109 -0
  222. package/src/plugins/community/swarm/tools/ReadFeedTool.ts +110 -0
  223. package/src/plugins/community/swarm/tools/UpdateFeedTool.ts +149 -0
  224. package/src/plugins/community/swarm/tools/UploadDataTool.ts +109 -0
  225. package/src/plugins/community/swarm/tools/UploadFileTool.ts +163 -0
  226. package/src/plugins/community/swarm/tools/UploadFolderTool.ts +150 -0
  227. package/src/plugins/community/swarm/utils.ts +172 -0
  228. package/src/plugins/index.ts +1 -0
  229. package/cli/dist/CLIApp.d.ts +0 -11
  230. package/cli/dist/CLIApp.d.ts.map +0 -1
  231. package/cli/dist/CLIApp.js +0 -128
  232. package/cli/dist/CLIApp.js.map +0 -1
  233. package/cli/dist/LocalConversationalAgent.d.ts +0 -37
  234. package/cli/dist/LocalConversationalAgent.js +0 -58
  235. package/cli/dist/app.d.ts +0 -18
  236. package/cli/dist/app.d.ts.map +0 -1
  237. package/cli/dist/app.js +0 -14
  238. package/cli/dist/app.js.map +0 -1
  239. package/cli/dist/cli.d.ts +0 -3
  240. package/cli/dist/cli.d.ts.map +0 -1
  241. package/cli/dist/cli.js +0 -87
  242. package/cli/dist/cli.js.map +0 -1
  243. package/cli/dist/components/AppContainer.d.ts +0 -16
  244. package/cli/dist/components/AppContainer.js +0 -24
  245. package/cli/dist/components/AppScreens.d.ts +0 -2
  246. package/cli/dist/components/AppScreens.js +0 -259
  247. package/cli/dist/components/ChatScreen.d.ts +0 -21
  248. package/cli/dist/components/ChatScreen.d.ts.map +0 -1
  249. package/cli/dist/components/ChatScreen.js +0 -40
  250. package/cli/dist/components/ChatScreen.js.map +0 -1
  251. package/cli/dist/components/DebugLoadingScreen.d.ts +0 -5
  252. package/cli/dist/components/DebugLoadingScreen.js +0 -31
  253. package/cli/dist/components/LoadingScreen.d.ts +0 -3
  254. package/cli/dist/components/LoadingScreen.d.ts.map +0 -1
  255. package/cli/dist/components/LoadingScreen.js +0 -17
  256. package/cli/dist/components/LoadingScreen.js.map +0 -1
  257. package/cli/dist/components/LoadingScreenDebug.d.ts +0 -5
  258. package/cli/dist/components/LoadingScreenDebug.js +0 -27
  259. package/cli/dist/components/MCPConfigScreen.d.ts +0 -28
  260. package/cli/dist/components/MCPConfigScreen.d.ts.map +0 -1
  261. package/cli/dist/components/MCPConfigScreen.js +0 -186
  262. package/cli/dist/components/MCPConfigScreen.js.map +0 -1
  263. package/cli/dist/components/ScreenRouter.d.ts +0 -13
  264. package/cli/dist/components/ScreenRouter.d.ts.map +0 -1
  265. package/cli/dist/components/ScreenRouter.js +0 -23
  266. package/cli/dist/components/ScreenRouter.js.map +0 -1
  267. package/cli/dist/components/SetupScreen.d.ts +0 -16
  268. package/cli/dist/components/SetupScreen.d.ts.map +0 -1
  269. package/cli/dist/components/SetupScreen.js +0 -67
  270. package/cli/dist/components/SetupScreen.js.map +0 -1
  271. package/cli/dist/components/SingleLoadingScreen.d.ts +0 -5
  272. package/cli/dist/components/SingleLoadingScreen.js +0 -27
  273. package/cli/dist/components/StatusBadge.d.ts +0 -10
  274. package/cli/dist/components/StatusBadge.d.ts.map +0 -1
  275. package/cli/dist/components/StatusBadge.js +0 -24
  276. package/cli/dist/components/StatusBadge.js.map +0 -1
  277. package/cli/dist/components/TerminalWindow.d.ts +0 -9
  278. package/cli/dist/components/TerminalWindow.d.ts.map +0 -1
  279. package/cli/dist/components/TerminalWindow.js +0 -19
  280. package/cli/dist/components/TerminalWindow.js.map +0 -1
  281. package/cli/dist/components/WelcomeScreen.d.ts +0 -12
  282. package/cli/dist/components/WelcomeScreen.d.ts.map +0 -1
  283. package/cli/dist/components/WelcomeScreen.js +0 -47
  284. package/cli/dist/components/WelcomeScreen.js.map +0 -1
  285. package/cli/dist/context/AppContext.d.ts +0 -68
  286. package/cli/dist/context/AppContext.js +0 -363
  287. package/cli/dist/headless-runner.d.ts +0 -17
  288. package/cli/dist/headless-runner.d.ts.map +0 -1
  289. package/cli/dist/headless-runner.js +0 -128
  290. package/cli/dist/headless-runner.js.map +0 -1
  291. package/cli/dist/hooks/useInitializeAgent.d.ts +0 -19
  292. package/cli/dist/hooks/useInitializeAgent.d.ts.map +0 -1
  293. package/cli/dist/hooks/useInitializeAgent.js +0 -29
  294. package/cli/dist/hooks/useInitializeAgent.js.map +0 -1
  295. package/cli/dist/hooks/useStableState.d.ts +0 -38
  296. package/cli/dist/hooks/useStableState.d.ts.map +0 -1
  297. package/cli/dist/hooks/useStableState.js +0 -69
  298. package/cli/dist/hooks/useStableState.js.map +0 -1
  299. package/cli/dist/managers/AgentManager.d.ts +0 -58
  300. package/cli/dist/managers/AgentManager.d.ts.map +0 -1
  301. package/cli/dist/managers/AgentManager.js +0 -121
  302. package/cli/dist/managers/AgentManager.js.map +0 -1
  303. package/cli/dist/managers/ConfigManager.d.ts +0 -54
  304. package/cli/dist/managers/ConfigManager.d.ts.map +0 -1
  305. package/cli/dist/managers/ConfigManager.js +0 -188
  306. package/cli/dist/managers/ConfigManager.js.map +0 -1
  307. package/cli/dist/types.d.ts +0 -52
  308. package/cli/dist/types.d.ts.map +0 -1
  309. package/cli/dist/types.js +0 -34
  310. package/cli/dist/types.js.map +0 -1
@@ -1,319 +1,686 @@
1
- import { ZodError } from "zod";
1
+ import { zodToJsonSchema } from "zod-to-json-schema";
2
+ import { extractRenderConfigs, generateFieldOrdering } from "@hashgraphonline/standards-agent-kit";
2
3
  import { Logger } from "@hashgraphonline/standards-sdk";
3
- import { FormGenerator } from "./index10.js";
4
- import { isFormValidatable } from "@hashgraphonline/standards-agent-kit";
5
- class FormEngine {
6
- constructor(logger) {
7
- this.formGenerator = new FormGenerator();
8
- this.logger = logger || new Logger({ module: "FormEngine" });
4
+ import { fieldTypeRegistry } from "./index13.js";
5
+ import { fieldGuidanceRegistry } from "./index14.js";
6
+ import "./index44.js";
7
+ import { FIELD_PRIORITIES } from "./index47.js";
8
+ function isZodObjectSchema(schema) {
9
+ return typeof schema === "object" && schema !== null && "shape" in schema;
10
+ }
11
+ class FormGenerator {
12
+ constructor() {
13
+ this.logger = new Logger({ module: "FormGenerator" });
9
14
  }
10
15
  /**
11
- * Generate a form for a tool with the given input
16
+ * Creates a form message from a Zod validation error
17
+ * @param error The Zod validation error
18
+ * @param schema The original Zod schema
19
+ * @param toolName Name of the tool that failed validation
20
+ * @param originalPrompt The user's original request
21
+ * @returns FormMessage to send to the chat UI
12
22
  */
13
- async generateForm(toolName, tool, input, context) {
14
- const fullContext = {
15
- tool,
16
- input,
17
- ...context
23
+ generateFormFromError(error, schema, toolName, originalPrompt) {
24
+ const validationErrors = this.extractValidationErrors(error);
25
+ const missingFields = this.identifyMissingFields(validationErrors, schema);
26
+ const formConfig = this.createFormConfig(schema, missingFields, toolName);
27
+ return {
28
+ type: "form",
29
+ id: `form_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
30
+ formConfig,
31
+ originalPrompt,
32
+ toolName,
33
+ validationErrors
18
34
  };
19
- try {
20
- if (isFormValidatable(tool)) {
21
- return await this.generateFormValidatableForm(tool, input, fullContext);
22
- }
23
- if (input instanceof ZodError) {
24
- return await this.generateErrorBasedForm(tool, input, fullContext);
25
- }
26
- if (this.hasRenderConfig(tool)) {
27
- return await this.generateRenderConfigForm(tool, input, fullContext);
28
- }
29
- if (this.isZodObject(tool.schema)) {
30
- return await this.generateSchemaBasedForm(tool, input, fullContext);
35
+ }
36
+ /**
37
+ * Generates a form from a schema and partial input
38
+ * @param schema The Zod schema to generate a form from
39
+ * @param partialInput Any partial input already provided
40
+ * @param context Additional context about the tool
41
+ * @param preCalculatedMissingFields Optional pre-calculated missing fields set. If undefined, includes all fields from schema.
42
+ * @returns FormMessage to send to the chat UI
43
+ */
44
+ async generateFormFromSchema(schema, partialInput, context, preCalculatedMissingFields) {
45
+ let missingFields;
46
+ this.logger.info(`🏁 FormGenerator.generateFormFromSchema starting`, {
47
+ toolName: context.toolName,
48
+ partialInput,
49
+ hasSchema: !!schema,
50
+ hasShape: !!(schema && isZodObjectSchema(schema)),
51
+ hasPreCalculatedFields: preCalculatedMissingFields !== void 0,
52
+ preCalculatedFieldsSize: preCalculatedMissingFields?.size || 0
53
+ });
54
+ if (preCalculatedMissingFields !== void 0) {
55
+ missingFields = preCalculatedMissingFields;
56
+ this.logger.info(`📋 Using pre-calculated missing fields`, {
57
+ missingFieldsCount: missingFields.size,
58
+ missingFields: Array.from(missingFields)
59
+ });
60
+ } else {
61
+ missingFields = /* @__PURE__ */ new Set();
62
+ const zodObject = this.extractZodObject(schema);
63
+ if (zodObject) {
64
+ const shape = zodObject.shape;
65
+ for (const fieldName of Object.keys(shape)) {
66
+ missingFields.add(fieldName);
67
+ this.logger.info(
68
+ `⭐ Including all fields from focused schema: ${fieldName}`
69
+ );
70
+ }
31
71
  }
32
- return null;
33
- } catch (error) {
34
- this.logger.error(`Failed to generate form for tool: ${toolName}`, {
35
- error: error instanceof Error ? error.message : String(error)
72
+ this.logger.info(`📋 Using ALL fields from focused schema`, {
73
+ totalFields: zodObject ? Object.keys(zodObject.shape).length : 0,
74
+ missingFieldsCount: missingFields.size,
75
+ missingFields: Array.from(missingFields)
36
76
  });
37
- throw error;
38
77
  }
78
+ const formConfig = this.createFormConfig(
79
+ schema,
80
+ missingFields,
81
+ context.toolName,
82
+ preCalculatedMissingFields
83
+ );
84
+ return {
85
+ type: "form",
86
+ id: `form_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
87
+ formConfig,
88
+ originalPrompt: context.toolDescription || `Complete ${context.toolName}`,
89
+ toolName: context.toolName,
90
+ validationErrors: []
91
+ };
39
92
  }
40
93
  /**
41
- * Process a form submission
94
+ * Extracts validation errors from ZodError
42
95
  */
43
- async processSubmission(submission, context) {
44
- this.validateSubmission(submission);
45
- const baseToolInput = this.extractBaseToolInput(context);
46
- const submissionData = this.extractSubmissionData(submission);
47
- return this.mergeInputData(baseToolInput, submissionData);
96
+ extractValidationErrors(error) {
97
+ return error.issues.map((issue) => ({
98
+ path: issue.path.map((p) => String(p)),
99
+ message: issue.message,
100
+ code: issue.code
101
+ }));
48
102
  }
49
103
  /**
50
- * Check if a tool requires form generation based on input
104
+ * Identifies which fields are missing or invalid from validation errors
51
105
  */
52
- shouldGenerateForm(tool, input) {
53
- const inputRecord = input;
54
- if (inputRecord?.__fromForm === true || inputRecord?.renderForm === false) {
55
- return false;
56
- }
57
- if (isFormValidatable(tool)) {
58
- try {
59
- const formValidatableTool = tool;
60
- return formValidatableTool.shouldGenerateForm(input);
61
- } catch (error) {
62
- this.logger.error(
63
- `Error calling shouldGenerateForm() on ${tool.name}:`,
64
- error
65
- );
66
- return false;
106
+ identifyMissingFields(errors, _schema) {
107
+ const missingFields = /* @__PURE__ */ new Set();
108
+ errors.forEach((error) => {
109
+ const fieldPath = error.path.join(".");
110
+ if (fieldPath) {
111
+ missingFields.add(fieldPath);
67
112
  }
68
- }
69
- const validation = this.validateInput(tool, input);
70
- return !validation.isValid;
113
+ });
114
+ return missingFields;
71
115
  }
72
116
  /**
73
- * Generate form from error context
117
+ * Creates form configuration from schema
74
118
  */
75
- async generateFormFromError(error, toolName, toolSchema, originalPrompt) {
76
- return this.formGenerator.generateFormFromError(
77
- error,
78
- toolSchema,
119
+ createFormConfig(schema, missingFields, toolName, preCalculatedMissingFields) {
120
+ const extractedConfig = this.extractRenderConfigsSafely(schema);
121
+ const fieldOrdering = this.generateFieldOrderingSafely(schema);
122
+ const fields = this.generateFormFields(
123
+ schema,
124
+ extractedConfig,
125
+ missingFields,
126
+ fieldOrdering,
127
+ preCalculatedMissingFields,
128
+ toolName
129
+ );
130
+ const globalGuidance = fieldGuidanceRegistry.getGlobalGuidance(toolName);
131
+ let description = this.generateFormDescription(
79
132
  toolName,
80
- originalPrompt
133
+ missingFields.size
81
134
  );
135
+ if (globalGuidance?.qualityStandards) {
136
+ description += "\n\nQuality Guidelines:\n" + globalGuidance.qualityStandards.map((standard) => `• ${standard}`).join("\n");
137
+ }
138
+ return {
139
+ title: this.generateFormTitle(toolName),
140
+ description,
141
+ fields,
142
+ submitLabel: "Continue",
143
+ cancelLabel: "Cancel",
144
+ metadata: {
145
+ toolName,
146
+ missingFieldCount: missingFields.size,
147
+ globalGuidance
148
+ }
149
+ };
82
150
  }
83
151
  /**
84
- * Generate form for FormValidatable tools
152
+ * Safely extracts render configs from schema
85
153
  */
86
- async generateFormValidatableForm(tool, input, _context) {
87
- const { schemaToUse, isFocusedSchema } = this.resolveFormSchema(tool);
88
- const missingFields = this.determineMissingFields(
89
- tool,
90
- input,
91
- schemaToUse,
92
- isFocusedSchema
93
- );
94
- return this.generateFormWithSchema(tool, input, schemaToUse, missingFields);
154
+ extractRenderConfigsSafely(schema) {
155
+ try {
156
+ if (typeof extractRenderConfigs === "function") {
157
+ return extractRenderConfigs(schema);
158
+ }
159
+ } catch (error) {
160
+ this.logger.warn("Could not extract render configs:", error);
161
+ }
162
+ return {
163
+ fields: {},
164
+ groups: {},
165
+ order: [],
166
+ metadata: {}
167
+ };
95
168
  }
96
169
  /**
97
- * Generate form based on schema validation
170
+ * Safely generates field ordering from schema
98
171
  */
99
- async generateSchemaBasedForm(tool, input, context) {
100
- const schema = tool.schema;
101
- const formMessage = await this.formGenerator.generateFormFromSchema(
102
- schema,
103
- input,
104
- {
105
- toolName: tool.name,
106
- toolDescription: tool.description
107
- },
108
- context.missingFields
109
- );
110
- if (this.isZodObject(schema)) {
111
- try {
112
- const { jsonSchema, uiSchema } = this.formGenerator.generateJsonSchemaForm(
113
- schema,
114
- input,
115
- context.missingFields || /* @__PURE__ */ new Set()
116
- );
117
- formMessage.jsonSchema = jsonSchema;
118
- formMessage.uiSchema = uiSchema;
119
- } catch (error) {
120
- this.logger.warn(
121
- "Failed to generate JSON Schema for schema-based tool:",
122
- error
172
+ generateFieldOrderingSafely(schema) {
173
+ try {
174
+ if (typeof generateFieldOrdering === "function") {
175
+ const ordering = generateFieldOrdering(
176
+ schema
123
177
  );
178
+ const sections = Object.values(ordering.sections).map((section) => ({
179
+ fields: section.fields
180
+ }));
181
+ return { sections };
124
182
  }
183
+ } catch (error) {
184
+ this.logger.warn("Could not generate field ordering:", error);
125
185
  }
126
- formMessage.partialInput = input;
127
- return formMessage;
186
+ return { sections: [] };
128
187
  }
129
188
  /**
130
- * Generate form based on render config
189
+ * Determines field priority for progressive disclosure
131
190
  */
132
- async generateRenderConfigForm(tool, input, context) {
133
- const schema = tool.schema;
134
- const renderConfig = this.extractRenderConfig(tool);
135
- const formMessage = await this.formGenerator.generateFormFromSchema(
136
- schema,
137
- input,
138
- {
139
- toolName: tool.name,
140
- toolDescription: tool.description
141
- },
142
- context.missingFields
143
- );
144
- if (renderConfig) {
145
- formMessage.formConfig.metadata = {
146
- ...formMessage.formConfig.metadata,
147
- renderConfig
148
- };
191
+ getFieldPriority(name, renderConfig, isRequired) {
192
+ if (renderConfig?.ui?.priority) {
193
+ const priority = renderConfig.ui.priority;
194
+ if (Object.values(FIELD_PRIORITIES).includes(priority)) {
195
+ return priority;
196
+ }
197
+ }
198
+ if (isRequired === true) {
199
+ return FIELD_PRIORITIES.ESSENTIAL;
200
+ }
201
+ const ui = renderConfig?.ui;
202
+ if (ui?.advanced === true) {
203
+ return FIELD_PRIORITIES.ADVANCED;
149
204
  }
150
- formMessage.partialInput = input;
151
- return formMessage;
205
+ if (ui?.expert === true) {
206
+ return FIELD_PRIORITIES.EXPERT;
207
+ }
208
+ return FIELD_PRIORITIES.COMMON;
152
209
  }
153
210
  /**
154
- * Generate form from Zod validation error
211
+ * Determines which fields should be included in the form
155
212
  */
156
- async generateErrorBasedForm(tool, error, context) {
157
- return this.formGenerator.generateFormFromError(
158
- error,
159
- tool.schema,
160
- tool.name,
161
- context.input ? String(context.input) : ""
162
- );
213
+ determineFieldsToInclude(schema, missingFields, preCalculatedMissingFields) {
214
+ const fieldsToInclude = /* @__PURE__ */ new Set();
215
+ if (preCalculatedMissingFields === void 0) {
216
+ this.logger.info(
217
+ `⭐ Focused schema mode - including ALL fields from schema`
218
+ );
219
+ const allSchemaFields = this.extractFieldsFromSchema(schema);
220
+ allSchemaFields.forEach((fieldName) => {
221
+ fieldsToInclude.add(fieldName);
222
+ this.logger.info(`✅ Including focused schema field: ${fieldName}`);
223
+ });
224
+ } else if (preCalculatedMissingFields.size > 0) {
225
+ this.logger.info(
226
+ `📋 Using ONLY pre-calculated missing fields (${preCalculatedMissingFields.size} fields)`,
227
+ { fields: Array.from(preCalculatedMissingFields) }
228
+ );
229
+ preCalculatedMissingFields.forEach((fieldName) => {
230
+ fieldsToInclude.add(fieldName);
231
+ this.logger.info(`✅ Including pre-calculated field: ${fieldName}`);
232
+ });
233
+ } else {
234
+ this.logger.info(
235
+ "⚠️ No pre-calculated fields, falling back to schema analysis"
236
+ );
237
+ this.includeRequiredMissingFields(schema, missingFields, fieldsToInclude);
238
+ }
239
+ return fieldsToInclude;
163
240
  }
164
241
  /**
165
- * Validate input against tool schema
242
+ * Includes required fields that are missing
166
243
  */
167
- validateInput(tool, input) {
168
- try {
169
- const zodSchema = tool.schema;
170
- zodSchema.parse(input);
171
- return { isValid: true };
172
- } catch (error) {
173
- if (error instanceof ZodError) {
174
- const errors = error.errors.map(
175
- (err) => `${err.path.join(".")}: ${err.message}`
176
- );
177
- return { isValid: false, errors };
244
+ includeRequiredMissingFields(schema, missingFields, fieldsToInclude) {
245
+ const allSchemaFields = this.extractFieldsFromSchema(schema);
246
+ allSchemaFields.forEach((fieldName) => {
247
+ const isRequired = this.isFieldRequired(schema, fieldName);
248
+ const isMissing = missingFields.has(fieldName);
249
+ const shouldInclude = isMissing && isRequired;
250
+ this.logger.info(`🔍 FormGenerator field inclusion check: ${fieldName}`, {
251
+ isRequired,
252
+ isMissing,
253
+ shouldInclude
254
+ });
255
+ if (shouldInclude) {
256
+ fieldsToInclude.add(fieldName);
178
257
  }
179
- return { isValid: false, errors: ["Validation failed"] };
180
- }
258
+ });
181
259
  }
182
260
  /**
183
- * Check if schema is ZodObject
261
+ * Creates form fields from ordered field names
184
262
  */
185
- isZodObject(schema) {
186
- if (!schema || typeof schema !== "object") {
187
- return false;
263
+ createOrderedFields(fieldsToInclude, fieldOrdering, extractedConfig, schema, toolName) {
264
+ const fields = [];
265
+ const processedFields = /* @__PURE__ */ new Set();
266
+ if (fieldOrdering.sections.length > 0) {
267
+ const orderedFieldNames = fieldOrdering.sections.flatMap((s) => s.fields);
268
+ orderedFieldNames.forEach((fieldName) => {
269
+ if (fieldsToInclude.has(fieldName) && !processedFields.has(fieldName)) {
270
+ const field = this.createFormField(
271
+ fieldName,
272
+ extractedConfig.fields[fieldName],
273
+ schema,
274
+ fieldName,
275
+ toolName
276
+ );
277
+ if (field) {
278
+ fields.push(field);
279
+ processedFields.add(fieldName);
280
+ }
281
+ }
282
+ });
188
283
  }
189
- const candidate = schema;
190
- return Boolean(candidate._def && candidate._def.typeName === "ZodObject");
191
- }
192
- /**
193
- * Check if tool has render configuration
194
- */
195
- hasRenderConfig(tool) {
196
- const schema = tool.schema;
197
- return !!(schema && schema._renderConfig);
284
+ fieldsToInclude.forEach((fieldName) => {
285
+ if (!processedFields.has(fieldName)) {
286
+ const field = this.createFormField(
287
+ fieldName,
288
+ extractedConfig.fields[fieldName],
289
+ schema,
290
+ fieldName,
291
+ toolName
292
+ );
293
+ if (field) {
294
+ fields.push(field);
295
+ }
296
+ }
297
+ });
298
+ return fields;
198
299
  }
199
300
  /**
200
- * Extract render configuration from tool
301
+ * Generates form fields from schema and validation errors
201
302
  */
202
- extractRenderConfig(tool) {
203
- const schema = tool.schema;
204
- return schema?._renderConfig;
303
+ generateFormFields(schema, extractedConfig, missingFields, fieldOrdering, preCalculatedMissingFields, toolName) {
304
+ const fieldsToInclude = this.determineFieldsToInclude(
305
+ schema,
306
+ missingFields,
307
+ preCalculatedMissingFields
308
+ );
309
+ let fields = this.createOrderedFields(
310
+ fieldsToInclude,
311
+ fieldOrdering,
312
+ extractedConfig,
313
+ schema,
314
+ toolName
315
+ );
316
+ if (fields.length === 0 && missingFields.size > 0) {
317
+ fields = Array.from(missingFields).map(
318
+ (fieldName) => this.createFormField(
319
+ fieldName,
320
+ extractedConfig.fields[fieldName],
321
+ schema,
322
+ fieldName,
323
+ toolName
324
+ )
325
+ ).filter(
326
+ (field) => field !== null && field !== void 0
327
+ );
328
+ }
329
+ return fields;
205
330
  }
206
331
  /**
207
- * Resolve form schema for FormValidatable tools
332
+ * Creates a single form field
208
333
  */
209
- resolveFormSchema(tool) {
210
- const formValidatableTool = tool;
211
- if (formValidatableTool.getFormSchema) {
212
- const focusedSchema = formValidatableTool.getFormSchema();
213
- if (focusedSchema) {
214
- return { schemaToUse: focusedSchema, isFocusedSchema: true };
334
+ createFormField(fieldName, renderConfig, schema, fieldPath, toolName) {
335
+ const type = this.mapFieldType(renderConfig?.fieldType, schema, fieldPath);
336
+ const isRequired = this.isFieldRequired(schema, fieldPath || fieldName);
337
+ const guidance = toolName ? fieldGuidanceRegistry.getFieldGuidance(toolName, fieldName) : null;
338
+ const finalType = guidance?.fieldTypeOverride || type;
339
+ const field = {
340
+ name: fieldName,
341
+ label: renderConfig?.ui?.label || this.humanizeFieldName(fieldName),
342
+ type: finalType,
343
+ required: isRequired,
344
+ priority: this.getFieldPriority(fieldName, renderConfig, isRequired)
345
+ };
346
+ if (guidance) {
347
+ if (guidance.suggestions && guidance.suggestions.length > 0) {
348
+ field.suggestions = guidance.suggestions;
349
+ if (!field.placeholder) {
350
+ field.placeholder = `e.g., ${guidance.suggestions[0]}`;
351
+ }
352
+ }
353
+ if (guidance.predefinedOptions) {
354
+ field.options = [
355
+ ...field.options || [],
356
+ ...guidance.predefinedOptions
357
+ ];
358
+ }
359
+ if (guidance.contextualHelpText) {
360
+ field.helpText = guidance.contextualHelpText;
361
+ }
362
+ if (guidance.warnings) {
363
+ field.warnings = guidance.warnings.map((w) => w.message);
364
+ }
365
+ if (guidance.validationRules) {
366
+ const { qualityChecks } = guidance.validationRules;
367
+ if (qualityChecks) {
368
+ field.contextualGuidance = {
369
+ qualityStandards: [],
370
+ examples: guidance.suggestions || [],
371
+ avoidPatterns: qualityChecks.forbidTechnicalTerms || []
372
+ };
373
+ if (qualityChecks.minNonTechnicalWords) {
374
+ field.contextualGuidance.qualityStandards?.push(
375
+ `Use at least ${qualityChecks.minNonTechnicalWords} meaningful words`
376
+ );
377
+ }
378
+ if (qualityChecks.forbidTechnicalTerms) {
379
+ field.contextualGuidance.qualityStandards?.push(
380
+ `Avoid technical terms like: ${qualityChecks.forbidTechnicalTerms.join(
381
+ ", "
382
+ )}`
383
+ );
384
+ }
385
+ }
386
+ }
387
+ }
388
+ if (renderConfig) {
389
+ field.renderConfig = renderConfig;
390
+ }
391
+ if (renderConfig?.ui?.placeholder) {
392
+ field.placeholder = renderConfig.ui.placeholder;
393
+ }
394
+ if (renderConfig?.ui?.helpText) {
395
+ field.helpText = renderConfig.ui.helpText;
396
+ }
397
+ if (renderConfig?.constraints) {
398
+ const validation = {};
399
+ if (renderConfig.constraints.min !== void 0)
400
+ validation.min = renderConfig.constraints.min;
401
+ if (renderConfig.constraints.max !== void 0)
402
+ validation.max = renderConfig.constraints.max;
403
+ if (renderConfig.constraints.minLength !== void 0)
404
+ validation.minLength = renderConfig.constraints.minLength;
405
+ if (renderConfig.constraints.maxLength !== void 0)
406
+ validation.maxLength = renderConfig.constraints.maxLength;
407
+ if (renderConfig.constraints.pattern !== void 0)
408
+ validation.pattern = renderConfig.constraints.pattern;
409
+ if (Object.keys(validation).length > 0) {
410
+ field.validation = validation;
215
411
  }
216
412
  }
217
- return { schemaToUse: tool.schema, isFocusedSchema: false };
413
+ if (renderConfig?.options) {
414
+ field.options = renderConfig.options.map((opt) => ({
415
+ value: String(opt.value),
416
+ label: opt.label,
417
+ ...opt.disabled !== void 0 && { disabled: opt.disabled }
418
+ }));
419
+ }
420
+ return field;
218
421
  }
219
422
  /**
220
- * Determine missing fields for form generation
423
+ * Maps render config field type to form field type with fallback inference
221
424
  */
222
- determineMissingFields(tool, input, _schema, _isFocusedSchema) {
223
- const missingFields = /* @__PURE__ */ new Set();
224
- if (!input || typeof input !== "object") {
225
- return missingFields;
425
+ mapFieldType(fieldType, schema, fieldPath) {
426
+ if (!fieldType && schema && fieldPath) {
427
+ const inferredType = this.inferTypeFromSchema(schema, fieldPath);
428
+ if (inferredType) {
429
+ return inferredType;
430
+ }
226
431
  }
227
- const inputRecord = input;
228
- const formValidatableTool = tool;
229
- if (formValidatableTool.getEssentialFields) {
230
- const essentialFields = formValidatableTool.getEssentialFields();
231
- for (const field of essentialFields) {
232
- if (!(field in inputRecord) || formValidatableTool.isFieldEmpty && formValidatableTool.isFieldEmpty(field, inputRecord[field])) {
233
- missingFields.add(field);
234
- }
432
+ if (!fieldType && fieldPath) {
433
+ const registryType = fieldTypeRegistry.detectType(fieldPath);
434
+ if (registryType) {
435
+ return registryType;
235
436
  }
236
437
  }
237
- return missingFields;
438
+ if (!fieldType) {
439
+ return "text";
440
+ }
441
+ const normalizedType = fieldType.toLowerCase();
442
+ if (["text", "string"].includes(normalizedType)) return "text";
443
+ if (["number", "integer", "float", "decimal"].includes(normalizedType))
444
+ return "number";
445
+ if (["select", "enum", "dropdown"].includes(normalizedType))
446
+ return "select";
447
+ if (["checkbox", "boolean", "bool"].includes(normalizedType))
448
+ return "checkbox";
449
+ if (["textarea", "longtext", "multiline"].includes(normalizedType))
450
+ return "textarea";
451
+ if (["file", "upload", "attachment"].includes(normalizedType))
452
+ return "file";
453
+ if (["array", "list"].includes(normalizedType)) return "array";
454
+ if (["object", "json"].includes(normalizedType)) return "object";
455
+ if (["currency", "money", "price"].includes(normalizedType))
456
+ return "currency";
457
+ if (["percentage", "percent"].includes(normalizedType)) return "percentage";
458
+ return "text";
238
459
  }
239
460
  /**
240
- * Generate form with resolved schema
461
+ * Converts field name to human-readable label
241
462
  */
242
- async generateFormWithSchema(tool, input, schema, missingFields) {
243
- const formMessage = await this.formGenerator.generateFormFromSchema(
244
- schema,
245
- input,
246
- {
247
- toolName: tool.name,
248
- toolDescription: tool.description
249
- },
250
- missingFields
251
- );
252
- if (this.isZodObject(schema)) {
253
- try {
254
- const { jsonSchema, uiSchema } = this.formGenerator.generateJsonSchemaForm(
255
- schema,
256
- input,
257
- missingFields
258
- );
259
- formMessage.jsonSchema = jsonSchema;
260
- formMessage.uiSchema = uiSchema;
261
- } catch (error) {
262
- this.logger.warn("Failed to generate JSON Schema:", error);
263
- }
264
- }
265
- formMessage.partialInput = input;
266
- return formMessage;
463
+ humanizeFieldName(fieldName) {
464
+ return fieldName.replace(/([A-Z])/g, " $1").replace(/_/g, " ").replace(/\./g, " ").trim().split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
267
465
  }
268
466
  /**
269
- * Validate form submission
467
+ * Generates a title for the form
270
468
  */
271
- validateSubmission(submission) {
272
- if (!submission.toolName) {
273
- throw new Error("Tool name is required in form submission");
274
- }
275
- if (!submission.parameters) {
276
- throw new Error("Parameters are required in form submission");
469
+ generateFormTitle(toolName) {
470
+ const cleanName = toolName.replace(/Tool$/, "").replace(/Hedera/g, "").replace(/([A-Z])/g, " $1").trim();
471
+ return `Complete ${cleanName} Information`;
472
+ }
473
+ /**
474
+ * Safely extracts ZodObject from a schema, returns null if not an object schema
475
+ */
476
+ extractZodObject(schema) {
477
+ try {
478
+ const def = schema._def;
479
+ if (def && def.typeName === "ZodObject") {
480
+ return schema;
481
+ }
482
+ } catch (error) {
483
+ this.logger.debug("Could not extract ZodObject from schema:", error);
277
484
  }
485
+ return null;
278
486
  }
279
487
  /**
280
- * Extract base tool input from context
488
+ * Extracts field names from Zod schema structure
281
489
  */
282
- extractBaseToolInput(context) {
283
- return context?.originalInput || {};
490
+ extractFieldsFromSchema(schema) {
491
+ const fields = [];
492
+ const zodObject = this.extractZodObject(schema);
493
+ if (zodObject) {
494
+ fields.push(...Object.keys(zodObject.shape));
495
+ return fields;
496
+ }
497
+ try {
498
+ const def = schema._def;
499
+ if (def && def.typeName === "ZodUnion" && def.options) {
500
+ const firstOption = def.options[0];
501
+ const firstOptionObject = this.extractZodObject(firstOption);
502
+ if (firstOptionObject) {
503
+ fields.push(...Object.keys(firstOptionObject.shape));
504
+ }
505
+ }
506
+ } catch (error) {
507
+ this.logger.debug(
508
+ "Could not extract fields from schema structure:",
509
+ error
510
+ );
511
+ }
512
+ return fields;
284
513
  }
285
514
  /**
286
- * Extract submission data
515
+ * Infers field type from Zod schema
287
516
  */
288
- extractSubmissionData(submission) {
289
- return {
290
- ...submission.parameters,
291
- __fromForm: true
292
- };
517
+ inferTypeFromSchema(schema, fieldPath) {
518
+ try {
519
+ const zodObject = this.extractZodObject(schema);
520
+ if (!zodObject) return null;
521
+ const shape = zodObject.shape;
522
+ if (!shape) return null;
523
+ let fieldSchema = shape[fieldPath];
524
+ if (!fieldSchema) return null;
525
+ const fieldDef = fieldSchema._def;
526
+ if (fieldDef && fieldDef.typeName === "ZodOptional" && fieldDef.innerType) {
527
+ fieldSchema = fieldDef.innerType;
528
+ }
529
+ if (!fieldSchema || !fieldSchema._def) return null;
530
+ const typeDef = fieldSchema._def;
531
+ const fieldTypeName = typeDef.typeName;
532
+ const lowerPath = fieldPath.toLowerCase();
533
+ switch (fieldTypeName) {
534
+ case "ZodString":
535
+ if (lowerPath.includes("memo") || lowerPath.includes("description")) {
536
+ return "textarea";
537
+ }
538
+ return "text";
539
+ case "ZodNumber":
540
+ if (lowerPath.includes("percent")) {
541
+ return "percentage";
542
+ }
543
+ if (lowerPath.includes("price") || lowerPath.includes("cost")) {
544
+ return "currency";
545
+ }
546
+ return "number";
547
+ case "ZodBoolean":
548
+ return "checkbox";
549
+ case "ZodEnum":
550
+ case "ZodNativeEnum":
551
+ return "select";
552
+ case "ZodArray":
553
+ return "array";
554
+ case "ZodObject":
555
+ return "object";
556
+ default:
557
+ return "text";
558
+ }
559
+ } catch (error) {
560
+ this.logger.debug("Could not infer type from schema:", error);
561
+ }
562
+ return null;
293
563
  }
294
564
  /**
295
- * Merge input data
565
+ * Determines if a field is required based on the Zod schema
296
566
  */
297
- mergeInputData(baseInput, submissionData) {
298
- return {
299
- ...baseInput,
300
- ...submissionData
301
- };
567
+ isFieldRequired(schema, fieldPath) {
568
+ if (!schema || !fieldPath) {
569
+ return false;
570
+ }
571
+ try {
572
+ const zodObject = this.extractZodObject(schema);
573
+ if (!zodObject) return false;
574
+ const shape = zodObject.shape;
575
+ if (!shape || !shape[fieldPath]) return false;
576
+ const fieldSchema = shape[fieldPath];
577
+ if (!fieldSchema || !fieldSchema._def) return true;
578
+ const fieldDef = fieldSchema._def;
579
+ const typeName = fieldDef.typeName;
580
+ if (typeName === "ZodOptional") {
581
+ return false;
582
+ }
583
+ if (typeName === "ZodDefault") {
584
+ return false;
585
+ }
586
+ if (fieldDef.defaultValue !== void 0) {
587
+ return false;
588
+ }
589
+ return true;
590
+ } catch (error) {
591
+ this.logger.debug(
592
+ `Could not determine if field ${fieldPath} is required:`,
593
+ error
594
+ );
595
+ }
596
+ return false;
302
597
  }
303
598
  /**
304
- * Get registered strategies
599
+ * Generates a description for the form
305
600
  */
306
- getRegisteredStrategies() {
307
- return ["FormValidatable", "SchemaBased", "RenderConfig", "ZodErrorBased"];
601
+ generateFormDescription(toolName, fieldCount) {
602
+ if (fieldCount === 0) {
603
+ return "Please provide the required information to continue with your request.";
604
+ }
605
+ return `Please provide the following ${fieldCount} required field${fieldCount !== 1 ? "s" : ""} to continue with your request.`;
308
606
  }
309
607
  /**
310
- * Get registered middleware
608
+ * Generates JSON Schema and uiSchema from a Zod schema for use with @rjsf/core
609
+ * @param zodSchema The Zod schema to convert
610
+ * @param partialInput Existing input data to filter out fields that already have values
611
+ * @param missingFields Set of fields that are missing and should be shown
612
+ * @returns Object containing jsonSchema and uiSchema
311
613
  */
312
- getRegisteredMiddleware() {
313
- return ["FormSubmissionValidator"];
614
+ generateJsonSchemaForm(zodSchema, partialInput, missingFields) {
615
+ const fullJsonSchema = zodToJsonSchema(zodSchema, {
616
+ target: "jsonSchema7"
617
+ });
618
+ const uiSchema = {};
619
+ let jsonSchema = fullJsonSchema;
620
+ if (missingFields && missingFields.size > 0) {
621
+ const fullSchemaAsObject = fullJsonSchema;
622
+ if (fullSchemaAsObject.properties && typeof fullSchemaAsObject.properties === "object") {
623
+ const filteredSchema = {
624
+ ...fullSchemaAsObject,
625
+ type: "object",
626
+ properties: {},
627
+ required: []
628
+ };
629
+ let fieldsAdded = 0;
630
+ missingFields.forEach((fieldName) => {
631
+ if (fullSchemaAsObject.properties && fullSchemaAsObject.properties[fieldName]) {
632
+ filteredSchema.properties[fieldName] = fullSchemaAsObject.properties[fieldName];
633
+ fieldsAdded++;
634
+ }
635
+ });
636
+ if (Array.isArray(fullSchemaAsObject.required)) {
637
+ filteredSchema.required = fullSchemaAsObject.required.filter(
638
+ (field) => missingFields.has(field)
639
+ );
640
+ }
641
+ if (fieldsAdded > 0) {
642
+ jsonSchema = filteredSchema;
643
+ }
644
+ }
645
+ }
646
+ const fieldNames = this.extractFieldsFromSchema(zodSchema);
647
+ fieldNames.forEach((fieldName) => {
648
+ const isRequired = this.isFieldRequired(zodSchema, fieldName);
649
+ const priority = this.getFieldPriority(fieldName, void 0, isRequired);
650
+ const lower = fieldName.toLowerCase();
651
+ if (lower === "attributes" || lower === "metadata" || lower === "properties") {
652
+ uiSchema[fieldName] = {
653
+ "ui:options": {
654
+ collapsible: true,
655
+ collapsed: true
656
+ }
657
+ };
658
+ }
659
+ switch (priority) {
660
+ case "essential":
661
+ if (isRequired) {
662
+ uiSchema[fieldName] = {
663
+ ...uiSchema[fieldName],
664
+ "ui:help": "Required field"
665
+ };
666
+ }
667
+ break;
668
+ case "advanced":
669
+ case "expert":
670
+ uiSchema[fieldName] = {
671
+ ...uiSchema[fieldName],
672
+ "ui:options": {
673
+ ...uiSchema[fieldName]?.["ui:options"],
674
+ collapsed: true
675
+ }
676
+ };
677
+ break;
678
+ }
679
+ });
680
+ return { jsonSchema, uiSchema };
314
681
  }
315
682
  }
316
683
  export {
317
- FormEngine
684
+ FormGenerator
318
685
  };
319
686
  //# sourceMappingURL=index11.js.map