@empiricalrun/test-gen 0.42.8 → 0.42.9

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/agent/browsing/utils.d.ts.map +1 -1
  3. package/dist/agent/browsing/utils.js +1 -0
  4. package/dist/agent/codegen/create-test-block.d.ts.map +1 -1
  5. package/dist/agent/codegen/create-test-block.js +4 -2
  6. package/dist/agent/codegen/lexical-scoped-vars.d.ts.map +1 -1
  7. package/dist/agent/codegen/lexical-scoped-vars.js +4 -6
  8. package/dist/agent/codegen/promptBuilder.d.ts +3 -0
  9. package/dist/agent/codegen/promptBuilder.d.ts.map +1 -0
  10. package/dist/agent/codegen/promptBuilder.js +44 -0
  11. package/dist/agent/master/action-tool-calls.d.ts +6 -1
  12. package/dist/agent/master/action-tool-calls.d.ts.map +1 -1
  13. package/dist/agent/master/action-tool-calls.js +14 -1
  14. package/dist/agent/master/element-annotation.d.ts +1 -1
  15. package/dist/agent/master/element-annotation.d.ts.map +1 -1
  16. package/dist/agent/master/element-annotation.js +11 -2
  17. package/dist/agent/master/next-action.d.ts +10 -5
  18. package/dist/agent/master/next-action.d.ts.map +1 -1
  19. package/dist/agent/master/next-action.js +59 -11
  20. package/dist/agent/master/run.d.ts.map +1 -1
  21. package/dist/agent/master/run.js +15 -15
  22. package/dist/agent/master/scroller.d.ts +15 -0
  23. package/dist/agent/master/scroller.d.ts.map +1 -0
  24. package/dist/agent/master/scroller.js +371 -0
  25. package/dist/agent/utils.d.ts +2 -0
  26. package/dist/agent/utils.d.ts.map +1 -0
  27. package/dist/agent/utils.js +12 -0
  28. package/dist/bin/utils/platform/web/index.d.ts.map +1 -1
  29. package/dist/bin/utils/platform/web/index.js +2 -0
  30. package/dist/browser-injected-scripts/annotate-elements.js +49 -42
  31. package/dist/browser-injected-scripts/annotate-elements.spec.js +5 -20
  32. package/dist/browser-injected-scripts/annotate-elements.spec.ts +4 -19
  33. package/dist/evals/master-agent.evals.d.ts.map +1 -1
  34. package/dist/evals/master-agent.evals.js +3 -4
  35. package/dist/prompts/lib/ts-transformer.d.ts +4 -0
  36. package/dist/prompts/lib/ts-transformer.d.ts.map +1 -0
  37. package/dist/prompts/lib/ts-transformer.js +90 -0
  38. package/dist/prompts/lib/vitest-plugin.d.ts +8 -0
  39. package/dist/prompts/lib/vitest-plugin.d.ts.map +1 -0
  40. package/dist/prompts/lib/vitest-plugin.js +20 -0
  41. package/dist/session/index.d.ts.map +1 -1
  42. package/dist/session/index.js +4 -0
  43. package/package.json +8 -6
  44. package/vitest.config.ts +5 -0
