From 72bc24a4900495f269ed280bf268a0e7e88217eb Mon Sep 17 00:00:00 2001 From: Manish Madan Date: Mon, 13 Oct 2025 21:41:24 +0530 Subject: [PATCH] Chore: deleted unused files, dead code; minor fixes (#2059) * (feat:pause-stream) generator exit * (feat:pause-stream) close request * (feat:pause-stream) finally close; google anthropic * (feat:task_status)communicate failure * (clean:connector) unused routes * (feat:file-table) missing skeletons * (chore:fe) purge unused * (fix:apiKeys) build err * (chore:settings) clean unused * merge from main * (chore:purge) unused fe assets * (clean:check_docs) unused logic * (feat:selectedDocs) replace null type --------- Co-authored-by: GH Action - Upstream Sync --- application/api/user/sources/routes.py | 27 -- frontend/src/agents/agentPreviewSlice.ts | 4 +- frontend/src/api/endpoints.ts | 1 - frontend/src/api/services/userService.ts | 2 - frontend/src/assets/arrow.svg | 3 - frontend/src/assets/caret-sort.svg | 1 - frontend/src/assets/cogwheel.svg | 3 - frontend/src/assets/copy-linear.svg | 4 - frontend/src/assets/discord-dark.svg | 3 - frontend/src/assets/envelope-dark.svg | 3 - frontend/src/assets/github-dark.svg | 3 - frontend/src/assets/hamburger-dark.svg | 3 - frontend/src/assets/info-dark.svg | 3 - frontend/src/assets/key.svg | 3 - frontend/src/assets/message-dark.svg | 3 - frontend/src/assets/message.svg | 3 - frontend/src/assets/outline-source.svg | 3 - frontend/src/assets/paper_plane.svg | 3 - frontend/src/assets/send_dark.svg | 3 - frontend/src/assets/server.svg | 0 frontend/src/assets/settingGear-dark.svg | 3 - frontend/src/assets/website_collect.svg | 6 - frontend/src/components/ShareButton.tsx | 36 --- frontend/src/components/SourceDropdown.tsx | 175 ------------- .../src/conversation/conversationHandlers.ts | 18 +- frontend/src/hooks/usePromptManager.ts | 168 ------------- frontend/src/modals/ChunkModal.tsx | 158 ------------ frontend/src/preferences/preferenceApi.ts | 10 - frontend/src/preferences/preferenceSlice.ts | 9 +- frontend/src/settings/APIKeys.tsx | 233 ------------------ frontend/src/settings/Widgets.tsx | 112 --------- frontend/src/settings/index.tsx | 18 -- frontend/src/store.ts | 2 +- frontend/src/upload/Upload.tsx | 10 +- 34 files changed, 27 insertions(+), 1009 deletions(-) delete mode 100644 frontend/src/assets/arrow.svg delete mode 100644 frontend/src/assets/caret-sort.svg delete mode 100644 frontend/src/assets/cogwheel.svg delete mode 100644 frontend/src/assets/copy-linear.svg delete mode 100644 frontend/src/assets/discord-dark.svg delete mode 100644 frontend/src/assets/envelope-dark.svg delete mode 100644 frontend/src/assets/github-dark.svg delete mode 100644 frontend/src/assets/hamburger-dark.svg delete mode 100644 frontend/src/assets/info-dark.svg delete mode 100644 frontend/src/assets/key.svg delete mode 100644 frontend/src/assets/message-dark.svg delete mode 100644 frontend/src/assets/message.svg delete mode 100644 frontend/src/assets/outline-source.svg delete mode 100644 frontend/src/assets/paper_plane.svg delete mode 100644 frontend/src/assets/send_dark.svg delete mode 100644 frontend/src/assets/server.svg delete mode 100644 frontend/src/assets/settingGear-dark.svg delete mode 100644 frontend/src/assets/website_collect.svg delete mode 100644 frontend/src/components/ShareButton.tsx delete mode 100644 frontend/src/components/SourceDropdown.tsx delete mode 100644 frontend/src/hooks/usePromptManager.ts delete mode 100644 frontend/src/modals/ChunkModal.tsx delete mode 100644 frontend/src/settings/APIKeys.tsx delete mode 100644 frontend/src/settings/Widgets.tsx diff --git a/application/api/user/sources/routes.py b/application/api/user/sources/routes.py index d67b2935..395c8c0a 100644 --- a/application/api/user/sources/routes.py +++ b/application/api/user/sources/routes.py @@ -2,12 +2,10 @@ import json import math -import os from bson.objectid import ObjectId from flask import current_app, jsonify, make_response, redirect, request from flask_restx import fields, Namespace, Resource -from werkzeug.utils import secure_filename from application.api import api from application.api.user.base import sources_collection @@ -136,31 +134,6 @@ class PaginatedSources(Resource): return make_response(jsonify({"success": False}), 400) -@sources_ns.route("/docs_check") -class CheckDocs(Resource): - check_docs_model = api.model( - "CheckDocsModel", - {"docs": fields.String(required=True, description="Document name")}, - ) - - @api.expect(check_docs_model) - @api.doc(description="Check if document exists") - def post(self): - data = request.get_json() - required_fields = ["docs"] - missing_fields = check_required_fields(data, required_fields) - if missing_fields: - return missing_fields - try: - vectorstore = "vectors/" + secure_filename(data["docs"]) - if os.path.exists(vectorstore) or data["docs"] == "default": - return {"status": "exists"}, 200 - except Exception as err: - current_app.logger.error(f"Error checking document: {err}", exc_info=True) - return make_response(jsonify({"success": False}), 400) - return make_response(jsonify({"status": "not found"}), 404) - - @sources_ns.route("/delete_by_ids") class DeleteByIds(Resource): @api.doc( diff --git a/frontend/src/agents/agentPreviewSlice.ts b/frontend/src/agents/agentPreviewSlice.ts index b08d9d2e..f7e8d6f4 100644 --- a/frontend/src/agents/agentPreviewSlice.ts +++ b/frontend/src/agents/agentPreviewSlice.ts @@ -57,7 +57,7 @@ export const fetchPreviewAnswer = createAsyncThunk< question, signal, state.preference.token, - state.preference.selectedDocs!, + state.preference.selectedDocs, null, // No conversation ID for previews state.preference.prompt.id, state.preference.chunks, @@ -128,7 +128,7 @@ export const fetchPreviewAnswer = createAsyncThunk< question, signal, state.preference.token, - state.preference.selectedDocs!, + state.preference.selectedDocs, null, // No conversation ID for previews state.preference.prompt.id, state.preference.chunks, diff --git a/frontend/src/api/endpoints.ts b/frontend/src/api/endpoints.ts index 569e2095..81639da4 100644 --- a/frontend/src/api/endpoints.ts +++ b/frontend/src/api/endpoints.ts @@ -3,7 +3,6 @@ const endpoints = { CONFIG: '/api/config', NEW_TOKEN: '/api/generate_token', DOCS: '/api/sources', - DOCS_CHECK: '/api/docs_check', DOCS_PAGINATED: '/api/sources/paginated', API_KEYS: '/api/get_api_keys', CREATE_API_KEY: '/api/create_api_key', diff --git a/frontend/src/api/services/userService.ts b/frontend/src/api/services/userService.ts index 513dd613..ecd3df3d 100644 --- a/frontend/src/api/services/userService.ts +++ b/frontend/src/api/services/userService.ts @@ -10,8 +10,6 @@ const userService = { apiClient.get(`${endpoints.USER.DOCS}`, token), getDocsWithPagination: (query: string, token: string | null): Promise => apiClient.get(`${endpoints.USER.DOCS_PAGINATED}?${query}`, token), - checkDocs: (data: any, token: string | null): Promise => - apiClient.post(endpoints.USER.DOCS_CHECK, data, token), getAPIKeys: (token: string | null): Promise => apiClient.get(endpoints.USER.API_KEYS, token), createAPIKey: (data: any, token: string | null): Promise => diff --git a/frontend/src/assets/arrow.svg b/frontend/src/assets/arrow.svg deleted file mode 100644 index 8debfc9a..00000000 --- a/frontend/src/assets/arrow.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/frontend/src/assets/caret-sort.svg b/frontend/src/assets/caret-sort.svg deleted file mode 100644 index 9380120d..00000000 --- a/frontend/src/assets/caret-sort.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/frontend/src/assets/cogwheel.svg b/frontend/src/assets/cogwheel.svg deleted file mode 100644 index f5299b8b..00000000 --- a/frontend/src/assets/cogwheel.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/frontend/src/assets/copy-linear.svg b/frontend/src/assets/copy-linear.svg deleted file mode 100644 index f6b8b64e..00000000 --- a/frontend/src/assets/copy-linear.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/frontend/src/assets/discord-dark.svg b/frontend/src/assets/discord-dark.svg deleted file mode 100644 index 8438962a..00000000 --- a/frontend/src/assets/discord-dark.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/frontend/src/assets/envelope-dark.svg b/frontend/src/assets/envelope-dark.svg deleted file mode 100644 index a61bec4f..00000000 --- a/frontend/src/assets/envelope-dark.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/frontend/src/assets/github-dark.svg b/frontend/src/assets/github-dark.svg deleted file mode 100644 index b4689ddd..00000000 --- a/frontend/src/assets/github-dark.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/frontend/src/assets/hamburger-dark.svg b/frontend/src/assets/hamburger-dark.svg deleted file mode 100644 index 454d76ad..00000000 --- a/frontend/src/assets/hamburger-dark.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/frontend/src/assets/info-dark.svg b/frontend/src/assets/info-dark.svg deleted file mode 100644 index 9241dee6..00000000 --- a/frontend/src/assets/info-dark.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/frontend/src/assets/key.svg b/frontend/src/assets/key.svg deleted file mode 100644 index 4f8a272b..00000000 --- a/frontend/src/assets/key.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/frontend/src/assets/message-dark.svg b/frontend/src/assets/message-dark.svg deleted file mode 100644 index 7d8964a6..00000000 --- a/frontend/src/assets/message-dark.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/frontend/src/assets/message.svg b/frontend/src/assets/message.svg deleted file mode 100644 index 228598dd..00000000 --- a/frontend/src/assets/message.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/frontend/src/assets/outline-source.svg b/frontend/src/assets/outline-source.svg deleted file mode 100644 index 36b3aa6e..00000000 --- a/frontend/src/assets/outline-source.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/frontend/src/assets/paper_plane.svg b/frontend/src/assets/paper_plane.svg deleted file mode 100644 index 7520946d..00000000 --- a/frontend/src/assets/paper_plane.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/frontend/src/assets/send_dark.svg b/frontend/src/assets/send_dark.svg deleted file mode 100644 index 15911f95..00000000 --- a/frontend/src/assets/send_dark.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/frontend/src/assets/server.svg b/frontend/src/assets/server.svg deleted file mode 100644 index e69de29b..00000000 diff --git a/frontend/src/assets/settingGear-dark.svg b/frontend/src/assets/settingGear-dark.svg deleted file mode 100644 index b48608a9..00000000 --- a/frontend/src/assets/settingGear-dark.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/frontend/src/assets/website_collect.svg b/frontend/src/assets/website_collect.svg deleted file mode 100644 index 22d3e1de..00000000 --- a/frontend/src/assets/website_collect.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/frontend/src/components/ShareButton.tsx b/frontend/src/components/ShareButton.tsx deleted file mode 100644 index 143fe37f..00000000 --- a/frontend/src/components/ShareButton.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import { useState } from 'react'; -import ShareIcon from '../assets/share.svg'; -import { ShareConversationModal } from '../modals/ShareConversationModal'; - -type ShareButtonProps = { - conversationId: string; -}; - -export default function ShareButton({ conversationId }: ShareButtonProps) { - const [isShareModalOpen, setShareModalState] = useState(false); - return ( - <> - - {isShareModalOpen && ( - { - setShareModalState(false); - }} - conversationId={conversationId} - /> - )} - - ); -} diff --git a/frontend/src/components/SourceDropdown.tsx b/frontend/src/components/SourceDropdown.tsx deleted file mode 100644 index a1097e4f..00000000 --- a/frontend/src/components/SourceDropdown.tsx +++ /dev/null @@ -1,175 +0,0 @@ -import React, { useState } from 'react'; -import Trash from '../assets/trash.svg'; -import Arrow2 from '../assets/dropdown-arrow.svg'; -import { Doc, ActiveState } from '../models/misc'; -import { useDispatch } from 'react-redux'; -import { useTranslation } from 'react-i18next'; -import ConfirmationModal from '../modals/ConfirmationModal'; - -type Props = { - options: Doc[] | null; - selectedDocs: Doc | null; - setSelectedDocs: any; - isDocsListOpen: boolean; - setIsDocsListOpen: React.Dispatch>; - handleDeleteClick: any; - handlePostDocumentSelect: any; -}; - -function SourceDropdown({ - options, - setSelectedDocs, - selectedDocs, - setIsDocsListOpen, - isDocsListOpen, - handleDeleteClick, - handlePostDocumentSelect, // Callback function fired after a document is selected -}: Props) { - const dispatch = useDispatch(); - const { t } = useTranslation(); - const dropdownRef = React.useRef(null); - const embeddingsName = - import.meta.env.VITE_EMBEDDINGS_NAME || - 'huggingface_sentence-transformers/all-mpnet-base-v2'; - - const [deleteModalState, setDeleteModalState] = - useState('INACTIVE'); - const [documentToDelete, setDocumentToDelete] = useState(null); - - const handleEmptyDocumentSelect = () => { - dispatch(setSelectedDocs(null)); - setIsDocsListOpen(false); - }; - - const handleClickOutside = (event: MouseEvent) => { - if ( - dropdownRef.current && - !dropdownRef.current.contains(event.target as Node) - ) { - setIsDocsListOpen(false); - } - }; - - React.useEffect(() => { - document.addEventListener('mousedown', handleClickOutside); - return () => { - document.removeEventListener('mousedown', handleClickOutside); - }; - }, []); - - const confirmDelete = (option: Doc) => { - setDocumentToDelete(option); - setDeleteModalState('ACTIVE'); - }; - - const handleConfirmedDelete = () => { - if (documentToDelete) { - handleDeleteClick(documentToDelete); - setDeleteModalState('INACTIVE'); - setDocumentToDelete(null); - } - }; - - const handleCancelDelete = () => { - setDeleteModalState('INACTIVE'); - setDocumentToDelete(null); - }; - - return ( -
- - {isDocsListOpen && ( -
- {options ? ( - options.map((option: any, index: number) => { - if (option.model === embeddingsName) { - return ( -
{ - dispatch(setSelectedDocs(option)); - setIsDocsListOpen(false); - handlePostDocumentSelect(option); - }} - > - { - setIsDocsListOpen(false); - }} - className="ml-4 flex-1 overflow-hidden py-3 text-ellipsis whitespace-nowrap" - > - {option.name} - - {option.location === 'local' && ( - Delete { - event.stopPropagation(); - confirmDelete(option); - }} - /> - )} -
- ); - } - }) - ) : ( - <> - )} -
- { - handlePostDocumentSelect(null); - }} - > - {t('none')} - -
-
- )} - -
- ); -} - -export default SourceDropdown; diff --git a/frontend/src/conversation/conversationHandlers.ts b/frontend/src/conversation/conversationHandlers.ts index 63557924..8f145d08 100644 --- a/frontend/src/conversation/conversationHandlers.ts +++ b/frontend/src/conversation/conversationHandlers.ts @@ -7,7 +7,7 @@ export function handleFetchAnswer( question: string, signal: AbortSignal, token: string | null, - selectedDocs: Doc[] | null, + selectedDocs: Doc[], conversationId: string | null, promptId: string | null, chunks: string, @@ -42,7 +42,7 @@ export function handleFetchAnswer( prompt_id: promptId, chunks: chunks, token_limit: token_limit, - isNoneDoc: selectedDocs === null, + isNoneDoc: selectedDocs.length === 0, agent_id: agentId, save_conversation: save_conversation, }; @@ -52,7 +52,7 @@ export function handleFetchAnswer( payload.attachments = attachments; } - if (selectedDocs && Array.isArray(selectedDocs)) { + if (selectedDocs.length > 0) { if (selectedDocs.length > 1) { // Handle multiple documents payload.active_docs = selectedDocs.map((doc) => doc.id!); @@ -91,7 +91,7 @@ export function handleFetchAnswerSteaming( question: string, signal: AbortSignal, token: string | null, - selectedDocs: Doc[] | null, + selectedDocs: Doc[], conversationId: string | null, promptId: string | null, chunks: string, @@ -108,7 +108,7 @@ export function handleFetchAnswerSteaming( prompt_id: promptId, chunks: chunks, token_limit: token_limit, - isNoneDoc: selectedDocs === null, + isNoneDoc: selectedDocs.length === 0, index: indx, agent_id: agentId, save_conversation: save_conversation, @@ -119,7 +119,7 @@ export function handleFetchAnswerSteaming( payload.attachments = attachments; } - if (selectedDocs && Array.isArray(selectedDocs)) { + if (selectedDocs.length > 0) { if (selectedDocs.length > 1) { // Handle multiple documents payload.active_docs = selectedDocs.map((doc) => doc.id!); @@ -185,7 +185,7 @@ export function handleFetchAnswerSteaming( export function handleSearch( question: string, token: string | null, - selectedDocs: Doc[] | null, + selectedDocs: Doc[], conversation_id: string | null, chunks: string, token_limit: number, @@ -195,9 +195,9 @@ export function handleSearch( conversation_id: conversation_id, chunks: chunks, token_limit: token_limit, - isNoneDoc: selectedDocs === null, + isNoneDoc: selectedDocs.length === 0, }; - if (selectedDocs && Array.isArray(selectedDocs)) { + if (selectedDocs.length > 0) { if (selectedDocs.length > 1) { // Handle multiple documents payload.active_docs = selectedDocs.map((doc) => doc.id!); diff --git a/frontend/src/hooks/usePromptManager.ts b/frontend/src/hooks/usePromptManager.ts deleted file mode 100644 index 28d1d6b5..00000000 --- a/frontend/src/hooks/usePromptManager.ts +++ /dev/null @@ -1,168 +0,0 @@ -import { useCallback, useState, useEffect } from 'react'; -import { useSelector } from 'react-redux'; - -import userService from '../api/services/userService'; -import { Prompt } from '../models/misc'; -import { selectToken } from '../preferences/preferenceSlice'; - -type UsePromptManagerProps = { - initialPrompts: Prompt[]; - onPromptSelect: (name: string, id: string, type: string) => void; - onPromptsUpdate: (updatedPrompts: Prompt[]) => void; -}; - -type PromptContentResponse = { - id: string; - name: string; - content: string; -}; - -type PromptCreateResponse = { - id: string; -}; - -export const usePromptManager = ({ - initialPrompts, - onPromptSelect, - onPromptsUpdate, -}: UsePromptManagerProps) => { - const token = useSelector(selectToken); - - const [prompts, setPrompts] = useState(initialPrompts); - const [isLoading, setIsLoading] = useState(false); - const [error, setError] = useState(null); - - useEffect(() => { - setPrompts(initialPrompts); - }, [initialPrompts]); - - const handleApiCall = async ( - apiCall: () => Promise, - errorMessage: string, - ): Promise => { - setIsLoading(true); - setError(null); - try { - const response = await apiCall(); - if (!response.ok) { - const errorData = await response.text(); - console.error(`${errorMessage}: ${response.status} ${errorData}`); - throw new Error(`${errorMessage} (Status: ${response.status})`); - } - const contentType = response.headers.get('content-type'); - if (contentType && contentType.includes('application/json')) { - return (await response.json()) as T; - } - return null; - } catch (err) { - const message = err instanceof Error ? err.message : String(err); - setError(message); - console.error(err); - return null; - } finally { - setIsLoading(false); - } - }; - - const addPrompt = useCallback( - async (name: string, content: string): Promise => { - const newPromptData = await handleApiCall( - () => userService.createPrompt({ name, content }, token), - 'Failed to add prompt', - ); - - if (newPromptData) { - const newPrompt: Prompt = { - name, - id: newPromptData.id, - type: 'private', - }; - const updatedPrompts = [...prompts, newPrompt]; - setPrompts(updatedPrompts); - onPromptsUpdate(updatedPrompts); - onPromptSelect(newPrompt.name, newPrompt.id, newPrompt.type); - return newPrompt; - } - return null; - }, - [token, prompts, onPromptsUpdate, onPromptSelect], - ); - - const deletePrompt = useCallback( - async (idToDelete: string): Promise => { - const originalPrompts = [...prompts]; - const updatedPrompts = prompts.filter( - (prompt) => prompt.id !== idToDelete, - ); - setPrompts(updatedPrompts); - onPromptsUpdate(updatedPrompts); - - const result = await handleApiCall( - () => userService.deletePrompt({ id: idToDelete }, token), - 'Failed to delete prompt', - ); - - if (result === null && error) { - setPrompts(originalPrompts); - onPromptsUpdate(originalPrompts); - } else { - if (updatedPrompts.length > 0) { - onPromptSelect( - updatedPrompts[0].name, - updatedPrompts[0].id, - updatedPrompts[0].type, - ); - } - } - }, - [token, prompts, onPromptsUpdate, onPromptSelect, error], - ); - - const fetchPromptContent = useCallback( - async (id: string): Promise => { - const promptDetails = await handleApiCall( - () => userService.getSinglePrompt(id, token), - 'Failed to fetch prompt content', - ); - return promptDetails ? promptDetails.content : null; - }, - [token], - ); - - const updatePrompt = useCallback( - async ( - id: string, - name: string, - content: string, - type: string, - ): Promise => { - const result = await handleApiCall<{ success: boolean }>( - () => userService.updatePrompt({ id, name, content }, token), - 'Failed to update prompt', - ); - - if (result?.success) { - const updatedPrompts = prompts.map((p) => - p.id === id ? { ...p, name, type } : p, - ); - setPrompts(updatedPrompts); - onPromptsUpdate(updatedPrompts); - onPromptSelect(name, id, type); - return true; - } - return false; - }, - [token, prompts, onPromptsUpdate, onPromptSelect], - ); - - return { - prompts, - isLoading, - error, - addPrompt, - deletePrompt, - fetchPromptContent, - updatePrompt, - setError, - }; -}; diff --git a/frontend/src/modals/ChunkModal.tsx b/frontend/src/modals/ChunkModal.tsx deleted file mode 100644 index e24fc5b9..00000000 --- a/frontend/src/modals/ChunkModal.tsx +++ /dev/null @@ -1,158 +0,0 @@ -import React from 'react'; -import { useTranslation } from 'react-i18next'; - -import Input from '../components/Input'; -import { ActiveState } from '../models/misc'; -import ConfirmationModal from './ConfirmationModal'; -import WrapperModal from './WrapperModal'; - -export default function ChunkModal({ - type, - modalState, - setModalState, - handleSubmit, - originalTitle, - originalText, - handleDelete, -}: { - type: 'ADD' | 'EDIT'; - modalState: ActiveState; - setModalState: (state: ActiveState) => void; - handleSubmit: (title: string, text: string) => void; - originalTitle?: string; - originalText?: string; - handleDelete?: () => void; -}) { - const { t } = useTranslation(); - const [title, setTitle] = React.useState(''); - const [chunkText, setChunkText] = React.useState(''); - const [deleteModal, setDeleteModal] = React.useState('INACTIVE'); - - React.useEffect(() => { - setTitle(originalTitle || ''); - setChunkText(originalText || ''); - }, [originalTitle, originalText]); - - const resetForm = () => { - setTitle(''); - setChunkText(''); - }; - - const handleDeleteConfirmed = () => { - if (handleDelete) { - handleDelete(); - } - setDeleteModal('INACTIVE'); - setModalState('INACTIVE'); - }; - - if (modalState !== 'ACTIVE') return null; - - const content = ( -
-

- {t(`modals.chunk.${type === 'ADD' ? 'add' : 'edit'}`)} -

-
- setTitle(e.target.value)} - borderVariant="thin" - placeholder={t('modals.chunk.title')} - labelBgClassName="bg-white dark:bg-charleston-green-2" - /> -
-
-
- - {t('modals.chunk.bodyText')} - - -
-
- - {type === 'ADD' ? ( -
- - -
- ) : ( -
- -
- - -
-
- )} -
- ); - - return ( - <> - setModalState('INACTIVE')} - className="sm:w-[620px]" - isPerformingTask={true} - > - {content} - - - {type === 'EDIT' && ( - - )} - - ); -} diff --git a/frontend/src/preferences/preferenceApi.ts b/frontend/src/preferences/preferenceApi.ts index 4e5b5d00..19fe54f5 100644 --- a/frontend/src/preferences/preferenceApi.ts +++ b/frontend/src/preferences/preferenceApi.ts @@ -111,16 +111,6 @@ export function setLocalPrompt(prompt: string): void { export function setLocalRecentDocs(docs: Doc[] | null): void { if (docs && docs.length > 0) { localStorage.setItem('DocsGPTRecentDocs', JSON.stringify(docs)); - - docs.forEach((doc) => { - let docPath = 'default'; - if (doc.type === 'local') { - docPath = 'local' + '/' + doc.name + '/'; - } - userService - .checkDocs({ docs: docPath }, null) - .then((response) => response.json()); - }); } else { localStorage.removeItem('DocsGPTRecentDocs'); } diff --git a/frontend/src/preferences/preferenceSlice.ts b/frontend/src/preferences/preferenceSlice.ts index e3300a4e..18fe698c 100644 --- a/frontend/src/preferences/preferenceSlice.ts +++ b/frontend/src/preferences/preferenceSlice.ts @@ -15,7 +15,7 @@ export interface Preference { prompt: { name: string; id: string; type: string }; chunks: string; token_limit: number; - selectedDocs: Doc[] | null; + selectedDocs: Doc[]; sourceDocs: Doc[] | null; conversations: { data: { name: string; id: string }[] | null; @@ -137,8 +137,11 @@ prefListenerMiddleware.startListening({ prefListenerMiddleware.startListening({ matcher: isAnyOf(setSelectedDocs), effect: (action, listenerApi) => { + const state = listenerApi.getState() as RootState; setLocalRecentDocs( - (listenerApi.getState() as RootState).preference.selectedDocs ?? null, + state.preference.selectedDocs.length > 0 + ? state.preference.selectedDocs + : null, ); }, }); @@ -179,7 +182,7 @@ export const selectApiKey = (state: RootState) => state.preference.apiKey; export const selectApiKeyStatus = (state: RootState) => !!state.preference.apiKey; export const selectSelectedDocsStatus = (state: RootState) => - !!state.preference.selectedDocs; + state.preference.selectedDocs.length > 0; export const selectSourceDocs = (state: RootState) => state.preference.sourceDocs; export const selectModalStateDeleteConv = (state: RootState) => diff --git a/frontend/src/settings/APIKeys.tsx b/frontend/src/settings/APIKeys.tsx deleted file mode 100644 index dfeb3c47..00000000 --- a/frontend/src/settings/APIKeys.tsx +++ /dev/null @@ -1,233 +0,0 @@ -import React, { useState } from 'react'; -import { useTranslation } from 'react-i18next'; -import { useSelector } from 'react-redux'; - -import userService from '../api/services/userService'; -import Trash from '../assets/trash.svg'; -import SkeletonLoader from '../components/SkeletonLoader'; -import { useLoaderState } from '../hooks'; -import ConfirmationModal from '../modals/ConfirmationModal'; -import CreateAPIKeyModal from '../modals/CreateAPIKeyModal'; -import SaveAPIKeyModal from '../modals/SaveAPIKeyModal'; -import { selectToken } from '../preferences/preferenceSlice'; -import { APIKeyData } from './types'; - -export default function APIKeys() { - const { t } = useTranslation(); - const token = useSelector(selectToken); - const [isCreateModalOpen, setCreateModal] = useState(false); - const [isSaveKeyModalOpen, setSaveKeyModal] = useState(false); - const [newKey, setNewKey] = useState(''); - const [apiKeys, setApiKeys] = useState([]); - const [loading, setLoading] = useLoaderState(true); - const [keyToDelete, setKeyToDelete] = useState<{ - id: string; - name: string; - } | null>(null); - - const handleFetchKeys = async () => { - setLoading(true); - try { - const response = await userService.getAPIKeys(token); - if (!response.ok) { - throw new Error('Failed to fetch API Keys'); - } - const apiKeys = await response.json(); - setApiKeys(apiKeys); - } catch (error) { - console.log(error); - } finally { - setLoading(false); - } - }; - - const handleDeleteKey = (id: string) => { - setLoading(true); - userService - .deleteAPIKey({ id }, token) - .then((response) => { - if (!response.ok) { - throw new Error('Failed to delete API Key'); - } - return response.json(); - }) - .then((data) => { - if (data.success === true) { - setApiKeys((previous) => previous.filter((elem) => elem.id !== id)); - } - setKeyToDelete(null); - }) - .catch((error) => { - console.error(error); - }) - .finally(() => { - setLoading(false); - }); - }; - - const handleCreateKey = (payload: { - name: string; - source?: string; - retriever?: string; - prompt_id: string; - chunks: string; - }) => { - setLoading(true); - userService - .createAPIKey(payload, token) - .then((response) => { - if (!response.ok) { - throw new Error('Failed to create API Key'); - } - return response.json(); - }) - .then((data) => { - setApiKeys([...apiKeys, data]); - setCreateModal(false); - setNewKey(data.key); - setSaveKeyModal(true); - handleFetchKeys(); - }) - .catch((error) => { - console.error(error); - }) - .finally(() => { - setLoading(false); - }); - }; - - React.useEffect(() => { - handleFetchKeys(); - }, []); - - return ( -
-
-
-

- {t('settings.apiKeys.description')} -

-
- -
- -
- -
-
-
- - - - - - - - - - - {loading ? ( - - ) : !apiKeys?.length ? ( - - - - ) : ( - Array.isArray(apiKeys) && - apiKeys.map((element) => ( - - - - - - - )) - )} - -
- {t('settings.apiKeys.name')} - - {t('settings.apiKeys.sourceDoc')} - - - {t('settings.apiKeys.key')} - - - {t('settings.apiKeys.key')} - - - Actions -
- {t('settings.apiKeys.noData')} -
-
- {element.name} -
-
-
- {element.source} -
-
-
- {element.key} -
-
-
- -
-
-
-
-
-
- {isCreateModalOpen && ( - setCreateModal(false)} - /> - )} - {isSaveKeyModalOpen && ( - setSaveKeyModal(false)} /> - )} - {keyToDelete && ( - setKeyToDelete(null)} - submitLabel={t('modals.deleteConv.delete')} - handleSubmit={() => handleDeleteKey(keyToDelete.id)} - handleCancel={() => setKeyToDelete(null)} - variant="danger" - /> - )} -
- ); -} diff --git a/frontend/src/settings/Widgets.tsx b/frontend/src/settings/Widgets.tsx deleted file mode 100644 index a0a41b9f..00000000 --- a/frontend/src/settings/Widgets.tsx +++ /dev/null @@ -1,112 +0,0 @@ -import React from 'react'; -import Dropdown from '../components/Dropdown'; - -const Widgets: React.FC<{ - widgetScreenshot: File | null; - onWidgetScreenshotChange: (screenshot: File | null) => void; -}> = ({ widgetScreenshot, onWidgetScreenshotChange }) => { - const widgetSources = ['Source 1', 'Source 2', 'Source 3']; - const widgetMethods = ['Method 1', 'Method 2', 'Method 3']; - const widgetTypes = ['Type 1', 'Type 2', 'Type 3']; - - const [selectedWidgetSource, setSelectedWidgetSource] = React.useState( - widgetSources[0], - ); - const [selectedWidgetMethod, setSelectedWidgetMethod] = React.useState( - widgetMethods[0], - ); - const [selectedWidgetType, setSelectedWidgetType] = React.useState( - widgetTypes[0], - ); - - // const [widgetScreenshot, setWidgetScreenshot] = useState(null); - const [widgetCode, setWidgetCode] = React.useState(''); // Your widget code state - - const handleScreenshotChange = ( - event: React.ChangeEvent, - ) => { - const files = event.target.files; - - if (files && files.length > 0) { - const selectedScreenshot = files[0]; - onWidgetScreenshotChange(selectedScreenshot); // Update the screenshot in the parent component - } - }; - - const handleCopyToClipboard = () => { - // Create a new textarea element to select the text - const textArea = document.createElement('textarea'); - textArea.value = widgetCode; - document.body.appendChild(textArea); - - // Select and copy the text - textArea.select(); - document.execCommand('copy'); - - // Clean up the textarea element - document.body.removeChild(textArea); - }; - - return ( -
-
-

Widget Source

- -
-
-

Widget Method

- -
-
-

Widget Type

- -
-
-

Widget Code Snippet

-