@zhama/a2ui-core 0.3.0 → 0.5.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
@@ -1,13 +1,17 @@
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
+
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.
4
7
 
5
8
  ## Overview
6
9
 
7
10
  A2UI (Agent to UI) is a JSON-based streaming UI protocol for dynamically rendering user interfaces. This library provides:
8
11
 
9
- - **Types**: Complete TypeScript type definitions for A2UI v0.8 and v0.9
12
+ - **Types**: Complete TypeScript type definitions for A2UI v0.9
10
13
  - **Builders**: Convenient functions to build messages and components
14
+ - **Surface**: Surface ID constants and creation utilities
11
15
  - **Validators**: Message validation utilities
12
16
  - **Utils**: Utility functions for path bindings and data manipulation
13
17
 
@@ -24,10 +28,13 @@ pnpm add @zhama/a2ui-core
24
28
  ```typescript
25
29
  import {
26
30
  // Builders
27
- text, column, button, card,
31
+ text, column, button, h1,
28
32
  createSurface, updateComponents, updateDataModel,
29
33
  createV09Messages,
30
34
 
35
+ // Surface
36
+ SURFACE_IDS, createA2UISurface,
37
+
31
38
  // Validators
32
39
  validateMessage,
33
40
 
@@ -36,17 +43,17 @@ import {
36
43
 
37
44
  // Types
38
45
  type ComponentInstance,
39
- type ServerToClientMessage,
46
+ type ServerToClientMessageV09,
40
47
  } from '@zhama/a2ui-core';
41
48
 
42
49
  // Create components
43
- const title = text('Hello World', { id: 'title', usageHint: 'h1' });
50
+ const title = h1('Hello World', { id: 'title' });
44
51
  const greeting = text({ path: '/user/name' }, { id: 'greeting' });
45
52
  const root = column(['title', 'greeting'], { id: 'root' });
46
53
 
47
54
  // Create messages
48
55
  const messages = createV09Messages({
49
- surfaceId: 'my-surface',
56
+ surfaceId: SURFACE_IDS.CHAT,
50
57
  components: [title, greeting, root],
51
58
  dataModel: { user: { name: 'John' } },
52
59
  });
@@ -62,7 +69,7 @@ You can import specific modules for tree-shaking:
62
69
 
63
70
  ```typescript
64
71
  // Types only
65
- import type { ComponentInstance, ServerToClientMessage } from '@zhama/a2ui-core/types';
72
+ import type { ComponentInstance, ServerToClientMessageV09 } from '@zhama/a2ui-core/types';
66
73
 
67
74
  // Builders only
68
75
  import { text, column, createV09Messages } from '@zhama/a2ui-core/builders';
@@ -72,35 +79,15 @@ import { validateMessage, validateMessages } from '@zhama/a2ui-core/validators';
72
79
 
73
80
  // Utils only
74
81
  import { path, uuid, deepMerge } from '@zhama/a2ui-core/utils';
82
+
83
+ // Surface utilities
84
+ import { SURFACE_IDS, createA2UISurface, createChatSurface } from '@zhama/a2ui-core/surface';
75
85
  ```
76
86
 
77
87
  ## API Reference
78
88
 
79
- ### Types
80
-
81
- #### Primitives
82
- - `StringOrPath` - String literal or data path binding
83
- - `NumberOrPath` - Number literal or data path binding
84
- - `BooleanOrPath` - Boolean literal or data path binding
85
- - `StringArrayOrPath` - String array literal or data path binding
86
-
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`
89
+ ### Component Builders
91
90
 
92
- #### Messages
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
100
-
101
- ### Builders
102
-
103
- #### Component Builders
104
91
  ```typescript
105
92
  // Content components
106
93
  text(content: StringOrPath, options?: TextOptions): ComponentInstance
@@ -137,36 +124,53 @@ caption(content: StringOrPath, options?: TextOptions): ComponentInstance
137
124
  body(content: StringOrPath, options?: TextOptions): ComponentInstance
138
125
  ```
139
126
 
