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

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,CAqzClD,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,CA42ClD,CAAC"}
@@ -14,7 +14,7 @@ export const useChatBot = () => {
14
14
  }
15
15
  return context;
16
16
  };
17
- export const ChatBotProvider = ({ onMessage, onError, onToolUse, presetMessages = [], placeholder = 'Type a message...', className = '', maxRetries = 3, retryDelay = 1000, serviceId, apiKey, apiSecret, onVerifyWallet, permissionGroup, children,
17
+ export const ChatBotProvider = ({ onMessage, onError, onToolUse, presetMessages = [], placeholder = 'Type a message...', className = '', maxRetries = 3, retryDelay = 2000, serviceId, apiKey, apiSecret, onVerifyWallet, permissionGroup, children,
18
18
  // AI Model related attributes
19
19
  availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector = true, onModelChange }) => {
20
20
  // State
@@ -285,6 +285,8 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
285
285
  }
286
286
  const { accessToken } = response;
287
287
  setNxtlinqAITServiceAccessToken(accessToken);
288
+ // Wait for state to update before refreshing AIT
289
+ await new Promise(resolve => setTimeout(resolve, 100));
288
290
  // Wait for AIT to be loaded before showing success message
289
291
  await refreshAIT();
290
292
  if (autoShowSuccessMessage) {
@@ -323,14 +325,14 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
323
325
  console.log('Set justAutoConnected to true after auto-connect');
324
326
  // Show brief success message for auto-connect
325
327
  showSuccess('Auto wallet connection successful');
326
- // Clear the flag after a short delay
328
+ // Clear the flag after a longer delay to allow for AIT loading
327
329
  setTimeout(() => {
328
330
  setJustAutoConnected(false);
329
- }, 2000);
331
+ }, 15000); // 15 seconds to allow for full AIT loading process
330
332
  onAutoConnect?.(); // Call callback if provided
331
333
  // If connection successful, continue with permission check
332
334
  // Wait a bit for state to update
333
- await new Promise(resolve => setTimeout(resolve, 500));
335
+ await new Promise(resolve => setTimeout(resolve, 2000));
334
336
  const result = await hasPermission(toolName, false);
335
337
  return result;
336
338
  }
@@ -366,16 +368,24 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
366
368
  await refreshAIT();
367
369
  // Wait for AIT to be fully loaded with polling
368
370
  let attempts = 0;
369
- const maxAttempts = 20; // Wait up to 10 seconds
371
+ const maxAttempts = 5; // Wait up to 10 seconds (5 * 2000ms)
370
372
  while (!aitRef.current && attempts < maxAttempts) {
371
- await new Promise(resolve => setTimeout(resolve, 500));
373
+ await new Promise(resolve => setTimeout(resolve, 2000));
372
374
  attempts++;
373
375
  }
374
- // Wait a bit more to ensure permissions are also loaded
375
- await new Promise(resolve => setTimeout(resolve, 1000));
376
- // If sign-in successful, continue with permission check
377
- const result = await hasPermission(toolName, false);
378
- return result;
376
+ // Only continue if AIT is actually loaded
377
+ if (aitRef.current) {
378
+ console.log('AIT loaded successfully after sign-in, continuing permission check');
379
+ // Wait a bit more to ensure permissions are also loaded
380
+ await new Promise(resolve => setTimeout(resolve, 2000));
381
+ // If sign-in successful, continue with permission check
382
+ const result = await hasPermission(toolName, false);
383
+ return result;
384
+ }
385
+ else {
386
+ console.log('AIT failed to load after sign-in, returning false');
387
+ return false;
388
+ }
379
389
  }
380
390
  catch (error) {
381
391
  console.error('Failed to auto-sign-in wallet:', error);
@@ -411,16 +421,24 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
411
421
  await refreshAIT();
412
422
  // Wait for AIT to be fully loaded with polling
413
423
  let attempts = 0;
414
- const maxAttempts = 20; // Wait up to 10 seconds
424
+ const maxAttempts = 5; // Wait up to 10 seconds (5 * 2000ms)
415
425
  while (!aitRef.current && attempts < maxAttempts) {
416
- await new Promise(resolve => setTimeout(resolve, 500));
426
+ await new Promise(resolve => setTimeout(resolve, 2000));
417
427
  attempts++;
418
428
  }
419
- // Wait a bit more to ensure permissions are also loaded
420
- await new Promise(resolve => setTimeout(resolve, 1000));
421
- // If sign-in successful, continue with permission check
422
- const result = await hasPermission(toolName, false);
423
- return result;
429
+ // Only continue if AIT is actually loaded
430
+ if (aitRef.current) {
431
+ console.log('AIT loaded successfully after session expiry, continuing permission check');
432
+ // Wait a bit more to ensure permissions are also loaded
433
+ await new Promise(resolve => setTimeout(resolve, 2000));
434
+ // If sign-in successful, continue with permission check
435
+ const result = await hasPermission(toolName, false);
436
+ return result;
437
+ }
438
+ else {
439
+ console.log('AIT failed to load after session expiry, returning false');
440
+ return false;
441
+ }
424
442
  }
