@mearl/client 2.4.0 → 2.5.1
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/README.md +2 -1
- package/dist/actionTimeouts.js +5 -1
- package/dist/browserRegistry.js +8 -3
- package/dist/commands.d.ts +18 -10
- package/dist/commands.js +30 -8
- package/dist/generated-browser-action-protocol.d.ts +18 -1
- package/dist/socket.js +10 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,6 +62,7 @@ mearl <action> --help
|
|
|
62
62
|
mearl browser_launch --payload '{"name":"account-a","accountId":12345}'
|
|
63
63
|
mearl browser_launch --payload '{"name":"account-b","query":"test_account"}'
|
|
64
64
|
mearl browser_launch --payload '{"name":"cookie-copy","copyCookieDomains":["example.com"]}'
|
|
65
|
+
mearl browser_launch --payload '{"name":"cloud-login","provider":"agentbay","persistent":true,"userAgentMode":"desktop","copyCookieDomains":["example.com"],"url":"https://example.com/account"}'
|
|
65
66
|
mearl browser_launch --payload '{"name":"figma","userAgentMode":"desktop","copyCookieDomains":["figma.com"]}'
|
|
66
67
|
mearl browser_list
|
|
67
68
|
mearl browser_release
|
|
@@ -104,7 +105,7 @@ mearl browser_release
|
|
|
104
105
|
|
|
105
106
|
`browser_release` 仅在用户明确要求结束调试、退出接管或清理会话资源时使用,不作为普通任务收尾。它会释放当前目标浏览器的 debugger/CDP 控制和会话级临时状态(包括设备/时区模拟),保留浏览器及全部标签页;后续浏览器操作可自动重新建立控制。
|
|
106
107
|
|
|
107
|
-
托管浏览器使用独立 Profile
|
|
108
|
+
托管浏览器使用独立 Profile。控制浏览器需先登录 TDBank;生成的 SSO 地址在本地内部传递,本地实例可以使用 `headless: true`(默认)完成测试账号登录。AgentBay 固定为非 headless,传 `headless: true` 会被拒绝;`imageId` 可指定镜像别名或具体镜像 ID,省略时使用已验证的 Linux Browser Use 内网镜像。`persistent: true` 会让本地实例保留 Profile,让 AgentBay 同名实例绑定稳定的云端 Browser Context;正常关闭时同步 Cookie、LocalStorage、IndexedDB 等状态,下次启动无需再次复制本地登录态。`deleteProfile: true` 会显式删除对应 Profile 或 Context。`copyCookieDomains` 可在首次启动或需要刷新登录态时把控制浏览器指定域的 Cookie 复制到新实例,Cookie 值不会经过 cloud-server,也不会出现在命令结果或日志中;`userAgentMode: "desktop"` 让本地实例使用匹配本机 Chrome 版本的桌面 UA,AgentBay 则复用当前控制浏览器的桌面 UA。`browser_list` 通过 `agentbayImageId`、`agentbayContextId` 和 `agentbayContextName` 返回 AgentBay 实例配置;当服务返回无影浏览器串流入口时,还会通过 `agentbayAccessUrl` 暴露,该地址可能包含临时访问凭据,应按敏感信息处理。完整设计见 [托管浏览器与 TDBank 多账号设计](../../docs/managed-browsers.md)。
|
|
108
109
|
|
|
109
110
|
## 架构
|
|
110
111
|
|
package/dist/actionTimeouts.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { PAGE_ACT_ACTIONS } from './generated-browser-action-protocol.js';
|
|
2
2
|
const SEND_REQUEST_FILE_TRANSFER_TIMEOUT_MS = 120_000;
|
|
3
|
+
// AgentBay context sync can poll for about 12 minutes before session deletion waits up to 5 more.
|
|
4
|
+
const BROWSER_CLOSE_TIMEOUT_SEC = 18 * 60;
|
|
3
5
|
function boundedNumber(value, fallback, minimum, maximum) {
|
|
4
6
|
const numeric = Number(value);
|
|
5
7
|
if (!Number.isFinite(numeric))
|
|
@@ -35,7 +37,9 @@ export function resolveActionTimeoutSec(action, data, fallback = 15) {
|
|
|
35
37
|
return Math.max(fallback, 40);
|
|
36
38
|
if (action === 'browser_launch')
|
|
37
39
|
return Math.max(fallback, 90);
|
|
38
|
-
if (action === 'browser_close'
|
|
40
|
+
if (action === 'browser_close')
|
|
41
|
+
return Math.max(fallback, BROWSER_CLOSE_TIMEOUT_SEC);
|
|
42
|
+
if (action === 'tdbank_account')
|
|
39
43
|
return Math.max(fallback, 20);
|
|
40
44
|
if (action === 'run_actions') {
|
|
41
45
|
const actions = Array.isArray(data.actions) ? data.actions : [{}];
|
package/dist/browserRegistry.js
CHANGED
|
@@ -68,9 +68,14 @@ export function findBrowser(browsers, selector) {
|
|
|
68
68
|
const byId = browsers.find(b => b.browserId.toLowerCase() === sel);
|
|
69
69
|
if (byId)
|
|
70
70
|
return byId;
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
|
|
71
|
+
const exactNameMatches = browsers.filter(b => b.browserName.toLowerCase() === sel);
|
|
72
|
+
if (exactNameMatches.length > 1) {
|
|
73
|
+
throw new Error(`Browser name "${selector.trim()}" is ambiguous. Use a full browserId: ${exactNameMatches
|
|
74
|
+
.map(browser => browser.browserId)
|
|
75
|
+
.join(', ')}`);
|
|
76
|
+
}
|
|
77
|
+
if (exactNameMatches[0])
|
|
78
|
+
return exactNameMatches[0];
|
|
74
79
|
return (browsers.find(b => b.browserId.toLowerCase().includes(sel) || b.browserName.toLowerCase().includes(sel)) ?? null);
|
|
75
80
|
}
|
|
76
81
|
/** Human-readable one-line label for a browser, used in listings and errors. */
|
package/dist/commands.d.ts
CHANGED
|
@@ -294,7 +294,7 @@ export declare const COMMANDS: readonly [{
|
|
|
294
294
|
readonly examples: ["tdbank_account --payload '{\"operation\":\"current\"}'", "tdbank_account --payload '{\"operation\":\"list\",\"refresh\":true}'", "tdbank_account --payload '{\"operation\":\"switch\",\"accountId\":12345}'", "tdbank_account --payload '{\"operation\":\"borrow\",\"query\":\"test_account\"}'"];
|
|
295
295
|
}, {
|
|
296
296
|
readonly name: "browser_list";
|
|
297
|
-
readonly description: "
|
|
297
|
+
readonly description: "列出所有浏览器及其连接状态、类型和托管实例信息;AgentBay 可包含镜像、持久化 Context 和串流地址";
|
|
298
298
|
readonly examples: ["browser_list"];
|
|
299
299
|
}, {
|
|
300
300
|
readonly name: "browser_release";
|
|
@@ -302,24 +302,32 @@ export declare const COMMANDS: readonly [{
|
|
|
302
302
|
readonly examples: ["browser_release", "browser_release --browser chrome-a"];
|
|
303
303
|
}, {
|
|
304
304
|
readonly name: "browser_launch";
|
|
305
|
-
readonly description: "
|
|
305
|
+
readonly description: "启动本地 Chrome 或 AgentBay 云浏览器,并通过 CDP 接入 Mearl";
|
|
306
306
|
readonly params: [{
|
|
307
307
|
readonly name: "name";
|
|
308
308
|
readonly type: "string";
|
|
309
309
|
readonly required: true;
|
|
310
310
|
readonly description: "实例名称,最多 64 个字符";
|
|
311
|
+
}, {
|
|
312
|
+
readonly name: "provider";
|
|
313
|
+
readonly type: "\"local\" | \"agentbay\"";
|
|
314
|
+
readonly description: "运行环境,默认 local;agentbay 从 AGENTBAY_KEY 创建云浏览器";
|
|
315
|
+
}, {
|
|
316
|
+
readonly name: "imageId";
|
|
317
|
+
readonly type: "string";
|
|
318
|
+
readonly description: "AgentBay 镜像别名或具体镜像 ID;默认使用已验证的 Linux Browser Use 内网镜像";
|
|
311
319
|
}, {
|
|
312
320
|
readonly name: "headless";
|
|
313
321
|
readonly type: "boolean";
|
|
314
|
-
readonly description: "是否无头运行,默认 true";
|
|
322
|
+
readonly description: "本地 provider 是否无头运行,默认 true;AgentBay 固定为 false,不支持 true";
|
|
315
323
|
}, {
|
|
316
324
|
readonly name: "userAgentMode";
|
|
317
325
|
readonly type: "\"default\" | \"desktop\"";
|
|
318
|
-
readonly description: "UA 模式:default 使用
|
|
326
|
+
readonly description: "UA 模式:default 使用 provider 默认 UA;desktop 本地使用匹配本机版本的 UA,AgentBay 复用控制浏览器的桌面 UA";
|
|
319
327
|
}, {
|
|
320
328
|
readonly name: "persistent";
|
|
321
329
|
readonly type: "boolean";
|
|
322
|
-
readonly description: "
|
|
330
|
+
readonly description: "关闭后是否保留浏览器状态,默认 false;本地保留 Profile,AgentBay 同名实例复用云端 Context";
|
|
323
331
|
}, {
|
|
324
332
|
readonly name: "url";
|
|
325
333
|
readonly type: "string";
|
|
@@ -351,12 +359,12 @@ export declare const COMMANDS: readonly [{
|
|
|
351
359
|
}, {
|
|
352
360
|
readonly name: "copyCookieDomains";
|
|
353
361
|
readonly type: "string[]";
|
|
354
|
-
readonly description: "
|
|
362
|
+
readonly description: "从控制浏览器复制到本地或 AgentBay 新实例的 Cookie 域名列表,可与本地 TDBank 登录组合";
|
|
355
363
|
}];
|
|
356
|
-
readonly examples: ["browser_launch --payload '{\"name\":\"account-a\",\"headless\":true,\"accountId\":12345}'", "browser_launch --payload '{\"name\":\"figma\",\"userAgentMode\":\"desktop\",\"copyCookieDomains\":[\"figma.com\"]}'", "browser_launch --payload '{\"name\":\"account-b\",\"query\":\"test_account\",\"url\":\"https://www.taobao.com\"}'", "browser_launch --payload '{\"name\":\"with-cookies\",\"copyCookieDomains\":[\"example.com\",\"sub.example.org\"]}'"];
|
|
364
|
+
readonly examples: ["browser_launch --payload '{\"name\":\"cloud-a\",\"provider\":\"agentbay\",\"userAgentMode\":\"desktop\",\"url\":\"https://example.com\"}'", "browser_launch --payload '{\"name\":\"cloud-public\",\"provider\":\"agentbay\",\"imageId\":\"browser_latest\",\"url\":\"https://example.com\"}'", "browser_launch --payload '{\"name\":\"cloud-login\",\"provider\":\"agentbay\",\"persistent\":true,\"copyCookieDomains\":[\"example.com\"],\"url\":\"https://example.com/account\"}'", "browser_launch --payload '{\"name\":\"account-a\",\"headless\":true,\"accountId\":12345}'", "browser_launch --payload '{\"name\":\"figma\",\"userAgentMode\":\"desktop\",\"copyCookieDomains\":[\"figma.com\"]}'", "browser_launch --payload '{\"name\":\"account-b\",\"query\":\"test_account\",\"url\":\"https://www.taobao.com\"}'", "browser_launch --payload '{\"name\":\"with-cookies\",\"copyCookieDomains\":[\"example.com\",\"sub.example.org\"]}'"];
|
|
357
365
|
}, {
|
|
358
366
|
readonly name: "browser_close";
|
|
359
|
-
readonly description: "
|
|
367
|
+
readonly description: "关闭指定托管浏览器并按策略保留或清理本地 Profile / AgentBay Context";
|
|
360
368
|
readonly params: [{
|
|
361
369
|
readonly name: "browser";
|
|
362
370
|
readonly type: "string";
|
|
@@ -365,9 +373,9 @@ export declare const COMMANDS: readonly [{
|
|
|
365
373
|
}, {
|
|
366
374
|
readonly name: "deleteProfile";
|
|
367
375
|
readonly type: "boolean";
|
|
368
|
-
readonly description: "
|
|
376
|
+
readonly description: "强制删除持久化本地 Profile 或 AgentBay Context,默认 false";
|
|
369
377
|
}];
|
|
370
|
-
readonly examples: ["browser_close --payload '{\"browser\":\"managed:account-a\"}'", "browser_close --payload '{\"browser\":\"account-b\",\"deleteProfile\":true}'"];
|
|
378
|
+
readonly examples: ["browser_close --payload '{\"browser\":\"managed:account-a\"}'", "browser_close --payload '{\"browser\":\"managed:agentbay:cloud-a\"}'", "browser_close --payload '{\"browser\":\"account-b\",\"deleteProfile\":true}'"];
|
|
371
379
|
}, {
|
|
372
380
|
readonly name: "tab_open";
|
|
373
381
|
readonly description: "打开或按 URL 规则复用 Tab,并等待新页面加载完成";
|
package/dist/commands.js
CHANGED
|
@@ -210,7 +210,7 @@ export const COMMANDS = [
|
|
|
210
210
|
// ── 浏览器 ────────────────────────────────────────────────────────────────
|
|
211
211
|
{
|
|
212
212
|
name: 'browser_list',
|
|
213
|
-
description: '
|
|
213
|
+
description: '列出所有浏览器及其连接状态、类型和托管实例信息;AgentBay 可包含镜像、持久化 Context 和串流地址',
|
|
214
214
|
examples: ['browser_list'],
|
|
215
215
|
},
|
|
216
216
|
{
|
|
@@ -220,19 +220,33 @@ export const COMMANDS = [
|
|
|
220
220
|
},
|
|
221
221
|
{
|
|
222
222
|
name: 'browser_launch',
|
|
223
|
-
description: '
|
|
223
|
+
description: '启动本地 Chrome 或 AgentBay 云浏览器,并通过 CDP 接入 Mearl',
|
|
224
224
|
params: [
|
|
225
225
|
{ name: 'name', type: 'string', required: true, description: '实例名称,最多 64 个字符' },
|
|
226
|
-
{
|
|
226
|
+
{
|
|
227
|
+
name: 'provider',
|
|
228
|
+
type: '"local" | "agentbay"',
|
|
229
|
+
description: '运行环境,默认 local;agentbay 从 AGENTBAY_KEY 创建云浏览器',
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
name: 'imageId',
|
|
233
|
+
type: 'string',
|
|
234
|
+
description: 'AgentBay 镜像别名或具体镜像 ID;默认使用已验证的 Linux Browser Use 内网镜像',
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
name: 'headless',
|
|
238
|
+
type: 'boolean',
|
|
239
|
+
description: '本地 provider 是否无头运行,默认 true;AgentBay 固定为 false,不支持 true',
|
|
240
|
+
},
|
|
227
241
|
{
|
|
228
242
|
name: 'userAgentMode',
|
|
229
243
|
type: '"default" | "desktop"',
|
|
230
|
-
description: 'UA 模式:default 使用
|
|
244
|
+
description: 'UA 模式:default 使用 provider 默认 UA;desktop 本地使用匹配本机版本的 UA,AgentBay 复用控制浏览器的桌面 UA',
|
|
231
245
|
},
|
|
232
246
|
{
|
|
233
247
|
name: 'persistent',
|
|
234
248
|
type: 'boolean',
|
|
235
|
-
description: '
|
|
249
|
+
description: '关闭后是否保留浏览器状态,默认 false;本地保留 Profile,AgentBay 同名实例复用云端 Context',
|
|
236
250
|
},
|
|
237
251
|
{ name: 'url', type: 'string', description: '登录完成后打开的初始页面' },
|
|
238
252
|
{ name: 'executablePath', type: 'string', description: '自定义 Chrome 可执行文件路径' },
|
|
@@ -252,10 +266,13 @@ export const COMMANDS = [
|
|
|
252
266
|
{
|
|
253
267
|
name: 'copyCookieDomains',
|
|
254
268
|
type: 'string[]',
|
|
255
|
-
description: '
|
|
269
|
+
description: '从控制浏览器复制到本地或 AgentBay 新实例的 Cookie 域名列表,可与本地 TDBank 登录组合',
|
|
256
270
|
},
|
|
257
271
|
],
|
|
258
272
|
examples: [
|
|
273
|
+
`browser_launch --payload '{"name":"cloud-a","provider":"agentbay","userAgentMode":"desktop","url":"https://example.com"}'`,
|
|
274
|
+
`browser_launch --payload '{"name":"cloud-public","provider":"agentbay","imageId":"browser_latest","url":"https://example.com"}'`,
|
|
275
|
+
`browser_launch --payload '{"name":"cloud-login","provider":"agentbay","persistent":true,"copyCookieDomains":["example.com"],"url":"https://example.com/account"}'`,
|
|
259
276
|
`browser_launch --payload '{"name":"account-a","headless":true,"accountId":12345}'`,
|
|
260
277
|
`browser_launch --payload '{"name":"figma","userAgentMode":"desktop","copyCookieDomains":["figma.com"]}'`,
|
|
261
278
|
`browser_launch --payload '{"name":"account-b","query":"test_account","url":"https://www.taobao.com"}'`,
|
|
@@ -264,7 +281,7 @@ export const COMMANDS = [
|
|
|
264
281
|
},
|
|
265
282
|
{
|
|
266
283
|
name: 'browser_close',
|
|
267
|
-
description: '
|
|
284
|
+
description: '关闭指定托管浏览器并按策略保留或清理本地 Profile / AgentBay Context',
|
|
268
285
|
params: [
|
|
269
286
|
{
|
|
270
287
|
name: 'browser',
|
|
@@ -272,10 +289,15 @@ export const COMMANDS = [
|
|
|
272
289
|
required: true,
|
|
273
290
|
description: '托管浏览器的 browserId 或名称',
|
|
274
291
|
},
|
|
275
|
-
{
|
|
292
|
+
{
|
|
293
|
+
name: 'deleteProfile',
|
|
294
|
+
type: 'boolean',
|
|
295
|
+
description: '强制删除持久化本地 Profile 或 AgentBay Context,默认 false',
|
|
296
|
+
},
|
|
276
297
|
],
|
|
277
298
|
examples: [
|
|
278
299
|
`browser_close --payload '{"browser":"managed:account-a"}'`,
|
|
300
|
+
`browser_close --payload '{"browser":"managed:agentbay:cloud-a"}'`,
|
|
279
301
|
`browser_close --payload '{"browser":"account-b","deleteProfile":true}'`,
|
|
280
302
|
],
|
|
281
303
|
},
|
|
@@ -137,9 +137,19 @@ export interface ManagedBrowserAccount {
|
|
|
137
137
|
}
|
|
138
138
|
export interface ManagedBrowserInfo extends BrowserInfoBase {
|
|
139
139
|
type: 'managed';
|
|
140
|
+
provider?: 'local' | 'agentbay';
|
|
140
141
|
headless: boolean;
|
|
141
142
|
persistent: boolean;
|
|
142
|
-
cdpPort
|
|
143
|
+
cdpPort?: number;
|
|
144
|
+
agentbaySessionId?: string;
|
|
145
|
+
/** AgentBay image used to create the session. */
|
|
146
|
+
agentbayImageId?: string;
|
|
147
|
+
/** Persistent AgentBay browser context ID when enabled for this instance. */
|
|
148
|
+
agentbayContextId?: string;
|
|
149
|
+
/** Stable AgentBay browser context name derived from the managed browser name. */
|
|
150
|
+
agentbayContextName?: string;
|
|
151
|
+
/** Browser-accessible AgentBay session URL when returned by the provider. */
|
|
152
|
+
agentbayAccessUrl?: string;
|
|
143
153
|
createdAt: string;
|
|
144
154
|
account?: ManagedBrowserAccount;
|
|
145
155
|
copiedCookies?: {
|
|
@@ -178,7 +188,13 @@ export interface BrowserReleaseResult {
|
|
|
178
188
|
}
|
|
179
189
|
export interface BrowserLaunchParams {
|
|
180
190
|
name: string;
|
|
191
|
+
/** Browser runtime provider. Defaults to local Chrome. */
|
|
192
|
+
provider?: 'local' | 'agentbay';
|
|
193
|
+
/** AgentBay image alias or concrete image ID. Only supported by the AgentBay provider. */
|
|
194
|
+
imageId?: string;
|
|
195
|
+
/** Local Chrome defaults to true. AgentBay is fixed to false and rejects true. */
|
|
181
196
|
headless?: boolean;
|
|
197
|
+
/** Desktop mode uses the local Chrome UA or copies the selected control browser UA to AgentBay. */
|
|
182
198
|
userAgentMode?: 'default' | 'desktop';
|
|
183
199
|
persistent?: boolean;
|
|
184
200
|
executablePath?: string;
|
|
@@ -188,6 +204,7 @@ export interface BrowserLaunchParams {
|
|
|
188
204
|
site?: string | number;
|
|
189
205
|
query?: string;
|
|
190
206
|
tabId?: number;
|
|
207
|
+
/** Copy matching cookies from the selected control browser before opening url. */
|
|
191
208
|
copyCookieDomains?: string[];
|
|
192
209
|
}
|
|
193
210
|
export interface BrowserCloseParams {
|
package/dist/socket.js
CHANGED
|
@@ -41,8 +41,16 @@ export function getDefaultBrowser() {
|
|
|
41
41
|
function findConnectedBrowser(items, selector) {
|
|
42
42
|
const normalized = selector.trim().toLowerCase();
|
|
43
43
|
const connected = items.filter(item => item.status === 'connected');
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const byId = connected.find(item => String(item.browserId).toLowerCase() === normalized);
|
|
45
|
+
if (byId)
|
|
46
|
+
return byId;
|
|
47
|
+
const exactNameMatches = connected.filter(item => String(item.name).toLowerCase() === normalized);
|
|
48
|
+
if (exactNameMatches.length > 1) {
|
|
49
|
+
throw new Error(`Browser name "${selector.trim()}" is ambiguous. Use a full browserId: ${exactNameMatches
|
|
50
|
+
.map(item => String(item.browserId))
|
|
51
|
+
.join(', ')}`);
|
|
52
|
+
}
|
|
53
|
+
return (exactNameMatches[0] ??
|
|
46
54
|
connected.find(item => String(item.browserId).toLowerCase().includes(normalized) ||
|
|
47
55
|
String(item.name).toLowerCase().includes(normalized)) ??
|
|
48
56
|
null);
|