140
- #### Message Builders
127
+ ### Message Builders
128
+
141
129
  ```typescript
142
- // v0.9
143
130
  createSurface(surfaceId: string, catalogId?: string): CreateSurfaceMessage
144
131
  updateComponents(surfaceId: string, components: ComponentInstance[]): UpdateComponentsMessage
145
132
  updateDataModel(surfaceId: string, value: unknown, path?: string, op?: 'add' | 'replace' | 'remove'): UpdateDataModelMessage
146
133
  deleteSurface(surfaceId: string): DeleteSurfaceMessage
147
134
  createV09Messages(options): ServerToClientMessageV09[]
148
135
 
149
- // v0.8
150
- beginRendering(rootId: string, surfaceId?: string, styles?: Theme): BeginRenderingMessage
151
- surfaceUpdate(components: ComponentInstanceV08[], surfaceId?: string): SurfaceUpdateMessage
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[]
156
-
157
136
  // Utilities
158
- messagesToJsonl(messages: ServerToClientMessage[]): string
159
- jsonlToMessages(jsonl: string): ServerToClientMessage[]
137
+ messagesToJsonl(messages: ServerToClientMessageV09[]): string
138
+ jsonlToMessages(jsonl: string): ServerToClientMessageV09[]
160
139
  ```
161
140
 
162
- #### Data Model Builders
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
165
+ ```
166
+
167
+ ### Data Model
168
+
163
169
  ```typescript
164
170
  objectToValueMap(obj: DataObject, prefix?: string): ValueMap[]
165
171
  valueToValueMap(key: string, value: DataValue): ValueMap
166
172
  valueMapToObject(valueMaps: ValueMap[]): DataObject
167
173
  normalizePath(path: string, pathMappings?: PathMappings): string
168
- updatesToValueMap(updates: UpdateDataItem[], basePath?: string): ValueMap[]
169
- flattenObjectToValueMap(obj: DataObject, basePath: string): ValueMap[]
170
174
  ```
171
175
 
172
176
  ### Validators
@@ -175,7 +179,6 @@ flattenObjectToValueMap(obj: DataObject, basePath: string): ValueMap[]
175
179
  validateMessage(message: ServerToClientMessage, options?: ValidationOptions): ValidationResult
176
180
  validateMessages(messages: ServerToClientMessage[], options?: ValidationOptions): ValidationResult
177
181
  validateV09Message(message: ServerToClientMessageV09, options?: ValidationOptions): ValidationResult
178
- validateV08Message(message: ServerToClientMessageV08, options?: ValidationOptions): ValidationResult
179
182
  ```
180
183
 
181
184
  ### Utils
