adspower-browser 1.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.
package/build/cli.js ADDED
@@ -0,0 +1,1024 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // ../core/src/constants/api.ts
27
+ var import_axios = __toESM(require("axios"));
28
+
29
+ // ../core/src/constants/config.ts
30
+ function parseArgs() {
31
+ const args = process.argv;
32
+ let port;
33
+ let apiKey;
34
+ for (let i = 0; i < args.length; i++) {
35
+ if (args[i] === "--port" && i + 1 < args.length) {
36
+ port = args[i + 1];
37
+ }
38
+ if (args[i] === "--api-key" && i + 1 < args.length) {
39
+ apiKey = args[i + 1];
40
+ }
41
+ }
42
+ return {
43
+ port: port || process.env.PORT || "50325",
44
+ apiKey: apiKey || process.env.API_KEY
45
+ };
46
+ }
47
+ var config = parseArgs();
48
+ var PORT = config.port;
49
+ var API_KEY = config.apiKey;
50
+
51
+ // ../core/src/constants/api.ts
52
+ var LOCAL_API_BASE = `http://127.0.0.1:${PORT}`;
53
+ var API_ENDPOINTS = {
54
+ STATUS: "/status",
55
+ START_BROWSER: "/api/v2/browser-profile/start",
56
+ CLOSE_BROWSER: "/api/v2/browser-profile/stop",
57
+ CREATE_BROWSER: "/api/v2/browser-profile/create",
58
+ GET_BROWSER_LIST: "/api/v2/browser-profile/list",
59
+ UPDATE_BROWSER: "/api/v2/browser-profile/update",
60
+ DELETE_BROWSER: "/api/v2/browser-profile/delete",
61
+ GET_PROFILE_COOKIES: "/api/v2/browser-profile/cookies",
62
+ GET_PROFILE_UA: "/api/v2/browser-profile/ua",
63
+ CLOSE_ALL_PROFILES: "/api/v2/browser-profile/stop-all",
64
+ NEW_FINGERPRINT: "/api/v2/browser-profile/new-fingerprint",
65
+ DELETE_CACHE_V2: "/api/v2/browser-profile/delete-cache",
66
+ SHARE_PROFILE: "/api/v2/browser-profile/share",
67
+ GET_BROWSER_ACTIVE: "/api/v2/browser-profile/active",
68
+ CREATE_PROXY: "/api/v2/proxy-list/create",
69
+ UPDATE_PROXY: "/api/v2/proxy-list/update",
70
+ GET_PROXY_LIST: "/api/v2/proxy-list/list",
71
+ DELETE_PROXY: "/api/v2/proxy-list/delete",
72
+ GET_OPENED_BROWSER: "/api/v1/browser/local-active",
73
+ GET_CLOUD_ACTIVE: "/api/v1/browser/cloud-active",
74
+ MOVE_BROWSER: "/api/v1/user/regroup",
75
+ GET_GROUP_LIST: "/api/v1/group/list",
76
+ CREATE_GROUP: "/api/v1/group/create",
77
+ UPDATE_GROUP: "/api/v1/group/update",
78
+ GET_APPLICATION_LIST: "/api/v2/category/list"
79
+ };
80
+ var apiClient = import_axios.default.create({
81
+ headers: API_KEY ? { "Authorization": `Bearer ${API_KEY}` } : {}
82
+ });
83
+
84
+ // ../core/src/utils/requestBuilder.ts
85
+ function buildRequestBody(params) {
86
+ const requestBody = {};
87
+ const basicFields = {
88
+ groupId: "group_id",
89
+ username: "username",
90
+ password: "password",
91
+ cookie: "cookie",
92
+ fakey: "fakey",
93
+ name: "name",
94
+ platform: "platform",
95
+ remark: "remark",
96
+ proxyid: "proxyid",
97
+ repeatConfig: "repeat_config",
98
+ ignoreCookieError: "ignore_cookie_error",
99
+ tabs: "tabs",
100
+ ip: "ip",
101
+ country: "country",
102
+ region: "region",
103
+ city: "city",
104
+ ipchecker: "ipchecker",
105
+ categoryId: "category_id",
106
+ launchArgs: "launch_args",
107
+ profileId: "profile_id"
108
+ };
109
+ Object.entries(basicFields).forEach(([paramKey, key]) => {
110
+ const value = params[paramKey];
111
+ if (value !== void 0) {
112
+ requestBody[key] = value;
113
+ }
114
+ });
115
+ if (params.userProxyConfig) {
116
+ const proxyConfig = buildNestedConfig(params.userProxyConfig);
117
+ if (Object.keys(proxyConfig).length > 0) {
118
+ requestBody.user_proxy_config = proxyConfig;
119
+ }
120
+ }
121
+ if (params.fingerprintConfig) {
122
+ const fpConfig = buildNestedConfig(params.fingerprintConfig);
123
+ if (Object.keys(fpConfig).length > 0) {
124
+ requestBody.fingerprint_config = fpConfig;
125
+ }
126
+ }
127
+ return requestBody;
128
+ }
129
+ function buildNestedConfig(config2) {
130
+ const result = {};
131
+ Object.entries(config2).forEach(([key, value]) => {
132
+ if (value !== void 0) {
133
+ if (typeof value === "object" && value !== null) {
134
+ const nestedConfig = buildNestedConfig(value);
135
+ if (Object.keys(nestedConfig).length > 0) {
136
+ result[key] = nestedConfig;
137
+ }
138
+ } else {
139
+ result[key] = value;
140
+ }
141
+ }
142
+ });
143
+ return result;
144
+ }
145
+
146
+ // ../core/src/handlers/browser.ts
147
+ var browserHandlers = {
148
+ async openBrowser({ profileNo, profileId, ipTab, launchArgs, clearCacheAfterClosing, cdpMask }) {
149
+ const requestBody = {};
150
+ if (profileId) {
151
+ requestBody.profile_id = profileId;
152
+ }
153
+ if (profileNo) {
154
+ requestBody.profile_no = profileNo;
155
+ }
156
+ if (ipTab) {
157
+ requestBody.ip_tab = ipTab;
158
+ }
159
+ if (launchArgs) {
160
+ requestBody.launch_args = launchArgs;
161
+ }
162
+ if (clearCacheAfterClosing) {
163
+ requestBody.delete_cache = clearCacheAfterClosing;
164
+ }
165
+ if (cdpMask) {
166
+ requestBody.cdp_mask = cdpMask;
167
+ }
168
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.START_BROWSER}`, requestBody);
169
+ if (response.data.code === 0) {
170
+ return `Browser opened successfully with: ${Object.entries(response.data.data).map(([key, value]) => {
171
+ if (value && typeof value === "object") {
172
+ return Object.entries(value).map(([key2, value2]) => `ws.${key2}: ${value2}`).join("\n");
173
+ }
174
+ return `${key}: ${value}`;
175
+ }).join("\n")}`;
176
+ }
177
+ throw new Error(`Failed to open browser: ${response.data.msg}`);
178
+ },
179
+ async closeBrowser({ profileId, profileNo }) {
180
+ const requestBody = {};
181
+ if (profileId) {
182
+ requestBody.profile_id = profileId;
183
+ }
184
+ if (profileNo) {
185
+ requestBody.profile_no = profileNo;
186
+ }
187
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.CLOSE_BROWSER}`, requestBody);
188
+ if (response.data.code === 0) {
189
+ return "Browser closed successfully";
190
+ }
191
+ throw new Error(`Failed to close browser: ${response.data.msg}`);
192
+ },
193
+ async createBrowser(params) {
194
+ const requestBody = buildRequestBody(params);
195
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.CREATE_BROWSER}`, requestBody);
196
+ if (response.data.code === 0) {
197
+ return `Browser created successfully with: ${Object.entries(response.data.data).map(([key, value]) => `${key}: ${value}`).join("\n")}`;
198
+ }
199
+ throw new Error(`Failed to create browser: ${response.data.msg}`);
200
+ },
201
+ async updateBrowser(params) {
202
+ const requestBody = buildRequestBody(params);
203
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.UPDATE_BROWSER}`, requestBody);
204
+ if (response.data.code === 0) {
205
+ return `Browser updated successfully with: ${Object.entries(response.data.data || {}).map(([key, value]) => `${key}: ${value}`).join("\n")}`;
206
+ }
207
+ throw new Error(`Failed to update browser: ${response.data.msg}`);
208
+ },
209
+ async deleteBrowser({ profileIds }) {
210
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.DELETE_BROWSER}`, {
211
+ profile_id: profileIds
212
+ });
213
+ if (response.data.code === 0) {
214
+ return `Browsers deleted successfully: ${profileIds.join(", ")}`;
215
+ }
216
+ throw new Error(`Failed to delete browsers: ${response.data.msg}`);
217
+ },
218
+ async getBrowserList(params) {
219
+ const { groupId, limit, page, profileId, profileNo, sortType, sortOrder } = params;
220
+ const requestBody = {};
221
+ if (limit !== void 0) {
222
+ requestBody.limit = limit;
223
+ }
224
+ if (page !== void 0) {
225
+ requestBody.page = page;
226
+ }
227
+ if (profileId && profileId.length > 0) {
228
+ requestBody.profile_id = profileId;
229
+ }
230
+ if (profileNo && profileNo.length > 0) {
231
+ requestBody.profile_no = profileNo;
232
+ }
233
+ if (groupId !== void 0) {
234
+ requestBody.group_id = groupId;
235
+ }
236
+ if (sortType) {
237
+ requestBody.sort_type = sortType;
238
+ }
239
+ if (sortOrder) {
240
+ requestBody.sort_order = sortOrder;
241
+ }
242
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.GET_BROWSER_LIST}`, requestBody);
243
+ if (response.data.code === 0) {
244
+ return `Browser list: ${JSON.stringify(response.data.data.list, null, 2)}`;
245
+ }
246
+ throw new Error(`Failed to get browser list: ${response.data.msg}`);
247
+ },
248
+ async getOpenedBrowser() {
249
+ const response = await apiClient.get(`${LOCAL_API_BASE}${API_ENDPOINTS.GET_OPENED_BROWSER}`);
250
+ if (response.data.code === 0) {
251
+ return `Opened browser list: ${JSON.stringify(response.data.data.list, null, 2)}`;
252
+ }
253
+ throw new Error(`Failed to get opened browsers: ${response.data.msg}`);
254
+ },
255
+ async moveBrowser({ groupId, userIds }) {
256
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.MOVE_BROWSER}`, {
257
+ group_id: groupId,
258
+ user_ids: userIds
259
+ });
260
+ if (response.data.code === 0) {
261
+ return `Browsers moved successfully to group ${groupId}: ${userIds.join(", ")}`;
262
+ }
263
+ throw new Error(`Failed to move browsers: ${response.data.msg}`);
264
+ },
265
+ async getProfileCookies({ profileId, profileNo }) {
266
+ const params = new URLSearchParams();
267
+ if (profileId) {
268
+ params.set("profile_id", profileId);
269
+ }
270
+ if (profileNo) {
271
+ params.set("profile_no", profileNo);
272
+ }
273
+ const response = await apiClient.get(`${LOCAL_API_BASE}${API_ENDPOINTS.GET_PROFILE_COOKIES}`, { params });
274
+ if (response.data.code === 0) {
275
+ return `Profile cookies: ${JSON.stringify(response.data.data, null, 2)}`;
276
+ }
277
+ throw new Error(`Failed to get profile cookies: ${response.data.msg}`);
278
+ },
279
+ async getProfileUa({ profileId, profileNo }) {
280
+ const requestBody = {};
281
+ if (profileId && profileId.length > 0) {
282
+ requestBody.profile_id = profileId;
283
+ }
284
+ if (profileNo && profileNo.length > 0) {
285
+ requestBody.profile_no = profileNo;
286
+ }
287
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.GET_PROFILE_UA}`, requestBody);
288
+ if (response.data.code === 0) {
289
+ return `Profile User-Agent: ${JSON.stringify(response.data.data, null, 2)}`;
290
+ }
291
+ throw new Error(`Failed to get profile User-Agent: ${response.data.msg}`);
292
+ },
293
+ async closeAllProfiles(_params) {
294
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.CLOSE_ALL_PROFILES}`, {});
295
+ if (response.data.code === 0) {
296
+ return "All profiles closed successfully";
297
+ }
298
+ throw new Error(`Failed to close all profiles: ${response.data.msg}`);
299
+ },
300
+ async newFingerprint({ profileId, profileNo }) {
301
+ const requestBody = {};
302
+ if (profileId && profileId.length > 0) {
303
+ requestBody.profile_id = profileId;
304
+ }
305
+ if (profileNo && profileNo.length > 0) {
306
+ requestBody.profile_no = profileNo;
307
+ }
308
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.NEW_FINGERPRINT}`, requestBody);
309
+ if (response.data.code === 0) {
310
+ return `New fingerprint created: ${JSON.stringify(response.data.data, null, 2)}`;
311
+ }
312
+ throw new Error(`Failed to create new fingerprint: ${response.data.msg}`);
313
+ },
314
+ async deleteCacheV2({ profileIds, type }) {
315
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.DELETE_CACHE_V2}`, {
316
+ profile_id: profileIds,
317
+ type
318
+ });
319
+ if (response.data.code === 0) {
320
+ return `Cache deleted successfully for profiles: ${profileIds.join(", ")}`;
321
+ }
322
+ throw new Error(`Failed to delete cache: ${response.data.msg}`);
323
+ },
324
+ async shareProfile({ profileIds, receiver, shareType, content }) {
325
+ const requestBody = {
326
+ profile_id: profileIds,
327
+ receiver
328
+ };
329
+ if (shareType !== void 0) {
330
+ requestBody.share_type = shareType;
331
+ }
332
+ if (content !== void 0) {
333
+ requestBody.content = content;
334
+ }
335
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.SHARE_PROFILE}`, requestBody);
336
+ if (response.data.code === 0) {
337
+ return `Profiles shared successfully: ${profileIds.join(", ")}`;
338
+ }
339
+ throw new Error(`Failed to share profiles: ${response.data.msg}`);
340
+ },
341
+ async getBrowserActive({ profileId, profileNo }) {
342
+ const params = new URLSearchParams();
343
+ if (profileId) {
344
+ params.set("profile_id", profileId);
345
+ }
346
+ if (profileNo) {
347
+ params.set("profile_no", profileNo);
348
+ }
349
+ const response = await apiClient.get(`${LOCAL_API_BASE}${API_ENDPOINTS.GET_BROWSER_ACTIVE}`, { params });
350
+ if (response.data.code === 0) {
351
+ return `Browser active info: ${JSON.stringify(response.data.data, null, 2)}`;
352
+ }
353
+ throw new Error(`Failed to get browser active: ${response.data.msg}`);
354
+ },
355
+ async getCloudActive({ userIds }) {
356
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.GET_CLOUD_ACTIVE}`, {
357
+ user_ids: userIds
358
+ });
359
+ if (response.data.code === 0) {
360
+ return `Cloud active browsers: ${JSON.stringify(response.data.data, null, 2)}`;
361
+ }
362
+ throw new Error(`Failed to get cloud active browsers: ${response.data.msg}`);
363
+ }
364
+ };
365
+
366
+ // ../core/src/handlers/group.ts
367
+ var groupHandlers = {
368
+ async createGroup({ groupName, remark }) {
369
+ const requestBody = {
370
+ group_name: groupName
371
+ };
372
+ if (remark !== void 0) {
373
+ requestBody.remark = remark;
374
+ }
375
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.CREATE_GROUP}`, requestBody);
376
+ if (response.data.code === 0) {
377
+ return `Group created successfully with name: ${groupName}${remark ? `, remark: ${remark}` : ""}`;
378
+ }
379
+ throw new Error(`Failed to create group: ${response.data.msg}`);
380
+ },
381
+ async updateGroup({ groupId, groupName, remark }) {
382
+ const requestBody = {
383
+ group_id: groupId,
384
+ group_name: groupName
385
+ };
386
+ if (remark !== void 0) {
387
+ requestBody.remark = remark;
388
+ }
389
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.UPDATE_GROUP}`, requestBody);
390
+ if (response.data.code === 0) {
391
+ return `Group updated successfully with id: ${groupId}, name: ${groupName}${remark !== void 0 ? `, remark: ${remark === null ? "(cleared)" : remark}` : ""}`;
392
+ }
393
+ throw new Error(`Failed to update group: ${response.data.msg}`);
394
+ },
395
+ async getGroupList({ groupName, size, page }) {
396
+ const params = new URLSearchParams();
397
+ if (groupName) {
398
+ params.set("group_name", groupName);
399
+ }
400
+ if (size) {
401
+ params.set("page_size", size.toString());
402
+ }
403
+ if (page) {
404
+ params.set("page", page.toString());
405
+ }
406
+ const response = await apiClient.get(`${LOCAL_API_BASE}${API_ENDPOINTS.GET_GROUP_LIST}`, { params });
407
+ return `Group list: ${JSON.stringify(response.data.data.list, null, 2)}`;
408
+ }
409
+ };
410
+
411
+ // ../core/src/handlers/application.ts
412
+ var applicationHandlers = {
413
+ async checkStatus() {
414
+ const response = await apiClient.get(`${LOCAL_API_BASE}${API_ENDPOINTS.STATUS}`);
415
+ return `Connection status: ${JSON.stringify(response.data, null, 2)}`;
416
+ },
417
+ async getApplicationList({ category_id, page, limit }) {
418
+ const params = new URLSearchParams();
419
+ if (category_id) {
420
+ params.set("category_id", category_id);
421
+ }
422
+ if (page !== void 0) {
423
+ params.set("page", page.toString());
424
+ }
425
+ if (limit !== void 0) {
426
+ params.set("limit", limit.toString());
427
+ }
428
+ const response = await apiClient.get(`${LOCAL_API_BASE}${API_ENDPOINTS.GET_APPLICATION_LIST}`, { params });
429
+ return `Application list: ${JSON.stringify(response.data.data.list, null, 2)}`;
430
+ }
431
+ };
432
+
433
+ // ../core/src/handlers/proxy.ts
434
+ function buildProxyRequestBody(params) {
435
+ const requestBody = {};
436
+ if (params.proxyId) {
437
+ requestBody.proxy_id = params.proxyId;
438
+ }
439
+ if (params.type !== void 0) {
440
+ requestBody.type = params.type;
441
+ }
442
+ if (params.host !== void 0) {
443
+ requestBody.host = params.host;
444
+ }
445
+ if (params.port !== void 0) {
446
+ requestBody.port = params.port;
447
+ }
448
+ if (params.user !== void 0) {
449
+ requestBody.user = params.user;
450
+ }
451
+ if (params.password !== void 0) {
452
+ requestBody.password = params.password;
453
+ }
454
+ if (params.proxyUrl !== void 0) {
455
+ requestBody.proxy_url = params.proxyUrl;
456
+ }
457
+ if (params.remark !== void 0) {
458
+ requestBody.remark = params.remark;
459
+ }
460
+ if (params.ipchecker !== void 0) {
461
+ requestBody.ipchecker = params.ipchecker;
462
+ }
463
+ return requestBody;
464
+ }
465
+ function buildCreateProxyRequestBody(proxy) {
466
+ const requestBody = {};
467
+ requestBody.type = proxy.type;
468
+ requestBody.host = proxy.host;
469
+ requestBody.port = proxy.port;
470
+ if (proxy.user !== void 0) {
471
+ requestBody.user = proxy.user;
472
+ }
473
+ if (proxy.password !== void 0) {
474
+ requestBody.password = proxy.password;
475
+ }
476
+ if (proxy.proxy_url !== void 0) {
477
+ requestBody.proxy_url = proxy.proxy_url;
478
+ }
479
+ if (proxy.remark !== void 0) {
480
+ requestBody.remark = proxy.remark;
481
+ }
482
+ if (proxy.ipchecker !== void 0) {
483
+ requestBody.ipchecker = proxy.ipchecker;
484
+ }
485
+ return requestBody;
486
+ }
487
+ var proxyHandlers = {
488
+ async createProxy(params) {
489
+ const requestBody = params.proxies.map((proxy) => buildCreateProxyRequestBody(proxy));
490
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.CREATE_PROXY}`, requestBody);
491
+ if (response.data.code === 0) {
492
+ return `Proxy created successfully with: ${Object.entries(response.data.data || {}).map(([key, value]) => `${key}: ${value}`).join("\n")}`;
493
+ }
494
+ throw new Error(`Failed to create proxy: ${response.data.msg}`);
495
+ },
496
+ async updateProxy(params) {
497
+ const requestBody = buildProxyRequestBody(params);
498
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.UPDATE_PROXY}`, requestBody);
499
+ if (response.data.code === 0) {
500
+ return `Proxy updated successfully with: ${Object.entries(response.data.data || {}).map(([key, value]) => `${key}: ${value}`).join("\n")}`;
501
+ }
502
+ throw new Error(`Failed to update proxy: ${response.data.msg}`);
503
+ },
504
+ async getProxyList(params) {
505
+ const { limit, page, proxyId } = params;
506
+ const requestBody = {};
507
+ if (limit !== void 0) {
508
+ requestBody.limit = limit;
509
+ }
510
+ if (page !== void 0) {
511
+ requestBody.page = page;
512
+ }
513
+ if (proxyId && proxyId.length > 0) {
514
+ requestBody.proxy_id = proxyId;
515
+ }
516
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.GET_PROXY_LIST}`, requestBody);
517
+ if (response.data.code === 0) {
518
+ return `Proxy list: ${JSON.stringify(response.data.data.list || response.data.data, null, 2)}`;
519
+ }
520
+ throw new Error(`Failed to get proxy list: ${response.data.msg}`);
521
+ },
522
+ async deleteProxy({ proxyIds }) {
523
+ const response = await apiClient.post(`${LOCAL_API_BASE}${API_ENDPOINTS.DELETE_PROXY}`, {
524
+ proxy_id: proxyIds
525
+ });
526
+ if (response.data.code === 0) {
527
+ return `Proxies deleted successfully: ${proxyIds.join(", ")}`;
528
+ }
529
+ throw new Error(`Failed to delete proxies: ${response.data.msg}`);
530
+ }
531
+ };
532
+
533
+ // ../core/src/handlers/automation.ts
534
+ var import_path = __toESM(require("path"));
535
+ var import_os = __toESM(require("os"));
536
+
537
+ // ../core/src/utils/browserBase.ts
538
+ var import_playwright = require("playwright");
539
+ var BrowserBase = class {
540
+ browser;
541
+ page;
542
+ screenshots;
543
+ constructor() {
544
+ this.browser = null;
545
+ this.page = null;
546
+ this.screenshots = /* @__PURE__ */ new Map();
547
+ }
548
+ get browserInstance() {
549
+ return this.browser;
550
+ }
551
+ get pageInstance() {
552
+ return this.page;
553
+ }
554
+ set pageInstance(page) {
555
+ this.page = page;
556
+ }
557
+ get screenshotsInstance() {
558
+ return this.screenshots;
559
+ }
560
+ checkConnected() {
561
+ const error = new Error("Browser not connected, please connect browser first");
562
+ if (!this.browser) {
563
+ throw error;
564
+ }
565
+ if (!this.browser.isConnected()) {
566
+ throw error;
567
+ }
568
+ if (!this.page) {
569
+ throw error;
570
+ }
571
+ }
572
+ async connectBrowserWithWs(wsUrl) {
573
+ this.browser = await import_playwright.chromium.connectOverCDP(wsUrl);
574
+ const defaultContext = this.browser.contexts()[0];
575
+ this.page = defaultContext.pages()[0];
576
+ await this.page.bringToFront().catch((error) => {
577
+ console.error("Failed to bring page to front", error);
578
+ });
579
+ }
580
+ async resetBrowser() {
581
+ this.browser = null;
582
+ this.page = null;
583
+ }
584
+ };
585
+ var browserBase_default = new BrowserBase();
586
+
587
+ // ../core/src/handlers/automation.ts
588
+ var defaultDownloadsPath = import_path.default.join(import_os.default.homedir(), "Downloads");
589
+
590
+ // ../core/src/types/schemas.ts
591
+ var import_zod = require("zod");
592
+ var userProxyConfigSchema = import_zod.z.object({
593
+ proxy_soft: import_zod.z.enum([
594
+ "brightdata",
595
+ "brightauto",
596
+ "oxylabsauto",
597
+ "922S5auto",
598
+ "ipideeauto",
599
+ "ipfoxyauto",
600
+ "922S5auth",
601
+ "kookauto",
602
+ "ssh",
603
+ "other",
604
+ "no_proxy"
605
+ ]).describe("The proxy soft of the browser"),
606
+ proxy_type: import_zod.z.enum(["http", "https", "socks5", "no_proxy"]).optional(),
607
+ proxy_host: import_zod.z.string().optional().describe("The proxy host of the browser, eg: 127.0.0.1"),
608
+ proxy_port: import_zod.z.string().optional().describe("The proxy port of the browser, eg: 8080"),
609
+ proxy_user: import_zod.z.string().optional().describe("The proxy user of the browser, eg: user"),
610
+ proxy_password: import_zod.z.string().optional().describe("The proxy password of the browser, eg: password"),
611
+ proxy_url: import_zod.z.string().optional().describe("The proxy url of the browser, eg: http://127.0.0.1:8080"),
612
+ global_config: import_zod.z.enum(["0", "1"]).optional().describe("The global config of the browser, default is 0")
613
+ }).describe("The user proxy config of the browser");
614
+ var CHROME_VERSIONS = [
615
+ "92",
616
+ "99",
617
+ "102",
618
+ "105",
619
+ "108",
620
+ "111",
621
+ "114",
622
+ "115",
623
+ "116",
624
+ "117",
625
+ "118",
626
+ "119",
627
+ "120",
628
+ "121",
629
+ "122",
630
+ "123",
631
+ "124",
632
+ "125",
633
+ "126",
634
+ "127",
635
+ "128",
636
+ "129",
637
+ "130",
638
+ "131",
639
+ "132",
640
+ "133",
641
+ "134",
642
+ "135",
643
+ "136",
644
+ "137",
645
+ "138",
646
+ "139",
647
+ "140",
648
+ "141",
649
+ "142",
650
+ "143",
651
+ "144",
652
+ "ua_auto"
653
+ ];
654
+ var FIREFOX_VERSIONS = ["100", "107", "114", "120", "123", "126", "129", "132", "135", "138", "141", "144", "ua_auto"];
655
+ var ALL_KERNEL_VERSIONS = [.../* @__PURE__ */ new Set([...CHROME_VERSIONS, ...FIREFOX_VERSIONS])];
656
+ var browserKernelConfigSchema = import_zod.z.object({
657
+ version: import_zod.z.union(
658
+ ALL_KERNEL_VERSIONS.map((v) => import_zod.z.literal(v))
659
+ ).optional().describe("The version of the browser, must match type: chrome 92\u2013143 or ua_auto, firefox 100,107,114,120,123,126,129,132,135,138,141,144 or ua_auto; default is ua_auto"),
660
+ type: import_zod.z.enum(["chrome", "firefox"]).optional().describe("The type of the browser, default is chrome")
661
+ }).optional().superRefine((data, ctx) => {
662
+ if (!data) return;
663
+ const type = data.type ?? "chrome";
664
+ const version = data.version;
665
+ if (version === void 0) return;
666
+ const validForChrome = CHROME_VERSIONS.includes(version);
667
+ const validForFirefox = FIREFOX_VERSIONS.includes(version);
668
+ if (type === "chrome" && !validForChrome) {
669
+ ctx.addIssue({ code: import_zod.z.ZodIssueCode.custom, message: `Chrome does not support version "${version}". Supported: ${CHROME_VERSIONS.join(", ")}` });
670
+ }
671
+ if (type === "firefox" && !validForFirefox) {
672
+ ctx.addIssue({ code: import_zod.z.ZodIssueCode.custom, message: `Firefox does not support version "${version}". Supported: ${FIREFOX_VERSIONS.join(", ")}` });
673
+ }
674
+ }).describe("The browser kernel config of the browser, default is version: ua_auto, type: chrome");
675
+ var randomUaConfigSchema = import_zod.z.object({
676
+ ua_version: import_zod.z.array(import_zod.z.string()).optional(),
677
+ ua_system_version: import_zod.z.array(
678
+ import_zod.z.enum([
679
+ "Android 9",
680
+ "Android 10",
681
+ "Android 11",
682
+ "Android 12",
683
+ "Android 13",
684
+ "Android 14",
685
+ "Android 15",
686
+ "iOS 14",
687
+ "iOS 15",
688
+ "iOS 16",
689
+ "iOS 17",
690
+ "iOS 18",
691
+ "Windows 7",
692
+ "Windows 8",
693
+ "Windows 10",
694
+ "Windows 11",
695
+ "Mac OS X 10",
696
+ "Mac OS X 11",
697
+ "Mac OS X 12",
698
+ "Mac OS X 13",
699
+ "Mac OS X 14",
700
+ "Mac OS X 15",
701
+ "Mac OS X",
702
+ "Windows",
703
+ "iOS",
704
+ "Android",
705
+ "Linux"
706
+ ])
707
+ ).optional().describe(
708
+ 'UA system version. Mac OS X / Windows / iOS / Android / Linux = random any version of that system; omit to random across all systems. e.g. ["Android 9", "iOS 14"] or ["Android", "Mac OS X"]'
709
+ )
710
+ }).optional().describe("The random ua config of the browser, default is ua_version: [], ua_system_version: []");
711
+ var fingerprintConfigSchema = import_zod.z.object({
712
+ automatic_timezone: import_zod.z.enum(["0", "1"]).optional().describe("The automatic timezone of the browser, default is 0"),
713
+ timezone: import_zod.z.string().optional().describe("The timezone of the browser, eg: Asia/Shanghai"),
714
+ language: import_zod.z.array(import_zod.z.string()).optional().describe('The language of the browser, eg: ["en-US", "zh-CN"]'),
715
+ flash: import_zod.z.enum(["block", "allow"]).optional().describe("The flash of the browser, default is disabled"),
716
+ fonts: import_zod.z.array(import_zod.z.string()).optional().describe('The fonts of the browser, eg: ["Arial", "Times New Roman"]'),
717
+ webrtc: import_zod.z.enum(["disabled", "forward", "proxy", "local"]).optional().describe("The webrtc of the browser, default is disabled"),
718
+ browser_kernel_config: browserKernelConfigSchema,
719
+ random_ua: randomUaConfigSchema,
720
+ tls_switch: import_zod.z.enum(["0", "1"]).optional().describe("The tls switch of the browser, default is 0"),
721
+ tls: import_zod.z.string().optional().describe('The tls of the browser, if tls_switch is 1, you can set the tls of the browser, eg: "0xC02C,0xC030"')
722
+ }).optional().describe('The fingerprint config of the browser, default is automatic_timezone: 0, timezone: "", language: [], flash: "", fonts: [], webrtc: disabled, browser_kernel_config: ua_auto, random_ua: ua_version: [], ua_system_version: [], tls_switch: 0, tls: ""');
723
+ var schemas = {
724
+ createBrowserSchema: import_zod.z.object({
725
+ groupId: import_zod.z.string().regex(/^\d+$/, "Group ID must be a numeric string").describe('The group id of the browser, must be a numeric string (e.g., "123"). You can use the get-group-list tool to get the group list or create a new group, use 0 for Ungrouped'),
726
+ username: import_zod.z.string().optional().describe("Platform account username"),
727
+ password: import_zod.z.string().optional().describe("Platform account password"),
728
+ cookie: import_zod.z.string().optional().describe("Cookie data in JSON or Netscape format"),
729
+ fakey: import_zod.z.string().optional().describe("2FA key for online 2FA code generators"),
730
+ name: import_zod.z.string().max(100).optional().describe("Account name, max 100 characters"),
731
+ platform: import_zod.z.string().optional().describe("Platform domain, eg: facebook.com"),
732
+ remark: import_zod.z.string().optional().describe("Remarks to describe the account. Maximum 1500 characters."),
733
+ userProxyConfig: userProxyConfigSchema.optional().describe("Either user_proxy_config or proxyid must be provided. Only one is required."),
734
+ proxyid: import_zod.z.string().optional().describe("Either user_proxy_config or proxyid must be provided. Only one is required."),
735
+ repeatConfig: import_zod.z.array(import_zod.z.union([import_zod.z.literal(0), import_zod.z.literal(2), import_zod.z.literal(3), import_zod.z.literal(4)])).optional().describe("Account deduplication settings (0, 2, 3, or 4)"),
736
+ ignoreCookieError: import_zod.z.enum(["0", "1"]).optional().describe("Handle cookie verification failures: 0 (default) return data as-is, 1 filter out incorrectly formatted cookies"),
737
+ tabs: import_zod.z.array(import_zod.z.string()).optional().describe('URLs to open on startup, eg: ["https://www.google.com"]'),
738
+ ip: import_zod.z.string().optional().describe("IP address"),
739
+ country: import_zod.z.string().optional().describe('Country/Region, eg: "CN"'),
740
+ region: import_zod.z.string().optional().describe("Region"),
741
+ city: import_zod.z.string().optional().describe("City"),
742
+ ipchecker: import_zod.z.enum(["ip2location", "ipapi"]).optional().describe("IP query channel"),
743
+ categoryId: import_zod.z.string().optional().describe("The category id of the browser, you can use the get-application-list tool to get the application list"),
744
+ fingerprintConfig: fingerprintConfigSchema.optional()
745
+ }).refine((data) => data.userProxyConfig || data.proxyid, {
746
+ message: "Either userProxyConfig or proxyid must be provided"
747
+ }).refine((data) => data.username || data.password || data.cookie || data.fakey, {
748
+ message: "At least one account information field (username, password, cookie, or fakey) must be provided"
749
+ }),
750
+ updateBrowserSchema: import_zod.z.object({
751
+ platform: import_zod.z.string().optional().describe("The platform of the browser, eg: facebook.com"),
752
+ tabs: import_zod.z.array(import_zod.z.string()).optional().describe('The tabs of the browser, eg: ["https://www.google.com"]'),
753
+ cookie: import_zod.z.string().optional().describe("The cookie of the browser"),
754
+ username: import_zod.z.string().optional().describe('The username of the browser, eg: "user"'),
755
+ password: import_zod.z.string().optional().describe('The password of the browser, eg: "password"'),
756
+ fakey: import_zod.z.string().optional().describe("Enter the 2FA-key"),
757
+ ignoreCookieError: import_zod.z.enum(["0", "1"]).optional().describe("Specifies how to handle the case when cookie validation fails."),
758
+ groupId: import_zod.z.string().optional().describe('The group id of the browser, must be a numeric string (e.g., "123"). You can use the get-group-list tool to get the group list or create a new group'),
759
+ name: import_zod.z.string().max(100).optional().describe('The Profile name of the browser, eg: "My Browser"'),
760
+ remark: import_zod.z.string().max(1500).optional().describe("Profile remarks, maximum 1500 characters"),
761
+ country: import_zod.z.string().optional().describe('The country of the browser, eg: "CN"'),
762
+ region: import_zod.z.string().optional().describe("The region of the browser"),
763
+ city: import_zod.z.string().optional().describe("The city of the browser"),
764
+ ip: import_zod.z.string().optional().describe("The IP of the browser"),
765
+ categoryId: import_zod.z.string().optional().describe("The category id of the browser, you can use the get-application-list tool to get the application list"),
766
+ userProxyConfig: userProxyConfigSchema.optional(),
767
+ proxyid: import_zod.z.string().optional().describe("Proxy ID"),
768
+ fingerprintConfig: fingerprintConfigSchema.optional(),
769
+ launchArgs: import_zod.z.string().optional().describe("Browser startup parameters"),
770
+ profileId: import_zod.z.string().describe("The profile id of the browser to update, it is required when you want to update the browser")
771
+ }),
772
+ openBrowserSchema: import_zod.z.object({
773
+ profileNo: import_zod.z.string().optional().describe("Priority will be given to user id when profile_id is filled."),
774
+ profileId: import_zod.z.string().describe("Unique profile ID, generated after creating profile. The profile id of the browser to open"),
775
+ ipTab: import_zod.z.enum(["0", "1"]).optional().describe("The ip tab of the browser, 0 is not use ip tab, 1 is use ip tab, default is 0"),
776
+ launchArgs: import_zod.z.string().optional().describe("The launch args of the browser, use chrome launch args, or vista url"),
777
+ clearCacheAfterClosing: import_zod.z.enum(["0", "1"]).optional().describe("The clear cache after closing of the browser, 0 is not clear cache after closing, 1 is clear cache after closing, default is 0"),
778
+ cdpMask: import_zod.z.enum(["0", "1"]).optional().describe("The cdp mask of the browser, 0 is not use cdp mask, 1 is use cdp mask, default is 0")
779
+ }).strict(),
780
+ closeBrowserSchema: import_zod.z.object({
781
+ profileId: import_zod.z.string().optional().describe("The profile id of the browser to stop, either profileId or profileNo must be provided"),
782
+ profileNo: import_zod.z.string().optional().describe("The profile number of the browser to stop, priority will be given to profileId when profileId is filled")
783
+ }).refine((data) => data.profileId || data.profileNo, {
784
+ message: "Either profileId or profileNo must be provided"
785
+ }),
786
+ deleteBrowserSchema: import_zod.z.object({
787
+ profileIds: import_zod.z.array(import_zod.z.string()).describe("The profile ids of the browsers to delete, it is required when you want to delete the browser")
788
+ }).strict(),
789
+ getBrowserListSchema: import_zod.z.object({
790
+ groupId: import_zod.z.string().regex(/^\d+$/, "Group ID must be a numeric string").optional().describe("Query by group ID; searches all groups if empty"),
791
+ limit: import_zod.z.number().optional().describe("Profiles per page. Number of profiles returned per page, range 1 ~ 200, default is 50"),
792
+ page: import_zod.z.number().optional().describe("Page number for results, default is 1"),
793
+ profileId: import_zod.z.array(import_zod.z.string()).optional().describe('Query by profile ID. Example: ["h1yynkm","h1yynks"]'),
794
+ profileNo: import_zod.z.array(import_zod.z.string()).optional().describe('Query by profile number. Example: ["123","124"]'),
795
+ sortType: import_zod.z.enum(["profile_no", "last_open_time", "created_time"]).optional().describe("Sort results by: profile_no, last_open_time, or created_time"),
796
+ sortOrder: import_zod.z.enum(["asc", "desc"]).optional().describe('Sort order: "asc" (ascending) or "desc" (descending)')
797
+ }).strict(),
798
+ moveBrowserSchema: import_zod.z.object({
799
+ groupId: import_zod.z.string().regex(/^\d+$/, "Group ID must be a numeric string").describe('The target group id, must be a numeric string (e.g., "123"). You can use the get-group-list tool to get the group list'),
800
+ userIds: import_zod.z.array(import_zod.z.string()).describe("The browser Profile ids to move")
801
+ }).strict(),
802
+ getProfileCookiesSchema: import_zod.z.object({
803
+ profileId: import_zod.z.string().optional().describe("The profile id, either profileId or profileNo must be provided"),
804
+ profileNo: import_zod.z.string().optional().describe("The profile number, priority will be given to profileId when profileId is filled")
805
+ }).refine((data) => data.profileId || data.profileNo, {
806
+ message: "Either profileId or profileNo must be provided"
807
+ }),
808
+ getProfileUaSchema: import_zod.z.object({
809
+ profileId: import_zod.z.array(import_zod.z.string()).optional().describe("The profile id array, either profileId or profileNo must be provided"),
810
+ profileNo: import_zod.z.array(import_zod.z.string()).optional().describe("The profile number array, priority will be given to profileId when profileId is filled")
811
+ }).refine((data) => data.profileId && data.profileId.length > 0 || data.profileNo && data.profileNo.length > 0, {
812
+ message: "Either profileId or profileNo must be provided with at least one element"
813
+ }),
814
+ closeAllProfilesSchema: import_zod.z.object({}).strict(),
815
+ newFingerprintSchema: import_zod.z.object({
816
+ profileId: import_zod.z.array(import_zod.z.string()).optional().describe("The profile id array, either profileId or profileNo must be provided"),
817
+ profileNo: import_zod.z.array(import_zod.z.string()).optional().describe("The profile number array, priority will be given to profileId when profileId is filled")
818
+ }).strict(),
819
+ deleteCacheV2Schema: import_zod.z.object({
820
+ profileIds: import_zod.z.array(import_zod.z.string()).describe("The profile ids array, it is required"),
821
+ type: import_zod.z.array(import_zod.z.enum(["local_storage", "indexeddb", "extension_cache", "cookie", "history", "image_file"])).describe("Types of cache to clear, it is required")
822
+ }).strict(),
823
+ shareProfileSchema: import_zod.z.object({
824
+ profileIds: import_zod.z.array(import_zod.z.string()).describe("The profile ids array, it is required"),
825
+ receiver: import_zod.z.string().describe("Receiver's account email or phone number (no area code), it is required"),
826
+ shareType: import_zod.z.number().int().optional().describe("Share type: 1 for email (default), 2 for phone number"),
827
+ content: import_zod.z.array(import_zod.z.enum(["name", "proxy", "remark", "tabs"])).optional().describe("Shared content")
828
+ }).strict(),
829
+ createGroupSchema: import_zod.z.object({
830
+ groupName: import_zod.z.string().describe("The name of the group to create"),
831
+ remark: import_zod.z.string().optional().describe("The remark of the group")
832
+ }).strict(),
833
+ updateGroupSchema: import_zod.z.object({
834
+ groupId: import_zod.z.string().regex(/^\d+$/, "Group ID must be a numeric string").describe('The id of the group to update, must be a numeric string (e.g., "123"). You can use the get-group-list tool to get the group list'),
835
+ groupName: import_zod.z.string().describe("The new name of the group"),
836
+ remark: import_zod.z.string().nullable().optional().describe("The new remark of the group")
837
+ }).strict(),
838
+ getGroupListSchema: import_zod.z.object({
839
+ groupName: import_zod.z.string().optional().describe("The name of the group to search, use like to search"),
840
+ size: import_zod.z.number().optional().describe("The size of the page, max is 100, default is 10"),
841
+ page: import_zod.z.number().optional().describe("The page of the group, default is 1")
842
+ }).strict(),
843
+ getApplicationListSchema: import_zod.z.object({
844
+ category_id: import_zod.z.string().optional().describe("Extension category_id"),
845
+ page: import_zod.z.number().optional().describe("Page number, default 1"),
846
+ limit: import_zod.z.number().min(1).max(100).optional().describe("Default 1, how many values are returned per page, range 1 to 100")
847
+ }).strict(),
848
+ getBrowserActiveSchema: import_zod.z.object({
849
+ profileId: import_zod.z.string().optional().describe("The profile id, either profileId or profileNo must be provided"),
850
+ profileNo: import_zod.z.string().optional().describe("The profile number, priority will be given to profileId when profileId is filled")
851
+ }).refine((data) => data.profileId || data.profileNo, {
852
+ message: "Either profileId or profileNo must be provided"
853
+ }),
854
+ getCloudActiveSchema: import_zod.z.object({
855
+ userIds: import_zod.z.string().describe("Profile IDs string to check (split by comma, max 100 per request). Unique profile ID, generated after creating the profile.")
856
+ }).refine((data) => data.userIds.split(",").length <= 100, {
857
+ message: "The number of profile ids is too many, the maximum is 100"
858
+ }),
859
+ createProxySchema: import_zod.z.object({
860
+ proxies: import_zod.z.array(import_zod.z.object({
861
+ type: import_zod.z.enum(["http", "https", "ssh", "socks5"]).describe("Proxy type, support: http/https/ssh/socks5"),
862
+ host: import_zod.z.string().describe("Proxy host, support: ipV4, ipV6, eg: 192.168.0.1"),
863
+ port: import_zod.z.string().describe("Port, range: 0-65536, eg: 8000"),
864
+ user: import_zod.z.string().optional().describe("Proxy username, eg: user12345678"),
865
+ password: import_zod.z.string().optional().describe("Proxy password, eg: password"),
866
+ proxy_url: import_zod.z.string().optional().describe("URL used to refresh the proxy, eg: https://www.baidu.com/"),
867
+ remark: import_zod.z.string().optional().describe("Remark/description for the proxy"),
868
+ ipchecker: import_zod.z.enum(["ipinfo", "ip2location", "ipapi", "ipfoxy", "ipidea"]).optional().describe("IP checker.")
869
+ }).strict()).describe("Array of proxy configurations to create")
870
+ }).strict(),
871
+ updateProxySchema: import_zod.z.object({
872
+ proxyId: import_zod.z.string().describe("The unique id after the proxy is added"),
873
+ type: import_zod.z.enum(["http", "https", "ssh", "socks5"]).optional().describe("Proxy type, support: http/https/ssh/socks5"),
874
+ host: import_zod.z.string().optional().describe("Proxy host, support: ipV4, ipV6, eg: 192.168.0.1"),
875
+ port: import_zod.z.string().optional().describe("Port, range: 0-65536, eg: 8000"),
876
+ user: import_zod.z.string().optional().describe("Proxy username, eg: user12345678"),
877
+ password: import_zod.z.string().optional().describe("Proxy password, eg: password"),
878
+ proxyUrl: import_zod.z.string().optional().describe("URL used to refresh the proxy, eg: https://www.baidu.com/"),
879
+ remark: import_zod.z.string().optional().describe("Remark/description for the proxy"),
880
+ ipchecker: import_zod.z.enum(["ip2location", "ipapi", "ipfoxy", "ipidea"]).optional().describe("IP checker.")
881
+ }).strict(),
882
+ getProxyListSchema: import_zod.z.object({
883
+ limit: import_zod.z.number().optional().describe("Profiles per page. Number of proxies returned per page, range 1 ~ 200, default is 50"),
884
+ page: import_zod.z.number().optional().describe("Page number for results, default is 1"),
885
+ proxyId: import_zod.z.array(import_zod.z.string()).optional().describe('Query by proxy ID. Example: ["proxy1","proxy2"]')
886
+ }).strict(),
887
+ deleteProxySchema: import_zod.z.object({
888
+ proxyIds: import_zod.z.array(import_zod.z.string()).describe("The proxy ids of the proxies to delete, it is required when you want to delete the proxy. The maximum is 100. ")
889
+ }).strict(),
890
+ emptySchema: import_zod.z.object({}).strict(),
891
+ createAutomationSchema: import_zod.z.object({
892
+ userId: import_zod.z.string().optional().describe("The browser id of the browser to connect"),
893
+ serialNumber: import_zod.z.string().optional().describe("The serial number of the browser to connect"),
894
+ wsUrl: import_zod.z.string().describe("The ws url of the browser, get from the open-browser tool content `ws.puppeteer`")
895
+ }).strict(),
896
+ navigateSchema: import_zod.z.object({
897
+ url: import_zod.z.string().describe("The url to navigate to")
898
+ }).strict(),
899
+ screenshotSchema: import_zod.z.object({
900
+ savePath: import_zod.z.string().optional().describe("The path to save the screenshot"),
901
+ isFullPage: import_zod.z.boolean().optional().describe("The is full page of the screenshot")
902
+ }).strict(),
903
+ clickElementSchema: import_zod.z.object({
904
+ selector: import_zod.z.string().describe("The selector of the element to click, find from the page source code")
905
+ }).strict(),
906
+ fillInputSchema: import_zod.z.object({
907
+ selector: import_zod.z.string().describe("The selector of the input to fill, find from the page source code"),
908
+ text: import_zod.z.string().describe("The text to fill in the input")
909
+ }).strict(),
910
+ selectOptionSchema: import_zod.z.object({
911
+ selector: import_zod.z.string().describe("The selector of the option to select, find from the page source code"),
912
+ value: import_zod.z.string().describe("The value of the option to select")
913
+ }).strict(),
914
+ hoverElementSchema: import_zod.z.object({
915
+ selector: import_zod.z.string().describe("The selector of the element to hover, find from the page source code")
916
+ }).strict(),
917
+ scrollElementSchema: import_zod.z.object({
918
+ selector: import_zod.z.string().describe("The selector of the element to scroll, find from the page source code")
919
+ }).strict(),
920
+ pressKeySchema: import_zod.z.object({
921
+ key: import_zod.z.string().describe('The key to press, eg: "Enter"'),
922
+ selector: import_zod.z.string().optional().describe("The selector of the element to press the key, find from the page source code")
923
+ }).strict(),
924
+ evaluateScriptSchema: import_zod.z.object({
925
+ script: import_zod.z.string().describe(`The script to evaluate, eg: "document.querySelector('#username').value = 'test'"`)
926
+ }).strict(),
927
+ dragElementSchema: import_zod.z.object({
928
+ selector: import_zod.z.string().describe("The selector of the element to drag, find from the page source code"),
929
+ targetSelector: import_zod.z.string().describe("The selector of the element to drag to, find from the page source code")
930
+ }).strict(),
931
+ iframeClickElementSchema: import_zod.z.object({
932
+ selector: import_zod.z.string().describe("The selector of the element to click, find from the page source code"),
933
+ iframeSelector: import_zod.z.string().describe("The selector of the iframe to click, find from the page source code")
934
+ }).strict()
935
+ };
936
+
937
+ // src/cli.ts
938
+ var STATELESS_HANDLERS = {
939
+ "open-browser": browserHandlers.openBrowser,
940
+ "close-browser": browserHandlers.closeBrowser,
941
+ "create-browser": browserHandlers.createBrowser,
942
+ "update-browser": browserHandlers.updateBrowser,
943
+ "delete-browser": browserHandlers.deleteBrowser,
944
+ "get-browser-list": browserHandlers.getBrowserList,
945
+ "get-opened-browser": browserHandlers.getOpenedBrowser,
946
+ "move-browser": browserHandlers.moveBrowser,
947
+ "get-profile-cookies": browserHandlers.getProfileCookies,
948
+ "get-profile-ua": browserHandlers.getProfileUa,
949
+ "close-all-profiles": browserHandlers.closeAllProfiles,
950
+ "new-fingerprint": browserHandlers.newFingerprint,
951
+ "delete-cache-v2": browserHandlers.deleteCacheV2,
952
+ "share-profile": browserHandlers.shareProfile,
953
+ "get-browser-active": browserHandlers.getBrowserActive,
954
+ "get-cloud-active": browserHandlers.getCloudActive,
955
+ "create-group": groupHandlers.createGroup,
956
+ "update-group": groupHandlers.updateGroup,
957
+ "get-group-list": groupHandlers.getGroupList,
958
+ "check-status": applicationHandlers.checkStatus,
959
+ "get-application-list": applicationHandlers.getApplicationList,
960
+ "create-proxy": proxyHandlers.createProxy,
961
+ "update-proxy": proxyHandlers.updateProxy,
962
+ "get-proxy-list": proxyHandlers.getProxyList,
963
+ "delete-proxy": proxyHandlers.deleteProxy
964
+ };
965
+ var SINGLE_PROFILE_ID_COMMANDS = {
966
+ "open-browser": "profileId",
967
+ "close-browser": "profileId",
968
+ "get-profile-cookies": "profileId",
969
+ "get-browser-active": "profileId"
970
+ };
971
+ var SINGLE_PROFILE_ID_ARRAY_COMMANDS = ["get-profile-ua", "new-fingerprint"];
972
+ function parseArgv(argv) {
973
+ let i = 0;
974
+ while (i < argv.length) {
975
+ if (argv[i] === "--port" || argv[i] === "--api-key") {
976
+ i += 2;
977
+ continue;
978
+ }
979
+ break;
980
+ }
981
+ const command = argv[i];
982
+ const arg = argv[i + 1];
983
+ if (!command || !STATELESS_HANDLERS[command]) {
984
+ throw new Error(`Unknown or unsupported command: ${command || "(missing)"}. Supported: ${Object.keys(STATELESS_HANDLERS).join(", ")}`);
985
+ }
986
+ let args = {};
987
+ if (arg) {
988
+ const trimmed = arg.trim();
989
+ if (trimmed.startsWith("{")) {
990
+ try {
991
+ args = JSON.parse(arg);
992
+ } catch {
993
+ throw new Error("Invalid JSON for command args");
994
+ }
995
+ } else if (SINGLE_PROFILE_ID_COMMANDS[command]) {
996
+ const key = SINGLE_PROFILE_ID_COMMANDS[command];
997
+ args = { [key]: trimmed };
998
+ } else if (SINGLE_PROFILE_ID_ARRAY_COMMANDS.includes(command)) {
999
+ args = { profileId: [trimmed] };
1000
+ } else {
1001
+ try {
1002
+ args = JSON.parse(arg);
1003
+ } catch {
1004
+ throw new Error(`Command requires JSON args (e.g. '{"key":"value"}') or use a supported shorthand`);
1005
+ }
1006
+ }
1007
+ }
1008
+ return { command, args };
1009
+ }
1010
+ async function main() {
1011
+ const argv = process.argv.slice(2);
1012
+ try {
1013
+ const { command, args } = parseArgv(argv);
1014
+ const handler = STATELESS_HANDLERS[command];
1015
+ const result = await handler(args);
1016
+ const out = typeof result === "string" ? result : JSON.stringify(result, null, 2);
1017
+ process.stdout.write(out + "\n");
1018
+ } catch (err) {
1019
+ const msg = err instanceof Error ? err.message : String(err);
1020
+ process.stderr.write(msg + "\n");
1021
+ process.exit(1);
1022
+ }
1023
+ }
1024
+ main();