agentlink-sdk 1.0.5 → 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/Prompt.md +52 -0
- package/README.md +37 -14
- package/dist/index.d.mts +8 -5
- package/dist/index.d.ts +8 -5
- package/dist/index.js +5 -2
- package/dist/index.mjs +5 -2
- package/package.json +1 -1
package/Prompt.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
添加一个 **AgentLink** 功能,用于将xxx数据发送到https://www.mixlab.top
|
|
2
|
+
|
|
3
|
+
### 安装方式
|
|
4
|
+
|
|
5
|
+
- **npm 安装**
|
|
6
|
+
```bash
|
|
7
|
+
npm install agentlink-sdk
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
- **CDN 引入(浏览器端)**
|
|
11
|
+
```html
|
|
12
|
+
<script type="module">
|
|
13
|
+
import { AgentLinkClient } from 'https://cdn.jsdelivr.net/npm/agentlink-sdk@latest/dist/index.mjs';
|
|
14
|
+
</script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### 使用说明
|
|
18
|
+
|
|
19
|
+
SDK 默认连接的服务端地址为 `https://www.mixlab.top`。你可以直接创建客户端实例;如需使用自建或其他服务端,可通过 `serverUrl` 参数覆盖默认地址。
|
|
20
|
+
|
|
21
|
+
#### Node.js / 模块化环境示例:
|
|
22
|
+
```javascript
|
|
23
|
+
import { AgentLinkClient } from 'agentlink-sdk';
|
|
24
|
+
|
|
25
|
+
// 使用默认服务端(https://www.mixlab.top)
|
|
26
|
+
const client = new AgentLinkClient();
|
|
27
|
+
|
|
28
|
+
// 或指定自定义服务端地址
|
|
29
|
+
const client = new AgentLinkClient({
|
|
30
|
+
serverUrl: 'https://your-agentlink-server.com'
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
#### 发送数据
|
|
35
|
+
```javascript
|
|
36
|
+
await client.sendData(
|
|
37
|
+
'https://target-domain.com/page', // 目标页面 URL
|
|
38
|
+
{ message: 'Hello from AgentLink' }, // 要发送的数据(任意 JSON 兼容对象)
|
|
39
|
+
'greeting' // 数据类型标识(自定义字符串)
|
|
40
|
+
);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### 接收数据
|
|
44
|
+
```javascript
|
|
45
|
+
client.receiveData((data, type, senderInfo) => {
|
|
46
|
+
console.log('收到数据:', data);
|
|
47
|
+
console.log('数据类型:', type);
|
|
48
|
+
console.log('发送方信息:', senderInfo); // 包含来源 URL 等上下文
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
> 请确保在支持模块化(ESM)的环境中使用该 SDK,并注意跨域策略限制。
|
package/README.md
CHANGED
|
@@ -34,12 +34,17 @@ pnpm add agentlink-sdk
|
|
|
34
34
|
|
|
35
35
|
### 基本使用
|
|
36
36
|
|
|
37
|
+
SDK 默认使用服务端地址 `https://www.mixlab.top`,可直接创建客户端;如需使用自建或其它服务端,可传入 `serverUrl` 覆盖默认值。
|
|
38
|
+
|
|
37
39
|
```typescript
|
|
38
40
|
import { AgentLinkClient } from 'agentlink-sdk';
|
|
39
41
|
|
|
40
|
-
//
|
|
42
|
+
// 使用默认地址 https://www.mixlab.top
|
|
43
|
+
const client = new AgentLinkClient();
|
|
44
|
+
|
|
45
|
+
// 或指定自定义服务端地址
|
|
41
46
|
const client = new AgentLinkClient({
|
|
42
|
-
serverUrl: 'https://
|
|
47
|
+
serverUrl: 'https://your-agentlink-server.com'
|
|
43
48
|
});
|
|
44
49
|
|
|
45
50
|
// 发送数据
|
|
@@ -57,6 +62,17 @@ client.receiveData((data, type, senderInfo) => {
|
|
|
57
62
|
});
|
|
58
63
|
```
|
|
59
64
|
|
|
65
|
+
## 跨域与白名单说明
|
|
66
|
+
|
|
67
|
+
在**任意域名**的网页(例如 `https://your-site.com`)中接入 SDK 并发送数据时:
|
|
68
|
+
|
|
69
|
+
- **跨域(CORS)**:AgentLink 服务端已对相关 API 配置 CORS,会正确返回 `Access-Control-Allow-Origin` 等响应头。因此从你的站点向服务端发起的 `fetch` 请求**不会被浏览器以跨域为由拦截**,无需额外配置。
|
|
70
|
+
- **白名单**:发送数据前,你的**当前页面所在域名**必须在 AgentLink 服务端的**域名白名单**中。若未加入白名单,服务端将拒绝签发 Token,`sendData` 会报错。
|
|
71
|
+
- 使用默认服务端(如 `https://www.mixlab.top`)时,需在对应后台将你的域名加入白名单。
|
|
72
|
+
- 使用自建服务端时,请在自己的 AgentLink 管理后台添加域名。
|
|
73
|
+
|
|
74
|
+
总结:只要你的域名已在所用 AgentLink 服务端的白名单中,即可正常跨域调用、发送数据,无需担心浏览器跨域限制。
|
|
75
|
+
|
|
60
76
|
## API 文档
|
|
61
77
|
|
|
62
78
|
### AgentLinkClient
|
|
@@ -69,7 +85,7 @@ new AgentLinkClient(options: AgentLinkClientOptions)
|
|
|
69
85
|
|
|
70
86
|
**参数:**
|
|
71
87
|
|
|
72
|
-
- `options.serverUrl` (string,
|
|
88
|
+
- `options.serverUrl` (string, 可选): 服务端验证地址。不传时使用默认地址 `https://www.mixlab.top`;可传入自定义地址如 `'https://your-server.com'`
|
|
73
89
|
|
|
74
90
|
#### 方法
|
|
75
91
|
|
|
@@ -223,10 +239,18 @@ console.log('所有白名单:', allInfo.whitelist);
|
|
|
223
239
|
|
|
224
240
|
```typescript
|
|
225
241
|
interface AgentLinkClientOptions {
|
|
226
|
-
serverUrl
|
|
242
|
+
serverUrl?: string; // 可选,默认 'https://www.mixlab.top'
|
|
227
243
|
}
|
|
228
244
|
```
|
|
229
245
|
|
|
246
|
+
### DEFAULT_SERVER_URL
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
const DEFAULT_SERVER_URL = 'https://www.mixlab.top';
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
如需与默认地址保持一致(例如在配置中引用),可从 SDK 导入:`import { DEFAULT_SERVER_URL } from 'agentlink-sdk'`。
|
|
253
|
+
|
|
230
254
|
### SenderInfo
|
|
231
255
|
|
|
232
256
|
```typescript
|
|
@@ -289,9 +313,8 @@ interface WhitelistResponse {
|
|
|
289
313
|
### 发送数据示例
|
|
290
314
|
|
|
291
315
|
```typescript
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
});
|
|
316
|
+
// 使用默认地址
|
|
317
|
+
const client = new AgentLinkClient();
|
|
295
318
|
|
|
296
319
|
// 发送复杂数据
|
|
297
320
|
await client.sendData(
|
|
@@ -310,9 +333,8 @@ await client.sendData(
|
|
|
310
333
|
### 接收数据示例
|
|
311
334
|
|
|
312
335
|
```typescript
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
});
|
|
336
|
+
// 使用默认地址,也可传入 serverUrl 使用自建服务端
|
|
337
|
+
const client = new AgentLinkClient();
|
|
316
338
|
|
|
317
339
|
// 监听数据
|
|
318
340
|
client.receiveData((data, type, senderInfo, verification) => {
|
|
@@ -335,10 +357,11 @@ client.receiveData((data, type, senderInfo, verification) => {
|
|
|
335
357
|
|
|
336
358
|
## 注意事项
|
|
337
359
|
|
|
338
|
-
1.
|
|
339
|
-
2.
|
|
340
|
-
3. **
|
|
341
|
-
4. **
|
|
360
|
+
1. **域名白名单**: 发送数据前,请确认当前站点域名已在 AgentLink 服务端的白名单中,否则无法获取 Token。详见上文「跨域与白名单说明」。
|
|
361
|
+
2. **弹窗拦截**: 某些浏览器可能会拦截 `window.open`,确保在用户交互事件(如点击)中调用 `sendData`
|
|
362
|
+
3. **URL 长度限制**: 虽然 SDK 会自动压缩数据,但过大的数据仍可能超出浏览器 URL 长度限制
|
|
363
|
+
4. **HTTPS 要求**: 生产环境建议使用 HTTPS,确保数据传输安全
|
|
364
|
+
5. **Token 缓存**: Token 在实例级别缓存,同一实例的多次调用会复用 Token
|
|
342
365
|
|
|
343
366
|
## 浏览器支持
|
|
344
367
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
interface AgentLinkClientOptions {
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* 例如: 'https://
|
|
3
|
+
* 服务端验证地址,不传则使用默认地址 https://www.mixlab.top
|
|
4
|
+
* 例如: 'https://www.mixlab.top' 或自定义 'https://your-server.com'
|
|
5
5
|
*/
|
|
6
|
-
serverUrl
|
|
6
|
+
serverUrl?: string;
|
|
7
7
|
}
|
|
8
|
+
/** 默认服务端地址 */
|
|
9
|
+
declare const DEFAULT_SERVER_URL = "https://www.mixlab.top";
|
|
8
10
|
interface WhitelistInfo {
|
|
9
11
|
domain: string;
|
|
12
|
+
name?: string | null;
|
|
10
13
|
description?: string | null;
|
|
11
14
|
}
|
|
12
15
|
interface WhitelistResponse {
|
|
@@ -28,7 +31,7 @@ declare class AgentLinkClient {
|
|
|
28
31
|
private static tokenCache;
|
|
29
32
|
private static whitelistCache;
|
|
30
33
|
private static CACHE_TTL;
|
|
31
|
-
constructor(options
|
|
34
|
+
constructor(options?: AgentLinkClientOptions);
|
|
32
35
|
/**
|
|
33
36
|
* 确保有 Token(自动获取)
|
|
34
37
|
*/
|
|
@@ -117,4 +120,4 @@ declare function verifyWhitelist(serverUrl: string, origin?: string): Promise<bo
|
|
|
117
120
|
*/
|
|
118
121
|
declare function fetchWhitelistInfo(serverUrl: string, includeAll?: boolean): Promise<any>;
|
|
119
122
|
|
|
120
|
-
export { AgentLinkClient, type AgentLinkClientOptions, type SenderInfo, type URLData, type WhitelistInfo, type WhitelistResponse, base64ToUint8Array, compress, decodeDataFromUrl, decompress, encodeDataToUrl, fetchWhitelistInfo, uint8ArrayToBase64, verifyWhitelist };
|
|
123
|
+
export { AgentLinkClient, type AgentLinkClientOptions, DEFAULT_SERVER_URL, type SenderInfo, type URLData, type WhitelistInfo, type WhitelistResponse, base64ToUint8Array, compress, decodeDataFromUrl, decompress, encodeDataToUrl, fetchWhitelistInfo, uint8ArrayToBase64, verifyWhitelist };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
interface AgentLinkClientOptions {
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* 例如: 'https://
|
|
3
|
+
* 服务端验证地址,不传则使用默认地址 https://www.mixlab.top
|
|
4
|
+
* 例如: 'https://www.mixlab.top' 或自定义 'https://your-server.com'
|
|
5
5
|
*/
|
|
6
|
-
serverUrl
|
|
6
|
+
serverUrl?: string;
|
|
7
7
|
}
|
|
8
|
+
/** 默认服务端地址 */
|
|
9
|
+
declare const DEFAULT_SERVER_URL = "https://www.mixlab.top";
|
|
8
10
|
interface WhitelistInfo {
|
|
9
11
|
domain: string;
|
|
12
|
+
name?: string | null;
|
|
10
13
|
description?: string | null;
|
|
11
14
|
}
|
|
12
15
|
interface WhitelistResponse {
|
|
@@ -28,7 +31,7 @@ declare class AgentLinkClient {
|
|
|
28
31
|
private static tokenCache;
|
|
29
32
|
private static whitelistCache;
|
|
30
33
|
private static CACHE_TTL;
|
|
31
|
-
constructor(options
|
|
34
|
+
constructor(options?: AgentLinkClientOptions);
|
|
32
35
|
/**
|
|
33
36
|
* 确保有 Token(自动获取)
|
|
34
37
|
*/
|
|
@@ -117,4 +120,4 @@ declare function verifyWhitelist(serverUrl: string, origin?: string): Promise<bo
|
|
|
117
120
|
*/
|
|
118
121
|
declare function fetchWhitelistInfo(serverUrl: string, includeAll?: boolean): Promise<any>;
|
|
119
122
|
|
|
120
|
-
export { AgentLinkClient, type AgentLinkClientOptions, type SenderInfo, type URLData, type WhitelistInfo, type WhitelistResponse, base64ToUint8Array, compress, decodeDataFromUrl, decompress, encodeDataToUrl, fetchWhitelistInfo, uint8ArrayToBase64, verifyWhitelist };
|
|
123
|
+
export { AgentLinkClient, type AgentLinkClientOptions, DEFAULT_SERVER_URL, type SenderInfo, type URLData, type WhitelistInfo, type WhitelistResponse, base64ToUint8Array, compress, decodeDataFromUrl, decompress, encodeDataToUrl, fetchWhitelistInfo, uint8ArrayToBase64, verifyWhitelist };
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
AgentLinkClient: () => AgentLinkClient,
|
|
24
|
+
DEFAULT_SERVER_URL: () => DEFAULT_SERVER_URL,
|
|
24
25
|
base64ToUint8Array: () => base64ToUint8Array,
|
|
25
26
|
compress: () => compress,
|
|
26
27
|
decodeDataFromUrl: () => decodeDataFromUrl,
|
|
@@ -173,12 +174,14 @@ async function fetchWhitelistInfo(serverUrl, includeAll = false) {
|
|
|
173
174
|
}
|
|
174
175
|
|
|
175
176
|
// src/client.ts
|
|
177
|
+
var DEFAULT_SERVER_URL = "https://www.mixlab.top";
|
|
176
178
|
var _AgentLinkClient = class _AgentLinkClient {
|
|
177
|
-
constructor(options) {
|
|
179
|
+
constructor(options = {}) {
|
|
178
180
|
// 发送端 Token 缓存(实例级别)
|
|
179
181
|
this.token = null;
|
|
180
182
|
this.tokenPromise = null;
|
|
181
|
-
|
|
183
|
+
const base = options.serverUrl ?? DEFAULT_SERVER_URL;
|
|
184
|
+
this.serverUrl = base.replace(/\/$/, "");
|
|
182
185
|
}
|
|
183
186
|
/**
|
|
184
187
|
* 确保有 Token(自动获取)
|
package/dist/index.mjs
CHANGED
|
@@ -139,12 +139,14 @@ async function fetchWhitelistInfo(serverUrl, includeAll = false) {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
// src/client.ts
|
|
142
|
+
var DEFAULT_SERVER_URL = "https://www.mixlab.top";
|
|
142
143
|
var _AgentLinkClient = class _AgentLinkClient {
|
|
143
|
-
constructor(options) {
|
|
144
|
+
constructor(options = {}) {
|
|
144
145
|
// 发送端 Token 缓存(实例级别)
|
|
145
146
|
this.token = null;
|
|
146
147
|
this.tokenPromise = null;
|
|
147
|
-
|
|
148
|
+
const base = options.serverUrl ?? DEFAULT_SERVER_URL;
|
|
149
|
+
this.serverUrl = base.replace(/\/$/, "");
|
|
148
150
|
}
|
|
149
151
|
/**
|
|
150
152
|
* 确保有 Token(自动获取)
|
|
@@ -304,6 +306,7 @@ _AgentLinkClient.CACHE_TTL = 60 * 60 * 1e3;
|
|
|
304
306
|
var AgentLinkClient = _AgentLinkClient;
|
|
305
307
|
export {
|
|
306
308
|
AgentLinkClient,
|
|
309
|
+
DEFAULT_SERVER_URL,
|
|
307
310
|
base64ToUint8Array,
|
|
308
311
|
compress,
|
|
309
312
|
decodeDataFromUrl,
|