{history.length === 0 ? (
diff --git a/frontend/app/chat/[chatId]/components/index.ts b/frontend/app/chat/[chatId]/components/index.ts
index 7a175bc6b..5f101f5d9 100644
--- a/frontend/app/chat/[chatId]/components/index.ts
+++ b/frontend/app/chat/[chatId]/components/index.ts
@@ -1,3 +1,2 @@
export * from "./ChatInput";
export * from "./ChatMessages";
-export * from "./ChatMessages/components/ChatMessage/components/ChatMessage";
diff --git a/frontend/app/chat/[chatId]/hooks/useChat.ts b/frontend/app/chat/[chatId]/hooks/useChat.ts
index e326eb907..902b62eb8 100644
--- a/frontend/app/chat/[chatId]/hooks/useChat.ts
+++ b/frontend/app/chat/[chatId]/hooks/useChat.ts
@@ -4,11 +4,11 @@ import { useParams } from "next/navigation";
import { useEffect, useState } from "react";
import { useBrainConfig } from "@/lib/context/BrainConfigProvider/hooks/useBrainConfig";
+import { useChatContext } from "@/lib/context/ChatProvider/hooks/useChatContext";
import { useToast } from "@/lib/hooks";
import { useEventTracking } from "@/services/analytics/useEventTracking";
import { useChatService } from "./useChatService";
-import { useChatContext } from "../../../../lib/context/ChatProvider";
import { ChatQuestion } from "../types";
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
diff --git a/frontend/app/chat/[chatId]/hooks/useChatService.ts b/frontend/app/chat/[chatId]/hooks/useChatService.ts
index acd2a2959..7107b7bb8 100644
--- a/frontend/app/chat/[chatId]/hooks/useChatService.ts
+++ b/frontend/app/chat/[chatId]/hooks/useChatService.ts
@@ -3,9 +3,9 @@
import { useCallback } from "react";
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";
+import { useChatContext } from "@/lib/context/ChatProvider/hooks/useChatContext";
import { useAxios, useFetch } from "@/lib/hooks";
-import { useChatContext } from "../../../../lib/context/ChatProvider";
import { ChatEntity, ChatHistory, ChatQuestion } from "../types";
interface UseChatService {
diff --git a/frontend/app/chat/[chatId]/page.tsx b/frontend/app/chat/[chatId]/page.tsx
index cdaffcecf..5d7243737 100644
--- a/frontend/app/chat/[chatId]/page.tsx
+++ b/frontend/app/chat/[chatId]/page.tsx
@@ -1,14 +1,13 @@
-/* eslint-disable */
"use client";
import PageHeading from "@/lib/components/ui/PageHeading";
+import { ChatProvider } from "@/lib/context/ChatProvider";
-import { ChatProvider } from "../../../lib/context/ChatProvider";
import { ChatInput, ChatMessages } from "./components";
-export default function ChatPage() {
+const ChatPage = (): JSX.Element => {
return (
-
+
);
-}
+};
+
+export default ChatPage;
diff --git a/frontend/app/chat/components/ChatsList/index.tsx b/frontend/app/chat/components/ChatsList/index.tsx
index 4e4c7596e..6a816f4af 100644
--- a/frontend/app/chat/components/ChatsList/index.tsx
+++ b/frontend/app/chat/components/ChatsList/index.tsx
@@ -1,9 +1,9 @@
-/* eslint-disable */
"use client";
+import { motion, MotionConfig } from "framer-motion";
+import { MdChevronRight } from "react-icons/md";
+
import { useChatsContext } from "@/lib/context/ChatsProvider/hooks/useChatsContext";
import { cn } from "@/lib/utils";
-import { MotionConfig, motion } from "framer-motion";
-import { MdChevronRight } from "react-icons/md";
import { ChatsListItem } from "./components/ChatsListItem";
import { MiniFooter } from "./components/ChatsListItem/components/MiniFooter";
@@ -13,6 +13,7 @@ import { useChatsList } from "./hooks/useChatsList";
export const ChatsList = (): JSX.Element => {
const { allChats, deleteChat } = useChatsContext();
const { open, setOpen } = useChatsList();
+
return (
{
))}
diff --git a/frontend/app/layout.tsx b/frontend/app/layout.tsx
index 5ca1e2e4c..9ac28da53 100644
--- a/frontend/app/layout.tsx
+++ b/frontend/app/layout.tsx
@@ -7,8 +7,8 @@ import Footer from "@/lib/components/Footer";
import { NavBar } from "@/lib/components/NavBar";
import { TrackingWrapper } from "@/lib/components/TrackingWrapper";
import { ToastProvider } from "@/lib/components/ui/Toast";
-import { BrainProvider } from "@/lib/context";
-import { BrainConfigProvider } from "@/lib/context/BrainConfigProvider/brain-config-provider";
+import { BrainConfigProvider } from "@/lib/context/BrainConfigProvider";
+import { BrainProvider } from "@/lib/context/BrainProvider";
import { SupabaseProvider } from "@/lib/context/SupabaseProvider";
import "./globals.css";
diff --git a/frontend/lib/context/BrainConfigProvider/brain-config-provider.tsx b/frontend/lib/context/BrainConfigProvider/brain-config-provider.tsx
index 41f3f285b..d6f0fac89 100644
--- a/frontend/lib/context/BrainConfigProvider/brain-config-provider.tsx
+++ b/frontend/lib/context/BrainConfigProvider/brain-config-provider.tsx
@@ -9,11 +9,11 @@ import {
getBrainConfigFromLocalStorage,
saveBrainConfigInLocalStorage,
} from "./helpers/brainConfigLocalStorage";
-import { BrainConfig, ConfigContext } from "./types";
+import { BrainConfig, BrainConfigContextType } from "./types";
-export const BrainConfigContext = createContext(
- undefined
-);
+export const BrainConfigContext = createContext<
+ BrainConfigContextType | undefined
+>(undefined);
const defaultBrainConfig: BrainConfig = {
model: "gpt-3.5-turbo-0613",
diff --git a/frontend/lib/context/BrainConfigProvider/hooks/useBrainConfig.ts b/frontend/lib/context/BrainConfigProvider/hooks/useBrainConfig.ts
index 3b5dfb13b..3fc38fa61 100644
--- a/frontend/lib/context/BrainConfigProvider/hooks/useBrainConfig.ts
+++ b/frontend/lib/context/BrainConfigProvider/hooks/useBrainConfig.ts
@@ -7,7 +7,7 @@ export const useBrainConfig = () => {
const context = useContext(BrainConfigContext);
if (context === undefined) {
- throw new Error("useConfig must be used inside SupabaseProvider");
+ throw new Error("useBrainConfig must be used inside BrainConfigProvider");
}
return context;
diff --git a/frontend/lib/context/BrainConfigProvider/index.ts b/frontend/lib/context/BrainConfigProvider/index.ts
new file mode 100644
index 000000000..b2ca684d5
--- /dev/null
+++ b/frontend/lib/context/BrainConfigProvider/index.ts
@@ -0,0 +1 @@
+export * from "./brain-config-provider";
diff --git a/frontend/lib/context/BrainConfigProvider/mocks/BrainConfigProviderMock.tsx b/frontend/lib/context/BrainConfigProvider/mocks/BrainConfigProviderMock.tsx
new file mode 100644
index 000000000..34a26ecfe
--- /dev/null
+++ b/frontend/lib/context/BrainConfigProvider/mocks/BrainConfigProviderMock.tsx
@@ -0,0 +1,28 @@
+import { createContext, PropsWithChildren } from "react";
+
+import { BrainConfigContextType } from "../types";
+
+export const BrainConfigContextMock = createContext<
+ BrainConfigContextType | undefined
+>(undefined);
+
+export const BrainConfigProviderMock = ({
+ children,
+}: PropsWithChildren): JSX.Element => {
+ return (
+ void 0,
+ resetConfig: () => void 0,
+ }}
+ >
+ {children}
+
+ );
+};
diff --git a/frontend/lib/context/BrainConfigProvider/types.ts b/frontend/lib/context/BrainConfigProvider/types.ts
index 45548bdd5..28d8ee304 100644
--- a/frontend/lib/context/BrainConfigProvider/types.ts
+++ b/frontend/lib/context/BrainConfigProvider/types.ts
@@ -12,7 +12,7 @@ export type BrainConfig = {
type OptionalConfig = { [K in keyof BrainConfig]?: BrainConfig[K] | undefined };
-export type ConfigContext = {
+export type BrainConfigContextType = {
config: BrainConfig;
updateConfig: (config: OptionalConfig) => void;
resetConfig: () => void;
diff --git a/frontend/lib/context/BrainProvider/brain-provider.tsx b/frontend/lib/context/BrainProvider/brain-provider.tsx
index d14267df0..a858f4170 100644
--- a/frontend/lib/context/BrainProvider/brain-provider.tsx
+++ b/frontend/lib/context/BrainProvider/brain-provider.tsx
@@ -1,7 +1,13 @@
"use client";
-import { BrainContext } from "./hooks/useBrainContext";
+import { createContext } from "react";
+
import { useBrainState } from "./hooks/useBrainState";
+import { BrainContextType } from "./types";
+
+export const BrainContext = createContext(
+ undefined
+);
export const BrainProvider = ({
children,
diff --git a/frontend/lib/context/BrainProvider/hooks/useBrainContext.ts b/frontend/lib/context/BrainProvider/hooks/useBrainContext.ts
index 76b271d51..0f02c28d6 100644
--- a/frontend/lib/context/BrainProvider/hooks/useBrainContext.ts
+++ b/frontend/lib/context/BrainProvider/hooks/useBrainContext.ts
@@ -1,9 +1,7 @@
-import { createContext, useContext } from "react";
+import { useContext } from "react";
import { BrainStateProps } from "./useBrainState";
-import { ScopeContext } from "../types";
-
-export const BrainContext = createContext(undefined);
+import { BrainContext } from "../brain-provider";
export const useBrainContext = (): BrainStateProps => {
const context = useContext(BrainContext);
diff --git a/frontend/lib/context/BrainProvider/mocks/BrainProviderMock.tsx b/frontend/lib/context/BrainProvider/mocks/BrainProviderMock.tsx
new file mode 100644
index 000000000..499f1a958
--- /dev/null
+++ b/frontend/lib/context/BrainProvider/mocks/BrainProviderMock.tsx
@@ -0,0 +1,36 @@
+import { createContext, PropsWithChildren } from "react";
+
+import { BrainContextType } from "../types";
+
+export const BrainContextMock = createContext(
+ undefined
+);
+
+export const BrainProviderMock = ({
+ children,
+}: PropsWithChildren): JSX.Element => {
+ return (
+ void 0,
+ //@ts-ignore we are not using the functions in tests
+ deleteBrain: () => void 0,
+ //@ts-ignore we are not using the functions in tests
+ currentBrainId: undefined,
+ //@ts-ignore we are not using the functions in tests
+ fetchAllBrains: () => void 0,
+ //@ts-ignore we are not using the functions in tests
+ getBrainWithId: () => void 0,
+ //@ts-ignore we are not using the functions in tests
+ setActiveBrain: () => void 0,
+ //@ts-ignore we are not using the functions in tests
+ setDefaultBrain: () => void 0,
+ }}
+ >
+ {children}
+
+ );
+};
diff --git a/frontend/lib/context/BrainProvider/types.ts b/frontend/lib/context/BrainProvider/types.ts
index 4cc6f51a3..ce30d003d 100644
--- a/frontend/lib/context/BrainProvider/types.ts
+++ b/frontend/lib/context/BrainProvider/types.ts
@@ -14,4 +14,4 @@ export type Brain = {
temperature?: string;
};
-export type ScopeContext = ReturnType;
+export type BrainContextType = ReturnType;
diff --git a/frontend/lib/context/ChatProvider.tsx b/frontend/lib/context/ChatProvider/ChatProvider.tsx
similarity index 69%
rename from frontend/lib/context/ChatProvider.tsx
rename to frontend/lib/context/ChatProvider/ChatProvider.tsx
index 3b771a6b2..99a38d147 100644
--- a/frontend/lib/context/ChatProvider.tsx
+++ b/frontend/lib/context/ChatProvider/ChatProvider.tsx
@@ -1,16 +1,10 @@
"use client";
-import { createContext, useContext, useState } from "react";
+import { createContext, useState } from "react";
-import { ChatHistory } from "../../app/chat/[chatId]/types";
+import { ChatHistory } from "@/app/chat/[chatId]/types";
-type ChatContextProps = {
- history: ChatHistory[];
- setHistory: (history: ChatHistory[]) => void;
- addToHistory: (message: ChatHistory) => void;
- updateHistory: (chat: ChatHistory) => void;
- updateStreamingHistory: (streamedChat: ChatHistory) => void;
-};
+import { ChatContextProps } from "./types";
export const ChatContext = createContext(
undefined
@@ -29,7 +23,6 @@ export const ChatProvider = ({
const updateStreamingHistory = (streamedChat: ChatHistory): void => {
setHistory((prevHistory: ChatHistory[]) => {
- console.log("new chat", streamedChat);
const updatedHistory = prevHistory.find(
(item) => item.message_id === streamedChat.message_id
)
@@ -40,8 +33,6 @@ export const ChatProvider = ({
)
: [...prevHistory, streamedChat];
- console.log("updated history", updatedHistory);
-
return updatedHistory;
});
};
@@ -76,13 +67,3 @@ export const ChatProvider = ({
);
};
-
-export const useChatContext = (): ChatContextProps => {
- const context = useContext(ChatContext);
-
- if (context === undefined) {
- throw new Error("useChatContext must be used inside ChatProvider");
- }
-
- return context;
-};
diff --git a/frontend/lib/context/ChatProvider/hooks/useChatContext.ts b/frontend/lib/context/ChatProvider/hooks/useChatContext.ts
new file mode 100644
index 000000000..160f2173b
--- /dev/null
+++ b/frontend/lib/context/ChatProvider/hooks/useChatContext.ts
@@ -0,0 +1,14 @@
+import { useContext } from "react";
+
+import { ChatContext } from "../ChatProvider";
+import { ChatContextProps } from "../types";
+
+export const useChatContext = (): ChatContextProps => {
+ const context = useContext(ChatContext);
+
+ if (context === undefined) {
+ throw new Error("useChatContext must be used inside ChatProvider");
+ }
+
+ return context;
+};
diff --git a/frontend/lib/context/ChatProvider/index.ts b/frontend/lib/context/ChatProvider/index.ts
new file mode 100644
index 000000000..143eb5fe3
--- /dev/null
+++ b/frontend/lib/context/ChatProvider/index.ts
@@ -0,0 +1,2 @@
+export * from "./ChatProvider";
+export * from "./hooks/useChatContext";
diff --git a/frontend/lib/context/ChatProvider/mocks/ChatProviderMock.tsx b/frontend/lib/context/ChatProvider/mocks/ChatProviderMock.tsx
new file mode 100644
index 000000000..bbfe8d750
--- /dev/null
+++ b/frontend/lib/context/ChatProvider/mocks/ChatProviderMock.tsx
@@ -0,0 +1,25 @@
+import { createContext, PropsWithChildren } from "react";
+
+import { ChatContextProps } from "../types";
+
+export const ChatContextMock = createContext(
+ undefined
+);
+
+export const ChatProviderMock = ({
+ children,
+}: PropsWithChildren): JSX.Element => {
+ return (
+ void 0,
+ addToHistory: () => void 0,
+ updateHistory: () => void 0,
+ updateStreamingHistory: () => void 0,
+ }}
+ >
+ {children}
+
+ );
+};
diff --git a/frontend/lib/context/ChatProvider/types.ts b/frontend/lib/context/ChatProvider/types.ts
new file mode 100644
index 000000000..16740f0d9
--- /dev/null
+++ b/frontend/lib/context/ChatProvider/types.ts
@@ -0,0 +1,9 @@
+import { ChatHistory } from "@/app/chat/[chatId]/types";
+
+export type ChatContextProps = {
+ history: ChatHistory[];
+ setHistory: (history: ChatHistory[]) => void;
+ addToHistory: (message: ChatHistory) => void;
+ updateHistory: (chat: ChatHistory) => void;
+ updateStreamingHistory: (streamedChat: ChatHistory) => void;
+};
diff --git a/frontend/lib/context/ChatsProvider/hooks/useChatsContext.tsx b/frontend/lib/context/ChatsProvider/hooks/useChatsContext.tsx
index 596ce1058..d2a569e36 100644
--- a/frontend/lib/context/ChatsProvider/hooks/useChatsContext.tsx
+++ b/frontend/lib/context/ChatsProvider/hooks/useChatsContext.tsx
@@ -1,8 +1,8 @@
-/* eslint-disable */
import { useContext } from "react";
import { ChatsContext } from "../chats-provider";
+// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const useChatsContext = () => {
const context = useContext(ChatsContext);
diff --git a/frontend/lib/context/ChatsProvider/index.ts b/frontend/lib/context/ChatsProvider/index.ts
new file mode 100644
index 000000000..7fef2716c
--- /dev/null
+++ b/frontend/lib/context/ChatsProvider/index.ts
@@ -0,0 +1 @@
+export * from "./chats-provider";
diff --git a/frontend/lib/context/SupabaseProvider/hooks/useSupabase.ts b/frontend/lib/context/SupabaseProvider/hooks/useSupabase.ts
new file mode 100644
index 000000000..78f06f461
--- /dev/null
+++ b/frontend/lib/context/SupabaseProvider/hooks/useSupabase.ts
@@ -0,0 +1,14 @@
+import { useContext } from "react";
+
+import { SupabaseContext } from "../supabase-provider";
+import { SupabaseContextType } from "../types";
+
+export const useSupabase = (): SupabaseContextType => {
+ const context = useContext(SupabaseContext);
+
+ if (context === undefined) {
+ throw new Error("useSupabase must be used inside SupabaseProvider");
+ }
+
+ return context;
+};
diff --git a/frontend/lib/context/SupabaseProvider/index.ts b/frontend/lib/context/SupabaseProvider/index.ts
index a141d20b1..d4e02357b 100644
--- a/frontend/lib/context/SupabaseProvider/index.ts
+++ b/frontend/lib/context/SupabaseProvider/index.ts
@@ -1 +1,2 @@
+export * from "./hooks/useSupabase";
export * from "./supabase-provider";
diff --git a/frontend/lib/context/SupabaseProvider/mocks/SupabaseProviderMock.tsx b/frontend/lib/context/SupabaseProvider/mocks/SupabaseProviderMock.tsx
new file mode 100644
index 000000000..2e35c746c
--- /dev/null
+++ b/frontend/lib/context/SupabaseProvider/mocks/SupabaseProviderMock.tsx
@@ -0,0 +1,24 @@
+import { createContext, PropsWithChildren } from "react";
+
+import { SupabaseContextType } from "../types";
+
+export const SupabaseContextMock = createContext<
+ SupabaseContextType | undefined
+>(undefined);
+
+export const SupabaseProviderMock = ({
+ children,
+}: PropsWithChildren): JSX.Element => {
+ return (
+
+ {children}
+
+ );
+};
diff --git a/frontend/lib/context/SupabaseProvider/supabase-provider.tsx b/frontend/lib/context/SupabaseProvider/supabase-provider.tsx
index 26f992bcb..7a9e217eb 100644
--- a/frontend/lib/context/SupabaseProvider/supabase-provider.tsx
+++ b/frontend/lib/context/SupabaseProvider/supabase-provider.tsx
@@ -1,28 +1,24 @@
"use client";
-import type { SupabaseClient } from "@supabase/auth-helpers-nextjs";
import {
createBrowserSupabaseClient,
Session,
} from "@supabase/auth-helpers-nextjs";
import { useRouter } from "next/navigation";
-import { createContext, useContext, useEffect, useState } from "react";
+import { createContext, useEffect, useState } from "react";
-type MaybeSession = Session | null;
+import { SupabaseContextType } from "./types";
-export type SupabaseContext = {
- supabase: SupabaseClient;
- session: MaybeSession;
-};
-
-const Context = createContext(undefined);
+export const SupabaseContext = createContext(
+ undefined
+);
export const SupabaseProvider = ({
children,
session,
}: {
children: React.ReactNode;
- session: MaybeSession;
+ session: Session | null;
}): JSX.Element => {
const [supabase] = useState(() => createBrowserSupabaseClient());
const router = useRouter();
@@ -40,18 +36,8 @@ export const SupabaseProvider = ({
}, [router, supabase]);
return (
-
+
<>{children}>
-
+
);
};
-
-export const useSupabase = (): SupabaseContext => {
- const context = useContext(Context);
-
- if (context === undefined) {
- throw new Error("useSupabase must be used inside SupabaseProvider");
- }
-
- return context;
-};
diff --git a/frontend/lib/context/SupabaseProvider/types.ts b/frontend/lib/context/SupabaseProvider/types.ts
new file mode 100644
index 000000000..3f45bbb1e
--- /dev/null
+++ b/frontend/lib/context/SupabaseProvider/types.ts
@@ -0,0 +1,6 @@
+import { Session, SupabaseClient } from "@supabase/auth-helpers-nextjs";
+
+export type SupabaseContextType = {
+ supabase: SupabaseClient;
+ session: Session | null;
+};
diff --git a/frontend/lib/hooks/useAxios.ts b/frontend/lib/hooks/useAxios.ts
index 50b8c1b4f..0d373ce1a 100644
--- a/frontend/lib/hooks/useAxios.ts
+++ b/frontend/lib/hooks/useAxios.ts
@@ -1,7 +1,7 @@
import axios, { AxiosError, AxiosInstance } from "axios";
-import { useBrainConfig } from "../context/BrainConfigProvider/hooks/useBrainConfig";
-import { useSupabase } from "../context/SupabaseProvider";
+import { useBrainConfig } from "@/lib/context/BrainConfigProvider/hooks/useBrainConfig";
+import { useSupabase } from "@/lib/context/SupabaseProvider";
const axiosInstance = axios.create({
baseURL: `${process.env.NEXT_PUBLIC_BACKEND_URL ?? ""}`,
diff --git a/frontend/lib/hooks/useFetch.ts b/frontend/lib/hooks/useFetch.ts
index e2cea39d9..cb9f76aa9 100644
--- a/frontend/lib/hooks/useFetch.ts
+++ b/frontend/lib/hooks/useFetch.ts
@@ -1,7 +1,8 @@
import { useEffect, useState } from "react";
+import { useSupabase } from "@/lib/context/SupabaseProvider";
+
import { useBrainConfig } from "../context/BrainConfigProvider/hooks/useBrainConfig";
-import { useSupabase } from "../context/SupabaseProvider";
interface FetchInstance {
get: (url: string, headers?: HeadersInit) => Promise;