@a2ui/angular

中文文档
0.14.0发布于 2026/11/02Apache-2.0TypeScriptES Module近 30 天下载 7万

The Angular implementation of the A2UI framework, providing seamless integration of agent-generated UI into Angular applications.

原始使用文档
文档目录10 节
  1. Features
  2. Installation
  3. Protocol Versioning
  4. Basic Setup
  5. Usage
  6. Rendering a Surface
  7. Dynamic Component Hosting
  8. Core Service: A2uiRendererService
  9. Basic Catalog Components
  10. Security

A2UI Angular Renderer

The Angular implementation of the A2UI framework, providing seamless integration of agent-generated UI into Angular applications.

Features

  • Reactive Rendering: Uses Angular Signals for efficient, fine-grained UI updates.
  • Dynamic Component Resolution: Maps A2UI component types to Angular components via extensible catalogs.
  • Surface Management: Built-in support for multiple independent UI surfaces within a single session.
  • Action Handling: Simple callback-based integration for handling agent-dispatched actions.

Installation

yarn add @a2ui/angular @a2ui/web_core

Protocol Versioning

A2UI supports multiple protocol versions to ensure backward compatibility as the framework evolves. The root @a2ui/angular package provides version-agnostic surface management, component hosting, and the latest standard catalog.

import {A2uiRendererService, A2UI_RENDERER_CONFIG, BasicCatalog} from '@a2ui/angular';

For backward compatibility with prior protocol versions, version-specific subpaths are available:

  • @a2ui/angular/v0_9: v0.9 protocol and native catalog
  • @a2ui/angular/v0_8: v0.8 protocol and native catalog

Basic Setup

Configure the renderer in your app.config.ts using the A2UI_RENDERER_CONFIG injection token:

import {ApplicationConfig} from '@angular/core';
import {A2UI_RENDERER_CONFIG, A2uiRendererService, BasicCatalog} from '@a2ui/angular';

export const appConfig: ApplicationConfig = {
  providers: [
    {
      provide: A2UI_RENDERER_CONFIG,
      useValue: {
        catalogs: [new BasicCatalog()],
        actionHandler: action => {
          console.log('Action received:', action);
        },
      },
    },
    A2uiRendererService,
  ],
};

Usage

Rendering a Surface

The simplest way to render an A2UI surface is using the SurfaceComponent. This component handles setting up the root ComponentHost for you.

import {Component} from '@angular/core';
import {SurfaceComponent} from '@a2ui/angular/v0_9';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [SurfaceComponent],
  template: ` <a2ui-v09-surface surfaceId="main-surface" /> `,
})
export class AppComponent {}

Dynamic Component Hosting

For more fine-grained control, use the ComponentHostComponent to render specific components within a surface:

import {Component} from '@angular/core';
import {ComponentHostComponent} from '@a2ui/angular/v0_9';

@Component({
  selector: 'app-custom-layout',
  standalone: true,
  imports: [ComponentHostComponent],
  template: `
    <div class="user-sidebar">
      <a2ui-v09-component-host surfaceId="main-surface" componentId="sidebar-config" />
    </div>
  `,
})
export class CustomLayoutComponent {}

Core Service: A2uiRendererService

The A2uiRendererService is the heart of the Angular renderer. It bridges the A2UI MessageProcessor to Angular's reactive system.

  • processMessages(messages: Message[]): Ingest messages from the agent to update the UI surfaces.
  • surfaceGroup(): Returns the SurfaceGroupModel containing the current state of all surfaces.

Basic Catalog Components

The @a2ui/angular/v0_9 package includes a BasicCatalog with the following standard components:

  • Layout: Row, Column, List, Card, Tabs, Modal, Divider
  • Content: Text, Image, Icon, Video, AudioPlayer
  • Input: Button, TextField, CheckBox, ChoicePicker, Slider, DateTimeInput

Security

[!IMPORTANT] The sample code provided is for demonstration purposes and illustrates the mechanics of A2UI and the Agent-to-Agent (A2A) protocol. When building production applications, it is critical to treat any agent operating outside of your direct control as a potentially untrusted entity.

All operational data received from an external agent—including its AgentCard, messages, artifacts, and task statuses—should be handled as untrusted input. For example, a malicious agent could provide crafted data in its fields (e.g., name, skills.description) that, if used without sanitization to construct prompts for a Large Language Model (LLM), could expose your application to prompt injection attacks.

Similarly, any UI definition or data stream received must be treated as untrusted. Malicious agents could attempt to spoof legitimate interfaces to deceive users (phishing), inject malicious scripts via property values (XSS), or generate excessive layout complexity to degrade client performance (DoS). If your application supports optional embedded content (such as iframes or web views), additional care must be taken to prevent exposure to malicious external sites.

Developer Responsibility: Failure to properly validate data and strictly sandbox rendered content can introduce severe vulnerabilities. Developers are responsible for implementing appropriate security measures—such as input sanitization, Content Security Policies (CSP), strict isolation for optional embedded content, and secure credential handling—to protect their systems and users.

版本与发布记录

@a2ui/angular 共发布 23 个版本,首次发布于 2025/12/16;过去 12 个月发布了 23 个版本。

版本发布日期距今
0.14.0latest2026/11/024 天前
0.13.02026/10/1720 天前
0.12.02026/10/1027 天前
0.11.02026/09/291 个月前
0.10.72026/09/121 个月前
0.10.62026/09/012 个月前

关于 @a2ui/angular 的常见问题

@a2ui/angular 是什么?

The Angular implementation of the A2UI framework, providing seamless integration of agent-generated UI into Angular applications.

如何安装 @a2ui/angular?

在项目目录运行 npm install @a2ui/angular,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/core(^21.2.5)、@angular/common(^21.2.5)、@angular/platform-browser(^21.2.5)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@a2ui/angular 支持 TypeScript 吗?

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

@a2ui/angular 支持 ESM 还是 CommonJS?

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

@a2ui/angular 可以商用吗?

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

@a2ui/angular 的下载量有多少?

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

@a2ui/angular 还在维护吗?

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