@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
@@ -388,10 +388,7 @@ import { sleep } from "@midscene/core/utils";
388
388
  import { UITarsModelVersion } from "@midscene/shared/env";
389
389
  import { uiTarsModelVersion } from "@midscene/shared/env";
390
390
  import { vlLocateMode } from "@midscene/shared/env";
391
- import {
392
- imageInfo,
393
- resizeImgBase64 as resizeImgBase642
394
- } from "@midscene/shared/img";
391
+ import { imageInfo, resizeImgBase64 as resizeImgBase642 } from "@midscene/shared/img";
395
392
  import { getDebug as getDebug2 } from "@midscene/shared/logger";
396
393
  import { assert as assert4 } from "@midscene/shared/utils";
397
394
 
@@ -1484,17 +1481,23 @@ var PageTaskExecutor = class {
1484
1481
  executor: taskExecutor
1485
1482
  };
1486
1483
  }
1487
- async query(demand) {
1488
- const description = typeof demand === "string" ? demand : JSON.stringify(demand);
1489
- const taskExecutor = new Executor(taskTitleStr("Query", description), {
1490
- onTaskStart: this.onTaskStartCallback
1491
- });
1484
+ async createTypeQueryTask(type, demand) {
1485
+ const taskExecutor = new Executor(
1486
+ taskTitleStr(
1487
+ type,
1488
+ typeof demand === "string" ? demand : JSON.stringify(demand)
1489
+ ),
1490
+ {
1491
+ onTaskStart: this.onTaskStartCallback
1492
+ }
1493
+ );
1492
1494
  const queryTask = {
1493
1495
  type: "Insight",
1494
- subType: "Query",
1496
+ subType: type,
1495
1497
  locate: null,
1496
1498
  param: {
1497
1499
  dataDemand: demand
1500
+ // for user param presentation in report right sidebar
1498
1501
  },
1499
1502
  executor: async (param) => {
1500
1503
  let insightDump;
@@ -1502,11 +1505,21 @@ var PageTaskExecutor = class {
1502
1505
  insightDump = dump;
1503
1506
  };
1504
1507
  this.insight.onceDumpUpdatedFn = dumpCollector;
1505
- const { data, usage } = await this.insight.extract(
1506
- param.dataDemand
1507
- );
1508
+ const ifTypeRestricted = type !== "Query";
1509
+ let demandInput = demand;
1510
+ if (ifTypeRestricted) {
1511
+ demandInput = {
1512
+ result: `${type}, ${demand}`
1513
+ };
1514
+ }
1515
+ const { data, usage } = await this.insight.extract(demandInput);
1516
+ let outputResult = data;
1517
+ if (ifTypeRestricted) {
1518
+ assert4(data?.result !== void 0, "No result in query data");
1519
+ outputResult = data.result;
1520
+ }
1508
1521
  return {
1509
- output: data,
1522
+ output: outputResult,
1510
1523
  log: { dump: insightDump },
1511
1524
  usage
1512
1525
  };
@@ -1519,6 +1532,18 @@ var PageTaskExecutor = class {
1519
1532
  executor: taskExecutor
1520
1533
  };
1521
1534
  }
1535
+ async query(demand) {
1536
+ return this.createTypeQueryTask("Query", demand);
1537
+ }
1538
+ async boolean(prompt) {
1539
+ return this.createTypeQueryTask("Boolean", prompt);
1540
+ }
1541
+ async number(prompt) {
1542
+ return this.createTypeQueryTask("Number", prompt);
1543
+ }
1544
+ async string(prompt) {
1545
+ return this.createTypeQueryTask("String", prompt);
1546
+ }
1522
1547
  async assert(assertion) {
1523
1548
  const description = `assert: ${assertion}`;
1524
1549
  const taskExecutor = new Executor(taskTitleStr("Assert", description), {
@@ -1705,6 +1730,16 @@ function buildPlans(type, locateParam, param) {
1705
1730
  };
1706
1731
  returnPlans = [sleepPlan];
1707
1732
  }
1733
+ if (type === "Locate") {
1734
+ assert5(locateParam, `missing locate info for action "${type}"`);
1735
+ const locatePlan2 = {
1736
+ type,
1737
+ param: locateParam,
1738
+ locate: locateParam,
1739
+ thought: ""
1740
+ };
1741
+ returnPlans = [locatePlan2];
1742
+ }
1708
1743
  if (returnPlans) {
1709
1744
  debug3("buildPlans", returnPlans);
1710
1745
  return returnPlans;
@@ -1904,6 +1939,35 @@ ${errorTask?.errorStack}`);
1904
1939
  this.afterTaskRunning(executor);
1905
1940
  return output;
1906
1941
  }
1942
+ async aiBoolean(prompt) {
1943
+ const { output, executor } = await this.taskExecutor.boolean(prompt);
1944
+ this.afterTaskRunning(executor);
1945
+ return output;
1946
+ }
1947
+ async aiNumber(prompt) {
1948
+ const { output, executor } = await this.taskExecutor.number(prompt);
1949
+ this.afterTaskRunning(executor);
1950
+ return output;
1951
+ }
1952
+ async aiString(prompt) {
1953
+ const { output, executor } = await this.taskExecutor.string(prompt);
1954
+ this.afterTaskRunning(executor);
1955
+ return output;
1956
+ }
1957
+ async aiLocate(prompt, opt) {
1958
+ const detailedLocateParam = this.buildDetailedLocateParam(prompt, opt);
1959
+ const plans = buildPlans("Locate", detailedLocateParam);
1960
+ const { executor, output } = await this.taskExecutor.runPlans(
1961
+ taskTitleStr("Locate", locateParamStr(detailedLocateParam)),
1962
+ plans
1963
+ );
1964
+ this.afterTaskRunning(executor);
1965
+ const { element } = output;
1966
+ return {
1967
+ rect: element?.rect,
1968
+ center: element?.center
1969
+ };
1970
+ }
1907
1971
  async aiAssert(assertion, msg, opt) {
1908
1972
  const { output, executor } = await this.taskExecutor.assert(assertion);
1909
1973
  this.afterTaskRunning(executor, true);