gpt-driver-node 1.0.6 → 1.0.8

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.cjs CHANGED
@@ -954,6 +954,7 @@ class GptDriver {
954
954
  step_number = 1;
955
955
  organisationId;
956
956
  configFilePath;
957
+ additionalUserContext;
957
958
  // Session Execution Stats
958
959
  _stats_startTime = 0;
959
960
  _stats_executedSteps = 0;
@@ -989,6 +990,7 @@ class GptDriver {
989
990
  this.cachingMode = config.cachingMode ?? "NONE";
990
991
  this.organisationId = config.organisationId;
991
992
  this.configFilePath = config.configFilePath;
993
+ this.additionalUserContext = config.additionalUserContext;
992
994
  if (config.useGptDriverCloud) {
993
995
  if (config.serverConfig.device?.platform == null) {
994
996
  throw new Error("Platform is missing. Please specify the platform when using GPTDriver Cloud.");
@@ -1115,7 +1117,8 @@ class GptDriver {
1115
1117
  },
1116
1118
  use_internal_virtual_device: this.useGptDriverCloud,
1117
1119
  build_id: this.buildId,
1118
- caching_mode: this.cachingMode
1120
+ caching_mode: this.cachingMode,
1121
+ ...this.additionalUserContext && { additional_user_context: this.additionalUserContext }
1119
1122
  }
1120
1123
  );
1121
1124
  this.gptDriverSessionId = response.data.sessionId;
@@ -1484,31 +1487,40 @@ ${"=".repeat(50)}`);
1484
1487
  globalLogger.debug("Capturing screenshot...");
1485
1488
  let screenshot;
1486
1489
  if (appiumSessionConfig.platform === "Android") {
1487
- try {
1488
- const { execSync } = await import('node:child_process');
1489
- let udid;
1490
- if (this.driver) {
1491
- if (this.driver.sessionId != null) {
1492
- const caps = this.driver.capabilities;
1493
- udid = caps["appium:udid"] || caps["udid"];
1494
- } else {
1495
- const driver = this.driver;
1496
- const capabilities = await driver.getCapabilities();
1497
- udid = capabilities.get("appium:udid") || capabilities.get("udid");
1490
+ const serverHostname = new URL(appiumSessionConfig.serverUrl).hostname;
1491
+ const isLocalhost = serverHostname === "localhost" || serverHostname === "127.0.0.1" || serverHostname === "::1";
1492
+ let rawBuffer;
1493
+ if (isLocalhost) {
1494
+ try {
1495
+ const { execSync } = await import('node:child_process');
1496
+ let udid;
1497
+ if (this.driver) {
1498
+ if (this.driver.sessionId != null) {
1499
+ const caps = this.driver.capabilities;
1500
+ udid = caps["appium:udid"] || caps["udid"];
1501
+ } else {
1502
+ const driver = this.driver;
1503
+ const capabilities = await driver.getCapabilities();
1504
+ udid = capabilities.get("appium:udid") || capabilities.get("udid");
1505
+ }
1498
1506
  }
1507
+ const deviceArg = udid ? `-s ${udid}` : "";
1508
+ rawBuffer = execSync(`adb ${deviceArg} exec-out screencap -p`, {
1509
+ encoding: "buffer",
1510
+ maxBuffer: 50 * 1024 * 1024
1511
+ });
1512
+ } catch (e) {
1513
+ globalLogger.warn("ADB screenshot failed, falling back to Appium screenshot");
1514
+ const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/screenshot`);
1515
+ const screenshotResponse = await axios.get(url);
1516
+ rawBuffer = Buffer.from(screenshotResponse.data.value, "base64");
1499
1517
  }
1500
- const deviceArg = udid ? `-s ${udid}` : "";
1501
- const buffer = execSync(`adb ${deviceArg} exec-out screencap -p`, {
1502
- encoding: "buffer",
1503
- maxBuffer: 50 * 1024 * 1024
1504
- });
1505
- screenshot = buffer.toString("base64");
1506
- } catch (e) {
1507
- globalLogger.warn("ADB screenshot failed, falling back to Appium screenshot");
1518
+ } else {
1508
1519
  const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/screenshot`);
1509
1520
  const screenshotResponse = await axios.get(url);
1510
- screenshot = screenshotResponse.data.value;
1521
+ rawBuffer = Buffer.from(screenshotResponse.data.value, "base64");
1511
1522
  }
1523
+ screenshot = (await sharp(rawBuffer).jpeg({ quality: 80 }).toBuffer()).toString("base64");
1512
1524
  } else {
1513
1525
  const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/screenshot`);
1514
1526
  const screenshotResponse = await axios.get(url);
