@bytexbyte/nxtlinq-ai-agent-ui-react-development 0.4.1 → 0.4.2

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/context/ChatBotContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAyB/B,OAAO,EAEL,kBAAkB,EAClB,YAAY,EAEb,MAAM,uBAAuB,CAAC;AAM/B,eAAO,MAAM,UAAU,0BAMtB,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CA+vGlD,CAAC"}
1
+ {"version":3,"file":"ChatBotContext.d.ts","sourceRoot":"","sources":["../../src/context/ChatBotContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AA6B/B,OAAO,EAEL,kBAAkB,EAClB,YAAY,EAEb,MAAM,uBAAuB,CAAC;AAM/B,eAAO,MAAM,UAAU,0BAMtB,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CA25FlD,CAAC"}
@@ -5,6 +5,7 @@ import * as React from 'react';
5
5
  import { flushSync } from 'react-dom';
6
6
  import { v4 as uuidv4 } from 'uuid';
7
7
  import { createNxtlinqApi, setApiHosts, synthesizeSpeechToBuffer, streamSpeechToAudioContext, useLocalStorage, useSessionStorage, useSpeechToTextFromMic, useVoiceMode, metakeepClient, getEthers, sleep, walletTextUtils, } from '@bytexbyte/nxtlinq-ai-agent-web-development';
8
+ import { authorizeTextFrontendTool, hasRecordedWalletVerification, } from '@bytexbyte/nxtlinq-ai-agent-core-development';
8
9
  const MIC_ENABLED_SESSION_KEY = 'chatbot-mic-enabled';
9
10
  const ChatBotContext = React.createContext(undefined);
10
11
  export const useChatBot = () => {
@@ -868,14 +869,18 @@ customError, voiceThresholds, debugVoiceRms = false, sttGlossary, }) => {
868
869
  }
869
870
  setIsAITLoading(true);
