UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

40 lines 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChooseSelectOptionTool = exports.ChooseSelectOptionGptSchema = exports.ChooseSelectOptionNonGptSchema = exports.ChooseSelectOptionCoreSchema = void 0; const v4_1 = require("zod/v4"); const TargetUtils_1 = require("../utils/TargetUtils"); const ReplayableInteraction_1 = require("./ReplayableInteraction"); exports.ChooseSelectOptionCoreSchema = v4_1.z.object({ optionValues: v4_1.z .array(v4_1.z.string()) .min(1) .describe('The <option> values to choose'), }); exports.ChooseSelectOptionNonGptSchema = v4_1.z.object({ ...ReplayableInteraction_1.SelectorBasedSchema.shape, ...exports.ChooseSelectOptionCoreSchema.shape, }); exports.ChooseSelectOptionGptSchema = v4_1.z.object({ ...ReplayableInteraction_1.AnnotationBasedSchema.shape, ...exports.ChooseSelectOptionCoreSchema.shape, }); class ChooseSelectOptionTool extends ReplayableInteraction_1.ReplayableInteraction { constructor() { super(ChooseSelectOptionTool.NAME, `Choose <option> values for a particular <select> HTML element. Note that this tool can ONLY be used with a <select> HTML element.`, exports.ChooseSelectOptionCoreSchema, exports.ChooseSelectOptionNonGptSchema, exports.ChooseSelectOptionGptSchema); } async invoke(context, parameters, handles) { await context.interactionVisualizer.pointAt((0, TargetUtils_1.webPage)(context), handles.target); // ReplayableInteraction may surface a label handle for labelable elements. // Playwright delegates clicks from <label> to its control, but selectOption must // be invoked on an actual <select> element. Using the raw target avoids the // "Element is not a <select> element" error when the locator resolved to a label. const selectedValues = await handles.target.selectOption(parameters.optionValues, { timeout: 3000, }); return `Selected the ${selectedValues} value${selectedValues.length > 1 ? 's' : ''} from: `; } } exports.ChooseSelectOptionTool = ChooseSelectOptionTool; ChooseSelectOptionTool.NAME = 'chooseSelectOption'; //# sourceMappingURL=ChooseSelectOptionTool.js.map