From 29df483a2703edb3cb1009dc613ec12f97fb6290 Mon Sep 17 00:00:00 2001 From: Timothy Carambat Date: Tue, 27 Aug 2024 14:58:47 -0700 Subject: [PATCH] AnythingLLM Chrome Extension (#2066) * initial commit for chrome extension * wip browser extension backend * wip frontend browser extension settings * fix typo for browserExtension route * implement verification codes + frontend panel for browser extension keys * reorganize + state management for all connection states * implement embed to workspace * add send page to anythingllm extension option + refactor * refactor connection string auth + update context menus + organize background.js into models * popup extension from main app and save if successful * fix hebrew translation misspelling * fetch custom logo inside chrome extension * delete api keys on disconnect of extension * use correct apiUrl constant in frontend + remove unneeded comments * remove upload-link endpoint and send inner text html to raw text collector endpoint * update readme * fix readme link * fix readme typo * update readme * handle deletion of browser keys with key id and DELETE endpoint * move event string to constant * remove tablename and writable fields from BrowserExtensionApiKey backend model * add border-none to all buttons and inputs for desktop compatibility * patch prisma injections * update delete endpoints to delete keys by id * remove unused prop * add button to attempt browser extension connection + remove max active keys * wip multi user mode support * multi user mode support * clean up backend + show created by in frotend browser extension page * show multi user warning message on key creation + hide context menus when no workspaces * show browser extension options to managers * small backend changes and refactors * extension cleanup * rename submodule * extension updates & docs * dev docker build --------- Co-authored-by: shatfield4 --- .github/workflows/dev-build.yaml | 2 +- .gitmodules | 3 + README.md | 3 +- browser-extension | 1 + embed | 1 - frontend/src/App.jsx | 7 + .../src/components/SettingsSidebar/index.jsx | 6 + frontend/src/locales/de/common.js | 1 + frontend/src/locales/en/common.js | 1 + frontend/src/locales/es/common.js | 1 + frontend/src/locales/fr/common.js | 1 + frontend/src/locales/he/common.js | 1 + frontend/src/locales/it/common.js | 1 + frontend/src/locales/ko/common.js | 1 + frontend/src/locales/pt_BR/common.js | 1 + frontend/src/locales/ru/common.js | 1 + frontend/src/locales/zh/common.js | 1 + frontend/src/models/browserExtensionApiKey.js | 42 ++++ .../BrowserExtensionApiKeyRow/index.jsx | 120 ++++++++++ .../NewBrowserExtensionApiKeyModal/index.jsx | 127 ++++++++++ .../BrowserExtensionApiKey/index.jsx | 133 +++++++++++ frontend/src/utils/constants.js | 2 + frontend/src/utils/paths.js | 3 + server/endpoints/browserExtension.js | 224 ++++++++++++++++++ server/endpoints/system.js | 2 + server/index.js | 4 + server/models/browserExtensionApiKey.js | 168 +++++++++++++ .../20240824005054_init/migration.sql | 15 ++ server/prisma/schema.prisma | 12 + .../middleware/validBrowserExtensionApiKey.js | 36 +++ 30 files changed, 918 insertions(+), 3 deletions(-) create mode 160000 browser-extension delete mode 160000 embed create mode 100644 frontend/src/models/browserExtensionApiKey.js create mode 100644 frontend/src/pages/GeneralSettings/BrowserExtensionApiKey/BrowserExtensionApiKeyRow/index.jsx create mode 100644 frontend/src/pages/GeneralSettings/BrowserExtensionApiKey/NewBrowserExtensionApiKeyModal/index.jsx create mode 100644 frontend/src/pages/GeneralSettings/BrowserExtensionApiKey/index.jsx create mode 100644 server/endpoints/browserExtension.js create mode 100644 server/models/browserExtensionApiKey.js create mode 100644 server/prisma/migrations/20240824005054_init/migration.sql create mode 100644 server/utils/middleware/validBrowserExtensionApiKey.js diff --git a/.github/workflows/dev-build.yaml b/.github/workflows/dev-build.yaml index aef9a6c35c..6d938af8ee 100644 --- a/.github/workflows/dev-build.yaml +++ b/.github/workflows/dev-build.yaml @@ -6,7 +6,7 @@ concurrency: on: push: - branches: ['encrypt-jwt-value'] # put your current branch to create a build. Core team only. + branches: ['chrome-extension'] # put your current branch to create a build. Core team only. paths-ignore: - '**.md' - 'cloud-deployments/*' diff --git a/.gitmodules b/.gitmodules index dfb4bfcaa7..a27e72e970 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,6 @@ branch = main path = embed url = git@github.com:Mintplex-Labs/anythingllm-embed.git +[submodule "browser-extension"] + path = browser-extension + url = git@github.com:Mintplex-Labs/anythingllm-extension.git diff --git a/README.md b/README.md index 299ab9ea68..5c4e9cccb5 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,8 @@ This monorepo consists of three main sections: - `server`: A NodeJS express server to handle all the interactions and do all the vectorDB management and LLM interactions. - `collector`: NodeJS express server that process and parses documents from the UI. - `docker`: Docker instructions and build process + information for building from source. -- `embed`: Submodule specifically for generation & creation of the [web embed widget](https://github.com/Mintplex-Labs/anythingllm-embed). +- `embed`: Submodule for generation & creation of the [web embed widget](https://github.com/Mintplex-Labs/anythingllm-embed). +- `browser-extension`: Submodule for the [chrome browser extension](https://github.com/Mintplex-Labs/anythingllm-extension). ## 🛳 Self Hosting diff --git a/browser-extension b/browser-extension new file mode 160000 index 0000000000..d9b28cc1e2 --- /dev/null +++ b/browser-extension @@ -0,0 +1 @@ +Subproject commit d9b28cc1e23b64fdb4e666d5b5b49cc8e583aabd diff --git a/embed b/embed deleted file mode 160000 index 22a0848d58..0000000000 --- a/embed +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 22a0848d58e3a758d85d93d9204a72a65854ea94 diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 3737541f24..c6cac66db7 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -49,6 +49,9 @@ const GeneralVectorDatabase = lazy( () => import("@/pages/GeneralSettings/VectorDatabase") ); const GeneralSecurity = lazy(() => import("@/pages/GeneralSettings/Security")); +const GeneralBrowserExtension = lazy( + () => import("@/pages/GeneralSettings/BrowserExtensionApiKey") +); const WorkspaceSettings = lazy(() => import("@/pages/WorkspaceSettings")); const EmbedConfigSetup = lazy( () => import("@/pages/GeneralSettings/EmbedConfigs") @@ -157,6 +160,10 @@ export default function App() { path="/settings/api-keys" element={} /> + } + /> } diff --git a/frontend/src/components/SettingsSidebar/index.jsx b/frontend/src/components/SettingsSidebar/index.jsx index 9fa6fd6112..54cf9b4a13 100644 --- a/frontend/src/components/SettingsSidebar/index.jsx +++ b/frontend/src/components/SettingsSidebar/index.jsx @@ -332,6 +332,12 @@ const SidebarOptions = ({ user = null, t }) => ( flex: true, roles: ["admin"], }, + { + btnText: t("settings.browser-extension"), + href: paths.settings.browserExtension(), + flex: true, + roles: ["admin", "manager"], + }, ]} />