@bytexbyte/nxtlinq-ai-agent-ui-react-development 0.4.9 → 0.4.11

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.
@@ -0,0 +1,7 @@
1
+ export type AITMutationAuthenticationPlan = 'reuse_session' | 'sign_in' | 'connect_and_sign_in';
2
+ export declare function planAITMutationAuthentication(params: {
3
+ walletAddress: string | null | undefined;
4
+ walletToken: string | null | undefined;
5
+ hasSigner: boolean;
6
+ }): AITMutationAuthenticationPlan;
7
+ //# sourceMappingURL=aitMutationAuthentication.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aitMutationAuthentication.d.ts","sourceRoot":"","sources":["../src/aitMutationAuthentication.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,6BAA6B,GACrC,eAAe,GACf,SAAS,GACT,qBAAqB,CAAC;AAE1B,wBAAgB,6BAA6B,CAAC,MAAM,EAAE;IACpD,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACzC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACvC,SAAS,EAAE,OAAO,CAAC;CACpB,GAAG,6BAA6B,CAehC"}
@@ -0,0 +1,13 @@
1
+ import { validateWalletSession } from '@bytexbyte/nxtlinq-ai-agent-core-development';
2
+ export function planAITMutationAuthentication(params) {
3
+ const walletAddress = params.walletAddress?.trim();
4
+ const walletToken = params.walletToken?.trim();
5
+ if (walletAddress
6
+ && walletToken
7
+ && validateWalletSession(walletToken, walletAddress).valid) {
8
+ return 'reuse_session';
9
+ }
10
+ return walletAddress && params.hasSigner
11
+ ? 'sign_in'
12
+ : 'connect_and_sign_in';
13
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"ChatBotContext.d.ts","sourceRoot":"","sources":["../../src/context/ChatBotContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AA+B/B,OAAO,EAEL,kBAAkB,EAClB,YAAY,EAEb,MAAM,uBAAuB,CAAC;AAuB/B,eAAO,MAAM,UAAU,0BAMtB,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CA8+FlD,CAAC"}
1
+ {"version":3,"file":"ChatBotContext.d.ts","sourceRoot":"","sources":["../../src/context/ChatBotContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AA+B/B,OAAO,EAEL,kBAAkB,EAClB,YAAY,EAEb,MAAM,uBAAuB,CAAC;AAwB/B,eAAO,MAAM,UAAU,0BAMtB,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAo/FlD,CAAC"}
@@ -8,6 +8,7 @@ import { createNxtlinqApi, setApiHosts, synthesizeSpeechToBuffer, streamSpeechTo
8
8
  import { authorizeTextFrontendTool, hasRecordedWalletVerification, validateWalletSession, } from '@bytexbyte/nxtlinq-ai-agent-core-development';
9
9
  import { AuthorizationLoadingState } from '../authorizationLoadingState';
10
10
  import { PendingTextToolRetryController } from '../pendingTextToolRetry';
11
+ import { planAITMutationAuthentication } from '../aitMutationAuthentication';
11
12
  import { completePiiScan } from '../piiMessageState';
12
13
  import { filterSuggestions } from '../suggestionState';
13
14
  import { RuntimeAITMutationQueue, RuntimeAITRecomputeCoordinator, StaleRuntimeAITResponseError, runtimeAITContextKey, runtimeAITSubjectKey, runtimeAuthorizationMatchesContext, runtimeAuthorizationState, unavailableRuntimeAuthorization, useProviderRuntimeCommit, useRuntimeAITContextCommit, } from '../permissionState';
@@ -2233,8 +2234,16 @@ customError, voiceThresholds, debugVoiceRms = false, sttGlossary, }) => {
2233
2234
  setIsAITEnabling(true);
2234
2235
  let currentSigner = signer;
2235
2236
  let currentHitAddress = hitAddress;
2236
- // If no wallet connected, try to auto-connect first
2237
- if (!currentSigner || !currentHitAddress) {
2237
+ const currentWalletToken = nxtlinqAITServiceAccessTokenRef.current
2238
+ || nxtlinqAITServiceAccessToken;
2239
+ const authenticationPlan = planAITMutationAuthentication({
2240
+ walletAddress: currentHitAddress,
2241
+ walletToken: currentWalletToken,
2242
+ hasSigner: Boolean(currentSigner),
2243
+ });
2244
+ // A valid wallet session is sufficient for an authenticated DB mutation.
2245
+ // A signer is only needed when the session must be established or renewed.
2246
+ if (authenticationPlan === 'connect_and_sign_in') {
2238
2247
  const autoConnectResult = await connectWallet(false); // Don't show sign-in message yet
2239
2248
  if (autoConnectResult) {
2240
2249
  // Wait for state to update - increase wait time
@@ -2248,14 +2257,6 @@ customError, voiceThresholds, debugVoiceRms = false, sttGlossary, }) => {
2248
2257
  currentSigner = signerRef.current || signer;
2249
2258
  currentHitAddress = hitAddressRef.current || hitAddress;
2250
2259
  }
2251
- try {
2252
- await signInWallet(false); // Don't show success message yet
2253
- }
2254
- catch (signInError) {
2255
- showError(walletTextUtils.getWalletText('Wallet connected but sign-in failed. Please try signing in manually.', serviceId));
2256
- setIsAITEnabling(false);
2257
- return false;
2258
- }
2259
2260
  }
2260
2261
  else {
2261
2262
  showError(walletTextUtils.getWalletText('Please connect your wallet first', serviceId));
@@ -2263,13 +2264,17 @@ customError, voiceThresholds, debugVoiceRms = false, sttGlossary, }) => {
2263
2264
  return false;
2264
2265
  }
2265
2266
  }
