@eko-ai/eko 1.2.3 → 1.2.5

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.
@@ -7,5 +7,6 @@ import { Screenshot } from './screenshot';
7
7
  import { TabManagement } from './tab_management';
8
8
  import { WebSearch } from './web_search';
9
9
  import { RequestLogin } from './request_login';
10
+ import { SwitchTab } from './switch_tab';
10
11
  export * from '../../common/tools';
11
- export { BrowserUse, ExportFile, ExtractContent, OpenUrl, GetAllTabs, Screenshot, TabManagement, WebSearch, RequestLogin, };
12
+ export { BrowserUse, ExportFile, ExtractContent, OpenUrl, GetAllTabs, Screenshot, TabManagement, WebSearch, RequestLogin, SwitchTab, };
@@ -0,0 +1,8 @@
1
+ import { ExecutionContext, InputSchema, SwitchTabParam, TabManagementResult, Tool } from '@/types';
2
+ export declare class SwitchTab implements Tool<SwitchTabParam, TabManagementResult> {
3
+ description: string;
4
+ input_schema: InputSchema;
5
+ name: string;
6
+ constructor();
7
+ execute(context: ExecutionContext, params: SwitchTabParam): Promise<TabManagementResult>;
8
+ }
@@ -695,7 +695,13 @@ async function getTabId(context) {
695
695
  logger.debug("getCurrentTabId(context.ekoConfig.chromeProxy) #2 returns " + tabId);
696
696
  }
697
697
  if (!tabId) {
698
- throw new Error('Could not find a valid tab');
698
+ const fellouTabId = window.__FELLOU_TAB_ID__;
699
+ if (tabId) {
700
+ tabId = fellouTabId;
701
+ }
702
+ else {
703
+ throw new Error('Could not find a valid tab');
704
+ }
699
705
  }
700
706
  context.variables.set('tabId', tabId);
701
707
  }
@@ -1221,6 +1227,9 @@ async function screenshot(chromeProxy, windowId, compress) {
1221
1227
  },
1222
1228
  };
1223
1229
  logger.debug('screenshot Got screenshot result:', result);
1230
+ if (!data || data.length < 30) {
1231
+ throw new Error('image error');
1232
+ }
1224
1233
  return result;
1225
1234
  }
1226
1235
  catch (e) {
@@ -1266,6 +1275,9 @@ async function compress_image(dataUrl, scale = 0.8, quality = 0.8) {
1266
1275
  logger.debug('Got compressed image result (sliced):', result.slice(0, 200));
1267
1276
  resolve(result);
1268
1277
  };
1278
+ reader.onerror = () => {
1279
+ resolve(dataUrl);
1280
+ };
1269
1281
  reader.readAsDataURL(blob);
1270
1282
  });
1271
1283
  }
