misoai-web 1.5.6 → 1.5.7

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 (75) hide show
  1. package/dist/es/agent.js +124 -21
  2. package/dist/es/agent.js.map +1 -1
  3. package/dist/es/bridge-mode-browser.js +10 -9
  4. package/dist/es/bridge-mode-browser.js.map +1 -1
  5. package/dist/es/bridge-mode.js +126 -23
  6. package/dist/es/bridge-mode.js.map +1 -1
  7. package/dist/es/chrome-extension.js +132 -28
  8. package/dist/es/chrome-extension.js.map +1 -1
  9. package/dist/es/index.js +140 -21
  10. package/dist/es/index.js.map +1 -1
  11. package/dist/es/midscene-playground.js +124 -21
  12. package/dist/es/midscene-playground.js.map +1 -1
  13. package/dist/es/midscene-server.js.map +1 -1
  14. package/dist/es/playground.js +124 -21
  15. package/dist/es/playground.js.map +1 -1
  16. package/dist/es/playwright-report.js +1 -1
  17. package/dist/es/playwright-report.js.map +1 -1
  18. package/dist/es/playwright.js +140 -21
  19. package/dist/es/playwright.js.map +1 -1
  20. package/dist/es/puppeteer-agent-launcher.js +124 -21
  21. package/dist/es/puppeteer-agent-launcher.js.map +1 -1
  22. package/dist/es/puppeteer.js +124 -21
  23. package/dist/es/puppeteer.js.map +1 -1
  24. package/dist/es/ui-utils.js.map +1 -1
  25. package/dist/es/utils.js +7 -4
  26. package/dist/es/utils.js.map +1 -1
  27. package/dist/es/yaml.js +24 -0
  28. package/dist/es/yaml.js.map +1 -1
  29. package/dist/lib/agent.js +122 -19
  30. package/dist/lib/agent.js.map +1 -1
  31. package/dist/lib/bridge-mode-browser.js +10 -9
  32. package/dist/lib/bridge-mode-browser.js.map +1 -1
  33. package/dist/lib/bridge-mode.js +124 -21
  34. package/dist/lib/bridge-mode.js.map +1 -1
  35. package/dist/lib/chrome-extension.js +130 -26
  36. package/dist/lib/chrome-extension.js.map +1 -1
  37. package/dist/lib/index.js +138 -19
  38. package/dist/lib/index.js.map +1 -1
  39. package/dist/lib/midscene-playground.js +122 -19
  40. package/dist/lib/midscene-playground.js.map +1 -1
  41. package/dist/lib/midscene-server.js.map +1 -1
  42. package/dist/lib/playground.js +122 -19
  43. package/dist/lib/playground.js.map +1 -1
  44. package/dist/lib/playwright-report.js +1 -1
  45. package/dist/lib/playwright-report.js.map +1 -1
  46. package/dist/lib/playwright.js +138 -19
  47. package/dist/lib/playwright.js.map +1 -1
  48. package/dist/lib/puppeteer-agent-launcher.js +122 -19
  49. package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
  50. package/dist/lib/puppeteer.js +122 -19
  51. package/dist/lib/puppeteer.js.map +1 -1
  52. package/dist/lib/ui-utils.js.map +1 -1
  53. package/dist/lib/utils.js +7 -4
  54. package/dist/lib/utils.js.map +1 -1
  55. package/dist/lib/yaml.js +24 -0
  56. package/dist/lib/yaml.js.map +1 -1
  57. package/dist/types/agent.d.ts +10 -7
  58. package/dist/types/bridge-mode-browser.d.ts +2 -3
  59. package/dist/types/bridge-mode.d.ts +2 -3
  60. package/dist/types/{browser-aec1055d.d.ts → browser-9b472ffb.d.ts} +1 -1
  61. package/dist/types/chrome-extension.d.ts +2 -3
  62. package/dist/types/index.d.ts +1 -2
  63. package/dist/types/midscene-server.d.ts +1 -2
  64. package/dist/types/{page-86ab0fe1.d.ts → page-ed0ecb44.d.ts} +19 -9
  65. package/dist/types/playground.d.ts +2 -3
  66. package/dist/types/playwright.d.ts +9 -2
  67. package/dist/types/puppeteer-agent-launcher.d.ts +1 -2
  68. package/dist/types/puppeteer.d.ts +6 -5
  69. package/dist/types/ui-utils.d.ts +1 -1
  70. package/dist/types/utils.d.ts +1 -2
  71. package/dist/types/yaml.d.ts +1 -2
  72. package/iife-script/htmlElement.js +51 -73
  73. package/iife-script/htmlElementDebug.js +33 -54
  74. package/package.json +23 -23
  75. package/LICENSE +0 -21
