Skip to content

Commit 4ac0c04

Browse files
feat: add plugin search functionality (danny-avila#1007)
* feat: add plugin search functionality * Delete env/conda-meta/history File deleted * UI fix and 3 new translations * fix(PluginStoreDialog) can't select pages * fix(PluginStoreDialog) select pages fixed. Layout fixed * update test * fix(PluginStoreDialog) Fixed count pages --------- Co-authored-by: Marco Beretta <[email protected]>
1 parent bc7a079 commit 4ac0c04

File tree

14 files changed

+122
-26
lines changed

14 files changed

+122
-26
lines changed

client/src/components/Plugins/Store/PluginStoreDialog.tsx

+55-23
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState, useEffect, useCallback } from 'react';
22
import { Dialog } from '@headlessui/react';
33
import { useRecoilState } from 'recoil';
4-
import { X } from 'lucide-react';
4+
import { Search, X } from 'lucide-react';
55
import store from '~/store';
66
import PluginStoreItem from './PluginStoreItem';
77
import PluginPagination from './PluginPagination';
@@ -15,13 +15,15 @@ import {
1515
TError,
1616
} from 'librechat-data-provider';
1717
import { useAuthContext } from '~/hooks/AuthContext';
18+
import { useLocalize } from '~/hooks';
1819

1920
type TPluginStoreDialogProps = {
2021
isOpen: boolean;
2122
setIsOpen: (open: boolean) => void;
2223
};
2324

2425
function PluginStoreDialog({ isOpen, setIsOpen }: TPluginStoreDialogProps) {
26+
const localize = useLocalize();
2527
const { data: availablePlugins } = useAvailablePluginsQuery();
2628
const { user } = useAuthContext();
2729
const updateUserPlugins = useUpdateUserPluginsMutation();
@@ -121,17 +123,20 @@ function PluginStoreDialog({ isOpen, setIsOpen }: TPluginStoreDialogProps) {
121123
},
122124
[itemsPerPage],
123125
);
124-
126+
const [searchValue, setSearchValue] = useState<string>('');
127+
const filteredPlugins = availablePlugins?.filter((plugin) =>
128+
plugin.name.toLowerCase().includes(searchValue.toLowerCase()),
129+
);
125130
useEffect(() => {
126-
if (user) {
127-
if (user.plugins) {
128-
setUserPlugins(user.plugins);
129-
}
131+
if (user && user.plugins) {
132+
setUserPlugins(user.plugins);
130133
}
131-
if (availablePlugins) {
132-
setMaxPage(Math.ceil(availablePlugins.length / itemsPerPage));
134+
135+
if (filteredPlugins) {
136+
setMaxPage(Math.ceil(filteredPlugins.length / itemsPerPage));
137+
setCurrentPage(1); // Reset the current page to 1 whenever the filtered list changes
133138
}
134-
}, [availablePlugins, itemsPerPage, user]);
139+
}, [availablePlugins, itemsPerPage, user, searchValue]); // Add searchValue to the dependency list
135140

