@bytexbyte/nxtlinq-ai-agent-sdk 1.1.1 → 1.1.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.
|
@@ -53,9 +53,9 @@ export interface ChatBotProps {
|
|
|
53
53
|
serviceId: string;
|
|
54
54
|
apiKey: string;
|
|
55
55
|
apiSecret: string;
|
|
56
|
-
onVerifyWallet?: (
|
|
56
|
+
onVerifyWallet?: () => Promise<{
|
|
57
57
|
token: string;
|
|
58
|
-
}>;
|
|
58
|
+
} | undefined>;
|
|
59
59
|
}
|
|
60
60
|
export declare const ChatBot: React.FC<ChatBotProps>;
|
|
61
61
|
//# sourceMappingURL=ChatBot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatBot.d.ts","sourceRoot":"","sources":["../../src/components/ChatBot.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,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,CA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I,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;CAChB;AAoUD,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAo2B1C,CAAC"}
|
|
@@ -11,7 +11,6 @@ const PermissionForm = ({ hitAddress, permissions, setPermissions, setIsDisabled
|
|
|
11
11
|
{ id: 'navigateToPage', label: 'Navigate To Page' },
|
|
12
12
|
{ id: 'addMember', label: 'Add Member' }
|
|
13
13
|
];
|
|
14
|
-
const hasAccessToken = !!localStorage.getItem('nxtlinqAITServiceAccessToken');
|
|
15
14
|
const isWalletVerified = walletInfo?.id;
|
|
16
15
|
return (_jsxs("div", { style: {
|
|
17
16
|
backgroundColor: 'white',
|
|
@@ -213,11 +212,47 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
213
212
|
const messagesEndRef = React.useRef(null);
|
|
214
213
|
const [isDisabled, setIsDisabled] = React.useState(true);
|
|
215
214
|
const [signer, setSigner] = React.useState(null);
|
|
216
|
-
const [accessToken, setAccessToken] = React.useState(null);
|
|
217
215
|
const [walletInfo, setWalletInfo] = React.useState(null);
|
|
218
216
|
const verifyWalletBtnRef = React.useRef(null);
|
|
219
217
|
const [nxtlinqAITServiceAccessToken, setNxtlinqAITServiceAccessToken] = useLocalStorage('nxtlinqAITServiceAccessToken', '');
|
|
220
218
|
const nxtlinqApi = React.useMemo(() => createNxtlinqApi(apiKey, apiSecret), [apiKey, apiSecret]);
|
|
219
|
+
const refreshAIT = async () => {
|
|
220
|
+
console.log('refreshAIT called');
|
|
221
|
+
console.log('hitAddress:', hitAddress);
|
|
222
|
+
console.log('nxtlinqAITServiceAccessToken:', nxtlinqAITServiceAccessToken);
|
|
223
|
+
if (!hitAddress) {
|
|
224
|
+
setAit(null);
|
|
225
|
+
setPermissions([]);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
const response = await nxtlinqApi.ait.getAITByServiceIdAndController({
|
|
230
|
+
serviceId,
|
|
231
|
+
controller: hitAddress
|
|
232
|
+
}, nxtlinqAITServiceAccessToken || '');
|
|
233
|
+
if ('error' in response) {
|
|
234
|
+
console.error('Failed to fetch AIT:', response.error);
|
|
235
|
+
setAit(null);
|
|
236
|
+
setPermissions([]);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
console.log('AIT response:', response);
|
|
240
|
+
setAit(response);
|
|
241
|
+
setPermissions(response.metadata?.permissions || []);
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
console.error('Failed to fetch AIT:', error);
|
|
245
|
+
setAit(null);
|
|
246
|
+
setPermissions([]);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
React.useEffect(() => {
|
|
250
|
+
console.log('hitAddress:', hitAddress);
|
|
251
|
+
console.log('nxtlinqAITServiceAccessToken:', nxtlinqAITServiceAccessToken);
|
|
252
|
+
if (hitAddress && nxtlinqAITServiceAccessToken) {
|
|
253
|
+
refreshAIT();
|
|
254
|
+
}
|
|
255
|
+
}, [hitAddress, nxtlinqAITServiceAccessToken]);
|
|
221
256
|
const isNeedSignInWithWallet = React.useMemo(() => {
|
|
222
257
|
if (!hitAddress) {
|
|
223
258
|
return false;
|
|
@@ -278,7 +313,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
278
313
|
if (isNeedSignInWithWallet) {
|
|
279
314
|
return;
|
|
280
315
|
}
|
|
281
|
-
const getWalletResponse = await nxtlinqApi.wallet.getWallet({ address: hitAddress },
|
|
316
|
+
const getWalletResponse = await nxtlinqApi.wallet.getWallet({ address: hitAddress }, nxtlinqAITServiceAccessToken);
|
|
282
317
|
if ('error' in getWalletResponse) {
|
|
283
318
|
if (getWalletResponse.error === 'Wallet not found') {
|
|
284
319
|
console.log('Wallet not found - this is expected for new users');
|
|
@@ -306,8 +341,12 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
306
341
|
try {
|
|
307
342
|
if (onVerifyWallet) {
|
|
308
343
|
setIsLoading(true);
|
|
309
|
-
const result = await onVerifyWallet(
|
|
344
|
+
const result = await onVerifyWallet();
|
|
310
345
|
console.log('Verify wallet response:', result);
|
|
346
|
+
if (!result) {
|
|
347
|
+
setIsLoading(false);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
311
350
|
const { token } = result;
|
|
312
351
|
const address = hitAddress;
|
|
313
352
|
if (token && address) {
|
|
@@ -342,6 +381,8 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
342
381
|
}
|
|
343
382
|
}
|
|
344
383
|
setIsLoading(false);
|
|
384
|
+
// Refresh AIT after wallet verification
|
|
385
|
+
refreshAIT();
|
|
345
386
|
return { token, hitAddress: address };
|
|
346
387
|
}
|
|
347
388
|
alert(verifyWalletResponse.error);
|
|
@@ -369,6 +410,8 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
369
410
|
}
|
|
370
411
|
}
|
|
371
412
|
setIsLoading(false);
|
|
413
|
+
// Refresh AIT after wallet verification
|
|
414
|
+
refreshAIT();
|
|
372
415
|
return { token, hitAddress: address };
|
|
373
416
|
}
|
|
374
417
|
catch (error) {
|
|
@@ -455,6 +498,10 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
455
498
|
localStorage.setItem('walletAddress', userAddress);
|
|
456
499
|
setHitAddress(userAddress);
|
|
457
500
|
setSigner(userSigner);
|
|
501
|
+
// Refresh AIT after connecting wallet
|
|
502
|
+
if (nxtlinqAITServiceAccessToken) {
|
|
503
|
+
refreshAIT();
|
|
504
|
+
}
|
|
458
505
|
return userAddress;
|
|
459
506
|
}
|
|
460
507
|
catch (error) {
|
|
@@ -464,7 +511,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
464
511
|
setSigner(null);
|
|
465
512
|
throw error;
|
|
466
513
|
}
|
|
467
|
-
}, []);
|
|
514
|
+
}, [nxtlinqAITServiceAccessToken, refreshAIT]);
|
|
468
515
|
const signInWallet = async () => {
|
|
469
516
|
if (!hitAddress) {
|
|
470
517
|
alert('Please connect your wallet first.');
|
|
@@ -497,7 +544,8 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
497
544
|
}
|
|
498
545
|
const { accessToken } = response;
|
|
499
546
|
setNxtlinqAITServiceAccessToken(accessToken);
|
|
500
|
-
|
|
547
|
+
// Refresh AIT after signing in
|
|
548
|
+
refreshAIT();
|
|
501
549
|
}
|
|
502
550
|
catch (error) {
|
|
503
551
|
console.error('Failed to sign in:', error);
|
|
@@ -645,7 +693,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
645
693
|
const metadataStr = stringify(metadata);
|
|
646
694
|
const metadataHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(metadataStr));
|
|
647
695
|
// 1️⃣ Upload metadata to Pinata, get CID
|
|
648
|
-
const uploadResponse = await nxtlinqApi.metadata.createMetadata(metadata,
|
|
696
|
+
const uploadResponse = await nxtlinqApi.metadata.createMetadata(metadata, nxtlinqAITServiceAccessToken || '');
|
|
649
697
|
if ('error' in uploadResponse) {
|
|
650
698
|
throw new Error(`Failed to upload metadata: ${uploadResponse.error}`);
|
|
651
699
|
}
|
|
@@ -656,7 +704,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
656
704
|
serviceId,
|
|
657
705
|
metadataHash,
|
|
658
706
|
metadataCid,
|
|
659
|
-
},
|
|
707
|
+
}, nxtlinqAITServiceAccessToken || '');
|
|
660
708
|
const aitInfo = {
|
|
661
709
|
aitId,
|
|
662
710
|
controller: hitAddress,
|
package/package.json
CHANGED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { NxtlinqAITSDK } from '../index';
|
|
2
|
-
import { AITInfo, WalletInfo } from '../types/ait-api';
|
|
3
|
-
export declare function useNxtlinqAIT(sdk: NxtlinqAITSDK): {
|
|
4
|
-
walletAddress: string | null;
|
|
5
|
-
walletInfo: WalletInfo | null;
|
|
6
|
-
ait: AITInfo | null;
|
|
7
|
-
isLoading: boolean;
|
|
8
|
-
error: string | null;
|
|
9
|
-
connectWallet: () => Promise<void>;
|
|
10
|
-
verifyWallet: (token: string, method: string) => Promise<any>;
|
|
11
|
-
signInWithWallet: () => Promise<any>;
|
|
12
|
-
generateAndRegisterAIT: (permissions: string[]) => Promise<any>;
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=useNxtlinqAIT.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useNxtlinqAIT.d.ts","sourceRoot":"","sources":["../../src/hooks/useNxtlinqAIT.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEvD,wBAAgB,aAAa,CAAC,GAAG,EAAE,aAAa;;;;;;;0BAoBX,MAAM,UAAU,MAAM;;0CA6BN,MAAM,EAAE;EA6C5D"}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
export function useNxtlinqAIT(sdk) {
|
|
3
|
-
const [walletAddress, setWalletAddress] = useState(null);
|
|
4
|
-
const [walletInfo, setWalletInfo] = useState(null);
|
|
5
|
-
const [ait, setAit] = useState(null);
|
|
6
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
7
|
-
const [error, setError] = useState(null);
|
|
8
|
-
const connectWallet = async () => {
|
|
9
|
-
try {
|
|
10
|
-
setIsLoading(true);
|
|
11
|
-
setError(null);
|
|
12
|
-
const address = await sdk.connectWallet();
|
|
13
|
-
setWalletAddress(address);
|
|
14
|
-
}
|
|
15
|
-
catch (err) {
|
|
16
|
-
setError(err instanceof Error ? err.message : 'Failed to connect wallet');
|
|
17
|
-
}
|
|
18
|
-
finally {
|
|
19
|
-
setIsLoading(false);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const verifyWallet = async (token, method) => {
|
|
23
|
-
try {
|
|
24
|
-
setIsLoading(true);
|
|
25
|
-
setError(null);
|
|
26
|
-
const info = await sdk.verifyWallet(token, method);
|
|
27
|
-
setWalletInfo(info);
|
|
28
|
-
return info;
|
|
29
|
-
}
|
|
30
|
-
catch (err) {
|
|
31
|
-
setError(err instanceof Error ? err.message : 'Failed to verify wallet');
|
|
32
|
-
throw err;
|
|
33
|
-
}
|
|
34
|
-
finally {
|
|
35
|
-
setIsLoading(false);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
const signInWithWallet = async () => {
|
|
39
|
-
try {
|
|
40
|
-
setIsLoading(true);
|
|
41
|
-
setError(null);
|
|
42
|
-
const token = await sdk.signInWithWallet();
|
|
43
|
-
return token;
|
|
44
|
-
}
|
|
45
|
-
catch (err) {
|
|
46
|
-
setError(err instanceof Error ? err.message : 'Failed to sign in with wallet');
|
|
47
|
-
throw err;
|
|
48
|
-
}
|
|
49
|
-
finally {
|
|
50
|
-
setIsLoading(false);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
const generateAndRegisterAIT = async (permissions) => {
|
|
54
|
-
try {
|
|
55
|
-
setIsLoading(true);
|
|
56
|
-
setError(null);
|
|
57
|
-
const aitInfo = await sdk.generateAndRegisterAIT(permissions);
|
|
58
|
-
setAit(aitInfo);
|
|
59
|
-
return aitInfo;
|
|
60
|
-
}
|
|
61
|
-
catch (err) {
|
|
62
|
-
setError(err instanceof Error ? err.message : 'Failed to generate AIT');
|
|
63
|
-
throw err;
|
|
64
|
-
}
|
|
65
|
-
finally {
|
|
66
|
-
setIsLoading(false);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
const loadData = async () => {
|
|
71
|
-
if (walletAddress) {
|
|
72
|
-
try {
|
|
73
|
-
const [walletInfo, aitInfo] = await Promise.all([
|
|
74
|
-
sdk.getWalletInfo(),
|
|
75
|
-
sdk.getAIT()
|
|
76
|
-
]);
|
|
77
|
-
setWalletInfo(walletInfo);
|
|
78
|
-
setAit(aitInfo);
|
|
79
|
-
}
|
|
80
|
-
catch (err) {
|
|
81
|
-
console.error('Failed to load wallet info or AIT:', err);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
loadData();
|
|
86
|
-
}, [walletAddress, sdk]);
|
|
87
|
-
return {
|
|
88
|
-
walletAddress,
|
|
89
|
-
walletInfo,
|
|
90
|
-
ait,
|
|
91
|
-
isLoading,
|
|
92
|
-
error,
|
|
93
|
-
connectWallet,
|
|
94
|
-
verifyWallet,
|
|
95
|
-
signInWithWallet,
|
|
96
|
-
generateAndRegisterAIT
|
|
97
|
-
};
|
|
98
|
-
}
|