@copilotkit/shared 2.0.0-rc.31 → 2.0.0-rc.33

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 (231) hide show
  1. package/README.md +1 -1
  2. package/dist/generative-ui/catalog/catalog-export.cjs +329 -0
  3. package/dist/generative-ui/catalog/catalog-export.cjs.map +1 -0
  4. package/dist/generative-ui/catalog/catalog-export.d.cts +92 -0
  5. package/dist/generative-ui/catalog/catalog-export.d.cts.map +1 -0
  6. package/dist/generative-ui/catalog/catalog-export.d.mts +92 -0
  7. package/dist/generative-ui/catalog/catalog-export.d.mts.map +1 -0
  8. package/dist/generative-ui/catalog/catalog-export.mjs +328 -0
  9. package/dist/generative-ui/catalog/catalog-export.mjs.map +1 -0
  10. package/dist/generative-ui/catalog/catalog.cjs +315 -0
  11. package/dist/generative-ui/catalog/catalog.cjs.map +1 -0
  12. package/dist/generative-ui/catalog/catalog.d.cts +407 -0
  13. package/dist/generative-ui/catalog/catalog.d.cts.map +1 -0
  14. package/dist/generative-ui/catalog/catalog.d.mts +407 -0
  15. package/dist/generative-ui/catalog/catalog.d.mts.map +1 -0
  16. package/dist/generative-ui/catalog/catalog.mjs +312 -0
  17. package/dist/generative-ui/catalog/catalog.mjs.map +1 -0
  18. package/dist/generative-ui/catalog/errors.cjs +13 -0
  19. package/dist/generative-ui/catalog/errors.cjs.map +1 -0
  20. package/dist/generative-ui/catalog/errors.d.cts +46 -0
  21. package/dist/generative-ui/catalog/errors.d.cts.map +1 -0
  22. package/dist/generative-ui/catalog/errors.d.mts +46 -0
  23. package/dist/generative-ui/catalog/errors.d.mts.map +1 -0
  24. package/dist/generative-ui/catalog/errors.mjs +12 -0
  25. package/dist/generative-ui/catalog/errors.mjs.map +1 -0
  26. package/dist/generative-ui/catalog/index.d.mts +6 -0
  27. package/dist/generative-ui/catalog/json-schema.cjs +16 -0
  28. package/dist/generative-ui/catalog/json-schema.cjs.map +1 -0
  29. package/dist/generative-ui/catalog/json-schema.d.cts +12 -0
  30. package/dist/generative-ui/catalog/json-schema.d.cts.map +1 -0
  31. package/dist/generative-ui/catalog/json-schema.d.mts +12 -0
  32. package/dist/generative-ui/catalog/json-schema.d.mts.map +1 -0
  33. package/dist/generative-ui/catalog/json-schema.mjs +16 -0
  34. package/dist/generative-ui/catalog/json-schema.mjs.map +1 -0
  35. package/dist/generative-ui/catalog/refs.cjs +21 -0
  36. package/dist/generative-ui/catalog/refs.cjs.map +1 -0
  37. package/dist/generative-ui/catalog/refs.d.cts +55 -0
  38. package/dist/generative-ui/catalog/refs.d.cts.map +1 -0
  39. package/dist/generative-ui/catalog/refs.d.mts +55 -0
  40. package/dist/generative-ui/catalog/refs.d.mts.map +1 -0
  41. package/dist/generative-ui/catalog/refs.mjs +18 -0
  42. package/dist/generative-ui/catalog/refs.mjs.map +1 -0
  43. package/dist/generative-ui/catalog/schema.cjs +74 -0
  44. package/dist/generative-ui/catalog/schema.cjs.map +1 -0
  45. package/dist/generative-ui/catalog/schema.d.cts +43 -0
  46. package/dist/generative-ui/catalog/schema.d.cts.map +1 -0
  47. package/dist/generative-ui/catalog/schema.d.mts +43 -0
  48. package/dist/generative-ui/catalog/schema.d.mts.map +1 -0
  49. package/dist/generative-ui/catalog/schema.mjs +68 -0
  50. package/dist/generative-ui/catalog/schema.mjs.map +1 -0
  51. package/dist/generative-ui/index.cjs +247 -0
  52. package/dist/generative-ui/index.d.cts +33 -0
  53. package/dist/generative-ui/index.d.mts +35 -0
  54. package/dist/generative-ui/index.mjs +34 -0
  55. package/dist/generative-ui/is-record.cjs +6 -1
  56. package/dist/generative-ui/is-record.cjs.map +1 -1
  57. package/dist/generative-ui/is-record.d.cts +6 -0
  58. package/dist/generative-ui/is-record.d.cts.map +1 -0
  59. package/dist/generative-ui/is-record.d.mts +6 -0
  60. package/dist/generative-ui/is-record.d.mts.map +1 -0
  61. package/dist/generative-ui/is-record.mjs +6 -2
  62. package/dist/generative-ui/is-record.mjs.map +1 -1
  63. package/dist/generative-ui/standard/chart.cjs +56 -0
  64. package/dist/generative-ui/standard/chart.cjs.map +1 -0
  65. package/dist/generative-ui/standard/chart.d.cts +62 -0
  66. package/dist/generative-ui/standard/chart.d.cts.map +1 -0
  67. package/dist/generative-ui/standard/chart.d.mts +62 -0
  68. package/dist/generative-ui/standard/chart.d.mts.map +1 -0
  69. package/dist/generative-ui/standard/chart.mjs +54 -0
  70. package/dist/generative-ui/standard/chart.mjs.map +1 -0
  71. package/dist/generative-ui/standard/checks.cjs +74 -0
  72. package/dist/generative-ui/standard/checks.cjs.map +1 -0
  73. package/dist/generative-ui/standard/checks.d.cts +56 -0
  74. package/dist/generative-ui/standard/checks.d.cts.map +1 -0
  75. package/dist/generative-ui/standard/checks.d.mts +56 -0
  76. package/dist/generative-ui/standard/checks.d.mts.map +1 -0
  77. package/dist/generative-ui/standard/checks.mjs +71 -0
  78. package/dist/generative-ui/standard/checks.mjs.map +1 -0
  79. package/dist/generative-ui/standard/components.cjs +23 -0
  80. package/dist/generative-ui/standard/components.cjs.map +1 -0
  81. package/dist/generative-ui/standard/components.d.cts +24 -0
  82. package/dist/generative-ui/standard/components.d.cts.map +1 -0
  83. package/dist/generative-ui/standard/components.d.mts +24 -0
  84. package/dist/generative-ui/standard/components.d.mts.map +1 -0
  85. package/dist/generative-ui/standard/components.mjs +22 -0
  86. package/dist/generative-ui/standard/components.mjs.map +1 -0
  87. package/dist/generative-ui/standard/composites.cjs +143 -0
  88. package/dist/generative-ui/standard/composites.cjs.map +1 -0
  89. package/dist/generative-ui/standard/composites.d.cts +233 -0
  90. package/dist/generative-ui/standard/composites.d.cts.map +1 -0
  91. package/dist/generative-ui/standard/composites.d.mts +233 -0
  92. package/dist/generative-ui/standard/composites.d.mts.map +1 -0
  93. package/dist/generative-ui/standard/composites.mjs +132 -0
  94. package/dist/generative-ui/standard/composites.mjs.map +1 -0
  95. package/dist/generative-ui/standard/data.cjs +176 -0
  96. package/dist/generative-ui/standard/data.cjs.map +1 -0
  97. package/dist/generative-ui/standard/data.d.cts +365 -0
  98. package/dist/generative-ui/standard/data.d.cts.map +1 -0
  99. package/dist/generative-ui/standard/data.d.mts +365 -0
  100. package/dist/generative-ui/standard/data.d.mts.map +1 -0
  101. package/dist/generative-ui/standard/data.mjs +167 -0
  102. package/dist/generative-ui/standard/data.mjs.map +1 -0
  103. package/dist/generative-ui/standard/declarations.cjs +40 -0
  104. package/dist/generative-ui/standard/declarations.cjs.map +1 -0
  105. package/dist/generative-ui/standard/declarations.d.cts +2570 -0
  106. package/dist/generative-ui/standard/declarations.d.cts.map +1 -0
  107. package/dist/generative-ui/standard/declarations.d.mts +2571 -0
  108. package/dist/generative-ui/standard/declarations.d.mts.map +1 -0
  109. package/dist/generative-ui/standard/declarations.mjs +39 -0
  110. package/dist/generative-ui/standard/declarations.mjs.map +1 -0
  111. package/dist/generative-ui/standard/feedback.cjs +97 -0
  112. package/dist/generative-ui/standard/feedback.cjs.map +1 -0
  113. package/dist/generative-ui/standard/feedback.d.cts +133 -0
  114. package/dist/generative-ui/standard/feedback.d.cts.map +1 -0
  115. package/dist/generative-ui/standard/feedback.d.mts +133 -0
  116. package/dist/generative-ui/standard/feedback.d.mts.map +1 -0
  117. package/dist/generative-ui/standard/feedback.mjs +90 -0
  118. package/dist/generative-ui/standard/feedback.mjs.map +1 -0
  119. package/dist/generative-ui/standard/index.d.mts +16 -0
  120. package/dist/generative-ui/standard/inputs.cjs +333 -0
  121. package/dist/generative-ui/standard/inputs.cjs.map +1 -0
  122. package/dist/generative-ui/standard/inputs.d.cts +1128 -0
  123. package/dist/generative-ui/standard/inputs.d.cts.map +1 -0
  124. package/dist/generative-ui/standard/inputs.d.mts +1128 -0
  125. package/dist/generative-ui/standard/inputs.d.mts.map +1 -0
  126. package/dist/generative-ui/standard/inputs.mjs +318 -0
  127. package/dist/generative-ui/standard/inputs.mjs.map +1 -0
  128. package/dist/generative-ui/standard/layout.cjs +289 -0
  129. package/dist/generative-ui/standard/layout.cjs.map +1 -0
  130. package/dist/generative-ui/standard/layout.d.cts +1974 -0
  131. package/dist/generative-ui/standard/layout.d.cts.map +1 -0
  132. package/dist/generative-ui/standard/layout.d.mts +1975 -0
  133. package/dist/generative-ui/standard/layout.d.mts.map +1 -0
  134. package/dist/generative-ui/standard/layout.mjs +269 -0
  135. package/dist/generative-ui/standard/layout.mjs.map +1 -0
  136. package/dist/generative-ui/standard/map.cjs +27 -0
  137. package/dist/generative-ui/standard/map.cjs.map +1 -0
  138. package/dist/generative-ui/standard/map.d.cts +31 -0
  139. package/dist/generative-ui/standard/map.d.cts.map +1 -0
  140. package/dist/generative-ui/standard/map.d.mts +31 -0
  141. package/dist/generative-ui/standard/map.d.mts.map +1 -0
  142. package/dist/generative-ui/standard/map.mjs +25 -0
  143. package/dist/generative-ui/standard/map.mjs.map +1 -0
  144. package/dist/generative-ui/standard/media.cjs +215 -0
  145. package/dist/generative-ui/standard/media.cjs.map +1 -0
  146. package/dist/generative-ui/standard/media.d.cts +396 -0
  147. package/dist/generative-ui/standard/media.d.cts.map +1 -0
  148. package/dist/generative-ui/standard/media.d.mts +396 -0
  149. package/dist/generative-ui/standard/media.d.mts.map +1 -0
  150. package/dist/generative-ui/standard/media.mjs +205 -0
  151. package/dist/generative-ui/standard/media.mjs.map +1 -0
  152. package/dist/generative-ui/standard/parameter-order.cjs +231 -0
  153. package/dist/generative-ui/standard/parameter-order.cjs.map +1 -0
  154. package/dist/generative-ui/standard/parameter-order.d.cts +84 -0
  155. package/dist/generative-ui/standard/parameter-order.d.cts.map +1 -0
  156. package/dist/generative-ui/standard/parameter-order.d.mts +84 -0
  157. package/dist/generative-ui/standard/parameter-order.d.mts.map +1 -0
  158. package/dist/generative-ui/standard/parameter-order.mjs +230 -0
  159. package/dist/generative-ui/standard/parameter-order.mjs.map +1 -0
  160. package/dist/generative-ui/standard/styles.cjs +62 -0
  161. package/dist/generative-ui/standard/styles.cjs.map +1 -0
  162. package/dist/generative-ui/standard/styles.d.cts +17 -0
  163. package/dist/generative-ui/standard/styles.d.cts.map +1 -0
  164. package/dist/generative-ui/standard/styles.d.mts +17 -0
  165. package/dist/generative-ui/standard/styles.d.mts.map +1 -0
  166. package/dist/generative-ui/standard/styles.mjs +60 -0
  167. package/dist/generative-ui/standard/styles.mjs.map +1 -0
  168. package/dist/generative-ui/standard/text.cjs +226 -0
  169. package/dist/generative-ui/standard/text.cjs.map +1 -0
  170. package/dist/generative-ui/standard/text.d.cts +522 -0
  171. package/dist/generative-ui/standard/text.d.cts.map +1 -0
  172. package/dist/generative-ui/standard/text.d.mts +522 -0
  173. package/dist/generative-ui/standard/text.d.mts.map +1 -0
  174. package/dist/generative-ui/standard/text.mjs +209 -0
  175. package/dist/generative-ui/standard/text.mjs.map +1 -0
  176. package/dist/generative-ui/standard/theme.cjs +115 -0
  177. package/dist/generative-ui/standard/theme.cjs.map +1 -0
  178. package/dist/generative-ui/standard/theme.d.cts +60 -0
  179. package/dist/generative-ui/standard/theme.d.cts.map +1 -0
  180. package/dist/generative-ui/standard/theme.d.mts +60 -0
  181. package/dist/generative-ui/standard/theme.d.mts.map +1 -0
  182. package/dist/generative-ui/standard/theme.mjs +112 -0
  183. package/dist/generative-ui/standard/theme.mjs.map +1 -0
  184. package/dist/generative-ui/standard/tokens.cjs +336 -0
  185. package/dist/generative-ui/standard/tokens.cjs.map +1 -0
  186. package/dist/generative-ui/standard/tokens.d.cts +76 -0
  187. package/dist/generative-ui/standard/tokens.d.cts.map +1 -0
  188. package/dist/generative-ui/standard/tokens.d.mts +76 -0
  189. package/dist/generative-ui/standard/tokens.d.mts.map +1 -0
  190. package/dist/generative-ui/standard/tokens.mjs +305 -0
  191. package/dist/generative-ui/standard/tokens.mjs.map +1 -0
  192. package/dist/index.cjs.map +1 -1
  193. package/dist/index.d.cts +10 -10
  194. package/dist/index.d.mts +10 -10
  195. package/dist/index.mjs.map +1 -1
  196. package/dist/index.umd.js +2 -2
  197. package/dist/index.umd.js.map +1 -1
  198. package/dist/package.cjs +1 -1
  199. package/dist/package.mjs +1 -1
  200. package/package.json +7 -3
  201. package/src/generative-ui/base.ts +9 -0
  202. package/src/generative-ui/catalog/catalog-export.ts +478 -0
  203. package/src/generative-ui/catalog/catalog.ts +1167 -0
  204. package/src/generative-ui/catalog/errors.ts +102 -0
  205. package/src/generative-ui/catalog/index.ts +6 -0
  206. package/src/generative-ui/catalog/json-schema.ts +14 -0
  207. package/src/generative-ui/catalog/refs.ts +87 -0
  208. package/src/generative-ui/catalog/schema.ts +107 -0
  209. package/src/generative-ui/index.ts +7 -0
  210. package/src/generative-ui/is-record.ts +6 -1
  211. package/src/generative-ui/standard/__tests__/theme.test.ts +61 -0
  212. package/src/generative-ui/standard/__tests__/tokens.test.ts +139 -0
  213. package/src/generative-ui/standard/chart.ts +79 -0
  214. package/src/generative-ui/standard/checks.ts +98 -0
  215. package/src/generative-ui/standard/components.ts +35 -0
  216. package/src/generative-ui/standard/composites.ts +158 -0
  217. package/src/generative-ui/standard/data.ts +213 -0
  218. package/src/generative-ui/standard/declarations.ts +57 -0
  219. package/src/generative-ui/standard/feedback.ts +105 -0
  220. package/src/generative-ui/standard/index.ts +19 -0
  221. package/src/generative-ui/standard/inputs.ts +423 -0
  222. package/src/generative-ui/standard/layout.ts +312 -0
  223. package/src/generative-ui/standard/map.ts +32 -0
  224. package/src/generative-ui/standard/media.ts +265 -0
  225. package/src/generative-ui/standard/parameter-order.ts +155 -0
  226. package/src/generative-ui/standard/styles.ts +79 -0
  227. package/src/generative-ui/standard/text.ts +210 -0
  228. package/src/generative-ui/standard/theme.ts +198 -0
  229. package/src/generative-ui/standard/tokens.ts +317 -0
  230. package/src/index.ts +1 -1
  231. package/tsdown.config.ts +1 -1
