@zhama/a2ui-core 0.1.0 → 0.3.0

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.
package/README.md CHANGED
@@ -9,6 +9,7 @@ A2UI (Agent to UI) is a JSON-based streaming UI protocol for dynamically renderi
9
9
  - **Types**: Complete TypeScript type definitions for A2UI v0.8 and v0.9
10
10
  - **Builders**: Convenient functions to build messages and components
11
11
  - **Validators**: Message validation utilities
12
+ - **Utils**: Utility functions for path bindings and data manipulation
12
13
 
13
14
  ## Installation
14
15
 
@@ -55,6 +56,24 @@ const result = validateMessage(messages[0]);
55
56
  console.log(result.valid); // true
56
57
  ```
57
58
 
59
+ ## Modular Imports
60
+
61
+ You can import specific modules for tree-shaking:
62
+
63
+ ```typescript
64
+ // Types only
65
+ import type { ComponentInstance, ServerToClientMessage } from '@zhama/a2ui-core/types';
66
+
67
+ // Builders only
68
+ import { text, column, createV09Messages } from '@zhama/a2ui-core/builders';
69
+
70
+ // Validators only
71
+ import { validateMessage, validateMessages } from '@zhama/a2ui-core/validators';
72
+
73
+ // Utils only
74
+ import { path, uuid, deepMerge } from '@zhama/a2ui-core/utils';
75
+ ```
76
+
58
77
  ## API Reference
59
78
 
60
79
  ### Types
@@ -63,17 +82,21 @@ console.log(result.valid); // true
63
82
  - `StringOrPath` - String literal or data path binding
64
83
  - `NumberOrPath` - Number literal or data path binding
65
84
  - `BooleanOrPath` - Boolean literal or data path binding
85
+ - `StringArrayOrPath` - String array literal or data path binding
66
86
 
67
- #### Components
68
- - `TextComponent`, `ImageComponent`, `IconComponent`, `VideoComponent`, `AudioPlayerComponent`
69
- - `RowComponent`, `ColumnComponent`, `ListComponent`, `CardComponent`
70
- - `TabsComponent`, `DividerComponent`, `ModalComponent`
71
- - `ButtonComponent`, `CheckBoxComponent`, `TextFieldComponent`
72
- - `DateTimeInputComponent`, `ChoicePickerComponent`, `SliderComponent`
87
+ #### Components (18 standard components)
88
+ **Content**: `TextComponent`, `ImageComponent`, `IconComponent`, `VideoComponent`, `AudioPlayerComponent`
89
+ **Layout**: `RowComponent`, `ColumnComponent`, `ListComponent`, `CardComponent`, `TabsComponent`, `DividerComponent`, `ModalComponent`
90
+ **Interactive**: `ButtonComponent`, `CheckBoxComponent`, `TextFieldComponent`, `DateTimeInputComponent`, `ChoicePickerComponent`, `SliderComponent`
73
91
 
74
92
  #### Messages
75
- - `CreateSurfaceMessage`, `UpdateComponentsMessage`, `UpdateDataModelMessage`, `DeleteSurfaceMessage` (v0.9)
76
- - `BeginRenderingMessage`, `SurfaceUpdateMessage`, `DataModelUpdateMessage` (v0.8)
93
+ - **v0.9**: `CreateSurfaceMessage`, `UpdateComponentsMessage`, `UpdateDataModelMessage`, `DeleteSurfaceMessage`
94
+ - **v0.8**: `BeginRenderingMessage`, `SurfaceUpdateMessage`, `DataModelUpdateMessage`
95
+
96
+ #### Other Types
97
+ - `Theme` - UI theme configuration
98
+ - `Action` - User action definition
99
+ - `ComponentInstance` - Component instance with ID
77
100
 
78
101
  ### Builders
79
102
 
@@ -83,19 +106,35 @@ console.log(result.valid); // true
83
106
  text(content: StringOrPath, options?: TextOptions): ComponentInstance
84
107
  image(url: StringOrPath, options?: ImageOptions): ComponentInstance
85
108
  icon(name: StringOrPath, options?: IconOptions): ComponentInstance
109
+ video(url: StringOrPath, options?: VideoOptions): ComponentInstance
110
+ audioPlayer(url: StringOrPath, options?: AudioPlayerOptions): ComponentInstance
86
111
 
87
112
  // Layout components
88
113
  row(children: ChildrenProperty, options?: LayoutOptions): ComponentInstance
89
114
  column(children: ChildrenProperty, options?: LayoutOptions): ComponentInstance
115
+ list(children: ChildrenProperty, options?: ListOptions): ComponentInstance
90
116
  card(childId: string, options?: CardOptions): ComponentInstance
117
+ tabs(items: TabItem[], options?: TabsOptions): ComponentInstance
118
+ divider(options?: DividerOptions): ComponentInstance
119
+ modal(entryPointChildId: string, contentChildId: string, options?: ModalOptions): ComponentInstance
91
120
 
92
121
  // Interactive components
93
122
  button(childId: string, action: Action, options?: ButtonOptions): ComponentInstance
123
+ checkbox(label: StringOrPath, value: BooleanOrPath, options?: CheckBoxOptions): ComponentInstance
94
124
  textField(label: StringOrPath, text?: StringOrPath, options?: TextFieldOptions): ComponentInstance
125
+ dateTimeInput(value: StringOrPath, options?: DateTimeInputOptions): ComponentInstance
126
+ choicePicker(options: ChoiceOption[], value: StringArrayOrPath, usageHint: string, opts?: ChoicePickerOptions): ComponentInstance
127
+ slider(value: NumberOrPath, options?: SliderOptions): ComponentInstance
95
128
 
96
- // Convenience
129
+ // Convenience helpers
97
130
  textButton(buttonText: string, action: Action, options?: ButtonOptions): [ComponentInstance, ComponentInstance]
98
131
  h1(content: StringOrPath, options?: TextOptions): ComponentInstance
132
+ h2(content: StringOrPath, options?: TextOptions): ComponentInstance
133
+ h3(content: StringOrPath, options?: TextOptions): ComponentInstance
134
+ h4(content: StringOrPath, options?: TextOptions): ComponentInstance
135
+ h5(content: StringOrPath, options?: TextOptions): ComponentInstance
136
+ caption(content: StringOrPath, options?: TextOptions): ComponentInstance
137
+ body(content: StringOrPath, options?: TextOptions): ComponentInstance
99
138
  ```
