diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 4b74dabc..0acc62f3 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -16,11 +16,12 @@ import { MessageWithFiles } from "./utils/formTypes.ts"; import { useNavigate } from "react-router-dom"; import { useThreadAndAssistant } from "./hooks/useThreadAndAssistant.ts"; import { Message } from "./types.ts"; +import { OrphanChat } from "./components/OrphanChat.tsx"; function App(props: { edit?: boolean }) { const navigate = useNavigate(); const [sidebarOpen, setSidebarOpen] = useState(false); - const { chats, createChat, deleteChat } = useChatList(); + const { chats, createChat, updateChat, deleteChat } = useChatList(); const { configs, saveConfig, deleteConfig } = useConfigList(); const { startStream, stopStream, stream } = useStreamState(); const { configSchema, configDefaults } = useSchemas(); @@ -145,6 +146,9 @@ function App(props: { edit?: boolean }) { {currentChat && assistantConfig && ( )} + {currentChat && !assistantConfig && ( + + )} {!currentChat && assistantConfig && !props.edit && ( Promise; +}) { + const [newConfigId, setNewConfigId] = useState(null as string | null); + const [configs, setConfigs] = useState([]); + const { invalidateChat } = useThreadAndAssistant(); + + const update = async () => { + if (!newConfigId) { + alert("Please select a bot."); + return; + } + const updatedChat = await props.updateChat( + props.chat.thread_id, + props.chat.name, + newConfigId, + ); + invalidateChat(updatedChat.thread_id); + }; + + const botTypeToName = (botType: string) => { + switch (botType) { + case "chatbot": + return "Chatbot"; + case "chat_retrieval": + return "RAG"; + case "agent": + return "Assistant"; + default: + return botType; + } + }; + + useEffect(() => { + async function fetchConfigs() { + const configs = await getAssistants(); + const suitableConfigs = configs + ? configs.filter( + (config) => + config.config.configurable?.type === + props.chat.metadata?.assistant_type, + ) + : []; + setConfigs(suitableConfigs); + } + + fetchConfigs(); + }, [props.chat.metadata?.assistant_type]); + + return ( +
+ {configs.length ? ( +
{ + e.preventDefault(); + await update(); + }} + className="space-y-4 max-w-xl w-full px-4" + > +
+ This chat has no bot attached. To continue chatting, please attach a + bot. +
+
+
+ +
+ +
+
+ ) : ( +
+
+ This chat has no bot attached. To continue chatting, you need to + attach a bot. However, there are no suitable bots available for this + chat. Please create a new bot with type{" "} + {botTypeToName(props.chat.metadata?.assistant_type as string)} and + try again. +
+
+ )} +
+ ); +}