package/dist/lib/index.js CHANGED
@@ -148,6 +148,10 @@ var ScriptPlayer = class {
148
148
  } else if ("aiQuery" in flowItem) {
149
149
  const queryTask = flowItem;
150
150
  const prompt = queryTask.aiQuery;
151
+ const options = {
152
+ domIncluded: queryTask.domIncluded,
153
+ screenshotIncluded: queryTask.screenshotIncluded
154
+ };
151
155
  (0, import_utils.assert)(prompt, "missing prompt for aiQuery");
152
156
  (0, import_utils.assert)(
153
157
  typeof prompt === "string",
@@ -158,6 +162,10 @@ var ScriptPlayer = class {
158
162
  } else if ("aiNumber" in flowItem) {
159
163
  const numberTask = flowItem;
160
164
  const prompt = numberTask.aiNumber;
165
+ const options = {
166
+ domIncluded: numberTask.domIncluded,
167
+ screenshotIncluded: numberTask.screenshotIncluded
168
+ };
161
169
  (0, import_utils.assert)(prompt, "missing prompt for number");
162
170
  (0, import_utils.assert)(
163
171
  typeof prompt === "string",
@@ -168,6 +176,10 @@ var ScriptPlayer = class {
168
176
  } else if ("aiString" in flowItem) {
169
177
  const stringTask = flowItem;
170
178
  const prompt = stringTask.aiString;
179
+ const options = {
180
+ domIncluded: stringTask.domIncluded,
181
+ screenshotIncluded: stringTask.screenshotIncluded
182
+ };
171
183
  (0, import_utils.assert)(prompt, "missing prompt for string");
172
184
  (0, import_utils.assert)(
173
185
  typeof prompt === "string",
@@ -178,6 +190,10 @@ var ScriptPlayer = class {
178
190
  } else if ("aiBoolean" in flowItem) {
179
191
  const booleanTask = flowItem;
180
192
  const prompt = booleanTask.aiBoolean;
193
+ const options = {
194
+ domIncluded: booleanTask.domIncluded,
195
+ screenshotIncluded: booleanTask.screenshotIncluded
196
+ };
181
197
  (0, import_utils.assert)(prompt, "missing prompt for boolean");
182
198
  (0, import_utils.assert)(
183
199
  typeof prompt === "string",
@@ -220,6 +236,9 @@ var ScriptPlayer = class {
220
236
  } else if ("aiTap" in flowItem) {
221
237
  const tapTask = flowItem;
222
238
  await agent.aiTap(tapTask.aiTap, tapTask);
239
+ } else if ("aiRightClick" in flowItem) {
240
+ const rightClickTask = flowItem;
241
+ await agent.aiRightClick(rightClickTask.aiRightClick, rightClickTask);
223
242
  } else if ("aiHover" in flowItem) {
224
243
  const hoverTask = flowItem;
225
244
  await agent.aiHover(hoverTask.aiHover, hoverTask);
@@ -242,6 +261,11 @@ var ScriptPlayer = class {
242
261
  evaluateJavaScriptTask.javascript
243
262
  );
244
263
  this.setResult(evaluateJavaScriptTask.name, result);
264
+ } else if ("logScreenshot" in flowItem) {
265
+ const logScreenshotTask = flowItem;
266
+ await agent.logScreenshot(logScreenshotTask.logScreenshot, {
267
+ content: logScreenshotTask.content || ""
268
+ });
245
269
  } else {
246
270
  throw new Error(`unknown flowItem: ${JSON.stringify(flowItem)}`);
247
271
  }
@@ -490,7 +514,8 @@ var WebElementInfo = class {
490
514
  id,
491
515
  attributes,
492
516
  indexId,
493
- xpaths
517
+ xpaths,
518
+ isVisible
494
519
  }) {
495
520
  this.content = content;
496
521
  this.rect = rect;
@@ -503,6 +528,7 @@ var WebElementInfo = class {
503
528
  this.attributes = attributes;
504
529
  this.indexId = indexId;
505
530
  this.xpaths = xpaths;
531
+ this.isVisible = isVisible;
506
532
  }
507
533
  };
508
534
 
@@ -525,14 +551,15 @@ async function parseContextFromWebPage(page, _opt) {
525
551
  })
526
552
  ]);
527
553
  const webTree = (0, import_extractor.traverseTree)(tree, (elementInfo) => {
528
- const { rect, id, content, attributes, locator, indexId } = elementInfo;
554
+ const { rect, id, content, attributes, locator, indexId, isVisible } = elementInfo;
529
555
  return new WebElementInfo({
530
556
  rect,
531
557
  locator,
532
558
  id,
533
559
  content,
534
560
  attributes,
535
- indexId
561
+ indexId,
562
+ isVisible
536
563
  });
537
564
  });
538
565
  (0, import_utils4.assert)(screenshotBase64, "screenshotBase64 is required");
@@ -562,7 +589,7 @@ function printReportMsg(filepath) {
562
589
  (0, import_utils4.logMsg)(`Midscene - report file updated: ${filepath}`);
563
590
  }
564
591
  function replaceIllegalPathCharsAndSpace(str) {
565
- return str.replace(/[/\\:*?"<>| ]/g, "-");
592
+ return str.replace(/[:*?"<>| ]/g, "-");
566
593
  }
567
594
  function forceClosePopup(page, debug7) {
568
595
  page.on("popup", async (popup) => {
@@ -876,10 +903,10 @@ var PageTaskExecutor = class {
876
903
  if (!taskParam || !taskParam.value) {
877
904
  return;
878
905
  }
879
- await this.page.keyboard.type(taskParam.value);
880
- } else {
881
- await this.page.keyboard.type(taskParam.value);
882
906
  }
907
+ await this.page.keyboard.type(taskParam.value, {
908
+ autoDismissKeyboard: taskParam.autoDismissKeyboard
909
+ });
883
910
  }
884
911
  };
885
912
  tasks.push(taskActionInput);
@@ -908,6 +935,22 @@ var PageTaskExecutor = class {
908
935
  }
909
936
  };
910
937
  tasks.push(taskActionTap);
938
+ } else if (plan2.type === "RightClick") {
939
+ const taskActionRightClick = {
940
+ type: "Action",
941
+ subType: "RightClick",
942
+ thought: plan2.thought,
943
+ locate: plan2.locate,
944
+ executor: async (param, { element }) => {
945
+ (0, import_utils6.assert)(element, "Element not found, cannot right click");
946
+ await this.page.mouse.click(
947
+ element.center[0],
948
+ element.center[1],
949
+ { button: "right" }
950
+ );
951
+ }
952
+ };
953
+ tasks.push(taskActionRightClick);
911
954
  } else if (plan2.type === "Drag") {
912
955
  const taskActionDrag = {
913
956
  type: "Action",
@@ -1436,7 +1479,7 @@ var PageTaskExecutor = class {
1436
1479
  executor: taskExecutor
1437
1480
  };
1438
1481
  }
1439
- async createTypeQueryTask(type, demand) {
1482
+ async createTypeQueryTask(type, demand, opt) {
1440
1483
  const taskExecutor = new import_misoai_core.Executor(
1441
1484
  taskTitleStr(
1442
1485
  type,
@@ -1467,7 +1510,10 @@ var PageTaskExecutor = class {
1467
1510
  result: `${type}, ${demand}`
1468
1511
  };
1469
1512
  }
1470
- const { data, usage } = await this.insight.extract(demandInput);
1513
+ const { data, usage } = await this.insight.extract(
1514
+ demandInput,
1515
+ opt
1516
+ );
1471
1517
  let outputResult = data;
1472
1518
  if (ifTypeRestricted) {
1473
1519
  (0, import_utils6.assert)(data?.result !== void 0, "No result in query data");
@@ -1487,17 +1533,17 @@ var PageTaskExecutor = class {
1487
1533
  executor: taskExecutor
1488
1534
  };
1489
1535
  }
1490
- async query(demand) {
1491
- return this.createTypeQueryTask("Query", demand);
1536
+ async query(demand, opt) {
1537
+ return this.createTypeQueryTask("Query", demand, opt);
1492
1538
  }
1493
- async boolean(prompt) {
1494
- return this.createTypeQueryTask("Boolean", prompt);
1539
+ async boolean(prompt, opt) {
1540
+ return this.createTypeQueryTask("Boolean", prompt, opt);
1495
1541
  }
1496
- async number(prompt) {
1497
- return this.createTypeQueryTask("Number", prompt);
1542
+ async number(prompt, opt) {
1543
+ return this.createTypeQueryTask("Number", prompt, opt);
1498
1544
  }
1499
- async string(prompt) {
1500
- return this.createTypeQueryTask("String", prompt);
1545
+ async string(prompt, opt) {
1546
+ return this.createTypeQueryTask("String", prompt, opt);
1501
1547
  }
1502
1548
  async assert(assertion) {
1503
1549
  const description = `assert: ${assertion}`;
@@ -1633,7 +1679,7 @@ function buildPlans(type, locateParam, param) {
1633
1679
  param: locateParam,
1634
1680
  thought: ""
1635
1681
  } : null;
1636
- if (type === "Tap" || type === "Hover") {
1682
+ if (type === "Tap" || type === "Hover" || type === "RightClick") {
1637
1683
  (0, import_utils8.assert)(locateParam, `missing locate info for action "${type}"`);
1638
1684
  (0, import_utils8.assert)(locatePlan, `missing locate info for action "${type}"`);
1639
1685
  const tapPlan = {
@@ -1713,7 +1759,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
1713
1759
  var import_semver = __toESM(require("semver"));
1714
1760
 
1715
1761
  // package.json
1716
- var version = "1.5.6";
1762
+ var version = "1.0.3";
1717
1763
 
1718
1764
  // src/common/task-cache.ts
1719
1765
  var debug3 = (0, import_logger3.getDebug)("cache");
@@ -1844,8 +1890,14 @@ cache file: ${cacheFile}`
1844
1890
  return;
1845
1891
  }
1846
1892
  try {
1893
+ const dir = (0, import_node_path2.dirname)(this.cacheFilePath);
1894
+ if (!(0, import_node_fs2.existsSync)(dir)) {
1895
+ (0, import_node_fs2.mkdirSync)(dir, { recursive: true });
1896
+ debug3("created cache directory: %s", dir);
1897
+ }
1847
1898
  const yamlData = import_js_yaml3.default.dump(this.cache);
1848
1899
  (0, import_node_fs2.writeFileSync)(this.cacheFilePath, yamlData);
1900
+ debug3("cache flushed to file: %s", this.cacheFilePath);
1849
1901
  } catch (err) {
1850
1902
  debug3(
1851
1903
  "write cache to file failed, path: %s, error: %s",
@@ -2103,6 +2155,23 @@ var PageAgent = class {
2103
2155
  metadata
2104
2156
  };
2105
2157
  }
2158
+ async aiRightClick(locatePrompt, opt) {
2159
+ const detailedLocateParam = this.buildDetailedLocateParam(
2160
+ locatePrompt,
2161
+ opt
2162
+ );
2163
+ const plans = buildPlans("RightClick", detailedLocateParam);
2164
+ const { executor, output } = await this.taskExecutor.runPlans(
2165
+ taskTitleStr("RightClick", locateParamStr(detailedLocateParam)),
2166
+ plans,
2167
+ { cacheable: opt?.cacheable }
2168
+ );
2169
+ const metadata = this.afterTaskRunning(executor);
2170
+ return {
2171
+ result: output,
2172
+ metadata
2173
+ };
2174
+ }
2106
2175
  async aiInput(value, locatePrompt, opt) {
2107
2176
  (0, import_utils12.assert)(
2108
2177
  typeof value === "string",
@@ -2534,6 +2603,40 @@ ${errors}`);
2534
2603
  }
2535
2604
  throw new Error("evaluateJavaScript is not supported in current agent");
2536
2605
  }
2606
+ async logScreenshot(title, options) {
2607
+ const screenshotTitle = title || "untitled";
2608
+ const content = options?.content || "";
2609
+ const screenshot = await this.page.screenshotBase64?.();
2610
+ if (screenshot) {
2611
+ const executionDump = {
2612
+ name: screenshotTitle,
2613
+ description: content,
2614
+ tasks: [{
2615
+ type: "Screenshot",
2616
+ subType: "log",
2617
+ status: "finished",
2618
+ executor: null,
2619
+ param: {
2620
+ title: screenshotTitle,
2621
+ content
2622
+ },
2623
+ output: {
2624
+ screenshot
2625
+ },
2626
+ thought: `Logged screenshot: ${screenshotTitle}`,
2627
+ timing: {
2628
+ start: Date.now(),
2629
+ end: Date.now(),
2630
+ cost: 0
2631
+ }
2632
+ }],
2633
+ sdkVersion: "1.0.0",
2634
+ logTime: Date.now(),
2635
+ model_name: "screenshot"
2636
+ };
2637
+ this.appendExecutionDump(executionDump);
2638
+ }
2639
+ }
2537
2640
  async destroy() {
2538
2641
  await this.page.destroy();
2539
2642
  }
@@ -2957,6 +3060,14 @@ var PlaywrightAiFixture = (options) => {
2957
3060
  aiActionType: "aiTap"
2958
3061
  });
2959
3062
  },
3063
+ aiRightClick: async ({ page }, use, testInfo) => {
3064
+ await generateAiFunction({
3065
+ page,
3066
+ testInfo,
3067
+ use,
3068
+ aiActionType: "aiRightClick"
3069
+ });
3070
+ },
2960
3071
  aiHover: async ({ page }, use, testInfo) => {
2961
3072
  await generateAiFunction({
2962
3073
  page,
@@ -3044,6 +3155,14 @@ var PlaywrightAiFixture = (options) => {
3044
3155
  use,
3045
3156
  aiActionType: "aiBoolean"
3046
3157
  });
3158
+ },
3159
+ logScreenshot: async ({ page }, use, testInfo) => {
3160
+ await generateAiFunction({
3161
+ page,
3162
+ testInfo,
3163
+ use,
3164
+ aiActionType: "logScreenshot"
3165
+ });
3047
3166
  }
3048
3167
  };
3049
3168
  };