@frontmcp/uipack 0.12.1 → 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (298) hide show
  1. package/CLAUDE.md +56 -154
  2. package/README.md +367 -62
  3. package/adapters/base-template.d.ts +30 -0
  4. package/adapters/base-template.d.ts.map +1 -0
  5. package/adapters/cdn-info.d.ts +34 -0
  6. package/adapters/cdn-info.d.ts.map +1 -0
  7. package/adapters/constants.d.ts +18 -0
  8. package/adapters/constants.d.ts.map +1 -0
  9. package/adapters/content-detector.d.ts +19 -0
  10. package/adapters/content-detector.d.ts.map +1 -0
  11. package/adapters/content-renderers.d.ts +27 -0
  12. package/adapters/content-renderers.d.ts.map +1 -0
  13. package/adapters/index.d.ts +14 -7
  14. package/adapters/index.d.ts.map +1 -1
  15. package/adapters/index.js +2343 -426
  16. package/adapters/render-failure.d.ts +18 -0
  17. package/adapters/render-failure.d.ts.map +1 -0
  18. package/adapters/response-builder.d.ts +34 -104
  19. package/adapters/response-builder.d.ts.map +1 -1
  20. package/adapters/serving-mode.d.ts +28 -91
  21. package/adapters/serving-mode.d.ts.map +1 -1
  22. package/adapters/template-renderer.d.ts +50 -0
  23. package/adapters/template-renderer.d.ts.map +1 -0
  24. package/adapters/type-detector.d.ts +18 -0
  25. package/adapters/type-detector.d.ts.map +1 -0
  26. package/bridge-runtime/index.js +1 -1
  27. package/component/index.d.ts +14 -0
  28. package/component/index.d.ts.map +1 -0
  29. package/component/index.js +2043 -0
  30. package/component/loader.d.ts +36 -0
  31. package/component/loader.d.ts.map +1 -0
  32. package/component/renderer.d.ts +30 -0
  33. package/component/renderer.d.ts.map +1 -0
  34. package/component/transpiler.d.ts +49 -0
  35. package/component/transpiler.d.ts.map +1 -0
  36. package/component/types.d.ts +82 -0
  37. package/component/types.d.ts.map +1 -0
  38. package/esm/adapters/index.mjs +2337 -422
  39. package/esm/bridge-runtime/index.mjs +1 -1
  40. package/esm/component/index.mjs +2013 -0
  41. package/esm/index.mjs +3446 -13935
  42. package/esm/package.json +3 -12
  43. package/esm/resolver/index.mjs +661 -0
  44. package/esm/shell/index.mjs +1406 -0
  45. package/esm/types/index.mjs +11 -11
  46. package/esm/utils/index.mjs +53 -8
  47. package/index.d.ts +12 -40
  48. package/index.d.ts.map +1 -1
  49. package/index.js +3579 -14218
  50. package/package.json +3 -12
  51. package/resolver/cdn-registry.d.ts +39 -0
  52. package/resolver/cdn-registry.d.ts.map +1 -0
  53. package/resolver/esm-sh.resolver.d.ts +54 -0
  54. package/resolver/esm-sh.resolver.d.ts.map +1 -0
  55. package/resolver/import-map.d.ts +47 -0
  56. package/resolver/import-map.d.ts.map +1 -0
  57. package/resolver/import-parser.d.ts +28 -0
  58. package/resolver/import-parser.d.ts.map +1 -0
  59. package/resolver/import-rewriter.d.ts +29 -0
  60. package/resolver/import-rewriter.d.ts.map +1 -0
  61. package/resolver/index.d.ts +15 -0
  62. package/resolver/index.d.ts.map +1 -0
  63. package/resolver/index.js +708 -0
  64. package/resolver/types.d.ts +191 -0
  65. package/resolver/types.d.ts.map +1 -0
  66. package/shell/builder.d.ts +31 -0
  67. package/shell/builder.d.ts.map +1 -0
  68. package/shell/csp.d.ts +37 -0
  69. package/shell/csp.d.ts.map +1 -0
  70. package/shell/custom-shell-applier.d.ts +33 -0
  71. package/shell/custom-shell-applier.d.ts.map +1 -0
  72. package/shell/custom-shell-resolver.d.ts +47 -0
  73. package/shell/custom-shell-resolver.d.ts.map +1 -0
  74. package/shell/custom-shell-types.d.ts +75 -0
  75. package/shell/custom-shell-types.d.ts.map +1 -0
  76. package/shell/custom-shell-validator.d.ts +26 -0
  77. package/shell/custom-shell-validator.d.ts.map +1 -0
  78. package/shell/data-injector.d.ts +40 -0
  79. package/shell/data-injector.d.ts.map +1 -0
  80. package/shell/index.d.ts +19 -0
  81. package/shell/index.d.ts.map +1 -0
  82. package/shell/index.js +1453 -0
  83. package/shell/types.d.ts +54 -0
  84. package/shell/types.d.ts.map +1 -0
  85. package/types/index.d.ts +1 -3
  86. package/types/index.d.ts.map +1 -1
  87. package/types/index.js +11 -11
  88. package/types/ui-config.d.ts +50 -11
  89. package/types/ui-config.d.ts.map +1 -1
  90. package/types/ui-runtime.d.ts +8 -82
  91. package/types/ui-runtime.d.ts.map +1 -1
  92. package/utils/index.d.ts +9 -3
  93. package/utils/index.d.ts.map +1 -1
  94. package/utils/index.js +59 -7
  95. package/adapters/platform-meta.constants.d.ts +0 -26
  96. package/adapters/platform-meta.constants.d.ts.map +0 -1
  97. package/adapters/platform-meta.d.ts +0 -234
  98. package/adapters/platform-meta.d.ts.map +0 -1
  99. package/base-template/bridge.d.ts +0 -90
  100. package/base-template/bridge.d.ts.map +0 -1
  101. package/base-template/default-base-template.d.ts +0 -91
  102. package/base-template/default-base-template.d.ts.map +0 -1
  103. package/base-template/index.d.ts +0 -15
  104. package/base-template/index.d.ts.map +0 -1
  105. package/base-template/index.js +0 -1393
  106. package/base-template/polyfills.d.ts +0 -31
  107. package/base-template/polyfills.d.ts.map +0 -1
  108. package/base-template/theme-styles.d.ts +0 -74
  109. package/base-template/theme-styles.d.ts.map +0 -1
  110. package/build/builders/base-builder.d.ts +0 -124
  111. package/build/builders/base-builder.d.ts.map +0 -1
  112. package/build/builders/esbuild-config.d.ts +0 -94
  113. package/build/builders/esbuild-config.d.ts.map +0 -1
  114. package/build/builders/hybrid-builder.d.ts +0 -93
  115. package/build/builders/hybrid-builder.d.ts.map +0 -1
  116. package/build/builders/index.d.ts +0 -17
  117. package/build/builders/index.d.ts.map +0 -1
  118. package/build/builders/inline-builder.d.ts +0 -83
  119. package/build/builders/inline-builder.d.ts.map +0 -1
  120. package/build/builders/static-builder.d.ts +0 -78
  121. package/build/builders/static-builder.d.ts.map +0 -1
  122. package/build/builders/types.d.ts +0 -341
  123. package/build/builders/types.d.ts.map +0 -1
  124. package/build/cdn-resources.d.ts +0 -244
  125. package/build/cdn-resources.d.ts.map +0 -1
  126. package/build/hybrid-data.d.ts +0 -127
  127. package/build/hybrid-data.d.ts.map +0 -1
  128. package/build/index.d.ts +0 -299
  129. package/build/index.d.ts.map +0 -1
  130. package/build/index.js +0 -8699
  131. package/build/ui-components-browser.d.ts +0 -64
  132. package/build/ui-components-browser.d.ts.map +0 -1
  133. package/build/widget-manifest.d.ts +0 -362
  134. package/build/widget-manifest.d.ts.map +0 -1
  135. package/bundler/cache.d.ts +0 -173
  136. package/bundler/cache.d.ts.map +0 -1
  137. package/bundler/file-cache/component-builder.d.ts +0 -167
  138. package/bundler/file-cache/component-builder.d.ts.map +0 -1
  139. package/bundler/file-cache/hash-calculator.d.ts +0 -155
  140. package/bundler/file-cache/hash-calculator.d.ts.map +0 -1
  141. package/bundler/file-cache/index.d.ts +0 -12
  142. package/bundler/file-cache/index.d.ts.map +0 -1
  143. package/bundler/file-cache/storage/filesystem.d.ts +0 -149
  144. package/bundler/file-cache/storage/filesystem.d.ts.map +0 -1
  145. package/bundler/file-cache/storage/index.d.ts +0 -11
  146. package/bundler/file-cache/storage/index.d.ts.map +0 -1
  147. package/bundler/file-cache/storage/interface.d.ts +0 -152
  148. package/bundler/file-cache/storage/interface.d.ts.map +0 -1
  149. package/bundler/file-cache/storage/redis.d.ts +0 -139
  150. package/bundler/file-cache/storage/redis.d.ts.map +0 -1
  151. package/bundler/index.d.ts +0 -35
  152. package/bundler/index.d.ts.map +0 -1
  153. package/bundler/index.js +0 -2953
  154. package/bundler/sandbox/enclave-adapter.d.ts +0 -121
  155. package/bundler/sandbox/enclave-adapter.d.ts.map +0 -1
  156. package/bundler/sandbox/executor.d.ts +0 -14
  157. package/bundler/sandbox/executor.d.ts.map +0 -1
  158. package/bundler/sandbox/policy.d.ts +0 -62
  159. package/bundler/sandbox/policy.d.ts.map +0 -1
  160. package/bundler/types.d.ts +0 -702
  161. package/bundler/types.d.ts.map +0 -1
  162. package/dependency/cdn-registry.d.ts +0 -98
  163. package/dependency/cdn-registry.d.ts.map +0 -1
  164. package/dependency/import-map.d.ts +0 -186
  165. package/dependency/import-map.d.ts.map +0 -1
  166. package/dependency/import-parser.d.ts +0 -82
  167. package/dependency/import-parser.d.ts.map +0 -1
  168. package/dependency/index.d.ts +0 -17
  169. package/dependency/index.d.ts.map +0 -1
  170. package/dependency/index.js +0 -3180
  171. package/dependency/resolver.d.ts +0 -164
  172. package/dependency/resolver.d.ts.map +0 -1
  173. package/dependency/schemas.d.ts +0 -486
  174. package/dependency/schemas.d.ts.map +0 -1
  175. package/dependency/template-loader.d.ts +0 -204
  176. package/dependency/template-loader.d.ts.map +0 -1
  177. package/dependency/template-processor.d.ts +0 -118
  178. package/dependency/template-processor.d.ts.map +0 -1
  179. package/dependency/types.d.ts +0 -739
  180. package/dependency/types.d.ts.map +0 -1
  181. package/esm/base-template/index.mjs +0 -1359
  182. package/esm/build/index.mjs +0 -8601
  183. package/esm/bundler/index.mjs +0 -2895
  184. package/esm/dependency/index.mjs +0 -3068
  185. package/esm/handlebars/index.mjs +0 -587
  186. package/esm/registry/index.mjs +0 -6305
  187. package/esm/renderers/index.mjs +0 -1557
  188. package/esm/runtime/index.mjs +0 -5361
  189. package/esm/styles/index.mjs +0 -171
  190. package/esm/theme/index.mjs +0 -756
  191. package/esm/tool-template/index.mjs +0 -3652
  192. package/esm/validation/index.mjs +0 -542
  193. package/handlebars/expression-extractor.d.ts +0 -147
  194. package/handlebars/expression-extractor.d.ts.map +0 -1
  195. package/handlebars/helpers.d.ts +0 -339
  196. package/handlebars/helpers.d.ts.map +0 -1
  197. package/handlebars/index.d.ts +0 -195
  198. package/handlebars/index.d.ts.map +0 -1
  199. package/handlebars/index.js +0 -659
  200. package/preview/claude-preview.d.ts +0 -67
  201. package/preview/claude-preview.d.ts.map +0 -1
  202. package/preview/generic-preview.d.ts +0 -66
  203. package/preview/generic-preview.d.ts.map +0 -1
  204. package/preview/index.d.ts +0 -36
  205. package/preview/index.d.ts.map +0 -1
  206. package/preview/openai-preview.d.ts +0 -70
  207. package/preview/openai-preview.d.ts.map +0 -1
  208. package/preview/types.d.ts +0 -199
  209. package/preview/types.d.ts.map +0 -1
  210. package/registry/index.d.ts +0 -46
  211. package/registry/index.d.ts.map +0 -1
  212. package/registry/index.js +0 -6342
  213. package/registry/render-template.d.ts +0 -91
  214. package/registry/render-template.d.ts.map +0 -1
  215. package/registry/tool-ui.registry.d.ts +0 -294
  216. package/registry/tool-ui.registry.d.ts.map +0 -1
  217. package/registry/uri-utils.d.ts +0 -56
  218. package/registry/uri-utils.d.ts.map +0 -1
  219. package/renderers/cache.d.ts +0 -145
  220. package/renderers/cache.d.ts.map +0 -1
  221. package/renderers/html.renderer.d.ts +0 -123
  222. package/renderers/html.renderer.d.ts.map +0 -1
  223. package/renderers/index.d.ts +0 -36
  224. package/renderers/index.d.ts.map +0 -1
  225. package/renderers/index.js +0 -1603
  226. package/renderers/mdx-client.renderer.d.ts +0 -124
  227. package/renderers/mdx-client.renderer.d.ts.map +0 -1
  228. package/renderers/registry.d.ts +0 -133
  229. package/renderers/registry.d.ts.map +0 -1
  230. package/renderers/types.d.ts +0 -343
  231. package/renderers/types.d.ts.map +0 -1
  232. package/renderers/utils/detect.d.ts +0 -107
  233. package/renderers/utils/detect.d.ts.map +0 -1
  234. package/renderers/utils/hash.d.ts +0 -40
  235. package/renderers/utils/hash.d.ts.map +0 -1
  236. package/renderers/utils/index.d.ts +0 -9
  237. package/renderers/utils/index.d.ts.map +0 -1
  238. package/renderers/utils/transpiler.d.ts +0 -70
  239. package/renderers/utils/transpiler.d.ts.map +0 -1
  240. package/runtime/adapters/html.adapter.d.ts +0 -59
  241. package/runtime/adapters/html.adapter.d.ts.map +0 -1
  242. package/runtime/adapters/index.d.ts +0 -26
  243. package/runtime/adapters/index.d.ts.map +0 -1
  244. package/runtime/adapters/mdx.adapter.d.ts +0 -73
  245. package/runtime/adapters/mdx.adapter.d.ts.map +0 -1
  246. package/runtime/adapters/types.d.ts +0 -95
  247. package/runtime/adapters/types.d.ts.map +0 -1
  248. package/runtime/csp.d.ts +0 -48
  249. package/runtime/csp.d.ts.map +0 -1
  250. package/runtime/index.d.ts +0 -17
  251. package/runtime/index.d.ts.map +0 -1
  252. package/runtime/index.js +0 -5432
  253. package/runtime/mcp-bridge.d.ts +0 -101
  254. package/runtime/mcp-bridge.d.ts.map +0 -1
  255. package/runtime/renderer-runtime.d.ts +0 -133
  256. package/runtime/renderer-runtime.d.ts.map +0 -1
  257. package/runtime/sanitizer.d.ts +0 -180
  258. package/runtime/sanitizer.d.ts.map +0 -1
  259. package/runtime/types.d.ts +0 -415
  260. package/runtime/types.d.ts.map +0 -1
  261. package/runtime/wrapper.d.ts +0 -421
  262. package/runtime/wrapper.d.ts.map +0 -1
  263. package/styles/index.d.ts +0 -8
  264. package/styles/index.d.ts.map +0 -1
  265. package/styles/index.js +0 -222
  266. package/styles/variants.d.ts +0 -51
  267. package/styles/variants.d.ts.map +0 -1
  268. package/theme/cdn.d.ts +0 -195
  269. package/theme/cdn.d.ts.map +0 -1
  270. package/theme/css-to-theme.d.ts +0 -64
  271. package/theme/css-to-theme.d.ts.map +0 -1
  272. package/theme/index.d.ts +0 -19
  273. package/theme/index.d.ts.map +0 -1
  274. package/theme/index.js +0 -814
  275. package/theme/platforms.d.ts +0 -102
  276. package/theme/platforms.d.ts.map +0 -1
  277. package/theme/presets/github-openai.d.ts +0 -50
  278. package/theme/presets/github-openai.d.ts.map +0 -1
  279. package/theme/presets/index.d.ts +0 -11
  280. package/theme/presets/index.d.ts.map +0 -1
  281. package/theme/theme.d.ts +0 -396
  282. package/theme/theme.d.ts.map +0 -1
  283. package/tool-template/builder.d.ts +0 -213
  284. package/tool-template/builder.d.ts.map +0 -1
  285. package/tool-template/index.d.ts +0 -16
  286. package/tool-template/index.d.ts.map +0 -1
  287. package/tool-template/index.js +0 -3690
  288. package/validation/error-box.d.ts +0 -56
  289. package/validation/error-box.d.ts.map +0 -1
  290. package/validation/index.d.ts +0 -13
  291. package/validation/index.d.ts.map +0 -1
  292. package/validation/index.js +0 -576
  293. package/validation/schema-paths.d.ts +0 -118
  294. package/validation/schema-paths.d.ts.map +0 -1
  295. package/validation/template-validator.d.ts +0 -143
  296. package/validation/template-validator.d.ts.map +0 -1
  297. package/validation/wrapper.d.ts +0 -97
  298. package/validation/wrapper.d.ts.map +0 -1
