@aomi-labs/widget-lib 0.2.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 +310 -0
- package/dist/core/AomiChatWidget.d.ts +41 -0
- package/dist/core/AomiChatWidget.d.ts.map +1 -0
- package/dist/core/ChatManager.d.ts +81 -0
- package/dist/core/ChatManager.d.ts.map +1 -0
- package/dist/core/ThemeManager.d.ts +80 -0
- package/dist/core/ThemeManager.d.ts.map +1 -0
- package/dist/core/WalletManager.d.ts +105 -0
- package/dist/core/WalletManager.d.ts.map +1 -0
- package/dist/index.d.ts +816 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3289 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3215 -0
- package/dist/index.mjs.map +1 -0
- package/dist/index.umd.js +3295 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/types/constants.d.ts +91 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/errors.d.ts +102 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/index.d.ts +263 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/utils/index.d.ts +99 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/package.json +89 -0
package/README.md
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
# @aomi-labs/widget-lib
|
|
2
|
+
|
|
3
|
+
Embeddable AI chat widget with Web3 capabilities for any website.
|
|
4
|
+
|
|
5
|
+
## 🚀 Quick Start
|
|
6
|
+
|
|
7
|
+
### Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @aomi-labs/widget-lib
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Basic Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createChatWidget } from '@aomi-labs/widget-lib';
|
|
17
|
+
|
|
18
|
+
const widget = createChatWidget('chat-container', {
|
|
19
|
+
appCode: 'my-dapp',
|
|
20
|
+
theme: 'terminal',
|
|
21
|
+
provider: window.ethereum
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Advanced Usage
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { createAomiChatWidget } from '@aomi-labs/widget-lib';
|
|
29
|
+
|
|
30
|
+
const widget = createAomiChatWidget(container, {
|
|
31
|
+
params: {
|
|
32
|
+
appCode: 'my-advanced-dapp',
|
|
33
|
+
theme: {
|
|
34
|
+
baseTheme: 'dark',
|
|
35
|
+
primary: '#00ff88',
|
|
36
|
+
background: '#0a0a0a'
|
|
37
|
+
},
|
|
38
|
+
width: '500px',
|
|
39
|
+
height: '700px',
|
|
40
|
+
enableTransactions: true,
|
|
41
|
+
chainId: 1
|
|
42
|
+
},
|
|
43
|
+
provider: window.ethereum,
|
|
44
|
+
listeners: {
|
|
45
|
+
onReady: () => console.log('Widget ready!'),
|
|
46
|
+
onMessage: (msg) => console.log('New message:', msg),
|
|
47
|
+
onTransactionRequest: (tx) => console.log('Transaction:', tx)
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 📚 Documentation
|
|
53
|
+
|
|
54
|
+
### Configuration Options
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
interface AomiChatWidgetParams {
|
|
58
|
+
// Required
|
|
59
|
+
appCode: string;
|
|
60
|
+
|
|
61
|
+
// Appearance
|
|
62
|
+
theme?: 'light' | 'dark' | 'terminal' | 'neon' | 'minimal' | CustomTheme;
|
|
63
|
+
width?: string;
|
|
64
|
+
height?: string;
|
|
65
|
+
mode?: 'full' | 'minimal' | 'compact' | 'terminal';
|
|
66
|
+
|
|
67
|
+
// Behavior
|
|
68
|
+
welcomeMessage?: string;
|
|
69
|
+
placeholder?: string;
|
|
70
|
+
enableTransactions?: boolean;
|
|
71
|
+
requireWalletConnection?: boolean;
|
|
72
|
+
|
|
73
|
+
// Network
|
|
74
|
+
chainId?: SupportedChainId;
|
|
75
|
+
supportedChains?: SupportedChainId[];
|
|
76
|
+
|
|
77
|
+
// Integration
|
|
78
|
+
baseUrl?: string;
|
|
79
|
+
apiKey?: string;
|
|
80
|
+
sessionId?: string;
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Event Handling
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
widget.on('ready', () => {
|
|
88
|
+
console.log('Widget is ready');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
widget.on('message', (message) => {
|
|
92
|
+
console.log('New message:', message.content);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
widget.on('transactionRequest', async (tx) => {
|
|
96
|
+
// Handle transaction request
|
|
97
|
+
console.log('Transaction requested:', tx);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
widget.on('walletConnect', (address) => {
|
|
101
|
+
console.log('Wallet connected:', address);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
widget.on('error', (error) => {
|
|
105
|
+
console.error('Widget error:', error);
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Widget Methods
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
// Send a message
|
|
113
|
+
await widget.sendMessage('Hello AI!');
|
|
114
|
+
|
|
115
|
+
// Update configuration
|
|
116
|
+
widget.updateParams({
|
|
117
|
+
theme: 'light',
|
|
118
|
+
enableTransactions: false
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Clear chat history
|
|
122
|
+
widget.clearChat();
|
|
123
|
+
|
|
124
|
+
// Export chat messages
|
|
125
|
+
const messages = widget.exportChat();
|
|
126
|
+
|
|
127
|
+
// Resize widget
|
|
128
|
+
widget.resize('600px', '800px');
|
|
129
|
+
|
|
130
|
+
// Destroy widget
|
|
131
|
+
widget.destroy();
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## 🎨 Themes
|
|
135
|
+
|
|
136
|
+
### Predefined Themes
|
|
137
|
+
|
|
138
|
+
- `light` - Clean light theme
|
|
139
|
+
- `dark` - Modern dark theme
|
|
140
|
+
- `terminal` - Green terminal style
|
|
141
|
+
- `neon` - Cyberpunk neon theme
|
|
142
|
+
- `minimal` - Clean minimal design
|
|
143
|
+
|
|
144
|
+
### Custom Themes
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
const customTheme = {
|
|
148
|
+
baseTheme: 'dark',
|
|
149
|
+
primary: '#ff6b35',
|
|
150
|
+
background: '#1a1a1a',
|
|
151
|
+
surface: '#2d2d2d',
|
|
152
|
+
text: '#ffffff',
|
|
153
|
+
textSecondary: '#cccccc',
|
|
154
|
+
border: '#404040',
|
|
155
|
+
success: '#00d26a',
|
|
156
|
+
error: '#ff4757',
|
|
157
|
+
warning: '#ffa500',
|
|
158
|
+
accent: '#8b5cf6'
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
widget.updateParams({ theme: customTheme });
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## 🌐 Network Support
|
|
165
|
+
|
|
166
|
+
Supported networks:
|
|
167
|
+
- Ethereum Mainnet (1)
|
|
168
|
+
- Goerli Testnet (5)
|
|
169
|
+
- Sepolia Testnet (11155111)
|
|
170
|
+
- Gnosis Chain (100)
|
|
171
|
+
- Polygon (137)
|
|
172
|
+
- Arbitrum One (42161)
|
|
173
|
+
- Base (8453)
|
|
174
|
+
- Optimism (10)
|
|
175
|
+
|
|
176
|
+
## 🔧 Advanced Features
|
|
177
|
+
|
|
178
|
+
### Flexible Configuration
|
|
179
|
+
|
|
180
|
+
Configure different settings per network or mode:
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
const config = {
|
|
184
|
+
appCode: 'my-app',
|
|
185
|
+
// Different settings per network
|
|
186
|
+
enableTransactions: {
|
|
187
|
+
1: true, // Mainnet: enabled
|
|
188
|
+
5: false, // Goerli: disabled
|
|
189
|
+
100: true // Gnosis: enabled
|
|
190
|
+
},
|
|
191
|
+
// Different settings per mode
|
|
192
|
+
welcomeMessage: {
|
|
193
|
+
full: 'Welcome to our full chat experience!',
|
|
194
|
+
minimal: 'Hi there!',
|
|
195
|
+
compact: 'Hello!'
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Custom Commands
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
const widget = createAomiChatWidget(container, {
|
|
204
|
+
params: {
|
|
205
|
+
appCode: 'my-app',
|
|
206
|
+
customCommands: [
|
|
207
|
+
{
|
|
208
|
+
command: 'balance',
|
|
209
|
+
description: 'Check wallet balance',
|
|
210
|
+
handler: async (args) => {
|
|
211
|
+
// Custom command logic
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
]
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Rate Limiting
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
const config = {
|
|
223
|
+
appCode: 'my-app',
|
|
224
|
+
rateLimiting: {
|
|
225
|
+
maxMessages: 10,
|
|
226
|
+
windowMs: 60000, // 1 minute
|
|
227
|
+
skipWhenConnected: true
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## 🧪 Development
|
|
233
|
+
|
|
234
|
+
### Building
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
npm run build
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Testing
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
npm test
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Development Server
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
npm run dev
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## 📦 Package Exports
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
// Main factory functions
|
|
256
|
+
import { createChatWidget, createAomiChatWidget } from '@aomi-labs/widget-lib';
|
|
257
|
+
|
|
258
|
+
// Core managers
|
|
259
|
+
import { ChatManager, ThemeManager, WalletManager } from '@aomi-labs/widget-lib';
|
|
260
|
+
|
|
261
|
+
// Types
|
|
262
|
+
import type {
|
|
263
|
+
AomiChatWidgetParams,
|
|
264
|
+
AomiChatWidgetHandler,
|
|
265
|
+
ChatMessage,
|
|
266
|
+
WalletTransaction
|
|
267
|
+
} from '@aomi-labs/widget-lib';
|
|
268
|
+
|
|
269
|
+
// Constants
|
|
270
|
+
import {
|
|
271
|
+
SUPPORTED_CHAINS,
|
|
272
|
+
PREDEFINED_THEMES,
|
|
273
|
+
ERROR_CODES
|
|
274
|
+
} from '@aomi-labs/widget-lib';
|
|
275
|
+
|
|
276
|
+
// Utilities
|
|
277
|
+
import {
|
|
278
|
+
validateWidgetParams,
|
|
279
|
+
generateSessionId,
|
|
280
|
+
formatTimestamp
|
|
281
|
+
} from '@aomi-labs/widget-lib';
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## 🔗 Related Packages
|
|
285
|
+
|
|
286
|
+
- `@aomi-labs/widget-react` - React wrapper component
|
|
287
|
+
- `@aomi-labs/widget-vue` - Vue.js wrapper component
|
|
288
|
+
- `@aomi-labs/widget-themes` - Additional theme packs
|
|
289
|
+
|
|
290
|
+
## 📄 License
|
|
291
|
+
|
|
292
|
+
MIT License - see LICENSE file for details.
|
|
293
|
+
|
|
294
|
+
## 🤝 Contributing
|
|
295
|
+
|
|
296
|
+
1. Fork the repository
|
|
297
|
+
2. Create a feature branch
|
|
298
|
+
3. Make your changes
|
|
299
|
+
4. Add tests
|
|
300
|
+
5. Submit a pull request
|
|
301
|
+
|
|
302
|
+
## 📞 Support
|
|
303
|
+
|
|
304
|
+
- Documentation: [docs.aomi.ai/widget](https://docs.aomi.ai/widget)
|
|
305
|
+
- Issues: [GitHub Issues](https://github.com/aomi-labs/widget-lib/issues)
|
|
306
|
+
- Discord: [Aomi Labs Community](https://discord.gg/aomi)
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
Built with ❤️ by [Aomi Labs](https://aomi.ai)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AomiChatWidgetParams, AomiChatWidgetHandler, WidgetConfig, ChatState, AomiChatEventListeners, EthereumProvider, ChatMessage } from '../types';
|
|
2
|
+
declare class AomiChatWidgetHandlerImpl implements AomiChatWidgetHandler {
|
|
3
|
+
private container;
|
|
4
|
+
private config;
|
|
5
|
+
private chatManager;
|
|
6
|
+
private themeManager;
|
|
7
|
+
private walletManager;
|
|
8
|
+
private widgetElement;
|
|
9
|
+
private isDestroyed;
|
|
10
|
+
private eventEmitter;
|
|
11
|
+
constructor(container: HTMLElement, config: WidgetConfig);
|
|
12
|
+
sendMessage(message: string): Promise<void>;
|
|
13
|
+
updateParams(params: Partial<AomiChatWidgetParams>): void;
|
|
14
|
+
updateProvider(provider?: EthereumProvider): void;
|
|
15
|
+
getState(): ChatState;
|
|
16
|
+
getSessionId(): string;
|
|
17
|
+
isReady(): boolean;
|
|
18
|
+
on<K extends keyof AomiChatEventListeners>(event: K, listener: NonNullable<AomiChatEventListeners[K]>): AomiChatWidgetHandler;
|
|
19
|
+
off<K extends keyof AomiChatEventListeners>(event: K, listener: NonNullable<AomiChatEventListeners[K]>): AomiChatWidgetHandler;
|
|
20
|
+
clearChat(): void;
|
|
21
|
+
exportChat(): ChatMessage[];
|
|
22
|
+
resize(width?: string, height?: string): void;
|
|
23
|
+
focus(): void;
|
|
24
|
+
destroy(): void;
|
|
25
|
+
private initialize;
|
|
26
|
+
private setupEventListeners;
|
|
27
|
+
private setupWalletEventListeners;
|
|
28
|
+
private forwardStateEvents;
|
|
29
|
+
private handleTransactionRequest;
|
|
30
|
+
private render;
|
|
31
|
+
private renderChatInterface;
|
|
32
|
+
private applyTheme;
|
|
33
|
+
private getModeClass;
|
|
34
|
+
private updateDimensions;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates and initializes an Aomi Chat Widget
|
|
38
|
+
*/
|
|
39
|
+
export declare function createAomiChatWidget(container: HTMLElement, config: WidgetConfig): AomiChatWidgetHandler;
|
|
40
|
+
export { AomiChatWidgetHandlerImpl as AomiChatWidgetHandler };
|
|
41
|
+
//# sourceMappingURL=AomiChatWidget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AomiChatWidget.d.ts","sourceRoot":"","sources":["../../src/core/AomiChatWidget.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACrB,YAAY,EACZ,SAAS,EACT,sBAAsB,EACtB,gBAAgB,EAChB,WAAW,EAEZ,MAAM,UAAU,CAAC;AA8BlB,cAAM,yBAA0B,YAAW,qBAAqB;IAC9D,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,aAAa,CAA8B;IACnD,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,YAAY,CAAe;gBAEvB,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY;IA+B3C,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQjD,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,oBAAoB,CAAC,GAAG,IAAI;IA+BzD,cAAc,CAAC,QAAQ,CAAC,EAAE,gBAAgB,GAAG,IAAI;IAsBjD,QAAQ,IAAI,SAAS;IAIrB,YAAY,IAAI,MAAM;IAItB,OAAO,IAAI,OAAO;IAKlB,EAAE,CAAC,CAAC,SAAS,MAAM,sBAAsB,EAC9C,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,WAAW,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,GAC/C,qBAAqB;IAKjB,GAAG,CAAC,CAAC,SAAS,MAAM,sBAAsB,EAC/C,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,WAAW,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,GAC/C,qBAAqB;IAKjB,SAAS,IAAI,IAAI;IAKjB,UAAU,IAAI,WAAW,EAAE;IAI3B,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAa7C,KAAK,IAAI,IAAI;IASb,OAAO,IAAI,IAAI;YA+BR,UAAU;IAoBxB,OAAO,CAAC,mBAAmB;IA8B3B,OAAO,CAAC,yBAAyB;IA2BjC,OAAO,CAAC,kBAAkB;YAMZ,wBAAwB;IAyBtC,OAAO,CAAC,MAAM;IA+Bd,OAAO,CAAC,mBAAmB;IAiC3B,OAAO,CAAC,UAAU;IAmBlB,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,gBAAgB;CAMzB;AAMD;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,WAAW,EACtB,MAAM,EAAE,YAAY,GACnB,qBAAqB,CAmBvB;AAGD,OAAO,EAAE,yBAAyB,IAAI,qBAAqB,EAAE,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { EventEmitter } from 'eventemitter3';
|
|
2
|
+
import type { ChatMessage, ChatState, WalletTransaction, WalletState, ChatManagerConfig, AomiChatError } from '../types';
|
|
3
|
+
import { ConnectionStatus } from '../types';
|
|
4
|
+
interface ChatManagerEvents {
|
|
5
|
+
stateChange: (state: ChatState) => void;
|
|
6
|
+
message: (message: ChatMessage) => void;
|
|
7
|
+
error: (error: AomiChatError) => void;
|
|
8
|
+
connectionChange: (status: ConnectionStatus) => void;
|
|
9
|
+
transactionRequest: (transaction: WalletTransaction) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare class ChatManager extends EventEmitter<ChatManagerEvents> {
|
|
12
|
+
private config;
|
|
13
|
+
private state;
|
|
14
|
+
private eventSource;
|
|
15
|
+
private reconnectAttempt;
|
|
16
|
+
private reconnectTimer;
|
|
17
|
+
private heartbeatTimer;
|
|
18
|
+
constructor(config?: Partial<ChatManagerConfig>);
|
|
19
|
+
/**
|
|
20
|
+
* Gets the current state
|
|
21
|
+
*/
|
|
22
|
+
getState(): ChatState;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the session ID
|
|
25
|
+
*/
|
|
26
|
+
getSessionId(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Sets a new session ID and reconnects if needed
|
|
29
|
+
*/
|
|
30
|
+
setSessionId(sessionId: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Connects to the backend via Server-Sent Events
|
|
33
|
+
*/
|
|
34
|
+
connectSSE(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Disconnects from the backend
|
|
37
|
+
*/
|
|
38
|
+
disconnectSSE(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Sends a message to the backend
|
|
41
|
+
*/
|
|
42
|
+
sendMessage(message: string): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Sends a system message
|
|
45
|
+
*/
|
|
46
|
+
sendSystemMessage(message: string): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Interrupts current processing
|
|
49
|
+
*/
|
|
50
|
+
interrupt(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Sends transaction result back to backend
|
|
53
|
+
*/
|
|
54
|
+
sendTransactionResult(success: boolean, txHash?: string, error?: string): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Clears all messages
|
|
57
|
+
*/
|
|
58
|
+
clearMessages(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Updates wallet state
|
|
61
|
+
*/
|
|
62
|
+
updateWalletState(walletState: Partial<WalletState>): void;
|
|
63
|
+
/**
|
|
64
|
+
* Destroys the chat manager
|
|
65
|
+
*/
|
|
66
|
+
destroy(): void;
|
|
67
|
+
private handleBackendMessage;
|
|
68
|
+
private normalizeReadiness;
|
|
69
|
+
private addMessage;
|
|
70
|
+
private setConnectionStatus;
|
|
71
|
+
private setReadiness;
|
|
72
|
+
private emitStateChange;
|
|
73
|
+
private postToBackend;
|
|
74
|
+
private handleConnectionError;
|
|
75
|
+
private scheduleReconnect;
|
|
76
|
+
private clearReconnectTimer;
|
|
77
|
+
private startHeartbeat;
|
|
78
|
+
private stopHeartbeat;
|
|
79
|
+
}
|
|
80
|
+
export {};
|
|
81
|
+
//# sourceMappingURL=ChatManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatManager.d.ts","sourceRoot":"","sources":["../../src/core/ChatManager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EAET,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,aAAa,EACd,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,gBAAgB,EAEjB,MAAM,UAAU,CAAC;AA4BlB,UAAU,iBAAiB;IACzB,WAAW,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IACxC,OAAO,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IACxC,KAAK,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACtC,gBAAgB,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACrD,kBAAkB,EAAE,CAAC,WAAW,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAC9D;AAMD,qBAAa,WAAY,SAAQ,YAAY,CAAC,iBAAiB,CAAC;IAC9D,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,KAAK,CAAY;IACzB,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,cAAc,CAA+B;gBAEzC,MAAM,GAAE,OAAO,CAAC,iBAAiB,CAAM;IA+BnD;;OAEG;IACI,QAAQ,IAAI,SAAS;IAI5B;;OAEG;IACI,YAAY,IAAI,MAAM;IAI7B;;OAEG;IACI,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAS5C;;OAEG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAyCxC;;OAEG;IACI,aAAa,IAAI,IAAI;IAW5B;;OAEG;IACU,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAsCxD;;OAEG;IACU,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY9D;;OAEG;IACU,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAWvC;;OAEG;IACU,qBAAqB,CAChC,OAAO,EAAE,OAAO,EAChB,MAAM,CAAC,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC;IAUhB;;OAEG;IACI,aAAa,IAAI,IAAI;IAK5B;;OAEG;IACI,iBAAiB,CAAC,WAAW,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI;IAKjE;;OAEG;IACI,OAAO,IAAI,IAAI;IAStB,OAAO,CAAC,oBAAoB;IAuD5B,OAAO,CAAC,kBAAkB;IA2B1B,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,eAAe;YAIT,aAAa;IA4B3B,OAAO,CAAC,qBAAqB;IAW7B,OAAO,CAAC,iBAAiB;IAgBzB,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,cAAc;IAatB,OAAO,CAAC,aAAa;CAMtB"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { AomiChatTheme, AomiChatWidgetPalette, AomiChatWidgetPaletteColors, ThemeDefinition } from '../types';
|
|
2
|
+
export declare class ThemeManager {
|
|
3
|
+
private currentTheme;
|
|
4
|
+
private customPalette;
|
|
5
|
+
constructor(theme?: AomiChatTheme | AomiChatWidgetPalette);
|
|
6
|
+
/**
|
|
7
|
+
* Updates the current theme
|
|
8
|
+
*/
|
|
9
|
+
updateTheme(theme?: AomiChatTheme | AomiChatWidgetPalette): void;
|
|
10
|
+
/**
|
|
11
|
+
* Gets the current computed theme
|
|
12
|
+
*/
|
|
13
|
+
getComputedTheme(): ThemeDefinition;
|
|
14
|
+
/**
|
|
15
|
+
* Gets a specific color from the current theme
|
|
16
|
+
*/
|
|
17
|
+
getColor(colorKey: keyof AomiChatWidgetPaletteColors): string;
|
|
18
|
+
/**
|
|
19
|
+
* Gets the CSS class name for the current theme
|
|
20
|
+
*/
|
|
21
|
+
getThemeClass(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Gets the font family for the current theme
|
|
24
|
+
*/
|
|
25
|
+
getFontFamily(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Gets the monospace font family for the current theme
|
|
28
|
+
*/
|
|
29
|
+
getMonospaceFontFamily(): string;
|
|
30
|
+
/**
|
|
31
|
+
* Gets a spacing value for the current theme
|
|
32
|
+
*/
|
|
33
|
+
getSpacing(size: 'xs' | 'sm' | 'md' | 'lg' | 'xl'): string;
|
|
34
|
+
/**
|
|
35
|
+
* Gets a border radius value for the current theme
|
|
36
|
+
*/
|
|
37
|
+
getBorderRadius(size: 'sm' | 'md' | 'lg'): string;
|
|
38
|
+
/**
|
|
39
|
+
* Gets a shadow value for the current theme
|
|
40
|
+
*/
|
|
41
|
+
getShadow(size: 'sm' | 'md' | 'lg'): string;
|
|
42
|
+
/**
|
|
43
|
+
* Generates CSS custom properties for the current theme
|
|
44
|
+
*/
|
|
45
|
+
getCSSCustomProperties(): Record<string, string>;
|
|
46
|
+
/**
|
|
47
|
+
* Applies the theme to a DOM element
|
|
48
|
+
*/
|
|
49
|
+
applyThemeToElement(element: HTMLElement): void;
|
|
50
|
+
/**
|
|
51
|
+
* Generates CSS string for the current theme
|
|
52
|
+
*/
|
|
53
|
+
generateCSS(selector?: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Destroys the theme manager
|
|
56
|
+
*/
|
|
57
|
+
destroy(): void;
|
|
58
|
+
private resolveTheme;
|
|
59
|
+
private isCustomPalette;
|
|
60
|
+
private getBaseThemeName;
|
|
61
|
+
private isPaletteEqual;
|
|
62
|
+
private generateComponentCSS;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Creates a theme manager instance
|
|
66
|
+
*/
|
|
67
|
+
export declare function createThemeManager(theme?: AomiChatTheme | AomiChatWidgetPalette): ThemeManager;
|
|
68
|
+
/**
|
|
69
|
+
* Gets all available predefined themes
|
|
70
|
+
*/
|
|
71
|
+
export declare function getAvailableThemes(): Record<string, ThemeDefinition>;
|
|
72
|
+
/**
|
|
73
|
+
* Validates a custom palette
|
|
74
|
+
*/
|
|
75
|
+
export declare function validateCustomPalette(palette: unknown): palette is AomiChatWidgetPalette;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a custom palette from a base theme
|
|
78
|
+
*/
|
|
79
|
+
export declare function createCustomPalette(baseTheme: AomiChatTheme, overrides: Partial<AomiChatWidgetPaletteColors>): AomiChatWidgetPalette;
|
|
80
|
+
//# sourceMappingURL=ThemeManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeManager.d.ts","sourceRoot":"","sources":["../../src/core/ThemeManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,qBAAqB,EACrB,2BAA2B,EAC3B,eAAe,EAChB,MAAM,UAAU,CAAC;AAYlB,qBAAa,YAAY;IACvB,OAAO,CAAC,YAAY,CAAkB;IACtC,OAAO,CAAC,aAAa,CAA4C;gBAErD,KAAK,CAAC,EAAE,aAAa,GAAG,qBAAqB;IAQzD;;OAEG;IACI,WAAW,CAAC,KAAK,CAAC,EAAE,aAAa,GAAG,qBAAqB,GAAG,IAAI;IAKvE;;OAEG;IACI,gBAAgB,IAAI,eAAe;IAU1C;;OAEG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
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { EventEmitter } from 'eventemitter3';
|
|
2
|
+
import type { EthereumProvider, SupportedChainId, AomiChatError } from '../types';
|
|
3
|
+
interface TransactionRequest {
|
|
4
|
+
to: string;
|
|
5
|
+
value: string;
|
|
6
|
+
data: string;
|
|
7
|
+
gas?: string;
|
|
8
|
+
}
|
|
9
|
+
interface WalletManagerEvents {
|
|
10
|
+
connect: (address: string) => void;
|
|
11
|
+
disconnect: () => void;
|
|
12
|
+
chainChange: (chainId: SupportedChainId) => void;
|
|
13
|
+
accountsChange: (accounts: string[]) => void;
|
|
14
|
+
error: (error: AomiChatError) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare class WalletManager extends EventEmitter<WalletManagerEvents> {
|
|
17
|
+
private provider;
|
|
18
|
+
private currentAccount;
|
|
19
|
+
private currentChainId;
|
|
20
|
+
private isConnected;
|
|
21
|
+
constructor(provider: EthereumProvider);
|
|
22
|
+
/**
|
|
23
|
+
* Gets the current connected account
|
|
24
|
+
*/
|
|
25
|
+
getCurrentAccount(): string | null;
|
|
26
|
+
/**
|
|
27
|
+
* Gets the current chain ID
|
|
28
|
+
*/
|
|
29
|
+
getCurrentChainId(): SupportedChainId | null;
|
|
30
|
+
/**
|
|
31
|
+
* Gets the current network name
|
|
32
|
+
*/
|
|
33
|
+
getCurrentNetworkName(): string | null;
|
|
34
|
+
/**
|
|
35
|
+
* Checks if wallet is connected
|
|
36
|
+
*/
|
|
37
|
+
getIsConnected(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Connects to the wallet
|
|
40
|
+
*/
|
|
41
|
+
connect(): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Disconnects from the wallet
|
|
44
|
+
*/
|
|
45
|
+
disconnect(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Switches to a specific network
|
|
48
|
+
*/
|
|
49
|
+
switchNetwork(chainId: SupportedChainId): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Sends a transaction
|
|
52
|
+
*/
|
|
53
|
+
sendTransaction(transaction: TransactionRequest): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Signs a message
|
|
56
|
+
*/
|
|
57
|
+
signMessage(message: string): Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* Gets account balance
|
|
60
|
+
*/
|
|
61
|
+
getBalance(address?: string): Promise<string>;
|
|
62
|
+
/**
|
|
63
|
+
* Updates the provider
|
|
64
|
+
*/
|
|
65
|
+
updateProvider(provider: EthereumProvider): void;
|
|
66
|
+
/**
|
|
67
|
+
* Destroys the wallet manager
|
|
68
|
+
*/
|
|
69
|
+
destroy(): void;
|
|
70
|
+
private initializeState;
|
|
71
|
+
private updateChainId;
|
|
72
|
+
private setupEventListeners;
|
|
73
|
+
private removeProviderListeners;
|
|
74
|
+
private handleAccountsChanged;
|
|
75
|
+
private handleChainChanged;
|
|
76
|
+
private handleDisconnect;
|
|
77
|
+
private validateTransaction;
|
|
78
|
+
private addNetwork;
|
|
79
|
+
private getNetworkConfig;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Creates a wallet manager instance
|
|
83
|
+
*/
|
|
84
|
+
export declare function createWalletManager(provider: EthereumProvider): WalletManager;
|
|
85
|
+
/**
|
|
86
|
+
* Checks if a provider supports the required methods
|
|
87
|
+
*/
|
|
88
|
+
export declare function isValidProvider(provider: unknown): provider is EthereumProvider;
|
|
89
|
+
/**
|
|
90
|
+
* Detects available wallets
|
|
91
|
+
*/
|
|
92
|
+
export declare function detectWallets(): Array<{
|
|
93
|
+
name: string;
|
|
94
|
+
provider: EthereumProvider;
|
|
95
|
+
}>;
|
|
96
|
+
declare global {
|
|
97
|
+
interface Window {
|
|
98
|
+
ethereum?: EthereumProvider & {
|
|
99
|
+
isMetaMask?: boolean;
|
|
100
|
+
isWalletConnect?: boolean;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export {};
|
|
105
|
+
//# sourceMappingURL=WalletManager.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