UNPKG

@auto-browse/auto-browse

Version:
38 lines (37 loc) 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.browser_press_key = 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 pressing keyboard keys */ const pressKeySchema = zod_1.z.object({ key: zod_1.z .string() .describe("Name of the key to press or a character to generate, such as `ArrowLeft` or `a`"), }); exports.browser_press_key = (0, tools_1.tool)(async ({ key }) => { try { console.log(`[Press Key Tool] Starting operation:`, { key }); const result = await test_1.test.step(`Press key ${key}`, async () => { return await (0, utils_1.runAndWait)(context_1.context, `Pressed key ${key}`, async (page) => { await page.keyboard.press(key); }, true); }); console.log(`[Press Key Tool] Operation completed`); return result; } catch (error) { const errorMessage = `Failed to press key: ${error instanceof Error ? error.message : "Unknown error"}`; console.error(`[Press Key Tool] Error:`, errorMessage); return errorMessage; } }, { name: "pressKey", description: "Press a key on the keyboard", schema: pressKeySchema, });