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
@@ -78,7 +78,8 @@ var WebElementInfo = class {
78
78
  id,
79
79
  attributes,
80
80
  indexId,
81
- xpaths
81
+ xpaths,
82
+ isVisible
82
83
  }) {
83
84
  this.content = content;
84
85
  this.rect = rect;
@@ -91,6 +92,7 @@ var WebElementInfo = class {
91
92
  this.attributes = attributes;
92
93
  this.indexId = indexId;
93
94
  this.xpaths = xpaths;
95
+ this.isVisible = isVisible;
94
96
  }
95
97
  };
96
98
 
@@ -113,14 +115,15 @@ async function parseContextFromWebPage(page, _opt) {
113
115
  })
114
116
  ]);
115
117
  const webTree = (0, import_extractor.traverseTree)(tree, (elementInfo) => {
116
- const { rect, id, content, attributes, locator, indexId } = elementInfo;
118
+ const { rect, id, content, attributes, locator, indexId, isVisible } = elementInfo;
117
119
  return new WebElementInfo({
118
120
  rect,
119
121
  locator,
120
122
  id,
121
123
  content,
122
124
  attributes,
123
- indexId
125
+ indexId,
126
+ isVisible
124
127
  });
125
128
  });
126
129
  (0, import_utils2.assert)(screenshotBase64, "screenshotBase64 is required");
@@ -151,7 +154,7 @@ function printReportMsg(filepath) {
151
154
  }
152
155
  var ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED = "NOT_IMPLEMENTED_AS_DESIGNED";