@@ -183,10 +186,10 @@ validateV08Message(message: ServerToClientMessageV08, options?: ValidationOption
183
186
  ```typescript
184
187
  path(dataPath: string): { path: string } // Create data binding
185
188
  isPathBinding(value): boolean // Check if value is a path binding
186
- getLiteralValue<T>(value): T | undefined // Get literal value from StringOrPath/NumberOrPath/BooleanOrPath
189
+ getLiteralValue<T>(value): T | undefined // Get literal value
187
190
  getPathValue(value): string | undefined // Get path from binding
188
191
  generateId(prefix?: string): string // Generate unique component ID
189
- resetIdCounter(): void // Reset ID counter (for new scenes)
192
+ resetIdCounter(): void // Reset ID counter
190
193
  uuid(): string // Generate UUID v4
191
194
  deepMerge<T>(target: T, source: Partial<T>): T // Deep merge objects
192
195
  ```
@@ -196,39 +199,24 @@ deepMerge<T>(target: T, source: Partial<T>): T // Deep merge objects
196
199
  ```typescript
197
200
  STANDARD_CATALOG_ID // Standard A2UI catalog URL
198
201
  A2UI_EXTENSION_URI // A2UI v0.9 extension URI
199
- A2UI_EXTENSION_URI_V08 // A2UI v0.8 extension URI
200
202
  A2UI_MIME_TYPE // A2UI MIME type (application/json+a2ui)
201
203
  ```
202
204
 
203
- ## Protocol Versions
205
+ ## v0.9 Message Format
204
206
 
205
- ### v0.9 (Prompt-first)
206
- Optimized for prompt-first embedding, more concise format:
207
- - `createSurface` - Create a new surface with catalog ID
208
- - `updateComponents` - Update components with flat component list
209
- - `updateDataModel` - Update data model with JSON Patch-like operations
210
- - `deleteSurface` - Delete surface
211
-
212
- ### v0.8 (Structured output)
213
- Optimized for LLM structured output:
214
- - `beginRendering` - Signal to begin rendering with root component
215
- - `surfaceUpdate` - Update components
216
- - `dataModelUpdate` - Update data model using ValueMap format
217
- - `deleteSurface` - Delete surface
218
-
219
- ## Type Guards
207
+ A2UI v0.9 uses a cleaner, flatter format:
220
208
 
221
209
  ```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
- }
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' } }
229
218
  ```
230
219
 
231
220
  ## License
232
221
 
233
222
  MIT
234
-
@@ -1,3 +1,3 @@
1
- 'use strict';var g=0;function i(t="comp"){return `${t}_${Date.now()}_${g++}`}function V(){g=0;}function D(){return g}function p(t,e={}){let{id:n=i("text"),weight:o,usageHint:a}=e;return {id:n,component:"Text",text:t,...o!==void 0&&{weight:o},...a&&{usageHint:a}}}function v(t,e={}){let{id:n=i("image"),weight:o,fit:a,usageHint:r}=e;return {id:n,component:"Image",url:t,...o!==void 0&&{weight:o},...a&&{fit:a},...r&&{usageHint:r}}}function P(t,e={}){let{id:n=i("icon"),weight:o}=e;return {id:n,component:"Icon",name:t,...o!==void 0&&{weight:o}}}function A(t,e={}){let{id:n=i("video"),weight:o}=e;return {id:n,component:"Video",url:t,...o!==void 0&&{weight:o}}}function U(t,e={}){let{id:n=i("audio"),weight:o,description:a}=e;return {id:n,component:"AudioPlayer",url:t,...o!==void 0&&{weight:o},...a&&{description:a}}}function w(t,e={}){let{id:n=i("row"),weight:o,alignment:a,distribution:r}=e;return {id:n,component:"Row",children:t,...o!==void 0&&{weight:o},...a&&{alignment:a},...r&&{distribution:r}}}function j(t,e={}){let{id:n=i("column"),weight:o,alignment:a,distribution:r}=e;return {id:n,component:"Column",children:t,...o!==void 0&&{weight:o},...a&&{alignment:a},...r&&{distribution:r}}}function R(t,e={}){let{id:n=i("list"),weight:o,direction:a,alignment:r}=e;return {id:n,component:"List",children:t,...o!==void 0&&{weight:o},...a&&{direction:a},...r&&{alignment:r}}}function _(t,e={}){let{id:n=i("card"),weight:o}=e;return {id:n,component:"Card",child:t,...o!==void 0&&{weight:o}}}function k(t,e={}){let{id:n=i("tabs"),weight:o}=e;return {id:n,component:"Tabs",tabItems:t.map(a=>({title:a.title,child:a.childId})),...o!==void 0&&{weight:o}}}function B(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 H(t,e,n={}){let{id:o=i("modal"),weight:a}=n;return {id:o,component:"Modal",entryPointChild:t,contentChild:e,...a!==void 0&&{weight:a}}}function f(t,e,n={}){let{id:o=i("button"),weight:a,primary:r}=n;return {id:o,component:"Button",child:t,action:e,...a!==void 0&&{weight:a},...r!==void 0&&{primary:r}}}function N(t,e,n={}){let{id:o=i("checkbox"),weight:a}=n;return {id:o,component:"CheckBox",label:t,value:e,...a!==void 0&&{weight:a}}}function E(t,e,n={}){let{id:o=i("textfield"),weight:a,usageHint:r,validationRegexp:s}=n;return {id:o,component:"TextField",label:t,...e!==void 0&&{text:e},...a!==void 0&&{weight:a},...r&&{usageHint:r},...s&&{validationRegexp:s}}}function L(t,e={}){let{id:n=i("datetime"),weight:o,enableDate:a,enableTime:r,outputFormat:s,label:c}=e;return {id:n,component:"DateTimeInput",value:t,...o!==void 0&&{weight:o},...a!==void 0&&{enableDate:a},...r!==void 0&&{enableTime:r},...s&&{outputFormat:s},...c&&{label:c}}}function $(t,e,n,o={}){let{id:a=i("choice"),weight:r,label:s}=o;return {id:a,component:"ChoicePicker",options:t,value:e,usageHint:n,...r!==void 0&&{weight:r},...s&&{label:s}}}function F(t,e={}){let{id:n=i("slider"),weight:o,label:a,min:r,max:s}=e;return {id:n,component:"Slider",value:t,...o!==void 0&&{weight:o},...a&&{label:a},...r!==void 0&&{min:r},...s!==void 0&&{max:s}}}function G(t,e,n={}){let o=n.textId??i("btn_text"),a=p(t,{id:o}),r=f(o,e,n);return [a,r]}function z(t,e={}){return p(t,{...e,usageHint:"h1"})}function J(t,e={}){return p(t,{...e,usageHint:"h2"})}function X(t,e={}){return p(t,{...e,usageHint:"h3"})}function W(t,e={}){return p(t,{...e,usageHint:"h4"})}function Y(t,e={}){return p(t,{...e,usageHint:"h5"})}function K(t,e={}){return p(t,{...e,usageHint:"caption"})}function q(t,e={}){return p(t,{...e,usageHint:"body"})}var d="https://a2ui.dev/specification/0.9/standard_catalog_definition.json";var C={};function l(t,e=""){let n=[];for(let[o,a]of Object.entries(t)){let r=e?`${e}/${o}`:`/${o}`;n.push(u(r,a));}return n}function u(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)=>u(String(o),n))};if(typeof e=="object"){let n=[];for(let[o,a]of Object.entries(e))n.push(u(o,a));return {key:t,valueMap:n}}return {key:t,valueString:String(e)}}function x(t,e={}){let n=t.replace(/\./g,"/");n.startsWith("/")||(n=`/${n}`);for(let[o,a]of Object.entries(e)){let r=new RegExp(`^/${o}(/|$)`);r.test(n)&&(n=n.replace(r,`/${a}$1`));}return n}function Q(t,e="",n=C){let o=[];for(let a of t){let r=a.path.startsWith("/")?a.path:`${e}/${a.path}`,s=x(r,n);if(a.value!==null&&typeof a.value=="object"&&!Array.isArray(a.value)){let c=m(a.value,s);o.push(...c);}else o.push(u(s,a.value));}return o}function m(t,e){let n=[];for(let[o,a]of Object.entries(t)){let r=`${e}/${o}`;if(a!==null&&typeof a=="object"&&!Array.isArray(a)){let s=m(a,r);n.push(...s);}else n.push(u(r,a));}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}function O(t,e=d){return {createSurface:{surfaceId:t,catalogId:e}}}function h(t,e){return {updateComponents:{surfaceId:t,components:e}}}function I(t,e,n,o="replace"){return {updateDataModel:{surfaceId:t,...n&&{path:n},op:o,...o!=="remove"&&{value:e}}}}function Z(t){return {deleteSurface:{surfaceId:t}}}function ee(t){let{surfaceId:e,catalogId:n=d,components:o,dataModel:a}=t,r=[O(e,n),h(e,o)];return a&&r.push(I(e,a)),r}function S(t,e="@default",n){return {beginRendering:{surfaceId:e,root:t,...n&&{styles:n}}}}function T(t,e="@default"){return {surfaceUpdate:{surfaceId:e,components:t}}}function y(t,e="@default",n){return {dataModelUpdate:{surfaceId:e,contents:t,...n&&{path:n}}}}function b(t,e="@default"){return y(l(t),e)}function te(t,e,n="@default"){return {dataModelUpdate:{surfaceId:n,path:t,contents:[u("",e)]}}}function ne(t){return {deleteSurface:{surfaceId:t}}}function oe(t){let{rootId:e,components:n,dataModel:o,surfaceId:a="@default",styles:r}=t,s=[T(n,a)];return o&&s.push(b(o,a)),s.push(S(e,a,r)),s}function ae(t){return t.map(e=>JSON.stringify(e)).join(`
2
- `)}function re(t){return t.split(`
3
- `).filter(e=>e.trim()).map(e=>JSON.parse(e))}exports.DEFAULT_PATH_MAPPINGS=C;exports.audioPlayer=U;exports.beginRendering=S;exports.body=q;exports.button=f;exports.caption=K;exports.card=_;exports.checkbox=N;exports.choicePicker=$;exports.column=j;exports.createSurface=O;exports.createV08Messages=oe;exports.createV09Messages=ee;exports.dataModelInit=b;exports.dataModelUpdate=y;exports.dateTimeInput=L;exports.deleteSurface=Z;exports.deleteSurfaceV08=ne;exports.divider=B;exports.flattenObjectToValueMap=m;exports.generateId=i;exports.getIdCounter=D;exports.h1=z;exports.h2=J;exports.h3=X;exports.h4=W;exports.h5=Y;exports.icon=P;exports.image=v;exports.jsonlToMessages=re;exports.list=R;exports.messagesToJsonl=ae;exports.modal=H;exports.normalizePath=x;exports.objectToValueMap=l;exports.pathUpdate=te;exports.resetIdCounter=V;exports.row=w;exports.slider=F;exports.surfaceUpdate=T;exports.tabs=k;exports.text=p;exports.textButton=G;exports.textField=E;exports.updateComponents=h;exports.updateDataModel=I;exports.updatesToValueMap=Q;exports.valueMapToObject=M;exports.valueToValueMap=u;exports.video=A;
1
+ 'use strict';var m=0;function i(t="comp"){return `${t}_${Date.now()}_${m++}`}function I(){m=0;}function y(){return m}function p(t,e={}){let{id:n=i("text"),weight:o,usageHint:r}=e;return {id:n,component:"Text",text:t,...o!==void 0&&{weight:o},...r&&{usageHint:r}}}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}=e;return {id:n,component:"Column",children:t,...o!==void 0&&{weight:o},...r&&{alignment:r},...a&&{distribution:a}}}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}=e;return {id:n,component:"Card",child:t,...o!==void 0&&{weight:o}}}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 l(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=l(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
+ `)}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,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=l;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-nmkVz-tB.cjs';
2
- import { TextComponent, ImageComponent, RowComponent, ListComponent, DividerComponent, TextFieldComponent, ComponentInstance, ChildrenProperty, Action, ChoicePickerComponent, CreateSurfaceMessage, UpdateComponentsMessage, UpdateDataModelMessage, DeleteSurfaceMessage, DataObject, ServerToClientMessageV09, BeginRenderingMessage, ComponentInstanceV08, SurfaceUpdateMessage, ValueMap, DataModelUpdateMessage, DataValue, ServerToClientMessageV08 } from '../types/index.cjs';
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
@@ -322,35 +322,66 @@ declare function body(content: StringOrPath, options?: Omit<TextOptions, 'usageH
322
322
  /**
323
323
  * Message Builder
324
324
  *
325
- * 提供 A2UI 协议消息的构建工具函数
326
- * 支持 v0.8 和 v0.9 两种消息格式
325
+ * 提供 A2UI v0.9 协议消息的构建工具函数
326
+ *
327
+ * v0.9 消息类型:
328
+ * - createSurface: 创建新的 UI Surface
329
+ * - updateComponents: 更新组件
330
+ * - updateDataModel: 更新数据模型 (JSON Patch 风格)
331
+ * - deleteSurface: 删除 Surface
332
+ *
333
+ * 参考: https://a2ui.org/
327
334
  */
328
335
 
329
336
  /**
330
- * 创建 CreateSurface 消息 (v0.9)
337
+ * 创建 CreateSurface 消息
331
338
  *
332
339
  * @param surfaceId - Surface ID
333
340
  * @param catalogId - Catalog ID(默认为标准目录)
341
+ *
342
+ * @example
343
+ * ```typescript
344
+ * const msg = createSurface('my-surface');
345
+ * // { createSurface: { surfaceId: 'my-surface', catalogId: '...' } }
346
+ * ```
334
347
  */
335
348
  declare function createSurface(surfaceId: string, catalogId?: string): CreateSurfaceMessage;
336
349
  /**
337
- * 创建 UpdateComponents 消息 (v0.9)
350
+ * 创建 UpdateComponents 消息
338
351
  *
339
352
  * @param surfaceId - Surface ID
340
353
  * @param components - 组件列表
354
+ *
355
+ * @example
356
+ * ```typescript
357
+ * const title = text('Hello', { id: 'title' });
358
+ * const msg = updateComponents('my-surface', [title]);
359
+ * ```
341
360
  */
342
361
  declare function updateComponents(surfaceId: string, components: ComponentInstance[]): UpdateComponentsMessage;
343
362
  /**
344
- * 创建 UpdateDataModel 消息 (v0.9)
363
+ * 创建 UpdateDataModel 消息
345
364
  *
346
365
  * @param surfaceId - Surface ID
347
366
  * @param value - 数据值
348
- * @param path - 数据路径(可选)
367
+ * @param path - 数据路径(可选,默认为根路径)
349
368
  * @param op - 操作类型(默认为 replace)
369
+ *
370
+ * @example
371
+ * ```typescript
372
+ * // 替换整个数据模型
373
+ * updateDataModel('my-surface', { user: { name: 'John' } });
374
+ *
375
+ * // 更新特定路径
376
+ * updateDataModel('my-surface', 'Jane', '/user/name', 'replace');
377
+ *
378
+ * // 添加数据
379
+ * updateDataModel('my-surface', 'new-item', '/items/-', 'add');
380
+ * ```
350
381
  */
351
382
  declare function updateDataModel(surfaceId: string, value: unknown, path?: string, op?: 'add' | 'replace' | 'remove'): UpdateDataModelMessage;
352
383
  /**
353
- * 创建 DeleteSurface 消息 (v0.9)
384
+ * 创建 DeleteSurface 消息
354
385
  *
355
386
  * @param surfaceId - 要删除的 Surface ID
356
387
  */
@@ -360,6 +391,21 @@ declare function deleteSurface(surfaceId: string): DeleteSurfaceMessage;
360
391
  *
361
392
  * @param options - 选项
362
393
  * @returns 消息数组(可直接作为 JSONL 流发送)
394
+ *
395
+ * @example
396
+ * ```typescript
397
+ * const title = h1('Welcome', { id: 'title' });
398
+ * const root = column(['title'], { id: 'root' });
399
+ *
400
+ * const messages = createV09Messages({
401
+ * surfaceId: '@chat',
402
+ * components: [title, root],
403
+ * dataModel: { user: { name: 'John' } }
404
+ * });
405
+ *
406
+ * // 发送为 JSONL 流
407
+ * const jsonl = messagesToJsonl(messages);
408
+ * ```
363
409
  */
364
410
  declare function createV09Messages(options: {
365
411
  surfaceId: string;
@@ -367,89 +413,45 @@ declare function createV09Messages(options: {
367
413
  components: ComponentInstance[];
368
414
  dataModel?: DataObject;
369
415
  }): ServerToClientMessageV09[];
370
- /**
371
- * 创建 BeginRendering 消息 (v0.8)
372
- *
373
- * @param rootId - 根组件 ID
374
- * @param surfaceId - Surface ID
375
- * @param styles - 样式配置
376
- */
377
- declare function beginRendering(rootId: string, surfaceId?: string, styles?: Record<string, string>): BeginRenderingMessage;
378
- /**
379
- * 创建 SurfaceUpdate 消息 (v0.8)
380
- *
381
- * @param components - 组件定义数组
382
- * @param surfaceId - Surface ID
383
- */
384
- declare function surfaceUpdate(components: ComponentInstanceV08[], surfaceId?: string): SurfaceUpdateMessage;
385
- /**
386
- * 创建 DataModelUpdate 消息 (v0.8)
387
- *
388
- * @param contents - ValueMap 数组
389
- * @param surfaceId - Surface ID
390
- * @param path - 数据路径(可选)
391
- */
392
- declare function dataModelUpdate(contents: ValueMap[], surfaceId?: string, path?: string): DataModelUpdateMessage;
393
- /**
394
- * 创建 DataModel 初始化消息 (v0.8)
395
- *
396
- * @param data - 初始数据对象
397
- * @param surfaceId - Surface ID
398
- */
399
- declare function dataModelInit(data: DataObject, surfaceId?: string): DataModelUpdateMessage;
400
- /**
401
- * 创建路径更新消息 (v0.8)
402
- *
403
- * @param path - 数据路径
404
- * @param value - 新值
405
- * @param surfaceId - Surface ID
406
- */
407
- declare function pathUpdate(path: string, value: DataValue, surfaceId?: string): DataModelUpdateMessage;
408
- /**
409
- * 创建 DeleteSurface 消息 (v0.8)
410
- *
411
- * @param surfaceId - 要删除的 Surface ID
412
- */
413
- declare function deleteSurfaceV08(surfaceId: string): {
414
- deleteSurface: {
415
- surfaceId: string;
416
- };
417
- };
418
- /**
419
- * 创建完整的 v0.8 消息数组
420
- *
421
- * @param options - 选项
422
- * @returns 消息数组
423
- */
424
- declare function createV08Messages(options: {
425
- rootId: string;
426
- components: ComponentInstanceV08[];
427
- dataModel?: DataObject;
428
- surfaceId?: string;
429
- styles?: Record<string, string>;
430
- }): ServerToClientMessageV08[];
431
416
  /**
432
417
  * 将消息数组转换为 JSONL 格式字符串
433
418
  *
434
419
  * @param messages - 消息数组
435
420
  * @returns JSONL 格式字符串
421
+ *
422
+ * @example
423
+ * ```typescript
424
+ * const jsonl = messagesToJsonl(messages);
425
+ * // 每行一个 JSON 对象
426
+ * ```
436
427
  */
437
- declare function messagesToJsonl(messages: Array<ServerToClientMessageV08 | ServerToClientMessageV09>): string;
428
+ declare function messagesToJsonl(messages: ServerToClientMessageV09[]): string;
438
429
  /**
439
430
  * 从 JSONL 格式字符串解析消息数组
440
431
  *
441
432
  * @param jsonl - JSONL 格式字符串
442
433
  * @returns 消息数组
443
434
  */
444
- declare function jsonlToMessages(jsonl: string): Array<ServerToClientMessageV08 | ServerToClientMessageV09>;
435
+ declare function jsonlToMessages(jsonl: string): ServerToClientMessageV09[];
445
436
 
446
437
  /**
447
438
  * Data Model Builder
448
439
  *
449
440
  * 提供 DataModel 相关的构建工具函数
450
- * 符合 A2UI 协议的 ValueMap 格式
441
+ * 包括 v0.9 JSON 对象格式和 v0.8 ValueMap 格式转换
451
442
  */
452
443
 
444
+ /**
445
+ * ValueMap 格式 - 用于 v0.8 兼容和内部数据转换
446
+ * @internal
447
+ */
448
+ interface ValueMap {
449
+ key: string;
450
+ valueString?: string;
451
+ valueNumber?: number;
452
+ valueBoolean?: boolean;
453
+ valueMap?: ValueMap[];
454
+ }
453
455
  /**
454
456
  * 路径映射表类型
455
457
  */
@@ -530,4 +532,4 @@ declare function flattenObjectToValueMap(obj: DataObject, basePath: string): Val
530
532
  */
531
533
  declare function valueMapToObject(valueMaps: ValueMap[]): DataObject;
532
534
 
533
- export { type AudioPlayerOptions, type ButtonOptions, type CardOptions, type CheckBoxOptions, type ChoicePickerOptions, type ComponentOptions, DEFAULT_PATH_MAPPINGS, type DateTimeInputOptions, type DividerOptions, type IconOptions, type ImageOptions, type LayoutOptions, type ListOptions, type ModalOptions, type PathMappings, type SliderOptions, type TabItem, type TabsOptions, type TextFieldOptions, type TextOptions, type UpdateDataItem, type VideoOptions, audioPlayer, beginRendering, body, button, caption, card, checkbox, choicePicker, column, createSurface, createV08Messages, createV09Messages, dataModelInit, dataModelUpdate, dateTimeInput, deleteSurface, deleteSurfaceV08, divider, flattenObjectToValueMap, generateId, getIdCounter, h1, h2, h3, h4, h5, icon, image, jsonlToMessages, list, messagesToJsonl, modal, normalizePath, objectToValueMap, pathUpdate, resetIdCounter, row, slider, surfaceUpdate, tabs, text, textButton, textField, updateComponents, updateDataModel, updatesToValueMap, valueMapToObject, valueToValueMap, video };
535
+ export { type AudioPlayerOptions, type ButtonOptions, type CardOptions, type CheckBoxOptions, type ChoicePickerOptions, type ComponentOptions, DEFAULT_PATH_MAPPINGS, type DateTimeInputOptions, type DividerOptions, type IconOptions, type ImageOptions, type LayoutOptions, type ListOptions, type ModalOptions, type PathMappings, type SliderOptions, type TabItem, type TabsOptions, type TextFieldOptions, type TextOptions, type UpdateDataItem, type 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 };