@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.
Files changed (43) hide show
  1. package/README.md +175 -221
  2. package/dist/api/nxtlinq-api.d.ts.map +1 -1
  3. package/dist/api/nxtlinq-api.js +121 -142
  4. package/dist/components/ChatBot.d.ts +2 -44
  5. package/dist/components/ChatBot.d.ts.map +1 -1
  6. package/dist/components/ChatBot.js +5 -1241
  7. package/dist/components/context/ChatBotContext.d.ts +5 -0
  8. package/dist/components/context/ChatBotContext.d.ts.map +1 -0
  9. package/dist/components/context/ChatBotContext.js +737 -0
  10. package/dist/components/types/ChatBotTypes.d.ts +98 -0
  11. package/dist/components/types/ChatBotTypes.d.ts.map +1 -0
  12. package/dist/components/types/ChatBotTypes.js +1 -0
  13. package/dist/components/ui/ChatBotUI.d.ts +3 -0
  14. package/dist/components/ui/ChatBotUI.d.ts.map +1 -0
  15. package/dist/components/ui/ChatBotUI.js +146 -0
  16. package/dist/components/ui/MessageInput.d.ts +3 -0
  17. package/dist/components/ui/MessageInput.d.ts.map +1 -0
  18. package/dist/components/ui/MessageInput.js +46 -0
  19. package/dist/components/ui/MessageList.d.ts +3 -0
  20. package/dist/components/ui/MessageList.d.ts.map +1 -0
  21. package/dist/components/ui/MessageList.js +54 -0
  22. package/dist/components/ui/NotificationModal.d.ts +14 -0
  23. package/dist/components/ui/NotificationModal.d.ts.map +1 -0
  24. package/dist/components/ui/NotificationModal.js +79 -0
  25. package/dist/components/ui/PermissionForm.d.ts +8 -0
  26. package/dist/components/ui/PermissionForm.d.ts.map +1 -0
  27. package/dist/components/ui/PermissionForm.js +299 -0
  28. package/dist/components/ui/PresetMessages.d.ts +3 -0
  29. package/dist/components/ui/PresetMessages.d.ts.map +1 -0
  30. package/dist/components/ui/PresetMessages.js +35 -0
  31. package/dist/core/utils/aitUtils.d.ts +28 -0
  32. package/dist/core/utils/aitUtils.d.ts.map +1 -0
  33. package/dist/core/utils/aitUtils.js +34 -0
  34. package/dist/core/utils/notificationUtils.d.ts +29 -0
  35. package/dist/core/utils/notificationUtils.d.ts.map +1 -0
  36. package/dist/core/utils/notificationUtils.js +47 -0
  37. package/dist/core/utils/walletUtils.d.ts +10 -0
  38. package/dist/core/utils/walletUtils.d.ts.map +1 -0
  39. package/dist/core/utils/walletUtils.js +38 -0
  40. package/dist/index.d.ts +13 -1
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +17 -0
  43. package/package.json +1 -1
package/README.md CHANGED
@@ -1,282 +1,236 @@
1
1
  # Nxtlinq AI Agent SDK
2
2
 
