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