@frontmcp/ui 0.6.0 → 0.6.2
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.
- package/README.md +140 -362
- package/bridge/core/bridge-factory.d.ts +1 -0
- package/bridge/core/bridge-factory.d.ts.map +1 -1
- package/bridge/index.d.ts +1 -1
- package/bridge/index.d.ts.map +1 -1
- package/bridge/index.js +39 -881
- package/bridge/runtime/index.d.ts +2 -1
- package/bridge/runtime/index.d.ts.map +1 -1
- package/bundler/browser-components.d.ts +42 -0
- package/bundler/browser-components.d.ts.map +1 -0
- package/bundler/bundler.d.ts +78 -4
- package/bundler/bundler.d.ts.map +1 -1
- package/bundler/index.d.ts +8 -8
- package/bundler/index.d.ts.map +1 -1
- package/bundler/index.js +1411 -2997
- package/bundler/types.d.ts +188 -7
- package/bundler/types.d.ts.map +1 -1
- package/components/alert.schema.d.ts +6 -6
- package/components/avatar.schema.d.ts +9 -9
- package/components/badge.schema.d.ts +9 -9
- package/components/button.schema.d.ts +9 -9
- package/components/card.schema.d.ts +7 -7
- package/components/form.schema.d.ts +24 -24
- package/components/index.js +128 -198
- package/components/modal.schema.d.ts +8 -8
- package/components/table.schema.d.ts +6 -6
- package/esm/bridge/{index.js → index.mjs} +40 -877
- package/esm/bundler/index.mjs +3136 -0
- package/esm/components/{index.js → index.mjs} +136 -196
- package/esm/index.mjs +5450 -0
- package/esm/layouts/index.mjs +409 -0
- package/esm/package.json +15 -32
- package/esm/react/{index.js → index.mjs} +71 -260
- package/esm/renderers/index.mjs +611 -0
- package/esm/universal/index.mjs +1951 -0
- package/esm/web-components/{index.js → index.mjs} +232 -287
- package/index.d.ts +22 -41
- package/index.d.ts.map +1 -1
- package/index.js +4286 -19607
- package/layouts/base.d.ts +2 -2
- package/layouts/base.d.ts.map +1 -1
- package/layouts/index.js +46 -539
- package/layouts/presets.d.ts.map +1 -1
- package/package.json +15 -32
- package/react/Alert.d.ts +1 -2
- package/react/Alert.d.ts.map +1 -1
- package/react/Badge.d.ts +1 -2
- package/react/Badge.d.ts.map +1 -1
- package/react/Button.d.ts +1 -2
- package/react/Button.d.ts.map +1 -1
- package/react/Card.d.ts +1 -2
- package/react/Card.d.ts.map +1 -1
- package/react/hooks/context.d.ts +1 -1
- package/react/hooks/context.d.ts.map +1 -1
- package/react/index.d.ts +5 -7
- package/react/index.d.ts.map +1 -1
- package/react/index.js +55 -269
- package/react/types.d.ts +1 -2
- package/react/types.d.ts.map +1 -1
- package/renderers/index.d.ts +15 -25
- package/renderers/index.d.ts.map +1 -1
- package/renderers/index.js +393 -1619
- package/renderers/mdx.renderer.d.ts +13 -34
- package/renderers/mdx.renderer.d.ts.map +1 -1
- package/{esm/runtime/adapters → renderers}/react.adapter.d.ts +2 -2
- package/renderers/react.adapter.d.ts.map +1 -0
- package/renderers/react.renderer.d.ts +25 -16
- package/renderers/react.renderer.d.ts.map +1 -1
- package/renderers/transpiler.d.ts +49 -0
- package/renderers/transpiler.d.ts.map +1 -0
- package/universal/cached-runtime.d.ts +25 -1
- package/universal/cached-runtime.d.ts.map +1 -1
- package/universal/index.js +2037 -0
- package/universal/runtime-builder.d.ts.map +1 -1
- package/universal/types.d.ts.map +1 -1
- package/web-components/elements/fmcp-input.d.ts.map +1 -1
- package/web-components/elements/fmcp-select.d.ts.map +1 -1
- package/web-components/index.d.ts +0 -1
- package/web-components/index.d.ts.map +1 -1
- package/web-components/index.js +224 -289
- package/adapters/index.d.ts +0 -13
- package/adapters/index.d.ts.map +0 -1
- package/adapters/index.js +0 -462
- package/adapters/platform-meta.d.ts +0 -166
- package/adapters/platform-meta.d.ts.map +0 -1
- package/adapters/response-builder.d.ts +0 -108
- package/adapters/response-builder.d.ts.map +0 -1
- package/adapters/serving-mode.d.ts +0 -107
- package/adapters/serving-mode.d.ts.map +0 -1
- package/base-template/bridge.d.ts +0 -90
- package/base-template/bridge.d.ts.map +0 -1
- package/base-template/default-base-template.d.ts +0 -92
- package/base-template/default-base-template.d.ts.map +0 -1
- package/base-template/index.d.ts +0 -15
- package/base-template/index.d.ts.map +0 -1
- package/base-template/index.js +0 -1398
- package/base-template/polyfills.d.ts +0 -31
- package/base-template/polyfills.d.ts.map +0 -1
- package/base-template/theme-styles.d.ts +0 -74
- package/base-template/theme-styles.d.ts.map +0 -1
- package/build/cdn-resources.d.ts +0 -243
- package/build/cdn-resources.d.ts.map +0 -1
- package/build/index.d.ts +0 -295
- package/build/index.d.ts.map +0 -1
- package/build/index.js +0 -7096
- package/build/widget-manifest.d.ts +0 -362
- package/build/widget-manifest.d.ts.map +0 -1
- package/bundler/cache.d.ts +0 -173
- package/bundler/cache.d.ts.map +0 -1
- package/bundler/file-cache/component-builder.d.ts +0 -167
- package/bundler/file-cache/component-builder.d.ts.map +0 -1
- package/bundler/file-cache/hash-calculator.d.ts +0 -155
- package/bundler/file-cache/hash-calculator.d.ts.map +0 -1
- package/bundler/file-cache/index.d.ts +0 -12
- package/bundler/file-cache/index.d.ts.map +0 -1
- package/bundler/file-cache/storage/filesystem.d.ts +0 -149
- package/bundler/file-cache/storage/filesystem.d.ts.map +0 -1
- package/bundler/file-cache/storage/index.d.ts +0 -11
- package/bundler/file-cache/storage/index.d.ts.map +0 -1
- package/bundler/file-cache/storage/interface.d.ts +0 -152
- package/bundler/file-cache/storage/interface.d.ts.map +0 -1
- package/bundler/file-cache/storage/redis.d.ts +0 -139
- package/bundler/file-cache/storage/redis.d.ts.map +0 -1
- package/bundler/sandbox/enclave-adapter.d.ts +0 -121
- package/bundler/sandbox/enclave-adapter.d.ts.map +0 -1
- package/bundler/sandbox/executor.d.ts +0 -14
- package/bundler/sandbox/executor.d.ts.map +0 -1
- package/bundler/sandbox/policy.d.ts +0 -62
- package/bundler/sandbox/policy.d.ts.map +0 -1
- package/dependency/cdn-registry.d.ts +0 -98
- package/dependency/cdn-registry.d.ts.map +0 -1
- package/dependency/import-map.d.ts +0 -186
- package/dependency/import-map.d.ts.map +0 -1
- package/dependency/import-parser.d.ts +0 -82
- package/dependency/import-parser.d.ts.map +0 -1
- package/dependency/index.d.ts +0 -17
- package/dependency/index.d.ts.map +0 -1
- package/dependency/resolver.d.ts +0 -164
- package/dependency/resolver.d.ts.map +0 -1
- package/dependency/schemas.d.ts +0 -486
- package/dependency/schemas.d.ts.map +0 -1
- package/dependency/template-loader.d.ts +0 -204
- package/dependency/template-loader.d.ts.map +0 -1
- package/dependency/template-processor.d.ts +0 -118
- package/dependency/template-processor.d.ts.map +0 -1
- package/dependency/types.d.ts +0 -739
- package/dependency/types.d.ts.map +0 -1
- package/esm/adapters/index.d.ts +0 -13
- package/esm/adapters/index.d.ts.map +0 -1
- package/esm/adapters/index.js +0 -427
- package/esm/adapters/platform-meta.d.ts +0 -166
- package/esm/adapters/platform-meta.d.ts.map +0 -1
- package/esm/adapters/response-builder.d.ts +0 -108
- package/esm/adapters/response-builder.d.ts.map +0 -1
- package/esm/adapters/serving-mode.d.ts +0 -107
- package/esm/adapters/serving-mode.d.ts.map +0 -1
- package/esm/base-template/bridge.d.ts +0 -90
- package/esm/base-template/bridge.d.ts.map +0 -1
- package/esm/base-template/default-base-template.d.ts +0 -92
- package/esm/base-template/default-base-template.d.ts.map +0 -1
- package/esm/base-template/index.d.ts +0 -15
- package/esm/base-template/index.d.ts.map +0 -1
- package/esm/base-template/index.js +0 -1364
- package/esm/base-template/polyfills.d.ts +0 -31
- package/esm/base-template/polyfills.d.ts.map +0 -1
- package/esm/base-template/theme-styles.d.ts +0 -74
- package/esm/base-template/theme-styles.d.ts.map +0 -1
- package/esm/bridge/adapters/base-adapter.d.ts +0 -104
- package/esm/bridge/adapters/base-adapter.d.ts.map +0 -1
- package/esm/bridge/adapters/claude.adapter.d.ts +0 -67
- package/esm/bridge/adapters/claude.adapter.d.ts.map +0 -1
- package/esm/bridge/adapters/ext-apps.adapter.d.ts +0 -143
- package/esm/bridge/adapters/ext-apps.adapter.d.ts.map +0 -1
- package/esm/bridge/adapters/gemini.adapter.d.ts +0 -64
- package/esm/bridge/adapters/gemini.adapter.d.ts.map +0 -1
- package/esm/bridge/adapters/generic.adapter.d.ts +0 -56
- package/esm/bridge/adapters/generic.adapter.d.ts.map +0 -1
- package/esm/bridge/adapters/index.d.ts +0 -26
- package/esm/bridge/adapters/index.d.ts.map +0 -1
- package/esm/bridge/adapters/openai.adapter.d.ts +0 -65
- package/esm/bridge/adapters/openai.adapter.d.ts.map +0 -1
- package/esm/bridge/core/adapter-registry.d.ts +0 -122
- package/esm/bridge/core/adapter-registry.d.ts.map +0 -1
- package/esm/bridge/core/bridge-factory.d.ts +0 -199
- package/esm/bridge/core/bridge-factory.d.ts.map +0 -1
- package/esm/bridge/core/index.d.ts +0 -10
- package/esm/bridge/core/index.d.ts.map +0 -1
- package/esm/bridge/index.d.ts +0 -62
- package/esm/bridge/index.d.ts.map +0 -1
- package/esm/bridge/runtime/iife-generator.d.ts +0 -62
- package/esm/bridge/runtime/iife-generator.d.ts.map +0 -1
- package/esm/bridge/runtime/index.d.ts +0 -9
- package/esm/bridge/runtime/index.d.ts.map +0 -1
- package/esm/bridge/types.d.ts +0 -386
- package/esm/bridge/types.d.ts.map +0 -1
- package/esm/build/cdn-resources.d.ts +0 -243
- package/esm/build/cdn-resources.d.ts.map +0 -1
- package/esm/build/index.d.ts +0 -295
- package/esm/build/index.d.ts.map +0 -1
- package/esm/build/index.js +0 -7021
- package/esm/build/widget-manifest.d.ts +0 -362
- package/esm/build/widget-manifest.d.ts.map +0 -1
- package/esm/bundler/bundler.d.ts +0 -208
- package/esm/bundler/bundler.d.ts.map +0 -1
- package/esm/bundler/cache.d.ts +0 -173
- package/esm/bundler/cache.d.ts.map +0 -1
- package/esm/bundler/file-cache/component-builder.d.ts +0 -167
- package/esm/bundler/file-cache/component-builder.d.ts.map +0 -1
- package/esm/bundler/file-cache/hash-calculator.d.ts +0 -155
- package/esm/bundler/file-cache/hash-calculator.d.ts.map +0 -1
- package/esm/bundler/file-cache/index.d.ts +0 -12
- package/esm/bundler/file-cache/index.d.ts.map +0 -1
- package/esm/bundler/file-cache/storage/filesystem.d.ts +0 -149
- package/esm/bundler/file-cache/storage/filesystem.d.ts.map +0 -1
- package/esm/bundler/file-cache/storage/index.d.ts +0 -11
- package/esm/bundler/file-cache/storage/index.d.ts.map +0 -1
- package/esm/bundler/file-cache/storage/interface.d.ts +0 -152
- package/esm/bundler/file-cache/storage/interface.d.ts.map +0 -1
- package/esm/bundler/file-cache/storage/redis.d.ts +0 -139
- package/esm/bundler/file-cache/storage/redis.d.ts.map +0 -1
- package/esm/bundler/index.d.ts +0 -43
- package/esm/bundler/index.d.ts.map +0 -1
- package/esm/bundler/index.js +0 -4687
- package/esm/bundler/sandbox/enclave-adapter.d.ts +0 -121
- package/esm/bundler/sandbox/enclave-adapter.d.ts.map +0 -1
- package/esm/bundler/sandbox/executor.d.ts +0 -14
- package/esm/bundler/sandbox/executor.d.ts.map +0 -1
- package/esm/bundler/sandbox/policy.d.ts +0 -62
- package/esm/bundler/sandbox/policy.d.ts.map +0 -1
- package/esm/bundler/types.d.ts +0 -702
- package/esm/bundler/types.d.ts.map +0 -1
- package/esm/components/alert.d.ts +0 -66
- package/esm/components/alert.d.ts.map +0 -1
- package/esm/components/alert.schema.d.ts +0 -98
- package/esm/components/alert.schema.d.ts.map +0 -1
- package/esm/components/avatar.d.ts +0 -77
- package/esm/components/avatar.d.ts.map +0 -1
- package/esm/components/avatar.schema.d.ts +0 -170
- package/esm/components/avatar.schema.d.ts.map +0 -1
- package/esm/components/badge.d.ts +0 -64
- package/esm/components/badge.d.ts.map +0 -1
- package/esm/components/badge.schema.d.ts +0 -91
- package/esm/components/badge.schema.d.ts.map +0 -1
- package/esm/components/button.d.ts +0 -100
- package/esm/components/button.d.ts.map +0 -1
- package/esm/components/button.schema.d.ts +0 -120
- package/esm/components/button.schema.d.ts.map +0 -1
- package/esm/components/card.d.ts +0 -53
- package/esm/components/card.d.ts.map +0 -1
- package/esm/components/card.schema.d.ts +0 -93
- package/esm/components/card.schema.d.ts.map +0 -1
- package/esm/components/form.d.ts +0 -212
- package/esm/components/form.d.ts.map +0 -1
- package/esm/components/form.schema.d.ts +0 -365
- package/esm/components/form.schema.d.ts.map +0 -1
- package/esm/components/index.d.ts +0 -29
- package/esm/components/index.d.ts.map +0 -1
- package/esm/components/list.d.ts +0 -121
- package/esm/components/list.d.ts.map +0 -1
- package/esm/components/list.schema.d.ts +0 -129
- package/esm/components/list.schema.d.ts.map +0 -1
- package/esm/components/modal.d.ts +0 -100
- package/esm/components/modal.d.ts.map +0 -1
- package/esm/components/modal.schema.d.ts +0 -151
- package/esm/components/modal.schema.d.ts.map +0 -1
- package/esm/components/table.d.ts +0 -91
- package/esm/components/table.d.ts.map +0 -1
- package/esm/components/table.schema.d.ts +0 -123
- package/esm/components/table.schema.d.ts.map +0 -1
- package/esm/dependency/cdn-registry.d.ts +0 -98
- package/esm/dependency/cdn-registry.d.ts.map +0 -1
- package/esm/dependency/import-map.d.ts +0 -186
- package/esm/dependency/import-map.d.ts.map +0 -1
- package/esm/dependency/import-parser.d.ts +0 -82
- package/esm/dependency/import-parser.d.ts.map +0 -1
- package/esm/dependency/index.d.ts +0 -17
- package/esm/dependency/index.d.ts.map +0 -1
- package/esm/dependency/resolver.d.ts +0 -164
- package/esm/dependency/resolver.d.ts.map +0 -1
- package/esm/dependency/schemas.d.ts +0 -486
- package/esm/dependency/schemas.d.ts.map +0 -1
- package/esm/dependency/template-loader.d.ts +0 -204
- package/esm/dependency/template-loader.d.ts.map +0 -1
- package/esm/dependency/template-processor.d.ts +0 -118
- package/esm/dependency/template-processor.d.ts.map +0 -1
- package/esm/dependency/types.d.ts +0 -739
- package/esm/dependency/types.d.ts.map +0 -1
- package/esm/handlebars/expression-extractor.d.ts +0 -147
- package/esm/handlebars/expression-extractor.d.ts.map +0 -1
- package/esm/handlebars/helpers.d.ts +0 -339
- package/esm/handlebars/helpers.d.ts.map +0 -1
- package/esm/handlebars/index.d.ts +0 -195
- package/esm/handlebars/index.d.ts.map +0 -1
- package/esm/handlebars/index.js +0 -587
- package/esm/index.d.ts +0 -56
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -20511
- package/esm/layouts/base.d.ts +0 -86
- package/esm/layouts/base.d.ts.map +0 -1
- package/esm/layouts/index.d.ts +0 -8
- package/esm/layouts/index.d.ts.map +0 -1
- package/esm/layouts/index.js +0 -892
- package/esm/layouts/presets.d.ts +0 -134
- package/esm/layouts/presets.d.ts.map +0 -1
- package/esm/pages/consent.d.ts +0 -117
- package/esm/pages/consent.d.ts.map +0 -1
- package/esm/pages/error.d.ts +0 -101
- package/esm/pages/error.d.ts.map +0 -1
- package/esm/pages/index.d.ts +0 -9
- package/esm/pages/index.d.ts.map +0 -1
- package/esm/pages/index.js +0 -1563
- package/esm/react/Alert.d.ts +0 -102
- package/esm/react/Alert.d.ts.map +0 -1
- package/esm/react/Badge.d.ts +0 -101
- package/esm/react/Badge.d.ts.map +0 -1
- package/esm/react/Button.d.ts +0 -109
- package/esm/react/Button.d.ts.map +0 -1
- package/esm/react/Card.d.ts +0 -104
- package/esm/react/Card.d.ts.map +0 -1
- package/esm/react/hooks/context.d.ts +0 -179
- package/esm/react/hooks/context.d.ts.map +0 -1
- package/esm/react/hooks/index.d.ts +0 -42
- package/esm/react/hooks/index.d.ts.map +0 -1
- package/esm/react/hooks/tools.d.ts +0 -284
- package/esm/react/hooks/tools.d.ts.map +0 -1
- package/esm/react/index.d.ts +0 -81
- package/esm/react/index.d.ts.map +0 -1
- package/esm/react/types.d.ts +0 -106
- package/esm/react/types.d.ts.map +0 -1
- package/esm/react/utils.d.ts +0 -43
- package/esm/react/utils.d.ts.map +0 -1
- package/esm/registry/index.d.ts +0 -46
- package/esm/registry/index.d.ts.map +0 -1
- package/esm/registry/index.js +0 -6422
- package/esm/registry/render-template.d.ts +0 -91
- package/esm/registry/render-template.d.ts.map +0 -1
- package/esm/registry/tool-ui.registry.d.ts +0 -294
- package/esm/registry/tool-ui.registry.d.ts.map +0 -1
- package/esm/registry/uri-utils.d.ts +0 -56
- package/esm/registry/uri-utils.d.ts.map +0 -1
- package/esm/render/index.d.ts +0 -8
- package/esm/render/index.d.ts.map +0 -1
- package/esm/render/prerender.d.ts +0 -57
- package/esm/render/prerender.d.ts.map +0 -1
- package/esm/renderers/cache.d.ts +0 -145
- package/esm/renderers/cache.d.ts.map +0 -1
- package/esm/renderers/html.renderer.d.ts +0 -123
- package/esm/renderers/html.renderer.d.ts.map +0 -1
- package/esm/renderers/index.d.ts +0 -36
- package/esm/renderers/index.d.ts.map +0 -1
- package/esm/renderers/index.js +0 -1827
- package/esm/renderers/mdx.renderer.d.ts +0 -120
- package/esm/renderers/mdx.renderer.d.ts.map +0 -1
- package/esm/renderers/react.renderer.d.ts +0 -96
- package/esm/renderers/react.renderer.d.ts.map +0 -1
- package/esm/renderers/registry.d.ts +0 -134
- package/esm/renderers/registry.d.ts.map +0 -1
- package/esm/renderers/types.d.ts +0 -342
- package/esm/renderers/types.d.ts.map +0 -1
- package/esm/renderers/utils/detect.d.ts +0 -107
- package/esm/renderers/utils/detect.d.ts.map +0 -1
- package/esm/renderers/utils/hash.d.ts +0 -40
- package/esm/renderers/utils/hash.d.ts.map +0 -1
- package/esm/renderers/utils/index.d.ts +0 -9
- package/esm/renderers/utils/index.d.ts.map +0 -1
- package/esm/renderers/utils/transpiler.d.ts +0 -89
- package/esm/renderers/utils/transpiler.d.ts.map +0 -1
- package/esm/runtime/adapters/html.adapter.d.ts +0 -59
- package/esm/runtime/adapters/html.adapter.d.ts.map +0 -1
- package/esm/runtime/adapters/index.d.ts +0 -26
- package/esm/runtime/adapters/index.d.ts.map +0 -1
- package/esm/runtime/adapters/mdx.adapter.d.ts +0 -73
- package/esm/runtime/adapters/mdx.adapter.d.ts.map +0 -1
- package/esm/runtime/adapters/react.adapter.d.ts.map +0 -1
- package/esm/runtime/adapters/types.d.ts +0 -95
- package/esm/runtime/adapters/types.d.ts.map +0 -1
- package/esm/runtime/csp.d.ts +0 -48
- package/esm/runtime/csp.d.ts.map +0 -1
- package/esm/runtime/index.d.ts +0 -17
- package/esm/runtime/index.d.ts.map +0 -1
- package/esm/runtime/index.js +0 -5186
- package/esm/runtime/mcp-bridge.d.ts +0 -101
- package/esm/runtime/mcp-bridge.d.ts.map +0 -1
- package/esm/runtime/renderer-runtime.d.ts +0 -133
- package/esm/runtime/renderer-runtime.d.ts.map +0 -1
- package/esm/runtime/sanitizer.d.ts +0 -172
- package/esm/runtime/sanitizer.d.ts.map +0 -1
- package/esm/runtime/types.d.ts +0 -415
- package/esm/runtime/types.d.ts.map +0 -1
- package/esm/runtime/wrapper.d.ts +0 -421
- package/esm/runtime/wrapper.d.ts.map +0 -1
- package/esm/styles/index.d.ts +0 -8
- package/esm/styles/index.d.ts.map +0 -1
- package/esm/styles/index.js +0 -171
- package/esm/styles/variants.d.ts +0 -51
- package/esm/styles/variants.d.ts.map +0 -1
- package/esm/theme/cdn.d.ts +0 -195
- package/esm/theme/cdn.d.ts.map +0 -1
- package/esm/theme/index.d.ts +0 -18
- package/esm/theme/index.d.ts.map +0 -1
- package/esm/theme/index.js +0 -700
- package/esm/theme/platforms.d.ts +0 -107
- package/esm/theme/platforms.d.ts.map +0 -1
- package/esm/theme/presets/github-openai.d.ts +0 -50
- package/esm/theme/presets/github-openai.d.ts.map +0 -1
- package/esm/theme/presets/index.d.ts +0 -11
- package/esm/theme/presets/index.d.ts.map +0 -1
- package/esm/theme/theme.d.ts +0 -396
- package/esm/theme/theme.d.ts.map +0 -1
- package/esm/tool-template/builder.d.ts +0 -213
- package/esm/tool-template/builder.d.ts.map +0 -1
- package/esm/tool-template/index.d.ts +0 -16
- package/esm/tool-template/index.d.ts.map +0 -1
- package/esm/tool-template/index.js +0 -3515
- package/esm/types/index.d.ts +0 -14
- package/esm/types/index.d.ts.map +0 -1
- package/esm/types/index.js +0 -75
- package/esm/types/ui-config.d.ts +0 -639
- package/esm/types/ui-config.d.ts.map +0 -1
- package/esm/types/ui-runtime.d.ts +0 -1007
- package/esm/types/ui-runtime.d.ts.map +0 -1
- package/esm/typings/cache/cache-adapter.d.ts +0 -125
- package/esm/typings/cache/cache-adapter.d.ts.map +0 -1
- package/esm/typings/cache/index.d.ts +0 -10
- package/esm/typings/cache/index.d.ts.map +0 -1
- package/esm/typings/cache/memory-cache.d.ts +0 -92
- package/esm/typings/cache/memory-cache.d.ts.map +0 -1
- package/esm/typings/dts-parser.d.ts +0 -90
- package/esm/typings/dts-parser.d.ts.map +0 -1
- package/esm/typings/index.d.ts +0 -48
- package/esm/typings/index.d.ts.map +0 -1
- package/esm/typings/schemas.d.ts +0 -232
- package/esm/typings/schemas.d.ts.map +0 -1
- package/esm/typings/type-fetcher.d.ts +0 -89
- package/esm/typings/type-fetcher.d.ts.map +0 -1
- package/esm/typings/types.d.ts +0 -320
- package/esm/typings/types.d.ts.map +0 -1
- package/esm/universal/UniversalApp.d.ts +0 -108
- package/esm/universal/UniversalApp.d.ts.map +0 -1
- package/esm/universal/cached-runtime.d.ts +0 -115
- package/esm/universal/cached-runtime.d.ts.map +0 -1
- package/esm/universal/context.d.ts +0 -122
- package/esm/universal/context.d.ts.map +0 -1
- package/esm/universal/index.d.ts +0 -57
- package/esm/universal/index.d.ts.map +0 -1
- package/esm/universal/renderers/html.renderer.d.ts +0 -37
- package/esm/universal/renderers/html.renderer.d.ts.map +0 -1
- package/esm/universal/renderers/index.d.ts +0 -112
- package/esm/universal/renderers/index.d.ts.map +0 -1
- package/esm/universal/renderers/markdown.renderer.d.ts +0 -33
- package/esm/universal/renderers/markdown.renderer.d.ts.map +0 -1
- package/esm/universal/renderers/mdx.renderer.d.ts +0 -38
- package/esm/universal/renderers/mdx.renderer.d.ts.map +0 -1
- package/esm/universal/renderers/react.renderer.d.ts +0 -46
- package/esm/universal/renderers/react.renderer.d.ts.map +0 -1
- package/esm/universal/runtime-builder.d.ts +0 -33
- package/esm/universal/runtime-builder.d.ts.map +0 -1
- package/esm/universal/store.d.ts +0 -135
- package/esm/universal/store.d.ts.map +0 -1
- package/esm/universal/types.d.ts +0 -199
- package/esm/universal/types.d.ts.map +0 -1
- package/esm/utils/escape-html.d.ts +0 -58
- package/esm/utils/escape-html.d.ts.map +0 -1
- package/esm/utils/index.d.ts +0 -10
- package/esm/utils/index.d.ts.map +0 -1
- package/esm/utils/index.js +0 -40
- package/esm/utils/safe-stringify.d.ts +0 -30
- package/esm/utils/safe-stringify.d.ts.map +0 -1
- package/esm/validation/error-box.d.ts +0 -56
- package/esm/validation/error-box.d.ts.map +0 -1
- package/esm/validation/index.d.ts +0 -13
- package/esm/validation/index.d.ts.map +0 -1
- package/esm/validation/index.js +0 -562
- package/esm/validation/schema-paths.d.ts +0 -118
- package/esm/validation/schema-paths.d.ts.map +0 -1
- package/esm/validation/template-validator.d.ts +0 -143
- package/esm/validation/template-validator.d.ts.map +0 -1
- package/esm/validation/wrapper.d.ts +0 -97
- package/esm/validation/wrapper.d.ts.map +0 -1
- package/esm/web-components/core/attribute-parser.d.ts +0 -82
- package/esm/web-components/core/attribute-parser.d.ts.map +0 -1
- package/esm/web-components/core/base-element.d.ts +0 -197
- package/esm/web-components/core/base-element.d.ts.map +0 -1
- package/esm/web-components/core/index.d.ts +0 -9
- package/esm/web-components/core/index.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-alert.d.ts +0 -46
- package/esm/web-components/elements/fmcp-alert.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-badge.d.ts +0 -47
- package/esm/web-components/elements/fmcp-badge.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-button.d.ts +0 -117
- package/esm/web-components/elements/fmcp-button.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-card.d.ts +0 -53
- package/esm/web-components/elements/fmcp-card.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-input.d.ts +0 -96
- package/esm/web-components/elements/fmcp-input.d.ts.map +0 -1
- package/esm/web-components/elements/fmcp-select.d.ts +0 -100
- package/esm/web-components/elements/fmcp-select.d.ts.map +0 -1
- package/esm/web-components/elements/index.d.ts +0 -13
- package/esm/web-components/elements/index.d.ts.map +0 -1
- package/esm/web-components/index.d.ts +0 -50
- package/esm/web-components/index.d.ts.map +0 -1
- package/esm/web-components/register.d.ts +0 -57
- package/esm/web-components/register.d.ts.map +0 -1
- package/esm/web-components/types.d.ts +0 -122
- package/esm/web-components/types.d.ts.map +0 -1
- package/esm/widgets/index.d.ts +0 -8
- package/esm/widgets/index.d.ts.map +0 -1
- package/esm/widgets/index.js +0 -941
- package/esm/widgets/progress.d.ts +0 -133
- package/esm/widgets/progress.d.ts.map +0 -1
- package/esm/widgets/resource.d.ts +0 -163
- package/esm/widgets/resource.d.ts.map +0 -1
- package/handlebars/expression-extractor.d.ts +0 -147
- package/handlebars/expression-extractor.d.ts.map +0 -1
- package/handlebars/helpers.d.ts +0 -339
- package/handlebars/helpers.d.ts.map +0 -1
- package/handlebars/index.d.ts +0 -195
- package/handlebars/index.d.ts.map +0 -1
- package/handlebars/index.js +0 -666
- package/pages/consent.d.ts +0 -117
- package/pages/consent.d.ts.map +0 -1
- package/pages/error.d.ts +0 -101
- package/pages/error.d.ts.map +0 -1
- package/pages/index.d.ts +0 -9
- package/pages/index.d.ts.map +0 -1
- package/pages/index.js +0 -1602
- package/react/utils.d.ts +0 -43
- package/react/utils.d.ts.map +0 -1
- package/registry/index.d.ts +0 -46
- package/registry/index.d.ts.map +0 -1
- package/registry/index.js +0 -6465
- package/registry/render-template.d.ts +0 -91
- package/registry/render-template.d.ts.map +0 -1
- package/registry/tool-ui.registry.d.ts +0 -294
- package/registry/tool-ui.registry.d.ts.map +0 -1
- package/registry/uri-utils.d.ts +0 -56
- package/registry/uri-utils.d.ts.map +0 -1
- package/renderers/cache.d.ts +0 -145
- package/renderers/cache.d.ts.map +0 -1
- package/renderers/html.renderer.d.ts +0 -123
- package/renderers/html.renderer.d.ts.map +0 -1
- package/renderers/registry.d.ts +0 -134
- package/renderers/registry.d.ts.map +0 -1
- package/renderers/types.d.ts +0 -342
- package/renderers/types.d.ts.map +0 -1
- package/renderers/utils/detect.d.ts +0 -107
- package/renderers/utils/detect.d.ts.map +0 -1
- package/renderers/utils/hash.d.ts +0 -40
- package/renderers/utils/hash.d.ts.map +0 -1
- package/renderers/utils/index.d.ts +0 -9
- package/renderers/utils/index.d.ts.map +0 -1
- package/renderers/utils/transpiler.d.ts +0 -89
- package/renderers/utils/transpiler.d.ts.map +0 -1
- package/runtime/adapters/html.adapter.d.ts +0 -59
- package/runtime/adapters/html.adapter.d.ts.map +0 -1
- package/runtime/adapters/index.d.ts +0 -26
- package/runtime/adapters/index.d.ts.map +0 -1
- package/runtime/adapters/mdx.adapter.d.ts +0 -73
- package/runtime/adapters/mdx.adapter.d.ts.map +0 -1
- package/runtime/adapters/react.adapter.d.ts +0 -70
- package/runtime/adapters/react.adapter.d.ts.map +0 -1
- package/runtime/adapters/types.d.ts +0 -95
- package/runtime/adapters/types.d.ts.map +0 -1
- package/runtime/csp.d.ts +0 -48
- package/runtime/csp.d.ts.map +0 -1
- package/runtime/index.d.ts +0 -17
- package/runtime/index.d.ts.map +0 -1
- package/runtime/index.js +0 -5264
- package/runtime/mcp-bridge.d.ts +0 -101
- package/runtime/mcp-bridge.d.ts.map +0 -1
- package/runtime/renderer-runtime.d.ts +0 -133
- package/runtime/renderer-runtime.d.ts.map +0 -1
- package/runtime/sanitizer.d.ts +0 -172
- package/runtime/sanitizer.d.ts.map +0 -1
- package/runtime/types.d.ts +0 -415
- package/runtime/types.d.ts.map +0 -1
- package/runtime/wrapper.d.ts +0 -421
- package/runtime/wrapper.d.ts.map +0 -1
- package/styles/index.d.ts +0 -8
- package/styles/index.d.ts.map +0 -1
- package/styles/index.js +0 -222
- package/styles/variants.d.ts +0 -51
- package/styles/variants.d.ts.map +0 -1
- package/theme/cdn.d.ts +0 -195
- package/theme/cdn.d.ts.map +0 -1
- package/theme/index.d.ts +0 -18
- package/theme/index.d.ts.map +0 -1
- package/theme/index.js +0 -757
- package/theme/platforms.d.ts +0 -107
- package/theme/platforms.d.ts.map +0 -1
- package/theme/presets/github-openai.d.ts +0 -50
- package/theme/presets/github-openai.d.ts.map +0 -1
- package/theme/presets/index.d.ts +0 -11
- package/theme/presets/index.d.ts.map +0 -1
- package/theme/theme.d.ts +0 -396
- package/theme/theme.d.ts.map +0 -1
- package/tool-template/builder.d.ts +0 -213
- package/tool-template/builder.d.ts.map +0 -1
- package/tool-template/index.d.ts +0 -16
- package/tool-template/index.d.ts.map +0 -1
- package/tool-template/index.js +0 -3559
- package/types/index.d.ts +0 -14
- package/types/index.d.ts.map +0 -1
- package/types/index.js +0 -108
- package/types/ui-config.d.ts +0 -639
- package/types/ui-config.d.ts.map +0 -1
- package/types/ui-runtime.d.ts +0 -1007
- package/types/ui-runtime.d.ts.map +0 -1
- package/typings/cache/cache-adapter.d.ts +0 -125
- package/typings/cache/cache-adapter.d.ts.map +0 -1
- package/typings/cache/index.d.ts +0 -10
- package/typings/cache/index.d.ts.map +0 -1
- package/typings/cache/memory-cache.d.ts +0 -92
- package/typings/cache/memory-cache.d.ts.map +0 -1
- package/typings/dts-parser.d.ts +0 -90
- package/typings/dts-parser.d.ts.map +0 -1
- package/typings/index.d.ts +0 -48
- package/typings/index.d.ts.map +0 -1
- package/typings/schemas.d.ts +0 -232
- package/typings/schemas.d.ts.map +0 -1
- package/typings/type-fetcher.d.ts +0 -89
- package/typings/type-fetcher.d.ts.map +0 -1
- package/typings/types.d.ts +0 -320
- package/typings/types.d.ts.map +0 -1
- package/utils/escape-html.d.ts +0 -58
- package/utils/escape-html.d.ts.map +0 -1
- package/utils/index.d.ts +0 -10
- package/utils/index.d.ts.map +0 -1
- package/utils/index.js +0 -70
- package/utils/safe-stringify.d.ts +0 -30
- package/utils/safe-stringify.d.ts.map +0 -1
- package/validation/error-box.d.ts +0 -56
- package/validation/error-box.d.ts.map +0 -1
- package/validation/index.d.ts +0 -13
- package/validation/index.d.ts.map +0 -1
- package/validation/index.js +0 -603
- package/validation/schema-paths.d.ts +0 -118
- package/validation/schema-paths.d.ts.map +0 -1
- package/validation/template-validator.d.ts +0 -143
- package/validation/template-validator.d.ts.map +0 -1
- package/validation/wrapper.d.ts +0 -97
- package/validation/wrapper.d.ts.map +0 -1
- package/widgets/index.d.ts +0 -8
- package/widgets/index.d.ts.map +0 -1
- package/widgets/index.js +0 -978
- package/widgets/progress.d.ts +0 -133
- package/widgets/progress.d.ts.map +0 -1
- package/widgets/resource.d.ts +0 -163
- package/widgets/resource.d.ts.map +0 -1
- /package/esm/render/{index.js → index.mjs} +0 -0
|
@@ -0,0 +1,1951 @@
|
|
|
1
|
+
// libs/ui/src/universal/types.ts
|
|
2
|
+
var DEFAULT_FRONTMCP_STATE = {
|
|
3
|
+
toolName: null,
|
|
4
|
+
input: null,
|
|
5
|
+
output: null,
|
|
6
|
+
content: null,
|
|
7
|
+
structuredContent: null,
|
|
8
|
+
loading: false,
|
|
9
|
+
error: null
|
|
10
|
+
};
|
|
11
|
+
var UNIVERSAL_CDN = {
|
|
12
|
+
esm: {
|
|
13
|
+
reactMarkdown: "https://esm.sh/react-markdown@9",
|
|
14
|
+
mdxReact: "https://esm.sh/@mdx-js/react@3",
|
|
15
|
+
remarkGfm: "https://esm.sh/remark-gfm@4"
|
|
16
|
+
}
|
|
17
|
+
// Note: These libraries are not available on cdnjs
|
|
18
|
+
// For Claude, we use inline implementations
|
|
19
|
+
};
|
|
20
|
+
function detectContentType(source) {
|
|
21
|
+
if (typeof source === "function") {
|
|
22
|
+
return "react";
|
|
23
|
+
}
|
|
24
|
+
if (typeof source !== "string") {
|
|
25
|
+
return "html";
|
|
26
|
+
}
|
|
27
|
+
const hasModuleSyntax = /^import\s+/m.test(source) || /^export\s+(default\s+)?/m.test(source) || /^const\s+\w+\s*=\s*\([^)]*\)\s*=>/m.test(source) || // Arrow function components
|
|
28
|
+
/^function\s+\w+\s*\(/m.test(source);
|
|
29
|
+
const hasJsxTags = /<[A-Z][a-zA-Z]*/.test(source);
|
|
30
|
+
const hasMarkdown = /^#{1,6}\s/m.test(source) || /^\*\s/m.test(source) || /^-\s/m.test(source) || /^\d+\.\s/m.test(source);
|
|
31
|
+
if (hasModuleSyntax && hasJsxTags) {
|
|
32
|
+
return "react";
|
|
33
|
+
}
|
|
34
|
+
if (hasJsxTags && hasMarkdown && !hasModuleSyntax) {
|
|
35
|
+
return "mdx";
|
|
36
|
+
}
|
|
37
|
+
if (hasMarkdown || /\*\*[^*]+\*\*/.test(source) || /\[[^\]]+\]\([^)]+\)/.test(source)) {
|
|
38
|
+
return "markdown";
|
|
39
|
+
}
|
|
40
|
+
if (hasJsxTags && !hasModuleSyntax) {
|
|
41
|
+
return "mdx";
|
|
42
|
+
}
|
|
43
|
+
return "html";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// libs/ui/src/universal/store.ts
|
|
47
|
+
import { useSyncExternalStore } from "react";
|
|
48
|
+
function createFrontMCPStore(initialState) {
|
|
49
|
+
let state = {
|
|
50
|
+
...DEFAULT_FRONTMCP_STATE,
|
|
51
|
+
...initialState
|
|
52
|
+
};
|
|
53
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
54
|
+
const getState = () => state;
|
|
55
|
+
const getServerState = () => state;
|
|
56
|
+
const setState = (partial) => {
|
|
57
|
+
const hasChanged = Object.keys(partial).some(
|
|
58
|
+
(key) => partial[key] !== state[key]
|
|
59
|
+
);
|
|
60
|
+
if (hasChanged) {
|
|
61
|
+
state = { ...state, ...partial };
|
|
62
|
+
listeners.forEach((listener) => listener());
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const subscribe = (listener) => {
|
|
66
|
+
listeners.add(listener);
|
|
67
|
+
return () => {
|
|
68
|
+
listeners.delete(listener);
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
const reset = () => {
|
|
72
|
+
setState({
|
|
73
|
+
...DEFAULT_FRONTMCP_STATE,
|
|
74
|
+
...initialState
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
getState,
|
|
79
|
+
getServerState,
|
|
80
|
+
setState,
|
|
81
|
+
subscribe,
|
|
82
|
+
reset
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
var globalStore = null;
|
|
86
|
+
function getGlobalStore() {
|
|
87
|
+
if (!globalStore) {
|
|
88
|
+
globalStore = createFrontMCPStore();
|
|
89
|
+
}
|
|
90
|
+
return globalStore;
|
|
91
|
+
}
|
|
92
|
+
function setGlobalStore(store) {
|
|
93
|
+
globalStore = store;
|
|
94
|
+
}
|
|
95
|
+
function resetGlobalStore(initialState) {
|
|
96
|
+
globalStore = createFrontMCPStore(initialState);
|
|
97
|
+
}
|
|
98
|
+
function useFrontMCPStore(store) {
|
|
99
|
+
const targetStore = store ?? getGlobalStore();
|
|
100
|
+
return useSyncExternalStore(targetStore.subscribe, targetStore.getState, targetStore.getServerState);
|
|
101
|
+
}
|
|
102
|
+
function useToolOutput(store) {
|
|
103
|
+
const state = useFrontMCPStore(store);
|
|
104
|
+
return state.output;
|
|
105
|
+
}
|
|
106
|
+
function useToolInput(store) {
|
|
107
|
+
const state = useFrontMCPStore(store);
|
|
108
|
+
return state.input;
|
|
109
|
+
}
|
|
110
|
+
function useContent(store) {
|
|
111
|
+
const state = useFrontMCPStore(store);
|
|
112
|
+
return state.content;
|
|
113
|
+
}
|
|
114
|
+
function useToolName(store) {
|
|
115
|
+
const state = useFrontMCPStore(store);
|
|
116
|
+
return state.toolName;
|
|
117
|
+
}
|
|
118
|
+
function useLoadingState(store) {
|
|
119
|
+
const state = useFrontMCPStore(store);
|
|
120
|
+
return { loading: state.loading, error: state.error };
|
|
121
|
+
}
|
|
122
|
+
function initializeStoreFromWindow(store) {
|
|
123
|
+
const targetStore = store ?? getGlobalStore();
|
|
124
|
+
const windowData = typeof window !== "undefined" ? window.__frontmcp : void 0;
|
|
125
|
+
if (windowData?.context) {
|
|
126
|
+
targetStore.setState({
|
|
127
|
+
toolName: windowData.context.toolName ?? null,
|
|
128
|
+
input: windowData.context.toolInput ?? null,
|
|
129
|
+
output: windowData.context.toolOutput ?? null,
|
|
130
|
+
structuredContent: windowData.context.structuredContent ?? null,
|
|
131
|
+
loading: false,
|
|
132
|
+
error: null
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function createStoreSelector(selector) {
|
|
137
|
+
return (store) => {
|
|
138
|
+
const state = useFrontMCPStore(store);
|
|
139
|
+
return selector(state);
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// libs/ui/src/universal/context.tsx
|
|
144
|
+
import { createContext, useContext, useEffect, useMemo, useRef } from "react";
|
|
145
|
+
import { jsx } from "react/jsx-runtime";
|
|
146
|
+
var FrontMCPContext = createContext(null);
|
|
147
|
+
var ComponentsContext = createContext({});
|
|
148
|
+
function FrontMCPProvider({ store, initialState, children }) {
|
|
149
|
+
const storeRef = useRef(null);
|
|
150
|
+
if (!storeRef.current) {
|
|
151
|
+
storeRef.current = store ?? createFrontMCPStore(initialState);
|
|
152
|
+
}
|
|
153
|
+
const actualStore = storeRef.current;
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
if (typeof window !== "undefined" && !store) {
|
|
156
|
+
initializeStoreFromWindow(actualStore);
|
|
157
|
+
}
|
|
158
|
+
}, [actualStore, store]);
|
|
159
|
+
return /* @__PURE__ */ jsx(FrontMCPContext.Provider, { value: actualStore, children });
|
|
160
|
+
}
|
|
161
|
+
function ComponentsProvider({ components, children }) {
|
|
162
|
+
const parentComponents = useContext(ComponentsContext);
|
|
163
|
+
const mergedComponents = useMemo(
|
|
164
|
+
() => ({
|
|
165
|
+
...parentComponents,
|
|
166
|
+
...components
|
|
167
|
+
}),
|
|
168
|
+
[parentComponents, components]
|
|
169
|
+
);
|
|
170
|
+
return /* @__PURE__ */ jsx(ComponentsContext.Provider, { value: mergedComponents, children });
|
|
171
|
+
}
|
|
172
|
+
function useFrontMCPContext() {
|
|
173
|
+
const store = useContext(FrontMCPContext);
|
|
174
|
+
if (!store) {
|
|
175
|
+
throw new Error("useFrontMCPContext must be used within a FrontMCPProvider");
|
|
176
|
+
}
|
|
177
|
+
return store;
|
|
178
|
+
}
|
|
179
|
+
function useComponents() {
|
|
180
|
+
return useContext(ComponentsContext);
|
|
181
|
+
}
|
|
182
|
+
function useFrontMCPContextSafe() {
|
|
183
|
+
return useContext(FrontMCPContext);
|
|
184
|
+
}
|
|
185
|
+
function UniversalProvider({
|
|
186
|
+
store,
|
|
187
|
+
initialState,
|
|
188
|
+
components = {},
|
|
189
|
+
children
|
|
190
|
+
}) {
|
|
191
|
+
return /* @__PURE__ */ jsx(FrontMCPProvider, { store, initialState, children: /* @__PURE__ */ jsx(ComponentsProvider, { components, children }) });
|
|
192
|
+
}
|
|
193
|
+
function withFrontMCP(Component) {
|
|
194
|
+
const WrappedComponent = (props) => {
|
|
195
|
+
const store = useFrontMCPContext();
|
|
196
|
+
const state = store.getState();
|
|
197
|
+
return /* @__PURE__ */ jsx(Component, { ...props, state });
|
|
198
|
+
};
|
|
199
|
+
WrappedComponent.displayName = `withFrontMCP(${Component.displayName || Component.name || "Component"})`;
|
|
200
|
+
return WrappedComponent;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// libs/ui/src/universal/renderers/html.renderer.ts
|
|
204
|
+
import React2 from "react";
|
|
205
|
+
var htmlRenderer = {
|
|
206
|
+
type: "html",
|
|
207
|
+
priority: 0,
|
|
208
|
+
// Lowest priority (fallback)
|
|
209
|
+
canHandle(content) {
|
|
210
|
+
return content.type === "html" || typeof content.source === "string";
|
|
211
|
+
},
|
|
212
|
+
render(content, _context) {
|
|
213
|
+
const source = content.source;
|
|
214
|
+
if (typeof source !== "string") {
|
|
215
|
+
return React2.createElement("div", { className: "frontmcp-error" }, "HTML renderer requires a string source");
|
|
216
|
+
}
|
|
217
|
+
return React2.createElement("div", {
|
|
218
|
+
className: "frontmcp-html-content",
|
|
219
|
+
dangerouslySetInnerHTML: { __html: source }
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
function sanitizeHtml(html) {
|
|
224
|
+
let sanitized = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "");
|
|
225
|
+
sanitized = sanitized.replace(/\s+on\w+\s*=\s*["'][^"']*["']/gi, "");
|
|
226
|
+
sanitized = sanitized.replace(/\s+on\w+\s*=\s*[^\s>]*/gi, "");
|
|
227
|
+
sanitized = sanitized.replace(/href\s*=\s*["']javascript:[^"']*["']/gi, 'href="#"');
|
|
228
|
+
return sanitized;
|
|
229
|
+
}
|
|
230
|
+
var safeHtmlRenderer = {
|
|
231
|
+
type: "html",
|
|
232
|
+
priority: 0,
|
|
233
|
+
canHandle(content) {
|
|
234
|
+
return content.type === "html" && typeof content.source === "string";
|
|
235
|
+
},
|
|
236
|
+
render(content, _context) {
|
|
237
|
+
const source = content.source;
|
|
238
|
+
if (typeof source !== "string") {
|
|
239
|
+
return React2.createElement("div", { className: "frontmcp-error" }, "HTML renderer requires a string source");
|
|
240
|
+
}
|
|
241
|
+
const sanitized = sanitizeHtml(source);
|
|
242
|
+
return React2.createElement("div", {
|
|
243
|
+
className: "frontmcp-html-content",
|
|
244
|
+
dangerouslySetInnerHTML: { __html: sanitized }
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// libs/ui/src/universal/renderers/markdown.renderer.ts
|
|
250
|
+
import React3 from "react";
|
|
251
|
+
import { escapeHtml } from "@frontmcp/uipack/utils";
|
|
252
|
+
function isSafeUrl(url) {
|
|
253
|
+
if (!url) return false;
|
|
254
|
+
const lower = url.toLowerCase().trim();
|
|
255
|
+
return lower.startsWith("http://") || lower.startsWith("https://") || lower.startsWith("/") || lower.startsWith("#") || lower.startsWith("mailto:") || lower.startsWith("tel:");
|
|
256
|
+
}
|
|
257
|
+
function getReactMarkdown() {
|
|
258
|
+
if (typeof window !== "undefined" && window.ReactMarkdown) {
|
|
259
|
+
return window.ReactMarkdown;
|
|
260
|
+
}
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
function parseMarkdownToHtml(markdown) {
|
|
264
|
+
let html = escapeHtml(markdown);
|
|
265
|
+
html = html.replace(/^######\s+(.*)$/gm, "<h6>$1</h6>");
|
|
266
|
+
html = html.replace(/^#####\s+(.*)$/gm, "<h5>$1</h5>");
|
|
267
|
+
html = html.replace(/^####\s+(.*)$/gm, "<h4>$1</h4>");
|
|
268
|
+
html = html.replace(/^###\s+(.*)$/gm, "<h3>$1</h3>");
|
|
269
|
+
html = html.replace(/^##\s+(.*)$/gm, "<h2>$1</h2>");
|
|
270
|
+
html = html.replace(/^#\s+(.*)$/gm, "<h1>$1</h1>");
|
|
271
|
+
html = html.replace(/\*\*\*(.+?)\*\*\*/g, "<strong><em>$1</em></strong>");
|
|
272
|
+
html = html.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>");
|
|
273
|
+
html = html.replace(/\*(.+?)\*/g, "<em>$1</em>");
|
|
274
|
+
html = html.replace(/___(.+?)___/g, "<strong><em>$1</em></strong>");
|
|
275
|
+
html = html.replace(/__(.+?)__/g, "<strong>$1</strong>");
|
|
276
|
+
html = html.replace(/_(.+?)_/g, "<em>$1</em>");
|
|
277
|
+
html = html.replace(/`([^`]+)`/g, "<code>$1</code>");
|
|
278
|
+
html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, text, url) => {
|
|
279
|
+
return isSafeUrl(url) ? `<a href="${url}">${text}</a>` : text;
|
|
280
|
+
});
|
|
281
|
+
html = html.replace(/^[-*]\s+(.*)$/gm, "<li>$1</li>");
|
|
282
|
+
html = html.replace(/(<li>.*<\/li>\n?)+/g, "<ul>$&</ul>");
|
|
283
|
+
html = html.replace(/^\d+\.\s+(.*)$/gm, "<li>$1</li>");
|
|
284
|
+
html = html.replace(/\n\n+/g, "</p><p>");
|
|
285
|
+
html = "<p>" + html + "</p>";
|
|
286
|
+
html = html.replace(/<p>\s*<\/p>/g, "");
|
|
287
|
+
html = html.replace(/<p>\s*(<h[1-6]>)/g, "$1");
|
|
288
|
+
html = html.replace(/(<\/h[1-6]>)\s*<\/p>/g, "$1");
|
|
289
|
+
html = html.replace(/<p>\s*(<ul>)/g, "$1");
|
|
290
|
+
html = html.replace(/(<\/ul>)\s*<\/p>/g, "$1");
|
|
291
|
+
return html;
|
|
292
|
+
}
|
|
293
|
+
var markdownRenderer = {
|
|
294
|
+
type: "markdown",
|
|
295
|
+
priority: 10,
|
|
296
|
+
// Medium priority
|
|
297
|
+
canHandle(content) {
|
|
298
|
+
if (content.type === "markdown") {
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
if (typeof content.source === "string") {
|
|
302
|
+
const source = content.source;
|
|
303
|
+
const hasMarkdown = /^#{1,6}\s/m.test(source) || // Headers
|
|
304
|
+
/^\*\s/m.test(source) || // Unordered list
|
|
305
|
+
/^-\s/m.test(source) || // Unordered list
|
|
306
|
+
/^\d+\.\s/m.test(source) || // Ordered list
|
|
307
|
+
/\*\*[^*]+\*\*/.test(source) || // Bold
|
|
308
|
+
/\[[^\]]+\]\([^)]+\)/.test(source);
|
|
309
|
+
const hasJsx = /<[A-Z][a-zA-Z]*/.test(source);
|
|
310
|
+
return hasMarkdown && !hasJsx;
|
|
311
|
+
}
|
|
312
|
+
return false;
|
|
313
|
+
},
|
|
314
|
+
render(content, context) {
|
|
315
|
+
const source = content.source;
|
|
316
|
+
if (typeof source !== "string") {
|
|
317
|
+
return React3.createElement("div", { className: "frontmcp-error" }, "Markdown renderer requires a string source");
|
|
318
|
+
}
|
|
319
|
+
const ReactMarkdown = getReactMarkdown();
|
|
320
|
+
if (ReactMarkdown) {
|
|
321
|
+
const components = {
|
|
322
|
+
...context.components,
|
|
323
|
+
...content.components
|
|
324
|
+
};
|
|
325
|
+
return React3.createElement(ReactMarkdown, { components }, source);
|
|
326
|
+
}
|
|
327
|
+
const html = parseMarkdownToHtml(source);
|
|
328
|
+
return React3.createElement("div", {
|
|
329
|
+
className: "frontmcp-markdown-content prose",
|
|
330
|
+
dangerouslySetInnerHTML: { __html: html }
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
function createMarkdownRenderer(defaultComponents) {
|
|
335
|
+
return {
|
|
336
|
+
...markdownRenderer,
|
|
337
|
+
render(content, context) {
|
|
338
|
+
const enhancedContext = {
|
|
339
|
+
...context,
|
|
340
|
+
components: {
|
|
341
|
+
...defaultComponents,
|
|
342
|
+
...context.components
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
return markdownRenderer.render(content, enhancedContext);
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// libs/ui/src/universal/renderers/react.renderer.ts
|
|
351
|
+
import React4 from "react";
|
|
352
|
+
var reactRenderer = {
|
|
353
|
+
type: "react",
|
|
354
|
+
priority: 30,
|
|
355
|
+
// Highest priority for function components
|
|
356
|
+
canHandle(content) {
|
|
357
|
+
return content.type === "react" || typeof content.source === "function";
|
|
358
|
+
},
|
|
359
|
+
render(content, context) {
|
|
360
|
+
const Component = content.source;
|
|
361
|
+
if (typeof Component !== "function") {
|
|
362
|
+
return React4.createElement("div", {
|
|
363
|
+
className: "frontmcp-error",
|
|
364
|
+
children: "React renderer requires a component function"
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
const props = {
|
|
368
|
+
// Default props from context
|
|
369
|
+
output: context.output,
|
|
370
|
+
input: context.input,
|
|
371
|
+
state: context.state,
|
|
372
|
+
// Override with content-specific props
|
|
373
|
+
...content.props
|
|
374
|
+
};
|
|
375
|
+
return React4.createElement(Component, props);
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
function isReactComponent(value) {
|
|
379
|
+
if (typeof value !== "function") {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
const fn = value;
|
|
383
|
+
const typeofSymbol = fn.$$typeof;
|
|
384
|
+
if (typeofSymbol) {
|
|
385
|
+
const symbolString = typeofSymbol.toString();
|
|
386
|
+
return symbolString.includes("react.memo") || symbolString.includes("react.forward_ref") || symbolString.includes("react.lazy");
|
|
387
|
+
}
|
|
388
|
+
if (fn.prototype?.isReactComponent) {
|
|
389
|
+
return true;
|
|
390
|
+
}
|
|
391
|
+
if (fn.name && /^[A-Z]/.test(fn.name)) {
|
|
392
|
+
return true;
|
|
393
|
+
}
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// libs/ui/src/universal/renderers/mdx.renderer.ts
|
|
398
|
+
import React5 from "react";
|
|
399
|
+
import { escapeHtml as escapeHtml2 } from "@frontmcp/uipack/utils";
|
|
400
|
+
function getMDXRuntime() {
|
|
401
|
+
if (typeof window !== "undefined" && window.MDXProvider) {
|
|
402
|
+
return { MDXProvider: window.MDXProvider };
|
|
403
|
+
}
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
function containsMdxSyntax(source) {
|
|
407
|
+
if (/<[A-Z][a-zA-Z]*/.test(source)) {
|
|
408
|
+
return true;
|
|
409
|
+
}
|
|
410
|
+
if (/\{[^}"']+\}/.test(source)) {
|
|
411
|
+
return true;
|
|
412
|
+
}
|
|
413
|
+
if (/^(import|export)\s/m.test(source)) {
|
|
414
|
+
return true;
|
|
415
|
+
}
|
|
416
|
+
if (/\s(className|onClick|onChange)=/.test(source)) {
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
var mdxRenderer = {
|
|
422
|
+
type: "mdx",
|
|
423
|
+
priority: 20,
|
|
424
|
+
// Higher than markdown, lower than React
|
|
425
|
+
canHandle(content) {
|
|
426
|
+
if (content.type === "mdx") {
|
|
427
|
+
return true;
|
|
428
|
+
}
|
|
429
|
+
if (typeof content.source === "string") {
|
|
430
|
+
const source = content.source;
|
|
431
|
+
const hasMarkdown = /^#{1,6}\s/m.test(source) || /^\*\s/m.test(source) || /^-\s/m.test(source) || /^\d+\.\s/m.test(source);
|
|
432
|
+
return hasMarkdown && containsMdxSyntax(source);
|
|
433
|
+
}
|
|
434
|
+
return false;
|
|
435
|
+
},
|
|
436
|
+
render(content, context) {
|
|
437
|
+
const source = content.source;
|
|
438
|
+
if (typeof source !== "string") {
|
|
439
|
+
return React5.createElement("div", { className: "frontmcp-error" }, "MDX renderer requires a string source");
|
|
440
|
+
}
|
|
441
|
+
const mdxRuntime = getMDXRuntime();
|
|
442
|
+
if (!mdxRuntime) {
|
|
443
|
+
console.warn("[FrontMCP] MDX runtime not available. Content will be displayed as-is.");
|
|
444
|
+
const escapedContent = escapeHtml2(source).replace(/\n/g, "<br>");
|
|
445
|
+
return React5.createElement(
|
|
446
|
+
"div",
|
|
447
|
+
{ className: "frontmcp-mdx-fallback" },
|
|
448
|
+
React5.createElement(
|
|
449
|
+
"div",
|
|
450
|
+
{
|
|
451
|
+
key: "warning",
|
|
452
|
+
className: "frontmcp-warning bg-yellow-50 border border-yellow-200 rounded p-2 mb-4 text-sm text-yellow-800"
|
|
453
|
+
},
|
|
454
|
+
"MDX rendering is not available on this platform. Content is shown as raw text."
|
|
455
|
+
),
|
|
456
|
+
React5.createElement("pre", {
|
|
457
|
+
key: "content",
|
|
458
|
+
className: "bg-gray-100 p-4 rounded overflow-auto",
|
|
459
|
+
dangerouslySetInnerHTML: { __html: escapedContent }
|
|
460
|
+
})
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
const components = {
|
|
464
|
+
...context.components,
|
|
465
|
+
...content.components
|
|
466
|
+
};
|
|
467
|
+
if (typeof content.compiledContent === "function") {
|
|
468
|
+
const CompiledContent = content.compiledContent;
|
|
469
|
+
return React5.createElement(
|
|
470
|
+
mdxRuntime.MDXProvider,
|
|
471
|
+
{ components },
|
|
472
|
+
React5.createElement(CompiledContent, {
|
|
473
|
+
output: context.output,
|
|
474
|
+
input: context.input
|
|
475
|
+
})
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
console.warn("[FrontMCP] MDX content needs to be pre-compiled. Raw MDX string rendering is not supported.");
|
|
479
|
+
return React5.createElement(
|
|
480
|
+
"div",
|
|
481
|
+
{ className: "frontmcp-mdx-uncompiled" },
|
|
482
|
+
React5.createElement("pre", { className: "bg-gray-100 p-4 rounded overflow-auto text-sm" }, source)
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
function isMdxSupported() {
|
|
487
|
+
return getMDXRuntime() !== null;
|
|
488
|
+
}
|
|
489
|
+
function createMdxRenderer(defaultComponents) {
|
|
490
|
+
return {
|
|
491
|
+
...mdxRenderer,
|
|
492
|
+
render(content, context) {
|
|
493
|
+
const enhancedContext = {
|
|
494
|
+
...context,
|
|
495
|
+
components: {
|
|
496
|
+
...defaultComponents,
|
|
497
|
+
...context.components
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
return mdxRenderer.render(content, enhancedContext);
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// libs/ui/src/universal/renderers/index.ts
|
|
506
|
+
var RendererRegistry = class {
|
|
507
|
+
renderers = /* @__PURE__ */ new Map();
|
|
508
|
+
sortedRenderers = [];
|
|
509
|
+
constructor() {
|
|
510
|
+
this.register(htmlRenderer);
|
|
511
|
+
this.register(markdownRenderer);
|
|
512
|
+
this.register(reactRenderer);
|
|
513
|
+
this.register(mdxRenderer);
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Register a renderer.
|
|
517
|
+
* Renderers are sorted by priority (highest first) for auto-detection.
|
|
518
|
+
*/
|
|
519
|
+
register(renderer) {
|
|
520
|
+
this.renderers.set(renderer.type, renderer);
|
|
521
|
+
this.updateSortedList();
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Unregister a renderer by type.
|
|
525
|
+
*/
|
|
526
|
+
unregister(type) {
|
|
527
|
+
const removed = this.renderers.delete(type);
|
|
528
|
+
if (removed) {
|
|
529
|
+
this.updateSortedList();
|
|
530
|
+
}
|
|
531
|
+
return removed;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Get a renderer by type.
|
|
535
|
+
*/
|
|
536
|
+
get(type) {
|
|
537
|
+
return this.renderers.get(type);
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Check if a renderer type is registered.
|
|
541
|
+
*/
|
|
542
|
+
has(type) {
|
|
543
|
+
return this.renderers.has(type);
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Get all registered renderer types.
|
|
547
|
+
*/
|
|
548
|
+
getTypes() {
|
|
549
|
+
return Array.from(this.renderers.keys());
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Auto-detect the best renderer for content.
|
|
553
|
+
*
|
|
554
|
+
* Checks renderers in priority order (highest first).
|
|
555
|
+
* Falls back to HTML renderer if no match.
|
|
556
|
+
*/
|
|
557
|
+
detect(content) {
|
|
558
|
+
if (content.type) {
|
|
559
|
+
const explicit = this.renderers.get(content.type);
|
|
560
|
+
if (explicit) {
|
|
561
|
+
return explicit;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
for (const renderer of this.sortedRenderers) {
|
|
565
|
+
if (renderer.canHandle(content)) {
|
|
566
|
+
return renderer;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
return htmlRenderer;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Render content using auto-detection.
|
|
573
|
+
*/
|
|
574
|
+
render(content, context) {
|
|
575
|
+
const renderer = this.detect(content);
|
|
576
|
+
return renderer.render(content, context);
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Render with a specific renderer type.
|
|
580
|
+
*/
|
|
581
|
+
renderWith(type, content, context) {
|
|
582
|
+
const renderer = this.renderers.get(type);
|
|
583
|
+
if (!renderer) {
|
|
584
|
+
throw new Error(`Renderer '${type}' not registered`);
|
|
585
|
+
}
|
|
586
|
+
return renderer.render(content, context);
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Get registry statistics.
|
|
590
|
+
*/
|
|
591
|
+
getStats() {
|
|
592
|
+
return {
|
|
593
|
+
registeredTypes: this.getTypes(),
|
|
594
|
+
priorityOrder: this.sortedRenderers.map((r) => ({
|
|
595
|
+
type: r.type,
|
|
596
|
+
priority: r.priority
|
|
597
|
+
}))
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Update the sorted renderer list by priority.
|
|
602
|
+
*/
|
|
603
|
+
updateSortedList() {
|
|
604
|
+
this.sortedRenderers = Array.from(this.renderers.values()).sort((a, b) => b.priority - a.priority);
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
var rendererRegistry = new RendererRegistry();
|
|
608
|
+
function detectRenderer(content) {
|
|
609
|
+
return rendererRegistry.detect(content);
|
|
610
|
+
}
|
|
611
|
+
function renderContent(content, context) {
|
|
612
|
+
return rendererRegistry.render(content, context);
|
|
613
|
+
}
|
|
614
|
+
function createContent(source, options) {
|
|
615
|
+
return {
|
|
616
|
+
type: options?.type ?? detectContentType(source),
|
|
617
|
+
source,
|
|
618
|
+
props: options?.props,
|
|
619
|
+
components: options?.components
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// libs/ui/src/universal/UniversalApp.tsx
|
|
624
|
+
import React6 from "react";
|
|
625
|
+
import { escapeHtml as escapeHtml3 } from "@frontmcp/uipack/utils";
|
|
626
|
+
function LoadingSpinner() {
|
|
627
|
+
return React6.createElement(
|
|
628
|
+
"div",
|
|
629
|
+
{ className: "frontmcp-loading flex items-center justify-center min-h-[200px]" },
|
|
630
|
+
React6.createElement("div", {
|
|
631
|
+
className: "frontmcp-spinner w-6 h-6 border-2 border-gray-200 border-t-blue-500 rounded-full animate-spin"
|
|
632
|
+
})
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
function ErrorDisplay({ error }) {
|
|
636
|
+
return React6.createElement(
|
|
637
|
+
"div",
|
|
638
|
+
{
|
|
639
|
+
className: "frontmcp-error bg-red-50 border border-red-200 rounded-lg p-4 text-red-800"
|
|
640
|
+
},
|
|
641
|
+
[
|
|
642
|
+
React6.createElement("div", { key: "title", className: "font-medium" }, "Error"),
|
|
643
|
+
React6.createElement("div", { key: "message", className: "text-sm mt-1" }, escapeHtml3(error))
|
|
644
|
+
]
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
function EmptyState() {
|
|
648
|
+
return React6.createElement(
|
|
649
|
+
"div",
|
|
650
|
+
{
|
|
651
|
+
className: "frontmcp-empty text-gray-500 text-center py-8"
|
|
652
|
+
},
|
|
653
|
+
"No content to display"
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
function UniversalRenderer({
|
|
657
|
+
content,
|
|
658
|
+
state
|
|
659
|
+
}) {
|
|
660
|
+
const components = useComponents();
|
|
661
|
+
const context = {
|
|
662
|
+
output: state.output,
|
|
663
|
+
input: state.input,
|
|
664
|
+
components: {
|
|
665
|
+
...components,
|
|
666
|
+
...content.components
|
|
667
|
+
},
|
|
668
|
+
state
|
|
669
|
+
};
|
|
670
|
+
const rendered = renderContent(content, context);
|
|
671
|
+
return React6.createElement("div", { className: "frontmcp-content" }, rendered);
|
|
672
|
+
}
|
|
673
|
+
function UniversalApp({
|
|
674
|
+
content: contentOverride,
|
|
675
|
+
components,
|
|
676
|
+
fallback,
|
|
677
|
+
errorFallback: ErrorFallback = ErrorDisplay
|
|
678
|
+
}) {
|
|
679
|
+
const state = useFrontMCPStore();
|
|
680
|
+
if (state.loading) {
|
|
681
|
+
return fallback ? React6.createElement(React6.Fragment, null, fallback) : React6.createElement(LoadingSpinner, null);
|
|
682
|
+
}
|
|
683
|
+
if (state.error) {
|
|
684
|
+
return React6.createElement(ErrorFallback, { error: state.error });
|
|
685
|
+
}
|
|
686
|
+
const content = contentOverride ?? state.content;
|
|
687
|
+
if (!content) {
|
|
688
|
+
return React6.createElement(EmptyState, null);
|
|
689
|
+
}
|
|
690
|
+
if (components) {
|
|
691
|
+
return React6.createElement(
|
|
692
|
+
ComponentsProvider,
|
|
693
|
+
{ components },
|
|
694
|
+
React6.createElement(UniversalRenderer, { content, state })
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
return React6.createElement(UniversalRenderer, { content, state });
|
|
698
|
+
}
|
|
699
|
+
function UniversalAppWithProvider({
|
|
700
|
+
initialState,
|
|
701
|
+
components,
|
|
702
|
+
...appProps
|
|
703
|
+
}) {
|
|
704
|
+
return React6.createElement(
|
|
705
|
+
FrontMCPProvider,
|
|
706
|
+
{ initialState },
|
|
707
|
+
components ? React6.createElement(ComponentsProvider, { components }, React6.createElement(UniversalApp, appProps)) : React6.createElement(UniversalApp, appProps)
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// libs/ui/src/universal/runtime-builder.ts
|
|
712
|
+
function buildStoreRuntime() {
|
|
713
|
+
return `
|
|
714
|
+
// FrontMCP Store
|
|
715
|
+
(function() {
|
|
716
|
+
var state = {
|
|
717
|
+
toolName: null,
|
|
718
|
+
input: null,
|
|
719
|
+
output: null,
|
|
720
|
+
content: null,
|
|
721
|
+
structuredContent: null,
|
|
722
|
+
loading: false,
|
|
723
|
+
error: null
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
var listeners = new Set();
|
|
727
|
+
|
|
728
|
+
window.__frontmcp = {
|
|
729
|
+
// Store methods
|
|
730
|
+
getState: function() { return state; },
|
|
731
|
+
setState: function(partial) {
|
|
732
|
+
state = Object.assign({}, state, partial);
|
|
733
|
+
listeners.forEach(function(fn) { fn(); });
|
|
734
|
+
},
|
|
735
|
+
subscribe: function(fn) {
|
|
736
|
+
listeners.add(fn);
|
|
737
|
+
return function() { listeners.delete(fn); };
|
|
738
|
+
},
|
|
739
|
+
reset: function() {
|
|
740
|
+
state = {
|
|
741
|
+
toolName: null,
|
|
742
|
+
input: null,
|
|
743
|
+
output: null,
|
|
744
|
+
content: null,
|
|
745
|
+
structuredContent: null,
|
|
746
|
+
loading: false,
|
|
747
|
+
error: null
|
|
748
|
+
};
|
|
749
|
+
},
|
|
750
|
+
|
|
751
|
+
// Context (legacy support)
|
|
752
|
+
context: state,
|
|
753
|
+
setContext: function(ctx) {
|
|
754
|
+
this.setState(ctx);
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
// Hooks for React components
|
|
759
|
+
window.useFrontMCPStore = function() {
|
|
760
|
+
var store = window.__frontmcp;
|
|
761
|
+
return React.useSyncExternalStore(
|
|
762
|
+
store.subscribe,
|
|
763
|
+
store.getState,
|
|
764
|
+
store.getState
|
|
765
|
+
);
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
window.useToolOutput = function() {
|
|
769
|
+
return window.useFrontMCPStore().output;
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
window.useToolInput = function() {
|
|
773
|
+
return window.useFrontMCPStore().input;
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
window.useContent = function() {
|
|
777
|
+
return window.useFrontMCPStore().content;
|
|
778
|
+
};
|
|
779
|
+
})();
|
|
780
|
+
`;
|
|
781
|
+
}
|
|
782
|
+
function buildInlineMarkdownParser(options) {
|
|
783
|
+
const allowUnsafeLinks = options?.contentSecurity?.bypassSanitization || options?.contentSecurity?.allowUnsafeLinks;
|
|
784
|
+
return `
|
|
785
|
+
// Inline Markdown Parser
|
|
786
|
+
(function() {
|
|
787
|
+
// XSS protection settings (configured at build time)
|
|
788
|
+
var __allowUnsafeLinks = ${allowUnsafeLinks ? "true" : "false"};
|
|
789
|
+
|
|
790
|
+
// URL scheme validation to prevent XSS via javascript: URLs
|
|
791
|
+
function isSafeUrl(url) {
|
|
792
|
+
// If unsafe links are allowed, all URLs are considered safe
|
|
793
|
+
if (__allowUnsafeLinks) return true;
|
|
794
|
+
if (!url) return false;
|
|
795
|
+
var lower = url.toLowerCase().trim();
|
|
796
|
+
return lower.startsWith('http://') ||
|
|
797
|
+
lower.startsWith('https://') ||
|
|
798
|
+
lower.startsWith('/') ||
|
|
799
|
+
lower.startsWith('#') ||
|
|
800
|
+
lower.startsWith('mailto:');
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
function parseMarkdown(md) {
|
|
804
|
+
var html = md;
|
|
805
|
+
// Escape HTML
|
|
806
|
+
html = html.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
807
|
+
// Headers
|
|
808
|
+
html = html.replace(/^######\\s+(.*)$/gm, '<h6>$1</h6>');
|
|
809
|
+
html = html.replace(/^#####\\s+(.*)$/gm, '<h5>$1</h5>');
|
|
810
|
+
html = html.replace(/^####\\s+(.*)$/gm, '<h4>$1</h4>');
|
|
811
|
+
html = html.replace(/^###\\s+(.*)$/gm, '<h3>$1</h3>');
|
|
812
|
+
html = html.replace(/^##\\s+(.*)$/gm, '<h2>$1</h2>');
|
|
813
|
+
html = html.replace(/^#\\s+(.*)$/gm, '<h1>$1</h1>');
|
|
814
|
+
// Bold and italic
|
|
815
|
+
html = html.replace(/\\*\\*\\*(.+?)\\*\\*\\*/g, '<strong><em>$1</em></strong>');
|
|
816
|
+
html = html.replace(/\\*\\*(.+?)\\*\\*/g, '<strong>$1</strong>');
|
|
817
|
+
html = html.replace(/\\*(.+?)\\*/g, '<em>$1</em>');
|
|
818
|
+
// Inline code
|
|
819
|
+
html = html.replace(/\`([^\`]+)\`/g, '<code>$1</code>');
|
|
820
|
+
// Links - validate URL scheme to prevent XSS (unless bypassed)
|
|
821
|
+
html = html.replace(/\\[([^\\]]+)\\]\\(([^)]+)\\)/g, function(match, text, url) {
|
|
822
|
+
return isSafeUrl(url) ? '<a href="' + url + '">' + text + '</a>' : text;
|
|
823
|
+
});
|
|
824
|
+
// Lists
|
|
825
|
+
html = html.replace(/^[-*]\\s+(.*)$/gm, '<li>$1</li>');
|
|
826
|
+
// Paragraphs
|
|
827
|
+
html = html.replace(/\\n\\n+/g, '</p><p>');
|
|
828
|
+
html = '<p>' + html + '</p>';
|
|
829
|
+
return html;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
window.__frontmcp.parseMarkdown = parseMarkdown;
|
|
833
|
+
|
|
834
|
+
// Simple ReactMarkdown replacement
|
|
835
|
+
window.ReactMarkdown = function(props) {
|
|
836
|
+
var html = parseMarkdown(props.children || '');
|
|
837
|
+
return React.createElement('div', {
|
|
838
|
+
className: 'frontmcp-markdown prose',
|
|
839
|
+
dangerouslySetInnerHTML: { __html: html }
|
|
840
|
+
});
|
|
841
|
+
};
|
|
842
|
+
})();
|
|
843
|
+
`;
|
|
844
|
+
}
|
|
845
|
+
function buildRenderersRuntime(options) {
|
|
846
|
+
const bypassSanitization = options?.contentSecurity?.bypassSanitization;
|
|
847
|
+
const allowInlineScripts = bypassSanitization || options?.contentSecurity?.allowInlineScripts;
|
|
848
|
+
return `
|
|
849
|
+
// Universal Renderers
|
|
850
|
+
(function() {
|
|
851
|
+
var renderers = {};
|
|
852
|
+
|
|
853
|
+
// XSS protection settings (configured at build time)
|
|
854
|
+
var __allowInlineScripts = ${allowInlineScripts ? "true" : "false"};
|
|
855
|
+
|
|
856
|
+
// HTML Renderer
|
|
857
|
+
renderers.html = {
|
|
858
|
+
type: 'html',
|
|
859
|
+
priority: 0,
|
|
860
|
+
canHandle: function(c) { return c.type === 'html'; },
|
|
861
|
+
render: function(c, ctx) {
|
|
862
|
+
var html = c.source;
|
|
863
|
+
// Apply XSS protection unless bypassed
|
|
864
|
+
if (!__allowInlineScripts) {
|
|
865
|
+
// Remove script tags and event handlers
|
|
866
|
+
html = html.replace(/<script[^>]*>[\\s\\S]*?<\\/script>/gi, '');
|
|
867
|
+
html = html.replace(/\\s+on\\w+\\s*=/gi, ' data-removed-handler=');
|
|
868
|
+
}
|
|
869
|
+
return React.createElement('div', {
|
|
870
|
+
className: 'frontmcp-html-content',
|
|
871
|
+
dangerouslySetInnerHTML: { __html: html }
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
|
|
876
|
+
// Markdown Renderer
|
|
877
|
+
renderers.markdown = {
|
|
878
|
+
type: 'markdown',
|
|
879
|
+
priority: 10,
|
|
880
|
+
canHandle: function(c) {
|
|
881
|
+
if (c.type === 'markdown') return true;
|
|
882
|
+
if (typeof c.source !== 'string') return false;
|
|
883
|
+
var s = c.source;
|
|
884
|
+
return /^#{1,6}\\s/m.test(s) || /^[-*]\\s/m.test(s) || /\\*\\*[^*]+\\*\\*/.test(s);
|
|
885
|
+
},
|
|
886
|
+
render: function(c, ctx) {
|
|
887
|
+
if (window.ReactMarkdown) {
|
|
888
|
+
return React.createElement(window.ReactMarkdown, {
|
|
889
|
+
children: c.source,
|
|
890
|
+
components: Object.assign({}, ctx.components, c.components)
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
// Fallback to inline parser
|
|
894
|
+
var html = window.__frontmcp.parseMarkdown ? window.__frontmcp.parseMarkdown(c.source) : c.source;
|
|
895
|
+
return React.createElement('div', {
|
|
896
|
+
className: 'frontmcp-markdown prose',
|
|
897
|
+
dangerouslySetInnerHTML: { __html: html }
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
|
|
902
|
+
// React Renderer
|
|
903
|
+
renderers.react = {
|
|
904
|
+
type: 'react',
|
|
905
|
+
priority: 30,
|
|
906
|
+
canHandle: function(c) { return c.type === 'react' || typeof c.source === 'function'; },
|
|
907
|
+
render: function(c, ctx) {
|
|
908
|
+
var Component = c.source;
|
|
909
|
+
var props = Object.assign({
|
|
910
|
+
output: ctx.output,
|
|
911
|
+
input: ctx.input,
|
|
912
|
+
state: ctx.state
|
|
913
|
+
}, c.props);
|
|
914
|
+
return React.createElement(Component, props);
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
// MDX Renderer
|
|
919
|
+
renderers.mdx = {
|
|
920
|
+
type: 'mdx',
|
|
921
|
+
priority: 20,
|
|
922
|
+
canHandle: function(c) {
|
|
923
|
+
if (c.type === 'mdx') return true;
|
|
924
|
+
if (typeof c.source !== 'string') return false;
|
|
925
|
+
var s = c.source;
|
|
926
|
+
return /<[A-Z][a-zA-Z]*/.test(s) && /^#{1,6}\\s/m.test(s);
|
|
927
|
+
},
|
|
928
|
+
render: function(c, ctx) {
|
|
929
|
+
// MDX requires pre-compilation, fallback to showing source
|
|
930
|
+
if (typeof c.compiledContent === 'function') {
|
|
931
|
+
var MDXContent = c.compiledContent;
|
|
932
|
+
return React.createElement(MDXContent, {
|
|
933
|
+
output: ctx.output,
|
|
934
|
+
input: ctx.input,
|
|
935
|
+
components: Object.assign({}, ctx.components, c.components)
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
// Show warning
|
|
939
|
+
return React.createElement('div', { className: 'frontmcp-mdx-fallback' }, [
|
|
940
|
+
React.createElement('div', {
|
|
941
|
+
key: 'warn',
|
|
942
|
+
className: 'bg-yellow-50 border border-yellow-200 rounded p-2 mb-2 text-sm text-yellow-800'
|
|
943
|
+
}, 'MDX requires pre-compilation. Showing raw content.'),
|
|
944
|
+
React.createElement('pre', {
|
|
945
|
+
key: 'pre',
|
|
946
|
+
className: 'bg-gray-100 p-4 rounded text-sm overflow-auto'
|
|
947
|
+
}, c.source)
|
|
948
|
+
]);
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
// Sorted by priority
|
|
953
|
+
var sortedRenderers = [renderers.react, renderers.mdx, renderers.markdown, renderers.html];
|
|
954
|
+
|
|
955
|
+
// Detect renderer
|
|
956
|
+
window.__frontmcp.detectRenderer = function(content) {
|
|
957
|
+
if (content.type && renderers[content.type]) {
|
|
958
|
+
return renderers[content.type];
|
|
959
|
+
}
|
|
960
|
+
for (var i = 0; i < sortedRenderers.length; i++) {
|
|
961
|
+
if (sortedRenderers[i].canHandle(content)) {
|
|
962
|
+
return sortedRenderers[i];
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
return renderers.html;
|
|
966
|
+
};
|
|
967
|
+
|
|
968
|
+
// Render content
|
|
969
|
+
window.__frontmcp.renderContent = function(content, context) {
|
|
970
|
+
var renderer = window.__frontmcp.detectRenderer(content);
|
|
971
|
+
return renderer.render(content, context);
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
window.__frontmcp.renderers = renderers;
|
|
975
|
+
})();
|
|
976
|
+
`;
|
|
977
|
+
}
|
|
978
|
+
function buildUniversalAppRuntime() {
|
|
979
|
+
return `
|
|
980
|
+
// Universal App Component
|
|
981
|
+
(function() {
|
|
982
|
+
var LoadingSpinner = function() {
|
|
983
|
+
return React.createElement('div', {
|
|
984
|
+
className: 'frontmcp-loading flex items-center justify-center min-h-[200px]'
|
|
985
|
+
}, React.createElement('div', {
|
|
986
|
+
className: 'frontmcp-spinner w-6 h-6 border-2 border-gray-200 border-t-blue-500 rounded-full animate-spin'
|
|
987
|
+
}));
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
var ErrorDisplay = function(props) {
|
|
991
|
+
return React.createElement('div', {
|
|
992
|
+
className: 'frontmcp-error bg-red-50 border border-red-200 rounded-lg p-4 text-red-800'
|
|
993
|
+
}, [
|
|
994
|
+
React.createElement('div', { key: 'title', className: 'font-medium' }, 'Error'),
|
|
995
|
+
React.createElement('div', { key: 'msg', className: 'text-sm mt-1' }, props.error)
|
|
996
|
+
]);
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
var EmptyState = function() {
|
|
1000
|
+
return React.createElement('div', {
|
|
1001
|
+
className: 'frontmcp-empty text-gray-500 text-center py-8'
|
|
1002
|
+
}, 'No content to display');
|
|
1003
|
+
};
|
|
1004
|
+
|
|
1005
|
+
window.__frontmcp.UniversalApp = function(props) {
|
|
1006
|
+
var state = window.useFrontMCPStore();
|
|
1007
|
+
|
|
1008
|
+
if (state.loading) {
|
|
1009
|
+
return props.fallback || React.createElement(LoadingSpinner);
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
if (state.error) {
|
|
1013
|
+
var ErrorComp = props.errorFallback || ErrorDisplay;
|
|
1014
|
+
return React.createElement(ErrorComp, { error: state.error });
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
var content = props.content || state.content;
|
|
1018
|
+
|
|
1019
|
+
if (!content) {
|
|
1020
|
+
return React.createElement(EmptyState);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
var context = {
|
|
1024
|
+
output: state.output,
|
|
1025
|
+
input: state.input,
|
|
1026
|
+
state: state,
|
|
1027
|
+
components: props.components || {}
|
|
1028
|
+
};
|
|
1029
|
+
|
|
1030
|
+
var rendered = window.__frontmcp.renderContent(content, context);
|
|
1031
|
+
return React.createElement('div', { className: 'frontmcp-content' }, rendered);
|
|
1032
|
+
};
|
|
1033
|
+
|
|
1034
|
+
window.__frontmcp.LoadingSpinner = LoadingSpinner;
|
|
1035
|
+
window.__frontmcp.ErrorDisplay = ErrorDisplay;
|
|
1036
|
+
window.__frontmcp.EmptyState = EmptyState;
|
|
1037
|
+
})();
|
|
1038
|
+
`;
|
|
1039
|
+
}
|
|
1040
|
+
function buildCdnImports(options) {
|
|
1041
|
+
const parts = [];
|
|
1042
|
+
if (options.cdnType === "esm") {
|
|
1043
|
+
if (options.includeMarkdown) {
|
|
1044
|
+
parts.push(`
|
|
1045
|
+
<script type="module">
|
|
1046
|
+
import ReactMarkdown from '${UNIVERSAL_CDN.esm.reactMarkdown}';
|
|
1047
|
+
window.ReactMarkdown = ReactMarkdown;
|
|
1048
|
+
</script>`);
|
|
1049
|
+
}
|
|
1050
|
+
if (options.includeMdx) {
|
|
1051
|
+
parts.push(`
|
|
1052
|
+
<script type="module">
|
|
1053
|
+
import { MDXProvider } from '${UNIVERSAL_CDN.esm.mdxReact}';
|
|
1054
|
+
window.MDXProvider = MDXProvider;
|
|
1055
|
+
</script>`);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
return parts.join("\n");
|
|
1059
|
+
}
|
|
1060
|
+
function buildUniversalRuntime(options) {
|
|
1061
|
+
const parts = [];
|
|
1062
|
+
parts.push(buildStoreRuntime());
|
|
1063
|
+
if (options.cdnType === "umd" || options.includeMarkdown) {
|
|
1064
|
+
parts.push(buildInlineMarkdownParser(options));
|
|
1065
|
+
}
|
|
1066
|
+
parts.push(buildRenderersRuntime(options));
|
|
1067
|
+
parts.push(buildUniversalAppRuntime());
|
|
1068
|
+
if (options.customComponents) {
|
|
1069
|
+
parts.push(`
|
|
1070
|
+
// Custom Components
|
|
1071
|
+
(function() {
|
|
1072
|
+
${options.customComponents}
|
|
1073
|
+
})();
|
|
1074
|
+
`);
|
|
1075
|
+
}
|
|
1076
|
+
let script = parts.join("\n");
|
|
1077
|
+
if (options.minify) {
|
|
1078
|
+
script = script.replace(/\/\*[\s\S]*?\*\//g, "").replace(/^\s*\/\/[^\n]*$/gm, "").replace(/\n\s*\n/g, "\n").replace(/^\s+/gm, "").trim();
|
|
1079
|
+
}
|
|
1080
|
+
return {
|
|
1081
|
+
script,
|
|
1082
|
+
cdnImports: buildCdnImports(options),
|
|
1083
|
+
size: script.length
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
function buildMinimalRuntime(options) {
|
|
1087
|
+
let script = buildStoreRuntime();
|
|
1088
|
+
if (options.minify) {
|
|
1089
|
+
script = script.replace(/\/\*[\s\S]*?\*\//g, "").replace(/^\s*\/\/[^\n]*$/gm, "").replace(/\n\s*\n/g, "\n").replace(/^\s+/gm, "").trim();
|
|
1090
|
+
}
|
|
1091
|
+
return script;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
// libs/ui/src/universal/cached-runtime.ts
|
|
1095
|
+
import { getMCPBridgeScript } from "@frontmcp/uipack/runtime";
|
|
1096
|
+
import { buildUIComponentsRuntime as buildBrowserUIComponents } from "@frontmcp/uipack/build";
|
|
1097
|
+
var RUNTIME_PLACEHOLDERS = {
|
|
1098
|
+
/** Placeholder for transpiled component code */
|
|
1099
|
+
COMPONENT_CODE: "/*__FRONTMCP_COMPONENT_CODE__*/",
|
|
1100
|
+
/** Placeholder for data injection */
|
|
1101
|
+
DATA_INJECTION: "/*__FRONTMCP_DATA_INJECTION__*/",
|
|
1102
|
+
/** Placeholder for custom components */
|
|
1103
|
+
CUSTOM_COMPONENTS: "/*__FRONTMCP_CUSTOM_COMPONENTS__*/"
|
|
1104
|
+
};
|
|
1105
|
+
var runtimeCache = /* @__PURE__ */ new Map();
|
|
1106
|
+
var DEFAULT_CACHE_CONFIG = {
|
|
1107
|
+
maxEntries: 10,
|
|
1108
|
+
ttl: 0
|
|
1109
|
+
// Forever by default
|
|
1110
|
+
};
|
|
1111
|
+
function generateCacheKey(options) {
|
|
1112
|
+
const securityKey = options.contentSecurity ? [
|
|
1113
|
+
options.contentSecurity.allowUnsafeLinks ? "unsafeLinks" : "",
|
|
1114
|
+
options.contentSecurity.allowInlineScripts ? "unsafeScripts" : "",
|
|
1115
|
+
options.contentSecurity.bypassSanitization ? "bypass" : ""
|
|
1116
|
+
].filter(Boolean).join("+") || "secure" : "secure";
|
|
1117
|
+
return [
|
|
1118
|
+
options.cdnType,
|
|
1119
|
+
options.includeMarkdown ? "md" : "",
|
|
1120
|
+
options.includeMdx ? "mdx" : "",
|
|
1121
|
+
options.minify ? "min" : "",
|
|
1122
|
+
options.includeBridge ? "bridge" : "",
|
|
1123
|
+
securityKey
|
|
1124
|
+
].filter(Boolean).join(":");
|
|
1125
|
+
}
|
|
1126
|
+
function buildStoreRuntime2() {
|
|
1127
|
+
return `
|
|
1128
|
+
// FrontMCP Store (Vendor)
|
|
1129
|
+
(function() {
|
|
1130
|
+
var state = {
|
|
1131
|
+
toolName: null,
|
|
1132
|
+
input: null,
|
|
1133
|
+
output: null,
|
|
1134
|
+
content: null,
|
|
1135
|
+
structuredContent: null,
|
|
1136
|
+
loading: false,
|
|
1137
|
+
error: null
|
|
1138
|
+
};
|
|
1139
|
+
|
|
1140
|
+
var listeners = new Set();
|
|
1141
|
+
|
|
1142
|
+
window.__frontmcp = {
|
|
1143
|
+
getState: function() { return state; },
|
|
1144
|
+
setState: function(partial) {
|
|
1145
|
+
state = Object.assign({}, state, partial);
|
|
1146
|
+
listeners.forEach(function(fn) { fn(); });
|
|
1147
|
+
},
|
|
1148
|
+
subscribe: function(fn) {
|
|
1149
|
+
listeners.add(fn);
|
|
1150
|
+
return function() { listeners.delete(fn); };
|
|
1151
|
+
},
|
|
1152
|
+
reset: function() {
|
|
1153
|
+
state = {
|
|
1154
|
+
toolName: null,
|
|
1155
|
+
input: null,
|
|
1156
|
+
output: null,
|
|
1157
|
+
content: null,
|
|
1158
|
+
structuredContent: null,
|
|
1159
|
+
loading: false,
|
|
1160
|
+
error: null
|
|
1161
|
+
};
|
|
1162
|
+
},
|
|
1163
|
+
context: state,
|
|
1164
|
+
setContext: function(ctx) {
|
|
1165
|
+
this.setState(ctx);
|
|
1166
|
+
},
|
|
1167
|
+
// Dynamic mode: update output and re-render
|
|
1168
|
+
updateOutput: function(output) {
|
|
1169
|
+
this.setState({ output: output, loading: false });
|
|
1170
|
+
// Also update the global window variable for compatibility
|
|
1171
|
+
window.__mcpToolOutput = output;
|
|
1172
|
+
},
|
|
1173
|
+
// Dynamic mode: update input and re-render
|
|
1174
|
+
updateInput: function(input) {
|
|
1175
|
+
this.setState({ input: input });
|
|
1176
|
+
window.__mcpToolInput = input;
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
|
|
1180
|
+
// React hooks
|
|
1181
|
+
window.useFrontMCPStore = function() {
|
|
1182
|
+
var store = window.__frontmcp;
|
|
1183
|
+
return React.useSyncExternalStore(
|
|
1184
|
+
store.subscribe,
|
|
1185
|
+
store.getState,
|
|
1186
|
+
store.getState
|
|
1187
|
+
);
|
|
1188
|
+
};
|
|
1189
|
+
|
|
1190
|
+
window.useToolOutput = function() {
|
|
1191
|
+
return window.useFrontMCPStore().output;
|
|
1192
|
+
};
|
|
1193
|
+
|
|
1194
|
+
window.useToolInput = function() {
|
|
1195
|
+
return window.useFrontMCPStore().input;
|
|
1196
|
+
};
|
|
1197
|
+
|
|
1198
|
+
window.useContent = function() {
|
|
1199
|
+
return window.useFrontMCPStore().content;
|
|
1200
|
+
};
|
|
1201
|
+
|
|
1202
|
+
// Connect to MCP Bridge for platform data detection
|
|
1203
|
+
function initFromBridge() {
|
|
1204
|
+
// Check for data from mcpBridge (handles OpenAI, ext-apps, etc.)
|
|
1205
|
+
if (window.mcpBridge && window.mcpBridge.toolOutput != null) {
|
|
1206
|
+
window.__frontmcp.setState({
|
|
1207
|
+
output: window.mcpBridge.toolOutput,
|
|
1208
|
+
loading: false
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
// Subscribe to bridge updates via onToolResult
|
|
1213
|
+
if (window.mcpBridge && window.mcpBridge.onToolResult) {
|
|
1214
|
+
window.mcpBridge.onToolResult(function(result) {
|
|
1215
|
+
window.__frontmcp.updateOutput(result);
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
// Initialize from bridge when ready
|
|
1221
|
+
if (window.mcpBridge) {
|
|
1222
|
+
initFromBridge();
|
|
1223
|
+
} else {
|
|
1224
|
+
// Wait for bridge to be ready
|
|
1225
|
+
window.addEventListener('mcp:bridge-ready', initFromBridge);
|
|
1226
|
+
}
|
|
1227
|
+
})();
|
|
1228
|
+
`;
|
|
1229
|
+
}
|
|
1230
|
+
function buildRequireShim() {
|
|
1231
|
+
return `
|
|
1232
|
+
// Module Require Shim (Vendor)
|
|
1233
|
+
(function() {
|
|
1234
|
+
window.__moduleCache = {};
|
|
1235
|
+
window.require = function(moduleName) {
|
|
1236
|
+
if (window.__moduleCache[moduleName]) {
|
|
1237
|
+
return window.__moduleCache[moduleName];
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
var moduleMap = {
|
|
1241
|
+
'react': function() { return window.React; },
|
|
1242
|
+
'react-dom': function() { return window.ReactDOM; },
|
|
1243
|
+
'react-dom/client': function() { return window.ReactDOM; },
|
|
1244
|
+
'react/jsx-runtime': function() { return window.jsx_runtime_namespaceObject; },
|
|
1245
|
+
'react/jsx-dev-runtime': function() { return window.jsx_runtime_namespaceObject; },
|
|
1246
|
+
'@frontmcp/ui': function() { return window.frontmcp_ui_namespaceObject; },
|
|
1247
|
+
'@frontmcp/ui/react': function() { return window.frontmcp_ui_namespaceObject; }
|
|
1248
|
+
};
|
|
1249
|
+
|
|
1250
|
+
var resolver = moduleMap[moduleName];
|
|
1251
|
+
if (resolver) {
|
|
1252
|
+
var mod = resolver();
|
|
1253
|
+
window.__moduleCache[moduleName] = mod;
|
|
1254
|
+
return mod;
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
console.warn('[FrontMCP] Unknown module:', moduleName);
|
|
1258
|
+
return {};
|
|
1259
|
+
};
|
|
1260
|
+
})();
|
|
1261
|
+
`;
|
|
1262
|
+
}
|
|
1263
|
+
function buildInlineMarkdownParser2(options) {
|
|
1264
|
+
const allowUnsafeLinks = options?.contentSecurity?.bypassSanitization || options?.contentSecurity?.allowUnsafeLinks;
|
|
1265
|
+
return `
|
|
1266
|
+
// Inline Markdown Parser (Vendor)
|
|
1267
|
+
(function() {
|
|
1268
|
+
// XSS protection settings (configured at build time)
|
|
1269
|
+
// Set to true if contentSecurity.allowUnsafeLinks or bypassSanitization is enabled
|
|
1270
|
+
var __allowUnsafeLinks = ${allowUnsafeLinks ? "true" : "false"};
|
|
1271
|
+
|
|
1272
|
+
// URL scheme validation to prevent XSS via javascript: URLs
|
|
1273
|
+
function isSafeUrl(url) {
|
|
1274
|
+
// If unsafe links are explicitly allowed, skip validation
|
|
1275
|
+
if (__allowUnsafeLinks) return true;
|
|
1276
|
+
if (!url) return false;
|
|
1277
|
+
var lower = url.toLowerCase().trim();
|
|
1278
|
+
return lower.startsWith('http://') ||
|
|
1279
|
+
lower.startsWith('https://') ||
|
|
1280
|
+
lower.startsWith('/') ||
|
|
1281
|
+
lower.startsWith('#') ||
|
|
1282
|
+
lower.startsWith('mailto:');
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
function parseMarkdown(md) {
|
|
1286
|
+
var html = md;
|
|
1287
|
+
html = html.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
1288
|
+
html = html.replace(/^######\\s+(.*)$/gm, '<h6>$1</h6>');
|
|
1289
|
+
html = html.replace(/^#####\\s+(.*)$/gm, '<h5>$1</h5>');
|
|
1290
|
+
html = html.replace(/^####\\s+(.*)$/gm, '<h4>$1</h4>');
|
|
1291
|
+
html = html.replace(/^###\\s+(.*)$/gm, '<h3>$1</h3>');
|
|
1292
|
+
html = html.replace(/^##\\s+(.*)$/gm, '<h2>$1</h2>');
|
|
1293
|
+
html = html.replace(/^#\\s+(.*)$/gm, '<h1>$1</h1>');
|
|
1294
|
+
html = html.replace(/\\*\\*\\*(.+?)\\*\\*\\*/g, '<strong><em>$1</em></strong>');
|
|
1295
|
+
html = html.replace(/\\*\\*(.+?)\\*\\*/g, '<strong>$1</strong>');
|
|
1296
|
+
html = html.replace(/\\*(.+?)\\*/g, '<em>$1</em>');
|
|
1297
|
+
html = html.replace(/\`([^\`]+)\`/g, '<code>$1</code>');
|
|
1298
|
+
// Links - validate URL scheme to prevent XSS (unless bypassed)
|
|
1299
|
+
html = html.replace(/\\[([^\\]]+)\\]\\(([^)]+)\\)/g, function(match, text, url) {
|
|
1300
|
+
return isSafeUrl(url) ? '<a href="' + url + '">' + text + '</a>' : text;
|
|
1301
|
+
});
|
|
1302
|
+
html = html.replace(/^[-*]\\s+(.*)$/gm, '<li>$1</li>');
|
|
1303
|
+
html = html.replace(/\\n\\n+/g, '</p><p>');
|
|
1304
|
+
html = '<p>' + html + '</p>';
|
|
1305
|
+
return html;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
window.__frontmcp.parseMarkdown = parseMarkdown;
|
|
1309
|
+
|
|
1310
|
+
window.ReactMarkdown = function(props) {
|
|
1311
|
+
var html = parseMarkdown(props.children || '');
|
|
1312
|
+
return React.createElement('div', {
|
|
1313
|
+
className: 'frontmcp-markdown prose',
|
|
1314
|
+
dangerouslySetInnerHTML: { __html: html }
|
|
1315
|
+
});
|
|
1316
|
+
};
|
|
1317
|
+
})();
|
|
1318
|
+
`;
|
|
1319
|
+
}
|
|
1320
|
+
function buildRenderersRuntime2(options) {
|
|
1321
|
+
const bypassSanitization = options?.contentSecurity?.bypassSanitization;
|
|
1322
|
+
const allowInlineScripts = bypassSanitization || options?.contentSecurity?.allowInlineScripts;
|
|
1323
|
+
return `
|
|
1324
|
+
// Universal Renderers (Vendor)
|
|
1325
|
+
(function() {
|
|
1326
|
+
var renderers = {};
|
|
1327
|
+
|
|
1328
|
+
// XSS protection settings (configured at build time)
|
|
1329
|
+
// Set to true if contentSecurity.allowInlineScripts or bypassSanitization is enabled
|
|
1330
|
+
var __allowInlineScripts = ${allowInlineScripts ? "true" : "false"};
|
|
1331
|
+
|
|
1332
|
+
renderers.html = {
|
|
1333
|
+
type: 'html',
|
|
1334
|
+
priority: 0,
|
|
1335
|
+
canHandle: function(c) { return c.type === 'html'; },
|
|
1336
|
+
render: function(c, ctx) {
|
|
1337
|
+
var html = c.source;
|
|
1338
|
+
// Apply XSS protection unless bypassed
|
|
1339
|
+
if (!__allowInlineScripts) {
|
|
1340
|
+
// Remove script tags and event handlers to prevent XSS
|
|
1341
|
+
html = html.replace(/<script[^>]*>[\\s\\S]*?<\\/script>/gi, '');
|
|
1342
|
+
html = html.replace(/\\s+on\\w+\\s*=/gi, ' data-removed-handler=');
|
|
1343
|
+
}
|
|
1344
|
+
return React.createElement('div', {
|
|
1345
|
+
className: 'frontmcp-html-content',
|
|
1346
|
+
dangerouslySetInnerHTML: { __html: html }
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
};
|
|
1350
|
+
|
|
1351
|
+
renderers.markdown = {
|
|
1352
|
+
type: 'markdown',
|
|
1353
|
+
priority: 10,
|
|
1354
|
+
canHandle: function(c) {
|
|
1355
|
+
if (c.type === 'markdown') return true;
|
|
1356
|
+
if (typeof c.source !== 'string') return false;
|
|
1357
|
+
var s = c.source;
|
|
1358
|
+
return /^#{1,6}\\s/m.test(s) || /^[-*]\\s/m.test(s) || /\\*\\*[^*]+\\*\\*/.test(s);
|
|
1359
|
+
},
|
|
1360
|
+
render: function(c, ctx) {
|
|
1361
|
+
if (window.ReactMarkdown) {
|
|
1362
|
+
return React.createElement(window.ReactMarkdown, {
|
|
1363
|
+
children: c.source,
|
|
1364
|
+
components: Object.assign({}, ctx.components, c.components)
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
var html = window.__frontmcp.parseMarkdown ? window.__frontmcp.parseMarkdown(c.source) : c.source;
|
|
1368
|
+
return React.createElement('div', {
|
|
1369
|
+
className: 'frontmcp-markdown prose',
|
|
1370
|
+
dangerouslySetInnerHTML: { __html: html }
|
|
1371
|
+
});
|
|
1372
|
+
}
|
|
1373
|
+
};
|
|
1374
|
+
|
|
1375
|
+
renderers.react = {
|
|
1376
|
+
type: 'react',
|
|
1377
|
+
priority: 30,
|
|
1378
|
+
canHandle: function(c) { return c.type === 'react' || typeof c.source === 'function'; },
|
|
1379
|
+
render: function(c, ctx) {
|
|
1380
|
+
var Component = c.source;
|
|
1381
|
+
var props = Object.assign({
|
|
1382
|
+
output: ctx.output,
|
|
1383
|
+
input: ctx.input,
|
|
1384
|
+
state: ctx.state,
|
|
1385
|
+
data: ctx.output // Alias for convenience
|
|
1386
|
+
}, c.props);
|
|
1387
|
+
return React.createElement(Component, props);
|
|
1388
|
+
}
|
|
1389
|
+
};
|
|
1390
|
+
|
|
1391
|
+
renderers.mdx = {
|
|
1392
|
+
type: 'mdx',
|
|
1393
|
+
priority: 20,
|
|
1394
|
+
canHandle: function(c) {
|
|
1395
|
+
if (c.type === 'mdx') return true;
|
|
1396
|
+
if (typeof c.source !== 'string') return false;
|
|
1397
|
+
var s = c.source;
|
|
1398
|
+
return /<[A-Z][a-zA-Z]*/.test(s) && /^#{1,6}\\s/m.test(s);
|
|
1399
|
+
},
|
|
1400
|
+
render: function(c, ctx) {
|
|
1401
|
+
if (typeof c.compiledContent === 'function') {
|
|
1402
|
+
var MDXContent = c.compiledContent;
|
|
1403
|
+
return React.createElement(MDXContent, {
|
|
1404
|
+
output: ctx.output,
|
|
1405
|
+
input: ctx.input,
|
|
1406
|
+
components: Object.assign({}, ctx.components, c.components)
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1409
|
+
return React.createElement('div', { className: 'frontmcp-mdx-fallback' }, [
|
|
1410
|
+
React.createElement('div', {
|
|
1411
|
+
key: 'warn',
|
|
1412
|
+
className: 'bg-yellow-50 border border-yellow-200 rounded p-2 mb-2 text-sm text-yellow-800'
|
|
1413
|
+
}, 'MDX requires pre-compilation. Showing raw content.'),
|
|
1414
|
+
React.createElement('pre', {
|
|
1415
|
+
key: 'pre',
|
|
1416
|
+
className: 'bg-gray-100 p-4 rounded text-sm overflow-auto'
|
|
1417
|
+
}, c.source)
|
|
1418
|
+
]);
|
|
1419
|
+
}
|
|
1420
|
+
};
|
|
1421
|
+
|
|
1422
|
+
var sortedRenderers = [renderers.react, renderers.mdx, renderers.markdown, renderers.html];
|
|
1423
|
+
|
|
1424
|
+
window.__frontmcp.detectRenderer = function(content) {
|
|
1425
|
+
if (content.type && renderers[content.type]) {
|
|
1426
|
+
return renderers[content.type];
|
|
1427
|
+
}
|
|
1428
|
+
for (var i = 0; i < sortedRenderers.length; i++) {
|
|
1429
|
+
if (sortedRenderers[i].canHandle(content)) {
|
|
1430
|
+
return sortedRenderers[i];
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
return renderers.html;
|
|
1434
|
+
};
|
|
1435
|
+
|
|
1436
|
+
window.__frontmcp.renderContent = function(content, context) {
|
|
1437
|
+
var renderer = window.__frontmcp.detectRenderer(content);
|
|
1438
|
+
return renderer.render(content, context);
|
|
1439
|
+
};
|
|
1440
|
+
|
|
1441
|
+
window.__frontmcp.renderers = renderers;
|
|
1442
|
+
})();
|
|
1443
|
+
`;
|
|
1444
|
+
}
|
|
1445
|
+
function buildUIComponentsRuntime() {
|
|
1446
|
+
return buildBrowserUIComponents();
|
|
1447
|
+
}
|
|
1448
|
+
function buildUniversalAppRuntime2() {
|
|
1449
|
+
return `
|
|
1450
|
+
// Universal App (Vendor)
|
|
1451
|
+
(function() {
|
|
1452
|
+
var LoadingSpinner = function() {
|
|
1453
|
+
return React.createElement('div', {
|
|
1454
|
+
className: 'frontmcp-loading flex items-center justify-center min-h-[200px]'
|
|
1455
|
+
}, React.createElement('div', {
|
|
1456
|
+
className: 'frontmcp-spinner w-6 h-6 border-2 border-gray-200 border-t-blue-500 rounded-full animate-spin'
|
|
1457
|
+
}));
|
|
1458
|
+
};
|
|
1459
|
+
|
|
1460
|
+
var ErrorDisplay = function(props) {
|
|
1461
|
+
return React.createElement('div', {
|
|
1462
|
+
className: 'frontmcp-error bg-red-50 border border-red-200 rounded-lg p-4 text-red-800'
|
|
1463
|
+
}, [
|
|
1464
|
+
React.createElement('div', { key: 'title', className: 'font-medium' }, 'Error'),
|
|
1465
|
+
React.createElement('div', { key: 'msg', className: 'text-sm mt-1' }, props.error)
|
|
1466
|
+
]);
|
|
1467
|
+
};
|
|
1468
|
+
|
|
1469
|
+
var EmptyState = function() {
|
|
1470
|
+
return React.createElement('div', {
|
|
1471
|
+
className: 'frontmcp-empty text-gray-500 text-center py-8'
|
|
1472
|
+
}, 'No content to display');
|
|
1473
|
+
};
|
|
1474
|
+
|
|
1475
|
+
window.__frontmcp.UniversalApp = function(props) {
|
|
1476
|
+
var state = window.useFrontMCPStore();
|
|
1477
|
+
|
|
1478
|
+
if (state.loading) {
|
|
1479
|
+
return props.fallback || React.createElement(LoadingSpinner);
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
if (state.error) {
|
|
1483
|
+
var ErrorComp = props.errorFallback || ErrorDisplay;
|
|
1484
|
+
return React.createElement(ErrorComp, { error: state.error });
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
var content = props.content || state.content;
|
|
1488
|
+
|
|
1489
|
+
if (!content) {
|
|
1490
|
+
return React.createElement(EmptyState);
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
var context = {
|
|
1494
|
+
output: state.output,
|
|
1495
|
+
input: state.input,
|
|
1496
|
+
state: state,
|
|
1497
|
+
components: props.components || {}
|
|
1498
|
+
};
|
|
1499
|
+
|
|
1500
|
+
var rendered = window.__frontmcp.renderContent(content, context);
|
|
1501
|
+
return React.createElement('div', { className: 'frontmcp-content' }, rendered);
|
|
1502
|
+
};
|
|
1503
|
+
|
|
1504
|
+
window.__frontmcp.LoadingSpinner = LoadingSpinner;
|
|
1505
|
+
window.__frontmcp.ErrorDisplay = ErrorDisplay;
|
|
1506
|
+
window.__frontmcp.EmptyState = EmptyState;
|
|
1507
|
+
})();
|
|
1508
|
+
`;
|
|
1509
|
+
}
|
|
1510
|
+
function buildComponentWrapper() {
|
|
1511
|
+
return `
|
|
1512
|
+
// Component Execution (App Chunk)
|
|
1513
|
+
(function() {
|
|
1514
|
+
${RUNTIME_PLACEHOLDERS.COMPONENT_CODE}
|
|
1515
|
+
})();
|
|
1516
|
+
`;
|
|
1517
|
+
}
|
|
1518
|
+
function buildDataInjectionWrapper() {
|
|
1519
|
+
return `
|
|
1520
|
+
// Data Injection (App Chunk)
|
|
1521
|
+
(function() {
|
|
1522
|
+
${RUNTIME_PLACEHOLDERS.DATA_INJECTION}
|
|
1523
|
+
})();
|
|
1524
|
+
`;
|
|
1525
|
+
}
|
|
1526
|
+
function buildCustomComponentsWrapper() {
|
|
1527
|
+
return `
|
|
1528
|
+
// Custom Components (App Chunk)
|
|
1529
|
+
(function() {
|
|
1530
|
+
${RUNTIME_PLACEHOLDERS.CUSTOM_COMPONENTS}
|
|
1531
|
+
})();
|
|
1532
|
+
`;
|
|
1533
|
+
}
|
|
1534
|
+
function buildCdnImports2(options) {
|
|
1535
|
+
const parts = [];
|
|
1536
|
+
if (options.cdnType === "esm") {
|
|
1537
|
+
if (options.includeMarkdown) {
|
|
1538
|
+
parts.push(`
|
|
1539
|
+
<script type="module">
|
|
1540
|
+
import ReactMarkdown from '${UNIVERSAL_CDN.esm.reactMarkdown}';
|
|
1541
|
+
window.ReactMarkdown = ReactMarkdown;
|
|
1542
|
+
</script>`);
|
|
1543
|
+
}
|
|
1544
|
+
if (options.includeMdx) {
|
|
1545
|
+
parts.push(`
|
|
1546
|
+
<script type="module">
|
|
1547
|
+
import { MDXProvider } from '${UNIVERSAL_CDN.esm.mdxReact}';
|
|
1548
|
+
window.MDXProvider = MDXProvider;
|
|
1549
|
+
</script>`);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
return parts.join("\n");
|
|
1553
|
+
}
|
|
1554
|
+
function getCachedRuntime(options, config = {}) {
|
|
1555
|
+
const cacheKey = generateCacheKey(options);
|
|
1556
|
+
const cacheConfig = { ...DEFAULT_CACHE_CONFIG, ...config };
|
|
1557
|
+
const cached = runtimeCache.get(cacheKey);
|
|
1558
|
+
if (cached) {
|
|
1559
|
+
if (cacheConfig.ttl === 0 || Date.now() - cached.cachedAt < cacheConfig.ttl) {
|
|
1560
|
+
return {
|
|
1561
|
+
vendorScript: cached.script,
|
|
1562
|
+
appTemplate: buildAppTemplate(),
|
|
1563
|
+
cdnImports: cached.cdnImports,
|
|
1564
|
+
vendorSize: cached.size,
|
|
1565
|
+
cached: true,
|
|
1566
|
+
cacheKey
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
runtimeCache.delete(cacheKey);
|
|
1570
|
+
}
|
|
1571
|
+
const vendorParts = [];
|
|
1572
|
+
if (options.includeBridge) {
|
|
1573
|
+
vendorParts.push(getMCPBridgeScript());
|
|
1574
|
+
}
|
|
1575
|
+
vendorParts.push(buildStoreRuntime2(), buildRequireShim());
|
|
1576
|
+
if (options.cdnType === "umd" || options.includeMarkdown) {
|
|
1577
|
+
vendorParts.push(buildInlineMarkdownParser2(options));
|
|
1578
|
+
}
|
|
1579
|
+
vendorParts.push(buildRenderersRuntime2(options));
|
|
1580
|
+
vendorParts.push(buildUIComponentsRuntime());
|
|
1581
|
+
vendorParts.push(buildUniversalAppRuntime2());
|
|
1582
|
+
let vendorScript = vendorParts.join("\n");
|
|
1583
|
+
if (options.minify) {
|
|
1584
|
+
vendorScript = minifyScript(vendorScript);
|
|
1585
|
+
}
|
|
1586
|
+
const cdnImports = buildCdnImports2(options);
|
|
1587
|
+
const entry = {
|
|
1588
|
+
script: vendorScript,
|
|
1589
|
+
cdnImports,
|
|
1590
|
+
size: vendorScript.length,
|
|
1591
|
+
cacheKey,
|
|
1592
|
+
cachedAt: Date.now()
|
|
1593
|
+
};
|
|
1594
|
+
if (runtimeCache.size >= cacheConfig.maxEntries) {
|
|
1595
|
+
const oldestKey = runtimeCache.keys().next().value;
|
|
1596
|
+
if (oldestKey) {
|
|
1597
|
+
runtimeCache.delete(oldestKey);
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
runtimeCache.set(cacheKey, entry);
|
|
1601
|
+
return {
|
|
1602
|
+
vendorScript,
|
|
1603
|
+
appTemplate: buildAppTemplate(),
|
|
1604
|
+
cdnImports,
|
|
1605
|
+
vendorSize: vendorScript.length,
|
|
1606
|
+
cached: false,
|
|
1607
|
+
cacheKey
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
function buildAppTemplate() {
|
|
1611
|
+
return [buildCustomComponentsWrapper(), buildComponentWrapper(), buildDataInjectionWrapper()].join("\n");
|
|
1612
|
+
}
|
|
1613
|
+
function minifyScript(script) {
|
|
1614
|
+
return script.replace(/\/\*[\s\S]*?\*\//g, "").replace(/^\s*\/\/[^\n]*$/gm, "").replace(/\n\s*\n/g, "\n").replace(/^\s+/gm, "").trim();
|
|
1615
|
+
}
|
|
1616
|
+
function clearRuntimeCache() {
|
|
1617
|
+
runtimeCache.clear();
|
|
1618
|
+
}
|
|
1619
|
+
function getRuntimeCacheStats() {
|
|
1620
|
+
let totalSize = 0;
|
|
1621
|
+
const keys = [];
|
|
1622
|
+
for (const [key, entry] of runtimeCache) {
|
|
1623
|
+
keys.push(key);
|
|
1624
|
+
totalSize += entry.size;
|
|
1625
|
+
}
|
|
1626
|
+
return {
|
|
1627
|
+
entries: runtimeCache.size,
|
|
1628
|
+
totalSize,
|
|
1629
|
+
keys
|
|
1630
|
+
};
|
|
1631
|
+
}
|
|
1632
|
+
function buildAppScript(appTemplate, componentCode, dataInjection, customComponents = "") {
|
|
1633
|
+
return appTemplate.replace(RUNTIME_PLACEHOLDERS.CUSTOM_COMPONENTS, customComponents || "// No custom components").replace(RUNTIME_PLACEHOLDERS.COMPONENT_CODE, componentCode || "// No component code").replace(RUNTIME_PLACEHOLDERS.DATA_INJECTION, dataInjection);
|
|
1634
|
+
}
|
|
1635
|
+
var DEFAULT_OUTPUT_PLACEHOLDER = "__FRONTMCP_OUTPUT_PLACEHOLDER__";
|
|
1636
|
+
var DEFAULT_INPUT_PLACEHOLDER = "__FRONTMCP_INPUT_PLACEHOLDER__";
|
|
1637
|
+
function buildDataInjectionCode(toolName, input, output, structuredContent, contentType, source, hasComponent, options) {
|
|
1638
|
+
const buildMode = options?.buildMode ?? "static";
|
|
1639
|
+
const cdnType = options?.cdnType ?? "esm";
|
|
1640
|
+
switch (buildMode) {
|
|
1641
|
+
case "dynamic":
|
|
1642
|
+
return buildDynamicDataInjectionCode(
|
|
1643
|
+
toolName,
|
|
1644
|
+
input,
|
|
1645
|
+
output,
|
|
1646
|
+
structuredContent,
|
|
1647
|
+
contentType,
|
|
1648
|
+
source,
|
|
1649
|
+
hasComponent,
|
|
1650
|
+
cdnType,
|
|
1651
|
+
options?.dynamicOptions
|
|
1652
|
+
);
|
|
1653
|
+
case "hybrid":
|
|
1654
|
+
return buildHybridDataInjectionCode(
|
|
1655
|
+
toolName,
|
|
1656
|
+
structuredContent,
|
|
1657
|
+
contentType,
|
|
1658
|
+
source,
|
|
1659
|
+
hasComponent,
|
|
1660
|
+
options?.hybridOptions
|
|
1661
|
+
);
|
|
1662
|
+
default:
|
|
1663
|
+
return buildStaticDataInjectionCode(
|
|
1664
|
+
toolName,
|
|
1665
|
+
input,
|
|
1666
|
+
output,
|
|
1667
|
+
structuredContent,
|
|
1668
|
+
contentType,
|
|
1669
|
+
source,
|
|
1670
|
+
hasComponent
|
|
1671
|
+
);
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
function buildStaticDataInjectionCode(toolName, input, output, structuredContent, contentType, source, hasComponent) {
|
|
1675
|
+
const safeJson = (value) => {
|
|
1676
|
+
try {
|
|
1677
|
+
return JSON.stringify(value);
|
|
1678
|
+
} catch {
|
|
1679
|
+
return "null";
|
|
1680
|
+
}
|
|
1681
|
+
};
|
|
1682
|
+
if (hasComponent) {
|
|
1683
|
+
return `
|
|
1684
|
+
// Static Mode - Data baked at build time
|
|
1685
|
+
window.__frontmcp.setState({
|
|
1686
|
+
toolName: ${safeJson(toolName)},
|
|
1687
|
+
input: ${safeJson(input ?? null)},
|
|
1688
|
+
output: ${safeJson(output ?? null)},
|
|
1689
|
+
structuredContent: ${safeJson(structuredContent ?? null)},
|
|
1690
|
+
content: {
|
|
1691
|
+
type: 'react',
|
|
1692
|
+
source: window.__frontmcp_component
|
|
1693
|
+
},
|
|
1694
|
+
loading: false,
|
|
1695
|
+
error: null
|
|
1696
|
+
});`;
|
|
1697
|
+
}
|
|
1698
|
+
return `
|
|
1699
|
+
// Static Mode - Data baked at build time
|
|
1700
|
+
window.__frontmcp.setState({
|
|
1701
|
+
toolName: ${safeJson(toolName)},
|
|
1702
|
+
input: ${safeJson(input ?? null)},
|
|
1703
|
+
output: ${safeJson(output ?? null)},
|
|
1704
|
+
structuredContent: ${safeJson(structuredContent ?? null)},
|
|
1705
|
+
content: {
|
|
1706
|
+
type: ${safeJson(contentType)},
|
|
1707
|
+
source: ${safeJson(source)}
|
|
1708
|
+
},
|
|
1709
|
+
loading: false,
|
|
1710
|
+
error: null
|
|
1711
|
+
});`;
|
|
1712
|
+
}
|
|
1713
|
+
function buildDynamicDataInjectionCode(toolName, input, output, structuredContent, contentType, source, hasComponent, cdnType, dynamicOptions) {
|
|
1714
|
+
if (cdnType === "umd") {
|
|
1715
|
+
return buildDynamicWithPlaceholdersCode(
|
|
1716
|
+
toolName,
|
|
1717
|
+
structuredContent,
|
|
1718
|
+
contentType,
|
|
1719
|
+
source,
|
|
1720
|
+
hasComponent,
|
|
1721
|
+
dynamicOptions
|
|
1722
|
+
);
|
|
1723
|
+
}
|
|
1724
|
+
return buildDynamicWithSubscriptionCode(
|
|
1725
|
+
toolName,
|
|
1726
|
+
input,
|
|
1727
|
+
output,
|
|
1728
|
+
structuredContent,
|
|
1729
|
+
contentType,
|
|
1730
|
+
source,
|
|
1731
|
+
hasComponent,
|
|
1732
|
+
dynamicOptions
|
|
1733
|
+
);
|
|
1734
|
+
}
|
|
1735
|
+
function buildDynamicWithPlaceholdersCode(toolName, structuredContent, contentType, source, hasComponent, dynamicOptions) {
|
|
1736
|
+
const safeJson = (value) => {
|
|
1737
|
+
try {
|
|
1738
|
+
return JSON.stringify(value);
|
|
1739
|
+
} catch {
|
|
1740
|
+
return "null";
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
const outputPlaceholder = DEFAULT_OUTPUT_PLACEHOLDER;
|
|
1744
|
+
const inputPlaceholder = DEFAULT_INPUT_PLACEHOLDER;
|
|
1745
|
+
const includeInitialData = dynamicOptions?.includeInitialData ?? true;
|
|
1746
|
+
const contentBlock = hasComponent ? `content: { type: 'react', source: window.__frontmcp_component }` : `content: { type: ${safeJson(contentType)}, source: ${safeJson(source)} }`;
|
|
1747
|
+
return `
|
|
1748
|
+
// Dynamic Mode - Placeholder-based for non-OpenAI platforms
|
|
1749
|
+
var __outputRaw = "${outputPlaceholder}";
|
|
1750
|
+
var __inputRaw = "${inputPlaceholder}";
|
|
1751
|
+
var __output = null;
|
|
1752
|
+
var __input = null;
|
|
1753
|
+
var __error = null;
|
|
1754
|
+
var __outputNotReplaced = false;
|
|
1755
|
+
var __includeInitialData = ${includeInitialData};
|
|
1756
|
+
|
|
1757
|
+
// Parse output placeholder
|
|
1758
|
+
if (typeof __outputRaw === 'string' && __outputRaw !== "${outputPlaceholder}") {
|
|
1759
|
+
try { __output = JSON.parse(__outputRaw); } catch (e) {
|
|
1760
|
+
console.warn('[FrontMCP] Failed to parse output:', e);
|
|
1761
|
+
__error = 'Failed to parse output data';
|
|
1762
|
+
}
|
|
1763
|
+
} else if (__outputRaw === "${outputPlaceholder}") {
|
|
1764
|
+
__outputNotReplaced = true;
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
// Parse input placeholder
|
|
1768
|
+
if (typeof __inputRaw === 'string' && __inputRaw !== "${inputPlaceholder}") {
|
|
1769
|
+
try { __input = JSON.parse(__inputRaw); } catch (e) { console.warn('[FrontMCP] Failed to parse input:', e); }
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
// Handle placeholder not replaced - show error if expecting initial data
|
|
1773
|
+
if (__outputNotReplaced && __includeInitialData) {
|
|
1774
|
+
__error = 'No data provided. The output placeholder was not replaced.';
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
window.__frontmcp.setState({
|
|
1778
|
+
toolName: ${safeJson(toolName)},
|
|
1779
|
+
input: __input,
|
|
1780
|
+
output: __output,
|
|
1781
|
+
structuredContent: ${safeJson(structuredContent ?? null)},
|
|
1782
|
+
${contentBlock},
|
|
1783
|
+
loading: !__includeInitialData && __output === null && !__error,
|
|
1784
|
+
error: __error
|
|
1785
|
+
});`;
|
|
1786
|
+
}
|
|
1787
|
+
function buildDynamicWithSubscriptionCode(toolName, input, output, structuredContent, contentType, source, hasComponent, dynamicOptions) {
|
|
1788
|
+
const safeJson = (value) => {
|
|
1789
|
+
try {
|
|
1790
|
+
return JSON.stringify(value);
|
|
1791
|
+
} catch {
|
|
1792
|
+
return "null";
|
|
1793
|
+
}
|
|
1794
|
+
};
|
|
1795
|
+
const includeInitialData = dynamicOptions?.includeInitialData ?? true;
|
|
1796
|
+
const subscribeToUpdates = dynamicOptions?.subscribeToUpdates ?? true;
|
|
1797
|
+
const contentBlock = hasComponent ? `content: { type: 'react', source: window.__frontmcp_component }` : `content: { type: ${safeJson(contentType)}, source: ${safeJson(source)} }`;
|
|
1798
|
+
const initialState = includeInitialData ? `{
|
|
1799
|
+
toolName: ${safeJson(toolName)},
|
|
1800
|
+
input: ${safeJson(input ?? null)},
|
|
1801
|
+
output: ${safeJson(output ?? null)},
|
|
1802
|
+
structuredContent: ${safeJson(structuredContent ?? null)},
|
|
1803
|
+
${contentBlock},
|
|
1804
|
+
loading: false,
|
|
1805
|
+
error: null
|
|
1806
|
+
}` : `{
|
|
1807
|
+
toolName: ${safeJson(toolName)},
|
|
1808
|
+
input: ${safeJson(input ?? null)},
|
|
1809
|
+
output: null,
|
|
1810
|
+
structuredContent: ${safeJson(structuredContent ?? null)},
|
|
1811
|
+
${contentBlock},
|
|
1812
|
+
loading: true,
|
|
1813
|
+
error: null
|
|
1814
|
+
}`;
|
|
1815
|
+
const subscriptionBlock = subscribeToUpdates ? `
|
|
1816
|
+
// Subscribe to platform tool result events
|
|
1817
|
+
(function() {
|
|
1818
|
+
function subscribeToUpdates() {
|
|
1819
|
+
if (window.openai && window.openai.canvas && window.openai.canvas.onToolResult) {
|
|
1820
|
+
window.openai.canvas.onToolResult(function(result) {
|
|
1821
|
+
window.__frontmcp.updateOutput(result);
|
|
1822
|
+
window.dispatchEvent(new CustomEvent('frontmcp:toolResult', { detail: result }));
|
|
1823
|
+
});
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
if (document.readyState === 'loading') {
|
|
1827
|
+
document.addEventListener('DOMContentLoaded', subscribeToUpdates);
|
|
1828
|
+
} else {
|
|
1829
|
+
subscribeToUpdates();
|
|
1830
|
+
}
|
|
1831
|
+
})();` : "";
|
|
1832
|
+
return `
|
|
1833
|
+
// Dynamic Mode - OpenAI Subscription
|
|
1834
|
+
window.__frontmcp.setState(${initialState});
|
|
1835
|
+
${subscriptionBlock}`;
|
|
1836
|
+
}
|
|
1837
|
+
function buildHybridDataInjectionCode(toolName, structuredContent, contentType, source, hasComponent, hybridOptions) {
|
|
1838
|
+
const safeJson = (value) => {
|
|
1839
|
+
try {
|
|
1840
|
+
return JSON.stringify(value);
|
|
1841
|
+
} catch {
|
|
1842
|
+
return "null";
|
|
1843
|
+
}
|
|
1844
|
+
};
|
|
1845
|
+
const outputPlaceholder = hybridOptions?.placeholder ?? DEFAULT_OUTPUT_PLACEHOLDER;
|
|
1846
|
+
const inputPlaceholder = hybridOptions?.inputPlaceholder ?? DEFAULT_INPUT_PLACEHOLDER;
|
|
1847
|
+
const contentBlock = hasComponent ? `content: { type: 'react', source: window.__frontmcp_component }` : `content: { type: ${safeJson(contentType)}, source: ${safeJson(source)} }`;
|
|
1848
|
+
return `
|
|
1849
|
+
// Hybrid Mode - Placeholders replaced at runtime
|
|
1850
|
+
var __outputRaw = "${outputPlaceholder}";
|
|
1851
|
+
var __inputRaw = "${inputPlaceholder}";
|
|
1852
|
+
var __output = null;
|
|
1853
|
+
var __input = null;
|
|
1854
|
+
var __error = null;
|
|
1855
|
+
var __outputNotReplaced = false;
|
|
1856
|
+
|
|
1857
|
+
// Parse output placeholder
|
|
1858
|
+
if (typeof __outputRaw === 'string' && __outputRaw !== "${outputPlaceholder}") {
|
|
1859
|
+
try { __output = JSON.parse(__outputRaw); } catch (e) {
|
|
1860
|
+
console.warn('[FrontMCP] Failed to parse output:', e);
|
|
1861
|
+
__error = 'Failed to parse output data';
|
|
1862
|
+
}
|
|
1863
|
+
} else if (__outputRaw === "${outputPlaceholder}") {
|
|
1864
|
+
// Placeholder not replaced - no data was injected
|
|
1865
|
+
__outputNotReplaced = true;
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
// Parse input placeholder
|
|
1869
|
+
if (typeof __inputRaw === 'string' && __inputRaw !== "${inputPlaceholder}") {
|
|
1870
|
+
try { __input = JSON.parse(__inputRaw); } catch (e) { console.warn('[FrontMCP] Failed to parse input:', e); }
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
// Set error if output placeholder was not replaced (no data provided)
|
|
1874
|
+
if (__outputNotReplaced) {
|
|
1875
|
+
__error = 'No data provided. The output placeholder was not replaced.';
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
window.__frontmcp.setState({
|
|
1879
|
+
toolName: ${safeJson(toolName)},
|
|
1880
|
+
input: __input,
|
|
1881
|
+
output: __output,
|
|
1882
|
+
structuredContent: ${safeJson(structuredContent ?? null)},
|
|
1883
|
+
${contentBlock},
|
|
1884
|
+
loading: false,
|
|
1885
|
+
error: __error
|
|
1886
|
+
});`;
|
|
1887
|
+
}
|
|
1888
|
+
function buildComponentCode(transpiledCode) {
|
|
1889
|
+
return `
|
|
1890
|
+
// CommonJS module shim
|
|
1891
|
+
var module = { exports: {} };
|
|
1892
|
+
var exports = module.exports;
|
|
1893
|
+
|
|
1894
|
+
// Execute transpiled component
|
|
1895
|
+
${transpiledCode}
|
|
1896
|
+
|
|
1897
|
+
// Capture component
|
|
1898
|
+
window.__frontmcp_component = module.exports.default || module.exports;`;
|
|
1899
|
+
}
|
|
1900
|
+
export {
|
|
1901
|
+
ComponentsProvider,
|
|
1902
|
+
DEFAULT_FRONTMCP_STATE,
|
|
1903
|
+
EmptyState,
|
|
1904
|
+
ErrorDisplay,
|
|
1905
|
+
FrontMCPProvider,
|
|
1906
|
+
LoadingSpinner,
|
|
1907
|
+
RUNTIME_PLACEHOLDERS,
|
|
1908
|
+
RendererRegistry,
|
|
1909
|
+
UNIVERSAL_CDN,
|
|
1910
|
+
UniversalApp,
|
|
1911
|
+
UniversalAppWithProvider,
|
|
1912
|
+
UniversalProvider,
|
|
1913
|
+
buildAppScript,
|
|
1914
|
+
buildComponentCode,
|
|
1915
|
+
buildDataInjectionCode,
|
|
1916
|
+
buildMinimalRuntime,
|
|
1917
|
+
buildUniversalRuntime,
|
|
1918
|
+
clearRuntimeCache,
|
|
1919
|
+
createContent,
|
|
1920
|
+
createFrontMCPStore,
|
|
1921
|
+
createMarkdownRenderer,
|
|
1922
|
+
createMdxRenderer,
|
|
1923
|
+
createStoreSelector,
|
|
1924
|
+
detectContentType,
|
|
1925
|
+
detectRenderer,
|
|
1926
|
+
getCachedRuntime,
|
|
1927
|
+
getGlobalStore,
|
|
1928
|
+
getRuntimeCacheStats,
|
|
1929
|
+
htmlRenderer,
|
|
1930
|
+
initializeStoreFromWindow,
|
|
1931
|
+
isMdxSupported,
|
|
1932
|
+
isReactComponent,
|
|
1933
|
+
markdownRenderer,
|
|
1934
|
+
mdxRenderer,
|
|
1935
|
+
reactRenderer,
|
|
1936
|
+
renderContent,
|
|
1937
|
+
rendererRegistry,
|
|
1938
|
+
resetGlobalStore,
|
|
1939
|
+
safeHtmlRenderer,
|
|
1940
|
+
setGlobalStore,
|
|
1941
|
+
useComponents,
|
|
1942
|
+
useContent,
|
|
1943
|
+
useFrontMCPContext,
|
|
1944
|
+
useFrontMCPContextSafe,
|
|
1945
|
+
useFrontMCPStore,
|
|
1946
|
+
useLoadingState,
|
|
1947
|
+
useToolInput,
|
|
1948
|
+
useToolName,
|
|
1949
|
+
useToolOutput,
|
|
1950
|
+
withFrontMCP
|
|
1951
|
+
};
|