UNPKG

donobu

Version:

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

53 lines 2.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AssertPageTextTool = exports.AssertPageTextGptParameters = exports.AssertPageTextCoreParameters = void 0; const v4_1 = require("zod/v4"); const ToolCallResult_1 = require("../models/ToolCallResult"); const ToolSchema_1 = require("../models/ToolSchema"); const TargetUtils_1 = require("../utils/TargetUtils"); const Tool_1 = require("./Tool"); exports.AssertPageTextCoreParameters = v4_1.z.object({ text: v4_1.z .string() .describe('The text to check visibility for in the current page.'), }); exports.AssertPageTextGptParameters = v4_1.z.object({ ...ToolSchema_1.BaseGptArgsSchema.shape, ...exports.AssertPageTextCoreParameters.shape, }); class AssertPageTextTool extends Tool_1.Tool { constructor() { super(AssertPageTextTool.NAME, 'This method will test that the given text is visible in the current page.', exports.AssertPageTextCoreParameters, exports.AssertPageTextGptParameters, false, undefined, ['web']); } async call(context, parameters) { const locator = (0, TargetUtils_1.webPage)(context).getByText(parameters.text); const count = await locator.count(); const elementWasFoundWithText = count > 0; for (let i = 0; i < count; ++i) { const element = locator.nth(i); if (await element.isVisible()) { return ToolCallResult_1.ToolCallResult.successful(); } } if (elementWasFoundWithText) { return { isSuccessful: false, forLlm: `The text "${parameters.text}" was found in the page, but its containing element was not visible.`, metadata: null, }; } else { return { isSuccessful: false, forLlm: `Failed to find the text "${parameters.text}" anywhere in the page.`, metadata: null, }; } } async callFromGpt(context, parameters) { return this.call(context, parameters); } } exports.AssertPageTextTool = AssertPageTextTool; AssertPageTextTool.NAME = 'assertPageText'; //# sourceMappingURL=AssertPageTextTool.js.map