@eko-ai/eko 2.1.2 → 2.1.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.cjs.js
CHANGED
|
@@ -17930,7 +17930,7 @@ class HumanInteractTool {
|
|
|
17930
17930
|
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
17931
|
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
17932
|
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.`;
|
|
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 or Scan the QR code.`;
|
|
17934
17934
|
this.parameters = {
|
|
17935
17935
|
type: "object",
|
|
17936
17936
|
properties: {
|
|
@@ -18192,6 +18192,22 @@ class VariableStorageTool {
|
|
|
18192
18192
|
}
|
|
18193
18193
|
|
|
18194
18194
|
const TOOL_NAME = "watch_trigger";
|
|
18195
|
+
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.
|
|
18196
|
+
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.
|
|
18197
|
+
|
|
18198
|
+
## Example
|
|
18199
|
+
User: Monitor new messages in group chat
|
|
18200
|
+
### No changes detected
|
|
18201
|
+
Output:
|
|
18202
|
+
{
|
|
18203
|
+
"changed": false
|
|
18204
|
+
}
|
|
18205
|
+
### Change detected
|
|
18206
|
+
Output:
|
|
18207
|
+
{
|
|
18208
|
+
"changed": true,
|
|
18209
|
+
"changeInfo": "New message received in the group chat. The message content is: 'Hello, how are you?'"
|
|
18210
|
+
}`;
|
|
18195
18211
|
class WatchTriggerTool {
|
|
18196
18212
|
constructor() {
|
|
18197
18213
|
this.name = TOOL_NAME;
|
|
@@ -18256,19 +18272,22 @@ class WatchTriggerTool {
|
|
|
18256
18272
|
],
|
|
18257
18273
|
};
|
|
18258
18274
|
}
|
|
18259
|
-
|
|
18260
|
-
const
|
|
18261
|
-
const image1 = toImage(image1Result.imageBase64);
|
|
18275
|
+
await this.init_eko_observer(agentContext);
|
|
18276
|
+
const image1 = await this.get_screenshot(agentContext);
|
|
18262
18277
|
const start = new Date().getTime();
|
|
18263
18278
|
const timeout = (args.timeout || 5) * 60000;
|
|
18264
|
-
const frequency = Math.max(500, (args.frequency
|
|
18279
|
+
const frequency = Math.max(500, (args.frequency || 1) * 1000);
|
|
18265
18280
|
let rlm = new RetryLanguageModel(agentContext.context.config.llms, agentContext.agent.Llms);
|
|
18266
18281
|
while (new Date().getTime() - start < timeout) {
|
|
18267
18282
|
await agentContext.context.checkAborted();
|
|
18268
18283
|
await new Promise((resolve) => setTimeout(resolve, frequency));
|
|
18269
|
-
|
|
18270
|
-
|
|
18271
|
-
|
|
18284
|
+
let changed = await this.has_eko_changed(agentContext);
|
|
18285
|
+
if (changed == "false") {
|
|
18286
|
+
continue;
|
|
18287
|
+
}
|
|
18288
|
+
await this.init_eko_observer(agentContext);
|
|
18289
|
+
const image2 = await this.get_screenshot(agentContext);
|
|
18290
|
+
const changeResult = await this.is_dom_change(agentContext, rlm, image1, image2, task_description);
|
|
18272
18291
|
if (changeResult.changed) {
|
|
18273
18292
|
return {
|
|
18274
18293
|
content: [
|
|
@@ -18289,41 +18308,73 @@ class WatchTriggerTool {
|
|
|
18289
18308
|
],
|
|
18290
18309
|
};
|
|
18291
18310
|
}
|
|
18292
|
-
async
|
|
18311
|
+
async get_screenshot(agentContext) {
|
|
18312
|
+
const screenshot = agentContext.agent["screenshot"];
|
|
18313
|
+
const imageResult = (await screenshot.call(agentContext.agent, agentContext));
|
|
18314
|
+
const image = toImage(imageResult.imageBase64);
|
|
18315
|
+
return {
|
|
18316
|
+
image: image,
|
|
18317
|
+
imageType: imageResult.imageType,
|
|
18318
|
+
};
|
|
18319
|
+
}
|
|
18320
|
+
async init_eko_observer(agentContext) {
|
|
18321
|
+
try {
|
|
18322
|
+
const screenshot = agentContext.agent["execute_script"];
|
|
18323
|
+
await screenshot.call(agentContext.agent, agentContext, () => {
|
|
18324
|
+
let _window = window;
|
|
18325
|
+
_window.has_eko_changed = false;
|
|
18326
|
+
_window.eko_observer && _window.eko_observer.disconnect();
|
|
18327
|
+
let eko_observer = new MutationObserver(function (mutations) {
|
|
18328
|
+
_window.has_eko_changed = true;
|
|
18329
|
+
});
|
|
18330
|
+
eko_observer.observe(document.body, {
|
|
18331
|
+
childList: true,
|
|
18332
|
+
subtree: true,
|
|
18333
|
+
attributes: true,
|
|
18334
|
+
attributeOldValue: true,
|
|
18335
|
+
characterData: true,
|
|
18336
|
+
characterDataOldValue: true,
|
|
18337
|
+
});
|
|
18338
|
+
_window.eko_observer = eko_observer;
|
|
18339
|
+
}, []);
|
|
18340
|
+
}
|
|
18341
|
+
catch (error) {
|
|
18342
|
+
console.error("Error initializing Eko observer:", error);
|
|
18343
|
+
}
|
|
18344
|
+
}
|
|
18345
|
+
async has_eko_changed(agentContext) {
|
|
18346
|
+
try {
|
|
18347
|
+
const screenshot = agentContext.agent["execute_script"];
|
|
18348
|
+
let result = (await screenshot.call(agentContext.agent, agentContext, () => {
|
|
18349
|
+
return window.has_eko_changed + "";
|
|
18350
|
+
}, []));
|
|
18351
|
+
return result;
|
|
18352
|
+
}
|
|
18353
|
+
catch (e) {
|
|
18354
|
+
console.error("Error checking Eko change:", e);
|
|
18355
|
+
return "undefined";
|
|
18356
|
+
}
|
|
18357
|
+
}
|
|
18358
|
+
async is_dom_change(agentContext, rlm, image1, image2, task_description) {
|
|
18293
18359
|
try {
|
|
18294
18360
|
let request = {
|
|
18295
18361
|
messages: [
|
|
18296
18362
|
{
|
|
18297
18363
|
role: "system",
|
|
18298
|
-
content:
|
|
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
|
-
}`,
|
|
18364
|
+
content: watch_system_prompt,
|
|
18314
18365
|
},
|
|
18315
18366
|
{
|
|
18316
18367
|
role: "user",
|
|
18317
18368
|
content: [
|
|
18318
18369
|
{
|
|
18319
18370
|
type: "image",
|
|
18320
|
-
image: image1,
|
|
18321
|
-
mimeType:
|
|
18371
|
+
image: image1.image,
|
|
18372
|
+
mimeType: image1.imageType,
|
|
18322
18373
|
},
|
|
18323
18374
|
{
|
|
18324
18375
|
type: "image",
|
|
18325
|
-
image: image2,
|
|
18326
|
-
mimeType:
|
|
18376
|
+
image: image2.image,
|
|
18377
|
+
mimeType: image2.imageType,
|
|
18327
18378
|
},
|
|
18328
18379
|
{
|
|
18329
18380
|
type: "text",
|
|
@@ -18387,9 +18438,8 @@ const HUMAN_PROMPT = `
|
|
|
18387
18438
|
* HUMAN INTERACT
|
|
18388
18439
|
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
18440
|
- When performing dangerous operations such as deleting files, confirmation from humans is required.
|
|
18390
|
-
- When encountering obstacles while
|
|
18391
|
-
-
|
|
18392
|
-
- Try to minimize the use of \`${TOOL_NAME$3}\` tool.
|
|
18441
|
+
- 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.
|
|
18442
|
+
- Please do not use the \`${TOOL_NAME$3}\` tool frequently.
|
|
18393
18443
|
`;
|
|
18394
18444
|
const VARIABLE_PROMPT = `
|
|
18395
18445
|
* VARIABLE STORAGE
|