@frontmcp/ui 0.6.0 → 0.6.1

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 (445) hide show
  1. package/README.md +140 -362
  2. package/bridge/runtime/index.d.ts +2 -1
  3. package/bridge/runtime/index.d.ts.map +1 -1
  4. package/bundler/file-cache/component-builder.d.ts +1 -1
  5. package/bundler/file-cache/component-builder.d.ts.map +1 -1
  6. package/bundler/file-cache/hash-calculator.d.ts +1 -1
  7. package/bundler/file-cache/hash-calculator.d.ts.map +1 -1
  8. package/bundler/file-cache/storage/filesystem.d.ts +1 -1
  9. package/bundler/file-cache/storage/filesystem.d.ts.map +1 -1
  10. package/bundler/file-cache/storage/interface.d.ts +1 -1
  11. package/bundler/file-cache/storage/interface.d.ts.map +1 -1
  12. package/bundler/file-cache/storage/redis.d.ts +1 -1
  13. package/bundler/file-cache/storage/redis.d.ts.map +1 -1
  14. package/bundler/index.js +10 -1057
  15. package/components/alert.schema.d.ts +6 -6
  16. package/components/avatar.schema.d.ts +9 -9
  17. package/components/badge.schema.d.ts +9 -9
  18. package/components/button.schema.d.ts +9 -9
  19. package/components/card.schema.d.ts +7 -7
  20. package/components/form.schema.d.ts +24 -24
  21. package/components/index.js +128 -198
  22. package/components/modal.schema.d.ts +8 -8
  23. package/components/table.schema.d.ts +6 -6
  24. package/esm/bridge/runtime/index.d.ts +2 -1
  25. package/esm/bridge/runtime/index.d.ts.map +1 -1
  26. package/esm/bundler/file-cache/component-builder.d.ts +1 -1
  27. package/esm/bundler/file-cache/component-builder.d.ts.map +1 -1
  28. package/esm/bundler/file-cache/hash-calculator.d.ts +1 -1
  29. package/esm/bundler/file-cache/hash-calculator.d.ts.map +1 -1
  30. package/esm/bundler/file-cache/storage/filesystem.d.ts +1 -1
  31. package/esm/bundler/file-cache/storage/filesystem.d.ts.map +1 -1
  32. package/esm/bundler/file-cache/storage/interface.d.ts +1 -1
  33. package/esm/bundler/file-cache/storage/interface.d.ts.map +1 -1
  34. package/esm/bundler/file-cache/storage/redis.d.ts +1 -1
  35. package/esm/bundler/file-cache/storage/redis.d.ts.map +1 -1
  36. package/esm/bundler/index.js +3 -1050
  37. package/esm/components/alert.schema.d.ts +6 -6
  38. package/esm/components/avatar.schema.d.ts +9 -9
  39. package/esm/components/badge.schema.d.ts +9 -9
  40. package/esm/components/button.schema.d.ts +9 -9
  41. package/esm/components/card.schema.d.ts +7 -7
  42. package/esm/components/form.schema.d.ts +24 -24
  43. package/esm/components/index.js +136 -196
  44. package/esm/components/modal.schema.d.ts +8 -8
  45. package/esm/components/table.schema.d.ts +6 -6
  46. package/esm/index.d.ts +23 -39
  47. package/esm/index.d.ts.map +1 -1
  48. package/esm/index.js +4256 -16441
  49. package/esm/layouts/base.d.ts +2 -2
  50. package/esm/layouts/base.d.ts.map +1 -1
  51. package/esm/layouts/index.js +33 -516
  52. package/esm/package.json +8 -26
  53. package/esm/pages/index.js +100 -627
  54. package/esm/react/Alert.d.ts +1 -2
  55. package/esm/react/Alert.d.ts.map +1 -1
  56. package/esm/react/Badge.d.ts +1 -2
  57. package/esm/react/Badge.d.ts.map +1 -1
  58. package/esm/react/Button.d.ts +1 -2
  59. package/esm/react/Button.d.ts.map +1 -1
  60. package/esm/react/Card.d.ts +1 -2
  61. package/esm/react/Card.d.ts.map +1 -1
  62. package/esm/react/hooks/context.d.ts +1 -1
  63. package/esm/react/hooks/context.d.ts.map +1 -1
  64. package/esm/react/index.d.ts +5 -6
  65. package/esm/react/index.d.ts.map +1 -1
  66. package/esm/react/index.js +2074 -322
  67. package/esm/react/types.d.ts +1 -2
  68. package/esm/react/types.d.ts.map +1 -1
  69. package/esm/renderers/index.d.ts +10 -25
  70. package/esm/renderers/index.d.ts.map +1 -1
  71. package/esm/renderers/index.js +171 -1617
  72. package/esm/{runtime/adapters → renderers}/react.adapter.d.ts +2 -2
  73. package/esm/renderers/react.adapter.d.ts.map +1 -0
  74. package/esm/renderers/react.renderer.d.ts +3 -3
  75. package/esm/renderers/react.renderer.d.ts.map +1 -1
  76. package/esm/universal/index.js +1755 -0
  77. package/esm/web-components/index.js +232 -287
  78. package/esm/widgets/index.js +89 -147
  79. package/index.d.ts +23 -39
  80. package/index.d.ts.map +1 -1
  81. package/index.js +6123 -18539
  82. package/layouts/base.d.ts +2 -2
  83. package/layouts/base.d.ts.map +1 -1
  84. package/layouts/index.js +43 -536
  85. package/package.json +8 -26
  86. package/pages/index.js +111 -648
  87. package/react/Alert.d.ts +1 -2
  88. package/react/Alert.d.ts.map +1 -1
  89. package/react/Badge.d.ts +1 -2
  90. package/react/Badge.d.ts.map +1 -1
  91. package/react/Button.d.ts +1 -2
  92. package/react/Button.d.ts.map +1 -1
  93. package/react/Card.d.ts +1 -2
  94. package/react/Card.d.ts.map +1 -1
  95. package/react/hooks/context.d.ts +1 -1
  96. package/react/hooks/context.d.ts.map +1 -1
  97. package/react/index.d.ts +5 -6
  98. package/react/index.d.ts.map +1 -1
  99. package/react/index.js +2065 -335
  100. package/react/types.d.ts +1 -2
  101. package/react/types.d.ts.map +1 -1
  102. package/renderers/index.d.ts +10 -25
  103. package/renderers/index.d.ts.map +1 -1
  104. package/renderers/index.js +175 -1641
  105. package/{runtime/adapters → renderers}/react.adapter.d.ts +2 -2
  106. package/renderers/react.adapter.d.ts.map +1 -0
  107. package/renderers/react.renderer.d.ts +3 -3
  108. package/renderers/react.renderer.d.ts.map +1 -1
  109. package/universal/index.js +1841 -0
  110. package/web-components/index.js +224 -289
  111. package/widgets/index.js +80 -148
  112. package/adapters/index.d.ts +0 -13
  113. package/adapters/index.d.ts.map +0 -1
  114. package/adapters/index.js +0 -462
  115. package/adapters/platform-meta.d.ts +0 -166
  116. package/adapters/platform-meta.d.ts.map +0 -1
  117. package/adapters/response-builder.d.ts +0 -108
  118. package/adapters/response-builder.d.ts.map +0 -1
  119. package/adapters/serving-mode.d.ts +0 -107
  120. package/adapters/serving-mode.d.ts.map +0 -1
  121. package/base-template/bridge.d.ts +0 -90
  122. package/base-template/bridge.d.ts.map +0 -1
  123. package/base-template/default-base-template.d.ts +0 -92
  124. package/base-template/default-base-template.d.ts.map +0 -1
  125. package/base-template/index.d.ts +0 -15
  126. package/base-template/index.d.ts.map +0 -1
  127. package/base-template/index.js +0 -1398
  128. package/base-template/polyfills.d.ts +0 -31
  129. package/base-template/polyfills.d.ts.map +0 -1
  130. package/base-template/theme-styles.d.ts +0 -74
  131. package/base-template/theme-styles.d.ts.map +0 -1
  132. package/build/cdn-resources.d.ts +0 -243
  133. package/build/cdn-resources.d.ts.map +0 -1
  134. package/build/index.d.ts +0 -295
  135. package/build/index.d.ts.map +0 -1
  136. package/build/index.js +0 -7096
  137. package/build/widget-manifest.d.ts +0 -362
  138. package/build/widget-manifest.d.ts.map +0 -1
  139. package/dependency/cdn-registry.d.ts +0 -98
  140. package/dependency/cdn-registry.d.ts.map +0 -1
  141. package/dependency/import-map.d.ts +0 -186
  142. package/dependency/import-map.d.ts.map +0 -1
  143. package/dependency/import-parser.d.ts +0 -82
  144. package/dependency/import-parser.d.ts.map +0 -1
  145. package/dependency/index.d.ts +0 -17
  146. package/dependency/index.d.ts.map +0 -1
  147. package/dependency/resolver.d.ts +0 -164
  148. package/dependency/resolver.d.ts.map +0 -1
  149. package/dependency/schemas.d.ts +0 -486
  150. package/dependency/schemas.d.ts.map +0 -1
  151. package/dependency/template-loader.d.ts +0 -204
  152. package/dependency/template-loader.d.ts.map +0 -1
  153. package/dependency/template-processor.d.ts +0 -118
  154. package/dependency/template-processor.d.ts.map +0 -1
  155. package/dependency/types.d.ts +0 -739
  156. package/dependency/types.d.ts.map +0 -1
  157. package/esm/adapters/index.d.ts +0 -13
  158. package/esm/adapters/index.d.ts.map +0 -1
  159. package/esm/adapters/index.js +0 -427
  160. package/esm/adapters/platform-meta.d.ts +0 -166
  161. package/esm/adapters/platform-meta.d.ts.map +0 -1
  162. package/esm/adapters/response-builder.d.ts +0 -108
  163. package/esm/adapters/response-builder.d.ts.map +0 -1
  164. package/esm/adapters/serving-mode.d.ts +0 -107
  165. package/esm/adapters/serving-mode.d.ts.map +0 -1
  166. package/esm/base-template/bridge.d.ts +0 -90
  167. package/esm/base-template/bridge.d.ts.map +0 -1
  168. package/esm/base-template/default-base-template.d.ts +0 -92
  169. package/esm/base-template/default-base-template.d.ts.map +0 -1
  170. package/esm/base-template/index.d.ts +0 -15
  171. package/esm/base-template/index.d.ts.map +0 -1
  172. package/esm/base-template/index.js +0 -1364
  173. package/esm/base-template/polyfills.d.ts +0 -31
  174. package/esm/base-template/polyfills.d.ts.map +0 -1
  175. package/esm/base-template/theme-styles.d.ts +0 -74
  176. package/esm/base-template/theme-styles.d.ts.map +0 -1
  177. package/esm/build/cdn-resources.d.ts +0 -243
  178. package/esm/build/cdn-resources.d.ts.map +0 -1
  179. package/esm/build/index.d.ts +0 -295
  180. package/esm/build/index.d.ts.map +0 -1
  181. package/esm/build/index.js +0 -7021
  182. package/esm/build/widget-manifest.d.ts +0 -362
  183. package/esm/build/widget-manifest.d.ts.map +0 -1
  184. package/esm/dependency/cdn-registry.d.ts +0 -98
  185. package/esm/dependency/cdn-registry.d.ts.map +0 -1
  186. package/esm/dependency/import-map.d.ts +0 -186
  187. package/esm/dependency/import-map.d.ts.map +0 -1
  188. package/esm/dependency/import-parser.d.ts +0 -82
  189. package/esm/dependency/import-parser.d.ts.map +0 -1
  190. package/esm/dependency/index.d.ts +0 -17
  191. package/esm/dependency/index.d.ts.map +0 -1
  192. package/esm/dependency/resolver.d.ts +0 -164
  193. package/esm/dependency/resolver.d.ts.map +0 -1
  194. package/esm/dependency/schemas.d.ts +0 -486
  195. package/esm/dependency/schemas.d.ts.map +0 -1
  196. package/esm/dependency/template-loader.d.ts +0 -204
  197. package/esm/dependency/template-loader.d.ts.map +0 -1
  198. package/esm/dependency/template-processor.d.ts +0 -118
  199. package/esm/dependency/template-processor.d.ts.map +0 -1
  200. package/esm/dependency/types.d.ts +0 -739
  201. package/esm/dependency/types.d.ts.map +0 -1
  202. package/esm/handlebars/expression-extractor.d.ts +0 -147
  203. package/esm/handlebars/expression-extractor.d.ts.map +0 -1
  204. package/esm/handlebars/helpers.d.ts +0 -339
  205. package/esm/handlebars/helpers.d.ts.map +0 -1
  206. package/esm/handlebars/index.d.ts +0 -195
  207. package/esm/handlebars/index.d.ts.map +0 -1
  208. package/esm/handlebars/index.js +0 -587
  209. package/esm/registry/index.d.ts +0 -46
  210. package/esm/registry/index.d.ts.map +0 -1
  211. package/esm/registry/index.js +0 -6422
  212. package/esm/registry/render-template.d.ts +0 -91
  213. package/esm/registry/render-template.d.ts.map +0 -1
  214. package/esm/registry/tool-ui.registry.d.ts +0 -294
  215. package/esm/registry/tool-ui.registry.d.ts.map +0 -1
  216. package/esm/registry/uri-utils.d.ts +0 -56
  217. package/esm/registry/uri-utils.d.ts.map +0 -1
  218. package/esm/renderers/cache.d.ts +0 -145
  219. package/esm/renderers/cache.d.ts.map +0 -1
  220. package/esm/renderers/html.renderer.d.ts +0 -123
  221. package/esm/renderers/html.renderer.d.ts.map +0 -1
  222. package/esm/renderers/mdx.renderer.d.ts +0 -120
  223. package/esm/renderers/mdx.renderer.d.ts.map +0 -1
  224. package/esm/renderers/registry.d.ts +0 -134
  225. package/esm/renderers/registry.d.ts.map +0 -1
  226. package/esm/renderers/types.d.ts +0 -342
  227. package/esm/renderers/types.d.ts.map +0 -1
  228. package/esm/renderers/utils/detect.d.ts +0 -107
  229. package/esm/renderers/utils/detect.d.ts.map +0 -1
  230. package/esm/renderers/utils/hash.d.ts +0 -40
  231. package/esm/renderers/utils/hash.d.ts.map +0 -1
  232. package/esm/renderers/utils/index.d.ts +0 -9
  233. package/esm/renderers/utils/index.d.ts.map +0 -1
  234. package/esm/renderers/utils/transpiler.d.ts +0 -89
  235. package/esm/renderers/utils/transpiler.d.ts.map +0 -1
  236. package/esm/runtime/adapters/html.adapter.d.ts +0 -59
  237. package/esm/runtime/adapters/html.adapter.d.ts.map +0 -1
  238. package/esm/runtime/adapters/index.d.ts +0 -26
  239. package/esm/runtime/adapters/index.d.ts.map +0 -1
  240. package/esm/runtime/adapters/mdx.adapter.d.ts +0 -73
  241. package/esm/runtime/adapters/mdx.adapter.d.ts.map +0 -1
  242. package/esm/runtime/adapters/react.adapter.d.ts.map +0 -1
  243. package/esm/runtime/adapters/types.d.ts +0 -95
  244. package/esm/runtime/adapters/types.d.ts.map +0 -1
  245. package/esm/runtime/csp.d.ts +0 -48
  246. package/esm/runtime/csp.d.ts.map +0 -1
  247. package/esm/runtime/index.d.ts +0 -17
  248. package/esm/runtime/index.d.ts.map +0 -1
  249. package/esm/runtime/index.js +0 -5186
  250. package/esm/runtime/mcp-bridge.d.ts +0 -101
  251. package/esm/runtime/mcp-bridge.d.ts.map +0 -1
  252. package/esm/runtime/renderer-runtime.d.ts +0 -133
  253. package/esm/runtime/renderer-runtime.d.ts.map +0 -1
  254. package/esm/runtime/sanitizer.d.ts +0 -172
  255. package/esm/runtime/sanitizer.d.ts.map +0 -1
  256. package/esm/runtime/types.d.ts +0 -415
  257. package/esm/runtime/types.d.ts.map +0 -1
  258. package/esm/runtime/wrapper.d.ts +0 -421
  259. package/esm/runtime/wrapper.d.ts.map +0 -1
  260. package/esm/styles/index.d.ts +0 -8
  261. package/esm/styles/index.d.ts.map +0 -1
  262. package/esm/styles/index.js +0 -171
  263. package/esm/styles/variants.d.ts +0 -51
  264. package/esm/styles/variants.d.ts.map +0 -1
  265. package/esm/theme/cdn.d.ts +0 -195
  266. package/esm/theme/cdn.d.ts.map +0 -1
  267. package/esm/theme/index.d.ts +0 -18
  268. package/esm/theme/index.d.ts.map +0 -1
  269. package/esm/theme/index.js +0 -700
  270. package/esm/theme/platforms.d.ts +0 -107
  271. package/esm/theme/platforms.d.ts.map +0 -1
  272. package/esm/theme/presets/github-openai.d.ts +0 -50
  273. package/esm/theme/presets/github-openai.d.ts.map +0 -1
  274. package/esm/theme/presets/index.d.ts +0 -11
  275. package/esm/theme/presets/index.d.ts.map +0 -1
  276. package/esm/theme/theme.d.ts +0 -396
  277. package/esm/theme/theme.d.ts.map +0 -1
  278. package/esm/tool-template/builder.d.ts +0 -213
  279. package/esm/tool-template/builder.d.ts.map +0 -1
  280. package/esm/tool-template/index.d.ts +0 -16
  281. package/esm/tool-template/index.d.ts.map +0 -1
  282. package/esm/tool-template/index.js +0 -3515
  283. package/esm/types/index.d.ts +0 -14
  284. package/esm/types/index.d.ts.map +0 -1
  285. package/esm/types/index.js +0 -75
  286. package/esm/types/ui-config.d.ts +0 -639
  287. package/esm/types/ui-config.d.ts.map +0 -1
  288. package/esm/types/ui-runtime.d.ts +0 -1007
  289. package/esm/types/ui-runtime.d.ts.map +0 -1
  290. package/esm/typings/cache/cache-adapter.d.ts +0 -125
  291. package/esm/typings/cache/cache-adapter.d.ts.map +0 -1
  292. package/esm/typings/cache/index.d.ts +0 -10
  293. package/esm/typings/cache/index.d.ts.map +0 -1
  294. package/esm/typings/cache/memory-cache.d.ts +0 -92
  295. package/esm/typings/cache/memory-cache.d.ts.map +0 -1
  296. package/esm/typings/dts-parser.d.ts +0 -90
  297. package/esm/typings/dts-parser.d.ts.map +0 -1
  298. package/esm/typings/index.d.ts +0 -48
  299. package/esm/typings/index.d.ts.map +0 -1
  300. package/esm/typings/schemas.d.ts +0 -232
  301. package/esm/typings/schemas.d.ts.map +0 -1
  302. package/esm/typings/type-fetcher.d.ts +0 -89
  303. package/esm/typings/type-fetcher.d.ts.map +0 -1
  304. package/esm/typings/types.d.ts +0 -320
  305. package/esm/typings/types.d.ts.map +0 -1
  306. package/esm/utils/escape-html.d.ts +0 -58
  307. package/esm/utils/escape-html.d.ts.map +0 -1
  308. package/esm/utils/index.d.ts +0 -10
  309. package/esm/utils/index.d.ts.map +0 -1
  310. package/esm/utils/index.js +0 -40
  311. package/esm/utils/safe-stringify.d.ts +0 -30
  312. package/esm/utils/safe-stringify.d.ts.map +0 -1
  313. package/esm/validation/error-box.d.ts +0 -56
  314. package/esm/validation/error-box.d.ts.map +0 -1
  315. package/esm/validation/index.d.ts +0 -13
  316. package/esm/validation/index.d.ts.map +0 -1
  317. package/esm/validation/index.js +0 -562
  318. package/esm/validation/schema-paths.d.ts +0 -118
  319. package/esm/validation/schema-paths.d.ts.map +0 -1
  320. package/esm/validation/template-validator.d.ts +0 -143
  321. package/esm/validation/template-validator.d.ts.map +0 -1
  322. package/esm/validation/wrapper.d.ts +0 -97
  323. package/esm/validation/wrapper.d.ts.map +0 -1
  324. package/handlebars/expression-extractor.d.ts +0 -147
  325. package/handlebars/expression-extractor.d.ts.map +0 -1
  326. package/handlebars/helpers.d.ts +0 -339
  327. package/handlebars/helpers.d.ts.map +0 -1
  328. package/handlebars/index.d.ts +0 -195
  329. package/handlebars/index.d.ts.map +0 -1
  330. package/handlebars/index.js +0 -666
  331. package/registry/index.d.ts +0 -46
  332. package/registry/index.d.ts.map +0 -1
  333. package/registry/index.js +0 -6465
  334. package/registry/render-template.d.ts +0 -91
  335. package/registry/render-template.d.ts.map +0 -1
  336. package/registry/tool-ui.registry.d.ts +0 -294
  337. package/registry/tool-ui.registry.d.ts.map +0 -1
  338. package/registry/uri-utils.d.ts +0 -56
  339. package/registry/uri-utils.d.ts.map +0 -1
  340. package/renderers/cache.d.ts +0 -145
  341. package/renderers/cache.d.ts.map +0 -1
  342. package/renderers/html.renderer.d.ts +0 -123
  343. package/renderers/html.renderer.d.ts.map +0 -1
  344. package/renderers/mdx.renderer.d.ts +0 -120
  345. package/renderers/mdx.renderer.d.ts.map +0 -1
  346. package/renderers/registry.d.ts +0 -134
  347. package/renderers/registry.d.ts.map +0 -1
  348. package/renderers/types.d.ts +0 -342
  349. package/renderers/types.d.ts.map +0 -1
  350. package/renderers/utils/detect.d.ts +0 -107
  351. package/renderers/utils/detect.d.ts.map +0 -1
  352. package/renderers/utils/hash.d.ts +0 -40
  353. package/renderers/utils/hash.d.ts.map +0 -1
  354. package/renderers/utils/index.d.ts +0 -9
  355. package/renderers/utils/index.d.ts.map +0 -1
  356. package/renderers/utils/transpiler.d.ts +0 -89
  357. package/renderers/utils/transpiler.d.ts.map +0 -1
  358. package/runtime/adapters/html.adapter.d.ts +0 -59
  359. package/runtime/adapters/html.adapter.d.ts.map +0 -1
  360. package/runtime/adapters/index.d.ts +0 -26
  361. package/runtime/adapters/index.d.ts.map +0 -1
  362. package/runtime/adapters/mdx.adapter.d.ts +0 -73
  363. package/runtime/adapters/mdx.adapter.d.ts.map +0 -1
  364. package/runtime/adapters/react.adapter.d.ts.map +0 -1
  365. package/runtime/adapters/types.d.ts +0 -95
  366. package/runtime/adapters/types.d.ts.map +0 -1
  367. package/runtime/csp.d.ts +0 -48
  368. package/runtime/csp.d.ts.map +0 -1
  369. package/runtime/index.d.ts +0 -17
  370. package/runtime/index.d.ts.map +0 -1
  371. package/runtime/index.js +0 -5264
  372. package/runtime/mcp-bridge.d.ts +0 -101
  373. package/runtime/mcp-bridge.d.ts.map +0 -1
  374. package/runtime/renderer-runtime.d.ts +0 -133
  375. package/runtime/renderer-runtime.d.ts.map +0 -1
  376. package/runtime/sanitizer.d.ts +0 -172
  377. package/runtime/sanitizer.d.ts.map +0 -1
  378. package/runtime/types.d.ts +0 -415
  379. package/runtime/types.d.ts.map +0 -1
  380. package/runtime/wrapper.d.ts +0 -421
  381. package/runtime/wrapper.d.ts.map +0 -1
  382. package/styles/index.d.ts +0 -8
  383. package/styles/index.d.ts.map +0 -1
  384. package/styles/index.js +0 -222
  385. package/styles/variants.d.ts +0 -51
  386. package/styles/variants.d.ts.map +0 -1
  387. package/theme/cdn.d.ts +0 -195
  388. package/theme/cdn.d.ts.map +0 -1
  389. package/theme/index.d.ts +0 -18
  390. package/theme/index.d.ts.map +0 -1
  391. package/theme/index.js +0 -757
  392. package/theme/platforms.d.ts +0 -107
  393. package/theme/platforms.d.ts.map +0 -1
  394. package/theme/presets/github-openai.d.ts +0 -50
  395. package/theme/presets/github-openai.d.ts.map +0 -1
  396. package/theme/presets/index.d.ts +0 -11
  397. package/theme/presets/index.d.ts.map +0 -1
  398. package/theme/theme.d.ts +0 -396
  399. package/theme/theme.d.ts.map +0 -1
  400. package/tool-template/builder.d.ts +0 -213
  401. package/tool-template/builder.d.ts.map +0 -1
  402. package/tool-template/index.d.ts +0 -16
  403. package/tool-template/index.d.ts.map +0 -1
  404. package/tool-template/index.js +0 -3559
  405. package/types/index.d.ts +0 -14
  406. package/types/index.d.ts.map +0 -1
  407. package/types/index.js +0 -108
  408. package/types/ui-config.d.ts +0 -639
  409. package/types/ui-config.d.ts.map +0 -1
  410. package/types/ui-runtime.d.ts +0 -1007
  411. package/types/ui-runtime.d.ts.map +0 -1
  412. package/typings/cache/cache-adapter.d.ts +0 -125
  413. package/typings/cache/cache-adapter.d.ts.map +0 -1
  414. package/typings/cache/index.d.ts +0 -10
  415. package/typings/cache/index.d.ts.map +0 -1
  416. package/typings/cache/memory-cache.d.ts +0 -92
  417. package/typings/cache/memory-cache.d.ts.map +0 -1
  418. package/typings/dts-parser.d.ts +0 -90
  419. package/typings/dts-parser.d.ts.map +0 -1
  420. package/typings/index.d.ts +0 -48
  421. package/typings/index.d.ts.map +0 -1
  422. package/typings/schemas.d.ts +0 -232
  423. package/typings/schemas.d.ts.map +0 -1
  424. package/typings/type-fetcher.d.ts +0 -89
  425. package/typings/type-fetcher.d.ts.map +0 -1
  426. package/typings/types.d.ts +0 -320
  427. package/typings/types.d.ts.map +0 -1
  428. package/utils/escape-html.d.ts +0 -58
  429. package/utils/escape-html.d.ts.map +0 -1
  430. package/utils/index.d.ts +0 -10
  431. package/utils/index.d.ts.map +0 -1
  432. package/utils/index.js +0 -70
  433. package/utils/safe-stringify.d.ts +0 -30
  434. package/utils/safe-stringify.d.ts.map +0 -1
  435. package/validation/error-box.d.ts +0 -56
  436. package/validation/error-box.d.ts.map +0 -1
  437. package/validation/index.d.ts +0 -13
  438. package/validation/index.d.ts.map +0 -1
  439. package/validation/index.js +0 -603
  440. package/validation/schema-paths.d.ts +0 -118
  441. package/validation/schema-paths.d.ts.map +0 -1
  442. package/validation/template-validator.d.ts +0 -143
  443. package/validation/template-validator.d.ts.map +0 -1
  444. package/validation/wrapper.d.ts +0 -97
  445. package/validation/wrapper.d.ts.map +0 -1
