UNPKG

donobu

Version:

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

70 lines 3.1 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RunAccessibilityTestTool = void 0; const playwright_1 = __importDefault(require("@axe-core/playwright")); const ToolSchema_1 = require("../models/ToolSchema"); const TargetUtils_1 = require("../utils/TargetUtils"); const Tool_1 = require("./Tool"); class RunAccessibilityTestTool extends Tool_1.Tool { constructor() { super(RunAccessibilityTestTool.NAME, 'Run an web accessibility (axe-core) test on the current webpage.', ToolSchema_1.NoArgsSchema, ToolSchema_1.BaseGptArgsSchema, false, undefined, ['web']); } async call(context, _parameters) { const page = (0, TargetUtils_1.webPage)(context); const axe = new playwright_1.default({ page }); // Step 1: Run the analysis. const result = await axe.analyze(); const fullResult = { violations: result.violations, incomplete: result.incomplete, passCount: result.passes.length, ignoredRuleCount: result.inapplicable.length, totalRuleCount: result.violations.length + result.incomplete.length + result.passes.length + result.inapplicable.length, }; // Step 2: If nothing to report, short‑circuit if (fullResult.violations.length === 0 && fullResult.incomplete.length === 0) { return { isSuccessful: true, forLlm: `No accessibility violations or items needing review found. (${fullResult.passCount} checks passed)`, metadata: fullResult, }; } // Step 3: Summarise violations and incomplete items const countByHelp = (items, map) => { for (const item of items) { map.set(item.help, (map.get(item.help) ?? 0) + item.nodes.length); } }; const violationSummary = new Map(); const incompleteSummary = new Map(); countByHelp(fullResult.violations, violationSummary); countByHelp(fullResult.incomplete, incompleteSummary); // human‑readable summary const summaryLines = []; violationSummary.forEach((count, helpText) => { summaryLines.push(`${count}x violations - ${helpText}`); }); incompleteSummary.forEach((count, helpText) => { summaryLines.push(`${count}x needs manual review - ${helpText}`); }); summaryLines.push(`${fullResult.passCount} checks passed`); return { isSuccessful: true, forLlm: summaryLines.join('\n'), metadata: fullResult, }; } async callFromGpt(context, _parameters) { return this.call(context, {}); } } exports.RunAccessibilityTestTool = RunAccessibilityTestTool; RunAccessibilityTestTool.NAME = 'runAccessibilityTest'; //# sourceMappingURL=RunAccessibilityTestTool.js.map