@frontmcp/uipack 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +246 -0
- package/LICENSE +201 -0
- package/README.md +150 -0
- package/adapters/index.d.ts +13 -0
- package/adapters/index.d.ts.map +1 -0
- package/adapters/index.js +462 -0
- package/adapters/platform-meta.d.ts +166 -0
- package/adapters/platform-meta.d.ts.map +1 -0
- package/adapters/response-builder.d.ts +108 -0
- package/adapters/response-builder.d.ts.map +1 -0
- package/adapters/serving-mode.d.ts +107 -0
- package/adapters/serving-mode.d.ts.map +1 -0
- package/base-template/bridge.d.ts +90 -0
- package/base-template/bridge.d.ts.map +1 -0
- package/base-template/default-base-template.d.ts +92 -0
- package/base-template/default-base-template.d.ts.map +1 -0
- package/base-template/index.d.ts +15 -0
- package/base-template/index.d.ts.map +1 -0
- package/base-template/index.js +1398 -0
- package/base-template/polyfills.d.ts +31 -0
- package/base-template/polyfills.d.ts.map +1 -0
- package/base-template/theme-styles.d.ts +74 -0
- package/base-template/theme-styles.d.ts.map +1 -0
- package/bridge-runtime/iife-generator.d.ts +62 -0
- package/bridge-runtime/iife-generator.d.ts.map +1 -0
- package/bridge-runtime/index.d.ts +10 -0
- package/bridge-runtime/index.d.ts.map +1 -0
- package/bridge-runtime/index.js +883 -0
- package/build/cdn-resources.d.ts +243 -0
- package/build/cdn-resources.d.ts.map +1 -0
- package/build/index.d.ts +295 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +6861 -0
- package/build/widget-manifest.d.ts +362 -0
- package/build/widget-manifest.d.ts.map +1 -0
- package/bundler/cache.d.ts +173 -0
- package/bundler/cache.d.ts.map +1 -0
- package/bundler/file-cache/component-builder.d.ts +167 -0
- package/bundler/file-cache/component-builder.d.ts.map +1 -0
- package/bundler/file-cache/hash-calculator.d.ts +155 -0
- package/bundler/file-cache/hash-calculator.d.ts.map +1 -0
- package/bundler/file-cache/index.d.ts +12 -0
- package/bundler/file-cache/index.d.ts.map +1 -0
- package/bundler/file-cache/storage/filesystem.d.ts +149 -0
- package/bundler/file-cache/storage/filesystem.d.ts.map +1 -0
- package/bundler/file-cache/storage/index.d.ts +11 -0
- package/bundler/file-cache/storage/index.d.ts.map +1 -0
- package/bundler/file-cache/storage/interface.d.ts +152 -0
- package/bundler/file-cache/storage/interface.d.ts.map +1 -0
- package/bundler/file-cache/storage/redis.d.ts +139 -0
- package/bundler/file-cache/storage/redis.d.ts.map +1 -0
- package/bundler/index.d.ts +35 -0
- package/bundler/index.d.ts.map +1 -0
- package/bundler/index.js +2947 -0
- package/bundler/sandbox/enclave-adapter.d.ts +121 -0
- package/bundler/sandbox/enclave-adapter.d.ts.map +1 -0
- package/bundler/sandbox/executor.d.ts +14 -0
- package/bundler/sandbox/executor.d.ts.map +1 -0
- package/bundler/sandbox/policy.d.ts +62 -0
- package/bundler/sandbox/policy.d.ts.map +1 -0
- package/bundler/types.d.ts +702 -0
- package/bundler/types.d.ts.map +1 -0
- package/dependency/cdn-registry.d.ts +98 -0
- package/dependency/cdn-registry.d.ts.map +1 -0
- package/dependency/import-map.d.ts +186 -0
- package/dependency/import-map.d.ts.map +1 -0
- package/dependency/import-parser.d.ts +82 -0
- package/dependency/import-parser.d.ts.map +1 -0
- package/dependency/index.d.ts +17 -0
- package/dependency/index.d.ts.map +1 -0
- package/dependency/index.js +3215 -0
- package/dependency/resolver.d.ts +164 -0
- package/dependency/resolver.d.ts.map +1 -0
- package/dependency/schemas.d.ts +486 -0
- package/dependency/schemas.d.ts.map +1 -0
- package/dependency/template-loader.d.ts +204 -0
- package/dependency/template-loader.d.ts.map +1 -0
- package/dependency/template-processor.d.ts +118 -0
- package/dependency/template-processor.d.ts.map +1 -0
- package/dependency/types.d.ts +739 -0
- package/dependency/types.d.ts.map +1 -0
- package/esm/adapters/index.d.ts +13 -0
- package/esm/adapters/index.d.ts.map +1 -0
- package/esm/adapters/index.js +427 -0
- package/esm/adapters/platform-meta.d.ts +166 -0
- package/esm/adapters/platform-meta.d.ts.map +1 -0
- package/esm/adapters/response-builder.d.ts +108 -0
- package/esm/adapters/response-builder.d.ts.map +1 -0
- package/esm/adapters/serving-mode.d.ts +107 -0
- package/esm/adapters/serving-mode.d.ts.map +1 -0
- package/esm/base-template/bridge.d.ts +90 -0
- package/esm/base-template/bridge.d.ts.map +1 -0
- package/esm/base-template/default-base-template.d.ts +92 -0
- package/esm/base-template/default-base-template.d.ts.map +1 -0
- package/esm/base-template/index.d.ts +15 -0
- package/esm/base-template/index.d.ts.map +1 -0
- package/esm/base-template/index.js +1364 -0
- package/esm/base-template/polyfills.d.ts +31 -0
- package/esm/base-template/polyfills.d.ts.map +1 -0
- package/esm/base-template/theme-styles.d.ts +74 -0
- package/esm/base-template/theme-styles.d.ts.map +1 -0
- package/esm/bridge-runtime/iife-generator.d.ts +62 -0
- package/esm/bridge-runtime/iife-generator.d.ts.map +1 -0
- package/esm/bridge-runtime/index.d.ts +10 -0
- package/esm/bridge-runtime/index.d.ts.map +1 -0
- package/esm/bridge-runtime/index.js +853 -0
- package/esm/build/cdn-resources.d.ts +243 -0
- package/esm/build/cdn-resources.d.ts.map +1 -0
- package/esm/build/index.d.ts +295 -0
- package/esm/build/index.d.ts.map +1 -0
- package/esm/build/index.js +6786 -0
- package/esm/build/widget-manifest.d.ts +362 -0
- package/esm/build/widget-manifest.d.ts.map +1 -0
- package/esm/bundler/cache.d.ts +173 -0
- package/esm/bundler/cache.d.ts.map +1 -0
- package/esm/bundler/file-cache/component-builder.d.ts +167 -0
- package/esm/bundler/file-cache/component-builder.d.ts.map +1 -0
- package/esm/bundler/file-cache/hash-calculator.d.ts +155 -0
- package/esm/bundler/file-cache/hash-calculator.d.ts.map +1 -0
- package/esm/bundler/file-cache/index.d.ts +12 -0
- package/esm/bundler/file-cache/index.d.ts.map +1 -0
- package/esm/bundler/file-cache/storage/filesystem.d.ts +149 -0
- package/esm/bundler/file-cache/storage/filesystem.d.ts.map +1 -0
- package/esm/bundler/file-cache/storage/index.d.ts +11 -0
- package/esm/bundler/file-cache/storage/index.d.ts.map +1 -0
- package/esm/bundler/file-cache/storage/interface.d.ts +152 -0
- package/esm/bundler/file-cache/storage/interface.d.ts.map +1 -0
- package/esm/bundler/file-cache/storage/redis.d.ts +139 -0
- package/esm/bundler/file-cache/storage/redis.d.ts.map +1 -0
- package/esm/bundler/index.d.ts +35 -0
- package/esm/bundler/index.d.ts.map +1 -0
- package/esm/bundler/index.js +2882 -0
- package/esm/bundler/sandbox/enclave-adapter.d.ts +121 -0
- package/esm/bundler/sandbox/enclave-adapter.d.ts.map +1 -0
- package/esm/bundler/sandbox/executor.d.ts +14 -0
- package/esm/bundler/sandbox/executor.d.ts.map +1 -0
- package/esm/bundler/sandbox/policy.d.ts +62 -0
- package/esm/bundler/sandbox/policy.d.ts.map +1 -0
- package/esm/bundler/types.d.ts +702 -0
- package/esm/bundler/types.d.ts.map +1 -0
- package/esm/dependency/cdn-registry.d.ts +98 -0
- package/esm/dependency/cdn-registry.d.ts.map +1 -0
- package/esm/dependency/import-map.d.ts +186 -0
- package/esm/dependency/import-map.d.ts.map +1 -0
- package/esm/dependency/import-parser.d.ts +82 -0
- package/esm/dependency/import-parser.d.ts.map +1 -0
- package/esm/dependency/index.d.ts +17 -0
- package/esm/dependency/index.d.ts.map +1 -0
- package/esm/dependency/index.js +3096 -0
- package/esm/dependency/resolver.d.ts +164 -0
- package/esm/dependency/resolver.d.ts.map +1 -0
- package/esm/dependency/schemas.d.ts +486 -0
- package/esm/dependency/schemas.d.ts.map +1 -0
- package/esm/dependency/template-loader.d.ts +204 -0
- package/esm/dependency/template-loader.d.ts.map +1 -0
- package/esm/dependency/template-processor.d.ts +118 -0
- package/esm/dependency/template-processor.d.ts.map +1 -0
- package/esm/dependency/types.d.ts +739 -0
- package/esm/dependency/types.d.ts.map +1 -0
- package/esm/handlebars/expression-extractor.d.ts +147 -0
- package/esm/handlebars/expression-extractor.d.ts.map +1 -0
- package/esm/handlebars/helpers.d.ts +339 -0
- package/esm/handlebars/helpers.d.ts.map +1 -0
- package/esm/handlebars/index.d.ts +195 -0
- package/esm/handlebars/index.d.ts.map +1 -0
- package/esm/handlebars/index.js +587 -0
- package/esm/index.d.ts +50 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +12434 -0
- package/esm/package.json +68 -0
- package/esm/registry/index.d.ts +46 -0
- package/esm/registry/index.d.ts.map +1 -0
- package/esm/registry/index.js +6237 -0
- package/esm/registry/render-template.d.ts +91 -0
- package/esm/registry/render-template.d.ts.map +1 -0
- package/esm/registry/tool-ui.registry.d.ts +294 -0
- package/esm/registry/tool-ui.registry.d.ts.map +1 -0
- package/esm/registry/uri-utils.d.ts +56 -0
- package/esm/registry/uri-utils.d.ts.map +1 -0
- package/esm/renderers/cache.d.ts +145 -0
- package/esm/renderers/cache.d.ts.map +1 -0
- package/esm/renderers/html.renderer.d.ts +123 -0
- package/esm/renderers/html.renderer.d.ts.map +1 -0
- package/esm/renderers/index.d.ts +36 -0
- package/esm/renderers/index.d.ts.map +1 -0
- package/esm/renderers/index.js +1654 -0
- package/esm/renderers/mdx.renderer.d.ts +120 -0
- package/esm/renderers/mdx.renderer.d.ts.map +1 -0
- package/esm/renderers/registry.d.ts +133 -0
- package/esm/renderers/registry.d.ts.map +1 -0
- package/esm/renderers/types.d.ts +342 -0
- package/esm/renderers/types.d.ts.map +1 -0
- package/esm/renderers/utils/detect.d.ts +107 -0
- package/esm/renderers/utils/detect.d.ts.map +1 -0
- package/esm/renderers/utils/hash.d.ts +40 -0
- package/esm/renderers/utils/hash.d.ts.map +1 -0
- package/esm/renderers/utils/index.d.ts +9 -0
- package/esm/renderers/utils/index.d.ts.map +1 -0
- package/esm/renderers/utils/transpiler.d.ts +89 -0
- package/esm/renderers/utils/transpiler.d.ts.map +1 -0
- package/esm/runtime/adapters/html.adapter.d.ts +59 -0
- package/esm/runtime/adapters/html.adapter.d.ts.map +1 -0
- package/esm/runtime/adapters/index.d.ts +26 -0
- package/esm/runtime/adapters/index.d.ts.map +1 -0
- package/esm/runtime/adapters/mdx.adapter.d.ts +73 -0
- package/esm/runtime/adapters/mdx.adapter.d.ts.map +1 -0
- package/esm/runtime/adapters/types.d.ts +95 -0
- package/esm/runtime/adapters/types.d.ts.map +1 -0
- package/esm/runtime/csp.d.ts +48 -0
- package/esm/runtime/csp.d.ts.map +1 -0
- package/esm/runtime/index.d.ts +17 -0
- package/esm/runtime/index.d.ts.map +1 -0
- package/esm/runtime/index.js +4976 -0
- package/esm/runtime/mcp-bridge.d.ts +101 -0
- package/esm/runtime/mcp-bridge.d.ts.map +1 -0
- package/esm/runtime/renderer-runtime.d.ts +133 -0
- package/esm/runtime/renderer-runtime.d.ts.map +1 -0
- package/esm/runtime/sanitizer.d.ts +172 -0
- package/esm/runtime/sanitizer.d.ts.map +1 -0
- package/esm/runtime/types.d.ts +415 -0
- package/esm/runtime/types.d.ts.map +1 -0
- package/esm/runtime/wrapper.d.ts +421 -0
- package/esm/runtime/wrapper.d.ts.map +1 -0
- package/esm/styles/index.d.ts +8 -0
- package/esm/styles/index.d.ts.map +1 -0
- package/esm/styles/index.js +171 -0
- package/esm/styles/variants.d.ts +51 -0
- package/esm/styles/variants.d.ts.map +1 -0
- package/esm/theme/cdn.d.ts +195 -0
- package/esm/theme/cdn.d.ts.map +1 -0
- package/esm/theme/index.d.ts +18 -0
- package/esm/theme/index.d.ts.map +1 -0
- package/esm/theme/index.js +700 -0
- package/esm/theme/platforms.d.ts +107 -0
- package/esm/theme/platforms.d.ts.map +1 -0
- package/esm/theme/presets/github-openai.d.ts +50 -0
- package/esm/theme/presets/github-openai.d.ts.map +1 -0
- package/esm/theme/presets/index.d.ts +11 -0
- package/esm/theme/presets/index.d.ts.map +1 -0
- package/esm/theme/theme.d.ts +396 -0
- package/esm/theme/theme.d.ts.map +1 -0
- package/esm/tool-template/builder.d.ts +213 -0
- package/esm/tool-template/builder.d.ts.map +1 -0
- package/esm/tool-template/index.d.ts +16 -0
- package/esm/tool-template/index.d.ts.map +1 -0
- package/esm/tool-template/index.js +3518 -0
- package/esm/types/index.d.ts +14 -0
- package/esm/types/index.d.ts.map +1 -0
- package/esm/types/index.js +75 -0
- package/esm/types/ui-config.d.ts +641 -0
- package/esm/types/ui-config.d.ts.map +1 -0
- package/esm/types/ui-runtime.d.ts +1008 -0
- package/esm/types/ui-runtime.d.ts.map +1 -0
- package/esm/typings/cache/cache-adapter.d.ts +125 -0
- package/esm/typings/cache/cache-adapter.d.ts.map +1 -0
- package/esm/typings/cache/index.d.ts +10 -0
- package/esm/typings/cache/index.d.ts.map +1 -0
- package/esm/typings/cache/memory-cache.d.ts +92 -0
- package/esm/typings/cache/memory-cache.d.ts.map +1 -0
- package/esm/typings/dts-parser.d.ts +90 -0
- package/esm/typings/dts-parser.d.ts.map +1 -0
- package/esm/typings/index.d.ts +48 -0
- package/esm/typings/index.d.ts.map +1 -0
- package/esm/typings/index.js +812 -0
- package/esm/typings/schemas.d.ts +232 -0
- package/esm/typings/schemas.d.ts.map +1 -0
- package/esm/typings/type-fetcher.d.ts +89 -0
- package/esm/typings/type-fetcher.d.ts.map +1 -0
- package/esm/typings/types.d.ts +320 -0
- package/esm/typings/types.d.ts.map +1 -0
- package/esm/utils/escape-html.d.ts +58 -0
- package/esm/utils/escape-html.d.ts.map +1 -0
- package/esm/utils/index.d.ts +10 -0
- package/esm/utils/index.d.ts.map +1 -0
- package/esm/utils/index.js +40 -0
- package/esm/utils/safe-stringify.d.ts +30 -0
- package/esm/utils/safe-stringify.d.ts.map +1 -0
- package/esm/validation/error-box.d.ts +56 -0
- package/esm/validation/error-box.d.ts.map +1 -0
- package/esm/validation/index.d.ts +13 -0
- package/esm/validation/index.d.ts.map +1 -0
- package/esm/validation/index.js +542 -0
- package/esm/validation/schema-paths.d.ts +118 -0
- package/esm/validation/schema-paths.d.ts.map +1 -0
- package/esm/validation/template-validator.d.ts +143 -0
- package/esm/validation/template-validator.d.ts.map +1 -0
- package/esm/validation/wrapper.d.ts +97 -0
- package/esm/validation/wrapper.d.ts.map +1 -0
- package/handlebars/expression-extractor.d.ts +147 -0
- package/handlebars/expression-extractor.d.ts.map +1 -0
- package/handlebars/helpers.d.ts +339 -0
- package/handlebars/helpers.d.ts.map +1 -0
- package/handlebars/index.d.ts +195 -0
- package/handlebars/index.d.ts.map +1 -0
- package/handlebars/index.js +666 -0
- package/index.d.ts +50 -0
- package/index.d.ts.map +1 -0
- package/index.js +12683 -0
- package/package.json +66 -0
- package/registry/index.d.ts +46 -0
- package/registry/index.d.ts.map +1 -0
- package/registry/index.js +6280 -0
- package/registry/render-template.d.ts +91 -0
- package/registry/render-template.d.ts.map +1 -0
- package/registry/tool-ui.registry.d.ts +294 -0
- package/registry/tool-ui.registry.d.ts.map +1 -0
- package/registry/uri-utils.d.ts +56 -0
- package/registry/uri-utils.d.ts.map +1 -0
- package/renderers/cache.d.ts +145 -0
- package/renderers/cache.d.ts.map +1 -0
- package/renderers/html.renderer.d.ts +123 -0
- package/renderers/html.renderer.d.ts.map +1 -0
- package/renderers/index.d.ts +36 -0
- package/renderers/index.d.ts.map +1 -0
- package/renderers/index.js +1706 -0
- package/renderers/mdx.renderer.d.ts +120 -0
- package/renderers/mdx.renderer.d.ts.map +1 -0
- package/renderers/registry.d.ts +133 -0
- package/renderers/registry.d.ts.map +1 -0
- package/renderers/types.d.ts +342 -0
- package/renderers/types.d.ts.map +1 -0
- package/renderers/utils/detect.d.ts +107 -0
- package/renderers/utils/detect.d.ts.map +1 -0
- package/renderers/utils/hash.d.ts +40 -0
- package/renderers/utils/hash.d.ts.map +1 -0
- package/renderers/utils/index.d.ts +9 -0
- package/renderers/utils/index.d.ts.map +1 -0
- package/renderers/utils/transpiler.d.ts +89 -0
- package/renderers/utils/transpiler.d.ts.map +1 -0
- package/runtime/adapters/html.adapter.d.ts +59 -0
- package/runtime/adapters/html.adapter.d.ts.map +1 -0
- package/runtime/adapters/index.d.ts +26 -0
- package/runtime/adapters/index.d.ts.map +1 -0
- package/runtime/adapters/mdx.adapter.d.ts +73 -0
- package/runtime/adapters/mdx.adapter.d.ts.map +1 -0
- package/runtime/adapters/types.d.ts +95 -0
- package/runtime/adapters/types.d.ts.map +1 -0
- package/runtime/csp.d.ts +48 -0
- package/runtime/csp.d.ts.map +1 -0
- package/runtime/index.d.ts +17 -0
- package/runtime/index.d.ts.map +1 -0
- package/runtime/index.js +5052 -0
- package/runtime/mcp-bridge.d.ts +101 -0
- package/runtime/mcp-bridge.d.ts.map +1 -0
- package/runtime/renderer-runtime.d.ts +133 -0
- package/runtime/renderer-runtime.d.ts.map +1 -0
- package/runtime/sanitizer.d.ts +172 -0
- package/runtime/sanitizer.d.ts.map +1 -0
- package/runtime/types.d.ts +415 -0
- package/runtime/types.d.ts.map +1 -0
- package/runtime/wrapper.d.ts +421 -0
- package/runtime/wrapper.d.ts.map +1 -0
- package/styles/index.d.ts +8 -0
- package/styles/index.d.ts.map +1 -0
- package/styles/index.js +222 -0
- package/styles/variants.d.ts +51 -0
- package/styles/variants.d.ts.map +1 -0
- package/theme/cdn.d.ts +195 -0
- package/theme/cdn.d.ts.map +1 -0
- package/theme/index.d.ts +18 -0
- package/theme/index.d.ts.map +1 -0
- package/theme/index.js +757 -0
- package/theme/platforms.d.ts +107 -0
- package/theme/platforms.d.ts.map +1 -0
- package/theme/presets/github-openai.d.ts +50 -0
- package/theme/presets/github-openai.d.ts.map +1 -0
- package/theme/presets/index.d.ts +11 -0
- package/theme/presets/index.d.ts.map +1 -0
- package/theme/theme.d.ts +396 -0
- package/theme/theme.d.ts.map +1 -0
- package/tool-template/builder.d.ts +213 -0
- package/tool-template/builder.d.ts.map +1 -0
- package/tool-template/index.d.ts +16 -0
- package/tool-template/index.d.ts.map +1 -0
- package/tool-template/index.js +3562 -0
- package/types/index.d.ts +14 -0
- package/types/index.d.ts.map +1 -0
- package/types/index.js +108 -0
- package/types/ui-config.d.ts +641 -0
- package/types/ui-config.d.ts.map +1 -0
- package/types/ui-runtime.d.ts +1008 -0
- package/types/ui-runtime.d.ts.map +1 -0
- package/typings/cache/cache-adapter.d.ts +125 -0
- package/typings/cache/cache-adapter.d.ts.map +1 -0
- package/typings/cache/index.d.ts +10 -0
- package/typings/cache/index.d.ts.map +1 -0
- package/typings/cache/memory-cache.d.ts +92 -0
- package/typings/cache/memory-cache.d.ts.map +1 -0
- package/typings/dts-parser.d.ts +90 -0
- package/typings/dts-parser.d.ts.map +1 -0
- package/typings/index.d.ts +48 -0
- package/typings/index.d.ts.map +1 -0
- package/typings/index.js +868 -0
- package/typings/schemas.d.ts +232 -0
- package/typings/schemas.d.ts.map +1 -0
- package/typings/type-fetcher.d.ts +89 -0
- package/typings/type-fetcher.d.ts.map +1 -0
- package/typings/types.d.ts +320 -0
- package/typings/types.d.ts.map +1 -0
- package/utils/escape-html.d.ts +58 -0
- package/utils/escape-html.d.ts.map +1 -0
- package/utils/index.d.ts +10 -0
- package/utils/index.d.ts.map +1 -0
- package/utils/index.js +70 -0
- package/utils/safe-stringify.d.ts +30 -0
- package/utils/safe-stringify.d.ts.map +1 -0
- package/validation/error-box.d.ts +56 -0
- package/validation/error-box.d.ts.map +1 -0
- package/validation/index.d.ts +13 -0
- package/validation/index.d.ts.map +1 -0
- package/validation/index.js +583 -0
- package/validation/schema-paths.d.ts +118 -0
- package/validation/schema-paths.d.ts.map +1 -0
- package/validation/template-validator.d.ts +143 -0
- package/validation/template-validator.d.ts.map +1 -0
- package/validation/wrapper.d.ts +97 -0
- package/validation/wrapper.d.ts.map +1 -0
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
// libs/uipack/src/utils/escape-html.ts
|
|
2
|
+
function escapeHtml(str) {
|
|
3
|
+
if (str === null || str === void 0) {
|
|
4
|
+
return "";
|
|
5
|
+
}
|
|
6
|
+
const s = String(str);
|
|
7
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// libs/uipack/src/validation/error-box.ts
|
|
11
|
+
var errorIcon = `<svg class="w-5 h-5 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
|
12
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
|
|
13
|
+
</svg>`;
|
|
14
|
+
function validationErrorBox(options) {
|
|
15
|
+
const { componentName, invalidParam } = options;
|
|
16
|
+
return `<div
|
|
17
|
+
class="validation-error flex items-start gap-3 p-4 bg-red-50 border border-red-200 text-red-800 rounded-lg"
|
|
18
|
+
role="alert"
|
|
19
|
+
data-testid="validation-error"
|
|
20
|
+
data-component="${escapeHtml(componentName)}"
|
|
21
|
+
data-param="${escapeHtml(invalidParam)}"
|
|
22
|
+
>
|
|
23
|
+
${errorIcon}
|
|
24
|
+
<div class="min-w-0">
|
|
25
|
+
<p class="font-semibold text-sm">${escapeHtml(componentName)}: Invalid Configuration</p>
|
|
26
|
+
<p class="text-sm opacity-90 mt-0.5">The "${escapeHtml(invalidParam)}" parameter is invalid.</p>
|
|
27
|
+
</div>
|
|
28
|
+
</div>`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// libs/uipack/src/validation/wrapper.ts
|
|
32
|
+
function getFirstInvalidPath(error) {
|
|
33
|
+
const firstError = error.issues[0];
|
|
34
|
+
if (!firstError || firstError.path.length === 0) {
|
|
35
|
+
return "options";
|
|
36
|
+
}
|
|
37
|
+
return firstError.path.map(String).join(".");
|
|
38
|
+
}
|
|
39
|
+
function validateOptions(options, config) {
|
|
40
|
+
const result = config.schema.safeParse(options);
|
|
41
|
+
if (result.success) {
|
|
42
|
+
return { success: true, data: result.data };
|
|
43
|
+
}
|
|
44
|
+
const invalidParam = getFirstInvalidPath(result.error);
|
|
45
|
+
return {
|
|
46
|
+
success: false,
|
|
47
|
+
error: validationErrorBox({
|
|
48
|
+
componentName: config.componentName,
|
|
49
|
+
invalidParam
|
|
50
|
+
})
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// libs/uipack/src/validation/schema-paths.ts
|
|
55
|
+
import { z } from "zod";
|
|
56
|
+
function extractSchemaPaths(schema, prefix = "output", options = {}) {
|
|
57
|
+
const { maxDepth = 10, includeArrayItems = true } = options;
|
|
58
|
+
const paths = [];
|
|
59
|
+
const visited = /* @__PURE__ */ new Set();
|
|
60
|
+
function recurse(currentSchema, currentPath, depth, isOptional, isNullable, isArrayItem) {
|
|
61
|
+
if (depth > maxDepth) return;
|
|
62
|
+
const pathKey = `${currentPath}:${depth}`;
|
|
63
|
+
if (visited.has(pathKey)) return;
|
|
64
|
+
visited.add(pathKey);
|
|
65
|
+
const description = currentSchema.description;
|
|
66
|
+
const innerType = unwrapType(currentSchema);
|
|
67
|
+
paths.push({
|
|
68
|
+
path: currentPath,
|
|
69
|
+
zodType: currentSchema,
|
|
70
|
+
optional: isOptional,
|
|
71
|
+
nullable: isNullable,
|
|
72
|
+
isArrayItem,
|
|
73
|
+
description
|
|
74
|
+
});
|
|
75
|
+
if (innerType instanceof z.ZodObject) {
|
|
76
|
+
const shape = innerType.shape;
|
|
77
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
78
|
+
const childSchema = value;
|
|
79
|
+
const childOptional = isOptional || isOptionalType(childSchema);
|
|
80
|
+
const childNullable = isNullable || isNullableType(childSchema);
|
|
81
|
+
recurse(childSchema, `${currentPath}.${key}`, depth + 1, childOptional, childNullable, false);
|
|
82
|
+
}
|
|
83
|
+
} else if (innerType instanceof z.ZodArray && includeArrayItems) {
|
|
84
|
+
const itemSchema = innerType.element;
|
|
85
|
+
recurse(itemSchema, `${currentPath}.[]`, depth + 1, isOptional, isNullable, true);
|
|
86
|
+
} else if (innerType instanceof z.ZodUnion || innerType instanceof z.ZodDiscriminatedUnion) {
|
|
87
|
+
const options2 = "options" in innerType ? innerType.options : [];
|
|
88
|
+
for (const option of options2) {
|
|
89
|
+
recurse(option, currentPath, depth, isOptional, isNullable, isArrayItem);
|
|
90
|
+
}
|
|
91
|
+
} else if (innerType instanceof z.ZodIntersection) {
|
|
92
|
+
recurse(innerType._def.left, currentPath, depth, isOptional, isNullable, isArrayItem);
|
|
93
|
+
recurse(innerType._def.right, currentPath, depth, isOptional, isNullable, isArrayItem);
|
|
94
|
+
} else if (innerType instanceof z.ZodRecord) {
|
|
95
|
+
const valueSchema = innerType._def.valueType;
|
|
96
|
+
recurse(valueSchema, `${currentPath}.[]`, depth + 1, isOptional, isNullable, true);
|
|
97
|
+
} else if (innerType instanceof z.ZodTuple) {
|
|
98
|
+
const items = innerType._def.items;
|
|
99
|
+
items.forEach((item, index) => {
|
|
100
|
+
recurse(item, `${currentPath}.${index}`, depth + 1, isOptional, isNullable, true);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
recurse(schema, prefix, 0, false, false, false);
|
|
105
|
+
const seen = /* @__PURE__ */ new Set();
|
|
106
|
+
return paths.filter((p) => {
|
|
107
|
+
if (seen.has(p.path)) return false;
|
|
108
|
+
seen.add(p.path);
|
|
109
|
+
return true;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function unwrapType(schema) {
|
|
113
|
+
if (schema instanceof z.ZodOptional) {
|
|
114
|
+
return unwrapType(schema.unwrap());
|
|
115
|
+
}
|
|
116
|
+
if (schema instanceof z.ZodNullable) {
|
|
117
|
+
return unwrapType(schema.unwrap());
|
|
118
|
+
}
|
|
119
|
+
if (schema instanceof z.ZodDefault) {
|
|
120
|
+
return unwrapType(schema._def.innerType);
|
|
121
|
+
}
|
|
122
|
+
if (schema instanceof z.ZodCatch && "innerType" in schema._def) {
|
|
123
|
+
return unwrapType(schema._def.innerType);
|
|
124
|
+
}
|
|
125
|
+
return schema;
|
|
126
|
+
}
|
|
127
|
+
function isOptionalType(schema) {
|
|
128
|
+
if (schema instanceof z.ZodOptional) return true;
|
|
129
|
+
if (schema instanceof z.ZodDefault) return true;
|
|
130
|
+
if (schema instanceof z.ZodNullable) return isOptionalType(schema.unwrap());
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
function isNullableType(schema) {
|
|
134
|
+
if (schema instanceof z.ZodNullable) return true;
|
|
135
|
+
if (schema instanceof z.ZodOptional) return isNullableType(schema.unwrap());
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
function getSchemaPathStrings(schema, prefix = "output") {
|
|
139
|
+
const paths = extractSchemaPaths(schema, prefix);
|
|
140
|
+
return new Set(paths.map((p) => p.path));
|
|
141
|
+
}
|
|
142
|
+
function isValidSchemaPath(schema, path) {
|
|
143
|
+
const prefix = path.split(".")[0];
|
|
144
|
+
const paths = getSchemaPathStrings(schema, prefix);
|
|
145
|
+
if (paths.has(path)) return true;
|
|
146
|
+
const normalizedPath = normalizePath(path);
|
|
147
|
+
if (paths.has(normalizedPath)) return true;
|
|
148
|
+
const pathParts = path.split(".");
|
|
149
|
+
for (let i = pathParts.length - 1; i >= 0; i--) {
|
|
150
|
+
const part = pathParts[i];
|
|
151
|
+
if (/^\d+$/.test(part)) {
|
|
152
|
+
const parentPath = pathParts.slice(0, i).join(".");
|
|
153
|
+
const wildcardPath = `${parentPath}.[]`;
|
|
154
|
+
if (paths.has(wildcardPath)) {
|
|
155
|
+
const restPath = pathParts.slice(i + 1).join(".");
|
|
156
|
+
if (restPath) {
|
|
157
|
+
const fullWildcardPath = `${wildcardPath}.${restPath}`;
|
|
158
|
+
const normalizedFullPath = normalizePath(fullWildcardPath);
|
|
159
|
+
if (paths.has(normalizedFullPath)) return true;
|
|
160
|
+
} else {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
function normalizePath(path) {
|
|
169
|
+
return path.replace(/\.\d+\./g, ".[].").replace(/\.\d+$/g, ".[]").replace(/\[\d+\]/g, ".[]");
|
|
170
|
+
}
|
|
171
|
+
function getTypeAtPath(schema, path) {
|
|
172
|
+
const prefix = path.split(".")[0];
|
|
173
|
+
const paths = extractSchemaPaths(schema, prefix);
|
|
174
|
+
let schemaPath = paths.find((p) => p.path === path);
|
|
175
|
+
if (!schemaPath) {
|
|
176
|
+
const normalizedPath = normalizePath(path);
|
|
177
|
+
schemaPath = paths.find((p) => p.path === normalizedPath);
|
|
178
|
+
}
|
|
179
|
+
return schemaPath?.zodType;
|
|
180
|
+
}
|
|
181
|
+
function getPathInfo(schema, path) {
|
|
182
|
+
const prefix = path.split(".")[0];
|
|
183
|
+
const paths = extractSchemaPaths(schema, prefix);
|
|
184
|
+
let schemaPath = paths.find((p) => p.path === path);
|
|
185
|
+
if (!schemaPath) {
|
|
186
|
+
const normalizedPath = normalizePath(path);
|
|
187
|
+
schemaPath = paths.find((p) => p.path === normalizedPath);
|
|
188
|
+
}
|
|
189
|
+
return schemaPath;
|
|
190
|
+
}
|
|
191
|
+
function getRootFieldNames(schema) {
|
|
192
|
+
const unwrapped = unwrapType(schema);
|
|
193
|
+
if (unwrapped instanceof z.ZodObject) {
|
|
194
|
+
return Object.keys(unwrapped.shape);
|
|
195
|
+
}
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
function getTypeDescription(schema, path) {
|
|
199
|
+
const zodType = getTypeAtPath(schema, path);
|
|
200
|
+
if (!zodType) return "unknown";
|
|
201
|
+
return describeZodType(zodType);
|
|
202
|
+
}
|
|
203
|
+
function describeZodType(schema) {
|
|
204
|
+
const inner = unwrapType(schema);
|
|
205
|
+
if (inner instanceof z.ZodString) return "string";
|
|
206
|
+
if (inner instanceof z.ZodNumber) return "number";
|
|
207
|
+
if (inner instanceof z.ZodBoolean) return "boolean";
|
|
208
|
+
if (inner instanceof z.ZodDate) return "Date";
|
|
209
|
+
if (inner instanceof z.ZodBigInt) return "bigint";
|
|
210
|
+
if (inner instanceof z.ZodSymbol) return "symbol";
|
|
211
|
+
if (inner instanceof z.ZodUndefined) return "undefined";
|
|
212
|
+
if (inner instanceof z.ZodNull) return "null";
|
|
213
|
+
if (inner instanceof z.ZodVoid) return "void";
|
|
214
|
+
if (inner instanceof z.ZodAny) return "any";
|
|
215
|
+
if (inner instanceof z.ZodUnknown) return "unknown";
|
|
216
|
+
if (inner instanceof z.ZodNever) return "never";
|
|
217
|
+
if (inner instanceof z.ZodLiteral) return `literal(${JSON.stringify(inner.value)})`;
|
|
218
|
+
if (inner instanceof z.ZodEnum) return `enum(${inner.options.join(" | ")})`;
|
|
219
|
+
if (inner instanceof z.ZodArray) return `${describeZodType(inner.element)}[]`;
|
|
220
|
+
if (inner instanceof z.ZodObject) return "object";
|
|
221
|
+
if (inner instanceof z.ZodUnion) return "union";
|
|
222
|
+
if (inner instanceof z.ZodDiscriminatedUnion) return "discriminatedUnion";
|
|
223
|
+
if (inner instanceof z.ZodIntersection) return "intersection";
|
|
224
|
+
if (inner instanceof z.ZodTuple) return "tuple";
|
|
225
|
+
if (inner instanceof z.ZodRecord) return `Record<string, ${describeZodType(inner._def.valueType)}>`;
|
|
226
|
+
if (inner instanceof z.ZodMap) return "Map";
|
|
227
|
+
if (inner instanceof z.ZodSet) return "Set";
|
|
228
|
+
if (inner instanceof z.ZodFunction) return "function";
|
|
229
|
+
if (inner instanceof z.ZodPromise) return "Promise";
|
|
230
|
+
if (schema instanceof z.ZodOptional) {
|
|
231
|
+
return `${describeZodType(schema.unwrap())}?`;
|
|
232
|
+
}
|
|
233
|
+
if (schema instanceof z.ZodNullable) {
|
|
234
|
+
return `${describeZodType(schema.unwrap())} | null`;
|
|
235
|
+
}
|
|
236
|
+
return "unknown";
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// libs/uipack/src/handlebars/expression-extractor.ts
|
|
240
|
+
var EXPRESSION_REGEX = /\{\{\{?(?!!)(#|\/)?([^}]+?)\}?\}\}/g;
|
|
241
|
+
var PATH_REGEX = /\b(output|input|structuredContent)(\.[a-zA-Z_$][a-zA-Z0-9_$]*|\.\[[^\]]+\])+/g;
|
|
242
|
+
var KEYWORDS = /* @__PURE__ */ new Set(["this", "else", "@index", "@key", "@first", "@last", "@root"]);
|
|
243
|
+
function extractExpressions(template) {
|
|
244
|
+
const expressions = [];
|
|
245
|
+
const lines = template.split("\n");
|
|
246
|
+
const positionMap = buildPositionMap(template);
|
|
247
|
+
let match;
|
|
248
|
+
EXPRESSION_REGEX.lastIndex = 0;
|
|
249
|
+
while ((match = EXPRESSION_REGEX.exec(template)) !== null) {
|
|
250
|
+
const fullExpression = match[0];
|
|
251
|
+
const prefix = match[1];
|
|
252
|
+
const content = match[2].trim();
|
|
253
|
+
const position = positionMap.get(match.index) ?? { line: 1, column: 1 };
|
|
254
|
+
let type = "variable";
|
|
255
|
+
let helperName;
|
|
256
|
+
if (prefix === "/") {
|
|
257
|
+
type = "block-close";
|
|
258
|
+
helperName = content;
|
|
259
|
+
} else if (prefix === "#") {
|
|
260
|
+
type = "block";
|
|
261
|
+
const parts = content.split(/\s+/);
|
|
262
|
+
helperName = parts[0];
|
|
263
|
+
} else {
|
|
264
|
+
const parts = content.split(/\s+/);
|
|
265
|
+
if (parts.length > 1 && !content.startsWith("(")) {
|
|
266
|
+
const firstToken = parts[0];
|
|
267
|
+
if (!firstToken.includes(".") && !KEYWORDS.has(firstToken)) {
|
|
268
|
+
type = "helper";
|
|
269
|
+
helperName = firstToken;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const paths = extractPathsFromContent(content);
|
|
274
|
+
for (const path of paths) {
|
|
275
|
+
expressions.push({
|
|
276
|
+
path,
|
|
277
|
+
fullExpression,
|
|
278
|
+
line: position.line,
|
|
279
|
+
column: position.column,
|
|
280
|
+
type,
|
|
281
|
+
helperName
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
if (paths.length === 0 && type === "variable") {
|
|
285
|
+
const cleanContent = content.trim();
|
|
286
|
+
if (!KEYWORDS.has(cleanContent) && !cleanContent.includes(" ") && !cleanContent.startsWith("(")) {
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return expressions;
|
|
291
|
+
}
|
|
292
|
+
function extractPathsFromContent(content) {
|
|
293
|
+
const paths = [];
|
|
294
|
+
let match;
|
|
295
|
+
const regex = new RegExp(PATH_REGEX.source, "g");
|
|
296
|
+
while ((match = regex.exec(content)) !== null) {
|
|
297
|
+
paths.push(match[0]);
|
|
298
|
+
}
|
|
299
|
+
return paths;
|
|
300
|
+
}
|
|
301
|
+
function buildPositionMap(template) {
|
|
302
|
+
const map = /* @__PURE__ */ new Map();
|
|
303
|
+
let line = 1;
|
|
304
|
+
let column = 1;
|
|
305
|
+
for (let i = 0; i < template.length; i++) {
|
|
306
|
+
map.set(i, { line, column });
|
|
307
|
+
if (template[i] === "\n") {
|
|
308
|
+
line++;
|
|
309
|
+
column = 1;
|
|
310
|
+
} else {
|
|
311
|
+
column++;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return map;
|
|
315
|
+
}
|
|
316
|
+
function extractAll(template) {
|
|
317
|
+
const expressions = extractExpressions(template);
|
|
318
|
+
const paths = [...new Set(expressions.map((e) => e.path))];
|
|
319
|
+
return {
|
|
320
|
+
expressions,
|
|
321
|
+
paths,
|
|
322
|
+
outputPaths: paths.filter((p) => p.startsWith("output.")),
|
|
323
|
+
inputPaths: paths.filter((p) => p.startsWith("input.")),
|
|
324
|
+
structuredContentPaths: paths.filter((p) => p.startsWith("structuredContent."))
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function normalizePath2(path) {
|
|
328
|
+
return path.replace(/\.\d+\./g, ".[].").replace(/\.\d+$/g, ".[]").replace(/\[\d+\]/g, ".[]");
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// libs/uipack/src/validation/template-validator.ts
|
|
332
|
+
function validateTemplate(template, outputSchema, options = {}) {
|
|
333
|
+
const { inputSchema, warnOnOptional = true, suggestSimilar = true, maxSuggestionDistance = 3 } = options;
|
|
334
|
+
const errors = [];
|
|
335
|
+
const warnings = [];
|
|
336
|
+
const extraction = extractAll(template);
|
|
337
|
+
const expressions = extractExpressions(template);
|
|
338
|
+
const outputPaths = getSchemaPathStrings(outputSchema, "output");
|
|
339
|
+
const inputPaths = inputSchema ? getSchemaPathStrings(inputSchema, "input") : /* @__PURE__ */ new Set();
|
|
340
|
+
const outputPathInfos = extractSchemaPaths(outputSchema, "output");
|
|
341
|
+
const inputPathInfos = inputSchema ? extractSchemaPaths(inputSchema, "input") : [];
|
|
342
|
+
const pathInfoMap = /* @__PURE__ */ new Map();
|
|
343
|
+
for (const info of [...outputPathInfos, ...inputPathInfos]) {
|
|
344
|
+
pathInfoMap.set(info.path, info);
|
|
345
|
+
}
|
|
346
|
+
for (const expr of expressions) {
|
|
347
|
+
const { path, fullExpression, line, column } = expr;
|
|
348
|
+
let validPaths;
|
|
349
|
+
let allPaths;
|
|
350
|
+
if (path.startsWith("output.")) {
|
|
351
|
+
validPaths = outputPaths;
|
|
352
|
+
allPaths = Array.from(outputPaths);
|
|
353
|
+
} else if (path.startsWith("input.")) {
|
|
354
|
+
if (!inputSchema) {
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
validPaths = inputPaths;
|
|
358
|
+
allPaths = Array.from(inputPaths);
|
|
359
|
+
} else if (path.startsWith("structuredContent.")) {
|
|
360
|
+
continue;
|
|
361
|
+
} else {
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
const normalizedPath = normalizePath2(path);
|
|
365
|
+
const isValid = validPaths.has(path) || validPaths.has(normalizedPath);
|
|
366
|
+
if (!isValid) {
|
|
367
|
+
const isArrayAccess = checkArrayAccess(path, validPaths);
|
|
368
|
+
if (!isArrayAccess) {
|
|
369
|
+
const suggestions = suggestSimilar ? findSimilarPaths(path, allPaths, maxSuggestionDistance) : [];
|
|
370
|
+
errors.push({
|
|
371
|
+
type: "missing_field",
|
|
372
|
+
path,
|
|
373
|
+
expression: fullExpression,
|
|
374
|
+
line,
|
|
375
|
+
column,
|
|
376
|
+
message: `Field '${getFieldName(path)}' does not exist in ${getSchemaName(path)} schema`,
|
|
377
|
+
suggestions
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
} else {
|
|
381
|
+
const pathInfo = pathInfoMap.get(path) ?? pathInfoMap.get(normalizedPath);
|
|
382
|
+
if (pathInfo && warnOnOptional) {
|
|
383
|
+
if (pathInfo.optional && expr.type === "variable") {
|
|
384
|
+
const hasGuard = hasConditionalGuard(template, path);
|
|
385
|
+
if (!hasGuard) {
|
|
386
|
+
warnings.push({
|
|
387
|
+
type: "optional_field",
|
|
388
|
+
path,
|
|
389
|
+
expression: fullExpression,
|
|
390
|
+
line,
|
|
391
|
+
message: `Accessing optional field '${getFieldName(path)}' without {{#if}} guard`
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return {
|
|
399
|
+
valid: errors.length === 0,
|
|
400
|
+
errors,
|
|
401
|
+
warnings,
|
|
402
|
+
templatePaths: extraction.paths,
|
|
403
|
+
schemaPaths: [...outputPaths, ...inputPaths]
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
function checkArrayAccess(path, validPaths) {
|
|
407
|
+
const parts = path.split(".");
|
|
408
|
+
for (let i = 0; i < parts.length; i++) {
|
|
409
|
+
if (/^\d+$/.test(parts[i])) {
|
|
410
|
+
const wildcardParts = [...parts];
|
|
411
|
+
wildcardParts[i] = "[]";
|
|
412
|
+
const wildcardPath = wildcardParts.join(".");
|
|
413
|
+
if (validPaths.has(wildcardPath)) {
|
|
414
|
+
return true;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
function getFieldName(path) {
|
|
421
|
+
const parts = path.split(".");
|
|
422
|
+
return parts[parts.length - 1];
|
|
423
|
+
}
|
|
424
|
+
function getSchemaName(path) {
|
|
425
|
+
if (path.startsWith("output.")) return "output";
|
|
426
|
+
if (path.startsWith("input.")) return "input";
|
|
427
|
+
if (path.startsWith("structuredContent.")) return "structuredContent";
|
|
428
|
+
return "unknown";
|
|
429
|
+
}
|
|
430
|
+
function hasConditionalGuard(template, path) {
|
|
431
|
+
const guardPattern = new RegExp(`\\{\\{#if\\s+${escapeRegex(path)}`, "i");
|
|
432
|
+
return guardPattern.test(template);
|
|
433
|
+
}
|
|
434
|
+
function escapeRegex(str) {
|
|
435
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
436
|
+
}
|
|
437
|
+
function findSimilarPaths(path, validPaths, maxDistance) {
|
|
438
|
+
const fieldName = getFieldName(path);
|
|
439
|
+
const prefix = path.substring(0, path.lastIndexOf(".") + 1);
|
|
440
|
+
const suggestions = [];
|
|
441
|
+
for (const validPath of validPaths) {
|
|
442
|
+
if (!validPath.startsWith(prefix)) continue;
|
|
443
|
+
const validFieldName = getFieldName(validPath);
|
|
444
|
+
const distance = levenshteinDistance(fieldName, validFieldName);
|
|
445
|
+
if (distance <= maxDistance && distance > 0) {
|
|
446
|
+
suggestions.push({ path: validPath, distance });
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return suggestions.sort((a, b) => a.distance - b.distance).slice(0, 3).map((s) => s.path);
|
|
450
|
+
}
|
|
451
|
+
function levenshteinDistance(a, b) {
|
|
452
|
+
const matrix = [];
|
|
453
|
+
for (let i = 0; i <= a.length; i++) {
|
|
454
|
+
matrix[i] = [i];
|
|
455
|
+
}
|
|
456
|
+
for (let j = 0; j <= b.length; j++) {
|
|
457
|
+
matrix[0][j] = j;
|
|
458
|
+
}
|
|
459
|
+
for (let i = 1; i <= a.length; i++) {
|
|
460
|
+
for (let j = 1; j <= b.length; j++) {
|
|
461
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
462
|
+
matrix[i][j] = Math.min(
|
|
463
|
+
matrix[i - 1][j] + 1,
|
|
464
|
+
// deletion
|
|
465
|
+
matrix[i][j - 1] + 1,
|
|
466
|
+
// insertion
|
|
467
|
+
matrix[i - 1][j - 1] + cost
|
|
468
|
+
// substitution
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return matrix[a.length][b.length];
|
|
473
|
+
}
|
|
474
|
+
function formatValidationWarnings(result, toolName) {
|
|
475
|
+
if (result.valid && result.warnings.length === 0) {
|
|
476
|
+
return "";
|
|
477
|
+
}
|
|
478
|
+
const lines = [];
|
|
479
|
+
if (result.errors.length > 0) {
|
|
480
|
+
lines.push(`[FrontMCP] Template validation warnings for tool "${toolName}":`);
|
|
481
|
+
lines.push("");
|
|
482
|
+
for (const error of result.errors) {
|
|
483
|
+
lines.push(` Line ${error.line}: ${error.expression}`);
|
|
484
|
+
lines.push(` ${error.message}`);
|
|
485
|
+
if (error.suggestions.length > 0) {
|
|
486
|
+
lines.push(` Did you mean: ${error.suggestions.join(", ")}?`);
|
|
487
|
+
}
|
|
488
|
+
lines.push("");
|
|
489
|
+
}
|
|
490
|
+
const outputFields = result.schemaPaths.filter((p) => p.startsWith("output.") && p.split(".").length === 2).map((p) => p.replace("output.", ""));
|
|
491
|
+
if (outputFields.length > 0) {
|
|
492
|
+
lines.push(` Available output fields: ${outputFields.join(", ")}`);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
if (result.warnings.length > 0) {
|
|
496
|
+
if (lines.length > 0) lines.push("");
|
|
497
|
+
lines.push(` Warnings:`);
|
|
498
|
+
for (const warning of result.warnings) {
|
|
499
|
+
lines.push(` Line ${warning.line}: ${warning.message}`);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return lines.join("\n");
|
|
503
|
+
}
|
|
504
|
+
function logValidationWarnings(result, toolName) {
|
|
505
|
+
const formatted = formatValidationWarnings(result, toolName);
|
|
506
|
+
if (formatted) {
|
|
507
|
+
console.warn(formatted);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
function assertTemplateValid(template, outputSchema, toolName) {
|
|
511
|
+
const result = validateTemplate(template, outputSchema);
|
|
512
|
+
if (!result.valid) {
|
|
513
|
+
const formatted = formatValidationWarnings(result, toolName);
|
|
514
|
+
throw new Error(`Template validation failed for tool "${toolName}":
|
|
515
|
+
${formatted}`);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
function isTemplateValid(template, outputSchema) {
|
|
519
|
+
const result = validateTemplate(template, outputSchema);
|
|
520
|
+
return result.valid;
|
|
521
|
+
}
|
|
522
|
+
function getMissingFields(template, outputSchema) {
|
|
523
|
+
const result = validateTemplate(template, outputSchema);
|
|
524
|
+
return result.errors.map((e) => e.path);
|
|
525
|
+
}
|
|
526
|
+
export {
|
|
527
|
+
assertTemplateValid,
|
|
528
|
+
extractSchemaPaths,
|
|
529
|
+
formatValidationWarnings,
|
|
530
|
+
getMissingFields,
|
|
531
|
+
getPathInfo,
|
|
532
|
+
getRootFieldNames,
|
|
533
|
+
getSchemaPathStrings,
|
|
534
|
+
getTypeAtPath,
|
|
535
|
+
getTypeDescription,
|
|
536
|
+
isTemplateValid,
|
|
537
|
+
isValidSchemaPath,
|
|
538
|
+
logValidationWarnings,
|
|
539
|
+
validateOptions,
|
|
540
|
+
validateTemplate,
|
|
541
|
+
validationErrorBox
|
|
542
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema Path Extractor
|
|
3
|
+
*
|
|
4
|
+
* Extracts valid paths from Zod schemas for template validation.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
/**
|
|
10
|
+
* Information about a path in a schema.
|
|
11
|
+
*/
|
|
12
|
+
export interface SchemaPath {
|
|
13
|
+
/** The full path (e.g., "output.user.name") */
|
|
14
|
+
path: string;
|
|
15
|
+
/** The Zod type at this path */
|
|
16
|
+
zodType: z.ZodTypeAny;
|
|
17
|
+
/** Whether this path is optional */
|
|
18
|
+
optional: boolean;
|
|
19
|
+
/** Whether this path is nullable */
|
|
20
|
+
nullable: boolean;
|
|
21
|
+
/** Whether this is an array item path (contains []) */
|
|
22
|
+
isArrayItem: boolean;
|
|
23
|
+
/** Description from .describe() if present */
|
|
24
|
+
description?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Options for path extraction.
|
|
28
|
+
*/
|
|
29
|
+
export interface ExtractPathsOptions {
|
|
30
|
+
/** Maximum depth to recurse (default: 10) */
|
|
31
|
+
maxDepth?: number;
|
|
32
|
+
/** Include array item paths with [] notation */
|
|
33
|
+
includeArrayItems?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Extract all valid paths from a Zod schema.
|
|
37
|
+
*
|
|
38
|
+
* @param schema - The Zod schema to extract paths from
|
|
39
|
+
* @param prefix - Path prefix (default: "output")
|
|
40
|
+
* @param options - Extraction options
|
|
41
|
+
* @returns Array of schema paths with metadata
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const schema = z.object({
|
|
46
|
+
* temperature: z.number(),
|
|
47
|
+
* user: z.object({
|
|
48
|
+
* name: z.string(),
|
|
49
|
+
* email: z.string().optional(),
|
|
50
|
+
* }),
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* const paths = extractSchemaPaths(schema, 'output');
|
|
54
|
+
* // [
|
|
55
|
+
* // { path: 'output', ... },
|
|
56
|
+
* // { path: 'output.temperature', ... },
|
|
57
|
+
* // { path: 'output.user', ... },
|
|
58
|
+
* // { path: 'output.user.name', ... },
|
|
59
|
+
* // { path: 'output.user.email', optional: true, ... },
|
|
60
|
+
* // ]
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function extractSchemaPaths(schema: z.ZodTypeAny, prefix?: string, options?: ExtractPathsOptions): SchemaPath[];
|
|
64
|
+
/**
|
|
65
|
+
* Get just the path strings from a schema.
|
|
66
|
+
*
|
|
67
|
+
* @param schema - The Zod schema
|
|
68
|
+
* @param prefix - Path prefix (default: "output")
|
|
69
|
+
* @returns Set of valid path strings
|
|
70
|
+
*/
|
|
71
|
+
export declare function getSchemaPathStrings(schema: z.ZodTypeAny, prefix?: string): Set<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Check if a path exists in a schema.
|
|
74
|
+
*
|
|
75
|
+
* @param schema - The Zod schema
|
|
76
|
+
* @param path - The path to check
|
|
77
|
+
* @returns true if the path exists
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const schema = z.object({ name: z.string() });
|
|
82
|
+
* isValidSchemaPath(schema, 'output.name'); // true
|
|
83
|
+
* isValidSchemaPath(schema, 'output.age'); // false
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare function isValidSchemaPath(schema: z.ZodTypeAny, path: string): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Get the Zod type at a specific path.
|
|
89
|
+
*
|
|
90
|
+
* @param schema - The Zod schema
|
|
91
|
+
* @param path - The path to look up
|
|
92
|
+
* @returns The Zod type or undefined if not found
|
|
93
|
+
*/
|
|
94
|
+
export declare function getTypeAtPath(schema: z.ZodTypeAny, path: string): z.ZodTypeAny | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Get schema path info at a specific path.
|
|
97
|
+
*
|
|
98
|
+
* @param schema - The Zod schema
|
|
99
|
+
* @param path - The path to look up
|
|
100
|
+
* @returns SchemaPath info or undefined if not found
|
|
101
|
+
*/
|
|
102
|
+
export declare function getPathInfo(schema: z.ZodTypeAny, path: string): SchemaPath | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* Get all field names at the root level of a schema.
|
|
105
|
+
*
|
|
106
|
+
* @param schema - The Zod schema (should be ZodObject)
|
|
107
|
+
* @returns Array of field names
|
|
108
|
+
*/
|
|
109
|
+
export declare function getRootFieldNames(schema: z.ZodTypeAny): string[];
|
|
110
|
+
/**
|
|
111
|
+
* Get a human-readable type description for a path.
|
|
112
|
+
*
|
|
113
|
+
* @param schema - The Zod schema
|
|
114
|
+
* @param path - The path to describe
|
|
115
|
+
* @returns Human-readable type string
|
|
116
|
+
*/
|
|
117
|
+
export declare function getTypeDescription(schema: z.ZodTypeAny, path: string): string;
|
|
118
|
+
//# sourceMappingURL=schema-paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-paths.d.ts","sourceRoot":"","sources":["../../../src/validation/schema-paths.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,OAAO,EAAE,CAAC,CAAC,UAAU,CAAC;IACtB,oCAAoC;IACpC,QAAQ,EAAE,OAAO,CAAC;IAClB,oCAAoC;IACpC,QAAQ,EAAE,OAAO,CAAC;IAClB,uDAAuD;IACvD,WAAW,EAAE,OAAO,CAAC;IACrB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,CAAC,CAAC,UAAU,EACpB,MAAM,SAAW,EACjB,OAAO,GAAE,mBAAwB,GAChC,UAAU,EAAE,CAkFd;AA8CD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,MAAM,SAAW,GAAG,GAAG,CAAC,MAAM,CAAC,CAGzF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAqC7E;AAYD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC,UAAU,GAAG,SAAS,CAc1F;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CActF;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,GAAG,MAAM,EAAE,CAQhE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAK7E"}
|