136141
const handleChangePage = (page: number) => {
137142
setCurrentPage(page);
@@ -143,12 +148,15 @@ function PluginStoreDialog({ isOpen, setIsOpen }: TPluginStoreDialogProps) {
143148
<div className="fixed inset-0 bg-gray-500/90 transition-opacity dark:bg-gray-800/90" />
144149
{/* Full-screen container to center the panel */}
145150
<div className="fixed inset-0 flex items-center justify-center p-4">
146-
<Dialog.Panel className="relative w-full transform overflow-hidden overflow-y-auto rounded-lg bg-white text-left shadow-xl transition-all dark:bg-gray-900 max-sm:h-full sm:mx-7 sm:my-8 sm:max-w-2xl lg:max-w-5xl xl:max-w-7xl">
151+
<Dialog.Panel
152+
className="relative w-full transform overflow-hidden overflow-y-auto rounded-lg bg-white text-left shadow-xl transition-all dark:bg-gray-900 max-sm:h-full sm:mx-7 sm:my-8 sm:max-w-2xl lg:max-w-5xl xl:max-w-7xl"
153+
style={{ minHeight: '610px' }}
154+
>
147155
<div className="flex items-center justify-between border-b-[1px] border-black/10 px-4 pb-4 pt-5 dark:border-white/10 sm:p-6">
148156
<div className="flex items-center">
149157
<div className="text-center sm:text-left">
150158
<Dialog.Title className="text-lg font-medium leading-6 text-gray-900 dark:text-gray-200">
151-
Plugin store
159+
{localize('com_nav_plugin_store')}
152160
</Dialog.Title>
153161
</div>
154162
</div>
@@ -169,8 +177,7 @@ function PluginStoreDialog({ isOpen, setIsOpen }: TPluginStoreDialogProps) {
169177
className="relative m-4 rounded border border-red-400 bg-red-100 px-4 py-3 text-red-700"
170178
role="alert"
171179
>
172-
There was an error attempting to authenticate this plugin. Please try again.{' '}
173-
{errorMessage}
180+
{localize('com_nav_plugin_auth_error')} {errorMessage}
174181
</div>
175182
)}
176183
{showPluginAuthForm && (
@@ -183,12 +190,37 @@ function PluginStoreDialog({ isOpen, setIsOpen }: TPluginStoreDialogProps) {
183190
)}
184191
<div className="p-4 sm:p-6 sm:pt-4">
185192
<div className="mt-4 flex flex-col gap-4">
193+
<div style={{ position: 'relative', display: 'inline-block', width: '250px' }}>
194+
<input
195+
type="text"
196+
value={searchValue}
197+
onChange={(e) => setSearchValue(e.target.value)}
198+
placeholder={localize('com_nav_plugin_search')}
199+
style={{
200+
width: '100%',
201+
paddingLeft: '30px',
202+
border: '1px solid #ccc',
203+
borderRadius: '4px', // This rounds the corners
204+
}}
205+
/>
206+
<Search
207+
style={{
208+
position: 'absolute',
209+
left: '10px',
210+
top: '50%',
211+
transform: 'translateY(-50%)',
212+
width: '16px',
213+
height: '16px',
214+
}}
215+
/>
216+
</div>
186217
<div
187218
ref={gridRef}
188219
className="grid grid-cols-1 grid-rows-2 gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"
220+
style={{ minHeight: '410px' }}
189221
>
190-
{availablePlugins &&
191-
availablePlugins
222+
{filteredPlugins &&
223+
filteredPlugins
192224
.slice((currentPage - 1) * itemsPerPage, currentPage * itemsPerPage)
193225
.map((plugin, index) => (
194226
<PluginStoreItem
@@ -202,14 +234,14 @@ function PluginStoreDialog({ isOpen, setIsOpen }: TPluginStoreDialogProps) {
202234
</div>
203235
</div>
204236
<div className="mt-2 flex flex-col items-center gap-2 sm:flex-row sm:justify-between">
205-
{maxPage > 1 && (
206-
<div>
207-
<PluginPagination
208-
currentPage={currentPage}
209-
maxPage={maxPage}
210-
onChangePage={handleChangePage}
211-
/>
212-
</div>
237+
{maxPage > 0 ? (
238+
<PluginPagination
239+
currentPage={currentPage}
240+
maxPage={maxPage}
241+
onChangePage={handleChangePage}
242+
/>
243+
) : (
244+
<div style={{ height: '21px' }}></div>
213245
)}
214246
{/* API not yet implemented: */}
215247
{/* <div className="flex flex-col items-center gap-2 sm:flex-row">

client/src/components/Plugins/Store/__tests__/PluginStoreDialog.spec.tsx

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render } from 'test/layout-test-utils';
1+
import { render, screen, fireEvent } from 'test/layout-test-utils';
22
import PluginStoreDialog from '../PluginStoreDialog';
33
import userEvent from '@testing-library/user-event';
44
import * as mockDataProvider from 'librechat-data-provider';
@@ -202,3 +202,20 @@ test('allows the user to navigate between pages', async () => {
202202
expect(getByText('Wolfram')).toBeInTheDocument();
203203
expect(getByText('Plugin 1')).toBeInTheDocument();
204204
});
205+
206+
test('allows the user to search for plugins', async () => {
207+
setup();
208+
209+
const searchInput = screen.getByPlaceholderText('Search plugins');
210+
fireEvent.change(searchInput, { target: { value: 'Google' } });
211+
212+
expect(screen.getByText('Google')).toBeInTheDocument();
213+
expect(screen.queryByText('Wolfram')).not.toBeInTheDocument();
214+
expect(screen.queryByText('Plugin 1')).not.toBeInTheDocument();
215+
216+
fireEvent.change(searchInput, { target: { value: 'Plugin 1' } });
217+
218+
expect(screen.getByText('Plugin 1')).toBeInTheDocument();
219+
expect(screen.queryByText('Google')).not.toBeInTheDocument();
220+
expect(screen.queryByText('Wolfram')).not.toBeInTheDocument();
221+
});

client/src/localization/languages/Br.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ export default {
225225
com_endpoint_config_key_google_service_account: 'Criar uma Conta de Serviço',
226226
com_endpoint_config_key_google_vertex_api_role:
227227
'Certifique-se de clicar em \'Criar e Continuar\' para atribuir pelo menos a função de \'Usuário Vertex AI\'. Por fim, crie uma chave JSON para importar aqui.',
228+
com_nav_plugin_store: 'Loja de plugins',
229+
com_nav_plugin_search: 'Buscar plugins',
230+
com_nav_plugin_auth_error:
231+
'Ocorreu um erro ao tentar autenticar este plugin. Por favor, tente novamente.',
228232
com_nav_export_filename: 'Nome do Arquivo',
229233
com_nav_export_filename_placeholder: 'Defina o nome do arquivo',
230234
com_nav_export_type: 'Tipo',

client/src/localization/languages/De.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ export default {
168168
com_endpoint_func_hover: 'Aktiviere die Plugin Funktion für ChatGPT',
169169
com_endpoint_skip_hover:
170170
'Aktivieren Sie das Überspringen des Abschlussschritts, der die endgültige Antwort und die generierten Schritte überprüft.',
171+
com_nav_plugin_store: 'Plugin-Store',
172+
com_nav_plugin_search: 'Suche nach Plugins',
173+
com_nav_plugin_auth_error:
174+
'Beim Versuch, dieses Plugin zu authentifizieren, ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.',
171175
com_nav_export_filename: 'Dateiname',
172176
com_nav_export_filename_placeholder: 'Lege einen Dateinamen fest',
173177
com_nav_export_type: 'Typ',

client/src/localization/languages/Eng.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ export default {
226226
com_endpoint_config_key_google_service_account: 'Create a Service Account',
227227
com_endpoint_config_key_google_vertex_api_role:
228228
'Make sure to click \'Create and Continue\' to give at least the \'Vertex AI User\' role. Lastly, create a JSON key to import here.',
229+
com_nav_plugin_store: 'Plugin store',
230+
com_nav_plugin_search: 'Search plugins',
231+
com_nav_plugin_auth_error:
232+
'There was an error attempting to authenticate this plugin. Please try again.',
229233
com_nav_close_menu: 'Close sidebar',
230234
com_nav_open_menu: 'Open sidebar',
231235
com_nav_export_filename: 'Filename',

client/src/localization/languages/Es.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ export default {
230230
com_endpoint_config_key_google_service_account: 'Crear una Cuenta de Servicio',
231231
com_endpoint_config_key_google_vertex_api_role:
232232
'Asegúrese de hacer clic en \'Crear y Continuar\' para asignar al menos la función de \'Usuario de Vertex AI\'. Finalmente, cree una clave JSON para importar aquí.',
233+
com_nav_plugin_store: 'Tienda de complementos',
234+
com_nav_plugin_search: 'Buscar complementos',
235+
com_nav_plugin_auth_error:
236+
'Se produjo un error al intentar autenticar este complemento. Por favor, inténtalo de nuevo.',
233237
com_nav_export_filename: 'Nombre del Archivo',
234238
com_nav_export_filename_placeholder: 'Establece el nombre del archivo',
235239
com_nav_export_type: 'Tipo',

client/src/localization/languages/Fr.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ export default {
170170
com_endpoint_func_hover: 'Activer l\'utilisation des plugins comme fonctions OpenAI',
171171
com_endpoint_skip_hover:
172172
'Activer le saut de l\'étape de complétion, qui examine la réponse finale et les étapes générées',
173+
com_nav_plugin_store: 'Boutique de plugins',
174+
com_nav_plugin_search: 'Rechercher des plugins',
175+
com_nav_plugin_auth_error:
176+
'Une erreur s\'est produite lors de la tentative d\'authentification de ce plugin. Veuillez réessayer.',
173177
com_nav_export_filename: 'Nom du fichier',
174178
com_nav_export_filename_placeholder: 'Définir le nom du fichier',
175179
com_nav_export_type: 'Type',

client/src/localization/languages/It.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ export default {
226226
com_endpoint_config_key_google_service_account: 'Crea un account di servizio',
227227
com_endpoint_config_key_google_vertex_api_role:
228228
'Assicurati di fare clic su \'Crea e continua\' per dare almeno il ruolo \'Utente Vertex AI\'. Infine, crea una chiave JSON da importare qui.',
229+
com_nav_plugin_store: 'Negozio dei plugin',
230+
com_nav_plugin_search: 'Cerca plugin',
231+
com_nav_plugin_auth_error:
232+
'Si è verificato un errore durante il tentativo di autenticare questo plugin. Per favore, riprova.',
229233
com_nav_close_menu: 'Apri la barra laterale',
230234
com_nav_open_menu: 'Chiudi la barra laterale',
231235
com_nav_export_filename: 'Nome del file',

client/src/localization/languages/Jp.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ export default {
223223
com_endpoint_config_key_google_service_account: 'Service Accountを作成する',
224224
com_endpoint_config_key_google_vertex_api_role:
225225
'必ず「作成して続行」をクリックして、最低でも「Vertex AI ユーザー」ロールを与えてください。最後にここにインポートするJSONキーを作成してください。',
226+
com_nav_plugin_store: 'プラグインストア',
227+
com_nav_plugin_search: 'プラグイン検索',
228+
com_nav_plugin_auth_error:
229+
'このプラグインの認証中にエラーが発生しました。もう一度お試しください。',
226230
com_nav_export_filename: 'ファイル名',
227231
com_nav_export_filename_placeholder: 'ファイル名を入力してください',
228232
com_nav_export_type: 'タイプ',

client/src/localization/languages/Ko.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ export default {
103103
com_endpoint_bing_to_enable_sydney: '시드니를 활성화하려면',
104104
com_endpoint_bing_jailbreak: 'Jailbreak',
105105
com_endpoint_bing_context_placeholder:
106-
"Bing은 '컨텍스트'로 최대 7,000개의 토큰을 사용할 수 있으며, 대화에서 참조할 수 있습니다. 구체적인 제한은 알려져 있지 않지만, 7,000개의 토큰을 초과하면 오류가 발생할 수 있습니다.",
106+
'Bing은 \'컨텍스트\'로 최대 7,000개의 토큰을 사용할 수 있으며, 대화에서 참조할 수 있습니다. 구체적인 제한은 알려져 있지 않지만, 7,000개의 토큰을 초과하면 오류가 발생할 수 있습니다.',
107107
com_endpoint_bing_system_message_placeholder:
108-
"경고: 이 기능의 오용으로 인해 Bing의 사용이 '금지'될 수 있습니다. 모든 내용을 보려면 '시스템 메시지'를 클릭하세요. 생략된 경우 '시드니' 프리셋이 사용됩니다.",
108+
'경고: 이 기능의 오용으로 인해 Bing의 사용이 \'금지\'될 수 있습니다. 모든 내용을 보려면 \'시스템 메시지\'를 클릭하세요. 생략된 경우 \'시드니\' 프리셋이 사용됩니다.',
109109
com_endpoint_system_message: '시스템 메시지',
110110
com_endpoint_default_blank: '기본값: 공백',
111111
com_endpoint_default_false: '기본값: false',
@@ -209,6 +209,10 @@ export default {
209209
'로그인한 상태에서 개발 도구 또는 확장 프로그램을 사용하여 _U 쿠키의 내용을 복사합니다. 실패하는 경우 다음',
210210
com_endpoint_config_key_edge_instructions: '지침',
211211
com_endpoint_config_key_edge_full_key_string: '전체 쿠키 문자열을 제공하세요',
212+
com_nav_plugin_store: '플러그인 스토어',
213+
com_nav_plugin_search: '플러그인 검색',
214+
com_nav_plugin_auth_error:
215+
'이 플러그인을 인증하려는 중에 오류가 발생했습니다. 다시 시도해주세요.',
212216
com_nav_export_filename: '파일 이름',
213217
com_nav_export_filename_placeholder: '파일 이름을 설정하세요',
214218
com_nav_export_type: '유형',

client/src/localization/languages/Pl.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ export default {
171171
com_endpoint_skip_hover:
172172
'Omijaj etap uzupełnienia sprawdzający ostateczną odpowiedź i generowane kroki',
173173
com_endpoint_config_token: 'Token konfiguracji',
174+
com_nav_plugin_store: 'Sklep z wtyczkami',
175+
com_nav_plugin_search: 'Wyszukiwanie wtyczek',
176+
com_nav_plugin_auth_error:
177+
'Wystąpił błąd podczas próby uwierzytelnienia tej wtyczki. Proszę spróbować ponownie.',
174178
com_nav_export_filename: 'Nazwa pliku',
175179
com_nav_export_filename_placeholder: 'Podaj nazwę pliku',
176180
com_nav_export_type: 'Typ',

client/src/localization/languages/Ru.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ export default {
171171
com_endpoint_skip_hover:
172172
'Пропустить этап завершения, который проверяет окончательный ответ и сгенерированные шаги',
173173
com_endpoint_config_token: 'Токен конфигурации',
174+
com_nav_plugin_store: 'Магазин плагинов',
175+
com_nav_plugin_search: 'Поиск плагинов',
176+
com_nav_plugin_auth_error:
177+
'При попытке аутентификации этого плагина произошла ошибка. Пожалуйста, попробуйте еще раз.',
174178
com_nav_export_filename: 'Имя файла',
175179
com_nav_export_filename_placeholder: 'Установите имя файла',
176180
com_nav_export_type: 'Тип',

client/src/localization/languages/Sv.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ export default {
224224
com_endpoint_config_key_google_service_account: 'Skapa ett tjänstekonto', // Create a Service Account
225225
com_endpoint_config_key_google_vertex_api_role:
226226
'Se till att klicka på "Skapa och fortsätt" för att ge åtminstone rollen "Vertex AI-användare". Skapa slutligen en JSON-nyckel att importera här.', // Make sure to click 'Create and Continue' to give at least the 'Vertex AI User' role. Lastly, create a JSON key to import here.
227+
com_nav_plugin_store: 'Pluginbutik',
228+
com_nav_plugin_search: 'Sök efter plugins',
229+
com_nav_plugin_auth_error:
230+
'Det uppstod ett fel när försöket att autentisera denna plugin gjordes. Försök igen.',
227231
com_nav_export_filename: 'Filnamn', // Filename
228232
com_nav_export_filename_placeholder: 'Ange filnamnet', // Set the filename
229233
com_nav_export_type: 'Typ', // Type

client/src/localization/languages/Zh.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ export default {
167167
com_endpoint_completion_model: '补全模型 (推荐: GPT-4)',
168168
com_endpoint_func_hover: '将插件当做OpenAI函数使用',
169169
com_endpoint_skip_hover: '跳过补全步骤, 用于检查最终答案和生成步骤',
170+
com_nav_plugin_store: '插件商店',
171+
com_nav_plugin_search: '搜索插件',
172+
com_nav_plugin_auth_error: '尝试验证此插件时出错。请重试。',
170173
com_endpoint_import: '导入',
171174
com_endpoint_preset: '预设',
172175
com_endpoint_presets: '预设',

0 commit comments

Comments
 (0)