a2ui-react 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +190 -0
- package/dist/index.d.mts +541 -0
- package/dist/index.d.ts +541 -0
- package/dist/index.js +9205 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +9059 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +104 -0
package/README.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# a2ui-react
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/a2ui-react)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://github.com/burka/a2ui-react-shadcn)
|
|
6
|
+
|
|
7
|
+
Beautiful [shadcn/ui](https://ui.shadcn.com/) components for rendering [A2UI protocol](https://a2ui.org/) messages in React.
|
|
8
|
+
|
|
9
|
+
> **Work in Progress**: This library is under active development and APIs may change. We welcome feedback, bug reports, and contributions! Please [open an issue](https://github.com/burka/a2ui-react-shadcn/issues) if you encounter any problems or have suggestions.
|
|
10
|
+
|
|
11
|
+
**[Live Demo](https://burka.github.io/a2ui-react-shadcn/)** | **[GitHub](https://github.com/burka/a2ui-react-shadcn)**
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install a2ui-react
|
|
17
|
+
# or
|
|
18
|
+
yarn add a2ui-react
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { A2UIProvider, A2UISurface, shadcnRenderers } from 'a2ui-react'
|
|
25
|
+
|
|
26
|
+
const messages = [
|
|
27
|
+
{
|
|
28
|
+
beginRendering: {
|
|
29
|
+
surfaceId: 'my-surface',
|
|
30
|
+
root: 'root',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
surfaceUpdate: {
|
|
35
|
+
surfaceId: 'my-surface',
|
|
36
|
+
updates: [
|
|
37
|
+
{
|
|
38
|
+
id: 'root',
|
|
39
|
+
component: {
|
|
40
|
+
type: 'Column',
|
|
41
|
+
id: 'root',
|
|
42
|
+
children: ['greeting'],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: 'greeting',
|
|
47
|
+
component: {
|
|
48
|
+
type: 'Text',
|
|
49
|
+
id: 'greeting',
|
|
50
|
+
content: 'Hello, World!',
|
|
51
|
+
style: 'h1',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
function App() {
|
|
60
|
+
return (
|
|
61
|
+
<A2UIProvider renderers={shadcnRenderers}>
|
|
62
|
+
<A2UISurface surfaceId="my-surface" messages={messages} />
|
|
63
|
+
</A2UIProvider>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Features
|
|
69
|
+
|
|
70
|
+
- **Complete A2UI Protocol Support** - All component types from the A2UI specification
|
|
71
|
+
- **Beautiful shadcn/ui Components** - Modern, accessible, and customizable
|
|
72
|
+
- **Streaming Ready** - Process real-time streaming updates from AI models
|
|
73
|
+
- **Two-Way Data Binding** - Interactive components with automatic state management
|
|
74
|
+
- **Fully Typed** - Complete TypeScript support with exported types
|
|
75
|
+
- **Customizable Renderers** - Override any component with your own implementation
|
|
76
|
+
|
|
77
|
+
## Supported Components
|
|
78
|
+
|
|
79
|
+
### Layout
|
|
80
|
+
- `Row` - Horizontal flex container
|
|
81
|
+
- `Column` - Vertical flex container
|
|
82
|
+
|
|
83
|
+
### Display
|
|
84
|
+
- `Text` - Typography with styles (h1-h5, body, caption)
|
|
85
|
+
- `Image` - Images with loading states
|
|
86
|
+
- `Icon` - Lucide icons
|
|
87
|
+
- `Divider` - Horizontal/vertical separators
|
|
88
|
+
|
|
89
|
+
### Interactive
|
|
90
|
+
- `Button` - Clickable buttons with actions
|
|
91
|
+
- `TextField` - Text inputs (short, long, number, date, obscured)
|
|
92
|
+
- `Checkbox` - Boolean toggles
|
|
93
|
+
- `Select` - Dropdown selection
|
|
94
|
+
- `Slider` - Range input
|
|
95
|
+
- `DateTimeInput` - Date/time pickers
|
|
96
|
+
- `MultipleChoice` - Multi-select options
|
|
97
|
+
|
|
98
|
+
### Container
|
|
99
|
+
- `Card` - Content cards
|
|
100
|
+
- `Modal` - Dialog overlays
|
|
101
|
+
- `Tabs` - Tabbed content
|
|
102
|
+
- `List` - Data-driven lists
|
|
103
|
+
|
|
104
|
+
## Custom Renderers
|
|
105
|
+
|
|
106
|
+
Override any built-in renderer with your own:
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import type { A2UIRenderer, ButtonComponent } from 'a2ui-react'
|
|
110
|
+
import { motion } from 'framer-motion'
|
|
111
|
+
|
|
112
|
+
const AnimatedButton: A2UIRenderer<ButtonComponent> = {
|
|
113
|
+
type: 'Button',
|
|
114
|
+
render: ({ component, children, onAction }) => (
|
|
115
|
+
<motion.button
|
|
116
|
+
whileHover={{ scale: 1.05 }}
|
|
117
|
+
whileTap={{ scale: 0.95 }}
|
|
118
|
+
onClick={() => component.action && onAction({ type: component.action })}
|
|
119
|
+
>
|
|
120
|
+
{children}
|
|
121
|
+
</motion.button>
|
|
122
|
+
),
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Add to renderers (last one wins for same type)
|
|
126
|
+
const customRenderers = [...shadcnRenderers, AnimatedButton]
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Streaming Integration
|
|
130
|
+
|
|
131
|
+
Parse and render streaming A2UI messages:
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
import { createStore, parseJSONL, A2UIProvider, A2UISurface, shadcnRenderers } from 'a2ui-react'
|
|
135
|
+
|
|
136
|
+
const store = createStore()
|
|
137
|
+
|
|
138
|
+
// Process streaming response
|
|
139
|
+
async function handleStream(reader: ReadableStreamDefaultReader<Uint8Array>) {
|
|
140
|
+
for await (const message of parseJSONL(reader)) {
|
|
141
|
+
store.processMessage(message)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function App() {
|
|
146
|
+
return (
|
|
147
|
+
<A2UIProvider renderers={shadcnRenderers} store={store}>
|
|
148
|
+
<A2UISurface surfaceId="stream-surface" />
|
|
149
|
+
</A2UIProvider>
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## API Reference
|
|
155
|
+
|
|
156
|
+
### Components
|
|
157
|
+
|
|
158
|
+
- `A2UIProvider` - Context provider for renderers and store
|
|
159
|
+
- `A2UISurface` - Renders a surface by ID
|
|
160
|
+
- `ComponentRenderer` - Renders individual components
|
|
161
|
+
|
|
162
|
+
### Hooks
|
|
163
|
+
|
|
164
|
+
- `useA2UI()` - Access the A2UI context
|
|
165
|
+
- `useSurface(surfaceId)` - Subscribe to a surface
|
|
166
|
+
- `useDataBinding(dataPath)` - Two-way data binding
|
|
167
|
+
- `useAction()` - Access action handler
|
|
168
|
+
|
|
169
|
+
### Store
|
|
170
|
+
|
|
171
|
+
- `createStore()` - Create an A2UI store instance
|
|
172
|
+
- `store.processMessage(msg)` - Process incoming messages
|
|
173
|
+
- `store.getSurface(id)` - Get surface state
|
|
174
|
+
- `store.getData(surfaceId, path)` - Get data value
|
|
175
|
+
- `store.setData(surfaceId, path, value)` - Set data value
|
|
176
|
+
|
|
177
|
+
### Parser
|
|
178
|
+
|
|
179
|
+
- `parseMessage(json)` - Parse a single message
|
|
180
|
+
- `parseJSONL(reader)` - Async generator for streaming JSONL
|
|
181
|
+
- `createStreamParser()` - Create a stateful stream parser
|
|
182
|
+
|
|
183
|
+
## Requirements
|
|
184
|
+
|
|
185
|
+
- React 18.0.0+ or React 19.0.0+
|
|
186
|
+
- Tailwind CSS (for styling)
|
|
187
|
+
|
|
188
|
+
## License
|
|
189
|
+
|
|
190
|
+
MIT
|