From 100dd0ad530d3ed2f3e333d9012eae8a16f63133 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Wed, 16 Oct 2024 14:52:38 -0700 Subject: [PATCH] validated + cleaned --- .../assistants/gallery/AssistantsGallery.tsx | 5 +- web/src/app/assistants/gallery/page.tsx | 8 +++- .../assistants/mine/AssistantSharingModal.tsx | 2 +- .../app/assistants/mine/AssistantsList.tsx | 9 ++-- web/src/app/assistants/mine/page.tsx | 8 +++- .../modal/configuration/AssistantsTab.tsx | 1 + web/src/app/chat/page.tsx | 8 +++- web/src/app/search/page.tsx | 48 ++++++++++--------- .../components/chat_search/Notification.tsx | 11 ++--- .../components/context/AssisantsContext.tsx | 26 +++++++++- web/src/lib/chat/fetchChatData.ts | 4 ++ 11 files changed, 88 insertions(+), 42 deletions(-) diff --git a/web/src/app/assistants/gallery/AssistantsGallery.tsx b/web/src/app/assistants/gallery/AssistantsGallery.tsx index c704b50c0..aa3e61353 100644 --- a/web/src/app/assistants/gallery/AssistantsGallery.tsx +++ b/web/src/app/assistants/gallery/AssistantsGallery.tsx @@ -28,6 +28,7 @@ export function AssistantGalleryCard({ setPopup: (popup: PopupSpec) => void; selectedAssistant: boolean; }) { + const { refreshUser } = useUser(); const router = useRouter(); return (
- + {shouldShowWelcomeModal && } diff --git a/web/src/app/assistants/mine/AssistantSharingModal.tsx b/web/src/app/assistants/mine/AssistantSharingModal.tsx index a30f3ce08..fd2134582 100644 --- a/web/src/app/assistants/mine/AssistantSharingModal.tsx +++ b/web/src/app/assistants/mine/AssistantSharingModal.tsx @@ -138,7 +138,6 @@ export function AssistantSharingModal({ onOutsideClick={onClose} >
- {isUpdating && }

Manage access to this assistant by sharing it with other users.

@@ -225,6 +224,7 @@ export function AssistantSharingModal({ )}
+ {isUpdating && } ); } diff --git a/web/src/app/assistants/mine/AssistantsList.tsx b/web/src/app/assistants/mine/AssistantsList.tsx index eabed73c6..81ee8f08d 100644 --- a/web/src/app/assistants/mine/AssistantsList.tsx +++ b/web/src/app/assistants/mine/AssistantsList.tsx @@ -109,6 +109,7 @@ function AssistantListItem({ setPopup: (popupSpec: PopupSpec | null) => void; isDragging?: boolean; }) { + const { refreshUser } = useUser(); const router = useRouter(); const [showSharingModal, setShowSharingModal] = useState(false); @@ -203,7 +204,7 @@ function AssistantListItem({ message: `"${assistant.name}" has been removed from your list.`, type: "success", }); - router.refresh(); + await refreshUser(); } else { setPopup({ message: `"${assistant.name}" could not be removed from your list.`, @@ -226,7 +227,7 @@ function AssistantListItem({ message: `"${assistant.name}" has been added to your list.`, type: "success", }); - router.refresh(); + await refreshUser(); } else { setPopup({ message: `"${assistant.name}" could not be added to your list.`, @@ -359,7 +360,7 @@ export function AssistantsList() { message: `"${deletingPersona.name}" has been deleted.`, type: "success", }); - router.refresh(); + await refreshUser(); } else { setPopup({ message: `"${deletingPersona.name}" could not be deleted.`, @@ -380,7 +381,7 @@ export function AssistantsList() { makePublicPersona.id, newPublicStatus ); - router.refresh(); + await refreshAssistants(); }} /> )} diff --git a/web/src/app/assistants/mine/page.tsx b/web/src/app/assistants/mine/page.tsx index 0a27de835..b9c20bfd4 100644 --- a/web/src/app/assistants/mine/page.tsx +++ b/web/src/app/assistants/mine/page.tsx @@ -27,10 +27,16 @@ export default async function GalleryPage({ openedFolders, shouldShowWelcomeModal, toggleSidebar, + hasAnyConnectors, + hasImageCompatibleModel, } = data; return ( - + {shouldShowWelcomeModal && } diff --git a/web/src/app/chat/modal/configuration/AssistantsTab.tsx b/web/src/app/chat/modal/configuration/AssistantsTab.tsx index ef62d226c..70c64d4de 100644 --- a/web/src/app/chat/modal/configuration/AssistantsTab.tsx +++ b/web/src/app/chat/modal/configuration/AssistantsTab.tsx @@ -35,6 +35,7 @@ export function AssistantsTab({ const [_, llmName] = getFinalLLM(llmProviders, null, null); const { finalAssistants, refreshAssistants } = useAssistants(); const [assistants, setAssistants] = useState(finalAssistants); + console.log(finalAssistants); useEffect(() => { setAssistants(finalAssistants); diff --git a/web/src/app/chat/page.tsx b/web/src/app/chat/page.tsx index 3780cc331..b86cd29b3 100644 --- a/web/src/app/chat/page.tsx +++ b/web/src/app/chat/page.tsx @@ -34,13 +34,19 @@ export default async function Page({ shouldShowWelcomeModal, assistants, userInputPrompts, + hasAnyConnectors, + hasImageCompatibleModel, } = data; return ( <> {shouldShowWelcomeModal && } - + {shouldShowWelcomeModal && } - {shouldDisplayNoSourcesModal && } - {shouldDisplaySourcesIncompleteModal && ( )} - {/* ChatPopup is a custom popup that displays a admin-specified message on initial user visit. Only used in the EE version of the app. */} - - - - + + + + + s ); } diff --git a/web/src/components/chat_search/Notification.tsx b/web/src/components/chat_search/Notification.tsx index ab4405013..6e896800d 100644 --- a/web/src/components/chat_search/Notification.tsx +++ b/web/src/components/chat_search/Notification.tsx @@ -10,6 +10,7 @@ import { AssistantIcon } from "@/components/assistants/AssistantIcon"; import { addAssistantToList } from "@/lib/assistants/updateAssistantPreferences"; import { useAssistants } from "../context/AssisantsContext"; import { useUser } from "../user/UserProvider"; +import { Bell } from "@phosphor-icons/react"; export const NotificationCard = () => { const [showDropdown, setShowDropdown] = useState(false); @@ -118,18 +119,12 @@ export const NotificationCard = () => { }, [showDropdown]); return ( -
+
setShowDropdown(!showDropdown)} className="cursor-pointer relative notification-dropdown" > - - - + {sortedNotifications.length > 0 && ( )} diff --git a/web/src/components/context/AssisantsContext.tsx b/web/src/components/context/AssisantsContext.tsx index 52b698115..30503a29c 100644 --- a/web/src/components/context/AssisantsContext.tsx +++ b/web/src/components/context/AssisantsContext.tsx @@ -24,7 +24,14 @@ const AssistantsContext = createContext( export const AssistantsProvider: React.FC<{ children: React.ReactNode; initialAssistants: Persona[]; -}> = ({ children, initialAssistants }) => { + hasAnyConnectors: boolean; + hasImageCompatibleModel: boolean; +}> = ({ + children, + initialAssistants, + hasAnyConnectors, + hasImageCompatibleModel, +}) => { const [assistants, setAssistants] = useState( initialAssistants || [] ); @@ -39,7 +46,20 @@ export const AssistantsProvider: React.FC<{ }, }); if (!response.ok) throw new Error("Failed to fetch assistants"); - const assistants = await response.json(); + let assistants: Persona[] = await response.json(); + if (!hasImageCompatibleModel) { + assistants = assistants.filter( + (assistant) => + !assistant.tools.some( + (tool) => tool.in_code_tool_id === "ImageGenerationTool" + ) + ); + } + if (!hasAnyConnectors) { + assistants = assistants.filter( + (assistant) => assistant.num_chunks === 0 + ); + } setAssistants(assistants); } catch (error) { console.error("Error refreshing assistants:", error); @@ -56,9 +76,11 @@ export const AssistantsProvider: React.FC<{ user, assistants ); + const finalAssistants = user ? orderAssistantsForUser(visibleAssistants, user) : visibleAssistants; + const ownedButHiddenAssistants = getUserCreatedAssistants( user, hiddenAssistants diff --git a/web/src/lib/chat/fetchChatData.ts b/web/src/lib/chat/fetchChatData.ts index 82b10887d..8c2f0fb5a 100644 --- a/web/src/lib/chat/fetchChatData.ts +++ b/web/src/lib/chat/fetchChatData.ts @@ -47,6 +47,8 @@ interface FetchChatDataResult { finalDocumentSidebarInitialWidth?: number; shouldShowWelcomeModal: boolean; userInputPrompts: InputPrompt[]; + hasAnyConnectors: boolean; + hasImageCompatibleModel: boolean; } export async function fetchChatData(searchParams: { @@ -251,5 +253,7 @@ export async function fetchChatData(searchParams: { toggleSidebar, shouldShowWelcomeModal, userInputPrompts, + hasAnyConnectors, + hasImageCompatibleModel, }; }