@eko-ai/eko 3.1.1 → 3.1.2-alpha.2

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/dist/index.esm.js CHANGED
@@ -13,7 +13,7 @@ const config$1 = {
13
13
  maxDialogueImgFileNum: 1,
14
14
  toolResultMultimodal: true,
15
15
  parallelToolCalls: true,
16
- markImageMode: "dom",
16
+ markImageMode: "draw",
17
17
  expertMode: false,
18
18
  expertModeTodoLoopNum: 10,
19
19
  };
@@ -35117,7 +35117,7 @@ function mark_screenshot_highlight_elements(screenshot, area_map, client_rect) {
35117
35117
  .sort((a, b) => {
35118
35118
  const areaA = a[1].width * a[1].height;
35119
35119
  const areaB = b[1].width * b[1].height;
35120
- return areaA - areaB;
35120
+ return areaB - areaA;
35121
35121
  });
35122
35122
  const colors = [
35123
35123
  "#FF0000",
@@ -35135,6 +35135,11 @@ function mark_screenshot_highlight_elements(screenshot, area_map, client_rect) {
35135
35135
  ];
35136
35136
  sortedEntries.forEach(([id, area], index) => {
35137
35137
  const color = colors[index % colors.length];
35138
+ if (area.width * area.height < 40000) {
35139
+ // Draw a background color
35140
+ ctx.fillStyle = color + "1A";
35141
+ ctx.fillRect(area.x, area.y, area.width, area.height);
35142
+ }
35138
35143
  // Draw a border
35139
35144
  ctx.strokeStyle = color;
35140
35145
  ctx.lineWidth = 2;
@@ -35148,7 +35153,12 @@ function mark_screenshot_highlight_elements(screenshot, area_map, client_rect) {
35148
35153
  const labelHeight = fontSize + padding * 2;
35149
35154
  // The tag position is in the upper right corner.
35150
35155
  const labelX = area.x + area.width - labelWidth;
35151
- const labelY = area.y;
35156
+ let labelY = area.y;
35157
+ // Adjust if box is too small
35158
+ if (area.width < labelWidth + 4 || area.height < labelHeight + 4) {
35159
+ // Position outside the box if it's too small
35160
+ labelY = area.y - labelHeight;
35161
+ }
35152
35162
  // Draw label background
35153
35163
  ctx.fillStyle = color;
35154
35164
  ctx.fillRect(labelX, labelY, labelWidth, labelHeight);
@@ -35805,13 +35815,36 @@ function run_build_dom_tree() {
35805
35815
  interactiveRoles.has(ariaRole) ||
35806
35816
  (tabIndex !== null && tabIndex !== '-1') ||
35807
35817
  element.getAttribute('data-action') === 'a-dropdown-select' ||
35808
- element.getAttribute('data-action') === 'a-dropdown-button';
35818
+ element.getAttribute('data-action') === 'a-dropdown-button' ||
35819
+ element.getAttribute('contenteditable') === 'true';
35809
35820
  if (hasInteractiveRole)
35810
35821
  return true;
35811
- // Get computed style
35812
- const style = getCachedComputedStyle(element);
35813
- // Check if element has click-like styling
35814
- const hasClickStyling = style.cursor === 'pointer' || element.style.cursor === 'pointer';
35822
+ // const eventTypes = [
35823
+ // 'click',
35824
+ // 'mousedown',
35825
+ // 'mouseup',
35826
+ // 'touchstart',
35827
+ // 'touchend',
35828
+ // 'keydown',
35829
+ // 'keyup',
35830
+ // 'focus',
35831
+ // 'blur',
35832
+ // ];
35833
+ const clickEventTypes = [
35834
+ 'click',
35835
+ 'mousedown',
35836
+ 'mouseup',
35837
+ 'touchstart',
35838
+ 'touchend',
35839
+ ];
35840
+ // Filter elements that have no real event listeners at all
35841
+ if (window.getEventListeners) {
35842
+ const listeners = window.getEventListeners(element);
35843
+ const hasRealClickListeners = clickEventTypes.some((type) => listeners[type]?.length > 0);
35844
+ if (!hasRealClickListeners) {
35845
+ return false;
35846
+ }
35847
+ }
35815
35848
  // Check for event listeners
35816
35849
  const hasClickHandler = element.onclick !== null ||
35817
35850
  element.getAttribute('onclick') !== null ||
@@ -35819,24 +35852,10 @@ function run_build_dom_tree() {
35819
35852
  element.hasAttribute('@click') ||
35820
35853
  element.hasAttribute('v-on:click');
35821
35854
  // Helper function to safely get event listeners
35822
- function getEventListeners(el) {
35823
- // if (window.getEventListeners) {
35824
- // return window.getEventListeners?.(el) || {};
35825
- // }
35855
+ function getElementEventListeners(el) {
35826
35856
  // List of common event types to check
35827
35857
  const listeners = {};
35828
- const eventTypes = [
35829
- 'click',
35830
- 'mousedown',
35831
- 'mouseup',
35832
- 'touchstart',
35833
- 'touchend',
35834
- 'keydown',
35835
- 'keyup',
35836
- 'focus',
35837
- 'blur',
35838
- ];
35839
- for (const type of eventTypes) {
35858
+ for (const type of clickEventTypes) {
35840
35859
  const handler = el[`on${type}`];
35841
35860
  if (handler) {
35842
35861
  listeners[type] = [
@@ -35850,39 +35869,47 @@ function run_build_dom_tree() {
35850
35869
  return listeners;
35851
35870
  }
35852
35871
  // Check for click-related events on the element itself
35853
- const listeners = getEventListeners(element);
35854
- const hasClickListeners = listeners &&
35855
- (listeners.click?.length > 0 ||
35856
- listeners.mousedown?.length > 0 ||
35857
- listeners.mouseup?.length > 0 ||
35858
- listeners.touchstart?.length > 0 ||
35859
- listeners.touchend?.length > 0);
35872
+ const listeners = getElementEventListeners(element);
35873
+ const hasClickListeners = clickEventTypes.some((type) => listeners[type]?.length > 0);
35860
35874
  // Check for ARIA properties that suggest interactivity
35861
35875
  const hasAriaProps = element.hasAttribute('aria-expanded') ||
35862
35876
  element.hasAttribute('aria-pressed') ||
35863
35877
  element.hasAttribute('aria-selected') ||
35864
35878
  element.hasAttribute('aria-checked');
35865
- // Check for form-related functionality
35866
- element.form !== undefined ||
35867
- element.hasAttribute('contenteditable') ||
35868
- (style && style.userSelect !== 'none');
35869
35879
  // Check if element is draggable
35870
35880
  const isDraggable = element.draggable || element.getAttribute('draggable') === 'true';
35871
- return (hasAriaProps ||
35872
- hasClickStyling ||
35873
- hasClickHandler ||
35874
- hasClickListeners ||
35875
- // isFormRelated ||
35876
- isDraggable);
35881
+ if (hasAriaProps || hasClickHandler || hasClickListeners || isDraggable) {
35882
+ return true;
35883
+ }
35884
+ // Check if element has click-like styling
35885
+ let hasClickStyling = element.style.cursor === 'pointer' || getCachedComputedStyle(element).cursor === 'pointer';
35886
+ if (hasClickStyling) {
35887
+ let count = 0;
35888
+ let current = element.parentElement;
35889
+ while (current && current !== document.documentElement) {
35890
+ hasClickStyling = current.style.cursor === 'pointer' || getCachedComputedStyle(current).cursor === 'pointer';
35891
+ if (hasClickStyling)
35892
+ return false;
35893
+ current = current.parentElement;
35894
+ if (++count > 10)
35895
+ break;
35896
+ }
35897
+ return true;
35898
+ }
35899
+ return false;
35900
+ }
35901
+ // Helper function to check if element exists
35902
+ function isElementExist(element) {
35903
+ const style = getCachedComputedStyle(element);
35904
+ return (style?.visibility !== 'hidden' &&
35905
+ style?.display !== 'none');
35877
35906
  }
35878
35907
  // Helper function to check if element is visible
35879
35908
  function isElementVisible(element) {
35880
35909
  if (element.offsetWidth === 0 && element.offsetHeight === 0) {
35881
35910
  return false;
35882
35911
  }
35883
- const style = getCachedComputedStyle(element);
35884
- return (style?.visibility !== 'hidden' &&
35885
- style?.display !== 'none');
35912
+ return isElementExist(element);
35886
35913
  }
35887
35914
  // Helper function to check if element is the top element at its position
35888
35915
  function isTopElement(element) {
@@ -35903,11 +35930,14 @@ function run_build_dom_tree() {
35903
35930
  if (!topEl)
35904
35931
  return false;
35905
35932
  // Check if the element or any of its parents match our target element
35933
+ let count = 0;
35906
35934
  let current = topEl;
35907
35935
  while (current && current !== shadowRoot) {
35908
35936
  if (current === element)
35909
35937
  return true;
35910
35938
  current = current.parentElement;
35939
+ if (++count > 15)
35940
+ break;
35911
35941
  }
35912
35942
  return false;
35913
35943
  }
@@ -35922,11 +35952,14 @@ function run_build_dom_tree() {
35922
35952
  const topEl = document.elementFromPoint(point.x, point.y);
35923
35953
  if (!topEl)
35924
35954
  return false;
35955
+ let count = 0;
35925
35956
  let current = topEl;
35926
35957
  while (current && current !== document.documentElement) {
35927
35958
  if (current === element)
35928
35959
  return true;
35929
35960
  current = current.parentElement;
35961
+ if (++count > 15)
35962
+ break;
35930
35963
  }
35931
35964
  return false;
35932
35965
  }
@@ -36028,7 +36061,7 @@ function run_build_dom_tree() {
36028
36061
  }
36029
36062
  }
36030
36063
  else {
36031
- if (nodeData.isVisible != false) {
36064
+ if (isElementExist(node)) {
36032
36065
  const children = Array.from(node.childNodes).map((child) => buildDomTree(child, parentIframe));
36033
36066
  nodeData.children.push(...children);
36034
36067
  }
@@ -36472,7 +36505,7 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
36472
36505
  ];
36473
36506
  }
36474
36507
  async double_screenshots(agentContext, messages, tools) {
36475
- return config$1.mode != "fast";
36508
+ return config$1.mode == "expert";
36476
36509
  }
36477
36510
  async handleMessages(agentContext, messages, tools) {
36478
36511
  const pseudoHtmlDescription = "This is the environmental information after the operation, including the latest browser screenshot and page elements. Please perform the next operation based on the environmental information. Do not output the following elements and index information in your response.\n\nIndex and elements:\n";