MCPcopy Index your code
hub / github.com/easyops-cn/a2ui-sdk

github.com/easyops-cn/a2ui-sdk @react-v0.4.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release react-v0.4.0 ↗ · + Follow
386 symbols 1,146 edges 172 files 41 documented · 11%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

A2UI SDK

NPM Version

The TypeScript/React SDK for A2UI protocol.

NOTE: this is NOT the official SDK maintained by the A2UI team.

Supports all components in A2UI standard catalog out of the box. Built with shadcn/ui and Tailwind CSS.

Currently both A2UI protocol v0.8 and v0.9 are supported.

⚠️ Important: V0.9 is a draft version based on the A2UI specification as of 2026-01-12. The v0.9 protocol has changed significantly recently and may continue to evolve. We recommend using the stable v0.8 until v0.9 reaches alpha or beta status.

Docs | Playground

Packages

This SDK provides different levels of APIs to suit various use cases:

Package Description
@a2ui-sdk/react React components for rendering A2UI protocol.

Use this for rendering A2UI surfaces in React applications. | | @a2ui-sdk/utils | Utility functions for A2UI protocol (e.g., string interpolation, path utilities).

Use this when building custom renderers. | | @a2ui-sdk/types | TypeScript type definitions for A2UI protocol.

Use this for type-safe A2UI message handling. |

// React renderer - full rendering solution
import { A2UIProvider, A2UIRenderer } from '@a2ui-sdk/react/0.8'

// Utilities - for custom renderer implementations
import { resolveValue } from '@a2ui-sdk/utils/0.8'

// Types only - for type-safe message handling
import type { A2UIMessage, A2UIAction } from '@a2ui-sdk/types/0.8'

Installation

npm install @a2ui-sdk/react

V0.8

Usage

First, use the @source directive to tell Tailwind to scan the library code for class names in your global CSS:

@source "../node_modules/@a2ui-sdk/react";

Next, use A2UIProvider and A2UIRenderer to render A2UI messages:

import {
  A2UIProvider,
  A2UIRenderer,
  useA2UIMessageHandler,
  type A2UIMessage,
  type A2UIAction,
} from '@a2ui-sdk/react/0.8'

function App() {
  return (
    <A2UIProvider>
      <MyApp />
    </A2UIProvider>
  )
}

function MyApp() {
  const { processMessage } = useA2UIMessageHandler()

  useEffect(() => {
    const message: A2UIMessage = {
      // ...  A2UI message from your backend
    }
    processMessage(message)
  }, [processMessage])

  const handleAction = (action: A2UIAction) => {
    console.log('Action received:', action)
  }

  return <A2UIRenderer onAction={handleAction} />
}

Custom components

You can override default components or add new custom components via the catalog prop on A2UIProvider. Use standardCatalog as a base and extend it with your custom components.

import {
  A2UIProvider,
  A2UIRenderer,
  standardCatalog,
  type A2UIMessage,
  type A2UIAction,
} from '@a2ui-sdk/react/0.8'

// Extend standard catalog with custom components
const customCatalog = {
  ...standardCatalog,
  components: {
    ...standardCatalog.components,
    // Override default Button component with a custom one
    Button: CustomButtonComponent,
    // Add a new custom Switch component
    Switch: CustomSwitchComponent,
  },
}

function App() {
  return (
    <A2UIProvider catalog={customCatalog} messages={messages}>
      <A2UIRenderer onAction={handleAction} />
    </A2UIProvider>
  )
}

Implementing a custom button component with action dispatch:

import {
  useDispatchAction,
  ComponentRenderer,
  type ButtonComponentProps,
} from '@a2ui-sdk/react/0.8'

export function CustomButtonComponent({
  surfaceId,
  componentId,
  child,
  action,
}: ButtonComponentProps) {
  const dispatchAction = useDispatchAction()

  const handleClick = () => {
    if (action) {
      dispatchAction(surfaceId, componentId, action)
    }
  }

  return (
    <button onClick={handleClick}>
      <ComponentRenderer surfaceId={surfaceId} componentId={child} />
    </button>
  )
}

Implementing a custom switch component with data binding:

import { useDataBinding, useFormBinding } from '@a2ui-sdk/react/0.8'

