From bb7b7170cad22adda0277cde09c3de9ae8417d9f Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Sat, 27 Dec 2025 20:03:34 +0530 Subject: [PATCH] feat(media, suggestions): handle chat history correctly --- src/app/api/images/route.ts | 5 ++++- src/app/api/suggestions/route.ts | 5 ++++- src/app/api/videos/route.ts | 5 ++++- src/components/MessageBox.tsx | 13 ++++++++++--- src/components/SearchImages.tsx | 2 +- src/components/SearchVideos.tsx | 2 +- 6 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/app/api/images/route.ts b/src/app/api/images/route.ts index 9cfabb2..ab7dffb 100644 --- a/src/app/api/images/route.ts +++ b/src/app/api/images/route.ts @@ -21,7 +21,10 @@ export const POST = async (req: Request) => { const images = await searchImages( { - chatHistory: body.chatHistory, + chatHistory: body.chatHistory.map(([role, content]) => ({ + role: role === 'human' ? 'user' : 'assistant', + content, + })), query: body.query, }, llm, diff --git a/src/app/api/suggestions/route.ts b/src/app/api/suggestions/route.ts index 07432d6..0f4587c 100644 --- a/src/app/api/suggestions/route.ts +++ b/src/app/api/suggestions/route.ts @@ -20,7 +20,10 @@ export const POST = async (req: Request) => { const suggestions = await generateSuggestions( { - chatHistory: body.chatHistory, + chatHistory: body.chatHistory.map(([role, content]) => ({ + role: role === 'human' ? 'user' : 'assistant', + content, + })), }, llm, ); diff --git a/src/app/api/videos/route.ts b/src/app/api/videos/route.ts index 0d5e03c..7bbf59a 100644 --- a/src/app/api/videos/route.ts +++ b/src/app/api/videos/route.ts @@ -21,7 +21,10 @@ export const POST = async (req: Request) => { const videos = await handleVideoSearch( { - chatHistory: body.chatHistory, + chatHistory: body.chatHistory.map(([role, content]) => ({ + role: role === 'human' ? 'user' : 'assistant', + content, + })), query: body.query, }, llm, diff --git a/src/components/MessageBox.tsx b/src/components/MessageBox.tsx index 19e3546..dd60dec 100644 --- a/src/components/MessageBox.tsx +++ b/src/components/MessageBox.tsx @@ -50,7 +50,14 @@ const MessageBox = ({ dividerRef?: MutableRefObject; isLast: boolean; }) => { - const { loading, sendMessage, rewrite, messages, researchEnded } = useChat(); + const { + loading, + sendMessage, + rewrite, + messages, + researchEnded, + chatHistory, + } = useChat(); const parsedMessage = section.parsedTextBlocks.join('\n\n'); const speechMessage = section.speechMessage || ''; @@ -265,11 +272,11 @@ const MessageBox = ({
diff --git a/src/components/SearchImages.tsx b/src/components/SearchImages.tsx index ca4d477..d393335 100644 --- a/src/components/SearchImages.tsx +++ b/src/components/SearchImages.tsx @@ -17,7 +17,7 @@ const SearchImages = ({ messageId, }: { query: string; - chatHistory: Message[]; + chatHistory: [string, string][]; messageId: string; }) => { const [images, setImages] = useState(null); diff --git a/src/components/SearchVideos.tsx b/src/components/SearchVideos.tsx index 4084383..63b4ed8 100644 --- a/src/components/SearchVideos.tsx +++ b/src/components/SearchVideos.tsx @@ -30,7 +30,7 @@ const Searchvideos = ({ messageId, }: { query: string; - chatHistory: Message[]; + chatHistory: [string, string][]; messageId: string; }) => { const [videos, setVideos] = useState(null);