425
443
  catch (error) {
426
444
  console.error('Failed to auto-sign-in after session expiry:', error);
@@ -453,16 +471,24 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
453
471
  await refreshAIT();
454
472
  // Wait for AIT to be fully loaded with polling
455
473
  let attempts = 0;
456
- const maxAttempts = 20; // Wait up to 10 seconds
474
+ const maxAttempts = 5; // Wait up to 10 seconds (5 * 2000ms)
457
475
  while (!aitRef.current && attempts < maxAttempts) {
458
- await new Promise(resolve => setTimeout(resolve, 500));
476
+ await new Promise(resolve => setTimeout(resolve, 2000));
459
477
  attempts++;
460
478
  }
461
- // Wait a bit more to ensure permissions are also loaded
462
- await new Promise(resolve => setTimeout(resolve, 1000));
463
- // If sign-in successful, continue with permission check
464
- const result = await hasPermission(toolName, false);
465
- return result;
479
+ // Only continue if AIT is actually loaded
480
+ if (aitRef.current) {
481
+ console.log('AIT loaded successfully after address mismatch, continuing permission check');
482
+ // Wait a bit more to ensure permissions are also loaded
483
+ await new Promise(resolve => setTimeout(resolve, 2000));
484
+ // If sign-in successful, continue with permission check
485
+ const result = await hasPermission(toolName, false);
486
+ return result;
487
+ }
488
+ else {
489
+ console.log('AIT failed to load after address mismatch, returning false');
490
+ return false;
491
+ }
466
492
  }
467
493
  catch (error) {
468
494
  console.error('Failed to auto-sign-in after address mismatch:', error);
@@ -496,16 +522,24 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
496
522
  await refreshAIT();
497
523
  // Wait for AIT to be fully loaded with polling
498
524
  let attempts = 0;
499
- const maxAttempts = 20; // Wait up to 10 seconds
525
+ const maxAttempts = 5; // Wait up to 10 seconds (5 * 2000ms)
500
526
  while (!aitRef.current && attempts < maxAttempts) {
501
- await new Promise(resolve => setTimeout(resolve, 500));
527
+ await new Promise(resolve => setTimeout(resolve, 2000));
502
528
  attempts++;
503
529
  }
504
- // Wait a bit more to ensure permissions are also loaded
505
- await new Promise(resolve => setTimeout(resolve, 1000));
506
- // If sign-in successful, continue with permission check
507
- const result = await hasPermission(toolName, false);
508
- return result;
530
+ // Only continue if AIT is actually loaded
531
+ if (aitRef.current) {
532
+ console.log('AIT loaded successfully after token error, continuing permission check');
533
+ // Wait a bit more to ensure permissions are also loaded
534
+ await new Promise(resolve => setTimeout(resolve, 2000));
535
+ // If sign-in successful, continue with permission check
536
+ const result = await hasPermission(toolName, false);
537
+ return result;
538
+ }
539
+ else {
540
+ console.log('AIT failed to load after token error, returning false');
541
+ return false;
542
+ }
509
543
  }
510
544
  catch (signInError) {
511
545
  console.error('Failed to auto-sign-in after token parse error:', signInError);
@@ -534,9 +568,9 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
534
568
  await refreshAIT();
535
569
  // Wait for AIT to be loaded with polling
536
570
  let attempts = 0;
537
- const maxAttempts = 10; // Wait up to 5 seconds
571
+ const maxAttempts = 5; // Wait up to 10 seconds (5 * 2000ms)
538
572
  while (!aitRef.current && attempts < maxAttempts) {
539
- await new Promise(resolve => setTimeout(resolve, 500));
573
+ await new Promise(resolve => setTimeout(resolve, 2000));
540
574
  attempts++;
541
575
  }
542
576
  // Check again after refresh
@@ -701,23 +735,41 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
701
735
  console.log('Auto-connected, retrying message...');
702
736
  // Clear loading state and retry immediately
703
737
  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();
738
+ // Check if wallet is already signed in
739
+ const currentToken = nxtlinqAITServiceAccessTokenRef.current;
740
+ if (!currentToken) {
741
+ // If not signed in, directly retry the message without waiting for AIT
742
+ console.log('Wallet connected but not signed in, retrying message directly');
743
+ setTimeout(() => {
744
+ sendMessage(content, retryCount + 1, isPresetMessage);
745
+ }, 2000);
746
+ }
747
+ else {
748
+ // If already signed in, wait for AIT to be fully loaded before retrying
749
+ setTimeout(async () => {
750
+ // Wait for AIT to be loaded if needed
751
+ if (!aitRef.current && nxtlinqAITServiceAccessTokenRef.current) {
752
+ await refreshAIT();
753
+ }
709
754
  // Wait for AIT to be fully loaded with polling
710
755
  let attempts = 0;
711
- const maxAttempts = 20; // Wait up to 10 seconds
756
+ const maxAttempts = 5; // Wait up to 10 seconds (5 * 2000ms)
712
757
  while (!aitRef.current && attempts < maxAttempts) {
713
- await new Promise(resolve => setTimeout(resolve, 500));
758
+ await new Promise(resolve => setTimeout(resolve, 2000));
714
759
  attempts++;
715
760
  }
716
- }
717
- // Wait a bit more to ensure permissions are also loaded
718
- await new Promise(resolve => setTimeout(resolve, 1000));
719
- sendMessage(content, retryCount + 1, isPresetMessage);
720
- }, 1000);
761
+ // Only retry if AIT is actually loaded
762
+ if (aitRef.current) {
763
+ console.log('AIT loaded successfully, retrying message');
764
+ // Wait a bit more to ensure permissions are also loaded
765
+ await new Promise(resolve => setTimeout(resolve, 2000));
766
+ sendMessage(content, retryCount + 1, isPresetMessage);
767
+ }
768
+ else {
769
+ console.log('AIT failed to load, not retrying');
770
+ }
771
+ }, 2000);
772
+ }
721
773
  }
722
774
  else {
723
775
  console.log('Permission denied, not retrying. wasAutoConnected:', wasAutoConnected, 'retryCount:', retryCount);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytexbyte/nxtlinq-ai-agent-sdk",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
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",