@eko-ai/eko 3.0.2 → 3.0.3

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
@@ -32276,14 +32276,7 @@ const PLAN_SYSTEM_TEMPLATE = `
32276
32276
  You are {name}, an autonomous AI Agent Planner.
32277
32277
 
32278
32278
  ## Task Description
32279
- Your task is to understand the user's requirements, dynamically plan the user's tasks based on the Agent list, and please follow the steps below:
32280
- 1. Understand the user's requirements.
32281
- 2. Analyze the Agents that need to be used based on the user's requirements.
32282
- 3. Generate the Agent calling plan based on the analysis results.
32283
- 4. About agent name, please do not arbitrarily fabricate non-existent agent names.
32284
- 5. You only need to provide the steps to complete the user's task, key steps only, no need to be too detailed.
32285
- 6. Please strictly follow the output format and example output.
32286
- 7. The output language should follow the language corresponding to the user's task.
32279
+ {task_description}
32287
32280
 
32288
32281
  ## Agent list
32289
32282
  {agents}
@@ -32345,6 +32338,14 @@ Your task is to understand the user's requirements, dynamically plan the user's
32345
32338
 
32346
32339
  {example_prompt}
32347
32340
  `;
32341
+ const PLAN_TASK_DESCRIPTION = `Your task is to understand the user's requirements, dynamically plan the user's tasks based on the Agent list, and please follow the steps below:
32342
+ 1. Understand the user's requirements.
32343
+ 2. Analyze the Agents that need to be used based on the user's requirements.
32344
+ 3. Generate the Agent calling plan based on the analysis results.
32345
+ 4. About agent name, please do not arbitrarily fabricate non-existent agent names.
32346
+ 5. You only need to provide the steps to complete the user's task, key steps only, no need to be too detailed.
32347
+ 6. Please strictly follow the output format and example output.
32348
+ 7. The output language should follow the language corresponding to the user's task.`;
32348
32349
  const PLAN_CHAT_EXAMPLE = `User: hello.
32349
32350
  Output result:
32350
32351
  <root>
@@ -32512,7 +32513,7 @@ Task Website: {task_website}
32512
32513
  Current datetime: {datetime}
32513
32514
  Task Description: {task_prompt}
32514
32515
  `;
