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

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,6 +1,131 @@
1
1
  import { ethers } from 'ethers';
2
2
  import stringify from 'json-stable-stringify';
3
- import { createNxtlinqApi } from './api/nxtlinq-api';
3
+ const AI_AGENT_API_HOST = 'https://ai-agent.nxtlinq.ai';
4
+ const AIT_SERVICE_API_HOST = 'https://staging-ait-service.nxtlinq.ai';
5
+ export const createNxtlinqApi = (apiKey, apiSecret) => {
6
+ const getAuthHeader = () => {
7
+ const token = localStorage.getItem('nxtlinqAITServiceAccessToken');
8
+ return token ? { 'Authorization': `Bearer ${JSON.parse(token)}` } : {};
9
+ };
10
+ return {
11
+ ait: {
12
+ getAITByServiceIdAndController: async (params, token) => {
13
+ const response = await fetch(`${AIT_SERVICE_API_HOST}/api/ait/service/${params.serviceId}/controller/${params.controller}`, {
14
+ method: 'GET',
15
+ headers: {
16
+ 'X-API-Key': apiKey,
17
+ 'X-API-Secret': apiSecret,
18
+ ...getAuthHeader()
19
+ }
20
+ });
21
+ return response.json();
22
+ },
23
+ createAIT: async (params, token) => {
24
+ const response = await fetch(`${AIT_SERVICE_API_HOST}/api/ait`, {
25
+ method: 'POST',
26
+ headers: {
27
+ 'X-API-Key': apiKey,
28
+ 'X-API-Secret': apiSecret,
29
+ 'Content-Type': 'application/json',
30
+ ...getAuthHeader()
31
+ },
32
+ body: JSON.stringify(params)
33
+ });
34
+ return response.json();
35
+ }
36
+ },
37
+ wallet: {
38
+ verifyWallet: async (params, token) => {
39
+ const response = await fetch(`${AIT_SERVICE_API_HOST}/api/wallet`, {
40
+ method: 'POST',
41
+ headers: {
42
+ 'X-API-Key': apiKey,
43
+ 'X-API-Secret': apiSecret,
44
+ 'Content-Type': 'application/json',
45
+ ...getAuthHeader()
46
+ },
47
+ body: JSON.stringify(params)
48
+ });
49
+ return response.json();
50
+ },
51
+ getWallet: async (params, token) => {
52
+ const response = await fetch(`${AIT_SERVICE_API_HOST}/api/wallet/address/${params.address}`, {
53
+ method: 'GET',
54
+ headers: {
55
+ 'X-API-Key': apiKey,
56
+ 'X-API-Secret': apiSecret,
57
+ ...getAuthHeader()
58
+ }
59
+ });
60
+ return response.json();
61
+ }
62
+ },
63
+ metadata: {
64
+ createMetadata: async (metadata, token) => {
65
+ const response = await fetch(`${AIT_SERVICE_API_HOST}/api/metadata`, {
66
+ method: 'POST',
67
+ headers: {
68
+ 'X-API-Key': apiKey,
69
+ 'X-API-Secret': apiSecret,
70
+ 'Content-Type': 'application/json',
71
+ ...getAuthHeader()
72
+ },
73
+ body: JSON.stringify(metadata)
74
+ });
75
+ return response.json();
76
+ }
77
+ },
78
+ auth: {
79
+ getNonce: async (params) => {
80
+ const response = await fetch(`${AIT_SERVICE_API_HOST}/api/auth/address/${params.address}/nonce`, {
81
+ method: 'GET',
82
+ headers: {
83
+ 'X-API-Key': apiKey,
84
+ 'X-API-Secret': apiSecret,
85
+ ...getAuthHeader()
86
+ }
87
+ });
88
+ return response.json();
89
+ },
90
+ signIn: async (params) => {
91
+ const response = await fetch(`${AIT_SERVICE_API_HOST}/api/auth`, {
92
+ method: 'POST',
93
+ headers: {
94
+ 'X-API-Key': apiKey,
95
+ 'X-API-Secret': apiSecret,
96
+ 'Content-Type': 'application/json',
97
+ ...getAuthHeader()
98
+ },
99
+ body: JSON.stringify(params)
100
+ });
101
+ return response.json();
102
+ }
103
+ },
104
+ agent: {
105
+ sendMessage: async (params) => {
106
+ try {
107
+ const response = await fetch(`${AI_AGENT_API_HOST}/api/agent/message`, {
108
+ method: 'POST',
109
+ headers: {
110
+ 'X-API-Key': apiKey,
111
+ 'X-API-Secret': apiSecret,
112
+ 'Content-Type': 'application/json',
113
+ ...getAuthHeader()
114
+ },
115
+ body: JSON.stringify(params)
116
+ });
117
+ if (!response.ok) {
118
+ throw new Error('发送消息失败');
119
+ }
120
+ return await response.json();
121
+ }
122
+ catch (error) {
123
+ return { error: error instanceof Error ? error.message : '发送消息失败' };
124
+ }
125
+ }
126
+ }
127
+ };
128
+ };
4
129
  export { ChatBot } from './components/ChatBot';
