@midscene/ios 1.0.1-beta-20251202112442.0 → 1.0.1-beta-20251202152706.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/dist/lib/bin.js CHANGED
@@ -11421,18 +11421,6 @@ object-assign
11421
11421
  "use strict";
11422
11422
  module.exports = require("zlib");
11423
11423
  },
11424
- "@midscene/shared/img": function(module) {
11425
- "use strict";
11426
- module.exports = import("@midscene/shared/img").then(function(module) {
11427
- return module;
11428
- });
11429
- },
11430
- open: function(module) {
11431
- "use strict";
11432
- module.exports = import("open").then(function(module) {
11433
- return module;
11434
- });
11435
- },
11436
11424
  "../../node_modules/.pnpm/dotenv@16.4.5/node_modules/dotenv/package.json": function(module) {
11437
11425
  "use strict";
11438
11426
  module.exports = JSON.parse('{"name":"dotenv","version":"16.4.5","description":"Loads environment variables from .env file","main":"lib/main.js","types":"lib/main.d.ts","exports":{".":{"types":"./lib/main.d.ts","require":"./lib/main.js","default":"./lib/main.js"},"./config":"./config.js","./config.js":"./config.js","./lib/env-options":"./lib/env-options.js","./lib/env-options.js":"./lib/env-options.js","./lib/cli-options":"./lib/cli-options.js","./lib/cli-options.js":"./lib/cli-options.js","./package.json":"./package.json"},"scripts":{"dts-check":"tsc --project tests/types/tsconfig.json","lint":"standard","lint-readme":"standard-markdown","pretest":"npm run lint && npm run dts-check","test":"tap tests/*.js --100 -Rspec","test:coverage":"tap --coverage-report=lcov","prerelease":"npm test","release":"standard-version"},"repository":{"type":"git","url":"git://github.com/motdotla/dotenv.git"},"funding":"https://dotenvx.com","keywords":["dotenv","env",".env","environment","variables","config","settings"],"readmeFilename":"README.md","license":"BSD-2-Clause","devDependencies":{"@definitelytyped/dtslint":"^0.0.133","@types/node":"^18.11.3","decache":"^4.6.1","sinon":"^14.0.1","standard":"^17.0.0","standard-markdown":"^7.1.0","standard-version":"^9.5.0","tap":"^16.3.0","tar":"^6.1.11","typescript":"^4.8.4"},"engines":{"node":">=12"},"browser":{"fs":false}}');
@@ -11547,13 +11535,13 @@ var __webpack_exports__ = {};
11547
11535
  ...validationAPIs
11548
11536
  ];
11549
11537
  const formatErrorMessage = (e)=>{
11550
- const errorMessage = (null == e ? void 0 : e.message) || '';
11538
+ const errorMessage = e?.message || '';
11551
11539
  if (errorMessage.includes('of different extension')) return 'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://midscenejs.com/quick-experience.html#faq';
11552
11540
  if (errorMessage.includes('NOT_IMPLEMENTED_AS_DESIGNED')) return 'Further actions cannot be performed in the current environment';
11553
11541
  return errorMessage || 'Unknown error';
11554
11542
  };
11555
11543
  async function parseStructuredParams(action, params, options = {}) {
11556
- if (!(null == action ? void 0 : action.paramSchema) || !('shape' in action.paramSchema)) return [
11544
+ if (!action?.paramSchema || !('shape' in action.paramSchema)) return [
11557
11545
  params.prompt || '',
11558
11546
  options
11559
11547
  ];
@@ -11585,7 +11573,7 @@ var __webpack_exports__ = {};
11585
11573
  ];
11586
11574
  }
