@bytexbyte/nxtlinq-ai-agent-sdk 1.1.0 → 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.
- package/dist/components/ChatBot.d.ts +2 -3
- package/dist/components/ChatBot.d.ts.map +1 -1
- package/dist/components/ChatBot.js +74 -20
- package/dist/index.d.ts +0 -111
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -300
- package/dist/types/ait-api.d.ts +0 -3
- package/dist/types/ait-api.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/hooks/useNxtlinqAIT.d.ts +0 -14
- package/dist/hooks/useNxtlinqAIT.d.ts.map +0 -1
- package/dist/hooks/useNxtlinqAIT.js +0 -98
|
@@ -39,7 +39,6 @@ export interface AIT {
|
|
|
39
39
|
metadata: AITMetadata;
|
|
40
40
|
metadataHash: string;
|
|
41
41
|
metadataCid: string;
|
|
42
|
-
signature: string;
|
|
43
42
|
}
|
|
44
43
|
export interface ChatBotProps {
|
|
45
44
|
projectId?: string;
|
|
@@ -54,9 +53,9 @@ export interface ChatBotProps {
|
|
|
54
53
|
serviceId: string;
|
|
55
54
|
apiKey: string;
|
|
56
55
|
apiSecret: string;
|
|
57
|
-
onVerifyWallet?: (
|
|
56
|
+
onVerifyWallet?: () => Promise<{
|
|
58
57
|
token: string;
|
|
59
|
-
}>;
|
|
58
|
+
} | undefined>;
|
|
60
59
|
}
|
|
61
60
|
export declare const ChatBot: React.FC<ChatBotProps>;
|
|
62
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,GA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C,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,12 +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 [provider, setProvider] = React.useState(null);
|
|
217
|
-
const [accessToken, setAccessToken] = React.useState(null);
|
|
218
215
|
const [walletInfo, setWalletInfo] = React.useState(null);
|
|
219
216
|
const verifyWalletBtnRef = React.useRef(null);
|
|
220
217
|
const [nxtlinqAITServiceAccessToken, setNxtlinqAITServiceAccessToken] = useLocalStorage('nxtlinqAITServiceAccessToken', '');
|
|
221
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]);
|
|
222
256
|
const isNeedSignInWithWallet = React.useMemo(() => {
|
|
223
257
|
if (!hitAddress) {
|
|
224
258
|
return false;
|
|
@@ -279,8 +313,12 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
279
313
|
if (isNeedSignInWithWallet) {
|
|
280
314
|
return;
|
|
281
315
|
}
|
|
282
|
-
const getWalletResponse = await nxtlinqApi.wallet.getWallet({ address: hitAddress },
|
|
316
|
+
const getWalletResponse = await nxtlinqApi.wallet.getWallet({ address: hitAddress }, nxtlinqAITServiceAccessToken);
|
|
283
317
|
if ('error' in getWalletResponse) {
|
|
318
|
+
if (getWalletResponse.error === 'Wallet not found') {
|
|
319
|
+
console.log('Wallet not found - this is expected for new users');
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
284
322
|
console.error(getWalletResponse.error);
|
|
285
323
|
return;
|
|
286
324
|
}
|
|
@@ -303,8 +341,12 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
303
341
|
try {
|
|
304
342
|
if (onVerifyWallet) {
|
|
305
343
|
setIsLoading(true);
|
|
306
|
-
const result = await onVerifyWallet(
|
|
344
|
+
const result = await onVerifyWallet();
|
|
307
345
|
console.log('Verify wallet response:', result);
|
|
346
|
+
if (!result) {
|
|
347
|
+
setIsLoading(false);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
308
350
|
const { token } = result;
|
|
309
351
|
const address = hitAddress;
|
|
310
352
|
if (token && address) {
|
|
@@ -339,6 +381,8 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
339
381
|
}
|
|
340
382
|
}
|
|
341
383
|
setIsLoading(false);
|
|
384
|
+
// Refresh AIT after wallet verification
|
|
385
|
+
refreshAIT();
|
|
342
386
|
return { token, hitAddress: address };
|
|
343
387
|
}
|
|
344
388
|
alert(verifyWalletResponse.error);
|
|
@@ -366,6 +410,8 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
366
410
|
}
|
|
367
411
|
}
|
|
368
412
|
setIsLoading(false);
|
|
413
|
+
// Refresh AIT after wallet verification
|
|
414
|
+
refreshAIT();
|
|
369
415
|
return { token, hitAddress: address };
|
|
370
416
|
}
|
|
371
417
|
catch (error) {
|
|
@@ -446,13 +492,16 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
446
492
|
throw new Error('Web3 provider not available');
|
|
447
493
|
}
|
|
448
494
|
await web3Provider.enable();
|
|
449
|
-
const ethersProvider = new ethers.
|
|
495
|
+
const ethersProvider = new ethers.providers.Web3Provider(web3Provider);
|
|
450
496
|
const userSigner = await ethersProvider.getSigner();
|
|
451
497
|
const userAddress = await userSigner.getAddress();
|
|
452
498
|
localStorage.setItem('walletAddress', userAddress);
|
|
453
499
|
setHitAddress(userAddress);
|
|
454
500
|
setSigner(userSigner);
|
|
455
|
-
|
|
501
|
+
// Refresh AIT after connecting wallet
|
|
502
|
+
if (nxtlinqAITServiceAccessToken) {
|
|
503
|
+
refreshAIT();
|
|
504
|
+
}
|
|
456
505
|
return userAddress;
|
|
457
506
|
}
|
|
458
507
|
catch (error) {
|
|
@@ -460,10 +509,9 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
460
509
|
localStorage.removeItem('walletAddress');
|
|
461
510
|
setHitAddress(null);
|
|
462
511
|
setSigner(null);
|
|
463
|
-
setProvider(null);
|
|
464
512
|
throw error;
|
|
465
513
|
}
|
|
466
|
-
}, []);
|
|
514
|
+
}, [nxtlinqAITServiceAccessToken, refreshAIT]);
|
|
467
515
|
const signInWallet = async () => {
|
|
468
516
|
if (!hitAddress) {
|
|
469
517
|
alert('Please connect your wallet first.');
|
|
@@ -496,7 +544,8 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
496
544
|
}
|
|
497
545
|
const { accessToken } = response;
|
|
498
546
|
setNxtlinqAITServiceAccessToken(accessToken);
|
|
499
|
-
|
|
547
|
+
// Refresh AIT after signing in
|
|
548
|
+
refreshAIT();
|
|
500
549
|
}
|
|
501
550
|
catch (error) {
|
|
502
551
|
console.error('Failed to sign in:', error);
|
|
@@ -529,6 +578,18 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
529
578
|
const novaResponse = response;
|
|
530
579
|
if (novaResponse.toolCall?.toolUse && novaResponse.result !== 'Authentication data retrieved') {
|
|
531
580
|
if (onToolUse) {
|
|
581
|
+
const isToolAllowed = await hasPermission(novaResponse.toolCall.toolUse.name);
|
|
582
|
+
if (!isToolAllowed) {
|
|
583
|
+
if (ait) {
|
|
584
|
+
const message = {
|
|
585
|
+
id: Date.now().toString(),
|
|
586
|
+
content: 'You have not been granted this permission for the AI agent.',
|
|
587
|
+
role: 'assistant',
|
|
588
|
+
timestamp: new Date().toISOString()
|
|
589
|
+
};
|
|
590
|
+
return message;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
532
593
|
const toolUseResult = await onToolUse(novaResponse.toolCall.toolUse);
|
|
533
594
|
if (toolUseResult) {
|
|
534
595
|
onMessage?.(toolUseResult);
|
|
@@ -628,35 +689,28 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
628
689
|
model: 'gpt-4',
|
|
629
690
|
permissions,
|
|
630
691
|
issuedBy: hitAddress,
|
|
631
|
-
controller: hitAddress
|
|
632
692
|
};
|
|
633
693
|
const metadataStr = stringify(metadata);
|
|
634
|
-
const metadataHash = ethers.keccak256(ethers.toUtf8Bytes(metadataStr
|
|
694
|
+
const metadataHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(metadataStr));
|
|
635
695
|
// 1️⃣ Upload metadata to Pinata, get CID
|
|
636
|
-
const uploadResponse = await nxtlinqApi.metadata.createMetadata(metadata,
|
|
696
|
+
const uploadResponse = await nxtlinqApi.metadata.createMetadata(metadata, nxtlinqAITServiceAccessToken || '');
|
|
637
697
|
if ('error' in uploadResponse) {
|
|
638
698
|
throw new Error(`Failed to upload metadata: ${uploadResponse.error}`);
|
|
639
699
|
}
|
|
640
700
|
const { metadataCid } = uploadResponse;
|
|
641
|
-
// 2️⃣ Sign the message
|
|
642
|
-
const messageHash = ethers.solidityPackedKeccak256(['string', 'address', 'string', 'bytes32', 'uint256'], [aitId, hitAddress, serviceId, metadataHash, timestamp]);
|
|
643
|
-
const signature = await signer.signMessage(ethers.getBytes(messageHash));
|
|
644
701
|
await nxtlinqApi.ait.createAIT({
|
|
645
702
|
aitId,
|
|
646
703
|
controller: hitAddress,
|
|
647
704
|
serviceId,
|
|
648
705
|
metadataHash,
|
|
649
706
|
metadataCid,
|
|
650
|
-
|
|
651
|
-
signature
|
|
652
|
-
}, accessToken || '');
|
|
707
|
+
}, nxtlinqAITServiceAccessToken || '');
|
|
653
708
|
const aitInfo = {
|
|
654
709
|
aitId,
|
|
655
710
|
controller: hitAddress,
|
|
656
711
|
metadata,
|
|
657
712
|
metadataHash,
|
|
658
713
|
metadataCid,
|
|
659
|
-
signature
|
|
660
714
|
};
|
|
661
715
|
setAit(aitInfo);
|
|
662
716
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,114 +1,3 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
import { AITInfo, AITMetadata, PermissionGroup, PermissionOption, WalletInfo, CreateAITParams, CreateMetadataParams, VerifyWalletParams, SignInParams } from './types/ait-api';
|
|
3
1
|
export { ChatBot } from './components/ChatBot';
|
|
4
2
|
export type { Message, PresetMessage, ToolUse, ChatBotProps } from './components/ChatBot';
|
|
5
|
-
export type { AITInfo, AITMetadata, PermissionGroup, PermissionOption, WalletInfo, CreateAITParams, CreateMetadataParams, VerifyWalletParams, SignInParams };
|
|
6
|
-
export interface AITPermission {
|
|
7
|
-
hasPermission: boolean;
|
|
8
|
-
reason?: string;
|
|
9
|
-
permissions?: string[];
|
|
10
|
-
}
|
|
11
|
-
export interface AIT {
|
|
12
|
-
aitId: string;
|
|
13
|
-
controller: string;
|
|
14
|
-
metadata: AITMetadata;
|
|
15
|
-
metadataHash: string;
|
|
16
|
-
metadataCid: string;
|
|
17
|
-
signature: string;
|
|
18
|
-
}
|
|
19
|
-
export interface GenerateAITOptions {
|
|
20
|
-
hitAddress: string;
|
|
21
|
-
signer: ethers.Signer;
|
|
22
|
-
permissions: string[];
|
|
23
|
-
serviceId: string;
|
|
24
|
-
}
|
|
25
|
-
export interface MessageResponse {
|
|
26
|
-
reply: string;
|
|
27
|
-
timestamp: string;
|
|
28
|
-
}
|
|
29
|
-
export declare class NxtlinqAITSDK {
|
|
30
|
-
private serviceId;
|
|
31
|
-
private signer;
|
|
32
|
-
private walletAddress;
|
|
33
|
-
private api;
|
|
34
|
-
constructor(serviceId: string, apiKey: string, apiSecret: string);
|
|
35
|
-
connectWallet(): Promise<string>;
|
|
36
|
-
verifyWallet(token: string, method: string): Promise<WalletInfo>;
|
|
37
|
-
signInWithWallet(): Promise<string>;
|
|
38
|
-
generateAndRegisterAIT(permissions: string[]): Promise<AITInfo>;
|
|
39
|
-
getAIT(): Promise<AITInfo | null>;
|
|
40
|
-
getWalletInfo(): Promise<WalletInfo | null>;
|
|
41
|
-
createPermissionForm(permissionGroups: PermissionGroup[]): PermissionGroup[];
|
|
42
|
-
getSelectedPermissions(form: PermissionGroup[]): string[];
|
|
43
|
-
}
|
|
44
|
-
export declare class NxtlinqAIAgent {
|
|
45
|
-
private projectId;
|
|
46
|
-
private apiKey?;
|
|
47
|
-
private ait?;
|
|
48
|
-
private permissions;
|
|
49
|
-
private signer?;
|
|
50
|
-
private api;
|
|
51
|
-
constructor(projectId: string, apiKey: string, apiSecret: string);
|
|
52
|
-
setAIT(ait: AIT, signer?: ethers.Signer): void;
|
|
53
|
-
private hasPermission;
|
|
54
|
-
private checkAITPermission;
|
|
55
|
-
generateAIT(options: GenerateAITOptions): Promise<AIT>;
|
|
56
|
-
getAITInfo(serviceId: string, controller: string, signer?: ethers.Signer): Promise<AIT | null>;
|
|
57
|
-
sendMessage(message: string, toolName?: string): Promise<MessageResponse>;
|
|
58
|
-
}
|
|
59
|
-
export interface AITApi {
|
|
60
|
-
ait: {
|
|
61
|
-
getAITByServiceIdAndController: (params: {
|
|
62
|
-
serviceId: string;
|
|
63
|
-
controller: string;
|
|
64
|
-
}, token: string) => Promise<AITInfo | {
|
|
65
|
-
error: string;
|
|
66
|
-
}>;
|
|
67
|
-
createAIT: (params: CreateAITParams, token: string) => Promise<AITInfo | {
|
|
68
|
-
error: string;
|
|
69
|
-
}>;
|
|
70
|
-
};
|
|
71
|
-
wallet: {
|
|
72
|
-
verifyWallet: (params: VerifyWalletParams, token: string) => Promise<WalletInfo | {
|
|
73
|
-
error: string;
|
|
74
|
-
}>;
|
|
75
|
-
getWallet: (params: {
|
|
76
|
-
address: string;
|
|
77
|
-
}, token: string) => Promise<WalletInfo | {
|
|
78
|
-
error: string;
|
|
79
|
-
}>;
|
|
80
|
-
};
|
|
81
|
-
metadata: {
|
|
82
|
-
createMetadata: (metadata: CreateMetadataParams, token: string) => Promise<{
|
|
83
|
-
metadataCid: string;
|
|
84
|
-
} | {
|
|
85
|
-
error: string;
|
|
86
|
-
}>;
|
|
87
|
-
};
|
|
88
|
-
auth: {
|
|
89
|
-
getNonce: (params: {
|
|
90
|
-
address: string;
|
|
91
|
-
}) => Promise<{
|
|
92
|
-
code: string;
|
|
93
|
-
timestamp: number;
|
|
94
|
-
} | {
|
|
95
|
-
error: string;
|
|
96
|
-
}>;
|
|
97
|
-
signIn: (params: SignInParams) => Promise<{
|
|
98
|
-
accessToken: string;
|
|
99
|
-
} | {
|
|
100
|
-
error: string;
|
|
101
|
-
}>;
|
|
102
|
-
};
|
|
103
|
-
agent: {
|
|
104
|
-
sendMessage: (params: {
|
|
105
|
-
message: string;
|
|
106
|
-
projectId: string;
|
|
107
|
-
}) => Promise<{
|
|
108
|
-
reply: string;
|
|
109
|
-
} | {
|
|
110
|
-
error: string;
|
|
111
|
-
}>;
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,301 +1 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
import stringify from 'json-stable-stringify';
|
|
3
|
-
import { createNxtlinqApi } from './api/nxtlinq-api';
|
|
4
1
|
export { ChatBot } from './components/ChatBot';
|
|
5
|
-
export class NxtlinqAITSDK {
|
|
6
|
-
constructor(serviceId, apiKey, apiSecret) {
|
|
7
|
-
this.signer = null;
|
|
8
|
-
this.walletAddress = null;
|
|
9
|
-
this.serviceId = serviceId;
|
|
10
|
-
this.api = createNxtlinqApi(apiKey, apiSecret);
|
|
11
|
-
}
|
|
12
|
-
async connectWallet() {
|
|
13
|
-
if (typeof window === 'undefined' || !window.ethereum) {
|
|
14
|
-
throw new Error('MetaMask is not installed');
|
|
15
|
-
}
|
|
16
|
-
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
17
|
-
this.signer = await provider.getSigner();
|
|
18
|
-
this.walletAddress = await this.signer.getAddress();
|
|
19
|
-
return this.walletAddress;
|
|
20
|
-
}
|
|
21
|
-
async verifyWallet(token, method) {
|
|
22
|
-
if (!this.walletAddress) {
|
|
23
|
-
throw new Error('Please connect wallet first');
|
|
24
|
-
}
|
|
25
|
-
const response = await this.api.wallet.verifyWallet({
|
|
26
|
-
address: this.walletAddress,
|
|
27
|
-
token,
|
|
28
|
-
method,
|
|
29
|
-
timestamp: Date.now()
|
|
30
|
-
}, token);
|
|
31
|
-
if ('error' in response) {
|
|
32
|
-
throw new Error(response.error);
|
|
33
|
-
}
|
|
34
|
-
return response;
|
|
35
|
-
}
|
|
36
|
-
async signInWithWallet() {
|
|
37
|
-
if (!this.walletAddress || !this.signer) {
|
|
38
|
-
throw new Error('Please connect wallet first');
|
|
39
|
-
}
|
|
40
|
-
const nonceResponse = await this.api.auth.getNonce({ address: this.walletAddress });
|
|
41
|
-
if ('error' in nonceResponse) {
|
|
42
|
-
throw new Error(nonceResponse.error);
|
|
43
|
-
}
|
|
44
|
-
const payload = {
|
|
45
|
-
address: this.walletAddress,
|
|
46
|
-
code: nonceResponse.code,
|
|
47
|
-
timestamp: nonceResponse.timestamp
|
|
48
|
-
};
|
|
49
|
-
const stringToSign = stringify(payload);
|
|
50
|
-
const signature = await this.signer.signMessage(stringToSign || '');
|
|
51
|
-
const response = await this.api.auth.signIn({
|
|
52
|
-
...payload,
|
|
53
|
-
signature
|
|
54
|
-
});
|
|
55
|
-
if ('error' in response) {
|
|
56
|
-
throw new Error(response.error);
|
|
57
|
-
}
|
|
58
|
-
return response.accessToken;
|
|
59
|
-
}
|
|
60
|
-
async generateAndRegisterAIT(permissions) {
|
|
61
|
-
if (!this.signer || !this.walletAddress) {
|
|
62
|
-
throw new Error('Please connect wallet first');
|
|
63
|
-
}
|
|
64
|
-
const token = localStorage.getItem('nxtlinqAITServiceAccessToken');
|
|
65
|
-
if (!token) {
|
|
66
|
-
throw new Error('Access token not found');
|
|
67
|
-
}
|
|
68
|
-
const timestamp = Math.floor(Date.now() / 1000);
|
|
69
|
-
const aitId = `did:polygon:ike-dashboard:${this.walletAddress}:${timestamp}`;
|
|
70
|
-
const metadata = {
|
|
71
|
-
model: 'gpt-4',
|
|
72
|
-
permissions,
|
|
73
|
-
issuedBy: this.walletAddress
|
|
74
|
-
};
|
|
75
|
-
const metadataStr = stringify(metadata);
|
|
76
|
-
const metadataHash = ethers.keccak256(ethers.toUtf8Bytes(metadataStr || ''));
|
|
77
|
-
// Upload metadata
|
|
78
|
-
const uploadResponse = await this.api.metadata.createMetadata({
|
|
79
|
-
...metadata,
|
|
80
|
-
controller: this.walletAddress
|
|
81
|
-
}, token);
|
|
82
|
-
if ('error' in uploadResponse) {
|
|
83
|
-
throw new Error(`Failed to upload metadata: ${uploadResponse.error}`);
|
|
84
|
-
}
|
|
85
|
-
const { metadataCid } = uploadResponse;
|
|
86
|
-
// Sign the message
|
|
87
|
-
const messageHash = ethers.solidityPackedKeccak256(['string', 'address', 'string', 'bytes32', 'uint256'], [aitId, this.walletAddress, this.serviceId, metadataHash, timestamp]);
|
|
88
|
-
const signature = await this.signer.signMessage(ethers.getBytes(messageHash));
|
|
89
|
-
// Register AIT
|
|
90
|
-
const response = await this.api.ait.createAIT({
|
|
91
|
-
aitId,
|
|
92
|
-
controller: this.walletAddress,
|
|
93
|
-
serviceId: this.serviceId,
|
|
94
|
-
metadataHash,
|
|
95
|
-
metadataCid,
|
|
96
|
-
timestamp,
|
|
97
|
-
signature
|
|
98
|
-
}, token);
|
|
99
|
-
if ('error' in response) {
|
|
100
|
-
throw new Error(response.error);
|
|
101
|
-
}
|
|
102
|
-
return response;
|
|
103
|
-
}
|
|
104
|
-
async getAIT() {
|
|
105
|
-
if (!this.walletAddress) {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
const token = localStorage.getItem('nxtlinqAITServiceAccessToken');
|
|
109
|
-
if (!token) {
|
|
110
|
-
throw new Error('Access token not found');
|
|
111
|
-
}
|
|
112
|
-
const response = await this.api.ait.getAITByServiceIdAndController({
|
|
113
|
-
serviceId: this.serviceId,
|
|
114
|
-
controller: this.walletAddress
|
|
115
|
-
}, token);
|
|
116
|
-
if ('error' in response) {
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
return response;
|
|
120
|
-
}
|
|
121
|
-
async getWalletInfo() {
|
|
122
|
-
if (!this.walletAddress) {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
const token = localStorage.getItem('nxtlinqAITServiceAccessToken');
|
|
126
|
-
if (!token) {
|
|
127
|
-
throw new Error('Access token not found');
|
|
128
|
-
}
|
|
129
|
-
const response = await this.api.wallet.getWallet({ address: this.walletAddress }, token);
|
|
130
|
-
if ('error' in response) {
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
return response;
|
|
134
|
-
}
|
|
135
|
-
createPermissionForm(permissionGroups) {
|
|
136
|
-
return permissionGroups.map(group => ({
|
|
137
|
-
label: group.label,
|
|
138
|
-
options: group.options.map((option) => ({
|
|
139
|
-
...option,
|
|
140
|
-
isChecked: false,
|
|
141
|
-
}))
|
|
142
|
-
}));
|
|
143
|
-
}
|
|
144
|
-
getSelectedPermissions(form) {
|
|
145
|
-
return form.flatMap(group => group.options.filter((opt) => opt.isChecked).map((opt) => opt.value));
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
export class NxtlinqAIAgent {
|
|
149
|
-
constructor(projectId, apiKey, apiSecret) {
|
|
150
|
-
this.permissions = [];
|
|
151
|
-
this.projectId = projectId;
|
|
152
|
-
this.apiKey = apiKey;
|
|
153
|
-
this.api = createNxtlinqApi(apiKey, apiSecret);
|
|
154
|
-
}
|
|
155
|
-
setAIT(ait, signer) {
|
|
156
|
-
this.ait = ait;
|
|
157
|
-
this.permissions = ait.metadata.permissions;
|
|
158
|
-
if (signer) {
|
|
159
|
-
this.signer = signer;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
async hasPermission(toolName) {
|
|
163
|
-
if (!this.ait) {
|
|
164
|
-
throw new Error('Please connect wallet first to access permissions');
|
|
165
|
-
}
|
|
166
|
-
return this.permissions.includes(toolName);
|
|
167
|
-
}
|
|
168
|
-
async checkAITPermission(toolName) {
|
|
169
|
-
try {
|
|
170
|
-
if (!this.ait) {
|
|
171
|
-
return {
|
|
172
|
-
hasPermission: false,
|
|
173
|
-
reason: 'Please connect wallet first to access permissions'
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
if (!toolName) {
|
|
177
|
-
return {
|
|
178
|
-
hasPermission: true,
|
|
179
|
-
permissions: this.permissions
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
const hasPermission = await this.hasPermission(toolName);
|
|
183
|
-
return {
|
|
184
|
-
hasPermission,
|
|
185
|
-
reason: hasPermission ? undefined : 'No permission to use this tool',
|
|
186
|
-
permissions: this.permissions
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
catch (error) {
|
|
190
|
-
return {
|
|
191
|
-
hasPermission: false,
|
|
192
|
-
reason: error instanceof Error ? error.message : 'Unknown error',
|
|
193
|
-
permissions: this.permissions
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
async generateAIT(options) {
|
|
198
|
-
const { hitAddress, signer, permissions, serviceId } = options;
|
|
199
|
-
const token = localStorage.getItem('nxtlinqAITServiceAccessToken');
|
|
200
|
-
if (!token) {
|
|
201
|
-
throw new Error('Access token not found');
|
|
202
|
-
}
|
|
203
|
-
const timestamp = Math.floor(Date.now() / 1000);
|
|
204
|
-
const aitId = `did:polygon:ike-dashboard:${hitAddress}:${timestamp}`;
|
|
205
|
-
const metadata = {
|
|
206
|
-
model: 'gpt-4',
|
|
207
|
-
permissions,
|
|
208
|
-
issuedBy: hitAddress
|
|
209
|
-
};
|
|
210
|
-
const metadataStr = stringify(metadata);
|
|
211
|
-
const metadataHash = ethers.keccak256(ethers.toUtf8Bytes(metadataStr || ''));
|
|
212
|
-
// Upload metadata
|
|
213
|
-
const uploadResponse = await this.api.metadata.createMetadata({
|
|
214
|
-
...metadata,
|
|
215
|
-
controller: hitAddress
|
|
216
|
-
}, token);
|
|
217
|
-
if ('error' in uploadResponse) {
|
|
218
|
-
throw new Error(`Failed to upload metadata: ${uploadResponse.error}`);
|
|
219
|
-
}
|
|
220
|
-
const { metadataCid } = uploadResponse;
|
|
221
|
-
// Sign the message
|
|
222
|
-
const messageHash = ethers.solidityPackedKeccak256(['string', 'address', 'string', 'bytes32', 'uint256'], [aitId, hitAddress, serviceId, metadataHash, timestamp]);
|
|
223
|
-
const signature = await signer.signMessage(ethers.getBytes(messageHash));
|
|
224
|
-
// Register AIT
|
|
225
|
-
const response = await this.api.ait.createAIT({
|
|
226
|
-
aitId,
|
|
227
|
-
controller: hitAddress,
|
|
228
|
-
serviceId,
|
|
229
|
-
metadataHash,
|
|
230
|
-
metadataCid,
|
|
231
|
-
timestamp,
|
|
232
|
-
signature
|
|
233
|
-
}, token);
|
|
234
|
-
if ('error' in response) {
|
|
235
|
-
throw new Error(response.error);
|
|
236
|
-
}
|
|
237
|
-
return {
|
|
238
|
-
aitId: response.aitId,
|
|
239
|
-
controller: response.controller,
|
|
240
|
-
metadata: response.metadata,
|
|
241
|
-
metadataHash: response.metadataHash,
|
|
242
|
-
metadataCid: response.metadataCid,
|
|
243
|
-
signature: response.signature
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
async getAITInfo(serviceId, controller, signer) {
|
|
247
|
-
const token = localStorage.getItem('nxtlinqAITServiceAccessToken');
|
|
248
|
-
if (!token) {
|
|
249
|
-
throw new Error('Access token not found');
|
|
250
|
-
}
|
|
251
|
-
const response = await this.api.ait.getAITByServiceIdAndController({
|
|
252
|
-
serviceId,
|
|
253
|
-
controller
|
|
254
|
-
}, token);
|
|
255
|
-
if ('error' in response) {
|
|
256
|
-
return null;
|
|
257
|
-
}
|
|
258
|
-
if (signer) {
|
|
259
|
-
this.signer = signer;
|
|
260
|
-
}
|
|
261
|
-
return {
|
|
262
|
-
aitId: response.aitId,
|
|
263
|
-
controller: response.controller,
|
|
264
|
-
metadata: response.metadata,
|
|
265
|
-
metadataHash: response.metadataHash,
|
|
266
|
-
metadataCid: response.metadataCid,
|
|
267
|
-
signature: response.signature
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
async sendMessage(message, toolName) {
|
|
271
|
-
const permission = await this.checkAITPermission(toolName);
|
|
272
|
-
if (!permission.hasPermission) {
|
|
273
|
-
throw new Error(permission.reason || 'No permission to use this tool');
|
|
274
|
-
}
|
|
275
|
-
if (!this.ait || !this.signer) {
|
|
276
|
-
throw new Error('Please connect wallet first to access permissions');
|
|
277
|
-
}
|
|
278
|
-
const timestamp = Math.floor(Date.now() / 1000);
|
|
279
|
-
const stringToSign = stringify({
|
|
280
|
-
message,
|
|
281
|
-
aitId: this.ait.aitId,
|
|
282
|
-
controller: this.ait.controller,
|
|
283
|
-
metadata: this.ait.metadata,
|
|
284
|
-
metadataHash: this.ait.metadataHash,
|
|
285
|
-
serviceId: this.projectId,
|
|
286
|
-
timestamp
|
|
287
|
-
}) || '';
|
|
288
|
-
const signature = await this.signer.signMessage(stringToSign);
|
|
289
|
-
const response = await this.api.agent.sendMessage({
|
|
290
|
-
message,
|
|
291
|
-
projectId: this.projectId,
|
|
292
|
-
});
|
|
293
|
-
if ('error' in response) {
|
|
294
|
-
throw new Error(response.error);
|
|
295
|
-
}
|
|
296
|
-
return {
|
|
297
|
-
reply: response.reply,
|
|
298
|
-
timestamp: new Date().toISOString()
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
}
|
package/dist/types/ait-api.d.ts
CHANGED
|
@@ -41,11 +41,8 @@ export interface CreateAITParams {
|
|
|
41
41
|
serviceId: string;
|
|
42
42
|
metadataHash: string;
|
|
43
43
|
metadataCid: string;
|
|
44
|
-
timestamp: number;
|
|
45
|
-
signature: string;
|
|
46
44
|
}
|
|
47
45
|
export interface CreateMetadataParams extends AITMetadata {
|
|
48
|
-
controller: string;
|
|
49
46
|
}
|
|
50
47
|
export interface VerifyWalletParams {
|
|
51
48
|
address: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ait-api.d.ts","sourceRoot":"","sources":["../../src/types/ait-api.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,WAAW,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,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,IAAI,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAA;SAAE,GAAG;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAC5G,MAAM,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC;YAAE,WAAW,EAAE,MAAM,CAAA;SAAE,GAAG;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KACxF,CAAC;IACF,KAAK,EAAE;QACL,WAAW,EAAE,CAAC,MAAM,EAAE;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAA;SAAE,KAAK,OAAO,CAAC;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,GAAG;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KACjH,CAAC;CACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytexbyte/nxtlinq-ai-agent-sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Nxtlinq AI Agent SDK - Proprietary Software",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"typescript": "^5.4.2"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"ethers": "
|
|
34
|
+
"ethers": "5.7.0",
|
|
35
35
|
"json-stable-stringify": "^1.0.2",
|
|
36
36
|
"metakeep": "^2.2.8"
|
|
37
37
|
}
|
|
@@ -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<WalletInfo>;
|
|
11
|
-
signInWithWallet: () => Promise<string>;
|
|
12
|
-
generateAndRegisterAIT: (permissions: string[]) => Promise<AITInfo>;
|
|
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
|
-
}
|