@frontmcp/ui 0.5.0 → 0.6.0

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 (1134) hide show
  1. package/adapters/index.d.ts +13 -0
  2. package/adapters/index.d.ts.map +1 -0
  3. package/adapters/index.js +462 -0
  4. package/adapters/platform-meta.d.ts +166 -0
  5. package/adapters/platform-meta.d.ts.map +1 -0
  6. package/adapters/response-builder.d.ts +108 -0
  7. package/adapters/response-builder.d.ts.map +1 -0
  8. package/adapters/serving-mode.d.ts +107 -0
  9. package/adapters/serving-mode.d.ts.map +1 -0
  10. package/base-template/bridge.d.ts +90 -0
  11. package/base-template/bridge.d.ts.map +1 -0
  12. package/base-template/default-base-template.d.ts +92 -0
  13. package/base-template/default-base-template.d.ts.map +1 -0
  14. package/base-template/index.d.ts +15 -0
  15. package/base-template/index.d.ts.map +1 -0
  16. package/base-template/index.js +1398 -0
  17. package/base-template/polyfills.d.ts +31 -0
  18. package/base-template/polyfills.d.ts.map +1 -0
  19. package/base-template/theme-styles.d.ts +74 -0
  20. package/base-template/theme-styles.d.ts.map +1 -0
  21. package/bridge/adapters/base-adapter.d.ts +104 -0
  22. package/bridge/adapters/base-adapter.d.ts.map +1 -0
  23. package/bridge/adapters/claude.adapter.d.ts +67 -0
  24. package/bridge/adapters/claude.adapter.d.ts.map +1 -0
  25. package/bridge/adapters/ext-apps.adapter.d.ts +143 -0
  26. package/bridge/adapters/ext-apps.adapter.d.ts.map +1 -0
  27. package/bridge/adapters/gemini.adapter.d.ts +64 -0
  28. package/bridge/adapters/gemini.adapter.d.ts.map +1 -0
  29. package/bridge/adapters/generic.adapter.d.ts +56 -0
  30. package/bridge/adapters/generic.adapter.d.ts.map +1 -0
  31. package/bridge/adapters/index.d.ts +26 -0
  32. package/bridge/adapters/index.d.ts.map +1 -0
  33. package/bridge/adapters/openai.adapter.d.ts +65 -0
  34. package/bridge/adapters/openai.adapter.d.ts.map +1 -0
  35. package/bridge/core/adapter-registry.d.ts +122 -0
  36. package/bridge/core/adapter-registry.d.ts.map +1 -0
  37. package/bridge/core/bridge-factory.d.ts +199 -0
  38. package/bridge/core/bridge-factory.d.ts.map +1 -0
  39. package/bridge/core/index.d.ts +10 -0
  40. package/bridge/core/index.d.ts.map +1 -0
  41. package/bridge/index.d.ts +62 -0
  42. package/bridge/index.d.ts.map +1 -0
  43. package/bridge/index.js +2540 -0
  44. package/bridge/runtime/iife-generator.d.ts +62 -0
  45. package/bridge/runtime/iife-generator.d.ts.map +1 -0
  46. package/bridge/runtime/index.d.ts +9 -0
  47. package/bridge/runtime/index.d.ts.map +1 -0
  48. package/bridge/types.d.ts +386 -0
  49. package/bridge/types.d.ts.map +1 -0
  50. package/build/cdn-resources.d.ts +243 -0
  51. package/build/cdn-resources.d.ts.map +1 -0
  52. package/build/index.d.ts +295 -0
  53. package/build/index.d.ts.map +1 -0
  54. package/build/index.js +7096 -0
  55. package/build/widget-manifest.d.ts +362 -0
  56. package/build/widget-manifest.d.ts.map +1 -0
  57. package/bundler/bundler.d.ts +208 -0
  58. package/bundler/bundler.d.ts.map +1 -0
  59. package/bundler/cache.d.ts +173 -0
  60. package/bundler/cache.d.ts.map +1 -0
  61. package/bundler/file-cache/component-builder.d.ts +167 -0
  62. package/bundler/file-cache/component-builder.d.ts.map +1 -0
  63. package/bundler/file-cache/hash-calculator.d.ts +155 -0
  64. package/bundler/file-cache/hash-calculator.d.ts.map +1 -0
  65. package/bundler/file-cache/index.d.ts +12 -0
  66. package/bundler/file-cache/index.d.ts.map +1 -0
  67. package/bundler/file-cache/storage/filesystem.d.ts +149 -0
  68. package/bundler/file-cache/storage/filesystem.d.ts.map +1 -0
  69. package/bundler/file-cache/storage/index.d.ts +11 -0
  70. package/bundler/file-cache/storage/index.d.ts.map +1 -0
  71. package/bundler/file-cache/storage/interface.d.ts +152 -0
  72. package/bundler/file-cache/storage/interface.d.ts.map +1 -0
  73. package/bundler/file-cache/storage/redis.d.ts +139 -0
  74. package/bundler/file-cache/storage/redis.d.ts.map +1 -0
  75. package/bundler/index.d.ts +43 -0
  76. package/bundler/index.d.ts.map +1 -0
  77. package/bundler/index.js +4754 -0
  78. package/bundler/sandbox/enclave-adapter.d.ts +121 -0
  79. package/bundler/sandbox/enclave-adapter.d.ts.map +1 -0
  80. package/bundler/sandbox/executor.d.ts +14 -0
  81. package/bundler/sandbox/executor.d.ts.map +1 -0
  82. package/bundler/sandbox/policy.d.ts +62 -0
  83. package/bundler/sandbox/policy.d.ts.map +1 -0
  84. package/bundler/types.d.ts +702 -0
  85. package/bundler/types.d.ts.map +1 -0
  86. package/components/alert.d.ts +66 -0
  87. package/components/alert.d.ts.map +1 -0
  88. package/components/alert.schema.d.ts +98 -0
  89. package/components/alert.schema.d.ts.map +1 -0
  90. package/components/avatar.d.ts +77 -0
  91. package/components/avatar.d.ts.map +1 -0
  92. package/components/avatar.schema.d.ts +170 -0
  93. package/components/avatar.schema.d.ts.map +1 -0
  94. package/components/badge.d.ts +64 -0
  95. package/components/badge.d.ts.map +1 -0
  96. package/components/badge.schema.d.ts +91 -0
  97. package/components/badge.schema.d.ts.map +1 -0
  98. package/components/button.d.ts +100 -0
  99. package/components/button.d.ts.map +1 -0
  100. package/components/button.schema.d.ts +120 -0
  101. package/components/button.schema.d.ts.map +1 -0
  102. package/components/card.d.ts +53 -0
  103. package/components/card.d.ts.map +1 -0
  104. package/components/card.schema.d.ts +93 -0
  105. package/components/card.schema.d.ts.map +1 -0
  106. package/components/form.d.ts +212 -0
  107. package/components/form.d.ts.map +1 -0
  108. package/components/form.schema.d.ts +365 -0
  109. package/components/form.schema.d.ts.map +1 -0
  110. package/components/index.d.ts +29 -0
  111. package/components/index.d.ts.map +1 -0
  112. package/components/index.js +2595 -0
  113. package/components/list.d.ts +121 -0
  114. package/components/list.d.ts.map +1 -0
  115. package/components/list.schema.d.ts +129 -0
  116. package/components/list.schema.d.ts.map +1 -0
  117. package/components/modal.d.ts +100 -0
  118. package/components/modal.d.ts.map +1 -0
  119. package/components/modal.schema.d.ts +151 -0
  120. package/components/modal.schema.d.ts.map +1 -0
  121. package/components/table.d.ts +91 -0
  122. package/components/table.d.ts.map +1 -0
  123. package/components/table.schema.d.ts +123 -0
  124. package/components/table.schema.d.ts.map +1 -0
  125. package/dependency/cdn-registry.d.ts +98 -0
  126. package/dependency/cdn-registry.d.ts.map +1 -0
  127. package/dependency/import-map.d.ts +186 -0
  128. package/dependency/import-map.d.ts.map +1 -0
  129. package/dependency/import-parser.d.ts +82 -0
  130. package/dependency/import-parser.d.ts.map +1 -0
  131. package/dependency/index.d.ts +17 -0
  132. package/dependency/index.d.ts.map +1 -0
  133. package/dependency/resolver.d.ts +164 -0
  134. package/dependency/resolver.d.ts.map +1 -0
  135. package/dependency/schemas.d.ts +486 -0
  136. package/dependency/schemas.d.ts.map +1 -0
  137. package/dependency/template-loader.d.ts +204 -0
  138. package/dependency/template-loader.d.ts.map +1 -0
  139. package/dependency/template-processor.d.ts +118 -0
  140. package/dependency/template-processor.d.ts.map +1 -0
  141. package/dependency/types.d.ts +739 -0
  142. package/dependency/types.d.ts.map +1 -0
  143. package/esm/adapters/index.d.ts +13 -0
  144. package/esm/adapters/index.d.ts.map +1 -0
  145. package/esm/adapters/index.js +427 -0
  146. package/esm/adapters/platform-meta.d.ts +166 -0
  147. package/esm/adapters/platform-meta.d.ts.map +1 -0
  148. package/esm/adapters/response-builder.d.ts +108 -0
  149. package/esm/adapters/response-builder.d.ts.map +1 -0
  150. package/esm/adapters/serving-mode.d.ts +107 -0
  151. package/esm/adapters/serving-mode.d.ts.map +1 -0
  152. package/esm/base-template/bridge.d.ts +90 -0
  153. package/esm/base-template/bridge.d.ts.map +1 -0
  154. package/esm/base-template/default-base-template.d.ts +92 -0
  155. package/esm/base-template/default-base-template.d.ts.map +1 -0
  156. package/esm/base-template/index.d.ts +15 -0
  157. package/esm/base-template/index.d.ts.map +1 -0
  158. package/esm/base-template/index.js +1364 -0
  159. package/esm/base-template/polyfills.d.ts +31 -0
  160. package/esm/base-template/polyfills.d.ts.map +1 -0
  161. package/esm/base-template/theme-styles.d.ts +74 -0
  162. package/esm/base-template/theme-styles.d.ts.map +1 -0
  163. package/esm/bridge/adapters/base-adapter.d.ts +104 -0
  164. package/esm/bridge/adapters/base-adapter.d.ts.map +1 -0
  165. package/esm/bridge/adapters/claude.adapter.d.ts +67 -0
  166. package/esm/bridge/adapters/claude.adapter.d.ts.map +1 -0
  167. package/esm/bridge/adapters/ext-apps.adapter.d.ts +143 -0
  168. package/esm/bridge/adapters/ext-apps.adapter.d.ts.map +1 -0
  169. package/esm/bridge/adapters/gemini.adapter.d.ts +64 -0
  170. package/esm/bridge/adapters/gemini.adapter.d.ts.map +1 -0
  171. package/esm/bridge/adapters/generic.adapter.d.ts +56 -0
  172. package/esm/bridge/adapters/generic.adapter.d.ts.map +1 -0
  173. package/esm/bridge/adapters/index.d.ts +26 -0
  174. package/esm/bridge/adapters/index.d.ts.map +1 -0
  175. package/esm/bridge/adapters/openai.adapter.d.ts +65 -0
  176. package/esm/bridge/adapters/openai.adapter.d.ts.map +1 -0
  177. package/esm/bridge/core/adapter-registry.d.ts +122 -0
  178. package/esm/bridge/core/adapter-registry.d.ts.map +1 -0
  179. package/esm/bridge/core/bridge-factory.d.ts +199 -0
  180. package/esm/bridge/core/bridge-factory.d.ts.map +1 -0
  181. package/esm/bridge/core/index.d.ts +10 -0
  182. package/esm/bridge/core/index.d.ts.map +1 -0
  183. package/esm/bridge/index.d.ts +62 -0
  184. package/esm/bridge/index.d.ts.map +1 -0
  185. package/esm/bridge/index.js +2487 -0
  186. package/esm/bridge/runtime/iife-generator.d.ts +62 -0
  187. package/esm/bridge/runtime/iife-generator.d.ts.map +1 -0
  188. package/esm/bridge/runtime/index.d.ts +9 -0
  189. package/esm/bridge/runtime/index.d.ts.map +1 -0
  190. package/esm/bridge/types.d.ts +386 -0
  191. package/esm/bridge/types.d.ts.map +1 -0
  192. package/esm/build/cdn-resources.d.ts +243 -0
  193. package/esm/build/cdn-resources.d.ts.map +1 -0
  194. package/esm/build/index.d.ts +295 -0
  195. package/esm/build/index.d.ts.map +1 -0
  196. package/esm/build/index.js +7021 -0
  197. package/esm/build/widget-manifest.d.ts +362 -0
  198. package/esm/build/widget-manifest.d.ts.map +1 -0
  199. package/esm/bundler/bundler.d.ts +208 -0
  200. package/esm/bundler/bundler.d.ts.map +1 -0
  201. package/esm/bundler/cache.d.ts +173 -0
  202. package/esm/bundler/cache.d.ts.map +1 -0
  203. package/esm/bundler/file-cache/component-builder.d.ts +167 -0
  204. package/esm/bundler/file-cache/component-builder.d.ts.map +1 -0
  205. package/esm/bundler/file-cache/hash-calculator.d.ts +155 -0
  206. package/esm/bundler/file-cache/hash-calculator.d.ts.map +1 -0
  207. package/esm/bundler/file-cache/index.d.ts +12 -0
  208. package/esm/bundler/file-cache/index.d.ts.map +1 -0
  209. package/esm/bundler/file-cache/storage/filesystem.d.ts +149 -0
  210. package/esm/bundler/file-cache/storage/filesystem.d.ts.map +1 -0
  211. package/esm/bundler/file-cache/storage/index.d.ts +11 -0
  212. package/esm/bundler/file-cache/storage/index.d.ts.map +1 -0
  213. package/esm/bundler/file-cache/storage/interface.d.ts +152 -0
  214. package/esm/bundler/file-cache/storage/interface.d.ts.map +1 -0
  215. package/esm/bundler/file-cache/storage/redis.d.ts +139 -0
  216. package/esm/bundler/file-cache/storage/redis.d.ts.map +1 -0
  217. package/esm/bundler/index.d.ts +43 -0
  218. package/esm/bundler/index.d.ts.map +1 -0
  219. package/esm/bundler/index.js +4687 -0
  220. package/esm/bundler/sandbox/enclave-adapter.d.ts +121 -0
  221. package/esm/bundler/sandbox/enclave-adapter.d.ts.map +1 -0
  222. package/esm/bundler/sandbox/executor.d.ts +14 -0
  223. package/esm/bundler/sandbox/executor.d.ts.map +1 -0
  224. package/esm/bundler/sandbox/policy.d.ts +62 -0
  225. package/esm/bundler/sandbox/policy.d.ts.map +1 -0
  226. package/esm/bundler/types.d.ts +702 -0
  227. package/esm/bundler/types.d.ts.map +1 -0
  228. package/esm/components/alert.d.ts +66 -0
  229. package/esm/components/alert.d.ts.map +1 -0
  230. package/esm/components/alert.schema.d.ts +98 -0
  231. package/esm/components/alert.schema.d.ts.map +1 -0
  232. package/esm/components/avatar.d.ts +77 -0
  233. package/esm/components/avatar.d.ts.map +1 -0
  234. package/esm/components/avatar.schema.d.ts +170 -0
  235. package/esm/components/avatar.schema.d.ts.map +1 -0
  236. package/esm/components/badge.d.ts +64 -0
  237. package/esm/components/badge.d.ts.map +1 -0
  238. package/esm/components/badge.schema.d.ts +91 -0
  239. package/esm/components/badge.schema.d.ts.map +1 -0
  240. package/esm/components/button.d.ts +100 -0
  241. package/esm/components/button.d.ts.map +1 -0
  242. package/esm/components/button.schema.d.ts +120 -0
  243. package/esm/components/button.schema.d.ts.map +1 -0
  244. package/esm/components/card.d.ts +53 -0
  245. package/esm/components/card.d.ts.map +1 -0
  246. package/esm/components/card.schema.d.ts +93 -0
  247. package/esm/components/card.schema.d.ts.map +1 -0
  248. package/esm/components/form.d.ts +212 -0
  249. package/esm/components/form.d.ts.map +1 -0
  250. package/esm/components/form.schema.d.ts +365 -0
  251. package/esm/components/form.schema.d.ts.map +1 -0
  252. package/esm/components/index.d.ts +29 -0
  253. package/esm/components/index.d.ts.map +1 -0
  254. package/esm/components/index.js +2456 -0
  255. package/esm/components/list.d.ts +121 -0
  256. package/esm/components/list.d.ts.map +1 -0
  257. package/esm/components/list.schema.d.ts +129 -0
  258. package/esm/components/list.schema.d.ts.map +1 -0
  259. package/esm/components/modal.d.ts +100 -0
  260. package/esm/components/modal.d.ts.map +1 -0
  261. package/esm/components/modal.schema.d.ts +151 -0
  262. package/esm/components/modal.schema.d.ts.map +1 -0
  263. package/esm/components/table.d.ts +91 -0
  264. package/esm/components/table.d.ts.map +1 -0
  265. package/esm/components/table.schema.d.ts +123 -0
  266. package/esm/components/table.schema.d.ts.map +1 -0
  267. package/esm/dependency/cdn-registry.d.ts +98 -0
  268. package/esm/dependency/cdn-registry.d.ts.map +1 -0
  269. package/esm/dependency/import-map.d.ts +186 -0
  270. package/esm/dependency/import-map.d.ts.map +1 -0
  271. package/esm/dependency/import-parser.d.ts +82 -0
  272. package/esm/dependency/import-parser.d.ts.map +1 -0
  273. package/esm/dependency/index.d.ts +17 -0
  274. package/esm/dependency/index.d.ts.map +1 -0
  275. package/esm/dependency/resolver.d.ts +164 -0
  276. package/esm/dependency/resolver.d.ts.map +1 -0
  277. package/esm/dependency/schemas.d.ts +486 -0
  278. package/esm/dependency/schemas.d.ts.map +1 -0
  279. package/esm/dependency/template-loader.d.ts +204 -0
  280. package/esm/dependency/template-loader.d.ts.map +1 -0
  281. package/esm/dependency/template-processor.d.ts +118 -0
  282. package/esm/dependency/template-processor.d.ts.map +1 -0
  283. package/esm/dependency/types.d.ts +739 -0
  284. package/esm/dependency/types.d.ts.map +1 -0
  285. package/esm/handlebars/expression-extractor.d.ts +147 -0
  286. package/esm/handlebars/expression-extractor.d.ts.map +1 -0
  287. package/esm/handlebars/helpers.d.ts +339 -0
  288. package/esm/handlebars/helpers.d.ts.map +1 -0
  289. package/esm/handlebars/index.d.ts +195 -0
  290. package/esm/handlebars/index.d.ts.map +1 -0
  291. package/esm/handlebars/index.js +587 -0
  292. package/esm/index.d.ts +56 -0
  293. package/esm/index.d.ts.map +1 -0
  294. package/esm/index.js +20511 -0
  295. package/esm/layouts/base.d.ts +86 -0
  296. package/esm/layouts/base.d.ts.map +1 -0
  297. package/esm/layouts/index.d.ts +8 -0
  298. package/esm/layouts/index.d.ts.map +1 -0
  299. package/esm/layouts/index.js +892 -0
  300. package/esm/layouts/presets.d.ts +134 -0
  301. package/esm/layouts/presets.d.ts.map +1 -0
  302. package/esm/package.json +90 -0
  303. package/esm/pages/consent.d.ts +117 -0
  304. package/esm/pages/consent.d.ts.map +1 -0
  305. package/esm/pages/error.d.ts +101 -0
  306. package/esm/pages/error.d.ts.map +1 -0
  307. package/esm/pages/index.d.ts +9 -0
  308. package/esm/pages/index.d.ts.map +1 -0
  309. package/esm/pages/index.js +1563 -0
  310. package/esm/react/Alert.d.ts +102 -0
  311. package/esm/react/Alert.d.ts.map +1 -0
  312. package/esm/react/Badge.d.ts +101 -0
  313. package/esm/react/Badge.d.ts.map +1 -0
  314. package/esm/react/Button.d.ts +109 -0
  315. package/esm/react/Button.d.ts.map +1 -0
  316. package/esm/react/Card.d.ts +104 -0
  317. package/esm/react/Card.d.ts.map +1 -0
  318. package/esm/react/hooks/context.d.ts +179 -0
  319. package/esm/react/hooks/context.d.ts.map +1 -0
  320. package/esm/react/hooks/index.d.ts +42 -0
  321. package/esm/react/hooks/index.d.ts.map +1 -0
  322. package/esm/react/hooks/tools.d.ts +284 -0
  323. package/esm/react/hooks/tools.d.ts.map +1 -0
  324. package/esm/react/index.d.ts +81 -0
  325. package/esm/react/index.d.ts.map +1 -0
  326. package/esm/react/index.js +1372 -0
  327. package/esm/react/types.d.ts +106 -0
  328. package/esm/react/types.d.ts.map +1 -0
  329. package/esm/react/utils.d.ts +43 -0
  330. package/esm/react/utils.d.ts.map +1 -0
  331. package/esm/registry/index.d.ts +46 -0
  332. package/esm/registry/index.d.ts.map +1 -0
  333. package/esm/registry/index.js +6422 -0
  334. package/esm/registry/render-template.d.ts +91 -0
  335. package/esm/registry/render-template.d.ts.map +1 -0
  336. package/esm/registry/tool-ui.registry.d.ts +294 -0
  337. package/esm/registry/tool-ui.registry.d.ts.map +1 -0
  338. package/esm/registry/uri-utils.d.ts +56 -0
  339. package/esm/registry/uri-utils.d.ts.map +1 -0
  340. package/esm/render/index.d.ts +8 -0
  341. package/esm/render/index.d.ts.map +1 -0
  342. package/esm/render/index.js +45 -0
  343. package/esm/render/prerender.d.ts +57 -0
  344. package/esm/render/prerender.d.ts.map +1 -0
  345. package/esm/renderers/cache.d.ts +145 -0
  346. package/esm/renderers/cache.d.ts.map +1 -0
  347. package/esm/renderers/html.renderer.d.ts +123 -0
  348. package/esm/renderers/html.renderer.d.ts.map +1 -0
  349. package/esm/renderers/index.d.ts +36 -0
  350. package/esm/renderers/index.d.ts.map +1 -0
  351. package/esm/renderers/index.js +1827 -0
  352. package/esm/renderers/mdx.renderer.d.ts +120 -0
  353. package/esm/renderers/mdx.renderer.d.ts.map +1 -0
  354. package/esm/renderers/react.renderer.d.ts +96 -0
  355. package/esm/renderers/react.renderer.d.ts.map +1 -0
  356. package/esm/renderers/registry.d.ts +134 -0
  357. package/esm/renderers/registry.d.ts.map +1 -0
  358. package/esm/renderers/types.d.ts +342 -0
  359. package/esm/renderers/types.d.ts.map +1 -0
  360. package/esm/renderers/utils/detect.d.ts +107 -0
  361. package/esm/renderers/utils/detect.d.ts.map +1 -0
  362. package/esm/renderers/utils/hash.d.ts +40 -0
  363. package/esm/renderers/utils/hash.d.ts.map +1 -0
  364. package/esm/renderers/utils/index.d.ts +9 -0
  365. package/esm/renderers/utils/index.d.ts.map +1 -0
  366. package/esm/renderers/utils/transpiler.d.ts +89 -0
  367. package/esm/renderers/utils/transpiler.d.ts.map +1 -0
  368. package/esm/runtime/adapters/html.adapter.d.ts +59 -0
  369. package/esm/runtime/adapters/html.adapter.d.ts.map +1 -0
  370. package/esm/runtime/adapters/index.d.ts +26 -0
  371. package/esm/runtime/adapters/index.d.ts.map +1 -0
  372. package/esm/runtime/adapters/mdx.adapter.d.ts +73 -0
  373. package/esm/runtime/adapters/mdx.adapter.d.ts.map +1 -0
  374. package/esm/runtime/adapters/react.adapter.d.ts +70 -0
  375. package/esm/runtime/adapters/react.adapter.d.ts.map +1 -0
  376. package/esm/runtime/adapters/types.d.ts +95 -0
  377. package/esm/runtime/adapters/types.d.ts.map +1 -0
  378. package/esm/runtime/csp.d.ts +48 -0
  379. package/esm/runtime/csp.d.ts.map +1 -0
  380. package/esm/runtime/index.d.ts +17 -0
  381. package/esm/runtime/index.d.ts.map +1 -0
  382. package/esm/runtime/index.js +5186 -0
  383. package/esm/runtime/mcp-bridge.d.ts +101 -0
  384. package/esm/runtime/mcp-bridge.d.ts.map +1 -0
  385. package/esm/runtime/renderer-runtime.d.ts +133 -0
  386. package/esm/runtime/renderer-runtime.d.ts.map +1 -0
  387. package/esm/runtime/sanitizer.d.ts +172 -0
  388. package/esm/runtime/sanitizer.d.ts.map +1 -0
  389. package/esm/runtime/types.d.ts +415 -0
  390. package/esm/runtime/types.d.ts.map +1 -0
  391. package/esm/runtime/wrapper.d.ts +421 -0
  392. package/esm/runtime/wrapper.d.ts.map +1 -0
  393. package/esm/styles/index.d.ts +8 -0
  394. package/esm/styles/index.d.ts.map +1 -0
  395. package/esm/styles/index.js +171 -0
  396. package/esm/styles/variants.d.ts +51 -0
  397. package/esm/styles/variants.d.ts.map +1 -0
  398. package/esm/theme/cdn.d.ts +195 -0
  399. package/esm/theme/cdn.d.ts.map +1 -0
  400. package/esm/theme/index.d.ts +18 -0
  401. package/esm/theme/index.d.ts.map +1 -0
  402. package/esm/theme/index.js +700 -0
  403. package/esm/theme/platforms.d.ts +107 -0
  404. package/esm/theme/platforms.d.ts.map +1 -0
  405. package/esm/theme/presets/github-openai.d.ts +50 -0
  406. package/esm/theme/presets/github-openai.d.ts.map +1 -0
  407. package/esm/theme/presets/index.d.ts +11 -0
  408. package/esm/theme/presets/index.d.ts.map +1 -0
  409. package/esm/theme/theme.d.ts +396 -0
  410. package/esm/theme/theme.d.ts.map +1 -0
  411. package/esm/tool-template/builder.d.ts +213 -0
  412. package/esm/tool-template/builder.d.ts.map +1 -0
  413. package/esm/tool-template/index.d.ts +16 -0
  414. package/esm/tool-template/index.d.ts.map +1 -0
  415. package/esm/tool-template/index.js +3515 -0
  416. package/esm/types/index.d.ts +14 -0
  417. package/esm/types/index.d.ts.map +1 -0
  418. package/esm/types/index.js +75 -0
  419. package/esm/types/ui-config.d.ts +639 -0
  420. package/esm/types/ui-config.d.ts.map +1 -0
  421. package/esm/types/ui-runtime.d.ts +1007 -0
  422. package/esm/types/ui-runtime.d.ts.map +1 -0
  423. package/esm/typings/cache/cache-adapter.d.ts +125 -0
  424. package/esm/typings/cache/cache-adapter.d.ts.map +1 -0
  425. package/esm/typings/cache/index.d.ts +10 -0
  426. package/esm/typings/cache/index.d.ts.map +1 -0
  427. package/esm/typings/cache/memory-cache.d.ts +92 -0
  428. package/esm/typings/cache/memory-cache.d.ts.map +1 -0
  429. package/esm/typings/dts-parser.d.ts +90 -0
  430. package/esm/typings/dts-parser.d.ts.map +1 -0
  431. package/esm/typings/index.d.ts +48 -0
  432. package/esm/typings/index.d.ts.map +1 -0
  433. package/esm/typings/schemas.d.ts +232 -0
  434. package/esm/typings/schemas.d.ts.map +1 -0
  435. package/esm/typings/type-fetcher.d.ts +89 -0
  436. package/esm/typings/type-fetcher.d.ts.map +1 -0
  437. package/esm/typings/types.d.ts +320 -0
  438. package/esm/typings/types.d.ts.map +1 -0
  439. package/esm/universal/UniversalApp.d.ts +108 -0
  440. package/esm/universal/UniversalApp.d.ts.map +1 -0
  441. package/esm/universal/cached-runtime.d.ts +115 -0
  442. package/esm/universal/cached-runtime.d.ts.map +1 -0
  443. package/esm/universal/context.d.ts +122 -0
  444. package/esm/universal/context.d.ts.map +1 -0
  445. package/esm/universal/index.d.ts +57 -0
  446. package/esm/universal/index.d.ts.map +1 -0
  447. package/esm/universal/renderers/html.renderer.d.ts +37 -0
  448. package/esm/universal/renderers/html.renderer.d.ts.map +1 -0
  449. package/esm/universal/renderers/index.d.ts +112 -0
  450. package/esm/universal/renderers/index.d.ts.map +1 -0
  451. package/esm/universal/renderers/markdown.renderer.d.ts +33 -0
  452. package/esm/universal/renderers/markdown.renderer.d.ts.map +1 -0
  453. package/esm/universal/renderers/mdx.renderer.d.ts +38 -0
  454. package/esm/universal/renderers/mdx.renderer.d.ts.map +1 -0
  455. package/esm/universal/renderers/react.renderer.d.ts +46 -0
  456. package/esm/universal/renderers/react.renderer.d.ts.map +1 -0
  457. package/esm/universal/runtime-builder.d.ts +33 -0
  458. package/esm/universal/runtime-builder.d.ts.map +1 -0
  459. package/esm/universal/store.d.ts +135 -0
  460. package/esm/universal/store.d.ts.map +1 -0
  461. package/esm/universal/types.d.ts +199 -0
  462. package/esm/universal/types.d.ts.map +1 -0
  463. package/esm/utils/escape-html.d.ts +58 -0
  464. package/esm/utils/escape-html.d.ts.map +1 -0
  465. package/esm/utils/index.d.ts +10 -0
  466. package/esm/utils/index.d.ts.map +1 -0
  467. package/esm/utils/index.js +40 -0
  468. package/esm/utils/safe-stringify.d.ts +30 -0
  469. package/esm/utils/safe-stringify.d.ts.map +1 -0
  470. package/esm/validation/error-box.d.ts +56 -0
  471. package/esm/validation/error-box.d.ts.map +1 -0
  472. package/esm/validation/index.d.ts +13 -0
  473. package/esm/validation/index.d.ts.map +1 -0
  474. package/esm/validation/index.js +562 -0
  475. package/esm/validation/schema-paths.d.ts +118 -0
  476. package/esm/validation/schema-paths.d.ts.map +1 -0
  477. package/esm/validation/template-validator.d.ts +143 -0
  478. package/esm/validation/template-validator.d.ts.map +1 -0
  479. package/esm/validation/wrapper.d.ts +97 -0
  480. package/esm/validation/wrapper.d.ts.map +1 -0
  481. package/esm/web-components/core/attribute-parser.d.ts +82 -0
  482. package/esm/web-components/core/attribute-parser.d.ts.map +1 -0
  483. package/esm/web-components/core/base-element.d.ts +197 -0
  484. package/esm/web-components/core/base-element.d.ts.map +1 -0
  485. package/esm/web-components/core/index.d.ts +9 -0
  486. package/esm/web-components/core/index.d.ts.map +1 -0
  487. package/esm/web-components/elements/fmcp-alert.d.ts +46 -0
  488. package/esm/web-components/elements/fmcp-alert.d.ts.map +1 -0
  489. package/esm/web-components/elements/fmcp-badge.d.ts +47 -0
  490. package/esm/web-components/elements/fmcp-badge.d.ts.map +1 -0
  491. package/esm/web-components/elements/fmcp-button.d.ts +117 -0
  492. package/esm/web-components/elements/fmcp-button.d.ts.map +1 -0
  493. package/esm/web-components/elements/fmcp-card.d.ts +53 -0
  494. package/esm/web-components/elements/fmcp-card.d.ts.map +1 -0
  495. package/esm/web-components/elements/fmcp-input.d.ts +96 -0
  496. package/esm/web-components/elements/fmcp-input.d.ts.map +1 -0
  497. package/esm/web-components/elements/fmcp-select.d.ts +100 -0
  498. package/esm/web-components/elements/fmcp-select.d.ts.map +1 -0
  499. package/esm/web-components/elements/index.d.ts +13 -0
  500. package/esm/web-components/elements/index.d.ts.map +1 -0
  501. package/esm/web-components/index.d.ts +50 -0
  502. package/esm/web-components/index.d.ts.map +1 -0
  503. package/esm/web-components/index.js +2048 -0
  504. package/esm/web-components/register.d.ts +57 -0
  505. package/esm/web-components/register.d.ts.map +1 -0
  506. package/esm/web-components/types.d.ts +122 -0
  507. package/esm/web-components/types.d.ts.map +1 -0
  508. package/esm/widgets/index.d.ts +8 -0
  509. package/esm/widgets/index.d.ts.map +1 -0
  510. package/esm/widgets/index.js +941 -0
  511. package/esm/widgets/progress.d.ts +133 -0
  512. package/esm/widgets/progress.d.ts.map +1 -0
  513. package/esm/widgets/resource.d.ts +163 -0
  514. package/esm/widgets/resource.d.ts.map +1 -0
  515. package/handlebars/expression-extractor.d.ts +147 -0
  516. package/handlebars/expression-extractor.d.ts.map +1 -0
  517. package/handlebars/helpers.d.ts +339 -0
  518. package/handlebars/helpers.d.ts.map +1 -0
  519. package/handlebars/index.d.ts +195 -0
  520. package/handlebars/index.d.ts.map +1 -0
  521. package/handlebars/index.js +666 -0
  522. package/index.d.ts +56 -0
  523. package/index.d.ts.map +1 -0
  524. package/index.js +20942 -0
  525. package/layouts/base.d.ts +86 -0
  526. package/layouts/base.d.ts.map +1 -0
  527. package/layouts/index.d.ts +8 -0
  528. package/layouts/index.d.ts.map +1 -0
  529. package/layouts/index.js +930 -0
  530. package/layouts/presets.d.ts +134 -0
  531. package/layouts/presets.d.ts.map +1 -0
  532. package/package.json +28 -87
  533. package/pages/consent.d.ts +117 -0
  534. package/pages/consent.d.ts.map +1 -0
  535. package/pages/error.d.ts +101 -0
  536. package/pages/error.d.ts.map +1 -0
  537. package/pages/index.d.ts +9 -0
  538. package/pages/index.d.ts.map +1 -0
  539. package/pages/index.js +1602 -0
  540. package/react/Alert.d.ts +102 -0
  541. package/react/Alert.d.ts.map +1 -0
  542. package/react/Badge.d.ts +101 -0
  543. package/react/Badge.d.ts.map +1 -0
  544. package/react/Button.d.ts +109 -0
  545. package/react/Button.d.ts.map +1 -0
  546. package/react/Card.d.ts +104 -0
  547. package/react/Card.d.ts.map +1 -0
  548. package/react/hooks/context.d.ts +179 -0
  549. package/react/hooks/context.d.ts.map +1 -0
  550. package/react/hooks/index.d.ts +42 -0
  551. package/react/hooks/index.d.ts.map +1 -0
  552. package/react/hooks/tools.d.ts +284 -0
  553. package/react/hooks/tools.d.ts.map +1 -0
  554. package/react/index.d.ts +81 -0
  555. package/react/index.d.ts.map +1 -0
  556. package/react/index.js +1430 -0
  557. package/react/types.d.ts +106 -0
  558. package/react/types.d.ts.map +1 -0
  559. package/react/utils.d.ts +43 -0
  560. package/react/utils.d.ts.map +1 -0
  561. package/registry/index.d.ts +46 -0
  562. package/registry/index.d.ts.map +1 -0
  563. package/registry/index.js +6465 -0
  564. package/registry/render-template.d.ts +91 -0
  565. package/registry/render-template.d.ts.map +1 -0
  566. package/registry/tool-ui.registry.d.ts +294 -0
  567. package/registry/tool-ui.registry.d.ts.map +1 -0
  568. package/registry/uri-utils.d.ts +56 -0
  569. package/registry/uri-utils.d.ts.map +1 -0
  570. package/render/index.d.ts +8 -0
  571. package/render/index.d.ts.map +1 -0
  572. package/render/index.js +77 -0
  573. package/render/prerender.d.ts +57 -0
  574. package/render/prerender.d.ts.map +1 -0
  575. package/renderers/cache.d.ts +145 -0
  576. package/renderers/cache.d.ts.map +1 -0
  577. package/renderers/html.renderer.d.ts +123 -0
  578. package/renderers/html.renderer.d.ts.map +1 -0
  579. package/renderers/index.d.ts +36 -0
  580. package/renderers/index.d.ts.map +1 -0
  581. package/renderers/index.js +1882 -0
  582. package/renderers/mdx.renderer.d.ts +120 -0
  583. package/renderers/mdx.renderer.d.ts.map +1 -0
  584. package/renderers/react.renderer.d.ts +96 -0
  585. package/renderers/react.renderer.d.ts.map +1 -0
  586. package/renderers/registry.d.ts +134 -0
  587. package/renderers/registry.d.ts.map +1 -0
  588. package/renderers/types.d.ts +342 -0
  589. package/renderers/types.d.ts.map +1 -0
  590. package/renderers/utils/detect.d.ts +107 -0
  591. package/renderers/utils/detect.d.ts.map +1 -0
  592. package/renderers/utils/hash.d.ts +40 -0
  593. package/renderers/utils/hash.d.ts.map +1 -0
  594. package/renderers/utils/index.d.ts +9 -0
  595. package/renderers/utils/index.d.ts.map +1 -0
  596. package/renderers/utils/transpiler.d.ts +89 -0
  597. package/renderers/utils/transpiler.d.ts.map +1 -0
  598. package/runtime/adapters/html.adapter.d.ts +59 -0
  599. package/runtime/adapters/html.adapter.d.ts.map +1 -0
  600. package/runtime/adapters/index.d.ts +26 -0
  601. package/runtime/adapters/index.d.ts.map +1 -0
  602. package/runtime/adapters/mdx.adapter.d.ts +73 -0
  603. package/runtime/adapters/mdx.adapter.d.ts.map +1 -0
  604. package/runtime/adapters/react.adapter.d.ts +70 -0
  605. package/runtime/adapters/react.adapter.d.ts.map +1 -0
  606. package/runtime/adapters/types.d.ts +95 -0
  607. package/runtime/adapters/types.d.ts.map +1 -0
  608. package/runtime/csp.d.ts +48 -0
  609. package/runtime/csp.d.ts.map +1 -0
  610. package/runtime/index.d.ts +17 -0
  611. package/runtime/index.d.ts.map +1 -0
  612. package/runtime/index.js +5264 -0
  613. package/runtime/mcp-bridge.d.ts +101 -0
  614. package/runtime/mcp-bridge.d.ts.map +1 -0
  615. package/runtime/renderer-runtime.d.ts +133 -0
  616. package/runtime/renderer-runtime.d.ts.map +1 -0
  617. package/runtime/sanitizer.d.ts +172 -0
  618. package/runtime/sanitizer.d.ts.map +1 -0
  619. package/runtime/types.d.ts +415 -0
  620. package/runtime/types.d.ts.map +1 -0
  621. package/runtime/wrapper.d.ts +421 -0
  622. package/runtime/wrapper.d.ts.map +1 -0
  623. package/styles/index.d.ts +8 -0
  624. package/styles/index.d.ts.map +1 -0
  625. package/styles/index.js +222 -0
  626. package/styles/variants.d.ts +51 -0
  627. package/styles/variants.d.ts.map +1 -0
  628. package/theme/cdn.d.ts +195 -0
  629. package/theme/cdn.d.ts.map +1 -0
  630. package/theme/index.d.ts +18 -0
  631. package/theme/index.d.ts.map +1 -0
  632. package/theme/index.js +757 -0
  633. package/theme/platforms.d.ts +107 -0
  634. package/theme/platforms.d.ts.map +1 -0
  635. package/theme/presets/github-openai.d.ts +50 -0
  636. package/theme/presets/github-openai.d.ts.map +1 -0
  637. package/theme/presets/index.d.ts +11 -0
  638. package/theme/presets/index.d.ts.map +1 -0
  639. package/theme/theme.d.ts +396 -0
  640. package/theme/theme.d.ts.map +1 -0
  641. package/tool-template/builder.d.ts +213 -0
  642. package/tool-template/builder.d.ts.map +1 -0
  643. package/tool-template/index.d.ts +16 -0
  644. package/tool-template/index.d.ts.map +1 -0
  645. package/tool-template/index.js +3559 -0
  646. package/types/index.d.ts +14 -0
  647. package/types/index.d.ts.map +1 -0
  648. package/types/index.js +108 -0
  649. package/types/ui-config.d.ts +639 -0
  650. package/types/ui-config.d.ts.map +1 -0
  651. package/types/ui-runtime.d.ts +1007 -0
  652. package/types/ui-runtime.d.ts.map +1 -0
  653. package/typings/cache/cache-adapter.d.ts +125 -0
  654. package/typings/cache/cache-adapter.d.ts.map +1 -0
  655. package/typings/cache/index.d.ts +10 -0
  656. package/typings/cache/index.d.ts.map +1 -0
  657. package/typings/cache/memory-cache.d.ts +92 -0
  658. package/typings/cache/memory-cache.d.ts.map +1 -0
  659. package/typings/dts-parser.d.ts +90 -0
  660. package/typings/dts-parser.d.ts.map +1 -0
  661. package/typings/index.d.ts +48 -0
  662. package/typings/index.d.ts.map +1 -0
  663. package/typings/schemas.d.ts +232 -0
  664. package/typings/schemas.d.ts.map +1 -0
  665. package/typings/type-fetcher.d.ts +89 -0
  666. package/typings/type-fetcher.d.ts.map +1 -0
  667. package/typings/types.d.ts +320 -0
  668. package/typings/types.d.ts.map +1 -0
  669. package/universal/UniversalApp.d.ts +108 -0
  670. package/universal/UniversalApp.d.ts.map +1 -0
  671. package/universal/cached-runtime.d.ts +115 -0
  672. package/universal/cached-runtime.d.ts.map +1 -0
  673. package/universal/context.d.ts +122 -0
  674. package/universal/context.d.ts.map +1 -0
  675. package/universal/index.d.ts +57 -0
  676. package/universal/index.d.ts.map +1 -0
  677. package/universal/renderers/html.renderer.d.ts +37 -0
  678. package/universal/renderers/html.renderer.d.ts.map +1 -0
  679. package/universal/renderers/index.d.ts +112 -0
  680. package/universal/renderers/index.d.ts.map +1 -0
  681. package/universal/renderers/markdown.renderer.d.ts +33 -0
  682. package/universal/renderers/markdown.renderer.d.ts.map +1 -0
  683. package/universal/renderers/mdx.renderer.d.ts +38 -0
  684. package/universal/renderers/mdx.renderer.d.ts.map +1 -0
  685. package/universal/renderers/react.renderer.d.ts +46 -0
  686. package/universal/renderers/react.renderer.d.ts.map +1 -0
  687. package/universal/runtime-builder.d.ts +33 -0
  688. package/universal/runtime-builder.d.ts.map +1 -0
  689. package/universal/store.d.ts +135 -0
  690. package/universal/store.d.ts.map +1 -0
  691. package/universal/types.d.ts +199 -0
  692. package/universal/types.d.ts.map +1 -0
  693. package/utils/escape-html.d.ts +58 -0
  694. package/utils/escape-html.d.ts.map +1 -0
  695. package/utils/index.d.ts +10 -0
  696. package/utils/index.d.ts.map +1 -0
  697. package/utils/index.js +70 -0
  698. package/utils/safe-stringify.d.ts +30 -0
  699. package/utils/safe-stringify.d.ts.map +1 -0
  700. package/validation/error-box.d.ts +56 -0
  701. package/validation/error-box.d.ts.map +1 -0
  702. package/validation/index.d.ts +13 -0
  703. package/validation/index.d.ts.map +1 -0
  704. package/validation/index.js +603 -0
  705. package/validation/schema-paths.d.ts +118 -0
  706. package/validation/schema-paths.d.ts.map +1 -0
  707. package/validation/template-validator.d.ts +143 -0
  708. package/validation/template-validator.d.ts.map +1 -0
  709. package/validation/wrapper.d.ts +97 -0
  710. package/validation/wrapper.d.ts.map +1 -0
  711. package/web-components/core/attribute-parser.d.ts +82 -0
  712. package/web-components/core/attribute-parser.d.ts.map +1 -0
  713. package/web-components/core/base-element.d.ts +197 -0
  714. package/web-components/core/base-element.d.ts.map +1 -0
  715. package/web-components/core/index.d.ts +9 -0
  716. package/web-components/core/index.d.ts.map +1 -0
  717. package/web-components/elements/fmcp-alert.d.ts +46 -0
  718. package/web-components/elements/fmcp-alert.d.ts.map +1 -0
  719. package/web-components/elements/fmcp-badge.d.ts +47 -0
  720. package/web-components/elements/fmcp-badge.d.ts.map +1 -0
  721. package/web-components/elements/fmcp-button.d.ts +117 -0
  722. package/web-components/elements/fmcp-button.d.ts.map +1 -0
  723. package/web-components/elements/fmcp-card.d.ts +53 -0
  724. package/web-components/elements/fmcp-card.d.ts.map +1 -0
  725. package/web-components/elements/fmcp-input.d.ts +96 -0
  726. package/web-components/elements/fmcp-input.d.ts.map +1 -0
  727. package/web-components/elements/fmcp-select.d.ts +100 -0
  728. package/web-components/elements/fmcp-select.d.ts.map +1 -0
  729. package/web-components/elements/index.d.ts +13 -0
  730. package/web-components/elements/index.d.ts.map +1 -0
  731. package/web-components/index.d.ts +50 -0
  732. package/web-components/index.d.ts.map +1 -0
  733. package/web-components/index.js +2093 -0
  734. package/web-components/register.d.ts +57 -0
  735. package/web-components/register.d.ts.map +1 -0
  736. package/web-components/types.d.ts +122 -0
  737. package/web-components/types.d.ts.map +1 -0
  738. package/widgets/index.d.ts +8 -0
  739. package/widgets/index.d.ts.map +1 -0
  740. package/widgets/index.js +978 -0
  741. package/widgets/progress.d.ts +133 -0
  742. package/widgets/progress.d.ts.map +1 -0
  743. package/widgets/resource.d.ts +163 -0
  744. package/widgets/resource.d.ts.map +1 -0
  745. package/src/adapters/index.d.ts +0 -10
  746. package/src/adapters/index.js +0 -18
  747. package/src/adapters/index.js.map +0 -1
  748. package/src/adapters/platform-meta.d.ts +0 -165
  749. package/src/adapters/platform-meta.js +0 -310
  750. package/src/adapters/platform-meta.js.map +0 -1
  751. package/src/base-template/bridge.d.ts +0 -89
  752. package/src/base-template/bridge.js +0 -452
  753. package/src/base-template/bridge.js.map +0 -1
  754. package/src/base-template/default-base-template.d.ts +0 -91
  755. package/src/base-template/default-base-template.js +0 -435
  756. package/src/base-template/default-base-template.js.map +0 -1
  757. package/src/base-template/index.d.ts +0 -14
  758. package/src/base-template/index.js +0 -30
  759. package/src/base-template/index.js.map +0 -1
  760. package/src/base-template/polyfills.d.ts +0 -30
  761. package/src/base-template/polyfills.js +0 -190
  762. package/src/base-template/polyfills.js.map +0 -1
  763. package/src/base-template/theme-styles.d.ts +0 -73
  764. package/src/base-template/theme-styles.js +0 -95
  765. package/src/base-template/theme-styles.js.map +0 -1
  766. package/src/bridge/adapters/base-adapter.d.ts +0 -103
  767. package/src/bridge/adapters/base-adapter.js +0 -314
  768. package/src/bridge/adapters/base-adapter.js.map +0 -1
  769. package/src/bridge/adapters/claude.adapter.d.ts +0 -66
  770. package/src/bridge/adapters/claude.adapter.js +0 -145
  771. package/src/bridge/adapters/claude.adapter.js.map +0 -1
  772. package/src/bridge/adapters/ext-apps.adapter.d.ts +0 -142
  773. package/src/bridge/adapters/ext-apps.adapter.js +0 -416
  774. package/src/bridge/adapters/ext-apps.adapter.js.map +0 -1
  775. package/src/bridge/adapters/gemini.adapter.d.ts +0 -63
  776. package/src/bridge/adapters/gemini.adapter.js +0 -160
  777. package/src/bridge/adapters/gemini.adapter.js.map +0 -1
  778. package/src/bridge/adapters/generic.adapter.d.ts +0 -55
  779. package/src/bridge/adapters/generic.adapter.js +0 -108
  780. package/src/bridge/adapters/generic.adapter.js.map +0 -1
  781. package/src/bridge/adapters/index.d.ts +0 -25
  782. package/src/bridge/adapters/index.js +0 -65
  783. package/src/bridge/adapters/index.js.map +0 -1
  784. package/src/bridge/adapters/openai.adapter.d.ts +0 -64
  785. package/src/bridge/adapters/openai.adapter.js +0 -194
  786. package/src/bridge/adapters/openai.adapter.js.map +0 -1
  787. package/src/bridge/core/adapter-registry.d.ts +0 -121
  788. package/src/bridge/core/adapter-registry.js +0 -271
  789. package/src/bridge/core/adapter-registry.js.map +0 -1
  790. package/src/bridge/core/bridge-factory.d.ts +0 -198
  791. package/src/bridge/core/bridge-factory.js +0 -428
  792. package/src/bridge/core/bridge-factory.js.map +0 -1
  793. package/src/bridge/core/index.d.ts +0 -9
  794. package/src/bridge/core/index.js +0 -22
  795. package/src/bridge/core/index.js.map +0 -1
  796. package/src/bridge/index.d.ts +0 -61
  797. package/src/bridge/index.js +0 -94
  798. package/src/bridge/index.js.map +0 -1
  799. package/src/bridge/runtime/iife-generator.d.ts +0 -61
  800. package/src/bridge/runtime/iife-generator.js +0 -940
  801. package/src/bridge/runtime/iife-generator.js.map +0 -1
  802. package/src/bridge/runtime/index.d.ts +0 -8
  803. package/src/bridge/runtime/index.js +0 -16
  804. package/src/bridge/runtime/index.js.map +0 -1
  805. package/src/bridge/types.d.ts +0 -385
  806. package/src/bridge/types.js +0 -11
  807. package/src/bridge/types.js.map +0 -1
  808. package/src/build/cdn-resources.d.ts +0 -140
  809. package/src/build/cdn-resources.js +0 -314
  810. package/src/build/cdn-resources.js.map +0 -1
  811. package/src/build/index.d.ts +0 -294
  812. package/src/build/index.js +0 -325
  813. package/src/build/index.js.map +0 -1
  814. package/src/build/widget-manifest.d.ts +0 -212
  815. package/src/build/widget-manifest.js +0 -652
  816. package/src/build/widget-manifest.js.map +0 -1
  817. package/src/bundler/bundler.d.ts +0 -110
  818. package/src/bundler/bundler.js +0 -432
  819. package/src/bundler/bundler.js.map +0 -1
  820. package/src/bundler/cache.d.ts +0 -172
  821. package/src/bundler/cache.js +0 -250
  822. package/src/bundler/cache.js.map +0 -1
  823. package/src/bundler/index.d.ts +0 -41
  824. package/src/bundler/index.js +0 -73
  825. package/src/bundler/index.js.map +0 -1
  826. package/src/bundler/sandbox/enclave-adapter.d.ts +0 -120
  827. package/src/bundler/sandbox/enclave-adapter.js +0 -339
  828. package/src/bundler/sandbox/enclave-adapter.js.map +0 -1
  829. package/src/bundler/sandbox/executor.d.ts +0 -13
  830. package/src/bundler/sandbox/executor.js +0 -22
  831. package/src/bundler/sandbox/executor.js.map +0 -1
  832. package/src/bundler/sandbox/policy.d.ts +0 -61
  833. package/src/bundler/sandbox/policy.js +0 -238
  834. package/src/bundler/sandbox/policy.js.map +0 -1
  835. package/src/bundler/types.d.ts +0 -347
  836. package/src/bundler/types.js +0 -132
  837. package/src/bundler/types.js.map +0 -1
  838. package/src/components/alert.d.ts +0 -71
  839. package/src/components/alert.js +0 -189
  840. package/src/components/alert.js.map +0 -1
  841. package/src/components/alert.schema.d.ts +0 -114
  842. package/src/components/alert.schema.js +0 -105
  843. package/src/components/alert.schema.js.map +0 -1
  844. package/src/components/avatar.d.ts +0 -76
  845. package/src/components/avatar.js +0 -176
  846. package/src/components/avatar.js.map +0 -1
  847. package/src/components/avatar.schema.d.ts +0 -169
  848. package/src/components/avatar.schema.js +0 -103
  849. package/src/components/avatar.schema.js.map +0 -1
  850. package/src/components/badge.d.ts +0 -70
  851. package/src/components/badge.js +0 -149
  852. package/src/components/badge.js.map +0 -1
  853. package/src/components/badge.schema.d.ts +0 -109
  854. package/src/components/badge.schema.js +0 -96
  855. package/src/components/badge.schema.js.map +0 -1
  856. package/src/components/button.d.ts +0 -111
  857. package/src/components/button.js +0 -336
  858. package/src/components/button.js.map +0 -1
  859. package/src/components/button.schema.d.ts +0 -148
  860. package/src/components/button.schema.js +0 -121
  861. package/src/components/button.schema.js.map +0 -1
  862. package/src/components/card.d.ts +0 -60
  863. package/src/components/card.js +0 -117
  864. package/src/components/card.js.map +0 -1
  865. package/src/components/card.schema.d.ts +0 -113
  866. package/src/components/card.schema.js +0 -98
  867. package/src/components/card.schema.js.map +0 -1
  868. package/src/components/form.d.ts +0 -239
  869. package/src/components/form.js +0 -420
  870. package/src/components/form.js.map +0 -1
  871. package/src/components/form.schema.d.ts +0 -441
  872. package/src/components/form.schema.js +0 -406
  873. package/src/components/form.schema.js.map +0 -1
  874. package/src/components/index.d.ts +0 -29
  875. package/src/components/index.js +0 -98
  876. package/src/components/index.js.map +0 -1
  877. package/src/components/list.d.ts +0 -127
  878. package/src/components/list.js +0 -279
  879. package/src/components/list.js.map +0 -1
  880. package/src/components/list.schema.d.ts +0 -134
  881. package/src/components/list.schema.js +0 -168
  882. package/src/components/list.schema.js.map +0 -1
  883. package/src/components/modal.d.ts +0 -111
  884. package/src/components/modal.js +0 -260
  885. package/src/components/modal.js.map +0 -1
  886. package/src/components/modal.schema.d.ts +0 -186
  887. package/src/components/modal.schema.js +0 -167
  888. package/src/components/modal.schema.js.map +0 -1
  889. package/src/components/table.d.ts +0 -105
  890. package/src/components/table.js +0 -283
  891. package/src/components/table.js.map +0 -1
  892. package/src/components/table.schema.d.ts +0 -159
  893. package/src/components/table.schema.js +0 -173
  894. package/src/components/table.schema.js.map +0 -1
  895. package/src/handlebars/helpers.d.ts +0 -348
  896. package/src/handlebars/helpers.js +0 -605
  897. package/src/handlebars/helpers.js.map +0 -1
  898. package/src/handlebars/index.d.ts +0 -193
  899. package/src/handlebars/index.js +0 -350
  900. package/src/handlebars/index.js.map +0 -1
  901. package/src/index.d.ts +0 -50
  902. package/src/index.js +0 -192
  903. package/src/index.js.map +0 -1
  904. package/src/layouts/base.d.ts +0 -88
  905. package/src/layouts/base.js +0 -227
  906. package/src/layouts/base.js.map +0 -1
  907. package/src/layouts/index.d.ts +0 -7
  908. package/src/layouts/index.js +0 -25
  909. package/src/layouts/index.js.map +0 -1
  910. package/src/layouts/presets.d.ts +0 -133
  911. package/src/layouts/presets.js +0 -277
  912. package/src/layouts/presets.js.map +0 -1
  913. package/src/pages/consent.d.ts +0 -116
  914. package/src/pages/consent.js +0 -218
  915. package/src/pages/consent.js.map +0 -1
  916. package/src/pages/error.d.ts +0 -100
  917. package/src/pages/error.js +0 -263
  918. package/src/pages/error.js.map +0 -1
  919. package/src/pages/index.d.ts +0 -8
  920. package/src/pages/index.js +0 -27
  921. package/src/pages/index.js.map +0 -1
  922. package/src/react/Alert.d.ts +0 -101
  923. package/src/react/Alert.js +0 -51
  924. package/src/react/Alert.js.map +0 -1
  925. package/src/react/Badge.d.ts +0 -100
  926. package/src/react/Badge.js +0 -55
  927. package/src/react/Badge.js.map +0 -1
  928. package/src/react/Button.d.ts +0 -108
  929. package/src/react/Button.js +0 -52
  930. package/src/react/Button.js.map +0 -1
  931. package/src/react/Card.d.ts +0 -103
  932. package/src/react/Card.js +0 -55
  933. package/src/react/Card.js.map +0 -1
  934. package/src/react/hooks/context.d.ts +0 -178
  935. package/src/react/hooks/context.js +0 -287
  936. package/src/react/hooks/context.js.map +0 -1
  937. package/src/react/hooks/index.d.ts +0 -41
  938. package/src/react/hooks/index.js +0 -61
  939. package/src/react/hooks/index.js.map +0 -1
  940. package/src/react/hooks/tools.d.ts +0 -283
  941. package/src/react/hooks/tools.js +0 -465
  942. package/src/react/hooks/tools.js.map +0 -1
  943. package/src/react/index.d.ts +0 -80
  944. package/src/react/index.js +0 -113
  945. package/src/react/index.js.map +0 -1
  946. package/src/react/types.d.ts +0 -105
  947. package/src/react/types.js +0 -12
  948. package/src/react/types.js.map +0 -1
  949. package/src/react/utils.d.ts +0 -42
  950. package/src/react/utils.js +0 -99
  951. package/src/react/utils.js.map +0 -1
  952. package/src/registry/index.d.ts +0 -45
  953. package/src/registry/index.js +0 -67
  954. package/src/registry/index.js.map +0 -1
  955. package/src/registry/render-template.d.ts +0 -86
  956. package/src/registry/render-template.js +0 -239
  957. package/src/registry/render-template.js.map +0 -1
  958. package/src/registry/tool-ui.registry.d.ts +0 -260
  959. package/src/registry/tool-ui.registry.js +0 -438
  960. package/src/registry/tool-ui.registry.js.map +0 -1
  961. package/src/registry/uri-utils.d.ts +0 -55
  962. package/src/registry/uri-utils.js +0 -97
  963. package/src/registry/uri-utils.js.map +0 -1
  964. package/src/render/index.d.ts +0 -7
  965. package/src/render/index.js +0 -14
  966. package/src/render/index.js.map +0 -1
  967. package/src/render/prerender.d.ts +0 -56
  968. package/src/render/prerender.js +0 -98
  969. package/src/render/prerender.js.map +0 -1
  970. package/src/renderers/cache.d.ts +0 -144
  971. package/src/renderers/cache.js +0 -240
  972. package/src/renderers/cache.js.map +0 -1
  973. package/src/renderers/html.renderer.d.ts +0 -122
  974. package/src/renderers/html.renderer.js +0 -204
  975. package/src/renderers/html.renderer.js.map +0 -1
  976. package/src/renderers/index.d.ts +0 -35
  977. package/src/renderers/index.js +0 -70
  978. package/src/renderers/index.js.map +0 -1
  979. package/src/renderers/mdx.renderer.d.ts +0 -119
  980. package/src/renderers/mdx.renderer.js +0 -305
  981. package/src/renderers/mdx.renderer.js.map +0 -1
  982. package/src/renderers/react.renderer.d.ts +0 -95
  983. package/src/renderers/react.renderer.js +0 -260
  984. package/src/renderers/react.renderer.js.map +0 -1
  985. package/src/renderers/registry.d.ts +0 -133
  986. package/src/renderers/registry.js +0 -232
  987. package/src/renderers/registry.js.map +0 -1
  988. package/src/renderers/types.d.ts +0 -341
  989. package/src/renderers/types.js +0 -9
  990. package/src/renderers/types.js.map +0 -1
  991. package/src/renderers/utils/detect.d.ts +0 -106
  992. package/src/renderers/utils/detect.js +0 -267
  993. package/src/renderers/utils/detect.js.map +0 -1
  994. package/src/renderers/utils/hash.d.ts +0 -39
  995. package/src/renderers/utils/hash.js +0 -75
  996. package/src/renderers/utils/hash.js.map +0 -1
  997. package/src/renderers/utils/index.d.ts +0 -8
  998. package/src/renderers/utils/index.js +0 -28
  999. package/src/renderers/utils/index.js.map +0 -1
  1000. package/src/renderers/utils/transpiler.d.ts +0 -88
  1001. package/src/renderers/utils/transpiler.js +0 -215
  1002. package/src/renderers/utils/transpiler.js.map +0 -1
  1003. package/src/runtime/adapters/html.adapter.d.ts +0 -58
  1004. package/src/runtime/adapters/html.adapter.js +0 -131
  1005. package/src/runtime/adapters/html.adapter.js.map +0 -1
  1006. package/src/runtime/adapters/index.d.ts +0 -25
  1007. package/src/runtime/adapters/index.js +0 -54
  1008. package/src/runtime/adapters/index.js.map +0 -1
  1009. package/src/runtime/adapters/mdx.adapter.d.ts +0 -72
  1010. package/src/runtime/adapters/mdx.adapter.js +0 -241
  1011. package/src/runtime/adapters/mdx.adapter.js.map +0 -1
  1012. package/src/runtime/adapters/react.adapter.d.ts +0 -69
  1013. package/src/runtime/adapters/react.adapter.js +0 -245
  1014. package/src/runtime/adapters/react.adapter.js.map +0 -1
  1015. package/src/runtime/adapters/types.d.ts +0 -94
  1016. package/src/runtime/adapters/types.js +0 -11
  1017. package/src/runtime/adapters/types.js.map +0 -1
  1018. package/src/runtime/csp.d.ts +0 -37
  1019. package/src/runtime/csp.js +0 -140
  1020. package/src/runtime/csp.js.map +0 -1
  1021. package/src/runtime/index.d.ts +0 -16
  1022. package/src/runtime/index.js +0 -72
  1023. package/src/runtime/index.js.map +0 -1
  1024. package/src/runtime/mcp-bridge.d.ts +0 -100
  1025. package/src/runtime/mcp-bridge.js +0 -581
  1026. package/src/runtime/mcp-bridge.js.map +0 -1
  1027. package/src/runtime/renderer-runtime.d.ts +0 -132
  1028. package/src/runtime/renderer-runtime.js +0 -389
  1029. package/src/runtime/renderer-runtime.js.map +0 -1
  1030. package/src/runtime/sanitizer.d.ts +0 -171
  1031. package/src/runtime/sanitizer.js +0 -318
  1032. package/src/runtime/sanitizer.js.map +0 -1
  1033. package/src/runtime/types.d.ts +0 -414
  1034. package/src/runtime/types.js +0 -12
  1035. package/src/runtime/types.js.map +0 -1
  1036. package/src/runtime/wrapper.d.ts +0 -375
  1037. package/src/runtime/wrapper.js +0 -1793
  1038. package/src/runtime/wrapper.js.map +0 -1
  1039. package/src/styles/index.d.ts +0 -7
  1040. package/src/styles/index.js +0 -11
  1041. package/src/styles/index.js.map +0 -1
  1042. package/src/styles/variants.d.ts +0 -50
  1043. package/src/styles/variants.js +0 -175
  1044. package/src/styles/variants.js.map +0 -1
  1045. package/src/theme/cdn.d.ts +0 -194
  1046. package/src/theme/cdn.js +0 -375
  1047. package/src/theme/cdn.js.map +0 -1
  1048. package/src/theme/index.d.ts +0 -17
  1049. package/src/theme/index.js +0 -57
  1050. package/src/theme/index.js.map +0 -1
  1051. package/src/theme/platforms.d.ts +0 -106
  1052. package/src/theme/platforms.js +0 -161
  1053. package/src/theme/platforms.js.map +0 -1
  1054. package/src/theme/presets/github-openai.d.ts +0 -49
  1055. package/src/theme/presets/github-openai.js +0 -189
  1056. package/src/theme/presets/github-openai.js.map +0 -1
  1057. package/src/theme/presets/index.d.ts +0 -10
  1058. package/src/theme/presets/index.js +0 -17
  1059. package/src/theme/presets/index.js.map +0 -1
  1060. package/src/theme/theme.d.ts +0 -395
  1061. package/src/theme/theme.js +0 -332
  1062. package/src/theme/theme.js.map +0 -1
  1063. package/src/tool-template/builder.d.ts +0 -212
  1064. package/src/tool-template/builder.js +0 -397
  1065. package/src/tool-template/builder.js.map +0 -1
  1066. package/src/tool-template/index.d.ts +0 -15
  1067. package/src/tool-template/index.js +0 -38
  1068. package/src/tool-template/index.js.map +0 -1
  1069. package/src/types/index.d.ts +0 -13
  1070. package/src/types/index.js +0 -26
  1071. package/src/types/index.js.map +0 -1
  1072. package/src/types/ui-config.d.ts +0 -357
  1073. package/src/types/ui-config.js +0 -12
  1074. package/src/types/ui-config.js.map +0 -1
  1075. package/src/types/ui-runtime.d.ts +0 -965
  1076. package/src/types/ui-runtime.js +0 -117
  1077. package/src/types/ui-runtime.js.map +0 -1
  1078. package/src/validation/error-box.d.ts +0 -55
  1079. package/src/validation/error-box.js +0 -75
  1080. package/src/validation/error-box.js.map +0 -1
  1081. package/src/validation/index.d.ts +0 -12
  1082. package/src/validation/index.js +0 -21
  1083. package/src/validation/index.js.map +0 -1
  1084. package/src/validation/wrapper.d.ts +0 -96
  1085. package/src/validation/wrapper.js +0 -117
  1086. package/src/validation/wrapper.js.map +0 -1
  1087. package/src/web-components/core/attribute-parser.d.ts +0 -85
  1088. package/src/web-components/core/attribute-parser.js +0 -189
  1089. package/src/web-components/core/attribute-parser.js.map +0 -1
  1090. package/src/web-components/core/base-element.d.ts +0 -197
  1091. package/src/web-components/core/base-element.js +0 -289
  1092. package/src/web-components/core/base-element.js.map +0 -1
  1093. package/src/web-components/core/index.d.ts +0 -8
  1094. package/src/web-components/core/index.js +0 -18
  1095. package/src/web-components/core/index.js.map +0 -1
  1096. package/src/web-components/elements/fmcp-alert.d.ts +0 -45
  1097. package/src/web-components/elements/fmcp-alert.js +0 -93
  1098. package/src/web-components/elements/fmcp-alert.js.map +0 -1
  1099. package/src/web-components/elements/fmcp-badge.d.ts +0 -46
  1100. package/src/web-components/elements/fmcp-badge.js +0 -99
  1101. package/src/web-components/elements/fmcp-badge.js.map +0 -1
  1102. package/src/web-components/elements/fmcp-button.d.ts +0 -124
  1103. package/src/web-components/elements/fmcp-button.js +0 -233
  1104. package/src/web-components/elements/fmcp-button.js.map +0 -1
  1105. package/src/web-components/elements/fmcp-card.d.ts +0 -52
  1106. package/src/web-components/elements/fmcp-card.js +0 -115
  1107. package/src/web-components/elements/fmcp-card.js.map +0 -1
  1108. package/src/web-components/elements/fmcp-input.d.ts +0 -95
  1109. package/src/web-components/elements/fmcp-input.js +0 -248
  1110. package/src/web-components/elements/fmcp-input.js.map +0 -1
  1111. package/src/web-components/elements/fmcp-select.d.ts +0 -99
  1112. package/src/web-components/elements/fmcp-select.js +0 -243
  1113. package/src/web-components/elements/fmcp-select.js.map +0 -1
  1114. package/src/web-components/elements/index.d.ts +0 -12
  1115. package/src/web-components/elements/index.js +0 -34
  1116. package/src/web-components/elements/index.js.map +0 -1
  1117. package/src/web-components/index.d.ts +0 -49
  1118. package/src/web-components/index.js +0 -75
  1119. package/src/web-components/index.js.map +0 -1
  1120. package/src/web-components/register.d.ts +0 -56
  1121. package/src/web-components/register.js +0 -80
  1122. package/src/web-components/register.js.map +0 -1
  1123. package/src/web-components/types.d.ts +0 -121
  1124. package/src/web-components/types.js +0 -25
  1125. package/src/web-components/types.js.map +0 -1
  1126. package/src/widgets/index.d.ts +0 -7
  1127. package/src/widgets/index.js +0 -24
  1128. package/src/widgets/index.js.map +0 -1
  1129. package/src/widgets/progress.d.ts +0 -132
  1130. package/src/widgets/progress.js +0 -303
  1131. package/src/widgets/progress.js.map +0 -1
  1132. package/src/widgets/resource.d.ts +0 -162
  1133. package/src/widgets/resource.js +0 -340
  1134. package/src/widgets/resource.js.map +0 -1
