@a2ui-sdk/types

中文文档
0.4.0发布于 2026/02/02Apache-2.0TypeScriptES Module零依赖近 30 天下载 7.6万

A2UI 类型

中文使用文档
文档目录12 节
  1. 安装
  2. 使用量
  3. v0.9 (最晚) (中文(简体) )
  4. v. 0.8 (中文(简体) )
  5. 命名空间导入
  6. 密钥类型
  7. A2UIMessage (v0.9) (英语)
  8. 动态值( v0. 9)
  9. 数值来源(v0.8)
  10. 动作付费负荷
  11. 范围值(v0.8+)
  12. 许可证

@ a2ui- sdk/ 类型

A2UI协议的TypeScript类型定义. 这个包提供了与A2UI消息,组件和数据模型合作所需的所有类型定义.

安装

npm install @a2ui-sdk/types

使用量

v0.9 (最晚) (中文(简体) )

import type {
  // Message types
  A2UIMessage,
  CreateSurfacePayload,
  UpdateComponentsPayload,
  UpdateDataModelPayload,
  DeleteSurfacePayload,

  // Component types
  Component,
  TextComponent,
  ImageComponent,
  IconComponent,
  VideoComponent,
  AudioPlayerComponent,
  DividerComponent,
  RowComponent,
  ColumnComponent,
  ListComponent,
  CardComponent,
  TabsComponent,
  ModalComponent,
  ButtonComponent,
  TextFieldComponent,
  CheckBoxComponent,
  ChoicePickerComponent,
  SliderComponent,
  DateTimeInputComponent,

  // Value types
  DynamicValue,
  DynamicString,
  DynamicNumber,
  DynamicBoolean,
  DynamicStringList,
  ChildList,
  TemplateBinding,

  // Action types
  Action,
  ActionPayload,
  ActionHandler,

  // Validation types
  CheckRule,
  Checkable,
  ValidationResult,

  // State types
  ScopeValue,
  DataModel,
} from '@a2ui-sdk/types/0.9'

v. 0.8 (中文(简体) )

import type {
  // Message types
  A2UIMessage,
  BeginRenderingPayload,
  SurfaceUpdatePayload,
  DataModelUpdatePayload,
  DeleteSurfacePayload,

  // Core types
  Surface,
  SurfaceStyles,
  ComponentDefinition,
  ComponentProps,
  ValueSource,
  DataModel,
  DataModelValue,
  DataEntry,

  // Children types
  ChildrenDefinition,
  TemplateBinding,

  // Action types
  Action,
  ActionPayload,
  ActionHandler,
  ActionContextItem,

  // Component props
  BaseComponentProps,
  TextComponentProps,
  ImageComponentProps,
  IconComponentProps,
  VideoComponentProps,
  AudioPlayerComponentProps,
  DividerComponentProps,
  RowComponentProps,
  ColumnComponentProps,
  ListComponentProps,
  CardComponentProps,
  TabsComponentProps,
  ModalComponentProps,
  ButtonComponentProps,
  CheckBoxComponentProps,
  TextFieldComponentProps,
  DateTimeInputComponentProps,
  MultipleChoiceComponentProps,
  SliderComponentProps,

  // Layout types
  Distribution,
  Alignment,

  // State types
  ScopeValue,
} from '@a2ui-sdk/types/0.8'

命名空间导入

import { v0_8, v0_9 } from '@a2ui-sdk/types'

// Use v0.9 types
type Message = v0_9.A2UIMessage

密钥类型

A2UIMessage (v0.9) (英语)

从服务器发送到客户端的信件 :

type A2UIMessage =
  | { createSurface: CreateSurfacePayload }
  | { updateComponents: UpdateComponentsPayload }
  | { updateDataModel: UpdateDataModelPayload }
  | { deleteSurface: DeleteSurfacePayload }

动态值( v0. 9)

可以静态或数据绑定的值:

// Static string or path reference
type DynamicString = string | { path: string } | FunctionCall

// Static number or path reference
type DynamicNumber = number | { path: string } | FunctionCall

// Static boolean or logic expression
type DynamicBoolean = boolean | { path: string } | LogicExpression

数值来源(v0.8)

遗留值绑定 :

type ValueSource =
  | { literalString: string }
  | { literalNumber: number }
  | { literalBoolean: boolean }
  | { literalArray: string[] }
  | { path: string }

动作付费负荷

从客户端发送到服务器的动作 :

interface ActionPayload {
  name: string
  surfaceId: string
  sourceComponentId: string
  timestamp: string // ISO 8601
  context: Record<string, unknown>
}

范围值(v0.8+)

收集项目渲染的范围:

interface ScopeValue {
  /**
   * Base path for relative path resolution.
   * null = root scope (no scoping)
   * string = scoped to a specific data path (e.g., "/items/0")
   */
  basePath: string | null
}

内部用于支持模板交接子的相对路径(列表,行,有模板绑定的列).

许可证

阿帕奇 - 2.0

版本与发布记录

@a2ui-sdk/types 共发布 11 个版本,首次发布于 2026/01/13;过去 12 个月发布了 11 个版本。

版本发布日期距今
0.4.0latest2026/02/029 个月前
0.3.12026/02/029 个月前
0.3.02026/01/289 个月前
0.2.22026/01/279 个月前
0.2.12026/01/149 个月前
0.2.02026/01/149 个月前

关于 @a2ui-sdk/types 的常见问题

@a2ui-sdk/types 是什么?

A2UI 类型

如何安装 @a2ui-sdk/types?

在项目目录运行 npm install @a2ui-sdk/types,或使用 pnpm add / yarn add / bun add。

@a2ui-sdk/types 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@a2ui-sdk/types 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@a2ui-sdk/types 可以商用吗?

@a2ui-sdk/types 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@a2ui-sdk/types 的下载量有多少?

根据 npm 官方下载统计,@a2ui-sdk/types 在 2026/10/05 – 2026/11/03 这 30 天内被下载 75,830 次,日均约 2,528 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@a2ui-sdk/types 还在维护吗?

最新版本 0.4.0 发布于 2026/02/02(9 个月前);至今共发布 11 个版本,其中过去 12 个月发布了 11 个;首次发布于 2026/01/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。