@frontmcp/uipack 0.12.2 → 1.0.0-beta.10

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 +4 -13
  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 +4 -13
  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,542 +0,0 @@
1
- // libs/uipack/src/utils/index.ts
2
- import {
3
- safeStringify,
4
- escapeHtml,
5
- escapeHtmlAttr,
6
- escapeJsString,
7
- escapeScriptClose,
8
- safeJsonForScript
9
- } from "@frontmcp/utils";
10
-
11
- // libs/uipack/src/validation/error-box.ts
12
- var errorIcon = `<svg class="w-5 h-5 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
13
- <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"/>
14
- </svg>`;
15
- function validationErrorBox(options) {
16
- const { componentName, invalidParam } = options;
17
- return `<div
18
- class="validation-error flex items-start gap-3 p-4 bg-red-50 border border-red-200 text-red-800 rounded-lg"
19
- role="alert"
20
- data-testid="validation-error"
21
- data-component="${escapeHtml(componentName)}"
22
- data-param="${escapeHtml(invalidParam)}"
23
- >
24
- ${errorIcon}
25
- <div class="min-w-0">
26
- <p class="font-semibold text-sm">${escapeHtml(componentName)}: Invalid Configuration</p>
27
- <p class="text-sm opacity-90 mt-0.5">The "${escapeHtml(invalidParam)}" parameter is invalid.</p>
28
- </div>
29
- </div>`;
30
- }
31
-
32
- // libs/uipack/src/validation/wrapper.ts
33
- function getFirstInvalidPath(error) {
34
- const firstError = error.issues[0];
35
- if (!firstError || firstError.path.length === 0) {
36
- return "options";
37
- }
38
- return firstError.path.map(String).join(".");
39
- }
40
- function validateOptions(options, config) {
41
- const result = config.schema.safeParse(options);
42
- if (result.success) {
43
- return { success: true, data: result.data };
44
- }
45
- const invalidParam = getFirstInvalidPath(result.error);
46
- return {
47
- success: false,
48
- error: validationErrorBox({
49
- componentName: config.componentName,
50
- invalidParam
51
- })
52
- };
53
- }
54
-
55
- // libs/uipack/src/validation/schema-paths.ts
56
- import { z } from "zod";
57
- function extractSchemaPaths(schema, prefix = "output", options = {}) {
58
- const { maxDepth = 10, includeArrayItems = true } = options;
59
- const paths = [];
60
- const visited = /* @__PURE__ */ new Set();
61
- function recurse(currentSchema, currentPath, depth, isOptional, isNullable, isArrayItem) {
62
- if (depth > maxDepth) return;
63
- const pathKey = `${currentPath}:${depth}`;
64
- if (visited.has(pathKey)) return;
65
- visited.add(pathKey);
66
- const description = currentSchema.description;
67
- const innerType = unwrapType(currentSchema);
68
- paths.push({
69
- path: currentPath,
70
- zodType: currentSchema,
71
- optional: isOptional,
72
- nullable: isNullable,
73
- isArrayItem,
74
- description
75
- });
76
- if (innerType instanceof z.ZodObject) {
77
- const shape = innerType.shape;
78
- for (const [key, value] of Object.entries(shape)) {
79
- const childSchema = value;
80
- const childOptional = isOptional || isOptionalType(childSchema);
81
- const childNullable = isNullable || isNullableType(childSchema);
82
- recurse(childSchema, `${currentPath}.${key}`, depth + 1, childOptional, childNullable, false);
83
- }
84
- } else if (innerType instanceof z.ZodArray && includeArrayItems) {
85
- const itemSchema = innerType.element;
86
- recurse(itemSchema, `${currentPath}.[]`, depth + 1, isOptional, isNullable, true);
87
- } else if (innerType instanceof z.ZodUnion || innerType instanceof z.ZodDiscriminatedUnion) {
88
- const options2 = "options" in innerType ? innerType.options : [];
89
- for (const option of options2) {
90
- recurse(option, currentPath, depth, isOptional, isNullable, isArrayItem);
91
- }
92
- } else if (innerType instanceof z.ZodIntersection) {
93
- recurse(innerType._def.left, currentPath, depth, isOptional, isNullable, isArrayItem);
94
- recurse(innerType._def.right, currentPath, depth, isOptional, isNullable, isArrayItem);
95
- } else if (innerType instanceof z.ZodRecord) {
96
- const valueSchema = innerType._def.valueType;
97
- recurse(valueSchema, `${currentPath}.[]`, depth + 1, isOptional, isNullable, true);
98
- } else if (innerType instanceof z.ZodTuple) {
99
- const items = innerType._def.items;
100
- items.forEach((item, index) => {
101
- recurse(item, `${currentPath}.${index}`, depth + 1, isOptional, isNullable, true);
102
- });
103
- }
104
- }
105
- recurse(schema, prefix, 0, false, false, false);
106
- const seen = /* @__PURE__ */ new Set();
107
- return paths.filter((p) => {
108
- if (seen.has(p.path)) return false;
109
- seen.add(p.path);
110
- return true;
111
- });
112
- }
113
- function unwrapType(schema) {
114
- if (schema instanceof z.ZodOptional) {
115
- return unwrapType(schema.unwrap());
116
- }
117
- if (schema instanceof z.ZodNullable) {
118
- return unwrapType(schema.unwrap());
119
- }
120
- if (schema instanceof z.ZodDefault) {
121
- return unwrapType(schema._def.innerType);
122
- }
123
- if (schema instanceof z.ZodCatch && "innerType" in schema._def) {
124
- return unwrapType(schema._def.innerType);
125
- }
126
- return schema;
127
- }
128
- function isOptionalType(schema) {
129
- if (schema instanceof z.ZodOptional) return true;
130
- if (schema instanceof z.ZodDefault) return true;
131
- if (schema instanceof z.ZodNullable) return isOptionalType(schema.unwrap());
132
- return false;
133
- }
134
- function isNullableType(schema) {
135
- if (schema instanceof z.ZodNullable) return true;
136
- if (schema instanceof z.ZodOptional) return isNullableType(schema.unwrap());
137
- return false;
138
- }
139
- function getSchemaPathStrings(schema, prefix = "output") {
140
- const paths = extractSchemaPaths(schema, prefix);
141
- return new Set(paths.map((p) => p.path));
142
- }
143
- function isValidSchemaPath(schema, path) {
144
- const prefix = path.split(".")[0];
145
- const paths = getSchemaPathStrings(schema, prefix);
146
- if (paths.has(path)) return true;
147
- const normalizedPath = normalizePath(path);
148
- if (paths.has(normalizedPath)) return true;
149
- const pathParts = path.split(".");
150
- for (let i = pathParts.length - 1; i >= 0; i--) {
151
- const part = pathParts[i];
152
- if (/^\d+$/.test(part)) {
153
- const parentPath = pathParts.slice(0, i).join(".");
154
- const wildcardPath = `${parentPath}.[]`;
155
- if (paths.has(wildcardPath)) {
156
- const restPath = pathParts.slice(i + 1).join(".");
157
- if (restPath) {
158
- const fullWildcardPath = `${wildcardPath}.${restPath}`;
159
- const normalizedFullPath = normalizePath(fullWildcardPath);
160
- if (paths.has(normalizedFullPath)) return true;
161
- } else {
162
- return true;
163
- }
164
- }
165
- }
166
- }
167
- return false;
168
- }
169
- function normalizePath(path) {
170
- return path.replace(/\.\d+\./g, ".[].").replace(/\.\d+$/g, ".[]").replace(/\[\d+\]/g, ".[]");
171
- }
172
- function getTypeAtPath(schema, path) {
173
- const prefix = path.split(".")[0];
174
- const paths = extractSchemaPaths(schema, prefix);
175
- let schemaPath = paths.find((p) => p.path === path);
176
- if (!schemaPath) {
177
- const normalizedPath = normalizePath(path);
178
- schemaPath = paths.find((p) => p.path === normalizedPath);
179
- }
180
- return schemaPath?.zodType;
181
- }
182
- function getPathInfo(schema, path) {
183
- const prefix = path.split(".")[0];
184
- const paths = extractSchemaPaths(schema, prefix);
185
- let schemaPath = paths.find((p) => p.path === path);
186
- if (!schemaPath) {
187
- const normalizedPath = normalizePath(path);
188
- schemaPath = paths.find((p) => p.path === normalizedPath);
189
- }
190
- return schemaPath;
191
- }
192
- function getRootFieldNames(schema) {
193
- const unwrapped = unwrapType(schema);
194
- if (unwrapped instanceof z.ZodObject) {
195
- return Object.keys(unwrapped.shape);
196
- }
197
- return [];
198
- }
199
- function getTypeDescription(schema, path) {
200
- const zodType = getTypeAtPath(schema, path);
201
- if (!zodType) return "unknown";
202
- return describeZodType(zodType);
203
- }
204
- function describeZodType(schema) {
205
- const inner = unwrapType(schema);
206
- if (inner instanceof z.ZodString) return "string";
207
- if (inner instanceof z.ZodNumber) return "number";
208
- if (inner instanceof z.ZodBoolean) return "boolean";
209
- if (inner instanceof z.ZodDate) return "Date";
210
- if (inner instanceof z.ZodBigInt) return "bigint";
211
- if (inner instanceof z.ZodSymbol) return "symbol";
212
- if (inner instanceof z.ZodUndefined) return "undefined";
213
- if (inner instanceof z.ZodNull) return "null";
214
- if (inner instanceof z.ZodVoid) return "void";
215
- if (inner instanceof z.ZodAny) return "any";
216
- if (inner instanceof z.ZodUnknown) return "unknown";
217
- if (inner instanceof z.ZodNever) return "never";
218
- if (inner instanceof z.ZodLiteral) return `literal(${JSON.stringify(inner.value)})`;
219
- if (inner instanceof z.ZodEnum) return `enum(${inner.options.join(" | ")})`;
220
- if (inner instanceof z.ZodArray) return `${describeZodType(inner.element)}[]`;
221
- if (inner instanceof z.ZodObject) return "object";
222
- if (inner instanceof z.ZodUnion) return "union";
223
- if (inner instanceof z.ZodDiscriminatedUnion) return "discriminatedUnion";
224
- if (inner instanceof z.ZodIntersection) return "intersection";
225
- if (inner instanceof z.ZodTuple) return "tuple";
226
- if (inner instanceof z.ZodRecord) return `Record<string, ${describeZodType(inner._def.valueType)}>`;
227
- if (inner instanceof z.ZodMap) return "Map";
228
- if (inner instanceof z.ZodSet) return "Set";
229
- if (inner instanceof z.ZodFunction) return "function";
230
- if (inner instanceof z.ZodPromise) return "Promise";
231
- if (schema instanceof z.ZodOptional) {
232
- return `${describeZodType(schema.unwrap())}?`;
233
- }
234
- if (schema instanceof z.ZodNullable) {
235
- return `${describeZodType(schema.unwrap())} | null`;
236
- }
237
- return "unknown";
238
- }
239
-
240
- // libs/uipack/src/handlebars/expression-extractor.ts
241
- var EXPRESSION_REGEX = /\{\{\{?(?!!)(#|\/)?([^}]+?)\}?\}\}/g;
242
- var PATH_REGEX = /\b(output|input|structuredContent)(\.[a-zA-Z_$][a-zA-Z0-9_$]*|\.\[[^\]]+\])+/g;
243
- var KEYWORDS = /* @__PURE__ */ new Set(["this", "else", "@index", "@key", "@first", "@last", "@root"]);
244
- function extractExpressions(template) {
245
- const expressions = [];
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
- };
@@ -1,147 +0,0 @@
1
- /**
2
- * Handlebars Expression Extractor
3
- *
4
- * Extracts variable paths from Handlebars templates for validation
5
- * against schemas.
6
- *
7
- * @packageDocumentation
8
- */
9
- /**
10
- * Type of Handlebars expression.
11
- */
12
- export type ExpressionType = 'variable' | 'helper' | 'block' | 'block-close';
13
- /**
14
- * Extracted expression with metadata.
15
- */
16
- export interface ExtractedExpression {
17
- /** The variable path (e.g., "output.temperature") */
18
- path: string;
19
- /** The full expression (e.g., "{{output.temperature}}") */
20
- fullExpression: string;
21
- /** Line number in template (1-indexed) */
22
- line: number;
23
- /** Column position (1-indexed) */
24
- column: number;
25
- /** Type of expression */
26
- type: ExpressionType;
27
- /** For helpers, the helper name */
28
- helperName?: string;
29
- }
30
- /**
31
- * Result of expression extraction.
32
- */
33
- export interface ExtractionResult {
34
- /** All extracted expressions */
35
- expressions: ExtractedExpression[];
36
- /** Unique variable paths */
37
- paths: string[];
38
- /** Paths starting with "output." */
39
- outputPaths: string[];
40
- /** Paths starting with "input." */
41
- inputPaths: string[];
42
- /** Paths starting with "structuredContent." */
43
- structuredContentPaths: string[];
44
- }
45
- /**
46
- * Extract all Handlebars expressions from a template.
47
- *
48
- * @param template - Handlebars template string
49
- * @returns Array of extracted expressions with metadata
50
- *
51
- * @example
52
- * ```typescript
53
- * const expressions = extractExpressions('<div>{{output.name}}</div>');
54
- * // [{ path: 'output.name', fullExpression: '{{output.name}}', ... }]
55
- * ```
56
- */
57
- export declare function extractExpressions(template: string): ExtractedExpression[];
58
- /**
59
- * Extract all variable paths from a template.
60
- *
61
- * @param template - Handlebars template string
62
- * @returns Array of unique variable paths
63
- *
64
- * @example
65
- * ```typescript
66
- * const paths = extractVariablePaths('<div>{{output.a}} {{input.b}}</div>');
67
- * // ['output.a', 'input.b']
68
- * ```
69
- */
70
- export declare function extractVariablePaths(template: string): string[];
71
- /**
72
- * Extract only output.* paths from a template.
73
- *
74
- * @param template - Handlebars template string
75
- * @returns Array of unique output paths
76
- *
77
- * @example
78
- * ```typescript
79
- * const paths = extractOutputPaths('<div>{{output.temp}} {{input.city}}</div>');
80
- * // ['output.temp']
81
- * ```
82
- */
83
- export declare function extractOutputPaths(template: string): string[];
84
- /**
85
- * Extract only input.* paths from a template.
86
- *
87
- * @param template - Handlebars template string
88
- * @returns Array of unique input paths
89
- */
90
- export declare function extractInputPaths(template: string): string[];
91
- /**
92
- * Extract only structuredContent.* paths from a template.
93
- *
94
- * @param template - Handlebars template string
95
- * @returns Array of unique structuredContent paths
96
- */
97
- export declare function extractStructuredContentPaths(template: string): string[];
98
- /**
99
- * Comprehensive extraction returning all path categories.
100
- *
101
- * @param template - Handlebars template string
102
- * @returns Extraction result with categorized paths
103
- *
104
- * @example
105
- * ```typescript
106
- * const result = extractAll('<div>{{output.a}} {{input.b}}</div>');
107
- * // {
108
- * // expressions: [...],
109
- * // paths: ['output.a', 'input.b'],
110
- * // outputPaths: ['output.a'],
111
- * // inputPaths: ['input.b'],
112
- * // structuredContentPaths: []
113
- * // }
114
- * ```
115
- */
116
- export declare function extractAll(template: string): ExtractionResult;
117
- /**
118
- * Check if a template contains any Handlebars expressions with variable paths.
119
- *
120
- * @param template - Handlebars template string
121
- * @returns true if template contains variable paths
122
- */
123
- export declare function hasVariablePaths(template: string): boolean;
124
- /**
125
- * Get expression details at a specific line and column.
126
- *
127
- * @param template - Handlebars template string
128
- * @param line - Line number (1-indexed)
129
- * @param column - Column number (1-indexed)
130
- * @returns Expression at position or undefined
131
- */
132
- export declare function getExpressionAt(template: string, line: number, column: number): ExtractedExpression | undefined;
133
- /**
134
- * Normalize a path for comparison.
135
- * Converts array index access to wildcard format.
136
- *
137
- * @param path - Variable path
138
- * @returns Normalized path
139
- *
140
- * @example
141
- * ```typescript
142
- * normalizePath('output.items.0.name'); // 'output.items.[].name'
143
- * normalizePath('output.data[0].value'); // 'output.data.[].value'
144
- * ```
145
- */
146
- export declare function normalizePath(path: string): string;
147
- //# sourceMappingURL=expression-extractor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"expression-extractor.d.ts","sourceRoot":"","sources":["../../src/handlebars/expression-extractor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,aAAa,CAAC;AAE7E;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,cAAc,EAAE,MAAM,CAAC;IACvB,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,yBAAyB;IACzB,IAAI,EAAE,cAAc,CAAC;IACrB,mCAAmC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,gCAAgC;IAChC,WAAW,EAAE,mBAAmB,EAAE,CAAC;IACnC,4BAA4B;IAC5B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,oCAAoC;IACpC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,mCAAmC;IACnC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,+CAA+C;IAC/C,sBAAsB,EAAE,MAAM,EAAE,CAAC;CAClC;AAwCD;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,mBAAmB,EAAE,CAkE1E;AAgDD;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAI/D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAE7D;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAE5D;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAExE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAW7D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAS/G;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQlD"}