Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces a React renderer for A2UI, aiming for consistency with existing Lit, Angular, and Flutter renderers. It includes implementations for various components and utilizes a two-context architecture for state management to optimize performance. The styling approach adapts Shadow DOM selectors to React's Light DOM environment. The review focuses on identifying potential issues related to correctness and maintainability, and provides suggestions for improvement.
bbaefd0 to
3acfc9b
Compare
|
|
||
| let result = html; | ||
| for (const [regex, replacement] of replacements) { | ||
| result = result.replace(regex, replacement); |
There was a problem hiding this comment.
If I'm understanding this method correctly, it's looking at the rendered markdown and applying classnames to certain tag names through regexes.
This looks quite brittle and a pain to maintain! There's an example in the markdown-it on how to apply CSS classnames to elements through the renderer rules, here:
This is a similar approach to what the Lit renderer is doing here:
A2UI/renderers/lit/src/0.8/ui/directives/markdown.ts
Lines 103 to 117 in 9c35418
I'd suggest this step to be done by leveraging the existing markdown-it API, rather than doing string manipulations.
There was a problem hiding this comment.
Thank's for the suggestion! We've replaced applyMarkdownTheme with markdown-it's renderer rules API, using token.attrJoin() on _open tokens before rendering and cleaning up afterward.
This should now mirror the Lit renderer's #applyTagClassMap pattern.
| /* ========================================================================= | ||
| * Card (from Lit card.ts static styles) | ||
| * ========================================================================= */ |
There was a problem hiding this comment.
Why are these comments part of the output string?
There was a problem hiding this comment.
Fair point, they were developer notes explaining the transformation from Lit to React
-> I moved them into the JSDoc above.
ditman
left a comment
There was a problem hiding this comment.
Thanks for the PR! I left some comments about the handling of markdown in the Text widget on my first quick look to this, but more knowledgeable people should actually dive deeper than that :)
There's some brittleness by grabbing the structural styles directly from the lit renderer, but then maintaining a list of the classnames to be added to each markdown element in this repository; I wonder if some of those might make sense to be moved to a shared package somehow (this is not for this PR, of course)
|
I'm actually working on decoupling the Markdown rendering from the lit and angular renderers here, and I'm planning to do the same to the React renderer once it lands: |
gspencergoog
left a comment
There was a problem hiding this comment.
This looks reasonable to me, but I'm not familiar with React, so I'm going to abstain from approving anything here.
4e6363d to
f806ccb
Compare
There was a problem hiding this comment.
Code Review
This is a substantial pull request that introduces a new React renderer for A2UI, along with significant enhancements to the Python agent's schema management and validation capabilities. The new React renderer is well-architected, using a two-context pattern for performance and providing a comprehensive set of components. The Python agent changes improve schema validation robustness and build process. I've identified a potential bug in a file path for schema loading, a missing CODEOWNERS entry for the new renderer, and a minor architectural improvement to address a circular dependency. Overall, this is an excellent contribution.
| potential_path = os.path.abspath( | ||
| os.path.join( | ||
| os.path.dirname(__file__), | ||
| "..", |
There was a problem hiding this comment.
The relative path used in the "Local Assets" fallback logic for loading schemas appears to be incorrect. The path is constructed using os.path.join(os.path.dirname(__file__), "..", "assets", ...).
Given that this file is at src/a2ui/inference/schema/manager.py, going up one level (..) lands in src/a2ui/inference/. The assets directory is a sibling of inference, not a child. The path should likely go up two levels (../..) to reach src/a2ui/ before descending into assets/.
This could cause the fallback loading mechanism to fail when running from source if package resources are not available.
"..",
".."| def validator(self) -> "A2uiValidator": | ||
| from .validator import A2uiValidator | ||
|
|
||
| return A2uiValidator(self) |
There was a problem hiding this comment.
The validator property creates a runtime circular dependency between A2uiCatalog and A2uiValidator by using a local import inside the method. While this pattern works, it can make the code harder to reason about and maintain.
Consider refactoring to break the cycle, for example by using dependency injection: the A2uiValidator instance could be created separately and passed to the A2uiCatalog during its initialization, or a factory function could be used to construct both objects.
ava-cassiopeia
left a comment
There was a problem hiding this comment.
Looks like there's a large number of file conflicts, could you please rebase this and fix those?
Prevents stale 504 errors when file: dependencies are rebuilt by setting optimizeDeps.force in both vite configs.
ditman
left a comment
There was a problem hiding this comment.
I don't see anything that stands out anymore. If @ava-cassiopeia is happy, and you guys believe the API is idiomatic enough for React JS, I think this can land!
Thanks for all the updates! Please, take into consideration that I did a small update to the react rendering on web_core, so once packages publish, we might need to do an update to the dependencies of the test apps here! (I left a link to my PR with the change in comments below)
| // provide the theme directly on a component that renders a2ui-surface as a child | ||
| @customElement('themed-a2ui-surface') | ||
| class ThemedA2UISurface extends LitElement { | ||
| @provide({ context: UI.Context.themeContext }) |
There was a problem hiding this comment.
I changed a little bit the renderMarkdown method (made it async), this might break slightly until all the packages are at the right revisions. If using a NPM dependency, we should be fine for now! Once the new web_core and markdown-it packages update, we might need a dependency on markdown-it 0.0.2 which has the async implementation of the renderMarkdown function.
Apologies for this change, I realized too late that I need the renderMarkdown to be asynchronous for google's markdown rendering to work properly 🤦
See this:
(Only dep changes would be needed, nothing on the actual code of the app)
|
I'm going to take one more pass at this, but I think I'm pretty happy with the state of this, and it looks like pretty idiomatic React to me. |
ava-cassiopeia
left a comment
There was a problem hiding this comment.
There's a few small changes I want to make to this before we merge it - this needs Google copyright notices in the source code files, and I'll run a few of these markdown files through our formatter.
Otherwise, LGTM. Thanks for your contributions and your patience while we get this landed!
|
Oh darn, looks like there's a merge conflict on the codeowners now. @lukasmoschitz can you sort that out so I don't have to create another PR on Copilotkit (lol)? |
- Replace require('gts') with ESM import in eslint.config.js
- Disable prefer-arrow-callback to preserve React.memo display names
- Exclude .d.ts files from linting
- Fix floating promise in A2UIProvider dispatch
React renderer PR google#542 is still open and not by CopilotKit. Composer was contributed by maxkorp (@CopilotKit).
- React renderer PR google#542 merged — update status to Stable across all pages - Add React section to client-setup guide - Expand community renderer submission with step-by-step instructions - Replace community showcase placeholder with concrete guidance + sample links - Collapse duplicate partner info in community.md (points to a2ui-in-the-world) - Fix typo (signiciant → significant) - Tighten how-to-use wording, fix Angular install (add @a2ui/web-lib)
…dates (#776) * docs: reorganize files to match nav sections - Move catalogs, transports, client_to_server_actions → concepts/ - Move renderers, agents → reference/ - Move where-is-it-used, community → ecosystem/ - Rewrite agent-ui-ecosystem as concise 'How Does A2UI Compare?' intro page - Move third-party integrations (json-render, OpenClaw) to ecosystem - Fix all cross-references for moved files - Remove duplicate nav entries (each page appears once) * docs: refine How Does A2UI Compare page - native-first → declarative UI, clarify host controls styling - MCP Apps: clarify remote controls content, config via tool calling - AG UI: credit CopilotKit team, React renderer, Composer contributions - ChatKit: note shared design philosophy (basic components, declarative) * docs: restore comparison table as At a Glance section * docs: rename 'Where is A2UI Used?' → 'A2UI in the World' * docs: rename where-is-it-used → a2ui-in-the-world, MCP SEP-1865 citation * docs: add Google ADK section to A2UI in the World ADK Web has native A2UI rendering and A2A↔A2UI message conversion. Links to ADK docs, adk-web repo, and agent development guide. * docs: fix CopilotKit attribution — Composer yes, React renderer no React renderer PR #542 is still open and not by CopilotKit. Composer was contributed by maxkorp (@CopilotKit). * docs: React renderer status — In Review, link to PR #542 * docs: add redirects for all moved files Old URLs now redirect to new locations: - catalogs, transports, actions → concepts/ - renderers, agents → reference/ - community → ecosystem/ - where-is-it-used → ecosystem/a2ui-in-the-world * docs: React renderer merged, contribution guide, writing fixes - React renderer PR #542 merged — update status to Stable across all pages - Add React section to client-setup guide - Expand community renderer submission with step-by-step instructions - Replace community showcase placeholder with concrete guidance + sample links - Collapse duplicate partner info in community.md (points to a2ui-in-the-world) - Fix typo (signiciant → significant) - Tighten how-to-use wording, fix Angular install (add @a2ui/web-lib) * docs: add web_core shared library section to renderer development guide Explains what @a2ui/web-lib (web_core) provides, how Lit/Angular/React renderers use it, and why new web renderers should start from it rather than reimplementing message processing and state management. * docs: link renderer names to source in client-setup table * docs: remove stars and last-updated columns from community renderers table * docs: fix ChatKit link to point to actual docs instead of openai.com homepage * docs: add live shields.io badges for stars and last-commit to community renderers * docs: fix broken React sample link, fix relative path in ecosystem --------- Co-authored-by: Zaf <zaf@0-a.org>
|
@lukasmoschitz shouldn’t this be published on npm? The README says |
Thanks @timoslanitis-aisera for the heads up. We still had a few issues to sort out, but the npm package should be available soon. |
|
@lukasmoschitz |
|
I'm planning on publishing this to NPM today (US time, sometime within the next 8 hours after this comment's timestamp, lol) |
|
Published: https://www.npmjs.com/package/@a2ui/react |
* Add React renderer implementation * Improve React renderer with visual parity and tests - Refactor components to mirror Lit Shadow DOM structure for visual parity - Add CSS fixes for specificity and selector transformations - Add unit tests for all components (220 tests) - Add visual parity test infrastructure with Playwright - Update documentation with build and test instructions * Enable checkboxUnchecked visual parity test The Lit renderer bug has been fixed, so this fixture no longer needs to be skipped. * Update Icon component description to Material Symbols The Icon component uses Material Symbols Outlined font, not Lucide. * Update PARITY.md: add CheckBox and DateTimeInput to implemented components * Add unit tests for Tabs and Modal components - Add comprehensive Tabs tests (21 tests): rendering, tab selection, switching behavior, nested content, edge cases, accessibility - Add comprehensive Modal tests (21 tests): opening/closing, backdrop click, Escape key, nested content, portal rendering, accessibility - Theme tests document that empty theme classes are intentional (styling from structural CSS) * Add ThemeContext tests to verify theme switching - Add tests verifying components read theme from context, not hardcoded - Test custom theme classes applied to: Button, Card, Text, Column, Row, TextField, CheckBox, Tabs, Divider, Icon, Slider, MultipleChoice - Test theme isolation between different provider instances - Catches bugs where components import litTheme directly vs useTheme() * Fix path binding reactivity and add communication tests - useA2UIComponent now subscribes to state version via useA2UIState() ensuring components with path bindings re-render when data changes - Add comprehensive server-client communication tests (28 tests) covering message processing, multiple surfaces, dataModelUpdate, deleteSurface, path bindings, action dispatch, and error handling - Add createDataModelUpdate and createDeleteSurface test helpers - Update README with path binding reactivity documentation * Refactor test structure into unit and integration directories - Move component tests to tests/unit/components/ - Split communication.test.tsx into focused integration tests: - messages.test.tsx: basic message processing - data-binding.test.tsx: data model and path bindings - actions.test.tsx: action dispatch - components.test.tsx: component updates, nesting, errors - hooks.test.tsx: context hooks behavior - templates.test.tsx: template expansion tests - Move ThemeContext.test.tsx to tests/integration/ - Extract shared utilities to tests/utils/: - render.tsx: TestWrapper, TestRenderer - messages.ts: message factory functions - assertions.ts: type-safe getMockCallArg, getElement helpers - Update tsconfig.json to include tests directory and add types * Add ESLint and Prettier configuration - Add eslint.config.js with TypeScript, React, and React Hooks rules - Add .prettierrc for consistent code formatting - Add lint, lint:fix, format, and format:check scripts - Remove duplicate clsx and markdown-it from devDependencies - Add sideEffects field for proper tree-shaking - Add engines field requiring Node.js >= 18 * Update dependencies and clean up tsconfig - Update vitest to 4.x and jsdom to 28.x - Remove unused tsconfig options (declaration, declarationMap, sourceMap) - Update visual-parity dependencies: - vite 5.x → 7.x - @vitejs/plugin-react 4.x → 5.x - pixelmatch 5.x → 7.x - concurrently 8.x → 9.x - @playwright/test 1.57 → 1.58 * Fix ESLint errors and warnings - Fix ComponentNode: move useMemo before conditional return (Rules of Hooks) - Fix TextField: prefix unused isValid state with underscore - Auto-fix type imports in A2UIProvider and A2UIRenderer - Remove unused eslint-disable directive in Video * Add integration tests for message processing and surfaceUpdate behaviors * Add integration tests for server-driven updates across all components - Add property-updates.test.tsx: tests surfaceUpdate message handling for property changes (Text, Image, Icon, Button, TextField, CheckBox, Slider, Column, Row, List, Tabs) - Extend data-binding.test.tsx: tests dataModelUpdate message handling for all components with path bindings (Text, TextField, CheckBox, Slider, DateTimeInput, MultipleChoice, Image, Icon, Video, AudioPlayer) - Fix CheckBox and Slider to respond to server-driven literal value updates (literalBoolean/literalNumber), not just path bindings * Add React sample shell application for restaurant finder demo Mirrors the Lit shell demo with identical A2UI messages and theme. Includes mock restaurant data, demo configuration, and styling. * Fix React renderer style transformation to match Lit renderer - Transform primaryColor to --p-* color palette using color-mix - Transform font to --font-family and --font-family-flex variables - Add type assertion in ComponentNode to fix TypeScript build error - Add React deduplication in visual-parity vite config to fix hook errors * Remove Google copyright headers from React sample shell files * Fix additionalStyles applied to wrong element in DateTimeInput and Slider Move theme.additionalStyles from <section> container to <input> element to match Lit renderer behavior. TextField already did this correctly. * Use :where() for all component element selectors to match Lit specificity Wrap component-scoped element selectors (input, label, textarea, dialog, video, audio, img) in :where() so utility classes can override them, matching how bare element selectors work in Lit's Shadow DOM. * Initialize dark mode state from OS color scheme preference Read prefers-color-scheme media query on mount so the toggle button icon and hero image match the actual theme from first render. * Update PARITY.md to reflect :where() usage on all element selectors * Add test for action context resolving path bindings from data model * Add test for action context with mixed literal and path parameters * Fix Modal visual parity and add fixtures for Modal, Video, AudioPlayer Modal changes: - Render dialog in place (no portal) to stay inside .a2ui-surface - Match Lit's structure: closed shows section with entry, open shows dialog - Apply backdrop theme class to dialog, element class to inner section - Use #controls div with g-icon close button to match Lit - Add close event listener for native Escape key handling Visual parity fixtures: - Add modalBasic and modalWithCard fixtures - Add videoBasic and videoWithPathBinding fixtures - Add audioPlayerBasic and audioPlayerWithPathBinding fixtures - Document that Lit AudioPlayer does not implement description property Update PARITY.md to reflect implemented status for Modal, Video, AudioPlayer * Simplify MultipleChoice to select dropdown matching Lit renderer Replace radio/checkbox rendering with a <select> dropdown for visual parity. Update tests, fixtures, and documentation accordingly. * Exclude workspace packages from Vite optimizeDeps to fix stale cache * Add browser reset, style docs, and skip unknown components - Add @layer reset to restore browser defaults inside .a2ui-surface when host apps use CSS resets (e.g. Tailwind preflight) - Add style architecture README documenting the 7-layer priority system - Skip unknown components silently (return null) to match Lit behavior - Add markdown-it to Vite optimizeDeps exclude list * Use markdown-it renderer rules API for theme class injection in Text Replace regex-based HTML string patching in applyMarkdownTheme with markdown-it's renderer.rules API. Sets token.attrJoin() on _open tokens before render, then cleans up rules after — same approach as the Lit renderer's markdown directive. * Move CSS comments out of injected style output into JSDoc * fix(visual-parity): exclude transitive deps from Vite optimizeDeps in both renderers Exclude markdown-it, clsx, and signal-utils/* from pre-bundling in both the React and Lit dev servers to avoid stale cache / duplicate module instances. Also update cache-clearing instructions in PARITY.md. * Remove deprecated useA2UIStore and useA2UIStoreSelector * Simplify hash algorithm in A2UIViewer * fix(Text): make HintedStyles keys optional to match type guard semantics * fix(react): update test fixtures to match web_core Zod schema changes After merging main, web_core now validates messages with Zod schemas that enforce stricter requirements: - Text and Image components require usageHint (was optional) - dataModelUpdate contents use typed value keys (valueString, valueNumber, valueBoolean) instead of generic value - surfaceUpdate.components requires min 1 element Updated all test fixtures across 17 files to use valid protocol payloads. Updated empty surfaceUpdate test to verify both schema rejection and surface persistence after error. Converted nested valueMap template test to use JSON-encoded array format (the Zod schema does not support recursive valueMap in ValueMapItemSchema). * feat(react): add altText support to Image component Resolve the optional altText property from the schema and pass it to the img element, replacing the previously hardcoded empty string. * chore: add React renderer to CODEOWNERS Route renderers/react/ changes to @lukasmoschitz for review. * fix(react): use published @a2ui/lit package instead of local file path Replace "file:../lit" with "^0.8.1" so the package is publishable to NPM. * refactor(react): replace @a2ui/lit dependency with @a2ui/web_core Remove the heavyweight Lit renderer dependency in favor of the lightweight web_core package. This eliminates Lit, lit-html, and Lit signals from the React renderer's dependency tree, making it suitable for embedding in other packages without bundle bloat. - Replace all @a2ui/lit/0.8 imports with @a2ui/web_core subpath imports - Use plain A2uiMessageProcessor instead of Lit signal-based variant - Replace manual pixelmatch.d.ts with @types/pixelmatch package - Update empty surfaceUpdate test to match web_core@0.8.0 behavior * fix(visual-parity): inject markdown renderer for Lit test harness The Lit renderer no longer includes a default markdown renderer. Provide renderMarkdown from @a2ui/markdown-it via Lit context so Text widget parity tests continue to work. * replaced hero image with new version to keep parity to lit * fix(react): match Lit Icon component font-size (24px) web_core structural styles define .g-icon at 20px, but the Lit Icon component overrides this to 24px in its scoped styles. Add the same override in componentSpecificStyles to maintain visual parity. * feat(react): auto-initialize styles and catalog in A2UIProvider Move ensureInitialized() into A2UIProvider so users no longer need to manually call initializeDefaultCatalog() and injectStyles() before rendering. Both are idempotent so multiple providers are safe. * chore: update sample app package-lock after web_core migration * fix(visual-parity): force Vite dep re-optimization on startup Prevents stale 504 errors when file: dependencies are rebuilt by setting optimizeDeps.force in both vite configs. * Format main markdown file * foramt visual parity markdown file * Add GH workflow for the React renderer * add Google OSS copyright notices to all relevant files * Update formatter to match the Google TS style guide * Clarify gts import with a better comment * fix(lint): fix ESLint config and resolve lint errors - Replace require('gts') with ESM import in eslint.config.js - Disable prefer-arrow-callback to preserve React.memo display names - Exclude .d.ts files from linting - Fix floating promise in A2UIProvider dispatch * chore: remove CODEOWNERS, deleted upstream in google#803 * chore: add Google OSS copyright notices to sample app --------- Co-authored-by: alan blount <alan@zeroasterisk.com> Co-authored-by: Ava Mattie <6314286+ava-cassiopeia@users.noreply.github.com>
…dates (google#776) * docs: reorganize files to match nav sections - Move catalogs, transports, client_to_server_actions → concepts/ - Move renderers, agents → reference/ - Move where-is-it-used, community → ecosystem/ - Rewrite agent-ui-ecosystem as concise 'How Does A2UI Compare?' intro page - Move third-party integrations (json-render, OpenClaw) to ecosystem - Fix all cross-references for moved files - Remove duplicate nav entries (each page appears once) * docs: refine How Does A2UI Compare page - native-first → declarative UI, clarify host controls styling - MCP Apps: clarify remote controls content, config via tool calling - AG UI: credit CopilotKit team, React renderer, Composer contributions - ChatKit: note shared design philosophy (basic components, declarative) * docs: restore comparison table as At a Glance section * docs: rename 'Where is A2UI Used?' → 'A2UI in the World' * docs: rename where-is-it-used → a2ui-in-the-world, MCP SEP-1865 citation * docs: add Google ADK section to A2UI in the World ADK Web has native A2UI rendering and A2A↔A2UI message conversion. Links to ADK docs, adk-web repo, and agent development guide. * docs: fix CopilotKit attribution — Composer yes, React renderer no React renderer PR google#542 is still open and not by CopilotKit. Composer was contributed by maxkorp (@CopilotKit). * docs: React renderer status — In Review, link to PR google#542 * docs: add redirects for all moved files Old URLs now redirect to new locations: - catalogs, transports, actions → concepts/ - renderers, agents → reference/ - community → ecosystem/ - where-is-it-used → ecosystem/a2ui-in-the-world * docs: React renderer merged, contribution guide, writing fixes - React renderer PR google#542 merged — update status to Stable across all pages - Add React section to client-setup guide - Expand community renderer submission with step-by-step instructions - Replace community showcase placeholder with concrete guidance + sample links - Collapse duplicate partner info in community.md (points to a2ui-in-the-world) - Fix typo (signiciant → significant) - Tighten how-to-use wording, fix Angular install (add @a2ui/web-lib) * docs: add web_core shared library section to renderer development guide Explains what @a2ui/web-lib (web_core) provides, how Lit/Angular/React renderers use it, and why new web renderers should start from it rather than reimplementing message processing and state management. * docs: link renderer names to source in client-setup table * docs: remove stars and last-updated columns from community renderers table * docs: fix ChatKit link to point to actual docs instead of openai.com homepage * docs: add live shields.io badges for stars and last-commit to community renderers * docs: fix broken React sample link, fix relative path in ecosystem --------- Co-authored-by: Zaf <zaf@0-a.org>
React Renderer for A2UI
Summary
Adds a React renderer implementation for A2UI alongside the existing Lit and Angular renderers, that brings the protocol's declarative UI capabilities to React applications.
Approach
React.memo()for additional performance optimization.:hostselectors to scoped class selectors, allowing visual parity while working in React's Light DOM environment.Components
Core Modules
Demo images