@eko-ai/eko 2.1.2 → 2.1.4

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.
@@ -20,6 +20,7 @@ export default abstract class BaseBrowserLabelsAgent extends BaseBrowserAgent {
20
20
  private buildInitTools;
21
21
  protected double_screenshots(agentContext: AgentContext, messages: LanguageModelV1Prompt, tools: Tool[]): Promise<boolean>;
22
22
  protected handleMessages(agentContext: AgentContext, messages: LanguageModelV1Prompt, tools: Tool[]): Promise<void>;
23
+ private handlePseudoHtmlText;
23
24
  private removePseudoHtmlAttr;
24
25
  }
25
26
  export { BaseBrowserLabelsAgent };
@@ -1 +1 @@
1
- {"version":3,"file":"browser_labels.d.ts","sourceRoot":"","sources":["../../../src/agent/browser/browser_labels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAc,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAEL,qBAAqB,EACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAc,UAAU,EAAE,MAAM,aAAa,CAAC;AAG3D,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,sBAAuB,SAAQ,gBAAgB;gBAC/D,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE,SAAS,CAAC,EAAE,UAAU;cAqCvD,UAAU,CACxB,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,IAAI,CAAC;cAOA,aAAa,CAC3B,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAClC,OAAO,CAAC,IAAI,CAAC;cAMA,iBAAiB,CAC/B,YAAY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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;cA+VN,kBAAkB,CAChC,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,qBAAqB,EAC/B,KAAK,EAAE,IAAI,EAAE,GACZ,OAAO,CAAC,OAAO,CAAC;cAIH,cAAc,CAC5B,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,qBAAqB,EAC/B,KAAK,EAAE,IAAI,EAAE,GACZ,OAAO,CAAC,IAAI,CAAC;IA2ChB,OAAO,CAAC,oBAAoB;IAkC5B,OAAO,CAAC,oBAAoB;CA4B7B;AAqQD,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"build_dom_tree.d.ts","sourceRoot":"","sources":["../../../src/agent/browser/build_dom_tree.ts"],"names":[],"mappings":"AACA,wBAAgB,kBAAkB,SA+pBjC"}
1
+ {"version":3,"file":"build_dom_tree.d.ts","sourceRoot":"","sources":["../../../src/agent/browser/build_dom_tree.ts"],"names":[],"mappings":"AACA,wBAAgB,kBAAkB,SAgqBjC"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/common/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEjD;AAED,wBAAgB,MAAM,IAAI,MAAM,CAM/B;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,OAAO,CAAC,GAA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O,CAAC,QAAQ,CAAC;IAcP,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAuB3C,GAAG,CACd,UAAU,EAAE,MAAM,EAClB,MAAM,GAAE,MAAiB,EACzB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAClC,OAAO,CAAC,SAAS,CAAC;IAKR,WAAW,CACtB,QAAQ,EAAE,QAAQ,EAClB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAClC,OAAO,CAAC,OAAO,CAAC;YAoBL,aAAa;IAkCpB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAI5C,YAAY,IAAI,MAAM,EAAE;IAIxB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAInC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAUlC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO;IAUnD,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;CAIpC"}
package/dist/index.cjs.js CHANGED
@@ -12,7 +12,7 @@ const config = {
12
12
  compressThreshold: 80,
13
13
  largeTextLength: 5000,
14
14
  fileTextMaxLength: 20000,
15
- maxDialogueImgFileNum: 2,
15
+ maxDialogueImgFileNum: 1,
16
16
  };
17
17
 
18
18
  var LogLevel;
@@ -289,6 +289,9 @@ function sub(str, maxLength, appendPoint = true) {
289
289
  return str;
290
290
  }
291
291
  function fixXmlTag(code) {
292
+ if (code.indexOf('&') > -1) {
293
+ code = code.replace(/&(?![a-zA-Z0-9#]+;)/g, '&amp;');
294
+ }
292
295
  function fixDoubleChar(code) {
293
296
  const stack = [];
294
297
  for (let i = 0; i < code.length; i++) {
@@ -17930,7 +17933,7 @@ class HumanInteractTool {
17930
17933
  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.
17931
17934
  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.
17932
17935
  select: Allow the user to make a choice; in situations that require selection, the AI can ask the user to make a decision.
17933
- 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.`;
17936
+ 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 or Scan the QR code.`;
17934
17937
  this.parameters = {
17935
17938
  type: "object",
17936
17939
  properties: {
@@ -18192,6 +18195,22 @@ class VariableStorageTool {
18192
18195
  }
18193
18196
 
18194
18197
  const TOOL_NAME = "watch_trigger";
18198
+ const watch_system_prompt = `You are a tool for detecting element changes. Given a task description, compare two images to determine whether the changes described in the task have occurred.
18199
+ If the changes have occurred, return an json with \`changed\` set to true and \`changeInfo\` containing a description of the changes. If no changes have occurred, return an object with \`changed\` set to false.
18200
+
18201
+ ## Example
18202
+ User: Monitor new messages in group chat
18203
+ ### No changes detected
18204
+ Output:
18205
+ {
18206
+ "changed": false
18207
+ }
18208
+ ### Change detected
18209
+ Output:
18210
+ {
18211
+ "changed": true,
18212
+ "changeInfo": "New message received in the group chat. The message content is: 'Hello, how are you?'"
18213
+ }`;
18195
18214
  class WatchTriggerTool {
18196
18215
  constructor() {
18197
18216
  this.name = TOOL_NAME;
@@ -18256,19 +18275,22 @@ class WatchTriggerTool {
18256
18275
  ],
18257
18276
  };
18258
18277
  }
18259
- const screenshot = agentContext.agent["screenshot"];
18260
- const image1Result = (await screenshot.call(agentContext.agent, agentContext));
18261
- const image1 = toImage(image1Result.imageBase64);
18278
+ await this.init_eko_observer(agentContext);
18279
+ const image1 = await this.get_screenshot(agentContext);
18262
18280
  const start = new Date().getTime();
18263
18281
  const timeout = (args.timeout || 5) * 60000;
18264
- const frequency = Math.max(500, (args.frequency = args.frequency || 1) * 1000);
18282
+ const frequency = Math.max(500, (args.frequency || 1) * 1000);
18265
18283
  let rlm = new RetryLanguageModel(agentContext.context.config.llms, agentContext.agent.Llms);
18266
18284
  while (new Date().getTime() - start < timeout) {
18267
18285
  await agentContext.context.checkAborted();
18268
18286
  await new Promise((resolve) => setTimeout(resolve, frequency));
18269
- const image2Result = (await screenshot.call(agentContext.agent, agentContext));
18270
- const image2 = toImage(image2Result.imageBase64);
18271
- const changeResult = await this.is_dom_change(agentContext, rlm, image1, image1Result.imageType, image2, image2Result.imageType, task_description);
18287
+ let changed = await this.has_eko_changed(agentContext);
18288
+ if (changed == "false") {
18289
+ continue;
18290
+ }
18291
+ await this.init_eko_observer(agentContext);
18292
+ const image2 = await this.get_screenshot(agentContext);
18293
+ const changeResult = await this.is_dom_change(agentContext, rlm, image1, image2, task_description);
18272
18294
  if (changeResult.changed) {
18273
18295
  return {
18274
18296
  content: [
@@ -18289,41 +18311,73 @@ class WatchTriggerTool {
18289
18311
  ],
18290
18312
  };
18291
18313
  }
18292
- async is_dom_change(agentContext, rlm, image1, image1Type, image2, image2Type, task_description) {
18314
+ async get_screenshot(agentContext) {
18315
+ const screenshot = agentContext.agent["screenshot"];
18316
+ const imageResult = (await screenshot.call(agentContext.agent, agentContext));
18317
+ const image = toImage(imageResult.imageBase64);
18318
+ return {
18319
+ image: image,
18320
+ imageType: imageResult.imageType,
18321
+ };
18322
+ }
18323
+ async init_eko_observer(agentContext) {
18324
+ try {
18325
+ const screenshot = agentContext.agent["execute_script"];
18326
+ await screenshot.call(agentContext.agent, agentContext, () => {
18327
+ let _window = window;
18328
+ _window.has_eko_changed = false;
18329
+ _window.eko_observer && _window.eko_observer.disconnect();
18330
+ let eko_observer = new MutationObserver(function (mutations) {
18331
+ _window.has_eko_changed = true;
18332
+ });
18333
+ eko_observer.observe(document.body, {
18334
+ childList: true,
18335
+ subtree: true,
18336
+ attributes: true,
18337
+ attributeOldValue: true,
18338
+ characterData: true,
18339
+ characterDataOldValue: true,
18340
+ });
18341
+ _window.eko_observer = eko_observer;
18342
+ }, []);
18343
+ }
18344
+ catch (error) {
18345
+ console.error("Error initializing Eko observer:", error);
18346
+ }
18347
+ }
18348
+ async has_eko_changed(agentContext) {
18349
+ try {
18350
+ const screenshot = agentContext.agent["execute_script"];
18351
+ let result = (await screenshot.call(agentContext.agent, agentContext, () => {
18352
+ return window.has_eko_changed + "";
18353
+ }, []));
18354
+ return result;
18355
+ }
18356
+ catch (e) {
18357
+ console.error("Error checking Eko change:", e);
18358
+ return "undefined";
18359
+ }
18360
+ }
18361
+ async is_dom_change(agentContext, rlm, image1, image2, task_description) {
18293
18362
  try {
18294
18363
  let request = {
18295
18364
  messages: [
18296
18365
  {
18297
18366
  role: "system",
18298
- content: `You are a tool for detecting element changes. Given a task description, compare two images to determine whether the changes described in the task have occurred.
18299
- If the changes have occurred, return an json with \`changed\` set to true and \`changeInfo\` containing a description of the changes. If no changes have occurred, return an object with \`changed\` set to false.
18300
-
18301
- ## Example
18302
- User: Monitor new messages in group chat
18303
- ### No changes detected
18304
- Output:
18305
- {
18306
- "changed": false
18307
- }
18308
- ### Change detected
18309
- Output:
18310
- {
18311
- "changed": true,
18312
- "changeInfo": "New message received in the group chat. The message content is: 'Hello, how are you?'"
18313
- }`,
18367
+ content: watch_system_prompt,
18314
18368
  },
18315
18369
  {
18316
18370
  role: "user",
18317
18371
  content: [
18318
18372
  {
18319
18373
  type: "image",
18320
- image: image1,
18321
- mimeType: image1Type,
18374
+ image: image1.image,
18375
+ mimeType: image1.imageType,
18322
18376
  },
18323
18377
  {
18324
18378
  type: "image",
18325
- image: image2,
18326
- mimeType: image2Type,
18379
+ image: image2.image,
18380
+ mimeType: image2.imageType,
18327
18381
  },
18328
18382
  {
18329
18383
  type: "text",
@@ -18387,9 +18441,8 @@ const HUMAN_PROMPT = `
18387
18441
  * HUMAN INTERACT
18388
18442
  During the task execution process, you can use the \`${TOOL_NAME$3}\` tool to interact with humans, please call it in the following situations:
18389
18443
  - When performing dangerous operations such as deleting files, confirmation from humans is required.
18390
- - When encountering obstacles while visiting a website, such as requiring user login or captcha, you need to request for manual assistance.
18391
- - When requesting login, please only call the function when a login dialog box is clearly displayed.
18392
- - Try to minimize the use of \`${TOOL_NAME$3}\` tool.
18444
+ - When encountering obstacles while accessing websites, such as requiring user login, captcha verification, QR code scanning, or human verification, you need to request manual assistance.
18445
+ - Please do not use the \`${TOOL_NAME$3}\` tool frequently.
18393
18446
  `;
18394
18447
  const VARIABLE_PROMPT = `
18395
18448
  * VARIABLE STORAGE
@@ -19371,6 +19424,9 @@ class Eko {
19371
19424
  if (!context) {
19372
19425
  throw new Error("The task does not exist");
19373
19426
  }
19427
+ if (context.paused) {
19428
+ context.paused = false;
19429
+ }
19374
19430
  if (context.controller.signal.aborted) {
19375
19431
  context.controller = new AbortController();
19376
19432
  }
@@ -20444,7 +20500,8 @@ function run_build_dom_tree() {
20444
20500
  return { element_str, selector_map };
20445
20501
  }
20446
20502
  function get_highlight_element(highlightIndex) {
20447
- return window.clickable_elements[highlightIndex];
20503
+ let element = document.querySelector(`[eko-user-highlight-id="eko-highlight-${highlightIndex}"]`);
20504
+ return element || window.clickable_elements[highlightIndex];
20448
20505
  }
20449
20506
  function remove_highlight() {
20450
20507
  let highlight = document.getElementById('eko-highlight-container');
@@ -21035,6 +21092,7 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
21035
21092
  - Only use indexes that exist in the provided element list
21036
21093
  - Each element has a unique index number (e.g., "[33]:<button>")
21037
21094
  - Elements marked with "[]:" are non-interactive (for context only)
21095
+ - Use the latest element index, do not rely on historical outdated element indexes
21038
21096
  * ERROR HANDLING:
21039
21097
  - If no suitable elements exist, use other functions to complete the task
21040
21098
  - If stuck, try alternative approaches, don't refuse tasks
@@ -21092,7 +21150,8 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
21092
21150
  }
21093
21151
  if (extract_page_content) {
21094
21152
  let page_content = await this.extract_page_content(agentContext);
21095
- return "The current page content has been extracted, latest page content:\n" + page_content;
21153
+ return ("The current page content has been extracted, latest page content:\n" +
21154
+ page_content);
21096
21155
  }
21097
21156
  }
21098
21157
  async hover_to_element(agentContext, index) {
@@ -21448,27 +21507,34 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
21448
21507
  ],
21449
21508
  });
21450
21509
  }
21451
- if (messages.length > 10) {
21452
- // compressed pseudoHtml
21453
- for (let i = 2; i < messages.length - 3; i++) {
21454
- let message = messages[i];
21455
- if (message.role == "user" && message.content.length == 2) {
21456
- let content = message.content;
21457
- for (let j = 0; j < content.length; j++) {
21458
- let _content = content[j];
21459
- if (_content.type == "text" &&
21460
- _content.text.startsWith(pseudoHtmlDescription)) {
21461
- _content.text = this.removePseudoHtmlAttr(_content.text, [
21462
- "class",
21463
- "src",
21464
- "href",
21465
- ]);
21466
- }
21510
+ super.handleMessages(agentContext, messages, tools);
21511
+ this.handlePseudoHtmlText(messages, pseudoHtmlDescription);
21512
+ }
21513
+ handlePseudoHtmlText(messages, pseudoHtmlDescription) {
21514
+ for (let i = 0; i < messages.length; i++) {
21515
+ let message = messages[i];
21516
+ if (message.role !== "user" || message.content.length <= 1) {
21517
+ continue;
21518
+ }
21519
+ let content = message.content;
21520
+ for (let j = 0; j < content.length; j++) {
21521
+ let _content = content[j];
21522
+ if (_content.type == "text" &&
21523
+ _content.text.startsWith(pseudoHtmlDescription)) {
21524
+ if (i >= 2 && i < messages.length - 3) {
21525
+ _content.text = this.removePseudoHtmlAttr(_content.text, [
21526
+ "class",
21527
+ "src",
21528
+ "href",
21529
+ ]);
21467
21530
  }
21468
21531
  }
21469
21532
  }
21533
+ if (content[0].text == "[image]" &&
21534
+ content[1].text == "[image]") {
21535
+ content.splice(0, 1);
21536
+ }
21470
21537
  }
21471
- super.handleMessages(agentContext, messages, tools);
21472
21538
  }
21473
21539
  removePseudoHtmlAttr(pseudoHtml, remove_attrs) {
21474
21540
  return pseudoHtml
@@ -21477,6 +21543,7 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
21477
21543
  if (!line.startsWith("[") || line.indexOf("]:<") == -1) {
21478
21544
  return line;
21479
21545
  }
21546
+ line = line.substring(line.indexOf("]:<") + 2);
21480
21547
  for (let i = 0; i < remove_attrs.length; i++) {
21481
21548
  let sIdx = line.indexOf(remove_attrs[i] + '="');
21482
21549
  if (sIdx == -1) {
@@ -21488,12 +21555,9 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
21488
21555
  }
21489
21556
  line =
21490
21557
  line.substring(0, sIdx) +
21491
- line
21492
- .substring(eIdx + 1)
21493
- .trim()
21494
- .replace('" >', '">');
21558
+ line.substring(eIdx + 1).trim();
21495
21559
  }
21496
- return line;
21560
+ return line.replace('" >', '">').replace(" >", ">");
21497
21561
  })
21498
21562
  .join("\n");
21499
21563
  }