agentlink-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/Prompt.md +52 -0
- package/README.md +21 -9
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- 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,12 @@ pnpm add agentlink-sdk
|
|
|
34
34
|
|
|
35
35
|
### 基本使用
|
|
36
36
|
|
|
37
|
-
SDK 默认使用服务端地址 `https://mixlab.top`,可直接创建客户端;如需使用自建或其它服务端,可传入 `serverUrl` 覆盖默认值。
|
|
37
|
+
SDK 默认使用服务端地址 `https://www.mixlab.top`,可直接创建客户端;如需使用自建或其它服务端,可传入 `serverUrl` 覆盖默认值。
|
|
38
38
|
|
|
39
39
|
```typescript
|
|
40
40
|
import { AgentLinkClient } from 'agentlink-sdk';
|
|
41
41
|
|
|
42
|
-
// 使用默认地址 https://mixlab.top
|
|
42
|
+
// 使用默认地址 https://www.mixlab.top
|
|
43
43
|
const client = new AgentLinkClient();
|
|
44
44
|
|
|
45
45
|
// 或指定自定义服务端地址
|
|
@@ -62,6 +62,17 @@ client.receiveData((data, type, senderInfo) => {
|
|
|
62
62
|
});
|
|
63
63
|
```
|
|
64
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
|
+
|
|
65
76
|
## API 文档
|
|
66
77
|
|
|
67
78
|
### AgentLinkClient
|
|
@@ -74,7 +85,7 @@ new AgentLinkClient(options: AgentLinkClientOptions)
|
|
|
74
85
|
|
|
75
86
|
**参数:**
|
|
76
87
|
|
|
77
|
-
- `options.serverUrl` (string, 可选): 服务端验证地址。不传时使用默认地址 `https://mixlab.top`;可传入自定义地址如 `'https://your-server.com'`
|
|
88
|
+
- `options.serverUrl` (string, 可选): 服务端验证地址。不传时使用默认地址 `https://www.mixlab.top`;可传入自定义地址如 `'https://your-server.com'`
|
|
78
89
|
|
|
79
90
|
#### 方法
|
|
80
91
|
|
|
@@ -228,14 +239,14 @@ console.log('所有白名单:', allInfo.whitelist);
|
|
|
228
239
|
|
|
229
240
|
```typescript
|
|
230
241
|
interface AgentLinkClientOptions {
|
|
231
|
-
serverUrl?: string; // 可选,默认 'https://mixlab.top'
|
|
242
|
+
serverUrl?: string; // 可选,默认 'https://www.mixlab.top'
|
|
232
243
|
}
|
|
233
244
|
```
|
|
234
245
|
|
|
235
246
|
### DEFAULT_SERVER_URL
|
|
236
247
|
|
|
237
248
|
```typescript
|
|
238
|
-
const DEFAULT_SERVER_URL = 'https://mixlab.top';
|
|
249
|
+
const DEFAULT_SERVER_URL = 'https://www.mixlab.top';
|
|
239
250
|
```
|
|
240
251
|
|
|
241
252
|
如需与默认地址保持一致(例如在配置中引用),可从 SDK 导入:`import { DEFAULT_SERVER_URL } from 'agentlink-sdk'`。
|
|
@@ -346,10 +357,11 @@ client.receiveData((data, type, senderInfo, verification) => {
|
|
|
346
357
|
|
|
347
358
|
## 注意事项
|
|
348
359
|
|
|
349
|
-
1.
|
|
350
|
-
2.
|
|
351
|
-
3. **
|
|
352
|
-
4. **
|
|
360
|
+
1. **域名白名单**: 发送数据前,请确认当前站点域名已在 AgentLink 服务端的白名单中,否则无法获取 Token。详见上文「跨域与白名单说明」。
|
|
361
|
+
2. **弹窗拦截**: 某些浏览器可能会拦截 `window.open`,确保在用户交互事件(如点击)中调用 `sendData`
|
|
362
|
+
3. **URL 长度限制**: 虽然 SDK 会自动压缩数据,但过大的数据仍可能超出浏览器 URL 长度限制
|
|
363
|
+
4. **HTTPS 要求**: 生产环境建议使用 HTTPS,确保数据传输安全
|
|
364
|
+
5. **Token 缓存**: Token 在实例级别缓存,同一实例的多次调用会复用 Token
|
|
353
365
|
|
|
354
366
|
## 浏览器支持
|
|
355
367
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
interface AgentLinkClientOptions {
|
|
2
2
|
/**
|
|
3
|
-
* 服务端验证地址,不传则使用默认地址 https://mixlab.top
|
|
4
|
-
* 例如: 'https://mixlab.top' 或自定义 'https://your-server.com'
|
|
3
|
+
* 服务端验证地址,不传则使用默认地址 https://www.mixlab.top
|
|
4
|
+
* 例如: 'https://www.mixlab.top' 或自定义 'https://your-server.com'
|
|
5
5
|
*/
|
|
6
6
|
serverUrl?: string;
|
|
7
7
|
}
|
|
8
8
|
/** 默认服务端地址 */
|
|
9
|
-
declare const DEFAULT_SERVER_URL = "https://mixlab.top";
|
|
9
|
+
declare const DEFAULT_SERVER_URL = "https://www.mixlab.top";
|
|
10
10
|
interface WhitelistInfo {
|
|
11
11
|
domain: string;
|
|
12
12
|
name?: string | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
interface AgentLinkClientOptions {
|
|
2
2
|
/**
|
|
3
|
-
* 服务端验证地址,不传则使用默认地址 https://mixlab.top
|
|
4
|
-
* 例如: 'https://mixlab.top' 或自定义 'https://your-server.com'
|
|
3
|
+
* 服务端验证地址,不传则使用默认地址 https://www.mixlab.top
|
|
4
|
+
* 例如: 'https://www.mixlab.top' 或自定义 'https://your-server.com'
|
|
5
5
|
*/
|
|
6
6
|
serverUrl?: string;
|
|
7
7
|
}
|
|
8
8
|
/** 默认服务端地址 */
|
|
9
|
-
declare const DEFAULT_SERVER_URL = "https://mixlab.top";
|
|
9
|
+
declare const DEFAULT_SERVER_URL = "https://www.mixlab.top";
|
|
10
10
|
interface WhitelistInfo {
|
|
11
11
|
domain: string;
|
|
12
12
|
name?: string | null;
|
package/dist/index.js
CHANGED
|
@@ -174,7 +174,7 @@ async function fetchWhitelistInfo(serverUrl, includeAll = false) {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
// src/client.ts
|
|
177
|
-
var DEFAULT_SERVER_URL = "https://mixlab.top";
|
|
177
|
+
var DEFAULT_SERVER_URL = "https://www.mixlab.top";
|
|
178
178
|
var _AgentLinkClient = class _AgentLinkClient {
|
|
179
179
|
constructor(options = {}) {
|
|
180
180
|
// 发送端 Token 缓存(实例级别)
|
package/dist/index.mjs
CHANGED
|
@@ -139,7 +139,7 @@ async function fetchWhitelistInfo(serverUrl, includeAll = false) {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
// src/client.ts
|
|
142
|
-
var DEFAULT_SERVER_URL = "https://mixlab.top";
|
|
142
|
+
var DEFAULT_SERVER_URL = "https://www.mixlab.top";
|
|
143
143
|
var _AgentLinkClient = class _AgentLinkClient {
|
|
144
144
|
constructor(options = {}) {
|
|
145
145
|
// 发送端 Token 缓存(实例级别)
|