@midscene/web 0.11.1 → 0.11.3

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.
Files changed (38) hide show
  1. package/dist/es/appium.js +85 -39
  2. package/dist/es/bridge-mode-browser.js +58 -19
  3. package/dist/es/bridge-mode.js +62 -43
  4. package/dist/es/chrome-extension.js +105 -51
  5. package/dist/es/index.js +292 -218
  6. package/dist/es/midscene-playground.js +57 -38
  7. package/dist/es/playground.js +57 -38
  8. package/dist/es/playwright-report.js +4 -0
  9. package/dist/es/playwright.js +252 -203
  10. package/dist/es/puppeteer.js +86 -60
  11. package/dist/es/ui-utils.js +43 -0
  12. package/dist/lib/appium.js +85 -39
  13. package/dist/lib/bridge-mode-browser.js +58 -19
  14. package/dist/lib/bridge-mode.js +62 -43
  15. package/dist/lib/chrome-extension.js +105 -51
  16. package/dist/lib/index.js +292 -218
  17. package/dist/lib/midscene-playground.js +57 -38
  18. package/dist/lib/playground.js +57 -38
  19. package/dist/lib/playwright-report.js +4 -0
  20. package/dist/lib/playwright.js +252 -203
  21. package/dist/lib/puppeteer.js +86 -60
  22. package/dist/lib/ui-utils.js +43 -0
  23. package/dist/types/{tasks-d5a01262.d.ts → agent-ae110e80.d.ts} +43 -43
  24. package/dist/types/appium.d.ts +3 -3
  25. package/dist/types/bridge-mode-browser.d.ts +3 -3
  26. package/dist/types/bridge-mode.d.ts +4 -4
  27. package/dist/types/{browser-7d5614fb.d.ts → browser-9d620553.d.ts} +4 -4
  28. package/dist/types/chrome-extension.d.ts +4 -4
  29. package/dist/types/index.d.ts +8 -8
  30. package/dist/types/{page-77af8d5f.d.ts → page-97720803.d.ts} +34 -8
  31. package/dist/types/playground.d.ts +4 -4
  32. package/dist/types/playwright.d.ts +13 -7
  33. package/dist/types/puppeteer.d.ts +3 -3
  34. package/dist/types/ui-utils.d.ts +6 -1
  35. package/dist/types/{utils-1a3bc661.d.ts → utils-93b3f5f3.d.ts} +1 -1
  36. package/dist/types/utils.d.ts +2 -2
  37. package/dist/types/yaml.d.ts +4 -4
  38. package/package.json +6 -6
