-
Notifications
You must be signed in to change notification settings - Fork 1k
Angular v0.9 Renderer #878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dc38d42
feat: Add Angular v0.9 renderer and a2ui_explorer sample
gspencergoog 4c2eef0
Fix tests, add test script
gspencergoog 8a92f68
Remove unneeded file
gspencergoog 7978d42
Update docs
gspencergoog 1636dfc
Rename AngularComponentApi => AngularComponentImplementation
gspencergoog 56e2de2
feat(angular): add SurfaceComponent and default componentId to root
gspencergoog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| a2ui_explorer/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,84 @@ | ||
| Angular implementation of A2UI. | ||
| # A2UI Angular Renderer | ||
|
|
||
| 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. | ||
| The Angular implementation of the A2UI framework, providing seamless integration of agent-generated UI into Angular applications. | ||
|
|
||
| ## Getting Started | ||
|
|
||
| ### Installation | ||
|
|
||
| ```bash | ||
| npm install @a2ui/angular @a2ui/web_core | ||
| ``` | ||
|
|
||
| ### Protocol Versioning | ||
|
|
||
| A2UI supports multiple protocol versions. To use a specific version, use the versioned import path: | ||
|
|
||
| ```typescript | ||
| // Use the v0.9 implementation | ||
| import { A2uiRendererService, A2UI_RENDERER_CONFIG } from '@a2ui/angular/v0_9'; | ||
| import { minimalCatalog } from '@a2ui/angular/v0_9'; | ||
| ``` | ||
|
|
||
| ## Basic Setup | ||
|
|
||
| Configure the renderer in your `app.config.ts` using the `A2UI_RENDERER_CONFIG` injection token: | ||
|
|
||
| ```typescript | ||
| import { ApplicationConfig } from '@angular/core'; | ||
| import { A2UI_RENDERER_CONFIG, A2uiRendererService, minimalCatalog } from '@a2ui/angular/v0_9'; | ||
|
|
||
| export const appConfig: ApplicationConfig = { | ||
| providers: [ | ||
| { | ||
| provide: A2UI_RENDERER_CONFIG, | ||
| useValue: { | ||
| catalogs: [minimalCatalog], | ||
| actionHandler: (action) => { | ||
| console.log('Action received:', action); | ||
| } | ||
| } | ||
| }, | ||
| A2uiRendererService | ||
| ] | ||
| }; | ||
| ``` | ||
|
|
||
| ## Rendering Surfaces | ||
|
|
||
| Use the `a2ui-v09-component-host` component to render individual A2UI components within your application: | ||
|
|
||
| ```typescript | ||
| import { Component } from '@angular/core'; | ||
| import { ComponentHostComponent } from '@a2ui/angular/v0_9'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-root', | ||
| standalone: true, | ||
| imports: [ComponentHostComponent], | ||
| template: ` | ||
| <a2ui-v09-component-host | ||
| surfaceId="my-surface-id" | ||
| componentId="my-component-id" | ||
| /> | ||
| ` | ||
| }) | ||
| export class AppComponent {} | ||
| ``` | ||
|
|
||
| ## Core Concepts | ||
|
|
||
| - **A2uiRendererService**: The central service that manages the connection to the A2UI Message Processor and tracks surface state. | ||
| - **ComponentHostComponent**: A wrapper component that dynamically renders A2UI components based on the current surface model. | ||
| - **Catalogs**: Collections of Angular components mapped to A2UI component types. | ||
|
|
||
| ## 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. | ||
| **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. |
Binary file not shown.
29 changes: 29 additions & 0 deletions
29
renderers/angular/a2ui_explorer/src/app/action-dispatcher.service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { Injectable } from '@angular/core'; | ||
| import { Subject } from 'rxjs'; | ||
| import { SurfaceGroupAction } from '@a2ui/web_core/v0_9'; | ||
|
|
||
| @Injectable({ providedIn: 'root' }) | ||
| export class ActionDispatcher { | ||
| private action$ = new Subject<SurfaceGroupAction>(); | ||
| actions = this.action$.asObservable(); | ||
|
|
||
| dispatch(action: SurfaceGroupAction) { | ||
| this.action$.next(action); | ||
| } | ||
| } |
126 changes: 126 additions & 0 deletions
126
renderers/angular/a2ui_explorer/src/app/agent-stub.service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| /** | ||
| * Copyright 2026 Google LLC | ||
gspencergoog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { Injectable } from '@angular/core'; | ||
| import { A2uiRendererService } from '@a2ui/angular/v0_9'; | ||
| import { SurfaceGroupAction, A2uiMessage } from '@a2ui/web_core/v0_9'; | ||
| import { ActionDispatcher } from './action-dispatcher.service'; | ||
|
|
||
| /** | ||
| * Context for the 'update_property' event. | ||
| */ | ||
| interface UpdatePropertyContext { | ||
| path: string; | ||
| value: any; | ||
| surfaceId?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Context for the 'submit_form' event. | ||
| */ | ||
| interface SubmitFormContext { | ||
| [key: string]: any; | ||
| name?: string; | ||
| } | ||
|
|
||
| /** | ||
| * A stub service that simulates an A2UI agent. | ||
| * It listens for actions and responds with data model updates or new surfaces. | ||
| */ | ||
| @Injectable({ | ||
| providedIn: 'root', | ||
| }) | ||
| export class AgentStubService { | ||
| /** Log of actions received from the surface. */ | ||
| actionsLog: Array<{ timestamp: Date; action: SurfaceGroupAction }> = []; | ||
|
|
||
| constructor( | ||
| private rendererService: A2uiRendererService, | ||
| private dispatcher: ActionDispatcher, | ||
| ) { | ||
| // Subscribe to actions dispatched by the renderer | ||
| this.dispatcher.actions.subscribe((action) => this.handleAction(action)); | ||
| } | ||
|
|
||
| /** | ||
| * Pushes actions triggered from the rendered Canvas frame through simulation. | ||
| * - Logs actions into inspector event frame aggregates. | ||
| * - Emulates generic server-side evaluation triggers delaying deferred updates. | ||
| * - Dispatch subsequent node-tree node triggers back over `A2uiRendererService`. | ||
| */ | ||
| handleAction(action: SurfaceGroupAction) { | ||
| console.log('[AgentStub] handleAction action:', action); | ||
| this.actionsLog.push({ timestamp: new Date(), action }); | ||
|
|
||
| // Simulate server processing delay | ||
| setTimeout(() => { | ||
| if ('event' in action) { | ||
| const { name, context } = action.event; | ||
| if (name === 'update_property' && context) { | ||
| const { path, value, surfaceId } = context as unknown as UpdatePropertyContext; | ||
| console.log( | ||
| '[AgentStub] update_property path:', | ||
| path, | ||
| 'value:', | ||
| value, | ||
| 'surfaceId:', | ||
| surfaceId, | ||
| ); | ||
| this.rendererService.processMessages([ | ||
| { | ||
| version: 'v0.9', | ||
| updateDataModel: { | ||
| surfaceId: surfaceId || action.surfaceId, | ||
| path: path, | ||
| value: value, | ||
| }, | ||
| }, | ||
| ]); | ||
| } else if (name === 'submit_form' && context) { | ||
| const formData = context as unknown as SubmitFormContext; | ||
| const nameValue = formData.name || 'Anonymous'; | ||
|
|
||
| // Respond with an update to the data model in v0.9 layout | ||
| this.rendererService.processMessages([ | ||
| { | ||
| version: 'v0.9', | ||
| updateDataModel: { | ||
| surfaceId: action.surfaceId, | ||
| path: '/form/submitted', | ||
| value: true, | ||
| }, | ||
| }, | ||
| { | ||
| version: 'v0.9', | ||
| updateDataModel: { | ||
| surfaceId: action.surfaceId, | ||
| path: '/form/responseMessage', | ||
| value: `Hello, ${nameValue}! Your form has been processed.`, | ||
| }, | ||
| }, | ||
| ]); | ||
| } | ||
| } | ||
| }, 50); // Shorter delay for property updates | ||
| } | ||
|
|
||
| /** | ||
| * Initializes a demo session with an initial set of messages. | ||
| */ | ||
| initializeDemo(initialMessages: A2uiMessage[]) { | ||
| this.rendererService.processMessages(initialMessages); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * Copyright 2026 Google LLC | ||
gspencergoog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { ApplicationConfig, provideBrowserGlobalErrorListeners } from '@angular/core'; | ||
|
|
||
| export const appConfig: ApplicationConfig = { | ||
| providers: [provideBrowserGlobalErrorListeners()], | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This is great.