@hira-core/sdk 1.0.3 → 1.0.4

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/dist/index.d.ts CHANGED
@@ -541,9 +541,12 @@ interface IHidemiumProfile {
541
541
  created_at: string;
542
542
  }
543
543
  interface IHidemiumStartResult {
544
+ status: boolean;
544
545
  remote_port: number;
545
- web_socket: string;
546
+ web_socket?: string;
546
547
  profile_path: string;
548
+ execute_path: string;
549
+ profile_name?: string;
547
550
  uuid: string;
548
551
  }
549
552
  interface IHidemiumListParams {
@@ -572,7 +575,13 @@ declare class HidemiumService {
572
575
  deleteProfiles(uuids: string[]): Promise<boolean>;
573
576
  updateProxy(uuid: string, proxy: string): Promise<boolean>;
574
577
  checkHealth(): Promise<boolean>;
575
- connectToBrowser(wsUrl: string, maxRetries?: number, delayMs?: number): Promise<Browser>;
578
+ /**
579
+ * Kết nối browser — thử theo thứ tự:
580
+ * 1. web_socket (nếu API trả)
581
+ * 2. browserURL via remote_port (nếu API trả)
582
+ * 3. Fallback: quét default port 9222 (Hidemium mặc định)
583
+ */
584
+ connectToBrowser(startResult: IHidemiumStartResult, maxRetries?: number, delayMs?: number): Promise<Browser>;
576
585
  }
577
586
 
578
587
  declare class HidemiumStandaloneAdapter implements IBrowserAdapter {
package/dist/index.js CHANGED
@@ -12535,6 +12535,26 @@ var WindowManager = class {
12535
12535
  const y = Math.floor(row * itemHeight);
12536
12536
  return { x, y };
12537
12537
  }
12538
+ /**
12539
+ * Tính vị trí cửa sổ cho Hidemium (--force-device-scale-factor)
12540
+ * Khác GPM: scale ảnh hưởng kích thước thực tế của window
12541
+ * → dùng effectiveWidth/Height cho cả grid lẫn vị trí
12542
+ */
12543
+ static calculatePositionScaled(index, screen, itemWidth, itemHeight, scale = 1) {
12544
+ const screenWidth = screen.width;
12545
+ const screenHeight = screen.height;
12546
+ const scaledWidth = Math.floor((itemWidth > 0 ? itemWidth : 800) * scale);
12547
+ const scaledHeight = Math.floor((itemHeight > 0 ? itemHeight : 600) * scale);
12548
+ const cols = Math.floor(screenWidth / scaledWidth) || 1;
12549
+ const rows = Math.floor(screenHeight / scaledHeight) || 1;
12550
+ const itemsPerScreen = cols * rows;
12551
+ const visualIndex = index % itemsPerScreen;
12552
+ const row = Math.floor(visualIndex / cols);
12553
+ const col = visualIndex % cols;
12554
+ const x = col * scaledWidth;
12555
+ const y = row * scaledHeight;
12556
+ return { x, y, scaledWidth, scaledHeight };
12557
+ }
12538
12558
  };
12539
12559
 
12540
12560
  // ../../node_modules/.pnpm/axios@1.13.4/node_modules/axios/lib/helpers/bind.js
@@ -16480,7 +16500,7 @@ var HidemiumService = class {
16480
16500
  }
16481
16501
  return false;
16482
16502
  }
16483
- async getProfiles(params, isLocal = true) {
16503
+ async getProfiles(params, isLocal) {
16484
16504
  var _a, _b;
16485
16505
  const response = await this.api.post(
16486
16506
  "/v1/browser/list",
@@ -16490,7 +16510,8 @@ var HidemiumService = class {
16490
16510
  search: (params == null ? void 0 : params.search) || "",
16491
16511
  orderName: (params == null ? void 0 : params.orderName) || 0
16492
16512
  },
16493
- { params: { is_local: isLocal } }
16513
+ // Chỉ truyền is_local nếu caller chỉ định — mặc định lấy tất cả
16514
+ isLocal !== void 0 ? { params: { is_local: isLocal } } : void 0
16494
16515
  );
16495
16516
  return ((_b = (_a = response.data) == null ? void 0 : _a.data) == null ? void 0 : _b.content) || [];
16496
16517
  }
@@ -16520,24 +16541,49 @@ var HidemiumService = class {
16520
16541
  return false;
16521
16542
  }
16522
16543
  }
