@mearl/provider 2.21.0 → 3.0.0-beta.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
  Provider 使用相同的 `BrowserProviderDefinition`;区别只在于运行时位于 Native Host 进程内,
5
5
  还是通过本地 Provider Socket 接入。
6
6
 
7
+ action 清单直接复用 `@mearl/browser-core/browserActionProtocol` 的能力动作合同,不维护独立生成副本。
8
+
7
9
  ## 核心模型
8
10
 
9
11
  控制会话由 Mearl 管理。Provider 继续接收目标实例、页面与普通 action,无需处理控制会话 ID、资源归属或人工交接状态。带 `--session` 的释放只结束 Mearl 任务控制;实例关闭、退出接管与 Cookie 同步仍使用 Provider 的生命周期方法。上传与下载分别按 `capabilities.actions` 中的 `page_upload`、`page_download` 声明使用。
@@ -40,7 +42,7 @@ pnpm add @mearl/provider
40
42
  "provider": {
41
43
  "providerId": "example-device",
42
44
  "name": "Example device provider",
43
- "protocolVersion": 2,
45
+ "protocolVersion": 3,
44
46
  "entry": "./dist/runtime.js",
45
47
  "browserType": {
46
48
  "name": "Device",
@@ -147,7 +149,7 @@ Provider 需要查询设备池、已有会话或动态候选项时,声明 `bro
147
149
  初次查询携带静态表单默认值;查询只传入可解析的字段,最终启动仍严格校验全部输入。
148
150
  用户在等待期间输入的内容会保留,切换模式或环境会使旧请求失效。
149
151
  管理器通过内部
150
- `browser_provider_launch_form` 请求获取 `ProviderLaunchForm`,不识别 Provider ID 或业务字段:
152
+ `browser_providers` 的 `launch_form` operation 获取 `ProviderLaunchForm`,不识别 Provider ID 或业务字段:
151
153
 
152
154
  - `inputSchema` 描述当前模式的用户输入,`required` 决定必填标识与提交校验。
153
155
  - `variants` 的 `id/title/description` 描述连接方式,`variant` 指定当前方式。
@@ -185,3 +187,17 @@ npx @mearl/setup provider install <package>
185
187
  npx @mearl/setup provider update <provider-id>
186
188
  npx @mearl/setup provider uninstall <provider-id>
187
189
  ```
190
+
191
+ ## Socket 协议
192
+
193
+ 当前 Provider 协议版本为 **3**,请求 envelope 携带 `protocolVersion`。安装元数据、
194
+ 运行时 descriptor、运行中进程与调用方必须使用相同协议;不匹配时更新相关包并重启进程。
195
+
196
+ - `browser_providers`:`operation: "configure"` 携带 `options`,`operation: "launch_form"` 携带 `variant?` 和 `values`。
197
+ - `browser_instances`:`operation: "start" | "detach" | "sync_cookies"`;同步携带 `scope`,目标实例由 envelope 的 `browserId` 选择。
198
+ - `browser_launch`、`browser_close`、`get_browser_access_url` 保留各自职责。
199
+ - `browser_sessions` 由 Mearl 控制进程处理,不转交外部 Provider;会话释放与实例 `detach` 分开执行。
200
+
201
+ SDK 负责将 Socket 请求分发到 `configure/getLaunchForm/start/detach/syncCookies` 等方法。
202
+ `browser_release` 普通 action 不承担实例解绑;公开 CLI 的无会话释放由 Mearl 转换为 `detach`。
203
+ 打包 SDK 的 Provider 必须更新 SDK 并重新构建,修改安装元数据不能替换运行中的旧代码。
@@ -0,0 +1,4 @@
1
+ import { type BrowserCapabilityAction } from '@mearl/browser-core/browserActionProtocol';
2
+ export type ProviderAction = BrowserCapabilityAction;
3
+ export declare const PROVIDER_ACTIONS: readonly ProviderAction[];
4
+ export declare function isProviderAction(value: unknown): value is ProviderAction;
@@ -0,0 +1,5 @@
1
+ import { BROWSER_CAPABILITY_ACTIONS, isBrowserCapabilityAction } from '@mearl/browser-core/browserActionProtocol';
2
+ export const PROVIDER_ACTIONS = Object.keys(BROWSER_CAPABILITY_ACTIONS);
3
+ export function isProviderAction(value) {
4
+ return typeof value === 'string' && isBrowserCapabilityAction(value);
5
+ }
@@ -3,6 +3,7 @@ export interface ProviderControlHostRecord extends DaemonRecord {
3
3
  socketPath: string;
4
4
  token: string;
5
5
  ready: boolean;
6
+ protocolVersion: number;
6
7
  }
7
8
  export declare function providerControlHostFile(): string;
8
9
  export declare function providerControlSocketPath(pid: number): string;
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process';
2
2
  import { randomUUID } from 'node:crypto';
3
3
  import { tmpdir } from 'node:os';
4
4
  import { join } from 'node:path';
5
+ import { assertProviderProtocolVersion, MEARL_PROVIDER_PROTOCOL_VERSION } from './protocol.js';
5
6
  import { isAlive, keyedConfigFile, claimRecord, readRecord, removeInvalidRecord, removeRecordIfPid, writeRecordIfPid, } from '@mearl/daemon-core';
6
7
  export function providerControlHostFile() {
7
8
  return keyedConfigFile('control', 'providers');
@@ -13,9 +14,10 @@ export function providerControlSocketPath(pid) {
13
14
  }
14
15
  export function readProviderControlHost() {
15
16
  const record = readRecord(providerControlHostFile());
16
- return record?.ready && typeof record.socketPath === 'string' && isAlive(record.pid)
17
- ? record
18
- : null;
17
+ if (!record?.ready || typeof record.socketPath !== 'string' || !isAlive(record.pid))
18
+ return null;
19
+ assertProviderProtocolVersion(record.protocolVersion, 'Provider control host');
20
+ return record;
19
21
  }
20
22
  let startup;
21
23
  /** A single host owns Provider sessions across independent CLI and connector processes. */
@@ -36,7 +38,13 @@ export function ensureProviderControlHost(timeoutMs = 10_000) {
36
38
  else
37
39
  removeInvalidRecord(file);
38
40
  const token = randomUUID();
39
- if (claimRecord(file, { pid: process.pid, socketPath: '', token, ready: false })) {
41
+ if (claimRecord(file, {
42
+ pid: process.pid,
43
+ socketPath: '',
44
+ token,
45
+ ready: false,
46
+ protocolVersion: MEARL_PROVIDER_PROTOCOL_VERSION,
47
+ })) {
40
48
  try {
41
49
  const entry = process.env.MEARL_NATIVE_HOST_ENTRY;
42
50
  const child = spawn(entry ? process.execPath : 'mearl-native-host', [...(entry ? [entry] : []), '--provider-control', token], { detached: true, stdio: 'ignore', windowsHide: true });
@@ -52,6 +60,7 @@ export function ensureProviderControlHost(timeoutMs = 10_000) {
52
60
  socketPath: providerControlSocketPath(child.pid),
53
61
  token,
54
62
  ready: false,
63
+ protocolVersion: MEARL_PROVIDER_PROTOCOL_VERSION,
55
64
  });
56
65
  }
57
66
  catch (error) {
package/dist/host.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { listInstalledProviders, registerProviderPackage, stopProvider, readLiveProvider, readProviderStart, uninstallProvider, } from './registry.js';
1
+ export { listInstalledProviders, validateInstalledProviderManifest, registerProviderPackage, stopProvider, readLiveProvider, readProviderStart, uninstallProvider, } from './registry.js';
2
2
  export type { InstalledProviderManifest, ProviderPackageMetadata } from './types.js';
3
3
  export { ensureProviderControlHost, readProviderControlHost, providerControlHostFile, providerControlSocketPath, } from './control-host.js';
4
4
  export type { ProviderControlHostRecord } from './control-host.js';
package/dist/host.js CHANGED
@@ -1,2 +1,2 @@
1
- export { listInstalledProviders, registerProviderPackage, stopProvider, readLiveProvider, readProviderStart, uninstallProvider, } from './registry.js';
1
+ export { listInstalledProviders, validateInstalledProviderManifest, registerProviderPackage, stopProvider, readLiveProvider, readProviderStart, uninstallProvider, } from './registry.js';
2
2
  export { ensureProviderControlHost, readProviderControlHost, providerControlHostFile, providerControlSocketPath, } from './control-host.js';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './types.js';
2
- export { PROVIDER_ACTIONS, isProviderAction } from './generated-provider-actions.js';
2
+ export { assertProviderProtocolVersion } from './protocol.js';
3
+ export { PROVIDER_ACTIONS, isProviderAction } from './actions.js';
3
4
  export { providerDataDir } from './registry.js';
4
5
  export { createProviderRuntime, validateProviderBrowser, validateProviderInput, validateProviderLaunchForm, } from './provider-runtime.js';
5
6
  export { createProviderServer } from './server.js';
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './types.js';
2
- export { PROVIDER_ACTIONS, isProviderAction } from './generated-provider-actions.js';
2
+ export { assertProviderProtocolVersion } from './protocol.js';
3
+ export { PROVIDER_ACTIONS, isProviderAction } from './actions.js';
3
4
  export { providerDataDir } from './registry.js';
4
5
  export { createProviderRuntime, validateProviderBrowser, validateProviderInput, validateProviderLaunchForm, } from './provider-runtime.js';
5
6
  export { createProviderServer } from './server.js';
package/dist/launcher.js CHANGED
@@ -4,13 +4,18 @@ import { closeSync, existsSync, mkdirSync, openSync } from 'node:fs';
4
4
  import { join } from 'node:path';
5
5
  import { hashKey, keyedDir, rotateLogIfNeeded } from '@mearl/daemon-core';
6
6
  import { PROVIDER_START_TOKEN_ENV, claimProviderStart, listInstalledProviders, listLiveProviders, readLiveProvider, readProviderStart, releaseProviderStart, transferProviderStart, validateInstalledProviderManifest, } from './registry.js';
7
+ import { assertProviderProtocolVersion } from './protocol.js';
7
8
  export const PROVIDER_LOGS_SUBDIR = 'providers/logs';
8
9
  function providerLogFile(providerId) {
9
10
  const hash = hashKey(providerId);
10
11
  return join(keyedDir(PROVIDER_LOGS_SUBDIR), `${hash}.log`);
11
12
  }
12
- function liveProviderIds() {
13
- return new Set(listLiveProviders().map(record => record.providerId));
13
+ function hasCompatibleLiveProvider(providerId) {
14
+ const live = readLiveProvider(providerId);
15
+ if (!live)
16
+ return false;
17
+ assertProviderProtocolVersion(live.providerProtocolVersion, providerId);
18
+ return true;
14
19
  }
15
20
  function delay(ms) {
16
21
  return new Promise(resolve => setTimeout(resolve, ms));
@@ -52,38 +57,39 @@ export async function ensureInstalledProvidersRunning(providerIds) {
52
57
  const warnings = [];
53
58
  const selected = providerIds ? new Set(providerIds) : undefined;
54
59
  const installed = listInstalledProviders().filter(provider => !selected || selected.has(provider.providerId));
55
- const live = liveProviderIds();
56
60
  const starting = new Map();
57
61
  for (const manifest of installed) {
58
- if (live.has(manifest.providerId))
59
- continue;
60
62
  const invalid = validateInstalledProviderManifest(manifest);
61
63
  if (invalid) {
62
64
  warnings.push(`provider ${manifest.providerId || '(unknown)'}: ${invalid}`);
63
65
  continue;
64
66
  }
65
- const startToken = randomUUID();
66
- if (!claimProviderStart(manifest.providerId, startToken)) {
67
- if (readLiveProvider(manifest.providerId))
68
- continue;
69
- if (readProviderStart(manifest.providerId))
70
- starting.set(manifest.providerId, null);
71
- else
72
- warnings.push(`provider ${manifest.providerId}: failed to acquire startup ownership`);
73
- continue;
74
- }
75
- if (readLiveProvider(manifest.providerId)) {
76
- releaseProviderStart(manifest.providerId, startToken);
77
- continue;
78
- }
79
- const logFile = providerLogFile(manifest.providerId);
67
+ let startToken;
80
68
  try {
69
+ if (hasCompatibleLiveProvider(manifest.providerId))
70
+ continue;
71
+ startToken = randomUUID();
72
+ if (!claimProviderStart(manifest.providerId, startToken)) {
73
+ if (hasCompatibleLiveProvider(manifest.providerId))
74
+ continue;
75
+ if (readProviderStart(manifest.providerId))
76
+ starting.set(manifest.providerId, null);
77
+ else
78
+ warnings.push(`provider ${manifest.providerId}: failed to acquire startup ownership`);
79
+ continue;
80
+ }
81
+ if (hasCompatibleLiveProvider(manifest.providerId)) {
82
+ releaseProviderStart(manifest.providerId, startToken);
83
+ continue;
84
+ }
85
+ const logFile = providerLogFile(manifest.providerId);
81
86
  const childPid = await spawnProvider(manifest, logFile, startToken);
82
87
  transferProviderStart(manifest.providerId, startToken, childPid);
83
88
  starting.set(manifest.providerId, startToken);
84
89
  }
85
90
  catch (error) {
86
- releaseProviderStart(manifest.providerId, startToken);
91
+ if (startToken)
92
+ releaseProviderStart(manifest.providerId, startToken);
87
93
  warnings.push(`provider ${manifest.providerId}: ${error instanceof Error ? error.message : String(error)}`);
88
94
  }
89
95
  }
@@ -93,12 +99,20 @@ export async function ensureInstalledProvidersRunning(providerIds) {
93
99
  let remaining = [...starting.keys()];
94
100
  while (remaining.length > 0 && Date.now() < deadline) {
95
101
  await delay(100);
96
- const current = liveProviderIds();
102
+ const current = new Set(listLiveProviders().map(record => record.providerId));
97
103
  remaining = remaining.filter(providerId => !current.has(providerId));
98
104
  }
99
105
  for (const [providerId, token] of starting) {
100
106
  if (!remaining.includes(providerId) && token)
101
107
  releaseProviderStart(providerId, token);
108
+ if (!remaining.includes(providerId)) {
109
+ try {
110
+ hasCompatibleLiveProvider(providerId);
111
+ }
112
+ catch (error) {
113
+ warnings.push(`provider ${providerId}: ${error instanceof Error ? error.message : String(error)}`);
114
+ }
115
+ }
102
116
  }
103
117
  for (const providerId of remaining) {
104
118
  const logFile = providerLogFile(providerId);
@@ -0,0 +1,2 @@
1
+ export declare const MEARL_PROVIDER_PROTOCOL_VERSION = 3;
2
+ export declare function assertProviderProtocolVersion(actual: unknown, peer?: string): void;
@@ -0,0 +1,6 @@
1
+ export const MEARL_PROVIDER_PROTOCOL_VERSION = 3;
2
+ export function assertProviderProtocolVersion(actual, peer = 'Provider') {
3
+ if (actual !== MEARL_PROVIDER_PROTOCOL_VERSION) {
4
+ throw new Error(`PROVIDER_PROTOCOL_MISMATCH: ${peer} uses protocol ${String(actual ?? 'unknown')}; expected ${MEARL_PROVIDER_PROTOCOL_VERSION}. Update Mearl and the Provider package, then restart the services.`);
5
+ }
6
+ }
@@ -1,5 +1,5 @@
1
1
  import { MEARL_PROVIDER_PROTOCOL_VERSION } from './types.js';
2
- import { isProviderAction } from './generated-provider-actions.js';
2
+ import { isProviderAction } from './actions.js';
3
3
  const LIFECYCLE_OPERATIONS = new Set([
4
4
  'start',
5
5
  'close',
package/dist/registry.js CHANGED
@@ -4,6 +4,7 @@ import { isAbsolute, join, relative, resolve, sep } from 'node:path';
4
4
  import { claimRecord, ensureDir, hashKey, isAlive, keyedConfigFile, keyedDir, listRecordFiles, readLiveRecords, readRecord, removeInvalidRecord, removeRecordIfPid, writeRecord, writeRecordIfPid, } from '@mearl/daemon-core';
5
5
  import { MEARL_PROVIDER_PROTOCOL_VERSION, } from './types.js';
6
6
  import { validateProviderLaunchForm, isProviderInputSchema } from './provider-runtime.js';
7
+ import { assertProviderProtocolVersion } from './protocol.js';
7
8
  export const INSTALLED_PROVIDERS_SUBDIR = 'providers/installed';
8
9
  export const LIVE_PROVIDERS_SUBDIR = 'providers/live';
9
10
  export const STARTING_PROVIDERS_SUBDIR = 'providers/starting';
@@ -93,8 +94,11 @@ export function validateInstalledProviderManifest(manifest) {
93
94
  !manifest.version.trim()) {
94
95
  return 'manifest is incomplete';
95
96
  }
96
- if (manifest.protocolVersion !== MEARL_PROVIDER_PROTOCOL_VERSION) {
97
- return `protocol ${manifest.protocolVersion} is unsupported`;
97
+ try {
98
+ assertProviderProtocolVersion(manifest.protocolVersion, `Installed Provider ${manifest.providerId}`);
99
+ }
100
+ catch (error) {
101
+ return error.message;
98
102
  }
99
103
  if (RESERVED_PROVIDER_IDS.has(manifest.providerId)) {
100
104
  return `providerId ${manifest.providerId} is reserved for a built-in Provider`;
package/dist/server.js CHANGED
@@ -3,10 +3,11 @@ import { randomUUID } from 'node:crypto';
3
3
  import { chmodSync, rmSync } from 'node:fs';
4
4
  import { dirname } from 'node:path';
5
5
  import { ensureDir } from '@mearl/daemon-core';
6
- import { isProviderAction } from './generated-provider-actions.js';
6
+ import { isProviderAction } from './actions.js';
7
7
  import { createProviderRuntime } from './provider-runtime.js';
8
8
  import { PROVIDER_START_TOKEN_ENV, claimProviderStart, providerBrowserKey, providerSocketPath, publishLiveProvider, publishProviderBrowsers, readLiveProvider, releaseProviderStart, removeStaleProviderSocket, touchProviderBrowser, unpublishLiveProvider, unpublishProviderBrowsers, } from './registry.js';
9
9
  import { MEARL_PROVIDER_PROTOCOL_VERSION } from './types.js';
10
+ import { assertProviderProtocolVersion } from './protocol.js';
10
11
  const MAX_REQUEST_BYTES = 16 * 1024 * 1024;
11
12
  const activeProviderIds = new Set();
12
13
  function errorMessage(error) {
@@ -29,6 +30,7 @@ function isProviderActionRequest(value) {
29
30
  request.id.length > 0 &&
30
31
  typeof request.action === 'string' &&
31
32
  request.action.length > 0 &&
33
+ typeof request.protocolVersion === 'number' &&
32
34
  (request.data === undefined ||
33
35
  (request.data !== null &&
34
36
  typeof request.data === 'object' &&
@@ -84,32 +86,39 @@ export function createProviderServer(options) {
84
86
  if (request.controlSessionId)
85
87
  throw new Error('CONTROL_SESSION_UNSUPPORTED: this Provider does not implement control sessions');
86
88
  const context = providerContext(request);
87
- if (request.action === 'browser_provider_launch_form') {
89
+ if (request.action === 'browser_providers') {
88
90
  if (request.browserId)
89
- throw new Error('Provider launch form does not accept browserId');
90
- return runtime.getLaunchForm({
91
- variant: request.data?.variant,
92
- values: request.data?.values,
93
- }, context);
91
+ throw new Error('Provider management does not accept browserId');
92
+ switch (request.data?.operation) {
93
+ case 'configure':
94
+ return runtime.configure(request.data.options, context);
95
+ case 'launch_form':
96
+ return runtime.getLaunchForm({
97
+ variant: request.data.variant,
98
+ values: request.data.values,
99
+ }, context);
100
+ default:
101
+ throw new Error('Invalid browser provider operation');
102
+ }
94
103
  }
95
104
  if (request.action === 'browser_launch') {
96
105
  if (request.browserId)
97
106
  throw new Error('browser_launch does not accept browserId');
98
107
  return runtime.launch(request.data ?? {}, context);
99
108
  }
100
- if (request.action === 'browser_provider_configure') {
101
- if (request.browserId)
102
- throw new Error('Provider configuration does not accept browserId');
103
- return runtime.configure(request.data ?? {}, context);
104
- }
105
- if (request.action === 'browser_manager_start') {
106
- return runtime.start({ browserId: await providerBrowserId(request.browserId) }, context);
107
- }
108
- if (request.action === 'browser_manager_sync_cookies') {
109
- return runtime.syncCookies({
110
- browserId: await providerBrowserId(request.browserId),
111
- scope: request.data?.scope,
112
- }, context);
109
+ if (request.action === 'browser_instances') {
110
+ if (!['start', 'detach', 'sync_cookies'].includes(String(request.data?.operation))) {
111
+ throw new Error('Invalid browser instance operation');
112
+ }
113
+ const browserId = await providerBrowserId(request.browserId);
114
+ switch (request.data.operation) {
115
+ case 'start':
116
+ return runtime.start({ browserId }, context);
117
+ case 'detach':
118
+ return runtime.detach({ browserId }, context);
119
+ case 'sync_cookies':
120
+ return runtime.syncCookies({ browserId, scope: request.data.scope }, context);
121
+ }
113
122
  }
114
123
  if (request.action !== 'get_versions' &&
115
124
  request.action !== 'browser_close' &&
@@ -141,12 +150,6 @@ export function createProviderServer(options) {
141
150
  capabilities: found.control.kind === 'provider' ? found.control.capabilities : undefined,
142
151
  };
143
152
  }
144
- if (request.action === 'browser_release') {
145
- const found = (await runtime.listBrowsers()).find(browser => browser.browserId === browserId);
146
- if (found?.operations.includes('detach')) {
147
- return runtime.detach({ browserId }, context);
148
- }
149
- }
150
153
  touchProviderBrowser(providerBrowserKey(descriptor.providerId, browserId));
151
154
  return runtime.invokeAction({
152
155
  browserId,
@@ -179,12 +182,19 @@ export function createProviderServer(options) {
179
182
  socket.end(`${JSON.stringify({ id: '', success: false, error: 'Invalid JSON request' })}\n`);
180
183
  return;
181
184
  }
185
+ const id = parsed && typeof parsed === 'object' && typeof parsed.id === 'string'
186
+ ? parsed.id
187
+ : '';
188
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
189
+ try {
190
+ assertProviderProtocolVersion(parsed.protocolVersion);
191
+ }
192
+ catch (error) {
193
+ socket.end(`${JSON.stringify({ id, success: false, error: errorMessage(error) })}\n`);
194
+ return;
195
+ }
196
+ }
182
197
  if (!isProviderActionRequest(parsed)) {
183
- const id = parsed &&
184
- typeof parsed === 'object' &&
185
- typeof parsed.id === 'string'
186
- ? parsed.id
187
- : '';
188
198
  socket.end(`${JSON.stringify({ id, success: false, error: 'Invalid request envelope' })}\n`);
189
199
  return;
190
200
  }
package/dist/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { ProviderAction } from './generated-provider-actions.js';
2
- export declare const MEARL_PROVIDER_PROTOCOL_VERSION = 2;
3
- export type { ProviderAction } from './generated-provider-actions.js';
1
+ import type { ProviderAction } from './actions.js';
2
+ export { MEARL_PROVIDER_PROTOCOL_VERSION } from './protocol.js';
3
+ export type { ProviderAction } from './actions.js';
4
4
  export type JsonPrimitive = string | number | boolean | null;
5
5
  export type JsonValue = JsonPrimitive | JsonValue[] | JsonObject;
6
6
  export interface JsonObject {
@@ -197,6 +197,7 @@ export interface ProviderActionRequest {
197
197
  /** Provider-local browser id selected by the Mearl client. */
198
198
  browserId?: string;
199
199
  version?: string;
200
+ protocolVersion: number;
200
201
  controlSource?: string;
201
202
  host?: ProviderHostContextData;
202
203
  }
package/dist/types.js CHANGED
@@ -1 +1 @@
1
- export const MEARL_PROVIDER_PROTOCOL_VERSION = 2;
1
+ export { MEARL_PROVIDER_PROTOCOL_VERSION } from './protocol.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mearl/provider",
3
- "version": "2.21.0",
3
+ "version": "3.0.0-beta.0",
4
4
  "description": "Unified contracts and runtime utilities for built-in and external Mearl browser providers",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -27,7 +27,7 @@
27
27
  "mearl",
28
28
  "browser-provider"
29
29
  ],
30
- "license": "ISC",
30
+ "license": "Apache-2.0",
31
31
  "engines": {
32
32
  "node": ">=22.12.0"
33
33
  },
@@ -35,15 +35,16 @@
35
35
  "registry": "https://registry.npmjs.org"
36
36
  },
37
37
  "dependencies": {
38
- "@mearl/daemon-core": "2.21.0"
38
+ "@mearl/daemon-core": "3.0.0-beta.0",
39
+ "@mearl/browser-core": "3.0.0-beta.0"
39
40
  },
40
41
  "devDependencies": {
41
42
  "@types/node": "^24.9.1",
42
43
  "typescript": "^5.8.3"
43
44
  },
44
45
  "scripts": {
45
- "build": "node ../../scripts/generate-provider-actions.mjs --check && rm -rf dist/ && tsc",
46
- "typecheck": "node ../../scripts/generate-provider-actions.mjs --check && tsc --noEmit",
46
+ "build": "rm -rf dist/ && tsc",
47
+ "typecheck": "tsc --noEmit",
47
48
  "test": "vitest run"
48
49
  }
49
50
  }
@@ -1,3 +0,0 @@
1
- export declare const PROVIDER_ACTIONS: readonly ["tab_checkpoint", "capture_checkpoint", "get_requests", "get_logs", "get_events", "set_mock", "get_mocks", "set_rule", "get_rules", "send_request", "send_mtop_request", "browser_release", "page_screenshot", "tab_open", "tab_close", "tab_list", "tab_group", "page_click", "page_drag", "page_type", "page_scroll", "page_hover", "page_eval", "page_runtime", "page_inspect", "page_snapshot", "page_press", "page_wait", "page_navigate", "page_upload", "page_frames", "set_device_emulation", "set_app_profile", "set_timezone", "get_cookie", "set_cookie", "request_domain_permission", "run_actions", "page_download"];
2
- export type ProviderAction = (typeof PROVIDER_ACTIONS)[number];
3
- export declare function isProviderAction(value: unknown): value is ProviderAction;
@@ -1,47 +0,0 @@
1
- // Generated by scripts/generate-provider-actions.mjs.
2
- // Do not edit directly; update browser-core/src/browserActionProtocol.ts.
3
- export const PROVIDER_ACTIONS = [
4
- 'tab_checkpoint',
5
- 'capture_checkpoint',
6
- 'get_requests',
7
- 'get_logs',
8
- 'get_events',
9
- 'set_mock',
10
- 'get_mocks',
11
- 'set_rule',
12
- 'get_rules',
13
- 'send_request',
14
- 'send_mtop_request',
15
- 'browser_release',
16
- 'page_screenshot',
17
- 'tab_open',
18
- 'tab_close',
19
- 'tab_list',
20
- 'tab_group',
21
- 'page_click',
22
- 'page_drag',
23
- 'page_type',
24
- 'page_scroll',
25
- 'page_hover',
26
- 'page_eval',
27
- 'page_runtime',
28
- 'page_inspect',
29
- 'page_snapshot',
30
- 'page_press',
31
- 'page_wait',
32
- 'page_navigate',
33
- 'page_upload',
34
- 'page_frames',
35
- 'set_device_emulation',
36
- 'set_app_profile',
37
- 'set_timezone',
38
- 'get_cookie',
39
- 'set_cookie',
40
- 'request_domain_permission',
41
- 'run_actions',
42
- 'page_download',
43
- ];
44
- const providerActionSet = new Set(PROVIDER_ACTIONS);
45
- export function isProviderAction(value) {
46
- return typeof value === 'string' && providerActionSet.has(value);
47
- }