5
130
  export class NxtlinqAITSDK {
6
131
  constructor(serviceId, apiKey, apiSecret) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytexbyte/nxtlinq-ai-agent-sdk",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Nxtlinq AI Agent SDK - Proprietary Software",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { ethers } from 'ethers';
3
- import { createNxtlinqApi } from '../api/nxtlinq-api';
3
+ import { createNxtlinqApi } from '../index';
4
4
  import stringify from 'fast-json-stable-stringify';
5
5
  import metakeepClient from '../core/metakeepClient';
6
6
 
package/src/index.ts CHANGED
@@ -1,7 +1,136 @@
1
1
  import { ethers } from 'ethers';
2
2
  import stringify from 'json-stable-stringify';
3
- import { AITInfo, AITMetadata, PermissionGroup, PermissionOption, WalletInfo, CreateAITParams, CreateMetadataParams, VerifyWalletParams, SignInParams } from './types/ait-api';
4
- import { createNxtlinqApi } from './api/nxtlinq-api';
3
+ import { AITInfo, AITMetadata, PermissionGroup, PermissionOption, WalletInfo, CreateAITParams, CreateMetadataParams, VerifyWalletParams, SignInParams, AITApi } from './types/ait-api';
4
+
5
+ const AI_AGENT_API_HOST = 'https://ai-agent.nxtlinq.ai';
6
+ const AIT_SERVICE_API_HOST = 'https://staging-ait-service.nxtlinq.ai';
7
+
8
+ export const createNxtlinqApi = (apiKey: string, apiSecret: string): AITApi => {
9
+ const getAuthHeader = (): Record<string, string> => {
10
+ const token = localStorage.getItem('nxtlinqAITServiceAccessToken');
11
+ return token ? { 'Authorization': `Bearer ${JSON.parse(token)}` } : {};
12
+ };
13
+
14
+ return {
15
+ ait: {
16
+ getAITByServiceIdAndController: async (params: { serviceId: string; controller: string }, token: string) => {
17
+ const response = await fetch(`${AIT_SERVICE_API_HOST}/api/ait/service/${params.serviceId}/controller/${params.controller}`, {
18
+ method: 'GET',
19
+ headers: {
20
+ 'X-API-Key': apiKey,
21
+ 'X-API-Secret': apiSecret,
22
+ ...getAuthHeader()
23
+ }
24
+ });
25
+ return response.json();
26
+ },
27
+ createAIT: async (params: any, token: string) => {
28
+ const response = await fetch(`${AIT_SERVICE_API_HOST}/api/ait`, {
29
+ method: 'POST',
30
+ headers: {
31
+ 'X-API-Key': apiKey,
32
+ 'X-API-Secret': apiSecret,
33
+ 'Content-Type': 'application/json',
34
+ ...getAuthHeader()
35
+ },
36
+ body: JSON.stringify(params)
37
+ });
38
+ return response.json();
39
+ }
40
+ },
41
+ wallet: {
42
+ verifyWallet: async (params: any, token: string) => {
43
+ const response = await fetch(`${AIT_SERVICE_API_HOST}/api/wallet`, {
44
+ method: 'POST',
45
+ headers: {
46
+ 'X-API-Key': apiKey,
47
+ 'X-API-Secret': apiSecret,
48
+ 'Content-Type': 'application/json',
49
+ ...getAuthHeader()
50
+ },
51
+ body: JSON.stringify(params)
52
+ });
53
+ return response.json();
54
+ },
55
+ getWallet: async (params: { address: string }, token: string) => {
56
+ const response = await fetch(`${AIT_SERVICE_API_HOST}/api/wallet/address/${params.address}`, {
57
+ method: 'GET',
58
+ headers: {
59
+ 'X-API-Key': apiKey,
60
+ 'X-API-Secret': apiSecret,
61
+ ...getAuthHeader()
62
+ }
63
+ });
64
+ return response.json();
65
+ }
66
+ },
67
+ metadata: {
68
+ createMetadata: async (metadata: any, token: string) => {
69
+ const response = await fetch(`${AIT_SERVICE_API_HOST}/api/metadata`, {
70
+ method: 'POST',
71
+ headers: {
72
+ 'X-API-Key': apiKey,
73
+ 'X-API-Secret': apiSecret,
74
+ 'Content-Type': 'application/json',
75
+ ...getAuthHeader()
76
+ },
77
+ body: JSON.stringify(metadata)
78
+ });
79
+ return response.json();
80
+ }
81
+ },
82
+ auth: {
83
+ getNonce: async (params: { address: string }) => {
84
+ const response = await fetch(`${AIT_SERVICE_API_HOST}/api/auth/address/${params.address}/nonce`, {
85
+ method: 'GET',
86
+ headers: {
87
+ 'X-API-Key': apiKey,
88
+ 'X-API-Secret': apiSecret,
89
+ ...getAuthHeader()
90
+ }
91
+ });
92
+ return response.json();
93
+ },
94
+ signIn: async (params: any) => {
95
+ const response = await fetch(`${AIT_SERVICE_API_HOST}/api/auth`, {
96
+ method: 'POST',
97
+ headers: {
98
+ 'X-API-Key': apiKey,
99
+ 'X-API-Secret': apiSecret,
100
+ 'Content-Type': 'application/json',
101
+ ...getAuthHeader()
102
+ },
103
+ body: JSON.stringify(params)
104
+ });
105
+ return response.json();
106
+ }
107
+ },
108
+ agent: {
109
+ sendMessage: async (params) => {
110
+ try {
111
+ const response = await fetch(`${AI_AGENT_API_HOST}/api/agent/message`, {
112
+ method: 'POST',
113
+ headers: {
114
+ 'X-API-Key': apiKey,
115
+ 'X-API-Secret': apiSecret,
116
+ 'Content-Type': 'application/json',
117
+ ...getAuthHeader()
118
+ },
119
+ body: JSON.stringify(params)
120
+ });
121
+
122
+ if (!response.ok) {
123
+ throw new Error('发送消息失败');
124
+ }
125
+
126
+ return await response.json();
127
+ } catch (error) {
128
+ return { error: error instanceof Error ? error.message : '发送消息失败' };
129
+ }
130
+ }
131
+ }
132
+ };
133
+ };
5
134
 
6
135
  export { ChatBot } from './components/ChatBot';
7
136
  export type { Message, PresetMessage, ToolUse, ChatBotProps } from './components/ChatBot';
@@ -425,25 +554,4 @@ export class NxtlinqAIAgent {
425
554
  timestamp: new Date().toISOString()
426
555
  };
427
556
  }
