@bytexbyte/nxtlinq-ai-agent-sdk 1.2.2 → 1.2.3
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 +175 -221
- package/dist/api/nxtlinq-api.d.ts.map +1 -1
- package/dist/api/nxtlinq-api.js +121 -142
- package/dist/components/ChatBot.d.ts +2 -44
- package/dist/components/ChatBot.d.ts.map +1 -1
- package/dist/components/ChatBot.js +5 -1241
- package/dist/components/context/ChatBotContext.d.ts +5 -0
- package/dist/components/context/ChatBotContext.d.ts.map +1 -0
- package/dist/components/context/ChatBotContext.js +737 -0
- package/dist/components/types/ChatBotTypes.d.ts +98 -0
- package/dist/components/types/ChatBotTypes.d.ts.map +1 -0
- package/dist/components/types/ChatBotTypes.js +1 -0
- package/dist/components/ui/ChatBotUI.d.ts +3 -0
- package/dist/components/ui/ChatBotUI.d.ts.map +1 -0
- package/dist/components/ui/ChatBotUI.js +146 -0
- package/dist/components/ui/MessageInput.d.ts +3 -0
- package/dist/components/ui/MessageInput.d.ts.map +1 -0
- package/dist/components/ui/MessageInput.js +46 -0
- package/dist/components/ui/MessageList.d.ts +3 -0
- package/dist/components/ui/MessageList.d.ts.map +1 -0
- package/dist/components/ui/MessageList.js +54 -0
- package/dist/components/ui/NotificationModal.d.ts +14 -0
- package/dist/components/ui/NotificationModal.d.ts.map +1 -0
- package/dist/components/ui/NotificationModal.js +79 -0
- package/dist/components/ui/PermissionForm.d.ts +8 -0
- package/dist/components/ui/PermissionForm.d.ts.map +1 -0
- package/dist/components/ui/PermissionForm.js +299 -0
- package/dist/components/ui/PresetMessages.d.ts +3 -0
- package/dist/components/ui/PresetMessages.d.ts.map +1 -0
- package/dist/components/ui/PresetMessages.js +35 -0
- package/dist/core/utils/aitUtils.d.ts +28 -0
- package/dist/core/utils/aitUtils.d.ts.map +1 -0
- package/dist/core/utils/aitUtils.js +34 -0
- package/dist/core/utils/notificationUtils.d.ts +29 -0
- package/dist/core/utils/notificationUtils.d.ts.map +1 -0
- package/dist/core/utils/notificationUtils.js +47 -0
- package/dist/core/utils/walletUtils.d.ts +10 -0
- package/dist/core/utils/walletUtils.d.ts.map +1 -0
- package/dist/core/utils/walletUtils.js +38 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,282 +1,236 @@
|
|
|
1
1
|
# Nxtlinq AI Agent SDK
|
|
2
2
|
|
|
3
|
-
A
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- 🔐 AIT (AI Identity Token) management
|
|
17
|
-
- 🔑 Permission-based access control
|
|
18
|
-
- 🔍 Enhanced error handling and debugging
|
|
19
|
-
- ⚡ Improved async operation handling
|
|
20
|
-
- 🔔 Unified notification system with Modal prompts
|
|
21
|
-
|
|
22
|
-
## Installation
|
|
3
|
+
A React SDK designed for Nxtlinq AI Agent, providing complete wallet connection, AIT management, and AI conversation functionality.
|
|
4
|
+
|
|
5
|
+
## 🚀 Features
|
|
6
|
+
|
|
7
|
+
- **Modular Design**: Clear code structure, easy to maintain and extend
|
|
8
|
+
- **Wallet Integration**: Support for MetaKeep wallet connection and verification
|
|
9
|
+
- **AIT Management**: Complete AIT (AI Identity Token) creation and management
|
|
10
|
+
- **Permission Control**: Fine-grained permission management and validation
|
|
11
|
+
- **Real-time Chat**: Real-time conversation functionality with AI Agent
|
|
12
|
+
- **Type Safety**: Complete TypeScript type definitions
|
|
13
|
+
- **Responsive UI**: Modern user interface design
|
|
14
|
+
|
|
15
|
+
## 📦 Installation
|
|
23
16
|
|
|
24
17
|
```bash
|
|
25
|
-
npm install @bytexbyte/nxtlinq-ai-agent-sdk
|
|
26
|
-
# or
|
|
27
|
-
yarn add @bytexbyte/nxtlinq-ai-agent-sdk@1.1.9
|
|
18
|
+
npm install @bytexbyte/nxtlinq-ai-agent-sdk
|
|
28
19
|
```
|
|
29
20
|
|
|
30
|
-
## Quick Start
|
|
21
|
+
## 🎯 Quick Start
|
|
22
|
+
|
|
23
|
+
### Basic Usage
|
|
31
24
|
|
|
32
25
|
```tsx
|
|
33
26
|
import { ChatBot } from '@bytexbyte/nxtlinq-ai-agent-sdk';
|
|
34
27
|
|
|
35
28
|
function App() {
|
|
36
|
-
const handleMessage = (message) => {
|
|
37
|
-
console.log('Received new message:', message);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const handleToolUse = async (toolUse) => {
|
|
41
|
-
console.log('Tool use:', toolUse);
|
|
42
|
-
return {
|
|
43
|
-
id: Date.now().toString(),
|
|
44
|
-
content: 'Tool execution response',
|
|
45
|
-
role: 'assistant',
|
|
46
|
-
timestamp: new Date().toISOString()
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const presetMessages = [
|
|
51
|
-
{ text: 'Hello, how can you help me?' },
|
|
52
|
-
{ text: 'I want to add a new member' },
|
|
53
|
-
{ text: 'I want to view the analytics page' },
|
|
54
|
-
{ text: 'I want to change my name' }
|
|
55
|
-
];
|
|
56
|
-
|
|
57
29
|
return (
|
|
58
30
|
<ChatBot
|
|
59
31
|
serviceId="your-service-id"
|
|
60
32
|
apiKey="your-api-key"
|
|
61
33
|
apiSecret="your-api-secret"
|
|
62
|
-
onMessage={
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return { token: 'verification-token' };
|
|
34
|
+
onMessage={(message) => console.log('New message:', message)}
|
|
35
|
+
onError={(error) => console.error('Error:', error)}
|
|
36
|
+
onToolUse={async (toolUse) => {
|
|
37
|
+
// Handle tool calls
|
|
38
|
+
console.log('Tool use:', toolUse);
|
|
68
39
|
}}
|
|
69
40
|
/>
|
|
70
41
|
);
|
|
71
42
|
}
|
|
72
43
|
```
|
|
73
44
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
## Berify.me Integration
|
|
77
|
-
|
|
78
|
-
The SDK supports Berify.me wallet verification for enhanced security:
|
|
45
|
+
### Advanced Configuration
|
|
79
46
|
|
|
80
47
|
```tsx
|
|
81
48
|
import { ChatBot } from '@bytexbyte/nxtlinq-ai-agent-sdk';
|
|
82
49
|
|
|
83
50
|
function App() {
|
|
84
|
-
const handleVerifyWallet = async () => {
|
|
85
|
-
// Open Berify.me verification modal
|
|
86
|
-
const modal = window.open(
|
|
87
|
-
'https://berify.me/verify',
|
|
88
|
-
'BerifyMeModal',
|
|
89
|
-
'width=500,height=600'
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
return new Promise((resolve) => {
|
|
93
|
-
const handleMessage = (event) => {
|
|
94
|
-
if (event.origin === 'https://berify.me' && event.data.type === 'VERIFICATION_SUCCESS') {
|
|
95
|
-
window.removeEventListener('message', handleMessage);
|
|
96
|
-
modal?.close();
|
|
97
|
-
resolve({ token: event.data.token });
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
window.addEventListener('message', handleMessage);
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
|
|
105
51
|
return (
|
|
106
52
|
<ChatBot
|
|
107
53
|
serviceId="your-service-id"
|
|
108
54
|
apiKey="your-api-key"
|
|
109
55
|
apiSecret="your-api-secret"
|
|
110
|
-
|
|
56
|
+
permissionGroup="default"
|
|
57
|
+
maxRetries={3}
|
|
58
|
+
retryDelay={1000}
|
|
59
|
+
placeholder="Type your message..."
|
|
60
|
+
presetMessages={[
|
|
61
|
+
{ text: "Hello", autoSend: false },
|
|
62
|
+
{ text: "Help", autoSend: true }
|
|
63
|
+
]}
|
|
64
|
+
onVerifyWallet={async () => {
|
|
65
|
+
// Custom wallet verification logic
|
|
66
|
+
return { token: "verification-token" };
|
|
67
|
+
}}
|
|
111
68
|
/>
|
|
112
69
|
);
|
|
113
70
|
}
|
|
114
71
|
```
|
|
115
72
|
|
|
116
|
-
##
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
## Types
|
|
148
|
-
|
|
149
|
-
### Message
|
|
150
|
-
```typescript
|
|
151
|
-
interface Message {
|
|
152
|
-
id: string;
|
|
153
|
-
content: string;
|
|
154
|
-
role: 'user' | 'assistant';
|
|
155
|
-
timestamp: string;
|
|
156
|
-
button?: string;
|
|
157
|
-
error?: string;
|
|
158
|
-
}
|
|
73
|
+
## 🏗️ Project Structure
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
src/
|
|
77
|
+
├── components/ # React Components
|
|
78
|
+
│ ├── ChatBot.tsx # Main component entry
|
|
79
|
+
│ ├── context/ # Context and state management
|
|
80
|
+
│ │ └── ChatBotContext.tsx
|
|
81
|
+
│ ├── types/ # Type definitions
|
|
82
|
+
│ │ └── ChatBotTypes.ts
|
|
83
|
+
│ └── ui/ # UI Components
|
|
84
|
+
│ ├── ChatBotUI.tsx
|
|
85
|
+
│ ├── MessageList.tsx
|
|
86
|
+
│ ├── MessageInput.tsx
|
|
87
|
+
│ ├── PresetMessages.tsx
|
|
88
|
+
│ ├── PermissionForm.tsx
|
|
89
|
+
│ └── NotificationModal.tsx
|
|
90
|
+
├── api/ # API Layer
|
|
91
|
+
│ └── nxtlinq-api.ts # API Client
|
|
92
|
+
├── core/ # Core functionality
|
|
93
|
+
│ ├── metakeepClient.ts
|
|
94
|
+
│ ├── lib/ # Utility libraries
|
|
95
|
+
│ │ └── useLocalStorage.ts
|
|
96
|
+
│ └── utils/ # Utility functions
|
|
97
|
+
│ ├── walletUtils.ts
|
|
98
|
+
│ ├── aitUtils.ts
|
|
99
|
+
│ └── notificationUtils.ts
|
|
100
|
+
├── types/ # Global type definitions
|
|
101
|
+
│ ├── ait-api.ts
|
|
102
|
+
│ └── window.d.ts
|
|
103
|
+
└── index.ts # Main entry file
|
|
159
104
|
```
|
|
160
105
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
106
|
+
## 🔧 API Reference
|
|
107
|
+
|
|
108
|
+
### ChatBot Props
|
|
109
|
+
|
|
110
|
+
| Property | Type | Required | Description |
|
|
111
|
+
|----------|------|----------|-------------|
|
|
112
|
+
| `serviceId` | `string` | ✅ | Service ID |
|
|
113
|
+
| `apiKey` | `string` | ✅ | API Key |
|
|
114
|
+
| `apiSecret` | `string` | ✅ | API Secret |
|
|
115
|
+
| `onMessage` | `(message: Message) => void` | ❌ | Message callback |
|
|
116
|
+
| `onError` | `(error: Error) => void` | ❌ | Error callback |
|
|
117
|
+
| `onToolUse` | `(toolUse: ToolUse) => Promise<Message \| void>` | ❌ | Tool use callback |
|
|
118
|
+
| `presetMessages` | `PresetMessage[]` | ❌ | Preset messages |
|
|
119
|
+
| `placeholder` | `string` | ❌ | Input placeholder |
|
|
120
|
+
| `className` | `string` | ❌ | Custom CSS class |
|
|
121
|
+
| `maxRetries` | `number` | ❌ | Maximum retry attempts |
|
|
122
|
+
| `retryDelay` | `number` | ❌ | Retry delay |
|
|
123
|
+
| `onVerifyWallet` | `() => Promise<{token: string} \| undefined>` | ❌ | Wallet verification callback |
|
|
124
|
+
| `permissionGroup` | `string` | ❌ | Permission group |
|
|
125
|
+
|
|
126
|
+
### Utility Functions
|
|
127
|
+
|
|
128
|
+
#### Wallet Utilities
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
import { connectWallet, disconnectWallet, validateToken } from '@bytexbyte/nxtlinq-ai-agent-sdk';
|
|
132
|
+
|
|
133
|
+
// Connect wallet
|
|
134
|
+
const { address, signer } = await connectWallet();
|
|
135
|
+
|
|
136
|
+
// Disconnect wallet
|
|
137
|
+
disconnectWallet();
|
|
138
|
+
|
|
139
|
+
// Validate token
|
|
140
|
+
const isValid = validateToken(token, address);
|
|
167
141
|
```
|
|
168
142
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
143
|
+
#### AIT Utilities
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
import { generateAITId, createAITMetadata, prepareAITCreation } from '@bytexbyte/nxtlinq-ai-agent-sdk';
|
|
147
|
+
|
|
148
|
+
// Generate AIT ID
|
|
149
|
+
const aitId = generateAITId(address);
|
|
150
|
+
|
|
151
|
+
// Create AIT metadata
|
|
152
|
+
const metadata = createAITMetadata(permissions, address);
|
|
153
|
+
|
|
154
|
+
// Prepare AIT creation parameters
|
|
155
|
+
const { aitId, metadata, metadataHash, createAITParams } = prepareAITCreation(
|
|
156
|
+
address,
|
|
157
|
+
permissions,
|
|
158
|
+
serviceId
|
|
159
|
+
);
|
|
175
160
|
```
|
|
176
161
|
|
|
177
|
-
|
|
178
|
-
```typescript
|
|
179
|
-
interface AIT {
|
|
180
|
-
aitId: string;
|
|
181
|
-
controller: string;
|
|
182
|
-
metadata: AITMetadata;
|
|
183
|
-
metadataHash: string;
|
|
184
|
-
metadataCid: string;
|
|
185
|
-
}
|
|
162
|
+
#### Notification Utilities
|
|
186
163
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
164
|
+
```tsx
|
|
165
|
+
import { createNotification, getNotificationIcon } from '@bytexbyte/nxtlinq-ai-agent-sdk';
|
|
166
|
+
|
|
167
|
+
// Create notification
|
|
168
|
+
const notification = createNotification('success', 'Operation successful');
|
|
169
|
+
|
|
170
|
+
// Get notification icon
|
|
171
|
+
const icon = getNotificationIcon('success'); // '✅'
|
|
193
172
|
```
|
|
194
173
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
174
|
+
## 🔒 Permission Management
|
|
175
|
+
|
|
176
|
+
The SDK supports fine-grained permission management:
|
|
177
|
+
|
|
178
|
+
1. **Connect Wallet**: Users first need to connect their MetaKeep wallet
|
|
179
|
+
2. **Signature Verification**: Users need to sign to verify their identity
|
|
180
|
+
3. **AIT Configuration**: Users can select required permissions
|
|
181
|
+
4. **Permission Validation**: Each tool call validates permissions
|
|
182
|
+
|
|
183
|
+
## 🎨 Custom Styling
|
|
184
|
+
|
|
185
|
+
You can add custom styles through the `className` property:
|
|
186
|
+
|
|
187
|
+
```css
|
|
188
|
+
.nxtlinq-chatbot {
|
|
189
|
+
/* Custom styles */
|
|
190
|
+
border-radius: 15px;
|
|
191
|
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
|
202
192
|
}
|
|
203
193
|
```
|
|
204
194
|
|
|
205
|
-
##
|
|
206
|
-
|
|
207
|
-
### Wallet Integration
|
|
208
|
-
- MetaMask wallet connection
|
|
209
|
-
- Berify.me wallet verification
|
|
210
|
-
- Wallet-based authentication
|
|
211
|
-
- AIT (AI Identity Token) generation and management
|
|
212
|
-
|
|
213
|
-
### Authentication Flow
|
|
214
|
-
1. Connect MetaMask wallet
|
|
215
|
-
2. Verify wallet ownership (optional, via Berify.me)
|
|
216
|
-
3. Sign in with wallet
|
|
217
|
-
4. Generate and register AIT with required permissions
|
|
218
|
-
5. Use AIT for authenticated operations
|
|
219
|
-
|
|
220
|
-
### Enhanced Error Handling
|
|
221
|
-
- Improved async operation handling
|
|
222
|
-
- Better state management
|
|
223
|
-
- Detailed error messages
|
|
224
|
-
- Comprehensive debugging logs
|
|
225
|
-
|
|
226
|
-
## Error Handling
|
|
227
|
-
|
|
228
|
-
The SDK includes enhanced error handling with:
|
|
229
|
-
- Automatic retry mechanism for failed requests
|
|
230
|
-
- Error callback for custom error handling
|
|
231
|
-
- User-friendly error messages
|
|
232
|
-
- Wallet connection error handling
|
|
233
|
-
- Authentication error handling
|
|
234
|
-
- Detailed console logging for debugging
|
|
235
|
-
|
|
236
|
-
## Best Practices
|
|
237
|
-
|
|
238
|
-
1. Implement proper wallet verification logic
|
|
239
|
-
2. Handle AIT permissions appropriately
|
|
240
|
-
3. Set appropriate timeout values
|
|
241
|
-
4. Implement error retry mechanisms
|
|
242
|
-
5. Use context management to maintain conversation coherence
|
|
243
|
-
6. Handle wallet connection errors gracefully
|
|
244
|
-
7. Implement proper error handling for authentication flow
|
|
245
|
-
8. Monitor console logs for debugging
|
|
246
|
-
|
|
247
|
-
## Troubleshooting
|
|
248
|
-
|
|
249
|
-
Having issues? Check our [Troubleshooting Guide](./TROUBLESHOOTING.md) which includes:
|
|
250
|
-
|
|
251
|
-
- Common problems and solutions
|
|
252
|
-
- Authentication debugging steps
|
|
253
|
-
- Permission issue resolution
|
|
254
|
-
- Best practice recommendations
|
|
195
|
+
## 🐛 Troubleshooting
|
|
255
196
|
|
|
256
197
|
### Common Issues
|
|
257
198
|
|
|
258
|
-
**
|
|
259
|
-
|
|
199
|
+
1. **Wallet Connection Failed**
|
|
200
|
+
- Ensure MetaKeep extension is installed
|
|
201
|
+
- Check network connection
|
|
202
|
+
|
|
203
|
+
2. **Permission Validation Failed**
|
|
204
|
+
- Ensure AIT permissions are correctly configured
|
|
205
|
+
- Check service ID and API keys
|
|
206
|
+
|
|
207
|
+
3. **Message Sending Failed**
|
|
208
|
+
- Check network connection
|
|
209
|
+
- Verify API key and secret
|
|
260
210
|
|
|
261
|
-
|
|
262
|
-
A: Check AIT permission settings to ensure required tool permissions are included. See [Troubleshooting Guide](./TROUBLESHOOTING.md) for details.
|
|
211
|
+
### Debug Mode
|
|
263
212
|
|
|
264
|
-
|
|
213
|
+
Enable debug mode to get more information:
|
|
265
214
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
215
|
+
```tsx
|
|
216
|
+
<ChatBot
|
|
217
|
+
// ... other props
|
|
218
|
+
onError={(error) => {
|
|
219
|
+
console.error('ChatBot Error:', error);
|
|
220
|
+
}}
|
|
221
|
+
/>
|
|
222
|
+
```
|
|
271
223
|
|
|
272
|
-
## License
|
|
224
|
+
## 📄 License
|
|
273
225
|
|
|
274
|
-
|
|
226
|
+
MIT License
|
|
275
227
|
|
|
276
|
-
|
|
228
|
+
## 🤝 Contributing
|
|
277
229
|
|
|
278
|
-
|
|
230
|
+
Issues and Pull Requests are welcome!
|
|
279
231
|
|
|
280
|
-
|
|
232
|
+
## 📞 Support
|
|
281
233
|
|
|
282
|
-
For
|
|
234
|
+
For questions, please contact:
|
|
235
|
+
- Email: support@nxtlinq.ai
|
|
236
|
+
- Documentation: https://docs.nxtlinq.ai
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nxtlinq-api.d.ts","sourceRoot":"","sources":["../../src/api/nxtlinq-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"nxtlinq-api.d.ts","sourceRoot":"","sources":["../../src/api/nxtlinq-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAiL1C,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,KAAG,MASpE,CAAC"}
|