From 2187f0e7100c2faa1ea5e3556b75fff709e86238 Mon Sep 17 00:00:00 2001 From: veasion Date: Fri, 20 Dec 2024 18:05:57 +0800 Subject: [PATCH] feat: modify ekoai --- public/manifest.json | 7 ++-- src/background/index.ts | 70 +++++++++++++++++++++++++++++++++++++-- src/options/index.tsx | 6 ++-- webpack/webpack.common.js | 4 +-- 4 files changed, 77 insertions(+), 10 deletions(-) diff --git a/public/manifest.json b/public/manifest.json index ca66922..71a6cb9 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -21,17 +21,18 @@ "content_scripts": [ { "matches": [""], - "js": ["eko/extension.js", "js/content_script.js"], + "js": ["eko/extension_content_script.js", "js/content_script.js"], "run_at": "document_idle" } ], "permissions": [ "alarms", + "tabs", + "windows", "storage", "scripting", "activeTab", - "notifications", - "webRequest" + "notifications" ], "host_permissions": [ "" diff --git a/src/background/index.ts b/src/background/index.ts index 3938a33..60ec067 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -1,8 +1,68 @@ import { Eko } from "ekoai"; +import { ExecutionContext } from "ekoai/types"; +import { tools, utils } from "ekoai/extension"; + +let eko = new Eko("claude-3-5-sonnet-20241022"); +let context = { + variables: new Map(), + tools: [], +} as any as ExecutionContext; async function testWebSearch() { - let eko = new Eko("claude-3-sonnet"); - let result = await eko.testWebSearch("谢扬"); + let webSearch = new tools.WebSearch(); + let result = await webSearch.execute(context, { query: "谢扬" }); + console.log("result: ", result); + return result; +} + +async function testTabManagement(action: string) { + let tabManagement = new tools.TabManagement(); + let result = await tabManagement.execute(context, { action }); + console.log("result: ", action, result); + return result; +} + +async function exportFile() { + let exportFile = new tools.ExportFile(); + let result = await exportFile.execute(context, { + fileType: "csv", + content: "Name, Price\niPhone, $1000\nnotebook, $1.02", + }); + console.log("result: ", result); + return result; +} + +async function extractContent() { + let extract = new tools.ExtractContent(); + let result = await extract.execute(context, {}); + console.log("result: ", result); + return result; +} + +async function openUrl(url: string, newWindow: boolean) { + let openUrl = new tools.OpenUrl(); + let result = await openUrl.execute(context, { url, newWindow }); + console.log("result: ", result); + return result; +} + +async function screenshot() { + let screenshot = new tools.Screenshot(); + let result = await screenshot.execute(context, {}); + console.log("result: ", result); + return result; +} + +async function computerWeb( + action: string, + coordinate?: [number, number], + text?: string +) { + let tabId = await utils.getCurrentTabId(); + context.variables.set("tabId", tabId); + let pageSize = await utils.getPageSize(tabId); + let computer = new tools.ComputerWeb(pageSize); + let result = await computer.execute(context, { action, coordinate, text }); console.log("result: ", result); return result; } @@ -14,5 +74,11 @@ chrome.runtime.onMessage.addListener(async function ( ) { if (request.type == "run") { await testWebSearch(); + // await testTabManagement("current_tab"); + // await testTabManagement("tab_all"); + // await exportFile(); + // await extractContent(); + // await openUrl('https://www.google.com', true); + // await screenshot(); } }); diff --git a/src/options/index.tsx b/src/options/index.tsx index 405aed8..193a5a8 100644 --- a/src/options/index.tsx +++ b/src/options/index.tsx @@ -42,9 +42,9 @@ const OptionsPage = () => { }; const modelOptions = [ - { value: "claude-3-haiku", label: "Claude 3 Haiku" }, - { value: "claude-3-sonnet", label: "Claude 3 Sonnet (default)" }, - { value: "claude-3-opus", label: "Claude 3 Opus" }, + { value: "claude-3-5-haiku-20241022", label: "Claude 3.5 Haiku" }, + { value: "claude-3-5-sonnet-20241022", label: "Claude 3.5 Sonnet (default)" }, + { value: "claude-3-opus-20240229", label: "Claude 3 Opus" }, ]; return ( diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index 68ed4b6..7d66ac6 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -39,8 +39,8 @@ module.exports = { patterns: [ { from: "public", to: "../" }, { - from: 'node_modules/ekoai/dist/extension.js', - to: "../eko/extension.js" + from: 'node_modules/ekoai/dist/extension_content_script.js', + to: "../eko/extension_content_script.js" }, { from: 'node_modules/ekoai/dist/extension/script',