@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
@@ -1534,17 +1534,23 @@ var PageTaskExecutor = class {
1534
1534
  executor: taskExecutor
1535
1535
  };
1536
1536
  }
1537
- async query(demand) {
1538
- const description = typeof demand === "string" ? demand : JSON.stringify(demand);
1539
- const taskExecutor = new import_core.Executor(taskTitleStr("Query", description), {
1540
- onTaskStart: this.onTaskStartCallback
1541
- });
1537
+ async createTypeQueryTask(type, demand) {
1538
+ const taskExecutor = new import_core.Executor(
1539
+ taskTitleStr(
1540
+ type,
1541
+ typeof demand === "string" ? demand : JSON.stringify(demand)
1542
+ ),
1543
+ {
1544
+ onTaskStart: this.onTaskStartCallback
1545
+ }
1546
+ );
1542
1547
  const queryTask = {
1543
1548
  type: "Insight",
1544
- subType: "Query",
1549
+ subType: type,
1545
1550
  locate: null,
1546
1551
  param: {
1547
1552
  dataDemand: demand
1553
+ // for user param presentation in report right sidebar
1548
1554
  },
1549
1555
  executor: async (param) => {
1550
1556
  let insightDump;
@@ -1552,11 +1558,21 @@ var PageTaskExecutor = class {
1552
1558
  insightDump = dump;
1553
1559
  };
1554
1560
  this.insight.onceDumpUpdatedFn = dumpCollector;
1555
- const { data, usage } = await this.insight.extract(
1556
- param.dataDemand
1557
- );
1561
+ const ifTypeRestricted = type !== "Query";
1562
+ let demandInput = demand;
1563
+ if (ifTypeRestricted) {
1564
+ demandInput = {
1565
+ result: `${type}, ${demand}`
1566
+ };
1567
+ }
1568
+ const { data, usage } = await this.insight.extract(demandInput);
1569
+ let outputResult = data;
1570
+ if (ifTypeRestricted) {
1571
+ (0, import_utils9.assert)(data?.result !== void 0, "No result in query data");
1572
+ outputResult = data.result;
1573
+ }
1558
1574
  return {
1559
- output: data,
1575
+ output: outputResult,
1560
1576
  log: { dump: insightDump },
1561
1577
  usage
1562
1578
  };
@@ -1569,6 +1585,18 @@ var PageTaskExecutor = class {
1569
1585
  executor: taskExecutor
1570
1586
  };
1571
1587
  }
1588
+ async query(demand) {
1589
+ return this.createTypeQueryTask("Query", demand);
1590
+ }
1591
+ async boolean(prompt) {
1592
+ return this.createTypeQueryTask("Boolean", prompt);
1593
+ }
1594
+ async number(prompt) {
1595
+ return this.createTypeQueryTask("Number", prompt);
1596
+ }
1597
+ async string(prompt) {
1598
+ return this.createTypeQueryTask("String", prompt);
1599
+ }
1572
1600
  async assert(assertion) {
1573
1601
  const description = `assert: ${assertion}`;
1574
1602
  const taskExecutor = new import_core.Executor(taskTitleStr("Assert", description), {
@@ -1755,6 +1783,16 @@ function buildPlans(type, locateParam, param) {
1755
1783
  };
1756
1784
  returnPlans = [sleepPlan];
1757
1785
  }
1786
+ if (type === "Locate") {
1787
+ (0, import_utils10.assert)(locateParam, `missing locate info for action "${type}"`);
1788
+ const locatePlan2 = {
1789
+ type,
1790
+ param: locateParam,
1791
+ locate: locateParam,
1792
+ thought: ""
1793
+ };
1794
+ returnPlans = [locatePlan2];
1795
+ }
1758
1796
  if (returnPlans) {
1759
1797
  debug3("buildPlans", returnPlans);
1760
1798
  return returnPlans;
@@ -1954,6 +1992,35 @@ ${errorTask?.errorStack}`);
1954
1992
  this.afterTaskRunning(executor);
1955
1993
  return output;
1956
1994
  }
1995
+ async aiBoolean(prompt) {
1996
+ const { output, executor } = await this.taskExecutor.boolean(prompt);
1997
+ this.afterTaskRunning(executor);
1998
+ return output;
1999
+ }
2000
+ async aiNumber(prompt) {
2001
+ const { output, executor } = await this.taskExecutor.number(prompt);
2002
+ this.afterTaskRunning(executor);
2003
+ return output;
2004
+ }
2005
+ async aiString(prompt) {
2006
+ const { output, executor } = await this.taskExecutor.string(prompt);
2007
+ this.afterTaskRunning(executor);
2008
+ return output;
2009
+ }
2010
+ async aiLocate(prompt, opt) {
2011
+ const detailedLocateParam = this.buildDetailedLocateParam(prompt, opt);
2012
+ const plans = buildPlans("Locate", detailedLocateParam);
2013
+ const { executor, output } = await this.taskExecutor.runPlans(
2014
+ taskTitleStr("Locate", locateParamStr(detailedLocateParam)),
2015
+ plans
2016
+ );
2017
+ this.afterTaskRunning(executor);
2018
+ const { element } = output;
2019
+ return {
2020
+ rect: element?.rect,
2021
+ center: element?.center
2022
+ };
2023
+ }
1957
2024
  async aiAssert(assertion, msg, opt) {
1958
2025
  const { output, executor } = await this.taskExecutor.assert(assertion);
1959
2026
  this.afterTaskRunning(executor, true);
@@ -2488,6 +2555,38 @@ var PlaywrightAiFixture = (options) => {
2488
2555
  use,
2489
2556
  aiActionType: "aiWaitFor"
2490
2557
  });
2558
+ },
2559
+ aiLocate: async ({ page }, use, testInfo) => {
2560
+ await generateAiFunction({
2561
+ page,
2562
+ testInfo,
2563
+ use,
2564
+ aiActionType: "aiLocate"
2565
+ });
2566
+ },
2567
+ aiNumber: async ({ page }, use, testInfo) => {
2568
+ await generateAiFunction({
2569
+ page,
2570
+ testInfo,
2571
+ use,
2572
+ aiActionType: "aiNumber"
2573
+ });
2574
+ },
2575
+ aiString: async ({ page }, use, testInfo) => {
2576
+ await generateAiFunction({
2577
+ page,
2578
+ testInfo,
2579
+ use,
2580
+ aiActionType: "aiString"
2581
+ });
2582
+ },
2583
+ aiBoolean: async ({ page }, use, testInfo) => {
2584
+ await generateAiFunction({
2585
+ page,
2586
+ testInfo,
2587
+ use,
2588
+ aiActionType: "aiBoolean"
2589
+ });
2491
2590
  }
2492
2591
  };
2493
2592
  };