UNPKG

@auto-browse/auto-browse

Version:
42 lines (41 loc) 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.browser_click = 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 clicking elements with descriptions for the AI model */ const clickSchema = zod_1.z.object({ element: zod_1.z .string() .describe("Human-readable element description for the target element"), ref: zod_1.z .string() .describe("Element reference from page snapshot to locate the element"), }); exports.browser_click = (0, tools_1.tool)(async ({ element, ref }) => { try { console.log(`[Click Tool] Starting operation:`, { element, ref }); const result = await test_1.test.step(`Click "${element}"`, async () => { return await (0, utils_1.runAndWait)(context_1.context, `Clicked "${element}"`, async () => { const locator = context_1.context.refLocator(ref); await locator.click(); }, true); }); console.log(`[Click Tool] Operation completed with result:`, result); return result; } catch (error) { const errorMessage = `Failed to click: ${error instanceof Error ? error.message : "Unknown error"}`; console.error(`[Click Tool] Error:`, errorMessage); return errorMessage; } }, { name: "click", description: "Click an element on the page", schema: clickSchema, });