@@ -1617,7 +1629,7 @@ ${"=".repeat(50)}`);
1617
1629
  const smartLoopEndTime = performance.now();
1618
1630
  globalLogger.debug(`[Performance] Smart loop completed in ${(smartLoopEndTime - smartLoopStartTime).toFixed(2)}ms`);
1619
1631
  if (!result.success) {
1620
- throw new Error(result.error || "Smart loop execution failed");
1632
+ await this.setSessionFailed();
1621
1633
  }
1622
1634
  if (result.cacheHitCount) {
1623
1635
  this._stats_cacheHits += result.cacheHitCount;
package/dist/index.d.cts CHANGED
@@ -22,6 +22,7 @@ interface GptDriverConfig {
22
22
  useGptDriverCloud?: boolean;
23
23
  buildId?: string;
24
24
  cachingMode?: CachingMode;
25
+ additionalUserContext?: string;
25
26
  organisationId?: string;
26
27
  configFilePath?: string;
27
28
  }
@@ -512,6 +513,7 @@ declare class GptDriver {
512
513
  private step_number;
513
514
  private organisationId?;
514
515
  private configFilePath?;
516
+ private additionalUserContext?;
515
517
  private _stats_startTime;
516
518
  private _stats_executedSteps;
517
519
  private _stats_cacheHits;
package/dist/index.mjs CHANGED
@@ -952,6 +952,7 @@ class GptDriver {
952
952
  step_number = 1;
953
953
  organisationId;
954
954
  configFilePath;
955
+ additionalUserContext;
955
956
  // Session Execution Stats
956
957
  _stats_startTime = 0;
957
958
  _stats_executedSteps = 0;
@@ -987,6 +988,7 @@ class GptDriver {
987
988
  this.cachingMode = config.cachingMode ?? "NONE";
988
989
  this.organisationId = config.organisationId;
989
990
  this.configFilePath = config.configFilePath;
991
+ this.additionalUserContext = config.additionalUserContext;
990
992
  if (config.useGptDriverCloud) {
991
993
  if (config.serverConfig.device?.platform == null) {
992
994
  throw new Error("Platform is missing. Please specify the platform when using GPTDriver Cloud.");
@@ -1113,7 +1115,8 @@ class GptDriver {
1113
1115
  },
1114
1116
  use_internal_virtual_device: this.useGptDriverCloud,
1115
1117
  build_id: this.buildId,
1116
- caching_mode: this.cachingMode
1118
+ caching_mode: this.cachingMode,
1119
+ ...this.additionalUserContext && { additional_user_context: this.additionalUserContext }
1117
1120
  }
1118
1121
  );
1119
1122
  this.gptDriverSessionId = response.data.sessionId;
@@ -1482,31 +1485,40 @@ ${"=".repeat(50)}`);
1482
1485
  globalLogger.debug("Capturing screenshot...");
1483
1486
  let screenshot;
1484
1487
  if (appiumSessionConfig.platform === "Android") {
1485
- try {
1486
- const { execSync } = await import('node:child_process');
1487
- let udid;
1488
- if (this.driver) {
1489
- if (this.driver.sessionId != null) {
1490
- const caps = this.driver.capabilities;
1491
- udid = caps["appium:udid"] || caps["udid"];
1492
- } else {
1493
- const driver = this.driver;
1494
- const capabilities = await driver.getCapabilities();
1495
- udid = capabilities.get("appium:udid") || capabilities.get("udid");
1488
+ const serverHostname = new URL(appiumSessionConfig.serverUrl).hostname;
1489
+ const isLocalhost = serverHostname === "localhost" || serverHostname === "127.0.0.1" || serverHostname === "::1";
1490
+ let rawBuffer;
1491
+ if (isLocalhost) {
1492
+ try {
1493
+ const { execSync } = await import('node:child_process');
1494
+ let udid;
1495
+ if (this.driver) {
1496
+ if (this.driver.sessionId != null) {
1497
+ const caps = this.driver.capabilities;
1498
+ udid = caps["appium:udid"] || caps["udid"];
1499
+ } else {
1500
+ const driver = this.driver;
1501
+ const capabilities = await driver.getCapabilities();
1502
+ udid = capabilities.get("appium:udid") || capabilities.get("udid");
1503
+ }
1496
1504
  }
1505
+ const deviceArg = udid ? `-s ${udid}` : "";
1506
+ rawBuffer = execSync(`adb ${deviceArg} exec-out screencap -p`, {
1507
+ encoding: "buffer",
1508
+ maxBuffer: 50 * 1024 * 1024
1509
+ });
1510
+ } catch (e) {
1511
+ globalLogger.warn("ADB screenshot failed, falling back to Appium screenshot");
1512
+ const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/screenshot`);
1513
+ const screenshotResponse = await axios.get(url);
1514
+ rawBuffer = Buffer.from(screenshotResponse.data.value, "base64");
1497
1515
  }
1498
- const deviceArg = udid ? `-s ${udid}` : "";
1499
- const buffer = execSync(`adb ${deviceArg} exec-out screencap -p`, {
1500
- encoding: "buffer",
1501
- maxBuffer: 50 * 1024 * 1024
1502
- });
1503
- screenshot = buffer.toString("base64");
1504
- } catch (e) {
1505
- globalLogger.warn("ADB screenshot failed, falling back to Appium screenshot");
1516
+ } else {
1506
1517
  const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/screenshot`);
1507
1518
  const screenshotResponse = await axios.get(url);
1508
- screenshot = screenshotResponse.data.value;
1519
+ rawBuffer = Buffer.from(screenshotResponse.data.value, "base64");
1509
1520
  }
1521
+ screenshot = (await sharp(rawBuffer).jpeg({ quality: 80 }).toBuffer()).toString("base64");
1510
1522
  } else {
1511
1523
  const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/screenshot`);
1512
1524
  const screenshotResponse = await axios.get(url);
@@ -1615,7 +1627,7 @@ ${"=".repeat(50)}`);
1615
1627
  const smartLoopEndTime = performance.now();
1616
1628
  globalLogger.debug(`[Performance] Smart loop completed in ${(smartLoopEndTime - smartLoopStartTime).toFixed(2)}ms`);
1617
1629
  if (!result.success) {
1618
- throw new Error(result.error || "Smart loop execution failed");
1630
+ await this.setSessionFailed();
1619
1631
  }
1620
1632
  if (result.cacheHitCount) {
1621
1633
  this._stats_cacheHits += result.cacheHitCount;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gpt-driver-node",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "main": "./dist/index.cjs",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.cts",