11587
11575
  async function executeAction(activeAgent, actionType, actionSpace, value, options) {
11588
- const action = null == actionSpace ? void 0 : actionSpace.find((a)=>a.interfaceAlias === actionType || a.name === actionType);
11576
+ const action = actionSpace?.find((a)=>a.interfaceAlias === actionType || a.name === actionType);
11589
11577
  if (action && 'function' == typeof activeAgent.callActionInActionSpace) if (value.params) {
11590
11578
  const parsedParams = await parseStructuredParams(action, value.params, options);
11591
11579
  return await activeAgent.callActionInActionSpace(action.name, parsedParams[0]);
@@ -11605,11 +11593,10 @@ var __webpack_exports__ = {};
11605
11593
  {
11606
11594
  const prompt = value.prompt;
11607
11595
  if ('aiAssert' === actionType) {
11608
- var _activeAgent_aiAssert;
11609
- const { pass, thought } = await (null == activeAgent ? void 0 : null == (_activeAgent_aiAssert = activeAgent.aiAssert) ? void 0 : _activeAgent_aiAssert.call(activeAgent, prompt || '', void 0, {
11596
+ const { pass, thought } = await activeAgent?.aiAssert?.(prompt || '', void 0, {
11610
11597
  keepRawResponse: true,
11611
11598
  ...options
11612
- })) || {};
11599
+ }) || {};
11613
11600
  return {
11614
11601
  pass: pass || false,
11615
11602
  thought: thought || ''
@@ -11626,7 +11613,6 @@ var __webpack_exports__ = {};
11626
11613
  const env_namespaceObject = require("@midscene/shared/env");
11627
11614
  const shared_utils_namespaceObject = require("@midscene/shared/utils");
11628
11615
  var express = __webpack_require__("../../node_modules/.pnpm/express@4.21.2/node_modules/express/index.js");
11629
- var express_default = /*#__PURE__*/ __webpack_require__.n(express);
11630
11616
  __webpack_require__("../../node_modules/.pnpm/dotenv@16.4.5/node_modules/dotenv/config.js");
11631
11617
  function _define_property(obj, key, value) {
11632
11618
  if (key in obj) Object.defineProperty(obj, key, {
@@ -11655,7 +11641,7 @@ var __webpack_exports__ = {};
11655
11641
  }
11656
11642
  initializeApp() {
11657
11643
  if (this._initialized) return;
11658
- this._app.use(express_default().json({
11644
+ this._app.use(express.json({
11659
11645
  limit: '50mb'
11660
11646
  }));
11661
11647
  this._app.use((req, _res, next)=>{
@@ -11875,9 +11861,8 @@ var __webpack_exports__ = {};
11875
11861
  });
11876
11862
  this._app.get('/interface-info', async (_req, res)=>{
11877
11863
  try {
11878
- var _this_agent_interface_describe, _this_agent_interface;
11879
11864
  const type = this.agent.interface.interfaceType || 'Unknown';
11880
- const description = (null == (_this_agent_interface_describe = (_this_agent_interface = this.agent.interface).describe) ? void 0 : _this_agent_interface_describe.call(_this_agent_interface)) || void 0;
11865
+ const description = this.agent.interface.describe?.() || void 0;
11881
11866
  res.json({
11882
11867
  type,
11883
11868
  description
@@ -11921,7 +11906,7 @@ var __webpack_exports__ = {};
11921
11906
  this._app.get('/index.html', (_req, res)=>{
11922
11907
  this.serveHtmlWithPorts(res);
11923
11908
  });
11924
- this._app.use(express_default()["static"](this.staticPath));
11909
+ this._app.use(express["static"](this.staticPath));
11925
11910
  this._app.get('*', (_req, res)=>{
11926
11911
  this.serveHtmlWithPorts(res);
11927
11912
  });
@@ -11990,7 +11975,7 @@ var __webpack_exports__ = {};
11990
11975
  _define_property(this, "_initialized", false);
11991
11976
  _define_property(this, "agentFactory", void 0);
11992
11977
  _define_property(this, "currentTaskId", null);
11993
- this._app = express_default()();
11978
+ this._app = express();
11994
11979
  this.tmpDir = (0, utils_namespaceObject.getTmpDir)();
11995
11980
  this.staticPath = staticPath;
11996
11981
  this.taskProgressTips = {};
@@ -12157,9 +12142,8 @@ var __webpack_exports__ = {};
12157
12142
  this.ensureSession();
12158
12143
  debugIOS('Getting active element');
12159
12144
  try {
12160
- var _response_value, _response_value1;
12161
12145
  const response = await this.makeRequest('GET', `/session/${this.sessionId}/element/active`);
12162
- const elementId = (null == (_response_value = response.value) ? void 0 : _response_value.ELEMENT) || (null == (_response_value1 = response.value) ? void 0 : _response_value1['element-6066-11e4-a52e-4f735466cecf']) || response.ELEMENT || response['element-6066-11e4-a52e-4f735466cecf'];
12146
+ const elementId = response.value?.ELEMENT || response.value?.['element-6066-11e4-a52e-4f735466cecf'] || response.ELEMENT || response['element-6066-11e4-a52e-4f735466cecf'];
12163
12147
  if (elementId) {
12164
12148
  debugIOS(`Got active element ID: ${elementId}`);
12165
12149
  return elementId;
@@ -12321,9 +12305,8 @@ var __webpack_exports__ = {};
12321
12305
  async getScreenScale() {
12322
12306
  this.ensureSession();
12323
12307
  try {
12324
- var _screenResponse_value;
12325
12308
  const screenResponse = await this.makeRequest('GET', `/session/${this.sessionId}/wda/screen`);
12326
- if (null == screenResponse ? void 0 : null == (_screenResponse_value = screenResponse.value) ? void 0 : _screenResponse_value.scale) {
12309
+ if (screenResponse?.value?.scale) {
12327
12310
  debugIOS(`Got screen scale from WDA screen endpoint: ${screenResponse.value.scale}`);
12328
12311
  return screenResponse.value.scale;
12329
12312
  }
@@ -12336,7 +12319,7 @@ var __webpack_exports__ = {};
12336
12319
  this.takeScreenshot(),
12337
12320
  this.getWindowSize()
12338
12321
  ]);
12339
- const { jimpFromBase64 } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@midscene/shared/img"));
12322
+ const { jimpFromBase64 } = await import("@midscene/shared/img");
12340
12323
  const screenshotImg = await jimpFromBase64(screenshotBase64);
12341
12324
  const screenshotWidth = screenshotImg.bitmap.width;
12342
12325
  const screenshotHeight = screenshotImg.bitmap.height;
@@ -12424,14 +12407,13 @@ var __webpack_exports__ = {};
12424
12407
  locate: (0, core_namespaceObject.getMidsceneLocationSchema)().describe('The input field to be filled').optional()
12425
12408
  }),
12426
12409
  call: async (param)=>{
12427
- var _this_options;
12428
12410
  const element = param.locate;
12429
12411
  if (element) {
12430
12412
  if ('append' !== param.mode) await this.clearInput(element);
12431
12413
  }
12432
12414
  if ('clear' === param.mode) return;
12433
12415
  if (!param || !param.value) return;
12434
- const autoDismissKeyboard = param.autoDismissKeyboard ?? (null == (_this_options = this.options) ? void 0 : _this_options.autoDismissKeyboard);
12416
+ const autoDismissKeyboard = param.autoDismissKeyboard ?? this.options?.autoDismissKeyboard;
12435
12417
  await this.typeText(param.value, {
12436
12418
  autoDismissKeyboard
12437
12419
  });
@@ -12443,18 +12425,18 @@ var __webpack_exports__ = {};
12443
12425
  left: element.center[0],
12444
12426
  top: element.center[1]
12445
12427
  } : void 0;
12446
- const scrollToEventName = null == param ? void 0 : param.scrollType;
12428
+ const scrollToEventName = param?.scrollType;
12447
12429
  if ('scrollToTop' === scrollToEventName) await this.scrollUntilTop(startingPoint);
12448
12430
  else if ('scrollToBottom' === scrollToEventName) await this.scrollUntilBottom(startingPoint);
12449
12431
  else if ('scrollToRight' === scrollToEventName) await this.scrollUntilRight(startingPoint);
12450
12432
  else if ('scrollToLeft' === scrollToEventName) await this.scrollUntilLeft(startingPoint);
12451
12433
  else if ('singleAction' !== scrollToEventName && scrollToEventName) throw new Error(`Unknown scroll event type: ${scrollToEventName}, param: ${JSON.stringify(param)}`);
12452
12434
  else {
12453
- if ((null == param ? void 0 : param.direction) !== 'down' && param && param.direction) if ('up' === param.direction) await this.scrollUp(param.distance || void 0, startingPoint);
12435
+ if (param?.direction !== 'down' && param && param.direction) if ('up' === param.direction) await this.scrollUp(param.distance || void 0, startingPoint);
12454
12436
  else if ('left' === param.direction) await this.scrollLeft(param.distance || void 0, startingPoint);
12455
12437
  else if ('right' === param.direction) await this.scrollRight(param.distance || void 0, startingPoint);
12456
12438
  else throw new Error(`Unknown scroll direction: ${param.direction}`);
12457
- else await this.scrollDown((null == param ? void 0 : param.distance) || void 0, startingPoint);
12439
+ else await this.scrollDown(param?.distance || void 0, startingPoint);
12458
12440
  await (0, utils_namespaceObject.sleep)(500);
12459
12441
  }
12460
12442
  }),
@@ -12479,7 +12461,7 @@ var __webpack_exports__ = {};
12479
12461
  const element = param.locate;
12480
12462
  external_node_assert_default()(element, 'IOSLongPress requires an element to be located');
12481
12463
  const [x, y] = element.center;
12482
- await this.longPress(x, y, null == param ? void 0 : param.duration);
12464
+ await this.longPress(x, y, param?.duration);
12483
12465
  }
12484
12466
  }),
12485
12467
  (0, device_namespaceObject.defineActionClearInput)(async (param)=>{
@@ -12509,7 +12491,7 @@ var __webpack_exports__ = {};
12509
12491
  await this.wdaManager.start();
12510
12492
  await this.wdaBackend.createSession();
12511
12493
  const deviceInfo = await this.wdaBackend.getDeviceInfo();
12512
- if (null == deviceInfo ? void 0 : deviceInfo.udid) {
12494
+ if (deviceInfo?.udid) {
12513
12495
  this.deviceId = deviceInfo.udid;
12514
12496
  debugDevice(`Updated device ID to real UDID: ${this.deviceId}`);
12515
12497
  }
@@ -12617,9 +12599,8 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
12617
12599
  await this.wdaBackend.swipe(Math.round(fromX), Math.round(fromY), Math.round(toX), Math.round(toY), duration);
12618
12600
  }
12619
12601
  async typeText(text, options) {
12620
- var _this_options;
12621
12602
  if (!text) return;
12622
- const shouldAutoDismissKeyboard = (null == options ? void 0 : options.autoDismissKeyboard) ?? (null == (_this_options = this.options) ? void 0 : _this_options.autoDismissKeyboard) ?? true;
12603
+ const shouldAutoDismissKeyboard = options?.autoDismissKeyboard ?? this.options?.autoDismissKeyboard ?? true;
12623
12604
  debugDevice(`Typing text: "${text}"`);
12624
12605
  try {
12625
12606
  await (0, utils_namespaceObject.sleep)(200);
@@ -12919,9 +12900,9 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
12919
12900
  device_define_property(this, "options", void 0);
12920
12901
  this.deviceId = 'pending-connection';
12921
12902
  this.options = options;
12922
- this.customActions = null == options ? void 0 : options.customActions;
12923
- const wdaPort = (null == options ? void 0 : options.wdaPort) || constants_namespaceObject.DEFAULT_WDA_PORT;
12924
- const wdaHost = (null == options ? void 0 : options.wdaHost) || 'localhost';
12903
+ this.customActions = options?.customActions;
12904
+ const wdaPort = options?.wdaPort || constants_namespaceObject.DEFAULT_WDA_PORT;
12905
+ const wdaHost = options?.wdaHost || 'localhost';
12925
12906
  this.wdaBackend = new IOSWebDriverClient({
12926
12907
  port: wdaPort,
12927
12908
  host: wdaHost
@@ -13011,7 +12992,7 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
13011
12992
  while(!await isPortAvailable(port)){
13012
12993
  attempts++;
13013
12994
  if (attempts >= maxAttempts) {
13014
- console.error(`\u{274C} Unable to find available port after ${maxAttempts} attempts starting from ${startPort}`);
12995
+ console.error(`❌ Unable to find available port after ${maxAttempts} attempts starting from ${startPort}`);
13015
12996
  process.exit(1);
13016
12997
  }
13017
12998
  port++;
@@ -13019,7 +13000,7 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
13019
13000
  return port;
13020
13001
  }
13021
13002
  async function configureWebDriverAgent() {
13022
- console.log("\uD83D\uDD27 WebDriverAgent Configuration");
13003
+ console.log('🔧 WebDriverAgent Configuration');
13023
13004
  console.log(`Default: localhost:${constants_namespaceObject.DEFAULT_WDA_PORT}`);
13024
13005
  const useDefault = await (0, prompts_namespaceObject.select)({
13025
13006
  message: `Use default WebDriverAgent address (localhost:${constants_namespaceObject.DEFAULT_WDA_PORT})?`,
@@ -13049,7 +13030,7 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
13049
13030
  });
13050
13031
  const port = Number.parseInt(portInput, 10);
13051
13032
  if (Number.isNaN(port) || port < 1 || port > 65535) {
13052
- console.error(`\u{274C} Invalid port number. Using default ${constants_namespaceObject.DEFAULT_WDA_PORT}.`);
13033
+ console.error(`❌ Invalid port number. Using default ${constants_namespaceObject.DEFAULT_WDA_PORT}.`);
13053
13034
  return {
13054
13035
  host,
13055
13036
  port: constants_namespaceObject.DEFAULT_WDA_PORT
@@ -13062,7 +13043,7 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
13062
13043
  }
13063
13044
  const staticDir = external_node_path_default().join(__dirname, '../../static');
13064
13045
  const main = async ()=>{
13065
- const { default: open } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "open"));
13046
+ const { default: open } = await import("open");
13066
13047
  try {
13067
13048
  let wdaConfig = {
13068
13049
  host: 'localhost',
@@ -13074,39 +13055,39 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
13074
13055
  wdaHost: wdaConfig.host,
13075
13056
  wdaPort: wdaConfig.port
13076
13057
  });
13077
- console.log(`\u{1F50C} Connecting to WebDriverAgent at ${wdaConfig.host}:${wdaConfig.port}...`);
13058
+ console.log(`🔌 Connecting to WebDriverAgent at ${wdaConfig.host}:${wdaConfig.port}...`);
13078
13059
  await device.connect();
13079
13060
  connected = true;
13080
13061
  const deviceInfo = await device.getConnectedDeviceInfo();
13081
- console.log("\u2705 Connected to WebDriverAgent successfully!");
13062
+ console.log('✅ Connected to WebDriverAgent successfully!');
13082
13063
  if (deviceInfo) {
13083
- console.log(`\u{1F4F1} Connected to: ${deviceInfo.name} (${deviceInfo.model})`);
13084
- console.log(`\u{1F511} Device UDID: ${deviceInfo.udid}`);
13064
+ console.log(`📱 Connected to: ${deviceInfo.name} (${deviceInfo.model})`);
13065
+ console.log(`🔑 Device UDID: ${deviceInfo.udid}`);
13085
13066
  }
13086
13067
  } catch (error) {
13087
- console.error(`\u{274C} Failed to connect to WebDriverAgent: ${error instanceof Error ? error.message : String(error)}`);
13068
+ console.error(`❌ Failed to connect to WebDriverAgent: ${error instanceof Error ? error.message : String(error)}`);
13088
13069
  const action = await (0, prompts_namespaceObject.select)({
13089
13070
  message: 'What would you like to do?',
13090
13071
  choices: [
13091
13072
  {
13092
- name: "\uD83D\uDD27 Configure different WebDriverAgent address",
13073
+ name: '🔧 Configure different WebDriverAgent address',
13093
13074
  value: 'configure'
13094
13075
  },
13095
13076
  {
13096
- name: "\uD83D\uDCD6 Show setup instructions",
13077
+ name: '📖 Show setup instructions',
13097
13078
  value: 'instructions'
13098
13079
  },
13099
13080
  {
13100
- name: "\uD83D\uDEAA Exit",
13081
+ name: '🚪 Exit',
13101
13082
  value: 'exit'
13102
13083
  }
13103
13084
  ]
13104
13085
  });
13105
13086
  if ('exit' === action) {
13106
- console.log("\uD83D\uDC4B Goodbye!");
13087
+ console.log('👋 Goodbye!');
13107
13088
  process.exit(0);
13108
13089
  } else if ('instructions' === action) console.log(`
13109
- \u{1F527} WebDriverAgent Setup Instructions:
13090
+ 🔧 WebDriverAgent Setup Instructions:
13110
13091
 
13111
13092
  1. Install WebDriverAgent:
13112
13093
  npm install appium-webdriveragent
@@ -13122,8 +13103,8 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
13122
13103
 
13123
13104
  6. Restart this playground to connect
13124
13105
 
13125
- \u{1F4A1} The WebDriverAgent service is already bound to the device you selected in Xcode.
13126
- \u{1F4A1} For more details, visit: https://github.com/appium/WebDriverAgent
13106
+ 💡 The WebDriverAgent service is already bound to the device you selected in Xcode.
13107
+ 💡 For more details, visit: https://github.com/appium/WebDriverAgent
13127
13108
  `);
13128
13109
  else if ('configure' === action) wdaConfig = await configureWebDriverAgent();
13129
13110
  }
@@ -13136,16 +13117,16 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
13136
13117
  return new IOSAgent(newDevice);
13137
13118
  };
13138
13119
  const playgroundServer = new PlaygroundServer(agentFactory, staticDir);
13139
- console.log("\uD83D\uDE80 Starting server...");
13120
+ console.log('🚀 Starting server...');
13140
13121
  const availablePlaygroundPort = await findAvailablePort(constants_namespaceObject.PLAYGROUND_SERVER_PORT);
13141
- if (availablePlaygroundPort !== constants_namespaceObject.PLAYGROUND_SERVER_PORT) console.log(`\u{26A0}\u{FE0F} Port ${constants_namespaceObject.PLAYGROUND_SERVER_PORT} is busy, using port ${availablePlaygroundPort} instead`);
13122
+ if (availablePlaygroundPort !== constants_namespaceObject.PLAYGROUND_SERVER_PORT) console.log(`⚠️ Port ${constants_namespaceObject.PLAYGROUND_SERVER_PORT} is busy, using port ${availablePlaygroundPort} instead`);
13142
13123
  await playgroundServer.launch(availablePlaygroundPort);
13143
13124
  console.log('');
13144
- console.log("\u2728 Midscene iOS Playground is ready!");
13145
- console.log(`\u{1F3AE} Playground: http://localhost:${playgroundServer.port}`);
13146
- console.log("\uD83D\uDCF1 Device: WebDriverAgent Connected");
13147
- console.log(`\u{1F527} WebDriverAgent: ${wdaConfig.host}:${wdaConfig.port}`);
13148
- console.log(`\u{1F511} Generated Server ID: ${playgroundServer.id}`);
13125
+ console.log('✨ Midscene iOS Playground is ready!');
13126
+ console.log(`🎮 Playground: http://localhost:${playgroundServer.port}`);
13127
+ console.log('📱 Device: WebDriverAgent Connected');
13128
+ console.log(`🔧 WebDriverAgent: ${wdaConfig.host}:${wdaConfig.port}`);
13129
+ console.log(`🔑 Generated Server ID: ${playgroundServer.id}`);
13149
13130
  console.log('');
13150
13131
  open(`http://localhost:${playgroundServer.port}`);
13151
13132
  } catch (error) {