@bytexbyte/nxtlinq-ai-agent-sdk 1.0.6 → 1.0.7

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/index.js CHANGED
@@ -1,26 +1,19 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.NxtlinqAIAgent = exports.NxtlinqAITSDK = exports.ChatBot = void 0;
7
- const ethers_1 = require("ethers");
8
- const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
9
- const nxtlinq_api_js_1 = require("./api/nxtlinq-api.js");
10
- var ChatBot_1 = require("./components/ChatBot");
11
- Object.defineProperty(exports, "ChatBot", { enumerable: true, get: function () { return ChatBot_1.ChatBot; } });
12
- class NxtlinqAITSDK {
1
+ import { ethers } from 'ethers';
2
+ import stringify from 'json-stable-stringify';
3
+ import { createNxtlinqApi } from './api/nxtlinq-api';
4
+ export { ChatBot } from './components/ChatBot';
5
+ export class NxtlinqAITSDK {
13
6
  constructor(serviceId, apiKey, apiSecret) {
14
7
  this.signer = null;
15
8
  this.walletAddress = null;
16
9
  this.serviceId = serviceId;
17
- this.api = (0, nxtlinq_api_js_1.createNxtlinqApi)(apiKey, apiSecret);
10
+ this.api = createNxtlinqApi(apiKey, apiSecret);
18
11
  }
19
12
  async connectWallet() {
20
13
  if (typeof window === 'undefined' || !window.ethereum) {
21
14
  throw new Error('MetaMask is not installed');
22
15
  }
23
- const provider = new ethers_1.ethers.BrowserProvider(window.ethereum);
16
+ const provider = new ethers.BrowserProvider(window.ethereum);
24
17
  this.signer = await provider.getSigner();
25
18
  this.walletAddress = await this.signer.getAddress();
26
19
  return this.walletAddress;
@@ -53,7 +46,7 @@ class NxtlinqAITSDK {
53
46
  code: nonceResponse.code,
54
47
  timestamp: nonceResponse.timestamp
55
48
  };
56
- const stringToSign = (0, json_stable_stringify_1.default)(payload);
49
+ const stringToSign = stringify(payload);
57
50
  const signature = await this.signer.signMessage(stringToSign || '');
58
51
  const response = await this.api.auth.signIn({
59
52
  ...payload,
@@ -79,8 +72,8 @@ class NxtlinqAITSDK {
79
72
  permissions,
80
73
  issuedBy: this.walletAddress
81
74
  };
82
- const metadataStr = (0, json_stable_stringify_1.default)(metadata);
83
- const metadataHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(metadataStr || ''));
75
+ const metadataStr = stringify(metadata);
76
+ const metadataHash = ethers.keccak256(ethers.toUtf8Bytes(metadataStr || ''));
84
77
  // Upload metadata
85
78
  const uploadResponse = await this.api.metadata.createMetadata({
86
79
  ...metadata,
@@ -91,8 +84,8 @@ class NxtlinqAITSDK {
91
84
  }
92
85
  const { metadataCid } = uploadResponse;
93
86
  // Sign the message
94
- const messageHash = ethers_1.ethers.solidityPackedKeccak256(['string', 'address', 'string', 'bytes32', 'uint256'], [aitId, this.walletAddress, this.serviceId, metadataHash, timestamp]);
95
- const signature = await this.signer.signMessage(ethers_1.ethers.getBytes(messageHash));
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));
96
89
  // Register AIT
97
90
  const response = await this.api.ait.createAIT({
98
91
  aitId,
@@ -152,13 +145,12 @@ class NxtlinqAITSDK {
152
145
  return form.flatMap(group => group.options.filter((opt) => opt.isChecked).map((opt) => opt.value));
153
146
  }
154
147
  }
155
- exports.NxtlinqAITSDK = NxtlinqAITSDK;
156
- class NxtlinqAIAgent {
148
+ export class NxtlinqAIAgent {
157
149
  constructor(projectId, apiKey, apiSecret) {
158
150
  this.permissions = [];
159
151
  this.projectId = projectId;
160
152
  this.apiKey = apiKey;
161
- this.api = (0, nxtlinq_api_js_1.createNxtlinqApi)(apiKey, apiSecret);
153
+ this.api = createNxtlinqApi(apiKey, apiSecret);
162
154
  }
163
155
  setAIT(ait, signer) {
164
156
  this.ait = ait;
@@ -215,8 +207,8 @@ class NxtlinqAIAgent {
215
207
  permissions,
216
208
  issuedBy: hitAddress
217
209
  };
218
- const metadataStr = (0, json_stable_stringify_1.default)(metadata);
219
- const metadataHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(metadataStr || ''));
210
+ const metadataStr = stringify(metadata);
211
+ const metadataHash = ethers.keccak256(ethers.toUtf8Bytes(metadataStr || ''));
220
212
  // Upload metadata
221
213
  const uploadResponse = await this.api.metadata.createMetadata({
222
214
  ...metadata,
@@ -227,8 +219,8 @@ class NxtlinqAIAgent {
227
219
  }
228
220
  const { metadataCid } = uploadResponse;
229
221
  // Sign the message
230
- const messageHash = ethers_1.ethers.solidityPackedKeccak256(['string', 'address', 'string', 'bytes32', 'uint256'], [aitId, hitAddress, serviceId, metadataHash, timestamp]);
231
- const signature = await signer.signMessage(ethers_1.ethers.getBytes(messageHash));
222
+ const messageHash = ethers.solidityPackedKeccak256(['string', 'address', 'string', 'bytes32', 'uint256'], [aitId, hitAddress, serviceId, metadataHash, timestamp]);
223
+ const signature = await signer.signMessage(ethers.getBytes(messageHash));
232
224
  // Register AIT
233
225
  const response = await this.api.ait.createAIT({
234
226
  aitId,
@@ -284,7 +276,7 @@ class NxtlinqAIAgent {
284
276
  throw new Error('请先连接钱包以访问权限');
285
277
  }
286
278
  const timestamp = Math.floor(Date.now() / 1000);
287
- const stringToSign = (0, json_stable_stringify_1.default)({
279
+ const stringToSign = stringify({
288
280
  message,
289
281
  aitId: this.ait.aitId,
290
282
  controller: this.ait.controller,
@@ -307,4 +299,3 @@ class NxtlinqAIAgent {
307
299
  };
308
300
  }
309
301
  }
310
- exports.NxtlinqAIAgent = NxtlinqAIAgent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytexbyte/nxtlinq-ai-agent-sdk",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Nxtlinq AI Agent SDK - Proprietary Software",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,15 +1,17 @@
1
+ import { AITApi } from '../types/ait-api';
2
+
1
3
  const AI_AGENT_API_HOST = 'https://ai-agent.nxtlinq.ai';
2
4
  const AIT_SERVICE_API_HOST = 'https://staging-ait-service.nxtlinq.ai';
3
5
 
4
- export const createNxtlinqApi = (apiKey, apiSecret) => {
5
- const getAuthHeader = () => {
6
+ export const createNxtlinqApi = (apiKey: string, apiSecret: string): AITApi => {
7
+ const getAuthHeader = (): Record<string, string> => {
6
8
  const token = localStorage.getItem('nxtlinqAITServiceAccessToken');
7
9
  return token ? { 'Authorization': `Bearer ${JSON.parse(token)}` } : {};
8
10
  };
9
11
 
10
12
  return {
11
13
  ait: {
12
- getAITByServiceIdAndController: async (params, token) => {
14
+ getAITByServiceIdAndController: async (params: { serviceId: string; controller: string }, token: string) => {
13
15
  const response = await fetch(`${AIT_SERVICE_API_HOST}/api/ait/service/${params.serviceId}/controller/${params.controller}`, {
14
16
  method: 'GET',
15
17
  headers: {
@@ -20,7 +22,7 @@ export const createNxtlinqApi = (apiKey, apiSecret) => {
20
22
  });
21
23
  return response.json();
22
24
  },
23
- createAIT: async (params, token) => {
25
+ createAIT: async (params: any, token: string) => {
24
26
  const response = await fetch(`${AIT_SERVICE_API_HOST}/api/ait`, {
25
27
  method: 'POST',
26
28
  headers: {
@@ -35,7 +37,7 @@ export const createNxtlinqApi = (apiKey, apiSecret) => {
35
37
  }
36
38
  },
37
39
  wallet: {
38
- verifyWallet: async (params, token) => {
40
+ verifyWallet: async (params: any, token: string) => {
39
41
  const response = await fetch(`${AIT_SERVICE_API_HOST}/api/wallet`, {
40
42
  method: 'POST',
41
43
  headers: {
@@ -48,7 +50,7 @@ export const createNxtlinqApi = (apiKey, apiSecret) => {
48
50
  });
49
51
  return response.json();
50
52
  },
51
- getWallet: async (params, token) => {
53
+ getWallet: async (params: { address: string }, token: string) => {
52
54
  const response = await fetch(`${AIT_SERVICE_API_HOST}/api/wallet/address/${params.address}`, {
53
55
  method: 'GET',
54
56
  headers: {
@@ -61,7 +63,7 @@ export const createNxtlinqApi = (apiKey, apiSecret) => {
61
63
  }
62
64
  },
63
65
  metadata: {
64
- createMetadata: async (metadata, token) => {
66
+ createMetadata: async (metadata: any, token: string) => {
65
67
  const response = await fetch(`${AIT_SERVICE_API_HOST}/api/metadata`, {
66
68
  method: 'POST',
67
69
  headers: {
@@ -76,7 +78,7 @@ export const createNxtlinqApi = (apiKey, apiSecret) => {
76
78
  }
77
79
  },
78
80
  auth: {
79
- getNonce: async (params) => {
81
+ getNonce: async (params: { address: string }) => {
80
82
  const response = await fetch(`${AIT_SERVICE_API_HOST}/api/auth/address/${params.address}/nonce`, {
81
83
  method: 'GET',
82
84
  headers: {
@@ -87,7 +89,7 @@ export const createNxtlinqApi = (apiKey, apiSecret) => {
87
89
  });
88
90
  return response.json();
89
91
  },
90
- signIn: async (params) => {
92
+ signIn: async (params: any) => {
91
93
  const response = await fetch(`${AIT_SERVICE_API_HOST}/api/auth`, {
92
94
  method: 'POST',
93
95
  headers: {
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ethers } from 'ethers';
2
2
  import stringify from 'json-stable-stringify';
3
3
  import { AITInfo, AITMetadata, PermissionGroup, PermissionOption, WalletInfo, CreateAITParams, CreateMetadataParams, VerifyWalletParams, SignInParams } from './types/ait-api';
4
- import { createNxtlinqApi } from './api/nxtlinq-api.js';
4
+ import { createNxtlinqApi } from './api/nxtlinq-api';
5
5
 
6
6
  export { ChatBot } from './components/ChatBot';
7
7
  export type { Message, PresetMessage, ToolUse, ChatBotProps } from './components/ChatBot';
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2020",
4
- "module": "CommonJS",
4
+ "module": "ESNext",
5
5
  "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
6
  "declaration": true,
7
7
  "outDir": "dist",
@@ -1,24 +0,0 @@
1
- import { AITInfo, CreateAITParams, CreateMetadataParams, VerifyWalletParams, SignInParams, WalletInfo } from '../types/ait-api';
2
-
3
- export interface AITApi {
4
- ait: {
5
- getAITByServiceIdAndController: (params: { serviceId: string; controller: string }, token: string) => Promise<AITInfo | { error: string }>;
6
- createAIT: (params: CreateAITParams, token: string) => Promise<AITInfo | { error: string }>;
7
- };
8
- wallet: {
9
- verifyWallet: (params: VerifyWalletParams, token: string) => Promise<WalletInfo | { error: string }>;
10
- getWallet: (params: { address: string }, token: string) => Promise<WalletInfo | { error: string }>;
11
- };
12
- metadata: {
13
- createMetadata: (metadata: CreateMetadataParams, token: string) => Promise<{ metadataCid: string } | { error: string }>;
14
- };
15
- auth: {
16
- getNonce: (params: { address: string }) => Promise<{ code: string; timestamp: number } | { error: string }>;
17
- signIn: (params: SignInParams) => Promise<{ accessToken: string } | { error: string }>;
18
- };
19
- agent: {
20
- sendMessage: (params: { message: string; serviceId: string }) => Promise<{ reply: string } | { error: string }>;
21
- };
22
- }
23
-
24
- export function createNxtlinqApi(apiKey: string, apiSecret: string): AITApi;