@mearl/client 2.4.0 → 2.5.0

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 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","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 和动态 CDP 端口。控制浏览器需先登录 TDBank;生成的 SSO 地址在本地内部传递,新实例可以使用 `headless: true`(默认)完成测试账号登录。`copyCookieDomains` 可把控制浏览器指定域的 Cookie 复制到新实例,Cookie 值不会出现在命令结果或日志中;`userAgentMode: "desktop"` 可让实例使用匹配本机 Chrome 版本的桌面 UA。完整设计见 [托管浏览器与 TDBank 多账号设计](../../docs/managed-browsers.md)。
108
+ 托管浏览器使用独立 Profile。控制浏览器需先登录 TDBank;生成的 SSO 地址在本地内部传递,本地实例可以使用 `headless: true`(默认)完成测试账号登录。AgentBay 固定为非 headless,传 `headless: true` 会被拒绝;`imageId` 可指定镜像别名或具体镜像 ID,省略时使用已验证的 Linux Browser Use 内网镜像。`copyCookieDomains` 可把控制浏览器指定域的 Cookie 复制到本地或 AgentBay 新实例,Cookie 值不会经过 cloud-server,也不会出现在命令结果或日志中;`userAgentMode: "desktop"` 让本地实例使用匹配本机 Chrome 版本的桌面 UA,AgentBay 则复用当前控制浏览器的桌面 UA。`browser_list` 通过 `agentbayImageId` 返回实例的实际镜像;当服务返回无影浏览器串流入口时,还会通过 `agentbayAccessUrl` 暴露,该地址可能包含临时访问凭据,应按敏感信息处理。完整设计见 [托管浏览器与 TDBank 多账号设计](../../docs/managed-browsers.md)。
108
109
 
109
110
  ## 架构
110
111
 
@@ -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 byExactName = browsers.find(b => b.browserName.toLowerCase() === sel);
72
- if (byExactName)
73
- return byExactName;
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. */
@@ -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 可包含 agentbayImageId 和 agentbayAccessUrl";
298
298
  readonly examples: ["browser_list"];
299
299
  }, {
300
300
  readonly name: "browser_release";
@@ -302,20 +302,28 @@ 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: "启动独立 Chrome,可在新实例中通过 TDBank 登录指定账号";
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 使用 Chrome 默认 UA,desktop 使用匹配本机版本的桌面 UA";
326
+ readonly description: "UA 模式:default 使用 provider 默认 UA;desktop 本地使用匹配本机版本的 UA,AgentBay 复用控制浏览器的桌面 UA";
319
327
  }, {
320
328
  readonly name: "persistent";
321
329
  readonly type: "boolean";
@@ -351,9 +359,9 @@ export declare const COMMANDS: readonly [{
351
359
  }, {
352
360
  readonly name: "copyCookieDomains";
353
361
  readonly type: "string[]";
354
- readonly description: "从控制浏览器复制到新实例的 Cookie 域名列表,可与 TDBank 登录组合";
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\",\"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
367
  readonly description: "关闭指定托管浏览器并按策略清理独立 Profile";
@@ -367,7 +375,7 @@ export declare const COMMANDS: readonly [{
367
375
  readonly type: "boolean";
368
376
  readonly description: "强制删除持久化 Profile,默认 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 可包含 agentbayImageId 和 agentbayAccessUrl',
214
214
  examples: ['browser_list'],
215
215
  },
216
216
  {
@@ -220,14 +220,28 @@ export const COMMANDS = [
220
220
  },
221
221
  {
222
222
  name: 'browser_launch',
223
- description: '启动独立 Chrome,可在新实例中通过 TDBank 登录指定账号',
223
+ description: '启动本地 Chrome 或 AgentBay 云浏览器,并通过 CDP 接入 Mearl',
224
224
  params: [
225
225
  { name: 'name', type: 'string', required: true, description: '实例名称,最多 64 个字符' },
226
- { name: 'headless', type: 'boolean', description: '是否无头运行,默认 true' },
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 使用 Chrome 默认 UA,desktop 使用匹配本机版本的桌面 UA',
244
+ description: 'UA 模式:default 使用 provider 默认 UA;desktop 本地使用匹配本机版本的 UA,AgentBay 复用控制浏览器的桌面 UA',
231
245
  },
232
246
  {
233
247
  name: 'persistent',
@@ -252,10 +266,13 @@ export const COMMANDS = [
252
266
  {
253
267
  name: 'copyCookieDomains',
254
268
  type: 'string[]',
255
- description: '从控制浏览器复制到新实例的 Cookie 域名列表,可与 TDBank 登录组合',
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","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"}'`,
@@ -276,6 +293,7 @@ export const COMMANDS = [
276
293
  ],
277
294
  examples: [
278
295
  `browser_close --payload '{"browser":"managed:account-a"}'`,
296
+ `browser_close --payload '{"browser":"managed:agentbay:cloud-a"}'`,
279
297
  `browser_close --payload '{"browser":"account-b","deleteProfile":true}'`,
280
298
  ],
281
299
  },
@@ -137,9 +137,15 @@ 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: number;
143
+ cdpPort?: number;
144
+ agentbaySessionId?: string;
145
+ /** AgentBay image used to create the session. */
146
+ agentbayImageId?: string;
147
+ /** Browser-accessible AgentBay session URL when returned by the provider. */
148
+ agentbayAccessUrl?: string;
143
149
  createdAt: string;
144
150
  account?: ManagedBrowserAccount;
145
151
  copiedCookies?: {
@@ -178,7 +184,13 @@ export interface BrowserReleaseResult {
178
184
  }
179
185
  export interface BrowserLaunchParams {
180
186
  name: string;
187
+ /** Browser runtime provider. Defaults to local Chrome. */
188
+ provider?: 'local' | 'agentbay';
189
+ /** AgentBay image alias or concrete image ID. Only supported by the AgentBay provider. */
190
+ imageId?: string;
191
+ /** Local Chrome defaults to true. AgentBay is fixed to false and rejects true. */
181
192
  headless?: boolean;
193
+ /** Desktop mode uses the local Chrome UA or copies the selected control browser UA to AgentBay. */
182
194
  userAgentMode?: 'default' | 'desktop';
183
195
  persistent?: boolean;
184
196
  executablePath?: string;
@@ -188,6 +200,7 @@ export interface BrowserLaunchParams {
188
200
  site?: string | number;
189
201
  query?: string;
190
202
  tabId?: number;
203
+ /** Copy matching cookies from the selected control browser before opening url. */
191
204
  copyCookieDomains?: string[];
192
205
  }
193
206
  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
- return (connected.find(item => String(item.browserId).toLowerCase() === normalized) ??
45
- connected.find(item => String(item.name).toLowerCase() === normalized) ??
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mearl/client",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Client SDK & CLI for Mearl — communicate with Chrome Extension via Unix Socket",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",