@bytexbyte/nxtlinq-ai-agent-sdk 1.1.9 → 1.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 CHANGED
@@ -13,15 +13,17 @@ A powerful SDK for building intelligent conversation applications with Nxtlinq A
13
13
  - 🔌 Easy integration with React applications
14
14
  - 🔒 Secure authentication and API key management
15
15
  - 👛 MetaMask wallet integration
16
- - 🔐 AIT (AI Token) management
16
+ - 🔐 AIT (AI Identity Token) management
17
17
  - 🔑 Permission-based access control
18
+ - 🔍 Enhanced error handling and debugging
19
+ - ⚡ Improved async operation handling
18
20
 
19
21
  ## Installation
20
22
 
21
23
  ```bash
22
- npm install @bytexbyte/nxtlinq-ai-agent-sdk
24
+ npm install @bytexbyte/nxtlinq-ai-agent-sdk@1.1.9
23
25
  # or
24
- yarn add @bytexbyte/nxtlinq-ai-agent-sdk
26
+ yarn add @bytexbyte/nxtlinq-ai-agent-sdk@1.1.9
25
27
  ```
26
28
 
27
29
  ## Quick Start
@@ -59,8 +61,8 @@ function App() {
59
61
  onMessage={handleMessage}
60
62
  onToolUse={handleToolUse}
61
63
  presetMessages={presetMessages}
62
- onVerifyWallet={async (address) => {
63
- // Implement your wallet verification logic here
64
+ onVerifyWallet={async () => {
65
+ // Implement Berify.me verification
64
66
  return { token: 'verification-token' };
65
67
  }}
66
68
  />
@@ -68,47 +70,47 @@ function App() {
68
70
  }
69
71
  ```
70
72
 
71
- ## API Reference
72
-
73
- ### NxtlinqAITSDK
74
-
75
- | Method | Description |
76
- |--------|-------------|
77
- | `connectWallet()` | Connect to MetaMask wallet |
78
- | `verifyWallet(token: string, method: string)` | Verify wallet ownership |
79
- | `signInWithWallet()` | Sign in using wallet |
80
- | `generateAndRegisterAIT(permissions: string[])` | Generate and register a new AIT |
81
- | `getAIT()` | Get AIT information |
82
- | `getWalletInfo()` | Get wallet information |
83
-
84
- ### NxtlinqAIAgent
85
-
86
- | Method | Description |
87
- |--------|-------------|
88
- | `setAIT(ait: AIT, signer?: ethers.Signer)` | Set AIT for the agent |
89
- | `generateAIT(options: GenerateAITOptions)` | Generate a new AIT |
90
- | `getAITInfo(serviceId: string, controller: string, signer?: ethers.Signer)` | Get AIT information |
91
- | `sendMessage(message: string, toolName?: string)` | Send a message to the agent |
92
-
93
- ### API Endpoints
73
+ ## Berify.me Integration
94
74
 
95
- #### AIT API
96
- - `getAITByServiceIdAndController`: Get AIT by service ID and controller
97
- - `createAIT`: Create a new AIT
75
+ The SDK supports Berify.me wallet verification for enhanced security:
98
76
 
99
- #### Wallet API
100
- - `verifyWallet`: Verify wallet ownership
101
- - `getWallet`: Get wallet information
77
+ ```tsx
78
+ import { ChatBot } from '@bytexbyte/nxtlinq-ai-agent-sdk';
102
79
 
103
- #### Metadata API
104
- - `createMetadata`: Create metadata for AIT
80
+ function App() {
81
+ const handleVerifyWallet = async () => {
82
+ // Open Berify.me verification modal
83
+ const modal = window.open(
84
+ 'https://berify.me/verify',
85
+ 'BerifyMeModal',
86
+ 'width=500,height=600'
87
+ );
88
+
89
+ return new Promise((resolve) => {
90
+ const handleMessage = (event) => {
91
+ if (event.origin === 'https://berify.me' && event.data.type === 'VERIFICATION_SUCCESS') {
92
+ window.removeEventListener('message', handleMessage);
93
+ modal?.close();
94
+ resolve({ token: event.data.token });
95
+ }
96
+ };
97
+
98
+ window.addEventListener('message', handleMessage);
99
+ });
100
+ };
105
101
 
106
- #### Auth API
107
- - `getNonce`: Get nonce for wallet sign-in
108
- - `signIn`: Sign in with wallet
102
+ return (
103
+ <ChatBot
104
+ serviceId="your-service-id"
105
+ apiKey="your-api-key"
106
+ apiSecret="your-api-secret"
107
+ onVerifyWallet={handleVerifyWallet}
108
+ />
109
+ );
110
+ }
111
+ ```
109
112
 
110
- #### Agent API
111
- - `sendMessage`: Send message to AI agent
113
+ ## API Reference
112
114
 
113
115
  ### ChatBot Component Props
114
116
 
@@ -120,12 +122,13 @@ function App() {
120
122
  | onMessage | (message: Message) => void | No | Callback when a new message is received |
121
123
  | onError | (error: Error) => void | No | Callback when an error occurs |
122
124
  | onToolUse | (toolUse: ToolUse) => Promise<Message \| void> | No | Callback for handling tool usage |
123
- | onVerifyWallet | (address: string) => Promise<{ token: string }> | Yes | Callback for wallet verification |
125
+ | onVerifyWallet | () => Promise<{ token: string } \| undefined> | Yes | Callback for wallet verification |
124
126
  | presetMessages | PresetMessage[] | No | Array of preset messages to display |
125
127
  | placeholder | string | No | Input placeholder text (default: "Type a message...") |
126
128
  | className | string | No | Additional CSS class name |
127
129
  | maxRetries | number | No | Maximum number of retry attempts (default: 3) |
128
130
  | retryDelay | number | No | Delay between retries in milliseconds (default: 1000) |
131
+ | permissionGroup | string | No | Permission group name for filtering permissions |
129
132
 
130
133
  ## Types
131
134
 
@@ -136,7 +139,7 @@ interface Message {
136
139
  content: string;
137
140
  role: 'user' | 'assistant';
138
141
  timestamp: string;
139
- button?: boolean;
142
+ button?: string;
140
143
  error?: string;
141
144
  }
142
145
  ```
@@ -165,7 +168,6 @@ interface AIT {
165
168
  metadata: AITMetadata;
166
169
  metadataHash: string;
167
170
  metadataCid: string;
168
- signature: string;
169
171
  }
170
172
 
171
173
  interface AITMetadata {
@@ -174,39 +176,15 @@ interface AITMetadata {
174
176
  issuedBy: string;
175
177
  serviceId?: string;
176
178
  }
179
+ ```
177
180
 
178
- interface AITInfo {
179
- aitId: string;
180
- controller: string;
181
- metadata: AITMetadata;
182
- metadataHash: string;
183
- metadataCid: string;
184
- signature: string;
185
- }
186
-
187
- interface AITPermission {
188
- hasPermission: boolean;
189
- reason?: string;
190
- permissions?: string[];
191
- }
192
-
193
- interface GenerateAITOptions {
194
- hitAddress: string;
195
- signer: ethers.Signer;
196
- permissions: string[];
197
- serviceId: string;
198
- }
199
-
200
- interface WalletInfo {
181
+ ### ServicePermission
182
+ ```typescript
183
+ interface ServicePermission {
201
184
  id: string;
202
- address: string;
203
- verified: boolean;
204
- method?: string;
205
- }
206
-
207
- interface MessageContext {
208
- aitId?: string;
209
- walletAddress?: string | null;
185
+ label: string;
186
+ description: string;
187
+ groups: string[];
210
188
  }
211
189
  ```
212
190
 
@@ -214,30 +192,32 @@ interface MessageContext {
214
192
 
215
193
  ### Wallet Integration
216
194
  - MetaMask wallet connection
217
- - Wallet verification
195
+ - Berify.me wallet verification
218
196
  - Wallet-based authentication
219
- - AIT (AI Token) generation and management
220
-
221
- ### Available Permissions
222
- - Set User Name
223
- - Navigate To Page
224
- - Add Member
197
+ - AIT (AI Identity Token) generation and management
225
198
 
226
199
  ### Authentication Flow
227
200
  1. Connect MetaMask wallet
228
- 2. Verify wallet ownership
201
+ 2. Verify wallet ownership (optional, via Berify.me)
229
202
  3. Sign in with wallet
230
203
  4. Generate and register AIT with required permissions
231
204
  5. Use AIT for authenticated operations
232
205
 
206
+ ### Enhanced Error Handling
207
+ - Improved async operation handling
208
+ - Better state management
209
+ - Detailed error messages
210
+ - Comprehensive debugging logs
211
+
233
212
  ## Error Handling
234
213
 
235
- The SDK includes built-in error handling with:
214
+ The SDK includes enhanced error handling with:
236
215
  - Automatic retry mechanism for failed requests
237
216
  - Error callback for custom error handling
238
217
  - User-friendly error messages
239
218
  - Wallet connection error handling
240
219
  - Authentication error handling
220
+ - Detailed console logging for debugging
241
221
 
242
222
  ## Best Practices
243
223
 
@@ -248,6 +228,32 @@ The SDK includes built-in error handling with:
248
228
  5. Use context management to maintain conversation coherence
249
229
  6. Handle wallet connection errors gracefully
250
230
  7. Implement proper error handling for authentication flow
231
+ 8. Monitor console logs for debugging
232
+
233
+ ## Troubleshooting
234
+
235
+ Having issues? Check our [Troubleshooting Guide](./TROUBLESHOOTING.md) which includes:
236
+
237
+ - Common problems and solutions
238
+ - Authentication debugging steps
239
+ - Permission issue resolution
240
+ - Best practice recommendations
241
+
242
+ ### Common Issues
243
+
244
+ **Q: Still need to sign in after connecting wallet?**
245
+ 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.
246
+
247
+ **Q: Cannot use specific AI tool features?**
248
+ A: Check AIT permission settings to ensure required tool permissions are included. See [Troubleshooting Guide](./TROUBLESHOOTING.md) for details.
249
+
250
+ ## Changelog
251
+
252
+ ### v1.1.9
253
+ - 🔧 Fixed async operation timing issues in wallet connection
254
+ - 🐛 Improved state management for AIT validation
255
+ - 📝 Enhanced error messages and debugging logs
256
+ - ⚡ Better handling of authentication flow
251
257
 
252
258
  ## License
253
259
 
@@ -1 +1 @@
1
- {"version":3,"file":"ChatBot.d.ts","sourceRoot":"","sources":["../../src/components/ChatBot.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,EAAE,OAAO,EAAkC,MAAM,kBAAkB,CAAC;AAE3E,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/B,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,OAAO,CA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IAC/B,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IAC1D,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC;QAC7B,KAAK,EAAE,MAAM,CAAC;KACf,GAAG,SAAS,CAAC,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AA0VD,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CA08B1C,CAAC"}
@@ -28,7 +28,7 @@ const PermissionForm = ({ hitAddress, permissions, setPermissions, setIsDisabled
28
28
  React.useEffect(() => {
29
29
  fetchAvailablePermissions();
30
30
  }, [serviceId, nxtlinqApi, permissionGroup]);
31
- const isWalletVerified = walletInfo?.id;
31
+ const isWalletVerified = walletInfo?.id || !isNeedSignInWithWallet;
32
32
  return (_jsxs("div", { style: {
33
33
  backgroundColor: 'white',
34
34
  padding: '24px',
@@ -313,17 +313,15 @@ export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], pl
313
313
  if (address !== hitAddress) {
314
314
  return true;
315
315
  }
316
- // Check if AIT exists - if not, user needs to sign in to generate AIT
317
- if (!ait) {
318
- return true;
319
- }
316
+ // If user has valid token but no AIT, they don't need to sign in again
317
+ // They just need to generate AIT through the permission form
320
318
  return false;
321
319
  }
322
320
  catch (error) {
323
321
  console.error('Error parsing token:', error);
324
322
  return true;
325
323
  }
326
- }, [hitAddress, nxtlinqAITServiceAccessToken, ait]);
324
+ }, [hitAddress, nxtlinqAITServiceAccessToken]);
327
325
  const handleVerifySuccess = (address) => {
328
326
  localStorage.setItem(`wallet_verified_${address}`, 'true');
329
327
  const getWalletInfo = async () => {
@@ -639,16 +637,26 @@ export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], pl
639
637
  }]);
640
638
  return false;
641
639
  }
642
- if (!ait) {
640
+ // Check if user has signed in with wallet
641
+ if (!nxtlinqAITServiceAccessToken) {
643
642
  setMessages(prev => [...prev, {
644
643
  id: Date.now().toString(),
645
- content: 'Please sign in with your wallet to continue.',
644
+ content: 'Please sign in with your HIT wallet to continue.',
646
645
  role: 'assistant',
647
646
  timestamp: new Date().toISOString(),
648
647
  button: 'signIn'
649
648
  }]);
650
649
  return false;
651
650
  }
651
+ if (!ait) {
652
+ setMessages(prev => [...prev, {
653
+ id: Date.now().toString(),
654
+ content: 'No AIT found for your wallet. Please click the settings button (⚙️) to configure your AIT permissions.',
655
+ role: 'assistant',
656
+ timestamp: new Date().toISOString()
657
+ }]);
658
+ return false;
659
+ }
652
660
  // Check if the tool permission is available for current identity provider
653
661
  const availablePermissionLabels = availablePermissions.map(p => p.label);
654
662
  if (!availablePermissionLabels.includes(toolName)) {
@@ -664,7 +672,7 @@ export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], pl
664
672
  if (!permissions.includes(toolName)) {
665
673
  setMessages(prev => [...prev, {
666
674
  id: Date.now().toString(),
667
- content: `You do not have the required AIT permission: ${toolName}`,
675
+ content: `You do not have the required AIT permission: ${toolName}. Please click the settings button (⚙️) to update your permissions.`,
668
676
  role: 'assistant',
669
677
  timestamp: new Date().toISOString()
670
678
  }]);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bytexbyte/nxtlinq-ai-agent-sdk",
3
- "version": "1.1.9",
4
- "description": "Nxtlinq AI Agent SDK - Proprietary Software",
3
+ "version": "1.2.0",
4
+ "description": "Nxtlinq AI Agent SDK - Proprietary Software with enhanced async operation handling",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
@@ -16,7 +16,10 @@
16
16
  "nxtlinq",
17
17
  "ai",
18
18
  "agent",
19
- "sdk"
19
+ "sdk",
20
+ "wallet",
21
+ "authentication",
22
+ "berify"
20
23
  ],
21
24
  "author": "ByteXByte",
22
25
  "license": "MIT",