@cognitap/radiant 0.0.91 → 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 (129) hide show
  1. package/CHANGELOG.md +11 -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/Table/Table.d.ts +6 -2
  83. package/dist/library/components/Table/Table.d.ts.map +1 -1
  84. package/dist/library/components/Table/Table.js +10 -4
  85. package/dist/library/components/Table/Table.js.map +1 -1
  86. package/dist/library/index.d.ts +1 -1
  87. package/dist/library/index.d.ts.map +1 -1
  88. package/dist/library/presentation.d.ts +3 -0
  89. package/dist/library/presentation.d.ts.map +1 -1
  90. package/dist/library/styles.css +1 -1
  91. package/dist/library/themes/components.d.ts +6 -0
  92. package/dist/library/themes/components.d.ts.map +1 -1
  93. package/dist/library/themes/components.js +6 -0
  94. package/dist/library/themes/components.js.map +1 -1
  95. package/dist/library/themes/tokens.d.ts +4 -0
  96. package/dist/library/themes/tokens.d.ts.map +1 -1
  97. package/dist/library/themes/tokens.js +3 -0
  98. package/dist/library/themes/tokens.js.map +1 -1
  99. package/docs/accessibility.md +6 -0
  100. package/docs/architecture.md +13 -1
  101. package/docs/theming.md +13 -0
  102. package/package.json +17 -5
  103. package/src/a2ui/A2uiPlaceholder.tsx +64 -0
  104. package/src/a2ui/A2uiSurface.tsx +790 -0
  105. package/src/a2ui/accessibility.ts +145 -0
  106. package/src/a2ui/accessibilityRules.ts +106 -0
  107. package/src/a2ui/catalog.json +317 -0
  108. package/src/a2ui/catalogGenerator.ts +717 -0
  109. package/src/a2ui/coerce.ts +379 -0
  110. package/src/a2ui/entries.tsx +519 -0
  111. package/src/a2ui/fixtures.ts +402 -0
  112. package/src/a2ui/index.ts +50 -0
  113. package/src/a2ui/protocolErrors.ts +63 -0
  114. package/src/a2ui/registry.ts +221 -0
  115. package/src/a2ui/sanitize.ts +51 -0
  116. package/src/a2ui/surfaceRuntime.ts +317 -0
  117. package/src/catalog/actions.ts +108 -0
  118. package/src/catalog/coerce.ts +447 -0
  119. package/src/catalog/index.ts +67 -0
  120. package/src/catalog/radiantCatalog.ts +949 -0
  121. package/src/catalog/types.ts +159 -0
  122. package/src/catalog/validate.ts +454 -0
  123. package/src/components/Card/Card.tsx +35 -19
  124. package/src/components/Table/Table.tsx +16 -3
  125. package/src/index.ts +1 -1
  126. package/src/presentation.ts +3 -0
  127. package/src/themes/baseline.css +3 -0
  128. package/src/themes/components.ts +6 -0
  129. package/src/themes/tokens.ts +7 -0
