@mearl/client 3.1.12-beta.0 → 3.2.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.en.md CHANGED
@@ -176,7 +176,7 @@ It supports `signal` cancellation and `executionTimeoutSec`, sharing executors w
176
176
 
177
177
  ### Control sessions and files
178
178
 
179
- Use `session_list` to find control sessions. Use `session_manage` with `handoff` or `resume` and pass `--session <sessionId>` or a payload `sessionId`. For external Providers such as Ego, select the task with `--browser`.
179
+ Use `session_list` to find control sessions. Use `session_manage` with `handoff` or `resume` and pass `--session <sessionId>` or a payload `sessionId`. A Provider that supports task sessions can bind that session to a native task, such as an Ego Space. For an external task exposed directly as a browser, select it with `--browser`.
180
180
 
181
181
  Use `session_manage --browser <browserId> --payload '{"operation":"new"}'` to create an empty session, or pass `--session new` on the first `tab_open`, `page_snapshot`, or `page_screenshot`. Use the returned `sessionId` for subsequent calls.
182
182
 
@@ -199,7 +199,7 @@ New extension background tabs join a collapsed `Mearl` group; foreground tabs jo
199
199
 
200
200
  Ending a session closes its created tabs by default. Reused user tabs always stay open. Set `keepTabIds` to retain specific result tabs or `closeCreatedTabs:false` to keep all tabs. Providers without tab closing support keep tabs open and release the session by default. Retained tabs keep their mocks and emulation by default. Set `preserveEnvironment:false` to clear the session tabs' environment. Active sessions block browser-wide release and close.
201
201
 
202
- `page_download` listens before clicking and returns a browser artifact. CLI `--output` or SDK `saveArtifact(artifact, absolutePath, { session })` exports in 256 KiB chunks. `page_upload.files` accepts caller absolute `{filePath}` or browser `{artifactId}`; `filePaths` remains browser-host paths. Files are limited to 256 MiB. Caller-saved outputs are independent of temporary artifacts. Session release cleans temporary artifacts; `keepArtifactIds` retains selected ones. Sessionless artifacts expire after one idle hour; host exit clears staging.
202
+ `page_download` listens before clicking and returns a browser artifact. CLI `--output` or SDK `saveArtifact(artifact, absolutePath, { session })` exports in 256 KiB chunks. `page_upload.files` accepts caller absolute `{filePath}` or browser `{artifactId}`; `filePaths` refers to browser-host paths. Files are limited to 256 MiB. Caller-saved outputs are independent of temporary artifacts. Session release cleans temporary artifacts. Ordinary sessions support `keepArtifactIds`; save artifacts before ending a Provider task session. Sessionless artifacts expire after one idle hour and host exit clears staging.
203
203
 
204
204
  Through the Chrome extension, `files` transfers up to 256 MiB total per upload in chunks to file inputs in HTTP(S) documents without **Allow access to file URLs**. With `filePaths`, Chrome reads host files directly. This supports large files and sites that require native file selection events. The extension requires the setting for `filePaths`. Direct CDP uploads do not require the extension setting.
205
205
 
package/README.md CHANGED
@@ -176,7 +176,7 @@ SDK 宿主可从 `@mearl/client/script` 导入 `executeScript(code, options)`,
176
176
 
177
177
  ### 控制会话与文件
178
178
 
179
- 用 `session_list` 查询控制会话,使用 `session_manage` 的 `handoff` 和 `resume` 交接控制。指定 `--session <sessionId>` 或在 payload 中传入 `sessionId`。Ego 等外部 Provider 通过 `--browser` 指定任务。
179
+ 用 `session_list` 查询控制会话,使用 `session_manage` 的 `handoff` 和 `resume` 交接控制。指定 `--session <sessionId>` 或在 payload 中传入 `sessionId`。支持任务会话的 Provider 可以将该会话关联到原生任务,例如 Ego Space。若外部任务直接作为浏览器实例暴露,则通过 `--browser` 选择。
180
180
 
181
181
  用 `session_manage --browser <browserId> --payload '{"operation":"new"}'` 创建空会话。也可以在首次 `tab_open`、`page_snapshot` 或 `page_screenshot` 上用 `--session new`。后续用响应中的 `sessionId` 自动路由。会话绑定一个浏览器与传输,页面在首次使用时关联。同一页面只允许一个会话控制,会话之间共享 Cookie 和存储。
182
182
 
@@ -199,7 +199,7 @@ mearl session_manage --session '<sessionId>' --payload '{"operation":"end","keep
199
199
 