16523
- async connectToBrowser(wsUrl, maxRetries = 5, delayMs = 1e3) {
16544
+ /**
16545
+ * Kết nối browser — thử theo thứ tự:
16546
+ * 1. web_socket (nếu API trả)
16547
+ * 2. browserURL via remote_port (nếu API trả)
16548
+ * 3. Fallback: quét default port 9222 (Hidemium mặc định)
16549
+ */
16550
+ async connectToBrowser(startResult, maxRetries = 5, delayMs = 1e3) {
16524
16551
  let lastError;
16525
- for (let attempt = 1; attempt <= maxRetries; attempt++) {
16526
- try {
16527
- const browser = await import_puppeteer_core2.default.connect({
16528
- browserWSEndpoint: wsUrl,
16529
- defaultViewport: null
16530
- });
16531
- return browser;
16532
- } catch (error) {
16533
- lastError = error;
16534
- if (attempt < maxRetries) {
16535
- await new Promise((r) => setTimeout(r, delayMs));
16552
+ if (startResult.web_socket) {
16553
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
16554
+ try {
16555
+ const browser = await import_puppeteer_core2.default.connect({
16556
+ browserWSEndpoint: startResult.web_socket,
16557
+ defaultViewport: null
16558
+ });
16559
+ return browser;
16560
+ } catch (error) {
16561
+ lastError = error;
16562
+ if (attempt < maxRetries) {
16563
+ await new Promise((r) => setTimeout(r, delayMs));
16564
+ }
16565
+ }
16566
+ }
16567
+ }
16568
+ if (startResult.remote_port) {
16569
+ const browserURL = `http://127.0.0.1:${startResult.remote_port}`;
16570
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
16571
+ try {
16572
+ const browser = await import_puppeteer_core2.default.connect({
16573
+ browserURL,
16574
+ defaultViewport: null
16575
+ });
16576
+ return browser;
16577
+ } catch (error) {
16578
+ lastError = error;
16579
+ if (attempt < maxRetries) {
16580
+ await new Promise((r) => setTimeout(r, delayMs));
16581
+ }
16536
16582
  }
16537
16583
  }
16538
16584
  }
16539
16585
  throw new Error(
16540
- `Failed to connect to browser at ${wsUrl} after ${maxRetries} attempts. Last error: ${lastError == null ? void 0 : lastError.message}`
16586
+ `Failed to connect to Hidemium browser after ${maxRetries} attempts. Last error: ${lastError == null ? void 0 : lastError.message}`
16541
16587
  );
16542
16588
  }
16543
16589
  };
@@ -16599,7 +16645,16 @@ var HidemiumStandaloneAdapter = class {
16599
16645
  windowConfig.height,
16600
16646
  windowConfig.scale
16601
16647
  );
16602
- const command = `--window-position=${x},${y} --window-size=${windowConfig.width},${windowConfig.height}`;
16648
+ const command = [
16649
+ `--window-position=${x},${y}`,
16650
+ `--window-size=${windowConfig.width},${windowConfig.height}`,
16651
+ `--force-device-scale-factor=${windowConfig.scale}`
16652
+ ].join(" ");
16653
+ try {
16654
+ await this.service.stopProfile(targetProfile.uuid);
16655
+ await new Promise((r) => setTimeout(r, 2e3));
16656
+ } catch {
16657
+ }
16603
16658
  const startResult = await this.service.startProfile(
16604
16659
  targetProfile.uuid,
16605
16660
  command
@@ -16607,9 +16662,12 @@ var HidemiumStandaloneAdapter = class {
16607
16662
  if (!startResult) {
16608
16663
  throw new Error(`Failed to start profile: ${profileName}`);
16609
16664
  }
16610
- const browser = await this.service.connectToBrowser(
16611
- startResult.web_socket
16612
- );
16665
+ if (!startResult.web_socket && !startResult.remote_port) {
16666
+ throw new Error(
16667
+ `Hidemium openProfile did not return web_socket or remote_port for "${profileName}". Please ensure the profile is not already opened in another session.`
16668
+ );
16669
+ }
16670
+ const browser = await this.service.connectToBrowser(startResult);
16613
16671
  const pages = await browser.pages();
16614
16672
  const page = pages.length > 0 ? pages[0] : await browser.newPage();
16615
16673
  this.openedProfiles.set(profileName, targetProfile.uuid);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hira-core/sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "SDK for building Hira automation flows with TypeScript",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",