@eko-ai/eko 1.3.1 → 1.3.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/common/context-compressor.d.ts +10 -0
- package/dist/extension/tools/tab_management.d.ts +0 -6
- package/dist/extension.cjs.js +76 -92
- package/dist/extension.esm.js +76 -92
- package/dist/extension_content_script.js +24 -2
- package/dist/index.cjs.js +169 -70
- package/dist/index.esm.js +169 -70
- package/dist/nodejs.cjs.js +24 -2
- package/dist/nodejs.esm.js +24 -2
- package/dist/schemas/workflow.schema.d.ts +1 -29
- package/dist/types/tools.types.d.ts +2 -1
- package/dist/utils/sleep.d.ts +1 -0
- package/dist/web.cjs.js +24 -2
- package/dist/web.esm.js +24 -2
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Message } from "@/types";
|
|
2
|
+
export declare abstract class ContextComporessor {
|
|
3
|
+
abstract comporess(messages: Message[]): Message[];
|
|
4
|
+
}
|
|
5
|
+
export declare class NoComporess extends ContextComporessor {
|
|
6
|
+
comporess(messages: Message[]): Message[];
|
|
7
|
+
}
|
|
8
|
+
export declare class SimpleQAComporess extends ContextComporessor {
|
|
9
|
+
comporess(messages: Message[]): Message[];
|
|
10
|
+
}
|
|
@@ -8,12 +8,6 @@ export declare class TabManagement implements Tool<TabManagementParam, TabManage
|
|
|
8
8
|
description: string;
|
|
9
9
|
input_schema: InputSchema;
|
|
10
10
|
constructor();
|
|
11
|
-
/**
|
|
12
|
-
* Tab management
|
|
13
|
-
*
|
|
14
|
-
* @param {*} params { command: `new_tab [url]` | 'tab_all' | 'current_tab' | 'go_back' | 'close_tab' | 'switch_tab [tabId]' }
|
|
15
|
-
* @returns > { result, success: true }
|
|
16
|
-
*/
|
|
17
11
|
execute(context: ExecutionContext, params: TabManagementParam): Promise<TabManagementResult>;
|
|
18
12
|
destroy(context: ExecutionContext): void;
|
|
19
13
|
}
|
package/dist/extension.cjs.js
CHANGED
|
@@ -600,9 +600,31 @@ class Logger extends BaseLogger {
|
|
|
600
600
|
}
|
|
601
601
|
|
|
602
602
|
function transportFormatted(logMetaMarkup, logArgs, logErrors, settings) {
|
|
603
|
-
const logErrorsStr = (logErrors.length > 0 && logArgs.length > 0 ? "\n" : "") + logErrors.join("\n");
|
|
604
603
|
settings.prettyInspectOptions.colors = settings.stylePrettyLogs;
|
|
605
|
-
|
|
604
|
+
const logLevel = logMetaMarkup.trim().split(" ")[2];
|
|
605
|
+
let logFunc;
|
|
606
|
+
switch (logLevel) {
|
|
607
|
+
case "WARN":
|
|
608
|
+
logFunc = console.warn;
|
|
609
|
+
break;
|
|
610
|
+
case "ERROR":
|
|
611
|
+
case "FATAL":
|
|
612
|
+
logFunc = console.error;
|
|
613
|
+
break;
|
|
614
|
+
case "INFO":
|
|
615
|
+
logFunc = console.info;
|
|
616
|
+
break;
|
|
617
|
+
case "DEBUG":
|
|
618
|
+
case "TRACE":
|
|
619
|
+
case "SILLY":
|
|
620
|
+
default:
|
|
621
|
+
logFunc = console.debug;
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
logFunc(logMetaMarkup, ...logArgs);
|
|
625
|
+
logErrors.forEach(err => {
|
|
626
|
+
console.error(logMetaMarkup + err);
|
|
627
|
+
});
|
|
606
628
|
}
|
|
607
629
|
function formatMeta(logObjMeta) {
|
|
608
630
|
if (!logObjMeta) {
|
|
@@ -663,50 +685,34 @@ async function getWindowId(context) {
|
|
|
663
685
|
return windowId;
|
|
664
686
|
}
|
|
665
687
|
async function getTabId(context) {
|
|
666
|
-
logger.debug("
|
|
667
|
-
let
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
logger.debug("tabId is empty");
|
|
679
|
-
let windowId = await getWindowId(context);
|
|
680
|
-
logger.debug(`windowId=${windowId}`);
|
|
681
|
-
if (windowId) {
|
|
682
|
-
try {
|
|
683
|
-
tabId = await getCurrentTabId(context.ekoConfig.chromeProxy, windowId);
|
|
684
|
-
logger.debug("getCurrentTabId(context.ekoConfig.chromeProxy, windowId) returns " + tabId);
|
|
685
|
-
}
|
|
686
|
-
catch (e) {
|
|
687
|
-
tabId = await getCurrentTabId(context.ekoConfig.chromeProxy);
|
|
688
|
-
logger.debug("getCurrentTabId(context.ekoConfig.chromeProxy, windowId) throws an error");
|
|
689
|
-
logger.debug("getCurrentTabId(context.ekoConfig.chromeProxy) returns " + tabId);
|
|
690
|
-
context.variables.delete('windowId');
|
|
691
|
-
}
|
|
688
|
+
logger.debug("getTabId()...");
|
|
689
|
+
let tabs = await context.ekoConfig.chromeProxy.tabs.query({});
|
|
690
|
+
logger.debug("all tabs:", tabs);
|
|
691
|
+
const filtered = tabs.filter((tab) => tab.title && tab.url);
|
|
692
|
+
logger.debug("filtered:", filtered);
|
|
693
|
+
if (filtered.length > 0) {
|
|
694
|
+
if (typeof filtered[0].activeTime != "undefined") {
|
|
695
|
+
const sorted = filtered.sort((a, b) => parseInt(b.activeTime) - parseInt(a.activeTime));
|
|
696
|
+
logger.debug("sorted tabs:", sorted);
|
|
697
|
+
const tabId = sorted[0].id;
|
|
698
|
+
logger.debug("tabId:", tabId);
|
|
699
|
+
return tabId;
|
|
692
700
|
}
|
|
693
701
|
else {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
if (fellouTabId) {
|
|
700
|
-
tabId = fellouTabId;
|
|
702
|
+
tabs = await context.ekoConfig.chromeProxy.tabs.query({ active: true, currentWindow: true });
|
|
703
|
+
if (tabs.length > 0) {
|
|
704
|
+
const tabId = tabs[0].id;
|
|
705
|
+
logger.debug("tabId:", tabId);
|
|
706
|
+
return tabId;
|
|
701
707
|
}
|
|
702
708
|
else {
|
|
703
|
-
throw
|
|
709
|
+
throw Error("no active tab found");
|
|
704
710
|
}
|
|
705
711
|
}
|
|
706
|
-
context.variables.set('tabId', tabId);
|
|
707
712
|
}
|
|
708
|
-
|
|
709
|
-
|
|
713
|
+
else {
|
|
714
|
+
throw Error("no tab found");
|
|
715
|
+
}
|
|
710
716
|
}
|
|
711
717
|
function getCurrentTabId(chromeProxy, windowId) {
|
|
712
718
|
return new Promise((resolve, reject) => {
|
|
@@ -721,7 +727,7 @@ function getCurrentTabId(chromeProxy, windowId) {
|
|
|
721
727
|
logger.debug(`get the active tabId on current window`);
|
|
722
728
|
queryInfo = { active: true, currentWindow: true };
|
|
723
729
|
}
|
|
724
|
-
|
|
730
|
+
chromeProxy.tabs.query(queryInfo, (tabs) => {
|
|
725
731
|
if (chromeProxy.runtime.lastError) {
|
|
726
732
|
logger.error(`failed to get: `, chromeProxy.runtime.lastError);
|
|
727
733
|
reject(chromeProxy.runtime.lastError);
|
|
@@ -1954,65 +1960,31 @@ class TabManagement {
|
|
|
1954
1960
|
type: 'string',
|
|
1955
1961
|
description: `The command to perform. The available commands are:
|
|
1956
1962
|
* \`tab_all\`: View all tabs and return the tabId and title.
|
|
1957
|
-
* \`current_tab\`: Get current tab information (tabId, url, title).
|
|
1958
1963
|
* \`go_back\`: Go back to the previous page in the current tab.
|
|
1959
|
-
* \`
|
|
1960
|
-
enum: ['tab_all', '
|
|
1964
|
+
* \`switch_tab\`: Switch to the specified tab by tabId.`,
|
|
1965
|
+
enum: ['tab_all', 'go_back', 'switch_tab'],
|
|
1966
|
+
},
|
|
1967
|
+
tabId: {
|
|
1968
|
+
type: 'integer',
|
|
1969
|
+
description: "Tab id. Only needed when using 'switch_tab'",
|
|
1961
1970
|
},
|
|
1962
1971
|
},
|
|
1963
1972
|
required: ['command'],
|
|
1964
1973
|
};
|
|
1965
1974
|
}
|
|
1966
|
-
/**
|
|
1967
|
-
* Tab management
|
|
1968
|
-
*
|
|
1969
|
-
* @param {*} params { command: `new_tab [url]` | 'tab_all' | 'current_tab' | 'go_back' | 'close_tab' | 'switch_tab [tabId]' }
|
|
1970
|
-
* @returns > { result, success: true }
|
|
1971
|
-
*/
|
|
1972
1975
|
async execute(context, params) {
|
|
1973
1976
|
if (params === null || !params.command) {
|
|
1974
1977
|
throw new Error('Invalid parameters. Expected an object with a "command" property.');
|
|
1975
1978
|
}
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
if (command.startsWith('`')) {
|
|
1979
|
-
command = command.substring(1);
|
|
1980
|
-
}
|
|
1981
|
-
if (command.endsWith('`')) {
|
|
1982
|
-
command = command.substring(0, command.length - 1);
|
|
1983
|
-
}
|
|
1984
|
-
let result;
|
|
1985
|
-
if (command == 'tab_all') {
|
|
1986
|
-
result = [];
|
|
1987
|
-
let tabs = await context.ekoConfig.chromeProxy.tabs.query({ windowId: windowId });
|
|
1988
|
-
for (let i = 0; i < tabs.length; i++) {
|
|
1989
|
-
let tab = tabs[i];
|
|
1990
|
-
let tabInfo = {
|
|
1991
|
-
tabId: tab.id,
|
|
1992
|
-
windowId: tab.windowId,
|
|
1993
|
-
title: tab.title,
|
|
1994
|
-
url: tab.url,
|
|
1995
|
-
};
|
|
1996
|
-
if (tab.active) {
|
|
1997
|
-
tabInfo.active = true;
|
|
1998
|
-
}
|
|
1999
|
-
result.push(tabInfo);
|
|
2000
|
-
}
|
|
2001
|
-
}
|
|
2002
|
-
else if (command == 'current_tab') {
|
|
2003
|
-
let tabId = await getTabId(context);
|
|
2004
|
-
let tab = await context.ekoConfig.chromeProxy.tabs.get(tabId);
|
|
2005
|
-
let tabInfo = { tabId, windowId: tab.windowId, title: tab.title, url: tab.url };
|
|
2006
|
-
result = tabInfo;
|
|
2007
|
-
}
|
|
2008
|
-
else if (command == 'go_back') {
|
|
1979
|
+
if (params.command == 'tab_all') ;
|
|
1980
|
+
else if (params.command == 'go_back') {
|
|
2009
1981
|
let tabId = await getTabId(context);
|
|
2010
1982
|
await context.ekoConfig.chromeProxy.tabs.goBack(tabId);
|
|
2011
|
-
let tab = await context.ekoConfig.chromeProxy.tabs.get(tabId);
|
|
2012
|
-
let tabInfo = { tabId, windowId: tab.windowId, title: tab.title, url: tab.url };
|
|
2013
|
-
result = tabInfo;
|
|
2014
1983
|
}
|
|
2015
|
-
else if (command ==
|
|
1984
|
+
else if (params.command == "switch_tab") {
|
|
1985
|
+
await context.ekoConfig.chromeProxy.tabs.select(params.tabId);
|
|
1986
|
+
}
|
|
1987
|
+
else if (params.command == 'close_tab') {
|
|
2016
1988
|
let closedTabId = await getTabId(context);
|
|
2017
1989
|
await context.ekoConfig.chromeProxy.tabs.remove(closedTabId);
|
|
2018
1990
|
await sleep(100);
|
|
@@ -2024,16 +1996,28 @@ class TabManagement {
|
|
|
2024
1996
|
if (!tab.active) {
|
|
2025
1997
|
await context.ekoConfig.chromeProxy.tabs.update(tab.id, { active: true });
|
|
2026
1998
|
}
|
|
2027
|
-
let newTabId = tab.id;
|
|
2028
1999
|
context.variables.set('tabId', tab.id);
|
|
2029
2000
|
context.variables.set('windowId', tab.windowId);
|
|
2030
|
-
let closeTabInfo = { closedTabId, newTabId, newTabTitle: tab.title };
|
|
2031
|
-
result = closeTabInfo;
|
|
2032
2001
|
}
|
|
2033
2002
|
else {
|
|
2034
|
-
throw Error('Unknown command: ' + command);
|
|
2003
|
+
throw Error('Unknown command: ' + params.command);
|
|
2004
|
+
}
|
|
2005
|
+
// build return value
|
|
2006
|
+
let tabs = await context.ekoConfig.chromeProxy.tabs.query({});
|
|
2007
|
+
tabs = tabs.filter((tab) => tab.title && tab.url);
|
|
2008
|
+
if (tabs.length > 0) {
|
|
2009
|
+
let result = "After operation, the existing tabs are as follows:\n";
|
|
2010
|
+
for (const tab of tabs) {
|
|
2011
|
+
result += `<tab><id>${tab.id}</id><title>${tab.title}</title><url>${tab.url}</url></tab>\n`;
|
|
2012
|
+
}
|
|
2013
|
+
let currentTabId = await getTabId(context);
|
|
2014
|
+
let currentTab = await context.ekoConfig.chromeProxy.tabs.get(currentTabId);
|
|
2015
|
+
result += `The current active tab: <tab><id>${currentTab.id}</id><title>${currentTab.title}</title><url>${currentTab.url}</url></tab>`;
|
|
2016
|
+
return result;
|
|
2017
|
+
}
|
|
2018
|
+
else {
|
|
2019
|
+
return "No existing tab. Use 'open_url' to open a new tab";
|
|
2035
2020
|
}
|
|
2036
|
-
return result;
|
|
2037
2021
|
}
|
|
2038
2022
|
destroy(context) {
|
|
2039
2023
|
let windowIds = context.variables.get('windowIds');
|
|
@@ -2092,7 +2076,7 @@ class WebSearch {
|
|
|
2092
2076
|
let searchs = [{ url: url, keyword: query }];
|
|
2093
2077
|
let searchInfo = await deepSearch(context, taskId, searchs, maxResults || 5, context.ekoConfig.workingWindowId);
|
|
2094
2078
|
let links = ((_b = searchInfo.result[0]) === null || _b === void 0 ? void 0 : _b.links) || [];
|
|
2095
|
-
return links.filter((s) => s.content);
|
|
2079
|
+
return links.filter((s) => s.content.slice(0, 8000));
|
|
2096
2080
|
}
|
|
2097
2081
|
}
|
|
2098
2082
|
const deepSearchInjects = {
|
package/dist/extension.esm.js
CHANGED
|
@@ -598,9 +598,31 @@ class Logger extends BaseLogger {
|
|
|
598
598
|
}
|
|
599
599
|
|
|
600
600
|
function transportFormatted(logMetaMarkup, logArgs, logErrors, settings) {
|
|
601
|
-
const logErrorsStr = (logErrors.length > 0 && logArgs.length > 0 ? "\n" : "") + logErrors.join("\n");
|
|
602
601
|
settings.prettyInspectOptions.colors = settings.stylePrettyLogs;
|
|
603
|
-
|
|
602
|
+
const logLevel = logMetaMarkup.trim().split(" ")[2];
|
|
603
|
+
let logFunc;
|
|
604
|
+
switch (logLevel) {
|
|
605
|
+
case "WARN":
|
|
606
|
+
logFunc = console.warn;
|
|
607
|
+
break;
|
|
608
|
+
case "ERROR":
|
|
609
|
+
case "FATAL":
|
|
610
|
+
logFunc = console.error;
|
|
611
|
+
break;
|
|
612
|
+
case "INFO":
|
|
613
|
+
logFunc = console.info;
|
|
614
|
+
break;
|
|
615
|
+
case "DEBUG":
|
|
616
|
+
case "TRACE":
|
|
617
|
+
case "SILLY":
|
|
618
|
+
default:
|
|
619
|
+
logFunc = console.debug;
|
|
620
|
+
break;
|
|
621
|
+
}
|
|
622
|
+
logFunc(logMetaMarkup, ...logArgs);
|
|
623
|
+
logErrors.forEach(err => {
|
|
624
|
+
console.error(logMetaMarkup + err);
|
|
625
|
+
});
|
|
604
626
|
}
|
|
605
627
|
function formatMeta(logObjMeta) {
|
|
606
628
|
if (!logObjMeta) {
|
|
@@ -661,50 +683,34 @@ async function getWindowId(context) {
|
|
|
661
683
|
return windowId;
|
|
662
684
|
}
|
|
663
685
|
async function getTabId(context) {
|
|
664
|
-
logger.debug("
|
|
665
|
-
let
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
logger.debug("tabId is empty");
|
|
677
|
-
let windowId = await getWindowId(context);
|
|
678
|
-
logger.debug(`windowId=${windowId}`);
|
|
679
|
-
if (windowId) {
|
|
680
|
-
try {
|
|
681
|
-
tabId = await getCurrentTabId(context.ekoConfig.chromeProxy, windowId);
|
|
682
|
-
logger.debug("getCurrentTabId(context.ekoConfig.chromeProxy, windowId) returns " + tabId);
|
|
683
|
-
}
|
|
684
|
-
catch (e) {
|
|
685
|
-
tabId = await getCurrentTabId(context.ekoConfig.chromeProxy);
|
|
686
|
-
logger.debug("getCurrentTabId(context.ekoConfig.chromeProxy, windowId) throws an error");
|
|
687
|
-
logger.debug("getCurrentTabId(context.ekoConfig.chromeProxy) returns " + tabId);
|
|
688
|
-
context.variables.delete('windowId');
|
|
689
|
-
}
|
|
686
|
+
logger.debug("getTabId()...");
|
|
687
|
+
let tabs = await context.ekoConfig.chromeProxy.tabs.query({});
|
|
688
|
+
logger.debug("all tabs:", tabs);
|
|
689
|
+
const filtered = tabs.filter((tab) => tab.title && tab.url);
|
|
690
|
+
logger.debug("filtered:", filtered);
|
|
691
|
+
if (filtered.length > 0) {
|
|
692
|
+
if (typeof filtered[0].activeTime != "undefined") {
|
|
693
|
+
const sorted = filtered.sort((a, b) => parseInt(b.activeTime) - parseInt(a.activeTime));
|
|
694
|
+
logger.debug("sorted tabs:", sorted);
|
|
695
|
+
const tabId = sorted[0].id;
|
|
696
|
+
logger.debug("tabId:", tabId);
|
|
697
|
+
return tabId;
|
|
690
698
|
}
|
|
691
699
|
else {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
if (fellouTabId) {
|
|
698
|
-
tabId = fellouTabId;
|
|
700
|
+
tabs = await context.ekoConfig.chromeProxy.tabs.query({ active: true, currentWindow: true });
|
|
701
|
+
if (tabs.length > 0) {
|
|
702
|
+
const tabId = tabs[0].id;
|
|
703
|
+
logger.debug("tabId:", tabId);
|
|
704
|
+
return tabId;
|
|
699
705
|
}
|
|
700
706
|
else {
|
|
701
|
-
throw
|
|
707
|
+
throw Error("no active tab found");
|
|
702
708
|
}
|
|
703
709
|
}
|
|
704
|
-
context.variables.set('tabId', tabId);
|
|
705
710
|
}
|
|
706
|
-
|
|
707
|
-
|
|
711
|
+
else {
|
|
712
|
+
throw Error("no tab found");
|
|
713
|
+
}
|
|
708
714
|
}
|
|
709
715
|
function getCurrentTabId(chromeProxy, windowId) {
|
|
710
716
|
return new Promise((resolve, reject) => {
|
|
@@ -719,7 +725,7 @@ function getCurrentTabId(chromeProxy, windowId) {
|
|
|
719
725
|
logger.debug(`get the active tabId on current window`);
|
|
720
726
|
queryInfo = { active: true, currentWindow: true };
|
|
721
727
|
}
|
|
722
|
-
|
|
728
|
+
chromeProxy.tabs.query(queryInfo, (tabs) => {
|
|
723
729
|
if (chromeProxy.runtime.lastError) {
|
|
724
730
|
logger.error(`failed to get: `, chromeProxy.runtime.lastError);
|
|
725
731
|
reject(chromeProxy.runtime.lastError);
|
|
@@ -1952,65 +1958,31 @@ class TabManagement {
|
|
|
1952
1958
|
type: 'string',
|
|
1953
1959
|
description: `The command to perform. The available commands are:
|
|
1954
1960
|
* \`tab_all\`: View all tabs and return the tabId and title.
|
|
1955
|
-
* \`current_tab\`: Get current tab information (tabId, url, title).
|
|
1956
1961
|
* \`go_back\`: Go back to the previous page in the current tab.
|
|
1957
|
-
* \`
|
|
1958
|
-
enum: ['tab_all', '
|
|
1962
|
+
* \`switch_tab\`: Switch to the specified tab by tabId.`,
|
|
1963
|
+
enum: ['tab_all', 'go_back', 'switch_tab'],
|
|
1964
|
+
},
|
|
1965
|
+
tabId: {
|
|
1966
|
+
type: 'integer',
|
|
1967
|
+
description: "Tab id. Only needed when using 'switch_tab'",
|
|
1959
1968
|
},
|
|
1960
1969
|
},
|
|
1961
1970
|
required: ['command'],
|
|
1962
1971
|
};
|
|
1963
1972
|
}
|
|
1964
|
-
/**
|
|
1965
|
-
* Tab management
|
|
1966
|
-
*
|
|
1967
|
-
* @param {*} params { command: `new_tab [url]` | 'tab_all' | 'current_tab' | 'go_back' | 'close_tab' | 'switch_tab [tabId]' }
|
|
1968
|
-
* @returns > { result, success: true }
|
|
1969
|
-
*/
|
|
1970
1973
|
async execute(context, params) {
|
|
1971
1974
|
if (params === null || !params.command) {
|
|
1972
1975
|
throw new Error('Invalid parameters. Expected an object with a "command" property.');
|
|
1973
1976
|
}
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
if (command.startsWith('`')) {
|
|
1977
|
-
command = command.substring(1);
|
|
1978
|
-
}
|
|
1979
|
-
if (command.endsWith('`')) {
|
|
1980
|
-
command = command.substring(0, command.length - 1);
|
|
1981
|
-
}
|
|
1982
|
-
let result;
|
|
1983
|
-
if (command == 'tab_all') {
|
|
1984
|
-
result = [];
|
|
1985
|
-
let tabs = await context.ekoConfig.chromeProxy.tabs.query({ windowId: windowId });
|
|
1986
|
-
for (let i = 0; i < tabs.length; i++) {
|
|
1987
|
-
let tab = tabs[i];
|
|
1988
|
-
let tabInfo = {
|
|
1989
|
-
tabId: tab.id,
|
|
1990
|
-
windowId: tab.windowId,
|
|
1991
|
-
title: tab.title,
|
|
1992
|
-
url: tab.url,
|
|
1993
|
-
};
|
|
1994
|
-
if (tab.active) {
|
|
1995
|
-
tabInfo.active = true;
|
|
1996
|
-
}
|
|
1997
|
-
result.push(tabInfo);
|
|
1998
|
-
}
|
|
1999
|
-
}
|
|
2000
|
-
else if (command == 'current_tab') {
|
|
2001
|
-
let tabId = await getTabId(context);
|
|
2002
|
-
let tab = await context.ekoConfig.chromeProxy.tabs.get(tabId);
|
|
2003
|
-
let tabInfo = { tabId, windowId: tab.windowId, title: tab.title, url: tab.url };
|
|
2004
|
-
result = tabInfo;
|
|
2005
|
-
}
|
|
2006
|
-
else if (command == 'go_back') {
|
|
1977
|
+
if (params.command == 'tab_all') ;
|
|
1978
|
+
else if (params.command == 'go_back') {
|
|
2007
1979
|
let tabId = await getTabId(context);
|
|
2008
1980
|
await context.ekoConfig.chromeProxy.tabs.goBack(tabId);
|
|
2009
|
-
let tab = await context.ekoConfig.chromeProxy.tabs.get(tabId);
|
|
2010
|
-
let tabInfo = { tabId, windowId: tab.windowId, title: tab.title, url: tab.url };
|
|
2011
|
-
result = tabInfo;
|
|
2012
1981
|
}
|
|
2013
|
-
else if (command ==
|
|
1982
|
+
else if (params.command == "switch_tab") {
|
|
1983
|
+
await context.ekoConfig.chromeProxy.tabs.select(params.tabId);
|
|
1984
|
+
}
|
|
1985
|
+
else if (params.command == 'close_tab') {
|
|
2014
1986
|
let closedTabId = await getTabId(context);
|
|
2015
1987
|
await context.ekoConfig.chromeProxy.tabs.remove(closedTabId);
|
|
2016
1988
|
await sleep(100);
|
|
@@ -2022,16 +1994,28 @@ class TabManagement {
|
|
|
2022
1994
|
if (!tab.active) {
|
|
2023
1995
|
await context.ekoConfig.chromeProxy.tabs.update(tab.id, { active: true });
|
|
2024
1996
|
}
|
|
2025
|
-
let newTabId = tab.id;
|
|
2026
1997
|
context.variables.set('tabId', tab.id);
|
|
2027
1998
|
context.variables.set('windowId', tab.windowId);
|
|
2028
|
-
let closeTabInfo = { closedTabId, newTabId, newTabTitle: tab.title };
|
|
2029
|
-
result = closeTabInfo;
|
|
2030
1999
|
}
|
|
2031
2000
|
else {
|
|
2032
|
-
throw Error('Unknown command: ' + command);
|
|
2001
|
+
throw Error('Unknown command: ' + params.command);
|
|
2002
|
+
}
|
|
2003
|
+
// build return value
|
|
2004
|
+
let tabs = await context.ekoConfig.chromeProxy.tabs.query({});
|
|
2005
|
+
tabs = tabs.filter((tab) => tab.title && tab.url);
|
|
2006
|
+
if (tabs.length > 0) {
|
|
2007
|
+
let result = "After operation, the existing tabs are as follows:\n";
|
|
2008
|
+
for (const tab of tabs) {
|
|
2009
|
+
result += `<tab><id>${tab.id}</id><title>${tab.title}</title><url>${tab.url}</url></tab>\n`;
|
|
2010
|
+
}
|
|
2011
|
+
let currentTabId = await getTabId(context);
|
|
2012
|
+
let currentTab = await context.ekoConfig.chromeProxy.tabs.get(currentTabId);
|
|
2013
|
+
result += `The current active tab: <tab><id>${currentTab.id}</id><title>${currentTab.title}</title><url>${currentTab.url}</url></tab>`;
|
|
2014
|
+
return result;
|
|
2015
|
+
}
|
|
2016
|
+
else {
|
|
2017
|
+
return "No existing tab. Use 'open_url' to open a new tab";
|
|
2033
2018
|
}
|
|
2034
|
-
return result;
|
|
2035
2019
|
}
|
|
2036
2020
|
destroy(context) {
|
|
2037
2021
|
let windowIds = context.variables.get('windowIds');
|
|
@@ -2090,7 +2074,7 @@ class WebSearch {
|
|
|
2090
2074
|
let searchs = [{ url: url, keyword: query }];
|
|
2091
2075
|
let searchInfo = await deepSearch(context, taskId, searchs, maxResults || 5, context.ekoConfig.workingWindowId);
|
|
2092
2076
|
let links = ((_b = searchInfo.result[0]) === null || _b === void 0 ? void 0 : _b.links) || [];
|
|
2093
|
-
return links.filter((s) => s.content);
|
|
2077
|
+
return links.filter((s) => s.content.slice(0, 8000));
|
|
2094
2078
|
}
|
|
2095
2079
|
}
|
|
2096
2080
|
const deepSearchInjects = {
|
|
@@ -598,9 +598,31 @@ class Logger extends BaseLogger {
|
|
|
598
598
|
}
|
|
599
599
|
|
|
600
600
|
function transportFormatted(logMetaMarkup, logArgs, logErrors, settings) {
|
|
601
|
-
const logErrorsStr = (logErrors.length > 0 && logArgs.length > 0 ? "\n" : "") + logErrors.join("\n");
|
|
602
601
|
settings.prettyInspectOptions.colors = settings.stylePrettyLogs;
|
|
603
|
-
|
|
602
|
+
const logLevel = logMetaMarkup.trim().split(" ")[2];
|
|
603
|
+
let logFunc;
|
|
604
|
+
switch (logLevel) {
|
|
605
|
+
case "WARN":
|
|
606
|
+
logFunc = console.warn;
|
|
607
|
+
break;
|
|
608
|
+
case "ERROR":
|
|
609
|
+
case "FATAL":
|
|
610
|
+
logFunc = console.error;
|
|
611
|
+
break;
|
|
612
|
+
case "INFO":
|
|
613
|
+
logFunc = console.info;
|
|
614
|
+
break;
|
|
615
|
+
case "DEBUG":
|
|
616
|
+
case "TRACE":
|
|
617
|
+
case "SILLY":
|
|
618
|
+
default:
|
|
619
|
+
logFunc = console.debug;
|
|
620
|
+
break;
|
|
621
|
+
}
|
|
622
|
+
logFunc(logMetaMarkup, ...logArgs);
|
|
623
|
+
logErrors.forEach(err => {
|
|
624
|
+
console.error(logMetaMarkup + err);
|
|
625
|
+
});
|
|
604
626
|
}
|
|
605
627
|
function formatMeta(logObjMeta) {
|
|
606
628
|
if (!logObjMeta) {
|