@mearl/client 2.0.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.
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Payload 文件引用解析(@ 前缀,仅顶层字段)
3
+ *
4
+ * 约定:payload 的**顶层字段**若是以 `@` 开头的字符串,`@` 之后视为文件路径,
5
+ * 发送前会被替换为该文件内容:
6
+ * - 默认按 JSON 解析;解析失败则按原始文本注入(适配脚本 / HTML / 纯文本 body)。
7
+ * - **找不到 / 读不到该文件时,原样保留这个字符串**(不报错),因此 `@xxx` 这类
8
+ * 非文件路径的普通值不会被误伤。
9
+ *
10
+ * 用途:把大体积字段(mock 响应体、send_request 的 body、page_eval 的 script 等)
11
+ * 放到本地文件,调用方只传 `"@/abs/path"`,避免把整段内容塞进上下文。
12
+ *
13
+ * 解析在 client `invoke` 中统一执行,对所有 action 生效;路径按运行进程 cwd 解析,
14
+ * 建议传绝对路径。仅作用于顶层字段,不递归嵌套。
15
+ */
16
+ /**
17
+ * 解析 payload 顶层字段中的 `@<path>` 文件引用。返回新对象,不修改入参。
18
+ * 非对象入参原样返回。
19
+ */
20
+ export declare function resolveFileRefs(data: Record<string, any>): Record<string, any>;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Payload 文件引用解析(@ 前缀,仅顶层字段)
3
+ *
4
+ * 约定:payload 的**顶层字段**若是以 `@` 开头的字符串,`@` 之后视为文件路径,
5
+ * 发送前会被替换为该文件内容:
6
+ * - 默认按 JSON 解析;解析失败则按原始文本注入(适配脚本 / HTML / 纯文本 body)。
7
+ * - **找不到 / 读不到该文件时,原样保留这个字符串**(不报错),因此 `@xxx` 这类
8
+ * 非文件路径的普通值不会被误伤。
9
+ *
10
+ * 用途:把大体积字段(mock 响应体、send_request 的 body、page_eval 的 script 等)
11
+ * 放到本地文件,调用方只传 `"@/abs/path"`,避免把整段内容塞进上下文。
12
+ *
13
+ * 解析在 client `invoke` 中统一执行,对所有 action 生效;路径按运行进程 cwd 解析,
14
+ * 建议传绝对路径。仅作用于顶层字段,不递归嵌套。
15
+ */
16
+ import fs from 'node:fs';
17
+ const FILE_REF_PREFIX = '@';
18
+ function resolveValue(value) {
19
+ if (typeof value !== 'string' || !value.startsWith(FILE_REF_PREFIX))
20
+ return value;
21
+ const filePath = value.slice(FILE_REF_PREFIX.length);
22
+ if (!filePath)
23
+ return value;
24
+ let content;
25
+ try {
26
+ content = fs.readFileSync(filePath, 'utf-8');
27
+ }
28
+ catch {
29
+ // 找不到 / 读不到文件:原样保留该字符串
30
+ return value;
31
+ }
32
+ try {
33
+ return JSON.parse(content);
34
+ }
35
+ catch {
36
+ // 非 JSON 文件按原始文本注入
37
+ return content;
38
+ }
39
+ }
40
+ /**
41
+ * 解析 payload 顶层字段中的 `@<path>` 文件引用。返回新对象,不修改入参。
42
+ * 非对象入参原样返回。
43
+ */
44
+ export function resolveFileRefs(data) {
45
+ if (data === null || typeof data !== 'object' || Array.isArray(data))
46
+ return data;
47
+ const out = {};
48
+ for (const [key, value] of Object.entries(data)) {
49
+ out[key] = resolveValue(value);
50
+ }
51
+ return out;
52
+ }
@@ -0,0 +1,402 @@
1
+ /**
2
+ * @mearl/client — Mearl Socket Client SDK
3
+ *
4
+ * 通过 Unix Domain Socket 与 Chrome Extension 的 native host 通信,
5
+ * 提供类型安全的具名方法和通用的 invoke 底层方法。
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import * as client from '@mearl/client';
10
+ *
11
+ * // 具名方法(类型安全)
12
+ * const result = await client.sendRequest({ url: 'https://...', method: 'GET', withCookies: true });
13
+ *
14
+ * // 底层通用方法(灵活扩展)
15
+ * const data = await client.invoke('send_request', { url: '...' });
16
+ * ```
17
+ */
18
+ export { invoke } from './socket.js';
19
+ export type { InvokeOptions } from './socket.js';
20
+ export interface GetRequestsParams {
21
+ tabId?: number;
22
+ count?: number;
23
+ filter?: string;
24
+ since?: number;
25
+ includeBody?: boolean;
26
+ includeHeaders?: boolean;
27
+ maxBodySize?: number;
28
+ fields?: string[];
29
+ keysOnly?: boolean;
30
+ source?: 'mtop' | 'requests';
31
+ }
32
+ export declare function getRequests(params?: GetRequestsParams): Promise<any>;
33
+ export interface GetLogsParams {
34
+ level?: 'log' | 'warn' | 'error' | 'info' | 'all';
35
+ since?: number;
36
+ limit?: number;
37
+ filter?: string;
38
+ }
39
+ export declare function getLogs(params?: GetLogsParams): Promise<any>;
40
+ export interface GetEventsParams {
41
+ source?: 'rum' | 'aplus' | 'all';
42
+ event_type?: string;
43
+ filter?: string;
44
+ since?: number;
45
+ limit?: number;
46
+ }
47
+ export declare function getEvents(params?: GetEventsParams): Promise<any>;
48
+ export interface SetMockParams {
49
+ apiName: string;
50
+ mockData?: any;
51
+ fields?: Array<{
52
+ path: string;
53
+ value: any;
54
+ }>;
55
+ enabled?: boolean;
56
+ /** 完整响应时长(毫秒):mock 的总耗时,绕过真实服务器精确控制 */
57
+ duration?: number;
58
+ /** 请求 query/body 字段子集匹配;$index 从 0 开始指定调用顺序 */
59
+ conditions?: Record<string, any>;
60
+ }
61
+ export declare function setMock(params: SetMockParams): Promise<any>;
62
+ export interface GetMocksParams {
63
+ apiName?: string;
64
+ }
65
+ export declare function getMocks(params?: GetMocksParams): Promise<any>;
66
+ export interface GetApiSchemaParams {
67
+ api: string;
68
+ version?: string;
69
+ fields?: ('schema' | 'hsf')[];
70
+ }
71
+ export declare function getApiSchema(params: GetApiSchemaParams): Promise<any>;
72
+ export interface SendRequestParams {
73
+ url: string;
74
+ method?: string;
75
+ headers?: Record<string, string>;
76
+ params?: Record<string, string>;
77
+ body?: any;
78
+ withCookies?: boolean;
79
+ cookieDomain?: string;
80
+ responseType?: 'json' | 'text' | 'auto';
81
+ timeout?: number;
82
+ }
83
+ export declare function sendRequest(params: SendRequestParams): Promise<any>;
84
+ export interface SendMtopRequestParams {
85
+ api: string;
86
+ data?: any;
87
+ version?: string;
88
+ method?: string;
89
+ appKey?: string;
90
+ env?: string;
91
+ timeout?: number;
92
+ }
93
+ export declare function sendMtopRequest(params: SendMtopRequestParams): Promise<any>;
94
+ export interface TdbankAccountParams {
95
+ operation?: 'current' | 'list' | 'switch' | 'borrow';
96
+ pageIndex?: number;
97
+ refresh?: boolean;
98
+ query?: string;
99
+ accountId?: string | number;
100
+ havanaId?: string | number;
101
+ site?: string | number;
102
+ tabId?: number;
103
+ }
104
+ export declare function tdbankAccount(params?: TdbankAccountParams): Promise<any>;
105
+ export type BrowserStatus = 'connected' | 'running_disconnected' | 'stopped';
106
+ export interface BrowserInfoBase {
107
+ browserId: string;
108
+ name: string;
109
+ status: BrowserStatus;
110
+ extensionVersion?: string;
111
+ nativeHostVersion?: string;
112
+ transport?: 'extension' | 'cdp';
113
+ }
114
+ export interface RegularBrowserInfo extends BrowserInfoBase {
115
+ type: 'regular';
116
+ status: 'connected';
117
+ }
118
+ export interface ManagedBrowserAccount {
119
+ accountId?: string;
120
+ loginId?: string;
121
+ nickname: string;
122
+ }
123
+ export interface ManagedBrowserInfo extends BrowserInfoBase {
124
+ type: 'managed';
125
+ headless: boolean;
126
+ persistent: boolean;
127
+ cdpPort: number;
128
+ createdAt: string;
129
+ account?: ManagedBrowserAccount;
130
+ copiedCookies?: {
131
+ domains: string[];
132
+ count: number;
133
+ };
134
+ }
135
+ export type BrowserInfo = RegularBrowserInfo | ManagedBrowserInfo;
136
+ export interface BrowserListResult {
137
+ count: number;
138
+ connectedCount: number;
139
+ defaultBrowserId: string | null;
140
+ browsers: BrowserInfo[];
141
+ }
142
+ export declare function browserList(): Promise<BrowserListResult>;
143
+ export interface SelectBrowserParams {
144
+ browser?: string;
145
+ }
146
+ export interface SelectBrowserResult {
147
+ selected: {
148
+ browserId: string;
149
+ name: string;
150
+ } | null;
151
+ note?: string;
152
+ }
153
+ export declare function selectBrowser(params?: SelectBrowserParams): Promise<SelectBrowserResult>;
154
+ export interface BrowserLaunchParams {
155
+ name: string;
156
+ headless?: boolean;
157
+ userAgentMode?: 'default' | 'desktop';
158
+ persistent?: boolean;
159
+ executablePath?: string;
160
+ url?: string;
161
+ accountId?: string | number;
162
+ havanaId?: string | number;
163
+ site?: string | number;
164
+ query?: string;
165
+ tabId?: number;
166
+ copyCookieDomains?: string[];
167
+ }
168
+ export declare function browserLaunch(params: BrowserLaunchParams): Promise<any>;
169
+ export interface BrowserCloseParams {
170
+ browser: string;
171
+ deleteProfile?: boolean;
172
+ }
173
+ export declare function browserClose(params: BrowserCloseParams): Promise<any>;
174
+ export interface SetRuleParams {
175
+ actionType: 'redirect' | 'block' | 'allow' | 'upgradeScheme' | 'modifyHeaders';
176
+ filter: string;
177
+ redirectUrl?: string;
178
+ requestHeaders?: Array<{
179
+ header: string;
180
+ operation: 'set' | 'append' | 'remove';
181
+ value?: string;
182
+ }>;
183
+ responseHeaders?: Array<{
184
+ header: string;
185
+ operation: 'set' | 'append' | 'remove';
186
+ value?: string;
187
+ }>;
188
+ initiatorDomains?: string;
189
+ resourceTypes?: string[];
190
+ priority?: number;
191
+ description?: string;
192
+ }
193
+ export declare function setRule(params: SetRuleParams): Promise<any>;
194
+ /** 返回当前存储的全部请求规则(含 Options 面板配置的),字段结构与 set_rule 入参对齐。 */
195
+ export declare function getRules(): Promise<{
196
+ enabled: boolean;
197
+ rules: Array<Record<string, any>>;
198
+ }>;
199
+ export interface PageScreenshotParams {
200
+ tabId: number;
201
+ selector?: string;
202
+ format?: 'png' | 'jpeg';
203
+ quality?: number;
204
+ }
205
+ export declare function pageScreenshot(params: PageScreenshotParams): Promise<any>;
206
+ export interface PageSelectedElementParams {
207
+ tabId: number;
208
+ includeOuterHTML?: boolean;
209
+ includeScreenshot?: boolean;
210
+ }
211
+ export declare function pageSelectedElement(params: PageSelectedElementParams): Promise<any>;
212
+ export interface TabOpenParams {
213
+ url: string;
214
+ active?: boolean;
215
+ /** 打开前先关闭 Agent 受控的已有标签页。默认 false */
216
+ closeExisting?: boolean;
217
+ /** 是否复用匹配标签页。默认 never,保持始终新开的兼容行为。 */
218
+ reuse?: 'never' | 'prefer' | 'require';
219
+ /** 复用标签页时的 URL 匹配规则。 */
220
+ match?: {
221
+ /** 完整 URL glob,`*` 匹配任意字符;省略时匹配 url。 */
222
+ urlPattern?: string;
223
+ ignoreSearch?: boolean;
224
+ ignoreHash?: boolean;
225
+ onMultiple?: 'error' | 'first';
226
+ };
227
+ /** active 新标签页关闭后,恢复打开前的活动标签页。默认 false。 */
228
+ restoreFocusOnClose?: boolean;
229
+ /**
230
+ * 开 tab 即进入移动端模拟态(视口/UA/触摸),在导航前生效,页面首屏即移动态、无需 reload。
231
+ * 等价于随后立即调用 set_device_emulation,但省一次整页加载并避开桌面态首屏的 UA 判端跳转。
232
+ */
233
+ emulation?: EmulationOptions;
234
+ /** 把标签页加入指定标题的分组(同窗口同名分组存在则加入,否则新建)。仅扩展模式支持。 */
235
+ group?: string;
236
+ }
237
+ export declare function tabOpen(params: TabOpenParams): Promise<any>;
238
+ export interface TabCloseParams {
239
+ tabId: number;
240
+ }
241
+ export declare function tabClose(params: TabCloseParams): Promise<any>;
242
+ export declare function tabList(): Promise<any>;
243
+ /**
244
+ * 页面交互动作(click/type/hover/scroll/press/upload)默认内置观察:
245
+ * 同一次调用内执行动作并等待异步稳定,返回 `{ action, observation }`。
246
+ * 传 `observe: false` 关闭观察,仅执行裸动作并直接返回其结果。
247
+ */
248
+ export interface PageObserveOptions {
249
+ quietMs?: number;
250
+ firstChangeTimeoutMs?: number;
251
+ timeoutMs?: number;
252
+ navigationGraceMs?: number;
253
+ navigationTimeoutMs?: number;
254
+ networkIdleMs?: number;
255
+ contentReadyAfterMs?: number;
256
+ }
257
+ export interface PageClickParams {
258
+ tabId: number;
259
+ /** 原生 CSS 选择器或 @eN snapshot ref。selector/text/point 三选一。 */
260
+ selector?: string;
261
+ /** 按可见文本(AX name)定位;可配合 role/exact 消歧。 */
262
+ text?: string;
263
+ /** 按视口坐标点击(CSS 像素)。 */
264
+ point?: {
265
+ x: number;
266
+ y: number;
267
+ };
268
+ /** 配合 text,按 AX role 过滤。 */
269
+ role?: string;
270
+ /** 配合 text,默认 true(精确匹配),false 时子串匹配。 */
271
+ exact?: boolean;
272
+ /**
273
+ * 点击方式。默认 'js'(对 selector / @ref 调用 el.click())。
274
+ * 'cdp' 走真实 mouse/touch 事件;text 与 point 始终用 CDP。
275
+ */
276
+ clickType?: 'js' | 'cdp';
277
+ /** 观察选项;传 false 关闭内置观察。 */
278
+ observe?: PageObserveOptions | false;
279
+ }
280
+ export declare function pageClick(params: PageClickParams): Promise<any>;
281
+ export interface PageTypeParams {
282
+ tabId: number;
283
+ selector: string;
284
+ text: string;
285
+ clearFirst?: boolean;
286
+ /** 观察选项;传 false 关闭内置观察。 */
287
+ observe?: PageObserveOptions | false;
288
+ }
289
+ export declare function pageType(params: PageTypeParams): Promise<any>;
290
+ export interface PageScrollParams {
291
+ tabId: number;
292
+ direction: string;
293
+ distance?: number;
294
+ /** 观察选项;传 false 关闭内置观察。 */
295
+ observe?: PageObserveOptions | false;
296
+ }
297
+ export declare function pageScroll(params: PageScrollParams): Promise<any>;
298
+ export interface PageHoverParams {
299
+ tabId: number;
300
+ selector: string;
301
+ /** 观察选项;传 false 关闭内置观察。 */
302
+ observe?: PageObserveOptions | false;
303
+ }
304
+ export declare function pageHover(params: PageHoverParams): Promise<any>;
305
+ export interface PageEvalParams {
306
+ tabId: number;
307
+ expression: string;
308
+ frameId?: string;
309
+ awaitPromise?: boolean;
310
+ }
311
+ export declare function pageEval(params: PageEvalParams): Promise<any>;
312
+ export interface PageSnapshotParams {
313
+ tabId: number;
314
+ depth?: number;
315
+ maxChars?: number;
316
+ maxNodes?: number;
317
+ rootSelector?: string;
318
+ mode?: 'full' | 'interactive' | 'viewport';
319
+ }
320
+ export declare function pageSnapshot(params: PageSnapshotParams): Promise<any>;
321
+ export interface PagePressParams {
322
+ tabId: number;
323
+ key: string;
324
+ modifiers?: string[];
325
+ /** 观察选项;传 false 关闭内置观察。 */
326
+ observe?: PageObserveOptions | false;
327
+ }
328
+ export declare function pagePress(params: PagePressParams): Promise<any>;
329
+ export interface PageWaitParams {
330
+ tabId: number;
331
+ time?: number;
332
+ selector?: string;
333
+ /** 在页面主执行上下文中轮询,表达式返回 truthy 时结束。 */
334
+ condition?: string;
335
+ timeout?: number;
336
+ interval?: number;
337
+ }
338
+ export declare function pageWait(params: PageWaitParams): Promise<any>;
339
+ export interface PageNavigateParams {
340
+ tabId: number;
341
+ /** 要导航到的 URL;refresh 为 true 时可省略。 */
342
+ url?: string;
343
+ /** 为 true 时直接重新加载当前页面(忽略 url),用于刷新页面。 */
344
+ refresh?: boolean;
345
+ }
346
+ export declare function pageNavigate(params: PageNavigateParams): Promise<any>;
347
+ export interface PageUploadParams {
348
+ tabId: number;
349
+ selector: string;
350
+ filePaths: string[];
351
+ /** 观察选项;传 false 关闭内置观察。 */
352
+ observe?: PageObserveOptions | false;
353
+ }
354
+ export declare function pageUpload(params: PageUploadParams): Promise<any>;
355
+ export interface PageFramesParams {
356
+ tabId: number;
357
+ }
358
+ export declare function pageFrames(params: PageFramesParams): Promise<any>;
359
+ export type DevicePresetName = 'iphone-15-pro' | 'iphone-se' | 'pixel-8' | 'ipad-mini' | 'galaxy-s23';
360
+ /**
361
+ * 移动端模拟入参(不含 enabled/tabId/reload)。tab_open 的 emulation 字段与
362
+ * set_device_emulation 复用同一套字段,规则一致。
363
+ */
364
+ export interface EmulationOptions {
365
+ preset?: DevicePresetName;
366
+ width?: number;
367
+ height?: number;
368
+ deviceScaleFactor?: number;
369
+ mobile?: boolean;
370
+ userAgent?: string;
371
+ orientation?: 'portrait' | 'landscape';
372
+ touch?: boolean;
373
+ }
374
+ export interface SetDeviceEmulationParams extends EmulationOptions {
375
+ tabId: number;
376
+ enabled: boolean;
377
+ reload?: boolean;
378
+ }
379
+ export declare function setDeviceEmulation(params: SetDeviceEmulationParams): Promise<any>;
380
+ export interface SetTimezoneParams {
381
+ tabId: number;
382
+ /** IANA timezone identifier, or an empty string to restore the browser default. */
383
+ timezone: string;
384
+ }
385
+ export interface SetTimezoneResult {
386
+ enabled: boolean;
387
+ timezone: string | null;
388
+ }
389
+ export declare function setTimezone(params: SetTimezoneParams): Promise<SetTimezoneResult>;
390
+ export interface GetUserInfoParams {
391
+ detail?: boolean;
392
+ }
393
+ export declare function getUserInfo(params?: GetUserInfoParams): Promise<any>;
394
+ export interface ActionStep {
395
+ action: string;
396
+ data?: Record<string, any>;
397
+ }
398
+ export interface RunActionsParams {
399
+ actions: ActionStep[];
400
+ tabId: number;
401
+ }
402
+ export declare function runActions(params: RunActionsParams): Promise<any>;
package/dist/index.js ADDED
@@ -0,0 +1,125 @@
1
+ /**
2
+ * @mearl/client — Mearl Socket Client SDK
3
+ *
4
+ * 通过 Unix Domain Socket 与 Chrome Extension 的 native host 通信,
5
+ * 提供类型安全的具名方法和通用的 invoke 底层方法。
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import * as client from '@mearl/client';
10
+ *
11
+ * // 具名方法(类型安全)
12
+ * const result = await client.sendRequest({ url: 'https://...', method: 'GET', withCookies: true });
13
+ *
14
+ * // 底层通用方法(灵活扩展)
15
+ * const data = await client.invoke('send_request', { url: '...' });
16
+ * ```
17
+ */
18
+ export { invoke } from './socket.js';
19
+ import { invoke } from './socket.js';
20
+ export function getRequests(params = {}) {
21
+ return invoke('get_requests', params);
22
+ }
23
+ export function getLogs(params = {}) {
24
+ return invoke('get_logs', params);
25
+ }
26
+ export function getEvents(params = {}) {
27
+ return invoke('get_events', params);
28
+ }
29
+ export function setMock(params) {
30
+ return invoke('set_mock', params);
31
+ }
32
+ export function getMocks(params = {}) {
33
+ return invoke('get_mocks', params);
34
+ }
35
+ export function getApiSchema(params) {
36
+ return invoke('get_api_schema', params);
37
+ }
38
+ export function sendRequest(params) {
39
+ return invoke('send_request', params);
40
+ }
41
+ export function sendMtopRequest(params) {
42
+ return invoke('send_mtop_request', params);
43
+ }
44
+ export function tdbankAccount(params = {}) {
45
+ return invoke('tdbank_account', params);
46
+ }
47
+ export function browserList() {
48
+ return invoke('browser_list', {});
49
+ }
50
+ export function selectBrowser(params = {}) {
51
+ return invoke('browser_select_browser', params);
52
+ }
53
+ export function browserLaunch(params) {
54
+ return invoke('browser_launch', params);
55
+ }
56
+ export function browserClose(params) {
57
+ return invoke('browser_close', params);
58
+ }
59
+ export function setRule(params) {
60
+ return invoke('set_rule', params);
61
+ }
62
+ /** 返回当前存储的全部请求规则(含 Options 面板配置的),字段结构与 set_rule 入参对齐。 */
63
+ export function getRules() {
64
+ return invoke('get_rules', {});
65
+ }
66
+ export function pageScreenshot(params) {
67
+ return invoke('page_screenshot', params);
68
+ }
69
+ export function pageSelectedElement(params) {
70
+ return invoke('page_selected_element', params);
71
+ }
72
+ export function tabOpen(params) {
73
+ return invoke('tab_open', params);
74
+ }
75
+ export function tabClose(params) {
76
+ return invoke('tab_close', params);
77
+ }
78
+ export function tabList() {
79
+ return invoke('tab_list', {});
80
+ }
81
+ export function pageClick(params) {
82
+ return invoke('page_click', params);
83
+ }
84
+ export function pageType(params) {
85
+ return invoke('page_type', params);
86
+ }
87
+ export function pageScroll(params) {
88
+ return invoke('page_scroll', params);
89
+ }
90
+ export function pageHover(params) {
91
+ return invoke('page_hover', params);
92
+ }
93
+ export function pageEval(params) {
94
+ return invoke('page_eval', params);
95
+ }
96
+ export function pageSnapshot(params) {
97
+ return invoke('page_snapshot', params);
98
+ }
99
+ export function pagePress(params) {
100
+ return invoke('page_press', params);
101
+ }
102
+ export function pageWait(params) {
103
+ return invoke('page_wait', params);
104
+ }
105
+ export function pageNavigate(params) {
106
+ return invoke('page_navigate', params);
107
+ }
108
+ export function pageUpload(params) {
109
+ return invoke('page_upload', params);
110
+ }
111
+ export function pageFrames(params) {
112
+ return invoke('page_frames', params);
113
+ }
114
+ export function setDeviceEmulation(params) {
115
+ return invoke('set_device_emulation', params);
116
+ }
117
+ export function setTimezone(params) {
118
+ return invoke('set_timezone', params);
119
+ }
120
+ export function getUserInfo(params = {}) {
121
+ return invoke('get_user_info', params);
122
+ }
123
+ export function runActions(params) {
124
+ return invoke('run_actions', params);
125
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * 底层 Socket 通信模块
3
+ *
4
+ * 通过 Unix Domain Socket (macOS/Linux) 或 Named Pipe (Windows) 与 native host 进程通信。
5
+ * 每次调用新建连接,收到响应后关闭,简单可靠。
6
+ *
7
+ * 当 Socket 文件不存在(ENOENT)时,自动尝试拉起 native host,稍后重试连接。
8
+ */
9
+ export declare const CLIENT_VERSION: string;
10
+ /**
11
+ * Legacy well-known socket. New native-hosts publish per-browser sockets in the
12
+ * registry and we address those; this path is a fallback for pre-registry hosts
13
+ * (or the pre-ping startup window) and is what auto-spawn targets.
14
+ */
15
+ export declare const SOCKET_PATH: string;
16
+ export interface InvokeOptions {
17
+ /** 超时时间(秒),默认 15 */
18
+ timeoutSec?: number;
19
+ /** Force CDP transport instead of extension */
20
+ transport?: 'cdp';
21
+ /** Target a specific browser by id / name (see the browser registry). */
22
+ browser?: string;
23
+ }
24
+ /** Pin the default target browser for subsequent invokes (undefined clears it). */
25
+ export declare function setDefaultBrowser(selector: string | undefined): void;
26
+ export declare function getDefaultBrowser(): string | undefined;
27
+ export declare function decorateBrowserListResult(result: Record<string, any>): Record<string, any>;
28
+ /**
29
+ * 向 native host 发送一个 action 请求并等待响应。
30
+ *
31
+ * 目标解析优先级:显式 options.browser → setDefaultBrowser → 环境变量
32
+ * MEARL_BROWSER → 自动(注册表中最近聚焦的浏览器)。注册表为空时回退到
33
+ * legacy well-known socket,并在 socket 不存在(ENOENT)时自动拉起 native host。
34
+ */
35
+ export declare function invoke(action: string, data?: Record<string, any>, options?: InvokeOptions): Promise<any>;