UNPKG

donobu

Version:

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

48 lines 1.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InputTextTool = void 0; const ReplayableInteraction_1 = require("./ReplayableInteraction"); const MiscUtils_1 = require("../utils/MiscUtils"); class InputTextTool extends ReplayableInteraction_1.ReplayableInteraction { constructor() { super(InputTextTool.NAME, "Input text to a webpage's text input box.", 'SelectorBasedInputTextToolParameters', 'AnnotationBasedInputTextToolParameters'); } async invoke(_context, parameters, element) { // Clear any existing text first. await this.clearField(element); for (const char of parameters.text) { await element.press(char, { delay: MiscUtils_1.MiscUtils.generateHumanLikeKeyPressDurationInMs(char), timeout: 3000, }); } if (parameters.finalizeWithSubmit) { const char = 'Enter'; await element.press(char, { delay: MiscUtils_1.MiscUtils.generateHumanLikeKeyPressDurationInMs(char), timeout: 3000, }); } return 'Inputted text into the element.'; } async clearField(element) { try { const value = await element.inputValue(); if (value !== '') { await element.selectText({ timeout: 3000 }); const char = 'Backspace'; await element.press(char, { delay: MiscUtils_1.MiscUtils.generateHumanLikeKeyPressDurationInMs(char), timeout: 3000, }); } } catch (_e) { // This can happen if the element is not a text element, but still accepts text inputs. // Pass. } } } exports.InputTextTool = InputTextTool; InputTextTool.NAME = 'inputText'; //# sourceMappingURL=InputTextTool.js.map