870
871
  try {
872
+ let walletAllowsAITLookup = !requireWalletIDVVerification;
871
873
  // Get wallet info first - always try to get wallet info if we have a token
872
874
  if (nxtlinqAITServiceAccessToken) {
873
875
  try {
874
876
  const walletResponse = await nxtlinqApi.wallet.getWallet({ address: hitAddress }, nxtlinqAITServiceAccessToken);
875
877
  if (!('error' in walletResponse)) {
876
878
  setWalletInfo(walletResponse);
879
+ walletAllowsAITLookup = !requireWalletIDVVerification
880
+ || hasRecordedWalletVerification(walletResponse);
877
881
  }
878
882
  else {
883
+ setWalletInfo(null);
879
884
  // Check if the error is due to invalid/expired token
880
885
  if (walletResponse.error.includes('Invalid or expired token')) {
881
886
  console.log('Token appears to be invalid during wallet info fetch, clearing it');
@@ -884,9 +889,17 @@ customError, voiceThresholds, debugVoiceRms = false, sttGlossary, }) => {
884
889
  }
885
890
  }
886
891
  catch (error) {
892
+ setWalletInfo(null);
887
893
  console.error('Failed to fetch wallet info:', error);
888
894
  }
889
895
  }
896
+ // AIT existence is not identity verification. In strict mode, stop before
897
+ // the legacy AIT lookup can synthesize a custom wallet record.
898
+ if (nxtlinqAITServiceAccessToken && !walletAllowsAITLookup) {
899
+ setAit(null);
900
+ setPermissions([]);
901
+ return;
902
+ }
890
903
  // Only try to fetch AIT if we have a token
891
904
  if (nxtlinqAITServiceAccessToken) {
892
905
  const response = await nxtlinqApi.ait.getAITByServiceIdAndController({
@@ -1118,338 +1131,67 @@ customError, voiceThresholds, debugVoiceRms = false, sttGlossary, }) => {
1118
1131
  }
1119
1132
  };
1120
1133
  // Check permissions
1121
- const hasPermission = async (requiredPermission, autoRetry = true, onAutoConnect, onAutoSignIn) => {
1134
+ const hasPermission = async (requiredPermission) => {
1122
1135
  // Use refs to get latest state values
1123
1136
  const currentHitAddress = hitAddressRef.current;
1124
- const currentAit = aitRef.current;
1125
- const currentPermissions = permissionsRef.current;
1126
1137
  const currentToken = nxtlinqAITServiceAccessTokenRef.current;
1127
- if (!currentHitAddress) {
1128
- if (autoRetry) {
1129
- setIsLoading(false); // Stop thinking before showing message
1130
- setMessages(prev => [...prev, {
1131
- id: Date.now().toString(),
1132
- content: walletTextUtils.getWalletText('Please connect your HIT wallet to continue.', serviceId),
1133
- role: 'assistant',
1134
- timestamp: new Date().toISOString(),
1135
- button: 'connectWallet'
1136
- }]);
1137
- try {
1138
- setIsAutoConnecting(true); // Mark as auto-connecting
1139
- await connectWallet(false); // Don't show sign-in message yet
1140
- setIsAutoConnecting(false); // Clear auto-connecting state
1141
- // Show brief success message for auto-connect
1142
- showSuccess(walletTextUtils.getWalletText('Auto wallet connection successful', serviceId));
1143
- onAutoConnect?.(); // Call callback if provided
1144
- await new Promise(resolve => setTimeout(resolve, 2000));
1145
- // After auto connect, if not signed in, then auto sign-in
1146
- const tokenAfterConnect = nxtlinqAITServiceAccessTokenRef.current;
1147
- if (!tokenAfterConnect) {
1148
- setIsAutoConnecting(true);
1149
- await signInWallet(false);
1150
- onAutoSignIn?.(); // Call callback if provided
1151
- setIsAutoConnecting(false);
1152
- showSuccess(walletTextUtils.getWalletText('Auto sign-in successful after wallet connect', serviceId));
1153
- await refreshAIT();
1154
- // Wait for AIT to be fully loaded with polling
1155
- let attempts = 0;
1156
- const maxAttempts = 5;
1157
- while (!aitRef.current && attempts < maxAttempts) {
1158
- await new Promise(resolve => setTimeout(resolve, 2000));
1159
- attempts++;
1160
- }
1161
- }
1162
- // If connection (and sign-in if needed) successful, continue with permission check
1163
- const result = await hasPermission(requiredPermission, false);
1164
- return result;
1165
- }
1166
- catch (error) {
1167
- console.error('Failed to auto-connect wallet:', error);
1168
- setIsAutoConnecting(false); // Clear auto-connecting state on error
1169
- return false;
1170
- }
1171
- }
1172
- // If autoRetry is false, don't show message again, just return false
1173
- return false;
1174
- }
1175
- if (!currentToken) {
1176
- if (autoRetry) {
1177
- setIsLoading(false); // Stop thinking before showing message
1178
- setMessages(prev => [...prev, {
1179
- id: Date.now().toString(),
1180
- content: walletTextUtils.getWalletText('Please sign in with your HIT wallet to continue.', serviceId),
1181
- role: 'assistant',
1182
- timestamp: new Date().toISOString(),
1183
- button: 'signIn'
1184
- }]);
1185
- try {
1186
- setIsAutoConnecting(true); // Mark as auto-signing
1187
- await signInWallet(false); // Don't show success message yet
1188
- onAutoSignIn?.(); // Call callback if provided
1189
- setIsAutoConnecting(false); // Clear auto-signing state
1190
- // Show brief success message for auto-sign-in
1191
- showSuccess('Auto sign-in successful');
1192
- // Ensure AIT is refreshed after sign-in
1193
- await refreshAIT();
1194
- // Wait for AIT to be fully loaded with polling
1195
- let attempts = 0;
1196
- const maxAttempts = 5; // Wait up to 10 seconds (5 * 2000ms)
1197
- while (!aitRef.current && attempts < maxAttempts) {
1198
- await new Promise(resolve => setTimeout(resolve, 2000));
1199
- attempts++;
1200
- }
1201
- // Only continue if AIT is actually loaded
1202
- if (aitRef.current) {
1203
- // Wait a bit more to ensure permissions are also loaded
1204
- await new Promise(resolve => setTimeout(resolve, 2000));
1205
- // If sign-in successful, continue with permission check
1206
- const result = await hasPermission(requiredPermission, false);
1207
- return result;
1208
- }
1209
- else {
1210
- return false;
1211
- }
1212
- }
1213
- catch (error) {
1214
- console.error('Failed to auto-sign-in wallet:', error);
1215
- setIsAutoConnecting(false); // Clear auto-signing state on error
1216
- return false;
1217
- }
1218
- }
1219
- // If autoRetry is false, don't show message again, just return false
1220
- return false;
1221
- }
1222
- try {
1223
- const payload = JSON.parse(atob(currentToken.split('.')[1]));
1224
- const address = payload.address;
1225
- if (address !== currentHitAddress) {
1226
- setNxtlinqAITServiceAccessToken('');
1227
- if (autoRetry) {
1228
- setIsLoading(false); // Stop thinking before showing message
1229
- setMessages(prev => [...prev, {
1230
- id: Date.now().toString(),
1231
- content: walletTextUtils.getWalletText('Wallet address mismatch. Please sign in with the correct wallet.', serviceId),
1232
- role: 'assistant',
1233
- timestamp: new Date().toISOString(),
1234
- button: 'signIn'
1235
- }]);
1236
- try {
1237
- setIsAutoConnecting(true); // Mark as auto-signing
1238
- await signInWallet(false); // Don't show success message yet
1239
- onAutoSignIn?.(); // Call callback if provided
1240
- setIsAutoConnecting(false); // Clear auto-signing state
1241
- // Show brief success message for auto-sign-in after address mismatch
1242
- showSuccess('Auto sign-in successful after address mismatch');
1243
- // Ensure AIT is refreshed after sign-in
1244
- await refreshAIT();
1245
- // Wait for AIT to be fully loaded with polling
1246
- let attempts = 0;
1247
- const maxAttempts = 5; // Wait up to 10 seconds (5 * 2000ms)
1248
- while (!aitRef.current && attempts < maxAttempts) {
1249
- await new Promise(resolve => setTimeout(resolve, 2000));
1250
- attempts++;
1251
- }
1252
- // Only continue if AIT is actually loaded
1253
- if (aitRef.current) {
1254
- // Wait a bit more to ensure permissions are also loaded
1255
- await new Promise(resolve => setTimeout(resolve, 2000));
1256
- // If sign-in successful, continue with permission check
1257
- const result = await hasPermission(requiredPermission, false);
1258
- return result;
1259
- }
1260
- else {
1261
- return false;
1262
- }
1263
- }
1264
- catch (error) {
1265
- console.error('Failed to auto-sign-in after address mismatch:', error);
1266
- setIsAutoConnecting(false); // Clear auto-signing state on error
1267
- return false;
1268
- }
1269
- }
1270
- // If autoRetry is false, don't show message again, just return false
1271
- return false;
1272
- }
1273
- }
1274
- catch (error) {
1275
- console.error('Error parsing token:', error);
1276
- setNxtlinqAITServiceAccessToken('');
1277
- if (autoRetry) {
1278
- setIsLoading(false); // Stop thinking before showing message
1279
- setMessages(prev => [...prev, {
1280
- id: Date.now().toString(),
1281
- content: walletTextUtils.getWalletText('Invalid wallet session. Please sign in again.', serviceId),
1282
- role: 'assistant',
1283
- timestamp: new Date().toISOString(),
1284
- button: 'signIn'
1285
- }]);
1286
- try {
1287
- setIsAutoConnecting(true); // Mark as auto-signing
1288
- await signInWallet(false); // Don't show success message yet
1289
- onAutoSignIn?.(); // Call callback if provided
1290
- setIsAutoConnecting(false); // Clear auto-signing state
1291
- // Show brief success message for auto-sign-in after token parse error
1292
- showSuccess('Auto sign-in successful after token error');
1293
- // Ensure AIT is refreshed after sign-in
1294
- await refreshAIT();
1295
- // Wait for AIT to be fully loaded with polling
1296
- let attempts = 0;
1297
- const maxAttempts = 5; // Wait up to 10 seconds (5 * 2000ms)
1298
- while (!aitRef.current && attempts < maxAttempts) {
1299
- await new Promise(resolve => setTimeout(resolve, 2000));
1300
- attempts++;
1301
- }
1302
- // Only continue if AIT is actually loaded
1303
- if (aitRef.current) {
1304
- // Wait a bit more to ensure permissions are also loaded
1305
- await new Promise(resolve => setTimeout(resolve, 2000));
1306
- // If sign-in successful, continue with permission check
1307
- const result = await hasPermission(requiredPermission, false);
1308
- return result;
1309
- }
1310
- else {
1311
- return false;
1312
- }
1313
- }
1314
- catch (signInError) {
1315
- console.error('Failed to auto-sign-in after token parse error:', signInError);
1316
- setIsAutoConnecting(false); // Clear auto-signing state on error
1317
- return false;
1318
- }
1319
- }
1320
- // If autoRetry is false, don't show message again, just return false
1321
- return false;
1322
- }
1323
- if (!currentAit) {
1324
- // Show loading message if AIT is still loading
1325
- if (isAITLoading) {
1326
- setIsLoading(false); // Stop thinking before showing message
1327
- setMessages(prev => [...prev, {
1328
- id: Date.now().toString(),
1329
- content: walletTextUtils.getWalletText('Loading your wallet configuration... Please wait a moment.', serviceId),
1330
- role: 'assistant',
1331
- timestamp: new Date().toISOString()
1332
- }]);
1333
- return false;
1334
- }
1335
- // If AIT is not loaded but we have a token, try to refresh it once
1336
- if (currentToken && !isAITLoading) {
1337
- try {
1338
- await refreshAIT();
1339
- // Wait for AIT to be loaded with polling
1340
- let attempts = 0;
1341
- const maxAttempts = 5; // Wait up to 10 seconds (5 * 2000ms)
1342
- while (!aitRef.current && attempts < maxAttempts) {
1343
- await new Promise(resolve => setTimeout(resolve, 2000));
1344
- attempts++;
1345
- }
1346
- // Check again after refresh
1347
- if (!aitRef.current) {
1348
- setIsLoading(false); // Stop thinking before showing message
1349
- setMessages(prev => [...prev, {
1350
- id: Date.now().toString(),
1351
- content: walletTextUtils.getWalletText('No AIT found for your wallet. Please click the settings button (⚙️) to configure your AIT permissions.', serviceId),
1352
- role: 'assistant',
1353
- timestamp: new Date().toISOString()
1354
- }]);
1355
- return false;
1356
- }
1357
- }
1358
- catch (error) {
1359
- console.error('Failed to refresh AIT during permission check:', error);
1360
- setIsLoading(false); // Stop thinking before showing message
1361
- setMessages(prev => [...prev, {
1362
- id: Date.now().toString(),
1363
- content: 'No AIT found for your wallet. Please click the settings button (⚙️) to configure your AIT permissions.',
1364
- role: 'assistant',
1365
- timestamp: new Date().toISOString()
1366
- }]);
1367
- return false;
1368
- }
1369
- }
1370
- else {
1371
- setIsLoading(false); // Stop thinking before showing message
1372
- setMessages(prev => [...prev, {
1373
- id: Date.now().toString(),
1374
- content: 'No AIT found for your wallet. Please click the settings button (⚙️) to configure your AIT permissions.',
1375
- role: 'assistant',
1376
- timestamp: new Date().toISOString()
1377
- }]);
1378
- return false;
1379
- }
1380
- }
1381
- if (availablePermissions.length === 0) {
1382
- setIsLoading(false); // Stop thinking before showing message
1383
- setMessages(prev => [...prev, {
1384
- id: Date.now().toString(),
1385
- content: `No permissions available for your current identity provider. Please check your service configuration or contact support. Service ID: ${serviceId}, Permission Group: ${permissionGroup || 'None'}`,
1386
- role: 'assistant',
1387
- timestamp: new Date().toISOString()
1388
- }]);
1389
- return false;
1390
- }
1391
- const checkToolPermissionResult = await nxtlinqApi.agent.checkToolPermission({
1138
+ const authorization = await authorizeTextFrontendTool({
1139
+ api: nxtlinqApi,
1140
+ serviceId,
1141
+ toolName: requiredPermission,
1142
+ snapshot: {
1143
+ walletAddress: currentHitAddress,
1144
+ walletToken: currentToken,
1145
+ // Legacy AIT issuance is unscoped (`externalId=''`). Do not impose a
1146
+ // wallet-address subject until issuance/migration supports it.
1147
+ externalId: undefined,
1148
+ requireWalletIDVVerification,
1149
+ loading: isAITLoading || isAutoConnecting,
1150
+ },
1392
1151
  ...authFields(),
1393
- aitToken: currentToken,
1394
- controller: currentHitAddress,
1395
- toolName: requiredPermission
1152
+ customUsername: (!requireWalletIDVVerification && customUsername)
1153
+ ? getFinalCustomUsername(customUsername)
1154
+ : undefined,
1396
1155
  });
1397
- if ('error' in checkToolPermissionResult) {
1398
- // Check if AIT is still loading or if we just auto-connected
1399
- if (isAITLoading || isAutoConnecting) {
1400
- setIsLoading(false); // Stop thinking before showing message
1401
- setMessages(prev => [...prev, {
1402
- id: Date.now().toString(),
1403
- content: walletTextUtils.getWalletText('Loading your wallet configuration... Please wait a moment.', serviceId),
1404
- role: 'assistant',
1405
- timestamp: new Date().toISOString()
1406
- }]);
1407
- return false;
1408
- }
1409
- // Refresh service permissions before judging; use latest result to decide message
1410
- const freshAvailablePermissions = await fetchAvailablePermissions();
1411
- const latestAvailablePermissions = freshAvailablePermissions ?? availablePermissions;
1412
- const requiredPermission = checkToolPermissionResult.requiredPermission;
1413
- const isInServiceList = latestAvailablePermissions.some((p) => p.label === requiredPermission);
1414
- // Permission not in service's available list → "not available for your current identity provider"
1415
- if (!isInServiceList) {
1416
- setIsLoading(false); // Stop thinking before showing message
1417
- setMessages(prev => [...prev, {
1418
- id: Date.now().toString(),
1419
- content: `This permission (${requiredPermission}) is not available for your current identity provider.`,
1420
- role: 'assistant',
1421
- timestamp: new Date().toISOString()
1422
- }]);
1423
- return false;
1424
- }
1425
- // AIT loaded but permissions empty (no AIT found)
1426
- if (currentAit && currentPermissions.length === 0) {
1427
- setIsLoading(false); // Stop thinking before showing message
1428
- setMessages(prev => [...prev, {
1429
- id: Date.now().toString(),
1430
- content: 'No AIT found for your wallet. Please click the settings button (⚙️) to configure your AIT permissions.',
1431
- role: 'assistant',
1432
- timestamp: new Date().toISOString()
1433
- }]);
1434
- return false;
1435
- }
1436
- // User has AIT but hasn't enabled this permission → prompt to enable
1437
- setIsLoading(false); // Stop thinking before showing message
1438
- const permissionMsg = `You don't have the required AIT permission: ${requiredPermission}. Would you like to enable AIT permission?`;
1439
- setMessages(prev => [
1440
- ...prev,
1441
- {
1442
- id: Date.now().toString(),
1443
- content: permissionMsg,
1444
- role: 'assistant',
1445
- timestamp: new Date().toISOString(),
1446
- button: 'enableAIT',
1447
- metadata: { requiredPermission }
1448
- }
1449
- ]);
1450
- return false;
1451
- }
1452
- return true;
1156
+ if (authorization.status === 'allowed')
1157
+ return true;
1158
+ setIsLoading(false);
1159
+ const recovery = {
1160
+ id: Date.now().toString(),
1161
+ content: 'Authorization is temporarily unavailable. Please try again.',
1162
+ role: 'assistant',
1163
+ timestamp: new Date().toISOString(),
1164
+ };
1165
+ switch (authorization.status) {
1166
+ case 'wallet_disconnected':
1167
+ recovery.content = walletTextUtils.getWalletText('Please connect your HIT wallet to continue.', serviceId);
1168
+ recovery.button = 'connectWallet';
1169
+ break;
1170
+ case 'wallet_signed_out':
1171
+ recovery.content = walletTextUtils.getWalletText('Please sign in with your HIT wallet to continue.', serviceId);
1172
+ recovery.button = 'signIn';
1173
+ break;
1174
+ case 'wallet_session_invalid':
1175
+ recovery.content = walletTextUtils.getWalletText('Invalid wallet session. Please sign in again.', serviceId);
1176
+ recovery.button = 'signIn';
1177
+ break;
1178
+ case 'wallet_verification_required':
1179
+ recovery.content = 'Please verify your wallet identity before using this tool.';
1180
+ recovery.button = 'verifyWallet';
1181
+ break;
1182
+ case 'ait_not_found':
1183
+ recovery.content = 'No AIT found for your wallet. Please open settings to configure your AIT.';
1184
+ break;
1185
+ case 'permission_denied':
1186
+ recovery.content = `You don't have the required AIT permission: ${authorization.requiredPermission}. Would you like to enable AIT permission?`;
1187
+ recovery.button = 'enableAIT';
1188
+ recovery.metadata = { requiredPermission: authorization.requiredPermission };
1189
+ break;
1190
+ case 'authorization_unavailable':
1191
+ break;
1192
+ }
1193
+ setMessages(prev => [...prev, recovery]);
1194
+ return false;
1453
1195
  };
1454
1196
  // AI Model related functions
1455
1197
  const handleModelChange = React.useCallback((modelIndex) => {
@@ -1491,6 +1233,9 @@ customError, voiceThresholds, debugVoiceRms = false, sttGlossary, }) => {
1491
1233
  if (!hasContent || isLoading)
1492
1234
  return;
1493
1235
  setPendingAutoTts(null);
1236
+ const turnExternalId = typeof window !== 'undefined'
1237
+ ? localStorage.getItem('walletAddress') || undefined
1238
+ : hitAddressRef.current || undefined;
1494
1239
  const currentModel = getCurrentModel();
1495
1240
  // Initialize with current model, will be updated with actual model from backend response
1496
1241
  let actualModelUsed = currentModel.value;
@@ -1562,7 +1307,7 @@ customError, voiceThresholds, debugVoiceRms = false, sttGlossary, }) => {
1562
1307
  model: currentModel.value,
1563
1308
  ...authFields(),
1564
1309
  pseudoId: pseudoId,
1565
- externalId: localStorage.getItem('walletAddress') || undefined,
1310
+ externalId: turnExternalId,
1566
1311
  customUserInfo,
1567
1312
  customUsername,
1568
1313
  message: content || (attachments && attachments.length > 0 ? `Uploaded ${attachments.length} file(s)` : ''),
@@ -1776,82 +1521,10 @@ customError, voiceThresholds, debugVoiceRms = false, sttGlossary, }) => {
1776
1521
  const toolUse = response.toolCall.toolUse;
1777
1522
  let toolMsg = '';
1778
1523
  if (onToolUse) {
1779
- let wasAutoConnected = false;
1780
- let wasAutoSignedIn = false;
1781
- // Added: Mark if permission denied due to missing AIT permission
1782
- let permissionDenied = false;
1783
- // Use requiredPermission from response if available, otherwise fall back to toolUse.name
1784
- const permissionToCheck = response?.requiredPermission || toolUse.name;
1785
- const isToolAllowed = await hasPermission(permissionToCheck, true, () => { wasAutoConnected = true; }, () => { wasAutoSignedIn = true; });
1786
- // If currentPermissions does not include permissionToCheck and availablePermissionLabels includes permissionToCheck, it means AIT permission is missing
1787
- if (!isToolAllowed && !permissions.includes(permissionToCheck) && availablePermissions.map(p => p.label).includes(permissionToCheck)) {
1788
- permissionDenied = true;
1789
- }
1524
+ const isToolAllowed = await hasPermission(toolUse.name);
1525
+ // Typed preflight already emitted the only permitted recovery UI.
1790
1526
  if (!isToolAllowed) {
1791
- // If permission denied due to missing AIT permission return
1792
- if (permissionDenied) {
1793
- setIsLoading(false);
1794
- return;
1795
- }
1796
- if (isSemiAutomaticMode) {
1797
- setIsLoading(false);
1798
- setMessages(prev => [...prev, {
1799
- id: Date.now().toString(),
1800
- content: 'Click button to continue using tool',
1801
- role: 'assistant',
1802
- timestamp: new Date().toISOString(),
1803
- button: 'continue'
1804
- }]);
1805
- return;
1806
- }
1807
- else {
1808
- // Only retry for auto-connect/auto-sign-in scenarios
1809
- if (wasAutoConnected && retryCount < 1) {
1810
- // Clear loading state and retry immediately
1811
- setIsLoading(false);
1812
- // Check if wallet is already signed in
1813
- const currentToken = nxtlinqAITServiceAccessTokenRef.current;
1814
- if (!currentToken) {
1815
- // If not signed in, directly retry the message without waiting for AIT
1816
- setTimeout(() => {
1817
- sendMessage(content, retryCount + 1, isPresetMessage);
1818
- }, 2000);
1819
- }
1820
- else {
1821
- // If already signed in, wait for AIT to be fully loaded before retrying
1822
- setTimeout(async () => {
1823
- // Wait for AIT to be loaded if needed
1824
- if (!aitRef.current && nxtlinqAITServiceAccessTokenRef.current) {
1825
- await refreshAIT();
1826
- }
1827
- // Wait for AIT to be fully loaded with polling
1828
- let attempts = 0;
1829
- const maxAttempts = 5; // Wait up to 10 seconds (5 * 2000ms)
1830
- while (!aitRef.current && attempts < maxAttempts) {
1831
- await new Promise(resolve => setTimeout(resolve, 2000));
1832
- attempts++;
1833
- }
1834
- // Only retry if AIT is actually loaded
1835
- if (aitRef.current) {
1836
- // Wait a bit more to ensure permissions are also loaded
1837
- await new Promise(resolve => setTimeout(resolve, 3000));
1838
- sendMessage(content, retryCount + 1, isPresetMessage);
1839
- }
1840
- }, 2000);
1841
- }
1842
- }
1843
- return;
1844
- }
1845
- }
1846
- if (isSemiAutomaticMode && wasAutoSignedIn) {
1847
1527
  setIsLoading(false);
1848
- setMessages(prev => [...prev, {
1849
- id: Date.now().toString(),
1850
- content: 'Click button to continue using tool',
1851
- role: 'assistant',
1852
- timestamp: new Date().toISOString(),
1853
- button: 'continue'
1854
- }]);
1855
1528
  return;
1856
1529
  }
1857
1530
  // Create streaming message for tool execution
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { ChatBot } from './ChatBot';
2
2
  export { ChatBotProvider, useChatBot } from './context/ChatBotContext';
3
3
  export { ChatBotUI, MessageInput, MessageList, ModelSelector, NotificationModal, PermissionForm, PresetMessages, BerifyMeModal, } from './ui/index';
4
4
  export type { AIModel, AITMetadata, ChatBotContextType, ChatBotProps, NovaError, NovaResponse, ToolCall, ToolUse, PresetMessage, } from './types/ChatBotTypes';
5
- export type { AgentEnvironment, AgentConfig, Attachment, AgentResponse, Message, SendMessageOptions, NxtlinqAgentSnapshot, VoiceSession, VoiceStatus, } from '@bytexbyte/nxtlinq-ai-agent-core-development';
6
- export { NxtlinqAgent, setApiHosts, VoiceNotSupportedError, STORAGE_KEYS, } from '@bytexbyte/nxtlinq-ai-agent-core-development';
5
+ export type { AgentEnvironment, AgentConfig, Attachment, AgentResponse, Message, SendMessageOptions, NxtlinqAgentSnapshot, TextToolAuthorizationSnapshot, TextToolAuthorizationOutcome, VoiceSession, VoiceStatus, } from '@bytexbyte/nxtlinq-ai-agent-core-development';
6
+ export { NxtlinqAgent, setApiHosts, VoiceNotSupportedError, STORAGE_KEYS, authorizeTextFrontendTool, hasRecordedWalletVerification, validateWalletSession, } from '@bytexbyte/nxtlinq-ai-agent-core-development';
7
7
  export { createNxtlinqApi, useLocalStorage, useSessionStorage, useSpeechToTextFromMic, useVoiceMode, metakeepClient, getEthers, sleep, walletTextUtils, } from '@bytexbyte/nxtlinq-ai-agent-web-development';
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EACL,SAAS,EACT,YAAY,EACZ,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,aAAa,GACd,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,OAAO,EACP,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,aAAa,GACd,MAAM,sBAAsB,CAAC;AAE9B,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,aAAa,EACb,OAAO,EACP,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,WAAW,GACZ,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EACL,YAAY,EACZ,WAAW,EACX,sBAAsB,EACtB,YAAY,GACb,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACtB,YAAY,EACZ,cAAc,EACd,SAAS,EACT,KAAK,EACL,eAAe,GAChB,MAAM,6CAA6C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EACL,SAAS,EACT,YAAY,EACZ,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,aAAa,GACd,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,OAAO,EACP,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,aAAa,GACd,MAAM,sBAAsB,CAAC;AAE9B,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,aAAa,EACb,OAAO,EACP,kBAAkB,EAClB,oBAAoB,EACpB,6BAA6B,EAC7B,4BAA4B,EAC5B,YAAY,EACZ,WAAW,GACZ,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EACL,YAAY,EACZ,WAAW,EACX,sBAAsB,EACtB,YAAY,EACZ,yBAAyB,EACzB,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACtB,YAAY,EACZ,cAAc,EACd,SAAS,EACT,KAAK,EACL,eAAe,GAChB,MAAM,6CAA6C,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { ChatBot } from './ChatBot';
2
2
  export { ChatBotProvider, useChatBot } from './context/ChatBotContext';
3
3
  export { ChatBotUI, MessageInput, MessageList, ModelSelector, NotificationModal, PermissionForm, PresetMessages, BerifyMeModal, } from './ui/index';
4
- export { NxtlinqAgent, setApiHosts, VoiceNotSupportedError, STORAGE_KEYS, } from '@bytexbyte/nxtlinq-ai-agent-core-development';
4
+ export { NxtlinqAgent, setApiHosts, VoiceNotSupportedError, STORAGE_KEYS, authorizeTextFrontendTool, hasRecordedWalletVerification, validateWalletSession, } from '@bytexbyte/nxtlinq-ai-agent-core-development';
5
5
  export { createNxtlinqApi, useLocalStorage, useSessionStorage, useSpeechToTextFromMic, useVoiceMode, metakeepClient, getEthers, sleep, walletTextUtils, } from '@bytexbyte/nxtlinq-ai-agent-web-development';
@@ -0,0 +1,53 @@
1
+ import type { AIT, RuntimeAITResult } from '@bytexbyte/nxtlinq-ai-agent-core-development';
2
+ import * as React from 'react';
3
+ export declare function commitProviderRuntime<T, E>(identityRef: React.MutableRefObject<T>, identity: T, environment: E, publishEnvironment: (environment: E) => void): void;
4
+ export declare function useProviderRuntimeCommit<T, E>(identityRef: React.MutableRefObject<T>, identity: T, environment: E, publishEnvironment: (environment: E) => void): void;
5
+ export declare function replaceCurrentMaximumDenyList(persistedDeniedPermissions: readonly string[], maximumPermissions: readonly string[], checkedPermissions: readonly string[]): string[];
6
+ export declare function removeOneDeniedPermission(persistedDeniedPermissions: readonly string[], permission: string): string[];
7
+ export type RuntimeAITContext = {
8
+ controller: string;
9
+ serviceId: string;
10
+ roles?: string[];
11
+ permissionGroup?: string;
12
+ };
13
+ export declare function runtimeAITContextKey(context: RuntimeAITContext): string;
14
+ export declare function runtimeAITSubjectKey(context: RuntimeAITContext): string;
15
+ export declare function runtimeAuthorizationMatchesContext(authorizationContextKey: string | null, renderedContext: RuntimeAITContext | null): boolean;
16
+ export declare class StaleRuntimeAITResponseError extends Error {
17
+ constructor();
18
+ }
19
+ /**
20
+ * Owns the authoritative recompute lifecycle. Only the newest request for the
21
+ * active captured context may write state; its failures clear state first.
22
+ */
23
+ export declare class RuntimeAITRecomputeCoordinator {
24
+ private activeContextKey;
25
+ private activeContext;
26
+ private generation;
27
+ commitContext(context: RuntimeAITContext | null, invalidate: () => void): boolean;
28
+ getActiveContext(): RuntimeAITContext | null;
29
+ isContextActive(context: RuntimeAITContext): boolean;
30
+ assertContextActive(context: RuntimeAITContext): void;
31
+ run<T>(context: RuntimeAITContext, request: () => Promise<T>, apply: (result: T, context: RuntimeAITContext) => void, clear: () => void): Promise<T>;
32
+ }
33
+ export declare function useRuntimeAITContextCommit(coordinator: RuntimeAITRecomputeCoordinator, context: RuntimeAITContext | null, invalidate: () => void): void;
34
+ export declare function dispatchRuntimeAITCompleteReplacement(coordinator: RuntimeAITRecomputeCoordinator, context: RuntimeAITContext, update: () => Promise<unknown>, converge: (subjectKey: string) => Promise<void>, clear: () => void): Promise<void>;
35
+ /** Serializes reads, complete replacements, and convergence for one persistence subject. */
36
+ export declare class RuntimeAITMutationQueue {
37
+ private readonly tails;
38
+ run<T>(subjectKey: string, mutation: () => Promise<T>): Promise<T>;
39
+ }
40
+ export type RuntimeAuthorizationState = {
41
+ ait: AIT | null;
42
+ maximumPermissions: string[];
43
+ effectivePermissions: string[];
44
+ deniedPermissions: string[];
45
+ selectedRuleId: string | null;
46
+ selectedRuleType: RuntimeAITResult['selectedRuleType'];
47
+ expiresAt: string | null;
48
+ grantActive: boolean;
49
+ unavailable: boolean;
50
+ };
51
+ export declare function runtimeAuthorizationState(result: RuntimeAITResult, controller: string, serviceId: string): RuntimeAuthorizationState;
52
+ export declare function unavailableRuntimeAuthorization(persistedDeniedPermissions: readonly string[]): RuntimeAuthorizationState;
53
+ //# sourceMappingURL=permissionState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissionState.d.ts","sourceRoot":"","sources":["../src/permissionState.ts"],"names":[],"mappings":"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"}