mouse.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var mouse_exports = {};
  20. __export(mouse_exports, {
  21. default: () => mouse_default
  22. });
  23. module.exports = __toCommonJS(mouse_exports);
  24. var import_bundle = require("../../sdk/bundle");
  25. var import_tool = require("./tool");
  26. const elementSchema = import_bundle.z.object({
  27. element: import_bundle.z.string().describe("Human-readable element description used to obtain permission to interact with the element")
  28. });
  29. const mouseMove = (0, import_tool.defineTabTool)({
  30. capability: "vision",
  31. schema: {
  32. name: "browser_mouse_move_xy",
  33. title: "Move mouse",
  34. description: "Move mouse to a given position",
  35. inputSchema: elementSchema.extend({
  36. x: import_bundle.z.number().describe("X coordinate"),
  37. y: import_bundle.z.number().describe("Y coordinate")
  38. }),
  39. type: "input"
  40. },
  41. handle: async (tab, params, response) => {
  42. response.addCode(`// Move mouse to (${params.x}, ${params.y})`);
  43. response.addCode(`await page.mouse.move(${params.x}, ${params.y});`);
  44. await tab.waitForCompletion(async () => {
  45. await tab.page.mouse.move(params.x, params.y);
  46. });
  47. }
  48. });
  49. const mouseClick = (0, import_tool.defineTabTool)({
  50. capability: "vision",
  51. schema: {
  52. name: "browser_mouse_click_xy",
  53. title: "Click",
  54. description: "Click left mouse button at a given position",
  55. inputSchema: elementSchema.extend({
  56. x: import_bundle.z.number().describe("X coordinate"),
  57. y: import_bundle.z.number().describe("Y coordinate")
  58. }),
  59. type: "input"
  60. },
  61. handle: async (tab, params, response) => {
  62. response.setIncludeSnapshot();
  63. response.addCode(`// Click mouse at coordinates (${params.x}, ${params.y})`);
  64. response.addCode(`await page.mouse.move(${params.x}, ${params.y});`);
  65. response.addCode(`await page.mouse.down();`);
  66. response.addCode(`await page.mouse.up();`);
  67. await tab.waitForCompletion(async () => {
  68. await tab.page.mouse.move(params.x, params.y);
  69. await tab.page.mouse.down();
  70. await tab.page.mouse.up();
  71. });
  72. }
  73. });
  74. const mouseDrag = (0, import_tool.defineTabTool)({
  75. capability: "vision",
  76. schema: {
  77. name: "browser_mouse_drag_xy",
  78. title: "Drag mouse",
  79. description: "Drag left mouse button to a given position",
  80. inputSchema: elementSchema.extend({
  81. startX: import_bundle.z.number().describe("Start X coordinate"),
  82. startY: import_bundle.z.number().describe("Start Y coordinate"),
  83. endX: import_bundle.z.number().describe("End X coordinate"),
  84. endY: import_bundle.z.number().describe("End Y coordinate")
  85. }),
  86. type: "input"
  87. },
  88. handle: async (tab, params, response) => {
  89. response.setIncludeSnapshot();
  90. response.addCode(`// Drag mouse from (${params.startX}, ${params.startY}) to (${params.endX}, ${params.endY})`);
  91. response.addCode(`await page.mouse.move(${params.startX}, ${params.startY});`);
  92. response.addCode(`await page.mouse.down();`);
  93. response.addCode(`await page.mouse.move(${params.endX}, ${params.endY});`);
  94. response.addCode(`await page.mouse.up();`);
  95. await tab.waitForCompletion(async () => {
  96. await tab.page.mouse.move(params.startX, params.startY);
  97. await tab.page.mouse.down();
  98. await tab.page.mouse.move(params.endX, params.endY);
  99. await tab.page.mouse.up();
  100. });
  101. }
  102. });
  103. var mouse_default = [
  104. mouseMove,
  105. mouseClick,
  106. mouseDrag
  107. ];