@@ -0,0 +1,371 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scroller = void 0;
4
+ const llm_1 = require("@empiricalrun/llm");
5
+ const vision_1 = require("@empiricalrun/llm/vision");
6
+ const constants_1 = require("../../constants");
7
+ const utils_1 = require("../utils");
8
+ const action_tool_calls_1 = require("./action-tool-calls");
9
+ const element_annotation_1 = require("./element-annotation");
10
+ let usedAnnotations = [];
11
+ // This checks whether scroll is possible or not
12
+ // If the div annotation is undefined, we check the scrollability of the page
13
+ // else we check for the element
14
+ async function isScrollable({ scrollDirection, page, divAnnotation, }) {
15
+ if (divAnnotation) {
16
+ return await page.evaluate(({ scrollDirection, divAnnotation }) => {
17
+ if (
18
+ // @ts-ignore
19
+ window?.annotationInstance?.annotations?.[divAnnotation]) {
20
+ let element = // @ts-ignore
21
+ window?.annotationInstance?.annotations?.[divAnnotation]?.node;
22
+ if (scrollDirection === "up") {
23
+ return element.scrollTop > 0;
24
+ }
25
+ else {
26
+ return (element.scrollHeight > element.clientHeight + element.scrollTop);
27
+ }
28
+ }
29
+ return false;
30
+ }, { scrollDirection, divAnnotation });
31
+ }
32
+ return await page.evaluate(({ scrollDirection }) => {
33
+ if (scrollDirection === "up") {
34
+ return window.scrollY > 0;
35
+ }
36
+ else {
37
+ return (document.documentElement.scrollHeight >
38
+ window.innerHeight + window.scrollY);
39
+ }
40
+ }, { scrollDirection });
41
+ }
42
+ // Performs scroll on page or the element
43
+ // If the div annotation is undefined, we scroll the page
44
+ // else we scroll the element
45
+ async function scroll({ scrollBy, page, direction, divAnnotation, logger, }) {
46
+ if (divAnnotation) {
47
+ logger?.log("Scrolling the div since element is not in view");
48
+ return await page.evaluate(({ scrollBy, direction, divAnnotation }) => {
49
+ if (
50
+ // @ts-ignore
51
+ window?.annotationInstance?.annotations?.[divAnnotation]) {
52
+ let element = // @ts-ignore
53
+ window?.annotationInstance?.annotations?.[divAnnotation]?.node;
54
+ let scrollHeight = scrollBy || element.clientHeight;
55
+ element.scrollBy(0, scrollHeight * (direction === "up" ? -1 : 1));
56
+ return scrollHeight;
57
+ }
58
+ return 0;
59
+ }, { scrollBy, direction, divAnnotation });
60
+ }
61
+ logger?.log("Scrolling the page since element is not in view");
62
+ return await page.evaluate(({ scrollBy, direction }) => {
63
+ let scrollHeight = scrollBy || window.innerHeight;
64
+ window.scrollBy(0, scrollHeight * (direction === "up" ? -1 : 1));
65
+ return scrollHeight;
66
+ }, { scrollBy, direction });
67
+ }
68
+ // Scrolls the page to top
69
+ async function scrollToTop(page) {
70
+ await page.evaluate(() => {
71
+ window.scrollTo({ top: 0 });
72
+ });
73
+ }
74
+ // Checks if the element is visible in the current frame
75
+ async function isElementVisibleInFrame({ elementDescription, page, trace, logger, }) {
76
+ const buffer = await page.screenshot();
77
+ const frameScreenshot = buffer.toString("base64");
78
+ const systemMessage = {
79
+ role: "system",
80
+ content: `
81
+ You are a web automation tool having extraordinary capabilities of going through the webpage screenshots. You are given a task to identify whether the element with given element description is present on the screen.
82
+ You need to make a decision whether the element is visible or not. Only consider an element to be visible if it's completely visible, otherwise respond false.`,
83
+ };
84
+ const userMessage = {
85
+ role: "user",
86
+ content: [
87
+ {
88
+ type: "text",
89
+ text: `
90
+ Element description:
91
+ ${elementDescription}
92
+
93
+ ----
94
+
95
+ Follow the instructions before responding:
96
+ - Scan through the content in the screenshot
97
+ - While scanning check whether there is any element for which the given element description matches.
98
+ - If it matches set is_visible as true
99
+ - else set is_visible as false
100
+ `,
101
+ },
102
+ {
103
+ type: "text",
104
+ text: "Screenshot",
105
+ },
106
+ {
107
+ type: "image_url",
108
+ image_url: {
109
+ url: (0, vision_1.imageFormatForProvider)(constants_1.DEFAULT_MODEL_PROVIDER, frameScreenshot),
110
+ },
111
+ },
112
+ ],
113
+ };
114
+ const tool = {
115
+ type: "function",
116
+ function: {
117
+ name: "is-element-visible",
118
+ description: "Is the element with given element description present in the screenshot",
119
+ parameters: {
120
+ type: "object",
121
+ properties: {
122
+ reason: {
123
+ type: "string",
124
+ description: "Explain why the element is marked as visible and its location. The reason should be clear and concise.",
125
+ },
126
+ is_visible: {
127
+ type: "boolean",
128
+ description: "Boolean value for whether the element is completely visible in the screenshot.",
129
+ },
130
+ },
131
+ required: ["reason", "is_visible"],
132
+ },
133
+ },
134
+ };
135
+ const messages = [
136
+ systemMessage,
137
+ userMessage,
138
+ ];
139
+ const scrollSpan = trace?.span({
140
+ name: "is-element-visible-after-scroll",
141
+ input: {
142
+ elementDescription,
143
+ messages,
144
+ },
145
+ });
146
+ const llm = new llm_1.LLM({
147
+ provider: constants_1.DEFAULT_MODEL_PROVIDER,
148
+ defaultModel: constants_1.DEFAULT_MODEL,
149
+ });
150
+ const completion = await llm.createChatCompletion({
151
+ messages,
152
+ modelParameters: {
153
+ ...constants_1.DEFAULT_MODEL_PARAMETERS,
154
+ tool_choice: "required",
155
+ temperature: 1,
156
+ },
157
+ trace: scrollSpan,
158
+ tools: [tool],
159
+ });
160
+ let isVisible = false;
161
+ const toolCall = completion?.tool_calls?.[0];
162
+ scrollSpan?.end({ output: toolCall });
163
+ if (toolCall) {
164
+ const args = (0, utils_1.parseJson)(toolCall.function.arguments);
165
+ isVisible = args.is_visible || false;
166
+ }
167
+ else {
168
+ logger?.error(`No tool call found in completion. [Trace](${trace?.getTraceUrl()})`);
169
+ }
170
+ return {
171
+ isVisible,
172
+ frameScreenshot,
173
+ };
174
+ }
175
+ // Returns the element annotation to scroll on
176
+ // if there is no element matching the description we return "NA"
177
+ async function getDivAnnotationToScrollOn({ elementDescription, page, trace, logger, }) {
178
+ const preference = {
179
+ actionType: action_tool_calls_1.ActionType.SCROLL,
180
+ };
181
+ let { annotationKeys, annotatedPageScreenshot } = await (0, element_annotation_1.getAnnotationKeys)({
182
+ page,
183
+ preference: {
184
+ actionType: action_tool_calls_1.ActionType.SCROLL,
185
+ },
186
+ options: {},
187
+ });
188
+ // Remove the used annotations from the list
189
+ annotationKeys = annotationKeys.filter((key) => !usedAnnotations.includes(key.elementID));
190
+ if (annotationKeys.length === 0) {
191
+ return;
192
+ }
193
+ const annotationKeysString = annotationKeys
194
+ ?.map((a) => `${a.elementID}:${a.text}`)
195
+ .join("\n");
196
+ const annotationsSpan = trace?.span({
197
+ name: "get-div-annotation",
198
+ input: {
199
+ elementDescription,
200
+ annotationKeys,
201
+ annotatedPageScreenshot,
202
+ preference,
203
+ },
204
+ });
205
+ const systemMessage = {
206
+ role: "system",
207
+ content: `
208
+ You are an expert in describing the images and it's content. You will be provided with an annotated screenshot where scrollable divs are annotated.
209
+
210
+ The annotation is done by drawing a red box around the element and a small yellow box on it which contains unique element id.
211
+
212
+ You are given a "Annotations" which contains list of unique element Id and description of the element separated by ":".
213
+
214
+ You are also given the description of the element which can be present inside the annotated element. The description includes information about how the element looks, it's position etc.
215
+
216
+ Your task is to provide the annotation of the div on which the scroll action needs to be performed based on whether the provided element is inside the div. You can use the description of the annotated element as well. E.g. text in the div contains the text as described in the element description.
217
+
218
+ You also need to extract the relevant information like the element text or position from the provided element description, this can be used to match the div content with the element.
219
+
220
+ If there is a match provide the annotation for the div else respond with "NA".
221
+
222
+ Follow steps to fulfil your task:
223
+ - If the provided "Annotations" is empty, respond with "NA"
224
+ - For each element Id, read the description for the div element
225
+ - If the description contains the element description or anything on similar lines
226
+ - Respond with the element Id
227
+ - If none of the description contains the element description respond with "NA"
228
+ - If the specified element Id is not found in the "Annotations" section, the response is invalid.
229
+ `,
230
+ };
231
+ const userMessage = {
232
+ role: "user",
233
+ content: [
234
+ {
235
+ type: "text",
236
+ text: `
237
+ Element description:
238
+ ${elementDescription}
239
+
240
+ Annotations:
241
+ ${annotationKeysString}`,
242
+ },
243
+ {
244
+ type: "image_url",
245
+ image_url: {
246
+ url: (0, vision_1.imageFormatForProvider)(constants_1.DEFAULT_MODEL_PROVIDER, annotatedPageScreenshot),
247
+ },
248
+ },
249
+ ],
250
+ };
251
+ const messages = [
252
+ systemMessage,
253
+ userMessage,
254
+ ];
255
+ const annotationToolAction = {
256
+ name: "element_annotation",
257
+ schema: {
258
+ type: "function",
259
+ function: {
260
+ name: "element_annotation",
261
+ description: "Handles annotations for elements",
262
+ parameters: {
263
+ type: "object",
264
+ properties: {
265
+ element: {
266
+ type: "string",
267
+ description: "Relevant information from the provided element description.",
268
+ },
269
+ reason: {
270
+ type: "string",
271
+ description: "Explain why this element is selected. The reason should be clear and align with the task or purpose.",
272
+ },
273
+ element_annotation: {
274
+ type: "string",
275
+ description: "Return the unique element ID for the element on which the action needs to be performed.",
276
+ },
277
+ },
278
+ required: ["element", "reason", "element_annotation"],
279
+ },
280
+ },
281
+ },
282
+ };
283
+ const llm = new llm_1.LLM({
284
+ provider: constants_1.DEFAULT_MODEL_PROVIDER,
285
+ defaultModel: constants_1.DEFAULT_MODEL,
286
+ });
287
+ const completion = await llm.createChatCompletion({
288
+ messages,
289
+ modelParameters: {
290
+ ...constants_1.DEFAULT_MODEL_PARAMETERS,
291
+ tool_choice: "required",
292
+ temperature: 1,
293
+ },
294
+ trace: annotationsSpan,
295
+ traceName: "get-element-from-action",
296
+ //@ts-ignore
297
+ tools: [annotationToolAction.schema],
298
+ });
299
+ const toolCall = completion?.tool_calls?.[0];
300
+ annotationsSpan?.end({ output: toolCall });
301
+ if (toolCall) {
302
+ const args = (0, utils_1.parseJson)(toolCall.function.arguments);
303
+ const isAnnotationPresentInKeys = annotationKeys.some((annotation) => annotation.elementID === args.element_annotation);
304
+ if (args.element_annotation !== "NA" && isAnnotationPresentInKeys) {
305
+ usedAnnotations.push(args.element_annotation);
306
+ return args.element_annotation;
307
+ }
308
+ }
309
+ else {
310
+ logger?.error(`No tool call found in completion. [Trace](${trace?.getTraceUrl()})`);
311
+ }
312
+ return;
313
+ }
314
+ // Scrolls the page and returns the reference to the frame in which the element is visible
315
+ async function scroller({ elementDescription, page, trace, frameReference, logger, }) {
316
+ await scrollToTop(page);
317
+ if (frameReference) {
318
+ await scroll({
319
+ scrollBy: frameReference.scrollPosition,
320
+ page,
321
+ direction: "down",
322
+ });
323
+ return [frameReference];
324
+ }
325
+ let referenceImages = [];
326
+ let scrolledHeight = 0;
327
+ let isScrollAvailable = true;
328
+ const divAnnotation = await getDivAnnotationToScrollOn({
329
+ elementDescription,
330
+ page,
331
+ trace,
332
+ logger,
333
+ });
334
+ while (isScrollAvailable) {
335
+ // Perform action to check for visibility
336
+ const { isVisible, frameScreenshot } = await isElementVisibleInFrame({
337
+ elementDescription,
338
+ page,
339
+ trace,
340
+ logger,
341
+ });
342
+ if (isVisible) {
343
+ usedAnnotations = [];
344
+ referenceImages.push({
345
+ scrollPosition: scrolledHeight,
346
+ frameScreenshot,
347
+ });
348
+ // TODO: remove this to support multiple images
349
+ break;
350
+ }
351
+ isScrollAvailable = await isScrollable({
352
+ scrollDirection: "down",
353
+ page,
354
+ divAnnotation,
355
+ });
356
+ if (isScrollAvailable) {
357
+ scrolledHeight += await scroll({
358
+ page,
359
+ divAnnotation,
360
+ direction: "down",
361
+ logger,
362
+ });
363
+ }
364
+ }
365
+ if (referenceImages.length === 0) {
366
+ logger?.log("Element not found in the current scroll");
367
+ }
368
+ await (0, llm_1.flushAllTraces)();
369
+ return referenceImages;
370
+ }
371
+ exports.scroller = scroller;
@@ -0,0 +1,2 @@
1
+ export declare function parseJson(args: string): any;
2
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/agent/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,OAMrC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseJson = void 0;
4
+ function parseJson(args) {
5
+ try {
6
+ return JSON.parse(args);
7
+ }
8
+ catch (e) {
9
+ console.error("Failed to parse JSON", e);
10
+ }
11
+ }
12
+ exports.parseJson = parseJson;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/utils/platform/web/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMhD,OAAO,EAGL,IAAI,EAEJ,UAAU,EAEX,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,eAAO,MAAM,gCAAgC,eAC/B,UAAU,KACrB,MAgBF,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,YAAY,EACZ,MAAM,EACN,OAAO,GACR,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG;IACF,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,QAAQ,EAAE,IAAI,GAAG,SAAS,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;CACnB,CA2CA;AAwBD,wBAAsB,0CAA0C,CAC9D,QAAQ,EAAE,MAAM,oBA+BjB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,IAAI,GAAG,SAAS,GACrB,IAAI,GAAG,SAAS,CA4BlB;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OA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,WAYA;AAED,wBAAgB,mBAAmB,CAAC,EAClC,QAAQ,EACR,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,UAOA;AAED,wBAAgB,+BAA+B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CA4B5E;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAQnD"}
@@ -229,6 +229,8 @@ exports.stripAndPrependImports = stripAndPrependImports;
229
229
  async function lintErrors(filePath) {
230
230
  const eslint = new eslint_1.ESLint({
231
231
  fix: true,
232
+ // useEslintrc: false,
233
+ // overrideConfigFile: path.join(process.cwd(), ".eslintrc.js"),
232
234
  useEslintrc: true,
233
235
  });
234
236
  const [result] = await eslint.lintFiles(filePath);
@@ -9,7 +9,10 @@
9
9
  * @param {string} options.markerClass - CSS class to apply to hint markers.
10
10
  * @returns {Object} An object containing annotations map and enable/disable methods.
11
11
  */
12
- function annotateClickableElements({ options = {}, preference = {} } = {}) {
12
+ function annotateElementsWithPreference({
13
+ options = {},
14
+ preference = {},
15
+ } = {}) {
13
16
  const {
14
17
  hintCharacterSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", // Default set of characters for hints
15
18
  maxHints = 1000, // Maximum number of hints to generate
@@ -40,31 +43,7 @@ function annotateClickableElements({ options = {}, preference = {} } = {}) {
40
43
  centerY >
41
44
  (windowToAnnotate.innerHeight || document.documentElement.clientHeight)
42
45
  ) {
43
- // Determine the viewport dimensions
44
- const viewportWidth =
45
- windowToAnnotate.innerWidth || document.documentElement.clientWidth;
46
- const viewportHeight =
47
- windowToAnnotate.innerHeight || document.documentElement.clientHeight;
48
-
49
- // Calculate the new scroll positions to bring the element into the center of the viewport
50
- const newScrollX = centerX - viewportWidth / 2;
51
- const newScrollY = centerY - viewportHeight / 2;
52
-
53
- // Scroll the window to the new positions
54
- windowToAnnotate.scrollTo({
55
- top: newScrollY,
56
- left: newScrollX,
57
- });
58
-
59
- const newRect = element.getBoundingClientRect();
60
- const newCenterX = newRect.left + newRect.width / 2;
61
- const newCenterY = newRect.top + newRect.height / 2;
62
- const topElement = document.elementFromPoint(newCenterX, newCenterY);
63
- const doesElementContainTopElement = element.contains(topElement);
64
-
65
- // Restore the original scroll positions
66
- windowToAnnotate.scrollTo(originalScrollX, originalScrollY);
67
- return doesElementContainTopElement;
46
+ return false;
68
47
  }
69
48
 
70
49
  const topElement = windowToAnnotate.document.elementFromPoint(
@@ -411,6 +390,31 @@ function annotateClickableElements({ options = {}, preference = {} } = {}) {
411
390
  return true;
412
391
  }
413
392
 
393
+ // This checks if the element is scrollable or not
394
+ function isElementScrollable(elem) {
395
+ function getComputedStyle(elem) {
396
+ return window.getComputedStyle(elem, null);
397
+ }
398
+
399
+ function getActualCss(elem, style) {
400
+ return getComputedStyle(elem)[style];
401
+ }
402
+
403
+ function isYScrollable(elem) {
404
+ return (
405
+ elem.offsetHeight < elem.scrollHeight &&
406
+ autoOrScroll(getActualCss(elem, "overflow-y"))
407
+ );
408
+ }
409
+
410
+ function autoOrScroll(text) {
411
+ return text == "scroll" || text == "auto";
412
+ }
413
+
414
+ // This doesn't annotate the elements with horizontal scroll
415
+ return isYScrollable(elem);
416
+ }
417
+
414
418
  // Initialize annotations for a given window (including iframes)
415
419
  function initializeAnnotations(windowToAnnotate, parentHints, depth) {
416
420
  const container =
@@ -422,33 +426,36 @@ function annotateClickableElements({ options = {}, preference = {} } = {}) {
422
426
  if (!container) return;
423
427
 
424
428
  // Filter for clickable elements
425
- const clickableElements = Array.from(
429
+ const elementsToAnnotate = Array.from(
426
430
  windowToAnnotate.document.querySelectorAll("*"),
427
431
  ).filter((el) => {
428
- //If preference is fill then it should only annotate input elements
429
- if (preference.actionType === "fill") {
430
- if (!isInputElement(el)) {
431
- return false;
432
- }
433
- }
432
+ // Here based on the action type we filter the elements
433
+ // and annotate only those elements
434
+ switch (preference.actionType) {
435
+ case "fill":
436
+ return isInputElement(el);
434
437
 
435
- //If preference is assert text then only text with the text to be asserted should be highlighted.
436
- if (preference.actionType === "assert_text") {
437
- return isRequiredTextPresent(el, preference.assertionText);
438
- }
438
+ case "assert_text":
439
+ return isRequiredTextPresent(el, preference.assertionText);
440
+
441
+ case "scroll":
442
+ return isElementScrollable(el);
439
443
 
440
- const isClickable = isElementClickable(el, windowToAnnotate);
441
- const isClickNotBlocked = isElementClickNotBlocked(el, windowToAnnotate);
442
- return isClickable && isClickNotBlocked;
444
+ default:
445
+ return (
446
+ isElementClickable(el, windowToAnnotate) &&
447
+ isElementClickNotBlocked(el, windowToAnnotate)
448
+ );
449
+ }
443
450
  });
444
451
  // Generate hint strings for the clickable elements
445
452
  const hints = generateHintStrings(
446
453
  hintCharacterSet,
447
- Math.min(maxHints, clickableElements.length),
454
+ Math.min(maxHints, elementsToAnnotate.length),
448
455
  );
449
456
 
450
457
  // Create markers for the elements
451
- clickableElements.slice(0, maxHints).forEach((el, index) => {
458
+ elementsToAnnotate.slice(0, maxHints).forEach((el, index) => {
452
459
  const hint = hints[index];
453
460
  const rect = el.getBoundingClientRect();
454
461
 
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
4
  };
6
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ // @ts-nocheck
7
7
  const test_1 = require("@playwright/test");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const action_tool_calls_1 = require("../agent/master/action-tool-calls");
@@ -14,7 +14,7 @@ const action_tool_calls_1 = require("../agent/master/action-tool-calls");
14
14
  });
15
15
  const annotations = await page.evaluate(() => {
16
16
  // eslint-disable-next-line no-undef
17
- const { annotations } = annotateClickableElements();
17
+ const { annotations } = annotateElementsWithPreference();
18
18
  return Object.entries(annotations).map(([, config]) => ({
19
19
  innerText: config.node.innerText,
20
20
  tagName: config.node.tagName,
@@ -47,21 +47,6 @@ const action_tool_calls_1 = require("../agent/master/action-tool-calls");
47
47
  tagName: "A",
48
48
  href: "https://assets-test.empirical.run/contact",
49
49
  },
50
- {
51
- innerText: "Playwright\n(opens in a new tab)",
52
- tagName: "A",
53
- href: "https://github.com/microsoft/playwright",
54
- },
55
- {
56
- innerText: "Meet with us",
57
- tagName: "A",
58
- href: "https://assets-test.empirical.run/contact",
59
- },
60
- {
61
- innerText: "Privacy Policy",
62
- tagName: "A",
63
- href: "https://assets-test.empirical.run/privacy.html",
64
- },
65
50
  ]);
66
51
  });
67
52
  (0, test_1.test)("should annotate all important items on quizizz page", async ({ page, }) => {
@@ -71,7 +56,7 @@ const action_tool_calls_1 = require("../agent/master/action-tool-calls");
71
56
  });
72
57
  const annotations = await page.evaluate(() => {
73
58
  // eslint-disable-next-line no-undef
74
- const { annotations } = annotateClickableElements();
59
+ const { annotations } = annotateElementsWithPreference();
75
60
  return Object.entries(annotations).map(([hint, config]) => ({
76
61
  hint,
77
62
  innerText: config.node.innerText.toLowerCase().trim(),
@@ -159,7 +144,7 @@ const action_tool_calls_1 = require("../agent/master/action-tool-calls");
159
144
  };
160
145
  const annotations = await page.evaluate((preference) => {
161
146
  // eslint-disable-next-line no-undef
162
- const { annotations } = annotateClickableElements({
147
+ const { annotations } = annotateElementsWithPreference({
163
148
  preference: preference,
164
149
  });
165
150
  return Object.entries(annotations).map(([hint, config]) => ({
@@ -184,7 +169,7 @@ const action_tool_calls_1 = require("../agent/master/action-tool-calls");
184
169
  };
185
170
  const annotations = await page.evaluate((preference) => {
186
171
  // eslint-disable-next-line no-undef
187
- const { annotations } = annotateClickableElements({
172
+ const { annotations } = annotateElementsWithPreference({
188
173
  preference: preference,
189
174
  });
190
175
  return Object.entries(annotations).map(([hint, config]) => ({
@@ -19,7 +19,7 @@ test("should annotate all links on empirical landing page", async ({
19
19
 
20
20
  const annotations = await page.evaluate(() => {
21
21
  // eslint-disable-next-line no-undef
22
- const { annotations } = annotateClickableElements();
22
+ const { annotations } = annotateElementsWithPreference();
23
23
 
24
24
  return Object.entries(annotations).map(([, config]) => ({
25
25
  innerText: config.node.innerText,
@@ -54,21 +54,6 @@ test("should annotate all links on empirical landing page", async ({
54
54
  tagName: "A",
55
55
  href: "https://assets-test.empirical.run/contact",
56
56
  },
57
- {
58
- innerText: "Playwright\n(opens in a new tab)",
59
- tagName: "A",
60
- href: "https://github.com/microsoft/playwright",
61
- },
62
- {
63
- innerText: "Meet with us",
64
- tagName: "A",
65
- href: "https://assets-test.empirical.run/contact",
66
- },
67
- {
68
- innerText: "Privacy Policy",
69
- tagName: "A",
70
- href: "https://assets-test.empirical.run/privacy.html",
71
- },
72
57
  ]);
73
58
  });
74
59
 
@@ -85,7 +70,7 @@ test("should annotate all important items on quizizz page", async ({
85
70
 
86
71
  const annotations = await page.evaluate(() => {
87
72
  // eslint-disable-next-line no-undef
88
- const { annotations } = annotateClickableElements();
73
+ const { annotations } = annotateElementsWithPreference();
89
74
 
90
75
  return Object.entries(annotations).map(([hint, config]) => ({
91
76
  hint,
@@ -267,7 +252,7 @@ test("should only annotate input fields on quizizz page", async ({ page }) => {
267
252
  };
268
253
  const annotations = await page.evaluate((preference) => {
269
254
  // eslint-disable-next-line no-undef
270
- const { annotations } = annotateClickableElements({
255
+ const { annotations } = annotateElementsWithPreference({
271
256
  preference: preference,
272
257
  });
273
258
 
@@ -299,7 +284,7 @@ test("should only annotate given text on quizziz page", async ({ page }) => {
299
284
  };
300
285
  const annotations = await page.evaluate((preference) => {
301
286
  // eslint-disable-next-line no-undef
302
- const { annotations } = annotateClickableElements({
287
+ const { annotations } = annotateElementsWithPreference({
303
288
  preference: preference,
304
289
  });
305
290
 
@@ -1 +1 @@
1
- {"version":3,"file":"master-agent.evals.d.ts","sourceRoot":"","sources":["../../src/evals/master-agent.evals.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,eAAO,MAAM,4BAA4B,EAAE,UA2C1C,CAAC;AAEF,eAAe,4BAA4B,CAAC"}
1
+ {"version":3,"file":"master-agent.evals.d.ts","sourceRoot":"","sources":["../../src/evals/master-agent.evals.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,eAAO,MAAM,4BAA4B,EAAE,UAwC1C,CAAC;AAEF,eAAe,4BAA4B,CAAC"}