@bytexbyte/nxtlinq-ai-agent-sdk 1.4.4 → 1.4.6
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/dist/components/context/ChatBotContext.d.ts.map +1 -1
- package/dist/components/context/ChatBotContext.js +79 -45
- package/dist/components/types/ChatBotTypes.d.ts +1 -1
- package/dist/components/types/ChatBotTypes.d.ts.map +1 -1
- package/dist/components/ui/ChatBotUI.d.ts.map +1 -1
- package/dist/components/ui/ChatBotUI.js +7 -1
- package/dist/components/ui/MessageList.d.ts.map +1 -1
- package/dist/components/ui/MessageList.js +21 -8
- package/dist/components/ui/PermissionForm.d.ts.map +1 -1
- package/dist/components/ui/PermissionForm.js +35 -8
- package/dist/core/utils/__tests__/urlUtils.test.d.ts +5 -0
- package/dist/core/utils/__tests__/urlUtils.test.d.ts.map +1 -0
- package/dist/core/utils/__tests__/urlUtils.test.js +57 -0
- package/dist/core/utils/urlUtils.d.ts +23 -0
- package/dist/core/utils/urlUtils.d.ts.map +1 -0
- package/dist/core/utils/urlUtils.js +72 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/setupTests.d.ts +2 -0
- package/dist/setupTests.d.ts.map +1 -0
- package/dist/setupTests.js +16 -0
- package/package.json +1 -1
- package/umd/nxtlinq-ai-agent.umd.js +19 -19
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatBotContext.d.ts","sourceRoot":"","sources":["../../../src/components/context/ChatBotContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B,OAAO,EACL,kBAAkB,EAClB,YAAY,EAGb,MAAM,uBAAuB,CAAC;AAI/B,eAAO,MAAM,UAAU,0BAMtB,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"ChatBotContext.d.ts","sourceRoot":"","sources":["../../../src/components/context/ChatBotContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B,OAAO,EACL,kBAAkB,EAClB,YAAY,EAGb,MAAM,uBAAuB,CAAC;AAI/B,eAAO,MAAM,UAAU,0BAMtB,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAutDlD,CAAC"}
|
|
@@ -254,6 +254,9 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
254
254
|
localStorage.setItem('walletAddress', userAddress);
|
|
255
255
|
setHitAddress(userAddress);
|
|
256
256
|
setSigner(userSigner);
|
|
257
|
+
// Immediately update refs to ensure they're available for subsequent operations
|
|
258
|
+
hitAddressRef.current = userAddress;
|
|
259
|
+
signerRef.current = userSigner;
|
|
257
260
|
// Check if we have a valid token before trying to load AIT
|
|
258
261
|
if (nxtlinqAITServiceAccessToken) {
|
|
259
262
|
try {
|
|
@@ -882,36 +885,22 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
882
885
|
}
|
|
883
886
|
}
|
|
884
887
|
else if (errorResponse.requiresPermissionUpdate) {
|
|
885
|
-
// Case where permission update is required -
|
|
886
|
-
console.log('API requires permission update,
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
setMessages(prev => [...prev, {
|
|
902
|
-
id: Date.now().toString(),
|
|
903
|
-
content: errorResponse.message,
|
|
904
|
-
role: 'assistant',
|
|
905
|
-
timestamp: new Date().toISOString(),
|
|
906
|
-
button: 'enableAIT',
|
|
907
|
-
metadata: {
|
|
908
|
-
requiresPermissionUpdate: true,
|
|
909
|
-
toolName: errorResponse.toolName,
|
|
910
|
-
requiredPermission: errorResponse.requiredPermission
|
|
911
|
-
}
|
|
912
|
-
}]);
|
|
913
|
-
return;
|
|
914
|
-
}
|
|
888
|
+
// Case where permission update is required - show manual enable option
|
|
889
|
+
console.log('API requires permission update, showing manual enable option...');
|
|
890
|
+
setIsLoading(false);
|
|
891
|
+
setMessages(prev => [...prev, {
|
|
892
|
+
id: Date.now().toString(),
|
|
893
|
+
content: errorResponse.message,
|
|
894
|
+
role: 'assistant',
|
|
895
|
+
timestamp: new Date().toISOString(),
|
|
896
|
+
button: 'enableAIT',
|
|
897
|
+
metadata: {
|
|
898
|
+
requiresPermissionUpdate: true,
|
|
899
|
+
toolName: errorResponse.toolName,
|
|
900
|
+
requiredPermission: errorResponse.requiredPermission
|
|
901
|
+
}
|
|
902
|
+
}]);
|
|
903
|
+
return;
|
|
915
904
|
}
|
|
916
905
|
else {
|
|
917
906
|
// Other errors
|
|
@@ -1181,16 +1170,25 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
1181
1170
|
if (!signer || !hitAddress) {
|
|
1182
1171
|
throw new Error('Missing signer or wallet address');
|
|
1183
1172
|
}
|
|
1173
|
+
return generateAndRegisterAITWithSigner(newPermissions, isFromAIAgent, signer, hitAddress);
|
|
1174
|
+
};
|
|
1175
|
+
// Generate and register AIT with explicit signer and address
|
|
1176
|
+
const generateAndRegisterAITWithSigner = async (newPermissions, isFromAIAgent = false, explicitSigner, explicitAddress) => {
|
|
1177
|
+
const currentSigner = explicitSigner || signer;
|
|
1178
|
+
const currentAddress = explicitAddress || hitAddress;
|
|
1179
|
+
if (!currentSigner || !currentAddress) {
|
|
1180
|
+
throw new Error('Missing signer or wallet address');
|
|
1181
|
+
}
|
|
1184
1182
|
// If AI Agent is creating, must check if user has existing AIT
|
|
1185
|
-
if (isFromAIAgent && !
|
|
1183
|
+
if (isFromAIAgent && !aitRef.current) {
|
|
1186
1184
|
throw new Error('You must have an existing AIT before AI Agent can create new AITs');
|
|
1187
1185
|
}
|
|
1188
1186
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
1189
|
-
const aitId = `did:polygon:nxtlinq:${
|
|
1187
|
+
const aitId = `did:polygon:nxtlinq:${currentAddress}:${timestamp}`;
|
|
1190
1188
|
const metadata = {
|
|
1191
1189
|
model: 'gpt-4',
|
|
1192
1190
|
permissions: newPermissions || permissions,
|
|
1193
|
-
issuedBy:
|
|
1191
|
+
issuedBy: currentAddress,
|
|
1194
1192
|
};
|
|
1195
1193
|
const metadataStr = stringify(metadata);
|
|
1196
1194
|
const metadataHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(metadataStr));
|
|
@@ -1201,12 +1199,12 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
1201
1199
|
const { metadataCid } = uploadResponse;
|
|
1202
1200
|
const createAITParams = {
|
|
1203
1201
|
aitId,
|
|
1204
|
-
controller:
|
|
1202
|
+
controller: currentAddress,
|
|
1205
1203
|
serviceId,
|
|
1206
1204
|
metadataHash,
|
|
1207
1205
|
metadataCid,
|
|
1208
1206
|
isFromAIAgent: isFromAIAgent,
|
|
1209
|
-
parentAITId: isFromAIAgent ?
|
|
1207
|
+
parentAITId: isFromAIAgent ? aitRef.current?.aitId : undefined,
|
|
1210
1208
|
};
|
|
1211
1209
|
console.log('createAIT params:', createAITParams);
|
|
1212
1210
|
const createAITResponse = await nxtlinqApi.ait.createAIT(createAITParams, nxtlinqAITServiceAccessToken || '');
|
|
@@ -1215,7 +1213,7 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
1215
1213
|
}
|
|
1216
1214
|
const aitInfo = {
|
|
1217
1215
|
aitId,
|
|
1218
|
-
controller:
|
|
1216
|
+
controller: currentAddress,
|
|
1219
1217
|
metadata,
|
|
1220
1218
|
metadataHash,
|
|
1221
1219
|
metadataCid,
|
|
@@ -1224,23 +1222,30 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
1224
1222
|
setPermissions(permissions);
|
|
1225
1223
|
};
|
|
1226
1224
|
// Auto enable AIT permission
|
|
1227
|
-
const
|
|
1225
|
+
const enableAIT = async (toolName) => {
|
|
1228
1226
|
if (isAITEnabling)
|
|
1229
1227
|
return false; // Prevent duplicate
|
|
1230
1228
|
setIsAITEnabling(true);
|
|
1231
|
-
console.log('
|
|
1229
|
+
console.log('enableAIT called with toolName:', toolName, 'existing AIT:', !!aitRef.current);
|
|
1230
|
+
let currentSigner = signer;
|
|
1231
|
+
let currentHitAddress = hitAddress;
|
|
1232
1232
|
// If no wallet connected, try to auto-connect first
|
|
1233
|
-
if (!
|
|
1233
|
+
if (!currentSigner || !currentHitAddress) {
|
|
1234
1234
|
console.log('No wallet connected, attempting auto-connect...');
|
|
1235
1235
|
const autoConnectResult = await connectWallet(false); // Don't show sign-in message yet
|
|
1236
1236
|
if (autoConnectResult) {
|
|
1237
1237
|
console.log('Auto-connect successful, waiting for state update...');
|
|
1238
1238
|
// Wait for state to update - increase wait time
|
|
1239
|
-
await new Promise(resolve => setTimeout(resolve,
|
|
1239
|
+
await new Promise(resolve => setTimeout(resolve, 1500));
|
|
1240
|
+
// Get the latest state values after connection
|
|
1241
|
+
currentSigner = signerRef.current || signer;
|
|
1242
|
+
currentHitAddress = hitAddressRef.current || hitAddress;
|
|
1240
1243
|
// Double check that we have the required state
|
|
1241
|
-
if (!
|
|
1244
|
+
if (!currentSigner || !currentHitAddress) {
|
|
1242
1245
|
console.log('State not updated yet, waiting more...');
|
|
1243
|
-
await new Promise(resolve => setTimeout(resolve,
|
|
1246
|
+
await new Promise(resolve => setTimeout(resolve, 1500));
|
|
1247
|
+
currentSigner = signerRef.current || signer;
|
|
1248
|
+
currentHitAddress = hitAddressRef.current || hitAddress;
|
|
1244
1249
|
}
|
|
1245
1250
|
console.log('Trying to sign in...');
|
|
1246
1251
|
try {
|
|
@@ -1261,6 +1266,32 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
1261
1266
|
return false;
|
|
1262
1267
|
}
|
|
1263
1268
|
}
|
|
1269
|
+
// Final check before proceeding
|
|
1270
|
+
if (!currentSigner || !currentHitAddress) {
|
|
1271
|
+
console.error('Missing signer or wallet address after connection process');
|
|
1272
|
+
console.error('Current signer:', !!currentSigner);
|
|
1273
|
+
console.error('Current hitAddress:', currentHitAddress);
|
|
1274
|
+
console.error('Signer ref:', !!signerRef.current);
|
|
1275
|
+
console.error('HitAddress ref:', hitAddressRef.current);
|
|
1276
|
+
showError('Wallet connection failed. Please try connecting your wallet manually.');
|
|
1277
|
+
setIsAITEnabling(false);
|
|
1278
|
+
return false;
|
|
1279
|
+
}
|
|
1280
|
+
console.log('Proceeding with AIT creation - Signer:', !!currentSigner, 'Address:', currentHitAddress);
|
|
1281
|
+
// If we don't have AIT loaded but we have a token, try to refresh it first
|
|
1282
|
+
if (!aitRef.current && nxtlinqAITServiceAccessToken) {
|
|
1283
|
+
console.log('No AIT loaded but have token, attempting to refresh AIT...');
|
|
1284
|
+
try {
|
|
1285
|
+
await refreshAIT();
|
|
1286
|
+
// Wait a bit for AIT to be loaded
|
|
1287
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
1288
|
+
console.log('AIT refresh completed, current AIT:', !!aitRef.current);
|
|
1289
|
+
}
|
|
1290
|
+
catch (error) {
|
|
1291
|
+
console.log('Failed to refresh AIT:', error);
|
|
1292
|
+
// Continue anyway, we'll create a new AIT if needed
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1264
1295
|
try {
|
|
1265
1296
|
// Get available permissions to find the tool
|
|
1266
1297
|
const availablePermissionLabels = availablePermissions.map(p => p.label);
|
|
@@ -1274,8 +1305,11 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
1274
1305
|
if (!newPermissions.includes(toolName)) {
|
|
1275
1306
|
newPermissions.push(toolName);
|
|
1276
1307
|
}
|
|
1277
|
-
// Generate and register AIT with new permissions
|
|
1278
|
-
|
|
1308
|
+
// Generate and register AIT with new permissions
|
|
1309
|
+
// For auto-enable, we should create a regular AIT (not AI Agent AIT) if user doesn't have existing AIT
|
|
1310
|
+
const shouldCreateAsAIAgent = !!aitRef.current; // Only create as AI Agent if user already has an AIT
|
|
1311
|
+
console.log('Creating AIT - isFromAIAgent:', shouldCreateAsAIAgent, 'existing AIT:', !!aitRef.current);
|
|
1312
|
+
await generateAndRegisterAITWithSigner(newPermissions, shouldCreateAsAIAgent, currentSigner, currentHitAddress);
|
|
1279
1313
|
showSuccess('AIT permission enabled successfully! You can now use the AI agent.');
|
|
1280
1314
|
await refreshAIT(true);
|
|
1281
1315
|
setIsAITEnabling(false);
|
|
@@ -1536,7 +1570,7 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
1536
1570
|
handleSubmit,
|
|
1537
1571
|
handlePresetMessage,
|
|
1538
1572
|
savePermissions,
|
|
1539
|
-
|
|
1573
|
+
enableAIT,
|
|
1540
1574
|
handleVerifyWalletClick,
|
|
1541
1575
|
showSuccess,
|
|
1542
1576
|
showError,
|
|
@@ -102,7 +102,7 @@ export interface ChatBotContextType {
|
|
|
102
102
|
handleSubmit: (e: React.FormEvent) => Promise<void>;
|
|
103
103
|
handlePresetMessage: (message: PresetMessage) => void;
|
|
104
104
|
savePermissions: (newPermissions?: string[]) => Promise<void>;
|
|
105
|
-
|
|
105
|
+
enableAIT: (toolName: string) => Promise<boolean>;
|
|
106
106
|
handleVerifyWalletClick: () => Promise<void>;
|
|
107
107
|
showSuccess: (message: string) => void;
|
|
108
108
|
showError: (message: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatBotTypes.d.ts","sourceRoot":"","sources":["../../../src/components/types/ChatBotTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBA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AE,MAAM,KAAK,IAAI,CAAC;IACvC,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,UAAU,EAAE,CAAC,sBAAsB,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,aAAa,EAAE,MAAM,IAAI,CAAC;IAE1B,iBAAiB,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,eAAe,EAAE,MAAM,OAAO,CAAC;IAG/B,MAAM,EAAE,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,eAAe,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,KAAK,GAAG,SAAS,CAAC,CAAC;IAC3D,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,sBAAsB,EAAE,OAAO,CAAC;IAChC,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IAGzB,KAAK,EAAE,YAAY,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatBotUI.d.ts","sourceRoot":"","sources":["../../../src/components/ui/ChatBotUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAqG/B,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"ChatBotUI.d.ts","sourceRoot":"","sources":["../../../src/components/ui/ChatBotUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAqG/B,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EA4P7B,CAAC"}
|
|
@@ -207,6 +207,12 @@ export const ChatBotUI = () => {
|
|
|
207
207
|
display: 'flex',
|
|
208
208
|
alignItems: 'center',
|
|
209
209
|
justifyContent: 'center',
|
|
210
|
-
zIndex: 1002
|
|
210
|
+
zIndex: 1002,
|
|
211
|
+
padding: '20px'
|
|
212
|
+
}, onClick: (e) => {
|
|
213
|
+
// Close modal when clicking on background
|
|
214
|
+
if (e.target === e.currentTarget) {
|
|
215
|
+
setShowPermissionForm(false);
|
|
216
|
+
}
|
|
211
217
|
}, children: _jsx(PermissionForm, { onClose: () => setShowPermissionForm(false), onOpen: () => setShowPermissionForm(true) }) })), notification.show && (_jsx(ToastNotification, { type: notification.type, message: notification.message, onClose: handleCloseNotification, isChatOpen: isOpen }))] }));
|
|
212
218
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageList.d.ts","sourceRoot":"","sources":["../../../src/components/ui/MessageList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"MessageList.d.ts","sourceRoot":"","sources":["../../../src/components/ui/MessageList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EA+L/B,CAAC"}
|
|
@@ -2,8 +2,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useChatBot } from '../context/ChatBotContext';
|
|
4
4
|
import { AI_MODEL_MAP } from '../types/ChatBotTypes';
|
|
5
|
+
import { convertUrlsToLinks } from '../../core/utils/urlUtils';
|
|
5
6
|
export const MessageList = () => {
|
|
6
|
-
const { messages, isLoading, connectWallet, signInWallet, hitAddress, ait, setShowPermissionForm, isWalletLoading, isAutoConnecting, isNeedSignInWithWallet,
|
|
7
|
+
const { messages, isLoading, connectWallet, signInWallet, hitAddress, ait, setShowPermissionForm, isWalletLoading, isAutoConnecting, isNeedSignInWithWallet, enableAIT, isAITLoading, isAITEnabling, sendMessage, permissions } = useChatBot();
|
|
7
8
|
const messagesEndRef = React.useRef(null);
|
|
8
9
|
const scrollToBottom = () => {
|
|
9
10
|
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
|
|
@@ -21,7 +22,7 @@ export const MessageList = () => {
|
|
|
21
22
|
else if (buttonType === 'enableAIT') {
|
|
22
23
|
const toolName = message.metadata?.toolName;
|
|
23
24
|
if (toolName) {
|
|
24
|
-
const success = await
|
|
25
|
+
const success = await enableAIT(toolName);
|
|
25
26
|
if (success) {
|
|
26
27
|
// Find the last user message
|
|
27
28
|
const lastUserMsg = [...messages].reverse().find(m => m.role === 'user');
|
|
@@ -59,32 +60,44 @@ export const MessageList = () => {
|
|
|
59
60
|
wordWrap: 'break-word',
|
|
60
61
|
position: 'relative',
|
|
61
62
|
border: message.metadata?.isRetry ? '1px solid #ffeaa7' : 'none'
|
|
62
|
-
}, children: [message.metadata?.isRetry && (_jsx("span", { style: { marginRight: '8px', fontSize: '14px' }, children: "\uD83D\uDD04" })), message.content, message.button && (_jsx("div", { style: { marginTop: '10px' }, children: _jsx("button", { onClick: () =>
|
|
63
|
+
}, children: [message.metadata?.isRetry && (_jsx("span", { style: { marginRight: '8px', fontSize: '14px' }, children: "\uD83D\uDD04" })), message.role === 'assistant' ? convertUrlsToLinks(message.content) : message.content, message.button && (_jsx("div", { style: { marginTop: '10px' }, children: _jsx("button", { onClick: () => {
|
|
64
|
+
if (message.button && message.button.trim()) {
|
|
65
|
+
handleButtonClick(message.button, message);
|
|
66
|
+
}
|
|
67
|
+
}, disabled: isAutoConnecting ||
|
|
63
68
|
(message.button === 'connectWallet' && Boolean(hitAddress)) ||
|
|
64
69
|
(message.button === 'signIn' && !isNeedSignInWithWallet) ||
|
|
65
|
-
(message.button === 'enableAIT' && (isAITLoading || isAITEnabling
|
|
70
|
+
(message.button === 'enableAIT' && (isAITLoading || isAITEnabling ||
|
|
71
|
+
(message.metadata?.toolName && permissions.includes(message.metadata.toolName)))) || false, style: {
|
|
66
72
|
padding: '8px 16px',
|
|
67
73
|
backgroundColor: message.role === 'user' ? 'rgba(255, 255, 255, 0.2)' :
|
|
68
74
|
isAutoConnecting ? '#6c757d' :
|
|
69
75
|
(message.button === 'connectWallet' && Boolean(hitAddress)) ? '#28a745' :
|
|
70
76
|
(message.button === 'signIn' && !isNeedSignInWithWallet) ? '#28a745' :
|
|
71
|
-
(message.button === 'enableAIT' && (isAITLoading || isAITEnabling
|
|
77
|
+
(message.button === 'enableAIT' && (isAITLoading || isAITEnabling ||
|
|
78
|
+
(message.metadata?.toolName && permissions.includes(message.metadata.toolName)))) ?
|
|
79
|
+
((message.metadata?.toolName && permissions.includes(message.metadata.toolName)) ? '#28a745' : '#6c757d') : '#007bff',
|
|
72
80
|
color: message.role === 'user' ? 'white' : 'white',
|
|
73
81
|
border: 'none',
|
|
74
82
|
borderRadius: '5px',
|
|
75
83
|
cursor: (isAutoConnecting ||
|
|
76
84
|
(message.button === 'connectWallet' && Boolean(hitAddress)) ||
|
|
77
85
|
(message.button === 'signIn' && !isNeedSignInWithWallet) ||
|
|
78
|
-
(message.button === 'enableAIT' && (isAITLoading || isAITEnabling
|
|
86
|
+
(message.button === 'enableAIT' && (isAITLoading || isAITEnabling ||
|
|
87
|
+
(message.metadata?.toolName && permissions.includes(message.metadata.toolName))))) ? 'not-allowed' : 'pointer',
|
|
79
88
|
fontSize: '14px',
|
|
80
89
|
opacity: (isAutoConnecting ||
|
|
81
90
|
(message.button === 'connectWallet' && Boolean(hitAddress)) ||
|
|
82
91
|
(message.button === 'signIn' && !isNeedSignInWithWallet) ||
|
|
83
|
-
(message.button === 'enableAIT' && (isAITLoading || isAITEnabling
|
|
92
|
+
(message.button === 'enableAIT' && (isAITLoading || isAITEnabling ||
|
|
93
|
+
(message.metadata?.toolName && permissions.includes(message.metadata.toolName))))) ? 0.8 : 1
|
|
84
94
|
}, children: isAutoConnecting ? 'Connecting...' :
|
|
85
95
|
message.button === 'connectWallet' ? (Boolean(hitAddress) ? 'Connected' : 'Connect Wallet') :
|
|
86
96
|
message.button === 'signIn' ? (!isNeedSignInWithWallet ? 'Signed In' : 'Sign In') :
|
|
87
|
-
message.button === 'enableAIT' ?
|
|
97
|
+
message.button === 'enableAIT' ?
|
|
98
|
+
((isAITLoading || isAITEnabling) ? 'Enabling...' :
|
|
99
|
+
(message.metadata?.toolName && permissions.includes(message.metadata.toolName)) ? 'AIT Enabled' : 'Enable AIT Permissions') :
|
|
100
|
+
message.button }) }))] }), message.role === 'assistant' && message.metadata?.model && (_jsx("div", { style: {
|
|
88
101
|
display: 'flex',
|
|
89
102
|
alignItems: 'center',
|
|
90
103
|
marginTop: '4px',
|
|
@@ -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,
|
|
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,CAgiBxD,CAAC"}
|
|
@@ -133,7 +133,11 @@ export const PermissionForm = ({ onClose, onOpen }) => {
|
|
|
133
133
|
borderRadius: '12px',
|
|
134
134
|
width: '480px',
|
|
135
135
|
maxWidth: '90%',
|
|
136
|
-
|
|
136
|
+
maxHeight: '90vh',
|
|
137
|
+
boxShadow: '0 4px 12px rgba(0, 0, 0, 0.1)',
|
|
138
|
+
display: 'flex',
|
|
139
|
+
flexDirection: 'column',
|
|
140
|
+
overflow: 'hidden'
|
|
137
141
|
}, children: [_jsxs("div", { style: {
|
|
138
142
|
display: 'flex',
|
|
139
143
|
justifyContent: 'space-between',
|
|
@@ -150,11 +154,21 @@ export const PermissionForm = ({ onClose, onOpen }) => {
|
|
|
150
154
|
fontSize: '24px',
|
|
151
155
|
cursor: 'pointer',
|
|
152
156
|
color: '#666',
|
|
153
|
-
padding: '
|
|
157
|
+
padding: '8px',
|
|
154
158
|
display: 'flex',
|
|
155
159
|
alignItems: 'center',
|
|
156
|
-
justifyContent: 'center'
|
|
157
|
-
|
|
160
|
+
justifyContent: 'center',
|
|
161
|
+
borderRadius: '4px',
|
|
162
|
+
transition: 'background-color 0.2s',
|
|
163
|
+
minWidth: '32px',
|
|
164
|
+
minHeight: '32px'
|
|
165
|
+
}, onMouseOver: (e) => {
|
|
166
|
+
e.currentTarget.style.backgroundColor = '#f0f0f0';
|
|
167
|
+
e.currentTarget.style.color = '#333';
|
|
168
|
+
}, onMouseOut: (e) => {
|
|
169
|
+
e.currentTarget.style.backgroundColor = 'transparent';
|
|
170
|
+
e.currentTarget.style.color = '#666';
|
|
171
|
+
}, title: "Close", children: "\u00D7" })] }), !hitAddress ? (_jsxs("div", { style: { textAlign: 'center', padding: '32px 0' }, children: [_jsx("div", { style: {
|
|
158
172
|
width: '64px',
|
|
159
173
|
height: '64px',
|
|
160
174
|
margin: '0 auto 16px',
|
|
@@ -259,10 +273,17 @@ export const PermissionForm = ({ onClose, onOpen }) => {
|
|
|
259
273
|
fontSize: '14px',
|
|
260
274
|
color: '#333',
|
|
261
275
|
border: '1px solid #e9ecef'
|
|
262
|
-
}, children: hitAddress })] }), _jsxs("div", { style: {
|
|
276
|
+
}, children: hitAddress })] }), _jsxs("div", { style: {
|
|
277
|
+
marginBottom: '24px',
|
|
278
|
+
flex: 1,
|
|
279
|
+
display: 'flex',
|
|
280
|
+
flexDirection: 'column',
|
|
281
|
+
minHeight: 0
|
|
282
|
+
}, children: [_jsx("h4", { style: {
|
|
263
283
|
marginBottom: '12px',
|
|
264
284
|
fontSize: '16px',
|
|
265
|
-
color: '#666'
|
|
285
|
+
color: '#666',
|
|
286
|
+
flexShrink: 0
|
|
266
287
|
}, children: "Permissions" }), isAITLoading ? (_jsx("div", { style: {
|
|
267
288
|
backgroundColor: '#f8f9fa',
|
|
268
289
|
padding: '16px',
|
|
@@ -274,7 +295,11 @@ export const PermissionForm = ({ onClose, onOpen }) => {
|
|
|
274
295
|
backgroundColor: '#f8f9fa',
|
|
275
296
|
padding: '16px',
|
|
276
297
|
borderRadius: '8px',
|
|
277
|
-
border: '1px solid #e9ecef'
|
|
298
|
+
border: '1px solid #e9ecef',
|
|
299
|
+
flex: 1,
|
|
300
|
+
overflowY: 'auto',
|
|
301
|
+
overflowX: 'hidden',
|
|
302
|
+
minHeight: 0
|
|
278
303
|
}, children: availablePermissions.map((permission) => (_jsx("div", { style: { marginBottom: '12px' }, children: _jsxs("label", { style: {
|
|
279
304
|
display: 'flex',
|
|
280
305
|
alignItems: 'center',
|
|
@@ -313,7 +338,9 @@ export const PermissionForm = ({ onClose, onOpen }) => {
|
|
|
313
338
|
justifyContent: 'flex-end',
|
|
314
339
|
gap: '12px',
|
|
315
340
|
borderTop: '1px solid #e9ecef',
|
|
316
|
-
paddingTop: '24px'
|
|
341
|
+
paddingTop: '24px',
|
|
342
|
+
flexShrink: 0,
|
|
343
|
+
marginTop: 'auto'
|
|
317
344
|
}, children: [_jsx("button", { onClick: handleCancel, style: {
|
|
318
345
|
padding: '10px 20px',
|
|
319
346
|
backgroundColor: '#f8f9fa',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlUtils.test.d.ts","sourceRoot":"","sources":["../../../../src/core/utils/__tests__/urlUtils.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for URL utility functions
|
|
3
|
+
*/
|
|
4
|
+
import { containsUrls, convertUrlsToLinks, convertUrlsToHtml } from '../urlUtils';
|
|
5
|
+
describe('URL Utils', () => {
|
|
6
|
+
describe('containsUrls', () => {
|
|
7
|
+
it('should detect URLs with http protocol', () => {
|
|
8
|
+
expect(containsUrls('Visit https://example.com for more info')).toBe(true);
|
|
9
|
+
expect(containsUrls('Check out http://test.org')).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
it('should detect URLs with www', () => {
|
|
12
|
+
expect(containsUrls('Go to www.google.com')).toBe(true);
|
|
13
|
+
expect(containsUrls('Visit www.example.org')).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
it('should detect domain names', () => {
|
|
16
|
+
expect(containsUrls('Contact us at support@company.com')).toBe(false);
|
|
17
|
+
expect(containsUrls('Visit company.com for details')).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
it('should return false for text without URLs', () => {
|
|
20
|
+
expect(containsUrls('This is just plain text')).toBe(false);
|
|
21
|
+
expect(containsUrls('No URLs here')).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe('convertUrlsToHtml', () => {
|
|
25
|
+
it('should convert URLs to HTML anchor tags', () => {
|
|
26
|
+
const text = 'Visit https://example.com for more info';
|
|
27
|
+
const result = convertUrlsToHtml(text);
|
|
28
|
+
expect(result).toContain('<a href="https://example.com"');
|
|
29
|
+
expect(result).toContain('target="_blank"');
|
|
30
|
+
expect(result).toContain('rel="noopener noreferrer"');
|
|
31
|
+
});
|
|
32
|
+
it('should handle www URLs', () => {
|
|
33
|
+
const text = 'Go to www.google.com';
|
|
34
|
+
const result = convertUrlsToHtml(text);
|
|
35
|
+
expect(result).toContain('<a href="https://www.google.com"');
|
|
36
|
+
});
|
|
37
|
+
it('should handle multiple URLs', () => {
|
|
38
|
+
const text = 'Visit https://example.com and www.google.com';
|
|
39
|
+
const result = convertUrlsToHtml(text);
|
|
40
|
+
expect(result).toContain('https://example.com');
|
|
41
|
+
expect(result).toContain('https://www.google.com');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
describe('convertUrlsToLinks', () => {
|
|
45
|
+
it('should return array with mixed content', () => {
|
|
46
|
+
const text = 'Visit https://example.com for more info';
|
|
47
|
+
const result = convertUrlsToLinks(text);
|
|
48
|
+
expect(Array.isArray(result)).toBe(true);
|
|
49
|
+
expect(result.length).toBeGreaterThan(0);
|
|
50
|
+
});
|
|
51
|
+
it('should handle text without URLs', () => {
|
|
52
|
+
const text = 'This is just plain text';
|
|
53
|
+
const result = convertUrlsToLinks(text);
|
|
54
|
+
expect(result).toEqual([text]);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL utility functions for detecting and converting URLs to clickable links
|
|
3
|
+
*/
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
/**
|
|
6
|
+
* Check if a string contains URLs
|
|
7
|
+
* @param text - The text to check
|
|
8
|
+
* @returns boolean indicating if URLs are found
|
|
9
|
+
*/
|
|
10
|
+
export declare const containsUrls: (text: string) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Convert text with URLs to JSX elements with clickable links
|
|
13
|
+
* @param text - The text containing URLs
|
|
14
|
+
* @returns Array of JSX elements and strings
|
|
15
|
+
*/
|
|
16
|
+
export declare const convertUrlsToLinks: (text: string) => (string | React.ReactElement)[];
|
|
17
|
+
/**
|
|
18
|
+
* Simple function to wrap URLs in anchor tags for basic HTML rendering
|
|
19
|
+
* @param text - The text containing URLs
|
|
20
|
+
* @returns HTML string with clickable links
|
|
21
|
+
*/
|
|
22
|
+
export declare const convertUrlsToHtml: (text: string) => string;
|
|
23
|
+
//# sourceMappingURL=urlUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlUtils.d.ts","sourceRoot":"","sources":["../../../src/core/utils/urlUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,KAAG,OAE3C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,CAAC,MAAM,GAAG,KAAK,CAAC,YAAY,CAAC,EA+C9E,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG,MAKhD,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL utility functions for detecting and converting URLs to clickable links
|
|
3
|
+
*/
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
/**
|
|
6
|
+
* Regular expression to match URLs
|
|
7
|
+
* Supports http, https, ftp, and www protocols
|
|
8
|
+
*/
|
|
9
|
+
const URL_REGEX = /(https?:\/\/[^\s]+|www\.[^\s]+|[a-zA-Z0-9-]+\.[a-zA-Z]{2,}(?:\/[^\s]*)?)/g;
|
|
10
|
+
/**
|
|
11
|
+
* Check if a string contains URLs
|
|
12
|
+
* @param text - The text to check
|
|
13
|
+
* @returns boolean indicating if URLs are found
|
|
14
|
+
*/
|
|
15
|
+
export const containsUrls = (text) => {
|
|
16
|
+
return URL_REGEX.test(text);
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Convert text with URLs to JSX elements with clickable links
|
|
20
|
+
* @param text - The text containing URLs
|
|
21
|
+
* @returns Array of JSX elements and strings
|
|
22
|
+
*/
|
|
23
|
+
export const convertUrlsToLinks = (text) => {
|
|
24
|
+
const parts = [];
|
|
25
|
+
let lastIndex = 0;
|
|
26
|
+
let match;
|
|
27
|
+
// Reset regex lastIndex
|
|
28
|
+
URL_REGEX.lastIndex = 0;
|
|
29
|
+
while ((match = URL_REGEX.exec(text)) !== null) {
|
|
30
|
+
const url = match[0];
|
|
31
|
+
const startIndex = match.index;
|
|
32
|
+
// Add text before the URL
|
|
33
|
+
if (startIndex > lastIndex) {
|
|
34
|
+
parts.push(text.slice(lastIndex, startIndex));
|
|
35
|
+
}
|
|
36
|
+
// Create clickable link
|
|
37
|
+
const href = url.startsWith('http') ? url : `https://${url}`;
|
|
38
|
+
parts.push(React.createElement('a', {
|
|
39
|
+
key: startIndex,
|
|
40
|
+
href: href,
|
|
41
|
+
target: '_blank',
|
|
42
|
+
rel: 'noopener noreferrer',
|
|
43
|
+
style: {
|
|
44
|
+
color: '#007bff',
|
|
45
|
+
textDecoration: 'underline',
|
|
46
|
+
cursor: 'pointer'
|
|
47
|
+
},
|
|
48
|
+
onClick: (e) => {
|
|
49
|
+
e.preventDefault(); // Prevent default browser behavior
|
|
50
|
+
e.stopPropagation();
|
|
51
|
+
window.open(href, '_blank', 'noopener,noreferrer');
|
|
52
|
+
}
|
|
53
|
+
}, url));
|
|
54
|
+
lastIndex = startIndex + url.length;
|
|
55
|
+
}
|
|
56
|
+
// Add remaining text after the last URL
|
|
57
|
+
if (lastIndex < text.length) {
|
|
58
|
+
parts.push(text.slice(lastIndex));
|
|
59
|
+
}
|
|
60
|
+
return parts.length > 0 ? parts : [text];
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Simple function to wrap URLs in anchor tags for basic HTML rendering
|
|
64
|
+
* @param text - The text containing URLs
|
|
65
|
+
* @returns HTML string with clickable links
|
|
66
|
+
*/
|
|
67
|
+
export const convertUrlsToHtml = (text) => {
|
|
68
|
+
return text.replace(URL_REGEX, (url) => {
|
|
69
|
+
const href = url.startsWith('http') ? url : `https://${url}`;
|
|
70
|
+
return `<a href="${href}" target="_blank" rel="noopener noreferrer" style="color: #007bff; text-decoration: underline; cursor: pointer;">${url}</a>`;
|
|
71
|
+
});
|
|
72
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { AI_MODEL_MAP, ALL_AVAILABLE_MODELS, DEFAULT_AI_MODELS } from './compone
|
|
|
12
12
|
export { connectWallet, disconnectWallet, validateToken } from './core/utils/walletUtils';
|
|
13
13
|
export { createAITMetadata, generateAITId, prepareAITCreation } from './core/utils/aitUtils';
|
|
14
14
|
export { createNotification, getNotificationIcon } from './core/utils/notificationUtils';
|
|
15
|
+
export { containsUrls, convertUrlsToLinks, convertUrlsToHtml } from './core/utils/urlUtils';
|
|
15
16
|
export { createNxtlinqApi } from './api/nxtlinq-api';
|
|
16
17
|
export type { AIT, AITApi, Message, ServicePermission } from './types/ait-api';
|
|
17
18
|
export { default as useLocalStorage } from './core/lib/useLocalStorage';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAGlF,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGhE,YAAY,EAEV,OAAO,EACP,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,aAAa,E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