32515
- async function getPlanSystemPrompt(context) {
32516
+ async function getPlanSystemPrompt(context, planTaskDescription, planExampleList) {
32516
32517
  let agents_prompt = "";
32517
32518
  let agents = context.agents;
32518
32519
  for (let i = 0; i < agents.length; i++) {
@@ -32531,8 +32532,11 @@ async function getPlanSystemPrompt(context) {
32531
32532
  .join("\n") +
32532
32533
  "\n</agent>\n\n";
32533
32534
  }
32534
- let plan_example_list = context.variables.get("plan_example_list") || PLAN_EXAMPLE_LIST;
32535
- let hasChatAgent = context.agents.filter((a) => a.Name == "Chat").length > 0;
32535
+ const task_description = context.variables.get("plan_task_description") ||
32536
+ PLAN_TASK_DESCRIPTION;
32537
+ const plan_example_list = context.variables.get("plan_example_list") ||
32538
+ PLAN_EXAMPLE_LIST;
32539
+ const hasChatAgent = context.agents.filter((a) => a.Name == "Chat").length > 0;
32536
32540
  let example_prompt = "";
32537
32541
  const example_list = hasChatAgent
32538
32542
  ? [PLAN_CHAT_EXAMPLE, ...plan_example_list]
@@ -32541,6 +32545,7 @@ async function getPlanSystemPrompt(context) {
32541
32545
  example_prompt += `## Example ${i + 1}\n${example_list[i]}\n\n`;
32542
32546
  }
32543
32547
  return PLAN_SYSTEM_TEMPLATE.replace("{name}", config$1.name)
32548
+ .replace("{task_description}", task_description)
32544
32549
  .replace("{agents}", agents_prompt.trim())
32545
32550
  .replace("{example_prompt}", example_prompt)
32546
32551
  .trim();
@@ -32587,8 +32592,7 @@ class Planner {
32587
32592
  const messages = [
32588
32593
  {
32589
32594
  role: "system",
32590
- content: this.context.variables.get("plan_sys_prompt") ||
32591
- (await getPlanSystemPrompt(this.context)),
32595
+ content: await getPlanSystemPrompt(this.context),
32592
32596
  },
32593
32597
  {
32594
32598
  role: "user",
@@ -36524,6 +36528,27 @@ class BaseBrowserAgent extends Agent {
36524
36528
 
36525
36529
  // @ts-nocheck
36526
36530
  function run_build_dom_tree() {
36531
+ var computedStyleCache = new WeakMap();
36532
+ /**
36533
+ * Gets the cached computed style for an element.
36534
+ */
36535
+ function getCachedComputedStyle(element) {
36536
+ if (!element)
36537
+ return null;
36538
+ if (computedStyleCache.has(element)) {
36539
+ return computedStyleCache.get(element);
36540
+ }
36541
+ try {
36542
+ const style = window.getComputedStyle(element);
36543
+ if (style) {
36544
+ computedStyleCache.set(element, style);
36545
+ }
36546
+ return style;
36547
+ }
36548
+ catch (e) {
36549
+ return null;
36550
+ }
36551
+ }
36527
36552
  /**
36528
36553
  * Get clickable elements on the page
36529
36554
  *
@@ -36533,6 +36558,7 @@ function run_build_dom_tree() {
36533
36558
  */
36534
36559
  function get_clickable_elements(doHighlightElements = true, includeAttributes) {
36535
36560
  window.clickable_elements = {};
36561
+ computedStyleCache = new WeakMap();
36536
36562
  document.querySelectorAll("[eko-user-highlight-id]").forEach(ele => ele.removeAttribute("eko-user-highlight-id"));
36537
36563
  let page_tree = build_dom_tree(doHighlightElements);
36538
36564
  let element_tree = parse_node(page_tree);
@@ -36549,6 +36575,7 @@ function run_build_dom_tree() {
36549
36575
  if (highlight) {
36550
36576
  highlight.remove();
36551
36577
  }
36578
+ computedStyleCache = new WeakMap();
36552
36579
  }
36553
36580
  function clickable_elements_to_string(element_tree, includeAttributes) {
36554
36581
  if (!includeAttributes) {
@@ -36815,11 +36842,14 @@ function run_build_dom_tree() {
36815
36842
  }
36816
36843
  // Helper function to check if element is accepted
36817
36844
  function isElementAccepted(element) {
36818
- const leafElementDenyList = new Set(['svg', 'script', 'style', 'link', 'meta']);
36845
+ const leafElementDenyList = new Set(['svg', 'script', 'style', 'link', 'meta', 'noscript', 'template']);
36819
36846
  return !leafElementDenyList.has(element.tagName.toLowerCase());
36820
36847
  }
36821
36848
  // Helper function to check if element is interactive
36822
36849
  function isInteractiveElement(element) {
36850
+ if (!element || element.nodeType !== Node.ELEMENT_NODE) {
36851
+ return false;
36852
+ }
36823
36853
  // Base interactive elements and roles
36824
36854
  const interactiveElements = new Set([
36825
36855
  'a',
@@ -36834,11 +36864,16 @@ function run_build_dom_tree() {
36834
36864
  'select',
36835
36865
  'textarea',
36836
36866
  'summary',
36867
+ 'option',
36868
+ 'optgroup',
36869
+ 'fieldset',
36870
+ 'legend',
36837
36871
  ]);
36838
36872
  const interactiveRoles = new Set([
36839
36873
  'button',
36840
36874
  'menu',
36841
36875
  'menuitem',
36876
+ 'menubar',
36842
36877
  'link',
36843
36878
  'checkbox',
36844
36879
  'radio',
@@ -36885,7 +36920,7 @@ function run_build_dom_tree() {
36885
36920
  if (hasInteractiveRole)
36886
36921
  return true;
36887
36922
  // Get computed style
36888
- const style = window.getComputedStyle(element);
36923
+ const style = getCachedComputedStyle(element);
36889
36924
  // Check if element has click-like styling
36890
36925
  const hasClickStyling = style.cursor === 'pointer' || element.style.cursor === 'pointer';
36891
36926
  // Check for event listeners
@@ -36941,7 +36976,7 @@ function run_build_dom_tree() {
36941
36976
  // Check for form-related functionality
36942
36977
  element.form !== undefined ||
36943
36978
  element.hasAttribute('contenteditable') ||
36944
- style.userSelect !== 'none';
36979
+ (style && style.userSelect !== 'none');
36945
36980
  // Check if element is draggable
36946
36981
  const isDraggable = element.draggable || element.getAttribute('draggable') === 'true';
36947
36982
  return (hasAriaProps ||
@@ -36953,11 +36988,12 @@ function run_build_dom_tree() {
36953
36988
  }
36954
36989
  // Helper function to check if element is visible
36955
36990
  function isElementVisible(element) {
36956
- const style = window.getComputedStyle(element);
36957
- return (element.offsetWidth > 0 &&
36958
- element.offsetHeight > 0 &&
36959
- style.visibility !== 'hidden' &&
36960
- style.display !== 'none');
36991
+ if (element.offsetWidth === 0 && element.offsetHeight === 0) {
36992
+ return false;
36993
+ }
36994
+ const style = getCachedComputedStyle(element);
36995
+ return (style?.visibility !== 'hidden' &&
36996
+ style?.display !== 'none');
36961
36997
  }
36962
36998
  // Helper function to check if element is the top element at its position
36963
36999
  function isTopElement(element) {
@@ -37128,9 +37164,11 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
37128
37164
  - If the webpage content hasn't loaded, please use the \`wait\` tool to allow time for the content to load.
37129
37165
  * ELEMENT INTERACTION:
37130
37166
  - Only use indexes that exist in the provided element list
37167
+ - Browser tools only return elements in visible viewport by default
37131
37168
  - Each element has a unique index number (e.g., "[33]:<button>Submit</button>")
37132
37169
  - Elements marked with "[]:" are non-interactive (for context only, e.g., "[]: Google")
37133
37170
  - Use the latest element index, do not rely on historical outdated element indexes
37171
+ - Due to technical limitations, not all interactive elements may be identified; use coordinates to interact with unlisted elements
37134
37172
  * ERROR HANDLING:
37135
37173
  - If no suitable elements exist, use other functions to complete the task
37136
37174
  - If stuck, try alternative approaches, don't refuse tasks
@@ -37297,7 +37335,7 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
37297
37335
  },
37298
37336
  {
37299
37337
  name: "input_text",
37300
- description: "Input text into an element",
37338
+ description: "Input text into the element. It will first click the element to activate it, then proceed with text input.",
37301
37339
  parameters: {
37302
37340
  type: "object",
37303
37341
  properties: {