@@ -1,56 +0,0 @@
1
- /**
2
- * @file error-box.ts
3
- * @description Validation error box component for displaying input validation failures.
4
- *
5
- * Renders a styled error card when component options fail Zod validation.
6
- * Shows component name and invalid parameter without exposing internal details.
7
- *
8
- * @example
9
- * ```typescript
10
- * import { validationErrorBox } from '@frontmcp/ui';
11
- *
12
- * validationErrorBox({
13
- * componentName: 'Button',
14
- * invalidParam: 'variant',
15
- * });
16
- * ```
17
- *
18
- * @module @frontmcp/ui/validation/error-box
19
- */
20
- /**
21
- * Options for rendering a validation error box
22
- */
23
- export interface ValidationErrorBoxOptions {
24
- /** Name of the component that failed validation */
25
- componentName: string;
26
- /** Name of the invalid parameter (path notation for nested, e.g., "htmx.get") */
27
- invalidParam: string;
28
- }
29
- /**
30
- * Renders a validation error box for invalid component options
31
- *
32
- * This component is rendered in place of the actual component when
33
- * validation fails. It shows:
34
- * - The component name
35
- * - The invalid parameter name
36
- * - A styled error message
37
- *
38
- * It does NOT expose:
39
- * - The actual invalid value
40
- * - Internal Zod error messages
41
- * - Schema structure details
42
- *
43
- * @param options - Error box configuration
44
- * @returns HTML string for the error box
45
- *
46
- * @example
47
- * ```typescript
48
- * // Basic usage
49
- * validationErrorBox({ componentName: 'Button', invalidParam: 'variant' });
50
- *
51
- * // Nested param
52
- * validationErrorBox({ componentName: 'Button', invalidParam: 'htmx.get' });
53
- * ```
54
- */
55
- export declare function validationErrorBox(options: ValidationErrorBoxOptions): string;
56
- //# sourceMappingURL=error-box.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error-box.d.ts","sourceRoot":"","sources":["../../src/validation/error-box.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAQH;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,mDAAmD;IACnD,aAAa,EAAE,MAAM,CAAC;IACtB,iFAAiF;IACjF,YAAY,EAAE,MAAM,CAAC;CACtB;AAaD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,MAAM,CAgB7E"}
@@ -1,13 +0,0 @@
1
- /**
2
- * Validation Module
3
- *
4
- * Component input validation and template validation against Zod schemas
5
- * for FrontMCP UI widgets.
6
- *
7
- * @packageDocumentation
8
- */
9
- export { validationErrorBox, type ValidationErrorBoxOptions } from './error-box';
10
- export { validateOptions, type ValidationConfig, type ValidationResult } from './wrapper';
11
- export { extractSchemaPaths, getSchemaPathStrings, isValidSchemaPath, getTypeAtPath, getPathInfo, getRootFieldNames, getTypeDescription, type SchemaPath, type ExtractPathsOptions, } from './schema-paths';
12
- export { validateTemplate, formatValidationWarnings, logValidationWarnings, assertTemplateValid, isTemplateValid, getMissingFields, type TemplateValidationResult, type TemplateValidationError, type TemplateValidationWarning, type ValidateTemplateOptions, type ValidationErrorType, type ValidationWarningType, } from './template-validator';
13
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAEjF,OAAO,EAAE,eAAe,EAAE,KAAK,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAM1F,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,KAAK,UAAU,EACf,KAAK,mBAAmB,GACzB,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EACxB,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,GAC3B,MAAM,sBAAsB,CAAC"}
@@ -1,576 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // libs/uipack/src/validation/index.ts
21
- var validation_exports = {};
22
- __export(validation_exports, {
23
- assertTemplateValid: () => assertTemplateValid,
24
- extractSchemaPaths: () => extractSchemaPaths,
25
- formatValidationWarnings: () => formatValidationWarnings,
26
- getMissingFields: () => getMissingFields,
27
- getPathInfo: () => getPathInfo,
28
- getRootFieldNames: () => getRootFieldNames,
29
- getSchemaPathStrings: () => getSchemaPathStrings,
30
- getTypeAtPath: () => getTypeAtPath,
31
- getTypeDescription: () => getTypeDescription,
32
- isTemplateValid: () => isTemplateValid,
33
- isValidSchemaPath: () => isValidSchemaPath,
34
- logValidationWarnings: () => logValidationWarnings,
35
- validateOptions: () => validateOptions,
36
- validateTemplate: () => validateTemplate,
37
- validationErrorBox: () => validationErrorBox
38
- });
39
- module.exports = __toCommonJS(validation_exports);
40
-
41
- // libs/uipack/src/utils/index.ts
42
- var import_utils = require("@frontmcp/utils");
43
-
44
- // libs/uipack/src/validation/error-box.ts
45
- var errorIcon = `<svg class="w-5 h-5 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
46
- <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"/>
47
- </svg>`;
48
- function validationErrorBox(options) {
49
- const { componentName, invalidParam } = options;
50
- return `<div
51
- class="validation-error flex items-start gap-3 p-4 bg-red-50 border border-red-200 text-red-800 rounded-lg"
52
- role="alert"
53
- data-testid="validation-error"
54
- data-component="${(0, import_utils.escapeHtml)(componentName)}"
55
- data-param="${(0, import_utils.escapeHtml)(invalidParam)}"
56
- >
57
- ${errorIcon}
58
- <div class="min-w-0">
59
- <p class="font-semibold text-sm">${(0, import_utils.escapeHtml)(componentName)}: Invalid Configuration</p>
60
- <p class="text-sm opacity-90 mt-0.5">The "${(0, import_utils.escapeHtml)(invalidParam)}" parameter is invalid.</p>
61
- </div>
62
- </div>`;
63
- }
64
-
65
- // libs/uipack/src/validation/wrapper.ts
66
- function getFirstInvalidPath(error) {
67
- const firstError = error.issues[0];
68
- if (!firstError || firstError.path.length === 0) {
69
- return "options";
70
- }
71
- return firstError.path.map(String).join(".");
72
- }
73
- function validateOptions(options, config) {
74
- const result = config.schema.safeParse(options);
75
- if (result.success) {
76
- return { success: true, data: result.data };
77
- }
78
- const invalidParam = getFirstInvalidPath(result.error);
79
- return {
80
- success: false,
81
- error: validationErrorBox({
82
- componentName: config.componentName,
83
- invalidParam
84
- })
85
- };
86
- }
87
-
88
- // libs/uipack/src/validation/schema-paths.ts
89
- var import_zod = require("zod");
90
- function extractSchemaPaths(schema, prefix = "output", options = {}) {
91
- const { maxDepth = 10, includeArrayItems = true } = options;
92
- const paths = [];
93
- const visited = /* @__PURE__ */ new Set();
94
- function recurse(currentSchema, currentPath, depth, isOptional, isNullable, isArrayItem) {
95
- if (depth > maxDepth) return;
96
- const pathKey = `${currentPath}:${depth}`;
97
- if (visited.has(pathKey)) return;
98
- visited.add(pathKey);
99
- const description = currentSchema.description;
100
- const innerType = unwrapType(currentSchema);
101
- paths.push({
102
- path: currentPath,
103
- zodType: currentSchema,
104
- optional: isOptional,
105
- nullable: isNullable,
106
- isArrayItem,
107
- description
108
- });
109
- if (innerType instanceof import_zod.z.ZodObject) {
110
- const shape = innerType.shape;
111
- for (const [key, value] of Object.entries(shape)) {
112
- const childSchema = value;
113
- const childOptional = isOptional || isOptionalType(childSchema);
114
- const childNullable = isNullable || isNullableType(childSchema);
115
- recurse(childSchema, `${currentPath}.${key}`, depth + 1, childOptional, childNullable, false);
116
- }
117
- } else if (innerType instanceof import_zod.z.ZodArray && includeArrayItems) {
118
- const itemSchema = innerType.element;
119
- recurse(itemSchema, `${currentPath}.[]`, depth + 1, isOptional, isNullable, true);
120
- } else if (innerType instanceof import_zod.z.ZodUnion || innerType instanceof import_zod.z.ZodDiscriminatedUnion) {
121
- const options2 = "options" in innerType ? innerType.options : [];
122
- for (const option of options2) {
123
- recurse(option, currentPath, depth, isOptional, isNullable, isArrayItem);
124
- }
125
- } else if (innerType instanceof import_zod.z.ZodIntersection) {
126
- recurse(innerType._def.left, currentPath, depth, isOptional, isNullable, isArrayItem);
127
- recurse(innerType._def.right, currentPath, depth, isOptional, isNullable, isArrayItem);
128
- } else if (innerType instanceof import_zod.z.ZodRecord) {
129
- const valueSchema = innerType._def.valueType;
130
- recurse(valueSchema, `${currentPath}.[]`, depth + 1, isOptional, isNullable, true);
131
- } else if (innerType instanceof import_zod.z.ZodTuple) {
132
- const items = innerType._def.items;
133
- items.forEach((item, index) => {
134
- recurse(item, `${currentPath}.${index}`, depth + 1, isOptional, isNullable, true);
135
- });
136
- }
137
- }
138
- recurse(schema, prefix, 0, false, false, false);
139
- const seen = /* @__PURE__ */ new Set();
140
- return paths.filter((p) => {
141
- if (seen.has(p.path)) return false;
142
- seen.add(p.path);
143
- return true;
144
- });
145
- }
146
- function unwrapType(schema) {
147
- if (schema instanceof import_zod.z.ZodOptional) {
148
- return unwrapType(schema.unwrap());
149
- }
150
- if (schema instanceof import_zod.z.ZodNullable) {
151
- return unwrapType(schema.unwrap());
152
- }
153
- if (schema instanceof import_zod.z.ZodDefault) {
154
- return unwrapType(schema._def.innerType);
155
- }
156
- if (schema instanceof import_zod.z.ZodCatch && "innerType" in schema._def) {
157
- return unwrapType(schema._def.innerType);
158
- }
159
- return schema;
160
- }
161
- function isOptionalType(schema) {
162
- if (schema instanceof import_zod.z.ZodOptional) return true;
163
- if (schema instanceof import_zod.z.ZodDefault) return true;
164
- if (schema instanceof import_zod.z.ZodNullable) return isOptionalType(schema.unwrap());
165
- return false;
166
- }
167
- function isNullableType(schema) {
168
- if (schema instanceof import_zod.z.ZodNullable) return true;
169
- if (schema instanceof import_zod.z.ZodOptional) return isNullableType(schema.unwrap());
170
- return false;
171
- }
172
- function getSchemaPathStrings(schema, prefix = "output") {
173
- const paths = extractSchemaPaths(schema, prefix);
174
- return new Set(paths.map((p) => p.path));
175
- }
176
- function isValidSchemaPath(schema, path) {
177
- const prefix = path.split(".")[0];
178
- const paths = getSchemaPathStrings(schema, prefix);
179
- if (paths.has(path)) return true;
180
- const normalizedPath = normalizePath(path);
181
- if (paths.has(normalizedPath)) return true;
182
- const pathParts = path.split(".");
183
- for (let i = pathParts.length - 1; i >= 0; i--) {
184
- const part = pathParts[i];
185
- if (/^\d+$/.test(part)) {
186
- const parentPath = pathParts.slice(0, i).join(".");
187
- const wildcardPath = `${parentPath}.[]`;
188
- if (paths.has(wildcardPath)) {
189
- const restPath = pathParts.slice(i + 1).join(".");
190
- if (restPath) {
191
- const fullWildcardPath = `${wildcardPath}.${restPath}`;
192
- const normalizedFullPath = normalizePath(fullWildcardPath);
193
- if (paths.has(normalizedFullPath)) return true;
194
- } else {
195
- return true;
196
- }
197
- }
198
- }
199
- }
200
- return false;
201
- }
202
- function normalizePath(path) {
203
- return path.replace(/\.\d+\./g, ".[].").replace(/\.\d+$/g, ".[]").replace(/\[\d+\]/g, ".[]");
204
- }
205
- function getTypeAtPath(schema, path) {
206
- const prefix = path.split(".")[0];
207
- const paths = extractSchemaPaths(schema, prefix);
208
- let schemaPath = paths.find((p) => p.path === path);
209
- if (!schemaPath) {
210
- const normalizedPath = normalizePath(path);
211
- schemaPath = paths.find((p) => p.path === normalizedPath);
212
- }
213
- return schemaPath?.zodType;
214
- }
215
- function getPathInfo(schema, path) {
216
- const prefix = path.split(".")[0];
217
- const paths = extractSchemaPaths(schema, prefix);
218
- let schemaPath = paths.find((p) => p.path === path);
219
- if (!schemaPath) {
220
- const normalizedPath = normalizePath(path);
221
- schemaPath = paths.find((p) => p.path === normalizedPath);
222
- }
223
- return schemaPath;
224
- }
225
- function getRootFieldNames(schema) {
226
- const unwrapped = unwrapType(schema);
227
- if (unwrapped instanceof import_zod.z.ZodObject) {
228
- return Object.keys(unwrapped.shape);
229
- }
230
- return [];
231
- }
232
- function getTypeDescription(schema, path) {
233
- const zodType = getTypeAtPath(schema, path);
234
- if (!zodType) return "unknown";
235
- return describeZodType(zodType);
236
- }
237
- function describeZodType(schema) {
238
- const inner = unwrapType(schema);
239
- if (inner instanceof import_zod.z.ZodString) return "string";
240
- if (inner instanceof import_zod.z.ZodNumber) return "number";
241
- if (inner instanceof import_zod.z.ZodBoolean) return "boolean";
242
- if (inner instanceof import_zod.z.ZodDate) return "Date";
243
- if (inner instanceof import_zod.z.ZodBigInt) return "bigint";
244
- if (inner instanceof import_zod.z.ZodSymbol) return "symbol";
245
- if (inner instanceof import_zod.z.ZodUndefined) return "undefined";
246
- if (inner instanceof import_zod.z.ZodNull) return "null";
247
- if (inner instanceof import_zod.z.ZodVoid) return "void";
248
- if (inner instanceof import_zod.z.ZodAny) return "any";
249
- if (inner instanceof import_zod.z.ZodUnknown) return "unknown";
250
- if (inner instanceof import_zod.z.ZodNever) return "never";
251
- if (inner instanceof import_zod.z.ZodLiteral) return `literal(${JSON.stringify(inner.value)})`;
252
- if (inner instanceof import_zod.z.ZodEnum) return `enum(${inner.options.join(" | ")})`;
253
- if (inner instanceof import_zod.z.ZodArray) return `${describeZodType(inner.element)}[]`;
254
- if (inner instanceof import_zod.z.ZodObject) return "object";
255
- if (inner instanceof import_zod.z.ZodUnion) return "union";
256
- if (inner instanceof import_zod.z.ZodDiscriminatedUnion) return "discriminatedUnion";
257
- if (inner instanceof import_zod.z.ZodIntersection) return "intersection";
258
- if (inner instanceof import_zod.z.ZodTuple) return "tuple";
259
- if (inner instanceof import_zod.z.ZodRecord) return `Record<string, ${describeZodType(inner._def.valueType)}>`;
260
- if (inner instanceof import_zod.z.ZodMap) return "Map";
261
- if (inner instanceof import_zod.z.ZodSet) return "Set";
262
- if (inner instanceof import_zod.z.ZodFunction) return "function";
263
- if (inner instanceof import_zod.z.ZodPromise) return "Promise";
264
- if (schema instanceof import_zod.z.ZodOptional) {
265
- return `${describeZodType(schema.unwrap())}?`;
266
- }
267
- if (schema instanceof import_zod.z.ZodNullable) {
268
- return `${describeZodType(schema.unwrap())} | null`;
269
- }
270
- return "unknown";
271
- }
272
-
273
- // libs/uipack/src/handlebars/expression-extractor.ts
274
- var EXPRESSION_REGEX = /\{\{\{?(?!!)(#|\/)?([^}]+?)\}?\}\}/g;
275
- var PATH_REGEX = /\b(output|input|structuredContent)(\.[a-zA-Z_$][a-zA-Z0-9_$]*|\.\[[^\]]+\])+/g;
276
- var KEYWORDS = /* @__PURE__ */ new Set(["this", "else", "@index", "@key", "@first", "@last", "@root"]);
277
- function extractExpressions(template) {
278
- const expressions = [];
279
- const positionMap = buildPositionMap(template);
280
- let match;
281
- EXPRESSION_REGEX.lastIndex = 0;
282
- while ((match = EXPRESSION_REGEX.exec(template)) !== null) {
283
- const fullExpression = match[0];
284
- const prefix = match[1];
285
- const content = match[2].trim();
286
- const position = positionMap.get(match.index) ?? { line: 1, column: 1 };
287
- let type = "variable";
288
- let helperName;
289
- if (prefix === "/") {
290
- type = "block-close";
291
- helperName = content;
292
- } else if (prefix === "#") {
293
- type = "block";
294
- const parts = content.split(/\s+/);
295
- helperName = parts[0];
296
- } else {
297
- const parts = content.split(/\s+/);
298
- if (parts.length > 1 && !content.startsWith("(")) {
299
- const firstToken = parts[0];
300
- if (!firstToken.includes(".") && !KEYWORDS.has(firstToken)) {
301
- type = "helper";
302
- helperName = firstToken;
303
- }
304
- }
305
- }
306
- const paths = extractPathsFromContent(content);
307
- for (const path of paths) {
308
- expressions.push({
309
- path,
310
- fullExpression,
311
- line: position.line,
312
- column: position.column,
313
- type,
314
- helperName
315
- });
316
- }
317
- if (paths.length === 0 && type === "variable") {
318
- const cleanContent = content.trim();
319
- if (!KEYWORDS.has(cleanContent) && !cleanContent.includes(" ") && !cleanContent.startsWith("(")) {
320
- }
321
- }
322
- }
323
- return expressions;
324
- }
325
- function extractPathsFromContent(content) {
326
- const paths = [];
327
- let match;
328
- const regex = new RegExp(PATH_REGEX.source, "g");
329
- while ((match = regex.exec(content)) !== null) {
330
- paths.push(match[0]);
331
- }
332
- return paths;
333
- }
334
- function buildPositionMap(template) {
335
- const map = /* @__PURE__ */ new Map();
336
- let line = 1;
337
- let column = 1;
338
- for (let i = 0; i < template.length; i++) {
339
- map.set(i, { line, column });
340
- if (template[i] === "\n") {
341
- line++;
342
- column = 1;
343
- } else {
344
- column++;
345
- }
346
- }
347
- return map;
348
- }
349
- function extractAll(template) {
350
- const expressions = extractExpressions(template);
351
- const paths = [...new Set(expressions.map((e) => e.path))];
352
- return {
353
- expressions,
354
- paths,
355
- outputPaths: paths.filter((p) => p.startsWith("output.")),
356
- inputPaths: paths.filter((p) => p.startsWith("input.")),
357
- structuredContentPaths: paths.filter((p) => p.startsWith("structuredContent."))
358
- };
359
- }
360
- function normalizePath2(path) {
361
- return path.replace(/\.\d+\./g, ".[].").replace(/\.\d+$/g, ".[]").replace(/\[\d+\]/g, ".[]");
362
- }
363
-
364
- // libs/uipack/src/validation/template-validator.ts
365
- function validateTemplate(template, outputSchema, options = {}) {
366
- const { inputSchema, warnOnOptional = true, suggestSimilar = true, maxSuggestionDistance = 3 } = options;
367
- const errors = [];
368
- const warnings = [];
369
- const extraction = extractAll(template);
370
- const expressions = extractExpressions(template);
371
- const outputPaths = getSchemaPathStrings(outputSchema, "output");
372
- const inputPaths = inputSchema ? getSchemaPathStrings(inputSchema, "input") : /* @__PURE__ */ new Set();
373
- const outputPathInfos = extractSchemaPaths(outputSchema, "output");
374
- const inputPathInfos = inputSchema ? extractSchemaPaths(inputSchema, "input") : [];
375
- const pathInfoMap = /* @__PURE__ */ new Map();
376
- for (const info of [...outputPathInfos, ...inputPathInfos]) {
377
- pathInfoMap.set(info.path, info);
378
- }
379
- for (const expr of expressions) {
380
- const { path, fullExpression, line, column } = expr;
381
- let validPaths;
382
- let allPaths;
383
- if (path.startsWith("output.")) {
384
- validPaths = outputPaths;
385
- allPaths = Array.from(outputPaths);
386
- } else if (path.startsWith("input.")) {
387
- if (!inputSchema) {
388
- continue;
389
- }
390
- validPaths = inputPaths;
391
- allPaths = Array.from(inputPaths);
392
- } else if (path.startsWith("structuredContent.")) {
393
- continue;
394
- } else {
395
- continue;
396
- }
397
- const normalizedPath = normalizePath2(path);
398
- const isValid = validPaths.has(path) || validPaths.has(normalizedPath);
399
- if (!isValid) {
400
- const isArrayAccess = checkArrayAccess(path, validPaths);
401
- if (!isArrayAccess) {
402
- const suggestions = suggestSimilar ? findSimilarPaths(path, allPaths, maxSuggestionDistance) : [];
403
- errors.push({
404
- type: "missing_field",
405
- path,
406
- expression: fullExpression,
407
- line,
408
- column,
409
- message: `Field '${getFieldName(path)}' does not exist in ${getSchemaName(path)} schema`,
410
- suggestions
411
- });
412
- }
413
- } else {
414
- const pathInfo = pathInfoMap.get(path) ?? pathInfoMap.get(normalizedPath);
415
- if (pathInfo && warnOnOptional) {
416
- if (pathInfo.optional && expr.type === "variable") {
417
- const hasGuard = hasConditionalGuard(template, path);
418
- if (!hasGuard) {
419
- warnings.push({
420
- type: "optional_field",
421
- path,
422
- expression: fullExpression,
423
- line,
424
- message: `Accessing optional field '${getFieldName(path)}' without {{#if}} guard`
425
- });
426
- }
427
- }
428
- }
429
- }
430
- }
431
- return {
432
- valid: errors.length === 0,
433
- errors,
434
- warnings,
435
- templatePaths: extraction.paths,
436
- schemaPaths: [...outputPaths, ...inputPaths]
437
- };
438
- }
439
- function checkArrayAccess(path, validPaths) {
440
- const parts = path.split(".");
441
- for (let i = 0; i < parts.length; i++) {
442
- if (/^\d+$/.test(parts[i])) {
443
- const wildcardParts = [...parts];
444
- wildcardParts[i] = "[]";
445
- const wildcardPath = wildcardParts.join(".");
446
- if (validPaths.has(wildcardPath)) {
447
- return true;
448
- }
449
- }
450
- }
451
- return false;
452
- }
453
- function getFieldName(path) {
454
- const parts = path.split(".");
455
- return parts[parts.length - 1];
456
- }
457
- function getSchemaName(path) {
458
- if (path.startsWith("output.")) return "output";
459
- if (path.startsWith("input.")) return "input";
460
- if (path.startsWith("structuredContent.")) return "structuredContent";
461
- return "unknown";
462
- }
463
- function hasConditionalGuard(template, path) {
464
- const guardPattern = new RegExp(`\\{\\{#if\\s+${escapeRegex(path)}`, "i");
465
- return guardPattern.test(template);
466
- }
467
- function escapeRegex(str) {
468
- return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
469
- }
470
- function findSimilarPaths(path, validPaths, maxDistance) {
471
- const fieldName = getFieldName(path);
472
- const prefix = path.substring(0, path.lastIndexOf(".") + 1);
473
- const suggestions = [];
474
- for (const validPath of validPaths) {
475
- if (!validPath.startsWith(prefix)) continue;
476
- const validFieldName = getFieldName(validPath);
477
- const distance = levenshteinDistance(fieldName, validFieldName);
478
- if (distance <= maxDistance && distance > 0) {
479
- suggestions.push({ path: validPath, distance });
480
- }
481
- }
482
- return suggestions.sort((a, b) => a.distance - b.distance).slice(0, 3).map((s) => s.path);
483
- }
484
- function levenshteinDistance(a, b) {
485
- const matrix = [];
486
- for (let i = 0; i <= a.length; i++) {
487
- matrix[i] = [i];
488
- }
489
- for (let j = 0; j <= b.length; j++) {
490
- matrix[0][j] = j;
491
- }
492
- for (let i = 1; i <= a.length; i++) {
493
- for (let j = 1; j <= b.length; j++) {
494
- const cost = a[i - 1] === b[j - 1] ? 0 : 1;
495
- matrix[i][j] = Math.min(
496
- matrix[i - 1][j] + 1,
497
- // deletion
498
- matrix[i][j - 1] + 1,
499
- // insertion
500
- matrix[i - 1][j - 1] + cost
501
- // substitution
502
- );
503
- }
504
- }
505
- return matrix[a.length][b.length];
506
- }
507
- function formatValidationWarnings(result, toolName) {
508
- if (result.valid && result.warnings.length === 0) {
509
- return "";
510
- }
511
- const lines = [];
512
- if (result.errors.length > 0) {
513
- lines.push(`[FrontMCP] Template validation warnings for tool "${toolName}":`);
514
- lines.push("");
515
- for (const error of result.errors) {
516
- lines.push(` Line ${error.line}: ${error.expression}`);
517
- lines.push(` ${error.message}`);
518
- if (error.suggestions.length > 0) {
519
- lines.push(` Did you mean: ${error.suggestions.join(", ")}?`);
520
- }
521
- lines.push("");
522
- }
523
- const outputFields = result.schemaPaths.filter((p) => p.startsWith("output.") && p.split(".").length === 2).map((p) => p.replace("output.", ""));
524
- if (outputFields.length > 0) {
525
- lines.push(` Available output fields: ${outputFields.join(", ")}`);
526
- }
527
- }
528
- if (result.warnings.length > 0) {
529
- if (lines.length > 0) lines.push("");
530
- lines.push(` Warnings:`);
531
- for (const warning of result.warnings) {
532
- lines.push(` Line ${warning.line}: ${warning.message}`);
533
- }
534
- }
535
- return lines.join("\n");
536
- }
537
- function logValidationWarnings(result, toolName) {
538
- const formatted = formatValidationWarnings(result, toolName);
539
- if (formatted) {
540
- console.warn(formatted);
541
- }
542
- }
543
- function assertTemplateValid(template, outputSchema, toolName) {
544
- const result = validateTemplate(template, outputSchema);
545
- if (!result.valid) {
546
- const formatted = formatValidationWarnings(result, toolName);
547
- throw new Error(`Template validation failed for tool "${toolName}":
548
- ${formatted}`);
549
- }
550
- }
551
- function isTemplateValid(template, outputSchema) {
552
- const result = validateTemplate(template, outputSchema);
553
- return result.valid;
554
- }
555
- function getMissingFields(template, outputSchema) {
556
- const result = validateTemplate(template, outputSchema);
557
- return result.errors.map((e) => e.path);
558
- }
559
- // Annotate the CommonJS export names for ESM import in node:
560
- 0 && (module.exports = {
561
- assertTemplateValid,
562
- extractSchemaPaths,
563
- formatValidationWarnings,
564
- getMissingFields,
565
- getPathInfo,
566
- getRootFieldNames,
567
- getSchemaPathStrings,
568
- getTypeAtPath,
569
- getTypeDescription,
570
- isTemplateValid,
571
- isValidSchemaPath,
572
- logValidationWarnings,
573
- validateOptions,
574
- validateTemplate,
575
- validationErrorBox
576
- });