通用属性参考:通用属性
Box 组件作为容器,用于管理 Card 实例和命令分发。
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| children | 子元素 | React.ReactNode | - | - |
| components | 自定义组件映射,组件名称必须以大写字母开头 | Record<string, React.ComponentType<any>> | - | - |
| commands | A2UI 命令对象 | A2UICommand_v0_9 | XAgentCommand_v0_8 | - | - |
| onAction | Card 内部组件触发 action 时的回调函数 | (payload: ActionPayload) => void | - | - |
Card 组件用于渲染单个 Surface。
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| id | Surface ID,对应命令中的 surfaceId | string | - | - |
action 事件的数据结构。
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| name | 事件名称 | string | - | - |
| surfaceId | 触发该 action 的 surfaceId | string | - | - |
| context | 组件传递的上下文,已解析 path 引用 | Record<string, any> | - | - |
当组件触发 action 时,X-Card 会自动解析 context 中的 path 引用为实际值。
在 action 配置中使用 { path: string } 格式绑定 dataModel 中的值:
{"id": "submit-btn","component": "Button","action": {"event": {"name": "agent:send_context_text","context": {"username": { "path": "/form/username", "label": "用户名" },"email": { "path": "/form/email", "label": "邮箱" }}}}}
当用户点击按钮触发 action 时,onAction 回调收到的 context 会被自动解析:
{"username": { "value": "张三", "label": "用户名" },"email": { "value": "test@example.com", "label": "邮箱" }}
注意:
{ path: "xxx" } 格式时才进行转换{ value: "实际值" })不会被错误转换v0.9 版本的命令类型,支持以下命令:
创建新的 Surface。
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| version | 版本号 | 'v0.9' | - | - |
| createSurface.surfaceId | Surface ID | string | - | - |
| createSurface.catalogId | 组件目录 URL 或本地标识 | string | - | - |
更新 Surface 上的组件。
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| version | 版本号 | 'v0.9' | - | - |
| updateComponents.surfaceId | Surface ID | string | - | - |
| updateComponents.components | 组件列表 | BaseComponent_v0_9[] | - | - |
interface BaseComponent_v0_9 {id: string;component: string;child?: string;children?: string[];[key: string]: any | PathValue;}
更新数据模型。
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| version | 版本号 | 'v0.9' | - | - |
| updateDataModel.surfaceId | Surface ID | string | - | - |
| updateDataModel.path | 数据路径 | string | - | - |
| updateDataModel.value | 数据值 | any | - | - |
删除 Surface。
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| version | 版本号 | 'v0.9' | - | - |
| deleteSurface.surfaceId | Surface ID | string | - | - |
数据绑定路径对象。
interface PathValue {path: string;}
组件目录定义。
interface Catalog {$schema?: string;$id?: string;title?: string;description?: string;catalogId?: string;components?: Record<string, CatalogComponent>;functions?: Record<string, any>;$defs?: Record<string, any>;}
Catalog 中的组件定义。
interface CatalogComponent {type: 'object';allOf?: any[];properties?: Record<string, any>;required?: string[];[key: string]: any;}
注册本地 catalog。
registerCatalog(catalog: Catalog): void
加载 catalog(支持远程 URL 或本地注册的 schema)。
loadCatalog(catalogId: string): Promise<Catalog>
验证组件是否符合 catalog 定义。
validateComponent(catalog: Catalog, componentName: string, componentProps: Record<string, any>): boolean
清除 catalog 缓存。
clearCatalogCache(): void