@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,1398 @@
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/uipack/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/uipack/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/uipack/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/uipack/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/uipack/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/uipack/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/uipack/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/uipack/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/uipack/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
+ });