@frontmcp/ui 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (445) hide show
  1. package/README.md +140 -362
  2. package/bridge/runtime/index.d.ts +2 -1
  3. package/bridge/runtime/index.d.ts.map +1 -1
  4. package/bundler/file-cache/component-builder.d.ts +1 -1
  5. package/bundler/file-cache/component-builder.d.ts.map +1 -1
  6. package/bundler/file-cache/hash-calculator.d.ts +1 -1
  7. package/bundler/file-cache/hash-calculator.d.ts.map +1 -1
  8. package/bundler/file-cache/storage/filesystem.d.ts +1 -1
  9. package/bundler/file-cache/storage/filesystem.d.ts.map +1 -1
  10. package/bundler/file-cache/storage/interface.d.ts +1 -1
  11. package/bundler/file-cache/storage/interface.d.ts.map +1 -1
  12. package/bundler/file-cache/storage/redis.d.ts +1 -1
  13. package/bundler/file-cache/storage/redis.d.ts.map +1 -1
  14. package/bundler/index.js +10 -1057
  15. package/components/alert.schema.d.ts +6 -6
  16. package/components/avatar.schema.d.ts +9 -9
  17. package/components/badge.schema.d.ts +9 -9
  18. package/components/button.schema.d.ts +9 -9
  19. package/components/card.schema.d.ts +7 -7
  20. package/components/form.schema.d.ts +24 -24
  21. package/components/index.js +128 -198
  22. package/components/modal.schema.d.ts +8 -8
  23. package/components/table.schema.d.ts +6 -6
  24. package/esm/bridge/runtime/index.d.ts +2 -1
  25. package/esm/bridge/runtime/index.d.ts.map +1 -1
  26. package/esm/bundler/file-cache/component-builder.d.ts +1 -1
  27. package/esm/bundler/file-cache/component-builder.d.ts.map +1 -1
  28. package/esm/bundler/file-cache/hash-calculator.d.ts +1 -1
  29. package/esm/bundler/file-cache/hash-calculator.d.ts.map +1 -1
  30. package/esm/bundler/file-cache/storage/filesystem.d.ts +1 -1
  31. package/esm/bundler/file-cache/storage/filesystem.d.ts.map +1 -1
  32. package/esm/bundler/file-cache/storage/interface.d.ts +1 -1
  33. package/esm/bundler/file-cache/storage/interface.d.ts.map +1 -1
  34. package/esm/bundler/file-cache/storage/redis.d.ts +1 -1
  35. package/esm/bundler/file-cache/storage/redis.d.ts.map +1 -1
  36. package/esm/bundler/index.js +3 -1050
  37. package/esm/components/alert.schema.d.ts +6 -6
  38. package/esm/components/avatar.schema.d.ts +9 -9
  39. package/esm/components/badge.schema.d.ts +9 -9
  40. package/esm/components/button.schema.d.ts +9 -9
  41. package/esm/components/card.schema.d.ts +7 -7
  42. package/esm/components/form.schema.d.ts +24 -24
  43. package/esm/components/index.js +136 -196
  44. package/esm/components/modal.schema.d.ts +8 -8
  45. package/esm/components/table.schema.d.ts +6 -6
  46. package/esm/index.d.ts +23 -39
  47. package/esm/index.d.ts.map +1 -1
  48. package/esm/index.js +4256 -16441
  49. package/esm/layouts/base.d.ts +2 -2
  50. package/esm/layouts/base.d.ts.map +1 -1
  51. package/esm/layouts/index.js +33 -516
  52. package/esm/package.json +8 -26
  53. package/esm/pages/index.js +100 -627
  54. package/esm/react/Alert.d.ts +1 -2
  55. package/esm/react/Alert.d.ts.map +1 -1
  56. package/esm/react/Badge.d.ts +1 -2
  57. package/esm/react/Badge.d.ts.map +1 -1
  58. package/esm/react/Button.d.ts +1 -2
  59. package/esm/react/Button.d.ts.map +1 -1
  60. package/esm/react/Card.d.ts +1 -2
  61. package/esm/react/Card.d.ts.map +1 -1
  62. package/esm/react/hooks/context.d.ts +1 -1
  63. package/esm/react/hooks/context.d.ts.map +1 -1
  64. package/esm/react/index.d.ts +5 -6
  65. package/esm/react/index.d.ts.map +1 -1
  66. package/esm/react/index.js +2074 -322
  67. package/esm/react/types.d.ts +1 -2
  68. package/esm/react/types.d.ts.map +1 -1
  69. package/esm/renderers/index.d.ts +10 -25
  70. package/esm/renderers/index.d.ts.map +1 -1
  71. package/esm/renderers/index.js +171 -1617
  72. package/esm/{runtime/adapters → renderers}/react.adapter.d.ts +2 -2
  73. package/esm/renderers/react.adapter.d.ts.map +1 -0
  74. package/esm/renderers/react.renderer.d.ts +3 -3
  75. package/esm/renderers/react.renderer.d.ts.map +1 -1
  76. package/esm/universal/index.js +1755 -0
  77. package/esm/web-components/index.js +232 -287
  78. package/esm/widgets/index.js +89 -147
  79. package/index.d.ts +23 -39
  80. package/index.d.ts.map +1 -1
  81. package/index.js +6123 -18539
  82. package/layouts/base.d.ts +2 -2
  83. package/layouts/base.d.ts.map +1 -1
  84. package/layouts/index.js +43 -536
  85. package/package.json +8 -26
  86. package/pages/index.js +111 -648
  87. package/react/Alert.d.ts +1 -2
  88. package/react/Alert.d.ts.map +1 -1
  89. package/react/Badge.d.ts +1 -2
  90. package/react/Badge.d.ts.map +1 -1
  91. package/react/Button.d.ts +1 -2
  92. package/react/Button.d.ts.map +1 -1
  93. package/react/Card.d.ts +1 -2
  94. package/react/Card.d.ts.map +1 -1
  95. package/react/hooks/context.d.ts +1 -1
  96. package/react/hooks/context.d.ts.map +1 -1
  97. package/react/index.d.ts +5 -6
  98. package/react/index.d.ts.map +1 -1
  99. package/react/index.js +2065 -335
  100. package/react/types.d.ts +1 -2
  101. package/react/types.d.ts.map +1 -1
  102. package/renderers/index.d.ts +10 -25
  103. package/renderers/index.d.ts.map +1 -1
  104. package/renderers/index.js +175 -1641
  105. package/{runtime/adapters → renderers}/react.adapter.d.ts +2 -2
  106. package/renderers/react.adapter.d.ts.map +1 -0
  107. package/renderers/react.renderer.d.ts +3 -3
  108. package/renderers/react.renderer.d.ts.map +1 -1
  109. package/universal/index.js +1841 -0
  110. package/web-components/index.js +224 -289
  111. package/widgets/index.js +80 -148
  112. package/adapters/index.d.ts +0 -13
  113. package/adapters/index.d.ts.map +0 -1
  114. package/adapters/index.js +0 -462
  115. package/adapters/platform-meta.d.ts +0 -166
  116. package/adapters/platform-meta.d.ts.map +0 -1
  117. package/adapters/response-builder.d.ts +0 -108
  118. package/adapters/response-builder.d.ts.map +0 -1
  119. package/adapters/serving-mode.d.ts +0 -107
  120. package/adapters/serving-mode.d.ts.map +0 -1
  121. package/base-template/bridge.d.ts +0 -90
  122. package/base-template/bridge.d.ts.map +0 -1
  123. package/base-template/default-base-template.d.ts +0 -92
  124. package/base-template/default-base-template.d.ts.map +0 -1
  125. package/base-template/index.d.ts +0 -15
  126. package/base-template/index.d.ts.map +0 -1
  127. package/base-template/index.js +0 -1398
  128. package/base-template/polyfills.d.ts +0 -31
  129. package/base-template/polyfills.d.ts.map +0 -1
  130. package/base-template/theme-styles.d.ts +0 -74
  131. package/base-template/theme-styles.d.ts.map +0 -1
  132. package/build/cdn-resources.d.ts +0 -243
  133. package/build/cdn-resources.d.ts.map +0 -1
  134. package/build/index.d.ts +0 -295
  135. package/build/index.d.ts.map +0 -1
  136. package/build/index.js +0 -7096
  137. package/build/widget-manifest.d.ts +0 -362
  138. package/build/widget-manifest.d.ts.map +0 -1
  139. package/dependency/cdn-registry.d.ts +0 -98
  140. package/dependency/cdn-registry.d.ts.map +0 -1
  141. package/dependency/import-map.d.ts +0 -186
  142. package/dependency/import-map.d.ts.map +0 -1
  143. package/dependency/import-parser.d.ts +0 -82
  144. package/dependency/import-parser.d.ts.map +0 -1
  145. package/dependency/index.d.ts +0 -17
  146. package/dependency/index.d.ts.map +0 -1
  147. package/dependency/resolver.d.ts +0 -164
  148. package/dependency/resolver.d.ts.map +0 -1
  149. package/dependency/schemas.d.ts +0 -486
  150. package/dependency/schemas.d.ts.map +0 -1
  151. package/dependency/template-loader.d.ts +0 -204
  152. package/dependency/template-loader.d.ts.map +0 -1
  153. package/dependency/template-processor.d.ts +0 -118
  154. package/dependency/template-processor.d.ts.map +0 -1
  155. package/dependency/types.d.ts +0 -739
  156. package/dependency/types.d.ts.map +0 -1
  157. package/esm/adapters/index.d.ts +0 -13
  158. package/esm/adapters/index.d.ts.map +0 -1
  159. package/esm/adapters/index.js +0 -427
  160. package/esm/adapters/platform-meta.d.ts +0 -166
  161. package/esm/adapters/platform-meta.d.ts.map +0 -1
  162. package/esm/adapters/response-builder.d.ts +0 -108
  163. package/esm/adapters/response-builder.d.ts.map +0 -1
  164. package/esm/adapters/serving-mode.d.ts +0 -107
  165. package/esm/adapters/serving-mode.d.ts.map +0 -1
  166. package/esm/base-template/bridge.d.ts +0 -90
  167. package/esm/base-template/bridge.d.ts.map +0 -1
  168. package/esm/base-template/default-base-template.d.ts +0 -92
  169. package/esm/base-template/default-base-template.d.ts.map +0 -1
  170. package/esm/base-template/index.d.ts +0 -15
  171. package/esm/base-template/index.d.ts.map +0 -1
  172. package/esm/base-template/index.js +0 -1364
  173. package/esm/base-template/polyfills.d.ts +0 -31
  174. package/esm/base-template/polyfills.d.ts.map +0 -1
  175. package/esm/base-template/theme-styles.d.ts +0 -74
  176. package/esm/base-template/theme-styles.d.ts.map +0 -1
  177. package/esm/build/cdn-resources.d.ts +0 -243
  178. package/esm/build/cdn-resources.d.ts.map +0 -1
  179. package/esm/build/index.d.ts +0 -295
  180. package/esm/build/index.d.ts.map +0 -1
  181. package/esm/build/index.js +0 -7021
  182. package/esm/build/widget-manifest.d.ts +0 -362
  183. package/esm/build/widget-manifest.d.ts.map +0 -1
  184. package/esm/dependency/cdn-registry.d.ts +0 -98
  185. package/esm/dependency/cdn-registry.d.ts.map +0 -1
  186. package/esm/dependency/import-map.d.ts +0 -186
  187. package/esm/dependency/import-map.d.ts.map +0 -1
  188. package/esm/dependency/import-parser.d.ts +0 -82
  189. package/esm/dependency/import-parser.d.ts.map +0 -1
  190. package/esm/dependency/index.d.ts +0 -17
  191. package/esm/dependency/index.d.ts.map +0 -1
  192. package/esm/dependency/resolver.d.ts +0 -164
  193. package/esm/dependency/resolver.d.ts.map +0 -1
  194. package/esm/dependency/schemas.d.ts +0 -486
  195. package/esm/dependency/schemas.d.ts.map +0 -1
  196. package/esm/dependency/template-loader.d.ts +0 -204
  197. package/esm/dependency/template-loader.d.ts.map +0 -1
  198. package/esm/dependency/template-processor.d.ts +0 -118
  199. package/esm/dependency/template-processor.d.ts.map +0 -1
  200. package/esm/dependency/types.d.ts +0 -739
  201. package/esm/dependency/types.d.ts.map +0 -1
  202. package/esm/handlebars/expression-extractor.d.ts +0 -147
  203. package/esm/handlebars/expression-extractor.d.ts.map +0 -1
  204. package/esm/handlebars/helpers.d.ts +0 -339
  205. package/esm/handlebars/helpers.d.ts.map +0 -1
  206. package/esm/handlebars/index.d.ts +0 -195
  207. package/esm/handlebars/index.d.ts.map +0 -1
  208. package/esm/handlebars/index.js +0 -587
  209. package/esm/registry/index.d.ts +0 -46
  210. package/esm/registry/index.d.ts.map +0 -1
  211. package/esm/registry/index.js +0 -6422
  212. package/esm/registry/render-template.d.ts +0 -91
  213. package/esm/registry/render-template.d.ts.map +0 -1
  214. package/esm/registry/tool-ui.registry.d.ts +0 -294
  215. package/esm/registry/tool-ui.registry.d.ts.map +0 -1
  216. package/esm/registry/uri-utils.d.ts +0 -56
  217. package/esm/registry/uri-utils.d.ts.map +0 -1
  218. package/esm/renderers/cache.d.ts +0 -145
  219. package/esm/renderers/cache.d.ts.map +0 -1
  220. package/esm/renderers/html.renderer.d.ts +0 -123
  221. package/esm/renderers/html.renderer.d.ts.map +0 -1
  222. package/esm/renderers/mdx.renderer.d.ts +0 -120
  223. package/esm/renderers/mdx.renderer.d.ts.map +0 -1
  224. package/esm/renderers/registry.d.ts +0 -134
  225. package/esm/renderers/registry.d.ts.map +0 -1
  226. package/esm/renderers/types.d.ts +0 -342
  227. package/esm/renderers/types.d.ts.map +0 -1
  228. package/esm/renderers/utils/detect.d.ts +0 -107
  229. package/esm/renderers/utils/detect.d.ts.map +0 -1
  230. package/esm/renderers/utils/hash.d.ts +0 -40
  231. package/esm/renderers/utils/hash.d.ts.map +0 -1
  232. package/esm/renderers/utils/index.d.ts +0 -9
  233. package/esm/renderers/utils/index.d.ts.map +0 -1
  234. package/esm/renderers/utils/transpiler.d.ts +0 -89
  235. package/esm/renderers/utils/transpiler.d.ts.map +0 -1
  236. package/esm/runtime/adapters/html.adapter.d.ts +0 -59
  237. package/esm/runtime/adapters/html.adapter.d.ts.map +0 -1
  238. package/esm/runtime/adapters/index.d.ts +0 -26
  239. package/esm/runtime/adapters/index.d.ts.map +0 -1
  240. package/esm/runtime/adapters/mdx.adapter.d.ts +0 -73
  241. package/esm/runtime/adapters/mdx.adapter.d.ts.map +0 -1
  242. package/esm/runtime/adapters/react.adapter.d.ts.map +0 -1
  243. package/esm/runtime/adapters/types.d.ts +0 -95
  244. package/esm/runtime/adapters/types.d.ts.map +0 -1
  245. package/esm/runtime/csp.d.ts +0 -48
  246. package/esm/runtime/csp.d.ts.map +0 -1
  247. package/esm/runtime/index.d.ts +0 -17
  248. package/esm/runtime/index.d.ts.map +0 -1
  249. package/esm/runtime/index.js +0 -5186
  250. package/esm/runtime/mcp-bridge.d.ts +0 -101
  251. package/esm/runtime/mcp-bridge.d.ts.map +0 -1
  252. package/esm/runtime/renderer-runtime.d.ts +0 -133
  253. package/esm/runtime/renderer-runtime.d.ts.map +0 -1
  254. package/esm/runtime/sanitizer.d.ts +0 -172
  255. package/esm/runtime/sanitizer.d.ts.map +0 -1
  256. package/esm/runtime/types.d.ts +0 -415
  257. package/esm/runtime/types.d.ts.map +0 -1
  258. package/esm/runtime/wrapper.d.ts +0 -421
  259. package/esm/runtime/wrapper.d.ts.map +0 -1
  260. package/esm/styles/index.d.ts +0 -8
  261. package/esm/styles/index.d.ts.map +0 -1
  262. package/esm/styles/index.js +0 -171
  263. package/esm/styles/variants.d.ts +0 -51
  264. package/esm/styles/variants.d.ts.map +0 -1
  265. package/esm/theme/cdn.d.ts +0 -195
  266. package/esm/theme/cdn.d.ts.map +0 -1
  267. package/esm/theme/index.d.ts +0 -18
  268. package/esm/theme/index.d.ts.map +0 -1
  269. package/esm/theme/index.js +0 -700
  270. package/esm/theme/platforms.d.ts +0 -107
  271. package/esm/theme/platforms.d.ts.map +0 -1
  272. package/esm/theme/presets/github-openai.d.ts +0 -50
  273. package/esm/theme/presets/github-openai.d.ts.map +0 -1
  274. package/esm/theme/presets/index.d.ts +0 -11
  275. package/esm/theme/presets/index.d.ts.map +0 -1
  276. package/esm/theme/theme.d.ts +0 -396
  277. package/esm/theme/theme.d.ts.map +0 -1
  278. package/esm/tool-template/builder.d.ts +0 -213
  279. package/esm/tool-template/builder.d.ts.map +0 -1
  280. package/esm/tool-template/index.d.ts +0 -16
  281. package/esm/tool-template/index.d.ts.map +0 -1
  282. package/esm/tool-template/index.js +0 -3515
  283. package/esm/types/index.d.ts +0 -14
  284. package/esm/types/index.d.ts.map +0 -1
  285. package/esm/types/index.js +0 -75
  286. package/esm/types/ui-config.d.ts +0 -639
  287. package/esm/types/ui-config.d.ts.map +0 -1
  288. package/esm/types/ui-runtime.d.ts +0 -1007
  289. package/esm/types/ui-runtime.d.ts.map +0 -1
  290. package/esm/typings/cache/cache-adapter.d.ts +0 -125
  291. package/esm/typings/cache/cache-adapter.d.ts.map +0 -1
  292. package/esm/typings/cache/index.d.ts +0 -10
  293. package/esm/typings/cache/index.d.ts.map +0 -1
  294. package/esm/typings/cache/memory-cache.d.ts +0 -92
  295. package/esm/typings/cache/memory-cache.d.ts.map +0 -1
  296. package/esm/typings/dts-parser.d.ts +0 -90
  297. package/esm/typings/dts-parser.d.ts.map +0 -1
  298. package/esm/typings/index.d.ts +0 -48
  299. package/esm/typings/index.d.ts.map +0 -1
  300. package/esm/typings/schemas.d.ts +0 -232
  301. package/esm/typings/schemas.d.ts.map +0 -1
  302. package/esm/typings/type-fetcher.d.ts +0 -89
  303. package/esm/typings/type-fetcher.d.ts.map +0 -1
  304. package/esm/typings/types.d.ts +0 -320
  305. package/esm/typings/types.d.ts.map +0 -1
  306. package/esm/utils/escape-html.d.ts +0 -58
  307. package/esm/utils/escape-html.d.ts.map +0 -1
  308. package/esm/utils/index.d.ts +0 -10
  309. package/esm/utils/index.d.ts.map +0 -1
  310. package/esm/utils/index.js +0 -40
  311. package/esm/utils/safe-stringify.d.ts +0 -30
  312. package/esm/utils/safe-stringify.d.ts.map +0 -1
  313. package/esm/validation/error-box.d.ts +0 -56
  314. package/esm/validation/error-box.d.ts.map +0 -1
  315. package/esm/validation/index.d.ts +0 -13
  316. package/esm/validation/index.d.ts.map +0 -1
  317. package/esm/validation/index.js +0 -562
  318. package/esm/validation/schema-paths.d.ts +0 -118
  319. package/esm/validation/schema-paths.d.ts.map +0 -1
  320. package/esm/validation/template-validator.d.ts +0 -143
  321. package/esm/validation/template-validator.d.ts.map +0 -1
  322. package/esm/validation/wrapper.d.ts +0 -97
  323. package/esm/validation/wrapper.d.ts.map +0 -1
  324. package/handlebars/expression-extractor.d.ts +0 -147
  325. package/handlebars/expression-extractor.d.ts.map +0 -1
  326. package/handlebars/helpers.d.ts +0 -339
  327. package/handlebars/helpers.d.ts.map +0 -1
  328. package/handlebars/index.d.ts +0 -195
  329. package/handlebars/index.d.ts.map +0 -1
  330. package/handlebars/index.js +0 -666
  331. package/registry/index.d.ts +0 -46
  332. package/registry/index.d.ts.map +0 -1
  333. package/registry/index.js +0 -6465
  334. package/registry/render-template.d.ts +0 -91
  335. package/registry/render-template.d.ts.map +0 -1
  336. package/registry/tool-ui.registry.d.ts +0 -294
  337. package/registry/tool-ui.registry.d.ts.map +0 -1
  338. package/registry/uri-utils.d.ts +0 -56
  339. package/registry/uri-utils.d.ts.map +0 -1
  340. package/renderers/cache.d.ts +0 -145
  341. package/renderers/cache.d.ts.map +0 -1
  342. package/renderers/html.renderer.d.ts +0 -123
  343. package/renderers/html.renderer.d.ts.map +0 -1
  344. package/renderers/mdx.renderer.d.ts +0 -120
  345. package/renderers/mdx.renderer.d.ts.map +0 -1
  346. package/renderers/registry.d.ts +0 -134
  347. package/renderers/registry.d.ts.map +0 -1
  348. package/renderers/types.d.ts +0 -342
  349. package/renderers/types.d.ts.map +0 -1
  350. package/renderers/utils/detect.d.ts +0 -107
  351. package/renderers/utils/detect.d.ts.map +0 -1
  352. package/renderers/utils/hash.d.ts +0 -40
  353. package/renderers/utils/hash.d.ts.map +0 -1
  354. package/renderers/utils/index.d.ts +0 -9
  355. package/renderers/utils/index.d.ts.map +0 -1
  356. package/renderers/utils/transpiler.d.ts +0 -89
  357. package/renderers/utils/transpiler.d.ts.map +0 -1
  358. package/runtime/adapters/html.adapter.d.ts +0 -59
  359. package/runtime/adapters/html.adapter.d.ts.map +0 -1
  360. package/runtime/adapters/index.d.ts +0 -26
  361. package/runtime/adapters/index.d.ts.map +0 -1
  362. package/runtime/adapters/mdx.adapter.d.ts +0 -73
  363. package/runtime/adapters/mdx.adapter.d.ts.map +0 -1
  364. package/runtime/adapters/react.adapter.d.ts.map +0 -1
  365. package/runtime/adapters/types.d.ts +0 -95
  366. package/runtime/adapters/types.d.ts.map +0 -1
  367. package/runtime/csp.d.ts +0 -48
  368. package/runtime/csp.d.ts.map +0 -1
  369. package/runtime/index.d.ts +0 -17
  370. package/runtime/index.d.ts.map +0 -1
  371. package/runtime/index.js +0 -5264
  372. package/runtime/mcp-bridge.d.ts +0 -101
  373. package/runtime/mcp-bridge.d.ts.map +0 -1
  374. package/runtime/renderer-runtime.d.ts +0 -133
  375. package/runtime/renderer-runtime.d.ts.map +0 -1
  376. package/runtime/sanitizer.d.ts +0 -172
  377. package/runtime/sanitizer.d.ts.map +0 -1
  378. package/runtime/types.d.ts +0 -415
  379. package/runtime/types.d.ts.map +0 -1
  380. package/runtime/wrapper.d.ts +0 -421
  381. package/runtime/wrapper.d.ts.map +0 -1
  382. package/styles/index.d.ts +0 -8
  383. package/styles/index.d.ts.map +0 -1
  384. package/styles/index.js +0 -222
  385. package/styles/variants.d.ts +0 -51
  386. package/styles/variants.d.ts.map +0 -1
  387. package/theme/cdn.d.ts +0 -195
  388. package/theme/cdn.d.ts.map +0 -1
  389. package/theme/index.d.ts +0 -18
  390. package/theme/index.d.ts.map +0 -1
  391. package/theme/index.js +0 -757
  392. package/theme/platforms.d.ts +0 -107
  393. package/theme/platforms.d.ts.map +0 -1
  394. package/theme/presets/github-openai.d.ts +0 -50
  395. package/theme/presets/github-openai.d.ts.map +0 -1
  396. package/theme/presets/index.d.ts +0 -11
  397. package/theme/presets/index.d.ts.map +0 -1
  398. package/theme/theme.d.ts +0 -396
  399. package/theme/theme.d.ts.map +0 -1
  400. package/tool-template/builder.d.ts +0 -213
  401. package/tool-template/builder.d.ts.map +0 -1
  402. package/tool-template/index.d.ts +0 -16
  403. package/tool-template/index.d.ts.map +0 -1
  404. package/tool-template/index.js +0 -3559
  405. package/types/index.d.ts +0 -14
  406. package/types/index.d.ts.map +0 -1
  407. package/types/index.js +0 -108
  408. package/types/ui-config.d.ts +0 -639
  409. package/types/ui-config.d.ts.map +0 -1
  410. package/types/ui-runtime.d.ts +0 -1007
  411. package/types/ui-runtime.d.ts.map +0 -1
  412. package/typings/cache/cache-adapter.d.ts +0 -125
  413. package/typings/cache/cache-adapter.d.ts.map +0 -1
  414. package/typings/cache/index.d.ts +0 -10
  415. package/typings/cache/index.d.ts.map +0 -1
  416. package/typings/cache/memory-cache.d.ts +0 -92
  417. package/typings/cache/memory-cache.d.ts.map +0 -1
  418. package/typings/dts-parser.d.ts +0 -90
  419. package/typings/dts-parser.d.ts.map +0 -1
  420. package/typings/index.d.ts +0 -48
  421. package/typings/index.d.ts.map +0 -1
  422. package/typings/schemas.d.ts +0 -232
  423. package/typings/schemas.d.ts.map +0 -1
  424. package/typings/type-fetcher.d.ts +0 -89
  425. package/typings/type-fetcher.d.ts.map +0 -1
  426. package/typings/types.d.ts +0 -320
  427. package/typings/types.d.ts.map +0 -1
  428. package/utils/escape-html.d.ts +0 -58
  429. package/utils/escape-html.d.ts.map +0 -1
  430. package/utils/index.d.ts +0 -10
  431. package/utils/index.d.ts.map +0 -1
  432. package/utils/index.js +0 -70
  433. package/utils/safe-stringify.d.ts +0 -30
  434. package/utils/safe-stringify.d.ts.map +0 -1
  435. package/validation/error-box.d.ts +0 -56
  436. package/validation/error-box.d.ts.map +0 -1
  437. package/validation/index.d.ts +0 -13
  438. package/validation/index.d.ts.map +0 -1
  439. package/validation/index.js +0 -603
  440. package/validation/schema-paths.d.ts +0 -118
  441. package/validation/schema-paths.d.ts.map +0 -1
  442. package/validation/template-validator.d.ts +0 -143
  443. package/validation/template-validator.d.ts.map +0 -1
  444. package/validation/wrapper.d.ts +0 -97
  445. package/validation/wrapper.d.ts.map +0 -1
