@zhama/a2ui-core 0.3.0 → 0.4.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 +71 -2
- package/dist/builders/index.cjs +3 -3
- package/dist/builders/index.d.cts +63 -72
- package/dist/builders/index.d.ts +63 -72
- package/dist/builders/index.js +3 -3
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -3
- package/dist/surface/index.cjs +2 -0
- package/dist/surface/index.d.cts +165 -0
- package/dist/surface/index.d.ts +165 -0
- package/dist/surface/index.js +2 -0
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
A2UI Protocol Core Library - Framework-agnostic TypeScript types and builders for A2UI protocol.
|
|
4
4
|
|
|
5
|
+
> **Note**: A2UI v0.8 is the current stable version. v0.9 is still in draft status.
|
|
6
|
+
> See [a2ui.org](https://a2ui.org/) for the official specification.
|
|
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
12
|
- **Types**: Complete TypeScript type definitions for A2UI v0.8 and v0.9
|
|
10
|
-
- **Builders**: Convenient functions to build messages and components
|
|
13
|
+
- **Builders**: Convenient functions to build messages and components (both v0.8 and v0.9 formats)
|
|
11
14
|
- **Validators**: Message validation utilities
|
|
12
15
|
- **Utils**: Utility functions for path bindings and data manipulation
|
|
16
|
+
- **Surface**: Surface ID constants and creation utilities
|
|
13
17
|
|
|
14
18
|
## Installation
|
|
15
19
|
|
|
@@ -64,14 +68,20 @@ You can import specific modules for tree-shaking:
|
|
|
64
68
|
// Types only
|
|
65
69
|
import type { ComponentInstance, ServerToClientMessage } from '@zhama/a2ui-core/types';
|
|
66
70
|
|
|
67
|
-
// Builders only
|
|
71
|
+
// Builders only (v0.9 format)
|
|
68
72
|
import { text, column, createV09Messages } from '@zhama/a2ui-core/builders';
|
|
69
73
|
|
|
74
|
+
// Builders only (v0.8 format - compatible with tego-server)
|
|
75
|
+
import { createText, createColumn, createButton } from '@zhama/a2ui-core/builders';
|
|
76
|
+
|
|
70
77
|
// Validators only
|
|
71
78
|
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
|
|
@@ -200,6 +210,65 @@ A2UI_EXTENSION_URI_V08 // A2UI v0.8 extension URI
|
|
|
200
210
|
A2UI_MIME_TYPE // A2UI MIME type (application/json+a2ui)
|
|
201
211
|
```
|
|
202
212
|
|
|
213
|
+
### Surface Module
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
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:
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
// Text components
|
|
245
|
+
createText(text: string, options?: TextOptionsV08): ComponentDefinition
|
|
246
|
+
createBoundText(path: string, options?: TextOptionsV08): ComponentDefinition
|
|
247
|
+
createH1(text: string, options?: { id?: string }): ComponentDefinition
|
|
248
|
+
createH2(text: string, options?: { id?: string }): ComponentDefinition
|
|
249
|
+
createH3(text: string, options?: { id?: string }): ComponentDefinition
|
|
250
|
+
|
|
251
|
+
// Layout components
|
|
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
|
+
|
|
203
272
|
## Protocol Versions
|
|
204
273
|
|
|
205
274
|
### v0.9 (Prompt-first)
|
package/dist/builders/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
`)}function
|
|
3
|
-
`).filter(e=>e.trim()).map(e=>JSON.parse(e))}
|
|
1
|
+
'use strict';var m=0;function i(t="comp"){return `${t}_${Date.now()}_${m++}`}function I(){m=0;}function S(){return m}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 y(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 T(t,e={}){let{id:n=i("icon"),weight:o}=e;return {id:n,component:"Icon",name:t,...o!==void 0&&{weight:o}}}function b(t,e={}){let{id:n=i("video"),weight:o}=e;return {id:n,component:"Video",url:t,...o!==void 0&&{weight:o}}}function D(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 v(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 P(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 V(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 A(t,e={}){let{id:n=i("card"),weight:o}=e;return {id:n,component:"Card",child:t,...o!==void 0&&{weight:o}}}function U(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 w(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 j(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 l(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 _(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 k(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 H(t,e={}){let{id:n=i("datetime"),weight:o,enableDate:a,enableTime:r,outputFormat:s,label:u}=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},...u&&{label:u}}}function N(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 B(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 E(t,e,n={}){let o=n.textId??i("btn_text"),a=p(t,{id:o}),r=l(o,e,n);return [a,r]}function R(t,e={}){return p(t,{...e,usageHint:"h1"})}function L(t,e={}){return p(t,{...e,usageHint:"h2"})}function $(t,e={}){return p(t,{...e,usageHint:"h3"})}function F(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 X(t){return {deleteSurface:{surfaceId:t}}}function W(t){let{surfaceId:e,catalogId:n=d,components:o,dataModel:a}=t,r=[f(e,n),C(e,o)];return a&&r.push(x(e,a)),r}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,a]of Object.entries(t)){let r=e?`${e}/${o}`:`/${o}`;n.push(c(r,a));}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,a]of Object.entries(e))n.push(c(o,a));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,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=O){let o=[];for(let a of t){let r=a.path.startsWith("/")?a.path:`${e}/${a.path}`,s=h(r,n);if(a.value!==null&&typeof a.value=="object"&&!Array.isArray(a.value)){let u=g(a.value,s);o.push(...u);}else o.push(c(s,a.value));}return o}function g(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=g(a,r);n.push(...s);}else n.push(c(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}exports.DEFAULT_PATH_MAPPINGS=O;exports.audioPlayer=D;exports.body=J;exports.button=l;exports.caption=z;exports.card=A;exports.checkbox=_;exports.choicePicker=N;exports.column=P;exports.createSurface=f;exports.createV09Messages=W;exports.dateTimeInput=H;exports.deleteSurface=X;exports.divider=w;exports.flattenObjectToValueMap=g;exports.generateId=i;exports.getIdCounter=S;exports.h1=R;exports.h2=L;exports.h3=$;exports.h4=F;exports.h5=G;exports.icon=T;exports.image=y;exports.jsonlToMessages=K;exports.list=V;exports.messagesToJsonl=Y;exports.modal=j;exports.normalizePath=h;exports.objectToValueMap=q;exports.resetIdCounter=I;exports.row=v;exports.slider=B;exports.tabs=U;exports.text=p;exports.textButton=E;exports.textField=k;exports.updateComponents=C;exports.updateDataModel=x;exports.updatesToValueMap=Q;exports.valueMapToObject=M;exports.valueToValueMap=c;exports.video=b;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
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,
|
|
2
|
+
import { TextComponent, ImageComponent, RowComponent, ListComponent, DividerComponent, TextFieldComponent, ComponentInstance, ChildrenProperty, Action, ChoicePickerComponent, CreateSurfaceMessage, UpdateComponentsMessage, UpdateDataModelMessage, DeleteSurfaceMessage, DataObject, ServerToClientMessageV09, DataValue, ValueMap } 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
|
-
*
|
|
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 消息
|
|
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 消息
|
|
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 消息
|
|
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 消息
|
|
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,81 +413,26 @@ 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:
|
|
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):
|
|
435
|
+
declare function jsonlToMessages(jsonl: string): ServerToClientMessageV09[];
|
|
445
436
|
|
|
446
437
|
/**
|
|
447
438
|
* Data Model Builder
|
|
@@ -530,4 +521,4 @@ declare function flattenObjectToValueMap(obj: DataObject, basePath: string): Val
|
|
|
530
521
|
*/
|
|
531
522
|
declare function valueMapToObject(valueMaps: ValueMap[]): DataObject;
|
|
532
523
|
|
|
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,
|
|
524
|
+
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 };
|
package/dist/builders/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { S as StringOrPath, B as BooleanOrPath, a as StringArrayOrPath, N as NumberOrPath } from '../primitives-nmkVz-tB.js';
|
|
2
|
-
import { TextComponent, ImageComponent, RowComponent, ListComponent, DividerComponent, TextFieldComponent, ComponentInstance, ChildrenProperty, Action, ChoicePickerComponent, CreateSurfaceMessage, UpdateComponentsMessage, UpdateDataModelMessage, DeleteSurfaceMessage, DataObject, ServerToClientMessageV09,
|
|
2
|
+
import { TextComponent, ImageComponent, RowComponent, ListComponent, DividerComponent, TextFieldComponent, ComponentInstance, ChildrenProperty, Action, ChoicePickerComponent, CreateSurfaceMessage, UpdateComponentsMessage, UpdateDataModelMessage, DeleteSurfaceMessage, DataObject, ServerToClientMessageV09, DataValue, ValueMap } from '../types/index.js';
|
|
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
|
-
*
|
|
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 消息
|
|
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 消息
|
|
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 消息
|
|
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 消息
|
|
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,81 +413,26 @@ 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:
|
|
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):
|
|
435
|
+
declare function jsonlToMessages(jsonl: string): ServerToClientMessageV09[];
|
|
445
436
|
|
|
446
437
|
/**
|
|
447
438
|
* Data Model Builder
|
|
@@ -530,4 +521,4 @@ declare function flattenObjectToValueMap(obj: DataObject, basePath: string): Val
|
|
|
530
521
|
*/
|
|
531
522
|
declare function valueMapToObject(valueMaps: ValueMap[]): DataObject;
|
|
532
523
|
|
|
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,
|
|
524
|
+
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 };
|
package/dist/builders/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)}function
|
|
3
|
-
`).filter(e=>e.trim()).map(e=>JSON.parse(e))}
|
|
1
|
+
var m=0;function i(t="comp"){return `${t}_${Date.now()}_${m++}`}function I(){m=0;}function S(){return m}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 y(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 T(t,e={}){let{id:n=i("icon"),weight:o}=e;return {id:n,component:"Icon",name:t,...o!==void 0&&{weight:o}}}function b(t,e={}){let{id:n=i("video"),weight:o}=e;return {id:n,component:"Video",url:t,...o!==void 0&&{weight:o}}}function D(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 v(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 P(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 V(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 A(t,e={}){let{id:n=i("card"),weight:o}=e;return {id:n,component:"Card",child:t,...o!==void 0&&{weight:o}}}function U(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 w(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 j(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 l(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 _(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 k(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 H(t,e={}){let{id:n=i("datetime"),weight:o,enableDate:a,enableTime:r,outputFormat:s,label:u}=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},...u&&{label:u}}}function N(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 B(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 E(t,e,n={}){let o=n.textId??i("btn_text"),a=p(t,{id:o}),r=l(o,e,n);return [a,r]}function R(t,e={}){return p(t,{...e,usageHint:"h1"})}function L(t,e={}){return p(t,{...e,usageHint:"h2"})}function $(t,e={}){return p(t,{...e,usageHint:"h3"})}function F(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 X(t){return {deleteSurface:{surfaceId:t}}}function W(t){let{surfaceId:e,catalogId:n=d,components:o,dataModel:a}=t,r=[f(e,n),C(e,o)];return a&&r.push(x(e,a)),r}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,a]of Object.entries(t)){let r=e?`${e}/${o}`:`/${o}`;n.push(c(r,a));}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,a]of Object.entries(e))n.push(c(o,a));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,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=O){let o=[];for(let a of t){let r=a.path.startsWith("/")?a.path:`${e}/${a.path}`,s=h(r,n);if(a.value!==null&&typeof a.value=="object"&&!Array.isArray(a.value)){let u=g(a.value,s);o.push(...u);}else o.push(c(s,a.value));}return o}function g(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=g(a,r);n.push(...s);}else n.push(c(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}export{O as DEFAULT_PATH_MAPPINGS,D as audioPlayer,J as body,l as button,z as caption,A as card,_ as checkbox,N as choicePicker,P as column,f as createSurface,W as createV09Messages,H as dateTimeInput,X as deleteSurface,w as divider,g as flattenObjectToValueMap,i as generateId,S as getIdCounter,R as h1,L as h2,$ as h3,F as h4,G as h5,T as icon,y as image,K as jsonlToMessages,V as list,Y as messagesToJsonl,j as modal,h as normalizePath,q as objectToValueMap,I as resetIdCounter,v as row,B as slider,U as tabs,p as text,E as textButton,k as textField,C as updateComponents,x as updateDataModel,Q as updatesToValueMap,M as valueMapToObject,c as valueToValueMap,b 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 N(e){return "createSurface"in e||"updateComponents"in e||"updateDataModel"in e}function U(e){return "beginRendering"in e||"surfaceUpdate"in e||"dataModelUpdate"in e}var C="https://a2ui.dev/specification/0.9/standard_catalog_definition.json",_="https://a2ui.org/a2a-extension/a2ui/v0.8",E="https://a2ui.dev/specification/0.9",R="application/json+a2ui";var O=0;function p(e="comp"){return `${e}_${Date.now()}_${O++}`}function w(){O=0;}function k(){return O}function c(e,t={}){let{id:n=p("text"),weight:a,usageHint:o}=t;return {id:n,component:"Text",text:e,...a!==void 0&&{weight:a},...o&&{usageHint:o}}}function j(e,t={}){let{id:n=p("image"),weight:a,fit:o,usageHint:r}=t;return {id:n,component:"Image",url:e,...a!==void 0&&{weight:a},...o&&{fit:o},...r&&{usageHint:r}}}function F(e,t={}){let{id:n=p("icon"),weight:a}=t;return {id:n,component:"Icon",name:e,...a!==void 0&&{weight:a}}}function B(e,t={}){let{id:n=p("video"),weight:a}=t;return {id:n,component:"Video",url:e,...a!==void 0&&{weight:a}}}function $(e,t={}){let{id:n=p("audio"),weight:a,description:o}=t;return {id:n,component:"AudioPlayer",url:e,...a!==void 0&&{weight:a},...o&&{description:o}}}function L(e,t={}){let{id:n=p("row"),weight:a,alignment:o,distribution:r}=t;return {id:n,component:"Row",children:e,...a!==void 0&&{weight:a},...o&&{alignment:o},...r&&{distribution:r}}}function H(e,t={}){let{id:n=p("column"),weight:a,alignment:o,distribution:r}=t;return {id:n,component:"Column",children:e,...a!==void 0&&{weight:a},...o&&{alignment:o},...r&&{distribution:r}}}function G(e,t={}){let{id:n=p("list"),weight:a,direction:o,alignment:r}=t;return {id:n,component:"List",children:e,...a!==void 0&&{weight:a},...o&&{direction:o},...r&&{alignment:r}}}function W(e,t={}){let{id:n=p("card"),weight:a}=t;return {id:n,component:"Card",child:e,...a!==void 0&&{weight:a}}}function q(e,t={}){let{id:n=p("tabs"),weight:a}=t;return {id:n,component:"Tabs",tabItems:e.map(o=>({title:o.title,child:o.childId})),...a!==void 0&&{weight:a}}}function Y(e={}){let{id:t=p("divider"),weight:n,axis:a}=e;return {id:t,component:"Divider",...n!==void 0&&{weight:n},...a&&{axis:a}}}function X(e,t,n={}){let{id:a=p("modal"),weight:o}=n;return {id:a,component:"Modal",entryPointChild:e,contentChild:t,...o!==void 0&&{weight:o}}}function M(e,t,n={}){let{id:a=p("button"),weight:o,primary:r}=n;return {id:a,component:"Button",child:e,action:t,...o!==void 0&&{weight:o},...r!==void 0&&{primary:r}}}function z(e,t,n={}){let{id:a=p("checkbox"),weight:o}=n;return {id:a,component:"CheckBox",label:e,value:t,...o!==void 0&&{weight:o}}}function J(e,t,n={}){let{id:a=p("textfield"),weight:o,usageHint:r,validationRegexp:i}=n;return {id:a,component:"TextField",label:e,...t!==void 0&&{text:t},...o!==void 0&&{weight:o},...r&&{usageHint:r},...i&&{validationRegexp:i}}}function K(e,t={}){let{id:n=p("datetime"),weight:a,enableDate:o,enableTime:r,outputFormat:i,label:s}=t;return {id:n,component:"DateTimeInput",value:e,...a!==void 0&&{weight:a},...o!==void 0&&{enableDate:o},...r!==void 0&&{enableTime:r},...i&&{outputFormat:i},...s&&{label:s}}}function Q(e,t,n,a={}){let{id:o=p("choice"),weight:r,label:i}=a;return {id:o,component:"ChoicePicker",options:e,value:t,usageHint:n,...r!==void 0&&{weight:r},...i&&{label:i}}}function Z(e,t={}){let{id:n=p("slider"),weight:a,label:o,min:r,max:i}=t;return {id:n,component:"Slider",value:e,...a!==void 0&&{weight:a},...o&&{label:o},...r!==void 0&&{min:r},...i!==void 0&&{max:i}}}function ee(e,t,n={}){let a=n.textId??p("btn_text"),o=c(e,{id:a}),r=M(a,t,n);return [o,r]}function te(e,t={}){return c(e,{...t,usageHint:"h1"})}function ne(e,t={}){return c(e,{...t,usageHint:"h2"})}function oe(e,t={}){return c(e,{...t,usageHint:"h3"})}function ae(e,t={}){return c(e,{...t,usageHint:"h4"})}function re(e,t={}){return c(e,{...t,usageHint:"h5"})}function ie(e,t={}){return c(e,{...t,usageHint:"caption"})}function se(e,t={}){return c(e,{...t,usageHint:"body"})}function m(e,t=C){return {createSurface:{surfaceId:e,catalogId:t}}}function g(e,t){return {updateComponents:{surfaceId:e,components:t}}}function I(e,t,n,a="replace"){return {updateDataModel:{surfaceId:e,...n&&{path:n},op:a,...a!=="remove"&&{value:t}}}}function h(e){return {deleteSurface:{surfaceId:e}}}function pe(e){let{surfaceId:t,catalogId:n=C,components:a,dataModel:o}=e,r=[m(t,n),g(t,a)];return o&&r.push(I(t,o)),r}function ce(e){return e.map(t=>JSON.stringify(t)).join(`
|
|
2
|
+
`)}function ue(e){return e.split(`
|
|
3
|
+
`).filter(t=>t.trim()).map(t=>JSON.parse(t))}var T={};function de(e,t=""){let n=[];for(let[a,o]of Object.entries(e)){let r=t?`${t}/${a}`:`/${a}`;n.push(l(r,o));}return n}function l(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((n,a)=>l(String(a),n))};if(typeof t=="object"){let n=[];for(let[a,o]of Object.entries(t))n.push(l(a,o));return {key:e,valueMap:n}}return {key:e,valueString:String(t)}}function y(e,t={}){let n=e.replace(/\./g,"/");n.startsWith("/")||(n=`/${n}`);for(let[a,o]of Object.entries(t)){let r=new RegExp(`^/${a}(/|$)`);r.test(n)&&(n=n.replace(r,`/${o}$1`));}return n}function le(e,t="",n=T){let a=[];for(let o of e){let r=o.path.startsWith("/")?o.path:`${t}/${o.path}`,i=y(r,n);if(o.value!==null&&typeof o.value=="object"&&!Array.isArray(o.value)){let s=x(o.value,i);a.push(...s);}else a.push(l(i,o.value));}return a}function x(e,t){let n=[];for(let[a,o]of Object.entries(e)){let r=`${t}/${a}`;if(o!==null&&typeof o=="object"&&!Array.isArray(o)){let i=x(o,r);n.push(...i);}else n.push(l(r,o));}return n}function V(e){let t={};for(let n of e){let a=n.key.startsWith("/")?n.key.slice(1):n.key;n.valueString!==void 0?t[a]=n.valueString:n.valueNumber!==void 0?t[a]=n.valueNumber:n.valueBoolean!==void 0?t[a]=n.valueBoolean:n.valueMap!==void 0&&(t[a]=V(n.valueMap));}return t}var Te=["Text","Image","Icon","Video","AudioPlayer","Row","Column","List","Card","Tabs","Divider","Modal","Button","CheckBox","TextField","DateTimeInput","ChoicePicker","Slider"];function D(e,t={}){let n=[],a=[];if("createSurface"in e){let{createSurface:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"createSurface.surfaceId is required",path:"createSurface.surfaceId"}),o.catalogId||n.push({code:"MISSING_CATALOG_ID",message:"createSurface.catalogId is required",path:"createSurface.catalogId"});}else if("updateComponents"in e){let{updateComponents:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"updateComponents.surfaceId is required",path:"updateComponents.surfaceId"}),!o.components||!Array.isArray(o.components)?n.push({code:"INVALID_COMPONENTS",message:"updateComponents.components must be an array",path:"updateComponents.components"}):ye(o.components,n,a,t);}else if("updateDataModel"in e){let{updateDataModel:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"updateDataModel.surfaceId is required",path:"updateDataModel.surfaceId"});}else if("deleteSurface"in e){let{deleteSurface:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else n.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: createSurface, updateComponents, updateDataModel, deleteSurface"});return {valid:n.length===0,errors:n,warnings:a}}function b(e,t={}){let n=[],a=[];if("beginRendering"in e){let{beginRendering:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"beginRendering.surfaceId is required",path:"beginRendering.surfaceId"}),o.root||n.push({code:"MISSING_ROOT",message:"beginRendering.root is required",path:"beginRendering.root"});}else if("surfaceUpdate"in e){let{surfaceUpdate:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"surfaceUpdate.surfaceId is required",path:"surfaceUpdate.surfaceId"}),!o.components||!Array.isArray(o.components)?n.push({code:"INVALID_COMPONENTS",message:"surfaceUpdate.components must be an array",path:"surfaceUpdate.components"}):Ve(o.components,n,a,t);}else if("dataModelUpdate"in e){let{dataModelUpdate:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"dataModelUpdate.surfaceId is required",path:"dataModelUpdate.surfaceId"}),(!o.contents||!Array.isArray(o.contents))&&n.push({code:"INVALID_CONTENTS",message:"dataModelUpdate.contents must be an array",path:"dataModelUpdate.contents"});}else if("deleteSurface"in e){let{deleteSurface:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else n.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: beginRendering, surfaceUpdate, dataModelUpdate, deleteSurface"});return {valid:n.length===0,errors:n,warnings:a}}function A(e,t={}){return "createSurface"in e||"updateComponents"in e||"updateDataModel"in e?D(e,t):"beginRendering"in e||"surfaceUpdate"in e||"dataModelUpdate"in e?b(e,t):"deleteSurface"in e?e.deleteSurface.surfaceId?{valid:true,errors:[],warnings:[]}:{valid:false,errors:[{code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"}],warnings:[]}:{valid:false,errors:[{code:"UNKNOWN_MESSAGE_TYPE",message:"Unknown message type"}],warnings:[]}}function fe(e,t={}){let n=[],a=[];for(let o=0;o<e.length;o++){let r=e[o];if(!r)continue;let i=A(r,t);for(let s of i.errors)n.push({...s,path:`messages[${o}].${s.path??""}`});for(let s of i.warnings)a.push({...s,path:`messages[${o}].${s.path??""}`});}return {valid:n.length===0,errors:n,warnings:a}}function ye(e,t,n,a){let o=new Set,r=false;for(let i=0;i<e.length;i++){let s=e[i];if(!s)continue;let u=`updateComponents.components[${i}]`;s.id?(o.has(s.id)&&t.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${s.id}`,path:`${u}.id`}),o.add(s.id),s.id==="root"&&(r=true)):t.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${u}.id`}),s.component?a.strict&&a.allowedComponents&&(a.allowedComponents.includes(s.component)||n.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${s.component}`,path:`${u}.component`})):t.push({code:"MISSING_COMPONENT_TYPE",message:"Component type is required",path:`${u}.component`});}!r&&a.strict&&n.push({code:"MISSING_ROOT_COMPONENT",message:'No component with id "root" found',path:"updateComponents.components"});}function Ve(e,t,n,a){let o=new Set;for(let r=0;r<e.length;r++){let i=e[r];if(!i)continue;let s=`surfaceUpdate.components[${r}]`;if(i.id?(o.has(i.id)&&t.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${i.id}`,path:`${s}.id`}),o.add(i.id)):t.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${s}.id`}),!i.component||typeof i.component!="object")t.push({code:"MISSING_COMPONENT",message:"Component definition is required",path:`${s}.component`});else {let u=Object.keys(i.component)[0];u&&a.strict&&!Te.includes(u)&&n.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${u}`,path:`${s}.component`});}}}function P(e){return typeof e=="object"&&e!==null&&"path"in e}function De(e){if(!P(e))return e}function be(e){if(P(e))return e.path}function Ae(e){return {path:e}}function me(e,t){let n={...e};for(let a of Object.keys(t)){let o=t[a],r=n[a];o!==void 0&&typeof o=="object"&&o!==null&&!Array.isArray(o)&&typeof r=="object"&&r!==null&&!Array.isArray(r)?n[a]=me(r,o):o!==void 0&&(n[a]=o);}return n}function Pe(){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 d={CHAT:"@chat",RECOMMENDATION:"@recommendation",INPUT_FORM:"@input-form",ORCHESTRATION:"@orchestration",STATUS:"@status",RESULT:"@result",CONFIRM:"@confirm",NOTIFICATION:"@notification"},v=0;function S(e="surface"){return v++,`${e}-${Date.now()}-${v}`}function ge(){v=0;}function f(e,t,n){let a=n??S();return t.find(i=>i.id===e)||console.warn(`[A2UI] Root component "${e}" not found in components list`),{messages:[m(a),g(a,t)],surfaceId:a}}function Ce(e,t,n,a){let o=a??S();return {messages:[m(o),g(o,t),I(o,n)],surfaceId:o}}function Ie(e){return h(e)}function Se(e,t){return f(e,t,d.CHAT)}function he(e,t){return f(e,t,d.RECOMMENDATION)}function xe(e,t){return f(e,t,d.INPUT_FORM)}function Oe(e,t){return f(e,t,d.ORCHESTRATION)}function Me(e,t){return f(e,t,d.STATUS)}exports.A2UI_EXTENSION_URI=E;exports.A2UI_EXTENSION_URI_V08=_;exports.A2UI_MIME_TYPE=R;exports.DEFAULT_PATH_MAPPINGS=T;exports.STANDARD_CATALOG_ID=C;exports.SURFACE_IDS=d;exports.audioPlayer=$;exports.body=se;exports.button=M;exports.caption=ie;exports.card=W;exports.checkbox=z;exports.choicePicker=Q;exports.column=H;exports.createA2UISurface=f;exports.createA2UISurfaceWithData=Ce;exports.createChatSurface=Se;exports.createDeleteSurfaceMessage=Ie;exports.createInputFormSurface=xe;exports.createOrchestrationSurface=Oe;exports.createRecommendationSurface=he;exports.createStatusSurface=Me;exports.createSurface=m;exports.createV09Messages=pe;exports.dateTimeInput=K;exports.deepMerge=me;exports.deleteSurface=h;exports.divider=Y;exports.flattenObjectToValueMap=x;exports.generateId=p;exports.generateSurfaceId=S;exports.getIdCounter=k;exports.getLiteralValue=De;exports.getPathValue=be;exports.h1=te;exports.h2=ne;exports.h3=oe;exports.h4=ae;exports.h5=re;exports.icon=F;exports.image=j;exports.isPathBinding=P;exports.isV08Message=U;exports.isV09Message=N;exports.jsonlToMessages=ue;exports.list=G;exports.messagesToJsonl=ce;exports.modal=X;exports.normalizePath=y;exports.objectToValueMap=de;exports.path=Ae;exports.resetIdCounter=w;exports.resetSurfaceIdCounter=ge;exports.row=L;exports.slider=Z;exports.tabs=q;exports.text=c;exports.textButton=ee;exports.textField=J;exports.updateComponents=g;exports.updateDataModel=I;exports.updatesToValueMap=le;exports.uuid=Pe;exports.validateMessage=A;exports.validateMessages=fe;exports.validateV08Message=b;exports.validateV09Message=D;exports.valueMapToObject=V;exports.valueToValueMap=l;exports.video=B;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { B as BooleanOrPath, d as BooleanValue, C as ContextValue, N as NumberOrPath, c as NumberValue, a as StringArrayOrPath, e as StringArrayValue, S as StringOrPath, b as StringValue } from './primitives-nmkVz-tB.cjs';
|
|
2
2
|
export { A2UI_EXTENSION_URI, A2UI_EXTENSION_URI_V08, A2UI_MIME_TYPE, Action, ActionContextItem, ActionV08, AnyComponent, AudioPlayerComponent, BeginRenderingMessage, ButtonComponent, CardComponent, CheckBoxComponent, ChildrenProperty, ChoicePickerComponent, ClientToServerMessage, ColumnComponent, ComponentCommon, ComponentInstance, ComponentInstanceV08, ComponentType, CreateSurfaceMessage, DataArray, DataChangeEvent, DataModelUpdateMessage, DataObject, DataValue, DateTimeInputComponent, DeleteSurfaceMessage, DeleteSurfaceMessageV08, DividerComponent, IconComponent, ImageComponent, ListComponent, ModalComponent, RowComponent, STANDARD_CATALOG_ID, ServerToClientMessage, ServerToClientMessageV08, ServerToClientMessageV09, SliderComponent, StandardIconName, SurfaceUpdateMessage, TabsComponent, TextComponent, TextFieldComponent, Theme, UpdateComponentsMessage, UpdateDataModelMessage, UserActionEvent, ValueMap, VideoComponent, isV08Message, isV09Message } from './types/index.cjs';
|
|
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,
|
|
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
4
|
export { ValidationError, ValidationOptions, ValidationResult, ValidationWarning, validateMessage, validateMessages, validateV08Message, validateV09Message } from './validators/index.cjs';
|
|
5
5
|
export { deepMerge, getLiteralValue, getPathValue, isPathBinding, path, uuid } from './utils/index.cjs';
|
|
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,5 +1,6 @@
|
|
|
1
1
|
export { B as BooleanOrPath, d as BooleanValue, C as ContextValue, N as NumberOrPath, c as NumberValue, a as StringArrayOrPath, e as StringArrayValue, S as StringOrPath, b as StringValue } from './primitives-nmkVz-tB.js';
|
|
2
2
|
export { A2UI_EXTENSION_URI, A2UI_EXTENSION_URI_V08, A2UI_MIME_TYPE, Action, ActionContextItem, ActionV08, AnyComponent, AudioPlayerComponent, BeginRenderingMessage, ButtonComponent, CardComponent, CheckBoxComponent, ChildrenProperty, ChoicePickerComponent, ClientToServerMessage, ColumnComponent, ComponentCommon, ComponentInstance, ComponentInstanceV08, ComponentType, CreateSurfaceMessage, DataArray, DataChangeEvent, DataModelUpdateMessage, DataObject, DataValue, DateTimeInputComponent, DeleteSurfaceMessage, DeleteSurfaceMessageV08, DividerComponent, IconComponent, ImageComponent, ListComponent, ModalComponent, RowComponent, STANDARD_CATALOG_ID, ServerToClientMessage, ServerToClientMessageV08, ServerToClientMessageV09, SliderComponent, StandardIconName, SurfaceUpdateMessage, TabsComponent, TextComponent, TextFieldComponent, Theme, UpdateComponentsMessage, UpdateDataModelMessage, UserActionEvent, ValueMap, VideoComponent, isV08Message, isV09Message } from './types/index.js';
|
|
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,
|
|
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
4
|
export { ValidationError, ValidationOptions, ValidationResult, ValidationWarning, validateMessage, validateMessages, validateV08Message, validateV09Message } from './validators/index.js';
|
|
5
5
|
export { deepMerge, getLiteralValue, getPathValue, isPathBinding, path, uuid } from './utils/index.js';
|
|
6
|
+
export { SURFACE_IDS, SurfaceConfig, SurfaceIdType, SurfaceResult, createA2UISurface, createA2UISurfaceWithData, createChatSurface, createDeleteSurfaceMessage, createInputFormSurface, createOrchestrationSurface, createRecommendationSurface, createStatusSurface, generateSurfaceId, resetSurfaceIdCounter } from './surface/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
function
|
|
2
|
-
`)}function
|
|
3
|
-
`).filter(t=>t.trim()).map(t=>JSON.parse(t))}var
|
|
1
|
+
function N(e){return "createSurface"in e||"updateComponents"in e||"updateDataModel"in e}function U(e){return "beginRendering"in e||"surfaceUpdate"in e||"dataModelUpdate"in e}var C="https://a2ui.dev/specification/0.9/standard_catalog_definition.json",_="https://a2ui.org/a2a-extension/a2ui/v0.8",E="https://a2ui.dev/specification/0.9",R="application/json+a2ui";var O=0;function p(e="comp"){return `${e}_${Date.now()}_${O++}`}function w(){O=0;}function k(){return O}function c(e,t={}){let{id:n=p("text"),weight:a,usageHint:o}=t;return {id:n,component:"Text",text:e,...a!==void 0&&{weight:a},...o&&{usageHint:o}}}function j(e,t={}){let{id:n=p("image"),weight:a,fit:o,usageHint:r}=t;return {id:n,component:"Image",url:e,...a!==void 0&&{weight:a},...o&&{fit:o},...r&&{usageHint:r}}}function F(e,t={}){let{id:n=p("icon"),weight:a}=t;return {id:n,component:"Icon",name:e,...a!==void 0&&{weight:a}}}function B(e,t={}){let{id:n=p("video"),weight:a}=t;return {id:n,component:"Video",url:e,...a!==void 0&&{weight:a}}}function $(e,t={}){let{id:n=p("audio"),weight:a,description:o}=t;return {id:n,component:"AudioPlayer",url:e,...a!==void 0&&{weight:a},...o&&{description:o}}}function L(e,t={}){let{id:n=p("row"),weight:a,alignment:o,distribution:r}=t;return {id:n,component:"Row",children:e,...a!==void 0&&{weight:a},...o&&{alignment:o},...r&&{distribution:r}}}function H(e,t={}){let{id:n=p("column"),weight:a,alignment:o,distribution:r}=t;return {id:n,component:"Column",children:e,...a!==void 0&&{weight:a},...o&&{alignment:o},...r&&{distribution:r}}}function G(e,t={}){let{id:n=p("list"),weight:a,direction:o,alignment:r}=t;return {id:n,component:"List",children:e,...a!==void 0&&{weight:a},...o&&{direction:o},...r&&{alignment:r}}}function W(e,t={}){let{id:n=p("card"),weight:a}=t;return {id:n,component:"Card",child:e,...a!==void 0&&{weight:a}}}function q(e,t={}){let{id:n=p("tabs"),weight:a}=t;return {id:n,component:"Tabs",tabItems:e.map(o=>({title:o.title,child:o.childId})),...a!==void 0&&{weight:a}}}function Y(e={}){let{id:t=p("divider"),weight:n,axis:a}=e;return {id:t,component:"Divider",...n!==void 0&&{weight:n},...a&&{axis:a}}}function X(e,t,n={}){let{id:a=p("modal"),weight:o}=n;return {id:a,component:"Modal",entryPointChild:e,contentChild:t,...o!==void 0&&{weight:o}}}function M(e,t,n={}){let{id:a=p("button"),weight:o,primary:r}=n;return {id:a,component:"Button",child:e,action:t,...o!==void 0&&{weight:o},...r!==void 0&&{primary:r}}}function z(e,t,n={}){let{id:a=p("checkbox"),weight:o}=n;return {id:a,component:"CheckBox",label:e,value:t,...o!==void 0&&{weight:o}}}function J(e,t,n={}){let{id:a=p("textfield"),weight:o,usageHint:r,validationRegexp:i}=n;return {id:a,component:"TextField",label:e,...t!==void 0&&{text:t},...o!==void 0&&{weight:o},...r&&{usageHint:r},...i&&{validationRegexp:i}}}function K(e,t={}){let{id:n=p("datetime"),weight:a,enableDate:o,enableTime:r,outputFormat:i,label:s}=t;return {id:n,component:"DateTimeInput",value:e,...a!==void 0&&{weight:a},...o!==void 0&&{enableDate:o},...r!==void 0&&{enableTime:r},...i&&{outputFormat:i},...s&&{label:s}}}function Q(e,t,n,a={}){let{id:o=p("choice"),weight:r,label:i}=a;return {id:o,component:"ChoicePicker",options:e,value:t,usageHint:n,...r!==void 0&&{weight:r},...i&&{label:i}}}function Z(e,t={}){let{id:n=p("slider"),weight:a,label:o,min:r,max:i}=t;return {id:n,component:"Slider",value:e,...a!==void 0&&{weight:a},...o&&{label:o},...r!==void 0&&{min:r},...i!==void 0&&{max:i}}}function ee(e,t,n={}){let a=n.textId??p("btn_text"),o=c(e,{id:a}),r=M(a,t,n);return [o,r]}function te(e,t={}){return c(e,{...t,usageHint:"h1"})}function ne(e,t={}){return c(e,{...t,usageHint:"h2"})}function oe(e,t={}){return c(e,{...t,usageHint:"h3"})}function ae(e,t={}){return c(e,{...t,usageHint:"h4"})}function re(e,t={}){return c(e,{...t,usageHint:"h5"})}function ie(e,t={}){return c(e,{...t,usageHint:"caption"})}function se(e,t={}){return c(e,{...t,usageHint:"body"})}function m(e,t=C){return {createSurface:{surfaceId:e,catalogId:t}}}function g(e,t){return {updateComponents:{surfaceId:e,components:t}}}function I(e,t,n,a="replace"){return {updateDataModel:{surfaceId:e,...n&&{path:n},op:a,...a!=="remove"&&{value:t}}}}function h(e){return {deleteSurface:{surfaceId:e}}}function pe(e){let{surfaceId:t,catalogId:n=C,components:a,dataModel:o}=e,r=[m(t,n),g(t,a)];return o&&r.push(I(t,o)),r}function ce(e){return e.map(t=>JSON.stringify(t)).join(`
|
|
2
|
+
`)}function ue(e){return e.split(`
|
|
3
|
+
`).filter(t=>t.trim()).map(t=>JSON.parse(t))}var T={};function de(e,t=""){let n=[];for(let[a,o]of Object.entries(e)){let r=t?`${t}/${a}`:`/${a}`;n.push(l(r,o));}return n}function l(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((n,a)=>l(String(a),n))};if(typeof t=="object"){let n=[];for(let[a,o]of Object.entries(t))n.push(l(a,o));return {key:e,valueMap:n}}return {key:e,valueString:String(t)}}function y(e,t={}){let n=e.replace(/\./g,"/");n.startsWith("/")||(n=`/${n}`);for(let[a,o]of Object.entries(t)){let r=new RegExp(`^/${a}(/|$)`);r.test(n)&&(n=n.replace(r,`/${o}$1`));}return n}function le(e,t="",n=T){let a=[];for(let o of e){let r=o.path.startsWith("/")?o.path:`${t}/${o.path}`,i=y(r,n);if(o.value!==null&&typeof o.value=="object"&&!Array.isArray(o.value)){let s=x(o.value,i);a.push(...s);}else a.push(l(i,o.value));}return a}function x(e,t){let n=[];for(let[a,o]of Object.entries(e)){let r=`${t}/${a}`;if(o!==null&&typeof o=="object"&&!Array.isArray(o)){let i=x(o,r);n.push(...i);}else n.push(l(r,o));}return n}function V(e){let t={};for(let n of e){let a=n.key.startsWith("/")?n.key.slice(1):n.key;n.valueString!==void 0?t[a]=n.valueString:n.valueNumber!==void 0?t[a]=n.valueNumber:n.valueBoolean!==void 0?t[a]=n.valueBoolean:n.valueMap!==void 0&&(t[a]=V(n.valueMap));}return t}var Te=["Text","Image","Icon","Video","AudioPlayer","Row","Column","List","Card","Tabs","Divider","Modal","Button","CheckBox","TextField","DateTimeInput","ChoicePicker","Slider"];function D(e,t={}){let n=[],a=[];if("createSurface"in e){let{createSurface:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"createSurface.surfaceId is required",path:"createSurface.surfaceId"}),o.catalogId||n.push({code:"MISSING_CATALOG_ID",message:"createSurface.catalogId is required",path:"createSurface.catalogId"});}else if("updateComponents"in e){let{updateComponents:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"updateComponents.surfaceId is required",path:"updateComponents.surfaceId"}),!o.components||!Array.isArray(o.components)?n.push({code:"INVALID_COMPONENTS",message:"updateComponents.components must be an array",path:"updateComponents.components"}):ye(o.components,n,a,t);}else if("updateDataModel"in e){let{updateDataModel:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"updateDataModel.surfaceId is required",path:"updateDataModel.surfaceId"});}else if("deleteSurface"in e){let{deleteSurface:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else n.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: createSurface, updateComponents, updateDataModel, deleteSurface"});return {valid:n.length===0,errors:n,warnings:a}}function b(e,t={}){let n=[],a=[];if("beginRendering"in e){let{beginRendering:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"beginRendering.surfaceId is required",path:"beginRendering.surfaceId"}),o.root||n.push({code:"MISSING_ROOT",message:"beginRendering.root is required",path:"beginRendering.root"});}else if("surfaceUpdate"in e){let{surfaceUpdate:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"surfaceUpdate.surfaceId is required",path:"surfaceUpdate.surfaceId"}),!o.components||!Array.isArray(o.components)?n.push({code:"INVALID_COMPONENTS",message:"surfaceUpdate.components must be an array",path:"surfaceUpdate.components"}):Ve(o.components,n,a,t);}else if("dataModelUpdate"in e){let{dataModelUpdate:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"dataModelUpdate.surfaceId is required",path:"dataModelUpdate.surfaceId"}),(!o.contents||!Array.isArray(o.contents))&&n.push({code:"INVALID_CONTENTS",message:"dataModelUpdate.contents must be an array",path:"dataModelUpdate.contents"});}else if("deleteSurface"in e){let{deleteSurface:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else n.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: beginRendering, surfaceUpdate, dataModelUpdate, deleteSurface"});return {valid:n.length===0,errors:n,warnings:a}}function A(e,t={}){return "createSurface"in e||"updateComponents"in e||"updateDataModel"in e?D(e,t):"beginRendering"in e||"surfaceUpdate"in e||"dataModelUpdate"in e?b(e,t):"deleteSurface"in e?e.deleteSurface.surfaceId?{valid:true,errors:[],warnings:[]}:{valid:false,errors:[{code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"}],warnings:[]}:{valid:false,errors:[{code:"UNKNOWN_MESSAGE_TYPE",message:"Unknown message type"}],warnings:[]}}function fe(e,t={}){let n=[],a=[];for(let o=0;o<e.length;o++){let r=e[o];if(!r)continue;let i=A(r,t);for(let s of i.errors)n.push({...s,path:`messages[${o}].${s.path??""}`});for(let s of i.warnings)a.push({...s,path:`messages[${o}].${s.path??""}`});}return {valid:n.length===0,errors:n,warnings:a}}function ye(e,t,n,a){let o=new Set,r=false;for(let i=0;i<e.length;i++){let s=e[i];if(!s)continue;let u=`updateComponents.components[${i}]`;s.id?(o.has(s.id)&&t.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${s.id}`,path:`${u}.id`}),o.add(s.id),s.id==="root"&&(r=true)):t.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${u}.id`}),s.component?a.strict&&a.allowedComponents&&(a.allowedComponents.includes(s.component)||n.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${s.component}`,path:`${u}.component`})):t.push({code:"MISSING_COMPONENT_TYPE",message:"Component type is required",path:`${u}.component`});}!r&&a.strict&&n.push({code:"MISSING_ROOT_COMPONENT",message:'No component with id "root" found',path:"updateComponents.components"});}function Ve(e,t,n,a){let o=new Set;for(let r=0;r<e.length;r++){let i=e[r];if(!i)continue;let s=`surfaceUpdate.components[${r}]`;if(i.id?(o.has(i.id)&&t.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${i.id}`,path:`${s}.id`}),o.add(i.id)):t.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${s}.id`}),!i.component||typeof i.component!="object")t.push({code:"MISSING_COMPONENT",message:"Component definition is required",path:`${s}.component`});else {let u=Object.keys(i.component)[0];u&&a.strict&&!Te.includes(u)&&n.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${u}`,path:`${s}.component`});}}}function P(e){return typeof e=="object"&&e!==null&&"path"in e}function De(e){if(!P(e))return e}function be(e){if(P(e))return e.path}function Ae(e){return {path:e}}function me(e,t){let n={...e};for(let a of Object.keys(t)){let o=t[a],r=n[a];o!==void 0&&typeof o=="object"&&o!==null&&!Array.isArray(o)&&typeof r=="object"&&r!==null&&!Array.isArray(r)?n[a]=me(r,o):o!==void 0&&(n[a]=o);}return n}function Pe(){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 d={CHAT:"@chat",RECOMMENDATION:"@recommendation",INPUT_FORM:"@input-form",ORCHESTRATION:"@orchestration",STATUS:"@status",RESULT:"@result",CONFIRM:"@confirm",NOTIFICATION:"@notification"},v=0;function S(e="surface"){return v++,`${e}-${Date.now()}-${v}`}function ge(){v=0;}function f(e,t,n){let a=n??S();return t.find(i=>i.id===e)||console.warn(`[A2UI] Root component "${e}" not found in components list`),{messages:[m(a),g(a,t)],surfaceId:a}}function Ce(e,t,n,a){let o=a??S();return {messages:[m(o),g(o,t),I(o,n)],surfaceId:o}}function Ie(e){return h(e)}function Se(e,t){return f(e,t,d.CHAT)}function he(e,t){return f(e,t,d.RECOMMENDATION)}function xe(e,t){return f(e,t,d.INPUT_FORM)}function Oe(e,t){return f(e,t,d.ORCHESTRATION)}function Me(e,t){return f(e,t,d.STATUS)}export{E as A2UI_EXTENSION_URI,_ as A2UI_EXTENSION_URI_V08,R as A2UI_MIME_TYPE,T as DEFAULT_PATH_MAPPINGS,C as STANDARD_CATALOG_ID,d as SURFACE_IDS,$ as audioPlayer,se as body,M as button,ie as caption,W as card,z as checkbox,Q as choicePicker,H as column,f as createA2UISurface,Ce as createA2UISurfaceWithData,Se as createChatSurface,Ie as createDeleteSurfaceMessage,xe as createInputFormSurface,Oe as createOrchestrationSurface,he as createRecommendationSurface,Me as createStatusSurface,m as createSurface,pe as createV09Messages,K as dateTimeInput,me as deepMerge,h as deleteSurface,Y as divider,x as flattenObjectToValueMap,p as generateId,S as generateSurfaceId,k as getIdCounter,De as getLiteralValue,be as getPathValue,te as h1,ne as h2,oe as h3,ae as h4,re as h5,F as icon,j as image,P as isPathBinding,U as isV08Message,N as isV09Message,ue as jsonlToMessages,G as list,ce as messagesToJsonl,X as modal,y as normalizePath,de as objectToValueMap,Ae as path,w as resetIdCounter,ge as resetSurfaceIdCounter,L as row,Z as slider,q as tabs,c as text,ee as textButton,J as textField,g as updateComponents,I as updateDataModel,le as updatesToValueMap,Pe as uuid,A as validateMessage,fe as validateMessages,b as validateV08Message,D as validateV09Message,V as valueMapToObject,l as valueToValueMap,B as video};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var a={CHAT:"@chat",RECOMMENDATION:"@recommendation",INPUT_FORM:"@input-form",ORCHESTRATION:"@orchestration",STATUS:"@status",RESULT:"@result",CONFIRM:"@confirm",NOTIFICATION:"@notification"},c=0;function i(e="surface"){return c++,`${e}-${Date.now()}-${c}`}function S(){c=0;}var p="https://a2ui.dev/specification/0.9/standard_catalog_definition.json";function u(e,t=p){return {createSurface:{surfaceId:e,catalogId:t}}}function g(e,t){return {updateComponents:{surfaceId:e,components:t}}}function f(e,t,r,n="replace"){return {updateDataModel:{surfaceId:e,...r,op:n,...n!=="remove"&&{value:t}}}}function d(e){return {deleteSurface:{surfaceId:e}}}function o(e,t,r){let n=r??i();return t.find(l=>l.id===e)||console.warn(`[A2UI] Root component "${e}" not found in components list`),{messages:[u(n),g(n,t)],surfaceId:n}}function C(e,t,r,n){let s=n??i();return {messages:[u(s),g(s,t),f(s,r)],surfaceId:s}}function M(e){return d(e)}function I(e,t){return o(e,t,a.CHAT)}function T(e,t){return o(e,t,a.RECOMMENDATION)}function D(e,t){return o(e,t,a.INPUT_FORM)}function x(e,t){return o(e,t,a.ORCHESTRATION)}function A(e,t){return o(e,t,a.STATUS)}
|
|
2
|
+
exports.SURFACE_IDS=a;exports.createA2UISurface=o;exports.createA2UISurfaceWithData=C;exports.createChatSurface=I;exports.createDeleteSurfaceMessage=M;exports.createInputFormSurface=D;exports.createOrchestrationSurface=x;exports.createRecommendationSurface=T;exports.createStatusSurface=A;exports.generateSurfaceId=i;exports.resetSurfaceIdCounter=S;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { ServerToClientMessageV09, ComponentInstance, DataObject } from '../types/index.cjs';
|
|
2
|
+
import '../primitives-nmkVz-tB.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Surface IDs and Configuration
|
|
6
|
+
*
|
|
7
|
+
* 预定义的 Surface ID 常量和配置
|
|
8
|
+
* 前端根据这些 ID 决定渲染位置和样式
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* 标准 Surface ID 常量
|
|
12
|
+
*
|
|
13
|
+
* 前端可以根据这些 ID 决定:
|
|
14
|
+
* - 渲染位置(聊天区、侧边栏、模态框等)
|
|
15
|
+
* - 渲染样式(卡片、全屏、浮动等)
|
|
16
|
+
* - 交互行为(自动消失、持久化等)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { SURFACE_IDS, createA2UISurface } from '@zhama/a2ui-core';
|
|
21
|
+
*
|
|
22
|
+
* const surface = createA2UISurface('root', components, SURFACE_IDS.CHAT);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare const SURFACE_IDS: {
|
|
26
|
+
/** 聊天内容区 - 普通对话消息 */
|
|
27
|
+
readonly CHAT: "@chat";
|
|
28
|
+
/** 智能体推荐区 - 展示推荐的智能体列表 */
|
|
29
|
+
readonly RECOMMENDATION: "@recommendation";
|
|
30
|
+
/** 输入收集表单 - 收集用户输入 */
|
|
31
|
+
readonly INPUT_FORM: "@input-form";
|
|
32
|
+
/** 编排面板 - 多智能体编排状态 */
|
|
33
|
+
readonly ORCHESTRATION: "@orchestration";
|
|
34
|
+
/** 临时状态提示 - loading/thinking/error 等 */
|
|
35
|
+
readonly STATUS: "@status";
|
|
36
|
+
/** 结果展示区 - 智能体执行结果 */
|
|
37
|
+
readonly RESULT: "@result";
|
|
38
|
+
/** 确认对话框 - 需要用户确认的操作 */
|
|
39
|
+
readonly CONFIRM: "@confirm";
|
|
40
|
+
/** 通知区 - 系统通知 */
|
|
41
|
+
readonly NOTIFICATION: "@notification";
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Surface ID 类型
|
|
45
|
+
*/
|
|
46
|
+
type SurfaceIdType = (typeof SURFACE_IDS)[keyof typeof SURFACE_IDS];
|
|
47
|
+
/**
|
|
48
|
+
* Surface 配置
|
|
49
|
+
*/
|
|
50
|
+
interface SurfaceConfig {
|
|
51
|
+
/** Surface ID */
|
|
52
|
+
id: SurfaceIdType | string;
|
|
53
|
+
/** 是否自动消失 */
|
|
54
|
+
autoHide?: boolean;
|
|
55
|
+
/** 自动消失延迟(毫秒) */
|
|
56
|
+
autoHideDelay?: number;
|
|
57
|
+
/** 是否可关闭 */
|
|
58
|
+
closable?: boolean;
|
|
59
|
+
/** 优先级(数字越大越优先显示) */
|
|
60
|
+
priority?: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 生成唯一的 Surface ID
|
|
64
|
+
*
|
|
65
|
+
* @param prefix - ID 前缀
|
|
66
|
+
* @returns 唯一的 Surface ID
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const id = generateSurfaceId('status'); // 'status-1703123456789-1'
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
declare function generateSurfaceId(prefix?: string): string;
|
|
74
|
+
/**
|
|
75
|
+
* 重置 Surface ID 计数器
|
|
76
|
+
* 主要用于测试
|
|
77
|
+
*/
|
|
78
|
+
declare function resetSurfaceIdCounter(): void;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Surface Builder
|
|
82
|
+
*
|
|
83
|
+
* 提供 A2UI Surface 的构建工具函数
|
|
84
|
+
* 基于 v0.9 格式
|
|
85
|
+
*
|
|
86
|
+
* 参考:https://a2ui.org/
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Surface 构建结果
|
|
91
|
+
*/
|
|
92
|
+
interface SurfaceResult {
|
|
93
|
+
/** 构建的消息数组 */
|
|
94
|
+
messages: ServerToClientMessageV09[];
|
|
95
|
+
/** Surface ID */
|
|
96
|
+
surfaceId: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 创建 A2UI Surface 消息
|
|
100
|
+
*
|
|
101
|
+
* @param rootId - 根组件 ID
|
|
102
|
+
* @param components - 组件列表(v0.9 格式)
|
|
103
|
+
* @param surfaceId - Surface ID(可选,自动生成)
|
|
104
|
+
* @returns Surface 构建结果
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* import { createA2UISurface, h1, column, SURFACE_IDS } from '@zhama/a2ui-core';
|
|
109
|
+
*
|
|
110
|
+
* const title = h1('Hello', { id: 'title' });
|
|
111
|
+
* const root = column(['title'], { id: 'root' });
|
|
112
|
+
*
|
|
113
|
+
* const { messages, surfaceId } = createA2UISurface('root', [title, root], SURFACE_IDS.CHAT);
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
declare function createA2UISurface(rootId: string, components: ComponentInstance[], surfaceId?: string): SurfaceResult;
|
|
117
|
+
/**
|
|
118
|
+
* 创建带数据模型的 A2UI Surface
|
|
119
|
+
*
|
|
120
|
+
* @param rootId - 根组件 ID
|
|
121
|
+
* @param components - 组件列表(v0.9 格式)
|
|
122
|
+
* @param dataModel - 数据模型对象
|
|
123
|
+
* @param surfaceId - Surface ID(可选)
|
|
124
|
+
* @returns Surface 构建结果
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* const { messages } = createA2UISurfaceWithData(
|
|
129
|
+
* 'root',
|
|
130
|
+
* [title, greeting, root],
|
|
131
|
+
* { user: { name: 'John' } },
|
|
132
|
+
* SURFACE_IDS.CHAT
|
|
133
|
+
* );
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
declare function createA2UISurfaceWithData(rootId: string, components: ComponentInstance[], dataModel: DataObject, surfaceId?: string): SurfaceResult;
|
|
137
|
+
/**
|
|
138
|
+
* 创建删除 Surface 的消息
|
|
139
|
+
*
|
|
140
|
+
* @param surfaceId - 要删除的 Surface ID
|
|
141
|
+
* @returns 删除消息
|
|
142
|
+
*/
|
|
143
|
+
declare function createDeleteSurfaceMessage(surfaceId: string): ServerToClientMessageV09;
|
|
144
|
+
/**
|
|
145
|
+
* 创建聊天区 Surface
|
|
146
|
+
*/
|
|
147
|
+
declare function createChatSurface(rootId: string, components: ComponentInstance[]): SurfaceResult;
|
|
148
|
+
/**
|
|
149
|
+
* 创建智能体推荐区 Surface
|
|
150
|
+
*/
|
|
151
|
+
declare function createRecommendationSurface(rootId: string, components: ComponentInstance[]): SurfaceResult;
|
|
152
|
+
/**
|
|
153
|
+
* 创建输入表单区 Surface
|
|
154
|
+
*/
|
|
155
|
+
declare function createInputFormSurface(rootId: string, components: ComponentInstance[]): SurfaceResult;
|
|
156
|
+
/**
|
|
157
|
+
* 创建编排面板 Surface
|
|
158
|
+
*/
|
|
159
|
+
declare function createOrchestrationSurface(rootId: string, components: ComponentInstance[]): SurfaceResult;
|
|
160
|
+
/**
|
|
161
|
+
* 创建状态提示 Surface
|
|
162
|
+
*/
|
|
163
|
+
declare function createStatusSurface(rootId: string, components: ComponentInstance[]): SurfaceResult;
|
|
164
|
+
|
|
165
|
+
export { SURFACE_IDS, type SurfaceConfig, type SurfaceIdType, type SurfaceResult, createA2UISurface, createA2UISurfaceWithData, createChatSurface, createDeleteSurfaceMessage, createInputFormSurface, createOrchestrationSurface, createRecommendationSurface, createStatusSurface, generateSurfaceId, resetSurfaceIdCounter };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { ServerToClientMessageV09, ComponentInstance, DataObject } from '../types/index.js';
|
|
2
|
+
import '../primitives-nmkVz-tB.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Surface IDs and Configuration
|
|
6
|
+
*
|
|
7
|
+
* 预定义的 Surface ID 常量和配置
|
|
8
|
+
* 前端根据这些 ID 决定渲染位置和样式
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* 标准 Surface ID 常量
|
|
12
|
+
*
|
|
13
|
+
* 前端可以根据这些 ID 决定:
|
|
14
|
+
* - 渲染位置(聊天区、侧边栏、模态框等)
|
|
15
|
+
* - 渲染样式(卡片、全屏、浮动等)
|
|
16
|
+
* - 交互行为(自动消失、持久化等)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { SURFACE_IDS, createA2UISurface } from '@zhama/a2ui-core';
|
|
21
|
+
*
|
|
22
|
+
* const surface = createA2UISurface('root', components, SURFACE_IDS.CHAT);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare const SURFACE_IDS: {
|
|
26
|
+
/** 聊天内容区 - 普通对话消息 */
|
|
27
|
+
readonly CHAT: "@chat";
|
|
28
|
+
/** 智能体推荐区 - 展示推荐的智能体列表 */
|
|
29
|
+
readonly RECOMMENDATION: "@recommendation";
|
|
30
|
+
/** 输入收集表单 - 收集用户输入 */
|
|
31
|
+
readonly INPUT_FORM: "@input-form";
|
|
32
|
+
/** 编排面板 - 多智能体编排状态 */
|
|
33
|
+
readonly ORCHESTRATION: "@orchestration";
|
|
34
|
+
/** 临时状态提示 - loading/thinking/error 等 */
|
|
35
|
+
readonly STATUS: "@status";
|
|
36
|
+
/** 结果展示区 - 智能体执行结果 */
|
|
37
|
+
readonly RESULT: "@result";
|
|
38
|
+
/** 确认对话框 - 需要用户确认的操作 */
|
|
39
|
+
readonly CONFIRM: "@confirm";
|
|
40
|
+
/** 通知区 - 系统通知 */
|
|
41
|
+
readonly NOTIFICATION: "@notification";
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Surface ID 类型
|
|
45
|
+
*/
|
|
46
|
+
type SurfaceIdType = (typeof SURFACE_IDS)[keyof typeof SURFACE_IDS];
|
|
47
|
+
/**
|
|
48
|
+
* Surface 配置
|
|
49
|
+
*/
|
|
50
|
+
interface SurfaceConfig {
|
|
51
|
+
/** Surface ID */
|
|
52
|
+
id: SurfaceIdType | string;
|
|
53
|
+
/** 是否自动消失 */
|
|
54
|
+
autoHide?: boolean;
|
|
55
|
+
/** 自动消失延迟(毫秒) */
|
|
56
|
+
autoHideDelay?: number;
|
|
57
|
+
/** 是否可关闭 */
|
|
58
|
+
closable?: boolean;
|
|
59
|
+
/** 优先级(数字越大越优先显示) */
|
|
60
|
+
priority?: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 生成唯一的 Surface ID
|
|
64
|
+
*
|
|
65
|
+
* @param prefix - ID 前缀
|
|
66
|
+
* @returns 唯一的 Surface ID
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const id = generateSurfaceId('status'); // 'status-1703123456789-1'
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
declare function generateSurfaceId(prefix?: string): string;
|
|
74
|
+
/**
|
|
75
|
+
* 重置 Surface ID 计数器
|
|
76
|
+
* 主要用于测试
|
|
77
|
+
*/
|
|
78
|
+
declare function resetSurfaceIdCounter(): void;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Surface Builder
|
|
82
|
+
*
|
|
83
|
+
* 提供 A2UI Surface 的构建工具函数
|
|
84
|
+
* 基于 v0.9 格式
|
|
85
|
+
*
|
|
86
|
+
* 参考:https://a2ui.org/
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Surface 构建结果
|
|
91
|
+
*/
|
|
92
|
+
interface SurfaceResult {
|
|
93
|
+
/** 构建的消息数组 */
|
|
94
|
+
messages: ServerToClientMessageV09[];
|
|
95
|
+
/** Surface ID */
|
|
96
|
+
surfaceId: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 创建 A2UI Surface 消息
|
|
100
|
+
*
|
|
101
|
+
* @param rootId - 根组件 ID
|
|
102
|
+
* @param components - 组件列表(v0.9 格式)
|
|
103
|
+
* @param surfaceId - Surface ID(可选,自动生成)
|
|
104
|
+
* @returns Surface 构建结果
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* import { createA2UISurface, h1, column, SURFACE_IDS } from '@zhama/a2ui-core';
|
|
109
|
+
*
|
|
110
|
+
* const title = h1('Hello', { id: 'title' });
|
|
111
|
+
* const root = column(['title'], { id: 'root' });
|
|
112
|
+
*
|
|
113
|
+
* const { messages, surfaceId } = createA2UISurface('root', [title, root], SURFACE_IDS.CHAT);
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
declare function createA2UISurface(rootId: string, components: ComponentInstance[], surfaceId?: string): SurfaceResult;
|
|
117
|
+
/**
|
|
118
|
+
* 创建带数据模型的 A2UI Surface
|
|
119
|
+
*
|
|
120
|
+
* @param rootId - 根组件 ID
|
|
121
|
+
* @param components - 组件列表(v0.9 格式)
|
|
122
|
+
* @param dataModel - 数据模型对象
|
|
123
|
+
* @param surfaceId - Surface ID(可选)
|
|
124
|
+
* @returns Surface 构建结果
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* const { messages } = createA2UISurfaceWithData(
|
|
129
|
+
* 'root',
|
|
130
|
+
* [title, greeting, root],
|
|
131
|
+
* { user: { name: 'John' } },
|
|
132
|
+
* SURFACE_IDS.CHAT
|
|
133
|
+
* );
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
declare function createA2UISurfaceWithData(rootId: string, components: ComponentInstance[], dataModel: DataObject, surfaceId?: string): SurfaceResult;
|
|
137
|
+
/**
|
|
138
|
+
* 创建删除 Surface 的消息
|
|
139
|
+
*
|
|
140
|
+
* @param surfaceId - 要删除的 Surface ID
|
|
141
|
+
* @returns 删除消息
|
|
142
|
+
*/
|
|
143
|
+
declare function createDeleteSurfaceMessage(surfaceId: string): ServerToClientMessageV09;
|
|
144
|
+
/**
|
|
145
|
+
* 创建聊天区 Surface
|
|
146
|
+
*/
|
|
147
|
+
declare function createChatSurface(rootId: string, components: ComponentInstance[]): SurfaceResult;
|
|
148
|
+
/**
|
|
149
|
+
* 创建智能体推荐区 Surface
|
|
150
|
+
*/
|
|
151
|
+
declare function createRecommendationSurface(rootId: string, components: ComponentInstance[]): SurfaceResult;
|
|
152
|
+
/**
|
|
153
|
+
* 创建输入表单区 Surface
|
|
154
|
+
*/
|
|
155
|
+
declare function createInputFormSurface(rootId: string, components: ComponentInstance[]): SurfaceResult;
|
|
156
|
+
/**
|
|
157
|
+
* 创建编排面板 Surface
|
|
158
|
+
*/
|
|
159
|
+
declare function createOrchestrationSurface(rootId: string, components: ComponentInstance[]): SurfaceResult;
|
|
160
|
+
/**
|
|
161
|
+
* 创建状态提示 Surface
|
|
162
|
+
*/
|
|
163
|
+
declare function createStatusSurface(rootId: string, components: ComponentInstance[]): SurfaceResult;
|
|
164
|
+
|
|
165
|
+
export { SURFACE_IDS, type SurfaceConfig, type SurfaceIdType, type SurfaceResult, createA2UISurface, createA2UISurfaceWithData, createChatSurface, createDeleteSurfaceMessage, createInputFormSurface, createOrchestrationSurface, createRecommendationSurface, createStatusSurface, generateSurfaceId, resetSurfaceIdCounter };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a={CHAT:"@chat",RECOMMENDATION:"@recommendation",INPUT_FORM:"@input-form",ORCHESTRATION:"@orchestration",STATUS:"@status",RESULT:"@result",CONFIRM:"@confirm",NOTIFICATION:"@notification"},c=0;function i(e="surface"){return c++,`${e}-${Date.now()}-${c}`}function S(){c=0;}var p="https://a2ui.dev/specification/0.9/standard_catalog_definition.json";function u(e,t=p){return {createSurface:{surfaceId:e,catalogId:t}}}function g(e,t){return {updateComponents:{surfaceId:e,components:t}}}function f(e,t,r,n="replace"){return {updateDataModel:{surfaceId:e,...r,op:n,...n!=="remove"&&{value:t}}}}function d(e){return {deleteSurface:{surfaceId:e}}}function o(e,t,r){let n=r??i();return t.find(l=>l.id===e)||console.warn(`[A2UI] Root component "${e}" not found in components list`),{messages:[u(n),g(n,t)],surfaceId:n}}function C(e,t,r,n){let s=n??i();return {messages:[u(s),g(s,t),f(s,r)],surfaceId:s}}function M(e){return d(e)}function I(e,t){return o(e,t,a.CHAT)}function T(e,t){return o(e,t,a.RECOMMENDATION)}function D(e,t){return o(e,t,a.INPUT_FORM)}function x(e,t){return o(e,t,a.ORCHESTRATION)}function A(e,t){return o(e,t,a.STATUS)}
|
|
2
|
+
export{a as SURFACE_IDS,o as createA2UISurface,C as createA2UISurfaceWithData,I as createChatSurface,M as createDeleteSurfaceMessage,D as createInputFormSurface,x as createOrchestrationSurface,T as createRecommendationSurface,A as createStatusSurface,i as generateSurfaceId,S as resetSurfaceIdCounter};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhama/a2ui-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A2UI Protocol Core Library - Framework-agnostic TypeScript types and builders for A2UI protocol",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -36,6 +36,12 @@
|
|
|
36
36
|
"import": "./dist/utils/index.js",
|
|
37
37
|
"require": "./dist/utils/index.cjs",
|
|
38
38
|
"default": "./dist/utils/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./surface": {
|
|
41
|
+
"types": "./dist/surface/index.d.ts",
|
|
42
|
+
"import": "./dist/surface/index.js",
|
|
43
|
+
"require": "./dist/surface/index.cjs",
|
|
44
|
+
"default": "./dist/surface/index.js"
|
|
39
45
|
}
|
|
40
46
|
},
|
|
41
47
|
"files": [
|