@bytexbyte/nxtlinq-ai-agent-sdk 1.0.9 → 1.1.0
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 -0
- package/dist/components/ChatBot.d.ts.map +1 -1
- package/dist/components/ChatBot.js +42 -35
- 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/index.d.ts +1 -1
- package/dist/index.js +12 -12
- package/dist/types/ait-api.d.ts +1 -1
- package/package.json +1 -1
|
@@ -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[];
|
|
@@ -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;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;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' },
|
|
@@ -216,15 +217,13 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
216
217
|
const [accessToken, setAccessToken] = React.useState(null);
|
|
217
218
|
const [walletInfo, setWalletInfo] = React.useState(null);
|
|
218
219
|
const verifyWalletBtnRef = React.useRef(null);
|
|
220
|
+
const [nxtlinqAITServiceAccessToken, setNxtlinqAITServiceAccessToken] = useLocalStorage('nxtlinqAITServiceAccessToken', '');
|
|
219
221
|
const nxtlinqApi = React.useMemo(() => createNxtlinqApi(apiKey, apiSecret), [apiKey, apiSecret]);
|
|
220
222
|
const isNeedSignInWithWallet = React.useMemo(() => {
|
|
221
223
|
if (!hitAddress) {
|
|
222
|
-
console.log('isNeedSignInWithWallet: false (no hitAddress)');
|
|
223
224
|
return false;
|
|
224
225
|
}
|
|
225
|
-
const nxtlinqAITServiceAccessToken = localStorage.getItem('nxtlinqAITServiceAccessToken');
|
|
226
226
|
if (!nxtlinqAITServiceAccessToken) {
|
|
227
|
-
console.log('isNeedSignInWithWallet: true (no token)');
|
|
228
227
|
return true;
|
|
229
228
|
}
|
|
230
229
|
try {
|
|
@@ -233,26 +232,21 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
233
232
|
const exp = payload.exp * 1000; // Convert to milliseconds
|
|
234
233
|
const now = Date.now();
|
|
235
234
|
if (exp < now) {
|
|
236
|
-
console.log('isNeedSignInWithWallet: true (token expired)');
|
|
237
235
|
return true;
|
|
238
236
|
}
|
|
239
237
|
// Check is the token's payload has the same address as the wallet address
|
|
240
238
|
const address = payload.address;
|
|
241
239
|
if (address !== hitAddress) {
|
|
242
|
-
console.log('isNeedSignInWithWallet: true (address mismatch)');
|
|
243
240
|
return true;
|
|
244
241
|
}
|
|
245
|
-
console.log('isNeedSignInWithWallet: false (valid token)');
|
|
246
242
|
return false;
|
|
247
243
|
}
|
|
248
244
|
catch (error) {
|
|
249
245
|
console.error('Error parsing token:', error);
|
|
250
|
-
console.log('isNeedSignInWithWallet: true (token parse error)');
|
|
251
246
|
return true;
|
|
252
247
|
}
|
|
253
|
-
}, [hitAddress]);
|
|
248
|
+
}, [hitAddress, nxtlinqAITServiceAccessToken]);
|
|
254
249
|
const handleVerifySuccess = (address) => {
|
|
255
|
-
console.log('handleVerifySuccess called with address:', address);
|
|
256
250
|
localStorage.setItem(`wallet_verified_${address}`, 'true');
|
|
257
251
|
const getWalletInfo = async () => {
|
|
258
252
|
try {
|
|
@@ -324,7 +318,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
324
318
|
const verifyWalletResponse = await nxtlinqApi.wallet.verifyWallet({ ...payload }, token);
|
|
325
319
|
if ('error' in verifyWalletResponse) {
|
|
326
320
|
if (verifyWalletResponse.error === 'Wallet already exists') {
|
|
327
|
-
//
|
|
321
|
+
// If wallet exists, get wallet info directly
|
|
328
322
|
const walletResponse = await nxtlinqApi.wallet.getWallet({ address }, token);
|
|
329
323
|
if (!('error' in walletResponse)) {
|
|
330
324
|
setWalletInfo(walletResponse);
|
|
@@ -333,7 +327,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
333
327
|
setAit(aitResponse);
|
|
334
328
|
}
|
|
335
329
|
}
|
|
336
|
-
//
|
|
330
|
+
// Clean up token from URL
|
|
337
331
|
if (typeof window !== 'undefined') {
|
|
338
332
|
try {
|
|
339
333
|
const url = new URL(window.location.href);
|
|
@@ -351,7 +345,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
351
345
|
setIsLoading(false);
|
|
352
346
|
return;
|
|
353
347
|
}
|
|
354
|
-
//
|
|
348
|
+
// Verification successful, get wallet info
|
|
355
349
|
const walletResponse = await nxtlinqApi.wallet.getWallet({ address }, token);
|
|
356
350
|
if (!('error' in walletResponse)) {
|
|
357
351
|
setWalletInfo(walletResponse);
|
|
@@ -360,7 +354,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
360
354
|
setAit(aitResponse);
|
|
361
355
|
}
|
|
362
356
|
}
|
|
363
|
-
//
|
|
357
|
+
// Clean up token from URL
|
|
364
358
|
if (typeof window !== 'undefined') {
|
|
365
359
|
try {
|
|
366
360
|
const url = new URL(window.location.href);
|
|
@@ -400,7 +394,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
400
394
|
throw error;
|
|
401
395
|
}
|
|
402
396
|
};
|
|
403
|
-
//
|
|
397
|
+
// Add useEffect to handle URL parameters
|
|
404
398
|
React.useEffect(() => {
|
|
405
399
|
if (typeof window !== 'undefined') {
|
|
406
400
|
try {
|
|
@@ -501,19 +495,8 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
501
495
|
return;
|
|
502
496
|
}
|
|
503
497
|
const { accessToken } = response;
|
|
504
|
-
|
|
498
|
+
setNxtlinqAITServiceAccessToken(accessToken);
|
|
505
499
|
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
500
|
}
|
|
518
501
|
catch (error) {
|
|
519
502
|
console.error('Failed to sign in:', error);
|
|
@@ -538,20 +521,44 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
538
521
|
setIsLoading(true);
|
|
539
522
|
const response = await nxtlinqApi.agent.sendMessage({
|
|
540
523
|
message: content,
|
|
541
|
-
|
|
524
|
+
projectId: projectId || ''
|
|
542
525
|
});
|
|
543
526
|
if ('error' in response) {
|
|
544
527
|
throw new Error(response.error);
|
|
545
528
|
}
|
|
546
|
-
const
|
|
529
|
+
const novaResponse = response;
|
|
530
|
+
if (novaResponse.toolCall?.toolUse && novaResponse.result !== 'Authentication data retrieved') {
|
|
531
|
+
if (onToolUse) {
|
|
532
|
+
const toolUseResult = await onToolUse(novaResponse.toolCall.toolUse);
|
|
533
|
+
if (toolUseResult) {
|
|
534
|
+
onMessage?.(toolUseResult);
|
|
535
|
+
return toolUseResult;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
if (!novaResponse.toolCall?.toolUse && novaResponse.reply) {
|
|
540
|
+
const replyText = novaResponse.reply
|
|
541
|
+
.map(item => item.text.replace(/<thinking>/g, '').replace(/<\/thinking>/g, ''))
|
|
542
|
+
.join(' ') || 'Sorry, I cannot understand your question';
|
|
543
|
+
const message = {
|
|
544
|
+
id: Date.now().toString(),
|
|
545
|
+
content: replyText,
|
|
546
|
+
role: 'assistant',
|
|
547
|
+
timestamp: new Date().toISOString()
|
|
548
|
+
};
|
|
549
|
+
setMessages(prev => [...prev, message]);
|
|
550
|
+
onMessage?.(message);
|
|
551
|
+
return message;
|
|
552
|
+
}
|
|
553
|
+
const defaultMessage = {
|
|
547
554
|
id: Date.now().toString(),
|
|
548
|
-
content:
|
|
555
|
+
content: 'Sorry, I cannot understand your question',
|
|
549
556
|
role: 'assistant',
|
|
550
557
|
timestamp: new Date().toISOString()
|
|
551
558
|
};
|
|
552
|
-
setMessages(prev => [...prev,
|
|
553
|
-
onMessage?.(
|
|
554
|
-
return
|
|
559
|
+
setMessages(prev => [...prev, defaultMessage]);
|
|
560
|
+
onMessage?.(defaultMessage);
|
|
561
|
+
return defaultMessage;
|
|
555
562
|
}
|
|
556
563
|
catch (error) {
|
|
557
564
|
if (retryCount < maxRetries) {
|
|
@@ -585,8 +592,8 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
585
592
|
setMessages(prev => [...prev, response]);
|
|
586
593
|
}
|
|
587
594
|
catch (error) {
|
|
588
|
-
console.error('
|
|
589
|
-
onError?.(error instanceof Error ? error : new Error('
|
|
595
|
+
console.error('Failed to send message:', error);
|
|
596
|
+
onError?.(error instanceof Error ? error : new Error('Failed to send message'));
|
|
590
597
|
setMessages(prev => [...prev, {
|
|
591
598
|
id: Date.now().toString(),
|
|
592
599
|
content: 'Sorry, there was an error processing your message. Please try again.',
|
|
@@ -671,7 +678,7 @@ export const ChatBot = ({ projectId, onMessage, onError, onToolUse, presetMessag
|
|
|
671
678
|
}
|
|
672
679
|
}
|
|
673
680
|
};
|
|
674
|
-
//
|
|
681
|
+
// Add state change listener
|
|
675
682
|
React.useEffect(() => {
|
|
676
683
|
console.log('States updated:', {
|
|
677
684
|
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
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -63,7 +63,7 @@ export class NxtlinqAITSDK {
|
|
|
63
63
|
}
|
|
64
64
|
const token = localStorage.getItem('nxtlinqAITServiceAccessToken');
|
|
65
65
|
if (!token) {
|
|
66
|
-
throw new Error('
|
|
66
|
+
throw new Error('Access token not found');
|
|
67
67
|
}
|
|
68
68
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
69
69
|
const aitId = `did:polygon:ike-dashboard:${this.walletAddress}:${timestamp}`;
|
|
@@ -107,7 +107,7 @@ export class NxtlinqAITSDK {
|
|
|
107
107
|
}
|
|
108
108
|
const token = localStorage.getItem('nxtlinqAITServiceAccessToken');
|
|
109
109
|
if (!token) {
|
|
110
|
-
throw new Error('
|
|
110
|
+
throw new Error('Access token not found');
|
|
111
111
|
}
|
|
112
112
|
const response = await this.api.ait.getAITByServiceIdAndController({
|
|
113
113
|
serviceId: this.serviceId,
|
|
@@ -124,7 +124,7 @@ export class NxtlinqAITSDK {
|
|
|
124
124
|
}
|
|
125
125
|
const token = localStorage.getItem('nxtlinqAITServiceAccessToken');
|
|
126
126
|
if (!token) {
|
|
127
|
-
throw new Error('
|
|
127
|
+
throw new Error('Access token not found');
|
|
128
128
|
}
|
|
129
129
|
const response = await this.api.wallet.getWallet({ address: this.walletAddress }, token);
|
|
130
130
|
if ('error' in response) {
|
|
@@ -161,7 +161,7 @@ export class NxtlinqAIAgent {
|
|
|
161
161
|
}
|
|
162
162
|
async hasPermission(toolName) {
|
|
163
163
|
if (!this.ait) {
|
|
164
|
-
throw new Error('
|
|
164
|
+
throw new Error('Please connect wallet first to access permissions');
|
|
165
165
|
}
|
|
166
166
|
return this.permissions.includes(toolName);
|
|
167
167
|
}
|
|
@@ -170,7 +170,7 @@ export class NxtlinqAIAgent {
|
|
|
170
170
|
if (!this.ait) {
|
|
171
171
|
return {
|
|
172
172
|
hasPermission: false,
|
|
173
|
-
reason: '
|
|
173
|
+
reason: 'Please connect wallet first to access permissions'
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
176
|
if (!toolName) {
|
|
@@ -182,14 +182,14 @@ export class NxtlinqAIAgent {
|
|
|
182
182
|
const hasPermission = await this.hasPermission(toolName);
|
|
183
183
|
return {
|
|
184
184
|
hasPermission,
|
|
185
|
-
reason: hasPermission ? undefined : '
|
|
185
|
+
reason: hasPermission ? undefined : 'No permission to use this tool',
|
|
186
186
|
permissions: this.permissions
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
189
|
catch (error) {
|
|
190
190
|
return {
|
|
191
191
|
hasPermission: false,
|
|
192
|
-
reason: error instanceof Error ? error.message : '
|
|
192
|
+
reason: error instanceof Error ? error.message : 'Unknown error',
|
|
193
193
|
permissions: this.permissions
|
|
194
194
|
};
|
|
195
195
|
}
|
|
@@ -198,7 +198,7 @@ export class NxtlinqAIAgent {
|
|
|
198
198
|
const { hitAddress, signer, permissions, serviceId } = options;
|
|
199
199
|
const token = localStorage.getItem('nxtlinqAITServiceAccessToken');
|
|
200
200
|
if (!token) {
|
|
201
|
-
throw new Error('
|
|
201
|
+
throw new Error('Access token not found');
|
|
202
202
|
}
|
|
203
203
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
204
204
|
const aitId = `did:polygon:ike-dashboard:${hitAddress}:${timestamp}`;
|
|
@@ -246,7 +246,7 @@ export class NxtlinqAIAgent {
|
|
|
246
246
|
async getAITInfo(serviceId, controller, signer) {
|
|
247
247
|
const token = localStorage.getItem('nxtlinqAITServiceAccessToken');
|
|
248
248
|
if (!token) {
|
|
249
|
-
throw new Error('
|
|
249
|
+
throw new Error('Access token not found');
|
|
250
250
|
}
|
|
251
251
|
const response = await this.api.ait.getAITByServiceIdAndController({
|
|
252
252
|
serviceId,
|
|
@@ -270,10 +270,10 @@ export class NxtlinqAIAgent {
|
|
|
270
270
|
async sendMessage(message, toolName) {
|
|
271
271
|
const permission = await this.checkAITPermission(toolName);
|
|
272
272
|
if (!permission.hasPermission) {
|
|
273
|
-
throw new Error(permission.reason || '
|
|
273
|
+
throw new Error(permission.reason || 'No permission to use this tool');
|
|
274
274
|
}
|
|
275
275
|
if (!this.ait || !this.signer) {
|
|
276
|
-
throw new Error('
|
|
276
|
+
throw new Error('Please connect wallet first to access permissions');
|
|
277
277
|
}
|
|
278
278
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
279
279
|
const stringToSign = stringify({
|
|
@@ -288,7 +288,7 @@ export class NxtlinqAIAgent {
|
|
|
288
288
|
const signature = await this.signer.signMessage(stringToSign);
|
|
289
289
|
const response = await this.api.agent.sendMessage({
|
|
290
290
|
message,
|
|
291
|
-
|
|
291
|
+
projectId: this.projectId,
|
|
292
292
|
});
|
|
293
293
|
if ('error' in response) {
|
|
294
294
|
throw new Error(response.error);
|
package/dist/types/ait-api.d.ts
CHANGED