@cognitap/radiant 0.0.90 → 0.0.92

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 (169) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/library/a2ui/A2uiPlaceholder.d.ts +14 -0
  3. package/dist/library/a2ui/A2uiPlaceholder.d.ts.map +1 -0
  4. package/dist/library/a2ui/A2uiPlaceholder.js +44 -0
  5. package/dist/library/a2ui/A2uiPlaceholder.js.map +1 -0
  6. package/dist/library/a2ui/A2uiSurface.d.ts +33 -0
  7. package/dist/library/a2ui/A2uiSurface.d.ts.map +1 -0
  8. package/dist/library/a2ui/A2uiSurface.js +542 -0
  9. package/dist/library/a2ui/A2uiSurface.js.map +1 -0
  10. package/dist/library/a2ui/accessibility.d.ts +31 -0
  11. package/dist/library/a2ui/accessibility.d.ts.map +1 -0
  12. package/dist/library/a2ui/accessibility.js +108 -0
  13. package/dist/library/a2ui/accessibility.js.map +1 -0
  14. package/dist/library/a2ui/accessibilityRules.d.ts +28 -0
  15. package/dist/library/a2ui/accessibilityRules.d.ts.map +1 -0
  16. package/dist/library/a2ui/accessibilityRules.js +73 -0
  17. package/dist/library/a2ui/accessibilityRules.js.map +1 -0
  18. package/dist/library/a2ui/catalogGenerator.d.ts +29 -0
  19. package/dist/library/a2ui/catalogGenerator.d.ts.map +1 -0
  20. package/dist/library/a2ui/catalogGenerator.js +578 -0
  21. package/dist/library/a2ui/catalogGenerator.js.map +1 -0
  22. package/dist/library/a2ui/coerce.d.ts +16 -0
  23. package/dist/library/a2ui/coerce.d.ts.map +1 -0
  24. package/dist/library/a2ui/coerce.js +254 -0
  25. package/dist/library/a2ui/coerce.js.map +1 -0
  26. package/dist/library/a2ui/entries.d.ts +6 -0
  27. package/dist/library/a2ui/entries.d.ts.map +1 -0
  28. package/dist/library/a2ui/entries.js +277 -0
  29. package/dist/library/a2ui/entries.js.map +1 -0
  30. package/dist/library/a2ui/fixtures.d.ts +38 -0
  31. package/dist/library/a2ui/fixtures.d.ts.map +1 -0
  32. package/dist/library/a2ui/fixtures.js +389 -0
  33. package/dist/library/a2ui/fixtures.js.map +1 -0
  34. package/dist/library/a2ui/index.d.ts +17 -0
  35. package/dist/library/a2ui/index.d.ts.map +1 -0
  36. package/dist/library/a2ui/index.js +9 -0
  37. package/dist/library/a2ui/index.js.map +1 -0
  38. package/dist/library/a2ui/protocolErrors.d.ts +13 -0
  39. package/dist/library/a2ui/protocolErrors.d.ts.map +1 -0
  40. package/dist/library/a2ui/protocolErrors.js +48 -0
  41. package/dist/library/a2ui/protocolErrors.js.map +1 -0
  42. package/dist/library/a2ui/registry.d.ts +58 -0
  43. package/dist/library/a2ui/registry.d.ts.map +1 -0
  44. package/dist/library/a2ui/registry.js +128 -0
  45. package/dist/library/a2ui/registry.js.map +1 -0
  46. package/dist/library/a2ui/sanitize.d.ts +7 -0
  47. package/dist/library/a2ui/sanitize.d.ts.map +1 -0
  48. package/dist/library/a2ui/sanitize.js +54 -0
  49. package/dist/library/a2ui/sanitize.js.map +1 -0
  50. package/dist/library/a2ui/surfaceRuntime.d.ts +34 -0
  51. package/dist/library/a2ui/surfaceRuntime.d.ts.map +1 -0
  52. package/dist/library/a2ui/surfaceRuntime.js +284 -0
  53. package/dist/library/a2ui/surfaceRuntime.js.map +1 -0
  54. package/dist/library/catalog/actions.d.ts +40 -0
  55. package/dist/library/catalog/actions.d.ts.map +1 -0
  56. package/dist/library/catalog/actions.js +70 -0
  57. package/dist/library/catalog/actions.js.map +1 -0
  58. package/dist/library/catalog/coerce.d.ts +70 -0
  59. package/dist/library/catalog/coerce.d.ts.map +1 -0
  60. package/dist/library/catalog/coerce.js +332 -0
  61. package/dist/library/catalog/coerce.js.map +1 -0
  62. package/dist/library/catalog/index.d.ts +9 -0
  63. package/dist/library/catalog/index.d.ts.map +1 -0
  64. package/dist/library/catalog/index.js +6 -0
  65. package/dist/library/catalog/index.js.map +1 -0
  66. package/dist/library/catalog/radiantCatalog.d.ts +9 -0
  67. package/dist/library/catalog/radiantCatalog.d.ts.map +1 -0
  68. package/dist/library/catalog/radiantCatalog.js +902 -0
  69. package/dist/library/catalog/radiantCatalog.js.map +1 -0
  70. package/dist/library/catalog/types.d.ts +113 -0
  71. package/dist/library/catalog/types.d.ts.map +1 -0
  72. package/dist/library/catalog/types.js +27 -0
  73. package/dist/library/catalog/types.js.map +1 -0
  74. package/dist/library/catalog/validate.d.ts +31 -0
  75. package/dist/library/catalog/validate.d.ts.map +1 -0
  76. package/dist/library/catalog/validate.js +420 -0
  77. package/dist/library/catalog/validate.js.map +1 -0
  78. package/dist/library/components/Card/Card.d.ts +6 -2
  79. package/dist/library/components/Card/Card.d.ts.map +1 -1
  80. package/dist/library/components/Card/Card.js +12 -4
  81. package/dist/library/components/Card/Card.js.map +1 -1
  82. package/dist/library/components/Checkbox/Checkbox.d.ts.map +1 -1
  83. package/dist/library/components/Checkbox/Checkbox.js +2 -2
  84. package/dist/library/components/Checkbox/Checkbox.js.map +1 -1
  85. package/dist/library/components/Collapsible/Collapsible.js +1 -1
  86. package/dist/library/components/Collapsible/Collapsible.js.map +1 -1
  87. package/dist/library/components/InputGroup/InputGroup.js +1 -1
  88. package/dist/library/components/InputGroup/InputGroup.js.map +1 -1
  89. package/dist/library/components/NavLink/NavLink.d.ts.map +1 -1
  90. package/dist/library/components/NavLink/NavLink.js +1 -1
  91. package/dist/library/components/NavLink/NavLink.js.map +1 -1
  92. package/dist/library/components/RadioGroup/RadioGroup.d.ts.map +1 -1
  93. package/dist/library/components/RadioGroup/RadioGroup.js +3 -3
  94. package/dist/library/components/RadioGroup/RadioGroup.js.map +1 -1
  95. package/dist/library/components/ScrollArea/ScrollArea.d.ts.map +1 -1
  96. package/dist/library/components/ScrollArea/ScrollArea.js +4 -1
  97. package/dist/library/components/ScrollArea/ScrollArea.js.map +1 -1
  98. package/dist/library/components/Switch/Switch.d.ts.map +1 -1
  99. package/dist/library/components/Switch/Switch.js +2 -2
  100. package/dist/library/components/Switch/Switch.js.map +1 -1
  101. package/dist/library/components/Table/Table.d.ts +6 -2
  102. package/dist/library/components/Table/Table.d.ts.map +1 -1
  103. package/dist/library/components/Table/Table.js +10 -4
  104. package/dist/library/components/Table/Table.js.map +1 -1
  105. package/dist/library/components/TagsInput/TagsInput.d.ts.map +1 -1
  106. package/dist/library/components/TagsInput/TagsInput.js +1 -1
  107. package/dist/library/components/TagsInput/TagsInput.js.map +1 -1
  108. package/dist/library/components/TimeInput/TimeInput.d.ts.map +1 -1
  109. package/dist/library/components/TimeInput/TimeInput.js +28 -20
  110. package/dist/library/components/TimeInput/TimeInput.js.map +1 -1
  111. package/dist/library/components/Toast/Toast.js +1 -1
  112. package/dist/library/components/Toast/Toast.js.map +1 -1
  113. package/dist/library/components/ToggleGroup/ToggleGroup.js +1 -1
  114. package/dist/library/components/ToggleGroup/ToggleGroup.js.map +1 -1
  115. package/dist/library/index.d.ts +1 -1
  116. package/dist/library/index.d.ts.map +1 -1
  117. package/dist/library/presentation.d.ts +3 -0
  118. package/dist/library/presentation.d.ts.map +1 -1
  119. package/dist/library/styles.css +1 -1
  120. package/dist/library/themes/components.d.ts +6 -0
  121. package/dist/library/themes/components.d.ts.map +1 -1
  122. package/dist/library/themes/components.js +6 -0
  123. package/dist/library/themes/components.js.map +1 -1
  124. package/dist/library/themes/tokens.d.ts +4 -0
  125. package/dist/library/themes/tokens.d.ts.map +1 -1
  126. package/dist/library/themes/tokens.js +3 -0
  127. package/dist/library/themes/tokens.js.map +1 -1
  128. package/docs/accessibility.md +6 -0
  129. package/docs/architecture.md +20 -1
  130. package/docs/theming.md +13 -0
  131. package/package.json +17 -5
  132. package/src/a2ui/A2uiPlaceholder.tsx +64 -0
  133. package/src/a2ui/A2uiSurface.tsx +790 -0
  134. package/src/a2ui/accessibility.ts +145 -0
  135. package/src/a2ui/accessibilityRules.ts +106 -0
  136. package/src/a2ui/catalog.json +317 -0
  137. package/src/a2ui/catalogGenerator.ts +717 -0
  138. package/src/a2ui/coerce.ts +379 -0
  139. package/src/a2ui/entries.tsx +519 -0
  140. package/src/a2ui/fixtures.ts +402 -0
  141. package/src/a2ui/index.ts +50 -0
  142. package/src/a2ui/protocolErrors.ts +63 -0
  143. package/src/a2ui/registry.ts +221 -0
  144. package/src/a2ui/sanitize.ts +51 -0
  145. package/src/a2ui/surfaceRuntime.ts +317 -0
  146. package/src/catalog/actions.ts +108 -0
  147. package/src/catalog/coerce.ts +447 -0
  148. package/src/catalog/index.ts +67 -0
  149. package/src/catalog/radiantCatalog.ts +949 -0
  150. package/src/catalog/types.ts +159 -0
  151. package/src/catalog/validate.ts +454 -0
  152. package/src/components/Card/Card.tsx +35 -19
  153. package/src/components/Checkbox/Checkbox.tsx +2 -0
  154. package/src/components/Collapsible/Collapsible.tsx +1 -1
  155. package/src/components/InputGroup/InputGroup.tsx +2 -2
  156. package/src/components/NavLink/NavLink.tsx +1 -6
  157. package/src/components/RadioGroup/RadioGroup.tsx +3 -0
  158. package/src/components/ScrollArea/ScrollArea.tsx +5 -1
  159. package/src/components/Switch/Switch.tsx +2 -0
  160. package/src/components/Table/Table.tsx +16 -3
  161. package/src/components/TagsInput/TagsInput.tsx +1 -0
  162. package/src/components/TimeInput/TimeInput.tsx +100 -75
  163. package/src/components/Toast/Toast.tsx +1 -1
  164. package/src/components/ToggleGroup/ToggleGroup.tsx +1 -1
  165. package/src/index.ts +1 -1
  166. package/src/presentation.ts +3 -0
  167. package/src/themes/baseline.css +3 -0
  168. package/src/themes/components.ts +6 -0
  169. package/src/themes/tokens.ts +7 -0
