@bytexbyte/nxtlinq-ai-agent-sdk 1.1.1 → 1.1.3
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/api/nxtlinq-api.d.ts.map +1 -1
- package/dist/api/nxtlinq-api.js +23 -0
- package/dist/components/ChatBot.d.ts +3 -18
- package/dist/components/ChatBot.d.ts.map +1 -1
- package/dist/components/ChatBot.js +96 -27
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/types/ait-api.d.ts +26 -3
- package/dist/types/ait-api.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/hooks/useNxtlinqAIT.d.ts +0 -14
- package/dist/hooks/useNxtlinqAIT.d.ts.map +0 -1
- package/dist/hooks/useNxtlinqAIT.js +0 -98
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nxtlinq-api.d.ts","sourceRoot":"","sources":["../../src/api/nxtlinq-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAK1C,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"nxtlinq-api.d.ts","sourceRoot":"","sources":["../../src/api/nxtlinq-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAK1C,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,KAAG,MAmJpE,CAAC"}
|
package/dist/api/nxtlinq-api.js
CHANGED
|
@@ -119,6 +119,29 @@ export const createNxtlinqApi = (apiKey, apiSecret) => {
|
|
|
119
119
|
return { error: error instanceof Error ? error.message : 'Failed to send message' };
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
+
},
|
|
123
|
+
permissions: {
|
|
124
|
+
getServicePermissions: async (params) => {
|
|
125
|
+
try {
|
|
126
|
+
const response = await fetch(`${AI_AGENT_API_HOST}/api/permissions/service/${params.serviceId}`, {
|
|
127
|
+
method: 'GET',
|
|
128
|
+
headers: {
|
|
129
|
+
'X-API-Key': apiKey,
|
|
130
|
+
'X-API-Secret': apiSecret,
|
|
131
|
+
'Content-Type': 'application/json',
|
|
132
|
+
...getAuthHeader()
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
if (!response.ok) {
|
|
136
|
+
throw new Error('Failed to fetch permissions');
|
|
137
|
+
}
|
|
138
|
+
return await response.json();
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
console.error('Failed to fetch permissions:', error);
|
|
142
|
+
return { error: error instanceof Error ? error.message : 'Failed to fetch permissions' };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
122
145
|
}
|
|
123
146
|
};
|
|
124
147
|
};
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
id: string;
|
|
4
|
-
content: string;
|
|
5
|
-
role: 'user' | 'assistant';
|
|
6
|
-
timestamp: string;
|
|
7
|
-
button?: boolean;
|
|
8
|
-
error?: string;
|
|
9
|
-
}
|
|
2
|
+
import { Message } from '../types/ait-api';
|
|
10
3
|
export interface PresetMessage {
|
|
11
4
|
text: string;
|
|
12
5
|
autoSend?: boolean;
|
|
@@ -33,15 +26,7 @@ export interface AITMetadata {
|
|
|
33
26
|
permissions: string[];
|
|
34
27
|
issuedBy: string;
|
|
35
28
|
}
|
|
36
|
-
export interface AIT {
|
|
37
|
-
aitId: string;
|
|
38
|
-
controller: string;
|
|
39
|
-
metadata: AITMetadata;
|
|
40
|
-
metadataHash: string;
|
|
41
|
-
metadataCid: string;
|
|
42
|
-
}
|
|
43
29
|
export interface ChatBotProps {
|
|
44
|
-
projectId?: string;
|
|
45
30
|
onMessage?: (message: Message) => void;
|
|
46
31
|
onError?: (error: Error) => void;
|
|
47
32
|
onToolUse?: (toolUse: ToolUse) => Promise<Message | void>;
|
|
@@ -53,9 +38,9 @@ export interface ChatBotProps {
|
|
|
53
38
|
serviceId: string;
|
|
54
39
|
apiKey: string;
|
|
55
40
|
apiSecret: string;
|
|
56
|
-
onVerifyWallet?: (
|
|
41
|
+
onVerifyWallet?: () => Promise<{
|
|
57
42
|
token: string;
|
|
58
|
-
}>;
|
|
43
|
+
} | undefined>;
|
|
59
44
|
}
|
|
60
45
|
export declare const ChatBot: React.FC<ChatBotProps>;
|
|
61
46
|
//# 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;
|
|
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;CAChB;AAsVD,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CA62B1C,CAAC"}
|
|
@@ -5,13 +5,26 @@ 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 }) => {
|
|
9
|
-
const availablePermissions = [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
const PermissionForm = ({ hitAddress, permissions, setPermissions, setIsDisabled, onClose, onSave, onConnectWallet, onSignIn, isNeedSignInWithWallet, walletInfo, onVerifyWallet, serviceId, nxtlinqApi }) => {
|
|
9
|
+
const [availablePermissions, setAvailablePermissions] = React.useState([]);
|
|
10
|
+
React.useEffect(() => {
|
|
11
|
+
const fetchPermissions = async () => {
|
|
12
|
+
if (!serviceId)
|
|
13
|
+
return;
|
|
14
|
+
try {
|
|
15
|
+
const result = await nxtlinqApi.permissions.getServicePermissions({ serviceId });
|
|
16
|
+
if ('error' in result) {
|
|
17
|
+
console.error('Failed to fetch permissions:', result.error);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
setAvailablePermissions(result.permissions);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
console.error('Error fetching permissions:', error);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
fetchPermissions();
|
|
27
|
+
}, [serviceId, nxtlinqApi]);
|
|
15
28
|
const isWalletVerified = walletInfo?.id;
|
|
16
29
|
return (_jsxs("div", { style: {
|
|
17
30
|
backgroundColor: 'white',
|
|
@@ -200,7 +213,7 @@ const PermissionForm = ({ hitAddress, permissions, setPermissions, setIsDisabled
|
|
|
200
213
|
}
|
|
201
214
|
}, children: "Save" })] })] }))] }));
|
|
202
215
|
};
|
|
203
|
-
export const ChatBot = ({
|
|
216
|
+
export const ChatBot = ({ onMessage, onError, onToolUse, presetMessages = [], placeholder = 'Type a message...', className = '', maxRetries = 3, retryDelay = 1000, serviceId, apiKey, apiSecret, onVerifyWallet }) => {
|
|
204
217
|
const [messages, setMessages] = React.useState([]);
|
|
205
218
|
const [inputValue, setInputValue] = React.useState('');
|
|
206
219
|
const [isLoading, setIsLoading] = React.useState(false);
|
|
@@ -213,11 +226,47 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
213
226
|
const messagesEndRef = React.useRef(null);
|
|
214
227
|
const [isDisabled, setIsDisabled] = React.useState(true);
|
|
215
228
|
const [signer, setSigner] = React.useState(null);
|
|
216
|
-
const [accessToken, setAccessToken] = React.useState(null);
|
|
217
229
|
const [walletInfo, setWalletInfo] = React.useState(null);
|
|
218
230
|
const verifyWalletBtnRef = React.useRef(null);
|
|
219
231
|
const [nxtlinqAITServiceAccessToken, setNxtlinqAITServiceAccessToken] = useLocalStorage('nxtlinqAITServiceAccessToken', '');
|
|
220
232
|
const nxtlinqApi = React.useMemo(() => createNxtlinqApi(apiKey, apiSecret), [apiKey, apiSecret]);
|
|
233
|
+
const refreshAIT = async () => {
|
|
234
|
+
console.log('refreshAIT called');
|
|
235
|
+
console.log('hitAddress:', hitAddress);
|
|
236
|
+
console.log('nxtlinqAITServiceAccessToken:', nxtlinqAITServiceAccessToken);
|
|
237
|
+
if (!hitAddress) {
|
|
238
|
+
setAit(null);
|
|
239
|
+
setPermissions([]);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
const response = await nxtlinqApi.ait.getAITByServiceIdAndController({
|
|
244
|
+
serviceId,
|
|
245
|
+
controller: hitAddress
|
|
246
|
+
}, nxtlinqAITServiceAccessToken || '');
|
|
247
|
+
if ('error' in response) {
|
|
248
|
+
console.error('Failed to fetch AIT:', response.error);
|
|
249
|
+
setAit(null);
|
|
250
|
+
setPermissions([]);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
console.log('AIT response:', response);
|
|
254
|
+
setAit(response);
|
|
255
|
+
setPermissions(response.metadata?.permissions || []);
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
console.error('Failed to fetch AIT:', error);
|
|
259
|
+
setAit(null);
|
|
260
|
+
setPermissions([]);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
React.useEffect(() => {
|
|
264
|
+
console.log('hitAddress:', hitAddress);
|
|
265
|
+
console.log('nxtlinqAITServiceAccessToken:', nxtlinqAITServiceAccessToken);
|
|
266
|
+
if (hitAddress && nxtlinqAITServiceAccessToken) {
|
|
267
|
+
refreshAIT();
|
|
268
|
+
}
|
|
269
|
+
}, [hitAddress, nxtlinqAITServiceAccessToken]);
|
|
221
270
|
const isNeedSignInWithWallet = React.useMemo(() => {
|
|
222
271
|
if (!hitAddress) {
|
|
223
272
|
return false;
|
|
@@ -278,7 +327,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
278
327
|
if (isNeedSignInWithWallet) {
|
|
279
328
|
return;
|
|
280
329
|
}
|
|
281
|
-
const getWalletResponse = await nxtlinqApi.wallet.getWallet({ address: hitAddress },
|
|
330
|
+
const getWalletResponse = await nxtlinqApi.wallet.getWallet({ address: hitAddress }, nxtlinqAITServiceAccessToken);
|
|
282
331
|
if ('error' in getWalletResponse) {
|
|
283
332
|
if (getWalletResponse.error === 'Wallet not found') {
|
|
284
333
|
console.log('Wallet not found - this is expected for new users');
|
|
@@ -306,8 +355,12 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
306
355
|
try {
|
|
307
356
|
if (onVerifyWallet) {
|
|
308
357
|
setIsLoading(true);
|
|
309
|
-
const result = await onVerifyWallet(
|
|
358
|
+
const result = await onVerifyWallet();
|
|
310
359
|
console.log('Verify wallet response:', result);
|
|
360
|
+
if (!result) {
|
|
361
|
+
setIsLoading(false);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
311
364
|
const { token } = result;
|
|
312
365
|
const address = hitAddress;
|
|
313
366
|
if (token && address) {
|
|
@@ -342,6 +395,8 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
342
395
|
}
|
|
343
396
|
}
|
|
344
397
|
setIsLoading(false);
|
|
398
|
+
// Refresh AIT after wallet verification
|
|
399
|
+
refreshAIT();
|
|
345
400
|
return { token, hitAddress: address };
|
|
346
401
|
}
|
|
347
402
|
alert(verifyWalletResponse.error);
|
|
@@ -369,6 +424,8 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
369
424
|
}
|
|
370
425
|
}
|
|
371
426
|
setIsLoading(false);
|
|
427
|
+
// Refresh AIT after wallet verification
|
|
428
|
+
refreshAIT();
|
|
372
429
|
return { token, hitAddress: address };
|
|
373
430
|
}
|
|
374
431
|
catch (error) {
|
|
@@ -455,6 +512,10 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
455
512
|
localStorage.setItem('walletAddress', userAddress);
|
|
456
513
|
setHitAddress(userAddress);
|
|
457
514
|
setSigner(userSigner);
|
|
515
|
+
// Refresh AIT after connecting wallet
|
|
516
|
+
if (nxtlinqAITServiceAccessToken) {
|
|
517
|
+
refreshAIT();
|
|
518
|
+
}
|
|
458
519
|
return userAddress;
|
|
459
520
|
}
|
|
460
521
|
catch (error) {
|
|
@@ -464,7 +525,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
464
525
|
setSigner(null);
|
|
465
526
|
throw error;
|
|
466
527
|
}
|
|
467
|
-
}, []);
|
|
528
|
+
}, [nxtlinqAITServiceAccessToken, refreshAIT]);
|
|
468
529
|
const signInWallet = async () => {
|
|
469
530
|
if (!hitAddress) {
|
|
470
531
|
alert('Please connect your wallet first.');
|
|
@@ -497,7 +558,8 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
497
558
|
}
|
|
498
559
|
const { accessToken } = response;
|
|
499
560
|
setNxtlinqAITServiceAccessToken(accessToken);
|
|
500
|
-
|
|
561
|
+
// Refresh AIT after signing in
|
|
562
|
+
refreshAIT();
|
|
501
563
|
}
|
|
502
564
|
catch (error) {
|
|
503
565
|
console.error('Failed to sign in:', error);
|
|
@@ -522,7 +584,8 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
522
584
|
setIsLoading(true);
|
|
523
585
|
const response = await nxtlinqApi.agent.sendMessage({
|
|
524
586
|
message: content,
|
|
525
|
-
|
|
587
|
+
apiKey,
|
|
588
|
+
apiSecret,
|
|
526
589
|
});
|
|
527
590
|
if ('error' in response) {
|
|
528
591
|
throw new Error(response.error);
|
|
@@ -539,12 +602,13 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
539
602
|
role: 'assistant',
|
|
540
603
|
timestamp: new Date().toISOString()
|
|
541
604
|
};
|
|
605
|
+
setMessages(prev => [...prev, message]);
|
|
542
606
|
return message;
|
|
543
607
|
}
|
|
544
608
|
}
|
|
545
609
|
const toolUseResult = await onToolUse(novaResponse.toolCall.toolUse);
|
|
546
610
|
if (toolUseResult) {
|
|
547
|
-
|
|
611
|
+
setMessages(prev => [...prev, toolUseResult]);
|
|
548
612
|
return toolUseResult;
|
|
549
613
|
}
|
|
550
614
|
}
|
|
@@ -560,7 +624,6 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
560
624
|
timestamp: new Date().toISOString()
|
|
561
625
|
};
|
|
562
626
|
setMessages(prev => [...prev, message]);
|
|
563
|
-
onMessage?.(message);
|
|
564
627
|
return message;
|
|
565
628
|
}
|
|
566
629
|
const defaultMessage = {
|
|
@@ -570,7 +633,6 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
570
633
|
timestamp: new Date().toISOString()
|
|
571
634
|
};
|
|
572
635
|
setMessages(prev => [...prev, defaultMessage]);
|
|
573
|
-
onMessage?.(defaultMessage);
|
|
574
636
|
return defaultMessage;
|
|
575
637
|
}
|
|
576
638
|
catch (error) {
|
|
@@ -602,17 +664,17 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
602
664
|
if (response.error) {
|
|
603
665
|
throw new Error(response.error);
|
|
604
666
|
}
|
|
605
|
-
setMessages(prev => [...prev, response]);
|
|
606
667
|
}
|
|
607
668
|
catch (error) {
|
|
608
669
|
console.error('Failed to send message:', error);
|
|
609
670
|
onError?.(error instanceof Error ? error : new Error('Failed to send message'));
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
671
|
+
const errorMessage = {
|
|
672
|
+
id: Date.now().toString(),
|
|
673
|
+
content: 'Sorry, there was an error processing your message. Please try again.',
|
|
674
|
+
role: 'assistant',
|
|
675
|
+
timestamp: new Date().toISOString()
|
|
676
|
+
};
|
|
677
|
+
setMessages(prev => [...prev, errorMessage]);
|
|
616
678
|
}
|
|
617
679
|
finally {
|
|
618
680
|
setIsLoading(false);
|
|
@@ -645,7 +707,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
645
707
|
const metadataStr = stringify(metadata);
|
|
646
708
|
const metadataHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(metadataStr));
|
|
647
709
|
// 1️⃣ Upload metadata to Pinata, get CID
|
|
648
|
-
const uploadResponse = await nxtlinqApi.metadata.createMetadata(metadata,
|
|
710
|
+
const uploadResponse = await nxtlinqApi.metadata.createMetadata(metadata, nxtlinqAITServiceAccessToken || '');
|
|
649
711
|
if ('error' in uploadResponse) {
|
|
650
712
|
throw new Error(`Failed to upload metadata: ${uploadResponse.error}`);
|
|
651
713
|
}
|
|
@@ -656,7 +718,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
656
718
|
serviceId,
|
|
657
719
|
metadataHash,
|
|
658
720
|
metadataCid,
|
|
659
|
-
},
|
|
721
|
+
}, nxtlinqAITServiceAccessToken || '');
|
|
660
722
|
const aitInfo = {
|
|
661
723
|
aitId,
|
|
662
724
|
controller: hitAddress,
|
|
@@ -693,6 +755,13 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
693
755
|
isOpen
|
|
694
756
|
});
|
|
695
757
|
}, [hitAddress, isNeedSignInWithWallet, walletInfo, isOpen]);
|
|
758
|
+
// Add useEffect to monitor message changes
|
|
759
|
+
React.useEffect(() => {
|
|
760
|
+
if (messages.length > 0) {
|
|
761
|
+
const lastMessage = messages[messages.length - 1];
|
|
762
|
+
onMessage?.(lastMessage);
|
|
763
|
+
}
|
|
764
|
+
}, [messages, onMessage]);
|
|
696
765
|
return (_jsxs("div", { style: {
|
|
697
766
|
position: 'fixed',
|
|
698
767
|
bottom: '20px',
|
|
@@ -828,7 +897,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
828
897
|
alignItems: 'center',
|
|
829
898
|
justifyContent: 'center',
|
|
830
899
|
zIndex: 2000
|
|
831
|
-
}, children: _jsx(PermissionForm, { hitAddress: hitAddress, permissions: permissions, setPermissions: setPermissions, setIsDisabled: setIsDisabled, onClose: () => setShowPermissionForm(false), onConnectWallet: connectWallet, onSignIn: signInWallet, onSave: savePermissions, isNeedSignInWithWallet: isNeedSignInWithWallet, walletInfo: walletInfo, onVerifyWallet: handleVerifyWalletClick }) })), success && (_jsxs("div", { style: {
|
|
900
|
+
}, children: _jsx(PermissionForm, { hitAddress: hitAddress, permissions: permissions, setPermissions: setPermissions, setIsDisabled: setIsDisabled, onClose: () => setShowPermissionForm(false), onConnectWallet: connectWallet, onSignIn: signInWallet, onSave: savePermissions, isNeedSignInWithWallet: isNeedSignInWithWallet, walletInfo: walletInfo, onVerifyWallet: handleVerifyWalletClick, serviceId: serviceId, nxtlinqApi: nxtlinqApi }) })), success && (_jsxs("div", { style: {
|
|
832
901
|
position: 'fixed',
|
|
833
902
|
bottom: 100,
|
|
834
903
|
right: 40,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type { PresetMessage, ToolUse, ChatBotProps } from './components/ChatBot';
|
|
1
2
|
export { ChatBot } from './components/ChatBot';
|
|
2
|
-
export type { Message,
|
|
3
|
+
export type { Message, AIT, ServicePermission, AITApi } from './types/ait-api';
|
|
3
4
|
//# 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,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,YAAY,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,YAAY,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/types/ait-api.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
export interface Message {
|
|
2
|
+
id: string;
|
|
3
|
+
content: string;
|
|
4
|
+
role: 'user' | 'assistant';
|
|
5
|
+
timestamp: string;
|
|
6
|
+
button?: boolean;
|
|
7
|
+
error?: string;
|
|
8
|
+
}
|
|
1
9
|
export interface AIT {
|
|
2
10
|
aitId: string;
|
|
3
11
|
controller: string;
|
|
4
12
|
metadata: AITMetadata;
|
|
5
13
|
metadataHash: string;
|
|
6
14
|
metadataCid: string;
|
|
7
|
-
signature: string;
|
|
8
15
|
}
|
|
9
16
|
export interface AITMetadata {
|
|
10
17
|
model: string;
|
|
@@ -62,10 +69,16 @@ export interface MessageContext {
|
|
|
62
69
|
}
|
|
63
70
|
export interface SendMessageParams {
|
|
64
71
|
message: string;
|
|
65
|
-
|
|
72
|
+
apiKey: string;
|
|
73
|
+
apiSecret: string;
|
|
66
74
|
serviceId: string;
|
|
67
75
|
context: MessageContext;
|
|
68
76
|
}
|
|
77
|
+
export interface ServicePermission {
|
|
78
|
+
id: string;
|
|
79
|
+
label: string;
|
|
80
|
+
description: string;
|
|
81
|
+
}
|
|
69
82
|
export interface AITApi {
|
|
70
83
|
ait: {
|
|
71
84
|
getAITByServiceIdAndController: (params: {
|
|
@@ -113,12 +126,22 @@ export interface AITApi {
|
|
|
113
126
|
agent: {
|
|
114
127
|
sendMessage: (params: {
|
|
115
128
|
message: string;
|
|
116
|
-
|
|
129
|
+
apiKey: string;
|
|
130
|
+
apiSecret: string;
|
|
117
131
|
}) => Promise<{
|
|
118
132
|
reply: string;
|
|
119
133
|
} | {
|
|
120
134
|
error: string;
|
|
121
135
|
}>;
|
|
122
136
|
};
|
|
137
|
+
permissions: {
|
|
138
|
+
getServicePermissions: (params: {
|
|
139
|
+
serviceId: string;
|
|
140
|
+
}) => Promise<{
|
|
141
|
+
permissions: ServicePermission[];
|
|
142
|
+
} | {
|
|
143
|
+
error: string;
|
|
144
|
+
}>;
|
|
145
|
+
};
|
|
123
146
|
}
|
|
124
147
|
//# sourceMappingURL=ait-api.d.ts.map
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"ait-api.d.ts","sourceRoot":"","sources":["../../src/types/ait-api.ts"],"names":[],"mappings":"AAAA,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,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;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;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AAM,KAAK,OAAO,CAAC;YAAE,WAAW,EAAE,MAAM,CAAA;SAAE,GAAG;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KACzH,CAAC;IACF,IAAI,EAAE;QACJ,QAAQ,EAAE,CAAC,MAAM,EAAE;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,KAAK,OAAO,CAAC;YAAE,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,MAAM,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;KACjI,CAAC;IACF,WAAW,EAAE;QACX,qBAAqB,EAAE,CAAC,MAAM,EAAE;YAAE,SAAS,EAAE,MAAM,CAAA;SAAE,KAAK,OAAO,CAAC;YAAE,WAAW,EAAE,iBAAiB,EAAE,CAAA;SAAE,GAAG;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAC7H,CAAC;CACH"}
|
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
|
-
}
|