@@ -0,0 +1,4687 @@
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/bundler/file-cache/storage/interface.ts
12
+ function calculateManifestSize(manifest) {
13
+ try {
14
+ return Buffer.byteLength(JSON.stringify(manifest), "utf8");
15
+ } catch {
16
+ return 0;
17
+ }
18
+ }
19
+ var DEFAULT_STORAGE_OPTIONS;
20
+ var init_interface = __esm({
21
+ "libs/ui/src/bundler/file-cache/storage/interface.ts"() {
22
+ "use strict";
23
+ DEFAULT_STORAGE_OPTIONS = {
24
+ maxEntries: 1e3,
25
+ maxSize: 100 * 1024 * 1024,
26
+ // 100MB
27
+ defaultTtl: 24 * 60 * 60,
28
+ // 24 hours
29
+ compress: false
30
+ };
31
+ }
32
+ });
33
+
34
+ // libs/ui/src/bundler/file-cache/storage/filesystem.ts
35
+ var filesystem_exports = {};
36
+ __export(filesystem_exports, {
37
+ CacheInitializationError: () => CacheInitializationError,
38
+ CacheOperationError: () => CacheOperationError,
39
+ FilesystemStorage: () => FilesystemStorage,
40
+ StorageNotInitializedError: () => StorageNotInitializedError,
41
+ createFilesystemStorage: () => createFilesystemStorage
42
+ });
43
+ import { mkdir, readFile, writeFile, readdir, unlink, rm } from "fs/promises";
44
+ import { join, dirname } from "path";
45
+ import { existsSync } from "fs";
46
+ import { createHash } from "crypto";
47
+ function createFilesystemStorage(options) {
48
+ return new FilesystemStorage(options);
49
+ }
50
+ var CacheInitializationError, CacheOperationError, StorageNotInitializedError, DEFAULT_FS_OPTIONS, FilesystemStorage;
51
+ var init_filesystem = __esm({
52
+ "libs/ui/src/bundler/file-cache/storage/filesystem.ts"() {
53
+ "use strict";
54
+ init_interface();
55
+ CacheInitializationError = class extends Error {
56
+ cause;
57
+ constructor(message, cause) {
58
+ super(message);
59
+ this.name = "CacheInitializationError";
60
+ this.cause = cause;
61
+ }
62
+ };
63
+ CacheOperationError = class extends Error {
64
+ cause;
65
+ constructor(message, cause) {
66
+ super(message);
67
+ this.name = "CacheOperationError";
68
+ this.cause = cause;
69
+ }
70
+ };
71
+ StorageNotInitializedError = class extends Error {
72
+ constructor() {
73
+ super("Storage not initialized. Call initialize() first.");
74
+ this.name = "StorageNotInitializedError";
75
+ }
76
+ };
77
+ DEFAULT_FS_OPTIONS = {
78
+ ...DEFAULT_STORAGE_OPTIONS,
79
+ cacheDir: ".frontmcp-cache/builds",
80
+ extension: ".json"
81
+ };
82
+ FilesystemStorage = class {
83
+ type = "filesystem";
84
+ options;
85
+ initialized = false;
86
+ stats = {
87
+ entries: 0,
88
+ totalSize: 0,
89
+ hits: 0,
90
+ misses: 0,
91
+ hitRate: 0
92
+ };
93
+ constructor(options = {}) {
94
+ this.options = {
95
+ ...DEFAULT_FS_OPTIONS,
96
+ ...options
97
+ };
98
+ }
99
+ /**
100
+ * Initialize the storage directory.
101
+ */
102
+ async initialize() {
103
+ if (this.initialized) return;
104
+ try {
105
+ await mkdir(this.options.cacheDir, { recursive: true });
106
+ await this.loadStats();
107
+ this.initialized = true;
108
+ } catch (error) {
109
+ throw new CacheInitializationError(`Failed to initialize cache directory: ${error}`, error);
110
+ }
111
+ }
112
+ /**
113
+ * Get a cached manifest.
114
+ */
115
+ async get(key) {
116
+ this.ensureInitialized();
117
+ const filePath = this.getFilePath(key);
118
+ try {
119
+ if (!existsSync(filePath)) {
120
+ this.stats.misses++;
121
+ this.updateHitRate();
122
+ return void 0;
123
+ }
124
+ const content = await readFile(filePath, "utf8");
125
+ const entry = JSON.parse(content);
126
+ if (Date.now() > entry.metadata.expiresAt) {
127
+ await this.delete(key);
128
+ this.stats.misses++;
129
+ this.updateHitRate();
130
+ return void 0;
131
+ }
132
+ entry.metadata.lastAccessedAt = Date.now();
133
+ entry.metadata.accessCount++;
134
+ this.writeEntry(filePath, entry).catch((err) => {
135
+ if (process.env["DEBUG"]) {
136
+ console.debug(`[FilesystemStorage] Failed to update cache metadata for ${key}: ${err}`);
137
+ }
138
+ });
139
+ this.stats.hits++;
140
+ this.updateHitRate();
141
+ return entry.data;
142
+ } catch {
143
+ this.stats.misses++;
144
+ this.updateHitRate();
145
+ return void 0;
146
+ }
147
+ }
148
+ /**
149
+ * Store a manifest in cache.
150
+ */
151
+ async set(key, manifest, ttl) {
152
+ this.ensureInitialized();
153
+ const filePath = this.getFilePath(key);
154
+ const size = calculateManifestSize(manifest);
155
+ const effectiveTtl = ttl ?? this.options.defaultTtl;
156
+ await this.ensureCapacity(size);
157
+ const entry = {
158
+ data: manifest,
159
+ metadata: {
160
+ key,
161
+ size,
162
+ createdAt: Date.now(),
163
+ expiresAt: Date.now() + effectiveTtl * 1e3,
164
+ lastAccessedAt: Date.now(),
165
+ accessCount: 0
166
+ }
167
+ };
168
+ await this.writeEntry(filePath, entry);
169
+ this.stats.entries++;
170
+ this.stats.totalSize += size;
171
+ }
172
+ /**
173
+ * Check if a key exists.
174
+ */
175
+ async has(key) {
176
+ this.ensureInitialized();
177
+ const filePath = this.getFilePath(key);
178
+ try {
179
+ if (!existsSync(filePath)) return false;
180
+ const content = await readFile(filePath, "utf8");
181
+ const entry = JSON.parse(content);
182
+ if (Date.now() > entry.metadata.expiresAt) {
183
+ await this.delete(key);
184
+ return false;
185
+ }
186
+ return true;
187
+ } catch {
188
+ return false;
189
+ }
190
+ }
191
+ /**
192
+ * Delete a cached entry.
193
+ */
194
+ async delete(key) {
195
+ this.ensureInitialized();
196
+ const filePath = this.getFilePath(key);
197
+ try {
198
+ if (!existsSync(filePath)) return false;
199
+ const content = await readFile(filePath, "utf8");
200
+ const entry = JSON.parse(content);
201
+ await unlink(filePath);
202
+ this.stats.entries = Math.max(0, this.stats.entries - 1);
203
+ this.stats.totalSize = Math.max(0, this.stats.totalSize - entry.metadata.size);
204
+ return true;
205
+ } catch {
206
+ return false;
207
+ }
208
+ }
209
+ /**
210
+ * Clear all cached entries.
211
+ */
212
+ async clear() {
213
+ this.ensureInitialized();
214
+ try {
215
+ await rm(this.options.cacheDir, { recursive: true, force: true });
216
+ await mkdir(this.options.cacheDir, { recursive: true });
217
+ this.stats = {
218
+ entries: 0,
219
+ totalSize: 0,
220
+ hits: 0,
221
+ misses: 0,
222
+ hitRate: 0
223
+ };
224
+ } catch (error) {
225
+ throw new CacheOperationError(`Failed to clear cache: ${error}`, error);
226
+ }
227
+ }
228
+ /**
229
+ * Get cache statistics.
230
+ */
231
+ async getStats() {
232
+ return { ...this.stats };
233
+ }
234
+ /**
235
+ * Clean up expired entries.
236
+ */
237
+ async cleanup() {
238
+ this.ensureInitialized();
239
+ let removed = 0;
240
+ try {
241
+ const files = await readdir(this.options.cacheDir);
242
+ for (const file of files) {
243
+ if (!file.endsWith(this.options.extension)) continue;
244
+ const filePath = join(this.options.cacheDir, file);
245
+ try {
246
+ const content = await readFile(filePath, "utf8");
247
+ const entry = JSON.parse(content);
248
+ if (Date.now() > entry.metadata.expiresAt) {
249
+ await unlink(filePath);
250
+ this.stats.entries = Math.max(0, this.stats.entries - 1);
251
+ this.stats.totalSize = Math.max(0, this.stats.totalSize - entry.metadata.size);
252
+ removed++;
253
+ }
254
+ } catch {
255
+ await unlink(filePath).catch(() => {
256
+ });
257
+ removed++;
258
+ }
259
+ }
260
+ } catch {
261
+ }
262
+ return removed;
263
+ }
264
+ /**
265
+ * Close the storage (no-op for filesystem).
266
+ */
267
+ async close() {
268
+ }
269
+ /**
270
+ * Get the file path for a cache key.
271
+ * Uses SHA-256 hash to avoid collisions from key sanitization.
272
+ */
273
+ getFilePath(key) {
274
+ const hash = createHash("sha256").update(key).digest("hex").slice(0, 16);
275
+ return join(this.options.cacheDir, `${hash}${this.options.extension}`);
276
+ }
277
+ /**
278
+ * Write a cache entry to disk.
279
+ */
280
+ async writeEntry(filePath, entry) {
281
+ await mkdir(dirname(filePath), { recursive: true });
282
+ await writeFile(filePath, JSON.stringify(entry, null, 2), "utf8");
283
+ }
284
+ /**
285
+ * Ensure the storage is initialized.
286
+ */
287
+ ensureInitialized() {
288
+ if (!this.initialized) {
289
+ throw new StorageNotInitializedError();
290
+ }
291
+ }
292
+ /**
293
+ * Load stats from existing cache files.
294
+ * Reads entry metadata to get accurate manifest sizes.
295
+ */
296
+ async loadStats() {
297
+ try {
298
+ const files = await readdir(this.options.cacheDir);
299
+ let entries = 0;
300
+ let totalSize = 0;
301
+ for (const file of files) {
302
+ if (!file.endsWith(this.options.extension)) continue;
303
+ const filePath = join(this.options.cacheDir, file);
304
+ try {
305
+ const content = await readFile(filePath, "utf8");
306
+ const entry = JSON.parse(content);
307
+ entries++;
308
+ totalSize += entry.metadata.size;
309
+ } catch {
310
+ }
311
+ }
312
+ this.stats.entries = entries;
313
+ this.stats.totalSize = totalSize;
314
+ } catch {
315
+ }
316
+ }
317
+ /**
318
+ * Ensure there's capacity for a new entry.
319
+ */
320
+ async ensureCapacity(newEntrySize) {
321
+ if (this.stats.entries >= this.options.maxEntries) {
322
+ await this.evictLRU();
323
+ }
324
+ while (this.stats.totalSize + newEntrySize > this.options.maxSize) {
325
+ const evicted = await this.evictLRU();
326
+ if (!evicted) break;
327
+ }
328
+ }
329
+ /**
330
+ * Evict the least recently used entry.
331
+ */
332
+ async evictLRU() {
333
+ try {
334
+ const files = await readdir(this.options.cacheDir);
335
+ let oldestKey = null;
336
+ let oldestTime = Infinity;
337
+ let corruptedFile = null;
338
+ for (const file of files) {
339
+ if (!file.endsWith(this.options.extension)) continue;
340
+ const filePath = join(this.options.cacheDir, file);
341
+ try {
342
+ const content = await readFile(filePath, "utf8");
343
+ const entry = JSON.parse(content);
344
+ if (entry.metadata.lastAccessedAt < oldestTime) {
345
+ oldestTime = entry.metadata.lastAccessedAt;
346
+ oldestKey = entry.metadata.key;
347
+ }
348
+ } catch {
349
+ corruptedFile = filePath;
350
+ }
351
+ }
352
+ if (corruptedFile) {
353
+ try {
354
+ await unlink(corruptedFile);
355
+ this.stats.entries = Math.max(0, this.stats.entries - 1);
356
+ return true;
357
+ } catch {
358
+ return false;
359
+ }
360
+ }
361
+ if (oldestKey) {
362
+ return await this.delete(oldestKey);
363
+ }
364
+ return false;
365
+ } catch {
366
+ return false;
367
+ }
368
+ }
369
+ /**
370
+ * Update hit rate statistic.
371
+ */
372
+ updateHitRate() {
373
+ const total = this.stats.hits + this.stats.misses;
374
+ this.stats.hitRate = total > 0 ? this.stats.hits / total : 0;
375
+ }
376
+ };
377
+ }
378
+ });
379
+
380
+ // libs/ui/src/bundler/file-cache/storage/redis.ts
381
+ var redis_exports = {};
382
+ __export(redis_exports, {
383
+ RedisStorage: () => RedisStorage,
384
+ createRedisStorage: () => createRedisStorage
385
+ });
386
+ function createRedisStorage(options) {
387
+ return new RedisStorage(options);
388
+ }
389
+ var STATS_KEY_SUFFIX, RedisStorage;
390
+ var init_redis = __esm({
391
+ "libs/ui/src/bundler/file-cache/storage/redis.ts"() {
392
+ "use strict";
393
+ init_interface();
394
+ STATS_KEY_SUFFIX = ":__stats__";
395
+ RedisStorage = class {
396
+ type = "redis";
397
+ options;
398
+ initialized = false;
399
+ localStats = {
400
+ entries: 0,
401
+ totalSize: 0,
402
+ hits: 0,
403
+ misses: 0,
404
+ hitRate: 0
405
+ };
406
+ constructor(options) {
407
+ if (!options.client) {
408
+ throw new Error("Redis client is required");
409
+ }
410
+ this.options = {
411
+ ...DEFAULT_STORAGE_OPTIONS,
412
+ keyPrefix: "frontmcp:ui:build:",
413
+ json: true,
414
+ ...options
415
+ };
416
+ }
417
+ /**
418
+ * Initialize the Redis connection.
419
+ */
420
+ async initialize() {
421
+ if (this.initialized) return;
422
+ try {
423
+ await this.options.client.ping();
424
+ await this.loadStats();
425
+ this.initialized = true;
426
+ } catch (error) {
427
+ throw new Error(`Failed to connect to Redis: ${error}`);
428
+ }
429
+ }
430
+ /**
431
+ * Get a cached manifest.
432
+ */
433
+ async get(key) {
434
+ this.ensureInitialized();
435
+ const redisKey = this.getRedisKey(key);
436
+ try {
437
+ const data = await this.options.client.get(redisKey);
438
+ if (!data) {
439
+ this.localStats.misses++;
440
+ this.updateHitRate();
441
+ await this.persistStats();
442
+ return void 0;
443
+ }
444
+ const entry = JSON.parse(data);
445
+ entry.metadata.lastAccessedAt = Date.now();
446
+ entry.metadata.accessCount++;
447
+ const ttl = await this.options.client.ttl(redisKey);
448
+ if (ttl > 0) {
449
+ const serialized = JSON.stringify(entry);
450
+ await this.options.client.setex(redisKey, ttl, serialized);
451
+ }
452
+ this.localStats.hits++;
453
+ this.updateHitRate();
454
+ await this.persistStats();
455
+ return entry.data;
456
+ } catch (error) {
457
+ console.warn?.(`Redis cache get failed for key "${key}": ${error}`);
458
+ this.localStats.misses++;
459
+ this.updateHitRate();
460
+ await this.persistStats().catch(() => {
461
+ });
462
+ return void 0;
463
+ }
464
+ }
465
+ /**
466
+ * Store a manifest in cache.
467
+ */
468
+ async set(key, manifest, ttl) {
469
+ this.ensureInitialized();
470
+ const redisKey = this.getRedisKey(key);
471
+ const size = calculateManifestSize(manifest);
472
+ const effectiveTtl = ttl ?? this.options.defaultTtl;
473
+ const entry = {
474
+ data: manifest,
475
+ metadata: {
476
+ key,
477
+ size,
478
+ createdAt: Date.now(),
479
+ expiresAt: Date.now() + effectiveTtl * 1e3,
480
+ lastAccessedAt: Date.now(),
481
+ accessCount: 0
482
+ }
483
+ };
484
+ const serialized = JSON.stringify(entry);
485
+ await this.options.client.setex(redisKey, effectiveTtl, serialized);
486
+ this.localStats.entries++;
487
+ this.localStats.totalSize += size;
488
+ await this.persistStats();
489
+ }
490
+ /**
491
+ * Check if a key exists.
492
+ */
493
+ async has(key) {
494
+ this.ensureInitialized();
495
+ const redisKey = this.getRedisKey(key);
496
+ const exists = await this.options.client.exists(redisKey);
497
+ return exists > 0;
498
+ }
499
+ /**
500
+ * Delete a cached entry.
501
+ */
502
+ async delete(key) {
503
+ this.ensureInitialized();
504
+ const redisKey = this.getRedisKey(key);
505
+ try {
506
+ const data = await this.options.client.get(redisKey);
507
+ if (data) {
508
+ const entry = JSON.parse(data);
509
+ this.localStats.totalSize = Math.max(0, this.localStats.totalSize - entry.metadata.size);
510
+ }
511
+ } catch {
512
+ }
513
+ const deleted = await this.options.client.del(redisKey);
514
+ if (deleted > 0) {
515
+ this.localStats.entries = Math.max(0, this.localStats.entries - 1);
516
+ await this.persistStats();
517
+ return true;
518
+ }
519
+ return false;
520
+ }
521
+ /**
522
+ * Clear all cached entries.
523
+ */
524
+ async clear() {
525
+ this.ensureInitialized();
526
+ const pattern = `${this.options.keyPrefix}*`;
527
+ const keys = await this.options.client.keys(pattern);
528
+ if (keys.length > 0) {
529
+ await this.options.client.del(keys);
530
+ }
531
+ this.localStats = {
532
+ entries: 0,
533
+ totalSize: 0,
534
+ hits: 0,
535
+ misses: 0,
536
+ hitRate: 0
537
+ };
538
+ await this.persistStats();
539
+ }
540
+ /**
541
+ * Get cache statistics.
542
+ */
543
+ async getStats() {
544
+ await this.loadStats();
545
+ return { ...this.localStats };
546
+ }
547
+ /**
548
+ * Clean up expired entries.
549
+ * Redis handles TTL expiration automatically, so this just refreshes stats.
550
+ */
551
+ async cleanup() {
552
+ this.ensureInitialized();
553
+ const pattern = `${this.options.keyPrefix}*`;
554
+ const keys = await this.options.client.keys(pattern);
555
+ const dataKeys = keys.filter((k) => !k.endsWith(STATS_KEY_SUFFIX));
556
+ const previousCount = this.localStats.entries;
557
+ this.localStats.entries = dataKeys.length;
558
+ let totalSize = 0;
559
+ for (const key of dataKeys) {
560
+ try {
561
+ const data = await this.options.client.get(key);
562
+ if (data) {
563
+ const entry = JSON.parse(data);
564
+ totalSize += entry.metadata.size;
565
+ }
566
+ } catch {
567
+ }
568
+ }
569
+ this.localStats.totalSize = totalSize;
570
+ await this.persistStats();
571
+ return Math.max(0, previousCount - this.localStats.entries);
572
+ }
573
+ /**
574
+ * Close the Redis connection.
575
+ */
576
+ async close() {
577
+ await this.options.client.quit();
578
+ }
579
+ /**
580
+ * Get the Redis key for a cache key.
581
+ */
582
+ getRedisKey(key) {
583
+ return `${this.options.keyPrefix}${key}`;
584
+ }
585
+ /**
586
+ * Get the Redis key for stats.
587
+ */
588
+ getStatsKey() {
589
+ return `${this.options.keyPrefix}${STATS_KEY_SUFFIX}`;
590
+ }
591
+ /**
592
+ * Ensure the storage is initialized.
593
+ */
594
+ ensureInitialized() {
595
+ if (!this.initialized) {
596
+ throw new Error("Storage not initialized. Call initialize() first.");
597
+ }
598
+ }
599
+ /**
600
+ * Load stats from Redis.
601
+ */
602
+ async loadStats() {
603
+ try {
604
+ const statsKey = this.getStatsKey();
605
+ const data = await this.options.client.get(statsKey);
606
+ if (data) {
607
+ const savedStats = JSON.parse(data);
608
+ this.localStats = {
609
+ ...this.localStats,
610
+ ...savedStats
611
+ };
612
+ }
613
+ } catch {
614
+ }
615
+ }
616
+ /**
617
+ * Persist stats to Redis.
618
+ */
619
+ async persistStats() {
620
+ try {
621
+ const statsKey = this.getStatsKey();
622
+ const serialized = JSON.stringify(this.localStats);
623
+ await this.options.client.set(statsKey, serialized);
624
+ } catch {
625
+ }
626
+ }
627
+ /**
628
+ * Update hit rate statistic.
629
+ */
630
+ updateHitRate() {
631
+ const total = this.localStats.hits + this.localStats.misses;
632
+ this.localStats.hitRate = total > 0 ? this.localStats.hits / total : 0;
633
+ }
634
+ };
635
+ }
636
+ });
637
+
638
+ // libs/ui/src/bundler/types.ts
639
+ var DEFAULT_SECURITY_POLICY = {
640
+ allowedImports: [/^react$/, /^react-dom$/, /^react\/jsx-runtime$/, /^react\/jsx-dev-runtime$/, /^@frontmcp\/ui/],
641
+ blockedImports: [
642
+ /^fs$/,
643
+ /^fs\//,
644
+ /^net$/,
645
+ /^child_process$/,
646
+ /^os$/,
647
+ /^path$/,
648
+ /^crypto$/,
649
+ /^http$/,
650
+ /^https$/,
651
+ /^dgram$/,
652
+ /^dns$/,
653
+ /^cluster$/,
654
+ /^readline$/,
655
+ /^repl$/,
656
+ /^tls$/,
657
+ /^vm$/,
658
+ /^worker_threads$/
659
+ ],
660
+ maxBundleSize: 512e3,
661
+ // 500KB
662
+ maxTransformTime: 5e3,
663
+ // 5s
664
+ noEval: true,
665
+ noDynamicImports: true,
666
+ noRequire: true,
667
+ allowedGlobals: [
668
+ "console",
669
+ "Math",
670
+ "JSON",
671
+ "Date",
672
+ "Array",
673
+ "Object",
674
+ "String",
675
+ "Number",
676
+ "Boolean",
677
+ "Promise",
678
+ "Map",
679
+ "Set",
680
+ "WeakMap",
681
+ "WeakSet",
682
+ "Symbol",
683
+ "Reflect",
684
+ "Proxy",
685
+ "Error",
686
+ "TypeError",
687
+ "RangeError",
688
+ "SyntaxError",
689
+ "ReferenceError",
690
+ "parseInt",
691
+ "parseFloat",
692
+ "isNaN",
693
+ "isFinite",
694
+ "encodeURI",
695
+ "encodeURIComponent",
696
+ "decodeURI",
697
+ "decodeURIComponent",
698
+ "setTimeout",
699
+ "clearTimeout",
700
+ "setInterval",
701
+ "clearInterval",
702
+ "atob",
703
+ "btoa",
704
+ "Intl",
705
+ "TextEncoder",
706
+ "TextDecoder",
707
+ "URL",
708
+ "URLSearchParams",
709
+ "Uint8Array",
710
+ "Int8Array",
711
+ "Uint16Array",
712
+ "Int16Array",
713
+ "Uint32Array",
714
+ "Int32Array",
715
+ "Float32Array",
716
+ "Float64Array",
717
+ "BigInt",
718
+ "BigInt64Array",
719
+ "BigUint64Array",
720
+ "ArrayBuffer",
721
+ "SharedArrayBuffer",
722
+ "DataView",
723
+ "queueMicrotask"
724
+ ]
725
+ };
726
+ var DEFAULT_BUNDLE_OPTIONS = {
727
+ sourceType: "auto",
728
+ format: "iife",
729
+ minify: false,
730
+ sourceMaps: false,
731
+ externals: ["react", "react-dom"],
732
+ jsx: {
733
+ runtime: "automatic",
734
+ importSource: "react"
735
+ },
736
+ target: "es2020",
737
+ globalName: "Widget",
738
+ skipCache: false
739
+ };
740
+ var DEFAULT_BUNDLER_OPTIONS = {
741
+ defaultSecurity: DEFAULT_SECURITY_POLICY,
742
+ cache: {
743
+ maxSize: 100,
744
+ ttl: 3e5,
745
+ // 5 minutes
746
+ disabled: false
747
+ },
748
+ verbose: false,
749
+ esbuildOptions: {}
750
+ };
751
+ var STATIC_HTML_CDN = {
752
+ /**
753
+ * ES modules from esm.sh (React 19, modern platforms)
754
+ */
755
+ esm: {
756
+ react: "https://esm.sh/react@19",
757
+ reactDom: "https://esm.sh/react-dom@19/client"
758
+ },
759
+ /**
760
+ * UMD builds from cdnjs (React 18.2, Claude only trusts cloudflare)
761
+ */
762
+ umd: {
763
+ react: "https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js",
764
+ reactDom: "https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js"
765
+ },
766
+ /**
767
+ * Tailwind CSS from cdnjs (cloudflare) - works on all platforms
768
+ * Using CSS file instead of JS browser version to avoid style normalization issues
769
+ */
770
+ tailwind: "https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/3.4.1/tailwind.min.css",
771
+ /**
772
+ * Font CDN URLs
773
+ */
774
+ fonts: {
775
+ preconnect: ["https://fonts.googleapis.com", "https://fonts.gstatic.com"],
776
+ inter: "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap"
777
+ }
778
+ };
779
+ function getCdnTypeForPlatform(platform) {
780
+ if (platform === "claude") return "umd";
781
+ return "esm";
782
+ }
783
+ var DEFAULT_STATIC_HTML_OPTIONS = {
784
+ sourceType: "auto",
785
+ targetPlatform: "auto",
786
+ minify: true,
787
+ skipCache: false,
788
+ rootId: "frontmcp-widget-root",
789
+ widgetAccessible: false,
790
+ externals: {
791
+ react: "cdn",
792
+ reactDom: "cdn",
793
+ tailwind: "cdn",
794
+ frontmcpUi: "inline"
795
+ },
796
+ // Universal mode defaults
797
+ universal: false,
798
+ contentType: "auto",
799
+ includeMarkdown: false,
800
+ includeMdx: false
801
+ };
802
+
803
+ // libs/ui/src/bundler/cache.ts
804
+ var BundlerCache = class {
805
+ cache = /* @__PURE__ */ new Map();
806
+ options;
807
+ stats = {
808
+ hits: 0,
809
+ misses: 0,
810
+ evictions: 0
811
+ };
812
+ constructor(options = {}) {
813
+ this.options = {
814
+ maxSize: options.maxSize ?? 100,
815
+ ttl: options.ttl ?? 3e5
816
+ };
817
+ }
818
+ /**
819
+ * Get a cached bundle result.
820
+ *
821
+ * @param key - Cache key (typically content hash)
822
+ * @returns Cached result or undefined if not found/expired
823
+ */
824
+ get(key) {
825
+ const entry = this.cache.get(key);
826
+ if (!entry) {
827
+ this.stats.misses++;
828
+ return void 0;
829
+ }
830
+ if (this.isExpired(entry)) {
831
+ this.cache.delete(key);
832
+ this.stats.misses++;
833
+ this.stats.evictions++;
834
+ return void 0;
835
+ }
836
+ entry.lastAccessedAt = Date.now();
837
+ entry.accessCount++;
838
+ this.stats.hits++;
839
+ this.cache.delete(key);
840
+ this.cache.set(key, entry);
841
+ return entry.result;
842
+ }
843
+ /**
844
+ * Store a bundle result in the cache.
845
+ *
846
+ * @param key - Cache key (typically content hash)
847
+ * @param result - Bundle result to cache
848
+ */
849
+ set(key, result) {
850
+ while (this.cache.size >= this.options.maxSize) {
851
+ this.evictOldest();
852
+ }
853
+ const now = Date.now();
854
+ const entry = {
855
+ result,
856
+ createdAt: now,
857
+ lastAccessedAt: now,
858
+ accessCount: 1
859
+ };
860
+ this.cache.set(key, entry);
861
+ }
862
+ /**
863
+ * Check if a key exists in the cache (and is not expired).
864
+ *
865
+ * @param key - Cache key to check
866
+ * @returns true if key exists and is not expired
867
+ */
868
+ has(key) {
869
+ const entry = this.cache.get(key);
870
+ if (!entry) return false;
871
+ if (this.isExpired(entry)) {
872
+ this.cache.delete(key);
873
+ this.stats.evictions++;
874
+ return false;
875
+ }
876
+ return true;
877
+ }
878
+ /**
879
+ * Delete a specific entry from the cache.
880
+ *
881
+ * @param key - Cache key to delete
882
+ * @returns true if the key was found and deleted
883
+ */
884
+ delete(key) {
885
+ return this.cache.delete(key);
886
+ }
887
+ /**
888
+ * Clear all entries from the cache.
889
+ */
890
+ clear() {
891
+ this.cache.clear();
892
+ this.stats = {
893
+ hits: 0,
894
+ misses: 0,
895
+ evictions: 0
896
+ };
897
+ }
898
+ /**
899
+ * Get cache statistics.
900
+ *
901
+ * @returns Current cache statistics
902
+ */
903
+ getStats() {
904
+ const total = this.stats.hits + this.stats.misses;
905
+ const hitRate = total > 0 ? this.stats.hits / total : 0;
906
+ let memoryUsage = 0;
907
+ for (const entry of this.cache.values()) {
908
+ memoryUsage += entry.result.size;
909
+ if (entry.result.map) {
910
+ memoryUsage += entry.result.map.length;
911
+ }
912
+ }
913
+ return {
914
+ size: this.cache.size,
915
+ hits: this.stats.hits,
916
+ misses: this.stats.misses,
917
+ hitRate,
918
+ evictions: this.stats.evictions,
919
+ memoryUsage
920
+ };
921
+ }
922
+ /**
923
+ * Remove expired entries from the cache.
924
+ *
925
+ * @returns Number of entries removed
926
+ */
927
+ cleanup() {
928
+ let removed = 0;
929
+ for (const [key, entry] of this.cache.entries()) {
930
+ if (this.isExpired(entry)) {
931
+ this.cache.delete(key);
932
+ removed++;
933
+ }
934
+ }
935
+ this.stats.evictions += removed;
936
+ return removed;
937
+ }
938
+ /**
939
+ * Get all cache keys.
940
+ *
941
+ * @returns Array of cache keys
942
+ */
943
+ keys() {
944
+ return Array.from(this.cache.keys());
945
+ }
946
+ /**
947
+ * Get the number of entries in the cache.
948
+ */
949
+ get size() {
950
+ return this.cache.size;
951
+ }
952
+ /**
953
+ * Check if an entry is expired.
954
+ */
955
+ isExpired(entry) {
956
+ return Date.now() - entry.createdAt > this.options.ttl;
957
+ }
958
+ /**
959
+ * Evict the oldest (least recently used) entry.
960
+ */
961
+ evictOldest() {
962
+ const oldestKey = this.cache.keys().next().value;
963
+ if (oldestKey !== void 0) {
964
+ this.cache.delete(oldestKey);
965
+ this.stats.evictions++;
966
+ }
967
+ }
968
+ };
969
+ function hashContent(content) {
970
+ let hash = 2166136261;
971
+ for (let i = 0; i < content.length; i++) {
972
+ hash ^= content.charCodeAt(i);
973
+ hash = Math.imul(hash, 16777619);
974
+ }
975
+ return (hash >>> 0).toString(16).padStart(8, "0");
976
+ }
977
+ function createCacheKey(source, options) {
978
+ const sourceHash = hashContent(source);
979
+ const optionsHash = hashContent(
980
+ JSON.stringify({
981
+ sourceType: options.sourceType,
982
+ format: options.format,
983
+ minify: options.minify,
984
+ externals: options.externals?.sort(),
985
+ target: options.target
986
+ })
987
+ );
988
+ return `${sourceHash}-${optionsHash}`;
989
+ }
990
+
991
+ // libs/ui/src/bundler/sandbox/policy.ts
992
+ var UNSAFE_PATTERNS = {
993
+ eval: /\beval\s*\(/g,
994
+ functionConstructor: /\bnew\s+Function\s*\(/g,
995
+ dynamicImport: /\bimport\s*\(/g,
996
+ require: /\brequire\s*\(/g,
997
+ processEnv: /\bprocess\.env\b/g,
998
+ globalThis: /\bglobalThis\b/g,
999
+ windowLocation: /\bwindow\.location\b/g,
1000
+ documentCookie: /\bdocument\.cookie\b/g,
1001
+ innerHTML: /\.innerHTML\s*=/g,
1002
+ outerHTML: /\.outerHTML\s*=/g,
1003
+ document_write: /\bdocument\.write\s*\(/g
1004
+ };
1005
+ function validateSource(source, policy = DEFAULT_SECURITY_POLICY) {
1006
+ const violations = [];
1007
+ if (policy.noEval !== false) {
1008
+ const evalMatches = [...source.matchAll(UNSAFE_PATTERNS.eval)];
1009
+ for (const match of evalMatches) {
1010
+ violations.push({
1011
+ type: "eval-usage",
1012
+ message: "eval() is not allowed for security reasons",
1013
+ location: getLocation(source, match.index ?? 0),
1014
+ value: match[0]
1015
+ });
1016
+ }
1017
+ const fnMatches = [...source.matchAll(UNSAFE_PATTERNS.functionConstructor)];
1018
+ for (const match of fnMatches) {
1019
+ violations.push({
1020
+ type: "eval-usage",
1021
+ message: "new Function() is not allowed for security reasons",
1022
+ location: getLocation(source, match.index ?? 0),
1023
+ value: match[0]
1024
+ });
1025
+ }
1026
+ }
1027
+ if (policy.noDynamicImports !== false) {
1028
+ const matches = [...source.matchAll(UNSAFE_PATTERNS.dynamicImport)];
1029
+ for (const match of matches) {
1030
+ violations.push({
1031
+ type: "dynamic-import",
1032
+ message: "Dynamic imports are not allowed for security reasons",
1033
+ location: getLocation(source, match.index ?? 0),
1034
+ value: match[0]
1035
+ });
1036
+ }
1037
+ }
1038
+ if (policy.noRequire !== false) {
1039
+ const matches = [...source.matchAll(UNSAFE_PATTERNS.require)];
1040
+ for (const match of matches) {
1041
+ violations.push({
1042
+ type: "require-usage",
1043
+ message: "require() is not allowed for security reasons",
1044
+ location: getLocation(source, match.index ?? 0),
1045
+ value: match[0]
1046
+ });
1047
+ }
1048
+ }
1049
+ const importViolations = validateImports(source, policy);
1050
+ violations.push(...importViolations);
1051
+ return violations;
1052
+ }
1053
+ function validateImports(source, policy = DEFAULT_SECURITY_POLICY) {
1054
+ const violations = [];
1055
+ const importPattern = /import\s+(?:(?:\{[^}]*\}|[\w*]+)\s+from\s+)?['"]([^'"]+)['"]/g;
1056
+ const imports = [];
1057
+ let match;
1058
+ while ((match = importPattern.exec(source)) !== null) {
1059
+ imports.push({ module: match[1], index: match.index });
1060
+ }
1061
+ const requirePattern = /require\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
1062
+ while ((match = requirePattern.exec(source)) !== null) {
1063
+ imports.push({ module: match[1], index: match.index });
1064
+ }
1065
+ for (const imp of imports) {
1066
+ if (policy.blockedImports) {
1067
+ for (const blocked of policy.blockedImports) {
1068
+ if (blocked.test(imp.module)) {
1069
+ violations.push({
1070
+ type: "blocked-import",
1071
+ message: `Import '${imp.module}' is blocked by security policy`,
1072
+ location: getLocation(source, imp.index),
1073
+ value: imp.module
1074
+ });
1075
+ break;
1076
+ }
1077
+ }
1078
+ }
1079
+ if (policy.allowedImports && policy.allowedImports.length > 0) {
1080
+ const isAllowed = policy.allowedImports.some((pattern) => pattern.test(imp.module));
1081
+ if (!isAllowed) {
1082
+ const alreadyBlocked = violations.some((v) => v.type === "blocked-import" && v.value === imp.module);
1083
+ if (!alreadyBlocked) {
1084
+ violations.push({
1085
+ type: "disallowed-import",
1086
+ message: `Import '${imp.module}' is not in the allowed imports list`,
1087
+ location: getLocation(source, imp.index),
1088
+ value: imp.module
1089
+ });
1090
+ }
1091
+ }
1092
+ }
1093
+ }
1094
+ return violations;
1095
+ }
1096
+ function validateSize(size, policy = DEFAULT_SECURITY_POLICY) {
1097
+ const maxSize = policy.maxBundleSize ?? DEFAULT_SECURITY_POLICY.maxBundleSize ?? 512e3;
1098
+ if (size > maxSize) {
1099
+ return {
1100
+ type: "size-exceeded",
1101
+ message: `Bundle size (${formatBytes(size)}) exceeds maximum allowed (${formatBytes(maxSize)})`,
1102
+ value: String(size)
1103
+ };
1104
+ }
1105
+ return void 0;
1106
+ }
1107
+ function mergePolicy(userPolicy) {
1108
+ if (!userPolicy) {
1109
+ return { ...DEFAULT_SECURITY_POLICY };
1110
+ }
1111
+ return {
1112
+ allowedImports: userPolicy.allowedImports ?? DEFAULT_SECURITY_POLICY.allowedImports,
1113
+ blockedImports: userPolicy.blockedImports ?? DEFAULT_SECURITY_POLICY.blockedImports,
1114
+ maxBundleSize: userPolicy.maxBundleSize ?? DEFAULT_SECURITY_POLICY.maxBundleSize,
1115
+ maxTransformTime: userPolicy.maxTransformTime ?? DEFAULT_SECURITY_POLICY.maxTransformTime,
1116
+ noEval: userPolicy.noEval ?? DEFAULT_SECURITY_POLICY.noEval,
1117
+ noDynamicImports: userPolicy.noDynamicImports ?? DEFAULT_SECURITY_POLICY.noDynamicImports,
1118
+ noRequire: userPolicy.noRequire ?? DEFAULT_SECURITY_POLICY.noRequire,
1119
+ allowedGlobals: userPolicy.allowedGlobals ?? DEFAULT_SECURITY_POLICY.allowedGlobals
1120
+ };
1121
+ }
1122
+ function getLocation(source, index) {
1123
+ const lines = source.slice(0, index).split("\n");
1124
+ return {
1125
+ line: lines.length,
1126
+ column: lines[lines.length - 1].length + 1
1127
+ };
1128
+ }
1129
+ function formatBytes(bytes) {
1130
+ if (bytes < 1024) return `${bytes} B`;
1131
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
1132
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
1133
+ }
1134
+ var SecurityError = class extends Error {
1135
+ violations;
1136
+ constructor(message, violations) {
1137
+ super(message);
1138
+ this.name = "SecurityError";
1139
+ this.violations = violations;
1140
+ }
1141
+ };
1142
+ function throwOnViolations(violations) {
1143
+ if (violations.length > 0) {
1144
+ const message = violations.map((v) => v.message).join("; ");
1145
+ throw new SecurityError(`Security policy violation: ${message}`, violations);
1146
+ }
1147
+ }
1148
+
1149
+ // libs/ui/src/bundler/sandbox/enclave-adapter.ts
1150
+ import { Enclave } from "enclave-vm";
1151
+ var DEFAULT_ENCLAVE_OPTIONS = {
1152
+ securityLevel: "SECURE",
1153
+ timeout: 5e3,
1154
+ maxIterations: 1e4,
1155
+ validate: true,
1156
+ transform: true
1157
+ };
1158
+ var STRICT_SECURITY_BLOCKED_IMPORTS_THRESHOLD = 10;
1159
+ function mapSecurityLevel(policy) {
1160
+ if (policy?.blockedImports && policy.blockedImports.length > STRICT_SECURITY_BLOCKED_IMPORTS_THRESHOLD) {
1161
+ return "STRICT";
1162
+ }
1163
+ return "SECURE";
1164
+ }
1165
+ function createJSXRuntime(React) {
1166
+ const R = React;
1167
+ return {
1168
+ jsx: (type, props, key) => {
1169
+ const { children, ...rest } = props;
1170
+ return R.createElement(type, key ? { ...rest, key } : rest, children);
1171
+ },
1172
+ jsxs: (type, props, key) => {
1173
+ const { children, ...rest } = props;
1174
+ return R.createElement(type, key ? { ...rest, key } : rest, children);
1175
+ },
1176
+ jsxDEV: (type, props, key, _isStaticChildren, _source, _self) => {
1177
+ const { children, ...rest } = props;
1178
+ return R.createElement(type, key ? { ...rest, key } : rest, children);
1179
+ },
1180
+ Fragment: R.Fragment
1181
+ };
1182
+ }
1183
+ var DANGEROUS_GLOBAL_KEYS = /* @__PURE__ */ new Set([
1184
+ "process",
1185
+ "require",
1186
+ "__dirname",
1187
+ "__filename",
1188
+ "Buffer",
1189
+ "eval",
1190
+ "Function",
1191
+ "constructor",
1192
+ "global",
1193
+ "globalThis",
1194
+ "module",
1195
+ "exports",
1196
+ "__proto__"
1197
+ ]);
1198
+ function sanitizeGlobalKey(key) {
1199
+ return key.replace(/[^a-zA-Z0-9_$]/g, "_");
1200
+ }
1201
+ function buildGlobals(context) {
1202
+ const globals = {};
1203
+ if (context.React) {
1204
+ globals["React"] = context.React;
1205
+ }
1206
+ if (context.ReactDOM) {
1207
+ globals["ReactDOM"] = context.ReactDOM;
1208
+ }
1209
+ if (context.React) {
1210
+ const jsxRuntime = createJSXRuntime(context.React);
1211
+ globals["__jsx"] = jsxRuntime["jsx"];
1212
+ globals["__jsxs"] = jsxRuntime["jsxs"];
1213
+ globals["__jsxDEV"] = jsxRuntime["jsxDEV"];
1214
+ globals["Fragment"] = jsxRuntime["Fragment"];
1215
+ }
1216
+ if (context.modules) {
1217
+ for (const [key, value] of Object.entries(context.modules)) {
1218
+ const sanitizedKey = sanitizeGlobalKey(key);
1219
+ if (DANGEROUS_GLOBAL_KEYS.has(sanitizedKey)) {
1220
+ throw new ExecutionError(
1221
+ `Dangerous module key '${key}' (sanitized: '${sanitizedKey}') is not allowed in execution context`,
1222
+ { code: "SECURITY_VIOLATION" }
1223
+ );
1224
+ }
1225
+ globals[sanitizedKey] = value;
1226
+ }
1227
+ }
1228
+ if (context.globals) {
1229
+ for (const [key, value] of Object.entries(context.globals)) {
1230
+ if (DANGEROUS_GLOBAL_KEYS.has(key)) {
1231
+ throw new ExecutionError(`Dangerous global key '${key}' is not allowed in execution context`, {
1232
+ code: "SECURITY_VIOLATION"
1233
+ });
1234
+ }
1235
+ const sanitizedKey = sanitizeGlobalKey(key);
1236
+ if (DANGEROUS_GLOBAL_KEYS.has(sanitizedKey)) {
1237
+ throw new ExecutionError(
1238
+ `Dangerous global key '${key}' (sanitized: '${sanitizedKey}') is not allowed in execution context`,
1239
+ { code: "SECURITY_VIOLATION" }
1240
+ );
1241
+ }
1242
+ globals[sanitizedKey] = value;
1243
+ }
1244
+ }
1245
+ return globals;
1246
+ }
1247
+ function buildRequireFunction(context) {
1248
+ const normalizedContextModules = {};
1249
+ if (context.modules) {
1250
+ for (const [key, value] of Object.entries(context.modules)) {
1251
+ normalizedContextModules[key.toLowerCase()] = value;
1252
+ }
1253
+ }
1254
+ const modules = {
1255
+ react: context.React,
1256
+ "react-dom": context.ReactDOM,
1257
+ "react/jsx-runtime": context.React ? createJSXRuntime(context.React) : void 0,
1258
+ "react/jsx-dev-runtime": context.React ? createJSXRuntime(context.React) : void 0,
1259
+ ...normalizedContextModules
1260
+ };
1261
+ return (id) => {
1262
+ const normalizedId = id.toLowerCase();
1263
+ if (normalizedId in modules) {
1264
+ const mod = modules[normalizedId];
1265
+ if (mod === void 0) {
1266
+ throw new Error(`Module '${id}' is not available. Did you forget to provide it in the context?`);
1267
+ }
1268
+ return mod;
1269
+ }
1270
+ throw new Error(`Module '${id}' is not available in the sandbox environment`);
1271
+ };
1272
+ }
1273
+ async function executeCode(code, context = {}) {
1274
+ const consoleOutput = [];
1275
+ const globals = buildGlobals(context);
1276
+ globals["console"] = {
1277
+ log: (...args) => {
1278
+ consoleOutput.push(args.map(String).join(" "));
1279
+ },
1280
+ info: (...args) => {
1281
+ consoleOutput.push(`[INFO] ${args.map(String).join(" ")}`);
1282
+ },
1283
+ warn: (...args) => {
1284
+ consoleOutput.push(`[WARN] ${args.map(String).join(" ")}`);
1285
+ },
1286
+ error: (...args) => {
1287
+ consoleOutput.push(`[ERROR] ${args.map(String).join(" ")}`);
1288
+ },
1289
+ debug: (...args) => {
1290
+ consoleOutput.push(`[DEBUG] ${args.map(String).join(" ")}`);
1291
+ },
1292
+ trace: () => {
1293
+ },
1294
+ dir: () => {
1295
+ },
1296
+ table: () => {
1297
+ },
1298
+ group: () => {
1299
+ },
1300
+ groupEnd: () => {
1301
+ },
1302
+ time: () => {
1303
+ },
1304
+ timeEnd: () => {
1305
+ },
1306
+ assert: () => {
1307
+ },
1308
+ clear: () => {
1309
+ },
1310
+ count: () => {
1311
+ },
1312
+ countReset: () => {
1313
+ }
1314
+ };
1315
+ globals["require"] = buildRequireFunction(context);
1316
+ const enclave = new Enclave({
1317
+ ...DEFAULT_ENCLAVE_OPTIONS,
1318
+ timeout: context.timeout ?? DEFAULT_ENCLAVE_OPTIONS.timeout,
1319
+ maxIterations: context.maxIterations ?? DEFAULT_ENCLAVE_OPTIONS.maxIterations,
1320
+ securityLevel: mapSecurityLevel(context.security),
1321
+ globals,
1322
+ allowFunctionsInGlobals: true
1323
+ // Required for React components
1324
+ });
1325
+ try {
1326
+ const wrappedCode = `
1327
+ const module = { exports: {} };
1328
+ const exports = module.exports;
1329
+ const __filename = 'widget.js';
1330
+ const __dirname = '/';
1331
+ ${code}
1332
+ return module.exports;
1333
+ `;
1334
+ const result = await enclave.run(wrappedCode);
1335
+ if (!result.success) {
1336
+ const errorMessage = result.error?.message ?? "Execution failed";
1337
+ const errorCode = result.error?.code;
1338
+ if (errorCode === "TIMEOUT") {
1339
+ throw new ExecutionError(`Execution timed out after ${context.timeout ?? DEFAULT_ENCLAVE_OPTIONS.timeout}ms`, {
1340
+ code: "TIMEOUT"
1341
+ });
1342
+ }
1343
+ if (errorCode === "MAX_ITERATIONS") {
1344
+ throw new ExecutionError(
1345
+ `Maximum iterations exceeded (${context.maxIterations ?? DEFAULT_ENCLAVE_OPTIONS.maxIterations})`,
1346
+ {
1347
+ code: "MAX_ITERATIONS"
1348
+ }
1349
+ );
1350
+ }
1351
+ if (errorCode === "VALIDATION_ERROR") {
1352
+ throw new ExecutionError(`Security validation failed: ${errorMessage}`, { code: "SECURITY_VIOLATION" });
1353
+ }
1354
+ throw new ExecutionError(errorMessage, result.error);
1355
+ }
1356
+ return {
1357
+ exports: result.value,
1358
+ executionTime: result.stats.duration,
1359
+ consoleOutput: consoleOutput.length > 0 ? consoleOutput : void 0
1360
+ };
1361
+ } finally {
1362
+ enclave.dispose();
1363
+ }
1364
+ }
1365
+ async function executeDefault(code, context = {}) {
1366
+ const result = await executeCode(code, context);
1367
+ if ("default" in result.exports) {
1368
+ return result.exports.default;
1369
+ }
1370
+ const exportKeys = Object.keys(result.exports);
1371
+ if (exportKeys.length === 0) {
1372
+ throw new ExecutionError("Code did not export any values");
1373
+ }
1374
+ if (exportKeys.length === 1) {
1375
+ return result.exports[exportKeys[0]];
1376
+ }
1377
+ return result.exports;
1378
+ }
1379
+ var ExecutionError = class extends Error {
1380
+ /** Error code for categorization */
1381
+ code;
1382
+ constructor(message, cause) {
1383
+ super(message, { cause });
1384
+ this.name = "ExecutionError";
1385
+ if (cause && typeof cause === "object" && "code" in cause) {
1386
+ this.code = cause.code;
1387
+ }
1388
+ }
1389
+ };
1390
+ function isExecutionError(error) {
1391
+ return error instanceof ExecutionError;
1392
+ }
1393
+
1394
+ // libs/ui/src/utils/escape-html.ts
1395
+ function escapeHtml(str) {
1396
+ if (str === null || str === void 0) {
1397
+ return "";
1398
+ }
1399
+ const s = String(str);
1400
+ 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");
1401
+ }
1402
+ function escapeHtmlAttr(str) {
1403
+ return str.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
1404
+ }
1405
+
1406
+ // libs/ui/src/universal/types.ts
1407
+ var UNIVERSAL_CDN = {
1408
+ esm: {
1409
+ reactMarkdown: "https://esm.sh/react-markdown@9",
1410
+ mdxReact: "https://esm.sh/@mdx-js/react@3",
1411
+ remarkGfm: "https://esm.sh/remark-gfm@4"
1412
+ }
1413
+ // Note: These libraries are not available on cdnjs
1414
+ // For Claude, we use inline implementations
1415
+ };
1416
+ function detectContentType(source) {
1417
+ if (typeof source === "function") {
1418
+ return "react";
1419
+ }
1420
+ if (typeof source !== "string") {
1421
+ return "html";
1422
+ }
1423
+ const hasModuleSyntax = /^import\s+/m.test(source) || /^export\s+(default\s+)?/m.test(source) || /^const\s+\w+\s*=\s*\([^)]*\)\s*=>/m.test(source) || // Arrow function components
1424
+ /^function\s+\w+\s*\(/m.test(source);
1425
+ const hasJsxTags = /<[A-Z][a-zA-Z]*/.test(source);
1426
+ const hasMarkdown = /^#{1,6}\s/m.test(source) || /^\*\s/m.test(source) || /^-\s/m.test(source) || /^\d+\.\s/m.test(source);
1427
+ if (hasModuleSyntax && hasJsxTags) {
1428
+ return "react";
1429
+ }
1430
+ if (hasJsxTags && hasMarkdown && !hasModuleSyntax) {
1431
+ return "mdx";
1432
+ }
1433
+ if (hasMarkdown || /\*\*[^*]+\*\*/.test(source) || /\[[^\]]+\]\([^)]+\)/.test(source)) {
1434
+ return "markdown";
1435
+ }
1436
+ if (hasJsxTags && !hasModuleSyntax) {
1437
+ return "mdx";
1438
+ }
1439
+ return "html";
1440
+ }
1441
+
1442
+ // libs/ui/src/universal/cached-runtime.ts
1443
+ var RUNTIME_PLACEHOLDERS = {
1444
+ /** Placeholder for transpiled component code */
1445
+ COMPONENT_CODE: "/*__FRONTMCP_COMPONENT_CODE__*/",
1446
+ /** Placeholder for data injection */
1447
+ DATA_INJECTION: "/*__FRONTMCP_DATA_INJECTION__*/",
1448
+ /** Placeholder for custom components */
1449
+ CUSTOM_COMPONENTS: "/*__FRONTMCP_CUSTOM_COMPONENTS__*/"
1450
+ };
1451
+ var runtimeCache = /* @__PURE__ */ new Map();
1452
+ var DEFAULT_CACHE_CONFIG = {
1453
+ maxEntries: 10,
1454
+ ttl: 0
1455
+ // Forever by default
1456
+ };
1457
+ function generateCacheKey(options) {
1458
+ const securityKey = options.contentSecurity ? [
1459
+ options.contentSecurity.allowUnsafeLinks ? "unsafeLinks" : "",
1460
+ options.contentSecurity.allowInlineScripts ? "unsafeScripts" : "",
1461
+ options.contentSecurity.bypassSanitization ? "bypass" : ""
1462
+ ].filter(Boolean).join("+") || "secure" : "secure";
1463
+ return [
1464
+ options.cdnType,
1465
+ options.includeMarkdown ? "md" : "",
1466
+ options.includeMdx ? "mdx" : "",
1467
+ options.minify ? "min" : "",
1468
+ securityKey
1469
+ ].filter(Boolean).join(":");
1470
+ }
1471
+ function buildStoreRuntime() {
1472
+ return `
1473
+ // FrontMCP Store (Vendor)
1474
+ (function() {
1475
+ var state = {
1476
+ toolName: null,
1477
+ input: null,
1478
+ output: null,
1479
+ content: null,
1480
+ structuredContent: null,
1481
+ loading: false,
1482
+ error: null
1483
+ };
1484
+
1485
+ var listeners = new Set();
1486
+
1487
+ window.__frontmcp = {
1488
+ getState: function() { return state; },
1489
+ setState: function(partial) {
1490
+ state = Object.assign({}, state, partial);
1491
+ listeners.forEach(function(fn) { fn(); });
1492
+ },
1493
+ subscribe: function(fn) {
1494
+ listeners.add(fn);
1495
+ return function() { listeners.delete(fn); };
1496
+ },
1497
+ reset: function() {
1498
+ state = {
1499
+ toolName: null,
1500
+ input: null,
1501
+ output: null,
1502
+ content: null,
1503
+ structuredContent: null,
1504
+ loading: false,
1505
+ error: null
1506
+ };
1507
+ },
1508
+ context: state,
1509
+ setContext: function(ctx) {
1510
+ this.setState(ctx);
1511
+ }
1512
+ };
1513
+
1514
+ // React hooks
1515
+ window.useFrontMCPStore = function() {
1516
+ var store = window.__frontmcp;
1517
+ return React.useSyncExternalStore(
1518
+ store.subscribe,
1519
+ store.getState,
1520
+ store.getState
1521
+ );
1522
+ };
1523
+
1524
+ window.useToolOutput = function() {
1525
+ return window.useFrontMCPStore().output;
1526
+ };
1527
+
1528
+ window.useToolInput = function() {
1529
+ return window.useFrontMCPStore().input;
1530
+ };
1531
+
1532
+ window.useContent = function() {
1533
+ return window.useFrontMCPStore().content;
1534
+ };
1535
+ })();
1536
+ `;
1537
+ }
1538
+ function buildRequireShim() {
1539
+ return `
1540
+ // Module Require Shim (Vendor)
1541
+ (function() {
1542
+ window.__moduleCache = {};
1543
+ window.require = function(moduleName) {
1544
+ if (window.__moduleCache[moduleName]) {
1545
+ return window.__moduleCache[moduleName];
1546
+ }
1547
+
1548
+ var moduleMap = {
1549
+ 'react': function() { return window.React; },
1550
+ 'react-dom': function() { return window.ReactDOM; },
1551
+ 'react-dom/client': function() { return window.ReactDOM; },
1552
+ 'react/jsx-runtime': function() { return window.jsx_runtime_namespaceObject; },
1553
+ 'react/jsx-dev-runtime': function() { return window.jsx_runtime_namespaceObject; },
1554
+ '@frontmcp/ui': function() { return window.frontmcp_ui_namespaceObject; },
1555
+ '@frontmcp/ui/react': function() { return window.frontmcp_ui_namespaceObject; }
1556
+ };
1557
+
1558
+ var resolver = moduleMap[moduleName];
1559
+ if (resolver) {
1560
+ var mod = resolver();
1561
+ window.__moduleCache[moduleName] = mod;
1562
+ return mod;
1563
+ }
1564
+
1565
+ console.warn('[FrontMCP] Unknown module:', moduleName);
1566
+ return {};
1567
+ };
1568
+ })();
1569
+ `;
1570
+ }
1571
+ function buildInlineMarkdownParser(options) {
1572
+ const allowUnsafeLinks = options?.contentSecurity?.bypassSanitization || options?.contentSecurity?.allowUnsafeLinks;
1573
+ return `
1574
+ // Inline Markdown Parser (Vendor)
1575
+ (function() {
1576
+ // XSS protection settings (configured at build time)
1577
+ // Set to true if contentSecurity.allowUnsafeLinks or bypassSanitization is enabled
1578
+ var __allowUnsafeLinks = ${allowUnsafeLinks ? "true" : "false"};
1579
+
1580
+ // URL scheme validation to prevent XSS via javascript: URLs
1581
+ function isSafeUrl(url) {
1582
+ // If unsafe links are explicitly allowed, skip validation
1583
+ if (__allowUnsafeLinks) return true;
1584
+ if (!url) return false;
1585
+ var lower = url.toLowerCase().trim();
1586
+ return lower.startsWith('http://') ||
1587
+ lower.startsWith('https://') ||
1588
+ lower.startsWith('/') ||
1589
+ lower.startsWith('#') ||
1590
+ lower.startsWith('mailto:');
1591
+ }
1592
+
1593
+ function parseMarkdown(md) {
1594
+ var html = md;
1595
+ html = html.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
1596
+ html = html.replace(/^######\\s+(.*)$/gm, '<h6>$1</h6>');
1597
+ html = html.replace(/^#####\\s+(.*)$/gm, '<h5>$1</h5>');
1598
+ html = html.replace(/^####\\s+(.*)$/gm, '<h4>$1</h4>');
1599
+ html = html.replace(/^###\\s+(.*)$/gm, '<h3>$1</h3>');
1600
+ html = html.replace(/^##\\s+(.*)$/gm, '<h2>$1</h2>');
1601
+ html = html.replace(/^#\\s+(.*)$/gm, '<h1>$1</h1>');
1602
+ html = html.replace(/\\*\\*\\*(.+?)\\*\\*\\*/g, '<strong><em>$1</em></strong>');
1603
+ html = html.replace(/\\*\\*(.+?)\\*\\*/g, '<strong>$1</strong>');
1604
+ html = html.replace(/\\*(.+?)\\*/g, '<em>$1</em>');
1605
+ html = html.replace(/\`([^\`]+)\`/g, '<code>$1</code>');
1606
+ // Links - validate URL scheme to prevent XSS (unless bypassed)
1607
+ html = html.replace(/\\[([^\\]]+)\\]\\(([^)]+)\\)/g, function(match, text, url) {
1608
+ return isSafeUrl(url) ? '<a href="' + url + '">' + text + '</a>' : text;
1609
+ });
1610
+ html = html.replace(/^[-*]\\s+(.*)$/gm, '<li>$1</li>');
1611
+ html = html.replace(/\\n\\n+/g, '</p><p>');
1612
+ html = '<p>' + html + '</p>';
1613
+ return html;
1614
+ }
1615
+
1616
+ window.__frontmcp.parseMarkdown = parseMarkdown;
1617
+
1618
+ window.ReactMarkdown = function(props) {
1619
+ var html = parseMarkdown(props.children || '');
1620
+ return React.createElement('div', {
1621
+ className: 'frontmcp-markdown prose',
1622
+ dangerouslySetInnerHTML: { __html: html }
1623
+ });
1624
+ };
1625
+ })();
1626
+ `;
1627
+ }
1628
+ function buildRenderersRuntime(options) {
1629
+ const bypassSanitization = options?.contentSecurity?.bypassSanitization;
1630
+ const allowInlineScripts = bypassSanitization || options?.contentSecurity?.allowInlineScripts;
1631
+ return `
1632
+ // Universal Renderers (Vendor)
1633
+ (function() {
1634
+ var renderers = {};
1635
+
1636
+ // XSS protection settings (configured at build time)
1637
+ // Set to true if contentSecurity.allowInlineScripts or bypassSanitization is enabled
1638
+ var __allowInlineScripts = ${allowInlineScripts ? "true" : "false"};
1639
+
1640
+ renderers.html = {
1641
+ type: 'html',
1642
+ priority: 0,
1643
+ canHandle: function(c) { return c.type === 'html'; },
1644
+ render: function(c, ctx) {
1645
+ var html = c.source;
1646
+ // Apply XSS protection unless bypassed
1647
+ if (!__allowInlineScripts) {
1648
+ // Remove script tags and event handlers to prevent XSS
1649
+ html = html.replace(/<script[^>]*>[\\s\\S]*?<\\/script>/gi, '');
1650
+ html = html.replace(/\\s+on\\w+\\s*=/gi, ' data-removed-handler=');
1651
+ }
1652
+ return React.createElement('div', {
1653
+ className: 'frontmcp-html-content',
1654
+ dangerouslySetInnerHTML: { __html: html }
1655
+ });
1656
+ }
1657
+ };
1658
+
1659
+ renderers.markdown = {
1660
+ type: 'markdown',
1661
+ priority: 10,
1662
+ canHandle: function(c) {
1663
+ if (c.type === 'markdown') return true;
1664
+ if (typeof c.source !== 'string') return false;
1665
+ var s = c.source;
1666
+ return /^#{1,6}\\s/m.test(s) || /^[-*]\\s/m.test(s) || /\\*\\*[^*]+\\*\\*/.test(s);
1667
+ },
1668
+ render: function(c, ctx) {
1669
+ if (window.ReactMarkdown) {
1670
+ return React.createElement(window.ReactMarkdown, {
1671
+ children: c.source,
1672
+ components: Object.assign({}, ctx.components, c.components)
1673
+ });
1674
+ }
1675
+ var html = window.__frontmcp.parseMarkdown ? window.__frontmcp.parseMarkdown(c.source) : c.source;
1676
+ return React.createElement('div', {
1677
+ className: 'frontmcp-markdown prose',
1678
+ dangerouslySetInnerHTML: { __html: html }
1679
+ });
1680
+ }
1681
+ };
1682
+
1683
+ renderers.react = {
1684
+ type: 'react',
1685
+ priority: 30,
1686
+ canHandle: function(c) { return c.type === 'react' || typeof c.source === 'function'; },
1687
+ render: function(c, ctx) {
1688
+ var Component = c.source;
1689
+ var props = Object.assign({
1690
+ output: ctx.output,
1691
+ input: ctx.input,
1692
+ state: ctx.state,
1693
+ data: ctx.output // Alias for convenience
1694
+ }, c.props);
1695
+ return React.createElement(Component, props);
1696
+ }
1697
+ };
1698
+
1699
+ renderers.mdx = {
1700
+ type: 'mdx',
1701
+ priority: 20,
1702
+ canHandle: function(c) {
1703
+ if (c.type === 'mdx') return true;
1704
+ if (typeof c.source !== 'string') return false;
1705
+ var s = c.source;
1706
+ return /<[A-Z][a-zA-Z]*/.test(s) && /^#{1,6}\\s/m.test(s);
1707
+ },
1708
+ render: function(c, ctx) {
1709
+ if (typeof c.compiledContent === 'function') {
1710
+ var MDXContent = c.compiledContent;
1711
+ return React.createElement(MDXContent, {
1712
+ output: ctx.output,
1713
+ input: ctx.input,
1714
+ components: Object.assign({}, ctx.components, c.components)
1715
+ });
1716
+ }
1717
+ return React.createElement('div', { className: 'frontmcp-mdx-fallback' }, [
1718
+ React.createElement('div', {
1719
+ key: 'warn',
1720
+ className: 'bg-yellow-50 border border-yellow-200 rounded p-2 mb-2 text-sm text-yellow-800'
1721
+ }, 'MDX requires pre-compilation. Showing raw content.'),
1722
+ React.createElement('pre', {
1723
+ key: 'pre',
1724
+ className: 'bg-gray-100 p-4 rounded text-sm overflow-auto'
1725
+ }, c.source)
1726
+ ]);
1727
+ }
1728
+ };
1729
+
1730
+ var sortedRenderers = [renderers.react, renderers.mdx, renderers.markdown, renderers.html];
1731
+
1732
+ window.__frontmcp.detectRenderer = function(content) {
1733
+ if (content.type && renderers[content.type]) {
1734
+ return renderers[content.type];
1735
+ }
1736
+ for (var i = 0; i < sortedRenderers.length; i++) {
1737
+ if (sortedRenderers[i].canHandle(content)) {
1738
+ return sortedRenderers[i];
1739
+ }
1740
+ }
1741
+ return renderers.html;
1742
+ };
1743
+
1744
+ window.__frontmcp.renderContent = function(content, context) {
1745
+ var renderer = window.__frontmcp.detectRenderer(content);
1746
+ return renderer.render(content, context);
1747
+ };
1748
+
1749
+ window.__frontmcp.renderers = renderers;
1750
+ })();
1751
+ `;
1752
+ }
1753
+ function buildUIComponentsRuntime() {
1754
+ return `
1755
+ // UI Components (Vendor)
1756
+ (function() {
1757
+ window.Card = function(props) {
1758
+ var children = props.children;
1759
+ var title = props.title;
1760
+ var className = props.className || '';
1761
+ return React.createElement('div', {
1762
+ className: 'bg-white rounded-lg shadow border border-gray-200 overflow-hidden ' + className
1763
+ }, [
1764
+ title && React.createElement('div', {
1765
+ key: 'header',
1766
+ className: 'px-4 py-3 border-b border-gray-200 bg-gray-50'
1767
+ }, React.createElement('h3', { className: 'text-sm font-medium text-gray-900' }, title)),
1768
+ React.createElement('div', { key: 'body', className: 'p-4' }, children)
1769
+ ]);
1770
+ };
1771
+
1772
+ window.Badge = function(props) {
1773
+ var children = props.children;
1774
+ var variant = props.variant || 'default';
1775
+ var variantClasses = {
1776
+ default: 'bg-gray-100 text-gray-800',
1777
+ success: 'bg-green-100 text-green-800',
1778
+ warning: 'bg-yellow-100 text-yellow-800',
1779
+ error: 'bg-red-100 text-red-800',
1780
+ info: 'bg-blue-100 text-blue-800'
1781
+ };
1782
+ return React.createElement('span', {
1783
+ className: 'inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ' + (variantClasses[variant] || variantClasses.default)
1784
+ }, children);
1785
+ };
1786
+
1787
+ window.Button = function(props) {
1788
+ var children = props.children;
1789
+ var variant = props.variant || 'primary';
1790
+ var onClick = props.onClick;
1791
+ var disabled = props.disabled;
1792
+ var variantClasses = {
1793
+ primary: 'bg-blue-600 text-white hover:bg-blue-700',
1794
+ secondary: 'bg-gray-100 text-gray-900 hover:bg-gray-200',
1795
+ outline: 'border border-gray-300 text-gray-700 hover:bg-gray-50',
1796
+ danger: 'bg-red-600 text-white hover:bg-red-700'
1797
+ };
1798
+ return React.createElement('button', {
1799
+ className: 'px-4 py-2 rounded-md text-sm font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 ' +
1800
+ (disabled ? 'opacity-50 cursor-not-allowed ' : '') +
1801
+ (variantClasses[variant] || variantClasses.primary),
1802
+ onClick: onClick,
1803
+ disabled: disabled
1804
+ }, children);
1805
+ };
1806
+
1807
+ // Export to namespace
1808
+ window.frontmcp_ui_namespaceObject = Object.assign({}, window.React || {}, {
1809
+ useToolOutput: window.useToolOutput,
1810
+ useToolInput: window.useToolInput,
1811
+ useMcpBridgeContext: function() { return window.__frontmcp.context; },
1812
+ useCallTool: function() { return function() { return Promise.resolve(null); }; },
1813
+ Card: window.Card,
1814
+ Badge: window.Badge,
1815
+ Button: window.Button
1816
+ });
1817
+ })();
1818
+ `;
1819
+ }
1820
+ function buildUniversalAppRuntime() {
1821
+ return `
1822
+ // Universal App (Vendor)
1823
+ (function() {
1824
+ var LoadingSpinner = function() {
1825
+ return React.createElement('div', {
1826
+ className: 'frontmcp-loading flex items-center justify-center min-h-[200px]'
1827
+ }, React.createElement('div', {
1828
+ className: 'frontmcp-spinner w-6 h-6 border-2 border-gray-200 border-t-blue-500 rounded-full animate-spin'
1829
+ }));
1830
+ };
1831
+
1832
+ var ErrorDisplay = function(props) {
1833
+ return React.createElement('div', {
1834
+ className: 'frontmcp-error bg-red-50 border border-red-200 rounded-lg p-4 text-red-800'
1835
+ }, [
1836
+ React.createElement('div', { key: 'title', className: 'font-medium' }, 'Error'),
1837
+ React.createElement('div', { key: 'msg', className: 'text-sm mt-1' }, props.error)
1838
+ ]);
1839
+ };
1840
+
1841
+ var EmptyState = function() {
1842
+ return React.createElement('div', {
1843
+ className: 'frontmcp-empty text-gray-500 text-center py-8'
1844
+ }, 'No content to display');
1845
+ };
1846
+
1847
+ window.__frontmcp.UniversalApp = function(props) {
1848
+ var state = window.useFrontMCPStore();
1849
+
1850
+ if (state.loading) {
1851
+ return props.fallback || React.createElement(LoadingSpinner);
1852
+ }
1853
+
1854
+ if (state.error) {
1855
+ var ErrorComp = props.errorFallback || ErrorDisplay;
1856
+ return React.createElement(ErrorComp, { error: state.error });
1857
+ }
1858
+
1859
+ var content = props.content || state.content;
1860
+
1861
+ if (!content) {
1862
+ return React.createElement(EmptyState);
1863
+ }
1864
+
1865
+ var context = {
1866
+ output: state.output,
1867
+ input: state.input,
1868
+ state: state,
1869
+ components: props.components || {}
1870
+ };
1871
+
1872
+ var rendered = window.__frontmcp.renderContent(content, context);
1873
+ return React.createElement('div', { className: 'frontmcp-content' }, rendered);
1874
+ };
1875
+
1876
+ window.__frontmcp.LoadingSpinner = LoadingSpinner;
1877
+ window.__frontmcp.ErrorDisplay = ErrorDisplay;
1878
+ window.__frontmcp.EmptyState = EmptyState;
1879
+ })();
1880
+ `;
1881
+ }
1882
+ function buildComponentWrapper() {
1883
+ return `
1884
+ // Component Execution (App Chunk)
1885
+ (function() {
1886
+ ${RUNTIME_PLACEHOLDERS.COMPONENT_CODE}
1887
+ })();
1888
+ `;
1889
+ }
1890
+ function buildDataInjectionWrapper() {
1891
+ return `
1892
+ // Data Injection (App Chunk)
1893
+ (function() {
1894
+ ${RUNTIME_PLACEHOLDERS.DATA_INJECTION}
1895
+ })();
1896
+ `;
1897
+ }
1898
+ function buildCustomComponentsWrapper() {
1899
+ return `
1900
+ // Custom Components (App Chunk)
1901
+ (function() {
1902
+ ${RUNTIME_PLACEHOLDERS.CUSTOM_COMPONENTS}
1903
+ })();
1904
+ `;
1905
+ }
1906
+ function buildCdnImports(options) {
1907
+ const parts = [];
1908
+ if (options.cdnType === "esm") {
1909
+ if (options.includeMarkdown) {
1910
+ parts.push(`
1911
+ <script type="module">
1912
+ import ReactMarkdown from '${UNIVERSAL_CDN.esm.reactMarkdown}';
1913
+ window.ReactMarkdown = ReactMarkdown;
1914
+ </script>`);
1915
+ }
1916
+ if (options.includeMdx) {
1917
+ parts.push(`
1918
+ <script type="module">
1919
+ import { MDXProvider } from '${UNIVERSAL_CDN.esm.mdxReact}';
1920
+ window.MDXProvider = MDXProvider;
1921
+ </script>`);
1922
+ }
1923
+ }
1924
+ return parts.join("\n");
1925
+ }
1926
+ function getCachedRuntime(options, config = {}) {
1927
+ const cacheKey = generateCacheKey(options);
1928
+ const cacheConfig = { ...DEFAULT_CACHE_CONFIG, ...config };
1929
+ const cached = runtimeCache.get(cacheKey);
1930
+ if (cached) {
1931
+ if (cacheConfig.ttl === 0 || Date.now() - cached.cachedAt < cacheConfig.ttl) {
1932
+ return {
1933
+ vendorScript: cached.script,
1934
+ appTemplate: buildAppTemplate(),
1935
+ cdnImports: cached.cdnImports,
1936
+ vendorSize: cached.size,
1937
+ cached: true,
1938
+ cacheKey
1939
+ };
1940
+ }
1941
+ runtimeCache.delete(cacheKey);
1942
+ }
1943
+ const vendorParts = [buildStoreRuntime(), buildRequireShim()];
1944
+ if (options.cdnType === "umd" || options.includeMarkdown) {
1945
+ vendorParts.push(buildInlineMarkdownParser(options));
1946
+ }
1947
+ vendorParts.push(buildRenderersRuntime(options));
1948
+ vendorParts.push(buildUIComponentsRuntime());
1949
+ vendorParts.push(buildUniversalAppRuntime());
1950
+ let vendorScript = vendorParts.join("\n");
1951
+ if (options.minify) {
1952
+ vendorScript = minifyScript(vendorScript);
1953
+ }
1954
+ const cdnImports = buildCdnImports(options);
1955
+ const entry = {
1956
+ script: vendorScript,
1957
+ cdnImports,
1958
+ size: vendorScript.length,
1959
+ cacheKey,
1960
+ cachedAt: Date.now()
1961
+ };
1962
+ if (runtimeCache.size >= cacheConfig.maxEntries) {
1963
+ const oldestKey = runtimeCache.keys().next().value;
1964
+ if (oldestKey) {
1965
+ runtimeCache.delete(oldestKey);
1966
+ }
1967
+ }
1968
+ runtimeCache.set(cacheKey, entry);
1969
+ return {
1970
+ vendorScript,
1971
+ appTemplate: buildAppTemplate(),
1972
+ cdnImports,
1973
+ vendorSize: vendorScript.length,
1974
+ cached: false,
1975
+ cacheKey
1976
+ };
1977
+ }
1978
+ function buildAppTemplate() {
1979
+ return [buildCustomComponentsWrapper(), buildComponentWrapper(), buildDataInjectionWrapper()].join("\n");
1980
+ }
1981
+ function minifyScript(script) {
1982
+ return script.replace(/\/\/[^\n]*/g, "").replace(/\/\*[\s\S]*?\*\//g, "").replace(/\n\s*\n/g, "\n").replace(/^\s+/gm, "").trim();
1983
+ }
1984
+ function buildAppScript(appTemplate, componentCode, dataInjection, customComponents = "") {
1985
+ return appTemplate.replace(RUNTIME_PLACEHOLDERS.CUSTOM_COMPONENTS, customComponents || "// No custom components").replace(RUNTIME_PLACEHOLDERS.COMPONENT_CODE, componentCode || "// No component code").replace(RUNTIME_PLACEHOLDERS.DATA_INJECTION, dataInjection);
1986
+ }
1987
+ function buildDataInjectionCode(toolName, input, output, structuredContent, contentType, source, hasComponent) {
1988
+ const safeJson = (value) => {
1989
+ try {
1990
+ return JSON.stringify(value);
1991
+ } catch {
1992
+ return "null";
1993
+ }
1994
+ };
1995
+ if (hasComponent) {
1996
+ return `
1997
+ window.__frontmcp.setState({
1998
+ toolName: ${safeJson(toolName)},
1999
+ input: ${safeJson(input ?? null)},
2000
+ output: ${safeJson(output ?? null)},
2001
+ structuredContent: ${safeJson(structuredContent ?? null)},
2002
+ content: {
2003
+ type: 'react',
2004
+ source: window.__frontmcp_component
2005
+ },
2006
+ loading: false,
2007
+ error: null
2008
+ });`;
2009
+ }
2010
+ return `
2011
+ window.__frontmcp.setState({
2012
+ toolName: ${safeJson(toolName)},
2013
+ input: ${safeJson(input ?? null)},
2014
+ output: ${safeJson(output ?? null)},
2015
+ structuredContent: ${safeJson(structuredContent ?? null)},
2016
+ content: {
2017
+ type: ${safeJson(contentType)},
2018
+ source: ${safeJson(source)}
2019
+ },
2020
+ loading: false,
2021
+ error: null
2022
+ });`;
2023
+ }
2024
+ function buildComponentCode(transpiledCode) {
2025
+ return `
2026
+ // CommonJS module shim
2027
+ var module = { exports: {} };
2028
+ var exports = module.exports;
2029
+
2030
+ // Execute transpiled component
2031
+ ${transpiledCode}
2032
+
2033
+ // Capture component
2034
+ window.__frontmcp_component = module.exports.default || module.exports;`;
2035
+ }
2036
+
2037
+ // libs/ui/src/bundler/bundler.ts
2038
+ var esbuildTransform = null;
2039
+ async function loadEsbuild() {
2040
+ if (esbuildTransform !== null) {
2041
+ return esbuildTransform;
2042
+ }
2043
+ try {
2044
+ const esbuild = await import("esbuild");
2045
+ esbuildTransform = esbuild.transform;
2046
+ return esbuildTransform;
2047
+ } catch {
2048
+ try {
2049
+ const swc = await import("@swc/core");
2050
+ esbuildTransform = async (source, options) => {
2051
+ const opts = options;
2052
+ const result = await swc.transform(source, {
2053
+ jsc: {
2054
+ parser: {
2055
+ syntax: "typescript",
2056
+ tsx: opts.loader === "tsx" || opts.loader === "jsx"
2057
+ },
2058
+ transform: {
2059
+ react: {
2060
+ runtime: "automatic",
2061
+ development: false
2062
+ }
2063
+ },
2064
+ target: "es2020",
2065
+ minify: opts.minify ? { compress: true, mangle: true } : void 0
2066
+ },
2067
+ module: {
2068
+ type: "commonjs"
2069
+ },
2070
+ sourceMaps: opts.sourcemap ? true : false
2071
+ });
2072
+ return { code: result.code, map: result.map };
2073
+ };
2074
+ return esbuildTransform;
2075
+ } catch {
2076
+ console.warn(
2077
+ "[@frontmcp/ui/bundler] Neither esbuild nor @swc/core available. Install esbuild for best performance: npm install esbuild"
2078
+ );
2079
+ return null;
2080
+ }
2081
+ }
2082
+ }
2083
+ function sanitizeRootId(rootId) {
2084
+ const safeId = rootId.replace(/[^a-zA-Z0-9_-]/g, "");
2085
+ if (safeId !== rootId) {
2086
+ console.warn("[FrontMCP] rootId sanitized:", { original: rootId, sanitized: safeId });
2087
+ }
2088
+ return safeId || "frontmcp-root";
2089
+ }
2090
+ function sanitizeCss(css) {
2091
+ return css.replace(/<\/style>/gi, "\\3c/style\\3e");
2092
+ }
2093
+ var InMemoryBundler = class {
2094
+ cache;
2095
+ options;
2096
+ defaultSecurity;
2097
+ constructor(options = {}) {
2098
+ this.options = {
2099
+ ...DEFAULT_BUNDLER_OPTIONS,
2100
+ ...options,
2101
+ cache: {
2102
+ ...DEFAULT_BUNDLER_OPTIONS.cache,
2103
+ ...options.cache
2104
+ }
2105
+ };
2106
+ this.cache = new BundlerCache({
2107
+ maxSize: this.options.cache.maxSize,
2108
+ ttl: this.options.cache.ttl
2109
+ });
2110
+ this.defaultSecurity = mergePolicy(options.defaultSecurity);
2111
+ }
2112
+ /**
2113
+ * Bundle source code.
2114
+ *
2115
+ * @param options - Bundle options
2116
+ * @returns Bundle result
2117
+ */
2118
+ async bundle(options) {
2119
+ const startTime = performance.now();
2120
+ const opts = this.mergeOptions(options);
2121
+ if (!opts.skipCache && !this.options.cache.disabled) {
2122
+ const cacheKey = options.cacheKey ?? createCacheKey(options.source, opts);
2123
+ const cached = this.cache.get(cacheKey);
2124
+ if (cached) {
2125
+ return {
2126
+ ...cached,
2127
+ cached: true,
2128
+ metrics: {
2129
+ ...cached.metrics,
2130
+ cacheTime: performance.now() - startTime
2131
+ }
2132
+ };
2133
+ }
2134
+ }
2135
+ const security = mergePolicy(options.security ?? this.defaultSecurity);
2136
+ const violations = validateSource(options.source, security);
2137
+ throwOnViolations(violations);
2138
+ const sourceType = opts.sourceType === "auto" ? this.detectSourceType(options.source) : opts.sourceType;
2139
+ const transformStart = performance.now();
2140
+ const transformed = await this.transform(options.source, sourceType, opts);
2141
+ const transformTime = performance.now() - transformStart;
2142
+ const sizeViolation = validateSize(transformed.code.length, security);
2143
+ if (sizeViolation) {
2144
+ throwOnViolations([sizeViolation]);
2145
+ }
2146
+ const hash = hashContent(transformed.code);
2147
+ const result = {
2148
+ code: transformed.code,
2149
+ hash,
2150
+ cached: false,
2151
+ size: transformed.code.length,
2152
+ map: transformed.map,
2153
+ metrics: {
2154
+ transformTime,
2155
+ bundleTime: 0,
2156
+ // No separate bundle step for transform-only
2157
+ totalTime: performance.now() - startTime
2158
+ },
2159
+ sourceType,
2160
+ format: opts.format
2161
+ };
2162
+ if (!this.options.cache.disabled) {
2163
+ const cacheKey = options.cacheKey ?? createCacheKey(options.source, opts);
2164
+ this.cache.set(cacheKey, result);
2165
+ }
2166
+ return result;
2167
+ }
2168
+ /**
2169
+ * Bundle and execute for SSR.
2170
+ *
2171
+ * @param options - SSR bundle options
2172
+ * @returns SSR result with rendered HTML
2173
+ */
2174
+ async bundleSSR(options) {
2175
+ const startTime = performance.now();
2176
+ const bundleResult = await this.bundle({
2177
+ ...options,
2178
+ format: "cjs"
2179
+ // CommonJS for execution
2180
+ });
2181
+ let React;
2182
+ let ReactDOMServer;
2183
+ try {
2184
+ React = await import("react");
2185
+ ReactDOMServer = await import("react-dom/server");
2186
+ } catch {
2187
+ throw new Error("React and react-dom/server are required for SSR. Install them: npm install react react-dom");
2188
+ }
2189
+ const renderStart = performance.now();
2190
+ const Component = await executeDefault(bundleResult.code, {
2191
+ React,
2192
+ security: mergePolicy(options.security ?? this.defaultSecurity)
2193
+ });
2194
+ let html;
2195
+ try {
2196
+ const element = React.createElement(Component, options.context ?? {});
2197
+ html = ReactDOMServer.renderToString(element);
2198
+ } catch (error) {
2199
+ throw new ExecutionError(
2200
+ `SSR rendering failed: ${error instanceof Error ? error.message : String(error)}`,
2201
+ error
2202
+ );
2203
+ }
2204
+ const renderTime = performance.now() - renderStart;
2205
+ let hydrationScript;
2206
+ if (options.includeHydration) {
2207
+ hydrationScript = this.buildHydrationScript(bundleResult.code, options.context);
2208
+ }
2209
+ return {
2210
+ ...bundleResult,
2211
+ html,
2212
+ hydrationScript,
2213
+ metrics: {
2214
+ ...bundleResult.metrics,
2215
+ totalTime: performance.now() - startTime
2216
+ },
2217
+ ssrMetrics: {
2218
+ renderTime
2219
+ }
2220
+ };
2221
+ }
2222
+ /**
2223
+ * Bundle and execute code, returning the exports.
2224
+ *
2225
+ * @param options - Bundle options
2226
+ * @param context - Execution context
2227
+ * @returns Exported value
2228
+ */
2229
+ async bundleAndExecute(options, context) {
2230
+ const result = await this.bundle({
2231
+ ...options,
2232
+ format: "cjs"
2233
+ // CommonJS for execution
2234
+ });
2235
+ let React;
2236
+ try {
2237
+ React = await import("react");
2238
+ } catch {
2239
+ }
2240
+ return executeDefault(result.code, {
2241
+ React,
2242
+ globals: context,
2243
+ security: mergePolicy(options.security ?? this.defaultSecurity)
2244
+ });
2245
+ }
2246
+ /**
2247
+ * Bundle a component to a self-contained static HTML document.
2248
+ *
2249
+ * Creates a complete HTML page with:
2250
+ * - React runtime (CDN or inline based on platform)
2251
+ * - FrontMCP UI hooks and components (always inline)
2252
+ * - Tool data injection (input/output)
2253
+ * - Transpiled component code
2254
+ * - Client-side rendering via createRoot
2255
+ *
2256
+ * @param options - Static HTML options
2257
+ * @returns Static HTML result with complete document
2258
+ *
2259
+ * @example
2260
+ * ```typescript
2261
+ * const result = await bundler.bundleToStaticHTML({
2262
+ * source: `
2263
+ * import { Card, useToolOutput } from '@frontmcp/ui/react';
2264
+ * export default function Weather() {
2265
+ * const output = useToolOutput();
2266
+ * return <Card title="Weather">{output?.temperature}°F</Card>;
2267
+ * }
2268
+ * `,
2269
+ * toolName: 'get_weather',
2270
+ * output: { temperature: 72 },
2271
+ * });
2272
+ *
2273
+ * // result.html contains the complete HTML document
2274
+ * ```
2275
+ */
2276
+ async bundleToStaticHTML(options) {
2277
+ const startTime = performance.now();
2278
+ const opts = this.mergeStaticHTMLOptions(options);
2279
+ const platform = opts.targetPlatform === "auto" ? "generic" : opts.targetPlatform;
2280
+ const cdnType = getCdnTypeForPlatform(platform);
2281
+ if (opts.universal) {
2282
+ return this.bundleToStaticHTMLUniversal(options, opts, platform, cdnType, startTime);
2283
+ }
2284
+ const bundleResult = await this.bundle({
2285
+ source: options.source,
2286
+ sourceType: opts.sourceType,
2287
+ format: "cjs",
2288
+ minify: opts.minify,
2289
+ sourceMaps: false,
2290
+ externals: ["react", "react-dom", "react/jsx-runtime", "@frontmcp/ui", "@frontmcp/ui/react"],
2291
+ security: opts.security,
2292
+ skipCache: opts.skipCache
2293
+ });
2294
+ const head = this.buildStaticHTMLHead({ externals: opts.externals, customCss: opts.customCss });
2295
+ const reactRuntime = this.buildReactRuntimeScripts(opts.externals, platform, cdnType);
2296
+ const frontmcpRuntime = this.buildFrontMCPRuntime();
2297
+ const dataScript = this.buildDataInjectionScript(opts.toolName, opts.input, opts.output, opts.structuredContent);
2298
+ const componentScript = this.buildComponentRenderScript(bundleResult.code, opts.rootId, cdnType);
2299
+ const html = this.assembleStaticHTML({
2300
+ title: opts.title || `${opts.toolName} - Widget`,
2301
+ head,
2302
+ reactRuntime,
2303
+ frontmcpRuntime,
2304
+ dataScript,
2305
+ componentScript,
2306
+ rootId: opts.rootId,
2307
+ cdnType
2308
+ });
2309
+ const hash = hashContent(html);
2310
+ return {
2311
+ html,
2312
+ componentCode: bundleResult.code,
2313
+ metrics: {
2314
+ ...bundleResult.metrics,
2315
+ totalTime: performance.now() - startTime
2316
+ },
2317
+ hash,
2318
+ size: html.length,
2319
+ cached: bundleResult.cached,
2320
+ sourceType: bundleResult.sourceType,
2321
+ targetPlatform: platform
2322
+ };
2323
+ }
2324
+ /**
2325
+ * Bundle to static HTML with universal rendering mode.
2326
+ * Uses the universal renderer that can handle multiple content types.
2327
+ *
2328
+ * Optimization: Uses cached runtime (vendor chunk) to avoid rebuilding
2329
+ * static code on every request. Only the user's component is transpiled.
2330
+ */
2331
+ async bundleToStaticHTMLUniversal(options, opts, platform, cdnType, startTime) {
2332
+ let contentType;
2333
+ const rawContentType = options.contentType ?? "auto";
2334
+ if (rawContentType === "auto") {
2335
+ contentType = detectContentType(options.source);
2336
+ } else {
2337
+ contentType = rawContentType;
2338
+ }
2339
+ let transpiledCode = null;
2340
+ let transformTime = 0;
2341
+ if (contentType === "react") {
2342
+ const bundleResult = await this.bundle({
2343
+ source: options.source,
2344
+ sourceType: opts.sourceType,
2345
+ format: "cjs",
2346
+ minify: opts.minify,
2347
+ sourceMaps: false,
2348
+ externals: ["react", "react-dom", "react/jsx-runtime", "@frontmcp/ui", "@frontmcp/ui/react"],
2349
+ security: opts.security,
2350
+ skipCache: opts.skipCache
2351
+ });
2352
+ transpiledCode = bundleResult.code;
2353
+ transformTime = bundleResult.metrics.transformTime;
2354
+ }
2355
+ const cachedRuntime = getCachedRuntime({
2356
+ cdnType,
2357
+ includeMarkdown: opts.includeMarkdown || contentType === "markdown",
2358
+ includeMdx: opts.includeMdx || contentType === "mdx",
2359
+ minify: opts.minify
2360
+ });
2361
+ const componentCodeStr = transpiledCode ? buildComponentCode(transpiledCode) : "";
2362
+ const dataInjectionStr = buildDataInjectionCode(
2363
+ opts.toolName,
2364
+ opts.input,
2365
+ opts.output,
2366
+ opts.structuredContent,
2367
+ contentType,
2368
+ transpiledCode ? null : options.source,
2369
+ // Pass source only if not a component
2370
+ transpiledCode !== null
2371
+ );
2372
+ const appScript = buildAppScript(
2373
+ cachedRuntime.appTemplate,
2374
+ componentCodeStr,
2375
+ dataInjectionStr,
2376
+ opts.customComponents ?? ""
2377
+ );
2378
+ const head = this.buildStaticHTMLHead({ externals: opts.externals, customCss: opts.customCss });
2379
+ const reactRuntime = this.buildReactRuntimeScripts(opts.externals, platform, cdnType);
2380
+ const renderScript = this.buildUniversalRenderScript(opts.rootId, cdnType);
2381
+ const html = this.assembleUniversalStaticHTMLCached({
2382
+ title: opts.title || `${opts.toolName} - Widget`,
2383
+ head,
2384
+ reactRuntime,
2385
+ cdnImports: cachedRuntime.cdnImports,
2386
+ vendorScript: cachedRuntime.vendorScript,
2387
+ appScript,
2388
+ renderScript,
2389
+ rootId: opts.rootId,
2390
+ cdnType
2391
+ });
2392
+ const hash = hashContent(html);
2393
+ return {
2394
+ html,
2395
+ componentCode: transpiledCode ?? appScript,
2396
+ metrics: {
2397
+ transformTime,
2398
+ bundleTime: 0,
2399
+ totalTime: performance.now() - startTime,
2400
+ cacheTime: cachedRuntime.cached ? 0 : void 0
2401
+ },
2402
+ hash,
2403
+ size: html.length,
2404
+ cached: cachedRuntime.cached,
2405
+ sourceType: opts.sourceType === "auto" ? this.detectSourceType(options.source) : opts.sourceType,
2406
+ targetPlatform: platform,
2407
+ universal: true,
2408
+ contentType
2409
+ };
2410
+ }
2411
+ /**
2412
+ * Assemble the complete universal static HTML document using cached runtime.
2413
+ *
2414
+ * For ESM mode (OpenAI), scripts must wait for React to load asynchronously.
2415
+ * For UMD mode (Claude), scripts can execute synchronously.
2416
+ */
2417
+ assembleUniversalStaticHTMLCached(parts) {
2418
+ if (parts.cdnType === "umd") {
2419
+ return `<!DOCTYPE html>
2420
+ <html lang="en">
2421
+ <head>
2422
+ <title>${escapeHtml(parts.title)}</title>
2423
+ ${parts.head}
2424
+ ${parts.reactRuntime}
2425
+ ${parts.cdnImports}
2426
+ <!-- Vendor Runtime (Cached) -->
2427
+ <script>
2428
+ ${parts.vendorScript}
2429
+ </script>
2430
+ <!-- App Script (User Component) -->
2431
+ <script>
2432
+ ${parts.appScript}
2433
+ </script>
2434
+ </head>
2435
+ <body>
2436
+ <div id="${parts.rootId}" class="frontmcp-loading">
2437
+ <div class="frontmcp-spinner"></div>
2438
+ </div>
2439
+ ${parts.renderScript}
2440
+ </body>
2441
+ </html>`;
2442
+ } else {
2443
+ return `<!DOCTYPE html>
2444
+ <html lang="en">
2445
+ <head>
2446
+ <title>${escapeHtml(parts.title)}</title>
2447
+ ${parts.head}
2448
+ ${parts.reactRuntime}
2449
+ ${parts.cdnImports}
2450
+ </head>
2451
+ <body>
2452
+ <div id="${parts.rootId}" class="frontmcp-loading">
2453
+ <div class="frontmcp-spinner"></div>
2454
+ </div>
2455
+ <!-- Scripts wait for React to load (ESM is async) -->
2456
+ <script type="module">
2457
+ // Wait for React to be ready
2458
+ function initFrontMCP() {
2459
+ // Vendor Runtime (Cached)
2460
+ ${parts.vendorScript}
2461
+
2462
+ // App Script (User Component)
2463
+ ${parts.appScript}
2464
+
2465
+ // Render the app
2466
+ var container = document.getElementById('${parts.rootId}');
2467
+ if (container && window.ReactDOM && window.ReactDOM.createRoot && window.__frontmcp.UniversalApp) {
2468
+ var root = window.ReactDOM.createRoot(container);
2469
+ root.render(React.createElement(window.__frontmcp.UniversalApp));
2470
+ }
2471
+ }
2472
+
2473
+ if (window.__reactReady) {
2474
+ initFrontMCP();
2475
+ } else {
2476
+ window.addEventListener('react:ready', initFrontMCP);
2477
+ }
2478
+ </script>
2479
+ </body>
2480
+ </html>`;
2481
+ }
2482
+ }
2483
+ /**
2484
+ * Build the component script for transpiled React/MDX content.
2485
+ * Wraps CommonJS code with module/exports shim to capture the component.
2486
+ */
2487
+ buildUniversalComponentScript(transpiledCode, cdnType) {
2488
+ const wrappedCode = `
2489
+ // CommonJS module shim
2490
+ var module = { exports: {} };
2491
+ var exports = module.exports;
2492
+
2493
+ // Execute transpiled component code (CommonJS format)
2494
+ ${transpiledCode}
2495
+
2496
+ // Capture the component export
2497
+ window.__frontmcp_component = module.exports.default || module.exports;
2498
+ `;
2499
+ if (cdnType === "umd") {
2500
+ return `
2501
+ <!-- Universal Component Script (transpiled) -->
2502
+ <script>
2503
+ (function() {
2504
+ ${wrappedCode}
2505
+ })();
2506
+ </script>`;
2507
+ } else {
2508
+ return `
2509
+ <!-- Universal Component Script (transpiled, ESM) -->
2510
+ <script type="module">
2511
+ function loadComponent() {
2512
+ ${wrappedCode}
2513
+ }
2514
+
2515
+ if (window.__reactReady) {
2516
+ loadComponent();
2517
+ } else {
2518
+ window.addEventListener('react:ready', loadComponent);
2519
+ }
2520
+ </script>`;
2521
+ }
2522
+ }
2523
+ /**
2524
+ * Build the universal runtime script section.
2525
+ */
2526
+ buildUniversalRuntimeScript(runtimeScript) {
2527
+ return `
2528
+ <!-- Universal Runtime -->
2529
+ <script>
2530
+ ${runtimeScript}
2531
+ </script>`;
2532
+ }
2533
+ /**
2534
+ * Build data injection script for universal mode.
2535
+ */
2536
+ buildUniversalDataScript(toolName, input, output, structuredContent, contentType, source, hasTranspiledComponent = false) {
2537
+ const safeJson = (value) => {
2538
+ try {
2539
+ return JSON.stringify(value);
2540
+ } catch {
2541
+ return "null";
2542
+ }
2543
+ };
2544
+ if (hasTranspiledComponent) {
2545
+ return `
2546
+ <!-- Universal Data Injection (React Component) -->
2547
+ <script>
2548
+ window.__frontmcp.setState({
2549
+ toolName: ${safeJson(toolName)},
2550
+ input: ${safeJson(input ?? null)},
2551
+ output: ${safeJson(output ?? null)},
2552
+ structuredContent: ${safeJson(structuredContent ?? null)},
2553
+ content: {
2554
+ type: 'react',
2555
+ source: window.__frontmcp_component
2556
+ },
2557
+ loading: false,
2558
+ error: null
2559
+ });
2560
+ </script>`;
2561
+ }
2562
+ const escapedSource = JSON.stringify(source);
2563
+ return `
2564
+ <!-- Universal Data Injection -->
2565
+ <script>
2566
+ window.__frontmcp.setState({
2567
+ toolName: ${safeJson(toolName)},
2568
+ input: ${safeJson(input ?? null)},
2569
+ output: ${safeJson(output ?? null)},
2570
+ structuredContent: ${safeJson(structuredContent ?? null)},
2571
+ content: {
2572
+ type: ${safeJson(contentType)},
2573
+ source: ${escapedSource}
2574
+ },
2575
+ loading: false,
2576
+ error: null
2577
+ });
2578
+ </script>`;
2579
+ }
2580
+ /**
2581
+ * Build the universal render script.
2582
+ */
2583
+ buildUniversalRenderScript(rootId, cdnType) {
2584
+ if (cdnType === "umd") {
2585
+ return `
2586
+ <!-- Universal Render Script (UMD - synchronous) -->
2587
+ <script>
2588
+ (function() {
2589
+ var container = document.getElementById('${rootId}');
2590
+ if (container && window.ReactDOM && window.ReactDOM.createRoot && window.__frontmcp.UniversalApp) {
2591
+ var root = window.ReactDOM.createRoot(container);
2592
+ root.render(React.createElement(window.__frontmcp.UniversalApp));
2593
+ } else if (container && window.ReactDOM && window.ReactDOM.render && window.__frontmcp.UniversalApp) {
2594
+ window.ReactDOM.render(
2595
+ React.createElement(window.__frontmcp.UniversalApp),
2596
+ container
2597
+ );
2598
+ }
2599
+ })();
2600
+ </script>`;
2601
+ } else {
2602
+ return `
2603
+ <!-- Universal Render Script (ESM - waits for React) -->
2604
+ <script type="module">
2605
+ function renderUniversalApp() {
2606
+ var container = document.getElementById('${rootId}');
2607
+ if (container && window.ReactDOM && window.ReactDOM.createRoot && window.__frontmcp.UniversalApp) {
2608
+ var root = window.ReactDOM.createRoot(container);
2609
+ root.render(React.createElement(window.__frontmcp.UniversalApp));
2610
+ }
2611
+ }
2612
+
2613
+ if (window.__reactReady) {
2614
+ renderUniversalApp();
2615
+ } else {
2616
+ window.addEventListener('react:ready', renderUniversalApp);
2617
+ }
2618
+ </script>`;
2619
+ }
2620
+ }
2621
+ /**
2622
+ * Assemble the complete universal static HTML document.
2623
+ */
2624
+ assembleUniversalStaticHTML(parts) {
2625
+ return `<!DOCTYPE html>
2626
+ <html lang="en">
2627
+ <head>
2628
+ <title>${escapeHtml(parts.title)}</title>
2629
+ ${parts.head}
2630
+ ${parts.reactRuntime}
2631
+ ${parts.frontmcpRuntime ?? ""}
2632
+ ${parts.cdnImports}
2633
+ ${parts.universalRuntimeScript}
2634
+ ${parts.componentScript ?? ""}
2635
+ ${parts.dataScript}
2636
+ </head>
2637
+ <body>
2638
+ <div id="${parts.rootId}" class="frontmcp-loading">
2639
+ <div class="frontmcp-spinner"></div>
2640
+ </div>
2641
+ ${parts.renderScript}
2642
+ </body>
2643
+ </html>`;
2644
+ }
2645
+ /**
2646
+ * Get cache statistics.
2647
+ */
2648
+ getCacheStats() {
2649
+ return this.cache.getStats();
2650
+ }
2651
+ /**
2652
+ * Clear the cache.
2653
+ */
2654
+ clearCache() {
2655
+ this.cache.clear();
2656
+ }
2657
+ /**
2658
+ * Clean up expired cache entries.
2659
+ */
2660
+ cleanupCache() {
2661
+ return this.cache.cleanup();
2662
+ }
2663
+ /**
2664
+ * Transform source code using esbuild/SWC.
2665
+ */
2666
+ async transform(source, sourceType, options) {
2667
+ const transform = await loadEsbuild();
2668
+ if (!transform) {
2669
+ throw new Error("No bundler available. Install esbuild or @swc/core: npm install esbuild");
2670
+ }
2671
+ const loader = this.getLoader(sourceType);
2672
+ const esbuildOptions = {
2673
+ loader,
2674
+ minify: options.minify,
2675
+ sourcemap: options.sourceMaps,
2676
+ target: options.target,
2677
+ format: options.format === "cjs" ? "cjs" : options.format === "esm" ? "esm" : "iife",
2678
+ jsx: "automatic",
2679
+ jsxImportSource: options.jsx.importSource
2680
+ };
2681
+ try {
2682
+ const result = await transform(source, esbuildOptions);
2683
+ return {
2684
+ code: result.code,
2685
+ map: result.map
2686
+ };
2687
+ } catch (error) {
2688
+ throw new Error(`Transform failed: ${error instanceof Error ? error.message : String(error)}`);
2689
+ }
2690
+ }
2691
+ /**
2692
+ * Get esbuild loader for source type.
2693
+ */
2694
+ getLoader(sourceType) {
2695
+ switch (sourceType) {
2696
+ case "jsx":
2697
+ return "jsx";
2698
+ case "tsx":
2699
+ return "tsx";
2700
+ case "mdx":
2701
+ return "tsx";
2702
+ // MDX compiles to JSX/TSX
2703
+ case "html":
2704
+ return "text";
2705
+ default:
2706
+ return "tsx";
2707
+ }
2708
+ }
2709
+ /**
2710
+ * Detect source type from content.
2711
+ */
2712
+ detectSourceType(source) {
2713
+ const hasTypeScript = /:\s*(string|number|boolean|any|unknown|void|never|object)\b/.test(source) || /interface\s+\w+/.test(source) || /type\s+\w+\s*=/.test(source) || /<\w+>/.test(source);
2714
+ const hasJSX = /<[A-Z][a-zA-Z]*/.test(source) || // Component tags
2715
+ /<[a-z]+\s/.test(source) || // HTML tags with attributes
2716
+ /<[a-z]+>/.test(source) || // Self-closing HTML tags
2717
+ /<\/[a-z]+>/.test(source);
2718
+ const hasMDX = /^#\s+/.test(source) || // Markdown heading
2719
+ /^-\s+/.test(source) || // Markdown list
2720
+ /\*\*\w+\*\*/.test(source) || // Bold
2721
+ /```\w*\n/.test(source);
2722
+ if (hasMDX && hasJSX) {
2723
+ return "mdx";
2724
+ }
2725
+ if (hasTypeScript && hasJSX) {
2726
+ return "tsx";
2727
+ }
2728
+ if (hasJSX) {
2729
+ return "jsx";
2730
+ }
2731
+ if (hasTypeScript) {
2732
+ return "tsx";
2733
+ }
2734
+ return "jsx";
2735
+ }
2736
+ /**
2737
+ * Merge bundle options with defaults.
2738
+ */
2739
+ mergeOptions(options) {
2740
+ return {
2741
+ sourceType: options.sourceType ?? DEFAULT_BUNDLE_OPTIONS.sourceType,
2742
+ format: options.format ?? DEFAULT_BUNDLE_OPTIONS.format,
2743
+ minify: options.minify ?? DEFAULT_BUNDLE_OPTIONS.minify,
2744
+ sourceMaps: options.sourceMaps ?? DEFAULT_BUNDLE_OPTIONS.sourceMaps,
2745
+ externals: options.externals ?? DEFAULT_BUNDLE_OPTIONS.externals,
2746
+ jsx: {
2747
+ ...DEFAULT_BUNDLE_OPTIONS.jsx,
2748
+ ...options.jsx
2749
+ },
2750
+ target: options.target ?? DEFAULT_BUNDLE_OPTIONS.target,
2751
+ globalName: options.globalName ?? DEFAULT_BUNDLE_OPTIONS.globalName,
2752
+ skipCache: options.skipCache ?? DEFAULT_BUNDLE_OPTIONS.skipCache
2753
+ };
2754
+ }
2755
+ /**
2756
+ * Build hydration script for client-side React.
2757
+ */
2758
+ buildHydrationScript(bundledCode, context) {
2759
+ const contextJson = context ? JSON.stringify(context) : "{}";
2760
+ return `
2761
+ (function() {
2762
+ var context = ${contextJson};
2763
+ var exports = {};
2764
+ var module = { exports: exports };
2765
+
2766
+ // Execute bundled code
2767
+ (function(exports, module) {
2768
+ ${bundledCode}
2769
+ })(exports, module);
2770
+
2771
+ // Get component
2772
+ var Component = module.exports.default || module.exports;
2773
+
2774
+ // Hydrate
2775
+ if (typeof ReactDOM !== 'undefined' && ReactDOM.hydrateRoot) {
2776
+ var container = document.getElementById('root') || document.body.firstElementChild;
2777
+ if (container) {
2778
+ ReactDOM.hydrateRoot(container, React.createElement(Component, context));
2779
+ }
2780
+ }
2781
+ })();
2782
+ `.trim();
2783
+ }
2784
+ // ============================================
2785
+ // Static HTML Helper Methods
2786
+ // ============================================
2787
+ /**
2788
+ * Merge static HTML options with defaults.
2789
+ */
2790
+ mergeStaticHTMLOptions(options) {
2791
+ return {
2792
+ sourceType: options.sourceType ?? DEFAULT_STATIC_HTML_OPTIONS.sourceType,
2793
+ targetPlatform: options.targetPlatform ?? DEFAULT_STATIC_HTML_OPTIONS.targetPlatform,
2794
+ minify: options.minify ?? DEFAULT_STATIC_HTML_OPTIONS.minify,
2795
+ skipCache: options.skipCache ?? DEFAULT_STATIC_HTML_OPTIONS.skipCache,
2796
+ rootId: sanitizeRootId(options.rootId ?? DEFAULT_STATIC_HTML_OPTIONS.rootId),
2797
+ widgetAccessible: options.widgetAccessible ?? DEFAULT_STATIC_HTML_OPTIONS.widgetAccessible,
2798
+ externals: {
2799
+ ...DEFAULT_STATIC_HTML_OPTIONS.externals,
2800
+ ...options.externals
2801
+ },
2802
+ // Universal mode options
2803
+ universal: options.universal ?? DEFAULT_STATIC_HTML_OPTIONS.universal,
2804
+ contentType: options.contentType ?? DEFAULT_STATIC_HTML_OPTIONS.contentType,
2805
+ includeMarkdown: options.includeMarkdown ?? DEFAULT_STATIC_HTML_OPTIONS.includeMarkdown,
2806
+ includeMdx: options.includeMdx ?? DEFAULT_STATIC_HTML_OPTIONS.includeMdx,
2807
+ // Pass-through options
2808
+ toolName: options.toolName,
2809
+ input: options.input,
2810
+ output: options.output,
2811
+ structuredContent: options.structuredContent,
2812
+ title: options.title,
2813
+ security: options.security,
2814
+ customCss: options.customCss,
2815
+ customComponents: options.customComponents
2816
+ };
2817
+ }
2818
+ /**
2819
+ * Build the <head> section for static HTML.
2820
+ */
2821
+ buildStaticHTMLHead(opts) {
2822
+ const parts = [];
2823
+ parts.push(`<meta charset="UTF-8">`);
2824
+ parts.push(`<meta name="viewport" content="width=device-width, initial-scale=1.0">`);
2825
+ for (const url of STATIC_HTML_CDN.fonts.preconnect) {
2826
+ parts.push(`<link rel="preconnect" href="${url}" crossorigin>`);
2827
+ }
2828
+ parts.push(`<link rel="stylesheet" href="${STATIC_HTML_CDN.fonts.inter}">`);
2829
+ const tailwindConfig = opts.externals.tailwind ?? "cdn";
2830
+ if (tailwindConfig === "cdn") {
2831
+ parts.push(`<link rel="stylesheet" href="${STATIC_HTML_CDN.tailwind}">`);
2832
+ } else if (tailwindConfig !== "inline" && tailwindConfig) {
2833
+ parts.push(`<link rel="stylesheet" href="${tailwindConfig}">`);
2834
+ }
2835
+ parts.push(`<style>
2836
+ body { margin: 0; font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
2837
+ .frontmcp-loading { display: flex; align-items: center; justify-content: center; min-height: 200px; }
2838
+ .frontmcp-spinner { width: 24px; height: 24px; border: 2px solid #e5e7eb; border-top-color: #3b82f6; border-radius: 50%; animation: spin 1s linear infinite; }
2839
+ @keyframes spin { to { transform: rotate(360deg); } }
2840
+ </style>`);
2841
+ if (opts.customCss) {
2842
+ parts.push(`<style>
2843
+ ${sanitizeCss(opts.customCss)}
2844
+ </style>`);
2845
+ }
2846
+ return parts.join("\n ");
2847
+ }
2848
+ /**
2849
+ * Build React runtime scripts for static HTML.
2850
+ */
2851
+ buildReactRuntimeScripts(externals, platform, cdnType) {
2852
+ const reactConfig = externals.react ?? "cdn";
2853
+ const reactDomConfig = externals.reactDom ?? "cdn";
2854
+ if (cdnType === "umd") {
2855
+ const reactUrl = reactConfig === "cdn" ? STATIC_HTML_CDN.umd.react : reactConfig;
2856
+ const reactDomUrl = reactDomConfig === "cdn" ? STATIC_HTML_CDN.umd.reactDom : reactDomConfig;
2857
+ return `
2858
+ <!-- React Runtime (UMD from cdnjs - Claude compatible) -->
2859
+ <script src="${reactUrl}"></script>
2860
+ <script src="${reactDomUrl}"></script>
2861
+ <script>
2862
+ // Webpack/esbuild polyfills for transpiled code (UMD globals)
2863
+ window.external_react_namespaceObject = window.React;
2864
+ window.jsx_runtime_namespaceObject = {
2865
+ jsx: function(type, props, key) {
2866
+ if (key !== undefined) props = Object.assign({}, props, { key: key });
2867
+ return React.createElement(type, props);
2868
+ },
2869
+ jsxs: function(type, props, key) {
2870
+ if (key !== undefined) props = Object.assign({}, props, { key: key });
2871
+ return React.createElement(type, props);
2872
+ },
2873
+ Fragment: React.Fragment
2874
+ };
2875
+ window.__reactReady = true;
2876
+ </script>`;
2877
+ } else {
2878
+ const reactUrl = reactConfig === "cdn" ? STATIC_HTML_CDN.esm.react : reactConfig;
2879
+ const reactDomUrl = reactDomConfig === "cdn" ? STATIC_HTML_CDN.esm.reactDom : reactDomConfig;
2880
+ return `
2881
+ <!-- React Runtime (ES modules from esm.sh) -->
2882
+ <script type="module">
2883
+ import React from '${reactUrl}';
2884
+ import { createRoot } from '${reactDomUrl}';
2885
+
2886
+ // Make React available globally
2887
+ window.React = React;
2888
+ window.ReactDOM = { createRoot };
2889
+
2890
+ // Webpack/esbuild polyfills for transpiled code
2891
+ window.external_react_namespaceObject = React;
2892
+ window.jsx_runtime_namespaceObject = {
2893
+ jsx: function(type, props, key) {
2894
+ if (key !== undefined) props = Object.assign({}, props, { key: key });
2895
+ return React.createElement(type, props);
2896
+ },
2897
+ jsxs: function(type, props, key) {
2898
+ if (key !== undefined) props = Object.assign({}, props, { key: key });
2899
+ return React.createElement(type, props);
2900
+ },
2901
+ Fragment: React.Fragment
2902
+ };
2903
+
2904
+ // Signal React is ready
2905
+ window.__reactReady = true;
2906
+ window.dispatchEvent(new CustomEvent('react:ready'));
2907
+ </script>`;
2908
+ }
2909
+ }
2910
+ /**
2911
+ * Build FrontMCP runtime (hooks and UI components).
2912
+ * Always inlined for reliability across platforms.
2913
+ */
2914
+ buildFrontMCPRuntime() {
2915
+ return `
2916
+ <!-- FrontMCP Runtime (always inline) -->
2917
+ <script>
2918
+ // Custom require() shim for browser - maps module names to globals
2919
+ // This allows esbuild-transpiled code to work in browsers
2920
+ window.__moduleCache = {};
2921
+ window.require = function(moduleName) {
2922
+ // Check cache first
2923
+ if (window.__moduleCache[moduleName]) {
2924
+ return window.__moduleCache[moduleName];
2925
+ }
2926
+
2927
+ // Map module names to browser globals
2928
+ var moduleMap = {
2929
+ 'react': function() { return window.React; },
2930
+ 'react-dom': function() { return window.ReactDOM; },
2931
+ 'react-dom/client': function() { return window.ReactDOM; },
2932
+ 'react/jsx-runtime': function() { return window.jsx_runtime_namespaceObject; },
2933
+ 'react/jsx-dev-runtime': function() { return window.jsx_runtime_namespaceObject; },
2934
+ '@frontmcp/ui': function() { return window.react_namespaceObject; },
2935
+ '@frontmcp/ui/react': function() { return window.react_namespaceObject; },
2936
+ };
2937
+
2938
+ var resolver = moduleMap[moduleName];
2939
+ if (resolver) {
2940
+ var mod = resolver();
2941
+ window.__moduleCache[moduleName] = mod;
2942
+ return mod;
2943
+ }
2944
+
2945
+ console.warn('[FrontMCP] Unknown module requested:', moduleName);
2946
+ return {};
2947
+ };
2948
+
2949
+ // Async require for dynamic imports (returns Promise)
2950
+ window.requireAsync = function(moduleName) {
2951
+ return new Promise(function(resolve, reject) {
2952
+ // If module is already loaded, resolve immediately
2953
+ var mod = window.require(moduleName);
2954
+ if (mod && Object.keys(mod).length > 0) {
2955
+ resolve(mod);
2956
+ return;
2957
+ }
2958
+
2959
+ // For now, we don't support dynamic CDN loading
2960
+ // All required modules should be pre-loaded
2961
+ console.warn('[FrontMCP] Async module not available:', moduleName);
2962
+ resolve({});
2963
+ });
2964
+ };
2965
+
2966
+ // FrontMCP Hook implementations
2967
+ window.__frontmcp = {
2968
+ // Context for MCP bridge
2969
+ context: {
2970
+ toolName: null,
2971
+ toolInput: null,
2972
+ toolOutput: null,
2973
+ structuredContent: null,
2974
+ callTool: null,
2975
+ },
2976
+
2977
+ // Set context from data injection
2978
+ setContext: function(ctx) {
2979
+ Object.assign(this.context, ctx);
2980
+ },
2981
+ };
2982
+
2983
+ // Hook: useToolOutput - returns the tool output data
2984
+ window.useToolOutput = function() {
2985
+ return window.__frontmcp.context.toolOutput;
2986
+ };
2987
+
2988
+ // Hook: useToolInput - returns the tool input arguments
2989
+ window.useToolInput = function() {
2990
+ return window.__frontmcp.context.toolInput;
2991
+ };
2992
+
2993
+ // Hook: useMcpBridgeContext - returns full bridge context
2994
+ window.useMcpBridgeContext = function() {
2995
+ return window.__frontmcp.context;
2996
+ };
2997
+
2998
+ // Hook: useCallTool - returns function to call other tools
2999
+ window.useCallTool = function() {
3000
+ return function(name, args) {
3001
+ if (window.__frontmcp.context.callTool) {
3002
+ return window.__frontmcp.context.callTool(name, args);
3003
+ }
3004
+ console.warn('[FrontMCP] callTool not available - widget may not have tool access');
3005
+ return Promise.resolve(null);
3006
+ };
3007
+ };
3008
+
3009
+ // UI Components (simplified inline versions)
3010
+ window.Card = function(props) {
3011
+ var children = props.children;
3012
+ var title = props.title;
3013
+ var className = props.className || '';
3014
+ return React.createElement('div', {
3015
+ className: 'bg-white rounded-lg shadow border border-gray-200 overflow-hidden ' + className
3016
+ }, [
3017
+ title && React.createElement('div', {
3018
+ key: 'header',
3019
+ className: 'px-4 py-3 border-b border-gray-200 bg-gray-50'
3020
+ }, React.createElement('h3', { className: 'text-sm font-medium text-gray-900' }, title)),
3021
+ React.createElement('div', { key: 'body', className: 'p-4' }, children)
3022
+ ]);
3023
+ };
3024
+
3025
+ window.Badge = function(props) {
3026
+ var children = props.children;
3027
+ var variant = props.variant || 'default';
3028
+ var variantClasses = {
3029
+ default: 'bg-gray-100 text-gray-800',
3030
+ success: 'bg-green-100 text-green-800',
3031
+ warning: 'bg-yellow-100 text-yellow-800',
3032
+ error: 'bg-red-100 text-red-800',
3033
+ info: 'bg-blue-100 text-blue-800',
3034
+ };
3035
+ return React.createElement('span', {
3036
+ className: 'inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ' + (variantClasses[variant] || variantClasses.default)
3037
+ }, children);
3038
+ };
3039
+
3040
+ window.Button = function(props) {
3041
+ var children = props.children;
3042
+ var variant = props.variant || 'primary';
3043
+ var onClick = props.onClick;
3044
+ var disabled = props.disabled;
3045
+ var variantClasses = {
3046
+ primary: 'bg-blue-600 text-white hover:bg-blue-700',
3047
+ secondary: 'bg-gray-100 text-gray-900 hover:bg-gray-200',
3048
+ outline: 'border border-gray-300 text-gray-700 hover:bg-gray-50',
3049
+ danger: 'bg-red-600 text-white hover:bg-red-700',
3050
+ };
3051
+ return React.createElement('button', {
3052
+ className: 'px-4 py-2 rounded-md text-sm font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 ' +
3053
+ (disabled ? 'opacity-50 cursor-not-allowed ' : '') +
3054
+ (variantClasses[variant] || variantClasses.primary),
3055
+ onClick: onClick,
3056
+ disabled: disabled,
3057
+ }, children);
3058
+ };
3059
+
3060
+ // Make hooks available on react_namespaceObject for bundled imports
3061
+ window.react_namespaceObject = Object.assign({}, window.React || {}, {
3062
+ useToolOutput: window.useToolOutput,
3063
+ useToolInput: window.useToolInput,
3064
+ useMcpBridgeContext: window.useMcpBridgeContext,
3065
+ useCallTool: window.useCallTool,
3066
+ Card: window.Card,
3067
+ Badge: window.Badge,
3068
+ Button: window.Button,
3069
+ });
3070
+ </script>`;
3071
+ }
3072
+ /**
3073
+ * Build data injection script for tool input/output.
3074
+ */
3075
+ buildDataInjectionScript(toolName, input, output, structuredContent) {
3076
+ const safeJson = (value) => {
3077
+ try {
3078
+ return JSON.stringify(value);
3079
+ } catch {
3080
+ return "null";
3081
+ }
3082
+ };
3083
+ return `
3084
+ <!-- Tool Data Injection -->
3085
+ <script>
3086
+ window.__mcpToolName = ${safeJson(toolName)};
3087
+ window.__mcpToolInput = ${safeJson(input ?? null)};
3088
+ window.__mcpToolOutput = ${safeJson(output ?? null)};
3089
+ window.__mcpStructuredContent = ${safeJson(structuredContent ?? null)};
3090
+
3091
+ // Initialize FrontMCP context
3092
+ window.__frontmcp.setContext({
3093
+ toolName: window.__mcpToolName,
3094
+ toolInput: window.__mcpToolInput,
3095
+ toolOutput: window.__mcpToolOutput,
3096
+ structuredContent: window.__mcpStructuredContent,
3097
+ });
3098
+ </script>`;
3099
+ }
3100
+ /**
3101
+ * Build component render script.
3102
+ * Wraps CommonJS code with module/exports shim to capture the component.
3103
+ */
3104
+ buildComponentRenderScript(componentCode, rootId, cdnType) {
3105
+ const wrappedCode = `
3106
+ // CommonJS module shim
3107
+ var module = { exports: {} };
3108
+ var exports = module.exports;
3109
+
3110
+ // Execute transpiled component code (CommonJS format)
3111
+ ${componentCode}
3112
+
3113
+ // Capture the component export
3114
+ window.__frontmcp_component = module.exports;
3115
+ `;
3116
+ if (cdnType === "umd") {
3117
+ return `
3118
+ <!-- Component Render Script (UMD - synchronous) -->
3119
+ <script>
3120
+ (function() {
3121
+ ${wrappedCode}
3122
+
3123
+ // Get the component
3124
+ var Component = window.__frontmcp_component.default || window.__frontmcp_component;
3125
+
3126
+ // Render the component
3127
+ var container = document.getElementById('${rootId}');
3128
+ if (container && window.ReactDOM && window.ReactDOM.createRoot) {
3129
+ var root = window.ReactDOM.createRoot(container);
3130
+ root.render(React.createElement(Component, {
3131
+ output: window.__mcpToolOutput,
3132
+ input: window.__mcpToolInput,
3133
+ }));
3134
+ } else if (container && window.ReactDOM && window.ReactDOM.render) {
3135
+ // Fallback for React 17
3136
+ window.ReactDOM.render(
3137
+ React.createElement(Component, {
3138
+ output: window.__mcpToolOutput,
3139
+ input: window.__mcpToolInput,
3140
+ }),
3141
+ container
3142
+ );
3143
+ }
3144
+ })();
3145
+ </script>`;
3146
+ } else {
3147
+ return `
3148
+ <!-- Component Render Script (ESM - waits for React) -->
3149
+ <script type="module">
3150
+ function renderComponent() {
3151
+ ${wrappedCode}
3152
+
3153
+ // Get the component
3154
+ var Component = window.__frontmcp_component.default || window.__frontmcp_component;
3155
+
3156
+ // Render the component
3157
+ var container = document.getElementById('${rootId}');
3158
+ if (container && window.ReactDOM && window.ReactDOM.createRoot) {
3159
+ var root = window.ReactDOM.createRoot(container);
3160
+ root.render(React.createElement(Component, {
3161
+ output: window.__mcpToolOutput,
3162
+ input: window.__mcpToolInput,
3163
+ }));
3164
+ }
3165
+ }
3166
+
3167
+ // Wait for React to be ready
3168
+ if (window.__reactReady) {
3169
+ renderComponent();
3170
+ } else {
3171
+ window.addEventListener('react:ready', renderComponent);
3172
+ }
3173
+ </script>`;
3174
+ }
3175
+ }
3176
+ /**
3177
+ * Assemble the complete static HTML document.
3178
+ */
3179
+ assembleStaticHTML(parts) {
3180
+ return `<!DOCTYPE html>
3181
+ <html lang="en">
3182
+ <head>
3183
+ <title>${escapeHtml(parts.title)}</title>
3184
+ ${parts.head}
3185
+ ${parts.reactRuntime}
3186
+ ${parts.frontmcpRuntime}
3187
+ ${parts.dataScript}
3188
+ </head>
3189
+ <body>
3190
+ <div id="${parts.rootId}" class="frontmcp-loading">
3191
+ <div class="frontmcp-spinner"></div>
3192
+ </div>
3193
+ ${parts.componentScript}
3194
+ </body>
3195
+ </html>`;
3196
+ }
3197
+ };
3198
+ function createBundler(options) {
3199
+ return new InMemoryBundler(options);
3200
+ }
3201
+
3202
+ // libs/ui/src/bundler/file-cache/storage/index.ts
3203
+ init_interface();
3204
+ init_filesystem();
3205
+ init_redis();
3206
+
3207
+ // libs/ui/src/bundler/file-cache/hash-calculator.ts
3208
+ import { createHash as createHash2 } from "crypto";
3209
+ import { readFile as readFile2 } from "fs/promises";
3210
+ import { existsSync as existsSync2 } from "fs";
3211
+ import { join as join2, dirname as dirname2, resolve } from "path";
3212
+ function sha256(content) {
3213
+ return createHash2("sha256").update(content, "utf8").digest("hex");
3214
+ }
3215
+ function sha256Buffer(buffer) {
3216
+ return createHash2("sha256").update(buffer).digest("hex");
3217
+ }
3218
+ async function hashFile(filePath) {
3219
+ try {
3220
+ const content = await readFile2(filePath);
3221
+ return sha256Buffer(content);
3222
+ } catch {
3223
+ return void 0;
3224
+ }
3225
+ }
3226
+ async function hashFiles(filePaths) {
3227
+ const hashes = [];
3228
+ for (const filePath of filePaths.sort()) {
3229
+ const hash = await hashFile(filePath);
3230
+ if (hash) {
3231
+ hashes.push(`${filePath}:${hash}`);
3232
+ }
3233
+ }
3234
+ return sha256(hashes.join("\n"));
3235
+ }
3236
+ async function calculateComponentHash(options) {
3237
+ const {
3238
+ entryPath,
3239
+ baseDir = dirname2(entryPath),
3240
+ externals = [],
3241
+ dependencies = {},
3242
+ bundleOptions = {},
3243
+ maxDepth = 10
3244
+ } = options;
3245
+ const absoluteEntryPath = resolve(entryPath);
3246
+ const files = /* @__PURE__ */ new Set();
3247
+ const fileHashes = {};
3248
+ await collectLocalDependencies(absoluteEntryPath, baseDir, files, maxDepth, 0);
3249
+ for (const file of files) {
3250
+ const hash = await hashFile(file);
3251
+ if (hash) {
3252
+ fileHashes[file] = hash;
3253
+ }
3254
+ }
3255
+ const sortedFiles = Array.from(files).sort();
3256
+ const fileHashContent = sortedFiles.map((f) => `${f}:${fileHashes[f] || "missing"}`).join("\n");
3257
+ const filesHash = sha256(fileHashContent);
3258
+ const optionsHash = sha256(JSON.stringify(sortedObject(bundleOptions)));
3259
+ const dependenciesHash = sha256(JSON.stringify(sortedObject(dependencies)));
3260
+ const combinedHash = sha256([filesHash, optionsHash, dependenciesHash].join(":"));
3261
+ return {
3262
+ hash: combinedHash,
3263
+ entryHash: fileHashes[absoluteEntryPath] || "",
3264
+ files: sortedFiles,
3265
+ fileHashes,
3266
+ optionsHash,
3267
+ dependenciesHash
3268
+ };
3269
+ }
3270
+ async function calculateQuickHash(entryPath, bundleOptions) {
3271
+ const entryHash = await hashFile(entryPath);
3272
+ const optionsHash = bundleOptions ? sha256(JSON.stringify(sortedObject(bundleOptions))) : "";
3273
+ return sha256(`${entryHash || "missing"}:${optionsHash}`);
3274
+ }
3275
+ async function collectLocalDependencies(filePath, baseDir, collected, maxDepth, currentDepth) {
3276
+ if (currentDepth >= maxDepth) return;
3277
+ if (collected.has(filePath)) return;
3278
+ if (!existsSync2(filePath)) return;
3279
+ collected.add(filePath);
3280
+ try {
3281
+ const content = await readFile2(filePath, "utf8");
3282
+ const imports = extractImportPaths(content);
3283
+ for (const importPath of imports) {
3284
+ if (!importPath.startsWith(".") && !importPath.startsWith("/")) {
3285
+ continue;
3286
+ }
3287
+ const resolvedPath = resolveImportPath(importPath, dirname2(filePath));
3288
+ if (resolvedPath && existsSync2(resolvedPath)) {
3289
+ await collectLocalDependencies(resolvedPath, baseDir, collected, maxDepth, currentDepth + 1);
3290
+ }
3291
+ }
3292
+ } catch {
3293
+ }
3294
+ }
3295
+ function extractImportPaths(source) {
3296
+ const paths = [];
3297
+ const importRegex = /import\s+(?:[^'"]+\s+from\s+)?['"]([^'"]+)['"]/g;
3298
+ let match;
3299
+ while ((match = importRegex.exec(source)) !== null) {
3300
+ paths.push(match[1]);
3301
+ }
3302
+ const exportRegex = /export\s+(?:\*|{[^}]+})\s+from\s+['"]([^'"]+)['"]/g;
3303
+ while ((match = exportRegex.exec(source)) !== null) {
3304
+ paths.push(match[1]);
3305
+ }
3306
+ const requireRegex = /require\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
3307
+ while ((match = requireRegex.exec(source)) !== null) {
3308
+ paths.push(match[1]);
3309
+ }
3310
+ const dynamicRegex = /import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
3311
+ while ((match = dynamicRegex.exec(source)) !== null) {
3312
+ paths.push(match[1]);
3313
+ }
3314
+ return [...new Set(paths)];
3315
+ }
3316
+ function resolveImportPath(importPath, fromDir) {
3317
+ const extensions = ["", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"];
3318
+ for (const ext of extensions) {
3319
+ const fullPath = join2(fromDir, importPath + ext);
3320
+ if (existsSync2(fullPath)) {
3321
+ return fullPath;
3322
+ }
3323
+ }
3324
+ for (const ext of extensions) {
3325
+ const indexPath = join2(fromDir, importPath, `index${ext}`);
3326
+ if (existsSync2(indexPath)) {
3327
+ return indexPath;
3328
+ }
3329
+ }
3330
+ return void 0;
3331
+ }
3332
+ function sortedObject(obj) {
3333
+ const sorted = {};
3334
+ const keys = Object.keys(obj).sort();
3335
+ for (const key of keys) {
3336
+ const value = obj[key];
3337
+ if (value && typeof value === "object" && !Array.isArray(value)) {
3338
+ sorted[key] = sortedObject(value);
3339
+ } else {
3340
+ sorted[key] = value;
3341
+ }
3342
+ }
3343
+ return sorted;
3344
+ }
3345
+ function generateBuildId() {
3346
+ const timestamp = Date.now().toString(36);
3347
+ const random = Math.random().toString(36).substring(2, 10);
3348
+ return `${timestamp}-${random}`;
3349
+ }
3350
+ function buildIdFromHash(hash) {
3351
+ return hash.substring(0, 12);
3352
+ }
3353
+
3354
+ // libs/ui/src/bundler/file-cache/component-builder.ts
3355
+ import { readFile as readFile3 } from "fs/promises";
3356
+ import { existsSync as existsSync3 } from "fs";
3357
+ import { resolve as resolve2, extname } from "path";
3358
+ import { randomUUID } from "crypto";
3359
+
3360
+ // libs/ui/src/dependency/cdn-registry.ts
3361
+ var DEFAULT_CDN_REGISTRY = {
3362
+ // ============================================
3363
+ // React Ecosystem
3364
+ // ============================================
3365
+ react: {
3366
+ packageName: "react",
3367
+ defaultVersion: "18.3.1",
3368
+ providers: {
3369
+ cloudflare: {
3370
+ url: "https://cdnjs.cloudflare.com/ajax/libs/react/18.3.1/umd/react.production.min.js",
3371
+ integrity: "sha512-Qp8J4Xr8LBZ5CXNJQc/HmLqFrpXz6lNkbzMYkYHKzQx5p1q1yOqPQHntXKoYgPPE/n9m0QF1OkJdXa2ePpO4fw==",
3372
+ global: "React",
3373
+ crossorigin: "anonymous"
3374
+ },
3375
+ jsdelivr: {
3376
+ url: "https://cdn.jsdelivr.net/npm/react@18.3.1/umd/react.production.min.js",
3377
+ global: "React",
3378
+ crossorigin: "anonymous"
3379
+ },
3380
+ unpkg: {
3381
+ url: "https://unpkg.com/react@18.3.1/umd/react.production.min.js",
3382
+ global: "React",
3383
+ crossorigin: "anonymous"
3384
+ },
3385
+ "esm.sh": {
3386
+ url: "https://esm.sh/react@18.3.1",
3387
+ esm: true,
3388
+ crossorigin: "anonymous"
3389
+ }
3390
+ },
3391
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg", "esm.sh"],
3392
+ metadata: {
3393
+ description: "A JavaScript library for building user interfaces",
3394
+ homepage: "https://react.dev",
3395
+ license: "MIT"
3396
+ }
3397
+ },
3398
+ "react-dom": {
3399
+ packageName: "react-dom",
3400
+ defaultVersion: "18.3.1",
3401
+ providers: {
3402
+ cloudflare: {
3403
+ url: "https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.3.1/umd/react-dom.production.min.js",
3404
+ integrity: "sha512-6s2gVRdS3aT+FDdZTRJSzKlzIPqDXWyYl/5hPQb6hSgzKPGFcQyZhbqjbWVxGrs2dYNrINFXb0k0UD3d+CKPJA==",
3405
+ global: "ReactDOM",
3406
+ crossorigin: "anonymous",
3407
+ peerDependencies: ["react"]
3408
+ },
3409
+ jsdelivr: {
3410
+ url: "https://cdn.jsdelivr.net/npm/react-dom@18.3.1/umd/react-dom.production.min.js",
3411
+ global: "ReactDOM",
3412
+ crossorigin: "anonymous",
3413
+ peerDependencies: ["react"]
3414
+ },
3415
+ unpkg: {
3416
+ url: "https://unpkg.com/react-dom@18.3.1/umd/react-dom.production.min.js",
3417
+ global: "ReactDOM",
3418
+ crossorigin: "anonymous",
3419
+ peerDependencies: ["react"]
3420
+ },
3421
+ "esm.sh": {
3422
+ url: "https://esm.sh/react-dom@18.3.1",
3423
+ esm: true,
3424
+ crossorigin: "anonymous",
3425
+ peerDependencies: ["react"]
3426
+ }
3427
+ },
3428
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg", "esm.sh"],
3429
+ metadata: {
3430
+ description: "React package for working with the DOM",
3431
+ homepage: "https://react.dev",
3432
+ license: "MIT"
3433
+ }
3434
+ },
3435
+ // ============================================
3436
+ // Charting Libraries
3437
+ // ============================================
3438
+ "chart.js": {
3439
+ packageName: "chart.js",
3440
+ defaultVersion: "4.4.7",
3441
+ providers: {
3442
+ cloudflare: {
3443
+ url: "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.7/chart.umd.min.js",
3444
+ integrity: "sha512-dMDjIoZjJD6gs0KPBhFYjLQrH3kIohSEn6HzWs6Y6GiO0+L9kk/bM3cR5KNEDK1KvMNpTIZG6pHK9SZfCJHRpQ==",
3445
+ global: "Chart",
3446
+ crossorigin: "anonymous"
3447
+ },
3448
+ jsdelivr: {
3449
+ url: "https://cdn.jsdelivr.net/npm/chart.js@4.4.7/dist/chart.umd.min.js",
3450
+ global: "Chart",
3451
+ crossorigin: "anonymous"
3452
+ },
3453
+ unpkg: {
3454
+ url: "https://unpkg.com/chart.js@4.4.7/dist/chart.umd.min.js",
3455
+ global: "Chart",
3456
+ crossorigin: "anonymous"
3457
+ }
3458
+ },
3459
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
3460
+ metadata: {
3461
+ description: "Simple yet flexible JavaScript charting library",
3462
+ homepage: "https://www.chartjs.org",
3463
+ license: "MIT"
3464
+ }
3465
+ },
3466
+ "react-chartjs-2": {
3467
+ packageName: "react-chartjs-2",
3468
+ defaultVersion: "5.3.0",
3469
+ providers: {
3470
+ cloudflare: {
3471
+ url: "https://cdnjs.cloudflare.com/ajax/libs/react-chartjs-2/5.3.0/react-chartjs-2.min.js",
3472
+ global: "ReactChartjs2",
3473
+ crossorigin: "anonymous",
3474
+ peerDependencies: ["react", "chart.js"]
3475
+ },
3476
+ jsdelivr: {
3477
+ url: "https://cdn.jsdelivr.net/npm/react-chartjs-2@5.3.0/dist/index.umd.js",
3478
+ global: "ReactChartjs2",
3479
+ crossorigin: "anonymous",
3480
+ peerDependencies: ["react", "chart.js"]
3481
+ },
3482
+ "esm.sh": {
3483
+ url: "https://esm.sh/react-chartjs-2@5.3.0",
3484
+ esm: true,
3485
+ crossorigin: "anonymous",
3486
+ peerDependencies: ["react", "chart.js"]
3487
+ }
3488
+ },
3489
+ preferredProviders: ["cloudflare", "jsdelivr", "esm.sh"],
3490
+ metadata: {
3491
+ description: "React components for Chart.js",
3492
+ homepage: "https://react-chartjs-2.js.org",
3493
+ license: "MIT"
3494
+ }
3495
+ },
3496
+ // ============================================
3497
+ // D3.js
3498
+ // ============================================
3499
+ d3: {
3500
+ packageName: "d3",
3501
+ defaultVersion: "7.9.0",
3502
+ providers: {
3503
+ cloudflare: {
3504
+ url: "https://cdnjs.cloudflare.com/ajax/libs/d3/7.9.0/d3.min.js",
3505
+ integrity: "sha512-vc58qvvBdrDR4etbxMdlTt4GBQk1qjvyORR2nrsPsFPyrs+/u5c3+1Ct6upOgdZoIl7eq6k3a1UPDSNAQi/32A==",
3506
+ global: "d3",
3507
+ crossorigin: "anonymous"
3508
+ },
3509
+ jsdelivr: {
3510
+ url: "https://cdn.jsdelivr.net/npm/d3@7.9.0/dist/d3.min.js",
3511
+ global: "d3",
3512
+ crossorigin: "anonymous"
3513
+ },
3514
+ unpkg: {
3515
+ url: "https://unpkg.com/d3@7.9.0/dist/d3.min.js",
3516
+ global: "d3",
3517
+ crossorigin: "anonymous"
3518
+ }
3519
+ },
3520
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
3521
+ metadata: {
3522
+ description: "Data-Driven Documents",
3523
+ homepage: "https://d3js.org",
3524
+ license: "ISC"
3525
+ }
3526
+ },
3527
+ // ============================================
3528
+ // Utility Libraries
3529
+ // ============================================
3530
+ lodash: {
3531
+ packageName: "lodash",
3532
+ defaultVersion: "4.17.21",
3533
+ providers: {
3534
+ cloudflare: {
3535
+ url: "https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js",
3536
+ integrity: "sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==",
3537
+ global: "_",
3538
+ crossorigin: "anonymous"
3539
+ },
3540
+ jsdelivr: {
3541
+ url: "https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js",
3542
+ global: "_",
3543
+ crossorigin: "anonymous"
3544
+ },
3545
+ unpkg: {
3546
+ url: "https://unpkg.com/lodash@4.17.21/lodash.min.js",
3547
+ global: "_",
3548
+ crossorigin: "anonymous"
3549
+ }
3550
+ },
3551
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
3552
+ metadata: {
3553
+ description: "A modern JavaScript utility library",
3554
+ homepage: "https://lodash.com",
3555
+ license: "MIT"
3556
+ }
3557
+ },
3558
+ "lodash-es": {
3559
+ packageName: "lodash-es",
3560
+ defaultVersion: "4.17.21",
3561
+ providers: {
3562
+ "esm.sh": {
3563
+ url: "https://esm.sh/lodash-es@4.17.21",
3564
+ esm: true,
3565
+ crossorigin: "anonymous"
3566
+ },
3567
+ jsdelivr: {
3568
+ url: "https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm",
3569
+ esm: true,
3570
+ crossorigin: "anonymous"
3571
+ }
3572
+ },
3573
+ preferredProviders: ["esm.sh", "jsdelivr"],
3574
+ metadata: {
3575
+ description: "Lodash exported as ES modules",
3576
+ homepage: "https://lodash.com",
3577
+ license: "MIT"
3578
+ }
3579
+ },
3580
+ dayjs: {
3581
+ packageName: "dayjs",
3582
+ defaultVersion: "1.11.13",
3583
+ providers: {
3584
+ cloudflare: {
3585
+ url: "https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.11.13/dayjs.min.js",
3586
+ integrity: "sha512-Ot7ArUEhJDU0cwoBNNnWe487kjL5wAOsIYig8llY/l0P2TUFwgsAHVmrZMHsT8NGo+HwkjTJsNErS6QqIkBxDw==",
3587
+ global: "dayjs",
3588
+ crossorigin: "anonymous"
3589
+ },
3590
+ jsdelivr: {
3591
+ url: "https://cdn.jsdelivr.net/npm/dayjs@1.11.13/dayjs.min.js",
3592
+ global: "dayjs",
3593
+ crossorigin: "anonymous"
3594
+ },
3595
+ unpkg: {
3596
+ url: "https://unpkg.com/dayjs@1.11.13/dayjs.min.js",
3597
+ global: "dayjs",
3598
+ crossorigin: "anonymous"
3599
+ }
3600
+ },
3601
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
3602
+ metadata: {
3603
+ description: "Fast 2kB alternative to Moment.js with the same modern API",
3604
+ homepage: "https://day.js.org",
3605
+ license: "MIT"
3606
+ }
3607
+ },
3608
+ "date-fns": {
3609
+ packageName: "date-fns",
3610
+ defaultVersion: "4.1.0",
3611
+ providers: {
3612
+ "esm.sh": {
3613
+ url: "https://esm.sh/date-fns@4.1.0",
3614
+ esm: true,
3615
+ crossorigin: "anonymous"
3616
+ },
3617
+ jsdelivr: {
3618
+ url: "https://cdn.jsdelivr.net/npm/date-fns@4.1.0/+esm",
3619
+ esm: true,
3620
+ crossorigin: "anonymous"
3621
+ }
3622
+ },
3623
+ preferredProviders: ["esm.sh", "jsdelivr"],
3624
+ metadata: {
3625
+ description: "Modern JavaScript date utility library",
3626
+ homepage: "https://date-fns.org",
3627
+ license: "MIT"
3628
+ }
3629
+ },
3630
+ // ============================================
3631
+ // Animation Libraries
3632
+ // ============================================
3633
+ "framer-motion": {
3634
+ packageName: "framer-motion",
3635
+ defaultVersion: "11.15.0",
3636
+ providers: {
3637
+ "esm.sh": {
3638
+ url: "https://esm.sh/framer-motion@11.15.0",
3639
+ esm: true,
3640
+ crossorigin: "anonymous",
3641
+ peerDependencies: ["react", "react-dom"]
3642
+ },
3643
+ jsdelivr: {
3644
+ url: "https://cdn.jsdelivr.net/npm/framer-motion@11.15.0/dist/framer-motion.js",
3645
+ global: "Motion",
3646
+ crossorigin: "anonymous",
3647
+ peerDependencies: ["react", "react-dom"]
3648
+ }
3649
+ },
3650
+ preferredProviders: ["esm.sh", "jsdelivr"],
3651
+ metadata: {
3652
+ description: "Production-ready motion library for React",
3653
+ homepage: "https://www.framer.com/motion/",
3654
+ license: "MIT"
3655
+ }
3656
+ },
3657
+ // ============================================
3658
+ // UI Component Libraries
3659
+ // ============================================
3660
+ "lucide-react": {
3661
+ packageName: "lucide-react",
3662
+ defaultVersion: "0.468.0",
3663
+ providers: {
3664
+ "esm.sh": {
3665
+ url: "https://esm.sh/lucide-react@0.468.0",
3666
+ esm: true,
3667
+ crossorigin: "anonymous",
3668
+ peerDependencies: ["react"]
3669
+ },
3670
+ jsdelivr: {
3671
+ url: "https://cdn.jsdelivr.net/npm/lucide-react@0.468.0/dist/esm/lucide-react.js",
3672
+ esm: true,
3673
+ crossorigin: "anonymous",
3674
+ peerDependencies: ["react"]
3675
+ }
3676
+ },
3677
+ preferredProviders: ["esm.sh", "jsdelivr"],
3678
+ metadata: {
3679
+ description: "Beautiful & consistent icon toolkit for React",
3680
+ homepage: "https://lucide.dev",
3681
+ license: "ISC"
3682
+ }
3683
+ },
3684
+ // ============================================
3685
+ // Markdown/Syntax Highlighting
3686
+ // ============================================
3687
+ marked: {
3688
+ packageName: "marked",
3689
+ defaultVersion: "15.0.4",
3690
+ providers: {
3691
+ cloudflare: {
3692
+ url: "https://cdnjs.cloudflare.com/ajax/libs/marked/15.0.4/marked.min.js",
3693
+ integrity: "sha512-Rn/d0sGeizGbk3VJEiYNDt/mMcfuzYoFkia3iBffv+HX8VUrHMo/0cKjZuxWGoZLPh/VxUcC9ais+RBFZW9EBg==",
3694
+ global: "marked",
3695
+ crossorigin: "anonymous"
3696
+ },
3697
+ jsdelivr: {
3698
+ url: "https://cdn.jsdelivr.net/npm/marked@15.0.4/marked.min.js",
3699
+ global: "marked",
3700
+ crossorigin: "anonymous"
3701
+ },
3702
+ unpkg: {
3703
+ url: "https://unpkg.com/marked@15.0.4/marked.min.js",
3704
+ global: "marked",
3705
+ crossorigin: "anonymous"
3706
+ }
3707
+ },
3708
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
3709
+ metadata: {
3710
+ description: "A markdown parser and compiler",
3711
+ homepage: "https://marked.js.org",
3712
+ license: "MIT"
3713
+ }
3714
+ },
3715
+ "highlight.js": {
3716
+ packageName: "highlight.js",
3717
+ defaultVersion: "11.10.0",
3718
+ providers: {
3719
+ cloudflare: {
3720
+ url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.10.0/highlight.min.js",
3721
+ integrity: "sha512-6yoqbrcLAHDWAdQmiRlHG4+m0g/CT/V9AGyxabG8j7Jk8j3v3k6mIP1iN/PvSofcWet2tf8SRn/j3L/+pb7LRQ==",
3722
+ global: "hljs",
3723
+ crossorigin: "anonymous"
3724
+ },
3725
+ jsdelivr: {
3726
+ url: "https://cdn.jsdelivr.net/npm/highlight.js@11.10.0/lib/core.min.js",
3727
+ global: "hljs",
3728
+ crossorigin: "anonymous"
3729
+ },
3730
+ unpkg: {
3731
+ url: "https://unpkg.com/highlight.js@11.10.0/lib/core.min.js",
3732
+ global: "hljs",
3733
+ crossorigin: "anonymous"
3734
+ }
3735
+ },
3736
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
3737
+ metadata: {
3738
+ description: "Syntax highlighting for the web",
3739
+ homepage: "https://highlightjs.org",
3740
+ license: "BSD-3-Clause"
3741
+ }
3742
+ },
3743
+ // ============================================
3744
+ // Interactive Libraries
3745
+ // ============================================
3746
+ "htmx.org": {
3747
+ packageName: "htmx.org",
3748
+ defaultVersion: "2.0.4",
3749
+ providers: {
3750
+ cloudflare: {
3751
+ url: "https://cdnjs.cloudflare.com/ajax/libs/htmx/2.0.4/htmx.min.js",
3752
+ integrity: "sha512-2kIcAizYXhIn5IyXrMC72f2nh0JAtESHRpOieVw5dYPYeHwLCC2eKCqvdZDYRSEgasKrPpEPpRFjL8gqwBZWAA==",
3753
+ global: "htmx",
3754
+ crossorigin: "anonymous"
3755
+ },
3756
+ jsdelivr: {
3757
+ url: "https://cdn.jsdelivr.net/npm/htmx.org@2.0.4/dist/htmx.min.js",
3758
+ global: "htmx",
3759
+ crossorigin: "anonymous"
3760
+ },
3761
+ unpkg: {
3762
+ url: "https://unpkg.com/htmx.org@2.0.4/dist/htmx.min.js",
3763
+ global: "htmx",
3764
+ crossorigin: "anonymous"
3765
+ }
3766
+ },
3767
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
3768
+ metadata: {
3769
+ description: "High power tools for HTML",
3770
+ homepage: "https://htmx.org",
3771
+ license: "BSD-2-Clause"
3772
+ }
3773
+ },
3774
+ alpinejs: {
3775
+ packageName: "alpinejs",
3776
+ defaultVersion: "3.14.3",
3777
+ providers: {
3778
+ cloudflare: {
3779
+ url: "https://cdnjs.cloudflare.com/ajax/libs/alpinejs/3.14.3/cdn.min.js",
3780
+ integrity: "sha512-lrQ8FHgsWKFSuQFq8NKPJicjlvJFEIrCqEj8zeX7ZOUlHWltN/Iow4jND+x84jqTdDf9n+hvQpJjGDvOl/eDRA==",
3781
+ global: "Alpine",
3782
+ crossorigin: "anonymous"
3783
+ },
3784
+ jsdelivr: {
3785
+ url: "https://cdn.jsdelivr.net/npm/alpinejs@3.14.3/dist/cdn.min.js",
3786
+ global: "Alpine",
3787
+ crossorigin: "anonymous"
3788
+ },
3789
+ unpkg: {
3790
+ url: "https://unpkg.com/alpinejs@3.14.3/dist/cdn.min.js",
3791
+ global: "Alpine",
3792
+ crossorigin: "anonymous"
3793
+ }
3794
+ },
3795
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
3796
+ metadata: {
3797
+ description: "A rugged, minimal framework for composing behavior directly in your markup",
3798
+ homepage: "https://alpinejs.dev",
3799
+ license: "MIT"
3800
+ }
3801
+ },
3802
+ // ============================================
3803
+ // Templating Libraries
3804
+ // ============================================
3805
+ handlebars: {
3806
+ packageName: "handlebars",
3807
+ defaultVersion: "4.7.8",
3808
+ providers: {
3809
+ cloudflare: {
3810
+ url: "https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.8/handlebars.min.js",
3811
+ integrity: "sha512-E1dSFxg+wsfJ4HKjutk/WaCzK7S2wv1POn1RRPGh8ZK+ag9l244Vqxji3r6wgz9YBf6+vhQEYJZpSjqWFPg9gg==",
3812
+ global: "Handlebars",
3813
+ crossorigin: "anonymous"
3814
+ },
3815
+ jsdelivr: {
3816
+ url: "https://cdn.jsdelivr.net/npm/handlebars@4.7.8/dist/handlebars.min.js",
3817
+ global: "Handlebars",
3818
+ crossorigin: "anonymous"
3819
+ },
3820
+ unpkg: {
3821
+ url: "https://unpkg.com/handlebars@4.7.8/dist/handlebars.min.js",
3822
+ global: "Handlebars",
3823
+ crossorigin: "anonymous"
3824
+ }
3825
+ },
3826
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
3827
+ metadata: {
3828
+ description: "Minimal templating on steroids",
3829
+ homepage: "https://handlebarsjs.com",
3830
+ license: "MIT"
3831
+ }
3832
+ }
3833
+ };
3834
+ var CDN_PROVIDER_PRIORITY = {
3835
+ claude: ["cloudflare"],
3836
+ // ONLY cloudflare for Claude
3837
+ openai: ["cloudflare", "jsdelivr", "unpkg", "esm.sh"],
3838
+ cursor: ["cloudflare", "jsdelivr", "unpkg", "esm.sh"],
3839
+ gemini: ["cloudflare", "jsdelivr", "unpkg", "esm.sh"],
3840
+ continue: ["cloudflare", "jsdelivr", "unpkg", "esm.sh"],
3841
+ cody: ["cloudflare", "jsdelivr", "unpkg", "esm.sh"],
3842
+ unknown: ["cloudflare", "jsdelivr", "unpkg", "esm.sh"]
3843
+ // Default to cloudflare first
3844
+ };
3845
+ function lookupPackage(packageName, registry = DEFAULT_CDN_REGISTRY) {
3846
+ return registry[packageName];
3847
+ }
3848
+ function mergeRegistries(customRegistry) {
3849
+ return {
3850
+ ...DEFAULT_CDN_REGISTRY,
3851
+ ...customRegistry
3852
+ };
3853
+ }
3854
+ function getPackagePeerDependencies(packageName, registry = DEFAULT_CDN_REGISTRY) {
3855
+ const entry = lookupPackage(packageName, registry);
3856
+ if (!entry) return [];
3857
+ for (const provider of Object.keys(entry.providers)) {
3858
+ const config = entry.providers[provider];
3859
+ if (config?.peerDependencies) {
3860
+ return config.peerDependencies;
3861
+ }
3862
+ }
3863
+ return [];
3864
+ }
3865
+ function resolveAllDependencies(packageNames, platform = "unknown", registry = DEFAULT_CDN_REGISTRY) {
3866
+ const resolved = /* @__PURE__ */ new Set();
3867
+ const queue = [...packageNames];
3868
+ while (queue.length > 0) {
3869
+ const packageName = queue.shift();
3870
+ if (!packageName) continue;
3871
+ if (resolved.has(packageName)) continue;
3872
+ resolved.add(packageName);
3873
+ const peers = getPackagePeerDependencies(packageName, registry);
3874
+ for (const peer of peers) {
3875
+ if (!resolved.has(peer)) {
3876
+ queue.push(peer);
3877
+ }
3878
+ }
3879
+ }
3880
+ const result = [];
3881
+ const remaining = new Set(resolved);
3882
+ while (remaining.size > 0) {
3883
+ let added = false;
3884
+ for (const pkg of remaining) {
3885
+ const peers = getPackagePeerDependencies(pkg, registry);
3886
+ const allPeersResolved = peers.every((peer) => !remaining.has(peer) || result.includes(peer));
3887
+ if (allPeersResolved) {
3888
+ if (!result.includes(pkg)) {
3889
+ result.push(pkg);
3890
+ }
3891
+ remaining.delete(pkg);
3892
+ added = true;
3893
+ }
3894
+ }
3895
+ if (!added && remaining.size > 0) {
3896
+ const next = remaining.values().next().value;
3897
+ if (next !== void 0) {
3898
+ if (!result.includes(next)) {
3899
+ result.push(next);
3900
+ }
3901
+ remaining.delete(next);
3902
+ }
3903
+ }
3904
+ }
3905
+ return result;
3906
+ }
3907
+
3908
+ // libs/ui/src/dependency/import-parser.ts
3909
+ var IMPORT_PATTERNS = {
3910
+ /**
3911
+ * Named imports: import { foo, bar } from 'module'
3912
+ * Also handles renamed imports: import { foo as f } from 'module'
3913
+ */
3914
+ named: /import\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]/g,
3915
+ /**
3916
+ * Default imports: import foo from 'module'
3917
+ */
3918
+ default: /import\s+(\w+)\s+from\s*['"]([^'"]+)['"]/g,
3919
+ /**
3920
+ * Namespace imports: import * as foo from 'module'
3921
+ */
3922
+ namespace: /import\s*\*\s*as\s+(\w+)\s+from\s*['"]([^'"]+)['"]/g,
3923
+ /**
3924
+ * Side-effect imports: import 'module'
3925
+ */
3926
+ sideEffect: /import\s*['"]([^'"]+)['"]/g,
3927
+ /**
3928
+ * Dynamic imports: import('module') or await import('module')
3929
+ */
3930
+ dynamic: /(?:await\s+)?import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,
3931
+ /**
3932
+ * Combined default and named: import foo, { bar } from 'module'
3933
+ */
3934
+ defaultAndNamed: /import\s+(\w+)\s*,\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]/g,
3935
+ /**
3936
+ * Combined default and namespace: import foo, * as bar from 'module'
3937
+ */
3938
+ defaultAndNamespace: /import\s+(\w+)\s*,\s*\*\s*as\s+(\w+)\s+from\s*['"]([^'"]+)['"]/g,
3939
+ /**
3940
+ * Re-exports: export { foo } from 'module'
3941
+ */
3942
+ reExport: /export\s*\{[^}]+\}\s*from\s*['"]([^'"]+)['"]/g,
3943
+ /**
3944
+ * Re-export all: export * from 'module'
3945
+ */
3946
+ reExportAll: /export\s*\*\s*from\s*['"]([^'"]+)['"]/g
3947
+ };
3948
+ function parseNamedImports(namedString) {
3949
+ return namedString.split(",").map((s) => s.trim()).filter((s) => s.length > 0).map((s) => {
3950
+ const asMatch = s.match(/^(\w+)\s+as\s+\w+$/);
3951
+ return asMatch ? asMatch[1] : s;
3952
+ });
3953
+ }
3954
+ function isRelativeImport(specifier) {
3955
+ return specifier.startsWith("./") || specifier.startsWith("../") || specifier.startsWith("/");
3956
+ }
3957
+ function isExternalImport(specifier) {
3958
+ return !isRelativeImport(specifier) && !specifier.startsWith("#");
3959
+ }
3960
+ function getPackageName(specifier) {
3961
+ if (specifier.startsWith("@")) {
3962
+ const parts = specifier.split("/");
3963
+ if (parts.length >= 2) {
3964
+ return `${parts[0]}/${parts[1]}`;
3965
+ }
3966
+ return specifier;
3967
+ }
3968
+ const firstSlash = specifier.indexOf("/");
3969
+ return firstSlash === -1 ? specifier : specifier.slice(0, firstSlash);
3970
+ }
3971
+ function getLineNumber(source, index) {
3972
+ let line = 1;
3973
+ for (let i = 0; i < index && i < source.length; i++) {
3974
+ if (source[i] === "\n") {
3975
+ line++;
3976
+ }
3977
+ }
3978
+ return line;
3979
+ }
3980
+ function getColumnNumber(source, index) {
3981
+ let column = 0;
3982
+ for (let i = index - 1; i >= 0 && source[i] !== "\n"; i--) {
3983
+ column++;
3984
+ }
3985
+ return column;
3986
+ }
3987
+ function parseImports(source) {
3988
+ const imports = [];
3989
+ const seenStatements = /* @__PURE__ */ new Set();
3990
+ const addImport = (imp) => {
3991
+ const key = `${imp.type}:${imp.specifier}:${imp.statement}`;
3992
+ if (!seenStatements.has(key)) {
3993
+ seenStatements.add(key);
3994
+ imports.push(imp);
3995
+ }
3996
+ };
3997
+ let match;
3998
+ const defaultAndNamedRegex = new RegExp(IMPORT_PATTERNS.defaultAndNamed.source, "g");
3999
+ while ((match = defaultAndNamedRegex.exec(source)) !== null) {
4000
+ const [statement, defaultName, namedString, specifier] = match;
4001
+ const namedImports = parseNamedImports(namedString);
4002
+ addImport({
4003
+ statement,
4004
+ specifier,
4005
+ type: "default",
4006
+ defaultImport: defaultName,
4007
+ namedImports,
4008
+ line: getLineNumber(source, match.index),
4009
+ column: getColumnNumber(source, match.index)
4010
+ });
4011
+ }
4012
+ const defaultAndNamespaceRegex = new RegExp(IMPORT_PATTERNS.defaultAndNamespace.source, "g");
4013
+ while ((match = defaultAndNamespaceRegex.exec(source)) !== null) {
4014
+ const [statement, defaultName, namespaceName, specifier] = match;
4015
+ addImport({
4016
+ statement,
4017
+ specifier,
4018
+ type: "default",
4019
+ defaultImport: defaultName,
4020
+ namespaceImport: namespaceName,
4021
+ line: getLineNumber(source, match.index),
4022
+ column: getColumnNumber(source, match.index)
4023
+ });
4024
+ }
4025
+ const namedRegex = new RegExp(IMPORT_PATTERNS.named.source, "g");
4026
+ while ((match = namedRegex.exec(source)) !== null) {
4027
+ const [statement, namedString, specifier] = match;
4028
+ const namedImports = parseNamedImports(namedString);
4029
+ addImport({
4030
+ statement,
4031
+ specifier,
4032
+ type: "named",
4033
+ namedImports,
4034
+ line: getLineNumber(source, match.index),
4035
+ column: getColumnNumber(source, match.index)
4036
+ });
4037
+ }
4038
+ const defaultRegex = new RegExp(IMPORT_PATTERNS.default.source, "g");
4039
+ while ((match = defaultRegex.exec(source)) !== null) {
4040
+ const [statement, defaultName, specifier] = match;
4041
+ const afterMatch = source.slice(match.index + match[0].length - specifier.length - 2);
4042
+ if (afterMatch.startsWith(",")) continue;
4043
+ addImport({
4044
+ statement,
4045
+ specifier,
4046
+ type: "default",
4047
+ defaultImport: defaultName,
4048
+ line: getLineNumber(source, match.index),
4049
+ column: getColumnNumber(source, match.index)
4050
+ });
4051
+ }
4052
+ const namespaceRegex = new RegExp(IMPORT_PATTERNS.namespace.source, "g");
4053
+ while ((match = namespaceRegex.exec(source)) !== null) {
4054
+ const [statement, namespaceName, specifier] = match;
4055
+ addImport({
4056
+ statement,
4057
+ specifier,
4058
+ type: "namespace",
4059
+ namespaceImport: namespaceName,
4060
+ line: getLineNumber(source, match.index),
4061
+ column: getColumnNumber(source, match.index)
4062
+ });
4063
+ }
4064
+ const sideEffectRegex = new RegExp(IMPORT_PATTERNS.sideEffect.source, "g");
4065
+ while ((match = sideEffectRegex.exec(source)) !== null) {
4066
+ const [statement, specifier] = match;
4067
+ const beforeMatch = source.slice(Math.max(0, match.index - 50), match.index);
4068
+ if (beforeMatch.includes("from")) continue;
4069
+ addImport({
4070
+ statement,
4071
+ specifier,
4072
+ type: "side-effect",
4073
+ line: getLineNumber(source, match.index),
4074
+ column: getColumnNumber(source, match.index)
4075
+ });
4076
+ }
4077
+ const dynamicRegex = new RegExp(IMPORT_PATTERNS.dynamic.source, "g");
4078
+ while ((match = dynamicRegex.exec(source)) !== null) {
4079
+ const [statement, specifier] = match;
4080
+ addImport({
4081
+ statement,
4082
+ specifier,
4083
+ type: "dynamic",
4084
+ line: getLineNumber(source, match.index),
4085
+ column: getColumnNumber(source, match.index)
4086
+ });
4087
+ }
4088
+ const reExportRegex = new RegExp(IMPORT_PATTERNS.reExport.source, "g");
4089
+ while ((match = reExportRegex.exec(source)) !== null) {
4090
+ const [statement, specifier] = match;
4091
+ addImport({
4092
+ statement,
4093
+ specifier,
4094
+ type: "named",
4095
+ line: getLineNumber(source, match.index),
4096
+ column: getColumnNumber(source, match.index)
4097
+ });
4098
+ }
4099
+ const reExportAllRegex = new RegExp(IMPORT_PATTERNS.reExportAll.source, "g");
4100
+ while ((match = reExportAllRegex.exec(source)) !== null) {
4101
+ const [statement, specifier] = match;
4102
+ addImport({
4103
+ statement,
4104
+ specifier,
4105
+ type: "namespace",
4106
+ line: getLineNumber(source, match.index),
4107
+ column: getColumnNumber(source, match.index)
4108
+ });
4109
+ }
4110
+ const externalImports = imports.filter((imp) => isExternalImport(imp.specifier));
4111
+ const relativeImports = imports.filter((imp) => isRelativeImport(imp.specifier));
4112
+ const externalPackages = [...new Set(externalImports.map((imp) => getPackageName(imp.specifier)))];
4113
+ return {
4114
+ imports,
4115
+ externalImports,
4116
+ relativeImports,
4117
+ externalPackages
4118
+ };
4119
+ }
4120
+
4121
+ // libs/ui/src/dependency/import-map.ts
4122
+ function createImportMap(dependencies) {
4123
+ const imports = {};
4124
+ const integrity = {};
4125
+ for (const dep of dependencies) {
4126
+ imports[dep.packageName] = dep.cdnUrl;
4127
+ if (dep.integrity) {
4128
+ integrity[dep.cdnUrl] = dep.integrity;
4129
+ }
4130
+ }
4131
+ return {
4132
+ imports,
4133
+ integrity: Object.keys(integrity).length > 0 ? integrity : void 0
4134
+ };
4135
+ }
4136
+ function generateImportMapScriptTag(map) {
4137
+ const json = JSON.stringify(map, null, 2);
4138
+ return `<script type="importmap">
4139
+ ${json}
4140
+ </script>`;
4141
+ }
4142
+ function generateImportMapScriptTagMinified(map) {
4143
+ const json = JSON.stringify(map);
4144
+ return `<script type="importmap">${json}</script>`;
4145
+ }
4146
+ function generateUMDShim(dependencies, options = {}) {
4147
+ const { safe = true, minify = false } = options;
4148
+ const depsWithGlobals = dependencies.filter((d) => d.global && !d.esm);
4149
+ if (depsWithGlobals.length === 0) {
4150
+ return "";
4151
+ }
4152
+ const entries = depsWithGlobals.map((dep) => {
4153
+ const global = dep.global;
4154
+ return `'${dep.packageName}': { default: window.${global}, ...window.${global} }`;
4155
+ });
4156
+ const shimObject = `{
4157
+ ${entries.join(",\n ")}
4158
+ }`;
4159
+ const code = safe ? `(function() {
4160
+ try {
4161
+ window.__esm_shim = ${shimObject};
4162
+ } catch (e) {
4163
+ console.warn('UMD shim failed:', e);
4164
+ }
4165
+ })();` : `window.__esm_shim = ${shimObject};`;
4166
+ return minify ? code.replace(/\s+/g, " ").replace(/\s*([{},:])\s*/g, "$1") : code;
4167
+ }
4168
+ function generateCDNScriptTags(dependencies) {
4169
+ return dependencies.filter((dep) => !dep.esm).map((dep) => {
4170
+ const attrs = [`src="${escapeHtmlAttr(dep.cdnUrl)}"`];
4171
+ if (dep.integrity) {
4172
+ attrs.push(`integrity="${escapeHtmlAttr(dep.integrity)}"`);
4173
+ }
4174
+ attrs.push('crossorigin="anonymous"');
4175
+ return `<script ${attrs.join(" ")}></script>`;
4176
+ });
4177
+ }
4178
+ function generateESMScriptTags(dependencies) {
4179
+ return dependencies.filter((dep) => dep.esm).map((dep) => {
4180
+ const attrs = ['type="module"', `src="${escapeHtmlAttr(dep.cdnUrl)}"`];
4181
+ if (dep.integrity) {
4182
+ attrs.push(`integrity="${escapeHtmlAttr(dep.integrity)}"`);
4183
+ }
4184
+ attrs.push('crossorigin="anonymous"');
4185
+ return `<script ${attrs.join(" ")}></script>`;
4186
+ });
4187
+ }
4188
+ function generateDependencyHTML(dependencies, options = {}) {
4189
+ const { minify = false, includeShim = true } = options;
4190
+ const parts = [];
4191
+ const importMap = createImportMap(dependencies);
4192
+ const importMapTag = minify ? generateImportMapScriptTagMinified(importMap) : generateImportMapScriptTag(importMap);
4193
+ parts.push(importMapTag);
4194
+ const umdTags = generateCDNScriptTags(dependencies);
4195
+ parts.push(...umdTags);
4196
+ if (includeShim) {
4197
+ const shim = generateUMDShim(dependencies, { minify });
4198
+ if (shim) {
4199
+ parts.push(`<script>${shim}</script>`);
4200
+ }
4201
+ }
4202
+ const esmTags = generateESMScriptTags(dependencies);
4203
+ parts.push(...esmTags);
4204
+ return parts.join(minify ? "" : "\n");
4205
+ }
4206
+
4207
+ // libs/ui/src/dependency/resolver.ts
4208
+ var DependencyResolutionError = class extends Error {
4209
+ constructor(packageName, reason) {
4210
+ super(`Failed to resolve dependency "${packageName}": ${reason}`);
4211
+ this.packageName = packageName;
4212
+ this.reason = reason;
4213
+ this.name = "DependencyResolutionError";
4214
+ }
4215
+ };
4216
+ var NoProviderError = class extends DependencyResolutionError {
4217
+ constructor(packageName, platform) {
4218
+ super(packageName, `No CDN provider available for platform "${platform}"`);
4219
+ this.platform = platform;
4220
+ this.name = "NoProviderError";
4221
+ }
4222
+ };
4223
+ var DependencyResolver = class {
4224
+ options;
4225
+ registry;
4226
+ constructor(options = {}) {
4227
+ this.options = {
4228
+ platform: options.platform ?? "unknown",
4229
+ preferredProviders: options.preferredProviders ?? CDN_PROVIDER_PRIORITY[options.platform ?? "unknown"],
4230
+ customRegistry: options.customRegistry ?? {},
4231
+ strictMode: options.strictMode ?? true,
4232
+ requireIntegrity: options.requireIntegrity ?? false
4233
+ };
4234
+ this.registry = mergeRegistries(this.options.customRegistry);
4235
+ }
4236
+ /**
4237
+ * Resolve a single package to its CDN dependency.
4238
+ *
4239
+ * @param packageName - NPM package name
4240
+ * @param override - Optional explicit CDN dependency override
4241
+ * @returns Resolved dependency, or null in non-strict mode if package is not found (should be bundled)
4242
+ * @throws DependencyResolutionError if package cannot be resolved in strict mode
4243
+ */
4244
+ resolve(packageName, override) {
4245
+ if (override) {
4246
+ return this.createResolvedDependency(packageName, override, "custom");
4247
+ }
4248
+ const entry = lookupPackage(packageName, this.registry);
4249
+ if (!entry) {
4250
+ if (this.options.strictMode) {
4251
+ throw new DependencyResolutionError(
4252
+ packageName,
4253
+ 'Package not found in CDN registry. Add it to "dependencies" for explicit CDN configuration.'
4254
+ );
4255
+ }
4256
+ return null;
4257
+ }
4258
+ const providerPriority = this.options.preferredProviders;
4259
+ for (const provider of providerPriority) {
4260
+ const config = entry.providers[provider];
4261
+ if (config?.url) {
4262
+ if (this.options.requireIntegrity && !config.integrity) {
4263
+ continue;
4264
+ }
4265
+ return this.createResolvedDependency(packageName, config, provider, entry.defaultVersion);
4266
+ }
4267
+ }
4268
+ throw new NoProviderError(packageName, this.options.platform);
4269
+ }
4270
+ /**
4271
+ * Resolve multiple packages.
4272
+ *
4273
+ * @param packageNames - Array of package names
4274
+ * @param overrides - Optional explicit overrides for specific packages
4275
+ * @returns Array of resolved dependencies (in dependency order)
4276
+ */
4277
+ resolveMany(packageNames, overrides) {
4278
+ const allPackages = resolveAllDependencies(packageNames, this.options.platform, this.registry);
4279
+ const resolved = [];
4280
+ for (const pkgName of allPackages) {
4281
+ try {
4282
+ const override = overrides?.[pkgName];
4283
+ const dep = this.resolve(pkgName, override);
4284
+ if (dep) {
4285
+ resolved.push(dep);
4286
+ }
4287
+ } catch (error) {
4288
+ if (this.options.strictMode) {
4289
+ throw error;
4290
+ }
4291
+ }
4292
+ }
4293
+ return resolved;
4294
+ }
4295
+ /**
4296
+ * Resolve dependencies from source code.
4297
+ *
4298
+ * Parses the source to extract imports, then resolves external packages
4299
+ * that are in the externals list.
4300
+ *
4301
+ * @param source - Source code to parse
4302
+ * @param externals - Package names to resolve from CDN (others are bundled)
4303
+ * @param overrides - Optional explicit CDN overrides
4304
+ * @returns Resolved dependencies
4305
+ */
4306
+ resolveFromSource(source, externals, overrides) {
4307
+ const parseResult = parseImports(source);
4308
+ const packagesToResolve = parseResult.externalPackages.filter((pkg) => externals.includes(pkg));
4309
+ return this.resolveMany(packagesToResolve, overrides);
4310
+ }
4311
+ /**
4312
+ * Generate an import map for resolved dependencies.
4313
+ *
4314
+ * @param dependencies - Resolved dependencies
4315
+ * @returns Browser import map
4316
+ */
4317
+ generateImportMap(dependencies) {
4318
+ return createImportMap(dependencies);
4319
+ }
4320
+ /**
4321
+ * Check if a package can be resolved for the current platform.
4322
+ *
4323
+ * @param packageName - Package name to check
4324
+ * @returns true if the package can be resolved
4325
+ */
4326
+ canResolve(packageName) {
4327
+ try {
4328
+ const result = this.resolve(packageName);
4329
+ return result !== null;
4330
+ } catch {
4331
+ return false;
4332
+ }
4333
+ }
4334
+ /**
4335
+ * Get the resolved CDN URL for a package.
4336
+ *
4337
+ * @param packageName - Package name
4338
+ * @param override - Optional explicit override
4339
+ * @returns CDN URL or undefined if cannot resolve
4340
+ */
4341
+ getUrl(packageName, override) {
4342
+ try {
4343
+ const resolved = this.resolve(packageName, override);
4344
+ return resolved?.cdnUrl;
4345
+ } catch {
4346
+ return void 0;
4347
+ }
4348
+ }
4349
+ /**
4350
+ * Get peer dependencies for a package.
4351
+ */
4352
+ getPeerDependencies(packageName) {
4353
+ return getPackagePeerDependencies(packageName, this.registry);
4354
+ }
4355
+ /**
4356
+ * Create the current registry (default + custom).
4357
+ */
4358
+ getRegistry() {
4359
+ return this.registry;
4360
+ }
4361
+ /**
4362
+ * Get the current platform.
4363
+ */
4364
+ getPlatform() {
4365
+ return this.options.platform;
4366
+ }
4367
+ /**
4368
+ * Create a resolved dependency object.
4369
+ */
4370
+ createResolvedDependency(packageName, config, provider, version) {
4371
+ return {
4372
+ packageName,
4373
+ version: version ?? this.extractVersionFromUrl(config.url) ?? "latest",
4374
+ cdnUrl: config.url,
4375
+ integrity: config.integrity,
4376
+ global: config.global,
4377
+ esm: config.esm ?? false,
4378
+ provider
4379
+ };
4380
+ }
4381
+ /**
4382
+ * Try to extract version from CDN URL.
4383
+ */
4384
+ extractVersionFromUrl(url) {
4385
+ const versionMatch = url.match(/@(\d+\.\d+\.\d+(?:-[\w.]+)?)/);
4386
+ if (versionMatch) {
4387
+ return versionMatch[1];
4388
+ }
4389
+ const versionMatch2 = url.match(/\/v?(\d+\.\d+\.\d+)\//);
4390
+ if (versionMatch2) {
4391
+ return versionMatch2[1];
4392
+ }
4393
+ return void 0;
4394
+ }
4395
+ };
4396
+
4397
+ // libs/ui/src/bundler/file-cache/component-builder.ts
4398
+ var ComponentBuilder = class {
4399
+ storage;
4400
+ esbuild = null;
4401
+ constructor(storage) {
4402
+ this.storage = storage;
4403
+ }
4404
+ /**
4405
+ * Build a component from a file path.
4406
+ */
4407
+ async build(options) {
4408
+ const startTime = performance.now();
4409
+ const {
4410
+ entryPath,
4411
+ toolName,
4412
+ externals = [],
4413
+ dependencies = {},
4414
+ bundleOptions = {},
4415
+ platform = "unknown",
4416
+ skipCache = false,
4417
+ ssr = false,
4418
+ ssrContext = {},
4419
+ executeCode: executeCode3
4420
+ } = options;
4421
+ const absoluteEntryPath = resolve2(entryPath);
4422
+ if (!existsSync3(absoluteEntryPath)) {
4423
+ throw new Error(`Entry file not found: ${absoluteEntryPath}`);
4424
+ }
4425
+ const hashResult = await calculateComponentHash({
4426
+ entryPath: absoluteEntryPath,
4427
+ externals,
4428
+ dependencies,
4429
+ bundleOptions
4430
+ });
4431
+ if (!skipCache) {
4432
+ const cached = await this.storage.get(hashResult.hash);
4433
+ if (cached) {
4434
+ return {
4435
+ manifest: cached,
4436
+ cached: true,
4437
+ buildTimeMs: performance.now() - startTime
4438
+ };
4439
+ }
4440
+ }
4441
+ const source = await readFile3(absoluteEntryPath, "utf8");
4442
+ const resolver = new DependencyResolver({ platform });
4443
+ const resolvedDeps = [];
4444
+ for (const pkg of externals) {
4445
+ try {
4446
+ const override = dependencies[pkg];
4447
+ const resolved = resolver.resolve(pkg, override);
4448
+ if (resolved) {
4449
+ resolvedDeps.push(resolved);
4450
+ }
4451
+ } catch (error) {
4452
+ console.warn(`Failed to resolve external "${pkg}": ${error}`);
4453
+ }
4454
+ }
4455
+ const allExternals = new Set(externals);
4456
+ for (const dep of resolvedDeps) {
4457
+ const entry = resolver.getRegistry()[dep.packageName];
4458
+ if (entry?.providers) {
4459
+ const providerConfig = Object.values(entry.providers)[0];
4460
+ if (providerConfig?.peerDependencies) {
4461
+ for (const peer of providerConfig.peerDependencies) {
4462
+ if (!allExternals.has(peer)) {
4463
+ allExternals.add(peer);
4464
+ try {
4465
+ const peerOverride = dependencies[peer];
4466
+ const resolved = resolver.resolve(peer, peerOverride);
4467
+ if (resolved) {
4468
+ resolvedDeps.push(resolved);
4469
+ }
4470
+ } catch {
4471
+ }
4472
+ }
4473
+ }
4474
+ }
4475
+ }
4476
+ }
4477
+ const importMap = createImportMap(resolvedDeps);
4478
+ const bundleResult = await this.bundleComponent({
4479
+ source,
4480
+ entryPath: absoluteEntryPath,
4481
+ externals: Array.from(allExternals),
4482
+ bundleOptions
4483
+ });
4484
+ let ssrHtml;
4485
+ if (ssr) {
4486
+ ssrHtml = await this.renderSSR(bundleResult.code, ssrContext, resolvedDeps, executeCode3);
4487
+ }
4488
+ const manifest = {
4489
+ version: "1.0",
4490
+ buildId: randomUUID(),
4491
+ toolName,
4492
+ entryPath: absoluteEntryPath,
4493
+ contentHash: hashResult.hash,
4494
+ dependencies: resolvedDeps,
4495
+ outputs: {
4496
+ code: bundleResult.code,
4497
+ sourceMap: bundleResult.map,
4498
+ ssrHtml
4499
+ },
4500
+ importMap,
4501
+ metadata: {
4502
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
4503
+ buildTimeMs: performance.now() - startTime,
4504
+ totalSize: Buffer.byteLength(bundleResult.code, "utf8"),
4505
+ bundlerVersion: bundleResult.bundlerVersion
4506
+ }
4507
+ };
4508
+ await this.storage.set(hashResult.hash, manifest);
4509
+ return {
4510
+ manifest,
4511
+ cached: false,
4512
+ buildTimeMs: performance.now() - startTime
4513
+ };
4514
+ }
4515
+ /**
4516
+ * Build multiple components.
4517
+ */
4518
+ async buildMany(options) {
4519
+ return Promise.all(options.map((opt) => this.build(opt)));
4520
+ }
4521
+ /**
4522
+ * Check if a component needs rebuilding.
4523
+ */
4524
+ async needsRebuild(options) {
4525
+ const absoluteEntryPath = resolve2(options.entryPath);
4526
+ const hashResult = await calculateComponentHash({
4527
+ entryPath: absoluteEntryPath,
4528
+ externals: options.externals,
4529
+ dependencies: options.dependencies,
4530
+ bundleOptions: options.bundleOptions
4531
+ });
4532
+ const cached = await this.storage.has(hashResult.hash);
4533
+ return !cached;
4534
+ }
4535
+ /**
4536
+ * Get a cached build if it exists.
4537
+ */
4538
+ async getCached(options) {
4539
+ const absoluteEntryPath = resolve2(options.entryPath);
4540
+ const hashResult = await calculateComponentHash({
4541
+ entryPath: absoluteEntryPath,
4542
+ externals: options.externals,
4543
+ dependencies: options.dependencies,
4544
+ bundleOptions: options.bundleOptions
4545
+ });
4546
+ return this.storage.get(hashResult.hash);
4547
+ }
4548
+ /**
4549
+ * Invalidate a cached build.
4550
+ */
4551
+ async invalidate(contentHash) {
4552
+ return this.storage.delete(contentHash);
4553
+ }
4554
+ /**
4555
+ * Generate complete HTML for a built component.
4556
+ */
4557
+ generateHTML(manifest, minify = false) {
4558
+ const parts = [];
4559
+ const dependencyHtml = generateDependencyHTML(manifest.dependencies, { minify });
4560
+ parts.push(dependencyHtml);
4561
+ parts.push(`<script type="module">${manifest.outputs.code}</script>`);
4562
+ return parts.join(minify ? "" : "\n");
4563
+ }
4564
+ /**
4565
+ * Bundle a component using esbuild.
4566
+ */
4567
+ async bundleComponent(options) {
4568
+ const { source, entryPath, externals, bundleOptions } = options;
4569
+ if (!this.esbuild) {
4570
+ try {
4571
+ this.esbuild = await import("esbuild");
4572
+ } catch {
4573
+ throw new Error("esbuild is required for component building. Install with: npm install esbuild");
4574
+ }
4575
+ }
4576
+ const ext = extname(entryPath).toLowerCase();
4577
+ const loader = ext === ".tsx" ? "tsx" : ext === ".ts" ? "ts" : ext === ".jsx" ? "jsx" : "js";
4578
+ try {
4579
+ const result = await this.esbuild.transform(source, {
4580
+ loader,
4581
+ format: "esm",
4582
+ minify: bundleOptions.minify ?? process.env["NODE_ENV"] === "production",
4583
+ sourcemap: bundleOptions.sourceMaps ? "inline" : false,
4584
+ target: bundleOptions.target ?? "es2020",
4585
+ treeShaking: bundleOptions.treeShake ?? true,
4586
+ jsx: "automatic",
4587
+ jsxImportSource: bundleOptions.jsxImportSource ?? "react",
4588
+ // Mark externals for later import map resolution
4589
+ banner: externals.length > 0 ? `/* externals: ${externals.join(", ")} */` : void 0
4590
+ });
4591
+ return {
4592
+ code: result.code,
4593
+ map: result.map || void 0,
4594
+ bundlerVersion: this.esbuild.version
4595
+ };
4596
+ } catch (error) {
4597
+ throw new Error(`Bundle failed for ${entryPath}: ${error}`);
4598
+ }
4599
+ }
4600
+ /**
4601
+ * Perform server-side rendering.
4602
+ */
4603
+ async renderSSR(code, context, dependencies, executeCode3) {
4604
+ const hasReact = dependencies.some((d) => d.packageName === "react");
4605
+ if (!hasReact) {
4606
+ console.warn("SSR requires React as an external dependency");
4607
+ return void 0;
4608
+ }
4609
+ try {
4610
+ const React = await import("react");
4611
+ const ReactDOMServer = await import("react-dom/server");
4612
+ const exports = {};
4613
+ const module = { exports };
4614
+ if (executeCode3) {
4615
+ executeCode3(code, exports, module, React);
4616
+ } else {
4617
+ const fn = new Function("exports", "module", "React", code);
4618
+ fn(exports, module, React);
4619
+ }
4620
+ const Component = module.exports.default || module.exports;
4621
+ if (typeof Component !== "function") {
4622
+ console.warn("SSR: No default component export found");
4623
+ return void 0;
4624
+ }
4625
+ const element = React.createElement(Component, context);
4626
+ return ReactDOMServer.renderToString(element);
4627
+ } catch (error) {
4628
+ console.warn(`SSR failed: ${error}`);
4629
+ return void 0;
4630
+ }
4631
+ }
4632
+ };
4633
+ async function createFilesystemBuilder(cacheDir = ".frontmcp-cache/builds") {
4634
+ const { FilesystemStorage: FilesystemStorage2 } = await Promise.resolve().then(() => (init_filesystem(), filesystem_exports));
4635
+ const storage = new FilesystemStorage2({ cacheDir });
4636
+ await storage.initialize();
4637
+ return new ComponentBuilder(storage);
4638
+ }
4639
+ async function createRedisBuilder(redisClient, keyPrefix = "frontmcp:ui:build:") {
4640
+ const { RedisStorage: RedisStorage2 } = await Promise.resolve().then(() => (init_redis(), redis_exports));
4641
+ const storage = new RedisStorage2({
4642
+ client: redisClient,
4643
+ keyPrefix
4644
+ });
4645
+ await storage.initialize();
4646
+ return new ComponentBuilder(storage);
4647
+ }
4648
+ export {
4649
+ BundlerCache,
4650
+ ComponentBuilder,
4651
+ DEFAULT_BUNDLER_OPTIONS,
4652
+ DEFAULT_BUNDLE_OPTIONS,
4653
+ DEFAULT_SECURITY_POLICY,
4654
+ DEFAULT_STATIC_HTML_OPTIONS,
4655
+ DEFAULT_STORAGE_OPTIONS,
4656
+ ExecutionError,
4657
+ FilesystemStorage,
4658
+ InMemoryBundler,
4659
+ RedisStorage,
4660
+ STATIC_HTML_CDN,
4661
+ SecurityError,
4662
+ buildIdFromHash,
4663
+ calculateComponentHash,
4664
+ calculateManifestSize,
4665
+ calculateQuickHash,
4666
+ createBundler,
4667
+ createCacheKey,
4668
+ createFilesystemBuilder,
4669
+ createFilesystemStorage,
4670
+ createRedisBuilder,
4671
+ createRedisStorage,
4672
+ executeCode,
4673
+ executeDefault,
4674
+ generateBuildId,
4675
+ getCdnTypeForPlatform,
4676
+ hashContent,
4677
+ hashFile,
4678
+ hashFiles,
4679
+ isExecutionError,
4680
+ mergePolicy,
4681
+ sha256,
4682
+ sha256Buffer,
4683
+ throwOnViolations,
4684
+ validateImports,
4685
+ validateSize,
4686
+ validateSource
4687
+ };