@midscene/web 0.16.4 → 0.16.6

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 (46) hide show
  1. package/dist/es/agent.js +78 -14
  2. package/dist/es/agent.js.map +1 -1
  3. package/dist/es/bridge-mode-browser.js +3 -3
  4. package/dist/es/bridge-mode-browser.js.map +1 -1
  5. package/dist/es/bridge-mode.js +82 -18
  6. package/dist/es/bridge-mode.js.map +1 -1
  7. package/dist/es/chrome-extension.js +79 -15
  8. package/dist/es/chrome-extension.js.map +1 -1
  9. package/dist/es/index.js +110 -14
  10. package/dist/es/index.js.map +1 -1
  11. package/dist/es/midscene-playground.js +78 -14
  12. package/dist/es/midscene-playground.js.map +1 -1
  13. package/dist/es/playground.js +78 -14
  14. package/dist/es/playground.js.map +1 -1
  15. package/dist/es/playwright.js +110 -14
  16. package/dist/es/playwright.js.map +1 -1
  17. package/dist/es/puppeteer-agent-launcher.js +78 -14
  18. package/dist/es/puppeteer-agent-launcher.js.map +1 -1
  19. package/dist/es/puppeteer.js +78 -14
  20. package/dist/es/puppeteer.js.map +1 -1
  21. package/dist/es/ui-utils.js.map +1 -1
  22. package/dist/lib/agent.js +77 -10
  23. package/dist/lib/agent.js.map +1 -1
  24. package/dist/lib/bridge-mode-browser.js +3 -3
  25. package/dist/lib/bridge-mode-browser.js.map +1 -1
  26. package/dist/lib/bridge-mode.js +81 -14
  27. package/dist/lib/bridge-mode.js.map +1 -1
  28. package/dist/lib/chrome-extension.js +78 -11
  29. package/dist/lib/chrome-extension.js.map +1 -1
  30. package/dist/lib/index.js +109 -10
  31. package/dist/lib/index.js.map +1 -1
  32. package/dist/lib/midscene-playground.js +77 -10
  33. package/dist/lib/midscene-playground.js.map +1 -1
  34. package/dist/lib/playground.js +77 -10
  35. package/dist/lib/playground.js.map +1 -1
  36. package/dist/lib/playwright.js +109 -10
  37. package/dist/lib/playwright.js.map +1 -1
  38. package/dist/lib/puppeteer-agent-launcher.js +77 -10
  39. package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
  40. package/dist/lib/puppeteer.js +77 -10
  41. package/dist/lib/puppeteer.js.map +1 -1
  42. package/dist/lib/ui-utils.js.map +1 -1
  43. package/dist/types/agent.d.ts +8 -0
  44. package/dist/types/playwright.d.ts +16 -0
  45. package/dist/types/ui-utils.d.ts +1 -1
  46. package/package.json +4 -5
@@ -296,10 +296,7 @@ import { sleep } from "@midscene/core/utils";
296
296
  import { UITarsModelVersion } from "@midscene/shared/env";
297
297
  import { uiTarsModelVersion } from "@midscene/shared/env";
298
298
  import { vlLocateMode } from "@midscene/shared/env";
299
- import {
300
- imageInfo,
301
- resizeImgBase64 as resizeImgBase642
302
- } from "@midscene/shared/img";
299
+ import { imageInfo, resizeImgBase64 as resizeImgBase642 } from "@midscene/shared/img";
303
300
  import { getDebug as getDebug2 } from "@midscene/shared/logger";
304
301
  import { assert as assert4 } from "@midscene/shared/utils";
305
302
 
@@ -1513,17 +1510,23 @@ var PageTaskExecutor = class {
1513
1510
  executor: taskExecutor
1514
1511
  };
1515
1512
  }