@@ -0,0 +1,402 @@
1
+ import { A2UI_BASIC_CATALOG_ID, A2UI_PROTOCOL_VERSION } from './catalogGenerator.js'
2
+ import type { A2uiMessage } from './sanitize.js'
3
+
4
+ export const PROFILE_SURFACE_ID = 'profile_editor'
5
+
6
+ /**
7
+ * Recorded A2UI 1.0 tracer-bullet fixture containing Text, a data-bound TextField,
8
+ * and a Button whose action emits an event carrying the bound value in `context`.
9
+ */
10
+ export const profileFixtureMessages: readonly A2uiMessage[] = [
11
+ {
12
+ version: A2UI_PROTOCOL_VERSION,
13
+ createSurface: {
14
+ surfaceId: PROFILE_SURFACE_ID,
15
+ catalogId: A2UI_BASIC_CATALOG_ID,
16
+ dataModel: {
17
+ profile: {
18
+ displayName: 'Ada Lovelace'
19
+ }
20
+ },
21
+ components: [
22
+ {
23
+ id: 'root',
24
+ component: 'Column',
25
+ children: ['intro_text', 'caption_text', 'name_field', 'save_button']
26
+ },
27
+ {
28
+ id: 'intro_text',
29
+ component: 'Text',
30
+ text: 'Update how your name appears across shared workspaces.',
31
+ variant: 'body'
32
+ },
33
+ {
34
+ id: 'caption_text',
35
+ component: 'Text',
36
+ text: 'Changes apply immediately after saving.',
37
+ variant: 'caption'
38
+ },
39
+ {
40
+ id: 'name_field',
41
+ component: 'TextField',
42
+ label: 'Display name',
43
+ placeholder: 'Enter your name',
44
+ value: { '@path': '/profile/displayName' },
45
+ variant: 'shortText'
46
+ },
47
+ {
48
+ id: 'save_button',
49
+ component: 'Button',
50
+ child: 'save_button_label',
51
+ variant: 'primary',
52
+ action: {
53
+ event: {
54
+ name: 'save_profile',
55
+ context: {
56
+ displayName: { '@path': '/profile/displayName' }
57
+ }
58
+ }
59
+ }
60
+ },
61
+ {
62
+ id: 'save_button_label',
63
+ component: 'Text',
64
+ text: 'Save profile'
65
+ }
66
+ ]
67
+ }
68
+ }
69
+ ]
70
+
71
+ /**
72
+ * Same recorded A2UI 1.0 fixture carrying agent-supplied theme hints that Radiant must ignore.
73
+ */
74
+ export const profileFixtureWithThemeHintMessages: readonly A2uiMessage[] = [
75
+ {
76
+ version: A2UI_PROTOCOL_VERSION,
77
+ createSurface: {
78
+ ...(profileFixtureMessages[0]!.createSurface as Record<string, unknown>),
79
+ theme: {
80
+ primaryColor: '#ff00ff',
81
+ font: 'Comic Sans MS'
82
+ }
83
+ }
84
+ }
85
+ ]
86
+
87
+ /**
88
+ * Recorded A2UI 1.0 fixture with malformed model output: invalid enums, missing required label,
89
+ * mixed controlled/uncontrolled state (`value` + `defaultValue`), forbidden host props,
90
+ * non-string text, and an unknown component that must degrade to text without throwing.
91
+ */
92
+ export const malformedProfileFixtureMessages: readonly A2uiMessage[] = [
93
+ {
94
+ version: A2UI_PROTOCOL_VERSION,
95
+ createSurface: {
96
+ surfaceId: PROFILE_SURFACE_ID,
97
+ catalogId: A2UI_BASIC_CATALOG_ID,
98
+ dataModel: {
99
+ profile: {
100
+ displayName: 'Ada Lovelace'
101
+ }
102
+ },
103
+ components: [
104
+ {
105
+ id: 'root',
106
+ component: 'Column',
107
+ align: 'middle',
108
+ children: ['intro_text', 'unknown_banner', 'name_field', 'save_button']
109
+ },
110
+ {
111
+ id: 'intro_text',
112
+ component: 'Text',
113
+ text: 42,
114
+ variant: 'giant',
115
+ className: 'bg-red-500'
116
+ },
117
+ {
118
+ id: 'unknown_banner',
119
+ component: 'PromoBanner',
120
+ text: 'Workspace settings remain available.'
121
+ },
122
+ {
123
+ id: 'name_field',
124
+ component: 'TextField',
125
+ value: { '@path': '/profile/displayName' },
126
+ defaultValue: 'Grace Hopper',
127
+ variant: 'email',
128
+ style: { color: 'red' }
129
+ },
130
+ {
131
+ id: 'save_button',
132
+ component: 'Button',
133
+ variant: 'neon',
134
+ child: 'save_button_label',
135
+ action: {
136
+ event: {
137
+ name: 'save_profile',
138
+ context: {
139
+ displayName: { '@path': '/profile/displayName' }
140
+ }
141
+ }
142
+ }
143
+ },
144
+ {
145
+ id: 'save_button_label',
146
+ component: 'Text',
147
+ text: 'Save profile'
148
+ }
149
+ ]
150
+ }
151
+ }
152
+ ]
153
+
154
+ export const PREFERENCES_SURFACE_ID = 'workspace_preferences'
155
+
156
+ /**
157
+ * Recorded A2UI 1.0 fixture combining several client-local controls (TextField, ChoicePicker,
158
+ * Slider, CheckBox) with one named outbound action that delivers a surface state snapshot.
159
+ */
160
+ export const interactivePreferencesFixtureMessages: readonly A2uiMessage[] = [
161
+ {
162
+ version: A2UI_PROTOCOL_VERSION,
163
+ createSurface: {
164
+ surfaceId: PREFERENCES_SURFACE_ID,
165
+ catalogId: A2UI_BASIC_CATALOG_ID,
166
+ dataModel: {
167
+ note: '',
168
+ cadence: ['daily'],
169
+ channels: ['email'],
170
+ volume: 40,
171
+ notify: false
172
+ },
173
+ components: [
174
+ {
175
+ id: 'root',
176
+ component: 'Column',
177
+ children: [
178
+ 'note_field',
179
+ 'cadence_picker',
180
+ 'channel_picker',
181
+ 'volume_slider',
182
+ 'notify_checkbox',
183
+ 'apply_button'
184
+ ]
185
+ },
186
+ {
187
+ id: 'note_field',
188
+ component: 'TextField',
189
+ label: 'Summary note',
190
+ placeholder: 'Add a short note',
191
+ value: { '@path': '/note' },
192
+ variant: 'shortText'
193
+ },
194
+ {
195
+ id: 'cadence_picker',
196
+ component: 'ChoicePicker',
197
+ label: 'Digest cadence',
198
+ variant: 'mutuallyExclusive',
199
+ options: [
200
+ { label: 'Daily', value: 'daily' },
201
+ { label: 'Weekly', value: 'weekly' }
202
+ ],
203
+ value: { '@path': '/cadence' }
204
+ },
205
+ {
206
+ id: 'channel_picker',
207
+ component: 'ChoicePicker',
208
+ label: 'Delivery channels',
209
+ variant: 'multipleSelection',
210
+ options: [
211
+ { label: 'Email', value: 'email' },
212
+ { label: 'In-app', value: 'in_app' }
213
+ ],
214
+ value: { '@path': '/channels' }
215
+ },
216
+ {
217
+ id: 'volume_slider',
218
+ component: 'Slider',
219
+ label: 'Alert volume',
220
+ min: 0,
221
+ max: 100,
222
+ steps: 10,
223
+ value: { '@path': '/volume' }
224
+ },
225
+ {
226
+ id: 'notify_checkbox',
227
+ component: 'CheckBox',
228
+ label: 'Enable quiet hours',
229
+ value: { '@path': '/notify' }
230
+ },
231
+ {
232
+ id: 'apply_button',
233
+ component: 'Button',
234
+ variant: 'primary',
235
+ child: 'apply_button_label',
236
+ action: {
237
+ event: {
238
+ name: 'apply_preferences'
239
+ }
240
+ }
241
+ },
242
+ {
243
+ id: 'apply_button_label',
244
+ component: 'Text',
245
+ text: 'Apply preferences'
246
+ }
247
+ ]
248
+ }
249
+ }
250
+ ]
251
+
252
+ export const INACCESSIBLE_SURFACE_ID = 'inaccessible_signup'
253
+
254
+ /**
255
+ * A2UI 1.0 fixture that fails `validateA2uiAccessibility`: unlabeled controls (some fixable from
256
+ * author text), a button with no text, and a patch that adds another unlabeled control.
257
+ */
258
+ export const inaccessibleFixtureMessages: readonly A2uiMessage[] = [
259
+ {
260
+ version: A2UI_PROTOCOL_VERSION,
261
+ createSurface: {
262
+ surfaceId: INACCESSIBLE_SURFACE_ID,
263
+ catalogId: A2UI_BASIC_CATALOG_ID,
264
+ components: [
265
+ {
266
+ id: 'root',
267
+ component: 'Column',
268
+ children: ['email_field', 'terms_checkbox', 'plan_picker', 'submit_button']
269
+ },
270
+ {
271
+ id: 'email_field',
272
+ component: 'TextField',
273
+ placeholder: 'Email address',
274
+ value: { '@path': '/email' }
275
+ },
276
+ {
277
+ id: 'terms_checkbox',
278
+ component: 'CheckBox',
279
+ accessibility: { label: 'Accept the terms' },
280
+ value: false
281
+ },
282
+ {
283
+ id: 'plan_picker',
284
+ component: 'ChoicePicker',
285
+ accessibility: { label: 'Plan' },
286
+ options: [{ label: 'Free', value: 'free' }],
287
+ value: ['free']
288
+ },
289
+ {
290
+ id: 'submit_button',
291
+ component: 'Button',
292
+ child: 'submit_icon',
293
+ action: { event: { name: 'submit' } }
294
+ },
295
+ { id: 'submit_icon', component: 'Text', text: ' ' }
296
+ ]
297
+ }
298
+ },
299
+ {
300
+ version: A2UI_PROTOCOL_VERSION,
301
+ updateComponents: {
302
+ surfaceId: INACCESSIBLE_SURFACE_ID,
303
+ components: [
304
+ {
305
+ id: 'root',
306
+ component: 'Column',
307
+ children: [
308
+ 'email_field',
309
+ 'terms_checkbox',
310
+ 'plan_picker',
311
+ 'seats_slider',
312
+ 'submit_button'
313
+ ]
314
+ },
315
+ { id: 'seats_slider', component: 'Slider', min: 1, max: 10, value: 1 }
316
+ ]
317
+ }
318
+ }
319
+ ]
320
+
321
+ export const STREAMED_SURFACE_ID = 'weekly_check_in'
322
+
323
+ const streamed = (body: Record<string, unknown>): A2uiMessage => ({
324
+ version: A2UI_PROTOCOL_VERSION,
325
+ ...body
326
+ })
327
+ const streamedComponents = (...components: Record<string, unknown>[]) =>
328
+ streamed({ updateComponents: { surfaceId: STREAMED_SURFACE_ID, components } })
329
+
330
+ /**
331
+ * Recorded stream, replayed one message at a time: a component arrives before the root,
332
+ * children arrive out of order, and a binding names a data path that arrives last.
333
+ */
334
+ export const streamedFixtureMessages: readonly A2uiMessage[] = [
335
+ streamed({ createSurface: { surfaceId: STREAMED_SURFACE_ID, catalogId: A2UI_BASIC_CATALOG_ID } }),
336
+ streamedComponents({
337
+ id: 'greeting_text',
338
+ component: 'Text',
339
+ text: { '@path': '/learner/greeting' }
340
+ }),
341
+ streamedComponents({
342
+ id: 'root',
343
+ component: 'Column',
344
+ children: ['heading_text', 'greeting_text', 'name_field', 'submit_button']
345
+ }),
346
+ streamedComponents({
347
+ id: 'submit_button',
348
+ component: 'Button',
349
+ child: 'submit_label',
350
+ variant: 'primary',
351
+ action: { event: { name: 'submit_check_in' } }
352
+ }),
353
+ streamedComponents({ id: 'heading_text', component: 'Text', text: 'Weekly check-in' }),
354
+ streamedComponents({
355
+ id: 'name_field',
356
+ component: 'TextField',
357
+ label: 'Your name',
358
+ value: { '@path': '/learner/name' }
359
+ }),
360
+ streamed({
361
+ updateDataModel: {
362
+ surfaceId: STREAMED_SURFACE_ID,
363
+ path: '/learner',
364
+ value: { name: 'Ada', greeting: 'Welcome back, Ada.' }
365
+ }
366
+ }),
367
+ streamedComponents({ id: 'submit_label', component: 'Text', text: 'Send check-in' })
368
+ ]
369
+
370
+ /** Recorded stream that sends each component one prop at a time. */
371
+ export const propStreamFixtureMessages: readonly A2uiMessage[] = [
372
+ streamed({
373
+ createSurface: {
374
+ surfaceId: STREAMED_SURFACE_ID,
375
+ catalogId: A2UI_BASIC_CATALOG_ID,
376
+ components: [{ id: 'root', component: 'Column', children: ['title_text', 'next_button'] }]
377
+ }
378
+ }),
379
+ streamedComponents({ id: 'title_text', component: 'Text' }),
380
+ streamedComponents({ id: 'title_text', component: 'Text', text: 'Lesson complete' }),
381
+ streamedComponents({
382
+ id: 'title_text',
383
+ component: 'Text',
384
+ text: 'Lesson complete',
385
+ variant: 'body'
386
+ }),
387
+ streamedComponents({ id: 'next_button', component: 'Button', child: 'next_label' }),
388
+ streamedComponents({
389
+ id: 'next_button',
390
+ component: 'Button',
391
+ child: 'next_label',
392
+ action: { event: { name: 'next_lesson' } }
393
+ }),
394
+ streamedComponents({ id: 'next_label', component: 'Text', text: 'Next lesson' }),
395
+ streamedComponents({
396
+ id: 'next_button',
397
+ component: 'Button',
398
+ child: 'next_label',
399
+ action: { event: { name: 'next_lesson' } },
400
+ variant: 'primary'
401
+ })
402
+ ]
@@ -0,0 +1,50 @@
1
+ export { A2uiSurface } from './A2uiSurface.js'
2
+ export type { A2uiActionPayload, A2uiSurfaceProps } from './A2uiSurface.js'
3
+ export { radiantA2uiRegistry } from './entries.js'
4
+ export { createA2uiRegistry, createA2uiRegistryEntry } from './registry.js'
5
+ export type {
6
+ A2uiAdapterContext,
7
+ A2uiComponentAdapter,
8
+ A2uiComponentReference,
9
+ A2uiRegistry,
10
+ A2uiRegistryEntry,
11
+ A2uiRegistryEntryInput,
12
+ A2uiRegistryInput,
13
+ A2uiRenderOptions
14
+ } from './registry.js'
15
+ export {
16
+ A2UI_BASIC_CATALOG_ID,
17
+ A2UI_PROTOCOL_VERSION,
18
+ RADIANT_A2UI_EXTENSION_CATALOG_ID,
19
+ generateA2uiCatalogs
20
+ } from './catalogGenerator.js'
21
+ export type {
22
+ A2uiCatalogDocument,
23
+ A2uiJsonSchema,
24
+ GeneratedA2uiCatalogs
25
+ } from './catalogGenerator.js'
26
+ export { validateA2uiAccessibility } from './accessibility.js'
27
+ export type {
28
+ A2uiAccessibilityError,
29
+ ValidateA2uiAccessibilityOptions,
30
+ ValidateA2uiAccessibilityResult
31
+ } from './accessibility.js'
32
+ export { buttonNameRule, controlLabelRule } from './accessibilityRules.js'
33
+ export type {
34
+ A2uiAccessibilityFinding,
35
+ A2uiAccessibilityRule,
36
+ A2uiAccessibilityRuleContext,
37
+ A2uiComponentRecord,
38
+ ControlLabelRuleOptions
39
+ } from './accessibilityRules.js'
40
+ export { sanitizeA2uiMessages } from './sanitize.js'
41
+ export type { A2uiMessage } from './sanitize.js'
42
+ export { COERCED_NOOP_ACTION_NAME, coerceA2uiMessages } from './coerce.js'
43
+ export type { CoerceA2uiMessagesResult } from './coerce.js'
44
+ export type {
45
+ CatalogActionEvent,
46
+ CatalogActionHandler,
47
+ CatalogDiagnostic,
48
+ CatalogDiagnosticKind,
49
+ CatalogSurfaceState
50
+ } from '../catalog/index.js'
@@ -0,0 +1,63 @@
1
+ import { isPlainRecord } from '../catalog/coerce.js'
2
+ import type { CatalogDiagnostic } from '../catalog/index.js'
3
+ import type { A2uiMessage } from './sanitize.js'
4
+
5
+ const COMPONENT_ID_PATTERN = /Component '([^']+)'/
6
+
7
+ /** Maps a `@a2ui/web_core` error payload onto the structured `onDiagnostic` channel. */
8
+ export function protocolErrorDiagnostic(error: unknown): CatalogDiagnostic {
9
+ const payload = isPlainRecord(error) ? error : {}
10
+ const code = typeof payload.code === 'string' ? payload.code : 'PROTOCOL_ERROR'
11
+ const message = typeof payload.message === 'string' ? payload.message : 'Protocol error.'
12
+ return {
13
+ kind: 'error',
14
+ code,
15
+ nodeId: COMPONENT_ID_PATTERN.exec(message)?.[1] ?? '',
16
+ component: 'surface',
17
+ prop: 'message',
18
+ received: Object.freeze({ ...payload }),
19
+ used: undefined,
20
+ reason: message
21
+ }
22
+ }
23
+
24
+ function surfaceOf(message: A2uiMessage, key: string): string | undefined {
25
+ if (!isPlainRecord(message)) return undefined
26
+ const body = message[key]
27
+ return isPlainRecord(body) && typeof body.surfaceId === 'string' ? body.surfaceId : undefined
28
+ }
29
+
30
+ export const createsSurface = (message: A2uiMessage, surfaceId: string) =>
31
+ surfaceOf(message, 'createSurface') === surfaceId
32
+
33
+ export const deletesSurface = (message: A2uiMessage, surfaceId: string) =>
34
+ surfaceOf(message, 'deleteSurface') === surfaceId
35
+
36
+ /** Drops buffered updates a snapshot `createSurface` already supersedes. */
37
+ export function supersededBy(create: A2uiMessage, held: A2uiMessage): boolean {
38
+ const body = isPlainRecord(create) ? create.createSurface : undefined
39
+ if (!isPlainRecord(body) || !isPlainRecord(held)) return false
40
+ return (
41
+ (body.components !== undefined && 'updateComponents' in held) ||
42
+ (body.dataModel !== undefined && 'updateDataModel' in held)
43
+ )
44
+ }
45
+
46
+ /** True for component and data updates that need the surface to exist first. */
47
+ export const updatesSurface = (message: A2uiMessage, surfaceId: string) =>
48
+ surfaceOf(message, 'updateComponents') === surfaceId ||
49
+ surfaceOf(message, 'updateDataModel') === surfaceId
50
+
51
+ /** Component definitions a `createSurface` or `updateComponents` message carries for this surface. */
52
+ export function streamedComponents(
53
+ message: A2uiMessage,
54
+ surfaceId: string
55
+ ): readonly Readonly<Record<string, unknown>>[] {
56
+ for (const key of ['createSurface', 'updateComponents']) {
57
+ const body = isPlainRecord(message) ? message[key] : undefined
58
+ if (isPlainRecord(body) && body.surfaceId === surfaceId && Array.isArray(body.components)) {
59
+ return body.components.filter(isPlainRecord)
60
+ }
61
+ }
62
+ return []
63
+ }