UNPKG

@auto-browse/auto-browse

Version:
54 lines (53 loc) 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.browser_drag = void 0; const tools_1 = require("@langchain/core/tools"); const zod_1 = require("zod"); const test_1 = require("@playwright/test"); const utils_1 = require("./utils"); const context_1 = require("../browser/context"); /** * Schema for drag and drop operations with descriptions for the AI model */ const dragSchema = zod_1.z.object({ startElement: zod_1.z .string() .describe("Human-readable source element description for the element to drag"), startRef: zod_1.z .string() .describe("Source element reference from page snapshot to locate the draggable element"), endElement: zod_1.z .string() .describe("Human-readable target element description for the drop target"), endRef: zod_1.z .string() .describe("Target element reference from page snapshot to locate the drop target"), }); exports.browser_drag = (0, tools_1.tool)(async ({ startElement, startRef, endElement, endRef }) => { try { console.log(`[Drag Tool] Starting operation:`, { startElement, startRef, endElement, endRef, }); const result = await test_1.test.step(`Drag "${startElement}" to "${endElement}"`, async () => { return await (0, utils_1.runAndWait)(context_1.context, `Dragged "${startElement}" to "${endElement}"`, async () => { const startLocator = context_1.context.refLocator(startRef); const endLocator = context_1.context.refLocator(endRef); await startLocator.dragTo(endLocator); }, true); }); console.log(`[Drag Tool] Operation completed with result:`, result); return result; } catch (error) { const errorMessage = `Failed to drag: ${error instanceof Error ? error.message : "Unknown error"}`; console.error(`[Drag Tool] Error:`, errorMessage); return errorMessage; } }, { name: "drag", description: "Drag and drop an element to a target location on the page", schema: dragSchema, });