@bytexbyte/nxtlinq-ai-agent-sdk 1.0.6 → 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,26 +1,144 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ import { ethers } from 'ethers';
2
+ import stringify from 'json-stable-stringify';
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
+ };
4
128
  };
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 {
129
+ export { ChatBot } from './components/ChatBot';
130
+ export class NxtlinqAITSDK {
13
131
  constructor(serviceId, apiKey, apiSecret) {
14
132
  this.signer = null;
15
133
  this.walletAddress = null;
16
134
  this.serviceId = serviceId;
17
- this.api = (0, nxtlinq_api_js_1.createNxtlinqApi)(apiKey, apiSecret);
135
+ this.api = createNxtlinqApi(apiKey, apiSecret);
18
136
  }
19
137
  async connectWallet() {
20
138
  if (typeof window === 'undefined' || !window.ethereum) {
21
139
  throw new Error('MetaMask is not installed');
22
140
  }
23
- const provider = new ethers_1.ethers.BrowserProvider(window.ethereum);
141
+ const provider = new ethers.BrowserProvider(window.ethereum);
24
142
  this.signer = await provider.getSigner();
25
143
  this.walletAddress = await this.signer.getAddress();
26
144
  return this.walletAddress;
@@ -53,7 +171,7 @@ class NxtlinqAITSDK {
53
171
  code: nonceResponse.code,
54
172
  timestamp: nonceResponse.timestamp
55
173
  };
56
- const stringToSign = (0, json_stable_stringify_1.default)(payload);
174
+ const stringToSign = stringify(payload);
57
175
  const signature = await this.signer.signMessage(stringToSign || '');
58
176
  const response = await this.api.auth.signIn({
59
177
  ...payload,
@@ -79,8 +197,8 @@ class NxtlinqAITSDK {
79
197
  permissions,
80
198
  issuedBy: this.walletAddress
81
199
  };
82
- const metadataStr = (0, json_stable_stringify_1.default)(metadata);
83
- const metadataHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(metadataStr || ''));
200
+ const metadataStr = stringify(metadata);
201
+ const metadataHash = ethers.keccak256(ethers.toUtf8Bytes(metadataStr || ''));
84
202
  // Upload metadata
85
203
  const uploadResponse = await this.api.metadata.createMetadata({
86
204
  ...metadata,
@@ -91,8 +209,8 @@ class NxtlinqAITSDK {
91
209
  }
92
210
  const { metadataCid } = uploadResponse;
93
211
  // 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));
212
+ const messageHash = ethers.solidityPackedKeccak256(['string', 'address', 'string', 'bytes32', 'uint256'], [aitId, this.walletAddress, this.serviceId, metadataHash, timestamp]);
213
+ const signature = await this.signer.signMessage(ethers.getBytes(messageHash));
96
214
  // Register AIT
97
215
  const response = await this.api.ait.createAIT({
98
216
  aitId,
@@ -152,13 +270,12 @@ class NxtlinqAITSDK {
152
270
  return form.flatMap(group => group.options.filter((opt) => opt.isChecked).map((opt) => opt.value));
153
271
  }
154
272
  }
155
- exports.NxtlinqAITSDK = NxtlinqAITSDK;
156
- class NxtlinqAIAgent {
273
+ export class NxtlinqAIAgent {
157
274
  constructor(projectId, apiKey, apiSecret) {
158
275
  this.permissions = [];
159
276
  this.projectId = projectId;
160
277
  this.apiKey = apiKey;
161
- this.api = (0, nxtlinq_api_js_1.createNxtlinqApi)(apiKey, apiSecret);
278
+ this.api = createNxtlinqApi(apiKey, apiSecret);
162
279
  }
163
280
  setAIT(ait, signer) {
164
281
  this.ait = ait;
@@ -215,8 +332,8 @@ class NxtlinqAIAgent {
215
332
  permissions,
216
333
  issuedBy: hitAddress
217
334
  };
218
- const metadataStr = (0, json_stable_stringify_1.default)(metadata);
219
- const metadataHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(metadataStr || ''));
335
+ const metadataStr = stringify(metadata);
336
+ const metadataHash = ethers.keccak256(ethers.toUtf8Bytes(metadataStr || ''));
220
337
  // Upload metadata
221
338
  const uploadResponse = await this.api.metadata.createMetadata({
222
339
  ...metadata,
@@ -227,8 +344,8 @@ class NxtlinqAIAgent {
227
344
  }
228
345
  const { metadataCid } = uploadResponse;
229
346
  // 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));
347
+ const messageHash = ethers.solidityPackedKeccak256(['string', 'address', 'string', 'bytes32', 'uint256'], [aitId, hitAddress, serviceId, metadataHash, timestamp]);
348
+ const signature = await signer.signMessage(ethers.getBytes(messageHash));
232
349
  // Register AIT
233
350
  const response = await this.api.ait.createAIT({
234
351
  aitId,
@@ -284,7 +401,7 @@ class NxtlinqAIAgent {
284
401
  throw new Error('请先连接钱包以访问权限');
285
402
  }
286
403
  const timestamp = Math.floor(Date.now() / 1000);
287
- const stringToSign = (0, json_stable_stringify_1.default)({
404
+ const stringToSign = stringify({
288
405
  message,
289
406
  aitId: this.ait.aitId,
290
407
  controller: this.ait.controller,
@@ -307,4 +424,3 @@ class NxtlinqAIAgent {
307
424
  };
308
425
  }
309
426
  }
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.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.js';
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
  }
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;
@@ -1,129 +0,0 @@
1
- const AI_AGENT_API_HOST = 'https://ai-agent.nxtlinq.ai';
2
- const AIT_SERVICE_API_HOST = 'https://staging-ait-service.nxtlinq.ai';
3
-
4
- export const createNxtlinqApi = (apiKey, apiSecret) => {
5
- const getAuthHeader = () => {
6
- const token = localStorage.getItem('nxtlinqAITServiceAccessToken');
7
- return token ? { 'Authorization': `Bearer ${JSON.parse(token)}` } : {};
8
- };
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
-
118
- if (!response.ok) {
119
- throw new Error('发送消息失败');
120
- }
121
-
122
- return await response.json();
123
- } catch (error) {
124
- return { error: error instanceof Error ? error.message : '发送消息失败' };
125
- }
126
- }
127
- }
128
- };
129
- };