@@ -3812,7 +3812,9 @@ var TaskCache = class {
3812
3812
  if (!this.midscenePkgInfo) {
3813
3813
  return void 0;
3814
3814
  }
3815
- if (jsonData.pkgName !== this.midscenePkgInfo.name || jsonData.pkgVersion !== this.midscenePkgInfo.version) {
3815
+ const jsonDataPkgVersion = jsonData.pkgVersion.split(".");
3816
+ const midscenePkgInfoPkgVersion = this.midscenePkgInfo.version.split(".");
3817
+ if (jsonDataPkgVersion[0] !== midscenePkgInfoPkgVersion[0] || jsonDataPkgVersion[1] !== midscenePkgInfoPkgVersion[1]) {
3816
3818
  return void 0;
3817
3819
  }
3818
3820
  return jsonData;
@@ -3846,6 +3848,56 @@ var TaskCache = class {
3846
3848
  }
3847
3849
  };
3848
3850
 
3851
+ // src/common/ui-utils.ts
3852
+ function typeStr(task) {
3853
+ return task.subType ? `${task.type} / ${task.subType || ""}` : task.type;
3854
+ }
3855
+ function getKeyCommands(value) {
3856
+ const keys = Array.isArray(value) ? value : [value];
3857
+ return keys.reduce((acc, k) => {
3858
+ const includeMeta = keys.includes("Meta") || keys.includes("Control");
3859
+ if (includeMeta && (k === "a" || k === "A")) {
3860
+ return acc.concat([{ key: k, command: "SelectAll" }]);
3861
+ }
3862
+ if (includeMeta && (k === "c" || k === "C")) {
3863
+ return acc.concat([{ key: k, command: "Copy" }]);
3864
+ }
3865
+ if (includeMeta && (k === "v" || k === "V")) {
3866
+ return acc.concat([{ key: k, command: "Paste" }]);
3867
+ }
3868
+ return acc.concat([{ key: k }]);
3869
+ }, []);
3870
+ }
3871
+ function paramStr(task) {
3872
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3873
+ let value;
3874
+ if (task.type === "Planning") {
3875
+ value = (_a = task == null ? void 0 : task.param) == null ? void 0 : _a.userPrompt;
3876
+ }
3877
+ if (task.type === "Insight") {
3878
+ value = ((_b = task == null ? void 0 : task.param) == null ? void 0 : _b.prompt) || ((_c = task == null ? void 0 : task.param) == null ? void 0 : _c.id) || ((_d = task == null ? void 0 : task.param) == null ? void 0 : _d.dataDemand) || ((_e = task == null ? void 0 : task.param) == null ? void 0 : _e.assertion);
3879
+ }
3880
+ if (task.type === "Action") {
3881
+ const sleepMs = (_f = task == null ? void 0 : task.param) == null ? void 0 : _f.timeMs;
3882
+ const scrollType = (_g = task == null ? void 0 : task.param) == null ? void 0 : _g.scrollType;
3883
+ if (sleepMs) {
3884
+ value = `${sleepMs}ms`;
3885
+ } else if (scrollType) {
3886
+ const scrollDirection = (_h = task == null ? void 0 : task.param) == null ? void 0 : _h.direction;
3887
+ const scrollDistance = (_i = task == null ? void 0 : task.param) == null ? void 0 : _i.distance;
3888
+ value = `${scrollDirection || "down"}, ${scrollType || "once"}, ${scrollDistance || "distance-not-set"}`;
3889
+ } else {
3890
+ value = ((_j = task == null ? void 0 : task.param) == null ? void 0 : _j.value) || ((_k = task == null ? void 0 : task.param) == null ? void 0 : _k.scrollType);
3891
+ }
3892
+ if (!value) {
3893
+ value = task.thought;
3894
+ }
3895
+ }
3896
+ if (typeof value === "undefined")
3897
+ return "";
3898
+ return typeof value === "string" ? value : JSON.stringify(value, void 0, 2);
3899
+ }
3900
+
3849
3901
  // src/common/tasks.ts
3850
3902
  var PageTaskExecutor = class {
3851
3903
  constructor(page, insight, opts) {
@@ -3980,6 +4032,7 @@ var PageTaskExecutor = class {
3980
4032
  output: {
3981
4033
  element
3982
4034
  },
4035
+ pageContext,
3983
4036
  log: {
3984
4037
  dump: insightDump
3985
4038
  },
@@ -4059,8 +4112,8 @@ var PageTaskExecutor = class {
4059
4112
  thought: plan2.thought,
4060
4113
  locate: plan2.locate,
4061
4114
  executor: async (taskParam) => {
4062
- (0, import_node_assert4.default)(taskParam == null ? void 0 : taskParam.value, "No key to press");
4063
- await this.page.keyboard.press(taskParam.value);
4115
+ const keys = getKeyCommands(taskParam.value);
4116
+ await this.page.keyboard.press(keys);
4064
4117
  }
4065
4118
  };
4066
4119
  tasks.push(taskActionKeyboardPress);
@@ -4468,7 +4521,7 @@ var PageTaskExecutor = class {
4468
4521
  const cacheGroup = this.taskCache.getCacheGroupByPrompt(userPrompt);
4469
4522
  const isCompleted = false;
4470
4523
  let currentActionNumber = 0;
4471
- const maxActionNumber = 20;
4524
+ const maxActionNumber = 40;
4472
4525
  while (!isCompleted && currentActionNumber < maxActionNumber) {
4473
4526
  currentActionNumber++;
4474
4527
  const planningTask = this.planningTaskToGoal(
@@ -4664,40 +4717,6 @@ var PageTaskExecutor = class {
4664
4717
  }
4665
4718
  };
4666
4719
 
4667
- // src/common/ui-utils.ts
4668
- function typeStr(task) {
4669
- return task.subType ? `${task.type} / ${task.subType || ""}` : task.type;
4670
- }
4671
- function paramStr(task) {
4672
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
4673
- let value;
4674
- if (task.type === "Planning") {
4675
- value = (_a = task == null ? void 0 : task.param) == null ? void 0 : _a.userPrompt;
4676
- }
4677
- if (task.type === "Insight") {
4678
- value = ((_b = task == null ? void 0 : task.param) == null ? void 0 : _b.prompt) || ((_c = task == null ? void 0 : task.param) == null ? void 0 : _c.id) || ((_d = task == null ? void 0 : task.param) == null ? void 0 : _d.dataDemand) || ((_e = task == null ? void 0 : task.param) == null ? void 0 : _e.assertion);
4679
- }
4680
- if (task.type === "Action") {
4681
- const sleepMs = (_f = task == null ? void 0 : task.param) == null ? void 0 : _f.timeMs;
4682
- const scrollType = (_g = task == null ? void 0 : task.param) == null ? void 0 : _g.scrollType;
4683
- if (sleepMs) {
4684
- value = `${sleepMs}ms`;
4685
- } else if (scrollType) {
4686
- const scrollDirection = (_h = task == null ? void 0 : task.param) == null ? void 0 : _h.direction;
4687
- const scrollDistance = (_i = task == null ? void 0 : task.param) == null ? void 0 : _i.distance;
4688
- value = `${scrollDirection || "down"}, ${scrollType || "once"}, ${scrollDistance || "distance-not-set"}`;
4689
- } else {
4690
- value = ((_j = task == null ? void 0 : task.param) == null ? void 0 : _j.value) || ((_k = task == null ? void 0 : task.param) == null ? void 0 : _k.scrollType);
4691
- }
4692
- if (!value) {
4693
- value = task.thought;
4694
- }
4695
- }
4696
- if (typeof value === "undefined")
4697
- return "";
4698
- return typeof value === "string" ? value : JSON.stringify(value, void 0, 2);
4699
- }
4700
-
4701
4720
  // src/common/agent.ts
4702
4721
  var PageAgent = class {
4703
4722
  constructor(page, opts) {
@@ -3475,7 +3475,9 @@ var TaskCache = class {
3475
3475
  if (!this.midscenePkgInfo) {
3476
3476
  return void 0;
3477
3477
  }
3478
- if (jsonData.pkgName !== this.midscenePkgInfo.name || jsonData.pkgVersion !== this.midscenePkgInfo.version) {
3478
+ const jsonDataPkgVersion = jsonData.pkgVersion.split(".");
3479
+ const midscenePkgInfoPkgVersion = this.midscenePkgInfo.version.split(".");
3480
+ if (jsonDataPkgVersion[0] !== midscenePkgInfoPkgVersion[0] || jsonDataPkgVersion[1] !== midscenePkgInfoPkgVersion[1]) {
3479
3481
  return void 0;
3480
3482
  }
3481
3483
  return jsonData;
@@ -3509,6 +3511,56 @@ var TaskCache = class {
3509
3511
  }
3510
3512
  };
3511
3513
 
3514
+ // src/common/ui-utils.ts
3515
+ function typeStr(task) {
3516
+ return task.subType ? `${task.type} / ${task.subType || ""}` : task.type;
3517
+ }
3518
+ function getKeyCommands(value) {
3519
+ const keys = Array.isArray(value) ? value : [value];
3520
+ return keys.reduce((acc, k) => {
3521
+ const includeMeta = keys.includes("Meta") || keys.includes("Control");
3522
+ if (includeMeta && (k === "a" || k === "A")) {
3523
+ return acc.concat([{ key: k, command: "SelectAll" }]);
3524
+ }
3525
+ if (includeMeta && (k === "c" || k === "C")) {
3526
+ return acc.concat([{ key: k, command: "Copy" }]);
3527
+ }
3528
+ if (includeMeta && (k === "v" || k === "V")) {
3529
+ return acc.concat([{ key: k, command: "Paste" }]);
3530
+ }
3531
+ return acc.concat([{ key: k }]);
3532
+ }, []);
3533
+ }
3534
+ function paramStr(task) {
3535
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3536
+ let value;
3537
+ if (task.type === "Planning") {
3538
+ value = (_a = task == null ? void 0 : task.param) == null ? void 0 : _a.userPrompt;
3539
+ }
3540
+ if (task.type === "Insight") {
3541
+ value = ((_b = task == null ? void 0 : task.param) == null ? void 0 : _b.prompt) || ((_c = task == null ? void 0 : task.param) == null ? void 0 : _c.id) || ((_d = task == null ? void 0 : task.param) == null ? void 0 : _d.dataDemand) || ((_e = task == null ? void 0 : task.param) == null ? void 0 : _e.assertion);
3542
+ }
3543
+ if (task.type === "Action") {
3544
+ const sleepMs = (_f = task == null ? void 0 : task.param) == null ? void 0 : _f.timeMs;
3545
+ const scrollType = (_g = task == null ? void 0 : task.param) == null ? void 0 : _g.scrollType;
3546
+ if (sleepMs) {
3547
+ value = `${sleepMs}ms`;
3548
+ } else if (scrollType) {
3549
+ const scrollDirection = (_h = task == null ? void 0 : task.param) == null ? void 0 : _h.direction;
3550
+ const scrollDistance = (_i = task == null ? void 0 : task.param) == null ? void 0 : _i.distance;
3551
+ value = `${scrollDirection || "down"}, ${scrollType || "once"}, ${scrollDistance || "distance-not-set"}`;
3552
+ } else {
3553
+ value = ((_j = task == null ? void 0 : task.param) == null ? void 0 : _j.value) || ((_k = task == null ? void 0 : task.param) == null ? void 0 : _k.scrollType);
3554
+ }
3555
+ if (!value) {
3556
+ value = task.thought;
3557
+ }
3558
+ }
3559
+ if (typeof value === "undefined")
3560
+ return "";
3561
+ return typeof value === "string" ? value : JSON.stringify(value, void 0, 2);
3562
+ }
3563
+
3512
3564
  // src/common/tasks.ts
3513
3565
  var PageTaskExecutor = class {
3514
3566
  constructor(page, insight, opts) {
@@ -3643,6 +3695,7 @@ var PageTaskExecutor = class {
3643
3695
  output: {
3644
3696
  element
3645
3697
  },
3698
+ pageContext,
3646
3699
  log: {
3647
3700
  dump: insightDump
3648
3701
  },
@@ -3722,8 +3775,8 @@ var PageTaskExecutor = class {
3722
3775
  thought: plan2.thought,
3723
3776
  locate: plan2.locate,
3724
3777
  executor: async (taskParam) => {
3725
- (0, import_node_assert4.default)(taskParam == null ? void 0 : taskParam.value, "No key to press");
3726
- await this.page.keyboard.press(taskParam.value);
3778
+ const keys = getKeyCommands(taskParam.value);
3779
+ await this.page.keyboard.press(keys);
3727
3780
  }
3728
3781
  };
3729
3782
  tasks.push(taskActionKeyboardPress);
@@ -4131,7 +4184,7 @@ var PageTaskExecutor = class {
4131
4184
  const cacheGroup = this.taskCache.getCacheGroupByPrompt(userPrompt);
4132
4185
  const isCompleted = false;
4133
4186
  let currentActionNumber = 0;
4134
- const maxActionNumber = 20;
4187
+ const maxActionNumber = 40;
4135
4188
  while (!isCompleted && currentActionNumber < maxActionNumber) {
4136
4189
  currentActionNumber++;
4137
4190
  const planningTask = this.planningTaskToGoal(
@@ -4327,40 +4380,6 @@ var PageTaskExecutor = class {
4327
4380
  }
4328
4381
  };
4329
4382
 
4330
- // src/common/ui-utils.ts
4331
- function typeStr(task) {
4332
- return task.subType ? `${task.type} / ${task.subType || ""}` : task.type;
4333
- }
4334
- function paramStr(task) {
4335
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
4336
- let value;
4337
- if (task.type === "Planning") {
4338
- value = (_a = task == null ? void 0 : task.param) == null ? void 0 : _a.userPrompt;
4339
- }
4340
- if (task.type === "Insight") {
4341
- value = ((_b = task == null ? void 0 : task.param) == null ? void 0 : _b.prompt) || ((_c = task == null ? void 0 : task.param) == null ? void 0 : _c.id) || ((_d = task == null ? void 0 : task.param) == null ? void 0 : _d.dataDemand) || ((_e = task == null ? void 0 : task.param) == null ? void 0 : _e.assertion);
4342
- }
4343
- if (task.type === "Action") {
4344
- const sleepMs = (_f = task == null ? void 0 : task.param) == null ? void 0 : _f.timeMs;
4345
- const scrollType = (_g = task == null ? void 0 : task.param) == null ? void 0 : _g.scrollType;
4346
- if (sleepMs) {
4347
- value = `${sleepMs}ms`;
4348
- } else if (scrollType) {
4349
- const scrollDirection = (_h = task == null ? void 0 : task.param) == null ? void 0 : _h.direction;
4350
- const scrollDistance = (_i = task == null ? void 0 : task.param) == null ? void 0 : _i.distance;
4351
- value = `${scrollDirection || "down"}, ${scrollType || "once"}, ${scrollDistance || "distance-not-set"}`;
4352
- } else {
4353
- value = ((_j = task == null ? void 0 : task.param) == null ? void 0 : _j.value) || ((_k = task == null ? void 0 : task.param) == null ? void 0 : _k.scrollType);
4354
- }
4355
- if (!value) {
4356
- value = task.thought;
4357
- }
4358
- }
4359
- if (typeof value === "undefined")
4360
- return "";
4361
- return typeof value === "string" ? value : JSON.stringify(value, void 0, 2);
4362
- }
4363
-
4364
4383
  // src/common/agent.ts
4365
4384
  var PageAgent = class {
4366
4385
  constructor(page, opts) {
@@ -383,11 +383,15 @@ var MidsceneReporter = class {
383
383
  testDataList.push({
384
384
  dumpString: dumpAnnotation.description,
385
385
  attributes: {
386
+ playwright_test_id: test.id,
386
387
  playwright_test_title: test.title,
387
388
  playwright_test_status: result.status,
388
389
  playwright_test_duration: result.duration
389
390
  }
390
391
  });
392
+ test.annotations = test.annotations.filter(
393
+ (annotation) => annotation.type !== "MIDSCENE_DUMP_ANNOTATION"
394
+ );
391
395
  updateReport();
392
396
  }
393
397
  onEnd(result) {