@zhama/a2ui-core 0.4.0 → 0.6.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 +60 -141
- package/dist/builders/index.cjs +2 -2
- package/dist/builders/index.d.cts +16 -3
- package/dist/builders/index.d.ts +16 -3
- package/dist/builders/index.js +2 -2
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/{primitives-nmkVz-tB.d.cts → primitives-DLbBDhLq.d.cts} +1 -35
- package/dist/{primitives-nmkVz-tB.d.ts → primitives-DLbBDhLq.d.ts} +1 -35
- package/dist/surface/index.cjs +2 -2
- package/dist/surface/index.d.cts +1 -1
- package/dist/surface/index.d.ts +1 -1
- package/dist/surface/index.js +2 -2
- package/dist/types/index.cjs +2 -2
- package/dist/types/index.d.cts +67 -34
- package/dist/types/index.d.ts +67 -34
- package/dist/types/index.js +2 -2
- package/dist/utils/index.d.cts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/validators/index.cjs +1 -1
- package/dist/validators/index.d.cts +8 -12
- package/dist/validators/index.d.ts +8 -12
- package/dist/validators/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# @zhama/a2ui-core
|
|
2
2
|
|
|
3
|
-
A2UI Protocol Core Library - Framework-agnostic TypeScript types and builders for A2UI protocol.
|
|
3
|
+
A2UI Protocol Core Library - Framework-agnostic TypeScript types and builders for A2UI v0.9 protocol.
|
|
4
4
|
|
|
5
|
-
> **Note**: A2UI v0.
|
|
6
|
-
>
|
|
5
|
+
> **Note**: This library uses A2UI v0.9 format exclusively. While v0.9 is still in draft status
|
|
6
|
+
> according to [a2ui.org](https://a2ui.org/), it offers a cleaner and more modern API.
|
|
7
7
|
|
|
8
8
|
## Overview
|
|
9
9
|
|
|
10
10
|
A2UI (Agent to UI) is a JSON-based streaming UI protocol for dynamically rendering user interfaces. This library provides:
|
|
11
11
|
|
|
12
|
-
- **Types**: Complete TypeScript type definitions for A2UI v0.
|
|
13
|
-
- **Builders**: Convenient functions to build messages and components
|
|
12
|
+
- **Types**: Complete TypeScript type definitions for A2UI v0.9
|
|
13
|
+
- **Builders**: Convenient functions to build messages and components
|
|
14
|
+
- **Surface**: Surface ID constants and creation utilities
|
|
14
15
|
- **Validators**: Message validation utilities
|
|
15
16
|
- **Utils**: Utility functions for path bindings and data manipulation
|
|
16
|
-
- **Surface**: Surface ID constants and creation utilities
|
|
17
17
|
|
|
18
18
|
## Installation
|
|
19
19
|
|
|
@@ -28,10 +28,13 @@ pnpm add @zhama/a2ui-core
|
|
|
28
28
|
```typescript
|
|
29
29
|
import {
|
|
30
30
|
// Builders
|
|
31
|
-
text, column, button,
|
|
31
|
+
text, column, button, h1,
|
|
32
32
|
createSurface, updateComponents, updateDataModel,
|
|
33
33
|
createV09Messages,
|
|
34
34
|
|
|
35
|
+
// Surface
|
|
36
|
+
SURFACE_IDS, createA2UISurface,
|
|
37
|
+
|
|
35
38
|
// Validators
|
|
36
39
|
validateMessage,
|
|
37
40
|
|
|
@@ -40,17 +43,17 @@ import {
|
|
|
40
43
|
|
|
41
44
|
// Types
|
|
42
45
|
type ComponentInstance,
|
|
43
|
-
type
|
|
46
|
+
type ServerToClientMessageV09,
|
|
44
47
|
} from '@zhama/a2ui-core';
|
|
45
48
|
|
|
46
49
|
// Create components
|
|
47
|
-
const title =
|
|
50
|
+
const title = h1('Hello World', { id: 'title' });
|
|
48
51
|
const greeting = text({ path: '/user/name' }, { id: 'greeting' });
|
|
49
52
|
const root = column(['title', 'greeting'], { id: 'root' });
|
|
50
53
|
|
|
51
54
|
// Create messages
|
|
52
55
|
const messages = createV09Messages({
|
|
53
|
-
surfaceId:
|
|
56
|
+
surfaceId: SURFACE_IDS.CHAT,
|
|
54
57
|
components: [title, greeting, root],
|
|
55
58
|
dataModel: { user: { name: 'John' } },
|
|
56
59
|
});
|
|
@@ -66,14 +69,11 @@ You can import specific modules for tree-shaking:
|
|
|
66
69
|
|
|
67
70
|
```typescript
|
|
68
71
|
// Types only
|
|
69
|
-
import type { ComponentInstance,
|
|
72
|
+
import type { ComponentInstance, ServerToClientMessageV09 } from '@zhama/a2ui-core/types';
|
|
70
73
|
|
|
71
|
-
// Builders only
|
|
74
|
+
// Builders only
|
|
72
75
|
import { text, column, createV09Messages } from '@zhama/a2ui-core/builders';
|
|
73
76
|
|
|
74
|
-
// Builders only (v0.8 format - compatible with tego-server)
|
|
75
|
-
import { createText, createColumn, createButton } from '@zhama/a2ui-core/builders';
|
|
76
|
-
|
|
77
77
|
// Validators only
|
|
78
78
|
import { validateMessage, validateMessages } from '@zhama/a2ui-core/validators';
|
|
79
79
|
|
|
@@ -86,31 +86,8 @@ import { SURFACE_IDS, createA2UISurface, createChatSurface } from '@zhama/a2ui-c
|
|
|
86
86
|
|
|
87
87
|
## API Reference
|
|
88
88
|
|
|
89
|
-
###
|
|
90
|
-
|
|
91
|
-
#### Primitives
|
|
92
|
-
- `StringOrPath` - String literal or data path binding
|
|
93
|
-
- `NumberOrPath` - Number literal or data path binding
|
|
94
|
-
- `BooleanOrPath` - Boolean literal or data path binding
|
|
95
|
-
- `StringArrayOrPath` - String array literal or data path binding
|
|
96
|
-
|
|
97
|
-
#### Components (18 standard components)
|
|
98
|
-
**Content**: `TextComponent`, `ImageComponent`, `IconComponent`, `VideoComponent`, `AudioPlayerComponent`
|
|
99
|
-
**Layout**: `RowComponent`, `ColumnComponent`, `ListComponent`, `CardComponent`, `TabsComponent`, `DividerComponent`, `ModalComponent`
|
|
100
|
-
**Interactive**: `ButtonComponent`, `CheckBoxComponent`, `TextFieldComponent`, `DateTimeInputComponent`, `ChoicePickerComponent`, `SliderComponent`
|
|
101
|
-
|
|
102
|
-
#### Messages
|
|
103
|
-
- **v0.9**: `CreateSurfaceMessage`, `UpdateComponentsMessage`, `UpdateDataModelMessage`, `DeleteSurfaceMessage`
|
|
104
|
-
- **v0.8**: `BeginRenderingMessage`, `SurfaceUpdateMessage`, `DataModelUpdateMessage`
|
|
105
|
-
|
|
106
|
-
#### Other Types
|
|
107
|
-
- `Theme` - UI theme configuration
|
|
108
|
-
- `Action` - User action definition
|
|
109
|
-
- `ComponentInstance` - Component instance with ID
|
|
89
|
+
### Component Builders
|
|
110
90
|
|
|
111
|
-
### Builders
|
|
112
|
-
|
|
113
|
-
#### Component Builders
|
|
114
91
|
```typescript
|
|
115
92
|
// Content components
|
|
116
93
|
text(content: StringOrPath, options?: TextOptions): ComponentInstance
|
|
@@ -147,36 +124,53 @@ caption(content: StringOrPath, options?: TextOptions): ComponentInstance
|
|
|
147
124
|
body(content: StringOrPath, options?: TextOptions): ComponentInstance
|
|
148
125
|
```
|
|
149
126
|
|
|
150
|
-
|
|
127
|
+
### Message Builders
|
|
128
|
+
|
|
151
129
|
```typescript
|
|
152
|
-
// v0.9
|
|
153
130
|
createSurface(surfaceId: string, catalogId?: string): CreateSurfaceMessage
|
|
154
131
|
updateComponents(surfaceId: string, components: ComponentInstance[]): UpdateComponentsMessage
|
|
155
132
|
updateDataModel(surfaceId: string, value: unknown, path?: string, op?: 'add' | 'replace' | 'remove'): UpdateDataModelMessage
|
|
156
133
|
deleteSurface(surfaceId: string): DeleteSurfaceMessage
|
|
157
134
|
createV09Messages(options): ServerToClientMessageV09[]
|
|
158
135
|
|
|
159
|
-
// v0.8
|
|
160
|
-
beginRendering(rootId: string, surfaceId?: string, styles?: Theme): BeginRenderingMessage
|
|
161
|
-
surfaceUpdate(components: ComponentInstanceV08[], surfaceId?: string): SurfaceUpdateMessage
|
|
162
|
-
dataModelUpdate(contents: ValueMap[], surfaceId?: string, path?: string): DataModelUpdateMessage
|
|
163
|
-
dataModelInit(data: DataObject, surfaceId?: string): DataModelUpdateMessage
|
|
164
|
-
pathUpdate(path: string, value: DataValue, surfaceId?: string): DataModelUpdateMessage
|
|
165
|
-
createV08Messages(options): ServerToClientMessageV08[]
|
|
166
|
-
|
|
167
136
|
// Utilities
|
|
168
|
-
messagesToJsonl(messages:
|
|
169
|
-
jsonlToMessages(jsonl: string):
|
|
137
|
+
messagesToJsonl(messages: ServerToClientMessageV09[]): string
|
|
138
|
+
jsonlToMessages(jsonl: string): ServerToClientMessageV09[]
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Surface Module
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
// Surface ID constants
|
|
145
|
+
SURFACE_IDS.CHAT // '@chat' - Chat content area
|
|
146
|
+
SURFACE_IDS.RECOMMENDATION // '@recommendation' - Agent recommendations
|
|
147
|
+
SURFACE_IDS.INPUT_FORM // '@input-form' - Input collection forms
|
|
148
|
+
SURFACE_IDS.ORCHESTRATION // '@orchestration' - Multi-agent orchestration
|
|
149
|
+
SURFACE_IDS.STATUS // '@status' - Status messages
|
|
150
|
+
SURFACE_IDS.RESULT // '@result' - Agent results
|
|
151
|
+
SURFACE_IDS.CONFIRM // '@confirm' - Confirmation dialogs
|
|
152
|
+
SURFACE_IDS.NOTIFICATION // '@notification' - Notifications
|
|
153
|
+
|
|
154
|
+
// Surface creation functions
|
|
155
|
+
createA2UISurface(rootId: string, components: ComponentInstance[], surfaceId?: string): SurfaceResult
|
|
156
|
+
createA2UISurfaceWithData(rootId: string, components: ComponentInstance[], dataModel: DataObject, surfaceId?: string): SurfaceResult
|
|
157
|
+
createDeleteSurfaceMessage(surfaceId: string): ServerToClientMessageV09
|
|
158
|
+
|
|
159
|
+
// Convenience functions
|
|
160
|
+
createChatSurface(rootId: string, components: ComponentInstance[]): SurfaceResult
|
|
161
|
+
createRecommendationSurface(rootId: string, components: ComponentInstance[]): SurfaceResult
|
|
162
|
+
createInputFormSurface(rootId: string, components: ComponentInstance[]): SurfaceResult
|
|
163
|
+
createOrchestrationSurface(rootId: string, components: ComponentInstance[]): SurfaceResult
|
|
164
|
+
createStatusSurface(rootId: string, components: ComponentInstance[]): SurfaceResult
|
|
170
165
|
```
|
|
171
166
|
|
|
172
|
-
|
|
167
|
+
### Data Model
|
|
168
|
+
|
|
173
169
|
```typescript
|
|
174
170
|
objectToValueMap(obj: DataObject, prefix?: string): ValueMap[]
|
|
175
171
|
valueToValueMap(key: string, value: DataValue): ValueMap
|
|
176
172
|
valueMapToObject(valueMaps: ValueMap[]): DataObject
|
|
177
173
|
normalizePath(path: string, pathMappings?: PathMappings): string
|
|
178
|
-
updatesToValueMap(updates: UpdateDataItem[], basePath?: string): ValueMap[]
|
|
179
|
-
flattenObjectToValueMap(obj: DataObject, basePath: string): ValueMap[]
|
|
180
174
|
```
|
|
181
175
|
|
|
182
176
|
### Validators
|
|
@@ -185,7 +179,6 @@ flattenObjectToValueMap(obj: DataObject, basePath: string): ValueMap[]
|
|
|
185
179
|
validateMessage(message: ServerToClientMessage, options?: ValidationOptions): ValidationResult
|
|
186
180
|
validateMessages(messages: ServerToClientMessage[], options?: ValidationOptions): ValidationResult
|
|
187
181
|
validateV09Message(message: ServerToClientMessageV09, options?: ValidationOptions): ValidationResult
|
|
188
|
-
validateV08Message(message: ServerToClientMessageV08, options?: ValidationOptions): ValidationResult
|
|
189
182
|
```
|
|
190
183
|
|
|
191
184
|
### Utils
|
|
@@ -193,10 +186,10 @@ validateV08Message(message: ServerToClientMessageV08, options?: ValidationOption
|
|
|
193
186
|
```typescript
|
|
194
187
|
path(dataPath: string): { path: string } // Create data binding
|
|
195
188
|
isPathBinding(value): boolean // Check if value is a path binding
|
|
196
|
-
getLiteralValue<T>(value): T | undefined // Get literal value
|
|
189
|
+
getLiteralValue<T>(value): T | undefined // Get literal value
|
|
197
190
|
getPathValue(value): string | undefined // Get path from binding
|
|
198
191
|
generateId(prefix?: string): string // Generate unique component ID
|
|
199
|
-
resetIdCounter(): void // Reset ID counter
|
|
192
|
+
resetIdCounter(): void // Reset ID counter
|
|
200
193
|
uuid(): string // Generate UUID v4
|
|
201
194
|
deepMerge<T>(target: T, source: Partial<T>): T // Deep merge objects
|
|
202
195
|
```
|
|
@@ -206,98 +199,24 @@ deepMerge<T>(target: T, source: Partial<T>): T // Deep merge objects
|
|
|
206
199
|
```typescript
|
|
207
200
|
STANDARD_CATALOG_ID // Standard A2UI catalog URL
|
|
208
201
|
A2UI_EXTENSION_URI // A2UI v0.9 extension URI
|
|
209
|
-
A2UI_EXTENSION_URI_V08 // A2UI v0.8 extension URI
|
|
210
202
|
A2UI_MIME_TYPE // A2UI MIME type (application/json+a2ui)
|
|
211
203
|
```
|
|
212
204
|
|
|
213
|
-
|
|
205
|
+
## v0.9 Message Format
|
|
214
206
|
|
|
215
|
-
|
|
216
|
-
// Surface ID constants
|
|
217
|
-
SURFACE_IDS.CHAT // '@chat' - Chat content area
|
|
218
|
-
SURFACE_IDS.RECOMMENDATION // '@recommendation' - Agent recommendations
|
|
219
|
-
SURFACE_IDS.INPUT_FORM // '@input-form' - Input collection forms
|
|
220
|
-
SURFACE_IDS.ORCHESTRATION // '@orchestration' - Multi-agent orchestration
|
|
221
|
-
SURFACE_IDS.STATUS // '@status' - Status messages
|
|
222
|
-
SURFACE_IDS.RESULT // '@result' - Agent results
|
|
223
|
-
SURFACE_IDS.CONFIRM // '@confirm' - Confirmation dialogs
|
|
224
|
-
SURFACE_IDS.NOTIFICATION // '@notification' - Notifications
|
|
225
|
-
|
|
226
|
-
// Surface creation functions
|
|
227
|
-
createA2UISurface(rootId: string, components: ComponentInput[], surfaceId?: string): SurfaceResult
|
|
228
|
-
createA2UISurfaceWithData(rootId: string, components: ComponentInput[], dataModel: DataObject, surfaceId?: string): SurfaceResult
|
|
229
|
-
createDeleteSurface(surfaceId: string): A2UISurface
|
|
230
|
-
|
|
231
|
-
// Convenience functions
|
|
232
|
-
createChatSurface(rootId: string, components: ComponentInput[]): SurfaceResult
|
|
233
|
-
createRecommendationSurface(rootId: string, components: ComponentInput[]): SurfaceResult
|
|
234
|
-
createInputFormSurface(rootId: string, components: ComponentInput[]): SurfaceResult
|
|
235
|
-
createOrchestrationSurface(rootId: string, components: ComponentInput[]): SurfaceResult
|
|
236
|
-
createStatusSurface(rootId: string, components: ComponentInput[]): SurfaceResult
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
### v0.8 Component Builders (Stable)
|
|
240
|
-
|
|
241
|
-
These functions generate v0.8 format components compatible with tego-server:
|
|
207
|
+
A2UI v0.9 uses a cleaner, flatter format:
|
|
242
208
|
|
|
243
209
|
```typescript
|
|
244
|
-
//
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
createColumn(childIds: string[], options?: LayoutOptionsV08): ComponentDefinition
|
|
253
|
-
createRow(childIds: string[], options?: LayoutOptionsV08): ComponentDefinition
|
|
254
|
-
createCard(childIds: string[], options?: { id?: string; padding?: number }): ComponentDefinition
|
|
255
|
-
createList(childIds: string[], options?: { id?: string; direction?: string }): ComponentDefinition
|
|
256
|
-
createDivider(options?: { id?: string; axis?: string }): ComponentDefinition
|
|
257
|
-
|
|
258
|
-
// Interactive components
|
|
259
|
-
createButton(text: string, action: ActionDefinition, options?: ButtonOptionsV08): ButtonResult
|
|
260
|
-
createSimpleButton(text: string, action: ActionDefinition, options?: { id?: string }): ButtonResult
|
|
261
|
-
|
|
262
|
-
// Form components
|
|
263
|
-
createTextField(options: { label?: string; placeholder?: string; ... }): ComponentDefinition
|
|
264
|
-
createCheckbox(options: { label?: string; valuePath?: string; ... }): ComponentDefinition
|
|
265
|
-
createMultipleChoice(options: { options: Array<{value, label}>; ... }): ComponentDefinition
|
|
266
|
-
|
|
267
|
-
// Media components
|
|
268
|
-
createImage(url: string, options?: { alt?: string; width?: number; height?: number }): ComponentDefinition
|
|
269
|
-
createIcon(name: string, options?: IconOptionsV08): ComponentDefinition
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
## Protocol Versions
|
|
273
|
-
|
|
274
|
-
### v0.9 (Prompt-first)
|
|
275
|
-
Optimized for prompt-first embedding, more concise format:
|
|
276
|
-
- `createSurface` - Create a new surface with catalog ID
|
|
277
|
-
- `updateComponents` - Update components with flat component list
|
|
278
|
-
- `updateDataModel` - Update data model with JSON Patch-like operations
|
|
279
|
-
- `deleteSurface` - Delete surface
|
|
280
|
-
|
|
281
|
-
### v0.8 (Structured output)
|
|
282
|
-
Optimized for LLM structured output:
|
|
283
|
-
- `beginRendering` - Signal to begin rendering with root component
|
|
284
|
-
- `surfaceUpdate` - Update components
|
|
285
|
-
- `dataModelUpdate` - Update data model using ValueMap format
|
|
286
|
-
- `deleteSurface` - Delete surface
|
|
287
|
-
|
|
288
|
-
## Type Guards
|
|
289
|
-
|
|
290
|
-
```typescript
|
|
291
|
-
import { isV08Message, isV09Message } from '@zhama/a2ui-core';
|
|
292
|
-
|
|
293
|
-
if (isV09Message(message)) {
|
|
294
|
-
// Handle v0.9 message
|
|
295
|
-
} else if (isV08Message(message)) {
|
|
296
|
-
// Handle v0.8 message
|
|
297
|
-
}
|
|
210
|
+
// Component format
|
|
211
|
+
{ id: 'title', component: 'Text', text: 'Hello World', usageHint: 'h1' }
|
|
212
|
+
|
|
213
|
+
// Messages
|
|
214
|
+
{ createSurface: { surfaceId: '@chat', catalogId: '...' } }
|
|
215
|
+
{ updateComponents: { surfaceId: '@chat', components: [...] } }
|
|
216
|
+
{ updateDataModel: { surfaceId: '@chat', op: 'replace', value: { ... } } }
|
|
217
|
+
{ deleteSurface: { surfaceId: '@chat' } }
|
|
298
218
|
```
|
|
299
219
|
|
|
300
220
|
## License
|
|
301
221
|
|
|
302
222
|
MIT
|
|
303
|
-
|
package/dist/builders/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var l=0;function i(t="comp"){return `${t}_${Date.now()}_${l++}`}function I(){l=0;}function y(){return l}function p(t,e={}){let{id:n=i("text"),weight:o,usageHint:r,classes:a}=e;return {id:n,component:"Text",text:t,...o!==void 0&&{weight:o},...r&&{usageHint:r},...a&&a.length>0&&{classes:a}}}function S(t,e={}){let{id:n=i("image"),weight:o,fit:r,usageHint:a}=e;return {id:n,component:"Image",url:t,...o!==void 0&&{weight:o},...r&&{fit:r},...a&&{usageHint:a}}}function b(t,e={}){let{id:n=i("icon"),weight:o}=e;return {id:n,component:"Icon",name:t,...o!==void 0&&{weight:o}}}function T(t,e={}){let{id:n=i("video"),weight:o}=e;return {id:n,component:"Video",url:t,...o!==void 0&&{weight:o}}}function v(t,e={}){let{id:n=i("audio"),weight:o,description:r}=e;return {id:n,component:"AudioPlayer",url:t,...o!==void 0&&{weight:o},...r&&{description:r}}}function D(t,e={}){let{id:n=i("row"),weight:o,alignment:r,distribution:a}=e;return {id:n,component:"Row",children:t,...o!==void 0&&{weight:o},...r&&{alignment:r},...a&&{distribution:a}}}function P(t,e={}){let{id:n=i("column"),weight:o,alignment:r,distribution:a,classes:s}=e;return {id:n,component:"Column",children:t,...o!==void 0&&{weight:o},...r&&{alignment:r},...a&&{distribution:a},...s&&s.length>0&&{classes:s}}}function V(t,e={}){let{id:n=i("list"),weight:o,direction:r,alignment:a}=e;return {id:n,component:"List",children:t,...o!==void 0&&{weight:o},...r&&{direction:r},...a&&{alignment:a}}}function A(t,e={}){let{id:n=i("card"),weight:o,classes:r}=e;return {id:n,component:"Card",child:t,...o!==void 0&&{weight:o},...r&&r.length>0&&{classes:r}}}function w(t,e={}){let{id:n=i("tabs"),weight:o}=e;return {id:n,component:"Tabs",tabItems:t.map(r=>({title:r.title,child:r.childId})),...o!==void 0&&{weight:o}}}function U(t={}){let{id:e=i("divider"),weight:n,axis:o}=t;return {id:e,component:"Divider",...n!==void 0&&{weight:n},...o&&{axis:o}}}function E(t,e,n={}){let{id:o=i("modal"),weight:r}=n;return {id:o,component:"Modal",entryPointChild:t,contentChild:e,...r!==void 0&&{weight:r}}}function m(t,e,n={}){let{id:o=i("button"),weight:r,primary:a}=n;return {id:o,component:"Button",child:t,action:e,...r!==void 0&&{weight:r},...a!==void 0&&{primary:a}}}function j(t,e,n={}){let{id:o=i("checkbox"),weight:r}=n;return {id:o,component:"CheckBox",label:t,value:e,...r!==void 0&&{weight:r}}}function k(t,e,n={}){let{id:o=i("textfield"),weight:r,usageHint:a,validationRegexp:s}=n;return {id:o,component:"TextField",label:t,...e!==void 0&&{text:e},...r!==void 0&&{weight:r},...a&&{usageHint:a},...s&&{validationRegexp:s}}}function _(t,e={}){let{id:n=i("datetime"),weight:o,enableDate:r,enableTime:a,outputFormat:s,label:u}=e;return {id:n,component:"DateTimeInput",value:t,...o!==void 0&&{weight:o},...r!==void 0&&{enableDate:r},...a!==void 0&&{enableTime:a},...s&&{outputFormat:s},...u&&{label:u}}}function H(t,e,n,o={}){let{id:r=i("choice"),weight:a,label:s}=o;return {id:r,component:"ChoicePicker",options:t,value:e,usageHint:n,...a!==void 0&&{weight:a},...s&&{label:s}}}function B(t,e={}){let{id:n=i("slider"),weight:o,label:r,min:a,max:s}=e;return {id:n,component:"Slider",value:t,...o!==void 0&&{weight:o},...r&&{label:r},...a!==void 0&&{min:a},...s!==void 0&&{max:s}}}function N(t,e,n={}){let o=n.textId??i("btn_text"),r=p(t,{id:o}),a=m(o,e,n);return [r,a]}function R(t,e={}){return p(t,{...e,usageHint:"h1"})}function L(t,e={}){return p(t,{...e,usageHint:"h2"})}function F(t,e={}){return p(t,{...e,usageHint:"h3"})}function $(t,e={}){return p(t,{...e,usageHint:"h4"})}function G(t,e={}){return p(t,{...e,usageHint:"h5"})}function z(t,e={}){return p(t,{...e,usageHint:"caption"})}function J(t,e={}){return p(t,{...e,usageHint:"body"})}var d="https://a2ui.dev/specification/0.9/standard_catalog_definition.json";function f(t,e=d){return {createSurface:{surfaceId:t,catalogId:e}}}function C(t,e){return {updateComponents:{surfaceId:t,components:e}}}function x(t,e,n,o="replace"){return {updateDataModel:{surfaceId:t,...n&&{path:n},op:o,...o!=="remove"&&{value:e}}}}function W(t){return {deleteSurface:{surfaceId:t}}}function X(t){let{surfaceId:e,catalogId:n=d,components:o,dataModel:r}=t,a=[f(e,n),C(e,o)];return r&&a.push(x(e,r)),a}function Y(t){return t.map(e=>JSON.stringify(e)).join(`
|
|
2
2
|
`)}function K(t){return t.split(`
|
|
3
|
-
`).filter(e=>e.trim()).map(e=>JSON.parse(e))}var O={};function q(t,e=""){let n=[];for(let[o,
|
|
3
|
+
`).filter(e=>e.trim()).map(e=>JSON.parse(e))}var O={};function q(t,e=""){let n=[];for(let[o,r]of Object.entries(t)){let a=e?`${e}/${o}`:`/${o}`;n.push(c(a,r));}return n}function c(t,e){if(e==null)return {key:t,valueString:""};if(typeof e=="string")return {key:t,valueString:e};if(typeof e=="number")return {key:t,valueNumber:e};if(typeof e=="boolean")return {key:t,valueBoolean:e};if(Array.isArray(e))return {key:t,valueMap:e.map((n,o)=>c(String(o),n))};if(typeof e=="object"){let n=[];for(let[o,r]of Object.entries(e))n.push(c(o,r));return {key:t,valueMap:n}}return {key:t,valueString:String(e)}}function h(t,e={}){let n=t.replace(/\./g,"/");n.startsWith("/")||(n=`/${n}`);for(let[o,r]of Object.entries(e)){let a=new RegExp(`^/${o}(/|$)`);a.test(n)&&(n=n.replace(a,`/${r}$1`));}return n}function Q(t,e="",n=O){let o=[];for(let r of t){let a=r.path.startsWith("/")?r.path:`${e}/${r.path}`,s=h(a,n);if(r.value!==null&&typeof r.value=="object"&&!Array.isArray(r.value)){let u=g(r.value,s);o.push(...u);}else o.push(c(s,r.value));}return o}function g(t,e){let n=[];for(let[o,r]of Object.entries(t)){let a=`${e}/${o}`;if(r!==null&&typeof r=="object"&&!Array.isArray(r)){let s=g(r,a);n.push(...s);}else n.push(c(a,r));}return n}function M(t){let e={};for(let n of t){let o=n.key.startsWith("/")?n.key.slice(1):n.key;n.valueString!==void 0?e[o]=n.valueString:n.valueNumber!==void 0?e[o]=n.valueNumber:n.valueBoolean!==void 0?e[o]=n.valueBoolean:n.valueMap!==void 0&&(e[o]=M(n.valueMap));}return e}exports.DEFAULT_PATH_MAPPINGS=O;exports.audioPlayer=v;exports.body=J;exports.button=m;exports.caption=z;exports.card=A;exports.checkbox=j;exports.choicePicker=H;exports.column=P;exports.createSurface=f;exports.createV09Messages=X;exports.dateTimeInput=_;exports.deleteSurface=W;exports.divider=U;exports.flattenObjectToValueMap=g;exports.generateId=i;exports.getIdCounter=y;exports.h1=R;exports.h2=L;exports.h3=F;exports.h4=$;exports.h5=G;exports.icon=b;exports.image=S;exports.jsonlToMessages=K;exports.list=V;exports.messagesToJsonl=Y;exports.modal=E;exports.normalizePath=h;exports.objectToValueMap=q;exports.resetIdCounter=I;exports.row=D;exports.slider=B;exports.tabs=w;exports.text=p;exports.textButton=N;exports.textField=k;exports.updateComponents=C;exports.updateDataModel=x;exports.updatesToValueMap=Q;exports.valueMapToObject=M;exports.valueToValueMap=c;exports.video=T;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as StringOrPath, B as BooleanOrPath, a as StringArrayOrPath, N as NumberOrPath } from '../primitives-
|
|
2
|
-
import { TextComponent, ImageComponent, RowComponent, ListComponent, DividerComponent, TextFieldComponent, ComponentInstance, ChildrenProperty, Action, ChoicePickerComponent, CreateSurfaceMessage, UpdateComponentsMessage, UpdateDataModelMessage, DeleteSurfaceMessage, DataObject, ServerToClientMessageV09, DataValue
|
|
1
|
+
import { S as StringOrPath, B as BooleanOrPath, a as StringArrayOrPath, N as NumberOrPath } from '../primitives-DLbBDhLq.cjs';
|
|
2
|
+
import { TextComponent, ImageComponent, RowComponent, ListComponent, DividerComponent, TextFieldComponent, ComponentInstance, ChildrenProperty, Action, ChoicePickerComponent, CreateSurfaceMessage, UpdateComponentsMessage, UpdateDataModelMessage, DeleteSurfaceMessage, DataObject, ServerToClientMessageV09, DataValue } from '../types/index.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* ID Generator
|
|
@@ -42,6 +42,8 @@ interface ComponentOptions {
|
|
|
42
42
|
id?: string;
|
|
43
43
|
/** 在 Row/Column 中的权重 */
|
|
44
44
|
weight?: number;
|
|
45
|
+
/** 额外的 CSS 类名(A2UI 工具类或自定义类) */
|
|
46
|
+
classes?: string[];
|
|
45
47
|
}
|
|
46
48
|
/**
|
|
47
49
|
* Text 组件选项
|
|
@@ -438,9 +440,20 @@ declare function jsonlToMessages(jsonl: string): ServerToClientMessageV09[];
|
|
|
438
440
|
* Data Model Builder
|
|
439
441
|
*
|
|
440
442
|
* 提供 DataModel 相关的构建工具函数
|
|
441
|
-
*
|
|
443
|
+
* 包括 v0.9 JSON 对象格式和 v0.8 ValueMap 格式转换
|
|
442
444
|
*/
|
|
443
445
|
|
|
446
|
+
/**
|
|
447
|
+
* ValueMap 格式 - 用于 v0.8 兼容和内部数据转换
|
|
448
|
+
* @internal
|
|
449
|
+
*/
|
|
450
|
+
interface ValueMap {
|
|
451
|
+
key: string;
|
|
452
|
+
valueString?: string;
|
|
453
|
+
valueNumber?: number;
|
|
454
|
+
valueBoolean?: boolean;
|
|
455
|
+
valueMap?: ValueMap[];
|
|
456
|
+
}
|
|
444
457
|
/**
|
|
445
458
|
* 路径映射表类型
|
|
446
459
|
*/
|
package/dist/builders/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as StringOrPath, B as BooleanOrPath, a as StringArrayOrPath, N as NumberOrPath } from '../primitives-
|
|
2
|
-
import { TextComponent, ImageComponent, RowComponent, ListComponent, DividerComponent, TextFieldComponent, ComponentInstance, ChildrenProperty, Action, ChoicePickerComponent, CreateSurfaceMessage, UpdateComponentsMessage, UpdateDataModelMessage, DeleteSurfaceMessage, DataObject, ServerToClientMessageV09, DataValue
|
|
1
|
+
import { S as StringOrPath, B as BooleanOrPath, a as StringArrayOrPath, N as NumberOrPath } from '../primitives-DLbBDhLq.js';
|
|
2
|
+
import { TextComponent, ImageComponent, RowComponent, ListComponent, DividerComponent, TextFieldComponent, ComponentInstance, ChildrenProperty, Action, ChoicePickerComponent, CreateSurfaceMessage, UpdateComponentsMessage, UpdateDataModelMessage, DeleteSurfaceMessage, DataObject, ServerToClientMessageV09, DataValue } from '../types/index.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* ID Generator
|
|
@@ -42,6 +42,8 @@ interface ComponentOptions {
|
|
|
42
42
|
id?: string;
|
|
43
43
|
/** 在 Row/Column 中的权重 */
|
|
44
44
|
weight?: number;
|
|
45
|
+
/** 额外的 CSS 类名(A2UI 工具类或自定义类) */
|
|
46
|
+
classes?: string[];
|
|
45
47
|
}
|
|
46
48
|
/**
|
|
47
49
|
* Text 组件选项
|
|
@@ -438,9 +440,20 @@ declare function jsonlToMessages(jsonl: string): ServerToClientMessageV09[];
|
|
|
438
440
|
* Data Model Builder
|
|
439
441
|
*
|
|
440
442
|
* 提供 DataModel 相关的构建工具函数
|
|
441
|
-
*
|
|
443
|
+
* 包括 v0.9 JSON 对象格式和 v0.8 ValueMap 格式转换
|
|
442
444
|
*/
|
|
443
445
|
|
|
446
|
+
/**
|
|
447
|
+
* ValueMap 格式 - 用于 v0.8 兼容和内部数据转换
|
|
448
|
+
* @internal
|
|
449
|
+
*/
|
|
450
|
+
interface ValueMap {
|
|
451
|
+
key: string;
|
|
452
|
+
valueString?: string;
|
|
453
|
+
valueNumber?: number;
|
|
454
|
+
valueBoolean?: boolean;
|
|
455
|
+
valueMap?: ValueMap[];
|
|
456
|
+
}
|
|
444
457
|
/**
|
|
445
458
|
* 路径映射表类型
|
|
446
459
|
*/
|
package/dist/builders/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
1
|
+
var l=0;function i(t="comp"){return `${t}_${Date.now()}_${l++}`}function I(){l=0;}function y(){return l}function p(t,e={}){let{id:n=i("text"),weight:o,usageHint:r,classes:a}=e;return {id:n,component:"Text",text:t,...o!==void 0&&{weight:o},...r&&{usageHint:r},...a&&a.length>0&&{classes:a}}}function S(t,e={}){let{id:n=i("image"),weight:o,fit:r,usageHint:a}=e;return {id:n,component:"Image",url:t,...o!==void 0&&{weight:o},...r&&{fit:r},...a&&{usageHint:a}}}function b(t,e={}){let{id:n=i("icon"),weight:o}=e;return {id:n,component:"Icon",name:t,...o!==void 0&&{weight:o}}}function T(t,e={}){let{id:n=i("video"),weight:o}=e;return {id:n,component:"Video",url:t,...o!==void 0&&{weight:o}}}function v(t,e={}){let{id:n=i("audio"),weight:o,description:r}=e;return {id:n,component:"AudioPlayer",url:t,...o!==void 0&&{weight:o},...r&&{description:r}}}function D(t,e={}){let{id:n=i("row"),weight:o,alignment:r,distribution:a}=e;return {id:n,component:"Row",children:t,...o!==void 0&&{weight:o},...r&&{alignment:r},...a&&{distribution:a}}}function P(t,e={}){let{id:n=i("column"),weight:o,alignment:r,distribution:a,classes:s}=e;return {id:n,component:"Column",children:t,...o!==void 0&&{weight:o},...r&&{alignment:r},...a&&{distribution:a},...s&&s.length>0&&{classes:s}}}function V(t,e={}){let{id:n=i("list"),weight:o,direction:r,alignment:a}=e;return {id:n,component:"List",children:t,...o!==void 0&&{weight:o},...r&&{direction:r},...a&&{alignment:a}}}function A(t,e={}){let{id:n=i("card"),weight:o,classes:r}=e;return {id:n,component:"Card",child:t,...o!==void 0&&{weight:o},...r&&r.length>0&&{classes:r}}}function w(t,e={}){let{id:n=i("tabs"),weight:o}=e;return {id:n,component:"Tabs",tabItems:t.map(r=>({title:r.title,child:r.childId})),...o!==void 0&&{weight:o}}}function U(t={}){let{id:e=i("divider"),weight:n,axis:o}=t;return {id:e,component:"Divider",...n!==void 0&&{weight:n},...o&&{axis:o}}}function E(t,e,n={}){let{id:o=i("modal"),weight:r}=n;return {id:o,component:"Modal",entryPointChild:t,contentChild:e,...r!==void 0&&{weight:r}}}function m(t,e,n={}){let{id:o=i("button"),weight:r,primary:a}=n;return {id:o,component:"Button",child:t,action:e,...r!==void 0&&{weight:r},...a!==void 0&&{primary:a}}}function j(t,e,n={}){let{id:o=i("checkbox"),weight:r}=n;return {id:o,component:"CheckBox",label:t,value:e,...r!==void 0&&{weight:r}}}function k(t,e,n={}){let{id:o=i("textfield"),weight:r,usageHint:a,validationRegexp:s}=n;return {id:o,component:"TextField",label:t,...e!==void 0&&{text:e},...r!==void 0&&{weight:r},...a&&{usageHint:a},...s&&{validationRegexp:s}}}function _(t,e={}){let{id:n=i("datetime"),weight:o,enableDate:r,enableTime:a,outputFormat:s,label:u}=e;return {id:n,component:"DateTimeInput",value:t,...o!==void 0&&{weight:o},...r!==void 0&&{enableDate:r},...a!==void 0&&{enableTime:a},...s&&{outputFormat:s},...u&&{label:u}}}function H(t,e,n,o={}){let{id:r=i("choice"),weight:a,label:s}=o;return {id:r,component:"ChoicePicker",options:t,value:e,usageHint:n,...a!==void 0&&{weight:a},...s&&{label:s}}}function B(t,e={}){let{id:n=i("slider"),weight:o,label:r,min:a,max:s}=e;return {id:n,component:"Slider",value:t,...o!==void 0&&{weight:o},...r&&{label:r},...a!==void 0&&{min:a},...s!==void 0&&{max:s}}}function N(t,e,n={}){let o=n.textId??i("btn_text"),r=p(t,{id:o}),a=m(o,e,n);return [r,a]}function R(t,e={}){return p(t,{...e,usageHint:"h1"})}function L(t,e={}){return p(t,{...e,usageHint:"h2"})}function F(t,e={}){return p(t,{...e,usageHint:"h3"})}function $(t,e={}){return p(t,{...e,usageHint:"h4"})}function G(t,e={}){return p(t,{...e,usageHint:"h5"})}function z(t,e={}){return p(t,{...e,usageHint:"caption"})}function J(t,e={}){return p(t,{...e,usageHint:"body"})}var d="https://a2ui.dev/specification/0.9/standard_catalog_definition.json";function f(t,e=d){return {createSurface:{surfaceId:t,catalogId:e}}}function C(t,e){return {updateComponents:{surfaceId:t,components:e}}}function x(t,e,n,o="replace"){return {updateDataModel:{surfaceId:t,...n&&{path:n},op:o,...o!=="remove"&&{value:e}}}}function W(t){return {deleteSurface:{surfaceId:t}}}function X(t){let{surfaceId:e,catalogId:n=d,components:o,dataModel:r}=t,a=[f(e,n),C(e,o)];return r&&a.push(x(e,r)),a}function Y(t){return t.map(e=>JSON.stringify(e)).join(`
|
|
2
2
|
`)}function K(t){return t.split(`
|
|
3
|
-
`).filter(e=>e.trim()).map(e=>JSON.parse(e))}var O={};function q(t,e=""){let n=[];for(let[o,
|
|
3
|
+
`).filter(e=>e.trim()).map(e=>JSON.parse(e))}var O={};function q(t,e=""){let n=[];for(let[o,r]of Object.entries(t)){let a=e?`${e}/${o}`:`/${o}`;n.push(c(a,r));}return n}function c(t,e){if(e==null)return {key:t,valueString:""};if(typeof e=="string")return {key:t,valueString:e};if(typeof e=="number")return {key:t,valueNumber:e};if(typeof e=="boolean")return {key:t,valueBoolean:e};if(Array.isArray(e))return {key:t,valueMap:e.map((n,o)=>c(String(o),n))};if(typeof e=="object"){let n=[];for(let[o,r]of Object.entries(e))n.push(c(o,r));return {key:t,valueMap:n}}return {key:t,valueString:String(e)}}function h(t,e={}){let n=t.replace(/\./g,"/");n.startsWith("/")||(n=`/${n}`);for(let[o,r]of Object.entries(e)){let a=new RegExp(`^/${o}(/|$)`);a.test(n)&&(n=n.replace(a,`/${r}$1`));}return n}function Q(t,e="",n=O){let o=[];for(let r of t){let a=r.path.startsWith("/")?r.path:`${e}/${r.path}`,s=h(a,n);if(r.value!==null&&typeof r.value=="object"&&!Array.isArray(r.value)){let u=g(r.value,s);o.push(...u);}else o.push(c(s,r.value));}return o}function g(t,e){let n=[];for(let[o,r]of Object.entries(t)){let a=`${e}/${o}`;if(r!==null&&typeof r=="object"&&!Array.isArray(r)){let s=g(r,a);n.push(...s);}else n.push(c(a,r));}return n}function M(t){let e={};for(let n of t){let o=n.key.startsWith("/")?n.key.slice(1):n.key;n.valueString!==void 0?e[o]=n.valueString:n.valueNumber!==void 0?e[o]=n.valueNumber:n.valueBoolean!==void 0?e[o]=n.valueBoolean:n.valueMap!==void 0&&(e[o]=M(n.valueMap));}return e}export{O as DEFAULT_PATH_MAPPINGS,v as audioPlayer,J as body,m as button,z as caption,A as card,j as checkbox,H as choicePicker,P as column,f as createSurface,X as createV09Messages,_ as dateTimeInput,W as deleteSurface,U as divider,g as flattenObjectToValueMap,i as generateId,y as getIdCounter,R as h1,L as h2,F as h3,$ as h4,G as h5,b as icon,S as image,K as jsonlToMessages,V as list,Y as messagesToJsonl,E as modal,h as normalizePath,q as objectToValueMap,I as resetIdCounter,D as row,B as slider,w as tabs,p as text,N as textButton,k as textField,C as updateComponents,x as updateDataModel,Q as updatesToValueMap,M as valueMapToObject,c as valueToValueMap,T as video};
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';function
|
|
2
|
-
`)}function
|
|
3
|
-
`).filter(t=>t.trim()).map(t=>JSON.parse(t))}var
|
|
1
|
+
'use strict';function A(e){return "createSurface"in e||"updateComponents"in e||"updateDataModel"in e}var g="https://a2ui.dev/specification/0.9/standard_catalog_definition.json";var E="https://a2ui.dev/specification/0.9",N="application/json+a2ui";var O=0;function s(e="comp"){return `${e}_${Date.now()}_${O++}`}function R(){O=0;}function _(){return O}function c(e,t={}){let{id:o=s("text"),weight:a,usageHint:n,classes:r}=t;return {id:o,component:"Text",text:e,...a!==void 0&&{weight:a},...n&&{usageHint:n},...r&&r.length>0&&{classes:r}}}function U(e,t={}){let{id:o=s("image"),weight:a,fit:n,usageHint:r}=t;return {id:o,component:"Image",url:e,...a!==void 0&&{weight:a},...n&&{fit:n},...r&&{usageHint:r}}}function w(e,t={}){let{id:o=s("icon"),weight:a}=t;return {id:o,component:"Icon",name:e,...a!==void 0&&{weight:a}}}function k(e,t={}){let{id:o=s("video"),weight:a}=t;return {id:o,component:"Video",url:e,...a!==void 0&&{weight:a}}}function j(e,t={}){let{id:o=s("audio"),weight:a,description:n}=t;return {id:o,component:"AudioPlayer",url:e,...a!==void 0&&{weight:a},...n&&{description:n}}}function F(e,t={}){let{id:o=s("row"),weight:a,alignment:n,distribution:r}=t;return {id:o,component:"Row",children:e,...a!==void 0&&{weight:a},...n&&{alignment:n},...r&&{distribution:r}}}function B(e,t={}){let{id:o=s("column"),weight:a,alignment:n,distribution:r,classes:i}=t;return {id:o,component:"Column",children:e,...a!==void 0&&{weight:a},...n&&{alignment:n},...r&&{distribution:r},...i&&i.length>0&&{classes:i}}}function L(e,t={}){let{id:o=s("list"),weight:a,direction:n,alignment:r}=t;return {id:o,component:"List",children:e,...a!==void 0&&{weight:a},...n&&{direction:n},...r&&{alignment:r}}}function H(e,t={}){let{id:o=s("card"),weight:a,classes:n}=t;return {id:o,component:"Card",child:e,...a!==void 0&&{weight:a},...n&&n.length>0&&{classes:n}}}function $(e,t={}){let{id:o=s("tabs"),weight:a}=t;return {id:o,component:"Tabs",tabItems:e.map(n=>({title:n.title,child:n.childId})),...a!==void 0&&{weight:a}}}function G(e={}){let{id:t=s("divider"),weight:o,axis:a}=e;return {id:t,component:"Divider",...o!==void 0&&{weight:o},...a&&{axis:a}}}function W(e,t,o={}){let{id:a=s("modal"),weight:n}=o;return {id:a,component:"Modal",entryPointChild:e,contentChild:t,...n!==void 0&&{weight:n}}}function M(e,t,o={}){let{id:a=s("button"),weight:n,primary:r}=o;return {id:a,component:"Button",child:e,action:t,...n!==void 0&&{weight:n},...r!==void 0&&{primary:r}}}function q(e,t,o={}){let{id:a=s("checkbox"),weight:n}=o;return {id:a,component:"CheckBox",label:e,value:t,...n!==void 0&&{weight:n}}}function Y(e,t,o={}){let{id:a=s("textfield"),weight:n,usageHint:r,validationRegexp:i}=o;return {id:a,component:"TextField",label:e,...t!==void 0&&{text:t},...n!==void 0&&{weight:n},...r&&{usageHint:r},...i&&{validationRegexp:i}}}function z(e,t={}){let{id:o=s("datetime"),weight:a,enableDate:n,enableTime:r,outputFormat:i,label:p}=t;return {id:o,component:"DateTimeInput",value:e,...a!==void 0&&{weight:a},...n!==void 0&&{enableDate:n},...r!==void 0&&{enableTime:r},...i&&{outputFormat:i},...p&&{label:p}}}function J(e,t,o,a={}){let{id:n=s("choice"),weight:r,label:i}=a;return {id:n,component:"ChoicePicker",options:e,value:t,usageHint:o,...r!==void 0&&{weight:r},...i&&{label:i}}}function X(e,t={}){let{id:o=s("slider"),weight:a,label:n,min:r,max:i}=t;return {id:o,component:"Slider",value:e,...a!==void 0&&{weight:a},...n&&{label:n},...r!==void 0&&{min:r},...i!==void 0&&{max:i}}}function K(e,t,o={}){let a=o.textId??s("btn_text"),n=c(e,{id:a}),r=M(a,t,o);return [n,r]}function Q(e,t={}){return c(e,{...t,usageHint:"h1"})}function Z(e,t={}){return c(e,{...t,usageHint:"h2"})}function ee(e,t={}){return c(e,{...t,usageHint:"h3"})}function te(e,t={}){return c(e,{...t,usageHint:"h4"})}function ne(e,t={}){return c(e,{...t,usageHint:"h5"})}function oe(e,t={}){return c(e,{...t,usageHint:"caption"})}function ae(e,t={}){return c(e,{...t,usageHint:"body"})}function m(e,t=g){return {createSurface:{surfaceId:e,catalogId:t}}}function f(e,t){return {updateComponents:{surfaceId:e,components:t}}}function C(e,t,o,a="replace"){return {updateDataModel:{surfaceId:e,...o&&{path:o},op:a,...a!=="remove"&&{value:t}}}}function h(e){return {deleteSurface:{surfaceId:e}}}function re(e){let{surfaceId:t,catalogId:o=g,components:a,dataModel:n}=e,r=[m(t,o),f(t,a)];return n&&r.push(C(t,n)),r}function ie(e){return e.map(t=>JSON.stringify(t)).join(`
|
|
2
|
+
`)}function se(e){return e.split(`
|
|
3
|
+
`).filter(t=>t.trim()).map(t=>JSON.parse(t))}var y={};function pe(e,t=""){let o=[];for(let[a,n]of Object.entries(e)){let r=t?`${t}/${a}`:`/${a}`;o.push(d(r,n));}return o}function d(e,t){if(t==null)return {key:e,valueString:""};if(typeof t=="string")return {key:e,valueString:t};if(typeof t=="number")return {key:e,valueNumber:t};if(typeof t=="boolean")return {key:e,valueBoolean:t};if(Array.isArray(t))return {key:e,valueMap:t.map((o,a)=>d(String(a),o))};if(typeof t=="object"){let o=[];for(let[a,n]of Object.entries(t))o.push(d(a,n));return {key:e,valueMap:o}}return {key:e,valueString:String(t)}}function T(e,t={}){let o=e.replace(/\./g,"/");o.startsWith("/")||(o=`/${o}`);for(let[a,n]of Object.entries(t)){let r=new RegExp(`^/${a}(/|$)`);r.test(o)&&(o=o.replace(r,`/${n}$1`));}return o}function ce(e,t="",o=y){let a=[];for(let n of e){let r=n.path.startsWith("/")?n.path:`${t}/${n.path}`,i=T(r,o);if(n.value!==null&&typeof n.value=="object"&&!Array.isArray(n.value)){let p=S(n.value,i);a.push(...p);}else a.push(d(i,n.value));}return a}function S(e,t){let o=[];for(let[a,n]of Object.entries(e)){let r=`${t}/${a}`;if(n!==null&&typeof n=="object"&&!Array.isArray(n)){let i=S(n,r);o.push(...i);}else o.push(d(r,n));}return o}function D(e){let t={};for(let o of e){let a=o.key.startsWith("/")?o.key.slice(1):o.key;o.valueString!==void 0?t[a]=o.valueString:o.valueNumber!==void 0?t[a]=o.valueNumber:o.valueBoolean!==void 0?t[a]=o.valueBoolean:o.valueMap!==void 0&&(t[a]=D(o.valueMap));}return t}var Se=["Text","Image","Icon","Video","AudioPlayer","Row","Column","List","Card","Tabs","Divider","Modal","Button","CheckBox","TextField","DateTimeInput","ChoicePicker","Slider"];function V(e,t={}){let o=[],a=[];if("createSurface"in e){let{createSurface:n}=e;n.surfaceId||o.push({code:"MISSING_SURFACE_ID",message:"createSurface.surfaceId is required",path:"createSurface.surfaceId"}),n.catalogId||o.push({code:"MISSING_CATALOG_ID",message:"createSurface.catalogId is required",path:"createSurface.catalogId"});}else if("updateComponents"in e){let{updateComponents:n}=e;n.surfaceId||o.push({code:"MISSING_SURFACE_ID",message:"updateComponents.surfaceId is required",path:"updateComponents.surfaceId"}),!n.components||!Array.isArray(n.components)?o.push({code:"INVALID_COMPONENTS",message:"updateComponents.components must be an array",path:"updateComponents.components"}):Oe(n.components,o,a,t);}else if("updateDataModel"in e){let{updateDataModel:n}=e;n.surfaceId||o.push({code:"MISSING_SURFACE_ID",message:"updateDataModel.surfaceId is required",path:"updateDataModel.surfaceId"}),n.op&&!["add","replace","remove"].includes(n.op)&&o.push({code:"INVALID_OP",message:"updateDataModel.op must be one of: add, replace, remove",path:"updateDataModel.op"}),n.op==="remove"&&n.value!==void 0&&a.push({code:"UNNECESSARY_VALUE",message:"updateDataModel.value should not be provided for remove operation",path:"updateDataModel.value"}),n.op!=="remove"&&n.value===void 0&&n.op==="add"&&o.push({code:"MISSING_VALUE",message:"updateDataModel.value is required for add operation",path:"updateDataModel.value"});}else if("deleteSurface"in e){let{deleteSurface:n}=e;n.surfaceId||o.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else o.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: createSurface, updateComponents, updateDataModel, deleteSurface"});return {valid:o.length===0,errors:o,warnings:a}}function b(e,t={}){return V(e,t)}function ue(e,t={}){let o=[],a=[];for(let n=0;n<e.length;n++){let r=e[n];if(!r)continue;let i=b(r,t);for(let p of i.errors)o.push({...p,path:`messages[${n}].${p.path??""}`});for(let p of i.warnings)a.push({...p,path:`messages[${n}].${p.path??""}`});}return {valid:o.length===0,errors:o,warnings:a}}function Oe(e,t,o,a){let n=new Set,r=false;for(let i=0;i<e.length;i++){let p=e[i];if(!p)continue;let I=`updateComponents.components[${i}]`;p.id?(n.has(p.id)&&t.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${p.id}`,path:`${I}.id`}),n.add(p.id),p.id==="root"&&(r=true)):t.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${I}.id`}),p.component?a.strict&&!Se.includes(p.component)&&a.allowedComponents&&!a.allowedComponents.includes(p.component)&&o.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${p.component}`,path:`${I}.component`}):t.push({code:"MISSING_COMPONENT_TYPE",message:"Component type is required",path:`${I}.component`});}!r&&a.strict&&o.push({code:"MISSING_ROOT_COMPONENT",message:'No component with id "root" found',path:"updateComponents.components"});}function v(e){return typeof e=="object"&&e!==null&&"path"in e}function Me(e){if(!v(e))return e}function ye(e){if(v(e))return e.path}function Te(e){return {path:e}}function de(e,t){let o={...e};for(let a of Object.keys(t)){let n=t[a],r=o[a];n!==void 0&&typeof n=="object"&&n!==null&&!Array.isArray(n)&&typeof r=="object"&&r!==null&&!Array.isArray(r)?o[a]=de(r,n):n!==void 0&&(o[a]=n);}return o}function De(){return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return (e==="x"?t:t&3|8).toString(16)})}var u={CHAT:"@chat",RECOMMENDATION:"@recommendation",INPUT_FORM:"@input-form",ORCHESTRATION:"@orchestration",STATUS:"@status",RESULT:"@result",CONFIRM:"@confirm",NOTIFICATION:"@notification"},P=0;function x(e="surface"){return P++,`${e}-${Date.now()}-${P}`}function le(){P=0;}function l(e,t,o){let a=o??x();return t.find(i=>i.id===e)||console.warn(`[A2UI] Root component "${e}" not found in components list`),{messages:[m(a),f(a,t)],surfaceId:a}}function me(e,t,o,a){let n=a??x();return {messages:[m(n),f(n,t),C(n,o)],surfaceId:n}}function fe(e){return h(e)}function ge(e,t){return l(e,t,u.CHAT)}function Ce(e,t){return l(e,t,u.RECOMMENDATION)}function xe(e,t){return l(e,t,u.INPUT_FORM)}function Ie(e,t){return l(e,t,u.ORCHESTRATION)}function he(e,t){return l(e,t,u.STATUS)}exports.A2UI_EXTENSION_URI=E;exports.A2UI_MIME_TYPE=N;exports.DEFAULT_PATH_MAPPINGS=y;exports.STANDARD_CATALOG_ID=g;exports.SURFACE_IDS=u;exports.audioPlayer=j;exports.body=ae;exports.button=M;exports.caption=oe;exports.card=H;exports.checkbox=q;exports.choicePicker=J;exports.column=B;exports.createA2UISurface=l;exports.createA2UISurfaceWithData=me;exports.createChatSurface=ge;exports.createDeleteSurfaceMessage=fe;exports.createInputFormSurface=xe;exports.createOrchestrationSurface=Ie;exports.createRecommendationSurface=Ce;exports.createStatusSurface=he;exports.createSurface=m;exports.createV09Messages=re;exports.dateTimeInput=z;exports.deepMerge=de;exports.deleteSurface=h;exports.divider=G;exports.flattenObjectToValueMap=S;exports.generateId=s;exports.generateSurfaceId=x;exports.getIdCounter=_;exports.getLiteralValue=Me;exports.getPathValue=ye;exports.h1=Q;exports.h2=Z;exports.h3=ee;exports.h4=te;exports.h5=ne;exports.icon=w;exports.image=U;exports.isPathBinding=v;exports.isV09Message=A;exports.jsonlToMessages=se;exports.list=L;exports.messagesToJsonl=ie;exports.modal=W;exports.normalizePath=T;exports.objectToValueMap=pe;exports.path=Te;exports.resetIdCounter=R;exports.resetSurfaceIdCounter=le;exports.row=F;exports.slider=X;exports.tabs=$;exports.text=c;exports.textButton=K;exports.textField=Y;exports.updateComponents=f;exports.updateDataModel=C;exports.updatesToValueMap=ce;exports.uuid=De;exports.validateMessage=b;exports.validateMessages=ue;exports.validateV09Message=V;exports.valueMapToObject=D;exports.valueToValueMap=d;exports.video=k;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { B as BooleanOrPath,
|
|
2
|
-
export { A2UI_EXTENSION_URI,
|
|
1
|
+
export { B as BooleanOrPath, C as ContextValue, N as NumberOrPath, a as StringArrayOrPath, S as StringOrPath } from './primitives-DLbBDhLq.cjs';
|
|
2
|
+
export { A2UI_EXTENSION_URI, A2UI_MIME_TYPE, Action, AnyComponent, AudioPlayerComponent, ButtonComponent, CardComponent, CheckBoxComponent, ChildrenProperty, ChoicePickerComponent, ClientErrorMessage, ClientToServerMessage, ColumnComponent, ComponentCommon, ComponentInstance, ComponentType, CreateSurfaceMessage, DataArray, DataChangeEvent, DataObject, DataValue, DateTimeInputComponent, DeleteSurfaceMessage, DividerComponent, GenericError, IconComponent, ImageComponent, ListComponent, ModalComponent, RowComponent, STANDARD_CATALOG_ID, ServerToClientMessageV09 as ServerToClientMessage, ServerToClientMessageV09, SliderComponent, StandardIconName, TabsComponent, TextComponent, TextFieldComponent, Theme, UpdateComponentsMessage, UpdateDataModelMessage, UserActionEvent, ValidationFailedError, VideoComponent, isV09Message } from './types/index.cjs';
|
|
3
3
|
export { AudioPlayerOptions, ButtonOptions, CardOptions, CheckBoxOptions, ChoicePickerOptions, ComponentOptions, DEFAULT_PATH_MAPPINGS, DateTimeInputOptions, DividerOptions, IconOptions, ImageOptions, LayoutOptions, ListOptions, ModalOptions, PathMappings, SliderOptions, TabItem, TabsOptions, TextFieldOptions, TextOptions, UpdateDataItem, VideoOptions, audioPlayer, body, button, caption, card, checkbox, choicePicker, column, createSurface, createV09Messages, dateTimeInput, deleteSurface, divider, flattenObjectToValueMap, generateId, getIdCounter, h1, h2, h3, h4, h5, icon, image, jsonlToMessages, list, messagesToJsonl, modal, normalizePath, objectToValueMap, resetIdCounter, row, slider, tabs, text, textButton, textField, updateComponents, updateDataModel, updatesToValueMap, valueMapToObject, valueToValueMap, video } from './builders/index.cjs';
|
|
4
|
-
export { ValidationError, ValidationOptions, ValidationResult, ValidationWarning, validateMessage, validateMessages,
|
|
4
|
+
export { ValidationError, ValidationOptions, ValidationResult, ValidationWarning, validateMessage, validateMessages, validateV09Message } from './validators/index.cjs';
|
|
5
5
|
export { deepMerge, getLiteralValue, getPathValue, isPathBinding, path, uuid } from './utils/index.cjs';
|
|
6
6
|
export { SURFACE_IDS, SurfaceConfig, SurfaceIdType, SurfaceResult, createA2UISurface, createA2UISurfaceWithData, createChatSurface, createDeleteSurfaceMessage, createInputFormSurface, createOrchestrationSurface, createRecommendationSurface, createStatusSurface, generateSurfaceId, resetSurfaceIdCounter } from './surface/index.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { B as BooleanOrPath,
|
|
2
|
-
export { A2UI_EXTENSION_URI,
|
|
1
|
+
export { B as BooleanOrPath, C as ContextValue, N as NumberOrPath, a as StringArrayOrPath, S as StringOrPath } from './primitives-DLbBDhLq.js';
|
|
2
|
+
export { A2UI_EXTENSION_URI, A2UI_MIME_TYPE, Action, AnyComponent, AudioPlayerComponent, ButtonComponent, CardComponent, CheckBoxComponent, ChildrenProperty, ChoicePickerComponent, ClientErrorMessage, ClientToServerMessage, ColumnComponent, ComponentCommon, ComponentInstance, ComponentType, CreateSurfaceMessage, DataArray, DataChangeEvent, DataObject, DataValue, DateTimeInputComponent, DeleteSurfaceMessage, DividerComponent, GenericError, IconComponent, ImageComponent, ListComponent, ModalComponent, RowComponent, STANDARD_CATALOG_ID, ServerToClientMessageV09 as ServerToClientMessage, ServerToClientMessageV09, SliderComponent, StandardIconName, TabsComponent, TextComponent, TextFieldComponent, Theme, UpdateComponentsMessage, UpdateDataModelMessage, UserActionEvent, ValidationFailedError, VideoComponent, isV09Message } from './types/index.js';
|
|
3
3
|
export { AudioPlayerOptions, ButtonOptions, CardOptions, CheckBoxOptions, ChoicePickerOptions, ComponentOptions, DEFAULT_PATH_MAPPINGS, DateTimeInputOptions, DividerOptions, IconOptions, ImageOptions, LayoutOptions, ListOptions, ModalOptions, PathMappings, SliderOptions, TabItem, TabsOptions, TextFieldOptions, TextOptions, UpdateDataItem, VideoOptions, audioPlayer, body, button, caption, card, checkbox, choicePicker, column, createSurface, createV09Messages, dateTimeInput, deleteSurface, divider, flattenObjectToValueMap, generateId, getIdCounter, h1, h2, h3, h4, h5, icon, image, jsonlToMessages, list, messagesToJsonl, modal, normalizePath, objectToValueMap, resetIdCounter, row, slider, tabs, text, textButton, textField, updateComponents, updateDataModel, updatesToValueMap, valueMapToObject, valueToValueMap, video } from './builders/index.js';
|
|
4
|
-
export { ValidationError, ValidationOptions, ValidationResult, ValidationWarning, validateMessage, validateMessages,
|
|
4
|
+
export { ValidationError, ValidationOptions, ValidationResult, ValidationWarning, validateMessage, validateMessages, validateV09Message } from './validators/index.js';
|
|
5
5
|
export { deepMerge, getLiteralValue, getPathValue, isPathBinding, path, uuid } from './utils/index.js';
|
|
6
6
|
export { SURFACE_IDS, SurfaceConfig, SurfaceIdType, SurfaceResult, createA2UISurface, createA2UISurfaceWithData, createChatSurface, createDeleteSurfaceMessage, createInputFormSurface, createOrchestrationSurface, createRecommendationSurface, createStatusSurface, generateSurfaceId, resetSurfaceIdCounter } from './surface/index.js';
|