@bytexbyte/nxtlinq-ai-agent-sdk 1.0.9 → 1.1.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.
- package/dist/api/nxtlinq-api.d.ts.map +1 -1
- package/dist/api/nxtlinq-api.js +5 -7
- package/dist/components/ChatBot.d.ts +13 -1
- package/dist/components/ChatBot.d.ts.map +1 -1
- package/dist/components/ChatBot.js +60 -47
- package/dist/core/lib/useLocalStorage.d.ts +3 -0
- package/dist/core/lib/useLocalStorage.d.ts.map +1 -0
- package/dist/core/lib/useLocalStorage.js +18 -0
- package/dist/hooks/useNxtlinqAIT.d.ts +3 -3
- 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 +1 -4
- package/dist/types/ait-api.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -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,MA2HpE,CAAC"}
|
package/dist/api/nxtlinq-api.js
CHANGED
|
@@ -102,23 +102,21 @@ export const createNxtlinqApi = (apiKey, apiSecret) => {
|
|
|
102
102
|
agent: {
|
|
103
103
|
sendMessage: async (params) => {
|
|
104
104
|
try {
|
|
105
|
-
const response = await fetch(`${AI_AGENT_API_HOST}/api/
|
|
105
|
+
const response = await fetch(`${AI_AGENT_API_HOST}/api/nova`, {
|
|
106
106
|
method: 'POST',
|
|
107
107
|
headers: {
|
|
108
|
-
'X-API-Key': apiKey,
|
|
109
|
-
'X-API-Secret': apiSecret,
|
|
110
108
|
'Content-Type': 'application/json',
|
|
111
|
-
...getAuthHeader()
|
|
112
109
|
},
|
|
113
|
-
body: JSON.stringify(params)
|
|
110
|
+
body: JSON.stringify(params),
|
|
114
111
|
});
|
|
115
112
|
if (!response.ok) {
|
|
116
|
-
throw new Error('
|
|
113
|
+
throw new Error('Failed to send message');
|
|
117
114
|
}
|
|
118
115
|
return await response.json();
|
|
119
116
|
}
|
|
120
117
|
catch (error) {
|
|
121
|
-
|
|
118
|
+
console.error('Failed to send message:', error);
|
|
119
|
+
return { error: error instanceof Error ? error.message : 'Failed to send message' };
|
|
122
120
|
}
|
|
123
121
|
}
|
|
124
122
|
}
|
|
@@ -15,6 +15,19 @@ export interface ToolUse {
|
|
|
15
15
|
name: string;
|
|
16
16
|
input: Record<string, any>;
|
|
17
17
|
}
|
|
18
|
+
export interface ToolCall {
|
|
19
|
+
toolUse: ToolUse;
|
|
20
|
+
}
|
|
21
|
+
export interface NovaResponse {
|
|
22
|
+
result: string;
|
|
23
|
+
reply: Array<{
|
|
24
|
+
text: string;
|
|
25
|
+
}>;
|
|
26
|
+
toolCall?: ToolCall;
|
|
27
|
+
}
|
|
28
|
+
export interface NovaError {
|
|
29
|
+
error: string;
|
|
30
|
+
}
|
|
18
31
|
export interface AITMetadata {
|
|
19
32
|
model: string;
|
|
20
33
|
permissions: string[];
|
|
@@ -26,7 +39,6 @@ export interface AIT {
|
|
|
26
39
|
metadata: AITMetadata;
|
|
27
40
|
metadataHash: string;
|
|
28
41
|
metadataCid: string;
|
|
29
|
-
signature: string;
|
|
30
42
|
}
|
|
31
43
|
export interface ChatBotProps {
|
|
32
44
|
projectId?: string;
|
|
@@ -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;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,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,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,YAAY;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,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,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;QAC5C,KAAK,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;CACJ;AAsUD,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAgzB1C,CAAC"}
|
|
@@ -4,6 +4,7 @@ import { ethers } from 'ethers';
|
|
|
4
4
|
import { createNxtlinqApi } from '../api/nxtlinq-api';
|
|
5
5
|
import stringify from 'fast-json-stable-stringify';
|
|
6
6
|
import metakeepClient from '../core/metakeepClient';
|
|
7
|
+
import useLocalStorage from '../core/lib/useLocalStorage';
|
|
7
8
|
const PermissionForm = ({ hitAddress, permissions, setPermissions, setIsDisabled, onClose, onSave, onConnectWallet, onSignIn, isNeedSignInWithWallet, walletInfo, onVerifyWallet }) => {
|
|
8
9
|
const availablePermissions = [
|
|
9
10
|
{ id: 'setUserName', label: 'Set User Name' },
|
|
@@ -212,19 +213,16 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
212
213
|
const messagesEndRef = React.useRef(null);
|
|
213
214
|
const [isDisabled, setIsDisabled] = React.useState(true);
|
|
214
215
|
const [signer, setSigner] = React.useState(null);
|
|
215
|
-
const [provider, setProvider] = React.useState(null);
|
|
216
216
|
const [accessToken, setAccessToken] = React.useState(null);
|
|
217
217
|
const [walletInfo, setWalletInfo] = React.useState(null);
|
|
218
218
|
const verifyWalletBtnRef = React.useRef(null);
|
|
219
|
+
const [nxtlinqAITServiceAccessToken, setNxtlinqAITServiceAccessToken] = useLocalStorage('nxtlinqAITServiceAccessToken', '');
|
|
219
220
|
const nxtlinqApi = React.useMemo(() => createNxtlinqApi(apiKey, apiSecret), [apiKey, apiSecret]);
|
|
220
221
|
const isNeedSignInWithWallet = React.useMemo(() => {
|
|
221
222
|
if (!hitAddress) {
|
|
222
|
-
console.log('isNeedSignInWithWallet: false (no hitAddress)');
|
|
223
223
|
return false;
|
|
224
224
|
}
|
|
225
|
-
const nxtlinqAITServiceAccessToken = localStorage.getItem('nxtlinqAITServiceAccessToken');
|
|
226
225
|
if (!nxtlinqAITServiceAccessToken) {
|
|
227
|
-
console.log('isNeedSignInWithWallet: true (no token)');
|
|
228
226
|
return true;
|
|
229
227
|
}
|
|
230
228
|
try {
|
|
@@ -233,26 +231,21 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
233
231
|
const exp = payload.exp * 1000; // Convert to milliseconds
|
|
234
232
|
const now = Date.now();
|
|
235
233
|
if (exp < now) {
|
|
236
|
-
console.log('isNeedSignInWithWallet: true (token expired)');
|
|
237
234
|
return true;
|
|
238
235
|
}
|
|
239
236
|
// Check is the token's payload has the same address as the wallet address
|
|
240
237
|
const address = payload.address;
|
|
241
238
|
if (address !== hitAddress) {
|
|
242
|
-
console.log('isNeedSignInWithWallet: true (address mismatch)');
|
|
243
239
|
return true;
|
|
244
240
|
}
|
|
245
|
-
console.log('isNeedSignInWithWallet: false (valid token)');
|
|
246
241
|
return false;
|
|
247
242
|
}
|
|
248
243
|
catch (error) {
|
|
249
244
|
console.error('Error parsing token:', error);
|
|
250
|
-
console.log('isNeedSignInWithWallet: true (token parse error)');
|
|
251
245
|
return true;
|
|
252
246
|
}
|
|
253
|
-
}, [hitAddress]);
|
|
247
|
+
}, [hitAddress, nxtlinqAITServiceAccessToken]);
|
|
254
248
|
const handleVerifySuccess = (address) => {
|
|
255
|
-
console.log('handleVerifySuccess called with address:', address);
|
|
256
249
|
localStorage.setItem(`wallet_verified_${address}`, 'true');
|
|
257
250
|
const getWalletInfo = async () => {
|
|
258
251
|
try {
|
|
@@ -287,6 +280,10 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
287
280
|
}
|
|
288
281
|
const getWalletResponse = await nxtlinqApi.wallet.getWallet({ address: hitAddress }, accessToken);
|
|
289
282
|
if ('error' in getWalletResponse) {
|
|
283
|
+
if (getWalletResponse.error === 'Wallet not found') {
|
|
284
|
+
console.log('Wallet not found - this is expected for new users');
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
290
287
|
console.error(getWalletResponse.error);
|
|
291
288
|
return;
|
|
292
289
|
}
|
|
@@ -324,7 +321,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
324
321
|
const verifyWalletResponse = await nxtlinqApi.wallet.verifyWallet({ ...payload }, token);
|
|
325
322
|
if ('error' in verifyWalletResponse) {
|
|
326
323
|
if (verifyWalletResponse.error === 'Wallet already exists') {
|
|
327
|
-
//
|
|
324
|
+
// If wallet exists, get wallet info directly
|
|
328
325
|
const walletResponse = await nxtlinqApi.wallet.getWallet({ address }, token);
|
|
329
326
|
if (!('error' in walletResponse)) {
|
|
330
327
|
setWalletInfo(walletResponse);
|
|
@@ -333,7 +330,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
333
330
|
setAit(aitResponse);
|
|
334
331
|
}
|
|
335
332
|
}
|
|
336
|
-
//
|
|
333
|
+
// Clean up token from URL
|
|
337
334
|
if (typeof window !== 'undefined') {
|
|
338
335
|
try {
|
|
339
336
|
const url = new URL(window.location.href);
|
|
@@ -351,7 +348,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
351
348
|
setIsLoading(false);
|
|
352
349
|
return;
|
|
353
350
|
}
|
|
354
|
-
//
|
|
351
|
+
// Verification successful, get wallet info
|
|
355
352
|
const walletResponse = await nxtlinqApi.wallet.getWallet({ address }, token);
|
|
356
353
|
if (!('error' in walletResponse)) {
|
|
357
354
|
setWalletInfo(walletResponse);
|
|
@@ -360,7 +357,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
360
357
|
setAit(aitResponse);
|
|
361
358
|
}
|
|
362
359
|
}
|
|
363
|
-
//
|
|
360
|
+
// Clean up token from URL
|
|
364
361
|
if (typeof window !== 'undefined') {
|
|
365
362
|
try {
|
|
366
363
|
const url = new URL(window.location.href);
|
|
@@ -400,7 +397,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
400
397
|
throw error;
|
|
401
398
|
}
|
|
402
399
|
};
|
|
403
|
-
//
|
|
400
|
+
// Add useEffect to handle URL parameters
|
|
404
401
|
React.useEffect(() => {
|
|
405
402
|
if (typeof window !== 'undefined') {
|
|
406
403
|
try {
|
|
@@ -452,13 +449,12 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
452
449
|
throw new Error('Web3 provider not available');
|
|
453
450
|
}
|
|
454
451
|
await web3Provider.enable();
|
|
455
|
-
const ethersProvider = new ethers.
|
|
452
|
+
const ethersProvider = new ethers.providers.Web3Provider(web3Provider);
|
|
456
453
|
const userSigner = await ethersProvider.getSigner();
|
|
457
454
|
const userAddress = await userSigner.getAddress();
|
|
458
455
|
localStorage.setItem('walletAddress', userAddress);
|
|
459
456
|
setHitAddress(userAddress);
|
|
460
457
|
setSigner(userSigner);
|
|
461
|
-
setProvider(ethersProvider);
|
|
462
458
|
return userAddress;
|
|
463
459
|
}
|
|
464
460
|
catch (error) {
|
|
@@ -466,7 +462,6 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
466
462
|
localStorage.removeItem('walletAddress');
|
|
467
463
|
setHitAddress(null);
|
|
468
464
|
setSigner(null);
|
|
469
|
-
setProvider(null);
|
|
470
465
|
throw error;
|
|
471
466
|
}
|
|
472
467
|
}, []);
|
|
@@ -501,19 +496,8 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
501
496
|
return;
|
|
502
497
|
}
|
|
503
498
|
const { accessToken } = response;
|
|
504
|
-
|
|
499
|
+
setNxtlinqAITServiceAccessToken(accessToken);
|
|
505
500
|
setAccessToken(accessToken);
|
|
506
|
-
// 登录成功后,获取 AIT 信息
|
|
507
|
-
try {
|
|
508
|
-
const token = JSON.parse(localStorage.getItem('nxtlinqAITServiceAccessToken') || '');
|
|
509
|
-
const aitResponse = await nxtlinqApi.ait.getAITByServiceIdAndController({ serviceId, controller: hitAddress }, token);
|
|
510
|
-
if (!('error' in aitResponse)) {
|
|
511
|
-
setAit(aitResponse);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
catch (error) {
|
|
515
|
-
console.error('Failed to get AIT:', error);
|
|
516
|
-
}
|
|
517
501
|
}
|
|
518
502
|
catch (error) {
|
|
519
503
|
console.error('Failed to sign in:', error);
|
|
@@ -538,20 +522,56 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
538
522
|
setIsLoading(true);
|
|
539
523
|
const response = await nxtlinqApi.agent.sendMessage({
|
|
540
524
|
message: content,
|
|
541
|
-
|
|
525
|
+
projectId: projectId || ''
|
|
542
526
|
});
|
|
543
527
|
if ('error' in response) {
|
|
544
528
|
throw new Error(response.error);
|
|
545
529
|
}
|
|
546
|
-
const
|
|
530
|
+
const novaResponse = response;
|
|
531
|
+
if (novaResponse.toolCall?.toolUse && novaResponse.result !== 'Authentication data retrieved') {
|
|
532
|
+
if (onToolUse) {
|
|
533
|
+
const isToolAllowed = await hasPermission(novaResponse.toolCall.toolUse.name);
|
|
534
|
+
if (!isToolAllowed) {
|
|
535
|
+
if (ait) {
|
|
536
|
+
const message = {
|
|
537
|
+
id: Date.now().toString(),
|
|
538
|
+
content: 'You have not been granted this permission for the AI agent.',
|
|
539
|
+
role: 'assistant',
|
|
540
|
+
timestamp: new Date().toISOString()
|
|
541
|
+
};
|
|
542
|
+
return message;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
const toolUseResult = await onToolUse(novaResponse.toolCall.toolUse);
|
|
546
|
+
if (toolUseResult) {
|
|
547
|
+
onMessage?.(toolUseResult);
|
|
548
|
+
return toolUseResult;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
if (!novaResponse.toolCall?.toolUse && novaResponse.reply) {
|
|
553
|
+
const replyText = novaResponse.reply
|
|
554
|
+
.map(item => item.text.replace(/<thinking>/g, '').replace(/<\/thinking>/g, ''))
|
|
555
|
+
.join(' ') || 'Sorry, I cannot understand your question';
|
|
556
|
+
const message = {
|
|
557
|
+
id: Date.now().toString(),
|
|
558
|
+
content: replyText,
|
|
559
|
+
role: 'assistant',
|
|
560
|
+
timestamp: new Date().toISOString()
|
|
561
|
+
};
|
|
562
|
+
setMessages(prev => [...prev, message]);
|
|
563
|
+
onMessage?.(message);
|
|
564
|
+
return message;
|
|
565
|
+
}
|
|
566
|
+
const defaultMessage = {
|
|
547
567
|
id: Date.now().toString(),
|
|
548
|
-
content:
|
|
568
|
+
content: 'Sorry, I cannot understand your question',
|
|
549
569
|
role: 'assistant',
|
|
550
570
|
timestamp: new Date().toISOString()
|
|
551
571
|
};
|
|
552
|
-
setMessages(prev => [...prev,
|
|
553
|
-
onMessage?.(
|
|
554
|
-
return
|
|
572
|
+
setMessages(prev => [...prev, defaultMessage]);
|
|
573
|
+
onMessage?.(defaultMessage);
|
|
574
|
+
return defaultMessage;
|
|
555
575
|
}
|
|
556
576
|
catch (error) {
|
|
557
577
|
if (retryCount < maxRetries) {
|
|
@@ -585,8 +605,8 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
585
605
|
setMessages(prev => [...prev, response]);
|
|
586
606
|
}
|
|
587
607
|
catch (error) {
|
|
588
|
-
console.error('
|
|
589
|
-
onError?.(error instanceof Error ? error : new Error('
|
|
608
|
+
console.error('Failed to send message:', error);
|
|
609
|
+
onError?.(error instanceof Error ? error : new Error('Failed to send message'));
|
|
590
610
|
setMessages(prev => [...prev, {
|
|
591
611
|
id: Date.now().toString(),
|
|
592
612
|
content: 'Sorry, there was an error processing your message. Please try again.',
|
|
@@ -621,27 +641,21 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
621
641
|
model: 'gpt-4',
|
|
622
642
|
permissions,
|
|
623
643
|
issuedBy: hitAddress,
|
|
624
|
-
controller: hitAddress
|
|
625
644
|
};
|
|
626
645
|
const metadataStr = stringify(metadata);
|
|
627
|
-
const metadataHash = ethers.keccak256(ethers.toUtf8Bytes(metadataStr
|
|
646
|
+
const metadataHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(metadataStr));
|
|
628
647
|
// 1️⃣ Upload metadata to Pinata, get CID
|
|
629
648
|
const uploadResponse = await nxtlinqApi.metadata.createMetadata(metadata, accessToken || '');
|
|
630
649
|
if ('error' in uploadResponse) {
|
|
631
650
|
throw new Error(`Failed to upload metadata: ${uploadResponse.error}`);
|
|
632
651
|
}
|
|
633
652
|
const { metadataCid } = uploadResponse;
|
|
634
|
-
// 2️⃣ Sign the message
|
|
635
|
-
const messageHash = ethers.solidityPackedKeccak256(['string', 'address', 'string', 'bytes32', 'uint256'], [aitId, hitAddress, serviceId, metadataHash, timestamp]);
|
|
636
|
-
const signature = await signer.signMessage(ethers.getBytes(messageHash));
|
|
637
653
|
await nxtlinqApi.ait.createAIT({
|
|
638
654
|
aitId,
|
|
639
655
|
controller: hitAddress,
|
|
640
656
|
serviceId,
|
|
641
657
|
metadataHash,
|
|
642
658
|
metadataCid,
|
|
643
|
-
timestamp,
|
|
644
|
-
signature
|
|
645
659
|
}, accessToken || '');
|
|
646
660
|
const aitInfo = {
|
|
647
661
|
aitId,
|
|
@@ -649,7 +663,6 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
649
663
|
metadata,
|
|
650
664
|
metadataHash,
|
|
651
665
|
metadataCid,
|
|
652
|
-
signature
|
|
653
666
|
};
|
|
654
667
|
setAit(aitInfo);
|
|
655
668
|
};
|
|
@@ -671,7 +684,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
671
684
|
}
|
|
672
685
|
}
|
|
673
686
|
};
|
|
674
|
-
//
|
|
687
|
+
// Add state change listener
|
|
675
688
|
React.useEffect(() => {
|
|
676
689
|
console.log('States updated:', {
|
|
677
690
|
hitAddress,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocalStorage.d.ts","sourceRoot":"","sources":["../../../src/core/lib/useLocalStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAuB,MAAM,OAAO,CAAC;AAEtE,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAoBlH"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
export default function useLocalStorage(key, defaultValue) {
|
|
3
|
+
const [storedValue, setStoredValue] = useState(defaultValue);
|
|
4
|
+
const [isInitialized, setIsInitialized] = useState(false);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
const storageValue = localStorage.getItem(key);
|
|
7
|
+
if (storageValue) {
|
|
8
|
+
setStoredValue(JSON.parse(storageValue));
|
|
9
|
+
}
|
|
10
|
+
setIsInitialized(true);
|
|
11
|
+
}, [key]);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (isInitialized) {
|
|
14
|
+
localStorage.setItem(key, JSON.stringify(storedValue));
|
|
15
|
+
}
|
|
16
|
+
}, [storedValue, isInitialized, key]);
|
|
17
|
+
return [storedValue, setStoredValue, isInitialized];
|
|
18
|
+
}
|
|
@@ -7,8 +7,8 @@ export declare function useNxtlinqAIT(sdk: NxtlinqAITSDK): {
|
|
|
7
7
|
isLoading: boolean;
|
|
8
8
|
error: string | null;
|
|
9
9
|
connectWallet: () => Promise<void>;
|
|
10
|
-
verifyWallet: (token: string, method: string) => Promise<
|
|
11
|
-
signInWithWallet: () => Promise<
|
|
12
|
-
generateAndRegisterAIT: (permissions: string[]) => Promise<
|
|
10
|
+
verifyWallet: (token: string, method: string) => Promise<any>;
|
|
11
|
+
signInWithWallet: () => Promise<any>;
|
|
12
|
+
generateAndRegisterAIT: (permissions: string[]) => Promise<any>;
|
|
13
13
|
};
|
|
14
14
|
//# sourceMappingURL=useNxtlinqAIT.d.ts.map
|
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
|
-
serviceId: 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('未找到访问令牌');
|
|
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('未找到访问令牌');
|
|
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('未找到访问令牌');
|
|
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('请先连接钱包以访问权限');
|
|
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: '请先连接钱包以访问权限'
|
|
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 : '没有权限使用该工具',
|
|
186
|
-
permissions: this.permissions
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
catch (error) {
|
|
190
|
-
return {
|
|
191
|
-
hasPermission: false,
|
|
192
|
-
reason: error instanceof Error ? error.message : '未知错误',
|
|
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('未找到访问令牌');
|
|
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('未找到访问令牌');
|
|
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 || '没有权限使用该工具');
|
|
274
|
-
}
|
|
275
|
-
if (!this.ait || !this.signer) {
|
|
276
|
-
throw new Error('请先连接钱包以访问权限');
|
|
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
|
-
serviceId: 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;
|
|
@@ -116,7 +113,7 @@ export interface AITApi {
|
|
|
116
113
|
agent: {
|
|
117
114
|
sendMessage: (params: {
|
|
118
115
|
message: string;
|
|
119
|
-
|
|
116
|
+
projectId: string;
|
|
120
117
|
}) => Promise<{
|
|
121
118
|
reply: string;
|
|
122
119
|
} | {
|
|
@@ -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,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,OAAO;IACtB,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,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,gBAAgB,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,YAA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"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
|
}
|