diff --git a/src/frontend/src/modals/chatModal/chatMessage/index.tsx b/src/frontend/src/modals/chatModal/chatMessage/index.tsx index d960a149b..a41e59523 100644 --- a/src/frontend/src/modals/chatModal/chatMessage/index.tsx +++ b/src/frontend/src/modals/chatModal/chatMessage/index.tsx @@ -1,11 +1,10 @@ -import { - ChatBubbleOvalLeftEllipsisIcon, -} from "@heroicons/react/24/outline"; +import { ChatBubbleOvalLeftEllipsisIcon } from "@heroicons/react/24/outline"; import { useState } from "react"; import { ChatMessageType } from "../../../types/chat"; import { classNames } from "../../../utils"; -import AiIcon from "../../../assets/Gooey Ring-5s-271px.svg" +import AiIcon from "../../../assets/Gooey Ring-5s-271px.svg"; import { UserIcon } from "@heroicons/react/24/solid"; +import FileCard from "../fileComponent"; var Convert = require("ansi-to-html"); var convert = new Convert({ newline: true }); @@ -20,17 +19,16 @@ export default function ChatMessage({ chat }: { chat: ChatMessageType }) { >
- {!chat.isSend && } - {chat.isSend && } + {!chat.isSend && } + {chat.isSend && }
{!chat.isSend ? (
-
+
{hidden && chat.thought && chat.thought !== "" && (
setHidden((prev) => !prev)} @@ -42,17 +40,29 @@ export default function ChatMessage({ chat }: { chat: ChatMessageType }) { {chat.thought && chat.thought !== "" && !hidden && (
setHidden((prev) => !prev)} - className=" text-start inline-block w-full pb-3 pt-3 px-5 cursor-pointer" + className=" text-start inline-block rounded-md h-full + bg-white w-[95%] pb-3 pt-3 px-2 ml-3 cursor-pointer scrollbar-hide overflow-scroll" dangerouslySetInnerHTML={{ __html: convert.toHtml(chat.thought), }} >
)} {chat.thought && chat.thought !== "" && !hidden &&

} -
- {chat.message} +
+ {chat.file ? ( +
+ ) : ( + + {chat.message} +
+ +
+
+ )}
diff --git a/src/frontend/src/modals/chatModal/fileComponent/index.tsx b/src/frontend/src/modals/chatModal/fileComponent/index.tsx new file mode 100644 index 000000000..bfd5d0571 --- /dev/null +++ b/src/frontend/src/modals/chatModal/fileComponent/index.tsx @@ -0,0 +1,34 @@ +import { ArrowDownTrayIcon, CloudArrowDownIcon, DocumentIcon } from "@heroicons/react/24/outline"; + +export default function FileCard({ fileName, content, fileType }) { + const handleDownload = () => { + const blob = new Blob([content], { type: "application/octet-stream" }); + const url = URL.createObjectURL(blob); + const link = document.createElement("a"); + link.href = url; + link.download = fileName; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + URL.revokeObjectURL(url); + }; + + return ( + + ); +} diff --git a/src/frontend/src/modals/chatModal/index.tsx b/src/frontend/src/modals/chatModal/index.tsx index d19bf37d5..6661dfaf1 100644 --- a/src/frontend/src/modals/chatModal/index.tsx +++ b/src/frontend/src/modals/chatModal/index.tsx @@ -34,11 +34,15 @@ export default function ChatModal({ const addChatHistory = ( message: string, isSend: boolean, - thought?: string + thought?: string, + file?:Blob ) => { setChatHistory((old) => { let newChat = _.cloneDeep(old); - if (thought) { + if(file){ + newChat.push({ message, isSend,file }); + } + else if (thought) { newChat.push({ message, isSend, thought }); } else { newChat.push({ message, isSend }); @@ -82,8 +86,11 @@ export default function ChatModal({ addChatHistory(data.message, false, data.intermediate_steps); setLockChat(false) } + if (data.type=="file"){ + } // Do something with the data received from the WebSocket }; + newWs.onclose=(e)=>{console.log(e.reason)} setWs(newWs); return () => { diff --git a/src/frontend/src/types/chat/index.ts b/src/frontend/src/types/chat/index.ts index dc0c25b15..148a81d8a 100644 --- a/src/frontend/src/types/chat/index.ts +++ b/src/frontend/src/types/chat/index.ts @@ -2,4 +2,4 @@ import { ReactFlowInstance } from 'reactflow'; import { FlowType } from "../flow"; export type ChatType = {flow:FlowType,reactFlowInstance:ReactFlowInstance} -export type ChatMessageType = { message: string; isSend: boolean, thought?:string } \ No newline at end of file +export type ChatMessageType = { message: string; isSend: boolean, thought?:string,file?:Blob } \ No newline at end of file