@hyperbrowser/agent
Version:
Hyperbrowsers Web Agent
36 lines (35 loc) • 1.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.InputTextActionDefinition = exports.InputTextAction = void 0;
const zod_1 = require("zod");
const utils_1 = require("./utils");
exports.InputTextAction = zod_1.z
.object({
index: zod_1.z
.number()
.describe("The numeric index of the element to input text."),
text: zod_1.z.string().describe("The text to input."),
})
.describe("Input text into a input interactive element");
exports.InputTextActionDefinition = {
type: "inputText",
actionParams: exports.InputTextAction,
run: async (ctx, action) => {
let { index, text } = action;
const locator = (0, utils_1.getLocator)(ctx, index);
for (const variable of ctx.variables) {
text = text.replace(`<<${variable.key}>>`, variable.value);
}
if (!locator) {
return { success: false, message: "Element not found" };
}
await locator.fill(text, { timeout: 5000 });
return {
success: true,
message: `Inputted text "${text}" into element with index ${index}`,
};
},
pprintAction: function (params) {
return `Input text "${params.text}" into element at index ${params.index}`;
},
};