keyring-chatbot-agent 1.0.0 → 1.0.2
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 +235 -134
- package/dist/chat-widget-wc.es.js +73 -0
- package/dist/chat-widget-wc.umd.js +2 -0
- package/dist/chat-widget.es.js +3 -3
- package/dist/chat-widget.umd.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
# Keyring Chatbot Agent SDK
|
|
2
2
|
|
|
3
|
-
An AI-powered Web3 chatbot SDK
|
|
3
|
+
An AI-powered Web3 chatbot SDK. Provides a floating chat widget with on-chain capabilities: token swaps, sending tokens/NFTs, viewing balances, and natural-language AI conversation.
|
|
4
|
+
|
|
5
|
+
---
|
|
4
6
|
|
|
5
7
|
## Features
|
|
6
8
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
9
|
+
- **Natural language AI chat** — Understands user intent, distinguishes general questions from on-chain tasks
|
|
10
|
+
- **Token swaps** — Best-price routing via deBridge, automatic ERC-20 approval when needed
|
|
11
|
+
- **Send tokens** — ERC-20 and native tokens, supports "max", "50%", "$5" amount expressions
|
|
12
|
+
- **Send NFTs** — ERC-721 and ERC-1155, resolves NFT by name or token ID from the user's wallet
|
|
13
|
+
- **View balances** — Token list with USD values
|
|
14
|
+
- **Trending tokens** — Per-chain trending data with quick-buy buttons
|
|
15
|
+
- **Wrap / Unwrap** — ETH ↔ WETH and equivalents on each chain
|
|
16
|
+
- **Approve token** — ERC-20 spending allowance
|
|
17
|
+
- **Multi-language** — English, Japanese, Chinese UI
|
|
18
|
+
- **Multi-chain** — Ethereum, Optimism, BNB Chain, Polygon, Base, Arbitrum, Avalanche, Linea
|
|
19
|
+
- **Full TypeScript** — Complete type declarations included
|
|
16
20
|
|
|
17
21
|
---
|
|
18
22
|
|
|
@@ -32,7 +36,9 @@ npm install react react-dom
|
|
|
32
36
|
|
|
33
37
|
---
|
|
34
38
|
|
|
35
|
-
##
|
|
39
|
+
## React Usage
|
|
40
|
+
|
|
41
|
+
### Basic example
|
|
36
42
|
|
|
37
43
|
```tsx
|
|
38
44
|
import { ChatWidget } from 'keyring-chatbot-agent-sdk-test';
|
|
@@ -46,7 +52,6 @@ function App() {
|
|
|
46
52
|
tx: Transaction
|
|
47
53
|
): Promise<TransactionResult> => {
|
|
48
54
|
try {
|
|
49
|
-
// Sign and send via your wallet provider (wagmi, ethers.js, viem, etc.)
|
|
50
55
|
const hash = await walletClient.sendTransaction(tx);
|
|
51
56
|
return { status: 'success', transactionHash: hash };
|
|
52
57
|
} catch (err: unknown) {
|
|
@@ -56,51 +61,14 @@ function App() {
|
|
|
56
61
|
|
|
57
62
|
return (
|
|
58
63
|
<ChatWidget
|
|
59
|
-
account={{ address: '0x...
|
|
60
|
-
onTransaction={handleTransaction}
|
|
61
|
-
/>
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
## React — Full API
|
|
69
|
-
|
|
70
|
-
### `<ChatWidget />` Props
|
|
71
|
-
|
|
72
|
-
| Prop | Type | Default | Required | Description |
|
|
73
|
-
| --------------- | ------------------------------------------------- | ---------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
|
74
|
-
| `account` | `Account` | `undefined` | No | Connected wallet. Pass `undefined` when no wallet is connected. |
|
|
75
|
-
| `onTransaction` | `(tx: Transaction) => Promise<TransactionResult>` | `undefined` | No\* | Called when the chatbot needs to sign/send a transaction. |
|
|
76
|
-
| `position` | `'bottom-right'` \| `'bottom-left'` | `'bottom-right'` | No | Corner where the floating button appears. |
|
|
77
|
-
| `theme` | `ChatWidgetTheme` | `{}` | No | Visual customization. |
|
|
78
|
-
| `defaultOpen` | `boolean` | `false` | No | Open the chat modal on first render. |
|
|
79
|
-
| `onOpen` | `() => void` | — | No | Callback fired when the modal opens. |
|
|
80
|
-
| `onClose` | `() => void` | — | No | Callback fired when the modal closes. |
|
|
81
|
-
| `language` | `'en'` \| `'ja'` \| `'cn'` | `'en'` | No | UI language (English, Japanese, Chinese). |
|
|
82
|
-
| `rpcUrls` | `Record<number, string>` | — | No | Per-chain RPC URL overrides (`chainId → URL`). Takes priority over built-in defaults for balance queries and gas estimation. |
|
|
83
|
-
|
|
84
|
-
> \* `onTransaction` is required to execute on-chain actions (swap, send, approve, etc.). Without it, the AI can still answer questions and display information.
|
|
85
|
-
|
|
86
|
-
### Basic example
|
|
87
|
-
|
|
88
|
-
```tsx
|
|
89
|
-
import { ChatWidget } from 'keyring-chatbot-agent-sdk-test';
|
|
90
|
-
|
|
91
|
-
function App() {
|
|
92
|
-
return (
|
|
93
|
-
<ChatWidget
|
|
94
|
-
account={{ address: userAddress, chainId: 10 }}
|
|
64
|
+
account={{ address: '0x...', chainId: 10 }}
|
|
95
65
|
onTransaction={handleTransaction}
|
|
96
|
-
language="en"
|
|
97
|
-
position="bottom-right"
|
|
98
66
|
/>
|
|
99
67
|
);
|
|
100
68
|
}
|
|
101
69
|
```
|
|
102
70
|
|
|
103
|
-
### Full example
|
|
71
|
+
### Full example
|
|
104
72
|
|
|
105
73
|
```tsx
|
|
106
74
|
import { ChatWidget } from 'keyring-chatbot-agent-sdk-test';
|
|
@@ -150,7 +118,7 @@ function App() {
|
|
|
150
118
|
}
|
|
151
119
|
```
|
|
152
120
|
|
|
153
|
-
###
|
|
121
|
+
### With wagmi v2
|
|
154
122
|
|
|
155
123
|
```tsx
|
|
156
124
|
import { useSendTransaction, useAccount } from 'wagmi';
|
|
@@ -188,13 +156,52 @@ function App() {
|
|
|
188
156
|
}
|
|
189
157
|
```
|
|
190
158
|
|
|
159
|
+
### `<ChatWidget />` Props
|
|
160
|
+
|
|
161
|
+
| Prop | Type | Default | Required | Description |
|
|
162
|
+
| --------------- | ------------------------------------------------- | ---------------- | -------- | ---------------------------------------------------------------------------------------------------------- |
|
|
163
|
+
| `account` | `Account` | `undefined` | No | Connected wallet. Omit when no wallet is connected. |
|
|
164
|
+
| `onTransaction` | `(tx: Transaction) => Promise<TransactionResult>` | `undefined` | \* | Called when the chatbot needs to sign/send a transaction. |
|
|
165
|
+
| `position` | `'bottom-right'` \| `'bottom-left'` | `'bottom-right'` | No | Corner where the floating button appears. |
|
|
166
|
+
| `language` | `'en'` \| `'ja'` \| `'cn'` | `'en'` | No | UI language. |
|
|
167
|
+
| `theme` | `ChatWidgetTheme` | `{}` | No | Visual customization (color, size, z-index). |
|
|
168
|
+
| `defaultOpen` | `boolean` | `false` | No | Open the chat modal on first render. |
|
|
169
|
+
| `rpcUrls` | `Record<number, string>` | — | No | Per-chain RPC URL overrides. Takes priority over built-in defaults for balance queries and gas estimation. |
|
|
170
|
+
| `onOpen` | `() => void` | — | No | Callback fired when the modal opens. |
|
|
171
|
+
| `onClose` | `() => void` | — | No | Callback fired when the modal closes. |
|
|
172
|
+
|
|
173
|
+
> \* `onTransaction` is required to execute on-chain actions (swap, send, approve, etc.). Without it, the AI can still answer questions and display information.
|
|
174
|
+
|
|
191
175
|
---
|
|
192
176
|
|
|
193
|
-
## HTML
|
|
177
|
+
## HTML / Web Component Usage
|
|
178
|
+
|
|
179
|
+
The SDK ships a **Web Component** build (`chat-widget-wc`) that can be embedded in any HTML page without a React build pipeline. The Web Component supports **the same full feature set as the React component**: wallet connection, transaction signing, RPC URL overrides, language selection, and all callbacks.
|
|
180
|
+
|
|
181
|
+
### Configuration via HTML attributes
|
|
182
|
+
|
|
183
|
+
Simple scalar values (strings, numbers, booleans) can be set directly on the HTML tag:
|
|
184
|
+
|
|
185
|
+
| Attribute | Type | Default | Description |
|
|
186
|
+
| --------------- | --------- | ---------------- | ------------------------------------------------ |
|
|
187
|
+
| `position` | `string` | `'bottom-right'` | `'bottom-right'` or `'bottom-left'` |
|
|
188
|
+
| `primary-color` | `string` | `'#007bff'` | Widget accent color (hex or any CSS color value) |
|
|
189
|
+
| `button-size` | `number` | `60` | Floating button diameter in pixels |
|
|
190
|
+
| `z-index` | `number` | `9999` | CSS `z-index` of the widget |
|
|
191
|
+
| `default-open` | `boolean` | `false` | Set to `"true"` to open the chat on page load |
|
|
192
|
+
| `language` | `string` | `'en'` | UI language: `'en'`, `'ja'`, or `'cn'` |
|
|
194
193
|
|
|
195
|
-
|
|
194
|
+
### Configuration via JavaScript properties
|
|
196
195
|
|
|
197
|
-
|
|
196
|
+
Complex objects (`account`, `rpcUrls`, callbacks) are assigned as JavaScript properties on the element. Setting any property triggers an immediate re-render.
|
|
197
|
+
|
|
198
|
+
| Property | Type | Description |
|
|
199
|
+
| --------------- | ------------------------------------------------- | ------------------------------------- |
|
|
200
|
+
| `account` | `{ address: string; chainId: number }` | Connected wallet info |
|
|
201
|
+
| `onTransaction` | `(tx: Transaction) => Promise<TransactionResult>` | Transaction signing / sending handler |
|
|
202
|
+
| `rpcUrls` | `Record<number, string>` | Per-chain RPC URL overrides |
|
|
203
|
+
| `onOpen` | `() => void` | Callback fired when the modal opens |
|
|
204
|
+
| `onClose` | `() => void` | Callback fired when the modal closes |
|
|
198
205
|
|
|
199
206
|
### Via CDN — UMD script tag
|
|
200
207
|
|
|
@@ -206,18 +213,50 @@ The web component supports visual configuration via HTML attributes (`position`,
|
|
|
206
213
|
<title>My dApp</title>
|
|
207
214
|
</head>
|
|
208
215
|
<body>
|
|
209
|
-
<h1>My Web3 App</h1>
|
|
210
|
-
|
|
211
216
|
<!-- 1. Load the bundle -->
|
|
212
217
|
<script src="https://unpkg.com/keyring-chatbot-agent-sdk-test/dist/chat-widget-wc.umd.js"></script>
|
|
213
218
|
|
|
214
|
-
<!-- 2. Place the custom element -->
|
|
219
|
+
<!-- 2. Place the custom element with basic attributes -->
|
|
215
220
|
<chat-widget
|
|
221
|
+
id="my-chat"
|
|
216
222
|
position="bottom-right"
|
|
217
223
|
primary-color="#5B7FFF"
|
|
218
224
|
button-size="60"
|
|
219
225
|
z-index="9999"
|
|
226
|
+
language="en"
|
|
220
227
|
></chat-widget>
|
|
228
|
+
|
|
229
|
+
<!-- 3. Assign account and onTransaction via JavaScript -->
|
|
230
|
+
<script>
|
|
231
|
+
const widget = document.getElementById('my-chat');
|
|
232
|
+
|
|
233
|
+
// Set wallet info (reassign whenever the wallet changes)
|
|
234
|
+
widget.account = { address: '0xYourWalletAddress', chainId: 10 };
|
|
235
|
+
|
|
236
|
+
// Set the transaction handler
|
|
237
|
+
widget.onTransaction = async function (tx) {
|
|
238
|
+
try {
|
|
239
|
+
// Works with any provider: ethers.js, viem, MetaMask, etc.
|
|
240
|
+
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
241
|
+
const signer = await provider.getSigner();
|
|
242
|
+
const txResponse = await signer.sendTransaction({
|
|
243
|
+
to: tx.to,
|
|
244
|
+
data: tx.data,
|
|
245
|
+
value: BigInt(tx.value || '0'),
|
|
246
|
+
});
|
|
247
|
+
const receipt = await txResponse.wait();
|
|
248
|
+
return { status: 'success', transactionHash: receipt.hash };
|
|
249
|
+
} catch (err) {
|
|
250
|
+
return { status: 'fail', error: err.message };
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
// Optional: override RPC URLs
|
|
255
|
+
widget.rpcUrls = {
|
|
256
|
+
10: 'https://optimism-mainnet.infura.io/v3/YOUR_KEY',
|
|
257
|
+
8453: 'https://mainnet.base.org',
|
|
258
|
+
};
|
|
259
|
+
</script>
|
|
221
260
|
</body>
|
|
222
261
|
</html>
|
|
223
262
|
```
|
|
@@ -232,54 +271,114 @@ The web component supports visual configuration via HTML attributes (`position`,
|
|
|
232
271
|
<title>My dApp</title>
|
|
233
272
|
</head>
|
|
234
273
|
<body>
|
|
235
|
-
<
|
|
236
|
-
|
|
237
|
-
|
|
274
|
+
<chat-widget
|
|
275
|
+
id="my-chat"
|
|
276
|
+
position="bottom-right"
|
|
277
|
+
language="en"
|
|
278
|
+
></chat-widget>
|
|
238
279
|
|
|
239
280
|
<script type="module">
|
|
240
281
|
import 'https://unpkg.com/keyring-chatbot-agent-sdk-test/dist/chat-widget-wc.es.js';
|
|
241
|
-
</script>
|
|
242
|
-
</body>
|
|
243
|
-
</html>
|
|
244
|
-
```
|
|
245
282
|
|
|
246
|
-
|
|
283
|
+
const widget = document.getElementById('my-chat');
|
|
247
284
|
|
|
248
|
-
|
|
249
|
-
<script src="./node_modules/keyring-chatbot-agent-sdk-test/dist/chat-widget-wc.umd.js"></script>
|
|
285
|
+
widget.account = { address: '0xYourWalletAddress', chainId: 10 };
|
|
250
286
|
|
|
251
|
-
|
|
287
|
+
widget.onTransaction = async (tx) => {
|
|
288
|
+
// handle transaction signing here
|
|
289
|
+
};
|
|
290
|
+
</script>
|
|
291
|
+
</body>
|
|
292
|
+
</html>
|
|
252
293
|
```
|
|
253
294
|
|
|
254
|
-
###
|
|
295
|
+
### Full MetaMask integration (plain HTML)
|
|
255
296
|
|
|
256
297
|
```html
|
|
257
|
-
|
|
298
|
+
<!DOCTYPE html>
|
|
299
|
+
<html lang="en">
|
|
300
|
+
<head>
|
|
301
|
+
<meta charset="UTF-8" />
|
|
302
|
+
<title>My dApp</title>
|
|
303
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/ethers/6.13.0/ethers.umd.min.js"></script>
|
|
304
|
+
<script src="https://unpkg.com/keyring-chatbot-agent-sdk-test/dist/chat-widget-wc.umd.js"></script>
|
|
305
|
+
</head>
|
|
306
|
+
<body>
|
|
307
|
+
<button id="connect-btn">Connect Wallet</button>
|
|
308
|
+
<chat-widget
|
|
309
|
+
id="my-chat"
|
|
310
|
+
position="bottom-right"
|
|
311
|
+
language="en"
|
|
312
|
+
></chat-widget>
|
|
258
313
|
|
|
259
|
-
<
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
314
|
+
<script>
|
|
315
|
+
const widget = document.getElementById('my-chat');
|
|
316
|
+
|
|
317
|
+
widget.onTransaction = async function (tx) {
|
|
318
|
+
try {
|
|
319
|
+
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
320
|
+
const signer = await provider.getSigner();
|
|
321
|
+
const txResponse = await signer.sendTransaction({
|
|
322
|
+
to: tx.to,
|
|
323
|
+
data: tx.data,
|
|
324
|
+
value: BigInt(tx.value || '0'),
|
|
325
|
+
});
|
|
326
|
+
const receipt = await txResponse.wait();
|
|
327
|
+
return { status: 'success', transactionHash: receipt.hash };
|
|
328
|
+
} catch (err) {
|
|
329
|
+
return { status: 'fail', error: err.message };
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
document.getElementById('connect-btn').onclick = async function () {
|
|
334
|
+
if (!window.ethereum) return alert('Please install MetaMask!');
|
|
335
|
+
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
336
|
+
const accounts = await provider.send('eth_requestAccounts', []);
|
|
337
|
+
const network = await provider.getNetwork();
|
|
338
|
+
widget.account = {
|
|
339
|
+
address: accounts[0],
|
|
340
|
+
chainId: Number(network.chainId),
|
|
341
|
+
};
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
// React to wallet / chain changes
|
|
345
|
+
if (window.ethereum) {
|
|
346
|
+
window.ethereum.on('accountsChanged', async (accounts) => {
|
|
347
|
+
if (accounts.length === 0) {
|
|
348
|
+
widget.account = undefined;
|
|
349
|
+
} else {
|
|
350
|
+
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
351
|
+
const network = await provider.getNetwork();
|
|
352
|
+
widget.account = {
|
|
353
|
+
address: accounts[0],
|
|
354
|
+
chainId: Number(network.chainId),
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
window.ethereum.on('chainChanged', async () => {
|
|
359
|
+
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
360
|
+
const network = await provider.getNetwork();
|
|
361
|
+
const accounts = await provider.listAccounts();
|
|
362
|
+
if (accounts.length > 0) {
|
|
363
|
+
widget.account = {
|
|
364
|
+
address: accounts[0].address,
|
|
365
|
+
chainId: Number(network.chainId),
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
</script>
|
|
371
|
+
</body>
|
|
372
|
+
</html>
|
|
264
373
|
```
|
|
265
374
|
|
|
266
|
-
### Web Component — HTML Attributes
|
|
267
|
-
|
|
268
|
-
| Attribute | Type | Default | Description |
|
|
269
|
-
| --------------- | --------- | ---------------- | --------------------------------------------- |
|
|
270
|
-
| `position` | `string` | `'bottom-right'` | `'bottom-right'` or `'bottom-left'` |
|
|
271
|
-
| `primary-color` | `string` | `'#007bff'` | Widget accent color (hex or CSS color) |
|
|
272
|
-
| `button-size` | `number` | `60` | Floating button diameter in pixels |
|
|
273
|
-
| `z-index` | `number` | `9999` | CSS `z-index` of the widget |
|
|
274
|
-
| `default-open` | `boolean` | `false` | Set to `"true"` to open the chat on page load |
|
|
275
|
-
|
|
276
375
|
---
|
|
277
376
|
|
|
278
377
|
## Type Definitions
|
|
279
378
|
|
|
280
379
|
```typescript
|
|
281
380
|
interface Account {
|
|
282
|
-
address: string; // Wallet address (0x
|
|
381
|
+
address: string; // Wallet address (0x...)
|
|
283
382
|
chainId: number | string; // EIP-155 chain ID
|
|
284
383
|
}
|
|
285
384
|
|
|
@@ -287,7 +386,7 @@ interface Transaction {
|
|
|
287
386
|
from: string;
|
|
288
387
|
to: string;
|
|
289
388
|
data: string; // ABI-encoded calldata (hex)
|
|
290
|
-
value: string; // Native amount in wei
|
|
389
|
+
value: string; // Native token amount in wei
|
|
291
390
|
gasLimit?: string;
|
|
292
391
|
gasPrice?: string;
|
|
293
392
|
maxFeePerGas?: string;
|
|
@@ -303,7 +402,7 @@ interface TransactionResult {
|
|
|
303
402
|
}
|
|
304
403
|
|
|
305
404
|
interface ChatWidgetTheme {
|
|
306
|
-
primaryColor?: string; // Hex / CSS color
|
|
405
|
+
primaryColor?: string; // Hex / CSS color
|
|
307
406
|
buttonSize?: number; // Floating button size in px
|
|
308
407
|
zIndex?: number; // CSS z-index
|
|
309
408
|
}
|
|
@@ -330,34 +429,35 @@ type Language = 'en' | 'ja' | 'cn';
|
|
|
330
429
|
|
|
331
430
|
## AI Capabilities
|
|
332
431
|
|
|
333
|
-
The embedded AI (GPT-4.1-mini via Moralis Cortex) understands natural language and routes to on-chain actions
|
|
432
|
+
The embedded AI (GPT-4.1-mini via Moralis Cortex) understands natural language and automatically routes to on-chain actions:
|
|
334
433
|
|
|
335
|
-
|
|
|
336
|
-
|
|
|
337
|
-
| "Swap 1 ETH to USDC"
|
|
338
|
-
| "Swap max USDT to ETH"
|
|
339
|
-
| "Buy WBTC"
|
|
340
|
-
| "Send 10 USDC to 0x
|
|
341
|
-
| "Send 0.05 ETH to 0x
|
|
342
|
-
| "Wrap 1 ETH" / "Unwrap 0.5 WETH"
|
|
343
|
-
| "Show my NFTs"
|
|
344
|
-
| "Send my Bored Ape #1234 to 0x
|
|
345
|
-
| "What is the gas fee?"
|
|
346
|
-
| "What tokens are trending?"
|
|
434
|
+
| What the user says | Action performed |
|
|
435
|
+
| ---------------------------------- | ------------------------------------ |
|
|
436
|
+
| "Swap 1 ETH to USDC" | Token swap via deBridge |
|
|
437
|
+
| "Swap max USDT to ETH" | Swap with full-balance resolution |
|
|
438
|
+
| "Buy WBTC" | Trending token list for selection |
|
|
439
|
+
| "Send 10 USDC to 0x..." | ERC-20 transfer |
|
|
440
|
+
| "Send 0.05 ETH to 0x..." | Native token transfer |
|
|
441
|
+
| "Wrap 1 ETH" / "Unwrap 0.5 WETH" | Wrap / unwrap native token |
|
|
442
|
+
| "Show my NFTs" | Link to NFT gallery |
|
|
443
|
+
| "Send my Bored Ape #1234 to 0x..." | ERC-721 / ERC-1155 transfer |
|
|
444
|
+
| "What is the current gas fee?" | General blockchain Q&A |
|
|
445
|
+
| "What tokens are trending?" | Trending list with quick-buy buttons |
|
|
446
|
+
| "What is my balance?" | Token list with USD values |
|
|
347
447
|
|
|
348
|
-
### Smart
|
|
448
|
+
### Smart swap flow
|
|
349
449
|
|
|
350
450
|
The AI handles missing parameters gracefully:
|
|
351
451
|
|
|
352
|
-
|
|
|
353
|
-
|
|
|
354
|
-
| token_in + token_out + amount
|
|
355
|
-
| token_in + token_out
|
|
356
|
-
| token_out only
|
|
357
|
-
| token_in only
|
|
358
|
-
| Neither
|
|
359
|
-
| ERC-20 needs approval
|
|
360
|
-
| Insufficient balance
|
|
452
|
+
| Available information | Behaviour |
|
|
453
|
+
| -------------------------------- | --------------------------------------------- |
|
|
454
|
+
| token_in + token_out + amount | Full auto-swap: estimate → confirm → execute |
|
|
455
|
+
| token_in + token_out (no amount) | Shows 25 / 50 / 75 / 100 % amount selector |
|
|
456
|
+
| token_out only | Shows wallet balances to choose source token |
|
|
457
|
+
| token_in only | Shows trending tokens to choose destination |
|
|
458
|
+
| Neither token specified | Asks the user to specify both tokens |
|
|
459
|
+
| ERC-20 needs approval | Prompts Approve step before swap |
|
|
460
|
+
| Insufficient balance or fee | Warning message, no confirmation button shown |
|
|
361
461
|
|
|
362
462
|
---
|
|
363
463
|
|
|
@@ -411,7 +511,7 @@ yarn build:react
|
|
|
411
511
|
# Build Web Component bundle only
|
|
412
512
|
yarn build:wc
|
|
413
513
|
|
|
414
|
-
# Watch mode (auto-rebuild
|
|
514
|
+
# Watch mode (auto-rebuild on change)
|
|
415
515
|
yarn watch
|
|
416
516
|
|
|
417
517
|
# Lint
|
|
@@ -429,34 +529,35 @@ yarn format
|
|
|
429
529
|
```
|
|
430
530
|
src/
|
|
431
531
|
├── components/
|
|
432
|
-
│ ├── ActionForm.tsx
|
|
433
|
-
│ ├── ChatButton.tsx
|
|
434
|
-
│ ├── ChatModal.tsx
|
|
435
|
-
│ ├── ChatWidget.tsx
|
|
436
|
-
│ ├── MessageContent.tsx
|
|
532
|
+
│ ├── ActionForm.tsx # Inline transaction forms (send, approve, ...)
|
|
533
|
+
│ ├── ChatButton.tsx # Floating action button
|
|
534
|
+
│ ├── ChatModal.tsx # Chat UI + all AI and on-chain logic
|
|
535
|
+
│ ├── ChatWidget.tsx # Root component — public API entry point
|
|
536
|
+
│ ├── MessageContent.tsx # Markdown message renderer
|
|
437
537
|
│ ├── ScrollToBottomButton.tsx
|
|
438
538
|
│ └── WalletUserInfo.tsx
|
|
439
539
|
├── constants/
|
|
440
|
-
│ ├── agentActions.ts
|
|
441
|
-
│ ├── chains.ts
|
|
442
|
-
│ ├── storage.ts
|
|
443
|
-
│ └── systemPrompt.ts
|
|
540
|
+
│ ├── agentActions.ts # AgentActionType definitions + form schemas
|
|
541
|
+
│ ├── chains.ts # Supported chain configs
|
|
542
|
+
│ ├── storage.ts # localStorage key constants
|
|
543
|
+
│ └── systemPrompt.ts # AI system prompt builder
|
|
444
544
|
├── contexts/
|
|
445
|
-
│ ├── ConfigContext.tsx
|
|
446
|
-
│ ├── ConnectContext.tsx
|
|
447
|
-
│ └── LanguageContext.tsx
|
|
545
|
+
│ ├── ConfigContext.tsx # RPC URLs + theme config context
|
|
546
|
+
│ ├── ConnectContext.tsx # Wallet account context
|
|
547
|
+
│ └── LanguageContext.tsx # i18n language context
|
|
448
548
|
├── hooks/
|
|
449
|
-
│ └── useChatMessages.ts
|
|
549
|
+
│ └── useChatMessages.ts # Chat message state management
|
|
450
550
|
├── services/
|
|
451
|
-
│ ├── BaseApi.ts
|
|
452
|
-
│ ├── deBridge.ts
|
|
453
|
-
│ ├──
|
|
454
|
-
│ ├──
|
|
455
|
-
│
|
|
551
|
+
│ ├── BaseApi.ts # Base HTTP client
|
|
552
|
+
│ ├── deBridge.ts # deBridge swap quote + transaction API
|
|
553
|
+
│ ├── gemini.ts # Gemini AI: question classification, general chat
|
|
554
|
+
│ ├── moralis.ts # Moralis AI chat, wallet balances, NFTs, metadata
|
|
555
|
+
│ ├── token.ts # Token info + trending data
|
|
556
|
+
│ └── web3.ts # Transaction builder, fee estimation, allowance check
|
|
456
557
|
├── types/
|
|
457
|
-
│ └── index.ts
|
|
458
|
-
├── lib.tsx
|
|
459
|
-
└── web-component.tsx
|
|
558
|
+
│ └── index.ts # All public TypeScript interfaces
|
|
559
|
+
├── lib.tsx # React library entry point
|
|
560
|
+
└── web-component.tsx # Web Component entry point
|
|
460
561
|
```
|
|
461
562
|
|
|
462
563
|
---
|