1516
- async query(demand) {
1517
- const description = typeof demand === "string" ? demand : JSON.stringify(demand);
1518
- const taskExecutor = new Executor(taskTitleStr("Query", description), {
1519
- onTaskStart: this.onTaskStartCallback
1520
- });
1513
+ async createTypeQueryTask(type, demand) {
1514
+ const taskExecutor = new Executor(
1515
+ taskTitleStr(
1516
+ type,
1517
+ typeof demand === "string" ? demand : JSON.stringify(demand)
1518
+ ),
1519
+ {
1520
+ onTaskStart: this.onTaskStartCallback
1521
+ }
1522
+ );
1521
1523
  const queryTask = {
1522
1524
  type: "Insight",
1523
- subType: "Query",
1525
+ subType: type,
1524
1526
  locate: null,
1525
1527
  param: {
1526
1528
  dataDemand: demand
1529
+ // for user param presentation in report right sidebar
1527
1530
  },
1528
1531
  executor: async (param) => {
1529
1532
  let insightDump;
@@ -1531,11 +1534,21 @@ var PageTaskExecutor = class {
1531
1534
  insightDump = dump;
1532
1535
  };
1533
1536
  this.insight.onceDumpUpdatedFn = dumpCollector;
1534
- const { data, usage } = await this.insight.extract(
1535
- param.dataDemand
1536
- );
1537
+ const ifTypeRestricted = type !== "Query";
1538
+ let demandInput = demand;
1539
+ if (ifTypeRestricted) {
1540
+ demandInput = {
1541
+ result: `${type}, ${demand}`
1542
+ };
1543
+ }
1544
+ const { data, usage } = await this.insight.extract(demandInput);
1545
+ let outputResult = data;
1546
+ if (ifTypeRestricted) {
1547
+ assert4(data?.result !== void 0, "No result in query data");
1548
+ outputResult = data.result;
1549
+ }
1537
1550
  return {
1538
- output: data,
1551
+ output: outputResult,
1539
1552
  log: { dump: insightDump },
1540
1553
  usage
1541
1554
  };
@@ -1548,6 +1561,18 @@ var PageTaskExecutor = class {
1548
1561
  executor: taskExecutor
1549
1562
  };
1550
1563
  }
1564
+ async query(demand) {
1565
+ return this.createTypeQueryTask("Query", demand);
1566
+ }
1567
+ async boolean(prompt) {
1568
+ return this.createTypeQueryTask("Boolean", prompt);
1569
+ }
1570
+ async number(prompt) {
1571
+ return this.createTypeQueryTask("Number", prompt);
1572
+ }
1573
+ async string(prompt) {
1574
+ return this.createTypeQueryTask("String", prompt);
1575
+ }
1551
1576
  async assert(assertion) {
1552
1577
  const description = `assert: ${assertion}`;
1553
1578
  const taskExecutor = new Executor(taskTitleStr("Assert", description), {
@@ -1734,6 +1759,16 @@ function buildPlans(type, locateParam, param) {
1734
1759
  };
1735
1760
  returnPlans = [sleepPlan];
1736
1761
  }
1762
+ if (type === "Locate") {
1763
+ assert5(locateParam, `missing locate info for action "${type}"`);
1764
+ const locatePlan2 = {
1765
+ type,
1766
+ param: locateParam,
1767
+ locate: locateParam,
1768
+ thought: ""
1769
+ };
1770
+ returnPlans = [locatePlan2];
1771
+ }
1737
1772
  if (returnPlans) {
1738
1773
  debug3("buildPlans", returnPlans);
1739
1774
  return returnPlans;
@@ -1933,6 +1968,35 @@ ${errorTask?.errorStack}`);
1933
1968
  this.afterTaskRunning(executor);
1934
1969
  return output;
1935
1970
  }
1971
+ async aiBoolean(prompt) {
1972
+ const { output, executor } = await this.taskExecutor.boolean(prompt);
1973
+ this.afterTaskRunning(executor);
1974
+ return output;
1975
+ }
1976
+ async aiNumber(prompt) {
1977
+ const { output, executor } = await this.taskExecutor.number(prompt);
1978
+ this.afterTaskRunning(executor);
1979
+ return output;
1980
+ }
1981
+ async aiString(prompt) {
1982
+ const { output, executor } = await this.taskExecutor.string(prompt);
1983
+ this.afterTaskRunning(executor);
1984
+ return output;
1985
+ }
1986
+ async aiLocate(prompt, opt) {
1987
+ const detailedLocateParam = this.buildDetailedLocateParam(prompt, opt);
1988
+ const plans = buildPlans("Locate", detailedLocateParam);
1989
+ const { executor, output } = await this.taskExecutor.runPlans(
1990
+ taskTitleStr("Locate", locateParamStr(detailedLocateParam)),
1991
+ plans
1992
+ );
1993
+ this.afterTaskRunning(executor);
1994
+ const { element } = output;
1995
+ return {
1996
+ rect: element?.rect,
1997
+ center: element?.center
1998
+ };
1999
+ }
1936
2000
  async aiAssert(assertion, msg, opt) {
1937
2001
  const { output, executor } = await this.taskExecutor.assert(assertion);
1938
2002
  this.afterTaskRunning(executor, true);
@@ -2467,6 +2531,38 @@ var PlaywrightAiFixture = (options) => {
2467
2531
  use,
2468
2532
  aiActionType: "aiWaitFor"
2469
2533
  });
2534
+ },
2535
+ aiLocate: async ({ page }, use, testInfo) => {
2536
+ await generateAiFunction({
2537
+ page,
2538
+ testInfo,
2539
+ use,
2540
+ aiActionType: "aiLocate"
2541
+ });
2542
+ },
2543
+ aiNumber: async ({ page }, use, testInfo) => {
2544
+ await generateAiFunction({
2545
+ page,
2546
+ testInfo,
2547
+ use,
2548
+ aiActionType: "aiNumber"
2549
+ });
2550
+ },
2551
+ aiString: async ({ page }, use, testInfo) => {
2552
+ await generateAiFunction({
2553
+ page,
2554
+ testInfo,
2555
+ use,
2556
+ aiActionType: "aiString"
2557
+ });
2558
+ },
2559
+ aiBoolean: async ({ page }, use, testInfo) => {
2560
+ await generateAiFunction({
2561
+ page,
2562
+ testInfo,
2563
+ use,
2564
+ aiActionType: "aiBoolean"
2565
+ });
2470
2566
  }
2471
2567
  };
2472
2568
  };