export function CustomSwitchComponent({
  surfaceId,
  componentId,
  label,
  value,
}: SwitchComponentProps) {
  const labelText = useDataBinding<string>(surfaceId, label, '')
  const [checked, setChecked] = useFormBinding<boolean>(surfaceId, value, false)

  const handleChange = (newChecked: boolean) => {
    setChecked(newChecked)
  }

  return (
    <Switch checked={checked} onChange={handleChange}>
      {labelText}
    </Switch>
  )
}

V0.9

⚠️ Draft Version Warning: V0.9 is currently a draft implementation based on the A2UI specification as of 2026-01-12. The protocol has changed significantly recently and may continue to evolve. We recommend using the stable v0.8 for production use until v0.9 reaches alpha or beta status.

Usage

First, use the @source directive to tell Tailwind to scan the library code for class names in your global CSS:

@source "../node_modules/@a2ui-sdk/react";

Next, use A2UIProvider and A2UIRenderer to render A2UI messages:

import {
  A2UIProvider,
  A2UIRenderer,
  useA2UIMessageHandler,
  type A2UIMessage,
  type A2UIAction,
} from '@a2ui-sdk/react/0.9'

function App() {
  return (
    <A2UIProvider>
      <MyApp />
    </A2UIProvider>
  )
}

function MyApp() {
  const { processMessage } = useA2UIMessageHandler()

  useEffect(() => {
    const message: A2UIMessage = {
      // ...  A2UI message from your backend
    }
    processMessage(message)
  }, [processMessage])

  const handleAction = (action: A2UIAction) => {
    console.log('Action received:', action)
  }

  return <A2UIRenderer onAction={handleAction} />
}

Additionally, override or extend the standard catalog the same way as in v0.8.

Extension points exported contracts — how you extend this code

ParserState (Interface)
* Parser state maintaining current position and depth.
packages/utils/src/0.9/interpolation/parser.ts
A2UIRendererProps (Interface)
(no doc)
packages/react/src/0.8/A2UIRenderer.tsx
DataModel (Interface)
(no doc)
packages/types/src/0.8/index.ts
JsonEditorProps (Interface)
(no doc)
playground/src/components/JsonEditor.tsx
EvaluationContext (Interface)
(no doc)
packages/utils/src/0.9/validation.ts
UnknownComponentProps (Interface)
(no doc)
packages/react/src/0.8/components/UnknownComponent.tsx
DataEntry (Interface)
(no doc)
packages/types/src/0.8/index.ts
ErrorDisplayProps (Interface)
(no doc)
playground/src/components/ErrorDisplay.tsx

Core symbols most depended-on inside this repo

tokenize
called by 80
packages/utils/src/0.9/interpolation/lexer.ts
cn
called by 70
packages/react/src/lib/utils.ts
useDataModelContext
called by 55
packages/react/src/0.8/contexts/DataModelContext.tsx
useSurfaceContext
called by 39
packages/react/src/0.8/contexts/SurfaceContext.tsx
parse
called by 37
packages/utils/src/0.9/interpolation/parser.ts
resolveValue
called by 33
packages/utils/src/0.8/dataBinding.ts
useSurfaceContext
called by 30
packages/react/src/0.9/contexts/SurfaceContext.tsx
useDataBinding
called by 28
packages/react/src/0.8/hooks/useDataBinding.ts

Shape

Function 236
Interface 125
Method 16
Class 8
Enum 1

Languages

TypeScript100%

Modules by API surface

packages/types/src/0.9/standard-catalog.ts21 symbols
packages/types/src/0.8/standard-catalog.ts20 symbols
packages/types/src/0.9/index.ts16 symbols
packages/types/src/0.8/index.ts16 symbols
playground/src/components/Preview.tsx11 symbols
packages/utils/src/0.9/interpolation/parser.ts11 symbols
packages/react/src/components/ui/select.tsx10 symbols
packages/react/src/components/ui/dialog.tsx10 symbols
packages/react/src/0.9/contexts/A2UIProvider.test.tsx10 symbols
website/src/client/color-mode-switch/index.js8 symbols
packages/utils/src/0.9/interpolation/types.ts8 symbols
packages/utils/src/0.8/pathUtils.ts8 symbols

For agents

$ claude mcp add a2ui-sdk \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page