428
- }
429
-
430
- export interface AITApi {
431
- ait: {
432
- getAITByServiceIdAndController: (params: { serviceId: string; controller: string }, token: string) => Promise<AITInfo | { error: string }>;
433
- createAIT: (params: CreateAITParams, token: string) => Promise<AITInfo | { error: string }>;
434
- };
435
- wallet: {
436
- verifyWallet: (params: VerifyWalletParams, token: string) => Promise<WalletInfo | { error: string }>;
437
- getWallet: (params: { address: string }, token: string) => Promise<WalletInfo | { error: string }>;
438
- };
439
- metadata: {
440
- createMetadata: (metadata: CreateMetadataParams, token: string) => Promise<{ metadataCid: string } | { error: string }>;
441
- };
442
- auth: {
443
- getNonce: (params: { address: string }) => Promise<{ code: string; timestamp: number } | { error: string }>;
444
- signIn: (params: SignInParams) => Promise<{ accessToken: string } | { error: string }>;
445
- };
446
- agent: {
447
- sendMessage: (params: { message: string; serviceId: string }) => Promise<{ reply: string } | { error: string }>;
448
- };
449
557
  }
@@ -1,131 +0,0 @@
1
- import { AITApi } from '../types/ait-api';
2
-
3
- const AI_AGENT_API_HOST = 'https://ai-agent.nxtlinq.ai';
4
- const AIT_SERVICE_API_HOST = 'https://staging-ait-service.nxtlinq.ai';
5
-
6
- export const createNxtlinqApi = (apiKey: string, apiSecret: string): AITApi => {
7
- const getAuthHeader = (): Record<string, string> => {
8
- const token = localStorage.getItem('nxtlinqAITServiceAccessToken');
9
- return token ? { 'Authorization': `Bearer ${JSON.parse(token)}` } : {};
10
- };
11
-
12
- return {
13
- ait: {
14
- getAITByServiceIdAndController: async (params: { serviceId: string; controller: string }, token: string) => {
15
- const response = await fetch(`${AIT_SERVICE_API_HOST}/api/ait/service/${params.serviceId}/controller/${params.controller}`, {
16
- method: 'GET',
17
- headers: {
18
- 'X-API-Key': apiKey,
19
- 'X-API-Secret': apiSecret,
20
- ...getAuthHeader()
21
- }
22
- });
23
- return response.json();
24
- },
25
- createAIT: async (params: any, token: string) => {
26
- const response = await fetch(`${AIT_SERVICE_API_HOST}/api/ait`, {
27
- method: 'POST',
28
- headers: {
29
- 'X-API-Key': apiKey,
30
- 'X-API-Secret': apiSecret,
31
- 'Content-Type': 'application/json',
32
- ...getAuthHeader()
33
- },
34
- body: JSON.stringify(params)
35
- });
36
- return response.json();
37
- }
38
- },
39
- wallet: {
40
- verifyWallet: async (params: any, token: string) => {
41
- const response = await fetch(`${AIT_SERVICE_API_HOST}/api/wallet`, {
42
- method: 'POST',
43
- headers: {
44
- 'X-API-Key': apiKey,
45
- 'X-API-Secret': apiSecret,
46
- 'Content-Type': 'application/json',
47
- ...getAuthHeader()
48
- },
49
- body: JSON.stringify(params)
50
- });
51
- return response.json();
52
- },
53
- getWallet: async (params: { address: string }, token: string) => {
54
- const response = await fetch(`${AIT_SERVICE_API_HOST}/api/wallet/address/${params.address}`, {
55
- method: 'GET',
56
- headers: {
57
- 'X-API-Key': apiKey,
58
- 'X-API-Secret': apiSecret,
59
- ...getAuthHeader()
60
- }
61
- });
62
- return response.json();
63
- }
64
- },
65
- metadata: {
66
- createMetadata: async (metadata: any, token: string) => {
67
- const response = await fetch(`${AIT_SERVICE_API_HOST}/api/metadata`, {
68
- method: 'POST',
69
- headers: {
70
- 'X-API-Key': apiKey,
71
- 'X-API-Secret': apiSecret,
72
- 'Content-Type': 'application/json',
73
- ...getAuthHeader()
74
- },
75
- body: JSON.stringify(metadata)
76
- });
77
- return response.json();
78
- }
79
- },
80
- auth: {
81
- getNonce: async (params: { address: string }) => {
82
- const response = await fetch(`${AIT_SERVICE_API_HOST}/api/auth/address/${params.address}/nonce`, {
83
- method: 'GET',
84
- headers: {
85
- 'X-API-Key': apiKey,
86
- 'X-API-Secret': apiSecret,
87
- ...getAuthHeader()
88
- }
89
- });
90
- return response.json();
91
- },
92
- signIn: async (params: any) => {
93
- const response = await fetch(`${AIT_SERVICE_API_HOST}/api/auth`, {
94
- method: 'POST',
95
- headers: {
96
- 'X-API-Key': apiKey,
97
- 'X-API-Secret': apiSecret,
98
- 'Content-Type': 'application/json',
99
- ...getAuthHeader()
100
- },
101
- body: JSON.stringify(params)
102
- });
103
- return response.json();
104
- }
105
- },
106
- agent: {
107
- sendMessage: async (params) => {
108
- try {
109
- const response = await fetch(`${AI_AGENT_API_HOST}/api/agent/message`, {
110
- method: 'POST',
111
- headers: {
112
- 'X-API-Key': apiKey,
113
- 'X-API-Secret': apiSecret,
114
- 'Content-Type': 'application/json',
115
- ...getAuthHeader()
116
- },
117
- body: JSON.stringify(params)
118
- });
119
-
120
- if (!response.ok) {
121
- throw new Error('发送消息失败');
122
- }
123
-
124
- return await response.json();
125
- } catch (error) {
126
- return { error: error instanceof Error ? error.message : '发送消息失败' };
127
- }
128
- }
129
- }
130
- };
131
- };