100
139
 
101
140
  #### Message Builders
@@ -103,15 +142,17 @@ h1(content: StringOrPath, options?: TextOptions): ComponentInstance
103
142
  // v0.9
104
143
  createSurface(surfaceId: string, catalogId?: string): CreateSurfaceMessage
105
144
  updateComponents(surfaceId: string, components: ComponentInstance[]): UpdateComponentsMessage
106
- updateDataModel(surfaceId: string, value: unknown, path?: string): UpdateDataModelMessage
145
+ updateDataModel(surfaceId: string, value: unknown, path?: string, op?: 'add' | 'replace' | 'remove'): UpdateDataModelMessage
107
146
  deleteSurface(surfaceId: string): DeleteSurfaceMessage
108
- createV09Messages(options: CreateV09Options): ServerToClientMessageV09[]
147
+ createV09Messages(options): ServerToClientMessageV09[]
109
148
 
110
149
  // v0.8
111
- beginRendering(rootId: string, surfaceId?: string, styles?: Record<string, string>): BeginRenderingMessage
150
+ beginRendering(rootId: string, surfaceId?: string, styles?: Theme): BeginRenderingMessage
112
151
  surfaceUpdate(components: ComponentInstanceV08[], surfaceId?: string): SurfaceUpdateMessage
113
- dataModelUpdate(contents: ValueMap[], surfaceId?: string): DataModelUpdateMessage
114
- createV08Messages(options: CreateV08Options): ServerToClientMessageV08[]
152
+ dataModelUpdate(contents: ValueMap[], surfaceId?: string, path?: string): DataModelUpdateMessage
153
+ dataModelInit(data: DataObject, surfaceId?: string): DataModelUpdateMessage
154
+ pathUpdate(path: string, value: DataValue, surfaceId?: string): DataModelUpdateMessage
155
+ createV08Messages(options): ServerToClientMessageV08[]
115
156
 
116
157
  // Utilities
117
158
  messagesToJsonl(messages: ServerToClientMessage[]): string
