From 98e88e271509ab161b1bda580e53fc5a13eb8d0b Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Tue, 15 Oct 2024 10:26:01 -0700 Subject: [PATCH] ensure shared chats are shared (#2801) * ensure shared chats are shared * k * k * nit * k --- web/src/app/admin/assistants/lib.ts | 25 ++++++++++++++++++- web/src/app/chat/ChatPage.tsx | 7 ------ web/src/app/chat/message/Messages.tsx | 4 --- .../shared/[chatId]/SharedChatDisplay.tsx | 12 +++------ web/src/app/chat/shared/[chatId]/page.tsx | 13 ++++++---- .../chat_search/ProviderContext.tsx | 1 + 6 files changed, 37 insertions(+), 25 deletions(-) diff --git a/web/src/app/admin/assistants/lib.ts b/web/src/app/admin/assistants/lib.ts index 9b79ea7ef6c..9be6dbae834 100644 --- a/web/src/app/admin/assistants/lib.ts +++ b/web/src/app/admin/assistants/lib.ts @@ -1,5 +1,5 @@ import { FullLLMProvider } from "../configuration/llm/interfaces"; -import { Persona, Prompt, StarterMessage } from "./interfaces"; +import { Persona, StarterMessage } from "./interfaces"; interface PersonaCreationRequest { name: string; @@ -377,3 +377,26 @@ export function providersContainImageGeneratingSupport( ) { return providers.some((provider) => provider.provider === "openai"); } + +// Default fallback persona for when we must display a persona +// but assistant has access to none +export const defaultPersona: Persona = { + id: 0, + name: "Default Assistant", + description: "A default assistant", + is_visible: true, + is_public: true, + builtin_persona: false, + is_default_persona: true, + users: [], + groups: [], + document_sets: [], + prompts: [], + tools: [], + starter_messages: null, + display_priority: null, + search_start_date: null, + owner: null, + icon_shape: 50910, + icon_color: "#FF6F6F", +}; diff --git a/web/src/app/chat/ChatPage.tsx b/web/src/app/chat/ChatPage.tsx index 54432c40e3b..f218f7fab95 100644 --- a/web/src/app/chat/ChatPage.tsx +++ b/web/src/app/chat/ChatPage.tsx @@ -2185,7 +2185,6 @@ export function ChatPage({ query={ messageHistory[i]?.query || undefined } - personaName={liveAssistant.name} citedDocuments={getCitedDocumentsFromMessage( message )} @@ -2247,9 +2246,6 @@ export function ChatPage({ } : undefined } - isCurrentlyShowingRetrieved={ - isShowingRetrieved - } handleShowRetrieved={(messageNumber) => { if (isShowingRetrieved) { setSelectedMessageForDocDisplay(null); @@ -2299,7 +2295,6 @@ export function ChatPage({ {message.message} @@ -2347,7 +2342,6 @@ export function ChatPage({ alternativeAssistant } messageId={null} - personaName={liveAssistant.name} content={
{loadingError} diff --git a/web/src/app/chat/message/Messages.tsx b/web/src/app/chat/message/Messages.tsx index 56203cb06fc..56b917164df 100644 --- a/web/src/app/chat/message/Messages.tsx +++ b/web/src/app/chat/message/Messages.tsx @@ -124,13 +124,11 @@ export const AIMessage = ({ files, selectedDocuments, query, - personaName, citedDocuments, toolCall, isComplete, hasDocs, handleFeedback, - isCurrentlyShowingRetrieved, handleShowRetrieved, handleSearchQueryEdit, handleForceSearch, @@ -153,13 +151,11 @@ export const AIMessage = ({ content: string | JSX.Element; files?: FileDescriptor[]; query?: string; - personaName?: string; citedDocuments?: [string, DanswerDocument][] | null; toolCall?: ToolCallMetadata; isComplete?: boolean; hasDocs?: boolean; handleFeedback?: (feedbackType: FeedbackType) => void; - isCurrentlyShowingRetrieved?: boolean; handleShowRetrieved?: (messageNumber: number | null) => void; handleSearchQueryEdit?: (query: string) => void; handleForceSearch?: () => void; diff --git a/web/src/app/chat/shared/[chatId]/SharedChatDisplay.tsx b/web/src/app/chat/shared/[chatId]/SharedChatDisplay.tsx index 489163aa3c8..de2d443963f 100644 --- a/web/src/app/chat/shared/[chatId]/SharedChatDisplay.tsx +++ b/web/src/app/chat/shared/[chatId]/SharedChatDisplay.tsx @@ -11,10 +11,10 @@ import { import { AIMessage, HumanMessage } from "../../message/Messages"; import { Button, Callout, Divider } from "@tremor/react"; import { useRouter } from "next/navigation"; -import { Persona } from "@/app/admin/assistants/interfaces"; import { useContext, useEffect, useState } from "react"; import { SettingsContext } from "@/components/settings/SettingsProvider"; import { DanswerInitializingLoader } from "@/components/DanswerInitializingLoader"; +import { Persona } from "@/app/admin/assistants/interfaces"; function BackToDanswerButton() { const router = useRouter(); @@ -34,10 +34,10 @@ function BackToDanswerButton() { export function SharedChatDisplay({ chatSession, - availableAssistants, + persona, }: { chatSession: BackendChatSession | null; - availableAssistants: Persona[]; + persona: Persona; }) { const [isReady, setIsReady] = useState(false); useEffect(() => { @@ -56,9 +56,6 @@ export function SharedChatDisplay({
); } - const currentPersona = availableAssistants.find( - (persona) => persona.id === chatSession.persona_id - ); const messages = buildLatestMessageChain( processRawChatHistory(chatSession.messages) @@ -96,12 +93,11 @@ export function SharedChatDisplay({ return ( diff --git a/web/src/app/chat/shared/[chatId]/page.tsx b/web/src/app/chat/shared/[chatId]/page.tsx index 9e8ce58432e..d012b4a0d77 100644 --- a/web/src/app/chat/shared/[chatId]/page.tsx +++ b/web/src/app/chat/shared/[chatId]/page.tsx @@ -11,6 +11,7 @@ import { SharedChatDisplay } from "./SharedChatDisplay"; import { Persona } from "@/app/admin/assistants/interfaces"; import { fetchAssistantsSS } from "@/lib/assistants/fetchAssistantsSS"; import FunctionalHeader from "@/components/chat_search/Header"; +import { defaultPersona } from "@/app/admin/assistants/lib"; async function getSharedChat(chatId: string) { const response = await fetchSS( @@ -43,7 +44,7 @@ export default async function Page({ params }: { params: { chatId: string } }) { const authTypeMetadata = results[0] as AuthTypeMetadata | null; const user = results[1] as User | null; const chatSession = results[2] as BackendChatSession | null; - const [availableAssistants, _] = results[3] as [Persona[], string | null]; + const availableAssistants = results[3] as Persona[] | null; const authDisabled = authTypeMetadata?.authType === "disabled"; if (!authDisabled && !user) { @@ -53,6 +54,11 @@ export default async function Page({ params }: { params: { chatId: string } }) { if (user && !user.is_verified && authTypeMetadata?.requiresVerification) { return redirect("/auth/waiting-on-verification"); } + const persona = chatSession?.persona_id + ? (availableAssistants?.find((p) => p.id === chatSession.persona_id) ?? + availableAssistants?.[0] ?? + null) + : (availableAssistants?.[0] ?? defaultPersona); return (
@@ -61,10 +67,7 @@ export default async function Page({ params }: { params: { chatId: string } }) {
- +
); diff --git a/web/src/components/chat_search/ProviderContext.tsx b/web/src/components/chat_search/ProviderContext.tsx index 609713f874b..f0839373b8d 100644 --- a/web/src/components/chat_search/ProviderContext.tsx +++ b/web/src/components/chat_search/ProviderContext.tsx @@ -37,6 +37,7 @@ export function ProviderContextProvider({ const fetchProviderInfo = useCallback(async () => { const { providers, options, defaultCheckSuccessful } = await checkLlmProvider(user); + setValidProviderExists(providers.length > 0 && defaultCheckSuccessful); setProviderOptions(options); }, [user, setValidProviderExists, setProviderOptions]);