@@ -0,0 +1,717 @@
1
+ import {
2
+ assertValidCatalog,
3
+ type Catalog,
4
+ type CatalogBindingValueType,
5
+ type CatalogEntry,
6
+ type CatalogJsonPrimitive,
7
+ type CatalogJsonSchema,
8
+ type CatalogSlotConstraint
9
+ } from '../catalog/index.js'
10
+
11
+ export const A2UI_PROTOCOL_VERSION = '1.0'
12
+ export const A2UI_BASIC_CATALOG_ID =
13
+ 'https://a2ui.org/specification/v1_0/catalogs/basic/catalog.json'
14
+ export const RADIANT_A2UI_EXTENSION_CATALOG_ID =
15
+ 'https://radiant-docs.pages.dev/a2ui/v1_0/extension_catalog.json'
16
+
17
+ const COMMON = 'common_types.json#/$defs/'
18
+
19
+ export type A2uiJsonSchema = { readonly [keyword: string]: unknown }
20
+
21
+ export type A2uiCatalogDocument = {
22
+ readonly $schema: 'https://json-schema.org/draft/2020-12/schema'
23
+ readonly $id: string
24
+ readonly catalogId: string
25
+ readonly protocolVersion: typeof A2UI_PROTOCOL_VERSION
26
+ readonly title: string
27
+ readonly description: string
28
+ readonly components: Readonly<Record<string, A2uiJsonSchema>>
29
+ readonly functions: Readonly<Record<string, A2uiJsonSchema>>
30
+ readonly $defs: Readonly<Record<string, A2uiJsonSchema>>
31
+ }
32
+
33
+ export type GeneratedA2uiCatalogs = {
34
+ readonly basic: A2uiCatalogDocument
35
+ readonly extension: A2uiCatalogDocument
36
+ }
37
+
38
+ /**
39
+ * How one A2UI wire property maps onto the canonical entry it renders.
40
+ * `values` maps each A2UI enum value to the canonical value it renders as.
41
+ * `spec` carries a wire shape the A2UI specification fixes, still tied to its canonical sources.
42
+ */
43
+ type PropMapping =
44
+ | {
45
+ readonly from: 'prop'
46
+ readonly source: string
47
+ readonly values?: Readonly<Record<string, string>>
48
+ readonly default?: CatalogJsonPrimitive
49
+ readonly dynamic?: boolean
50
+ }
51
+ | { readonly from: 'binding'; readonly source: string }
52
+ | { readonly from: 'slot'; readonly source: string }
53
+ | { readonly from: 'action'; readonly source: string }
54
+ | { readonly from: 'spec'; readonly sources: readonly string[]; readonly schema: A2uiJsonSchema }
55
+
56
+ type BasicProjection = {
57
+ readonly a2uiName: string
58
+ readonly sourceEntry: string
59
+ readonly checkable?: boolean
60
+ readonly required: readonly string[]
61
+ readonly props: Readonly<Record<string, PropMapping>>
62
+ }
63
+
64
+ type ExtensionProjection = {
65
+ readonly a2uiName: string
66
+ readonly sourceEntry: string
67
+ readonly description?: string
68
+ readonly omit?: readonly string[]
69
+ readonly bindingValueTypes?: Readonly<Record<string, CatalogBindingValueType>>
70
+ }
71
+
72
+ const prop = (
73
+ source: string,
74
+ options: Omit<Extract<PropMapping, { from: 'prop' }>, 'from' | 'source'> = {}
75
+ ): PropMapping => ({ from: 'prop', source, ...options })
76
+ const dynamicProp = (source: string): PropMapping => ({ from: 'prop', source, dynamic: true })
77
+ const binding = (source: string): PropMapping => ({ from: 'binding', source })
78
+ const slot = (source: string): PropMapping => ({ from: 'slot', source })
79
+ const action = (source: string): PropMapping => ({ from: 'action', source })
80
+ const spec = (sources: readonly string[], schema: A2uiJsonSchema): PropMapping => ({
81
+ from: 'spec',
82
+ sources,
83
+ schema
84
+ })
85
+
86
+ const A2UI_ICON_NAMES = [
87
+ 'accountCircle',
88
+ 'add',
89
+ 'arrowBack',
90
+ 'arrowForward',
91
+ 'attachFile',
92
+ 'calendarToday',
93
+ 'call',
94
+ 'camera',
95
+ 'check',
96
+ 'close',
97
+ 'delete',
98
+ 'download',
99
+ 'edit',
100
+ 'event',
101
+ 'error',
102
+ 'fastForward',
103
+ 'favorite',
104
+ 'favoriteOff',
105
+ 'folder',
106
+ 'help',
107
+ 'home',
108
+ 'info',
109
+ 'locationOn',
110
+ 'lock',
111
+ 'lockOpen',
112
+ 'mail',
113
+ 'menu',
114
+ 'moreVert',
115
+ 'moreHoriz',
116
+ 'notificationsOff',
117
+ 'notifications',
118
+ 'pause',
119
+ 'payment',
120
+ 'person',
121
+ 'phone',
122
+ 'photo',
123
+ 'play',
124
+ 'print',
125
+ 'refresh',
126
+ 'rewind',
127
+ 'search',
128
+ 'send',
129
+ 'settings',
130
+ 'share',
131
+ 'shoppingCart',
132
+ 'skipNext',
133
+ 'skipPrevious',
134
+ 'star',
135
+ 'starHalf',
136
+ 'starOff',
137
+ 'stop',
138
+ 'upload',
139
+ 'visibility',
140
+ 'visibilityOff',
141
+ 'volumeDown',
142
+ 'volumeMute',
143
+ 'volumeOff',
144
+ 'volumeUp',
145
+ 'warning'
146
+ ] as const
147
+
148
+ const isoBound = (description: string): A2uiJsonSchema => ({
149
+ description,
150
+ allOf: [
151
+ { $ref: `${COMMON}DynamicString` },
152
+ {
153
+ if: { type: 'string' },
154
+ // oxlint-disable-next-line unicorn/no-thenable -- JSON Schema conditional keyword, never awaited.
155
+ then: { oneOf: [{ format: 'date' }, { format: 'time' }, { format: 'date-time' }] }
156
+ }
157
+ ]
158
+ })
159
+
160
+ const JUSTIFY_VALUES = {
161
+ start: 'start',
162
+ center: 'center',
163
+ end: 'end',
164
+ spaceBetween: 'between',
165
+ spaceAround: 'around',
166
+ spaceEvenly: 'evenly',
167
+ stretch: 'stretch'
168
+ }
169
+
170
+ // Each component matches the A2UI 1.0 basic catalog; tests/catalog.test.mjs checks it against the spec copy.
171
+ const BASIC_PROJECTIONS: readonly BasicProjection[] = [
172
+ {
173
+ a2uiName: 'Text',
174
+ sourceEntry: 'Text',
175
+ required: ['text'],
176
+ props: {
177
+ text: binding('text'),
178
+ variant: prop('variant', { values: { caption: 'caption', body: 'body' } })
179
+ }
180
+ },
181
+ {
182
+ a2uiName: 'Image',
183
+ sourceEntry: 'Image',
184
+ required: ['url'],
185
+ props: {
186
+ url: binding('url'),
187
+ description: dynamicProp('alt'),
188
+ fit: prop('fit', {
189
+ values: {
190
+ contain: 'contain',
191
+ cover: 'cover',
192
+ fill: 'fill',
193
+ none: 'none',
194
+ scaleDown: 'scale-down'
195
+ },
196
+ default: 'fill'
197
+ }),
198
+ variant: prop('usage')
199
+ }
200
+ },
201
+ {
202
+ a2uiName: 'Icon',
203
+ sourceEntry: 'Icon',
204
+ required: ['name'],
205
+ props: {
206
+ name: spec(['name'], {
207
+ description: 'A2UI icon name, custom SVG path, or bound icon name.',
208
+ oneOf: [
209
+ { type: 'string', enum: A2UI_ICON_NAMES },
210
+ {
211
+ type: 'object',
212
+ properties: { svgPath: { $ref: `${COMMON}DynamicString` } },
213
+ required: ['svgPath'],
214
+ additionalProperties: false
215
+ },
216
+ { $ref: `${COMMON}DataBinding` }
217
+ ]
218
+ })
219
+ }
220
+ },
221
+ {
222
+ a2uiName: 'Video',
223
+ sourceEntry: 'Video',
224
+ required: ['url'],
225
+ props: { url: binding('url'), posterUrl: dynamicProp('poster') }
226
+ },
227
+ {
228
+ a2uiName: 'AudioPlayer',
229
+ sourceEntry: 'AudioPlayer',
230
+ required: ['url'],
231
+ props: { url: binding('url'), description: dynamicProp('description') }
232
+ },
233
+ {
234
+ a2uiName: 'Row',
235
+ sourceEntry: 'Row',
236
+ required: ['children'],
237
+ props: {
238
+ children: slot('children'),
239
+ justify: prop('justify', { values: JUSTIFY_VALUES }),
240
+ align: prop('align')
241
+ }
242
+ },
243
+ {
244
+ a2uiName: 'Column',
245
+ sourceEntry: 'Column',
246
+ required: ['children'],
247
+ props: {
248
+ children: slot('children'),
249
+ justify: prop('justify', { values: JUSTIFY_VALUES }),
250
+ align: prop('align')
251
+ }
252
+ },
253
+ {
254
+ a2uiName: 'List',
255
+ sourceEntry: 'List',
256
+ required: ['children'],
257
+ props: { children: slot('children'), direction: prop('direction'), align: prop('align') }
258
+ },
259
+ { a2uiName: 'Card', sourceEntry: 'Card', required: ['child'], props: { child: slot('child') } },
260
+ {
261
+ a2uiName: 'Tabs',
262
+ sourceEntry: 'Tabs',
263
+ required: ['tabs'],
264
+ props: {
265
+ tabs: spec(['tabs', 'panels'], {
266
+ type: 'array',
267
+ description: 'Tabs, each pairing a title with the panel component it shows.',
268
+ minItems: 1,
269
+ items: {
270
+ type: 'object',
271
+ properties: {
272
+ title: { $ref: `${COMMON}DynamicString` },
273
+ child: { $ref: `${COMMON}Child` }
274
+ },
275
+ required: ['title', 'child'],
276
+ additionalProperties: false
277
+ }
278
+ })
279
+ }
280
+ },
281
+ {
282
+ a2uiName: 'Modal',
283
+ sourceEntry: 'Modal',
284
+ required: ['trigger', 'content'],
285
+ props: { trigger: slot('trigger'), content: slot('content') }
286
+ },
287
+ {
288
+ a2uiName: 'Divider',
289
+ sourceEntry: 'Divider',
290
+ required: [],
291
+ props: { axis: prop('orientation') }
292
+ },
293
+ {
294
+ a2uiName: 'Button',
295
+ sourceEntry: 'Button',
296
+ checkable: true,
297
+ required: ['child', 'action'],
298
+ props: {
299
+ child: slot('child'),
300
+ variant: prop('variant', {
301
+ values: { default: 'soft', primary: 'solid', borderless: 'ghost' },
302
+ default: 'default'
303
+ }),
304
+ action: action('action')
305
+ }
306
+ },
307
+ {
308
+ a2uiName: 'TextField',
309
+ sourceEntry: 'TextField',
310
+ checkable: true,
311
+ required: ['label', 'value'],
312
+ props: {
313
+ label: dynamicProp('label'),
314
+ value: binding('value'),
315
+ placeholder: dynamicProp('placeholder'),
316
+ variant: prop('kind', {
317
+ values: { longText: 'long', number: 'number', shortText: 'short', obscured: 'password' }
318
+ })
319
+ }
320
+ },
321
+ {
322
+ a2uiName: 'CheckBox',
323
+ sourceEntry: 'Checkbox',
324
+ checkable: true,
325
+ required: ['label', 'value'],
326
+ props: { label: dynamicProp('label'), value: binding('checked') }
327
+ },
328
+ {
329
+ a2uiName: 'ChoicePicker',
330
+ sourceEntry: 'Choice',
331
+ checkable: true,
332
+ required: ['options', 'value'],
333
+ props: {
334
+ label: dynamicProp('label'),
335
+ variant: prop('selection', {
336
+ values: { multipleSelection: 'multiple', mutuallyExclusive: 'single' }
337
+ }),
338
+ options: spec(['options'], {
339
+ type: 'array',
340
+ description: 'Selectable choices presented to the user.',
341
+ items: {
342
+ type: 'object',
343
+ properties: {
344
+ label: { $ref: `${COMMON}DynamicString` },
345
+ value: { type: 'string' }
346
+ },
347
+ required: ['label', 'value'],
348
+ additionalProperties: false
349
+ }
350
+ }),
351
+ value: binding('value'),
352
+ displayStyle: prop('presentation', {
353
+ values: { checkbox: 'list', chips: 'chips' },
354
+ default: 'checkbox'
355
+ }),
356
+ filterable: prop('searchable')
357
+ }
358
+ },
359
+ {
360
+ a2uiName: 'Slider',
361
+ sourceEntry: 'Slider',
362
+ checkable: true,
363
+ required: ['value', 'max'],
364
+ props: {
365
+ label: dynamicProp('label'),
366
+ min: prop('min', { default: 0 }),
367
+ max: prop('max'),
368
+ value: binding('value'),
369
+ steps: spec(['step'], {
370
+ type: 'integer',
371
+ minimum: 1,
372
+ description: 'Number of discrete divisions; the renderer derives the canonical step size.'
373
+ })
374
+ }
375
+ },
376
+ {
377
+ a2uiName: 'DateTimeInput',
378
+ sourceEntry: 'DateTimeInput',
379
+ checkable: true,
380
+ required: ['value'],
381
+ props: {
382
+ value: binding('value'),
383
+ enableDate: prop('enableDate', { default: false }),
384
+ enableTime: prop('enableTime'),
385
+ min: spec(['min'], isoBound('Minimum allowed ISO 8601 date or time.')),
386
+ max: spec(['max'], isoBound('Maximum allowed ISO 8601 date or time.')),
387
+ label: dynamicProp('label')
388
+ }
389
+ }
390
+ ]
391
+
392
+ const EXTENSION_PROJECTIONS: readonly ExtensionProjection[] = [
393
+ {
394
+ a2uiName: 'Select',
395
+ sourceEntry: 'Choice',
396
+ description: 'Single-value dropdown selection backed by Radiant Select.',
397
+ omit: ['selection', 'presentation', 'searchable'],
398
+ bindingValueTypes: { value: 'string' }
399
+ },
400
+ {
401
+ a2uiName: 'Combobox',
402
+ sourceEntry: 'Choice',
403
+ description: 'Filterable dropdown selection backed by Radiant Combobox.',
404
+ omit: ['presentation', 'searchable']
405
+ },
406
+ {
407
+ a2uiName: 'RadioGroup',
408
+ sourceEntry: 'Choice',
409
+ description: 'Mutually exclusive radio options backed by Radiant RadioGroup.',
410
+ omit: ['selection', 'presentation', 'searchable', 'placeholder'],
411
+ bindingValueTypes: { value: 'string' }
412
+ },
413
+ { a2uiName: 'Switch', sourceEntry: 'Switch' },
414
+ {
415
+ a2uiName: 'Textarea',
416
+ sourceEntry: 'TextField',
417
+ description: 'Multi-line text input backed by Radiant Textarea.',
418
+ omit: ['kind']
419
+ },
420
+ { a2uiName: 'Alert', sourceEntry: 'Alert' },
421
+ { a2uiName: 'Badge', sourceEntry: 'Badge' },
422
+ { a2uiName: 'Progress', sourceEntry: 'Progress' },
423
+ { a2uiName: 'Accordion', sourceEntry: 'Accordion' },
424
+ { a2uiName: 'Table', sourceEntry: 'Table' },
425
+ { a2uiName: 'Toast', sourceEntry: 'Toast' }
426
+ ]
427
+
428
+ const DYNAMIC_REF_BY_BINDING_TYPE: Record<CatalogBindingValueType, string> = {
429
+ string: `${COMMON}DynamicString`,
430
+ number: `${COMMON}DynamicNumber`,
431
+ boolean: `${COMMON}DynamicBoolean`,
432
+ 'string[]': `${COMMON}DynamicStringList`,
433
+ 'object[]': `${COMMON}DynamicValue`
434
+ }
435
+
436
+ function fail(component: string, message: string): never {
437
+ throw new TypeError(`Cannot generate A2UI component "${component}": ${message}`)
438
+ }
439
+
440
+ function withDescription(schema: A2uiJsonSchema, description: string | undefined): A2uiJsonSchema {
441
+ return description === undefined ? schema : { ...schema, description }
442
+ }
443
+
444
+ function dynamicRefForSchema(component: string, schema: CatalogJsonSchema): string {
445
+ switch (schema.type) {
446
+ case 'string':
447
+ return `${COMMON}DynamicString`
448
+ case 'number':
449
+ case 'integer':
450
+ return `${COMMON}DynamicNumber`
451
+ case 'boolean':
452
+ return `${COMMON}DynamicBoolean`
453
+ case 'array':
454
+ if (schema.items?.type === 'string') return `${COMMON}DynamicStringList`
455
+ }
456
+ return fail(component, `prop type ${JSON.stringify(schema.type)} has no A2UI dynamic type.`)
457
+ }
458
+
459
+ function slotSchema(slotConstraint: CatalogSlotConstraint): A2uiJsonSchema {
460
+ const ref = slotConstraint.cardinality === 'single' ? 'Child' : 'ChildList'
461
+ return { $ref: `${COMMON}${ref}`, description: slotConstraint.description }
462
+ }
463
+
464
+ function hasSource(entry: CatalogEntry, source: string): boolean {
465
+ return [entry.propsSchema.properties, entry.slots, entry.bindings, entry.actions].some(names =>
466
+ Object.hasOwn(names, source)
467
+ )
468
+ }
469
+
470
+ function lookup<T>(
471
+ component: string,
472
+ kind: string,
473
+ names: Readonly<Record<string, T>>,
474
+ source: string
475
+ ): T {
476
+ if (!Object.hasOwn(names, source)) fail(component, `canonical ${kind} "${source}" is missing.`)
477
+ return names[source] as T
478
+ }
479
+
480
+ function projectMappedProp(
481
+ component: string,
482
+ entry: CatalogEntry,
483
+ mapping: PropMapping
484
+ ): A2uiJsonSchema {
485
+ switch (mapping.from) {
486
+ case 'binding': {
487
+ const bound = lookup(component, 'binding', entry.bindings, mapping.source)
488
+ return { $ref: DYNAMIC_REF_BY_BINDING_TYPE[bound.valueType], description: bound.description }
489
+ }
490
+ case 'slot':
491
+ return slotSchema(lookup(component, 'slot', entry.slots, mapping.source))
492
+ case 'action': {
493
+ const shape = lookup(component, 'action', entry.actions, mapping.source)
494
+ return { $ref: `${COMMON}Action`, description: shape.description }
495
+ }
496
+ case 'spec':
497
+ for (const source of mapping.sources) {
498
+ if (!hasSource(entry, source)) fail(component, `canonical source "${source}" is missing.`)
499
+ }
500
+ return structuredClone(mapping.schema)
501
+ case 'prop': {
502
+ const schema = lookup(component, 'prop', entry.propsSchema.properties, mapping.source)
503
+ if (mapping.dynamic) {
504
+ return {
505
+ $ref: dynamicRefForSchema(component, schema),
506
+ description: schema.description
507
+ }
508
+ }
509
+ if (!mapping.values) {
510
+ const projected: Record<string, unknown> = structuredClone(schema)
511
+ if (mapping.default !== undefined) projected.default = mapping.default
512
+ return projected
513
+ }
514
+ const canonicalValues = new Set(schema.enum ?? [])
515
+ for (const [wireValue, canonicalValue] of Object.entries(mapping.values)) {
516
+ if (!canonicalValues.has(canonicalValue)) {
517
+ fail(
518
+ component,
519
+ `"${wireValue}" maps to "${canonicalValue}", which canonical prop "${mapping.source}" does not allow.`
520
+ )
521
+ }
522
+ }
523
+ const reverseDefault = Object.entries(mapping.values).find(
524
+ ([, canonicalValue]) => canonicalValue === schema.default
525
+ )?.[0]
526
+ const wireDefault = mapping.default ?? reverseDefault
527
+ return withDescription(
528
+ {
529
+ type: 'string',
530
+ enum: Object.keys(mapping.values),
531
+ ...(wireDefault === undefined ? {} : { default: wireDefault })
532
+ },
533
+ schema.description
534
+ )
535
+ }
536
+ }
537
+ }
538
+
539
+ function componentSchema(
540
+ a2uiName: string,
541
+ description: string,
542
+ properties: Record<string, A2uiJsonSchema>,
543
+ required: readonly string[],
544
+ checkable: boolean
545
+ ): A2uiJsonSchema {
546
+ const body = {
547
+ type: 'object',
548
+ properties: {
549
+ component: { const: a2uiName },
550
+ ...properties,
551
+ weight: { $ref: '#/$defs/Weight' }
552
+ },
553
+ required: ['component', ...required]
554
+ }
555
+ if (!checkable) return { description, ...body }
556
+ return { type: 'object', description, allOf: [{ $ref: `${COMMON}Checkable` }, body] }
557
+ }
558
+
559
+ function projectBasic(entry: CatalogEntry, projection: BasicProjection): A2uiJsonSchema {
560
+ const properties: Record<string, A2uiJsonSchema> = {}
561
+ for (const [wireName, mapping] of Object.entries(projection.props)) {
562
+ properties[wireName] = projectMappedProp(projection.a2uiName, entry, mapping)
563
+ }
564
+ for (const requiredProp of projection.required) {
565
+ if (!Object.hasOwn(properties, requiredProp)) {
566
+ fail(projection.a2uiName, `required prop "${requiredProp}" is not mapped.`)
567
+ }
568
+ }
569
+ return componentSchema(
570
+ projection.a2uiName,
571
+ entry.description,
572
+ properties,
573
+ projection.required,
574
+ projection.checkable ?? false
575
+ )
576
+ }
577
+
578
+ function projectExtension(entry: CatalogEntry, projection: ExtensionProjection): A2uiJsonSchema {
579
+ const omit = new Set(projection.omit ?? [])
580
+ const properties: Record<string, A2uiJsonSchema> = {}
581
+ const required: string[] = []
582
+ let checkable = false
583
+
584
+ for (const [propName, propSchema] of Object.entries(entry.propsSchema.properties)) {
585
+ if (omit.has(propName)) continue
586
+ // A binding that shares a prop's name makes that prop bindable without losing its constraints.
587
+ const bound = Object.hasOwn(entry.bindings, propName)
588
+ if (bound) {
589
+ const { description, ...literal } = structuredClone(propSchema)
590
+ properties[propName] = withDescription(
591
+ {
592
+ oneOf: [literal, { $ref: `${COMMON}DataBinding` }, { $ref: `${COMMON}FunctionCall` }]
593
+ },
594
+ description
595
+ )
596
+ } else {
597
+ properties[propName] = structuredClone(propSchema)
598
+ }
599
+ }
600
+ for (const requiredProp of entry.propsSchema.required ?? []) {
601
+ if (!omit.has(requiredProp)) required.push(requiredProp)
602
+ }
603
+ for (const [bindingName, bound] of Object.entries(entry.bindings)) {
604
+ if (omit.has(bindingName)) continue
605
+ if (bound.validatable) checkable = true
606
+ if (Object.hasOwn(properties, bindingName)) continue
607
+ const valueType = projection.bindingValueTypes?.[bindingName] ?? bound.valueType
608
+ properties[bindingName] = {
609
+ $ref: DYNAMIC_REF_BY_BINDING_TYPE[valueType],
610
+ description: bound.description
611
+ }
612
+ }
613
+ for (const [slotName, slotConstraint] of Object.entries(entry.slots)) {
614
+ properties[slotName] = slotSchema(slotConstraint)
615
+ if (slotConstraint.required) required.push(slotName)
616
+ }
617
+ for (const [actionName, shape] of Object.entries(entry.actions)) {
618
+ properties[actionName] = { $ref: `${COMMON}Action`, description: shape.description }
619
+ }
620
+
621
+ return componentSchema(
622
+ projection.a2uiName,
623
+ projection.description ?? entry.description,
624
+ properties,
625
+ required,
626
+ checkable
627
+ )
628
+ }
629
+
630
+ function catalogDocument(
631
+ catalogId: string,
632
+ title: string,
633
+ description: string,
634
+ components: Record<string, A2uiJsonSchema>
635
+ ): A2uiCatalogDocument {
636
+ return {
637
+ $schema: 'https://json-schema.org/draft/2020-12/schema',
638
+ $id: catalogId,
639
+ catalogId,
640
+ protocolVersion: A2UI_PROTOCOL_VERSION,
641
+ title,
642
+ description,
643
+ components,
644
+ functions: {},
645
+ $defs: {
646
+ anyComponent: {
647
+ oneOf: Object.keys(components).map(name => ({ $ref: `#/components/${name}` })),
648
+ discriminator: { propertyName: 'component' }
649
+ },
650
+ anyFunction: { not: {} },
651
+ Weight: {
652
+ type: 'number',
653
+ description:
654
+ 'Relative flex growth of this component inside a Row or Column. Set it only on direct children of a Row or Column.'
655
+ }
656
+ }
657
+ }
658
+ }
659
+
660
+ /**
661
+ * Generates the A2UI 1.0 basic catalog and the Radiant extension catalog from a canonical
662
+ * Radiant catalog. Entries added through `extendCatalog` join the extension catalog.
663
+ * Neither document defines functions yet.
664
+ */
665
+ export function generateA2uiCatalogs(catalog: Catalog): GeneratedA2uiCatalogs {
666
+ assertValidCatalog(catalog)
667
+
668
+ const sourceFor = (a2uiName: string, sourceEntry: string): CatalogEntry =>
669
+ catalog.entries[sourceEntry] ?? fail(a2uiName, `missing canonical entry "${sourceEntry}".`)
670
+
671
+ const basicComponents: Record<string, A2uiJsonSchema> = {}
672
+ const extensionComponents: Record<string, A2uiJsonSchema> = {}
673
+ const mappedSources = new Set<string>()
674
+
675
+ for (const projection of BASIC_PROJECTIONS) {
676
+ const entry = sourceFor(projection.a2uiName, projection.sourceEntry)
677
+ basicComponents[projection.a2uiName] = projectBasic(entry, projection)
678
+ mappedSources.add(projection.sourceEntry)
679
+ }
680
+ for (const projection of EXTENSION_PROJECTIONS) {
681
+ const entry = sourceFor(projection.a2uiName, projection.sourceEntry)
682
+ extensionComponents[projection.a2uiName] = projectExtension(entry, projection)
683
+ mappedSources.add(projection.sourceEntry)
684
+ }
685
+
686
+ for (const [entryName, entry] of Object.entries(catalog.entries)) {
687
+ if (mappedSources.has(entryName)) continue
688
+ if (
689
+ Object.hasOwn(basicComponents, entryName) ||
690
+ Object.hasOwn(extensionComponents, entryName)
691
+ ) {
692
+ fail(entryName, 'a custom entry cannot reuse the name of a generated A2UI component.')
693
+ }
694
+ extensionComponents[entryName] = projectExtension(entry, {
695
+ a2uiName: entryName,
696
+ sourceEntry: entryName
697
+ })
698
+ }
699
+
700
+ const generatedFrom = `Generated from canonical catalog "${catalog.id}" (${catalog.version}).`
701
+ return {
702
+ basic: catalogDocument(
703
+ A2UI_BASIC_CATALOG_ID,
704
+ 'A2UI Basic Catalog',
705
+ generatedFrom,
706
+ basicComponents
707
+ ),
708
+ extension: catalogDocument(
709
+ catalog.extends
710
+ ? `${RADIANT_A2UI_EXTENSION_CATALOG_ID}#${encodeURIComponent(catalog.id)}`
711
+ : RADIANT_A2UI_EXTENSION_CATALOG_ID,
712
+ 'Radiant A2UI Extension Catalog',
713
+ `${generatedFrom} Use alongside the A2UI basic catalog.`,
714
+ extensionComponents
715
+ )
716
+ }
717
+ }