@@ -0,0 +1,315 @@
1
+ const require_basic_functions = require('../basic-functions.cjs');
2
+ const require_is_record = require('../is-record.cjs');
3
+ const require_child_refs = require('../child-refs.cjs');
4
+ const require_types = require('../types.cjs');
5
+ const require_json_schema = require('./json-schema.cjs');
6
+
7
+ //#region src/generative-ui/catalog/catalog.ts
8
+ /** The A2UI component envelope: `id`, `component`, `catalogId`, `accessibility`, `metadata`. */
9
+ const RESERVED_KEYS = new Set([
10
+ "id",
11
+ "component",
12
+ ...require_types.A2UI_COMPONENT_ENVELOPE_KEYS
13
+ ]);
14
+ /** The id of the catalog that declared each component, for the inspector. */
15
+ const componentCatalogs = /* @__PURE__ */ new WeakMap();
16
+ /**
17
+ * The id of the catalog that declared each component of `ui`. A component
18
+ * from `extends` keeps the id of its base. Not exported from the package.
19
+ */
20
+ function componentCatalogIds(ui) {
21
+ return componentCatalogs.get(ui) ?? /* @__PURE__ */ new Map();
22
+ }
23
+ /**
24
+ * The catalogs that an operation can name: the id of `ui`, then the ids of
25
+ * the catalogs in its `extends` that declared a component. Not exported
26
+ * from the package.
27
+ */
28
+ function catalogIdsOf(ui) {
29
+ const declared = componentCatalogs.get(ui)?.values() ?? [];
30
+ return [...new Set([ui.id, ...declared])];
31
+ }
32
+ /**
33
+ * Experimental. Declares the components the model can render, the app state
34
+ * they read, and the functions they call.
35
+ *
36
+ * - A prop with the name of a top-level state key is bound to that state.
37
+ * - `bind: { prop: (state, props) => value }` binds a prop to a selector.
38
+ * - An event binds to the function with its name, else to the name without
39
+ * `on` (`onAddToCart` calls `addToCart`).
40
+ * - `writable: ["value"]` gives the component a `setValue` prop. See
41
+ * `GenerativeUIComponentDefinition.writable`.
42
+ *
43
+ * The model does not see bound props or matched events.
44
+ *
45
+ * @param config - `id`, then optional `extends`, `state`, `functions` and
46
+ * `overrides`, then `components`. Put `state` before `components`, so the selectors
47
+ * get typed state.
48
+ * @throws Error when a name comes from two places, an override names no
49
+ * component of the bases, `props` is not an object
50
+ * schema with a JSON Schema, a key is reserved or used
51
+ * twice on a component, an event matches two functions, an unmatched event
52
+ * has no `parameters`, a `bind` key is not a prop, a `writable` key is not
53
+ * a prop or is a bound prop, or a setter name is already a key of the
54
+ * component. Also throws when `parameterOrder` contains duplicate or unknown
55
+ * keys, or an ordered component declares integer-index keys whose JSON object
56
+ * enumeration order cannot be controlled.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const ui = createGenerativeUI({
61
+ * id: "acme/store@1",
62
+ * state: { cart: cartSchema },
63
+ * functions: { addToCart: { parameters: z.object({ productId: z.string() }) } },
64
+ * components: {
65
+ * CartSummary: {
66
+ * component: CartSummary,
67
+ * props: z.object({ count: z.number() }),
68
+ * bind: { count: (state) => state.cart.count },
69
+ * },
70
+ * },
71
+ * });
72
+ * ```
73
+ */
74
+ function createGenerativeUI(config) {
75
+ return buildGenerativeUI(config);
76
+ }
77
+ function buildGenerativeUI(config) {
78
+ const where = `generative UI "${config.id}"`;
79
+ const state = /* @__PURE__ */ new Map();
80
+ const functions = /* @__PURE__ */ new Map();
81
+ const definitions = /* @__PURE__ */ new Map();
82
+ const catalogs = /* @__PURE__ */ new Map();
83
+ function add(map, kind, name, value) {
84
+ if (map.has(name)) throw new Error(`[generativeUI] ${kind} "${name}" is defined more than once in ${where}.`);
85
+ map.set(name, value);
86
+ }
87
+ const bases = config.extends ?? [];
88
+ for (const base of bases) {
89
+ for (const [name, schema] of base.state) add(state, "State key", name, schema);
90
+ for (const [name, fn] of base.functions) add(functions, "Function", name, fn);
91
+ const baseCatalogs = componentCatalogIds(base);
92
+ for (const [name, component] of base.components) {
93
+ add(definitions, "Component", name, component);
94
+ catalogs.set(name, baseCatalogs.get(name) ?? base.id);
95
+ }
96
+ }
97
+ for (const [name, override] of Object.entries(config.overrides ?? {})) {
98
+ const base = definitions.get(name);
99
+ if (!base) throw new Error(`[generativeUI] Override "${name}" is not a component of the bases of ${where}.`);
100
+ definitions.set(name, {
101
+ ...base,
102
+ component: override.component
103
+ });
104
+ }
105
+ for (const [name, schema] of Object.entries(config.state ?? {})) add(state, "State key", name, schema);
106
+ for (const [name, fn] of Object.entries(config.functions ?? {})) add(functions, "Function", name, fn);
107
+ for (const [name, fn] of functions) if (fn.requiresUserActivation === true && fn.allowedCallers !== void 0 && fn.allowedCallers !== "rendererOnly") throw new Error(`[generativeUI] Function "${name}" in ${where} requires user activation, so its allowedCallers must be "rendererOnly", not "${fn.allowedCallers}".`);
108
+ for (const [name, component] of Object.entries(config.components)) {
109
+ add(definitions, "Component", name, component);
110
+ catalogs.set(name, config.id);
111
+ }
112
+ const components = /* @__PURE__ */ new Map();
113
+ const manifestComponents = {};
114
+ for (const [name, definition] of definitions) {
115
+ const { component, manifest } = resolveComponent(name, definition, {
116
+ state,
117
+ functions,
118
+ where
119
+ });
120
+ components.set(name, component);
121
+ manifestComponents[name] = manifest;
122
+ }
123
+ return withOmit({
124
+ id: config.id,
125
+ state,
126
+ functions,
127
+ components,
128
+ manifestComponents
129
+ }, catalogs);
130
+ }
131
+ /** Adds the `omit` method to the data of a generative UI. */
132
+ function withOmit(data, catalogs) {
133
+ const omit = (names) => {
134
+ for (const name of names) if (!data.components.has(name)) throw new Error(`[generativeUI] Cannot omit "${name}": it is not a component of generative UI "${data.id}".`);
135
+ const isKept = (name) => !names.includes(name);
136
+ return withOmit({
137
+ id: data.id,
138
+ state: data.state,
139
+ functions: data.functions,
140
+ components: new Map([...data.components].filter(([name]) => isKept(name))),
141
+ manifestComponents: Object.fromEntries(Object.entries(data.manifestComponents).filter(([name]) => isKept(name)))
142
+ }, catalogs);
143
+ };
144
+ const ui = {
145
+ ...data,
146
+ omit
147
+ };
148
+ componentCatalogs.set(ui, catalogs);
149
+ return ui;
150
+ }
151
+ /** Builds the selectors, the event map and the manifest of one component. */
152
+ function resolveComponent(name, definition, context) {
153
+ const propsJson = propsJsonSchema(name, definition, context.where);
154
+ const propKeys = Object.keys(propsJson.properties);
155
+ assertDisjointKeys(name, definition, propKeys);
156
+ assertParameterOrder(name, definition, propKeys);
157
+ const selectors = {};
158
+ for (const key of propKeys) if (context.state.has(key)) selectors[key] = (state) => state[key];
159
+ const bind = definition.bind ?? {};
160
+ const propKeySet = new Set(propKeys);
161
+ for (const [key, selector] of Object.entries(bind)) {
162
+ if (!propKeySet.has(key)) throw new Error(`[generativeUI] bind key "${key}" is not a prop of component "${name}" in ${context.where}.`);
163
+ selectors[key] = selector;
164
+ }
165
+ const eventFunctions = {};
166
+ const modelEvents = {};
167
+ const events = definition.events ?? {};
168
+ for (const [eventName, event] of Object.entries(events)) {
169
+ const functionName = matchFunction(eventName, name, context);
170
+ if (functionName !== void 0) {
171
+ const matched = context.functions.get(functionName);
172
+ if (matched && !require_basic_functions.functionCallers(matched).renderer) throw new Error(`[generativeUI] Event "${eventName}" of component "${name}" matches function "${functionName}", which the UI cannot call (allowedCallers "agentOnly") in ${context.where}.`);
173
+ eventFunctions[eventName] = functionName;
174
+ continue;
175
+ }
176
+ if (!event.parameters) throw new Error(`[generativeUI] Event "${eventName}" of component "${name}" matches no function in ${context.where}, so it needs "parameters".`);
177
+ modelEvents[eventName] = {
178
+ ...event.description ? { description: event.description } : {},
179
+ parameters: require_json_schema.toJsonSchema(event.parameters)
180
+ };
181
+ }
182
+ assertWritable(name, definition, propKeys, selectors, context.where);
183
+ return {
184
+ component: {
185
+ component: definition.component,
186
+ description: definition.description,
187
+ parameterOrder: definition.parameterOrder?.slice(),
188
+ props: definition.props,
189
+ bind: definition.bind,
190
+ events: definition.events,
191
+ slots: definition.slots,
192
+ writable: definition.writable,
193
+ accessibility: definition.accessibility ?? "wrapper",
194
+ selectors,
195
+ eventFunctions,
196
+ propKeys,
197
+ childRefs: require_child_refs.collectChildRefs(propsJson)
198
+ },
199
+ manifest: toManifest(definition, modelPropsJsonSchema(propsJson, selectors), modelEvents)
200
+ };
201
+ }
202
+ /** The JSON Schema of `props`. A component without `props` has none. */
203
+ function propsJsonSchema(name, definition, where) {
204
+ if (!definition.props) return {
205
+ type: "object",
206
+ properties: {}
207
+ };
208
+ const json = require_json_schema.toJsonSchema(definition.props);
209
+ const { properties } = json;
210
+ if (!(typeof properties === "object" && properties !== null && !Array.isArray(properties))) throw new Error(`[generativeUI] the props of component "${name}" in ${where} must be an object schema.`);
211
+ return json;
212
+ }
213
+ /**
214
+ * What the model sees of the props: the JSON Schema without the bound props,
215
+ * and with no other keys allowed.
216
+ */
217
+ function modelPropsJsonSchema(json, bound) {
218
+ const isModelKey = (key) => !require_is_record.hasOwnKey(bound, key);
219
+ const { properties, required, additionalProperties: _additionalProperties, ...rest } = json;
220
+ const modelRequired = Array.isArray(required) ? required.filter((key) => isModelKey(String(key))) : [];
221
+ return {
222
+ ...rest,
223
+ type: "object",
224
+ properties: Object.fromEntries(Object.entries(properties).filter(([key]) => isModelKey(key))),
225
+ ...modelRequired.length > 0 ? { required: modelRequired } : {},
226
+ additionalProperties: false
227
+ };
228
+ }
229
+ /** `onAddToCart` to `addToCart`. `undefined` when the name has no `on` prefix. */
230
+ function withoutOnPrefix(eventName) {
231
+ if (!(eventName.length > 2 && eventName.startsWith("on"))) return void 0;
232
+ return eventName.charAt(2).toLowerCase() + eventName.slice(3);
233
+ }
234
+ /** The declared function an event calls, or `undefined` when none matches. */
235
+ function matchFunction(eventName, componentName, context) {
236
+ const exact = context.functions.has(eventName) ? eventName : void 0;
237
+ const stripped = withoutOnPrefix(eventName);
238
+ const fromPrefix = stripped !== void 0 && context.functions.has(stripped) ? stripped : void 0;
239
+ if (exact !== void 0 && fromPrefix !== void 0) throw new Error(`[generativeUI] Event "${eventName}" of component "${componentName}" matches two functions, "${exact}" and "${fromPrefix}", in ${context.where}.`);
240
+ return exact ?? fromPrefix;
241
+ }
242
+ /** The setter prop of a writable prop: `value` gives `setValue`. */
243
+ function setterNameOf(key) {
244
+ return `set${key.charAt(0).toUpperCase()}${key.slice(1)}`;
245
+ }
246
+ /** Why a `writable` key is not valid, or `undefined` when it is valid. */
247
+ function writableProblem(key, definition, propKeys, selectors) {
248
+ if (require_is_record.hasOwnKey(definition.events ?? {}, key)) return "an event";
249
+ if (require_is_record.hasOwnKey(definition.slots ?? {}, key)) return "a slot";
250
+ if (!propKeys.includes(key)) return "not a prop";
251
+ if (require_is_record.hasOwnKey(selectors, key)) return "a bound prop";
252
+ }
253
+ function assertWritable(name, definition, propKeys, selectors, where) {
254
+ const writable = definition.writable ?? [];
255
+ const keys = new Set([
256
+ ...propKeys,
257
+ ...Object.keys(definition.events ?? {}),
258
+ ...Object.keys(definition.slots ?? {})
259
+ ]);
260
+ for (const key of writable) {
261
+ const problem = writableProblem(key, definition, propKeys, selectors);
262
+ if (problem) throw new Error(`[generativeUI] writable key "${key}" of component "${name}" is ${problem} in ${where}.`);
263
+ const setter = setterNameOf(key);
264
+ if (keys.has(setter)) throw new Error(`[generativeUI] the setter "${setter}" of writable key "${key}" is already a key of component "${name}" in ${where}.`);
265
+ }
266
+ }
267
+ function assertDisjointKeys(name, definition, propKeys) {
268
+ const seen = /* @__PURE__ */ new Set();
269
+ const keys = [
270
+ ...propKeys,
271
+ ...Object.keys(definition.events ?? {}),
272
+ ...Object.keys(definition.slots ?? {})
273
+ ];
274
+ for (const key of keys) {
275
+ if (RESERVED_KEYS.has(key)) throw new Error(`[generativeUI] "${key}" is reserved by A2UI and cannot be a prop, event or slot of component "${name}".`);
276
+ if (seen.has(key)) throw new Error(`[generativeUI] "${key}" is declared as more than one of prop, event, slot on component "${name}".`);
277
+ seen.add(key);
278
+ }
279
+ }
280
+ function assertParameterOrder(name, definition, propKeys) {
281
+ const order = definition.parameterOrder;
282
+ if (order === void 0) return;
283
+ const keys = new Set([
284
+ ...propKeys,
285
+ ...Object.keys(definition.slots ?? {}),
286
+ ...Object.keys(definition.events ?? {})
287
+ ]);
288
+ if ([...keys].some((key) => {
289
+ const index = Number(key);
290
+ return Number.isInteger(index) && index >= 0 && index < 2 ** 32 - 1 && String(index) === key;
291
+ })) throw new Error(`[generativeUI] Component "${name}" with parameterOrder cannot declare integer-index keys: JSON object enumeration sorts them numerically before other keys, ignoring the requested order.`);
292
+ if (!Array.isArray(order) || new Set(order).size !== order.length || order.some((key) => !keys.has(key))) throw new Error(`[generativeUI] parameterOrder of component "${name}" must contain unique declared prop, slot or event names.`);
293
+ }
294
+ function toManifest(definition, modelProps, modelEvents) {
295
+ const manifest = { props: modelProps };
296
+ if (definition.description) manifest.description = definition.description;
297
+ if (Object.keys(modelEvents).length > 0) manifest.events = modelEvents;
298
+ if (definition.slots) manifest.slots = { ...definition.slots };
299
+ if (definition.parameterOrder !== void 0) {
300
+ const visible = new Set([
301
+ ...Object.keys(modelProps.properties ?? {}),
302
+ ...Object.keys(definition.slots ?? {}),
303
+ ...Object.keys(modelEvents)
304
+ ]);
305
+ manifest.parameterOrder = [...new Set([...definition.parameterOrder.filter((key) => visible.has(key)), ...visible])];
306
+ }
307
+ return manifest;
308
+ }
309
+
310
+ //#endregion
311
+ exports.catalogIdsOf = catalogIdsOf;
312
+ exports.componentCatalogIds = componentCatalogIds;
313
+ exports.createGenerativeUI = createGenerativeUI;
314
+ exports.setterNameOf = setterNameOf;
315
+ //# sourceMappingURL=catalog.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.cjs","names":["A2UI_COMPONENT_ENVELOPE_KEYS","functionCallers","toJsonSchema","collectChildRefs","hasOwnKey"],"sources":["../../../src/generative-ui/catalog/catalog.ts"],"sourcesContent":["import {\n A2UI_COMPONENT_ENVELOPE_KEYS,\n collectChildRefs,\n functionCallers,\n} from \"../base\";\nimport type {\n A2UIFunctionPermissions,\n A2UIFunctionReturnType,\n ChildRef,\n GenerativeUIComponentManifest,\n GenerativeUIJSONSchema,\n} from \"../base\";\nimport type { StandardSchemaV1 } from \"../../standard-schema\";\nimport type { GenerativeUIInvokeResult } from \"./errors\";\nimport { hasOwnKey } from \"../is-record\";\nimport { toJsonSchema } from \"./json-schema\";\nimport type { GenerativeUIChildNode } from \"./refs\";\nimport type { GenerativeUISchema, SchemaInput, SchemaOutput } from \"./schema\";\n\nexport type GenerativeUISlotKind = \"single\" | \"multiple\";\n\n/**\n * The schema of the props of a component: any Standard Schema of an object,\n * for example `z.object({ ... })` or `v.object({ ... })`. The model gets\n * the props as JSON Schema, so the schema must give one: Standard JSON\n * Schema (zod 4.2+, ArkType, Valibot with `toStandardJsonSchema`).\n * It must validate synchronously, because props are checked while a\n * surface renders.\n */\nexport type PropsSchema = StandardSchemaV1<\n Record<string, unknown>,\n Record<string, unknown>\n>;\n\n/** An event prop of a component. */\nexport interface GenerativeUIEventDefinition {\n description?: string;\n /**\n * Arguments the component passes when it calls the event prop. An event\n * that matches a declared function can leave this out. Then the function\n * parameters are used.\n */\n parameters?: GenerativeUISchema;\n}\n\n/**\n * A function that generated UI can call. The handler comes from\n * `useGenerativeUIFunction`.\n */\nexport interface GenerativeUIFunctionDefinition extends A2UIFunctionPermissions {\n description?: string;\n parameters: GenerativeUISchema;\n /**\n * Who may call it. `\"rendererOnly\"` (the default, as in A2UI 1.0): event\n * bindings and prop values. `\"agentOnly\"`: `callRendererFunction`.\n * `\"rendererOrAgent\"`: both. The agent calls only what you allow.\n */\n allowedCallers?: A2UIFunctionPermissions[\"allowedCallers\"];\n /**\n * True for a function that runs only from a user gesture, like `openUrl`.\n * It is then for the renderer only.\n */\n requiresUserActivation?: boolean;\n /** What the handler gives back, as A2UI 1.0 names it. */\n returnType?: A2UIFunctionReturnType;\n}\n\n/**\n * Gives a bound prop its value. It gets the full state and the model-set\n * props of the node, before the props schema parses them (no defaults or\n * transforms). It runs in the browser and must be pure.\n */\nexport type GenerativeUISelector = (\n state: Record<string, unknown>,\n props: Record<string, unknown>,\n) => unknown;\n\n/**\n * Method syntax makes the parameters bivariant. So a selector with typed\n * parameters fits this runtime type.\n */\ntype RuntimeSelector = {\n select(\n state: Record<string, unknown>,\n props: Record<string, unknown>,\n ): unknown;\n}[\"select\"];\n\n/**\n * Any function or class component. Unlike a framework's component type,\n * checking a value against it does not read the component's props type. So\n * a component can type its props from `typeof ui` without a circular type\n * reference. A framework narrows it with the `TComponent` parameter of\n * `GenerativeUI` and the definition types.\n */\nexport type GenerativeUIAnyComponent =\n | ((...args: never) => unknown)\n | (abstract new (...args: never) => unknown);\n\n/** One component of a generative UI, as the renderer reads it. */\nexport interface GenerativeUIComponentDefinition<\n TComponent = GenerativeUIAnyComponent,\n> {\n component: TComponent;\n description?: string;\n /**\n * Positional prefix across props, slots and events for catalog consumers.\n * Remaining visible keys follow in declaration order (props, slots, events).\n * A2UI exports encode this as property order, not a protocol field.\n */\n parameterOrder?: readonly string[];\n /** All data props: the props the model sets and the bound props. */\n props?: PropsSchema;\n /** Explicit selectors for bound props. */\n bind?: Record<string, RuntimeSelector>;\n /** Callback props. */\n events?: Record<string, GenerativeUIEventDefinition>;\n /**\n * Child props, filled with rendered child components. A \"multiple\" slot\n * takes a list of component ids, or a template `{ componentId, path }`\n * that renders one component for each item of the list at `path`.\n */\n slots?: Record<string, GenerativeUISlotKind>;\n /**\n * Props that the component can write. Each one gets a setter prop named\n * `set` + the prop name: `value` gets `setValue`. When the model binds the\n * prop to `{ \"@path\" }`, the setter writes the surface data model at that\n * path, and the agent can no longer change that path. Else the setter\n * changes local state only.\n */\n writable?: readonly string[];\n /**\n * Who applies the `accessibility` envelope of the component: by default\n * the engine, in a wrapper element around the component. `\"self\"` for a\n * component that must not be wrapped (a table row or cell) and applies\n * the attributes itself with `useGenerativeUIAccessibility()`.\n */\n accessibility?: \"wrapper\" | \"self\";\n}\n\n/** A component after `createGenerativeUI` resolved its bindings. */\nexport interface ResolvedGenerativeUIComponent<\n TComponent = GenerativeUIAnyComponent,\n> extends GenerativeUIComponentDefinition<TComponent> {\n /**\n * One selector for each bound prop. A prop with the name of a top-level\n * state key reads `state[key]`. A `bind` entry wins over the name rule.\n */\n selectors: Record<string, GenerativeUISelector>;\n /** Event name to the name of the declared function it calls. */\n eventFunctions: Record<string, string>;\n /** The keys of `props`, read from its JSON Schema. */\n propKeys: readonly string[];\n /**\n * The component references in `props` (`child()`, `childList()`), at any\n * depth. The renderer replaces each one with the rendered component. The\n * `slots` of the definition are not in here.\n */\n childRefs: readonly ChildRef[];\n /** Who applies the `accessibility` envelope; see the definition. */\n accessibility: \"wrapper\" | \"self\";\n}\n\n/** Type-level data of one component, kept in `GenerativeUI[\"definitions\"]`. */\nexport interface GenerativeUIComponentTypes {\n /** The `props` schema, or `unknown` when the component has none. */\n props: unknown;\n /** The `events` object, or `unknown` when the component has none. */\n events: unknown;\n /** The `slots` object, or `unknown` when the component has none. */\n slots: unknown;\n /** The `writable` list, or `unknown` when the component has none. */\n writable: unknown;\n}\n\n/** Type-level data of a generative UI, with the keys of its bases merged in. */\nexport interface GenerativeUIDefinitions {\n state: Record<string, GenerativeUISchema>;\n functions: Record<string, GenerativeUIFunctionDefinition>;\n components: Record<string, GenerativeUIComponentTypes>;\n}\n\n/**\n * Experimental. The result of `createGenerativeUI`: the components the model\n * can render, the app state they read, and the functions they call. Give it\n * to the provider (`generativeUI={{ ui }}`) and to the typed hooks.\n */\nexport interface GenerativeUI<\n Definitions extends GenerativeUIDefinitions = GenerativeUIDefinitions,\n TComponent = GenerativeUIAnyComponent,\n> {\n /** Surfaces pin to this id. */\n readonly id: string;\n /** State schemas, bases first. */\n readonly state: ReadonlyMap<string, GenerativeUISchema>;\n /** Declared functions, bases first. */\n readonly functions: ReadonlyMap<string, GenerativeUIFunctionDefinition>;\n /** Components, bases first. */\n readonly components: ReadonlyMap<\n string,\n ResolvedGenerativeUIComponent<TComponent>\n >;\n /** What the model sees: model-set props and unmatched events only. */\n readonly manifestComponents: Record<string, GenerativeUIComponentManifest>;\n /** Type only, never set at runtime. */\n readonly definitions?: Definitions;\n /**\n * A copy without the named components. The model no longer sees them, so\n * the prompt gets smaller. State and functions stay. Call it once, at\n * module level, like `createGenerativeUI`.\n *\n * @throws Error when a name is not a component of this UI.\n *\n * @example\n * ```ts\n * const ui = createGenerativeUI({\n * id: \"acme/app@1\",\n * extends: [standardUI.omit([\"Map\", \"Chart\"])],\n * components: {},\n * });\n * ```\n */\n omit<Names extends keyof Definitions[\"components\"] & string>(\n names: readonly Names[],\n ): GenerativeUI<OmitComponents<Definitions, Names>, TComponent>;\n}\n\n/** Definitions without some components. */\ntype OmitComponents<\n Definitions extends GenerativeUIDefinitions,\n Names extends PropertyKey,\n> = {\n state: Definitions[\"state\"];\n functions: Definitions[\"functions\"];\n components: Omit<Definitions[\"components\"], Names>;\n};\n\n/** A generative UI of any definitions and any component type. */\nexport type AnyGenerativeUI = GenerativeUI<any, any>;\n\ntype Simplify<T> = { [Key in keyof T]: T[Key] } & {};\n\n/** `A | B` to `A & B`. */\nexport type UnionToIntersection<U> = (\n U extends unknown ? (value: U) => void : never\n) extends (value: infer I) => void\n ? I\n : never;\n\ntype OutputOf<Schema> = SchemaOutput<Schema>;\ntype InputOf<Schema> = SchemaInput<Schema>;\n/** The prop names. None for a component without `props`. */\ntype PropKeys<Props> = Props extends PropsSchema\n ? keyof OutputOf<Props> & string\n : never;\n/** The input type of one prop of a props schema. */\ntype PropInput<Props, Key> = Key extends keyof InputOf<Props>\n ? InputOf<Props>[Key]\n : never;\n\n/** The type-level data of a generative UI. */\nexport type GenerativeUIDefinitionsOf<UI extends AnyGenerativeUI> = NonNullable<\n UI[\"definitions\"]\n>;\n\ntype StateValues<State> = Simplify<{\n [Key in keyof State]: OutputOf<State[Key]>;\n}>;\n\n/**\n * The state object of a generative UI, bases included. Selectors get it, and\n * `useGenerativeUIState(ui, key, value)` sets one key of it.\n */\nexport type GenerativeUIStateOf<UI extends AnyGenerativeUI> = StateValues<\n GenerativeUIDefinitionsOf<UI>[\"state\"]\n>;\n\n/** The declared functions of a generative UI, bases included. */\nexport type GenerativeUIFunctionsOf<UI extends AnyGenerativeUI> =\n GenerativeUIDefinitionsOf<UI>[\"functions\"];\n\n/** The name of a declared function of a generative UI. */\nexport type GenerativeUIFunctionName<UI extends AnyGenerativeUI> =\n keyof GenerativeUIFunctionsOf<UI> & string;\n\n/**\n * The name of a component of a generative UI, bases included. For\n * `GenerativeUI<any>`, it is `string`.\n */\nexport type GenerativeUIComponentName<UI extends AnyGenerativeUI> =\n keyof GenerativeUIDefinitionsOf<UI>[\"components\"] & string;\n\ntype FunctionInput<Functions, Name> = Name extends keyof Functions\n ? Functions[Name] extends GenerativeUIFunctionDefinition\n ? InputOf<Functions[Name][\"parameters\"]>\n : never\n : never;\n\n/** What a caller passes to a declared function (the schema input). */\nexport type GenerativeUIFunctionInput<\n UI extends AnyGenerativeUI,\n Name extends GenerativeUIFunctionName<UI>,\n> = FunctionInput<GenerativeUIFunctionsOf<UI>, Name>;\n\n/**\n * What the handler of a declared function gets: the parsed arguments (the\n * schema output, with defaults set).\n */\nexport type GenerativeUIFunctionArgs<\n UI extends AnyGenerativeUI,\n Name extends GenerativeUIFunctionName<UI>,\n> = OutputOf<GenerativeUIFunctionsOf<UI>[Name][\"parameters\"]>;\n\n/**\n * The function an event calls: the function with the same name, else the\n * name without `on` and with a lowercase first letter. `never` when none.\n */\ntype MatchedFunction<\n Name extends string,\n Functions,\n> = Name extends keyof Functions\n ? Name\n : Name extends `on${infer Rest}`\n ? Uncapitalize<Rest> extends keyof Functions\n ? Uncapitalize<Rest>\n : never\n : never;\n\n/**\n * The argument type of an event prop. The event `parameters` input when it\n * declares them, else the input of the matched function.\n */\nexport type GenerativeUIEventInput<\n Name extends string,\n Event,\n Functions,\n> = \"parameters\" extends keyof Event\n ? InputOf<Event[\"parameters\" & keyof Event]>\n : FunctionInput<Functions, MatchedFunction<Name, Functions>>;\n\n/** `Value` with each `GenerativeUIChildNode` replaced by `TNode`. */\ntype WithNodes<Value, TNode> = Value extends GenerativeUIChildNode\n ? TNode\n : Value extends readonly (infer Item)[]\n ? WithNodes<Item, TNode>[]\n : Value extends Record<string, unknown>\n ? { [Key in keyof Value]: WithNodes<Value[Key], TNode> }\n : Value;\n\ntype DataProps<Props, TNode> = Props extends PropsSchema\n ? WithNodes<OutputOf<Props>, TNode>\n : {};\n\ntype EventProps<Events, Functions> =\n Events extends Record<string, unknown>\n ? {\n [Name in keyof Events]?: (\n args: GenerativeUIEventInput<Name & string, Events[Name], Functions>,\n ) => Promise<GenerativeUIInvokeResult>;\n }\n : {};\n\ntype SlotProps<Slots, TNode> =\n Slots extends Record<string, unknown>\n ? { [Name in keyof Slots]?: TNode }\n : {};\n\ntype WritableKeys<Writable> = Writable extends readonly (infer Key)[]\n ? Key & string\n : never;\n\n/** One setter for each writable prop: `value` gets `setValue`. */\ntype SetterProps<Props, Writable> = {\n [Key in WritableKeys<Writable> &\n PropKeys<Props> as `set${Capitalize<Key>}`]: (\n value: PropInput<Props, Key>,\n ) => void;\n};\n\n/**\n * Props that the renderer passes to a component:\n * `function CheckoutForm(props: GenerativeUIComponentProps<typeof ui, \"CheckoutForm\">)`.\n * Data props are the parsed `props` schema, bound props included. Event and\n * slot props are present only when they are bound or filled. Each writable\n * prop gets a setter (`value` gets `setValue`), which is always present.\n * `TNode` is the type of a rendered child: what a slot prop holds, and what\n * replaces each `GenerativeUIChildNode` of the data props.\n */\nexport type GenerativeUIComponentProps<\n UI extends AnyGenerativeUI,\n Name extends keyof GenerativeUIDefinitionsOf<UI>[\"components\"] & string,\n TNode = unknown,\n> = Simplify<\n DataProps<GenerativeUIDefinitionsOf<UI>[\"components\"][Name][\"props\"], TNode> &\n EventProps<\n GenerativeUIDefinitionsOf<UI>[\"components\"][Name][\"events\"],\n GenerativeUIDefinitionsOf<UI>[\"functions\"]\n > &\n SlotProps<\n GenerativeUIDefinitionsOf<UI>[\"components\"][Name][\"slots\"],\n TNode\n > &\n SetterProps<\n GenerativeUIDefinitionsOf<UI>[\"components\"][Name][\"props\"],\n GenerativeUIDefinitionsOf<UI>[\"components\"][Name][\"writable\"]\n >\n>;\n\n// ---- Config types ----\n\ntype BaseDefinitions<Bases extends readonly AnyGenerativeUI[]> =\n GenerativeUIDefinitionsOf<Bases[number]>;\n\ntype MergedState<Bases extends readonly AnyGenerativeUI[], State> = Simplify<\n UnionToIntersection<BaseDefinitions<Bases>[\"state\"]> & State\n>;\n\ntype MergedFunctions<\n Bases extends readonly AnyGenerativeUI[],\n Functions,\n> = Simplify<\n UnionToIntersection<BaseDefinitions<Bases>[\"functions\"]> & Functions\n>;\n\n/** Props keys with the name of a top-level state key. */\ntype NameKeys<Props, State> = PropKeys<Props> & keyof State;\n\ntype SelectorFor<Props, State, Key extends PropKeys<Props>> = (\n state: StateValues<State>,\n // ponytail: the type hides the name-bound keys and the key itself. Other `bind` keys stay in it, because TypeScript cannot read the `bind` keys before it types the selectors.\n props: Simplify<Omit<InputOf<Props>, NameKeys<Props, State> | Key>>,\n) => PropInput<Props, Key>;\n\ntype BindSelectors<Props, State> = {\n [Key in PropKeys<Props>]?: SelectorFor<Props, State, Key>;\n};\n\n/** Name-bound keys whose state type does not fit the prop schema input. */\ntype MismatchedNameKeys<Props, State> = {\n [Key in NameKeys<Props, State>]: [OutputOf<State[Key]>] extends [\n PropInput<Props, Key>,\n ]\n ? never\n : Key;\n}[NameKeys<Props, State>];\n\n/**\n * `bind` is optional. When a prop has the name of a state key but the state\n * type does not fit, `bind` must give that prop a selector.\n */\ntype BindField<Props, State> = [MismatchedNameKeys<Props, State>] extends [\n never,\n]\n ? { bind?: BindSelectors<Props, State> }\n : {\n bind: BindSelectors<Props, State> & {\n [Key in MismatchedNameKeys<Props, State>]-?: SelectorFor<\n Props,\n State,\n Key\n >;\n };\n };\n\n/** `unknown` (no props) or an object schema. Else `props` gets an error. */\ntype PropsCheck<Props> = unknown extends Props\n ? unknown\n : Props extends PropsSchema\n ? unknown\n : { props?: PropsSchema };\n\ntype MatchCheck<Name extends string, Event, Functions> = [\n MatchedFunction<Name, Functions>,\n] extends [never]\n ? \"parameters\" extends keyof Event\n ? unknown\n : { parameters: GenerativeUISchema }\n : \"parameters\" extends keyof Event\n ? [OutputOf<Event[\"parameters\" & keyof Event]>] extends [\n FunctionInput<Functions, MatchedFunction<Name, Functions>>,\n ]\n ? unknown\n : {\n parameters: `The output of these parameters does not fit the input of function \"${MatchedFunction<\n Name,\n Functions\n > &\n string}\".`;\n }\n : unknown;\n\n/**\n * `unknown` when the event is valid. Else a type the event does not fit, so\n * `tsc` reports the error on the event.\n */\ntype EventCheck<\n Name extends string,\n Event,\n Functions,\n> = Event extends GenerativeUIEventDefinition\n ? MatchCheck<Name, Event, Functions>\n : GenerativeUIEventDefinition;\n\ntype EventsCheck<Events, Functions> = {\n [Name in keyof Events]: EventCheck<Name & string, Events[Name], Functions>;\n};\n\n/** Props that a component can list in `writable`: not bound by name. */\ntype WritableKey<Props, State> = Exclude<\n PropKeys<Props>,\n NameKeys<Props, State>\n>;\n\n/**\n * Each component config is split over four mapped types. Each one infers\n * one part (props, events, slots, writable) of every component. The checks\n * are in `NoInfer`, so they do not change what is inferred. They are not\n * intersected with schema types directly, because two schema class types do\n * not intersect cleanly.\n */\ntype ComponentsConfig<Props, Events, Slots, Writable, State, Functions> = {\n [Name in keyof Props]: {\n component: GenerativeUIAnyComponent;\n description?: string;\n parameterOrder?: readonly string[];\n props?: Props[Name];\n accessibility?: \"wrapper\" | \"self\";\n } & NoInfer<PropsCheck<Props[Name]> & BindField<Props[Name], State>>;\n} & {\n [Name in keyof Events]: {\n events?: Events[Name] & NoInfer<EventsCheck<Events[Name], Functions>>;\n };\n} & {\n [Name in keyof Slots]: {\n slots?: Slots[Name] & Record<string, GenerativeUISlotKind>;\n };\n} & {\n [Name in keyof Writable]: {\n writable?: Writable[Name] &\n NoInfer<readonly WritableKey<Props[Name & keyof Props], State>[]>;\n };\n};\n\n/** The config of `createGenerativeUI`. */\nexport interface CreateGenerativeUIConfig<\n Bases extends readonly AnyGenerativeUI[],\n State extends Record<string, GenerativeUISchema>,\n Functions extends Record<string, GenerativeUIFunctionDefinition>,\n Props extends Record<string, unknown>,\n Events extends Record<string, unknown>,\n Slots extends Record<string, unknown>,\n Writable extends Record<string, unknown>,\n Overrides = GenerativeUIOverridesConfig<Bases>,\n> {\n /** Surfaces pin to it. Use a versioned id, for example \"acme/store@1\". */\n id: string;\n /** Bases. Their state, functions and components merge in, in order. */\n extends?: Bases;\n /** App state schemas, by top-level key. Put it before `components`. */\n state?: State;\n /** Functions that components can call. */\n functions?: Functions;\n /**\n * New components for components of the bases, by name. The model\n * sees the same component: its description, props, events and slots stay.\n * The new component gets the same props as the one it replaces.\n */\n overrides?: NoInfer<Overrides>;\n /** The components the model can render. */\n components: ComponentsConfig<\n Props,\n Events,\n Slots,\n Writable,\n MergedState<Bases, State>,\n MergedFunctions<Bases, Functions>\n >;\n}\n\n/** The definitions of the bases, merged. */\nexport type GenerativeUIBasesDefinitions<\n Bases extends readonly AnyGenerativeUI[],\n> = GenerativeUIResultDefinitions<Bases, {}, {}, {}, {}, {}, {}>;\n\n/**\n * One new component for each component of the bases that it names. A\n * framework package narrows `component` to its component type, with the\n * props of the component it replaces.\n */\nexport type GenerativeUIOverridesConfig<\n Bases extends readonly AnyGenerativeUI[],\n> = {\n [Name in keyof GenerativeUIBasesDefinitions<Bases>[\"components\"] & string]?: {\n component: GenerativeUIAnyComponent;\n };\n};\n\ntype OwnComponents<Props, Events, Slots, Writable> = {\n [Name in keyof Props]: {\n props: Props[Name];\n events: Name extends keyof Events ? Events[Name] : unknown;\n slots: Name extends keyof Slots ? Slots[Name] : unknown;\n writable: Name extends keyof Writable ? Writable[Name] : unknown;\n };\n};\n\n/** The definitions of the result of `createGenerativeUI`. */\nexport type GenerativeUIResultDefinitions<\n Bases extends readonly AnyGenerativeUI[],\n State,\n Functions,\n Props,\n Events,\n Slots,\n Writable,\n> = {\n state: MergedState<Bases, State>;\n functions: MergedFunctions<Bases, Functions>;\n components: Simplify<\n UnionToIntersection<BaseDefinitions<Bases>[\"components\"]> &\n OwnComponents<Props, Events, Slots, Writable>\n >;\n};\n\n// ---- Runtime ----\n\ninterface RuntimeComponentDefinition extends Omit<\n GenerativeUIComponentDefinition,\n \"component\"\n> {\n component: GenerativeUIAnyComponent;\n}\n\ninterface RuntimeConfig {\n id: string;\n extends?: readonly AnyGenerativeUI[];\n state?: Record<string, GenerativeUISchema>;\n functions?: Record<string, GenerativeUIFunctionDefinition>;\n overrides?: Record<string, { component: GenerativeUIAnyComponent }>;\n components: Record<string, RuntimeComponentDefinition>;\n}\n\n/** The A2UI component envelope: `id`, `component`, `catalogId`, `accessibility`, `metadata`. */\nconst RESERVED_KEYS = new Set([\n \"id\",\n \"component\",\n ...A2UI_COMPONENT_ENVELOPE_KEYS,\n]);\n\n/** The id of the catalog that declared each component, for the inspector. */\nconst componentCatalogs = new WeakMap<object, ReadonlyMap<string, string>>();\n\n/**\n * The id of the catalog that declared each component of `ui`. A component\n * from `extends` keeps the id of its base. Not exported from the package.\n */\nexport function componentCatalogIds(\n ui: AnyGenerativeUI,\n): ReadonlyMap<string, string> {\n return componentCatalogs.get(ui) ?? new Map();\n}\n\n/**\n * The catalogs that an operation can name: the id of `ui`, then the ids of\n * the catalogs in its `extends` that declared a component. Not exported\n * from the package.\n */\nexport function catalogIdsOf(ui: Pick<AnyGenerativeUI, \"id\">): string[] {\n const declared = componentCatalogs.get(ui)?.values() ?? [];\n return [...new Set([ui.id, ...declared])];\n}\n\n/**\n * Experimental. Declares the components the model can render, the app state\n * they read, and the functions they call.\n *\n * - A prop with the name of a top-level state key is bound to that state.\n * - `bind: { prop: (state, props) => value }` binds a prop to a selector.\n * - An event binds to the function with its name, else to the name without\n * `on` (`onAddToCart` calls `addToCart`).\n * - `writable: [\"value\"]` gives the component a `setValue` prop. See\n * `GenerativeUIComponentDefinition.writable`.\n *\n * The model does not see bound props or matched events.\n *\n * @param config - `id`, then optional `extends`, `state`, `functions` and\n * `overrides`, then `components`. Put `state` before `components`, so the selectors\n * get typed state.\n * @throws Error when a name comes from two places, an override names no\n * component of the bases, `props` is not an object\n * schema with a JSON Schema, a key is reserved or used\n * twice on a component, an event matches two functions, an unmatched event\n * has no `parameters`, a `bind` key is not a prop, a `writable` key is not\n * a prop or is a bound prop, or a setter name is already a key of the\n * component. Also throws when `parameterOrder` contains duplicate or unknown\n * keys, or an ordered component declares integer-index keys whose JSON object\n * enumeration order cannot be controlled.\n *\n * @example\n * ```ts\n * const ui = createGenerativeUI({\n * id: \"acme/store@1\",\n * state: { cart: cartSchema },\n * functions: { addToCart: { parameters: z.object({ productId: z.string() }) } },\n * components: {\n * CartSummary: {\n * component: CartSummary,\n * props: z.object({ count: z.number() }),\n * bind: { count: (state) => state.cart.count },\n * },\n * },\n * });\n * ```\n */\nexport function createGenerativeUI<\n Bases extends readonly AnyGenerativeUI[] = [],\n State extends Record<string, GenerativeUISchema> = {},\n Functions extends Record<string, GenerativeUIFunctionDefinition> = {},\n Props extends Record<string, unknown> = {},\n Events extends Record<string, unknown> = {},\n Slots extends Record<string, unknown> = {},\n Writable extends Record<string, unknown> = {},\n>(\n config: CreateGenerativeUIConfig<\n Bases,\n State,\n Functions,\n Props,\n Events,\n Slots,\n Writable\n >,\n) {\n // TypeScript cannot relate the generic mapped config type to the runtime\n // shape. The config type is stricter than `RuntimeConfig`, so this is safe.\n const ui: GenerativeUI<\n GenerativeUIResultDefinitions<\n Bases,\n State,\n Functions,\n Props,\n Events,\n Slots,\n Writable\n >\n > = buildGenerativeUI(config as RuntimeConfig) as GenerativeUI<any>;\n return ui;\n}\n\nfunction buildGenerativeUI(config: RuntimeConfig) {\n const where = `generative UI \"${config.id}\"`;\n const state = new Map<string, GenerativeUISchema>();\n const functions = new Map<string, GenerativeUIFunctionDefinition>();\n const definitions = new Map<string, RuntimeComponentDefinition>();\n const catalogs = new Map<string, string>();\n\n function add<Value>(\n map: Map<string, Value>,\n kind: string,\n name: string,\n value: Value,\n ) {\n if (map.has(name)) {\n throw new Error(\n `[generativeUI] ${kind} \"${name}\" is defined more than once in ${where}.`,\n );\n }\n map.set(name, value);\n }\n\n const bases = config.extends ?? [];\n for (const base of bases) {\n for (const [name, schema] of base.state)\n add(state, \"State key\", name, schema);\n for (const [name, fn] of base.functions)\n add(functions, \"Function\", name, fn);\n const baseCatalogs = componentCatalogIds(base);\n for (const [name, component] of base.components) {\n add(definitions, \"Component\", name, component);\n catalogs.set(name, baseCatalogs.get(name) ?? base.id);\n }\n }\n for (const [name, override] of Object.entries(config.overrides ?? {})) {\n const base = definitions.get(name);\n if (!base) {\n throw new Error(\n `[generativeUI] Override \"${name}\" is not a component of the bases of ${where}.`,\n );\n }\n definitions.set(name, { ...base, component: override.component });\n }\n for (const [name, schema] of Object.entries(config.state ?? {}))\n add(state, \"State key\", name, schema);\n for (const [name, fn] of Object.entries(config.functions ?? {}))\n add(functions, \"Function\", name, fn);\n for (const [name, fn] of functions) {\n const isGestureOnly = fn.requiresUserActivation === true;\n if (\n isGestureOnly &&\n fn.allowedCallers !== undefined &&\n fn.allowedCallers !== \"rendererOnly\"\n ) {\n throw new Error(\n `[generativeUI] Function \"${name}\" in ${where} requires user activation, so its allowedCallers must be \"rendererOnly\", not \"${fn.allowedCallers}\".`,\n );\n }\n }\n for (const [name, component] of Object.entries(config.components)) {\n add(definitions, \"Component\", name, component);\n catalogs.set(name, config.id);\n }\n\n const components = new Map<string, ResolvedGenerativeUIComponent>();\n const manifestComponents: Record<string, GenerativeUIComponentManifest> = {};\n for (const [name, definition] of definitions) {\n const { component, manifest } = resolveComponent(name, definition, {\n state,\n functions,\n where,\n });\n components.set(name, component);\n manifestComponents[name] = manifest;\n }\n return withOmit(\n { id: config.id, state, functions, components, manifestComponents },\n catalogs,\n );\n}\n\n/** Adds the `omit` method to the data of a generative UI. */\nfunction withOmit(\n data: Omit<GenerativeUI, \"omit\">,\n catalogs: ReadonlyMap<string, string>,\n): GenerativeUI {\n // The method is typed on `GenerativeUI`. The runtime works with names only.\n const omit = (names: readonly string[]): GenerativeUI => {\n for (const name of names) {\n if (!data.components.has(name)) {\n throw new Error(\n `[generativeUI] Cannot omit \"${name}\": it is not a component of generative UI \"${data.id}\".`,\n );\n }\n }\n const isKept = (name: string) => !names.includes(name);\n return withOmit(\n {\n id: data.id,\n state: data.state,\n functions: data.functions,\n components: new Map(\n [...data.components].filter(([name]) => isKept(name)),\n ),\n manifestComponents: Object.fromEntries(\n Object.entries(data.manifestComponents).filter(([name]) =>\n isKept(name),\n ),\n ),\n },\n catalogs,\n );\n };\n const ui = { ...data, omit: omit as GenerativeUI[\"omit\"] };\n componentCatalogs.set(ui, catalogs);\n return ui;\n}\n\ninterface ResolveContext {\n state: ReadonlyMap<string, GenerativeUISchema>;\n functions: ReadonlyMap<string, GenerativeUIFunctionDefinition>;\n where: string;\n}\n\n/** Builds the selectors, the event map and the manifest of one component. */\nfunction resolveComponent(\n name: string,\n definition: RuntimeComponentDefinition,\n context: ResolveContext,\n) {\n const propsJson = propsJsonSchema(name, definition, context.where);\n const propKeys = Object.keys(propsJson.properties);\n assertDisjointKeys(name, definition, propKeys);\n assertParameterOrder(name, definition, propKeys);\n\n const selectors: Record<string, GenerativeUISelector> = {};\n for (const key of propKeys) {\n if (context.state.has(key)) selectors[key] = (state) => state[key];\n }\n const bind = definition.bind ?? {};\n const propKeySet = new Set(propKeys);\n for (const [key, selector] of Object.entries(bind)) {\n if (!propKeySet.has(key)) {\n throw new Error(\n `[generativeUI] bind key \"${key}\" is not a prop of component \"${name}\" in ${context.where}.`,\n );\n }\n selectors[key] = selector;\n }\n const eventFunctions: Record<string, string> = {};\n const modelEvents: NonNullable<GenerativeUIComponentManifest[\"events\"]> = {};\n const events = definition.events ?? {};\n for (const [eventName, event] of Object.entries(events)) {\n const functionName = matchFunction(eventName, name, context);\n if (functionName !== undefined) {\n const matched = context.functions.get(functionName);\n if (matched && !functionCallers(matched).renderer) {\n throw new Error(\n `[generativeUI] Event \"${eventName}\" of component \"${name}\" matches function \"${functionName}\", which the UI cannot call (allowedCallers \"agentOnly\") in ${context.where}.`,\n );\n }\n eventFunctions[eventName] = functionName;\n continue;\n }\n if (!event.parameters) {\n throw new Error(\n `[generativeUI] Event \"${eventName}\" of component \"${name}\" matches no function in ${context.where}, so it needs \"parameters\".`,\n );\n }\n modelEvents[eventName] = {\n ...(event.description ? { description: event.description } : {}),\n parameters: toJsonSchema(event.parameters),\n };\n }\n\n assertWritable(name, definition, propKeys, selectors, context.where);\n\n const component: ResolvedGenerativeUIComponent = {\n component: definition.component,\n description: definition.description,\n parameterOrder: definition.parameterOrder?.slice(),\n props: definition.props,\n bind: definition.bind,\n events: definition.events,\n slots: definition.slots,\n writable: definition.writable,\n accessibility: definition.accessibility ?? \"wrapper\",\n selectors,\n eventFunctions,\n propKeys,\n childRefs: collectChildRefs(propsJson),\n };\n return {\n component,\n manifest: toManifest(\n definition,\n modelPropsJsonSchema(propsJson, selectors),\n modelEvents,\n ),\n };\n}\n\ntype ObjectJsonSchema = GenerativeUIJSONSchema & {\n properties: Record<string, GenerativeUIJSONSchema>;\n};\n\n/** The JSON Schema of `props`. A component without `props` has none. */\nfunction propsJsonSchema(\n name: string,\n definition: RuntimeComponentDefinition,\n where: string,\n): ObjectJsonSchema {\n if (!definition.props) return { type: \"object\", properties: {} };\n const json = toJsonSchema(definition.props);\n const { properties } = json;\n const isObject =\n typeof properties === \"object\" &&\n properties !== null &&\n !Array.isArray(properties);\n if (!isObject) {\n throw new Error(\n `[generativeUI] the props of component \"${name}\" in ${where} must be an object schema.`,\n );\n }\n return json as ObjectJsonSchema;\n}\n\n/**\n * What the model sees of the props: the JSON Schema without the bound props,\n * and with no other keys allowed.\n */\nfunction modelPropsJsonSchema(\n json: ObjectJsonSchema,\n bound: Record<string, unknown>,\n): GenerativeUIJSONSchema {\n const isModelKey = (key: string) => !hasOwnKey(bound, key);\n const {\n properties,\n required,\n additionalProperties: _additionalProperties,\n ...rest\n } = json;\n const modelRequired = Array.isArray(required)\n ? required.filter((key: unknown) => isModelKey(String(key)))\n : [];\n return {\n ...rest,\n type: \"object\",\n properties: Object.fromEntries(\n Object.entries(properties).filter(([key]) => isModelKey(key)),\n ),\n ...(modelRequired.length > 0 ? { required: modelRequired } : {}),\n additionalProperties: false,\n };\n}\n\n/** `onAddToCart` to `addToCart`. `undefined` when the name has no `on` prefix. */\nfunction withoutOnPrefix(eventName: string) {\n const hasOnPrefix = eventName.length > 2 && eventName.startsWith(\"on\");\n if (!hasOnPrefix) return undefined;\n return eventName.charAt(2).toLowerCase() + eventName.slice(3);\n}\n\n/** The declared function an event calls, or `undefined` when none matches. */\nfunction matchFunction(\n eventName: string,\n componentName: string,\n context: ResolveContext,\n) {\n const exact = context.functions.has(eventName) ? eventName : undefined;\n const stripped = withoutOnPrefix(eventName);\n const fromPrefix =\n stripped !== undefined && context.functions.has(stripped)\n ? stripped\n : undefined;\n if (exact !== undefined && fromPrefix !== undefined) {\n throw new Error(\n `[generativeUI] Event \"${eventName}\" of component \"${componentName}\" matches two functions, \"${exact}\" and \"${fromPrefix}\", in ${context.where}.`,\n );\n }\n return exact ?? fromPrefix;\n}\n\n/** The setter prop of a writable prop: `value` gives `setValue`. */\nexport function setterNameOf(key: string) {\n return `set${key.charAt(0).toUpperCase()}${key.slice(1)}`;\n}\n\n/** Why a `writable` key is not valid, or `undefined` when it is valid. */\nfunction writableProblem(\n key: string,\n definition: RuntimeComponentDefinition,\n propKeys: readonly string[],\n selectors: Record<string, GenerativeUISelector>,\n) {\n if (hasOwnKey(definition.events ?? {}, key)) return \"an event\";\n if (hasOwnKey(definition.slots ?? {}, key)) return \"a slot\";\n if (!propKeys.includes(key)) return \"not a prop\";\n if (hasOwnKey(selectors, key)) return \"a bound prop\";\n return undefined;\n}\n\nfunction assertWritable(\n name: string,\n definition: RuntimeComponentDefinition,\n propKeys: readonly string[],\n selectors: Record<string, GenerativeUISelector>,\n where: string,\n) {\n const writable = definition.writable ?? [];\n const keys = new Set([\n ...propKeys,\n ...Object.keys(definition.events ?? {}),\n ...Object.keys(definition.slots ?? {}),\n ]);\n for (const key of writable) {\n const problem = writableProblem(key, definition, propKeys, selectors);\n if (problem) {\n throw new Error(\n `[generativeUI] writable key \"${key}\" of component \"${name}\" is ${problem} in ${where}.`,\n );\n }\n const setter = setterNameOf(key);\n if (keys.has(setter)) {\n throw new Error(\n `[generativeUI] the setter \"${setter}\" of writable key \"${key}\" is already a key of component \"${name}\" in ${where}.`,\n );\n }\n }\n}\n\nfunction assertDisjointKeys(\n name: string,\n definition: RuntimeComponentDefinition,\n propKeys: readonly string[],\n) {\n const seen = new Set<string>();\n const keys = [\n ...propKeys,\n ...Object.keys(definition.events ?? {}),\n ...Object.keys(definition.slots ?? {}),\n ];\n for (const key of keys) {\n if (RESERVED_KEYS.has(key)) {\n throw new Error(\n `[generativeUI] \"${key}\" is reserved by A2UI and cannot be a prop, event or slot of component \"${name}\".`,\n );\n }\n if (seen.has(key)) {\n throw new Error(\n `[generativeUI] \"${key}\" is declared as more than one of prop, event, slot on component \"${name}\".`,\n );\n }\n seen.add(key);\n }\n}\n\nfunction assertParameterOrder(\n name: string,\n definition: RuntimeComponentDefinition,\n propKeys: readonly string[],\n) {\n const order = definition.parameterOrder;\n if (order === undefined) return;\n const keys = new Set([\n ...propKeys,\n ...Object.keys(definition.slots ?? {}),\n ...Object.keys(definition.events ?? {}),\n ]);\n if (\n [...keys].some((key) => {\n const index = Number(key);\n return (\n Number.isInteger(index) &&\n index >= 0 &&\n index < 2 ** 32 - 1 &&\n String(index) === key\n );\n })\n ) {\n throw new Error(\n `[generativeUI] Component \"${name}\" with parameterOrder cannot declare integer-index keys: JSON object enumeration sorts them numerically before other keys, ignoring the requested order.`,\n );\n }\n if (\n !Array.isArray(order) ||\n new Set(order).size !== order.length ||\n order.some((key) => !keys.has(key))\n ) {\n throw new Error(\n `[generativeUI] parameterOrder of component \"${name}\" must contain unique declared prop, slot or event names.`,\n );\n }\n}\n\nfunction toManifest(\n definition: RuntimeComponentDefinition,\n modelProps: GenerativeUIJSONSchema,\n modelEvents: NonNullable<GenerativeUIComponentManifest[\"events\"]>,\n) {\n const manifest: GenerativeUIComponentManifest = { props: modelProps };\n if (definition.description) manifest.description = definition.description;\n if (Object.keys(modelEvents).length > 0) manifest.events = modelEvents;\n if (definition.slots) manifest.slots = { ...definition.slots };\n if (definition.parameterOrder !== undefined) {\n const visible = new Set([\n ...Object.keys(modelProps.properties ?? {}),\n ...Object.keys(definition.slots ?? {}),\n ...Object.keys(modelEvents),\n ]);\n manifest.parameterOrder = [\n ...new Set([\n ...definition.parameterOrder.filter((key) => visible.has(key)),\n ...visible,\n ]),\n ];\n }\n return manifest;\n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