@@ -1,1398 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // libs/ui/src/base-template/index.ts
21
- var base_template_exports = {};
22
- __export(base_template_exports, {
23
- BRIDGE_TYPES: () => BRIDGE_TYPES,
24
- createDefaultBaseTemplate: () => createDefaultBaseTemplate,
25
- createMinimalBaseTemplate: () => createMinimalBaseTemplate,
26
- renderBridgeScript: () => renderBridgeScript,
27
- renderMcpSessionPolyfill: () => renderMcpSessionPolyfill,
28
- renderMinimalThemeStyles: () => renderMinimalThemeStyles,
29
- renderThemeCssOnly: () => renderThemeCssOnly,
30
- renderThemeStyles: () => renderThemeStyles
31
- });
32
- module.exports = __toCommonJS(base_template_exports);
33
-
34
- // libs/ui/src/theme/cdn.ts
35
- var CDN = {
36
- /**
37
- * Tailwind CSS v4 Browser CDN
38
- * Generates styles on-the-fly with @theme support
39
- * @see https://tailwindcss.com/docs/installation/play-cdn
40
- */
41
- tailwind: "https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",
42
- /**
43
- * HTMX 2.x - High power tools for HTML
44
- * Enables AJAX, WebSockets, Server Sent Events directly in HTML
45
- * @see https://htmx.org
46
- */
47
- htmx: {
48
- url: "https://cdnjs.cloudflare.com/ajax/libs/htmx/2.0.7/htmx.min.js",
49
- integrity: "sha512-T6VLg/MJYMbLTmQ8VLvonbWg8VOvmDhXcOvHzCwo6ShdGuUU5SEcp1IAPXL4k9lVoMi8gRXl5K/S/zh43Y9rJA=="
50
- },
51
- /**
52
- * Alpine.js - Lightweight reactive framework
53
- * Used for more complex client-side interactions
54
- * @see https://alpinejs.dev
55
- */
56
- alpine: {
57
- url: "https://cdn.jsdelivr.net/npm/alpinejs@3.14.3/dist/cdn.min.js",
58
- integrity: "sha384-6zY8MFQJ/EqS1r4RJl+7j8rvZPuBWpT0RzWf+IFcKhxqUzQNmJzA1X1VEVZhYaEz"
59
- },
60
- /**
61
- * Google Fonts - Inter for modern UI typography
62
- */
63
- fonts: {
64
- preconnect: ["https://fonts.googleapis.com", "https://fonts.gstatic.com"],
65
- inter: "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap",
66
- mono: "https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&display=swap"
67
- },
68
- /**
69
- * Lucide Icons - Beautiful & consistent icons
70
- * @see https://lucide.dev
71
- */
72
- icons: {
73
- url: "https://cdn.jsdelivr.net/npm/lucide@0.294.0/dist/umd/lucide.min.js",
74
- integrity: "sha384-wpLmHb7v7V1LsEuTmPQ9tXqWZvTtRWWVqJuE+Yz6X0I6O2T6bHJVeXH1lVWqF4qE"
75
- }
76
- };
77
- var scriptCache = /* @__PURE__ */ new Map();
78
- function getCachedScript(url) {
79
- return scriptCache.get(url);
80
- }
81
- function isScriptCached(url) {
82
- return scriptCache.has(url);
83
- }
84
- function buildScriptTag(url, integrity, options = {}) {
85
- const attrs = [`src="${url}"`];
86
- if (integrity) {
87
- attrs.push(`integrity="${integrity}"`);
88
- attrs.push('crossorigin="anonymous"');
89
- }
90
- if (options.defer) attrs.push("defer");
91
- if (options.async) attrs.push("async");
92
- return `<script ${attrs.join(" ")}></script>`;
93
- }
94
- function buildInlineScriptTag(content) {
95
- return `<script>${content}</script>`;
96
- }
97
- function buildFontPreconnectFromTheme(theme) {
98
- const preconnect = theme.cdn?.fonts?.preconnect ?? CDN.fonts.preconnect;
99
- return preconnect.map((url, i) => `<link rel="preconnect" href="${url}"${i > 0 ? " crossorigin" : ""}>`).join("\n ");
100
- }
101
- function buildFontStylesheetsFromTheme(theme) {
102
- const stylesheets = theme.cdn?.fonts?.stylesheets ?? [CDN.fonts.inter];
103
- return stylesheets.map((url) => `<link href="${url}" rel="stylesheet">`).join("\n ");
104
- }
105
- function buildCdnScriptsFromTheme(theme, options = {}) {
106
- const { tailwind = true, htmx = true, alpine = false, icons = false, inline = false } = options;
107
- const scripts = [];
108
- const tailwindUrl = theme.cdn?.scripts?.tailwind ?? CDN.tailwind;
109
- const htmxConfig = theme.cdn?.scripts?.htmx ?? CDN.htmx;
110
- const alpineConfig = theme.cdn?.scripts?.alpine ?? CDN.alpine;
111
- const iconsConfig = theme.cdn?.icons?.script ?? CDN.icons;
112
- if (inline) {
113
- if (tailwind) {
114
- if (isScriptCached(tailwindUrl)) {
115
- scripts.push(buildInlineScriptTag(getCachedScript(tailwindUrl)));
116
- } else {
117
- console.warn(
118
- "[frontmcp/ui] Inline mode requested but Tailwind script not cached. Call fetchAndCacheScriptsFromTheme() first."
119
- );
120
- }
121
- }
122
- if (htmx) {
123
- if (isScriptCached(htmxConfig.url)) {
124
- scripts.push(buildInlineScriptTag(getCachedScript(htmxConfig.url)));
125
- } else {
126
- console.warn(
127
- "[frontmcp/ui] Inline mode requested but HTMX script not cached. Call fetchAndCacheScriptsFromTheme() first."
128
- );
129
- }
130
- }
131
- if (alpine) {
132
- if (isScriptCached(alpineConfig.url)) {
133
- scripts.push(buildInlineScriptTag(getCachedScript(alpineConfig.url)));
134
- } else {
135
- console.warn(
136
- "[frontmcp/ui] Inline mode requested but Alpine.js script not cached. Call fetchAndCacheScriptsFromTheme() first."
137
- );
138
- }
139
- }
140
- if (icons) {
141
- if (isScriptCached(iconsConfig.url)) {
142
- scripts.push(buildInlineScriptTag(getCachedScript(iconsConfig.url)));
143
- } else {
144
- console.warn(
145
- "[frontmcp/ui] Inline mode requested but icons script not cached. Call fetchAndCacheScriptsFromTheme() first."
146
- );
147
- }
148
- }
149
- } else {
150
- if (tailwind) {
151
- scripts.push(buildScriptTag(tailwindUrl));
152
- }
153
- if (htmx) {
154
- scripts.push(buildScriptTag(htmxConfig.url, htmxConfig.integrity));
155
- }
156
- if (alpine) {
157
- scripts.push(buildScriptTag(alpineConfig.url, alpineConfig.integrity, { defer: true }));
158
- }
159
- if (icons) {
160
- scripts.push(buildScriptTag(iconsConfig.url, iconsConfig.integrity));
161
- }
162
- }
163
- return scripts.join("\n ");
164
- }
165
-
166
- // libs/ui/src/theme/platforms.ts
167
- var CLAUDE_PLATFORM = {
168
- id: "claude",
169
- name: "Claude (Artifacts)",
170
- supportsWidgets: true,
171
- supportsTailwind: true,
172
- supportsHtmx: false,
173
- // Network blocked, HTMX won't work for API calls
174
- networkMode: "blocked",
175
- scriptStrategy: "inline",
176
- maxInlineSize: 100 * 1024,
177
- // 100KB limit for artifacts
178
- cspRestrictions: ["script-src 'unsafe-inline'", "connect-src 'none'"],
179
- options: {
180
- mode: "artifacts",
181
- framework: "react"
182
- // Claude artifacts prefer React
183
- }
184
- };
185
-
186
- // libs/ui/src/theme/presets/github-openai.ts
187
- var GITHUB_OPENAI_THEME = {
188
- name: "github-openai",
189
- colors: {
190
- semantic: {
191
- // Primary: Near-black for main actions and branding
192
- primary: "#24292f",
193
- // Secondary: Medium gray for secondary elements
194
- secondary: "#57606a",
195
- // Accent: Blue for links, focus states, and highlights
196
- accent: "#0969da",
197
- // Status colors
198
- success: "#1a7f37",
199
- // GitHub green
200
- warning: "#9a6700",
201
- // Amber warning
202
- danger: "#cf222e",
203
- // GitHub red
204
- info: "#0969da"
205
- // Blue info
206
- },
207
- surface: {
208
- // Pure white background
209
- background: "#ffffff",
210
- // Light gray surface (GitHub code background style)
211
- surface: "#f6f8fa",
212
- // White elevated surfaces (modals, cards)
213
- elevated: "#ffffff",
214
- // Dark semi-transparent overlay
215
- overlay: "rgba(27, 31, 36, 0.5)"
216
- },
217
- text: {
218
- // Near-black for primary text
219
- primary: "#24292f",
220
- // Gray for secondary/muted text
221
- secondary: "#57606a",
222
- // Light gray for disabled text
223
- disabled: "#8c959f",
224
- // White for text on dark backgrounds
225
- inverse: "#ffffff",
226
- // Blue for links
227
- link: "#0969da"
228
- },
229
- border: {
230
- // Light gray border (GitHub style)
231
- default: "#d0d7de",
232
- // Medium gray on hover
233
- hover: "#8c959f",
234
- // Blue focus ring
235
- focus: "#0969da",
236
- // Subtle divider
237
- divider: "#d8dee4"
238
- }
239
- },
240
- typography: {
241
- families: {
242
- // System UI font stack (GitHub/Apple style)
243
- sans: '-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"',
244
- // Monospace stack
245
- mono: 'ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, "Liberation Mono", monospace'
246
- },
247
- sizes: {
248
- xs: "0.75rem",
249
- // 12px
250
- sm: "0.875rem",
251
- // 14px
252
- base: "1rem",
253
- // 16px
254
- lg: "1.125rem",
255
- // 18px
256
- xl: "1.25rem",
257
- // 20px
258
- "2xl": "1.5rem",
259
- // 24px
260
- "3xl": "1.875rem",
261
- // 30px
262
- "4xl": "2.25rem"
263
- // 36px
264
- },
265
- weights: {
266
- normal: "400",
267
- medium: "500",
268
- semibold: "600",
269
- bold: "700"
270
- }
271
- },
272
- radius: {
273
- none: "0",
274
- sm: "3px",
275
- // GitHub uses smaller radii
276
- md: "6px",
277
- lg: "8px",
278
- xl: "12px",
279
- "2xl": "16px",
280
- full: "9999px"
281
- },
282
- shadows: {
283
- // Subtle shadows with gray tones
284
- sm: "0 1px 0 rgba(27, 31, 36, 0.04)",
285
- md: "0 3px 6px rgba(140, 149, 159, 0.15)",
286
- lg: "0 8px 24px rgba(140, 149, 159, 0.2)",
287
- xl: "0 12px 28px rgba(140, 149, 159, 0.3)"
288
- },
289
- components: {
290
- button: {
291
- radius: "6px",
292
- paddingX: "16px",
293
- paddingY: "5px",
294
- fontSize: "14px",
295
- fontWeight: "500"
296
- },
297
- card: {
298
- radius: "6px",
299
- padding: "16px",
300
- shadow: "0 1px 0 rgba(27, 31, 36, 0.04)",
301
- borderWidth: "1px"
302
- },
303
- input: {
304
- radius: "6px",
305
- paddingX: "12px",
306
- paddingY: "5px",
307
- borderWidth: "1px",
308
- focusRingWidth: "3px"
309
- }
310
- },
311
- cdn: {
312
- fonts: {
313
- preconnect: ["https://fonts.googleapis.com", "https://fonts.gstatic.com"],
314
- stylesheets: [
315
- // System UI fonts don't need external stylesheets, but we include
316
- // Inter as an optional enhancement for consistent cross-platform rendering
317
- "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap"
318
- ]
319
- },
320
- icons: {
321
- script: {
322
- url: "https://cdn.jsdelivr.net/npm/lucide@0.294.0/dist/umd/lucide.min.js"
323
- }
324
- },
325
- scripts: {
326
- tailwind: "https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",
327
- htmx: {
328
- url: "https://cdnjs.cloudflare.com/ajax/libs/htmx/2.0.7/htmx.min.js",
329
- integrity: "sha512-T6VLg/MJYMbLTmQ8VLvonbWg8VOvmDhXcOvHzCwo6ShdGuUU5SEcp1IAPXL4k9lVoMi8gRXl5K/S/zh43Y9rJA=="
330
- },
331
- alpine: {
332
- url: "https://cdn.jsdelivr.net/npm/alpinejs@3.14.3/dist/cdn.min.js",
333
- integrity: "sha384-6zY8MFQJ/EqS1r4RJl+7j8rvZPuBWpT0RzWf+IFcKhxqUzQNmJzA1X1VEVZhYaEz"
334
- }
335
- }
336
- }
337
- };
338
- var DEFAULT_THEME = GITHUB_OPENAI_THEME;
339
-
340
- // libs/ui/src/theme/theme.ts
341
- function emitColorScale(lines, name, scale) {
342
- for (const [shade, value] of Object.entries(scale)) {
343
- if (value) lines.push(`--color-${name}-${shade}: ${value};`);
344
- }
345
- }
346
- function buildThemeCss(theme) {
347
- const lines = [];
348
- const semantic = theme.colors.semantic;
349
- if (typeof semantic.primary === "string") {
350
- lines.push(`--color-primary: ${semantic.primary};`);
351
- } else if (semantic.primary) {
352
- emitColorScale(lines, "primary", semantic.primary);
353
- }
354
- if (semantic.secondary) {
355
- if (typeof semantic.secondary === "string") {
356
- lines.push(`--color-secondary: ${semantic.secondary};`);
357
- } else {
358
- emitColorScale(lines, "secondary", semantic.secondary);
359
- }
360
- }
361
- if (semantic.accent) {
362
- if (typeof semantic.accent === "string") {
363
- lines.push(`--color-accent: ${semantic.accent};`);
364
- } else {
365
- emitColorScale(lines, "accent", semantic.accent);
366
- }
367
- }
368
- if (semantic.neutral) {
369
- if (typeof semantic.neutral === "string") {
370
- lines.push(`--color-neutral: ${semantic.neutral};`);
371
- } else {
372
- emitColorScale(lines, "neutral", semantic.neutral);
373
- }
374
- }
375
- if (semantic.success) lines.push(`--color-success: ${semantic.success};`);
376
- if (semantic.warning) lines.push(`--color-warning: ${semantic.warning};`);
377
- if (semantic.danger) lines.push(`--color-danger: ${semantic.danger};`);
378
- if (semantic.info) lines.push(`--color-info: ${semantic.info};`);
379
- const surface = theme.colors.surface;
380
- if (surface?.background) lines.push(`--color-background: ${surface.background};`);
381
- if (surface?.surface) lines.push(`--color-surface: ${surface.surface};`);
382
- if (surface?.elevated) lines.push(`--color-elevated: ${surface.elevated};`);
383
- if (surface?.overlay) lines.push(`--color-overlay: ${surface.overlay};`);
384
- const text = theme.colors.text;
385
- if (text?.primary) lines.push(`--color-text-primary: ${text.primary};`);
386
- if (text?.secondary) lines.push(`--color-text-secondary: ${text.secondary};`);
387
- if (text?.disabled) lines.push(`--color-text-disabled: ${text.disabled};`);
388
- if (text?.inverse) lines.push(`--color-text-inverse: ${text.inverse};`);
389
- if (text?.link) lines.push(`--color-text-link: ${text.link};`);
390
- const border = theme.colors.border;
391
- if (border?.default) lines.push(`--color-border: ${border.default};`);
392
- if (border?.hover) lines.push(`--color-border-hover: ${border.hover};`);
393
- if (border?.focus) lines.push(`--color-border-focus: ${border.focus};`);
394
- if (border?.divider) lines.push(`--color-divider: ${border.divider};`);
395
- if (theme.colors.custom) {
396
- for (const [key, value] of Object.entries(theme.colors.custom)) {
397
- lines.push(`--color-${key}: ${value};`);
398
- }
399
- }
400
- const typography = theme.typography;
401
- if (typography?.families?.sans) lines.push(`--font-sans: ${typography.families.sans};`);
402
- if (typography?.families?.serif) lines.push(`--font-serif: ${typography.families.serif};`);
403
- if (typography?.families?.mono) lines.push(`--font-mono: ${typography.families.mono};`);
404
- if (typography?.families?.display) lines.push(`--font-display: ${typography.families.display};`);
405
- const radius = theme.radius;
406
- if (radius?.none) lines.push(`--radius-none: ${radius.none};`);
407
- if (radius?.sm) lines.push(`--radius-sm: ${radius.sm};`);
408
- if (radius?.md) lines.push(`--radius-md: ${radius.md};`);
409
- if (radius?.lg) lines.push(`--radius-lg: ${radius.lg};`);
410
- if (radius?.xl) lines.push(`--radius-xl: ${radius.xl};`);
411
- if (radius?.["2xl"]) lines.push(`--radius-2xl: ${radius["2xl"]};`);
412
- if (radius?.full) lines.push(`--radius-full: ${radius.full};`);
413
- if (theme.customVars) {
414
- for (const [key, value] of Object.entries(theme.customVars)) {
415
- lines.push(`${key}: ${value};`);
416
- }
417
- }
418
- return lines.join("\n ");
419
- }
420
- function buildStyleBlock(theme) {
421
- const themeCss = buildThemeCss(theme);
422
- const customCss = theme.customCss || "";
423
- return `<style type="text/tailwindcss">
424
- @theme {
425
- ${themeCss}
426
- }
427
- ${customCss}
428
- </style>`;
429
- }
430
-
431
- // libs/ui/src/base-template/theme-styles.ts
432
- function renderThemeStyles(options = {}) {
433
- const {
434
- theme = DEFAULT_THEME,
435
- tailwind = true,
436
- htmx = false,
437
- alpine = false,
438
- fonts = true,
439
- inline = false
440
- } = options;
441
- const parts = [];
442
- if (fonts && !inline) {
443
- parts.push(buildFontPreconnectFromTheme(theme));
444
- }
445
- if (fonts && !inline) {
446
- parts.push(buildFontStylesheetsFromTheme(theme));
447
- }
448
- const scriptOptions = {
449
- tailwind,
450
- htmx,
451
- alpine,
452
- inline
453
- };
454
- parts.push(buildCdnScriptsFromTheme(theme, scriptOptions));
455
- parts.push(buildStyleBlock(theme));
456
- return parts.filter(Boolean).join("\n ");
457
- }
458
- function renderMinimalThemeStyles(theme = DEFAULT_THEME) {
459
- return renderThemeStyles({
460
- theme,
461
- tailwind: true,
462
- htmx: false,
463
- alpine: false,
464
- fonts: false,
465
- inline: false
466
- });
467
- }
468
- function renderThemeCssOnly(theme = DEFAULT_THEME) {
469
- return buildStyleBlock(theme);
470
- }
471
-
472
- // libs/ui/src/base-template/polyfills.ts
473
- function renderMcpSessionPolyfill(mcpSession) {
474
- const fallbackCode = mcpSession ? `
475
- return {
476
- mcpUrl: '${escapeJs(mcpSession.mcpUrl)}',
477
- sessionId: '${escapeJs(mcpSession.sessionId)}'
478
- };` : `
479
- return null;`;
480
- return `<script>
481
- (function() {
482
- 'use strict';
483
-
484
- window.__frontmcp = window.__frontmcp || {};
485
-
486
- /**
487
- * Auto-detect MCP session from page context.
488
- * Tries multiple sources in order of priority.
489
- */
490
- window.__frontmcp.detectMcpSession = function() {
491
- // 1. Check if explicitly set by developer
492
- if (window.__frontmcp.mcpSession) {
493
- return window.__frontmcp.mcpSession;
494
- }
495
-
496
- // 2. Check meta tags
497
- var mcpUrlMeta = document.querySelector('meta[name="mcp-url"]');
498
- var sessionIdMeta = document.querySelector('meta[name="mcp-session-id"]');
499
- if (mcpUrlMeta && sessionIdMeta) {
500
- return {
501
- mcpUrl: mcpUrlMeta.getAttribute('content'),
502
- sessionId: sessionIdMeta.getAttribute('content')
503
- };
504
- }
505
-
506
- // 3. Check URL query parameters (for ngrok/iframe scenarios)
507
- try {
508
- var params = new URLSearchParams(window.location.search);
509
- var mcpUrl = params.get('mcpUrl');
510
- var sessionId = params.get('sessionId');
511
- if (mcpUrl && sessionId) {
512
- return { mcpUrl: mcpUrl, sessionId: sessionId };
513
- }
514
- } catch (e) {
515
- // URLSearchParams may not be available in all environments
516
- }
517
-
518
- // 4. Use explicit fallback if provided at render time
519
- ${fallbackCode}
520
- };
521
-
522
- /**
523
- * Enhanced callTool that uses HTTP fallback when MCP bridge is unavailable.
524
- * This wraps window.mcpBridge.callTool with HTTP fallback support.
525
- */
526
- window.__frontmcp.callTool = async function(toolName, args) {
527
- // Priority 1: Direct OpenAI SDK call (most reliable in OpenAI iframe)
528
- if (typeof window !== 'undefined' && window.openai && typeof window.openai.callTool === 'function') {
529
- return window.openai.callTool(toolName, args);
530
- }
531
-
532
- // Priority 2: If MCP bridge has callTool, use it
533
- if (window.mcpBridge && typeof window.mcpBridge.callTool === 'function') {
534
- try {
535
- return await window.mcpBridge.callTool(toolName, args);
536
- } catch (e) {
537
- // If MCP bridge fails, fall through to HTTP fallback
538
- console.warn('MCP bridge callTool failed, trying HTTP fallback:', e.message);
539
- }
540
- }
541
-
542
- // Priority 3: HTTP fallback using detected session
543
- var session = window.__frontmcp.detectMcpSession();
544
- if (!session) {
545
- throw new Error(
546
- 'MCP session not available. Set window.__frontmcp.mcpSession, ' +
547
- 'add meta tags, or provide URL parameters.'
548
- );
549
- }
550
-
551
- var response = await fetch(session.mcpUrl, {
552
- method: 'POST',
553
- headers: {
554
- 'Content-Type': 'application/json',
555
- 'X-Session-Id': session.sessionId
556
- },
557
- body: JSON.stringify({
558
- jsonrpc: '2.0',
559
- method: 'tools/call',
560
- params: { name: toolName, arguments: args || {} },
561
- id: Date.now()
562
- })
563
- });
564
-
565
- if (!response.ok) {
566
- throw new Error('HTTP ' + response.status + ': ' + response.statusText);
567
- }
568
-
569
- var result = await response.json();
570
- if (result.error) {
571
- throw new Error(result.error.message || 'Tool call failed');
572
- }
573
- return result.result;
574
- };
575
-
576
- /**
577
- * Get tool output from all possible sources.
578
- * Priority: pre-rendered HTML from metadata > structured data > raw output
579
- *
580
- * Note: Returns undefined for null values from OpenAI (which is its initial state)
581
- * to allow proper loading state handling in the bridge.
582
- */
583
- window.__frontmcp.getToolOutput = function() {
584
- // 1. Check for pre-rendered HTML in OpenAI toolResponseMetadata (highest priority)
585
- // This is set when the tool has a UI template (React, HTML, etc.)
586
- if (window.openai && window.openai.toolResponseMetadata) {
587
- var html = window.openai.toolResponseMetadata['ui/html'];
588
- if (html && typeof html === 'string') {
589
- return html; // Return HTML string directly
590
- }
591
- }
592
-
593
- // 2. Check for pre-rendered HTML in MCP response metadata (for MCP Inspector, etc.)
594
- if (window.__mcpResponseMeta) {
595
- var mcpHtml = window.__mcpResponseMeta['ui/html'];
596
- if (mcpHtml && typeof mcpHtml === 'string') {
597
- return mcpHtml; // Return HTML string directly
598
- }
599
- }
600
-
601
- // 3. OpenAI injects structured data into window.openai.toolOutput
602
- // Skip null - that's OpenAI's initial state before real data is injected
603
- if (window.openai && window.openai.toolOutput !== undefined && window.openai.toolOutput !== null) {
604
- return window.openai.toolOutput;
605
- }
606
-
607
- // 4. MCP Bridge stores in window.__mcpToolOutput (skip null)
608
- if (window.__mcpToolOutput !== undefined && window.__mcpToolOutput !== null) {
609
- return window.__mcpToolOutput;
610
- }
611
-
612
- // 5. Explicit injection
613
- if (window.__frontmcp.toolOutput !== undefined) {
614
- return window.__frontmcp.toolOutput;
615
- }
616
-
617
- return undefined;
618
- };
619
- })();
620
- </script>`;
621
- }
622
- function escapeJs(str) {
623
- return str.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/"/g, '\\"').replace(/`/g, "\\`").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/<\/script/gi, "<\\/script").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
624
- }
625
-
626
- // libs/ui/src/base-template/bridge.ts
627
- function renderBridgeScript() {
628
- return `<script>
629
- (function() {
630
- 'use strict';
631
-
632
- // ============================================
633
- // Debug Mode
634
- // ============================================
635
-
636
- var DEBUG = window.location.search.indexOf('frontmcp_debug=1') > -1 ||
637
- window.localStorage.getItem('frontmcp_debug') === '1';
638
- var debugLog = [];
639
-
640
- function log(level, message, data) {
641
- var entry = {
642
- ts: new Date().toISOString(),
643
- level: level,
644
- message: message,
645
- data: data
646
- };
647
- debugLog.push(entry);
648
- if (DEBUG) {
649
- console[level === 'error' ? 'error' : level === 'warn' ? 'warn' : 'log'](
650
- '[frontmcp] ' + message,
651
- data || ''
652
- );
653
- }
654
- }
655
-
656
- // ============================================
657
- // Bridge State Management
658
- // ============================================
659
-
660
- var state = { data: null, loading: true, error: null };
661
- var subscribers = [];
662
- var stateVersion = 0; // For React useSyncExternalStore stability
663
-
664
- function notify() {
665
- stateVersion++;
666
- for (var i = 0; i < subscribers.length; i++) {
667
- try { subscribers[i](); } catch(e) {
668
- log('error', 'Subscriber error:', { error: e.message, stack: e.stack });
669
- }
670
- }
671
- // Dispatch custom event for HTMX
672
- if (typeof CustomEvent !== 'undefined') {
673
- document.dispatchEvent(new CustomEvent('frontmcp:change', { detail: state }));
674
- }
675
- }
676
-
677
- function setData(data) {
678
- // Skip if data hasn't actually changed (prevents unnecessary re-renders)
679
- if (!state.loading && state.data === data) return;
680
- log('info', 'setData called', {
681
- dataType: typeof data,
682
- dataLength: typeof data === 'string' ? data.length : 'N/A',
683
- isNull: data === null,
684
- isUndefined: data === undefined
685
- });
686
- state = { data: data, loading: false, error: null };
687
- notify();
688
- }
689
-
690
- function setError(error) {
691
- log('error', 'setError called', { error: error });
692
- state = { data: null, loading: false, error: error };
693
- notify();
694
- }
695
-
696
- function reset() {
697
- log('info', 'reset called');
698
- state = { data: null, loading: true, error: null };
699
- notify();
700
- }
701
-
702
- // ============================================
703
- // Data Validation
704
- // ============================================
705
-
706
- function validateToolOutput(data, source) {
707
- var errors = [];
708
-
709
- if (data === undefined) {
710
- errors.push('toolOutput is undefined');
711
- } else if (data === null) {
712
- // null is valid initial state from OpenAI
713
- log('info', 'toolOutput is null (OpenAI initial state)', { source: source });
714
- return { valid: false, errors: ['initial_state'], isInitial: true };
715
- }
716
-
717
- if (typeof data === 'object' && data !== null) {
718
- if (data.isError === true) {
719
- errors.push('Tool returned error: ' + JSON.stringify(data));
720
- }
721
- // Check for MCP error structure
722
- if (data.error && data.error.code) {
723
- errors.push('MCP error: code=' + data.error.code + ', message=' + (data.error.message || 'unknown'));
724
- }
725
- }
726
-
727
- if (errors.length > 0) {
728
- log('warn', 'Validation issues', { source: source, errors: errors });
729
- }
730
-
731
- return { valid: errors.length === 0, errors: errors, isInitial: false };
732
- }
733
-
734
- function validateMetadata(meta, source) {
735
- var errors = [];
736
-
737
- if (!meta) {
738
- errors.push('toolResponseMetadata is null/undefined');
739
- return { valid: false, errors: errors };
740
- }
741
-
742
- if (typeof meta !== 'object') {
743
- errors.push('toolResponseMetadata is not an object: ' + typeof meta);
744
- return { valid: false, errors: errors };
745
- }
746
-
747
- var html = meta['ui/html'];
748
- if (html !== undefined) {
749
- if (typeof html !== 'string') {
750
- errors.push('ui/html is not a string: ' + typeof html);
751
- } else if (html.length === 0) {
752
- errors.push('ui/html is empty string');
753
- } else if (html.indexOf('validation-error') > -1) {
754
- errors.push('ui/html contains validation error');
755
- log('warn', 'HTML contains validation error', { htmlPreview: html.substring(0, 500) });
756
- }
757
- }
758
-
759
- if (errors.length > 0) {
760
- log('warn', 'Metadata validation issues', { source: source, errors: errors, keys: Object.keys(meta) });
761
- }
762
-
763
- return { valid: errors.length === 0, errors: errors };
764
- }
765
-
766
- // ============================================
767
- // OpenAI Platform Interceptors
768
- // ============================================
769
-
770
- var openaiIntercepted = false;
771
-
772
- function checkOpenAIData(openai) {
773
- if (!openai) {
774
- log('warn', 'checkOpenAIData: openai object is null');
775
- return false;
776
- }
777
-
778
- log('info', 'checkOpenAIData called', {
779
- hasToolOutput: openai.toolOutput !== undefined,
780
- hasToolResponseMetadata: openai.toolResponseMetadata !== undefined,
781
- toolOutputType: typeof openai.toolOutput,
782
- metadataKeys: openai.toolResponseMetadata ? Object.keys(openai.toolResponseMetadata) : []
783
- });
784
-
785
- // Priority 1: Pre-rendered HTML from toolResponseMetadata
786
- if (openai.toolResponseMetadata) {
787
- var metaValidation = validateMetadata(openai.toolResponseMetadata, 'openai.toolResponseMetadata');
788
- var html = openai.toolResponseMetadata['ui/html'];
789
- if (html && typeof html === 'string') {
790
- log('info', 'Using ui/html from metadata', { htmlLength: html.length });
791
- setData(html);
792
- return true;
793
- }
794
- }
795
-
796
- // Priority 2: Tool output (skip null - that's OpenAI's initial state)
797
- if (openai.toolOutput !== undefined && openai.toolOutput !== null) {
798
- var outputValidation = validateToolOutput(openai.toolOutput, 'openai.toolOutput');
799
- if (!outputValidation.isInitial) {
800
- log('info', 'Using toolOutput', {
801
- valid: outputValidation.valid,
802
- errors: outputValidation.errors
803
- });
804
- setData(openai.toolOutput);
805
- return true;
806
- }
807
- }
808
-
809
- log('info', 'checkOpenAIData: no data found yet');
810
- return false;
811
- }
812
-
813
- function installPropertyInterceptor(obj, prop, onSet) {
814
- var current = obj[prop];
815
- var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
816
-
817
- // Don't re-intercept
818
- if (descriptor && descriptor.get && descriptor.set) return;
819
-
820
- Object.defineProperty(obj, prop, {
821
- get: function() { return current; },
822
- set: function(val) {
823
- current = val;
824
- onSet(val);
825
- },
826
- enumerable: true,
827
- configurable: true
828
- });
829
- }
830
-
831
- function installOpenAIInterceptors(openai) {
832
- if (!openai || openaiIntercepted) return;
833
- openaiIntercepted = true;
834
-
835
- // Check existing data first
836
- if (checkOpenAIData(openai)) return;
837
-
838
- // Intercept toolOutput
839
- installPropertyInterceptor(openai, 'toolOutput', function(val) {
840
- checkOpenAIData(openai);
841
- });
842
-
843
- // Intercept toolResponseMetadata
844
- installPropertyInterceptor(openai, 'toolResponseMetadata', function(val) {
845
- checkOpenAIData(openai);
846
- });
847
- }
848
-
849
- // Install interceptor on window.openai
850
- if (typeof window.openai !== 'undefined') {
851
- installOpenAIInterceptors(window.openai);
852
- } else {
853
- // OpenAI object doesn't exist yet - wait for it
854
- var pendingOpenai = undefined;
855
- Object.defineProperty(window, 'openai', {
856
- get: function() { return pendingOpenai; },
857
- set: function(val) {
858
- pendingOpenai = val;
859
- if (val) installOpenAIInterceptors(val);
860
- },
861
- enumerable: true,
862
- configurable: true
863
- });
864
- }
865
-
866
- // ============================================
867
- // MCP/Generic Platform Support
868
- // ============================================
869
-
870
- // Check for existing __frontmcp.toolOutput
871
- if (window.__frontmcp && window.__frontmcp.toolOutput !== undefined) {
872
- setData(window.__frontmcp.toolOutput);
873
- }
874
-
875
- // Check for __mcpToolOutput
876
- if (window.__mcpToolOutput !== undefined && window.__mcpToolOutput !== null) {
877
- setData(window.__mcpToolOutput);
878
- }
879
-
880
- // Check for __mcpResponseMeta
881
- if (window.__mcpResponseMeta && window.__mcpResponseMeta['ui/html']) {
882
- setData(window.__mcpResponseMeta['ui/html']);
883
- }
884
-
885
- // ============================================
886
- // Bridge API
887
- // ============================================
888
-
889
- window.__frontmcp = window.__frontmcp || {};
890
-
891
- window.__frontmcp.bridge = {
892
- getState: function() { return state; },
893
-
894
- // React useSyncExternalStore compatible
895
- getSnapshot: function() { return state; },
896
- getServerSnapshot: function() { return { data: null, loading: true, error: null }; },
897
-
898
- subscribe: function(callback) {
899
- subscribers.push(callback);
900
- return function() {
901
- var idx = subscribers.indexOf(callback);
902
- if (idx > -1) subscribers.splice(idx, 1);
903
- };
904
- },
905
-
906
- hasData: function() { return !state.loading && state.data !== null; },
907
-
908
- // Manual control (for testing/custom injection)
909
- setData: setData,
910
- setError: setError,
911
- reset: reset,
912
-
913
- // Debug API
914
- debug: {
915
- getLogs: function() { return debugLog.slice(); },
916
- getLastErrors: function() {
917
- return debugLog.filter(function(e) { return e.level === 'error' || e.level === 'warn'; });
918
- },
919
- enableDebug: function() {
920
- DEBUG = true;
921
- window.localStorage.setItem('frontmcp_debug', '1');
922
- console.log('[frontmcp] Debug mode enabled. Reload page to see all logs.');
923
- },
924
- disableDebug: function() {
925
- DEBUG = false;
926
- window.localStorage.removeItem('frontmcp_debug');
927
- },
928
- isDebugEnabled: function() { return DEBUG; },
929
- getStateHistory: function() {
930
- return {
931
- current: state,
932
- version: stateVersion,
933
- subscriberCount: subscribers.length,
934
- openaiIntercepted: openaiIntercepted,
935
- pollCount: pollCount
936
- };
937
- },
938
- dumpAll: function() {
939
- console.group('[frontmcp] Debug Dump');
940
- console.log('State:', state);
941
- console.log('Version:', stateVersion);
942
- console.log('Subscribers:', subscribers.length);
943
- console.log('OpenAI Intercepted:', openaiIntercepted);
944
- console.log('Poll Count:', pollCount);
945
- console.log('Debug Logs:', debugLog);
946
- console.groupEnd();
947
- return {
948
- state: state,
949
- logs: debugLog,
950
- version: stateVersion,
951
- openaiIntercepted: openaiIntercepted
952
- };
953
- }
954
- }
955
- };
956
-
957
- // ============================================
958
- // Fallback Polling (for platforms that don't trigger setters)
959
- // ============================================
960
-
961
- var pollCount = 0;
962
- var maxPolls = 30; // ~3 seconds with exponential backoff
963
-
964
- function pollForData() {
965
- if (state.data !== null || pollCount >= maxPolls) return;
966
- pollCount++;
967
-
968
- // Check all sources
969
- if (window.openai) {
970
- if (checkOpenAIData(window.openai)) return;
971
- }
972
-
973
- // Use getToolOutput if available
974
- if (window.__frontmcp.getToolOutput) {
975
- var data = window.__frontmcp.getToolOutput();
976
- if (data !== undefined && data !== null) {
977
- setData(data);
978
- return;
979
- }
980
- }
981
-
982
- // Exponential backoff: 50ms, 75ms, 112ms, ...
983
- var delay = Math.min(50 * Math.pow(1.5, Math.min(pollCount, 10)), 500);
984
- setTimeout(pollForData, delay);
985
- }
986
-
987
- // Start polling after a brief delay (give interceptors time to fire)
988
- setTimeout(pollForData, 50);
989
- })();
990
- </script>`;
991
- }
992
- var BRIDGE_TYPES = `
993
- interface BridgeState<T = unknown> {
994
- data: T | null;
995
- loading: boolean;
996
- error: string | null;
997
- }
998
-
999
- interface PlatformBridge<T = unknown> {
1000
- getState(): BridgeState<T>;
1001
- subscribe(callback: () => void): () => void;
1002
- getSnapshot(): BridgeState<T>;
1003
- getServerSnapshot(): BridgeState<T>;
1004
- hasData(): boolean;
1005
- setData(data: T): void;
1006
- setError(error: string): void;
1007
- reset(): void;
1008
- }
1009
-
1010
- declare global {
1011
- interface Window {
1012
- __frontmcp: {
1013
- bridge: PlatformBridge;
1014
- // ... other __frontmcp methods
1015
- };
1016
- }
1017
- }
1018
- `;
1019
-
1020
- // libs/ui/src/base-template/default-base-template.ts
1021
- function escapeAttr(str) {
1022
- return str.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1023
- }
1024
- function createDefaultBaseTemplate(options) {
1025
- const {
1026
- toolName,
1027
- theme = DEFAULT_THEME,
1028
- mcpSession,
1029
- htmx = false,
1030
- alpine = false,
1031
- fonts = true,
1032
- inline = false,
1033
- headContent = "",
1034
- bodyClass = "bg-transparent font-sans antialiased",
1035
- containerClass = "p-4"
1036
- } = options;
1037
- const themeStylesOptions = {
1038
- theme,
1039
- tailwind: true,
1040
- htmx,
1041
- alpine,
1042
- fonts,
1043
- inline
1044
- };
1045
- const themeStyles = renderThemeStyles(themeStylesOptions);
1046
- const polyfills = renderMcpSessionPolyfill(mcpSession);
1047
- const bridge = renderBridgeScript();
1048
- return `<!DOCTYPE html>
1049
- <html lang="en">
1050
- <head>
1051
- <meta charset="utf-8">
1052
- <meta name="viewport" content="width=device-width, initial-scale=1">
1053
- <meta name="color-scheme" content="light dark">
1054
- <title>${escapeAttr(toolName)} Widget</title>
1055
- ${themeStyles}
1056
- ${polyfills}
1057
- ${bridge}
1058
- ${headContent}
1059
- </head>
1060
- <body class="${escapeAttr(bodyClass)}">
1061
- <div id="widget-root" class="${escapeAttr(containerClass)}"></div>
1062
-
1063
- <script>
1064
- (function() {
1065
- 'use strict';
1066
-
1067
- var root = document.getElementById('widget-root');
1068
-
1069
- /**
1070
- * Render the widget based on bridge state.
1071
- * Uses the reactive bridge to automatically re-render when data changes.
1072
- */
1073
- function render() {
1074
- var state = window.__frontmcp.bridge.getState();
1075
-
1076
- // Loading state
1077
- if (state.loading) {
1078
- root.innerHTML = renderLoading();
1079
- return;
1080
- }
1081
-
1082
- // Error state
1083
- if (state.error) {
1084
- root.innerHTML = renderError(state.error);
1085
- return;
1086
- }
1087
-
1088
- // No data state
1089
- if (state.data === null) {
1090
- root.innerHTML = renderEmpty();
1091
- return;
1092
- }
1093
-
1094
- // Render data
1095
- try {
1096
- // Check for custom renderer provided by developer
1097
- if (window.__frontmcp && typeof window.__frontmcp.renderContent === 'function') {
1098
- root.innerHTML = window.__frontmcp.renderContent(state.data);
1099
- return;
1100
- }
1101
-
1102
- // Fall back to default renderer
1103
- root.innerHTML = defaultRenderer(state.data);
1104
- } catch (e) {
1105
- console.error('[frontmcp] Error rendering widget:', e);
1106
- root.innerHTML = renderError(e.message || 'Render error');
1107
- }
1108
- }
1109
-
1110
- /**
1111
- * Default renderer for tool output.
1112
- * Handles both pre-rendered HTML strings and raw JSON data.
1113
- */
1114
- function defaultRenderer(data) {
1115
- // Check if data is pre-rendered HTML (server-side rendered widget)
1116
- if (typeof data === 'string' && data.trim().startsWith('<')) {
1117
- // Direct HTML injection - content was already rendered/sanitized server-side
1118
- return data;
1119
- }
1120
-
1121
- // Check for special wrapper with HTML content
1122
- if (data && typeof data === 'object' && data.__html) {
1123
- return data.__html;
1124
- }
1125
-
1126
- // Fallback: JSON renderer for raw data
1127
- var json = JSON.stringify(data, null, 2);
1128
- return '<pre class="p-4 bg-surface rounded-md overflow-auto text-sm font-mono text-text-primary border border-border">' +
1129
- escapeHtml(json) +
1130
- '</pre>';
1131
- }
1132
-
1133
- /**
1134
- * Render loading state with animated spinner.
1135
- */
1136
- function renderLoading() {
1137
- return '<div class="flex items-center justify-center p-8">' +
1138
- '<div class="flex flex-col items-center gap-3">' +
1139
- '<svg class="animate-spin h-8 w-8 text-blue-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">' +
1140
- '<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>' +
1141
- '<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>' +
1142
- '</svg>' +
1143
- '<p class="text-text-secondary text-sm">Loading...</p>' +
1144
- '</div>' +
1145
- '</div>';
1146
- }
1147
-
1148
- /**
1149
- * Render error message.
1150
- */
1151
- function renderError(message) {
1152
- return '<div class="p-4 bg-red-50 border border-red-200 rounded-md">' +
1153
- '<p class="text-red-600 text-sm">Error: ' + escapeHtml(message) + '</p>' +
1154
- '</div>';
1155
- }
1156
-
1157
- /**
1158
- * Render empty state (no data available).
1159
- */
1160
- function renderEmpty() {
1161
- return '<div class="p-4 text-text-secondary text-sm text-center">' +
1162
- 'No data available' +
1163
- '</div>';
1164
- }
1165
-
1166
- /**
1167
- * Escape HTML special characters.
1168
- */
1169
- function escapeHtml(str) {
1170
- if (typeof str !== 'string') return str;
1171
- return str
1172
- .replace(/&/g, '&amp;')
1173
- .replace(/</g, '&lt;')
1174
- .replace(/>/g, '&gt;')
1175
- .replace(/"/g, '&quot;');
1176
- }
1177
-
1178
- /**
1179
- * Create debug overlay panel.
1180
- * Shows bridge state, logs, and OpenAI data status.
1181
- */
1182
- function createDebugOverlay() {
1183
- var overlay = document.createElement('div');
1184
- overlay.id = 'frontmcp-debug-overlay';
1185
- overlay.style.cssText = 'position:fixed;bottom:10px;right:10px;width:400px;max-height:60vh;' +
1186
- 'background:rgba(0,0,0,0.9);color:#0f0;font-family:monospace;font-size:11px;' +
1187
- 'padding:10px;border-radius:4px;z-index:99999;overflow:auto;display:none;';
1188
-
1189
- var toggle = document.createElement('button');
1190
- toggle.id = 'frontmcp-debug-toggle';
1191
- toggle.textContent = 'Debug';
1192
- toggle.style.cssText = 'position:fixed;bottom:10px;right:10px;padding:4px 8px;' +
1193
- 'background:#333;color:#0f0;font-family:monospace;font-size:10px;border:1px solid #0f0;' +
1194
- 'border-radius:4px;z-index:100000;cursor:pointer;';
1195
-
1196
- toggle.onclick = function() {
1197
- var o = document.getElementById('frontmcp-debug-overlay');
1198
- if (o.style.display === 'none') {
1199
- o.style.display = 'block';
1200
- toggle.style.right = '420px';
1201
- updateDebugOverlay();
1202
- } else {
1203
- o.style.display = 'none';
1204
- toggle.style.right = '10px';
1205
- }
1206
- };
1207
-
1208
- document.body.appendChild(overlay);
1209
- document.body.appendChild(toggle);
1210
-
1211
- // Auto-update every second
1212
- setInterval(updateDebugOverlay, 1000);
1213
- }
1214
-
1215
- function updateDebugOverlay() {
1216
- var overlay = document.getElementById('frontmcp-debug-overlay');
1217
- if (!overlay || overlay.style.display === 'none') return;
1218
-
1219
- var state = window.__frontmcp.bridge.getState();
1220
- var debug = window.__frontmcp.bridge.debug;
1221
- var logs = debug.getLogs();
1222
- var errors = debug.getLastErrors();
1223
- var stateHistory = debug.getStateHistory();
1224
-
1225
- var html = '<div style="margin-bottom:10px;border-bottom:1px solid #333;padding-bottom:5px;">' +
1226
- '<strong>FrontMCP Debug Panel</strong>' +
1227
- '<span style="float:right;color:#666;">v' + stateHistory.version + '</span>' +
1228
- '</div>';
1229
-
1230
- // Bridge State
1231
- html += '<div style="margin-bottom:10px;">' +
1232
- '<div style="color:#ff0;">Bridge State:</div>' +
1233
- '<div>Loading: ' + state.loading + '</div>' +
1234
- '<div>Has Data: ' + (state.data !== null) + '</div>' +
1235
- '<div>Data Type: ' + (state.data === null ? 'null' : typeof state.data) + '</div>' +
1236
- (typeof state.data === 'string' ? '<div>Data Length: ' + state.data.length + '</div>' : '') +
1237
- '<div>Error: ' + (state.error || 'none') + '</div>' +
1238
- '</div>';
1239
-
1240
- // OpenAI Status
1241
- html += '<div style="margin-bottom:10px;">' +
1242
- '<div style="color:#ff0;">OpenAI Status:</div>' +
1243
- '<div>Intercepted: ' + stateHistory.openaiIntercepted + '</div>' +
1244
- '<div>Poll Count: ' + stateHistory.pollCount + '</div>';
1245
-
1246
- if (window.openai) {
1247
- html += '<div>window.openai: exists</div>' +
1248
- '<div>toolOutput: ' + (window.openai.toolOutput !== undefined ? 'present' : 'undefined') + '</div>' +
1249
- '<div>toolResponseMetadata: ' + (window.openai.toolResponseMetadata !== undefined ? 'present' : 'undefined') + '</div>';
1250
- if (window.openai.toolResponseMetadata) {
1251
- html += '<div>meta keys: ' + Object.keys(window.openai.toolResponseMetadata).join(', ') + '</div>';
1252
- }
1253
- } else {
1254
- html += '<div>window.openai: undefined</div>';
1255
- }
1256
- html += '</div>';
1257
-
1258
- // Errors
1259
- if (errors.length > 0) {
1260
- html += '<div style="margin-bottom:10px;">' +
1261
- '<div style="color:#f00;">Errors (' + errors.length + '):</div>';
1262
- errors.slice(-5).forEach(function(e) {
1263
- html += '<div style="color:#f88;font-size:10px;">[' + e.level + '] ' + escapeHtml(e.message) + '</div>';
1264
- });
1265
- html += '</div>';
1266
- }
1267
-
1268
- // Recent Logs
1269
- html += '<div>' +
1270
- '<div style="color:#ff0;">Recent Logs (' + logs.length + '):</div>' +
1271
- '<div style="max-height:150px;overflow:auto;">';
1272
- logs.slice(-10).forEach(function(e) {
1273
- var color = e.level === 'error' ? '#f00' : e.level === 'warn' ? '#ff0' : '#0f0';
1274
- html += '<div style="color:' + color + ';font-size:10px;">' +
1275
- '[' + e.ts.split('T')[1].split('.')[0] + '] ' + escapeHtml(e.message) +
1276
- '</div>';
1277
- });
1278
- html += '</div></div>';
1279
-
1280
- // Actions
1281
- html += '<div style="margin-top:10px;border-top:1px solid #333;padding-top:5px;">' +
1282
- '<button onclick="console.log(window.__frontmcp.bridge.debug.dumpAll())" ' +
1283
- 'style="font-size:10px;padding:2px 6px;margin-right:5px;">Dump to Console</button>' +
1284
- '<button onclick="window.__frontmcp.bridge.reset()" ' +
1285
- 'style="font-size:10px;padding:2px 6px;">Reset Bridge</button>' +
1286
- '</div>';
1287
-
1288
- overlay.innerHTML = html;
1289
- }
1290
-
1291
- /**
1292
- * Initialize the widget with reactive rendering.
1293
- */
1294
- function init() {
1295
- // Subscribe to bridge state changes for reactive re-rendering
1296
- window.__frontmcp.bridge.subscribe(render);
1297
-
1298
- // Initial render
1299
- render();
1300
-
1301
- // Global click handler for SSR-compatible tool calls
1302
- // Handles buttons/elements with data-tool-call attribute
1303
- document.addEventListener('click', function(e) {
1304
- var target = e.target;
1305
- // Walk up the DOM to find element with data-tool-call (handles clicks on child elements)
1306
- while (target && target !== document.body) {
1307
- if (target.hasAttribute && target.hasAttribute('data-tool-call')) {
1308
- var toolName = target.getAttribute('data-tool-call');
1309
- var argsStr = target.getAttribute('data-tool-args');
1310
- var args = {};
1311
-
1312
- if (argsStr) {
1313
- try {
1314
- args = JSON.parse(argsStr);
1315
- } catch (parseErr) {
1316
- console.error('[frontmcp] Failed to parse data-tool-args:', parseErr);
1317
- }
1318
- }
1319
-
1320
- // Prevent default behavior and stop propagation
1321
- e.preventDefault();
1322
- e.stopPropagation();
1323
-
1324
- // Show loading state on the button
1325
- var originalContent = target.innerHTML;
1326
- var loadingContent = '<span style="display:inline-flex;align-items:center;">' +
1327
- '<span style="animation:spin 1s linear infinite;margin-right:4px;">\u23F3</span>' +
1328
- 'Loading...' +
1329
- '</span>';
1330
- target.innerHTML = loadingContent;
1331
- target.disabled = true;
1332
-
1333
- // Call the tool
1334
- if (window.__frontmcp && typeof window.__frontmcp.callTool === 'function') {
1335
- window.__frontmcp.callTool(toolName, args)
1336
- .then(function(result) {
1337
- console.log('[frontmcp] Tool call success:', toolName, result);
1338
- // Restore button state on success
1339
- target.innerHTML = originalContent;
1340
- target.disabled = false;
1341
- })
1342
- .catch(function(err) {
1343
- console.error('[frontmcp] Tool call failed:', toolName, err);
1344
- // Restore button state on error
1345
- target.innerHTML = originalContent;
1346
- target.disabled = false;
1347
- });
1348
- } else {
1349
- console.error('[frontmcp] callTool not available');
1350
- target.innerHTML = originalContent;
1351
- target.disabled = false;
1352
- }
1353
-
1354
- return;
1355
- }
1356
- target = target.parentElement;
1357
- }
1358
- });
1359
-
1360
- // Create debug overlay if debug mode is enabled
1361
- var DEBUG = window.location.search.indexOf('frontmcp_debug=1') > -1 ||
1362
- window.localStorage.getItem('frontmcp_debug') === '1';
1363
- if (DEBUG) {
1364
- createDebugOverlay();
1365
- }
1366
- }
1367
-
1368
- // Initialize when DOM is ready
1369
- if (document.readyState === 'loading') {
1370
- document.addEventListener('DOMContentLoaded', init);
1371
- } else {
1372
- init();
1373
- }
1374
- })();
1375
- </script>
1376
- </body>
1377
- </html>`;
1378
- }
1379
- function createMinimalBaseTemplate(toolName, mcpSession) {
1380
- return createDefaultBaseTemplate({
1381
- toolName,
1382
- mcpSession,
1383
- fonts: false,
1384
- htmx: false,
1385
- alpine: false
1386
- });
1387
- }
1388
- // Annotate the CommonJS export names for ESM import in node:
1389
- 0 && (module.exports = {
1390
- BRIDGE_TYPES,
1391
- createDefaultBaseTemplate,
1392
- createMinimalBaseTemplate,
1393
- renderBridgeScript,
1394
- renderMcpSessionPolyfill,
1395
- renderMinimalThemeStyles,
1396
- renderThemeCssOnly,
1397
- renderThemeStyles
1398
- });