200
200
  结束会话默认关闭会话新建的标签页,复用的用户页面始终保留。用 `keepTabIds` 保留指定结果页,或用 `closeCreatedTabs:false` 保留全部标签页。未提供关闭标签页能力的 Provider 默认保留页面并释放会话。保留的页面默认保留 Mock 和模拟环境,传 `preserveEnvironment:false` 可清理会话页面的环境。活动会话存在时,浏览器级释放与关闭会被拒绝。
201
201
 
202
- `page_download` 先监听再点击,返回浏览器文件产物;CLI `--output` 或 SDK `saveArtifact(artifact, absolutePath, { session })` 以 256 KiB 分块导出到调用方。`page_upload.files` 接受调用方绝对路径 `{filePath}` 或浏览器 `{artifactId}`,`filePaths` 仍指浏览器宿主路径。单文件最多 256 MiB;保存到调用方的结果独立于临时产物。会话释放清理临时产物,`keepArtifactIds` 可保留指定产物;无会话产物空闲一小时回收,宿主退出清理暂存。
202
+ `page_download` 先监听再点击,返回浏览器文件产物;CLI `--output` 或 SDK `saveArtifact(artifact, absolutePath, { session })` 以 256 KiB 分块导出到调用方。`page_upload.files` 接受调用方绝对路径 `{filePath}` 或浏览器 `{artifactId}`,`filePaths` 仍指浏览器宿主路径。单文件最多 256 MiB;保存到调用方的结果独立于临时产物。会话释放清理临时产物,普通会话可用 `keepArtifactIds` 保留指定产物。Provider 任务会话需要在结束前保存产物。无会话产物空闲一小时回收,宿主退出清理暂存。
203
203
 
204
204
  通过 Chrome 扩展连接时,`files` 支持 HTTP(S) 页面的文件输入框,分块传输合计最多 256 MiB,无需开启「允许访问文件网址」。`filePaths` 由 Chrome 直接读取宿主文件,适用于大文件或要求原生文件选择事件的站点,在扩展连接中需要开启该设置。直连 CDP 的上传无需此扩展设置。
205
205
 
@@ -8,7 +8,7 @@
8
8
  * registry directory and record shape; reading scans every *.json in the dir,
9
9
  * so it never needs to replicate daemon-core's filename hashing.
10
10
  */