@@ -1392,6 +1404,7 @@ class ToolReturnsScreenshot {
1392
1404
  const realResult = await this.realExecute(context, params);
1393
1405
  logger.debug("debug realResult...");
1394
1406
  logger.debug(realResult);
1407
+ await sleep(3000); // wait for page loding
1395
1408
  let instance = new BrowserUse();
1396
1409
  const image = await instance.realExecute(context, { action: "screenshot_extract_element" });
1397
1410
  return image;
@@ -1582,6 +1595,7 @@ class BrowserUse extends ToolReturnsScreenshot {
1582
1595
  result = { image: screenshot$1.image, text: element_result.element_str };
1583
1596
  }
1584
1597
  finally {
1598
+ await sleep(500);
1585
1599
  logger.debug("executeScript #2...");
1586
1600
  await executeScript(context.ekoConfig.chromeProxy, tabId, () => {
1587
1601
  return window.remove_highlight();
@@ -1930,7 +1944,9 @@ class Screenshot {
1930
1944
  class TabManagement {
1931
1945
  constructor() {
1932
1946
  this.name = 'tab_management';
1933
- this.description = 'Browser tab management, view and operate tabs';
1947
+ this.description = 'Browser tab management, view and operate tabs.You can use this tool to' +
1948
+ 'View all tabs with the tabId and title.Get current tab information (tabId, url, title).' +
1949
+ 'Go back to the previous page in the current tab. And Close the current tab.';
1934
1950
  this.input_schema = {
1935
1951
  type: 'object',
1936
1952
  properties: {
@@ -1940,9 +1956,8 @@ class TabManagement {
1940
1956
  * \`tab_all\`: View all tabs and return the tabId and title.
1941
1957
  * \`current_tab\`: Get current tab information (tabId, url, title).
1942
1958
  * \`go_back\`: Go back to the previous page in the current tab.
1943
- * \`close_tab\`: Close the current tab.
1944
- * \`switch_tab [tabId]\`: Switch to the specified tab using tabId, eg: \`switch_tab 1000\`.
1945
- * \`new_tab [url]\`: Open a new tab window and open the URL, eg: \`new_tab https://www.google.com\``,
1959
+ * \`close_tab\`: Close the current tab.`,
1960
+ enum: ['tab_all', 'current_tab', 'go_back', 'close_tab'],
1946
1961
  },
1947
1962
  },
1948
1963
  required: ['command'],
@@ -1955,7 +1970,6 @@ class TabManagement {
1955
1970
  * @returns > { result, success: true }
1956
1971
  */
1957
1972
  async execute(context, params) {
1958
- var _a, _b, _c;
1959
1973
  if (params === null || !params.command) {
1960
1974
  throw new Error('Invalid parameters. Expected an object with a "command" property.');
1961
1975
  }
@@ -2016,30 +2030,6 @@ class TabManagement {
2016
2030
  let closeTabInfo = { closedTabId, newTabId, newTabTitle: tab.title };
2017
2031
  result = closeTabInfo;
2018
2032
  }
2019
- else if (command.startsWith('switch_tab')) {
2020
- let tabId = parseInt(command.replace('switch_tab', '').replace('[', '').replace(']', ''));
2021
- let tab = await context.ekoConfig.chromeProxy.tabs.update(tabId, { active: true });
2022
- context.variables.set('tabId', tab.id);
2023
- context.variables.set('windowId', tab.windowId);
2024
- let tabInfo = { tabId, windowId: tab.windowId, title: tab.title, url: tab.url };
2025
- result = tabInfo;
2026
- }
2027
- else if (command.startsWith('new_tab')) {
2028
- let url = command.replace('new_tab', '').replace('[', '').replace(']', '').replace(/"/g, '').trim();
2029
- let windowId = await getWindowId(context);
2030
- let tab = await open_new_tab(context.ekoConfig.chromeProxy, url, windowId);
2031
- (_c = (_b = (_a = context.callback) === null || _a === void 0 ? void 0 : _a.hooks) === null || _b === void 0 ? void 0 : _b.onTabCreated) === null || _c === void 0 ? void 0 : _c.call(_b, tab.id);
2032
- let tabId = tab.id;
2033
- context.variables.set('windowId', windowId);
2034
- context.variables.set('tabId', tabId);
2035
- let tabInfo = {
2036
- tabId: tab.id,
2037
- windowId: tab.windowId,
2038
- title: tab.title,
2039
- url: tab.url,
2040
- };
2041
- result = tabInfo;
2042
- }
2043
2033
  else {
2044
2034
  throw Error('Unknown command: ' + command);
2045
2035
  }
@@ -2449,6 +2439,36 @@ class RequestLogin {
2449
2439
  }
2450
2440
  }
2451
2441
 
2442
+ class SwitchTab {
2443
+ constructor() {
2444
+ this.name = 'switch_tab';
2445
+ this.description = 'Switch to the specified tab using tabId';
2446
+ this.input_schema = {
2447
+ type: 'object',
2448
+ properties: {
2449
+ tabId: {
2450
+ type: 'integer',
2451
+ description: 'The tabId to switch to',
2452
+ },
2453
+ },
2454
+ required: ['tabId'],
2455
+ };
2456
+ }
2457
+ async execute(context, params) {
2458
+ if (params === null || !params.tabId) {
2459
+ throw new Error('Invalid parameters. Expected an object with a "tabId" property.');
2460
+ }
2461
+ let result;
2462
+ let tabId = parseInt(String(params.tabId));
2463
+ let tab = await context.ekoConfig.chromeProxy.tabs.update(tabId, { active: true });
2464
+ context.variables.set('tabId', tab.id);
2465
+ context.variables.set('windowId', tab.windowId);
2466
+ let tabInfo = { tabId, windowId: tab.windowId, title: tab.title, url: tab.url };
2467
+ result = tabInfo;
2468
+ return result;
2469
+ }
2470
+ }
2471
+
2452
2472
  class CancelWorkflow {
2453
2473
  constructor() {
2454
2474
  this.name = 'cancel_workflow';
@@ -2748,6 +2768,7 @@ var tools = /*#__PURE__*/Object.freeze({
2748
2768
  OpenUrl: OpenUrl,
2749
2769
  RequestLogin: RequestLogin,
2750
2770
  Screenshot: Screenshot,
2771
+ SwitchTab: SwitchTab,
2751
2772
  TabManagement: TabManagement,
2752
2773
  WebSearch: WebSearch
2753
2774
  });
@@ -693,7 +693,13 @@ async function getTabId(context) {
693
693
  logger.debug("getCurrentTabId(context.ekoConfig.chromeProxy) #2 returns " + tabId);
694
694
  }
695
695
  if (!tabId) {
696
- throw new Error('Could not find a valid tab');
696
+ const fellouTabId = window.__FELLOU_TAB_ID__;
697
+ if (tabId) {
698
+ tabId = fellouTabId;
699
+ }
700
+ else {
701
+ throw new Error('Could not find a valid tab');
702
+ }
697
703
  }
698
704
  context.variables.set('tabId', tabId);
699
705
  }
@@ -1219,6 +1225,9 @@ async function screenshot(chromeProxy, windowId, compress) {
1219
1225
  },
1220
1226
  };
1221
1227
  logger.debug('screenshot Got screenshot result:', result);
1228
+ if (!data || data.length < 30) {
1229
+ throw new Error('image error');
1230
+ }
1222
1231
  return result;
1223
1232
  }
1224
1233
  catch (e) {
@@ -1264,6 +1273,9 @@ async function compress_image(dataUrl, scale = 0.8, quality = 0.8) {
1264
1273
  logger.debug('Got compressed image result (sliced):', result.slice(0, 200));
1265
1274
  resolve(result);
1266
1275
  };
1276
+ reader.onerror = () => {
1277
+ resolve(dataUrl);
1278
+ };
1267
1279
  reader.readAsDataURL(blob);
1268
1280
  });
1269
1281
  }
@@ -1390,6 +1402,7 @@ class ToolReturnsScreenshot {
1390
1402
  const realResult = await this.realExecute(context, params);
1391
1403
  logger.debug("debug realResult...");
1392
1404
  logger.debug(realResult);
1405
+ await sleep(3000); // wait for page loding
1393
1406
  let instance = new BrowserUse();
1394
1407
  const image = await instance.realExecute(context, { action: "screenshot_extract_element" });
1395
1408
  return image;
@@ -1580,6 +1593,7 @@ class BrowserUse extends ToolReturnsScreenshot {
1580
1593
  result = { image: screenshot$1.image, text: element_result.element_str };
1581
1594
  }
1582
1595
  finally {
1596
+ await sleep(500);
1583
1597
  logger.debug("executeScript #2...");
1584
1598
  await executeScript(context.ekoConfig.chromeProxy, tabId, () => {
1585
1599
  return window.remove_highlight();
@@ -1928,7 +1942,9 @@ class Screenshot {
1928
1942
  class TabManagement {
1929
1943
  constructor() {
1930
1944
  this.name = 'tab_management';
1931
- this.description = 'Browser tab management, view and operate tabs';
1945
+ this.description = 'Browser tab management, view and operate tabs.You can use this tool to' +
1946
+ 'View all tabs with the tabId and title.Get current tab information (tabId, url, title).' +
1947
+ 'Go back to the previous page in the current tab. And Close the current tab.';
1932
1948
  this.input_schema = {
1933
1949
  type: 'object',
1934
1950
  properties: {
@@ -1938,9 +1954,8 @@ class TabManagement {
1938
1954
  * \`tab_all\`: View all tabs and return the tabId and title.
1939
1955
  * \`current_tab\`: Get current tab information (tabId, url, title).
1940
1956
  * \`go_back\`: Go back to the previous page in the current tab.
1941
- * \`close_tab\`: Close the current tab.
1942
- * \`switch_tab [tabId]\`: Switch to the specified tab using tabId, eg: \`switch_tab 1000\`.
1943
- * \`new_tab [url]\`: Open a new tab window and open the URL, eg: \`new_tab https://www.google.com\``,
1957
+ * \`close_tab\`: Close the current tab.`,
1958
+ enum: ['tab_all', 'current_tab', 'go_back', 'close_tab'],
1944
1959
  },
1945
1960
  },
1946
1961
  required: ['command'],
@@ -1953,7 +1968,6 @@ class TabManagement {
1953
1968
  * @returns > { result, success: true }
1954
1969
  */
1955
1970
  async execute(context, params) {
1956
- var _a, _b, _c;
1957
1971
  if (params === null || !params.command) {
1958
1972
  throw new Error('Invalid parameters. Expected an object with a "command" property.');
1959
1973
  }
@@ -2014,30 +2028,6 @@ class TabManagement {
2014
2028
  let closeTabInfo = { closedTabId, newTabId, newTabTitle: tab.title };
2015
2029
  result = closeTabInfo;
2016
2030
  }
2017
- else if (command.startsWith('switch_tab')) {
2018
- let tabId = parseInt(command.replace('switch_tab', '').replace('[', '').replace(']', ''));
2019
- let tab = await context.ekoConfig.chromeProxy.tabs.update(tabId, { active: true });
2020
- context.variables.set('tabId', tab.id);
2021
- context.variables.set('windowId', tab.windowId);
2022
- let tabInfo = { tabId, windowId: tab.windowId, title: tab.title, url: tab.url };
2023
- result = tabInfo;
2024
- }
2025
- else if (command.startsWith('new_tab')) {
2026
- let url = command.replace('new_tab', '').replace('[', '').replace(']', '').replace(/"/g, '').trim();
2027
- let windowId = await getWindowId(context);
2028
- let tab = await open_new_tab(context.ekoConfig.chromeProxy, url, windowId);
2029
- (_c = (_b = (_a = context.callback) === null || _a === void 0 ? void 0 : _a.hooks) === null || _b === void 0 ? void 0 : _b.onTabCreated) === null || _c === void 0 ? void 0 : _c.call(_b, tab.id);
2030
- let tabId = tab.id;
2031
- context.variables.set('windowId', windowId);
2032
- context.variables.set('tabId', tabId);
2033
- let tabInfo = {
2034
- tabId: tab.id,
2035
- windowId: tab.windowId,
2036
- title: tab.title,
2037
- url: tab.url,
2038
- };
2039
- result = tabInfo;
2040
- }
2041
2031
  else {
2042
2032
  throw Error('Unknown command: ' + command);
2043
2033
  }
@@ -2447,6 +2437,36 @@ class RequestLogin {
2447
2437
  }
2448
2438
  }
2449
2439
 
2440
+ class SwitchTab {
2441
+ constructor() {
2442
+ this.name = 'switch_tab';
2443
+ this.description = 'Switch to the specified tab using tabId';
2444
+ this.input_schema = {
2445
+ type: 'object',
2446
+ properties: {
2447
+ tabId: {
2448
+ type: 'integer',
2449
+ description: 'The tabId to switch to',
2450
+ },
2451
+ },
2452
+ required: ['tabId'],
2453
+ };
2454
+ }
2455
+ async execute(context, params) {
2456
+ if (params === null || !params.tabId) {
2457
+ throw new Error('Invalid parameters. Expected an object with a "tabId" property.');
2458
+ }
2459
+ let result;
2460
+ let tabId = parseInt(String(params.tabId));
2461
+ let tab = await context.ekoConfig.chromeProxy.tabs.update(tabId, { active: true });
2462
+ context.variables.set('tabId', tab.id);
2463
+ context.variables.set('windowId', tab.windowId);
2464
+ let tabInfo = { tabId, windowId: tab.windowId, title: tab.title, url: tab.url };
2465
+ result = tabInfo;
2466
+ return result;
2467
+ }
2468
+ }
2469
+
2450
2470
  class CancelWorkflow {
2451
2471
  constructor() {
2452
2472
  this.name = 'cancel_workflow';
@@ -2746,6 +2766,7 @@ var tools = /*#__PURE__*/Object.freeze({
2746
2766
  OpenUrl: OpenUrl,
2747
2767
  RequestLogin: RequestLogin,
2748
2768
  Screenshot: Screenshot,
2769
+ SwitchTab: SwitchTab,
2749
2770
  TabManagement: TabManagement,
2750
2771
  WebSearch: WebSearch
2751
2772
  });