@bytexbyte/nxtlinq-ai-agent-sdk 1.2.6 → 1.2.7

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ChatBotContext.d.ts","sourceRoot":"","sources":["../../../src/components/context/ChatBotContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,EACL,kBAAkB,EAClB,YAAY,EAOb,MAAM,uBAAuB,CAAC;AAI/B,eAAO,MAAM,UAAU,0BAMtB,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAqpClD,CAAC"}
1
+ {"version":3,"file":"ChatBotContext.d.ts","sourceRoot":"","sources":["../../../src/components/context/ChatBotContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,EACL,kBAAkB,EAClB,YAAY,EAOb,MAAM,uBAAuB,CAAC;AAI/B,eAAO,MAAM,UAAU,0BAMtB,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAqzClD,CAAC"}
@@ -41,6 +41,7 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
41
41
  const aitRef = React.useRef(ait);
42
42
  const permissionsRef = React.useRef(permissions);
43
43
  const nxtlinqAITServiceAccessTokenRef = React.useRef(nxtlinqAITServiceAccessToken);
44
+ const signerRef = React.useRef(signer);
44
45
  // Update refs when state changes
45
46
  React.useEffect(() => {
46
47
  hitAddressRef.current = hitAddress;
@@ -54,6 +55,9 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
54
55
  React.useEffect(() => {
55
56
  nxtlinqAITServiceAccessTokenRef.current = nxtlinqAITServiceAccessToken;
56
57
  }, [nxtlinqAITServiceAccessToken]);
58
+ React.useEffect(() => {
59
+ signerRef.current = signer;
60
+ }, [signer]);
57
61
  const [notification, setNotification] = React.useState({
58
62
  show: false,
59
63
  type: 'info',
@@ -84,6 +88,13 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
84
88
  const showError = (message) => showNotification('error', message, 5000);
85
89
  const showWarning = (message) => showNotification('warning', message, 4000);
86
90
  const showInfo = (message) => showNotification('info', message, 3000);
91
+ // Filter out wallet connection messages for API calls
92
+ const getFilteredMessagesForAPI = () => {
93
+ return messages.filter(msg => !msg.content.includes('Please connect your HIT wallet') &&
94
+ !msg.content.includes('Please sign in with your wallet') &&
95
+ !msg.content.includes('connect your wallet') &&
96
+ !msg.content.includes('Wallet verification completed successfully'));
97
+ };
87
98
  // Fetch available permissions
88
99
  const fetchAvailablePermissions = async () => {
89
100
  if (!serviceId)
@@ -113,18 +124,25 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
113
124
  }
114
125
  setIsAITLoading(true);
115
126
  try {
116
- // Get wallet info first
127
+ // Get wallet info first - always try to get wallet info if we have a token
117
128
  if (nxtlinqAITServiceAccessToken) {
118
129
  try {
119
130
  const walletResponse = await nxtlinqApi.wallet.getWallet({ address: hitAddress }, nxtlinqAITServiceAccessToken);
120
131
  if (!('error' in walletResponse)) {
121
132
  setWalletInfo(walletResponse);
133
+ console.log('Wallet info updated:', walletResponse);
134
+ }
135
+ else {
136
+ console.log('Failed to get wallet info:', walletResponse.error);
122
137
  }
123
138
  }
124
139
  catch (error) {
125
140
  console.error('Failed to fetch wallet info:', error);
126
141
  }
127
142
  }
143
+ else {
144
+ console.log('No access token available for wallet info fetch');
145
+ }
128
146
  const response = await nxtlinqApi.ait.getAITByServiceIdAndController({
129
147
  serviceId,
130
148
  controller: hitAddress
@@ -215,38 +233,54 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
215
233
  localStorage.removeItem('walletAddress');
216
234
  setHitAddress(null);
217
235
  setSigner(null);
218
- throw error;
236
+ if (autoShowSignInMessage) {
237
+ throw error;
238
+ }
219
239
  }
220
240
  }, [nxtlinqAITServiceAccessToken, refreshAIT, isNeedSignInWithWallet]);
221
241
  // Sign in wallet
222
242
  const signInWallet = async (autoShowSuccessMessage = true) => {
223
- if (!hitAddress) {
224
- showError('Please connect your wallet first.');
243
+ // Use refs to get latest state values for consistency with hasPermission
244
+ const currentHitAddress = hitAddressRef.current;
245
+ const currentSigner = signerRef.current;
246
+ console.log('signInWallet called: currentHitAddress =', currentHitAddress, 'currentSigner =', !!currentSigner);
247
+ if (!currentHitAddress) {
248
+ console.log('No currentHitAddress, returning early');
249
+ if (autoShowSuccessMessage) {
250
+ showError('Please connect your wallet first.');
251
+ }
225
252
  return;
226
253
  }
227
- if (!signer) {
228
- showError('Please connect your wallet first.');
254
+ if (!currentSigner) {
255
+ console.log('No currentSigner, returning early');
256
+ if (autoShowSuccessMessage) {
257
+ showError('Please connect your wallet first.');
258
+ }
229
259
  return;
230
260
  }
231
261
  try {
232
- const nonceResponse = await nxtlinqApi.auth.getNonce({ address: hitAddress });
262
+ const nonceResponse = await nxtlinqApi.auth.getNonce({ address: currentHitAddress });
233
263
  if ('error' in nonceResponse) {
234
- showError(nonceResponse.error);
264
+ if (autoShowSuccessMessage) {
265
+ showError(nonceResponse.error);
266
+ }
235
267
  return;
236
268
  }
237
269
  const payload = {
238
- address: hitAddress,
270
+ address: currentHitAddress,
239
271
  code: nonceResponse.code,
240
272
  timestamp: nonceResponse.timestamp
241
273
  };
242
274
  const stringToSign = stringify(payload);
243
- const signature = await signer.signMessage(stringToSign || '');
275
+ const signature = await currentSigner.signMessage(stringToSign || '');
244
276
  const response = await nxtlinqApi.auth.signIn({
245
277
  ...payload,
246
278
  signature
247
279
  });
248
280
  if ('error' in response) {
249
- showError(response.error);
281
+ if (autoShowSuccessMessage) {
282
+ showError(response.error);
283
+ }
250
284
  return;
251
285
  }
252
286
  const { accessToken } = response;
@@ -259,7 +293,9 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
259
293
  }
260
294
  catch (error) {
261
295
  console.error('Failed to sign in:', error);
262
- showError('Failed to sign in. Please try again.');
296
+ if (autoShowSuccessMessage) {
297
+ showError('Failed to sign in. Please try again.');
298
+ }
263
299
  }
264
300
  };
265
301
  // Check permissions
@@ -285,8 +321,16 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
285
321
  setIsAutoConnecting(false); // Clear auto-connecting state
286
322
  setJustAutoConnected(true); // Mark that we just auto-connected
287
323
  console.log('Set justAutoConnected to true after auto-connect');
324
+ // Show brief success message for auto-connect
325
+ showSuccess('Auto wallet connection successful');
326
+ // Clear the flag after a short delay
327
+ setTimeout(() => {
328
+ setJustAutoConnected(false);
329
+ }, 2000);
288
330
  onAutoConnect?.(); // Call callback if provided
289
331
  // If connection successful, continue with permission check
332
+ // Wait a bit for state to update
333
+ await new Promise(resolve => setTimeout(resolve, 500));
290
334
  const result = await hasPermission(toolName, false);
291
335
  return result;
292
336
  }
@@ -301,6 +345,7 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
301
345
  }
302
346
  if (!currentToken) {
303
347
  if (autoRetry) {
348
+ console.log('Auto sign-in triggered: currentHitAddress =', currentHitAddress, 'currentToken =', currentToken);
304
349
  setIsLoading(false); // Stop thinking before showing message
305
350
  setMessages(prev => [...prev, {
306
351
  id: Date.now().toString(),
@@ -311,8 +356,23 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
311
356
  }]);
312
357
  try {
313
358
  setIsAutoConnecting(true); // Mark as auto-signing
359
+ console.log('Starting auto sign-in...');
314
360
  await signInWallet(false); // Don't show success message yet
361
+ console.log('Auto sign-in completed');
315
362
  setIsAutoConnecting(false); // Clear auto-signing state
363
+ // Show brief success message for auto-sign-in
364
+ showSuccess('Auto sign-in successful');
365
+ // Ensure AIT is refreshed after sign-in
366
+ await refreshAIT();
367
+ // Wait for AIT to be fully loaded with polling
368
+ let attempts = 0;
369
+ const maxAttempts = 20; // Wait up to 10 seconds
370
+ while (!aitRef.current && attempts < maxAttempts) {
371
+ await new Promise(resolve => setTimeout(resolve, 500));
372
+ attempts++;
373
+ }
374
+ // Wait a bit more to ensure permissions are also loaded
375
+ await new Promise(resolve => setTimeout(resolve, 1000));
316
376
  // If sign-in successful, continue with permission check
317
377
  const result = await hasPermission(toolName, false);
318
378
  return result;
@@ -345,6 +405,19 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
345
405
  setIsAutoConnecting(true); // Mark as auto-signing
346
406
  await signInWallet(false); // Don't show success message yet
347
407
  setIsAutoConnecting(false); // Clear auto-signing state
408
+ // Show brief success message for auto-sign-in after session expiry
409
+ showSuccess('Auto sign-in successful after session expiry');
410
+ // Ensure AIT is refreshed after sign-in
411
+ await refreshAIT();
412
+ // Wait for AIT to be fully loaded with polling
413
+ let attempts = 0;
414
+ const maxAttempts = 20; // Wait up to 10 seconds
415
+ while (!aitRef.current && attempts < maxAttempts) {
416
+ await new Promise(resolve => setTimeout(resolve, 500));
417
+ attempts++;
418
+ }
419
+ // Wait a bit more to ensure permissions are also loaded
420
+ await new Promise(resolve => setTimeout(resolve, 1000));
348
421
  // If sign-in successful, continue with permission check
349
422
  const result = await hasPermission(toolName, false);
350
423
  return result;
@@ -374,6 +447,19 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
374
447
  setIsAutoConnecting(true); // Mark as auto-signing
375
448
  await signInWallet(false); // Don't show success message yet
376
449
  setIsAutoConnecting(false); // Clear auto-signing state
450
+ // Show brief success message for auto-sign-in after address mismatch
451
+ showSuccess('Auto sign-in successful after address mismatch');
452
+ // Ensure AIT is refreshed after sign-in
453
+ await refreshAIT();
454
+ // Wait for AIT to be fully loaded with polling
455
+ let attempts = 0;
456
+ const maxAttempts = 20; // Wait up to 10 seconds
457
+ while (!aitRef.current && attempts < maxAttempts) {
458
+ await new Promise(resolve => setTimeout(resolve, 500));
459
+ attempts++;
460
+ }
461
+ // Wait a bit more to ensure permissions are also loaded
462
+ await new Promise(resolve => setTimeout(resolve, 1000));
377
463
  // If sign-in successful, continue with permission check
378
464
  const result = await hasPermission(toolName, false);
379
465
  return result;
@@ -404,6 +490,19 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
404
490
  setIsAutoConnecting(true); // Mark as auto-signing
405
491
  await signInWallet(false); // Don't show success message yet
406
492
  setIsAutoConnecting(false); // Clear auto-signing state
493
+ // Show brief success message for auto-sign-in after token parse error
494
+ showSuccess('Auto sign-in successful after token error');
495
+ // Ensure AIT is refreshed after sign-in
496
+ await refreshAIT();
497
+ // Wait for AIT to be fully loaded with polling
498
+ let attempts = 0;
499
+ const maxAttempts = 20; // Wait up to 10 seconds
500
+ while (!aitRef.current && attempts < maxAttempts) {
501
+ await new Promise(resolve => setTimeout(resolve, 500));
502
+ attempts++;
503
+ }
504
+ // Wait a bit more to ensure permissions are also loaded
505
+ await new Promise(resolve => setTimeout(resolve, 1000));
407
506
  // If sign-in successful, continue with permission check
408
507
  const result = await hasPermission(toolName, false);
409
508
  return result;
@@ -497,6 +596,29 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
497
596
  return false;
498
597
  }
499
598
  if (!currentPermissions.includes(toolName)) {
599
+ // Check if AIT is still loading or if we just auto-connected
600
+ if (isAITLoading || isAutoConnecting) {
601
+ setIsLoading(false); // Stop thinking before showing message
602
+ setMessages(prev => [...prev, {
603
+ id: Date.now().toString(),
604
+ content: 'Loading your wallet configuration... Please wait a moment.',
605
+ role: 'assistant',
606
+ timestamp: new Date().toISOString()
607
+ }]);
608
+ return false;
609
+ }
610
+ // If AIT is loaded but permissions are empty, it means no AIT was found
611
+ if (currentAit && currentPermissions.length === 0) {
612
+ setIsLoading(false); // Stop thinking before showing message
613
+ setMessages(prev => [...prev, {
614
+ id: Date.now().toString(),
615
+ content: 'No AIT found for your wallet. Please click the settings button (⚙️) to configure your AIT permissions.',
616
+ role: 'assistant',
617
+ timestamp: new Date().toISOString()
618
+ }]);
619
+ return false;
620
+ }
621
+ // Only show permission error if AIT is loaded and permissions are not empty
500
622
  setIsLoading(false); // Stop thinking before showing message
501
623
  setMessages(prev => [...prev, {
502
624
  id: Date.now().toString(),
@@ -548,8 +670,9 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
548
670
  }
549
671
  setIsLoading(true);
550
672
  try {
551
- // Build context messages
552
- const contextMessages = messages.map(msg => ({
673
+ // Build context messages (filter out wallet connection messages)
674
+ const filteredMessages = getFilteredMessagesForAPI();
675
+ const contextMessages = filteredMessages.map(msg => ({
553
676
  role: msg.role,
554
677
  text: msg.content
555
678
  }));
@@ -576,9 +699,25 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
576
699
  // If we just auto-connected, retry the message once
577
700
  if (wasAutoConnected && retryCount < 1) {
578
701
  console.log('Auto-connected, retrying message...');
579
- setTimeout(() => {
702
+ // Clear loading state and retry immediately
703
+ setIsLoading(false);
704
+ // Use a longer delay to ensure AIT is fully loaded
705
+ setTimeout(async () => {
706
+ // Wait for AIT to be loaded if needed
707
+ if (!aitRef.current && nxtlinqAITServiceAccessTokenRef.current) {
708
+ await refreshAIT();
709
+ // Wait for AIT to be fully loaded with polling
710
+ let attempts = 0;
711
+ const maxAttempts = 20; // Wait up to 10 seconds
712
+ while (!aitRef.current && attempts < maxAttempts) {
713
+ await new Promise(resolve => setTimeout(resolve, 500));
714
+ attempts++;
715
+ }
716
+ }
717
+ // Wait a bit more to ensure permissions are also loaded
718
+ await new Promise(resolve => setTimeout(resolve, 1000));
580
719
  sendMessage(content, retryCount + 1, isPresetMessage);
581
- }, 2000);
720
+ }, 1000);
582
721
  }
583
722
  else {
584
723
  console.log('Permission denied, not retrying. wasAutoConnected:', wasAutoConnected, 'retryCount:', retryCount);
@@ -1 +1 @@
1
- {"version":3,"file":"PermissionForm.d.ts","sourceRoot":"","sources":["../../../src/components/ui/PermissionForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,UAAU,mBAAmB;IAC3B,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAifxD,CAAC"}
1
+ {"version":3,"file":"PermissionForm.d.ts","sourceRoot":"","sources":["../../../src/components/ui/PermissionForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,UAAU,mBAAmB;IAC3B,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAkgBxD,CAAC"}
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import * as React from 'react';
3
3
  import { useChatBot } from '../context/ChatBotContext';
4
4
  export const PermissionForm = ({ onClose, onOpen }) => {
5
- const { hitAddress, permissions, setPermissions, setIsDisabled, onSave, onConnectWallet, onSignIn, isNeedSignInWithWallet, walletInfo, onVerifyWallet, serviceId, nxtlinqApi, permissionGroup, isAITLoading, isWalletLoading = false } = useChatBot();
5
+ const { hitAddress, permissions, setPermissions, setIsDisabled, onSave, onConnectWallet, onSignIn, isNeedSignInWithWallet, walletInfo, onVerifyWallet, serviceId, nxtlinqApi, permissionGroup, isAITLoading, isWalletLoading = false, refreshAIT } = useChatBot();
6
6
  const [availablePermissions, setAvailablePermissions] = React.useState([]);
7
7
  const [isSaving, setIsSaving] = React.useState(false);
8
8
  const [tempPermissions, setTempPermissions] = React.useState(permissions);
@@ -31,6 +31,22 @@ export const PermissionForm = ({ onClose, onOpen }) => {
31
31
  React.useEffect(() => {
32
32
  fetchAvailablePermissions();
33
33
  }, [serviceId, nxtlinqApi, permissionGroup]);
34
+ // Refresh wallet info when component mounts or when hitAddress changes
35
+ React.useEffect(() => {
36
+ if (hitAddress) {
37
+ // Trigger a refresh of AIT and wallet info when the form opens
38
+ const refreshWalletInfo = async () => {
39
+ try {
40
+ // This will trigger refreshAIT which includes wallet info fetch
41
+ await refreshAIT();
42
+ }
43
+ catch (error) {
44
+ console.error('Failed to refresh wallet info:', error);
45
+ }
46
+ };
47
+ refreshWalletInfo();
48
+ }
49
+ }, [hitAddress]);
34
50
  const isWalletVerified = Boolean(walletInfo?.id);
35
51
  const handleSave = async () => {
36
52
  setIsSaving(true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytexbyte/nxtlinq-ai-agent-sdk",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
4
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",