@empiricalrun/test-gen 0.42.8 → 0.42.10

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 (42) hide show
  1. package/CHANGELOG.md +20 -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 +6 -9
  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 +12 -3
  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 +16 -16
  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 +375 -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/browser-injected-scripts/annotate-elements.js +71 -48
  29. package/dist/browser-injected-scripts/annotate-elements.spec.js +5 -20
  30. package/dist/browser-injected-scripts/annotate-elements.spec.ts +4 -19
  31. package/dist/evals/master-agent.evals.d.ts.map +1 -1
  32. package/dist/evals/master-agent.evals.js +3 -4
  33. package/dist/prompts/lib/ts-transformer.d.ts +4 -0
  34. package/dist/prompts/lib/ts-transformer.d.ts.map +1 -0
  35. package/dist/prompts/lib/ts-transformer.js +90 -0
  36. package/dist/prompts/lib/vitest-plugin.d.ts +8 -0
  37. package/dist/prompts/lib/vitest-plugin.d.ts.map +1 -0
  38. package/dist/prompts/lib/vitest-plugin.js +20 -0
  39. package/dist/session/index.d.ts.map +1 -1
  40. package/dist/session/index.js +4 -0
  41. package/package.json +11 -9
  42. package/vitest.config.ts +5 -0
@@ -0,0 +1,375 @@
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 reporter_1 = require("../../reporter");
8
+ const utils_1 = require("../utils");
9
+ const action_tool_calls_1 = require("./action-tool-calls");
10
+ const element_annotation_1 = require("./element-annotation");
11
+ let usedAnnotations = [];
12
+ // This checks whether scroll is possible or not
13
+ // If the div annotation is undefined, we check the scrollability of the page
14
+ // else we check for the element
15
+ async function isScrollable({ scrollDirection, page, divAnnotation, }) {
16
+ if (divAnnotation) {
17
+ return await page.evaluate(({ scrollDirection, divAnnotation }) => {
18
+ if (
19
+ // @ts-ignore
20
+ window?.annotationInstance?.annotations?.[divAnnotation]) {
21
+ let element = // @ts-ignore
22
+ window?.annotationInstance?.annotations?.[divAnnotation]?.node;
23
+ if (scrollDirection === "up") {
24
+ return element.scrollTop > 0;
25
+ }
26
+ else {
27
+ return (element.scrollHeight > element.clientHeight + element.scrollTop);
28
+ }
29
+ }
30
+ return false;
31
+ }, { scrollDirection, divAnnotation });
32
+ }
33
+ return await page.evaluate(({ scrollDirection }) => {
34
+ if (scrollDirection === "up") {
35
+ return window.scrollY > 0;
36
+ }
37
+ else {
38
+ return (document.documentElement.scrollHeight >
39
+ window.innerHeight + window.scrollY);
40
+ }
41
+ }, { scrollDirection });
42
+ }
43
+ // Performs scroll on page or the element
44
+ // If the div annotation is undefined, we scroll the page
45
+ // else we scroll the element
46
+ async function scroll({ scrollBy, page, direction, divAnnotation, logger, }) {
47
+ const testGenUpdatesReporter = new reporter_1.TestGenUpdatesReporter();
48
+ if (divAnnotation) {
49
+ await testGenUpdatesReporter.sendMessage("Scrolling the div since element is not in view");
50
+ logger?.log("Scrolling the div since element is not in view");
51
+ return await page.evaluate(({ scrollBy, direction, divAnnotation }) => {
52
+ if (
53
+ // @ts-ignore
54
+ window?.annotationInstance?.annotations?.[divAnnotation]) {
55
+ let element = // @ts-ignore
56
+ window?.annotationInstance?.annotations?.[divAnnotation]?.node;
57
+ let scrollHeight = scrollBy || element.clientHeight;
58
+ element.scrollBy(0, scrollHeight * (direction === "up" ? -1 : 1));
59
+ return scrollHeight;
60
+ }
61
+ return 0;
62
+ }, { scrollBy, direction, divAnnotation });
63
+ }
64
+ await testGenUpdatesReporter.sendMessage("Scrolling the page since element is not in view");
65
+ logger?.log("Scrolling the page since element is not in view");
66
+ return await page.evaluate(({ scrollBy, direction }) => {
67
+ let scrollHeight = scrollBy || window.innerHeight;
68
+ window.scrollBy(0, scrollHeight * (direction === "up" ? -1 : 1));
69
+ return scrollHeight;
70
+ }, { scrollBy, direction });
71
+ }
72
+ // Scrolls the page to top
73
+ async function scrollToTop(page) {
74
+ await page.evaluate(() => {
75
+ window.scrollTo({ top: 0 });
76
+ });
77
+ }
78
+ // Checks if the element is visible in the current frame
79
+ async function isElementVisibleInFrame({ elementDescription, page, trace, logger, }) {
80
+ const buffer = await page.screenshot();
81
+ const frameScreenshot = buffer.toString("base64");
82
+ const systemMessage = {
83
+ role: "system",
84
+ content: `
85
+ 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.
86
+ 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.`,
87
+ };
88
+ const userMessage = {
89
+ role: "user",
90
+ content: [
91
+ {
92
+ type: "text",
93
+ text: `
94
+ Element description:
95
+ ${elementDescription}
96
+
97
+ ----
98
+
99
+ Follow the instructions before responding:
100
+ - Scan through the content in the screenshot
101
+ - While scanning check whether there is any element for which the given element description matches.
102
+ - If it matches set is_visible as true
103
+ - else set is_visible as false
104
+ `,
105
+ },
106
+ {
107
+ type: "text",
108
+ text: "Screenshot",
109
+ },
110
+ {
111
+ type: "image_url",
112
+ image_url: {
113
+ url: (0, vision_1.imageFormatForProvider)(constants_1.DEFAULT_MODEL_PROVIDER, frameScreenshot),
114
+ },
115
+ },
116
+ ],
117
+ };
118
+ const tool = {
119
+ type: "function",
120
+ function: {
121
+ name: "is-element-visible",
122
+ description: "Is the element with given element description present in the screenshot",
123
+ parameters: {
124
+ type: "object",
125
+ properties: {
126
+ reason: {
127
+ type: "string",
128
+ description: "Explain why the element is marked as visible and its location. The reason should be clear and concise.",
129
+ },
130
+ is_visible: {
131
+ type: "boolean",
132
+ description: "Boolean value for whether the element is completely visible in the screenshot.",
133
+ },
134
+ },
135
+ required: ["reason", "is_visible"],
136
+ },
137
+ },
138
+ };
139
+ const messages = [
140
+ systemMessage,
141
+ userMessage,
142
+ ];
143
+ const scrollSpan = trace?.span({
144
+ name: "is-element-visible-after-scroll",
145
+ input: {
146
+ elementDescription,
147
+ messages,
148
+ },
149
+ });
150
+ const llm = new llm_1.LLM({
151
+ provider: constants_1.DEFAULT_MODEL_PROVIDER,
152
+ defaultModel: constants_1.DEFAULT_MODEL,
153
+ });
154
+ const completion = await llm.createChatCompletion({
155
+ messages,
156
+ modelParameters: {
157
+ ...constants_1.DEFAULT_MODEL_PARAMETERS,
158
+ tool_choice: "required",
159
+ temperature: 1,
160
+ },
161
+ trace: scrollSpan,
162
+ tools: [tool],
163
+ });
164
+ let isVisible = false;
165
+ const toolCall = completion?.tool_calls?.[0];
166
+ scrollSpan?.end({ output: toolCall });
167
+ if (toolCall) {
168
+ const args = (0, utils_1.parseJson)(toolCall.function.arguments);
169
+ isVisible = args.is_visible || false;
170
+ }
171
+ else {
172
+ logger?.error(`No tool call found in completion. [Trace](${trace?.getTraceUrl()})`);
173
+ }
174
+ return {
175
+ isVisible,
176
+ frameScreenshot,
177
+ };
178
+ }
179
+ // Returns the element annotation to scroll on
180
+ // if there is no element matching the description we return "NA"
181
+ async function getDivAnnotationToScrollOn({ elementDescription, page, trace, logger, }) {
182
+ const preference = {
183
+ actionType: action_tool_calls_1.ActionType.SCROLL,
184
+ };
185
+ let { annotationKeys, annotatedPageScreenshot } = await (0, element_annotation_1.getAnnotationKeys)({
186
+ page,
187
+ preference: {
188
+ actionType: action_tool_calls_1.ActionType.SCROLL,
189
+ },
190
+ options: {},
191
+ });
192
+ // Remove the used annotations from the list
193
+ annotationKeys = annotationKeys.filter((key) => !usedAnnotations.includes(key.elementID));
194
+ if (annotationKeys.length === 0) {
195
+ return;
196
+ }
197
+ const annotationKeysString = annotationKeys
198
+ ?.map((a) => `${a.elementID}:${a.text}`)
199
+ .join("\n");
200
+ const annotationsSpan = trace?.span({
201
+ name: "get-div-annotation",
202
+ input: {
203
+ elementDescription,
204
+ annotationKeys,
205
+ annotatedPageScreenshot,
206
+ preference,
207
+ },
208
+ });
209
+ const systemMessage = {
210
+ role: "system",
211
+ content: `
212
+ 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.
213
+
214
+ The annotation is done by drawing a red box around the element and a small yellow box on it which contains unique element id.
215
+
216
+ You are given a "Annotations" which contains list of unique element Id and description of the element separated by ":".
217
+
218
+ 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.
219
+
220
+ 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.
221
+
222
+ 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.
223
+
224
+ If there is a match provide the annotation for the div else respond with "NA".
225
+
226
+ Follow steps to fulfil your task:
227
+ - If the provided "Annotations" is empty, respond with "NA"
228
+ - For each element Id, read the description for the div element
229
+ - If the description contains the element description or anything on similar lines
230
+ - Respond with the element Id
231
+ - If none of the description contains the element description respond with "NA"
232
+ - If the specified element Id is not found in the "Annotations" section, the response is invalid.
233
+ `,
234
+ };
235
+ const userMessage = {
236
+ role: "user",
237
+ content: [
238
+ {
239
+ type: "text",
240
+ text: `
241
+ Element description:
242
+ ${elementDescription}
243
+
244
+ Annotations:
245
+ ${annotationKeysString}`,
246
+ },
247
+ {
248
+ type: "image_url",
249
+ image_url: {
250
+ url: (0, vision_1.imageFormatForProvider)(constants_1.DEFAULT_MODEL_PROVIDER, annotatedPageScreenshot),
251
+ },
252
+ },
253
+ ],
254
+ };
255
+ const messages = [
256
+ systemMessage,
257
+ userMessage,
258
+ ];
259
+ const annotationToolAction = {
260
+ name: "element_annotation",
261
+ schema: {
262
+ type: "function",
263
+ function: {
264
+ name: "element_annotation",
265
+ description: "Handles annotations for elements",
266
+ parameters: {
267
+ type: "object",
268
+ properties: {
269
+ element: {
270
+ type: "string",
271
+ description: "Relevant information from the provided element description.",
272
+ },
273
+ reason: {
274
+ type: "string",
275
+ description: "Explain why this element is selected. The reason should be clear and align with the task or purpose.",
276
+ },
277
+ element_annotation: {
278
+ type: "string",
279
+ description: "Return the unique element ID for the element on which the action needs to be performed.",
280
+ },
281
+ },
282
+ required: ["element", "reason", "element_annotation"],
283
+ },
284
+ },
285
+ },
286
+ };
287
+ const llm = new llm_1.LLM({
288
+ provider: constants_1.DEFAULT_MODEL_PROVIDER,
289
+ defaultModel: constants_1.DEFAULT_MODEL,
290
+ });
291
+ const completion = await llm.createChatCompletion({
292
+ messages,
293
+ modelParameters: {
294
+ ...constants_1.DEFAULT_MODEL_PARAMETERS,
295
+ tool_choice: "required",
296
+ temperature: 1,
297
+ },
298
+ trace: annotationsSpan,
299
+ traceName: "get-element-from-action",
300
+ //@ts-ignore
301
+ tools: [annotationToolAction.schema],
302
+ });
303
+ const toolCall = completion?.tool_calls?.[0];
304
+ annotationsSpan?.end({ output: toolCall });
305
+ if (toolCall) {
306
+ const args = (0, utils_1.parseJson)(toolCall.function.arguments);
307
+ const isAnnotationPresentInKeys = annotationKeys.some((annotation) => annotation.elementID === args.element_annotation);
308
+ if (args.element_annotation !== "NA" && isAnnotationPresentInKeys) {
309
+ usedAnnotations.push(args.element_annotation);
310
+ return args.element_annotation;
311
+ }
312
+ }
313
+ else {
314
+ logger?.error(`No tool call found in completion. [Trace](${trace?.getTraceUrl()})`);
315
+ }
316
+ return;
317
+ }
318
+ // Scrolls the page and returns the reference to the frame in which the element is visible
319
+ async function scroller({ elementDescription, page, trace, frameReference, logger, }) {
320
+ await scrollToTop(page);
321
+ if (frameReference) {
322
+ await scroll({
323
+ scrollBy: frameReference.scrollPosition,
324
+ page,
325
+ direction: "down",
326
+ });
327
+ return [frameReference];
328
+ }
329
+ let referenceImages = [];
330
+ let scrolledHeight = 0;
331
+ let isScrollAvailable = true;
332
+ const divAnnotation = await getDivAnnotationToScrollOn({
333
+ elementDescription,
334
+ page,
335
+ trace,
336
+ logger,
337
+ });
338
+ while (isScrollAvailable) {
339
+ // Perform action to check for visibility
340
+ const { isVisible, frameScreenshot } = await isElementVisibleInFrame({
341
+ elementDescription,
342
+ page,
343
+ trace,
344
+ logger,
345
+ });
346
+ if (isVisible) {
347
+ usedAnnotations = [];
348
+ referenceImages.push({
349
+ scrollPosition: scrolledHeight,
350
+ frameScreenshot,
351
+ });
352
+ // TODO: remove this to support multiple images
353
+ break;
354
+ }
355
+ isScrollAvailable = await isScrollable({
356
+ scrollDirection: "down",
357
+ page,
358
+ divAnnotation,
359
+ });
360
+ if (isScrollAvailable) {
361
+ scrolledHeight += await scroll({
362
+ page,
363
+ divAnnotation,
364
+ direction: "down",
365
+ logger,
366
+ });
367
+ }
368
+ }
369
+ if (referenceImages.length === 0) {
370
+ logger?.log("Element not found in the current scroll");
371
+ }
372
+ await (0, llm_1.flushAllTraces)();
373
+ return referenceImages;
374
+ }
375
+ 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;
@@ -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(
@@ -332,10 +311,7 @@ function annotateClickableElements({ options = {}, preference = {} } = {}) {
332
311
  // Style the marker
333
312
  Object.assign(marker.style, {
334
313
  position: "absolute",
335
- top: `${rect.top + windowToAnnotate.scrollY}px`,
336
- left: `${rect.left + windowToAnnotate.scrollX}px`,
337
- background:
338
- "-webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(255, 247, 133)), to(rgb(255, 197, 66)))",
314
+ background: "rgb(255, 197, 66)",
339
315
  padding: "1px 3px 0px",
340
316
  borderRadius: "3px",
341
317
  border: "1px solid rgb(227, 190, 35)",
@@ -352,10 +328,29 @@ function annotateClickableElements({ options = {}, preference = {} } = {}) {
352
328
  fontFamily: "Helvetica, Arial, sans-serif",
353
329
  fontWeight: "bold",
354
330
  textShadow: "rgba(255, 255, 255, 0.6) 0px 1px 0px",
331
+ visibility: "hidden", // Setting the visibility to hidden initially, to get the height and width of marker
355
332
  });
356
333
 
357
- // Attach the marker to the specified parent element
358
334
  parentElement.appendChild(marker);
335
+ let markerRect = marker.getBoundingClientRect();
336
+ let top = rect.top + windowToAnnotate.scrollY;
337
+ let left = rect.left + windowToAnnotate.scrollX;
338
+
339
+ // If the target element is smaller, we annotate outside the container
340
+ if (markerRect.height > rect.height - markerRect.height) {
341
+ top = top - markerRect.height;
342
+ }
343
+
344
+ if (markerRect.width > rect.width - markerRect.width) {
345
+ left = left - markerRect.width / 2;
346
+ }
347
+
348
+ // Applying the position and setting visibility
349
+ marker.style.top = `${top}px`;
350
+ marker.style.left = `${left}px`;
351
+ marker.style.visibility = "visible";
352
+
353
+ // Attach the marker to the specified parent element
359
354
  parentElements.push(parentElement);
360
355
  return marker;
361
356
  }
@@ -411,6 +406,31 @@ function annotateClickableElements({ options = {}, preference = {} } = {}) {
411
406
  return true;
412
407
  }
413
408
 
409
+ // This checks if the element is scrollable or not
410
+ function isElementScrollable(elem) {
411
+ function getComputedStyle(elem) {
412
+ return window.getComputedStyle(elem, null);
413
+ }
414
+
415
+ function getActualCss(elem, style) {
416
+ return getComputedStyle(elem)[style];
417
+ }
418
+
419
+ function isYScrollable(elem) {
420
+ return (
421
+ elem.offsetHeight < elem.scrollHeight &&
422
+ autoOrScroll(getActualCss(elem, "overflow-y"))
423
+ );
424
+ }
425
+
426
+ function autoOrScroll(text) {
427
+ return text == "scroll" || text == "auto";
428
+ }
429
+
430
+ // This doesn't annotate the elements with horizontal scroll
431
+ return isYScrollable(elem);
432
+ }
433
+
414
434
  // Initialize annotations for a given window (including iframes)
415
435
  function initializeAnnotations(windowToAnnotate, parentHints, depth) {
416
436
  const container =
@@ -422,39 +442,42 @@ function annotateClickableElements({ options = {}, preference = {} } = {}) {
422
442
  if (!container) return;
423
443
 
424
444
  // Filter for clickable elements
425
- const clickableElements = Array.from(
445
+ const elementsToAnnotate = Array.from(
426
446
  windowToAnnotate.document.querySelectorAll("*"),
427
447
  ).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
- }
448
+ // Here based on the action type we filter the elements
449
+ // and annotate only those elements
450
+ switch (preference.actionType) {
451
+ case "fill":
452
+ return isInputElement(el);
434
453
 
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
- }
454
+ case "assert_text":
455
+ return isRequiredTextPresent(el, preference.assertionText);
439
456
 
440
- const isClickable = isElementClickable(el, windowToAnnotate);
441
- const isClickNotBlocked = isElementClickNotBlocked(el, windowToAnnotate);
442
- return isClickable && isClickNotBlocked;
457
+ case "scroll":
458
+ return isElementScrollable(el);
459
+
460
+ default:
461
+ return (
462
+ isElementClickable(el, windowToAnnotate) &&
463
+ isElementClickNotBlocked(el, windowToAnnotate)
464
+ );
465
+ }
443
466
  });
444
467
  // Generate hint strings for the clickable elements
445
468
  const hints = generateHintStrings(
446
469
  hintCharacterSet,
447
- Math.min(maxHints, clickableElements.length),
470
+ Math.min(maxHints, elementsToAnnotate.length),
448
471
  );
449
472
 
450
473
  // Create markers for the elements
451
- clickableElements.slice(0, maxHints).forEach((el, index) => {
474
+ elementsToAnnotate.slice(0, maxHints).forEach((el, index) => {
452
475
  const hint = hints[index];
453
476
  const rect = el.getBoundingClientRect();
454
477
 
455
478
  // Use createHintMarker with the specified container
456
479
  createHintMarker(el, hint, container, windowToAnnotate);
457
- el.style.boxShadow = `inset 0 0 0px 2px red`;
480
+ el.style.boxShadow = `inset 0 0 0px 1px red`;
458
481
 
459
482
  // Add element details to the annotations map
460
483
  annotationsMap[hint] = {
@@ -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]) => ({