3
- A powerful SDK for building intelligent conversation applications with Nxtlinq AI Agent.
4
-
5
- ## Features
6
-
7
- - 💬 Real-time chat interface with AI Agent
8
- - 🎯 Preset messages for quick interactions
9
- - 🛠️ Tool integration support
10
- - 🔄 Automatic retry mechanism for failed requests
11
- - 📱 Responsive and modern UI design
12
- - 🎨 Customizable styling
13
- - 🔌 Easy integration with React applications
14
- - 🔒 Secure authentication and API key management
15
- - 👛 MetaMask wallet integration
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@1.1.9
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={handleMessage}
63
- onToolUse={handleToolUse}
64
- presetMessages={presetMessages}
65
- onVerifyWallet={async () => {
66
- // Implement Berify.me verification
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
- > **Note**: The SDK now includes a unified notification system. All success, error, warning, and info messages are displayed as Modal prompts in the top-right corner, providing a consistent and non-intrusive user experience.
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
- onVerifyWallet={handleVerifyWallet}
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
- ## API Reference
117
-
118
- ### ChatBot Component Props
119
-
120
- | Prop | Type | Required | Description |
121
- |------|------|----------|-------------|
122
- | serviceId | string | Yes | Your Nxtlinq service ID |
123
- | apiKey | string | Yes | Your Nxtlinq API key |
124
- | apiSecret | string | Yes | Your Nxtlinq API secret |
125
- | onMessage | (message: Message) => void | No | Callback when a new message is received |
126
- | onError | (error: Error) => void | No | Callback when an error occurs |
127
- | onToolUse | (toolUse: ToolUse) => Promise<Message \| void> | No | Callback for handling tool usage |
128
- | onVerifyWallet | () => Promise<{ token: string } \| undefined> | Yes | Callback for wallet verification |
129
- | presetMessages | PresetMessage[] | No | Array of preset messages to display |
130
- | placeholder | string | No | Input placeholder text (default: "Type a message...") |
131
- | className | string | No | Additional CSS class name |
132
- | maxRetries | number | No | Maximum number of retry attempts (default: 3) |
133
- | retryDelay | number | No | Delay between retries in milliseconds (default: 1000) |
134
- | permissionGroup | string | No | Permission group name for filtering permissions |
135
-
136
- ### Notification System
137
-
138
- The SDK includes a unified notification system that displays Modal prompts for various operations:
139
-
140
- - **Success Notifications**: Green modal for successful operations (auto-hide after 3 seconds)
141
- - **Error Notifications**: Red modal for error messages (auto-hide after 5 seconds)
142
- - **Warning Notifications**: Orange modal for warnings (auto-hide after 4 seconds)
143
- - **Info Notifications**: Blue modal for informational messages (auto-hide after 3 seconds)
144
-
145
- All notifications appear in the top-right corner and can be manually dismissed by clicking the × button.
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
- ### PresetMessage
162
- ```typescript
163
- interface PresetMessage {
164
- text: string;
165
- autoSend?: boolean;
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
- ### ToolUse
170
- ```typescript
171
- interface ToolUse {
172
- name: string;
173
- input: Record<string, any>;
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
- ### AIT
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
- interface AITMetadata {
188
- model: string;
189
- permissions: string[];
190
- issuedBy: string;
191
- serviceId?: string;
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
- ### ServicePermission
196
- ```typescript
197
- interface ServicePermission {
198
- id: string;
199
- label: string;
200
- description: string;
201
- groups: string[];
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
- ## Features
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
- **Q: Still need to sign in after connecting wallet?**
259
- A: This is usually due to expired authentication tokens or address mismatches. Check browser console logs and refer to the [Troubleshooting Guide](./TROUBLESHOOTING.md) for detailed solutions.
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
- **Q: Cannot use specific AI tool features?**
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
- ## Changelog
213
+ Enable debug mode to get more information:
265
214
 
266
- ### v1.1.9
267
- - 🔧 Fixed async operation timing issues in wallet connection
268
- - 🐛 Improved state management for AIT validation
269
- - 📝 Enhanced error messages and debugging logs
270
- - Better handling of authentication flow
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
- Proprietary - All Rights Reserved
226
+ MIT License
275
227
 
276
- Copyright (c) 2025 ByteXByte. All rights reserved.
228
+ ## 🤝 Contributing
277
229
 
278
- This software and associated documentation files (the "Software") are proprietary and confidential. The Software is protected by copyright laws and international copyright treaties, as well as other intellectual property laws and treaties.
230
+ Issues and Pull Requests are welcome!
279
231
 
280
- Unauthorized copying, distribution, modification, public display, or public performance of the Software is strictly prohibited. The Software may only be used in accordance with the terms of a valid license agreement with ByteXByte.
232
+ ## 📞 Support
281
233
 
282
- For licensing inquiries, please contact: [Your Contact Information]
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;AAK1C,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,KAAG,MAwJpE,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"}