@@ -120,9 +161,12 @@ jsonlToMessages(jsonl: string): ServerToClientMessage[]
120
161
 
121
162
  #### Data Model Builders
122
163
  ```typescript
123
- objectToValueMap(obj: DataObject): ValueMap[]
164
+ objectToValueMap(obj: DataObject, prefix?: string): ValueMap[]
124
165
  valueToValueMap(key: string, value: DataValue): ValueMap
125
166
  valueMapToObject(valueMaps: ValueMap[]): DataObject
167
+ normalizePath(path: string, pathMappings?: PathMappings): string
168
+ updatesToValueMap(updates: UpdateDataItem[], basePath?: string): ValueMap[]
169
+ flattenObjectToValueMap(obj: DataObject, basePath: string): ValueMap[]
126
170
  ```
127
171
 
128
172
  ### Validators
@@ -130,31 +174,60 @@ valueMapToObject(valueMaps: ValueMap[]): DataObject
130
174
  ```typescript
131
175
  validateMessage(message: ServerToClientMessage, options?: ValidationOptions): ValidationResult
132
176
  validateMessages(messages: ServerToClientMessage[], options?: ValidationOptions): ValidationResult
177
+ validateV09Message(message: ServerToClientMessageV09, options?: ValidationOptions): ValidationResult
178
+ validateV08Message(message: ServerToClientMessageV08, options?: ValidationOptions): ValidationResult
133
179
  ```
134
180
 
135
181
  ### Utils
136
182
 
137
183
  ```typescript
138
- path(dataPath: string): { path: string } // Create data binding
139
- isPathBinding(value): boolean // Check if value is a path binding
140
- generateId(prefix?: string): string // Generate unique ID
141
- uuid(): string // Generate UUID v4
184
+ path(dataPath: string): { path: string } // Create data binding
185
+ isPathBinding(value): boolean // Check if value is a path binding
186
+ getLiteralValue<T>(value): T | undefined // Get literal value from StringOrPath/NumberOrPath/BooleanOrPath
187
+ getPathValue(value): string | undefined // Get path from binding
188
+ generateId(prefix?: string): string // Generate unique component ID
189
+ resetIdCounter(): void // Reset ID counter (for new scenes)
190
+ uuid(): string // Generate UUID v4
191
+ deepMerge<T>(target: T, source: Partial<T>): T // Deep merge objects
192
+ ```
193
+
194
+ ### Constants
195
+
196
+ ```typescript
197
+ STANDARD_CATALOG_ID // Standard A2UI catalog URL
198
+ A2UI_EXTENSION_URI // A2UI v0.9 extension URI
199
+ A2UI_EXTENSION_URI_V08 // A2UI v0.8 extension URI
200
+ A2UI_MIME_TYPE // A2UI MIME type (application/json+a2ui)
142
201
  ```
143
202
 
144
203
  ## Protocol Versions
145
204
 
146
205
  ### v0.9 (Prompt-first)
147
- - `createSurface` - Create a new surface
206
+ Optimized for prompt-first embedding, more concise format:
207
+ - `createSurface` - Create a new surface with catalog ID
148
208
  - `updateComponents` - Update components with flat component list
149
- - `updateDataModel` - Update data model
209
+ - `updateDataModel` - Update data model with JSON Patch-like operations
150
210
  - `deleteSurface` - Delete surface
151
211
 
152
212
  ### v0.8 (Structured output)
153
- - `beginRendering` - Signal to begin rendering
213
+ Optimized for LLM structured output:
214
+ - `beginRendering` - Signal to begin rendering with root component
154
215
  - `surfaceUpdate` - Update components
155
216
  - `dataModelUpdate` - Update data model using ValueMap format
156
217
  - `deleteSurface` - Delete surface
157
218
 
219
+ ## Type Guards
220
+
221
+ ```typescript
222
+ import { isV08Message, isV09Message } from '@zhama/a2ui-core';
223
+
224
+ if (isV09Message(message)) {
225
+ // Handle v0.9 message
226
+ } else if (isV08Message(message)) {
227
+ // Handle v0.8 message
228
+ }
229
+ ```
230
+
158
231
  ## License
159
232
 
160
233
  MIT