@bytexbyte/nxtlinq-ai-agent-sdk 1.2.0 → 1.2.1
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":"ChatBot.d.ts","sourceRoot":"","sources":["../../src/components/ChatBot.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,EAAE,OAAO,EAAkC,MAAM,kBAAkB,CAAC;AAE3E,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/B,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IAC1D,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC;QAC7B,KAAK,EAAE,MAAM,CAAC;KACf,GAAG,SAAS,CAAC,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;
|
|
1
|
+
{"version":3,"file":"ChatBot.d.ts","sourceRoot":"","sources":["../../src/components/ChatBot.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,EAAE,OAAO,EAAkC,MAAM,kBAAkB,CAAC;AAE3E,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/B,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IAC1D,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC;QAC7B,KAAK,EAAE,MAAM,CAAC;KACf,GAAG,SAAS,CAAC,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AA2cD,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAogC1C,CAAC"}
|
|
@@ -5,8 +5,9 @@ import { createNxtlinqApi } from '../api/nxtlinq-api';
|
|
|
5
5
|
import stringify from 'fast-json-stable-stringify';
|
|
6
6
|
import metakeepClient from '../core/metakeepClient';
|
|
7
7
|
import useLocalStorage from '../core/lib/useLocalStorage';
|
|
8
|
-
const PermissionForm = ({ hitAddress, permissions, setPermissions, setIsDisabled, onClose, onSave, onConnectWallet, onSignIn, isNeedSignInWithWallet, walletInfo, onVerifyWallet, serviceId, nxtlinqApi, permissionGroup }) => {
|
|
8
|
+
const PermissionForm = ({ hitAddress, permissions, setPermissions, setIsDisabled, onClose, onSave, onConnectWallet, onSignIn, isNeedSignInWithWallet, walletInfo, onVerifyWallet, serviceId, nxtlinqApi, permissionGroup, isAITLoading, isWalletLoading = false }) => {
|
|
9
9
|
const [availablePermissions, setAvailablePermissions] = React.useState([]);
|
|
10
|
+
const [isSaving, setIsSaving] = React.useState(false);
|
|
10
11
|
const fetchAvailablePermissions = async () => {
|
|
11
12
|
if (!serviceId)
|
|
12
13
|
return;
|
|
@@ -28,7 +29,72 @@ const PermissionForm = ({ hitAddress, permissions, setPermissions, setIsDisabled
|
|
|
28
29
|
React.useEffect(() => {
|
|
29
30
|
fetchAvailablePermissions();
|
|
30
31
|
}, [serviceId, nxtlinqApi, permissionGroup]);
|
|
31
|
-
const isWalletVerified = walletInfo?.id
|
|
32
|
+
const isWalletVerified = Boolean(walletInfo?.id);
|
|
33
|
+
const handleSave = async () => {
|
|
34
|
+
setIsSaving(true);
|
|
35
|
+
try {
|
|
36
|
+
await onSave();
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
setIsSaving(false);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
// Show loading state while checking wallet status
|
|
43
|
+
if (isWalletLoading) {
|
|
44
|
+
return (_jsxs("div", { style: {
|
|
45
|
+
backgroundColor: 'white',
|
|
46
|
+
padding: '24px',
|
|
47
|
+
borderRadius: '12px',
|
|
48
|
+
width: '480px',
|
|
49
|
+
maxWidth: '90%',
|
|
50
|
+
boxShadow: '0 4px 12px rgba(0, 0, 0, 0.1)'
|
|
51
|
+
}, children: [_jsxs("div", { style: {
|
|
52
|
+
display: 'flex',
|
|
53
|
+
justifyContent: 'space-between',
|
|
54
|
+
alignItems: 'center',
|
|
55
|
+
marginBottom: '24px'
|
|
56
|
+
}, children: [_jsx("h3", { style: {
|
|
57
|
+
margin: 0,
|
|
58
|
+
fontSize: '20px',
|
|
59
|
+
fontWeight: '600',
|
|
60
|
+
color: '#1a1a1a'
|
|
61
|
+
}, children: "AIT Settings" }), _jsx("button", { onClick: onClose, style: {
|
|
62
|
+
background: 'none',
|
|
63
|
+
border: 'none',
|
|
64
|
+
fontSize: '24px',
|
|
65
|
+
cursor: 'pointer',
|
|
66
|
+
color: '#666',
|
|
67
|
+
padding: '4px',
|
|
68
|
+
display: 'flex',
|
|
69
|
+
alignItems: 'center',
|
|
70
|
+
justifyContent: 'center'
|
|
71
|
+
}, children: "\u00D7" })] }), _jsxs("div", { style: { textAlign: 'center', padding: '32px 0' }, children: [_jsx("div", { style: {
|
|
72
|
+
width: '64px',
|
|
73
|
+
height: '64px',
|
|
74
|
+
margin: '0 auto 16px',
|
|
75
|
+
backgroundColor: '#f5f5f5',
|
|
76
|
+
borderRadius: '50%',
|
|
77
|
+
display: 'flex',
|
|
78
|
+
alignItems: 'center',
|
|
79
|
+
justifyContent: 'center'
|
|
80
|
+
}, children: _jsx("div", { style: {
|
|
81
|
+
width: '32px',
|
|
82
|
+
height: '32px',
|
|
83
|
+
border: '3px solid #e3e3e3',
|
|
84
|
+
borderTop: '3px solid #007bff',
|
|
85
|
+
borderRadius: '50%',
|
|
86
|
+
animation: 'spin 1s linear infinite'
|
|
87
|
+
} }) }), _jsx("p", { style: {
|
|
88
|
+
marginBottom: '24px',
|
|
89
|
+
fontSize: '16px',
|
|
90
|
+
color: '#666'
|
|
91
|
+
}, children: "Checking wallet status..." })] }), _jsx("style", { children: `
|
|
92
|
+
@keyframes spin {
|
|
93
|
+
0% { transform: rotate(0deg); }
|
|
94
|
+
100% { transform: rotate(360deg); }
|
|
95
|
+
}
|
|
96
|
+
` })] }));
|
|
97
|
+
}
|
|
32
98
|
return (_jsxs("div", { style: {
|
|
33
99
|
backgroundColor: 'white',
|
|
34
100
|
padding: '24px',
|
|
@@ -147,7 +213,14 @@ const PermissionForm = ({ hitAddress, permissions, setPermissions, setIsDisabled
|
|
|
147
213
|
marginBottom: '12px',
|
|
148
214
|
fontSize: '16px',
|
|
149
215
|
color: '#666'
|
|
150
|
-
}, children: "Permissions" }), _jsx("div", { style: {
|
|
216
|
+
}, children: "Permissions" }), isAITLoading ? (_jsx("div", { style: {
|
|
217
|
+
backgroundColor: '#f8f9fa',
|
|
218
|
+
padding: '16px',
|
|
219
|
+
borderRadius: '8px',
|
|
220
|
+
border: '1px solid #e9ecef',
|
|
221
|
+
textAlign: 'center',
|
|
222
|
+
color: '#666'
|
|
223
|
+
}, children: "Loading permissions..." })) : (_jsx("div", { style: {
|
|
151
224
|
backgroundColor: '#f8f9fa',
|
|
152
225
|
padding: '16px',
|
|
153
226
|
borderRadius: '8px',
|
|
@@ -156,25 +229,36 @@ const PermissionForm = ({ hitAddress, permissions, setPermissions, setIsDisabled
|
|
|
156
229
|
display: 'flex',
|
|
157
230
|
alignItems: 'center',
|
|
158
231
|
gap: '12px',
|
|
159
|
-
cursor: 'pointer',
|
|
232
|
+
cursor: isAITLoading ? 'not-allowed' : 'pointer',
|
|
160
233
|
padding: '8px',
|
|
161
234
|
borderRadius: '6px',
|
|
162
|
-
transition: 'background-color 0.2s'
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
235
|
+
transition: 'background-color 0.2s',
|
|
236
|
+
opacity: isAITLoading ? 0.6 : 1
|
|
237
|
+
}, onMouseOver: (e) => {
|
|
238
|
+
if (!isAITLoading) {
|
|
239
|
+
e.currentTarget.style.backgroundColor = '#e9ecef';
|
|
240
|
+
}
|
|
241
|
+
}, onMouseOut: (e) => {
|
|
242
|
+
if (!isAITLoading) {
|
|
243
|
+
e.currentTarget.style.backgroundColor = 'transparent';
|
|
244
|
+
}
|
|
245
|
+
}, children: [_jsx("input", { type: "checkbox", checked: permissions.includes(permission.label), onChange: () => {
|
|
246
|
+
if (!isAITLoading) {
|
|
247
|
+
const newPermissions = permissions.includes(permission.label)
|
|
248
|
+
? permissions.filter(p => p !== permission.label)
|
|
249
|
+
: [...permissions, permission.label].sort();
|
|
250
|
+
setPermissions(newPermissions);
|
|
251
|
+
setIsDisabled(false);
|
|
252
|
+
}
|
|
253
|
+
}, disabled: isAITLoading, style: {
|
|
170
254
|
margin: 0,
|
|
171
255
|
width: '18px',
|
|
172
256
|
height: '18px',
|
|
173
|
-
cursor: 'pointer'
|
|
257
|
+
cursor: isAITLoading ? 'not-allowed' : 'pointer'
|
|
174
258
|
} }), _jsx("span", { style: {
|
|
175
259
|
fontSize: '14px',
|
|
176
260
|
color: '#333'
|
|
177
|
-
}, children: permission.label })] }) }, permission.id))) })] }), _jsxs("div", { style: {
|
|
261
|
+
}, children: permission.label })] }) }, permission.id))) }))] }), _jsxs("div", { style: {
|
|
178
262
|
display: 'flex',
|
|
179
263
|
justifyContent: 'flex-end',
|
|
180
264
|
gap: '12px',
|
|
@@ -196,25 +280,25 @@ const PermissionForm = ({ hitAddress, permissions, setPermissions, setIsDisabled
|
|
|
196
280
|
}, onMouseOut: (e) => {
|
|
197
281
|
e.currentTarget.style.backgroundColor = '#f8f9fa';
|
|
198
282
|
e.currentTarget.style.borderColor = '#dee2e6';
|
|
199
|
-
}, children: "Cancel" }), _jsx("button", { onClick:
|
|
283
|
+
}, children: "Cancel" }), _jsx("button", { onClick: handleSave, disabled: permissions.length === 0 || isSaving || isAITLoading, style: {
|
|
200
284
|
padding: '10px 20px',
|
|
201
|
-
backgroundColor: permissions.length === 0 ? '#e9ecef' : '#007bff',
|
|
202
|
-
color: 'white',
|
|
285
|
+
backgroundColor: permissions.length === 0 || isSaving || isAITLoading ? '#e9ecef' : '#007bff',
|
|
286
|
+
color: permissions.length === 0 || isSaving || isAITLoading ? '#6c757d' : 'white',
|
|
203
287
|
border: 'none',
|
|
204
288
|
borderRadius: '8px',
|
|
205
|
-
cursor: permissions.length === 0 ? 'not-allowed' : 'pointer',
|
|
289
|
+
cursor: permissions.length === 0 || isSaving || isAITLoading ? 'not-allowed' : 'pointer',
|
|
206
290
|
fontSize: '14px',
|
|
207
291
|
fontWeight: '500',
|
|
208
292
|
transition: 'background-color 0.2s'
|
|
209
293
|
}, onMouseOver: (e) => {
|
|
210
|
-
if (permissions.length > 0) {
|
|
294
|
+
if (permissions.length > 0 && !isSaving && !isAITLoading) {
|
|
211
295
|
e.currentTarget.style.backgroundColor = '#0056b3';
|
|
212
296
|
}
|
|
213
297
|
}, onMouseOut: (e) => {
|
|
214
|
-
if (permissions.length > 0) {
|
|
298
|
+
if (permissions.length > 0 && !isSaving && !isAITLoading) {
|
|
215
299
|
e.currentTarget.style.backgroundColor = '#007bff';
|
|
216
300
|
}
|
|
217
|
-
}, children:
|
|
301
|
+
}, children: isSaving ? 'Saving...' : 'Save' })] })] }))] }));
|
|
218
302
|
};
|
|
219
303
|
export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], placeholder = 'Type a message...', className = '', maxRetries = 3, retryDelay = 1000, serviceId, apiKey, apiSecret, onVerifyWallet, permissionGroup }) => {
|
|
220
304
|
const [messages, setMessages] = React.useState([]);
|
|
@@ -227,12 +311,15 @@ export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], pl
|
|
|
227
311
|
const [availablePermissions, setAvailablePermissions] = React.useState([]);
|
|
228
312
|
const [showPermissionForm, setShowPermissionForm] = React.useState(false);
|
|
229
313
|
const [success, setSuccess] = React.useState(false);
|
|
314
|
+
const [isPermissionFormOpen, setIsPermissionFormOpen] = React.useState(false);
|
|
315
|
+
const [isAITLoading, setIsAITLoading] = React.useState(false);
|
|
230
316
|
const messagesEndRef = React.useRef(null);
|
|
231
317
|
const [isDisabled, setIsDisabled] = React.useState(true);
|
|
232
318
|
const [signer, setSigner] = React.useState(null);
|
|
233
319
|
const [walletInfo, setWalletInfo] = React.useState(null);
|
|
234
320
|
const verifyWalletBtnRef = React.useRef(null);
|
|
235
321
|
const [nxtlinqAITServiceAccessToken, setNxtlinqAITServiceAccessToken] = useLocalStorage('nxtlinqAITServiceAccessToken', '');
|
|
322
|
+
const [isWalletLoading, setIsWalletLoading] = React.useState(false);
|
|
236
323
|
const nxtlinqApi = React.useMemo(() => createNxtlinqApi(apiKey, apiSecret), [apiKey, apiSecret]);
|
|
237
324
|
const fetchAvailablePermissions = async () => {
|
|
238
325
|
if (!serviceId)
|
|
@@ -252,7 +339,7 @@ export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], pl
|
|
|
252
339
|
console.error('Error fetching permissions:', error);
|
|
253
340
|
}
|
|
254
341
|
};
|
|
255
|
-
const refreshAIT = async () => {
|
|
342
|
+
const refreshAIT = async (forceUpdatePermissions = false) => {
|
|
256
343
|
console.log('refreshAIT called');
|
|
257
344
|
console.log('hitAddress:', hitAddress);
|
|
258
345
|
console.log('nxtlinqAITServiceAccessToken:', nxtlinqAITServiceAccessToken);
|
|
@@ -261,6 +348,7 @@ export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], pl
|
|
|
261
348
|
setPermissions([]);
|
|
262
349
|
return;
|
|
263
350
|
}
|
|
351
|
+
setIsAITLoading(true);
|
|
264
352
|
try {
|
|
265
353
|
const response = await nxtlinqApi.ait.getAITByServiceIdAndController({
|
|
266
354
|
serviceId,
|
|
@@ -274,13 +362,19 @@ export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], pl
|
|
|
274
362
|
}
|
|
275
363
|
console.log('AIT response:', response);
|
|
276
364
|
setAit(response);
|
|
277
|
-
|
|
365
|
+
// Update permissions if form is not open OR if force update is requested
|
|
366
|
+
if (!isPermissionFormOpen || forceUpdatePermissions) {
|
|
367
|
+
setPermissions(response.metadata?.permissions || []);
|
|
368
|
+
}
|
|
278
369
|
}
|
|
279
370
|
catch (error) {
|
|
280
371
|
console.error('Failed to fetch AIT:', error);
|
|
281
372
|
setAit(null);
|
|
282
373
|
setPermissions([]);
|
|
283
374
|
}
|
|
375
|
+
finally {
|
|
376
|
+
setIsAITLoading(false);
|
|
377
|
+
}
|
|
284
378
|
};
|
|
285
379
|
React.useEffect(() => {
|
|
286
380
|
console.log('hitAddress:', hitAddress);
|
|
@@ -325,6 +419,7 @@ export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], pl
|
|
|
325
419
|
const handleVerifySuccess = (address) => {
|
|
326
420
|
localStorage.setItem(`wallet_verified_${address}`, 'true');
|
|
327
421
|
const getWalletInfo = async () => {
|
|
422
|
+
setIsWalletLoading(true);
|
|
328
423
|
try {
|
|
329
424
|
const token = JSON.parse(localStorage.getItem('nxtlinqAITServiceAccessToken') || '');
|
|
330
425
|
const walletResponse = await nxtlinqApi.wallet.getWallet({ address }, token);
|
|
@@ -344,6 +439,9 @@ export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], pl
|
|
|
344
439
|
catch (error) {
|
|
345
440
|
console.error('Failed to update wallet info after verification:', error);
|
|
346
441
|
}
|
|
442
|
+
finally {
|
|
443
|
+
setIsWalletLoading(false);
|
|
444
|
+
}
|
|
347
445
|
};
|
|
348
446
|
getWalletInfo();
|
|
349
447
|
};
|
|
@@ -355,16 +453,25 @@ export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], pl
|
|
|
355
453
|
if (isNeedSignInWithWallet) {
|
|
356
454
|
return;
|
|
357
455
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
456
|
+
setIsWalletLoading(true);
|
|
457
|
+
try {
|
|
458
|
+
const getWalletResponse = await nxtlinqApi.wallet.getWallet({ address: hitAddress }, nxtlinqAITServiceAccessToken);
|
|
459
|
+
if ('error' in getWalletResponse) {
|
|
460
|
+
if (getWalletResponse.error === 'Wallet not found') {
|
|
461
|
+
console.log('Wallet not found - this is expected for new users');
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
console.error(getWalletResponse.error);
|
|
362
465
|
return;
|
|
363
466
|
}
|
|
364
|
-
|
|
365
|
-
|
|
467
|
+
setWalletInfo(getWalletResponse);
|
|
468
|
+
}
|
|
469
|
+
catch (error) {
|
|
470
|
+
console.error('Error getting wallet info:', error);
|
|
471
|
+
}
|
|
472
|
+
finally {
|
|
473
|
+
setIsWalletLoading(false);
|
|
366
474
|
}
|
|
367
|
-
setWalletInfo(getWalletResponse);
|
|
368
475
|
};
|
|
369
476
|
getWalletInfo();
|
|
370
477
|
}, [hitAddress, isNeedSignInWithWallet]);
|
|
@@ -403,19 +510,29 @@ export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], pl
|
|
|
403
510
|
if ('error' in verifyWalletResponse) {
|
|
404
511
|
if (verifyWalletResponse.error === 'Wallet already exists') {
|
|
405
512
|
// If wallet exists, get wallet info directly
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
513
|
+
setIsWalletLoading(true);
|
|
514
|
+
try {
|
|
515
|
+
const walletResponse = await nxtlinqApi.wallet.getWallet({ address }, token);
|
|
516
|
+
if (!('error' in walletResponse)) {
|
|
517
|
+
setWalletInfo(walletResponse);
|
|
518
|
+
const aitResponse = await nxtlinqApi.ait.getAITByServiceIdAndController({ serviceId, controller: address }, token);
|
|
519
|
+
if (!('error' in aitResponse)) {
|
|
520
|
+
setAit(aitResponse);
|
|
521
|
+
}
|
|
412
522
|
}
|
|
413
523
|
}
|
|
414
|
-
|
|
524
|
+
finally {
|
|
525
|
+
setIsWalletLoading(false);
|
|
526
|
+
}
|
|
527
|
+
// Clean up URL parameters after wallet verification
|
|
415
528
|
if (typeof window !== 'undefined') {
|
|
416
529
|
try {
|
|
417
530
|
const url = new URL(window.location.href);
|
|
531
|
+
// Clean up all Berify.me related parameters
|
|
418
532
|
url.searchParams.delete('token');
|
|
533
|
+
url.searchParams.delete('isAutoConnect');
|
|
534
|
+
url.searchParams.delete('method');
|
|
535
|
+
url.searchParams.delete('returnUrl');
|
|
419
536
|
window.history.replaceState({}, '', url.toString());
|
|
420
537
|
}
|
|
421
538
|
catch (e) {
|
|
@@ -432,19 +549,29 @@ export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], pl
|
|
|
432
549
|
return;
|
|
433
550
|
}
|
|
434
551
|
// Verification successful, get wallet info
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
552
|
+
setIsWalletLoading(true);
|
|
553
|
+
try {
|
|
554
|
+
const walletResponse = await nxtlinqApi.wallet.getWallet({ address }, token);
|
|
555
|
+
if (!('error' in walletResponse)) {
|
|
556
|
+
setWalletInfo(walletResponse);
|
|
557
|
+
const aitResponse = await nxtlinqApi.ait.getAITByServiceIdAndController({ serviceId, controller: address }, token);
|
|
558
|
+
if (!('error' in aitResponse)) {
|
|
559
|
+
setAit(aitResponse);
|
|
560
|
+
}
|
|
441
561
|
}
|
|
442
562
|
}
|
|
443
|
-
|
|
563
|
+
finally {
|
|
564
|
+
setIsWalletLoading(false);
|
|
565
|
+
}
|
|
566
|
+
// Clean up URL parameters after wallet verification
|
|
444
567
|
if (typeof window !== 'undefined') {
|
|
445
568
|
try {
|
|
446
569
|
const url = new URL(window.location.href);
|
|
570
|
+
// Clean up all Berify.me related parameters
|
|
447
571
|
url.searchParams.delete('token');
|
|
572
|
+
url.searchParams.delete('isAutoConnect');
|
|
573
|
+
url.searchParams.delete('method');
|
|
574
|
+
url.searchParams.delete('returnUrl');
|
|
448
575
|
window.history.replaceState({}, '', url.toString());
|
|
449
576
|
}
|
|
450
577
|
catch (e) {
|
|
@@ -813,17 +940,15 @@ export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], pl
|
|
|
813
940
|
setAit(aitInfo);
|
|
814
941
|
};
|
|
815
942
|
const savePermissions = async () => {
|
|
816
|
-
setIsLoading(true);
|
|
817
943
|
setIsDisabled(true);
|
|
818
944
|
try {
|
|
819
945
|
await generateAndRegisterAIT();
|
|
820
|
-
setIsLoading(false);
|
|
821
946
|
setSuccess(true);
|
|
822
947
|
setShowPermissionForm(false);
|
|
948
|
+
setIsPermissionFormOpen(false);
|
|
823
949
|
}
|
|
824
950
|
catch (error) {
|
|
825
951
|
console.error('Failed to generate AIT:', error);
|
|
826
|
-
setIsLoading(false);
|
|
827
952
|
setIsDisabled(false);
|
|
828
953
|
if (error instanceof Error) {
|
|
829
954
|
alert(error.message);
|
|
@@ -846,6 +971,15 @@ export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], pl
|
|
|
846
971
|
onMessage?.(lastMessage);
|
|
847
972
|
}
|
|
848
973
|
}, [messages, onMessage]);
|
|
974
|
+
// Auto hide success message after 3 seconds
|
|
975
|
+
React.useEffect(() => {
|
|
976
|
+
if (success) {
|
|
977
|
+
const timer = setTimeout(() => {
|
|
978
|
+
setSuccess(false);
|
|
979
|
+
}, 3000);
|
|
980
|
+
return () => clearTimeout(timer);
|
|
981
|
+
}
|
|
982
|
+
}, [success]);
|
|
849
983
|
return (_jsxs("div", { style: {
|
|
850
984
|
position: 'fixed',
|
|
851
985
|
bottom: '20px',
|
|
@@ -872,7 +1006,12 @@ export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], pl
|
|
|
872
1006
|
display: 'flex',
|
|
873
1007
|
justifyContent: 'space-between',
|
|
874
1008
|
alignItems: 'center'
|
|
875
|
-
}, children: [_jsx("h3", { style: { margin: 0 }, children: "AI Agent" }), _jsxs("div", { style: { display: 'flex', gap: '10px' }, children: [_jsx("button", { onClick: () =>
|
|
1009
|
+
}, children: [_jsx("h3", { style: { margin: 0 }, children: "AI Agent" }), _jsxs("div", { style: { display: 'flex', gap: '10px' }, children: [_jsx("button", { onClick: async () => {
|
|
1010
|
+
setShowPermissionForm(true);
|
|
1011
|
+
setIsPermissionFormOpen(true);
|
|
1012
|
+
// Force refresh AIT data when opening the form to show latest permissions
|
|
1013
|
+
await refreshAIT(true);
|
|
1014
|
+
}, style: {
|
|
876
1015
|
background: 'none',
|
|
877
1016
|
border: 'none',
|
|
878
1017
|
color: 'white',
|
|
@@ -981,7 +1120,10 @@ export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], pl
|
|
|
981
1120
|
alignItems: 'center',
|
|
982
1121
|
justifyContent: 'center',
|
|
983
1122
|
zIndex: 2000
|
|
984
|
-
}, children: _jsx(PermissionForm, { hitAddress: hitAddress, permissions: permissions, setPermissions: setPermissions, setIsDisabled: setIsDisabled, onClose: () =>
|
|
1123
|
+
}, children: _jsx(PermissionForm, { hitAddress: hitAddress, permissions: permissions, setPermissions: setPermissions, setIsDisabled: setIsDisabled, onClose: () => {
|
|
1124
|
+
setShowPermissionForm(false);
|
|
1125
|
+
setIsPermissionFormOpen(false);
|
|
1126
|
+
}, onConnectWallet: () => connectWallet(false), onSignIn: () => signInWallet(false), onSave: savePermissions, isNeedSignInWithWallet: isNeedSignInWithWallet, walletInfo: walletInfo, onVerifyWallet: handleVerifyWalletClick, serviceId: serviceId, nxtlinqApi: nxtlinqApi, permissionGroup: permissionGroup, isAITLoading: isAITLoading, isWalletLoading: isWalletLoading }) })), success && (_jsxs("div", { style: {
|
|
985
1127
|
position: 'fixed',
|
|
986
1128
|
bottom: 100,
|
|
987
1129
|
right: 40,
|
package/package.json
CHANGED