@midscene/ios 0.30.6-beta-20251022061949.0 → 0.30.6-beta-20251022093704.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/es/bin.mjs CHANGED
@@ -11540,24 +11540,6 @@ class PlaygroundServer {
11540
11540
  writeFileSync(tmpFile, context);
11541
11541
  return tmpFile;
11542
11542
  }
11543
- async recreateAgent() {
11544
- if (!this.pageFactory || !this.agentFactory) return void console.warn('Cannot recreate agent: factory functions not provided. Agent recreation is only available when using factory mode.');
11545
- console.log('Recreating agent to cancel current task...');
11546
- try {
11547
- if (this.agent && 'function' == typeof this.agent.destroy) await this.agent.destroy();
11548
- if (this.page && 'function' == typeof this.page.destroy) await this.page.destroy();
11549
- } catch (error) {
11550
- console.warn('Failed to destroy old agent/page:', error);
11551
- }
11552
- try {
11553
- this.page = await this.pageFactory();
11554
- this.agent = this.agentFactory(this.page);
11555
- console.log('Agent recreated successfully');
11556
- } catch (error) {
11557
- console.error('Failed to recreate agent:', error);
11558
- throw error;
11559
- }
11560
- }
11561
11543
  setupRoutes() {
11562
11544
  this._app.get('/status', async (req, res)=>{
11563
11545
  res.send({
@@ -11634,12 +11616,7 @@ class PlaygroundServer {
11634
11616
  if (!type) return res.status(400).json({
11635
11617
  error: 'type is required'
11636
11618
  });
11637
- if (this.currentTaskId) return res.status(409).json({
11638
- error: 'Another task is already running',
11639
- currentTaskId: this.currentTaskId
11640
- });
11641
11619
  if (requestId) {
11642
- this.currentTaskId = requestId;
11643
11620
  this.taskProgressTips[requestId] = '';
11644
11621
  this.agent.onTaskStartTip = (tip)=>{
11645
11622
  this.taskProgressTips[requestId] = tip;
@@ -11681,10 +11658,7 @@ class PlaygroundServer {
11681
11658
  const timeCost = Date.now() - startTime;
11682
11659
  if (response.error) console.error(`handle request failed after ${timeCost}ms: requestId: ${requestId}, ${response.error}`);
11683
11660
  else console.log(`handle request done after ${timeCost}ms: requestId: ${requestId}`);
11684
- if (requestId) {
11685
- delete this.taskProgressTips[requestId];
11686
- if (this.currentTaskId === requestId) this.currentTaskId = null;
11687
- }
11661
+ if (requestId) delete this.taskProgressTips[requestId];
11688
11662
  });
11689
11663
  this._app.post('/cancel/:requestId', async (req, res)=>{
11690
11664
  const { requestId } = req.params;
@@ -11692,17 +11666,9 @@ class PlaygroundServer {
11692
11666
  error: 'requestId is required'
11693
11667
  });
11694
11668
  try {
11695
- if (this.currentTaskId !== requestId) return res.json({
11696
- status: 'not_found',
11697
- message: 'Task not found or already completed'
11698
- });
11699
- console.log(`Cancelling task: ${requestId}`);
11700
- await this.recreateAgent();
11701
- delete this.taskProgressTips[requestId];
11702
- this.currentTaskId = null;
11669
+ if (this.taskProgressTips[requestId]) delete this.taskProgressTips[requestId];
11703
11670
  res.json({
11704
- status: 'cancelled',
11705
- message: 'Task cancelled successfully by recreating agent'
11671
+ status: 'cancelled'
11706
11672
  });
11707
11673
  } catch (error) {
11708
11674
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
@@ -11802,12 +11768,6 @@ class PlaygroundServer {
11802
11768
  }
11803
11769
  }
11804
11770
  async launch(port) {
11805
- if (this.pageFactory && this.agentFactory) {
11806
- console.log('Initializing page and agent from factory functions...');
11807
- this.page = await this.pageFactory();
11808
- this.agent = this.agentFactory(this.page);
11809
- console.log('Page and agent initialized successfully');
11810
- }
11811
11771
  this.initializeApp();
11812
11772
  this.port = port || defaultPort;
11813
11773
  return new Promise((resolve)=>{
@@ -11847,28 +11807,13 @@ class PlaygroundServer {
11847
11807
  _define_property(this, "taskProgressTips", void 0);
11848
11808
  _define_property(this, "id", void 0);
11849
11809
  _define_property(this, "_initialized", false);
11850
- _define_property(this, "pageFactory", void 0);
11851
- _define_property(this, "agentFactory", void 0);
11852
- _define_property(this, "currentTaskId", null);
11853
11810
  this._app = express_default()();
11854
11811
  this.tmpDir = getTmpDir();
11812
+ this.page = page;
11813
+ this.agent = agent;
11855
11814
  this.staticPath = staticPath;
11856
11815
  this.taskProgressTips = {};
11857
11816
  this.id = id || utils_uuid();
11858
- if ('function' == typeof page) {
11859
- this.pageFactory = page;
11860
- this.page = null;
11861
- } else {
11862
- this.page = page;
11863
- this.pageFactory = null;
11864
- }
11865
- if ('function' == typeof agent) {
11866
- this.agentFactory = agent;
11867
- this.agent = null;
11868
- } else {
11869
- this.agent = agent;
11870
- this.agentFactory = null;
11871
- }
11872
11817
  }
11873
11818
  }
11874
11819
  __webpack_require__("../../node_modules/.pnpm/cors@2.8.5/node_modules/cors/lib/index.js");
@@ -12771,14 +12716,17 @@ const main = async ()=>{
12771
12716
  host: 'localhost',
12772
12717
  port: DEFAULT_WDA_PORT
12773
12718
  };
12719
+ let device;
12720
+ let agent;
12774
12721
  let connected = false;
12775
12722
  while(!connected)try {
12776
- const device = new device_IOSDevice({
12723
+ device = new device_IOSDevice({
12777
12724
  wdaHost: wdaConfig.host,
12778
12725
  wdaPort: wdaConfig.port
12779
12726
  });
12780
12727
  console.log(`\u{1F50C} Connecting to WebDriverAgent at ${wdaConfig.host}:${wdaConfig.port}...`);
12781
12728
  await device.connect();
12729
+ agent = new IOSAgent(device);
12782
12730
  connected = true;
12783
12731
  const deviceInfo = await device.getConnectedDeviceInfo();
12784
12732
  console.log("\u2705 Connected to WebDriverAgent successfully!");
@@ -12830,16 +12778,7 @@ const main = async ()=>{
12830
12778
  `);
12831
12779
  else if ('configure' === action) wdaConfig = await configureWebDriverAgent();
12832
12780
  }
12833
- const deviceFactory = async ()=>{
12834
- const newDevice = new device_IOSDevice({
12835
- wdaHost: wdaConfig.host,
12836
- wdaPort: wdaConfig.port
12837
- });
12838
- await newDevice.connect();
12839
- return newDevice;
12840
- };
12841
- const agentFactory = (device)=>new IOSAgent(device);
12842
- const playgroundServer = new PlaygroundServer(deviceFactory, agentFactory, staticDir);
12781
+ const playgroundServer = new PlaygroundServer(device, agent, staticDir);
12843
12782
  console.log("\uD83D\uDE80 Starting server...");
12844
12783
  const availablePlaygroundPort = await findAvailablePort(constants_PLAYGROUND_SERVER_PORT);
12845
12784
  if (availablePlaygroundPort !== constants_PLAYGROUND_SERVER_PORT) console.log(`\u{26A0}\u{FE0F} Port ${constants_PLAYGROUND_SERVER_PORT} is busy, using port ${availablePlaygroundPort} instead`);
package/dist/lib/bin.js CHANGED
@@ -11669,24 +11669,6 @@ var __webpack_exports__ = {};
11669
11669
  (0, external_node_fs_namespaceObject.writeFileSync)(tmpFile, context);
11670
11670
  return tmpFile;
11671
11671
  }
11672
- async recreateAgent() {
11673
- if (!this.pageFactory || !this.agentFactory) return void console.warn('Cannot recreate agent: factory functions not provided. Agent recreation is only available when using factory mode.');
11674
- console.log('Recreating agent to cancel current task...');
11675
- try {
11676
- if (this.agent && 'function' == typeof this.agent.destroy) await this.agent.destroy();
11677
- if (this.page && 'function' == typeof this.page.destroy) await this.page.destroy();
11678
- } catch (error) {
11679
- console.warn('Failed to destroy old agent/page:', error);
11680
- }
11681
- try {
11682
- this.page = await this.pageFactory();
11683
- this.agent = this.agentFactory(this.page);
11684
- console.log('Agent recreated successfully');
11685
- } catch (error) {
11686
- console.error('Failed to recreate agent:', error);
11687
- throw error;
11688
- }
11689
- }
11690
11672
  setupRoutes() {
11691
11673
  this._app.get('/status', async (req, res)=>{
11692
11674
  res.send({
@@ -11763,12 +11745,7 @@ var __webpack_exports__ = {};
11763
11745
  if (!type) return res.status(400).json({
11764
11746
  error: 'type is required'
11765
11747
  });
11766
- if (this.currentTaskId) return res.status(409).json({
11767
- error: 'Another task is already running',
11768
- currentTaskId: this.currentTaskId
11769
- });
11770
11748
  if (requestId) {
11771
- this.currentTaskId = requestId;
11772
11749
  this.taskProgressTips[requestId] = '';
11773
11750
  this.agent.onTaskStartTip = (tip)=>{
11774
11751
  this.taskProgressTips[requestId] = tip;
@@ -11810,10 +11787,7 @@ var __webpack_exports__ = {};
11810
11787
  const timeCost = Date.now() - startTime;
11811
11788
  if (response.error) console.error(`handle request failed after ${timeCost}ms: requestId: ${requestId}, ${response.error}`);
11812
11789
  else console.log(`handle request done after ${timeCost}ms: requestId: ${requestId}`);
11813
- if (requestId) {
11814
- delete this.taskProgressTips[requestId];
11815
- if (this.currentTaskId === requestId) this.currentTaskId = null;
11816
- }
11790
+ if (requestId) delete this.taskProgressTips[requestId];
11817
11791
  });
11818
11792
  this._app.post('/cancel/:requestId', async (req, res)=>{
11819
11793
  const { requestId } = req.params;
@@ -11821,17 +11795,9 @@ var __webpack_exports__ = {};
11821
11795
  error: 'requestId is required'
11822
11796
  });
11823
11797
  try {
11824
- if (this.currentTaskId !== requestId) return res.json({
11825
- status: 'not_found',
11826
- message: 'Task not found or already completed'
11827
- });
11828
- console.log(`Cancelling task: ${requestId}`);
11829
- await this.recreateAgent();
11830
- delete this.taskProgressTips[requestId];
11831
- this.currentTaskId = null;
11798
+ if (this.taskProgressTips[requestId]) delete this.taskProgressTips[requestId];
11832
11799
  res.json({
11833
- status: 'cancelled',
11834
- message: 'Task cancelled successfully by recreating agent'
11800
+ status: 'cancelled'
11835
11801
  });
11836
11802
  } catch (error) {
11837
11803
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
@@ -11931,12 +11897,6 @@ var __webpack_exports__ = {};
11931
11897
  }
11932
11898
  }
11933
11899
  async launch(port) {
11934
- if (this.pageFactory && this.agentFactory) {
11935
- console.log('Initializing page and agent from factory functions...');
11936
- this.page = await this.pageFactory();
11937
- this.agent = this.agentFactory(this.page);
11938
- console.log('Page and agent initialized successfully');
11939
- }
11940
11900
  this.initializeApp();
11941
11901
  this.port = port || defaultPort;
11942
11902
  return new Promise((resolve)=>{
@@ -11976,28 +11936,13 @@ var __webpack_exports__ = {};
11976
11936
  _define_property(this, "taskProgressTips", void 0);
11977
11937
  _define_property(this, "id", void 0);
11978
11938
  _define_property(this, "_initialized", false);
11979
- _define_property(this, "pageFactory", void 0);
11980
- _define_property(this, "agentFactory", void 0);
11981
- _define_property(this, "currentTaskId", null);
11982
11939
  this._app = express_default()();
11983
11940
  this.tmpDir = (0, utils_namespaceObject.getTmpDir)();
11941
+ this.page = page;
11942
+ this.agent = agent;
11984
11943
  this.staticPath = staticPath;
11985
11944
  this.taskProgressTips = {};
11986
11945
  this.id = id || (0, shared_utils_namespaceObject.uuid)();
11987
- if ('function' == typeof page) {
11988
- this.pageFactory = page;
11989
- this.page = null;
11990
- } else {
11991
- this.page = page;
11992
- this.pageFactory = null;
11993
- }
11994
- if ('function' == typeof agent) {
11995
- this.agentFactory = agent;
11996
- this.agent = null;
11997
- } else {
11998
- this.agent = agent;
11999
- this.agentFactory = null;
12000
- }
12001
11946
  }
12002
11947
  }
12003
11948
  const external_node_child_process_namespaceObject = require("node:child_process");
@@ -12911,14 +12856,17 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
12911
12856
  host: 'localhost',
12912
12857
  port: constants_namespaceObject.DEFAULT_WDA_PORT
12913
12858
  };
12859
+ let device;
12860
+ let agent;
12914
12861
  let connected = false;
12915
12862
  while(!connected)try {
12916
- const device = new device_IOSDevice({
12863
+ device = new device_IOSDevice({
12917
12864
  wdaHost: wdaConfig.host,
12918
12865
  wdaPort: wdaConfig.port
12919
12866
  });
12920
12867
  console.log(`\u{1F50C} Connecting to WebDriverAgent at ${wdaConfig.host}:${wdaConfig.port}...`);
12921
12868
  await device.connect();
12869
+ agent = new IOSAgent(device);
12922
12870
  connected = true;
12923
12871
  const deviceInfo = await device.getConnectedDeviceInfo();
12924
12872
  console.log("\u2705 Connected to WebDriverAgent successfully!");
@@ -12970,16 +12918,7 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
12970
12918
  `);
12971
12919
  else if ('configure' === action) wdaConfig = await configureWebDriverAgent();
12972
12920
  }
12973
- const deviceFactory = async ()=>{
12974
- const newDevice = new device_IOSDevice({
12975
- wdaHost: wdaConfig.host,
12976
- wdaPort: wdaConfig.port
12977
- });
12978
- await newDevice.connect();
12979
- return newDevice;
12980
- };
12981
- const agentFactory = (device)=>new IOSAgent(device);
12982
- const playgroundServer = new PlaygroundServer(deviceFactory, agentFactory, staticDir);
12921
+ const playgroundServer = new PlaygroundServer(device, agent, staticDir);
12983
12922
  console.log("\uD83D\uDE80 Starting server...");
12984
12923
  const availablePlaygroundPort = await findAvailablePort(constants_namespaceObject.PLAYGROUND_SERVER_PORT);
12985
12924
  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`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/ios",
3
- "version": "0.30.6-beta-20251022061949.0",
3
+ "version": "0.30.6-beta-20251022093704.0",
4
4
  "description": "iOS automation library for Midscene",
5
5
  "keywords": [
6
6
  "iOS UI automation",
@@ -38,9 +38,9 @@
38
38
  "dependencies": {
39
39
  "@inquirer/prompts": "^7.8.6",
40
40
  "open": "10.1.0",
41
- "@midscene/shared": "0.30.6-beta-20251022061949.0",
42
- "@midscene/core": "0.30.6-beta-20251022061949.0",
43
- "@midscene/webdriver": "0.30.6-beta-20251022061949.0"
41
+ "@midscene/webdriver": "0.30.6-beta-20251022093704.0",
42
+ "@midscene/shared": "0.30.6-beta-20251022093704.0",
43
+ "@midscene/core": "0.30.6-beta-20251022093704.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@rslib/core": "^0.11.2",
@@ -49,7 +49,7 @@
49
49
  "typescript": "^5.8.3",
50
50
  "tsx": "^4.19.2",
51
51
  "vitest": "3.0.5",
52
- "@midscene/playground": "0.30.6-beta-20251022061949.0"
52
+ "@midscene/playground": "0.30.6-beta-20251022093704.0"
53
53
  },
54
54
  "license": "MIT",
55
55
  "scripts": {
package/static/index.html CHANGED
@@ -1 +1 @@
1
- <!doctype html><html><head><link rel="icon" href="/favicon.ico"><title>Midscene Playground</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><script defer src="/static/js/lib-react.f566a9ed.js"></script><script defer src="/static/js/657.5a5fe47b.js"></script><script defer src="/static/js/index.5c3c93e4.js"></script><link href="/static/css/index.44466eb4.css" rel="stylesheet"></head><body><div id="root"></div></body></html>
1
+ <!doctype html><html><head><link rel="icon" href="/favicon.ico"><title>Midscene Playground</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><script defer src="/static/js/lib-react.f566a9ed.js"></script><script defer src="/static/js/657.5a5fe47b.js"></script><script defer src="/static/js/index.914766d3.js"></script><link href="/static/css/index.44466eb4.css" rel="stylesheet"></head><body><div id="root"></div></body></html>