2266
- // Final check before proceeding
2267
- if (!currentSigner || !currentHitAddress) {
2268
- console.error('Missing signer or wallet address after connection process');
2269
- console.error('Current signer:', !!currentSigner);
2270
- console.error('Current hitAddress:', currentHitAddress);
2271
- console.error('Signer ref:', !!signerRef.current);
2272
- console.error('HitAddress ref:', hitAddressRef.current);
2267
+ if (authenticationPlan !== 'reuse_session') {
2268
+ const signedIn = await signInWallet(false);
2269
+ if (!signedIn) {
2270
+ showError(walletTextUtils.getWalletText('Wallet connected but sign-in failed. Please try signing in manually.', serviceId));
2271
+ setIsAITEnabling(false);
2272
+ return false;
2273
+ }
2274
+ currentHitAddress = hitAddressRef.current || hitAddress;
2275
+ }
2276
+ if (!currentHitAddress) {
2277
+ console.error('Missing wallet address after authentication');
2273
2278
  showError(walletTextUtils.getWalletText('Wallet connection failed. Please try connecting your wallet manually.', serviceId));
2274
2279
  setIsAITEnabling(false);
2275
2280
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytexbyte/nxtlinq-ai-agent-ui-react-development",
3
- "version": "0.4.9",
3
+ "version": "0.4.11",
4
4
  "description": "Official React Web UI for nxtlinq AI Agent — drop-in chat widget",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@bytexbyte/nxtlinq-ai-agent-core-development": "2.0.4",
42
- "@bytexbyte/nxtlinq-ai-agent-web-development": "1.0.4",
42
+ "@bytexbyte/nxtlinq-ai-agent-web-development": "1.0.5",
43
43
  "@emotion/react": "^11.14.0",
44
44
  "@emotion/styled": "^11.14.1",
45
45
  "@mui/icons-material": "^7.2.0",
@@ -0,0 +1,27 @@
1
+ import { validateWalletSession } from '@bytexbyte/nxtlinq-ai-agent-core-development';
2
+
3
+ export type AITMutationAuthenticationPlan =
4
+ | 'reuse_session'
5
+ | 'sign_in'
6
+ | 'connect_and_sign_in';
7
+
8
+ export function planAITMutationAuthentication(params: {
9
+ walletAddress: string | null | undefined;
10
+ walletToken: string | null | undefined;
11
+ hasSigner: boolean;
12
+ }): AITMutationAuthenticationPlan {
13
+ const walletAddress = params.walletAddress?.trim();
14
+ const walletToken = params.walletToken?.trim();
15
+
16
+ if (
17
+ walletAddress
18
+ && walletToken
19
+ && validateWalletSession(walletToken, walletAddress).valid
20
+ ) {
21
+ return 'reuse_session';
22
+ }
23
+
24
+ return walletAddress && params.hasSigner
25
+ ? 'sign_in'
26
+ : 'connect_and_sign_in';
27
+ }
@@ -39,6 +39,7 @@ import {
39
39
  } from '../types/ChatBotTypes';
40
40
  import { AuthorizationLoadingState } from '../authorizationLoadingState';
41
41
  import { PendingTextToolRetryController } from '../pendingTextToolRetry';
42
+ import { planAITMutationAuthentication } from '../aitMutationAuthentication';
42
43
  import { completePiiScan } from '../piiMessageState';
43
44
  import { filterSuggestions } from '../suggestionState';
44
45
  import {
@@ -2559,9 +2560,17 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
2559
2560
 
2560
2561
  let currentSigner = signer;
2561
2562
  let currentHitAddress = hitAddress;
2563
+ const currentWalletToken = nxtlinqAITServiceAccessTokenRef.current
2564
+ || nxtlinqAITServiceAccessToken;
2565
+ const authenticationPlan = planAITMutationAuthentication({
2566
+ walletAddress: currentHitAddress,
2567
+ walletToken: currentWalletToken,
2568
+ hasSigner: Boolean(currentSigner),
2569
+ });
2562
2570
 
2563
- // If no wallet connected, try to auto-connect first
2564
- if (!currentSigner || !currentHitAddress) {
2571
+ // A valid wallet session is sufficient for an authenticated DB mutation.
2572
+ // A signer is only needed when the session must be established or renewed.
2573
+ if (authenticationPlan === 'connect_and_sign_in') {
2565
2574
  const autoConnectResult = await connectWallet(false); // Don't show sign-in message yet
2566
2575
 
2567
2576
  if (autoConnectResult) {
@@ -2579,13 +2588,6 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
2579
2588
  currentHitAddress = hitAddressRef.current || hitAddress;
2580
2589
  }
2581
2590
 
2582
- try {
2583
- await signInWallet(false); // Don't show success message yet
2584
- } catch (signInError) {
2585
- showError(walletTextUtils.getWalletText('Wallet connected but sign-in failed. Please try signing in manually.', serviceId));
2586
- setIsAITEnabling(false);
2587
- return false;
2588
- }
2589
2591
  } else {
2590
2592
  showError(walletTextUtils.getWalletText('Please connect your wallet first', serviceId));
2591
2593
  setIsAITEnabling(false);
@@ -2593,13 +2595,18 @@ export const ChatBotProvider: React.FC<ChatBotProps> = ({
2593
2595
  }
2594
2596
  }
2595
2597
 
2596
- // Final check before proceeding
2597
- if (!currentSigner || !currentHitAddress) {
2598
- console.error('Missing signer or wallet address after connection process');
2599
- console.error('Current signer:', !!currentSigner);
2600
- console.error('Current hitAddress:', currentHitAddress);
2601
- console.error('Signer ref:', !!signerRef.current);
2602
- console.error('HitAddress ref:', hitAddressRef.current);
2598
+ if (authenticationPlan !== 'reuse_session') {
2599
+ const signedIn = await signInWallet(false);
2600
+ if (!signedIn) {
2601
+ showError(walletTextUtils.getWalletText('Wallet connected but sign-in failed. Please try signing in manually.', serviceId));
2602
+ setIsAITEnabling(false);
2603
+ return false;
2604
+ }
2605
+ currentHitAddress = hitAddressRef.current || hitAddress;
2606
+ }
2607
+
2608
+ if (!currentHitAddress) {
2609
+ console.error('Missing wallet address after authentication');
2603
2610
  showError(walletTextUtils.getWalletText('Wallet connection failed. Please try connecting your wallet manually.', serviceId));
2604
2611
  setIsAITEnabling(false);
2605
2612
  return false;