11
- import type { BrowserCapabilities, BrowserDetails, BrowserPairingInfo, BrowserProviderIdentity, BrowserProviderOperation, BrowserReference, BrowserTransport } from '@mearl/browser-core';
11
+ import { type BrowserCapabilities, type BrowserDetails, type BrowserPairingInfo, type BrowserProviderIdentity, type BrowserProviderOperation, type BrowserReference, type BrowserTransport } from '@mearl/browser-core';
12
12
  export interface LiveBrowser {
13
13
  pid: number;
14
14
  browserId: string;
@@ -11,6 +11,7 @@
11
11
  import fs from 'node:fs';
12
12
  import os from 'node:os';
13
13
  import path from 'node:path';
14
+ import { isDiscoverableBrowser, } from '@mearl/browser-core';
14
15
  /** Must match @mearl/daemon-core's DAEMON_HOME + the native-host 'browsers' subdir. */
15
16
  const BROWSERS_DIR = path.join(os.homedir(), '.mearl', 'browsers');
16
17
  function isAlive(pid) {
@@ -51,7 +52,11 @@ export function listLiveBrowsers() {
51
52
  // Corrupt or mid-write (a writer may be renaming it in); skip.
52
53
  continue;
53
54
  }
54
- if (rec && typeof rec.pid === 'number' && rec.socketPath && isAlive(rec.pid)) {
55
+ if (rec &&
56
+ typeof rec.pid === 'number' &&
57
+ rec.socketPath &&
58
+ isDiscoverableBrowser(rec) &&
59
+ isAlive(rec.pid)) {
55
60
  out.push(rec);
56
61
  }
57
62
  }
@@ -468,6 +468,10 @@ export declare const COMMANDS: readonly [{
468
468
  readonly name: "sessionId";
469
469
  readonly type: "string";
470
470
  readonly description: "已有会话 ID,也可使用 --session";
471
+ }, {
472
+ readonly name: "providerOptions";
473
+ readonly type: "Record<string, JSON value>";
474
+ readonly description: "new 时传入所选 Provider 的任务参数";
471
475
  }, {
472
476
  readonly name: "reason";
473
477
  readonly type: "string";
package/dist/commands.js CHANGED
@@ -488,6 +488,11 @@ export const COMMANDS = [
488
488
  description: 'new 创建空会话,handoff 交给用户,resume 恢复控制,end 结束会话并释放资源',
489
489
  },
490
490
  { name: 'sessionId', type: 'string', description: '已有会话 ID,也可使用 --session' },
491
+ {
492
+ name: 'providerOptions',
493
+ type: 'Record<string, JSON value>',
494
+ description: 'new 时传入所选 Provider 的任务参数',
495
+ },
491
496
  { name: 'reason', type: 'string', description: 'handoff 时说明需要用户处理的事项' },
492
497
  {
493
498
  name: 'closeCreatedTabs',
package/dist/guide.js CHANGED
@@ -66,7 +66,7 @@ export async function readGuide(id, commandName = 'mearl', version = CLIENT_VERS
66
66
  if (id === 'skills' || hasSetup) {
67
67
  const { readInstallationManagement, setupManagementCommand } = await import('@mearl/daemon-core/installation');
68
68
  const installed = await readInstallationManagement();
69
- const command = setupManagementCommand(installed.setup ?? { package: '@mearl/setup', version: 'beta' });
69
+ const command = setupManagementCommand(installed.setup ?? { package: '@mearl/setup', version: 'beta' }).replace(/@latest$/, '');
70
70
  if (hasSetup) {
71
71
  source = source.replaceAll('{{setup}}', command);
72
72
  if (id !== 'skills') {
@@ -74,7 +74,7 @@ mearl page_snapshot --browser '<browserId>' --payload '{"tabId":12345,"mode":"vi
74
74
 
75
75
  常规响应的 session 只包含 ID、浏览器、传输、状态、代次和可选 reason,不重复标签页清单。页面列表用 tab_list 查询;session_manage 的交接结果还包含会话页面的 tabs。CLI、SDK、MCP 使用同一结构。
76
76
 
77
- 会话自动记录新建与复用页面,串行执行同页面操作,并阻止其他会话或无会话调用占用其页面。不同任务使用独立会话;会话不隔离 Cookie 与存储,账号或浏览器共享资源冲突时使用独立浏览器。Extension、CDP 和采用 Mearl 控制的 Provider 共用这些规则;声明外部控制的 Provider(如 Ego)拒绝 Mearl 会话,交接和收尾沿用原工具。
77
+ 会话自动记录新建与复用页面,串行执行同页面操作,并阻止其他会话或无会话调用占用其页面。不同任务使用独立会话。会话共享 Cookie 与存储,账号或资源冲突时使用独立浏览器。支持任务会话的 Provider 可在 `session_manage new` 绑定原生任务,交接和收尾通过同一会话的 ID 执行。
78
78
 
79
79
  `session_manage` 的 `operation:"handoff"` 将控制权交给用户,用 `--session` 或 `sessionId` 指定会话,`reason` 说明需要用户处理的事项。用户在 Mearl Popup 浏览器管理页接管和交还;无扩展 UI 的环境,在用户明确确认交还后调用 `operation:"resume"`。
80
80
 
@@ -4,16 +4,13 @@ Mearl 单独使用时沿用主 Skill 的页面操作流程。任务已有 Ego、
4
4
 
5
5
  ## EgoLite
6
6
 
7
- 使用独立 `@mearl/provider-ego` 0.1.1+,安装入口和支持范围以 Provider 自身 README 为准。Mearl 3.0.7+ 可用 `{{setup}} provider install @mearl/provider-ego` 安装并注册;源码构建后可指定 `@mearl/provider-ego@/absolute/path/to/provider-ego`,也可指定带包名的 GitHub Release 安装包地址。
7
+ 使用 `{{setup}} provider install @mearl/provider-ego` 安装并注册独立 Ego Provider。在支持 Provider 任务会话的宿主上,`browser_list` 会发现正在运行的 EgoLite 实例。
8
8
 
9
- - 无需浏览器扩展。已有扩展可关闭 Agent 服务,保留人工调试面板。Mearl 本地运行时仍负责 Provider 路由和已安装 App 资源解析。
10
- - 一个 Provider 浏览器对应一个 Ego Space。启动时传 `providerOptions.name`;已有任务传数字 `providerOptions.spaceId`。只关联 Agent 所有的 Space,不隐式认领用户 Space。
11
- - 使用 Provider 返回的完整 `browserId` 和页面 `tabId`,不需要 Agent 手工匹配扩展标签页。不传 Mearl `--session`。
12
- - Space 交接、恢复和完成统一使用 `mearl session_manage --browser '<browserId>' --payload '{"operation":"handoff"}'`;operation 支持 `handoff`、`resume`、`end`。end 可带 `keepTabIds` 保留数字 ID 对应的结果页。仅在用户明确交还后 resume。
13
- - 所有页面操作经过 Ego 原生通道;用户接管、Space 失活时由 Ego 阻断,不改走扩展。连接断开或效果未知时不重放动作。
14
- - 设备和 App 分别通过 `set_device_emulation`、`set_app_profile` 设置。App 来自已安装目录,使用当前已解析版本;UA、声明式全局变量和页面桥通过原生 CDP 安装。导航、截图继续使用同一个 Provider。
15
- - 共享原生页面宿主提供设备外壳、根 WebView、网络控制和已安装 App 的协议/授权桥。真实授权仍需用户批准;接管会取消待授权会话,交还不恢复旧请求。不提供扩展专属请求/日志入口,其他参数限制以 Provider 指引为准。
16
- - `end` 默认不保留 Agent 页面;需要保留结果时显式传 `keepTabIds`。`browser_manage detach` 只解绑,不结束 Space、不清除模拟;需要普通页面时先清除模拟再 end。
9
+ - 用完整 `browserId` 执行 `session_manage` 的 `new`,并保存返回的 `sessionId`。可选的 `providerOptions.name` 用于新 Space,数字 `providerOptions.spaceId` 用于关联已有 Agent Space。
10
+ - 扩展已连接、开启 Agent 服务且能匹配同一个物理页面时,Mearl 优先由扩展执行页面操作。Provider 负责 Space 生命周期和标签页范围。页面通道在会话建立时确定,见 `session.task.pageTransport`。
11
+ - 后续操作传 `--session <sessionId>` 和当前会话返回的页面 `tabId`。以 `get_capabilities` 核对当前通道能力。
12
+ - 交接、恢复和完成使用 `session_manage` 的 `handoff`、`resume`、`end`。仅在用户明确交还后恢复。已有页面会保留,用 `keepTabIds` 留下本次会话新建的结果页。
13
+ - 旧版宿主可沿用 `browser_manage` 的 `launch`,然后使用返回的完整任务 `browserId`。这种任务的 `session_manage` 同样按该 `browserId` 路由。
17
14
 
18
15
  ## agent-browser 等其他工具
19
16
 
@@ -19,7 +19,7 @@ mearl page_click --payload '{"tabId":12345,"selector":"@e3"}'
19
19
 
20
20
  默认使用统一发现。需要选择目标时用 `browser_list`,沿用返回的完整实例名或 `browserId`。远端连接与 Provider 选择见[浏览器管理](./api-browser-setup.md)。
21
21
 
22
- 多步浏览器任务默认使用会话。首次 `tab_open` / `page_snapshot` / `page_screenshot` 传 `--session new`,后续复用完整 `session.sessionId` 与 `tabId`。会话建立后,页面 action 通常只传 `--session <id>`、`tabId` 及业务参数,不重复传 `--browser`;CLI 会从会话恢复浏览器与传输。仅当会话解析报告跨宿主歧义,或需要显式限定宿主时,再传 `--browser`;它会限定查找范围并校验结果是否与会话匹配。Cookie 和存储仍共享。目标声明由外部工具控制时(例如 Ego 任务),沿用其交接与收尾,不传 Mearl `--session`;跨工具先核验同一实例和物理页面,不能仅凭 URL/标题或直接复用 ref、label、tab ID。详见[工具协作](./browser-tool-cooperation.md)。
22
+ 多步浏览器任务默认使用会话。首次 `tab_open` / `page_snapshot` / `page_screenshot` 传 `--session new`,后续复用完整 `session.sessionId` 与 `tabId`。会话建立后,页面 action 通常只传 `--session <id>`、`tabId` 及业务参数,不重复传 `--browser`。CLI 会从会话恢复浏览器与传输。仅在跨宿主歧义或需要显式限定宿主时传 `--browser`。Cookie 和存储仍共享。支持任务会话的 Provider 可把会话绑定到原生任务,例如 Ego Space。直接以浏览器 ID 操作外部任务时,沿用该任务的交接和收尾流程。跨工具核验同一实例和物理页面后再操作。详见[工具协作](./browser-tool-cooperation.md)。
23
23
 
24
24
  ## 观察、操作与判读
25
25
 
package/dist/socket.js CHANGED
@@ -120,6 +120,12 @@ function isConnectedBrowser(browser) {
120
120
  function supportsAction(browser, action, data) {
121
121
  if (action === 'browser_release')
122
122
  return false;
123
+ if (browser.details?.taskSessionScope === 'browser' &&
124
+ data[SESSION_OPTION] &&
125
+ (isBrowserCapabilityAction(action) ||
126
+ action === 'run_actions' ||
127
+ action.startsWith('__artifact_')))
128
+ return true;
123
129
  if (browser.transport === 'provider') {
124
130
  if (action === 'session_manage' ||
125
131
  (action === 'get_capabilities' && isConnectedBrowser(browser)))
@@ -387,6 +393,18 @@ export function invoke(action, data = {}, options = {}) {
387
393
  });
388
394
  }
389
395
  const selector = browser ?? defaultBrowser ?? process.env.MEARL_BROWSER ?? undefined;
396
+ const sessionId = options.controlSessionId;
397
+ if (!selector &&
398
+ !options.socketPath &&
399
+ !process.env.MEARL_SOCKET_PATH?.trim() &&
400
+ sessionId &&
401
+ sessionId !== 'new') {
402
+ return resolveControlSession(sessionId, timeoutSec, controlSource, options.deadline).then(({ session }) => {
403
+ if (!session?.browserId)
404
+ throw new Error('CONTROL_SESSION_NOT_FOUND');
405
+ return dispatchInvoke(action, resolvedData, timeoutSec, session.browserId, controlSource, undefined, options.deadline);
406
+ });
407
+ }
390
408
  return dispatchInvoke(action, resolvedData, timeoutSec, selector, controlSource, options.socketPath, options.deadline);
391
409
  }
392
410
  /** Infrastructure calls stay on this machine even when an Agent has selected an external browser. */
@@ -436,7 +454,7 @@ async function listControlSessions(selector, timeoutSec, controlSource, socketPa
436
454
  return { sessions, ...(warnings.length ? { warnings } : {}) };
437
455
  }
438
456
  /** Session ownership lives in the control hosts and survives individual CLI connections. */
439
- async function resolveControlSession(sessionId, timeoutSec, controlSource) {
457
+ async function resolveControlSession(sessionId, timeoutSec, controlSource, deadline) {
440
458
  const browsers = listLiveBrowsers();
441
459
  const configuredSocketPath = process.env.MEARL_SOCKET_PATH?.trim();
442
460
  const sockets = configuredSocketPath
@@ -451,9 +469,9 @@ async function resolveControlSession(sessionId, timeoutSec, controlSource) {
451
469
  : browsers.find(browser => browser.transport === 'provider');
452
470
  if (!sockets.length && !provider)
453
471
  sockets.push(SOCKET_PATH);
454
- const requests = sockets.map(socketPath => invokeOnce('__control_session_resolve', { sessionId }, timeoutSec, socketPath, controlSource));
472
+ const requests = sockets.map(socketPath => invokeOnce('__control_session_resolve', { sessionId }, timeoutSec, socketPath, controlSource, undefined, undefined, deadline));
455
473
  if (provider) {
456
- requests.push(invokeOnce('__control_session_resolve', { sessionId }, timeoutSec, provider.socketPath, controlSource, provider.browserId));
474
+ requests.push(invokeOnce('__control_session_resolve', { sessionId }, timeoutSec, provider.socketPath, controlSource, provider.browserId, undefined, deadline));
457
475
  }
458
476
  const results = await Promise.allSettled(requests);
459
477
  const sessions = results.flatMap(result => result.status === 'fulfilled' && result.value?.session?.sessionId === sessionId
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mearl/client",
3
- "version": "3.1.12-beta.0",
3
+ "version": "3.2.0",
4
4
  "description": "Unified Mearl SDK & CLI for local and remote browsers",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -69,11 +69,11 @@
69
69
  "commander": "^14.0.3",
70
70
  "fastest-levenshtein": "^1.0.16",
71
71
  "ws": "^8.18.0",
72
- "@mearl/cloud-types": "3.1.12-beta.0",
73
- "@mearl/daemon-core": "3.1.12-beta.0",
74
- "@mearl/provider": "3.1.12-beta.0",
75
- "@mearl/agent-runtime": "3.1.12-beta.0",
76
- "@mearl/browser-core": "3.1.12-beta.0"
72
+ "@mearl/daemon-core": "3.2.0",
73
+ "@mearl/provider": "3.2.0",
74
+ "@mearl/agent-runtime": "3.2.0",
75
+ "@mearl/cloud-types": "3.2.0",
76
+ "@mearl/browser-core": "3.2.0"
77
77
  },
78
78
  "devDependencies": {
79
79
  "@types/node": "^24.9.1",