153
156
  function replaceIllegalPathCharsAndSpace(str) {
154
- return str.replace(/[/\\:*?"<>| ]/g, "-");
157
+ return str.replace(/[:*?"<>| ]/g, "-");
155
158
  }
156
159
  function matchElementFromPlan(planLocateParam, tree) {
157
160
  if (!planLocateParam) {
@@ -281,6 +284,10 @@ var ScriptPlayer = class {
281
284
  } else if ("aiQuery" in flowItem) {
282
285
  const queryTask = flowItem;
283
286
  const prompt = queryTask.aiQuery;
287
+ const options = {
288
+ domIncluded: queryTask.domIncluded,
289
+ screenshotIncluded: queryTask.screenshotIncluded
290
+ };
284
291
  (0, import_utils3.assert)(prompt, "missing prompt for aiQuery");
285
292
  (0, import_utils3.assert)(
286
293
  typeof prompt === "string",
@@ -291,6 +298,10 @@ var ScriptPlayer = class {
291
298
  } else if ("aiNumber" in flowItem) {
292
299
  const numberTask = flowItem;
293
300
  const prompt = numberTask.aiNumber;
301
+ const options = {
302
+ domIncluded: numberTask.domIncluded,
303
+ screenshotIncluded: numberTask.screenshotIncluded
304
+ };
294
305
  (0, import_utils3.assert)(prompt, "missing prompt for number");
295
306
  (0, import_utils3.assert)(
296
307
  typeof prompt === "string",
@@ -301,6 +312,10 @@ var ScriptPlayer = class {
301
312
  } else if ("aiString" in flowItem) {
302
313
  const stringTask = flowItem;
303
314
  const prompt = stringTask.aiString;
315
+ const options = {
316
+ domIncluded: stringTask.domIncluded,
317
+ screenshotIncluded: stringTask.screenshotIncluded
318
+ };
304
319
  (0, import_utils3.assert)(prompt, "missing prompt for string");
305
320
  (0, import_utils3.assert)(
306
321
  typeof prompt === "string",
@@ -311,6 +326,10 @@ var ScriptPlayer = class {
311
326
  } else if ("aiBoolean" in flowItem) {
312
327
  const booleanTask = flowItem;
313
328
  const prompt = booleanTask.aiBoolean;
329
+ const options = {
330
+ domIncluded: booleanTask.domIncluded,
331
+ screenshotIncluded: booleanTask.screenshotIncluded
332
+ };
314
333
  (0, import_utils3.assert)(prompt, "missing prompt for boolean");
315
334
  (0, import_utils3.assert)(
316
335
  typeof prompt === "string",
@@ -353,6 +372,9 @@ var ScriptPlayer = class {
353
372
  } else if ("aiTap" in flowItem) {
354
373
  const tapTask = flowItem;
355
374
  await agent.aiTap(tapTask.aiTap, tapTask);
375
+ } else if ("aiRightClick" in flowItem) {
376
+ const rightClickTask = flowItem;
377
+ await agent.aiRightClick(rightClickTask.aiRightClick, rightClickTask);
356
378
  } else if ("aiHover" in flowItem) {
357
379
  const hoverTask = flowItem;
358
380
  await agent.aiHover(hoverTask.aiHover, hoverTask);
@@ -375,6 +397,11 @@ var ScriptPlayer = class {
375
397
  evaluateJavaScriptTask.javascript
376
398
  );
377
399
  this.setResult(evaluateJavaScriptTask.name, result);
400
+ } else if ("logScreenshot" in flowItem) {
401
+ const logScreenshotTask = flowItem;
402
+ await agent.logScreenshot(logScreenshotTask.logScreenshot, {
403
+ content: logScreenshotTask.content || ""
404
+ });
378
405
  } else {
379
406
  throw new Error(`unknown flowItem: ${JSON.stringify(flowItem)}`);
380
407
  }
@@ -890,10 +917,10 @@ var PageTaskExecutor = class {
890
917
  if (!taskParam || !taskParam.value) {
891
918
  return;
892
919
  }
893
- await this.page.keyboard.type(taskParam.value);
894
- } else {
895
- await this.page.keyboard.type(taskParam.value);
896
920
  }
921
+ await this.page.keyboard.type(taskParam.value, {
922
+ autoDismissKeyboard: taskParam.autoDismissKeyboard
923
+ });
897
924
  }
898
925
  };
899
926
  tasks.push(taskActionInput);
@@ -922,6 +949,22 @@ var PageTaskExecutor = class {
922
949
  }
923
950
  };
924
951
  tasks.push(taskActionTap);
952
+ } else if (plan2.type === "RightClick") {
953
+ const taskActionRightClick = {
954
+ type: "Action",
955
+ subType: "RightClick",
956
+ thought: plan2.thought,
957
+ locate: plan2.locate,
958
+ executor: async (param, { element }) => {
959
+ (0, import_utils6.assert)(element, "Element not found, cannot right click");
960
+ await this.page.mouse.click(
961
+ element.center[0],
962
+ element.center[1],
963
+ { button: "right" }
964
+ );
965
+ }
966
+ };
967
+ tasks.push(taskActionRightClick);
925
968
  } else if (plan2.type === "Drag") {
926
969
  const taskActionDrag = {
927
970
  type: "Action",
@@ -1450,7 +1493,7 @@ var PageTaskExecutor = class {
1450
1493
  executor: taskExecutor
1451
1494
  };
1452
1495
  }
1453
- async createTypeQueryTask(type, demand) {
1496
+ async createTypeQueryTask(type, demand, opt) {
1454
1497
  const taskExecutor = new import_misoai_core.Executor(
1455
1498
  taskTitleStr(
1456
1499
  type,
@@ -1481,7 +1524,10 @@ var PageTaskExecutor = class {
1481
1524
  result: `${type}, ${demand}`
1482
1525
  };
1483
1526
  }
1484
- const { data, usage } = await this.insight.extract(demandInput);
1527
+ const { data, usage } = await this.insight.extract(
1528
+ demandInput,
1529
+ opt
1530
+ );
1485
1531
  let outputResult = data;
1486
1532
  if (ifTypeRestricted) {
1487
1533
  (0, import_utils6.assert)(data?.result !== void 0, "No result in query data");
@@ -1501,17 +1547,17 @@ var PageTaskExecutor = class {
1501
1547
  executor: taskExecutor
1502
1548
  };
1503
1549
  }
1504
- async query(demand) {
1505
- return this.createTypeQueryTask("Query", demand);
1550
+ async query(demand, opt) {
1551
+ return this.createTypeQueryTask("Query", demand, opt);
1506
1552
  }
1507
- async boolean(prompt) {
1508
- return this.createTypeQueryTask("Boolean", prompt);
1553
+ async boolean(prompt, opt) {
1554
+ return this.createTypeQueryTask("Boolean", prompt, opt);
1509
1555
  }
1510
- async number(prompt) {
1511
- return this.createTypeQueryTask("Number", prompt);
1556
+ async number(prompt, opt) {
1557
+ return this.createTypeQueryTask("Number", prompt, opt);
1512
1558
  }
1513
- async string(prompt) {
1514
- return this.createTypeQueryTask("String", prompt);
1559
+ async string(prompt, opt) {
1560
+ return this.createTypeQueryTask("String", prompt, opt);
1515
1561
  }
1516
1562
  async assert(assertion) {
1517
1563
  const description = `assert: ${assertion}`;
@@ -1647,7 +1693,7 @@ function buildPlans(type, locateParam, param) {
1647
1693
  param: locateParam,
1648
1694
  thought: ""
1649
1695
  } : null;
1650
- if (type === "Tap" || type === "Hover") {
1696
+ if (type === "Tap" || type === "Hover" || type === "RightClick") {
1651
1697
  (0, import_utils8.assert)(locateParam, `missing locate info for action "${type}"`);
1652
1698
  (0, import_utils8.assert)(locatePlan, `missing locate info for action "${type}"`);
1653
1699
  const tapPlan = {
@@ -1727,7 +1773,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
1727
1773
  var import_semver = __toESM(require("semver"));
1728
1774
 
1729
1775
  // package.json
1730
- var version = "1.5.6";
1776
+ var version = "1.0.3";
1731
1777
 
1732
1778
  // src/common/task-cache.ts
1733
1779
  var debug3 = (0, import_logger3.getDebug)("cache");
@@ -1858,8 +1904,14 @@ cache file: ${cacheFile}`
1858
1904
  return;
1859
1905
  }
1860
1906
  try {
1907
+ const dir = (0, import_node_path2.dirname)(this.cacheFilePath);
1908
+ if (!(0, import_node_fs2.existsSync)(dir)) {
1909
+ (0, import_node_fs2.mkdirSync)(dir, { recursive: true });
1910
+ debug3("created cache directory: %s", dir);
1911
+ }
1861
1912
  const yamlData = import_js_yaml3.default.dump(this.cache);
1862
1913
  (0, import_node_fs2.writeFileSync)(this.cacheFilePath, yamlData);
1914
+ debug3("cache flushed to file: %s", this.cacheFilePath);
1863
1915
  } catch (err) {
1864
1916
  debug3(
1865
1917
  "write cache to file failed, path: %s, error: %s",
@@ -2117,6 +2169,23 @@ var PageAgent = class {
2117
2169
  metadata
2118
2170
  };
2119
2171
  }
2172
+ async aiRightClick(locatePrompt, opt) {
2173
+ const detailedLocateParam = this.buildDetailedLocateParam(
2174
+ locatePrompt,
2175
+ opt
2176
+ );
2177
+ const plans = buildPlans("RightClick", detailedLocateParam);
2178
+ const { executor, output } = await this.taskExecutor.runPlans(
2179
+ taskTitleStr("RightClick", locateParamStr(detailedLocateParam)),
2180
+ plans,
2181
+ { cacheable: opt?.cacheable }
2182
+ );
2183
+ const metadata = this.afterTaskRunning(executor);
2184
+ return {
2185
+ result: output,
2186
+ metadata
2187
+ };
2188
+ }
2120
2189
  async aiInput(value, locatePrompt, opt) {
2121
2190
  (0, import_utils12.assert)(
2122
2191
  typeof value === "string",
@@ -2548,6 +2617,40 @@ ${errors}`);
2548
2617
  }
2549
2618
  throw new Error("evaluateJavaScript is not supported in current agent");
2550
2619
  }
2620
+ async logScreenshot(title, options) {
2621
+ const screenshotTitle = title || "untitled";
2622
+ const content = options?.content || "";
2623
+ const screenshot = await this.page.screenshotBase64?.();
2624
+ if (screenshot) {
2625
+ const executionDump = {
2626
+ name: screenshotTitle,
2627
+ description: content,
2628
+ tasks: [{
2629
+ type: "Screenshot",
2630
+ subType: "log",
2631
+ status: "finished",
2632
+ executor: null,
2633
+ param: {
2634
+ title: screenshotTitle,
2635
+ content
2636
+ },
2637
+ output: {
2638
+ screenshot
2639
+ },
2640
+ thought: `Logged screenshot: ${screenshotTitle}`,
2641
+ timing: {
2642
+ start: Date.now(),
2643
+ end: Date.now(),
2644
+ cost: 0
2645
+ }
2646
+ }],
2647
+ sdkVersion: "1.0.0",
2648
+ logTime: Date.now(),
2649
+ model_name: "screenshot"
2650
+ };
2651
+ this.appendExecutionDump(executionDump);
2652
+ }
2653
+ }
2551
2654
  async destroy() {
2552
2655
  await this.page.destroy();
2553
2656
  }
@@ -2768,7 +2871,7 @@ function sleep2(ms) {
2768
2871
  var ChromeExtensionProxyPage = class {
2769
2872
  constructor(forceSameTabNavigation) {
2770
2873
  this.pageType = "chrome-extension-proxy";
2771
- this.version = "1.5.6";
2874
+ this.version = "1.0.3";
2772
2875
  this.activeTabId = null;
2773
2876
  this.tabIdOfDebuggerAttached = null;
2774
2877
  this.attachingDebugger = null;
@@ -2777,7 +2880,8 @@ var ChromeExtensionProxyPage = class {
2777
2880
  this.latestMouseX = 100;
2778
2881
  this.latestMouseY = 100;
2779
2882
  this.mouse = {
2780
- click: async (x, y) => {
2883
+ click: async (x, y, options) => {
2884
+ const { button = "left", count = 1 } = options || {};
2781
2885
  await this.mouse.move(x, y);
2782
2886
  if (this.isMobileEmulation === null) {
2783
2887
  const result = await this.sendCommandToDebugger("Runtime.evaluate", {
@@ -2788,7 +2892,7 @@ var ChromeExtensionProxyPage = class {
2788
2892
  });
2789
2893
  this.isMobileEmulation = result?.result?.value;
2790
2894
  }
2791
- if (this.isMobileEmulation) {
2895
+ if (this.isMobileEmulation && button === "left") {
2792
2896
  const touchPoints = [{ x: Math.round(x), y: Math.round(y) }];
2793
2897
  await this.sendCommandToDebugger("Input.dispatchTouchEvent", {
2794
2898
  type: "touchStart",
@@ -2805,15 +2909,15 @@ var ChromeExtensionProxyPage = class {
2805
2909
  type: "mousePressed",
2806
2910
  x,
2807
2911
  y,
2808
- button: "left",
2809
- clickCount: 1
2912
+ button,
2913
+ clickCount: count
2810
2914
  });
2811
2915
  await this.sendCommandToDebugger("Input.dispatchMouseEvent", {
2812
2916
  type: "mouseReleased",
2813
2917
  x,
2814
2918
  y,
2815
- button: "left",
2816
- clickCount: 1
2919
+ button,
2920
+ clickCount: count
2817
2921
  });
2818
2922
  }
2819
2923
  },