@empiricalrun/test-gen 0.45.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/actions/assert.d.ts +2 -2
- package/dist/actions/assert.d.ts.map +1 -1
- package/dist/actions/assert.js +1 -2
- package/dist/actions/click.d.ts +2 -2
- package/dist/actions/click.d.ts.map +1 -1
- package/dist/actions/click.js +1 -2
- package/dist/actions/done.d.ts +2 -2
- package/dist/actions/done.d.ts.map +1 -1
- package/dist/actions/fill.d.ts +2 -2
- package/dist/actions/fill.d.ts.map +1 -1
- package/dist/actions/fill.js +1 -2
- package/dist/actions/goto.d.ts +2 -2
- package/dist/actions/goto.d.ts.map +1 -1
- package/dist/actions/hover.d.ts +2 -2
- package/dist/actions/hover.d.ts.map +1 -1
- package/dist/actions/hover.js +3 -3
- package/dist/actions/index.d.ts +2 -2
- package/dist/actions/index.d.ts.map +1 -1
- package/dist/actions/press.d.ts +2 -2
- package/dist/actions/press.d.ts.map +1 -1
- package/dist/actions/skill.d.ts +2 -2
- package/dist/actions/skill.d.ts.map +1 -1
- package/dist/actions/skill.js +2 -3
- package/dist/actions/text-content.d.ts +3 -3
- package/dist/actions/text-content.d.ts.map +1 -1
- package/dist/actions/text-content.js +12 -13
- package/dist/agent/master/browser-tests/index.spec.js +8 -1
- package/dist/agent/master/element-annotation.d.ts +2 -1
- package/dist/agent/master/element-annotation.d.ts.map +1 -1
- package/dist/agent/master/element-annotation.js +45 -12
- package/dist/agent/master/icon-descriptor/index.d.ts +22 -0
- package/dist/agent/master/icon-descriptor/index.d.ts.map +1 -0
- package/dist/agent/master/icon-descriptor/index.js +211 -0
- package/dist/agent/master/icon-descriptor/normalize-svg.d.ts +2 -0
- package/dist/agent/master/icon-descriptor/normalize-svg.d.ts.map +1 -0
- package/dist/agent/master/icon-descriptor/normalize-svg.js +248 -0
- package/dist/agent/master/run.d.ts.map +1 -1
- package/dist/agent/master/run.js +2 -1
- package/dist/agent/master/scroller.d.ts.map +1 -1
- package/dist/agent/master/scroller.js +1 -0
- package/dist/agent/planner/run-time-planner.d.ts +2 -9
- package/dist/agent/planner/run-time-planner.d.ts.map +1 -1
- package/dist/agent/planner/run-time-planner.js +9 -46
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -26
- package/dist/types/index.d.ts +46 -5
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getIconDescription = exports.createNodeFromHTML = exports.reverseKey = exports.generateKey = exports.saveIconsKnowledge = exports.loadIconsKnowledge = void 0;
|
|
7
|
+
const llm_1 = require("@empiricalrun/llm");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const jsdom_1 = require("jsdom");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const constants_1 = require("../../../constants");
|
|
12
|
+
const normalize_svg_1 = require("./normalize-svg");
|
|
13
|
+
const ICONS_KNOWLEDGE_PATH = path_1.default.join(process.cwd(), "icons.json");
|
|
14
|
+
function loadIconsKnowledge() {
|
|
15
|
+
if (!fs_1.default.existsSync(ICONS_KNOWLEDGE_PATH)) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
const raw = fs_1.default.readFileSync(ICONS_KNOWLEDGE_PATH, "utf-8");
|
|
19
|
+
if (raw) {
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(raw);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
console.log("error parsing iconsKnowledge json");
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
exports.loadIconsKnowledge = loadIconsKnowledge;
|
|
31
|
+
async function saveIconsKnowledge(iconsData) {
|
|
32
|
+
const content = JSON.stringify(iconsData, null, 2);
|
|
33
|
+
fs_1.default.writeFileSync(ICONS_KNOWLEDGE_PATH, content, "utf-8");
|
|
34
|
+
}
|
|
35
|
+
exports.saveIconsKnowledge = saveIconsKnowledge;
|
|
36
|
+
function generateKey(htmlString) {
|
|
37
|
+
const normalized = (0, normalize_svg_1.normalizeSVG)(htmlString);
|
|
38
|
+
// generate base64 string
|
|
39
|
+
const encoded = Buffer.from(normalized).toString("base64");
|
|
40
|
+
return `icon_${encoded}`;
|
|
41
|
+
}
|
|
42
|
+
exports.generateKey = generateKey;
|
|
43
|
+
function reverseKey(hash) {
|
|
44
|
+
const encoded = hash.replace(/^icon_/, "");
|
|
45
|
+
return Buffer.from(encoded, "base64").toString();
|
|
46
|
+
}
|
|
47
|
+
exports.reverseKey = reverseKey;
|
|
48
|
+
function createNodeFromHTML(htmlString) {
|
|
49
|
+
const dom = new jsdom_1.JSDOM(htmlString);
|
|
50
|
+
const document = dom.window.document;
|
|
51
|
+
const node = document.body.firstElementChild;
|
|
52
|
+
return {
|
|
53
|
+
node, // Return the first node
|
|
54
|
+
children: node?.children ? Array.from(node.children) : [], // Convert HTMLCollection to array
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.createNodeFromHTML = createNodeFromHTML;
|
|
58
|
+
function processSvgWithUseElements(svgElement, document) {
|
|
59
|
+
try {
|
|
60
|
+
const useElements = svgElement.querySelectorAll("use");
|
|
61
|
+
for (const useEl of Array.from(useElements)) {
|
|
62
|
+
const href = useEl.getAttribute("href") || useEl.getAttribute("xlink:href");
|
|
63
|
+
if (!href)
|
|
64
|
+
continue;
|
|
65
|
+
const id = href.startsWith("#") ? href.substring(1) : href;
|
|
66
|
+
const referencedElement = document.getElementById(id);
|
|
67
|
+
if (referencedElement) {
|
|
68
|
+
if (referencedElement.tagName.toLowerCase() === "symbol" ||
|
|
69
|
+
referencedElement.tagName.toLowerCase() === "svg") {
|
|
70
|
+
const group = document.createElement("g");
|
|
71
|
+
Array.from(useEl.attributes).forEach((attr) => {
|
|
72
|
+
if (attr.name !== "href" && attr.name !== "xlink:href") {
|
|
73
|
+
group.setAttribute(attr.name, attr.value);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
if (referencedElement.hasAttribute("viewBox")) {
|
|
77
|
+
group.setAttribute("viewBox", referencedElement.getAttribute("viewBox") || "");
|
|
78
|
+
}
|
|
79
|
+
group.innerHTML = referencedElement.innerHTML;
|
|
80
|
+
useEl.parentNode?.replaceChild(group, useEl);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
console.error("Error processing SVG with use elements:", error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Extracts and returns an SVG element from a given HTML string.
|
|
91
|
+
*
|
|
92
|
+
* This function checks whether the provided HTML string contains an SVG element
|
|
93
|
+
* either as the root node or as a child node.
|
|
94
|
+
*/
|
|
95
|
+
function getHtmlForDescription(elementHtml, pageHtml) {
|
|
96
|
+
const dom = new jsdom_1.JSDOM(pageHtml);
|
|
97
|
+
const page = dom.window.document;
|
|
98
|
+
const { node, children } = createNodeFromHTML(elementHtml);
|
|
99
|
+
if (!node) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
if (node.tagName.toLowerCase() === "svg") {
|
|
103
|
+
processSvgWithUseElements(node, page);
|
|
104
|
+
return node.outerHTML;
|
|
105
|
+
}
|
|
106
|
+
const svgChildren = children?.filter((child) => child?.tagName?.toLowerCase() === "svg");
|
|
107
|
+
if (svgChildren && svgChildren.length > 0) {
|
|
108
|
+
for (const svgChild of svgChildren) {
|
|
109
|
+
processSvgWithUseElements(svgChild, page);
|
|
110
|
+
}
|
|
111
|
+
return node.outerHTML;
|
|
112
|
+
}
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
async function describeSVGElementWithLLM({ element, trace, }) {
|
|
116
|
+
try {
|
|
117
|
+
const svgDescriptionSpan = trace?.span({
|
|
118
|
+
name: "get-svg-description",
|
|
119
|
+
input: {
|
|
120
|
+
element,
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
const messages = [
|
|
124
|
+
{
|
|
125
|
+
role: "system",
|
|
126
|
+
content: `
|
|
127
|
+
You are an expert at reading svg icons. You are given a task to provide the description of an icon based on the given HTML element string.
|
|
128
|
+
If the string does not contain any svg element, return NA.
|
|
129
|
+
`,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
role: "user",
|
|
133
|
+
content: `
|
|
134
|
+
Provide the description of below element:
|
|
135
|
+
${element}
|
|
136
|
+
|
|
137
|
+
Follow below steps to provide the description:
|
|
138
|
+
- Identify the svg element in the given HTML string
|
|
139
|
+
- If the string does not contain any svg element, return NA
|
|
140
|
+
- Else, read the svg element and provide a single line description for the element
|
|
141
|
+
- The description should be precise and readable
|
|
142
|
+
- Only provide the element description and nothing else
|
|
143
|
+
`,
|
|
144
|
+
},
|
|
145
|
+
];
|
|
146
|
+
const llm = new llm_1.LLM({
|
|
147
|
+
trace: svgDescriptionSpan,
|
|
148
|
+
provider: "anthropic",
|
|
149
|
+
defaultModel: "claude-3-5-sonnet-latest",
|
|
150
|
+
providerApiKey: constants_1.MODEL_API_KEYS["anthropic"],
|
|
151
|
+
});
|
|
152
|
+
const svgDescription = await llm.createChatCompletion({
|
|
153
|
+
messages,
|
|
154
|
+
modelParameters: {
|
|
155
|
+
temperature: 0.3,
|
|
156
|
+
},
|
|
157
|
+
responseFormat: {
|
|
158
|
+
type: "json_schema",
|
|
159
|
+
json_schema: {
|
|
160
|
+
name: "describe-svg-element",
|
|
161
|
+
strict: true,
|
|
162
|
+
schema: {
|
|
163
|
+
type: "object",
|
|
164
|
+
properties: {
|
|
165
|
+
description: {
|
|
166
|
+
type: "string",
|
|
167
|
+
description: "A clear description of what the SVG visually represents",
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
additionalProperties: false,
|
|
171
|
+
required: ["description"],
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
svgDescriptionSpan?.end({ output: svgDescription });
|
|
177
|
+
return svgDescription?.content ?? undefined;
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
console.error(`Error generating svg description ${err}`);
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async function getIconDescription({ htmlString, pageHtml, trace, }) {
|
|
185
|
+
const elementStringForDescription = getHtmlForDescription(htmlString, pageHtml);
|
|
186
|
+
if (!elementStringForDescription) {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
const key = generateKey(elementStringForDescription);
|
|
190
|
+
const iconsData = loadIconsKnowledge();
|
|
191
|
+
const cachedIcon = iconsData.find((icon) => icon.key === key);
|
|
192
|
+
if (cachedIcon) {
|
|
193
|
+
return cachedIcon.description;
|
|
194
|
+
}
|
|
195
|
+
const description = await describeSVGElementWithLLM({
|
|
196
|
+
element: elementStringForDescription,
|
|
197
|
+
trace,
|
|
198
|
+
});
|
|
199
|
+
if (description) {
|
|
200
|
+
const newIconEntry = {
|
|
201
|
+
description,
|
|
202
|
+
key,
|
|
203
|
+
normalized: htmlString,
|
|
204
|
+
createdAt: new Date(),
|
|
205
|
+
};
|
|
206
|
+
iconsData.push(newIconEntry);
|
|
207
|
+
await saveIconsKnowledge(iconsData);
|
|
208
|
+
}
|
|
209
|
+
return description;
|
|
210
|
+
}
|
|
211
|
+
exports.getIconDescription = getIconDescription;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-svg.d.ts","sourceRoot":"","sources":["../../../../src/agent/master/icon-descriptor/normalize-svg.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CA8BpD"}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeSVG = void 0;
|
|
4
|
+
const jsdom_1 = require("jsdom");
|
|
5
|
+
function normalizeSVG(svgHtml) {
|
|
6
|
+
// Parse the SVG HTML into a DOM structure using JSDOM
|
|
7
|
+
const dom = new jsdom_1.JSDOM(svgHtml);
|
|
8
|
+
const document = dom.window.document;
|
|
9
|
+
const svgElement = document.querySelector("svg");
|
|
10
|
+
if (!svgElement) {
|
|
11
|
+
throw new Error("No SVG element found in the provided HTML");
|
|
12
|
+
}
|
|
13
|
+
// Normalize whitespace and formatting
|
|
14
|
+
normalizeWhitespace(svgElement);
|
|
15
|
+
// Normalize attribute order
|
|
16
|
+
normalizeAttributeOrder(svgElement);
|
|
17
|
+
// Normalize transform values
|
|
18
|
+
normalizeTransforms(svgElement);
|
|
19
|
+
// Normalize color formats (convert rgb to hex, standardize hex case)
|
|
20
|
+
normalizeColors(svgElement);
|
|
21
|
+
// Normalize path data (standardize spacing, remove redundant commands)
|
|
22
|
+
normalizePaths(svgElement);
|
|
23
|
+
// Normalize viewBox and preserveAspectRatio
|
|
24
|
+
normalizeViewBox(svgElement);
|
|
25
|
+
// Return the normalized SVG string
|
|
26
|
+
return svgElement.outerHTML;
|
|
27
|
+
}
|
|
28
|
+
exports.normalizeSVG = normalizeSVG;
|
|
29
|
+
/**
|
|
30
|
+
* Normalizes whitespace in SVG element
|
|
31
|
+
* @param element - The element to normalize
|
|
32
|
+
*/
|
|
33
|
+
function normalizeWhitespace(element) {
|
|
34
|
+
// Convert text nodes to have consistent spacing
|
|
35
|
+
const walkNodes = (node) => {
|
|
36
|
+
if (node.nodeType === 3) {
|
|
37
|
+
// TEXT_NODE
|
|
38
|
+
if (node.textContent?.trim() === "") {
|
|
39
|
+
node.textContent = "";
|
|
40
|
+
}
|
|
41
|
+
else if (node.textContent) {
|
|
42
|
+
node.textContent = node.textContent.trim().replace(/\s+/g, " ");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else if (node.nodeType === 1) {
|
|
46
|
+
// ELEMENT_NODE
|
|
47
|
+
for (let child of Array.from(node.childNodes)) {
|
|
48
|
+
walkNodes(child);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
walkNodes(element);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Normalizes attribute order on SVG elements
|
|
56
|
+
* @param element - The element to normalize
|
|
57
|
+
*/
|
|
58
|
+
function normalizeAttributeOrder(element) {
|
|
59
|
+
const walkElements = (node) => {
|
|
60
|
+
if (node.nodeType === 1) {
|
|
61
|
+
// ELEMENT_NODE
|
|
62
|
+
const elementNode = node;
|
|
63
|
+
// Get all attributes in a sorted array
|
|
64
|
+
const attributes = Array.from(elementNode.attributes);
|
|
65
|
+
const sortedAttributes = attributes.sort((a, b) => a.name.localeCompare(b.name));
|
|
66
|
+
// Remove all attributes
|
|
67
|
+
for (const attr of attributes) {
|
|
68
|
+
elementNode.removeAttribute(attr.name);
|
|
69
|
+
}
|
|
70
|
+
// Add them back in sorted order
|
|
71
|
+
for (const attr of sortedAttributes) {
|
|
72
|
+
elementNode.setAttribute(attr.name, attr.value);
|
|
73
|
+
}
|
|
74
|
+
// Process children
|
|
75
|
+
for (let child of Array.from(node.childNodes)) {
|
|
76
|
+
walkElements(child);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
walkElements(element);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Normalizes transform values to a consistent format
|
|
84
|
+
* @param element - The element to normalize
|
|
85
|
+
*/
|
|
86
|
+
function normalizeTransforms(element) {
|
|
87
|
+
const walkElements = (node) => {
|
|
88
|
+
if (node.nodeType === 1) {
|
|
89
|
+
// ELEMENT_NODE
|
|
90
|
+
const elementNode = node;
|
|
91
|
+
if (elementNode.hasAttribute("transform")) {
|
|
92
|
+
const transform = elementNode.getAttribute("transform");
|
|
93
|
+
if (transform) {
|
|
94
|
+
// Normalize transform by ensuring consistent spacing and order
|
|
95
|
+
const normalizedTransform = transform
|
|
96
|
+
.replace(/\s*,\s*/g, ",")
|
|
97
|
+
.replace(/\s+/g, " ")
|
|
98
|
+
.replace(/\(\s+/g, "(")
|
|
99
|
+
.replace(/\s+\)/g, ")");
|
|
100
|
+
elementNode.setAttribute("transform", normalizedTransform);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// Process children
|
|
104
|
+
for (let child of Array.from(node.childNodes)) {
|
|
105
|
+
walkElements(child);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
walkElements(element);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Normalizes color formats to consistent hex values
|
|
113
|
+
* @param element - The element to normalize
|
|
114
|
+
*/
|
|
115
|
+
function normalizeColors(element) {
|
|
116
|
+
const colorAttributes = ["fill", "stroke", "stop-color", "color"];
|
|
117
|
+
const convertRgbToHex = (rgb) => {
|
|
118
|
+
// Convert rgb(r, g, b) or rgba(r, g, b, a) to hex
|
|
119
|
+
const rgbMatch = rgb.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([0-9.]+))?\)/);
|
|
120
|
+
if (rgbMatch) {
|
|
121
|
+
const r = parseInt(rgbMatch[1], 10);
|
|
122
|
+
const g = parseInt(rgbMatch[2], 10);
|
|
123
|
+
const b = parseInt(rgbMatch[3], 10);
|
|
124
|
+
// Convert to hex
|
|
125
|
+
const toHex = (c) => {
|
|
126
|
+
const hex = c.toString(16);
|
|
127
|
+
return hex.length === 1 ? "0" + hex : hex;
|
|
128
|
+
};
|
|
129
|
+
let hexColor = "#" + toHex(r) + toHex(g) + toHex(b);
|
|
130
|
+
// If there's alpha, we need to handle it separately (SVG doesn't use hex for alpha)
|
|
131
|
+
if (rgbMatch[4] && rgbMatch[4] !== "1") {
|
|
132
|
+
// Keep original rgba format but with normalized spacing
|
|
133
|
+
return `rgba(${r},${g},${b},${parseFloat(rgbMatch[4])})`;
|
|
134
|
+
}
|
|
135
|
+
return hexColor.toLowerCase();
|
|
136
|
+
}
|
|
137
|
+
return rgb;
|
|
138
|
+
};
|
|
139
|
+
const normalizeHex = (hex) => {
|
|
140
|
+
// Ensure lowercase for hex colors
|
|
141
|
+
if (hex.match(/#[0-9a-fA-F]{3,8}/)) {
|
|
142
|
+
return hex.toLowerCase();
|
|
143
|
+
}
|
|
144
|
+
return hex;
|
|
145
|
+
};
|
|
146
|
+
const walkElements = (node) => {
|
|
147
|
+
if (node.nodeType === 1) {
|
|
148
|
+
// ELEMENT_NODE
|
|
149
|
+
const elementNode = node;
|
|
150
|
+
// Check for color attributes
|
|
151
|
+
for (const attr of colorAttributes) {
|
|
152
|
+
if (elementNode.hasAttribute(attr)) {
|
|
153
|
+
let value = elementNode.getAttribute(attr);
|
|
154
|
+
if (value) {
|
|
155
|
+
value = convertRgbToHex(value);
|
|
156
|
+
value = normalizeHex(value);
|
|
157
|
+
elementNode.setAttribute(attr, value);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// Check for style attribute with colors
|
|
162
|
+
if (elementNode.hasAttribute("style")) {
|
|
163
|
+
let style = elementNode.getAttribute("style");
|
|
164
|
+
if (style) {
|
|
165
|
+
// Replace any colors in the style attribute
|
|
166
|
+
for (const attr of colorAttributes) {
|
|
167
|
+
style = style.replace(new RegExp(`${attr}:\\s*([^;]+)`, "g"), (match, color) => {
|
|
168
|
+
const normalizedColor = normalizeHex(convertRgbToHex(color));
|
|
169
|
+
return `${attr}: ${normalizedColor}`;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
elementNode.setAttribute("style", style);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// Process children
|
|
176
|
+
for (let child of Array.from(node.childNodes)) {
|
|
177
|
+
walkElements(child);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
walkElements(element);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Normalizes SVG path data
|
|
185
|
+
* @param element - The element to normalize
|
|
186
|
+
*/
|
|
187
|
+
function normalizePaths(element) {
|
|
188
|
+
const walkElements = (node) => {
|
|
189
|
+
if (node.nodeType === 1) {
|
|
190
|
+
// ELEMENT_NODE
|
|
191
|
+
const elementNode = node;
|
|
192
|
+
if (elementNode.tagName.toLowerCase() === "path" &&
|
|
193
|
+
elementNode.hasAttribute("d")) {
|
|
194
|
+
const pathData = elementNode.getAttribute("d");
|
|
195
|
+
if (pathData) {
|
|
196
|
+
// Normalize spacing in path data
|
|
197
|
+
const normalizedPathData = pathData
|
|
198
|
+
.replace(/\s+/g, " ")
|
|
199
|
+
.replace(/\s*([MmLlHhVvCcSsQqTtAaZz])\s*/g, "$1")
|
|
200
|
+
.replace(/\s*,\s*/g, ",")
|
|
201
|
+
.trim();
|
|
202
|
+
elementNode.setAttribute("d", normalizedPathData);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Process children
|
|
206
|
+
for (let child of Array.from(node.childNodes)) {
|
|
207
|
+
walkElements(child);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
walkElements(element);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Normalizes viewBox and preserveAspectRatio attributes
|
|
215
|
+
* @param element - The element to normalize
|
|
216
|
+
*/
|
|
217
|
+
function normalizeViewBox(element) {
|
|
218
|
+
if (element.tagName.toLowerCase() === "svg") {
|
|
219
|
+
if (element.hasAttribute("viewBox")) {
|
|
220
|
+
const viewBoxAttr = element.getAttribute("viewBox");
|
|
221
|
+
if (viewBoxAttr) {
|
|
222
|
+
// Normalize viewBox format
|
|
223
|
+
const viewBox = viewBoxAttr
|
|
224
|
+
.trim()
|
|
225
|
+
.replace(/\s+/g, " ")
|
|
226
|
+
.split(" ")
|
|
227
|
+
.map((val) => parseFloat(val).toString())
|
|
228
|
+
.join(" ");
|
|
229
|
+
element.setAttribute("viewBox", viewBox);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (element.hasAttribute("preserveAspectRatio")) {
|
|
233
|
+
const aspectRatio = element.getAttribute("preserveAspectRatio");
|
|
234
|
+
if (aspectRatio) {
|
|
235
|
+
// Normalize preserveAspectRatio to consistent formatting
|
|
236
|
+
const value = aspectRatio.trim();
|
|
237
|
+
element.setAttribute("preserveAspectRatio", value);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// Process children (in case of nested SVGs)
|
|
242
|
+
for (let child of Array.from(element.childNodes)) {
|
|
243
|
+
if (child.nodeType === 1) {
|
|
244
|
+
// ELEMENT_NODE
|
|
245
|
+
normalizeViewBox(child);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/master/run.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAqBlC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EACL,oBAAoB,EAErB,MAAM,aAAa,CAAC;AA6BrB,wBAAsB,0BAA0B,CAAC,EAC/C,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,SAAS,GACV,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;;;
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/master/run.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAqBlC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EACL,oBAAoB,EAErB,MAAM,aAAa,CAAC;AA6BrB,wBAAsB,0BAA0B,CAAC,EAC/C,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,SAAS,GACV,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;;;GA8XA"}
|
package/dist/agent/master/run.js
CHANGED
|
@@ -114,7 +114,7 @@ async function createTestUsingMasterAgent({ task, page, testCase, specPath, opti
|
|
|
114
114
|
const plannerResp = await (0, run_time_planner_1.runtimePlanner)({
|
|
115
115
|
trace: masterAgentSpan,
|
|
116
116
|
task,
|
|
117
|
-
|
|
117
|
+
successfulActions: [...masterAgentActions],
|
|
118
118
|
pages: getPageVariables(actions.getStateVariables()),
|
|
119
119
|
currentPage: (0, utils_1.getPageVarName)(),
|
|
120
120
|
});
|
|
@@ -224,6 +224,7 @@ async function createTestUsingMasterAgent({ task, page, testCase, specPath, opti
|
|
|
224
224
|
page,
|
|
225
225
|
preference,
|
|
226
226
|
options,
|
|
227
|
+
trace: masterAgentActionSpan,
|
|
227
228
|
});
|
|
228
229
|
if (annotationKeys.length > 0) {
|
|
229
230
|
// TODO: this string has newline characters that makes it harder to read
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroller.d.ts","sourceRoot":"","sources":["../../../src/agent/master/scroller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAchD,MAAM,MAAM,cAAc,GAAG;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;
|
|
1
|
+
{"version":3,"file":"scroller.d.ts","sourceRoot":"","sources":["../../../src/agent/master/scroller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAchD,MAAM,MAAM,cAAc,GAAG;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AA4ZF,wBAAsB,QAAQ,CAAC,EAC7B,kBAAkB,EAClB,IAAI,EACJ,KAAK,EACL,cAAc,EACd,MAAM,GACP,EAAE;IACD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CA6D5B"}
|
|
@@ -188,6 +188,7 @@ async function getDivAnnotationToScrollOn({ elementDescription, page, trace, log
|
|
|
188
188
|
actionType: action_tool_calls_1.ActionType.SCROLL,
|
|
189
189
|
},
|
|
190
190
|
options: {},
|
|
191
|
+
trace,
|
|
191
192
|
});
|
|
192
193
|
// Remove the used annotations from the list
|
|
193
194
|
annotationKeys = annotationKeys.filter((key) => !usedAnnotations.includes(key.elementID));
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { TraceClient } from "@empiricalrun/llm";
|
|
2
|
-
|
|
3
|
-
* This agent is used to divide the tasl into individual actions and then
|
|
4
|
-
* compare each action against the actions listed in the conversation.
|
|
5
|
-
* If the task is not fully completed, identify which specific actions are missing and suggest next steps to complete the task.
|
|
6
|
-
*
|
|
7
|
-
* This is very initial stage planner and needs iteration and currently forked from verification agent
|
|
8
|
-
*/
|
|
9
|
-
export declare function runtimePlanner({ trace, task, conversation, pages, currentPage, }: {
|
|
2
|
+
export declare function runtimePlanner({ trace, task, successfulActions, pages, currentPage, }: {
|
|
10
3
|
trace?: TraceClient;
|
|
11
|
-
|
|
4
|
+
successfulActions: string[];
|
|
12
5
|
task: string;
|
|
13
6
|
pages?: Record<string, any>;
|
|
14
7
|
currentPage?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-time-planner.d.ts","sourceRoot":"","sources":["../../../src/agent/planner/run-time-planner.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"run-time-planner.d.ts","sourceRoot":"","sources":["../../../src/agent/planner/run-time-planner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAKpE,wBAAsB,cAAc,CAAC,EACnC,KAAK,EACL,IAAI,EACJ,iBAAiB,EACjB,KAAK,EACL,WAAW,GACZ,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;;;;GAoFA"}
|
|
@@ -2,64 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runtimePlanner = void 0;
|
|
4
4
|
const llm_1 = require("@empiricalrun/llm");
|
|
5
|
+
const promptTemplate_0 = "{{#section \"system\"}}\nGiven a successfully executed actions that lists only the actions that were\nsuccessfully executed and a task comprising multiple actions, your goal is to\nanalyse the list and determine if the entire task is completed.\n\nThese actions are executed by AI agents using Playwright on a browser. These agents\nalready have access to browser tabs to execute actions. The successfully executed\nactions on browser post browser has opened, is provided to you as successfully\nexecuted actions.\n\nIf the task is not fully completed, identify which specific actions are missing\nand suggest next steps to complete the task. Assume that the conversation provided\nis entirely truthful and no additional actions were performed beyond those listed.\n\nTo fulfil your goal, follow these steps:\n- Divide the task into individual actions.\n- Compare each task action against the actions listed in the successfully executed actions list.\n- Identify which actions have been executed and which have not.\n- If all actions are executed, respond with the task as done.\n- If any actions are missing, respond with the task as not done, listing all actions\n and specifying which are complete and which are missing.\n- If provided with list of pages, based on the next pending action and previously executed\n action, identify the page on which next action needs to be taken \n{{/section}}\n\n{{#section \"user\"}}\nTask:\n{{task}}\n\n----\n\nFollowing are successfully executed actions:\n{{successfulActions}}\n\n----\n\nCurrent page:\n{{currentPage}}\n\n{{/section}}\n";
|
|
5
6
|
const utils_1 = require("../utils");
|
|
6
|
-
|
|
7
|
-
* This agent is used to divide the tasl into individual actions and then
|
|
8
|
-
* compare each action against the actions listed in the conversation.
|
|
9
|
-
* If the task is not fully completed, identify which specific actions are missing and suggest next steps to complete the task.
|
|
10
|
-
*
|
|
11
|
-
* This is very initial stage planner and needs iteration and currently forked from verification agent
|
|
12
|
-
*/
|
|
13
|
-
async function runtimePlanner({ trace, task, conversation, pages, currentPage, }) {
|
|
7
|
+
async function runtimePlanner({ trace, task, successfulActions, pages, currentPage, }) {
|
|
14
8
|
const runTimePlannerSpan = trace?.span({
|
|
15
9
|
name: "runtime-planner",
|
|
16
10
|
input: {
|
|
17
11
|
task,
|
|
18
|
-
|
|
12
|
+
successfulActions,
|
|
13
|
+
currentPage,
|
|
19
14
|
},
|
|
20
15
|
});
|
|
21
16
|
const llm = new llm_1.LLM({ provider: "openai" });
|
|
22
|
-
const prompt = [
|
|
23
|
-
{
|
|
24
|
-
role: "system",
|
|
25
|
-
content: `
|
|
26
|
-
Given a successfully executed actions that lists only the actions that were successfully executed and a task comprising multiple actions, your goal is to analyse the list and determine if the entire task is completed.
|
|
27
|
-
These actions are executed by AI agents using Playwright on a browser. These agents already have access to browser tabs to execute actions. The successfully executed actions on browser post browser has opened, is provided to you as successfully executed actions.
|
|
28
|
-
|
|
29
|
-
If the task is not fully completed, identify which specific actions are missing and suggest next steps to complete the task. Assume that the conversation provided is entirely truthful and no additional actions were performed beyond those listed.
|
|
30
|
-
|
|
31
|
-
To fulfil your goal, follow these steps:
|
|
32
|
-
- Divide the task into individual actions.
|
|
33
|
-
- Compare each task action against the actions listed in the successfully executed actions list.
|
|
34
|
-
- Identify which actions have been executed and which have not.
|
|
35
|
-
- If all actions are executed, respond with the task as done.
|
|
36
|
-
- If any actions are missing, respond with the task as not done, listing all actions and specifying which are complete and which are missing.
|
|
37
|
-
- If provided with list of pages, based on the next pending action and previously executed action, identify the page on which next action needs to be taken
|
|
38
|
-
`,
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
role: "user",
|
|
42
|
-
content: `
|
|
43
|
-
Task:
|
|
44
|
-
${task}
|
|
45
|
-
|
|
46
|
-
----
|
|
47
|
-
|
|
48
|
-
Following are successfully executed actions:
|
|
49
|
-
${conversation.join("\n")}
|
|
50
|
-
|
|
51
|
-
----
|
|
52
|
-
|
|
53
|
-
Current page:
|
|
54
|
-
${currentPage}
|
|
55
|
-
`,
|
|
56
|
-
},
|
|
57
|
-
];
|
|
58
17
|
const response = await llm.createChatCompletion({
|
|
59
18
|
trace: runTimePlannerSpan,
|
|
60
19
|
traceName: "runtime-planner-llm",
|
|
61
20
|
model: "gpt-4o",
|
|
62
|
-
messages:
|
|
21
|
+
messages: (0, llm_1.compilePrompt)(promptTemplate_0, {
|
|
22
|
+
task,
|
|
23
|
+
successfulActions: successfulActions.join("\n"),
|
|
24
|
+
currentPage,
|
|
25
|
+
}),
|
|
63
26
|
tools: [
|
|
64
27
|
{
|
|
65
28
|
type: "function",
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAOlC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAYpC,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,SAAS,iBAsC3E"}
|
package/dist/index.js
CHANGED
|
@@ -1,35 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
6
|
exports.createTest = void 0;
|
|
30
|
-
require("./initSentry");
|
|
31
7
|
const llm_1 = require("@empiricalrun/llm");
|
|
32
|
-
const Sentry = __importStar(require("@sentry/node"));
|
|
33
8
|
const run_1 = require("./agent/master/run");
|
|
34
9
|
const scenarios_1 = require("./bin/utils/scenarios");
|
|
35
10
|
const client_1 = __importDefault(require("./file/client"));
|
|
@@ -38,7 +13,6 @@ const session_1 = require("./session");
|
|
|
38
13
|
const pw_test_1 = require("./utils/pw-test");
|
|
39
14
|
const flushEvents = async () => {
|
|
40
15
|
await (0, llm_1.flushAllTraces)();
|
|
41
|
-
await Sentry.flush();
|
|
42
16
|
};
|
|
43
17
|
process.on("beforeExit", async () => await flushEvents());
|
|
44
18
|
process.on("exit", async () => await flushEvents());
|