@auto-browse/auto-browse
Version:
AI-powered browser automation
49 lines (48 loc) • 1.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.browser_select_option = 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 selecting options in dropdowns with descriptions for the AI model
*/
const selectOptionSchema = zod_1.z.object({
element: zod_1.z
.string()
.describe("Human-readable element description for the dropdown"),
ref: zod_1.z
.string()
.describe("Element reference from page snapshot to locate the dropdown"),
values: zod_1.z
.array(zod_1.z.string())
.describe("Array of values to select in the dropdown. Can be a single value or multiple values."),
});
exports.browser_select_option = (0, tools_1.tool)(async ({ element, ref, values }) => {
try {
console.log(`[Select Option Tool] Starting operation:`, {
element,
ref,
values,
});
const result = await test_1.test.step(`Select "${values}" in "${element}"`, async () => {
return await (0, utils_1.runAndWait)(context_1.context, `Selected options in "${element}"`, async () => {
const locator = context_1.context.refLocator(ref);
await locator.selectOption(values);
}, true);
});
console.log(`[Select Option Tool] Operation completed with result:`, result);
return result;
}
catch (error) {
const errorMessage = `Failed to select options: ${error instanceof Error ? error.message : "Unknown error"}`;
console.error(`[Select Option Tool] Error:`, errorMessage);
return errorMessage;
}
}, {
name: "selectOption",
description: "Select one or more options in a dropdown element",
schema: selectOptionSchema,
});