@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
@@ -301,10 +301,7 @@ import { sleep } from "@midscene/core/utils";
301
301
  import { UITarsModelVersion } from "@midscene/shared/env";
302
302
  import { uiTarsModelVersion } from "@midscene/shared/env";
303
303
  import { vlLocateMode } from "@midscene/shared/env";
304
- import {
305
- imageInfo,
306
- resizeImgBase64 as resizeImgBase642
307
- } from "@midscene/shared/img";
304
+ import { imageInfo, resizeImgBase64 as resizeImgBase642 } from "@midscene/shared/img";
308
305
  import { getDebug as getDebug2 } from "@midscene/shared/logger";
309
306
  import { assert as assert4 } from "@midscene/shared/utils";
310
307
 
@@ -1518,17 +1515,23 @@ var PageTaskExecutor = class {
1518
1515
  executor: taskExecutor
1519
1516
  };
1520
1517
  }
1521
- async query(demand) {
1522
- const description = typeof demand === "string" ? demand : JSON.stringify(demand);
1523
- const taskExecutor = new Executor(taskTitleStr("Query", description), {
1524
- onTaskStart: this.onTaskStartCallback
1525
- });
1518
+ async createTypeQueryTask(type, demand) {
1519
+ const taskExecutor = new Executor(
1520
+ taskTitleStr(
1521
+ type,
1522
+ typeof demand === "string" ? demand : JSON.stringify(demand)
1523
+ ),
1524
+ {
1525
+ onTaskStart: this.onTaskStartCallback
1526
+ }
1527
+ );
1526
1528
  const queryTask = {
1527
1529
  type: "Insight",
1528
- subType: "Query",
1530
+ subType: type,
1529
1531
  locate: null,
1530
1532
  param: {
1531
1533
  dataDemand: demand
1534
+ // for user param presentation in report right sidebar
1532
1535
  },
1533
1536
  executor: async (param) => {
1534
1537
  let insightDump;
@@ -1536,11 +1539,21 @@ var PageTaskExecutor = class {
1536
1539
  insightDump = dump;
1537
1540
  };
1538
1541
  this.insight.onceDumpUpdatedFn = dumpCollector;
1539
- const { data, usage } = await this.insight.extract(
1540
- param.dataDemand
1541
- );
1542
+ const ifTypeRestricted = type !== "Query";
1543
+ let demandInput = demand;
1544
+ if (ifTypeRestricted) {
1545
+ demandInput = {
1546
+ result: `${type}, ${demand}`
1547
+ };
1548
+ }
1549
+ const { data, usage } = await this.insight.extract(demandInput);
1550
+ let outputResult = data;
1551
+ if (ifTypeRestricted) {
1552
+ assert4(data?.result !== void 0, "No result in query data");
1553
+ outputResult = data.result;
1554
+ }
1542
1555
  return {
1543
- output: data,
1556
+ output: outputResult,
1544
1557
  log: { dump: insightDump },
1545
1558
  usage
1546
1559
  };
@@ -1553,6 +1566,18 @@ var PageTaskExecutor = class {
1553
1566
  executor: taskExecutor
1554
1567
  };
1555
1568
  }
1569
+ async query(demand) {
1570
+ return this.createTypeQueryTask("Query", demand);
1571
+ }
1572
+ async boolean(prompt) {
1573
+ return this.createTypeQueryTask("Boolean", prompt);
1574
+ }
1575
+ async number(prompt) {
1576
+ return this.createTypeQueryTask("Number", prompt);
1577
+ }
1578
+ async string(prompt) {
1579
+ return this.createTypeQueryTask("String", prompt);
1580
+ }
1556
1581
  async assert(assertion) {
1557
1582
  const description = `assert: ${assertion}`;
1558
1583
  const taskExecutor = new Executor(taskTitleStr("Assert", description), {
@@ -1739,6 +1764,16 @@ function buildPlans(type, locateParam, param) {
1739
1764
  };
1740
1765
  returnPlans = [sleepPlan];
1741
1766
  }
1767
+ if (type === "Locate") {
1768
+ assert5(locateParam, `missing locate info for action "${type}"`);
1769
+ const locatePlan2 = {
1770
+ type,
1771
+ param: locateParam,
1772
+ locate: locateParam,
1773
+ thought: ""
1774
+ };
1775
+ returnPlans = [locatePlan2];
1776
+ }
1742
1777
  if (returnPlans) {
1743
1778
  debug3("buildPlans", returnPlans);
1744
1779
  return returnPlans;
@@ -1938,6 +1973,35 @@ ${errorTask?.errorStack}`);
1938
1973
  this.afterTaskRunning(executor);
1939
1974
  return output;
1940
1975
  }
1976
+ async aiBoolean(prompt) {
1977
+ const { output, executor } = await this.taskExecutor.boolean(prompt);
1978
+ this.afterTaskRunning(executor);
1979
+ return output;
1980
+ }
1981
+ async aiNumber(prompt) {
1982
+ const { output, executor } = await this.taskExecutor.number(prompt);
1983
+ this.afterTaskRunning(executor);
1984
+ return output;
1985
+ }
1986
+ async aiString(prompt) {
1987
+ const { output, executor } = await this.taskExecutor.string(prompt);
1988
+ this.afterTaskRunning(executor);
1989
+ return output;
1990
+ }
1991
+ async aiLocate(prompt, opt) {
1992
+ const detailedLocateParam = this.buildDetailedLocateParam(prompt, opt);
1993
+ const plans = buildPlans("Locate", detailedLocateParam);
1994
+ const { executor, output } = await this.taskExecutor.runPlans(
1995
+ taskTitleStr("Locate", locateParamStr(detailedLocateParam)),
1996
+ plans
1997
+ );
1998
+ this.afterTaskRunning(executor);
1999
+ const { element } = output;
2000
+ return {
2001
+ rect: element?.rect,
2002
+ center: element?.center
2003
+ };
2004
+ }
1941
2005
  async aiAssert(assertion, msg, opt) {
1942
2006
  const { output, executor } = await this.taskExecutor.assert(assertion);
1943
2007
  this.afterTaskRunning(executor, true);