@eko-ai/eko 2.0.9 → 2.1.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.
@@ -41,6 +41,7 @@ export default abstract class BaseBrowserAgent extends Agent {
41
41
  result: unknown;
42
42
  isError?: boolean;
43
43
  } | null;
44
+ protected toolUseNames(messages: LanguageModelV1Prompt): string[];
44
45
  protected abstract execute_script(agentContext: AgentContext, func: (...args: any[]) => void, args: any[]): Promise<any>;
45
46
  protected execute_mcp_script(agentContext: AgentContext, script: string): Promise<string | number | Record<string, any> | undefined>;
46
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"browser_base.d.ts","sourceRoot":"","sources":["../../../src/agent/browser/browser_base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EAEtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAc,UAAU,EAAE,MAAM,aAAa,CAAC;AAEnE,eAAO,MAAM,UAAU,YAAY,CAAC;AAEpC,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,gBAAiB,SAAQ,KAAK;IAC1D,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC;QACjE,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,YAAY,GAAG,WAAW,CAAC;KACvC,CAAC;IAEF,SAAS,CAAC,QAAQ,CAAC,WAAW,CAC5B,YAAY,EAAE,YAAY,EAC1B,GAAG,EAAE,MAAM,GACV,OAAO,CAAC;QACT,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IAEF,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAClE,KAAK,CAAC;QACJ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AC,cAAc,CAC/B,YAAY,EAAE,YAAY,EAC1B,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EAC9B,IAAI,EAAE,GAAG,EAAE,GACV,OAAO,CAAC,GAAG,CAAC;cAEC,kBAAkB,CAChC,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;CAG9D;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -7,7 +7,7 @@ export default abstract class BaseBrowserLabelsAgent extends BaseBrowserAgent {
7
7
  protected input_text(agentContext: AgentContext, index: number, text: string, enter: boolean): Promise<void>;
8
8
  protected click_element(agentContext: AgentContext, index: number, num_clicks: number, button: "left" | "right" | "middle"): Promise<void>;
9
9
  protected scroll_to_element(agentContext: AgentContext, index: number): Promise<void>;
10
- protected scroll_mouse_wheel(agentContext: AgentContext, amount: number): Promise<void>;
10
+ protected scroll_mouse_wheel(agentContext: AgentContext, amount: number, extract_page_content: boolean): Promise<any>;
11
11
  protected hover_to_element(agentContext: AgentContext, index: number): Promise<void>;
12
12
  protected get_select_options(agentContext: AgentContext, index: number): Promise<any>;
13
13
  protected select_option(agentContext: AgentContext, index: number, option: string): Promise<any>;
@@ -1 +1 @@
1
- {"version":3,"file":"browser_labels.d.ts","sourceRoot":"","sources":["../../../src/agent/browser/browser_labels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAc,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAc,UAAU,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAGzD,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,sBAAuB,SAAQ,gBAAgB;gBA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EAC1B,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,GAAG,CAAC;cAMC,aAAa,CAC3B,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,GAAG,CAAC;cAMC,mBAAmB,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC;QACvE,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,YAAY,GAAG,WAAW,CAAC;QACtC,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IAwCF,SAAS,CAAC,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAInD,OAAO,CAAC,cAAc;cA2VN,cAAc,CAC5B,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,qBAAqB,EAC/B,KAAK,EAAE,IAAI,EAAE,GACZ,OAAO,CAAC,IAAI,CAAC;CA8BjB;AAwND,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -9,7 +9,7 @@ const config = {
9
9
  platform: "mac",
10
10
  maxReactNum: 200,
11
11
  maxTokens: 16000,
12
- compressThreshold: 60,
12
+ compressThreshold: 80,
13
13
  largeTextLength: 5000,
14
14
  shortTextLength: 800,
15
15
  };
@@ -17876,7 +17876,7 @@ class HumanInteractTool {
17876
17876
  this.name = TOOL_NAME$3;
17877
17877
  this.noPlan = true;
17878
17878
  this.description = `AI interacts with humans:
17879
- confirm: Ask the user to confirm whether to execute an operation, especially when performing dangerous actions such as deleting system files.
17879
+ confirm: Ask the user to confirm whether to execute an operation, especially when performing dangerous actions such as deleting system files, users will choose Yes or No.
17880
17880
  input: Prompt the user to enter text; for example, when a task is ambiguous, the AI can choose to ask the user for details, and the user can respond by inputting.
17881
17881
  select: Allow the user to make a choice; in situations that require selection, the AI can ask the user to make a decision.
17882
17882
  request_help: Request assistance from the user; for instance, when an operation is blocked, the AI can ask the user for help, such as needing to log into a website or solve a CAPTCHA.`;
@@ -18155,10 +18155,10 @@ The output language should follow the language corresponding to the user's task.
18155
18155
  const HUMAN_PROMPT = `
18156
18156
  * HUMAN INTERACT
18157
18157
  During the task execution process, you can use the \`${TOOL_NAME$3}\` tool to interact with humans, please call it in the following situations:
18158
- - When performing dangerous operations such as deleting files, confirmation from humans is required
18159
- - When encountering obstacles while accessing websites, such as requiring user login, you need to request human assistance
18158
+ - When performing dangerous operations such as deleting files, confirmation from humans is required.
18159
+ - When encountering obstacles while visiting a website, such as requiring user login or captcha, you need to request for manual assistance.
18160
18160
  - When requesting login, please only call the function when a login dialog box is clearly displayed.
18161
- - Try not to use the \`${TOOL_NAME$3}\` tool
18161
+ - Try to minimize the use of \`${TOOL_NAME$3}\` tool.
18162
18162
  `;
18163
18163
  const VARIABLE_PROMPT = `
18164
18164
  * VARIABLE STORAGE
@@ -20064,6 +20064,16 @@ class BaseBrowserAgent extends Agent {
20064
20064
  }
20065
20065
  return null;
20066
20066
  }
20067
+ toolUseNames(messages) {
20068
+ let toolNames = [];
20069
+ for (let i = 0; i < messages.length; i++) {
20070
+ let message = messages[i];
20071
+ if (message.role == "tool") {
20072
+ toolNames.push(message.content[0].toolName);
20073
+ }
20074
+ }
20075
+ return toolNames;
20076
+ }
20067
20077
  async execute_mcp_script(agentContext, script) {
20068
20078
  return;
20069
20079
  }
@@ -20712,15 +20722,13 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
20712
20722
  }, [index]);
20713
20723
  await sleep(200);
20714
20724
  }
20715
- async scroll_mouse_wheel(agentContext, amount) {
20716
- await this.execute_script(agentContext, (amount) => {
20717
- let viewportHeight = window.innerHeight ||
20718
- document.documentElement.clientHeight ||
20719
- document.body.clientHeight;
20720
- let y = Math.max(20, Math.min(viewportHeight / 10, 200));
20721
- window.scrollBy(0, y * amount);
20722
- }, [amount]);
20725
+ async scroll_mouse_wheel(agentContext, amount, extract_page_content) {
20726
+ await this.execute_script(agentContext, scroll_by, [{ amount }]);
20723
20727
  await sleep(200);
20728
+ if (extract_page_content) {
20729
+ let page_content = await this.extract_page_content(agentContext);
20730
+ return "This is the latest page content:\n" + page_content;
20731
+ }
20724
20732
  }
20725
20733
  async hover_to_element(agentContext, index) {
20726
20734
  await this.execute_script(agentContext, hover_to, [{ index }]);
@@ -20741,6 +20749,7 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
20741
20749
  for (let i = 0; i < 5; i++) {
20742
20750
  await sleep(200);
20743
20751
  await this.execute_script(agentContext, run_build_dom_tree, []);
20752
+ await sleep(50);
20744
20753
  element_result = (await this.execute_script(agentContext, () => {
20745
20754
  return window.get_clickable_elements(true);
20746
20755
  }, []));
@@ -20748,7 +20757,7 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
20748
20757
  break;
20749
20758
  }
20750
20759
  }
20751
- await sleep(50);
20760
+ await sleep(100);
20752
20761
  let screenshot = await this.screenshot(agentContext);
20753
20762
  // agentContext.variables.set("selector_map", element_result.selector_map);
20754
20763
  let pseudoHtml = element_result.element_str;
@@ -20882,7 +20891,7 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
20882
20891
  },
20883
20892
  {
20884
20893
  name: "scroll_mouse_wheel",
20885
- description: "Scroll the mouse wheel at current position, prioritize using extract_page_content, only scroll when you need to load more content",
20894
+ description: "Scroll the mouse wheel at current position, only scroll when you need to load more content",
20886
20895
  parameters: {
20887
20896
  type: "object",
20888
20897
  properties: {
@@ -20896,13 +20905,17 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
20896
20905
  type: "string",
20897
20906
  enum: ["up", "down"],
20898
20907
  },
20908
+ extract_page_content: {
20909
+ type: "boolean",
20910
+ description: "After scrolling is completed, whether to extract the current latest page content",
20911
+ },
20899
20912
  },
20900
20913
  required: ["amount", "direction"],
20901
20914
  },
20902
20915
  execute: async (args, agentContext) => {
20903
20916
  return await this.callInnerTool(async () => {
20904
20917
  let amount = args.amount;
20905
- await this.scroll_mouse_wheel(agentContext, args.direction == "up" ? -amount : amount);
20918
+ await this.scroll_mouse_wheel(agentContext, args.direction == "up" ? -amount : amount, args.extract_page_content == true);
20906
20919
  });
20907
20920
  },
20908
20921
  },
@@ -21188,6 +21201,50 @@ function select_option(params) {
21188
21201
  selectedText: option.text.trim(),
21189
21202
  };
21190
21203
  }
21204
+ function scroll_by(params) {
21205
+ const amount = params.amount;
21206
+ const documentElement = document.documentElement || document.body;
21207
+ if (documentElement.scrollHeight > window.innerHeight * 1.2) {
21208
+ const y = Math.max(20, Math.min((window.innerHeight || documentElement.clientHeight) / 10, 200));
21209
+ window.scrollBy(0, y * amount);
21210
+ return;
21211
+ }
21212
+ function findScrollableElements() {
21213
+ const allElements = Array.from(document.querySelectorAll("*"));
21214
+ return allElements.filter((el) => {
21215
+ const style = window.getComputedStyle(el);
21216
+ const overflowY = style.getPropertyValue("overflow-y");
21217
+ return ((overflowY === "auto" || overflowY === "scroll") &&
21218
+ el.scrollHeight > el.clientHeight);
21219
+ });
21220
+ }
21221
+ function getVisibleArea(element) {
21222
+ const rect = element.getBoundingClientRect();
21223
+ const viewportHeight = window.innerHeight || documentElement.clientHeight;
21224
+ const viewportWidth = window.innerWidth || documentElement.clientWidth;
21225
+ const visibleLeft = Math.max(0, Math.min(rect.left, viewportWidth));
21226
+ const visibleRight = Math.max(0, Math.min(rect.right, viewportWidth));
21227
+ const visibleTop = Math.max(0, Math.min(rect.top, viewportHeight));
21228
+ const visibleBottom = Math.max(0, Math.min(rect.bottom, viewportHeight));
21229
+ const visibleWidth = visibleRight - visibleLeft;
21230
+ const visibleHeight = visibleBottom - visibleTop;
21231
+ return visibleWidth * visibleHeight;
21232
+ }
21233
+ const scrollableElements = findScrollableElements();
21234
+ if (scrollableElements.length === 0) {
21235
+ const y = Math.max(20, Math.min((window.innerHeight || documentElement.clientHeight) / 10, 200));
21236
+ window.scrollBy(0, y * amount);
21237
+ return false;
21238
+ }
21239
+ const sortedElements = scrollableElements.sort((a, b) => {
21240
+ return getVisibleArea(b) - getVisibleArea(a);
21241
+ });
21242
+ const largestElement = sortedElements[0];
21243
+ const viewportHeight = largestElement.clientHeight;
21244
+ const y = Math.max(20, Math.min(viewportHeight / 10, 200));
21245
+ largestElement.scrollBy(0, y * amount);
21246
+ return true;
21247
+ }
21191
21248
 
21192
21249
  class BaseBrowserScreenAgent extends BaseBrowserAgent {
21193
21250
  constructor(llms, ext_tools, mcpClient) {