@@ -1,1428 +1,12 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropNames = Object.getOwnPropertyNames;
3
- var __esm = (fn, res) => function __init() {
4
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
5
- };
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
-
11
- // libs/ui/src/utils/safe-stringify.ts
12
- var init_safe_stringify = __esm({
13
- "libs/ui/src/utils/safe-stringify.ts"() {
14
- "use strict";
15
- }
16
- });
17
-
18
- // libs/ui/src/utils/escape-html.ts
19
- function escapeHtml(str) {
20
- if (str === null || str === void 0) {
21
- return "";
22
- }
23
- const s = String(str);
24
- return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
25
- }
26
- var init_escape_html = __esm({
27
- "libs/ui/src/utils/escape-html.ts"() {
28
- "use strict";
29
- }
30
- });
31
-
32
- // libs/ui/src/utils/index.ts
33
- var init_utils = __esm({
34
- "libs/ui/src/utils/index.ts"() {
35
- "use strict";
36
- init_safe_stringify();
37
- init_escape_html();
38
- }
39
- });
40
-
41
- // libs/ui/src/handlebars/helpers.ts
42
- function formatDate(date, format) {
43
- if (date === null || date === void 0) {
44
- return "";
45
- }
46
- let dateObj;
47
- if (date instanceof Date) {
48
- dateObj = date;
49
- } else if (typeof date === "string" || typeof date === "number") {
50
- dateObj = new Date(date);
51
- } else {
52
- return String(date);
53
- }
54
- if (isNaN(dateObj.getTime())) {
55
- return String(date);
56
- }
57
- const options = {};
58
- switch (format) {
59
- case "short":
60
- options.dateStyle = "short";
61
- break;
62
- case "medium":
63
- options.dateStyle = "medium";
64
- break;
65
- case "long":
66
- options.dateStyle = "long";
67
- break;
68
- case "full":
69
- options.dateStyle = "full";
70
- break;
71
- case "time":
72
- options.timeStyle = "short";
73
- break;
74
- case "datetime":
75
- options.dateStyle = "medium";
76
- options.timeStyle = "short";
77
- break;
78
- case "iso":
79
- return dateObj.toISOString();
80
- case "relative":
81
- return formatRelativeDate(dateObj);
82
- default:
83
- options.dateStyle = "medium";
84
- }
85
- return new Intl.DateTimeFormat("en-US", options).format(dateObj);
86
- }
87
- function formatRelativeDate(date) {
88
- const now = /* @__PURE__ */ new Date();
89
- const diffMs = now.getTime() - date.getTime();
90
- const diffSecs = Math.floor(diffMs / 1e3);
91
- const diffMins = Math.floor(diffSecs / 60);
92
- const diffHours = Math.floor(diffMins / 60);
93
- const diffDays = Math.floor(diffHours / 24);
94
- if (diffSecs < 60) {
95
- return "just now";
96
- } else if (diffMins < 60) {
97
- return `${diffMins} minute${diffMins === 1 ? "" : "s"} ago`;
98
- } else if (diffHours < 24) {
99
- return `${diffHours} hour${diffHours === 1 ? "" : "s"} ago`;
100
- } else if (diffDays < 7) {
101
- return `${diffDays} day${diffDays === 1 ? "" : "s"} ago`;
102
- } else {
103
- return formatDate(date, "medium");
104
- }
105
- }
106
- function formatCurrency(amount, currency) {
107
- if (amount === null || amount === void 0) {
108
- return "";
109
- }
110
- const num = typeof amount === "number" ? amount : parseFloat(String(amount));
111
- if (isNaN(num)) {
112
- return String(amount);
113
- }
114
- return new Intl.NumberFormat("en-US", {
115
- style: "currency",
116
- currency: typeof currency === "string" ? currency : "USD"
117
- }).format(num);
118
- }
119
- function formatNumber(value, decimals) {
120
- if (value === null || value === void 0) {
121
- return "";
122
- }
123
- const num = typeof value === "number" ? value : parseFloat(String(value));
124
- if (isNaN(num)) {
125
- return String(value);
126
- }
127
- const options = {};
128
- if (typeof decimals === "number") {
129
- options.minimumFractionDigits = decimals;
130
- options.maximumFractionDigits = decimals;
131
- }
132
- return new Intl.NumberFormat("en-US", options).format(num);
133
- }
134
- function jsonEmbed(data) {
135
- const json2 = JSON.stringify(data ?? null);
136
- return json2.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
137
- }
138
- function json(data, pretty) {
139
- return JSON.stringify(data ?? null, null, pretty ? 2 : void 0);
140
- }
141
- function eq(a, b) {
142
- return a === b;
143
- }
144
- function ne(a, b) {
145
- return a !== b;
146
- }
147
- function gt(a, b) {
148
- return Number(a) > Number(b);
149
- }
150
- function gte(a, b) {
151
- return Number(a) >= Number(b);
152
- }
153
- function lt(a, b) {
154
- return Number(a) < Number(b);
155
- }
156
- function lte(a, b) {
157
- return Number(a) <= Number(b);
158
- }
159
- function and(a, b) {
160
- return Boolean(a) && Boolean(b);
161
- }
162
- function or(a, b) {
163
- return Boolean(a) || Boolean(b);
164
- }
165
- function not(value) {
166
- return !value;
167
- }
168
- function first(arr) {
169
- if (!Array.isArray(arr)) return void 0;
170
- return arr[0];
171
- }
172
- function last(arr) {
173
- if (!Array.isArray(arr)) return void 0;
174
- return arr[arr.length - 1];
175
- }
176
- function length(value) {
177
- if (Array.isArray(value)) return value.length;
178
- if (typeof value === "string") return value.length;
179
- return 0;
180
- }
181
- function includes(arr, value) {
182
- if (!Array.isArray(arr)) return false;
183
- return arr.includes(value);
184
- }
185
- function join(arr, separator) {
186
- if (!Array.isArray(arr)) return "";
187
- return arr.join(typeof separator === "string" ? separator : ", ");
188
- }
189
- function uppercase(str) {
190
- return String(str ?? "").toUpperCase();
191
- }
192
- function lowercase(str) {
193
- return String(str ?? "").toLowerCase();
194
- }
195
- function capitalize(str) {
196
- const s = String(str ?? "");
197
- return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
198
- }
199
- function truncate(str, maxLength, suffix) {
200
- const s = String(str ?? "");
201
- const len = typeof maxLength === "number" ? maxLength : 50;
202
- const suf = typeof suffix === "string" ? suffix : "...";
203
- if (s.length <= len) return s;
204
- return s.slice(0, len - suf.length) + suf;
205
- }
206
- function defaultValue(value, defaultValue2) {
207
- return value || defaultValue2;
208
- }
209
- function uniqueId(prefix) {
210
- const id = ++idCounter;
211
- return prefix ? `${prefix}-${id}` : `id-${id}`;
212
- }
213
- function resetUniqueIdCounter() {
214
- idCounter = 0;
215
- }
216
- function classNames(...classes) {
217
- return classes.filter(Boolean).map(String).join(" ");
218
- }
219
- var idCounter, builtinHelpers;
220
- var init_helpers = __esm({
221
- "libs/ui/src/handlebars/helpers.ts"() {
222
- "use strict";
223
- init_utils();
224
- idCounter = 0;
225
- builtinHelpers = {
226
- // Escaping
227
- escapeHtml,
228
- // Formatting
229
- formatDate,
230
- formatCurrency,
231
- formatNumber,
232
- json,
233
- jsonEmbed,
234
- // Comparison
235
- eq,
236
- ne,
237
- gt,
238
- gte,
239
- lt,
240
- lte,
241
- // Logical
242
- and,
243
- or,
244
- not,
245
- // Array
246
- first,
247
- last,
248
- length,
249
- includes,
250
- join,
251
- // String
252
- uppercase,
253
- lowercase,
254
- capitalize,
255
- truncate,
256
- // Utility
257
- default: defaultValue,
258
- uniqueId,
259
- classNames
260
- };
261
- }
262
- });
263
-
264
- // libs/ui/src/handlebars/expression-extractor.ts
265
- function extractExpressions(template) {
266
- const expressions = [];
267
- const lines = template.split("\n");
268
- const positionMap = buildPositionMap(template);
269
- let match;
270
- EXPRESSION_REGEX.lastIndex = 0;
271
- while ((match = EXPRESSION_REGEX.exec(template)) !== null) {
272
- const fullExpression = match[0];
273
- const prefix = match[1];
274
- const content = match[2].trim();
275
- const position = positionMap.get(match.index) ?? { line: 1, column: 1 };
276
- let type = "variable";
277
- let helperName;
278
- if (prefix === "/") {
279
- type = "block-close";
280
- helperName = content;
281
- } else if (prefix === "#") {
282
- type = "block";
283
- const parts = content.split(/\s+/);
284
- helperName = parts[0];
285
- } else {
286
- const parts = content.split(/\s+/);
287
- if (parts.length > 1 && !content.startsWith("(")) {
288
- const firstToken = parts[0];
289
- if (!firstToken.includes(".") && !KEYWORDS.has(firstToken)) {
290
- type = "helper";
291
- helperName = firstToken;
292
- }
293
- }
294
- }
295
- const paths = extractPathsFromContent(content);
296
- for (const path of paths) {
297
- expressions.push({
298
- path,
299
- fullExpression,
300
- line: position.line,
301
- column: position.column,
302
- type,
303
- helperName
304
- });
305
- }
306
- if (paths.length === 0 && type === "variable") {
307
- const cleanContent = content.trim();
308
- if (!KEYWORDS.has(cleanContent) && !cleanContent.includes(" ") && !cleanContent.startsWith("(")) {
309
- }
310
- }
311
- }
312
- return expressions;
313
- }
314
- function extractPathsFromContent(content) {
315
- const paths = [];
316
- let match;
317
- const regex = new RegExp(PATH_REGEX.source, "g");
318
- while ((match = regex.exec(content)) !== null) {
319
- paths.push(match[0]);
320
- }
321
- return paths;
322
- }
323
- function buildPositionMap(template) {
324
- const map = /* @__PURE__ */ new Map();
325
- let line = 1;
326
- let column = 1;
327
- for (let i = 0; i < template.length; i++) {
328
- map.set(i, { line, column });
329
- if (template[i] === "\n") {
330
- line++;
331
- column = 1;
332
- } else {
333
- column++;
334
- }
335
- }
336
- return map;
337
- }
338
- function extractVariablePaths(template) {
339
- const expressions = extractExpressions(template);
340
- const paths = new Set(expressions.map((e) => e.path));
341
- return Array.from(paths);
342
- }
343
- function extractOutputPaths(template) {
344
- return extractVariablePaths(template).filter((p) => p.startsWith("output."));
345
- }
346
- function extractInputPaths(template) {
347
- return extractVariablePaths(template).filter((p) => p.startsWith("input."));
348
- }
349
- function extractStructuredContentPaths(template) {
350
- return extractVariablePaths(template).filter((p) => p.startsWith("structuredContent."));
351
- }
352
- function extractAll(template) {
353
- const expressions = extractExpressions(template);
354
- const paths = [...new Set(expressions.map((e) => e.path))];
355
- return {
356
- expressions,
357
- paths,
358
- outputPaths: paths.filter((p) => p.startsWith("output.")),
359
- inputPaths: paths.filter((p) => p.startsWith("input.")),
360
- structuredContentPaths: paths.filter((p) => p.startsWith("structuredContent."))
361
- };
362
- }
363
- function hasVariablePaths(template) {
364
- return extractVariablePaths(template).length > 0;
365
- }
366
- function getExpressionAt(template, line, column) {
367
- const expressions = extractExpressions(template);
368
- return expressions.find((expr) => {
369
- if (expr.line !== line) return false;
370
- const exprEnd = expr.column + expr.fullExpression.length;
371
- return column >= expr.column && column <= exprEnd;
372
- });
373
- }
374
- function normalizePath(path) {
375
- return path.replace(/\.\d+\./g, ".[].").replace(/\.\d+$/g, ".[]").replace(/\[\d+\]/g, ".[]");
376
- }
377
- var EXPRESSION_REGEX, PATH_REGEX, KEYWORDS;
378
- var init_expression_extractor = __esm({
379
- "libs/ui/src/handlebars/expression-extractor.ts"() {
380
- "use strict";
381
- EXPRESSION_REGEX = /\{\{\{?(?!!)(#|\/)?([^}]+?)\}?\}\}/g;
382
- PATH_REGEX = /\b(output|input|structuredContent)(\.[a-zA-Z_$][a-zA-Z0-9_$]*|\.\[[^\]]+\])+/g;
383
- KEYWORDS = /* @__PURE__ */ new Set(["this", "else", "@index", "@key", "@first", "@last", "@root"]);
384
- }
385
- });
386
-
387
- // libs/ui/src/handlebars/index.ts
388
- var handlebars_exports = {};
389
- __export(handlebars_exports, {
390
- HandlebarsRenderer: () => HandlebarsRenderer,
391
- and: () => and,
392
- builtinHelpers: () => builtinHelpers,
393
- capitalize: () => capitalize,
394
- classNames: () => classNames,
395
- containsHandlebars: () => containsHandlebars,
396
- createHandlebarsRenderer: () => createHandlebarsRenderer,
397
- defaultValue: () => defaultValue,
398
- eq: () => eq,
399
- escapeHtml: () => escapeHtml,
400
- extractAll: () => extractAll,
401
- extractExpressions: () => extractExpressions,
402
- extractInputPaths: () => extractInputPaths,
403
- extractOutputPaths: () => extractOutputPaths,
404
- extractStructuredContentPaths: () => extractStructuredContentPaths,
405
- extractVariablePaths: () => extractVariablePaths,
406
- first: () => first,
407
- formatCurrency: () => formatCurrency,
408
- formatDate: () => formatDate,
409
- formatNumber: () => formatNumber,
410
- getExpressionAt: () => getExpressionAt,
411
- gt: () => gt,
412
- gte: () => gte,
413
- hasVariablePaths: () => hasVariablePaths,
414
- includes: () => includes,
415
- isHandlebarsAvailable: () => isHandlebarsAvailable,
416
- join: () => join,
417
- json: () => json,
418
- jsonEmbed: () => jsonEmbed,
419
- last: () => last,
420
- length: () => length,
421
- lowercase: () => lowercase,
422
- lt: () => lt,
423
- lte: () => lte,
424
- ne: () => ne,
425
- normalizePath: () => normalizePath,
426
- not: () => not,
427
- or: () => or,
428
- renderTemplate: () => renderTemplate,
429
- resetUniqueIdCounter: () => resetUniqueIdCounter,
430
- truncate: () => truncate,
431
- uniqueId: () => uniqueId,
432
- uppercase: () => uppercase
433
- });
434
- async function loadHandlebars() {
435
- if (Handlebars !== null) {
436
- return Handlebars;
437
- }
438
- try {
439
- Handlebars = await import("handlebars");
440
- return Handlebars;
441
- } catch {
442
- throw new Error("Handlebars is required for template rendering. Install it: npm install handlebars");
443
- }
444
- }
445
- async function isHandlebarsAvailable() {
446
- try {
447
- await loadHandlebars();
448
- return true;
449
- } catch {
450
- return false;
451
- }
452
- }
453
- function createHandlebarsRenderer(options) {
454
- return new HandlebarsRenderer(options);
455
- }
456
- async function renderTemplate(template, context) {
457
- const renderer = createHandlebarsRenderer();
458
- return renderer.render(template, context);
459
- }
460
- function containsHandlebars(template) {
461
- return HandlebarsRenderer.containsHandlebars(template);
462
- }
463
- var Handlebars, HandlebarsRenderer;
464
- var init_handlebars = __esm({
465
- "libs/ui/src/handlebars/index.ts"() {
466
- "use strict";
467
- init_helpers();
468
- init_helpers();
469
- init_expression_extractor();
470
- Handlebars = null;
471
- HandlebarsRenderer = class {
472
- options;
473
- compiledTemplates = /* @__PURE__ */ new Map();
474
- initialized = false;
475
- hbs = null;
476
- constructor(options = {}) {
477
- this.options = {
478
- strict: false,
479
- autoEscape: true,
480
- ...options
481
- };
482
- }
483
- /**
484
- * Initialize the renderer with Handlebars.
485
- */
486
- async init() {
487
- if (this.initialized) return;
488
- this.hbs = await loadHandlebars();
489
- for (const [name, helper] of Object.entries(builtinHelpers)) {
490
- this.hbs.registerHelper(name, helper);
491
- }
492
- if (this.options.helpers) {
493
- for (const [name, helper] of Object.entries(this.options.helpers)) {
494
- this.hbs.registerHelper(name, helper);
495
- }
496
- }
497
- if (this.options.partials) {
498
- for (const [name, template] of Object.entries(this.options.partials)) {
499
- this.hbs.registerPartial(name, template);
500
- }
501
- }
502
- this.initialized = true;
503
- }
504
- /**
505
- * Render a Handlebars template.
506
- *
507
- * @param template - Template string
508
- * @param context - Render context with input/output
509
- * @returns Rendered HTML string
510
- */
511
- async render(template, context) {
512
- await this.init();
513
- if (!this.hbs) {
514
- throw new Error("Handlebars not initialized");
515
- }
516
- let compiled = this.compiledTemplates.get(template);
517
- if (!compiled) {
518
- compiled = this.hbs.compile(template, {
519
- strict: this.options.strict,
520
- noEscape: !this.options.autoEscape
521
- });
522
- this.compiledTemplates.set(template, compiled);
523
- }
524
- const data = {
525
- input: context.input ?? {},
526
- output: context.output ?? {},
527
- structuredContent: context.structuredContent,
528
- // Also expose at root level for convenience
529
- ...context.input,
530
- ...typeof context.output === "object" && context.output !== null ? context.output : {}
531
- };
532
- try {
533
- return compiled(data);
534
- } catch (error) {
535
- throw new Error(`Template rendering failed: ${error instanceof Error ? error.message : String(error)}`);
536
- }
537
- }
538
- /**
539
- * Render a template synchronously.
540
- *
541
- * Note: Requires Handlebars to be pre-loaded. Use `render()` for async loading.
542
- *
543
- * @param template - Template string
544
- * @param context - Render context
545
- * @returns Rendered HTML string
546
- */
547
- renderSync(template, context) {
548
- if (!this.initialized || !this.hbs) {
549
- throw new Error("HandlebarsRenderer not initialized. Call render() first or use initSync().");
550
- }
551
- let compiled = this.compiledTemplates.get(template);
552
- if (!compiled) {
553
- compiled = this.hbs.compile(template, {
554
- strict: this.options.strict,
555
- noEscape: !this.options.autoEscape
556
- });
557
- this.compiledTemplates.set(template, compiled);
558
- }
559
- const data = {
560
- input: context.input ?? {},
561
- output: context.output ?? {},
562
- structuredContent: context.structuredContent,
563
- ...context.input,
564
- ...typeof context.output === "object" && context.output !== null ? context.output : {}
565
- };
566
- return compiled(data);
567
- }
568
- /**
569
- * Initialize synchronously (for environments where Handlebars is already loaded).
570
- */
571
- initSync(handlebars) {
572
- this.hbs = handlebars;
573
- for (const [name, helper] of Object.entries(builtinHelpers)) {
574
- this.hbs.registerHelper(name, helper);
575
- }
576
- if (this.options.helpers) {
577
- for (const [name, helper] of Object.entries(this.options.helpers)) {
578
- this.hbs.registerHelper(name, helper);
579
- }
580
- }
581
- if (this.options.partials) {
582
- for (const [name, template] of Object.entries(this.options.partials)) {
583
- this.hbs.registerPartial(name, template);
584
- }
585
- }
586
- this.initialized = true;
587
- }
588
- /**
589
- * Register a custom helper.
590
- *
591
- * @param name - Helper name
592
- * @param fn - Helper function
593
- */
594
- registerHelper(name, fn) {
595
- if (this.hbs) {
596
- this.hbs.registerHelper(name, fn);
597
- }
598
- if (!this.options.helpers) {
599
- this.options.helpers = {};
600
- }
601
- this.options.helpers[name] = fn;
602
- }
603
- /**
604
- * Register a partial template.
605
- *
606
- * @param name - Partial name
607
- * @param template - Partial template string
608
- */
609
- registerPartial(name, template) {
610
- if (this.hbs) {
611
- this.hbs.registerPartial(name, template);
612
- }
613
- if (!this.options.partials) {
614
- this.options.partials = {};
615
- }
616
- this.options.partials[name] = template;
617
- }
618
- /**
619
- * Clear compiled template cache.
620
- */
621
- clearCache() {
622
- this.compiledTemplates.clear();
623
- }
624
- /**
625
- * Check if a template string contains Handlebars syntax.
626
- *
627
- * @param template - Template string to check
628
- * @returns true if contains {{...}} syntax
629
- */
630
- static containsHandlebars(template) {
631
- return /\{\{(?!!)[\s\S]*?\}\}/.test(template);
632
- }
633
- /**
634
- * Check if the renderer is initialized.
635
- */
636
- get isInitialized() {
637
- return this.initialized;
638
- }
639
- };
640
- }
641
- });
642
-
643
- // libs/ui/src/renderers/utils/hash.ts
644
- function hashString(source) {
645
- let hash = 2166136261;
646
- for (let i = 0; i < source.length; i++) {
647
- hash ^= source.charCodeAt(i);
648
- hash = hash * 16777619 >>> 0;
649
- }
650
- return hash.toString(36);
651
- }
652
- function hashCombined(...values) {
653
- const combined = values.map((v) => {
654
- if (typeof v === "string") return v;
655
- if (v === null) return "null";
656
- if (v === void 0) return "undefined";
657
- try {
658
- return JSON.stringify(v);
659
- } catch {
660
- return String(v);
661
- }
662
- }).join("|");
663
- return hashString(combined);
664
- }
665
- function isHash(value) {
666
- return /^[0-9a-z]{5,10}$/i.test(value);
667
- }
668
-
669
- // libs/ui/src/renderers/cache.ts
670
- var TranspileCache = class {
671
- cache = /* @__PURE__ */ new Map();
672
- maxSize;
673
- ttl;
674
- /** Cache statistics */
675
- stats = {
676
- hits: 0,
677
- misses: 0,
678
- evictions: 0
679
- };
680
- constructor(options = {}) {
681
- this.maxSize = options.maxSize ?? 500;
682
- this.ttl = options.ttl ?? 0;
683
- }
684
- /**
685
- * Get a cached transpile result by source content.
686
- *
687
- * @param source - Source code to look up
688
- * @returns Cached result or undefined if not found/expired
689
- */
690
- get(source) {
691
- const key = hashString(source);
692
- return this.getByKey(key);
693
- }
694
- /**
695
- * Get a cached transpile result by hash key.
696
- *
697
- * @param key - Hash key
698
- * @returns Cached result or undefined if not found/expired
699
- */
700
- getByKey(key) {
701
- const entry = this.cache.get(key);
702
- if (!entry) {
703
- this.stats.misses++;
704
- return void 0;
705
- }
706
- if (this.ttl > 0 && Date.now() - entry.timestamp > this.ttl) {
707
- this.cache.delete(key);
708
- this.stats.misses++;
709
- return void 0;
710
- }
711
- this.cache.delete(key);
712
- entry.accessCount++;
713
- this.cache.set(key, entry);
714
- this.stats.hits++;
715
- return entry.value;
716
- }
717
- /**
718
- * Store a transpile result.
719
- *
720
- * @param source - Source code (used to generate key)
721
- * @param value - Transpile result to cache
722
- * @returns The hash key used for storage
723
- */
724
- set(source, value) {
725
- const key = hashString(source);
726
- this.setByKey(key, value);
727
- return key;
728
- }
729
- /**
730
- * Store a transpile result by hash key.
731
- *
732
- * @param key - Hash key
733
- * @param value - Transpile result to cache
734
- */
735
- setByKey(key, value) {
736
- if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
737
- const oldestKey = this.cache.keys().next().value;
738
- if (oldestKey) {
739
- this.cache.delete(oldestKey);
740
- this.stats.evictions++;
741
- }
742
- }
743
- this.cache.set(key, {
744
- value,
745
- timestamp: Date.now(),
746
- accessCount: 1
747
- });
748
- }
749
- /**
750
- * Check if a source is cached.
751
- *
752
- * @param source - Source code to check
753
- * @returns True if cached and not expired
754
- */
755
- has(source) {
756
- const key = hashString(source);
757
- return this.hasByKey(key);
758
- }
759
- /**
760
- * Check if a key is cached.
761
- *
762
- * @param key - Hash key to check
763
- * @returns True if cached and not expired
764
- */
765
- hasByKey(key) {
766
- const entry = this.cache.get(key);
767
- if (!entry) return false;
768
- if (this.ttl > 0 && Date.now() - entry.timestamp > this.ttl) {
769
- this.cache.delete(key);
770
- return false;
771
- }
772
- return true;
773
- }
774
- /**
775
- * Delete a cached entry by source.
776
- *
777
- * @param source - Source code to delete
778
- * @returns True if entry was deleted
779
- */
780
- delete(source) {
781
- const key = hashString(source);
782
- return this.cache.delete(key);
783
- }
784
- /**
785
- * Clear all cached entries.
786
- */
787
- clear() {
788
- this.cache.clear();
789
- this.stats = { hits: 0, misses: 0, evictions: 0 };
790
- }
791
- /**
792
- * Get current cache size.
793
- */
794
- get size() {
795
- return this.cache.size;
796
- }
797
- /**
798
- * Get cache statistics.
799
- */
800
- getStats() {
801
- const total = this.stats.hits + this.stats.misses;
802
- return {
803
- ...this.stats,
804
- size: this.cache.size,
805
- hitRate: total > 0 ? this.stats.hits / total : 0
806
- };
807
- }
808
- };
809
- var transpileCache = new TranspileCache({ maxSize: 500 });
810
- var renderCache = new TranspileCache({
811
- maxSize: 1e3,
812
- ttl: 5 * 60 * 1e3
813
- // 5 minutes
814
- });
815
- var ComponentCache = class {
816
- cache = /* @__PURE__ */ new Map();
817
- maxSize;
818
- constructor(maxSize = 200) {
819
- this.maxSize = maxSize;
820
- }
821
- get(key) {
822
- const entry = this.cache.get(key);
823
- if (!entry) return void 0;
824
- this.cache.delete(key);
825
- this.cache.set(key, entry);
826
- return entry.value;
827
- }
828
- set(key, value) {
829
- if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
830
- const oldestKey = this.cache.keys().next().value;
831
- if (oldestKey) {
832
- this.cache.delete(oldestKey);
833
- }
834
- }
835
- this.cache.set(key, { value, timestamp: Date.now() });
836
- }
837
- has(key) {
838
- return this.cache.has(key);
839
- }
840
- delete(key) {
841
- return this.cache.delete(key);
842
- }
843
- clear() {
844
- this.cache.clear();
845
- }
846
- get size() {
847
- return this.cache.size;
848
- }
849
- };
850
- var componentCache = new ComponentCache();
851
-
852
- // libs/ui/src/theme/platforms.ts
853
- var OPENAI_PLATFORM = {
854
- id: "openai",
855
- name: "OpenAI",
856
- supportsWidgets: true,
857
- supportsTailwind: true,
858
- supportsHtmx: true,
859
- networkMode: "full",
860
- scriptStrategy: "cdn",
861
- options: {
862
- sdk: "apps-sdk",
863
- version: "1.0"
864
- }
865
- };
866
- var CLAUDE_PLATFORM = {
867
- id: "claude",
868
- name: "Claude (Artifacts)",
869
- supportsWidgets: true,
870
- supportsTailwind: true,
871
- supportsHtmx: false,
872
- // Network blocked, HTMX won't work for API calls
873
- networkMode: "blocked",
874
- scriptStrategy: "inline",
875
- maxInlineSize: 100 * 1024,
876
- // 100KB limit for artifacts
877
- cspRestrictions: ["script-src 'unsafe-inline'", "connect-src 'none'"],
878
- options: {
879
- mode: "artifacts",
880
- framework: "react"
881
- // Claude artifacts prefer React
882
- }
883
- };
884
-
885
- // libs/ui/src/renderers/utils/detect.ts
886
- function isReactComponent(value) {
887
- if (typeof value !== "function") {
888
- return false;
889
- }
890
- const fn = value;
891
- const typeofSymbol = fn.$$typeof;
892
- if (typeofSymbol) {
893
- const symbolString = typeofSymbol.toString();
894
- return symbolString.includes("react.memo") || symbolString.includes("react.forward_ref") || symbolString.includes("react.lazy");
895
- }
896
- if (fn.prototype?.isReactComponent) {
897
- return true;
898
- }
899
- if (fn.name && /^[A-Z]/.test(fn.name)) {
900
- return true;
901
- }
902
- return false;
903
- }
904
- function isTemplateBuilderFunction(fn) {
905
- if (isReactComponent(fn)) {
906
- return false;
907
- }
908
- if (fn.name && /^[A-Z]/.test(fn.name)) {
909
- return false;
910
- }
911
- return true;
912
- }
913
- function containsJsx(source) {
914
- if (/<[A-Z][a-zA-Z0-9]*(\s|>|\/)/.test(source)) {
915
- return true;
916
- }
917
- if (/<[A-Z][a-zA-Z0-9]*[^>]*\/>/.test(source)) {
918
- return true;
919
- }
920
- if (/<[a-z]+[^>]*\{[^}]+\}/.test(source)) {
921
- return true;
922
- }
923
- if (/\s(className|onClick|onChange|onSubmit|htmlFor)=/.test(source)) {
924
- return true;
925
- }
926
- if (/<>|<\/>|<React\.Fragment>/.test(source)) {
927
- return true;
928
- }
929
- if (/=>\s*\(?\s*</.test(source)) {
930
- return true;
931
- }
932
- if (/return\s*\(?\s*</.test(source)) {
933
- return true;
934
- }
935
- return false;
936
- }
937
- function containsMdxSyntax(source) {
938
- if (/<[A-Z][a-zA-Z0-9]*/.test(source)) {
939
- return true;
940
- }
941
- if (/^(import|export)\s/m.test(source)) {
942
- return true;
943
- }
944
- if (/\s(className|onClick|onChange|onSubmit|htmlFor|dangerouslySetInnerHTML)=/.test(source)) {
945
- return true;
946
- }
947
- if (/\{[^}"'\n]*\}/.test(source) && !/=\s*["'][^"']*\{/.test(source)) {
948
- return true;
949
- }
950
- if (/^---[\s\S]*?---/m.test(source)) {
951
- return true;
952
- }
953
- if (/<>|<\/>/.test(source)) {
954
- return true;
955
- }
956
- return false;
957
- }
958
- function isPlainHtml(source) {
959
- return !containsJsx(source) && !containsMdxSyntax(source);
960
- }
961
- function detectTemplateType(template) {
962
- if (typeof template === "function") {
963
- if (isReactComponent(template)) {
964
- return {
965
- type: "react",
966
- confidence: 0.9,
967
- reason: "Function detected as React component (PascalCase name or React symbols)"
968
- };
969
- }
970
- return {
971
- type: "html-function",
972
- confidence: 0.8,
973
- reason: "Function assumed to be HTML template builder"
974
- };
975
- }
976
- if (typeof template === "string") {
977
- if (containsMdxSyntax(template)) {
978
- const hasMarkdown = /^#{1,6}\s|^\*\s|^\d+\.\s|^-\s/m.test(template);
979
- if (hasMarkdown) {
980
- return {
981
- type: "mdx",
982
- confidence: 0.9,
983
- reason: "String contains Markdown with JSX components"
984
- };
985
- }
986
- return {
987
- type: "jsx-string",
988
- confidence: 0.8,
989
- reason: "String contains JSX syntax"
990
- };
991
- }
992
- if (containsJsx(template)) {
993
- return {
994
- type: "jsx-string",
995
- confidence: 0.85,
996
- reason: "String contains JSX component tags or expressions"
997
- };
998
- }
999
- return {
1000
- type: "html-string",
1001
- confidence: 1,
1002
- reason: "Plain HTML string"
1003
- };
1004
- }
1005
- return {
1006
- type: "html-string",
1007
- confidence: 0.5,
1008
- reason: "Unknown template type, defaulting to HTML"
1009
- };
1010
- }
1011
-
1012
- // libs/ui/src/renderers/html.renderer.ts
1013
- var handlebarsRenderer = null;
1014
- async function loadHandlebarsRenderer() {
1015
- if (handlebarsRenderer !== null) {
1016
- return handlebarsRenderer;
1017
- }
1018
- try {
1019
- const handlebarsModule = await Promise.resolve().then(() => (init_handlebars(), handlebars_exports));
1020
- const { HandlebarsRenderer: HandlebarsRenderer2 } = handlebarsModule;
1021
- const renderer = new HandlebarsRenderer2();
1022
- handlebarsRenderer = {
1023
- render: (template, context) => renderer.render(template, {
1024
- input: context.input ?? {},
1025
- output: context.output,
1026
- structuredContent: context.structuredContent
1027
- }),
1028
- containsHandlebars: (template) => HandlebarsRenderer2.containsHandlebars(template)
1029
- };
1030
- return handlebarsRenderer;
1031
- } catch {
1032
- return null;
1033
- }
1034
- }
1035
- function containsHandlebars2(template) {
1036
- return /\{\{(?!!)[\s\S]*?\}\}/.test(template);
1037
- }
1038
- var HtmlRenderer = class {
1039
- type = "html";
1040
- priority = 0;
1041
- // Lowest priority - fallback renderer
1042
- /**
1043
- * Check if this renderer can handle the given template.
1044
- *
1045
- * Accepts:
1046
- * - Any string (assumed to be HTML, with or without Handlebars)
1047
- * - Functions that are template builders (not React components)
1048
- */
1049
- canHandle(template) {
1050
- if (typeof template === "string") {
1051
- return true;
1052
- }
1053
- if (typeof template === "function") {
1054
- return isTemplateBuilderFunction(template);
1055
- }
1056
- return false;
1057
- }
1058
- /**
1059
- * Check if a template uses Handlebars syntax.
1060
- *
1061
- * @param template - Template string to check
1062
- * @returns true if template contains {{...}} syntax
1063
- */
1064
- usesHandlebars(template) {
1065
- return containsHandlebars2(template);
1066
- }
1067
- /**
1068
- * Transpile the template.
1069
- *
1070
- * For HTML templates, no transpilation is needed.
1071
- * This method returns a dummy result for consistency.
1072
- */
1073
- async transpile(template, _options) {
1074
- const source = typeof template === "string" ? template : template.toString();
1075
- const hash = hashString(source);
1076
- return {
1077
- code: "",
1078
- // No transpiled code needed
1079
- hash,
1080
- cached: true
1081
- // Always "cached" since no work is done
1082
- };
1083
- }
1084
- /**
1085
- * Render the template to HTML string.
1086
- *
1087
- * For static strings without Handlebars, returns the string directly.
1088
- * For strings with Handlebars syntax, processes with HandlebarsRenderer.
1089
- * For functions, calls the function with the context.
1090
- */
1091
- async render(template, context, _options) {
1092
- if (typeof template === "string") {
1093
- if (containsHandlebars2(template)) {
1094
- return this.renderHandlebars(template, context);
1095
- }
1096
- return template;
1097
- }
1098
- if (typeof template === "function") {
1099
- const result = template(context);
1100
- if (typeof result === "string" && containsHandlebars2(result)) {
1101
- return this.renderHandlebars(result, context);
1102
- }
1103
- return result;
1104
- }
1105
- return String(template);
1106
- }
1107
- /**
1108
- * Render Handlebars template with context.
1109
- */
1110
- async renderHandlebars(template, context) {
1111
- const renderer = await loadHandlebarsRenderer();
1112
- if (!renderer) {
1113
- console.warn(
1114
- "[@frontmcp/ui] Template contains Handlebars syntax but handlebars is not installed. Install it for template interpolation: npm install handlebars"
1115
- );
1116
- return template;
1117
- }
1118
- return renderer.render(template, {
1119
- input: context.input,
1120
- output: context.output,
1121
- structuredContent: context.structuredContent
1122
- });
1123
- }
1124
- /**
1125
- * Get runtime scripts for client-side functionality.
1126
- *
1127
- * HTML templates don't need additional runtime scripts.
1128
- */
1129
- getRuntimeScripts(_platform) {
1130
- return {
1131
- headScripts: "",
1132
- isInline: false
1133
- };
1134
- }
1135
- };
1136
- var htmlRenderer = new HtmlRenderer();
1137
-
1138
- // libs/ui/src/renderers/registry.ts
1139
- var RendererRegistry = class {
1140
- renderers = /* @__PURE__ */ new Map();
1141
- sortedRenderers = [];
1142
- defaultRenderer = "html";
1143
- debug;
1144
- constructor(options = {}) {
1145
- this.debug = options.debug ?? false;
1146
- this.register(htmlRenderer);
1147
- }
1148
- /**
1149
- * Register a renderer.
1150
- *
1151
- * Renderers are sorted by priority (highest first) for detection.
1152
- *
1153
- * @param renderer - Renderer to register
1154
- */
1155
- register(renderer) {
1156
- this.renderers.set(renderer.type, renderer);
1157
- this.updateSortedList();
1158
- if (this.debug) {
1159
- console.log(`[RendererRegistry] Registered renderer: ${renderer.type} (priority: ${renderer.priority})`);
1160
- }
1161
- }
1162
- /**
1163
- * Unregister a renderer.
1164
- *
1165
- * @param type - Type of renderer to remove
1166
- * @returns True if renderer was removed
1167
- */
1168
- unregister(type) {
1169
- const removed = this.renderers.delete(type);
1170
- if (removed) {
1171
- this.updateSortedList();
1172
- }
1173
- return removed;
1174
- }
1175
- /**
1176
- * Get a renderer by type.
1177
- *
1178
- * @param type - Renderer type
1179
- * @returns Renderer or undefined if not found
1180
- */
1181
- get(type) {
1182
- return this.renderers.get(type);
1183
- }
1184
- /**
1185
- * Check if a renderer type is registered.
1186
- *
1187
- * @param type - Renderer type
1188
- * @returns True if registered
1189
- */
1190
- has(type) {
1191
- return this.renderers.has(type);
1192
- }
1193
- /**
1194
- * Get all registered renderer types.
1195
- *
1196
- * @returns Array of renderer types
1197
- */
1198
- getTypes() {
1199
- return Array.from(this.renderers.keys());
1200
- }
1201
- /**
1202
- * Auto-detect the renderer for a template.
1203
- *
1204
- * Checks renderers in priority order (highest first).
1205
- * Returns HTML renderer as fallback.
1206
- *
1207
- * @param template - Template to detect
1208
- * @returns Detection result with renderer and confidence
1209
- */
1210
- detect(template) {
1211
- for (const renderer of this.sortedRenderers) {
1212
- if (renderer.canHandle(template)) {
1213
- const result = {
1214
- renderer,
1215
- confidence: renderer.priority / 100,
1216
- // Normalize to 0-1
1217
- reason: `Matched by ${renderer.type} renderer`
1218
- };
1219
- if (this.debug) {
1220
- console.log(`[RendererRegistry] Detected template as ${renderer.type} (confidence: ${result.confidence})`);
1221
- }
1222
- return result;
1223
- }
1224
- }
1225
- const fallback = this.renderers.get(this.defaultRenderer);
1226
- if (!fallback) {
1227
- throw new Error(`Default renderer '${this.defaultRenderer}' not found`);
1228
- }
1229
- return {
1230
- renderer: fallback,
1231
- confidence: 0.5,
1232
- reason: "Fallback to default HTML renderer"
1233
- };
1234
- }
1235
- /**
1236
- * Render a template with auto-detection.
1237
- *
1238
- * @param template - Template to render (React, MDX, or HTML)
1239
- * @param context - Template context with input/output
1240
- * @param options - Render options
1241
- * @returns Rendered result with HTML and metadata
1242
- */
1243
- async render(template, context, options = {}) {
1244
- const platform = options.platform ?? OPENAI_PLATFORM;
1245
- const detection = this.detect(template);
1246
- const renderer = detection.renderer;
1247
- if (this.debug) {
1248
- console.log(`[RendererRegistry] Rendering with ${renderer.type} renderer`);
1249
- }
1250
- const transpileResult = await renderer.transpile(template);
1251
- const html = await renderer.render(template, context, options);
1252
- const runtimeScripts = renderer.getRuntimeScripts(platform);
1253
- return {
1254
- html,
1255
- rendererType: renderer.type,
1256
- transpileCached: transpileResult.cached,
1257
- runtimeScripts
1258
- };
1259
- }
1260
- /**
1261
- * Render with a specific renderer type.
1262
- *
1263
- * @param type - Renderer type to use
1264
- * @param template - Template to render
1265
- * @param context - Template context
1266
- * @param options - Render options
1267
- * @returns Rendered result
1268
- */
1269
- async renderWith(type, template, context, options = {}) {
1270
- const renderer = this.renderers.get(type);
1271
- if (!renderer) {
1272
- throw new Error(`Renderer '${type}' not registered`);
1273
- }
1274
- const platform = options.platform ?? OPENAI_PLATFORM;
1275
- const transpileResult = await renderer.transpile(template);
1276
- const html = await renderer.render(template, context, options);
1277
- const runtimeScripts = renderer.getRuntimeScripts(platform);
1278
- return {
1279
- html,
1280
- rendererType: type,
1281
- transpileCached: transpileResult.cached,
1282
- runtimeScripts
1283
- };
1284
- }
1285
- /**
1286
- * Update the sorted renderer list by priority.
1287
- */
1288
- updateSortedList() {
1289
- this.sortedRenderers = Array.from(this.renderers.values()).sort((a, b) => b.priority - a.priority);
1290
- }
1291
- /**
1292
- * Set the default renderer type.
1293
- *
1294
- * @param type - Renderer type to use as default
1295
- */
1296
- setDefault(type) {
1297
- if (!this.renderers.has(type)) {
1298
- throw new Error(`Cannot set default to unregistered renderer '${type}'`);
1299
- }
1300
- this.defaultRenderer = type;
1301
- }
1302
- /**
1303
- * Get registry statistics.
1304
- */
1305
- getStats() {
1306
- return {
1307
- registeredRenderers: this.getTypes(),
1308
- defaultRenderer: this.defaultRenderer,
1309
- priorityOrder: this.sortedRenderers.map((r) => ({
1310
- type: r.type,
1311
- priority: r.priority
1312
- }))
1313
- };
1314
- }
1315
- };
1316
- var rendererRegistry = new RendererRegistry();
1317
-
1318
- // libs/ui/src/renderers/utils/transpiler.ts
1319
- var DEFAULT_SWC_OPTIONS = {
1320
- typescript: true,
1321
- jsx: true,
1322
- jsxRuntime: "automatic",
1323
- development: false
1324
- };
1325
- var swcTransform = null;
1326
- async function loadSwcTransform() {
1327
- if (swcTransform !== null) {
1328
- return swcTransform;
1329
- }
1330
- try {
1331
- const swc = await import("@swc/core");
1332
- swcTransform = swc.transform;
1333
- return swcTransform;
1334
- } catch {
1335
- console.warn(
1336
- "[@frontmcp/ui] @swc/core not available. Runtime JSX transpilation disabled. Install @swc/core to enable: npm install @swc/core"
1337
- );
1338
- return null;
1339
- }
1340
- }
1341
- async function transpileJsx(source, options = {}) {
1342
- const hash = hashString(source);
1343
- const cached = transpileCache.getByKey(hash);
1344
- if (cached) {
1345
- return { ...cached, cached: true };
1346
- }
1347
- const transform = await loadSwcTransform();
1348
- if (!transform) {
1349
- throw new Error(
1350
- "Runtime JSX transpilation requires @swc/core. Either install @swc/core or use pre-compiled React components."
1351
- );
1352
- }
1353
- const opts = { ...DEFAULT_SWC_OPTIONS, ...options };
1354
- const swcOptions = {
1355
- jsc: {
1356
- parser: {
1357
- syntax: opts.typescript ? "typescript" : "ecmascript",
1358
- tsx: opts.jsx,
1359
- jsx: opts.jsx
1360
- },
1361
- transform: {
1362
- react: {
1363
- runtime: opts.jsxRuntime,
1364
- development: opts.development
1365
- }
1366
- },
1367
- target: "es2020"
1368
- },
1369
- module: {
1370
- type: "commonjs"
1371
- }
1372
- };
1373
- const result = await transform(source, swcOptions);
1374
- const transpileResult = {
1375
- code: result.code,
1376
- hash,
1377
- cached: false
1378
- };
1379
- transpileCache.setByKey(hash, transpileResult);
1380
- return transpileResult;
1381
- }
1382
- async function isSwcAvailable() {
1383
- const transform = await loadSwcTransform();
1384
- return transform !== null;
1385
- }
1386
- async function executeTranspiledCode(code, context = {}) {
1387
- let React;
1388
- let jsxRuntime;
1389
- try {
1390
- React = await import("react");
1391
- jsxRuntime = await import("react/jsx-runtime");
1392
- } catch {
1393
- throw new Error("React is required for JSX templates. Install react: npm install react react-dom");
1394
- }
1395
- const exports = {};
1396
- const module = { exports };
1397
- const require2 = (id) => {
1398
- switch (id) {
1399
- case "react":
1400
- return React;
1401
- case "react/jsx-runtime":
1402
- return jsxRuntime;
1403
- case "react/jsx-dev-runtime":
1404
- return jsxRuntime;
1405
- default:
1406
- if (context[id]) {
1407
- return context[id];
1408
- }
1409
- throw new Error(`Module '${id}' not available in JSX template context`);
1410
- }
1411
- };
1412
- try {
1413
- const fn = new Function("exports", "require", "module", "__filename", "__dirname", "React", "context", code);
1414
- fn(exports, require2, module, "template.js", "/", React, context);
1415
- return module.exports["default"] || module.exports[Object.keys(module.exports)[0]] || module.exports;
1416
- } catch (error) {
1417
- throw new Error(`Failed to execute transpiled JSX: ${error instanceof Error ? error.message : String(error)}`);
1418
- }
1419
- }
1420
- async function transpileAndExecute(source, context = {}) {
1421
- const result = await transpileJsx(source);
1422
- return executeTranspiledCode(result.code, context);
1423
- }
1424
-
1425
1
  // libs/ui/src/renderers/react.renderer.ts
2
+ import {
3
+ isReactComponent,
4
+ containsJsx,
5
+ hashString,
6
+ transpileJsx,
7
+ executeTranspiledCode,
8
+ transpileCache
9
+ } from "@frontmcp/uipack/renderers";
1426
10
  var REACT_CDN = {
1427
11
  react: "https://esm.sh/react@19",
1428
12
  reactDom: "https://esm.sh/react-dom@19/client"
@@ -1592,236 +176,206 @@ function buildHydrationScript() {
1592
176
  `;
1593
177
  }
1594
178
 
1595
- // libs/ui/src/renderers/mdx.renderer.ts
1596
- var REACT_CDN2 = {
1597
- react: "https://unpkg.com/react@18/umd/react.production.min.js",
1598
- reactDom: "https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"
1599
- };
1600
- var INLINE_MDX_PLACEHOLDER = `
1601
- // MDX runtime not available inline yet.
1602
- // For blocked-network platforms, use pre-rendered HTML templates.
1603
- console.warn('[FrontMCP] MDX hydration not available on this platform.');
1604
- `;
1605
- var MdxRenderer = class {
1606
- type = "mdx";
1607
- priority = 10;
1608
- // Between HTML (0) and React (20)
179
+ // libs/ui/src/renderers/react.adapter.ts
180
+ var mountedRoots = /* @__PURE__ */ new WeakMap();
181
+ var ReactRendererAdapter = class {
182
+ type = "react";
183
+ // Lazy-loaded React runtime
184
+ react = null;
185
+ reactDOM = null;
186
+ loadPromise = null;
1609
187
  /**
1610
- * Lazy-loaded modules.
188
+ * Check if this adapter can handle the given content.
1611
189
  */
1612
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1613
- React = null;
1614
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1615
- ReactDOMServer = null;
1616
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1617
- jsxRuntime = null;
1618
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1619
- mdxEvaluate = null;
190
+ canHandle(content) {
191
+ if (typeof content === "function") {
192
+ return true;
193
+ }
194
+ if (typeof content === "string") {
195
+ return content.includes("React.createElement") || content.includes("jsx(") || content.includes("jsxs(") || /function\s+\w+\s*\([^)]*\)\s*\{[\s\S]*return\s*[\s\S]*</.test(content);
196
+ }
197
+ return false;
198
+ }
1620
199
  /**
1621
- * Check if this renderer can handle the given template.
1622
- *
1623
- * Accepts strings containing MDX syntax (Markdown + JSX).
200
+ * Render React component to a string.
201
+ * This is a client-side fallback - SSR should be done at build time.
1624
202
  */
1625
- canHandle(template) {
1626
- if (typeof template !== "string") {
1627
- return false;
1628
- }
1629
- return containsMdxSyntax(template);
203
+ async render(content, context, _options) {
204
+ return `<div data-frontmcp-react data-tool="${context.toolName}">${content}</div>`;
1630
205
  }
1631
206
  /**
1632
- * Transpile MDX to executable JavaScript.
1633
- *
1634
- * Uses @mdx-js/mdx to compile MDX source to a module.
1635
- * Note: For MDX, we use evaluate() which combines compile + run,
1636
- * so this method just returns the source hash for caching purposes.
207
+ * Render React component directly to the DOM.
1637
208
  */
1638
- async transpile(template, _options) {
1639
- const hash = hashString(template);
1640
- const cached = transpileCache.getByKey(hash);
1641
- if (cached) {
1642
- return { ...cached, cached: true };
209
+ async renderToDOM(content, target, context, options) {
210
+ try {
211
+ await this.ensureReactLoaded();
212
+ if (!this.react || !this.reactDOM) {
213
+ throw new Error("React runtime not available");
214
+ }
215
+ const componentName = target.getAttribute("data-component");
216
+ const component = this.getComponent(componentName, content);
217
+ if (!component) {
218
+ target.innerHTML = content;
219
+ return { success: true };
220
+ }
221
+ const element = this.react.createElement(component, {
222
+ input: context.input,
223
+ output: context.output,
224
+ structuredContent: context.structuredContent,
225
+ toolName: context.toolName
226
+ });
227
+ if (options?.hydrate && this.reactDOM.hydrateRoot) {
228
+ const root = this.reactDOM.hydrateRoot(target, element);
229
+ mountedRoots.set(target, root);
230
+ } else if (this.reactDOM.createRoot) {
231
+ const root = this.reactDOM.createRoot(target);
232
+ root.render(element);
233
+ mountedRoots.set(target, root);
234
+ } else if (this.reactDOM.render) {
235
+ this.reactDOM.render(element, target);
236
+ mountedRoots.set(target, {
237
+ unmount: () => this.reactDOM?.unmountComponentAtNode?.(target)
238
+ });
239
+ } else {
240
+ throw new Error("No suitable React render method available");
241
+ }
242
+ target.dispatchEvent(
243
+ new CustomEvent("frontmcp:rendered", {
244
+ bubbles: true,
245
+ detail: { type: "react", toolName: context.toolName }
246
+ })
247
+ );
248
+ return { success: true };
249
+ } catch (error) {
250
+ const message = error instanceof Error ? error.message : String(error);
251
+ console.error("[FrontMCP] React render failed:", message);
252
+ return { success: false, error: message };
1643
253
  }
1644
- const transpileResult = {
1645
- code: template,
1646
- // Store original MDX for evaluate()
1647
- hash,
1648
- cached: false
1649
- };
1650
- transpileCache.setByKey(hash, transpileResult);
1651
- return transpileResult;
1652
254
  }
1653
255
  /**
1654
- * Render MDX template to HTML string.
1655
- *
1656
- * Uses @mdx-js/mdx's evaluate() for clean compilation + execution,
1657
- * then renders the resulting React component to HTML via SSR.
256
+ * Hydrate existing SSR content with React.
1658
257
  */
1659
- async render(template, context, options) {
1660
- await this.loadReact();
1661
- await this.loadMdx();
1662
- if (!this.mdxEvaluate) {
1663
- throw new Error("MDX compilation requires @mdx-js/mdx. Install it: npm install @mdx-js/mdx");
1664
- }
1665
- const templateHash = hashString(template);
1666
- const cacheKey = `mdx-component:${templateHash}`;
1667
- let Content = componentCache.get(cacheKey);
1668
- if (!Content) {
1669
- const result = await this.mdxEvaluate(template, {
1670
- ...this.jsxRuntime,
1671
- Fragment: this.React.Fragment,
1672
- development: false
258
+ async hydrate(target, context, options) {
259
+ return this.renderToDOM("", target, context, { ...options, hydrate: true });
260
+ }
261
+ /**
262
+ * Update rendered React component with new data.
263
+ */
264
+ async update(target, context) {
265
+ try {
266
+ await this.ensureReactLoaded();
267
+ if (!this.react) {
268
+ throw new Error("React runtime not available");
269
+ }
270
+ const existingRoot = mountedRoots.get(target);
271
+ const componentName = target.getAttribute("data-component");
272
+ const component = this.getComponent(componentName, "");
273
+ if (!component) {
274
+ return { success: false, error: "No component found for update" };
275
+ }
276
+ const element = this.react.createElement(component, {
277
+ input: context.input,
278
+ output: context.output,
279
+ structuredContent: context.structuredContent,
280
+ toolName: context.toolName
1673
281
  });
1674
- Content = result.default;
1675
- componentCache.set(cacheKey, Content);
1676
- }
1677
- const mdxComponents = {
1678
- // User-provided components from tool config
1679
- ...options?.mdxComponents,
1680
- // Wrapper that provides context to the content
1681
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1682
- wrapper: ({ children }) => {
1683
- return this.React.createElement("div", { className: "mdx-content" }, children);
282
+ if (existingRoot && "render" in existingRoot) {
283
+ existingRoot.render(element);
284
+ return { success: true };
1684
285
  }
1685
- };
1686
- const props = {
1687
- input: context.input,
1688
- output: context.output,
1689
- structuredContent: context.structuredContent,
1690
- helpers: context.helpers
1691
- };
1692
- const spreadProps = {
1693
- ...props,
1694
- ...typeof context.output === "object" && context.output !== null ? context.output : {}
1695
- };
1696
- const element = this.React.createElement(Content, {
1697
- components: mdxComponents,
1698
- ...spreadProps
1699
- });
1700
- const html = this.ReactDOMServer.renderToString(element);
1701
- if (options?.hydrate) {
1702
- const escapedProps = JSON.stringify(props).replace(/&/g, "&amp;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1703
- return `<div data-mdx-hydrate="true" data-props='${escapedProps}'>${html}</div>`;
286
+ return this.renderToDOM("", target, context);
287
+ } catch (error) {
288
+ const message = error instanceof Error ? error.message : String(error);
289
+ console.error("[FrontMCP] React update failed:", message);
290
+ return { success: false, error: message };
1704
291
  }
1705
- return html;
1706
292
  }
1707
293
  /**
1708
- * Get runtime scripts for client-side functionality.
294
+ * Clean up React root.
1709
295
  */
1710
- getRuntimeScripts(platform) {
1711
- if (platform.networkMode === "blocked") {
1712
- return {
1713
- headScripts: "",
1714
- inlineScripts: INLINE_MDX_PLACEHOLDER,
1715
- isInline: true
1716
- };
296
+ destroy(target) {
297
+ const root = mountedRoots.get(target);
298
+ if (root) {
299
+ root.unmount();
300
+ mountedRoots.delete(target);
1717
301
  }
1718
- return {
1719
- headScripts: `
1720
- <script crossorigin src="${REACT_CDN2.react}"></script>
1721
- <script crossorigin src="${REACT_CDN2.reactDom}"></script>
1722
- `,
1723
- isInline: false
1724
- };
1725
302
  }
1726
303
  /**
1727
- * Load React and ReactDOMServer modules.
304
+ * Ensure React is loaded.
1728
305
  */
1729
- async loadReact() {
1730
- if (this.React && this.ReactDOMServer && this.jsxRuntime) {
306
+ async ensureReactLoaded() {
307
+ if (this.react && this.reactDOM) {
1731
308
  return;
1732
309
  }
1733
- try {
1734
- const [react, reactDomServer, jsxRuntime] = await Promise.all([
1735
- import("react"),
1736
- import("react-dom/server"),
1737
- import("react/jsx-runtime")
1738
- ]);
1739
- this.React = react;
1740
- this.ReactDOMServer = reactDomServer;
1741
- this.jsxRuntime = jsxRuntime;
1742
- } catch {
1743
- throw new Error("React is required for MdxRenderer. Install react and react-dom: npm install react react-dom");
310
+ if (this.loadPromise) {
311
+ return this.loadPromise;
1744
312
  }
313
+ this.loadPromise = this.loadReact();
314
+ return this.loadPromise;
1745
315
  }
1746
316
  /**
1747
- * Load @mdx-js/mdx evaluate function.
1748
- *
1749
- * evaluate() is the cleanest way to run MDX - it combines
1750
- * compile and run in a single step, handling all the runtime
1751
- * injection automatically.
317
+ * Load React runtime.
1752
318
  */
1753
- async loadMdx() {
1754
- if (this.mdxEvaluate) {
319
+ async loadReact() {
320
+ const win = typeof window !== "undefined" ? window : globalThis;
321
+ if (win.React) {
322
+ this.react = win.React;
323
+ }
324
+ if (win.ReactDOM) {
325
+ this.reactDOM = win.ReactDOM;
326
+ }
327
+ if (this.react && this.reactDOM) {
1755
328
  return;
1756
329
  }
1757
330
  try {
1758
- const mdx = await import("@mdx-js/mdx");
1759
- this.mdxEvaluate = mdx.evaluate;
331
+ if (!this.react) {
332
+ const reactModule = await import(
333
+ /* webpackIgnore: true */
334
+ "react"
335
+ );
336
+ this.react = reactModule.default || reactModule;
337
+ }
338
+ if (!this.reactDOM) {
339
+ const reactDOMModule = await import(
340
+ /* webpackIgnore: true */
341
+ "react-dom/client"
342
+ );
343
+ this.reactDOM = reactDOMModule.default || reactDOMModule;
344
+ }
1760
345
  } catch {
1761
- console.warn(
1762
- "[@frontmcp/ui] @mdx-js/mdx not available. MDX rendering disabled. Install @mdx-js/mdx to enable: npm install @mdx-js/mdx"
1763
- );
346
+ if (!this.react || !this.reactDOM) {
347
+ console.warn("[FrontMCP] React runtime not available. Ensure React is loaded via CDN or bundled.");
348
+ }
1764
349
  }
1765
350
  }
1766
- };
1767
- var mdxRenderer = new MdxRenderer();
1768
- function buildMdxHydrationScript() {
1769
- return `
1770
- <script>
1771
- (function() {
1772
- // MDX hydration requires React and component definitions
1773
- if (typeof React === 'undefined' || typeof ReactDOM === 'undefined') {
1774
- console.warn('[FrontMCP] React not available for MDX hydration');
1775
- return;
1776
- }
1777
-
1778
- // Find all elements marked for MDX hydration
1779
- document.querySelectorAll('[data-mdx-hydrate]').forEach(function(root) {
1780
- var propsJson = root.getAttribute('data-props');
1781
- var props = propsJson ? JSON.parse(propsJson) : {};
1782
-
1783
- // MDX content is pre-rendered, hydration mainly attaches event handlers
1784
- // For full interactivity, components need to be available client-side
1785
- if (window.__frontmcp_mdx_content) {
1786
- try {
1787
- ReactDOM.hydrateRoot(root, React.createElement(
1788
- window.__frontmcp_mdx_content,
1789
- props
1790
- ));
1791
- } catch (e) {
1792
- console.error('[FrontMCP] MDX hydration failed', e);
351
+ /**
352
+ * Get a React component by name or from content.
353
+ */
354
+ getComponent(componentName, content) {
355
+ const win = typeof window !== "undefined" ? window : globalThis;
356
+ if (componentName && win.__frontmcp_components) {
357
+ const registered = win.__frontmcp_components?.[componentName];
358
+ if (registered) {
359
+ return registered;
1793
360
  }
1794
361
  }
1795
- });
1796
- })();
1797
- </script>
1798
- `;
362
+ if (content && typeof content === "function") {
363
+ return content;
364
+ }
365
+ return null;
366
+ }
367
+ };
368
+ function createReactAdapter() {
369
+ return new ReactRendererAdapter();
370
+ }
371
+ async function loadReactAdapter() {
372
+ return createReactAdapter();
1799
373
  }
1800
374
  export {
1801
- HtmlRenderer,
1802
- MdxRenderer,
1803
375
  ReactRenderer,
1804
- RendererRegistry,
1805
- TranspileCache,
376
+ ReactRendererAdapter,
1806
377
  buildHydrationScript,
1807
- buildMdxHydrationScript,
1808
- containsJsx,
1809
- containsMdxSyntax,
1810
- detectTemplateType,
1811
- executeTranspiledCode,
1812
- hashCombined,
1813
- hashString,
1814
- htmlRenderer,
1815
- isHash,
1816
- isPlainHtml,
1817
- isReactComponent,
1818
- isSwcAvailable,
1819
- isTemplateBuilderFunction,
1820
- mdxRenderer,
1821
- reactRenderer,
1822
- renderCache,
1823
- rendererRegistry,
1824
- transpileAndExecute,
1825
- transpileCache,
1826
- transpileJsx
378
+ createReactAdapter,
379
+ loadReactAdapter,
380
+ reactRenderer
1827
381
  };