@aomi-labs/react 0.2.4 → 0.3.1
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 +142 -0
- package/dist/index.cjs +415 -944
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +94 -183
- package/dist/index.d.ts +94 -183
- package/dist/index.js +410 -932
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
package/README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# @aomi-labs/react
|
|
2
|
+
|
|
3
|
+
React runtime, hooks, and utilities for building UIs on top of the Aomi on-chain agent backend.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @aomi-labs/react @assistant-ui/react react react-dom
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @aomi-labs/react @assistant-ui/react react react-dom
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Optional peer dependencies for wallet features:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add wagmi viem
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
Wrap your app with `AomiRuntimeProvider`, then use `useAomiRuntime()` anywhere inside:
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { AomiRuntimeProvider, useAomiRuntime } from "@aomi-labs/react";
|
|
25
|
+
|
|
26
|
+
function App() {
|
|
27
|
+
return (
|
|
28
|
+
<AomiRuntimeProvider backendUrl="https://api.aomi.dev">
|
|
29
|
+
<Chat />
|
|
30
|
+
</AomiRuntimeProvider>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function Chat() {
|
|
35
|
+
const { sendMessage, isRunning, getMessages } = useAomiRuntime();
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div>
|
|
39
|
+
<button onClick={() => sendMessage("What's the price of ETH?")}>
|
|
40
|
+
Ask
|
|
41
|
+
</button>
|
|
42
|
+
{isRunning && <p>Thinking...</p>}
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Provider
|
|
49
|
+
|
|
50
|
+
### `<AomiRuntimeProvider>`
|
|
51
|
+
|
|
52
|
+
Root provider that composes thread, user, event, notification, and control contexts.
|
|
53
|
+
|
|
54
|
+
| Prop | Default | Description |
|
|
55
|
+
|------|---------|-------------|
|
|
56
|
+
| `backendUrl` | `"http://localhost:8080"` | Aomi backend URL |
|
|
57
|
+
| `children` | — | React children |
|
|
58
|
+
|
|
59
|
+
## Hooks
|
|
60
|
+
|
|
61
|
+
### `useAomiRuntime()`
|
|
62
|
+
|
|
63
|
+
Unified hook providing access to all runtime APIs. Must be used inside `<AomiRuntimeProvider>`.
|
|
64
|
+
|
|
65
|
+
Returns an `AomiRuntimeApi` object with:
|
|
66
|
+
|
|
67
|
+
**User API**
|
|
68
|
+
|
|
69
|
+
| Property | Description |
|
|
70
|
+
|----------|-------------|
|
|
71
|
+
| `user` | Current user state (wallet address, chain, etc.) |
|
|
72
|
+
| `setUser(data)` | Update user state (partial merge) |
|
|
73
|
+
| `onUserStateChange(cb)` | Subscribe to user state changes |
|
|
74
|
+
|
|
75
|
+
**Thread API**
|
|
76
|
+
|
|
77
|
+
| Property | Description |
|
|
78
|
+
|----------|-------------|
|
|
79
|
+
| `currentThreadId` | Active thread ID |
|
|
80
|
+
| `threadMetadata` | Map of all thread metadata |
|
|
81
|
+
| `createThread()` | Create a new thread |
|
|
82
|
+
| `deleteThread(id)` | Delete a thread |
|
|
83
|
+
| `renameThread(id, title)` | Rename a thread |
|
|
84
|
+
| `selectThread(id)` | Switch to a thread |
|
|
85
|
+
|
|
86
|
+
**Chat API**
|
|
87
|
+
|
|
88
|
+
| Property | Description |
|
|
89
|
+
|----------|-------------|
|
|
90
|
+
| `isRunning` | Whether the agent is generating |
|
|
91
|
+
| `getMessages(threadId?)` | Get messages for a thread |
|
|
92
|
+
| `sendMessage(text)` | Send a message |
|
|
93
|
+
| `cancelGeneration()` | Cancel current generation |
|
|
94
|
+
|
|
95
|
+
**Wallet API**
|
|
96
|
+
|
|
97
|
+
| Property | Description |
|
|
98
|
+
|----------|-------------|
|
|
99
|
+
| `pendingWalletRequests` | Queued wallet requests |
|
|
100
|
+
| `resolveWalletRequest(id, result)` | Complete a wallet request |
|
|
101
|
+
| `rejectWalletRequest(id, error?)` | Reject a wallet request |
|
|
102
|
+
|
|
103
|
+
**Event API**
|
|
104
|
+
|
|
105
|
+
| Property | Description |
|
|
106
|
+
|----------|-------------|
|
|
107
|
+
| `subscribe(type, cb)` | Subscribe to backend events |
|
|
108
|
+
| `sendSystemCommand(event)` | Send a system command |
|
|
109
|
+
| `sseStatus` | SSE connection status |
|
|
110
|
+
|
|
111
|
+
### Other Hooks
|
|
112
|
+
|
|
113
|
+
| Hook | Description |
|
|
114
|
+
|------|-------------|
|
|
115
|
+
| `useUser()` | User/wallet state context |
|
|
116
|
+
| `useThreadContext()` | Thread management context |
|
|
117
|
+
| `useControl()` | Model/namespace/API key state |
|
|
118
|
+
| `useNotification()` | Toast notification context |
|
|
119
|
+
| `useEventContext()` | Raw event system access |
|
|
120
|
+
| `useWalletHandler()` | Wallet request handler (auto-sign with wagmi) |
|
|
121
|
+
| `useNotificationHandler()` | Notification event handler |
|
|
122
|
+
|
|
123
|
+
## Utilities
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import {
|
|
127
|
+
cn, // clsx + tailwind-merge
|
|
128
|
+
formatAddress, // 0x1234...5678
|
|
129
|
+
getNetworkName, // chainId → "Ethereum", "Polygon", etc.
|
|
130
|
+
getChainInfo, // chainId → { name, symbol, explorer }
|
|
131
|
+
SUPPORTED_CHAINS, // supported chain info map
|
|
132
|
+
} from "@aomi-labs/react";
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Re-exports
|
|
136
|
+
|
|
137
|
+
`AomiClient` and all core types are re-exported from `@aomi-labs/client`:
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import { AomiClient } from "@aomi-labs/react";
|
|
141
|
+
import type { AomiMessage, AomiChatResponse } from "@aomi-labs/react";
|
|
142
|
+
```
|