diff --git a/src/frontend/src/modals/chatModal/chatInput/index.tsx b/src/frontend/src/modals/chatModal/chatInput/index.tsx
deleted file mode 100644
index 69d382748..000000000
--- a/src/frontend/src/modals/chatModal/chatInput/index.tsx
+++ /dev/null
@@ -1,78 +0,0 @@
-import { classNames } from "../../../utils";
-import { useContext, useEffect, useRef, useState } from "react";
-import { TabsContext } from "../../../contexts/tabsContext";
-import { INPUT_STYLE } from "../../../constants";
-import { Lock, Send } from "lucide-react";
-
-export default function ChatInput({
- lockChat,
- chatValue,
- sendMessage,
- setChatValue,
- inputRef,
-}) {
- useEffect(() => {
- if (!lockChat && inputRef.current) {
- inputRef.current.focus();
- }
- }, [lockChat, inputRef]);
-
- useEffect(() => {
- if (inputRef.current) {
- inputRef.current.style.height = "inherit"; // Reset the height
- inputRef.current.style.height = `${inputRef.current.scrollHeight}px`; // Set it to the scrollHeight
- }
- }, [chatValue]);
-
- return (
-
- );
-}
diff --git a/src/frontend/src/modals/chatModal/chatMessage/codeBlock/index.tsx b/src/frontend/src/modals/chatModal/chatMessage/codeBlock/index.tsx
deleted file mode 100644
index 851f5118a..000000000
--- a/src/frontend/src/modals/chatModal/chatMessage/codeBlock/index.tsx
+++ /dev/null
@@ -1,82 +0,0 @@
-import { IconCheck, IconClipboard, IconDownload } from "@tabler/icons-react";
-import { FC, memo, useState } from "react";
-import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
-import { oneDark } from "react-syntax-highlighter/dist/cjs/styles/prism";
-import { programmingLanguages } from "../../../../utils";
-
-interface Props {
- language: string;
- value: string;
-}
-
-export const CodeBlock: FC = memo(({ language, value }) => {
- const [isCopied, setIsCopied] = useState(false);
-
- const copyToClipboard = () => {
- if (!navigator.clipboard || !navigator.clipboard.writeText) {
- return;
- }
-
- navigator.clipboard.writeText(value).then(() => {
- setIsCopied(true);
-
- setTimeout(() => {
- setIsCopied(false);
- }, 2000);
- });
- };
- const downloadAsFile = () => {
- const fileExtension = programmingLanguages[language] || ".file";
- const suggestedFileName = `${"generated-code"}${fileExtension}`;
- const fileName = window.prompt("enter file name", suggestedFileName);
-
- if (!fileName) {
- // user pressed cancel on prompt
- return;
- }
-
- const blob = new Blob([value], { type: "text/plain" });
- const url = URL.createObjectURL(blob);
- const link = document.createElement("a");
- link.download = fileName;
- link.href = url;
- link.style.display = "none";
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- URL.revokeObjectURL(url);
- };
- return (
-
-
-
{language}
-
-
-
-
-
-
-
-
- {value}
-
-
- );
-});
-CodeBlock.displayName = "CodeBlock";
diff --git a/src/frontend/src/modals/chatModal/chatMessage/index.tsx b/src/frontend/src/modals/chatModal/chatMessage/index.tsx
deleted file mode 100644
index 3d4ce0b44..000000000
--- a/src/frontend/src/modals/chatModal/chatMessage/index.tsx
+++ /dev/null
@@ -1,166 +0,0 @@
-import { useEffect, useRef, useState } from "react";
-import { ChatMessageType } from "../../../types/chat";
-import { classNames } from "../../../utils";
-import AiIcon from "../../../assets/Gooey Ring-5s-271px.svg";
-import AiIconStill from "../../../assets/froze-flow.png";
-import FileCard from "../fileComponent";
-import ReactMarkdown from "react-markdown";
-import rehypeMathjax from "rehype-mathjax";
-import remarkGfm from "remark-gfm";
-import remarkMath from "remark-math";
-import { CodeBlock } from "./codeBlock";
-import Convert from "ansi-to-html";
-import { User2, MessageCircle } from "lucide-react";
-
-export default function ChatMessage({
- chat,
- lockChat,
- lastMessage,
-}: {
- chat: ChatMessageType;
- lockChat: boolean;
- lastMessage: boolean;
-}) {
- const convert = new Convert({ newline: true });
- const [message, setMessage] = useState("");
- const imgRef = useRef(null);
- useEffect(() => {
- setMessage(chat.message);
- }, [chat.message]);
- const [hidden, setHidden] = useState(true);
- return (
-
-
- {!chat.isSend && (
-
-

-

-
- )}
- {chat.isSend && (
-
- )}
-
- {!chat.isSend ? (
-
-
- {hidden && chat.thought && chat.thought !== "" && (
-
setHidden((prev) => !prev)}
- className="absolute -top-1 -left-2 cursor-pointer"
- >
-
-
- )}
- {chat.thought && chat.thought !== "" && !hidden && (
-
setHidden((prev) => !prev)}
- className=" text-start inline-block rounded-md text-gray-600 dark:text-gray-200 h-full border border-gray-300 dark:border-gray-500
- bg-muted dark:bg-gray-800 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 &&
}
-
-
-
-
- β
-
- );
- }
-
- children[0] = (children[0] as string).replace(
- "`β`",
- "β"
- );
- }
-
- const match = /language-(\w+)/.exec(className || "");
-
- return !inline ? (
-
- ) : (
-
- {children}
-
- );
- },
- }}
- >
- {message}
-
-
- {chat.files && (
-
- {chat.files.map((file, index) => {
- return (
-
-
-
- );
- })}
-
- )}
-
-
-
-
- ) : (
-
- )}
-
- );
-}
diff --git a/src/frontend/src/modals/chatModal/fileComponent/index.tsx b/src/frontend/src/modals/chatModal/fileComponent/index.tsx
deleted file mode 100644
index 0807cd80c..000000000
--- a/src/frontend/src/modals/chatModal/fileComponent/index.tsx
+++ /dev/null
@@ -1,79 +0,0 @@
-import * as base64js from "base64-js";
-import { useState } from "react";
-import { DownloadCloud, File } from "lucide-react";
-
-export default function FileCard({ fileName, content, fileType }) {
- const handleDownload = () => {
- const byteArray = new Uint8Array(base64js.toByteArray(content));
- const blob = new Blob([byteArray], { type: "application/octet-stream" });
- const url = URL.createObjectURL(blob);
- const link = document.createElement("a");
- link.href = url;
- link.download = fileName + ".png";
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- URL.revokeObjectURL(url);
- };
- const [isHovered, setIsHovered] = useState(false);
- function handleMouseEnter() {
- setIsHovered(true);
- }
- function handleMouseLeave() {
- setIsHovered(false);
- }
-
- if (fileType === "image") {
- return (
-
-

- {isHovered && (
-
-
-
- )}
-
- );
- }
-
- return (
-
- );
-}
diff --git a/src/frontend/src/modals/chatModal/index.tsx b/src/frontend/src/modals/chatModal/index.tsx
deleted file mode 100644
index 6b1744857..000000000
--- a/src/frontend/src/modals/chatModal/index.tsx
+++ /dev/null
@@ -1,415 +0,0 @@
-import { Dialog, Transition } from "@headlessui/react";
-import { Fragment, useContext, useEffect, useRef, useState } from "react";
-import { FlowType } from "../../types/flow";
-import { alertContext } from "../../contexts/alertContext";
-import { validateNodes } from "../../utils";
-import { typesContext } from "../../contexts/typesContext";
-import ChatMessage from "./chatMessage";
-import { X, MessagesSquare, Eraser } from "lucide-react";
-import { sendAllProps } from "../../types/api";
-import { ChatMessageType } from "../../types/chat";
-import ChatInput from "./chatInput";
-
-import _ from "lodash";
-
-export default function ChatModal({
- flow,
- open,
- setOpen,
-}: {
- open: boolean;
- setOpen: Function;
- flow: FlowType;
-}) {
- const [chatValue, setChatValue] = useState("");
- const [chatHistory, setChatHistory] = useState([]);
- const { reactFlowInstance } = useContext(typesContext);
- const { setErrorData, setNoticeData } = useContext(alertContext);
- const ws = useRef(null);
- const [lockChat, setLockChat] = useState(false);
- const isOpen = useRef(open);
- const messagesRef = useRef(null);
- const id = useRef(flow.id);
-
- useEffect(() => {
- if (messagesRef.current) {
- messagesRef.current.scrollTop = messagesRef.current.scrollHeight;
- }
- }, [chatHistory]);
-
- useEffect(() => {
- isOpen.current = open;
- }, [open]);
- useEffect(() => {
- id.current = flow.id;
- }, [flow.id]);
-
- var isStream = false;
-
- const addChatHistory = (
- message: string,
- isSend: boolean,
- thought?: string,
- files?: Array
- ) => {
- setChatHistory((old) => {
- let newChat = _.cloneDeep(old);
- if (files) {
- newChat.push({ message, isSend, files, thought });
- } else if (thought) {
- newChat.push({ message, isSend, thought });
- } else {
- newChat.push({ message, isSend });
- }
- return newChat;
- });
- };
-
- //add proper type signature for function
-
- function updateLastMessage({
- str,
- thought,
- end = false,
- files,
- }: {
- str?: string;
- thought?: string;
- // end param default is false
- end?: boolean;
- files?: Array;
- }) {
- setChatHistory((old) => {
- let newChat = [...old];
- if (str) {
- if (end) {
- newChat[newChat.length - 1].message = str;
- } else {
- newChat[newChat.length - 1].message =
- newChat[newChat.length - 1].message + str;
- }
- }
- if (thought) {
- newChat[newChat.length - 1].thought = thought;
- }
- if (files) {
- newChat[newChat.length - 1].files = files;
- }
- return newChat;
- });
- }
-
- function handleOnClose(event: CloseEvent) {
- if (isOpen.current) {
- setErrorData({ title: event.reason });
- setTimeout(() => {
- connectWS();
- setLockChat(false);
- }, 1000);
- }
- }
-
- function getWebSocketUrl(chatId, isDevelopment = false) {
- const isSecureProtocol = window.location.protocol === "https:";
- const webSocketProtocol = isSecureProtocol ? "wss" : "ws";
- const host = isDevelopment ? "localhost:7860" : window.location.host;
- const chatEndpoint = `/api/v1/chat/${chatId}`;
-
- return `${
- isDevelopment ? "ws" : webSocketProtocol
- }://${host}${chatEndpoint}`;
- }
-
- function handleWsMessage(data: any) {
- if (Array.isArray(data)) {
- //set chat history
- setChatHistory((_) => {
- let newChatHistory: ChatMessageType[] = [];
- data.forEach(
- (chatItem: {
- intermediate_steps?: "string";
- is_bot: boolean;
- message: string;
- type: string;
- files?: Array;
- }) => {
- if (chatItem.message) {
- newChatHistory.push(
- chatItem.files
- ? {
- isSend: !chatItem.is_bot,
- message: chatItem.message,
- thought: chatItem.intermediate_steps,
- files: chatItem.files,
- }
- : {
- isSend: !chatItem.is_bot,
- message: chatItem.message,
- thought: chatItem.intermediate_steps,
- }
- );
- }
- }
- );
- return newChatHistory;
- });
- }
- if (data.type === "start") {
- addChatHistory("", false);
- isStream = true;
- }
- if (data.type === "end") {
- if (data.message) {
- updateLastMessage({ str: data.message, end: true });
- }
- if (data.intermediate_steps) {
- updateLastMessage({
- str: data.message,
- thought: data.intermediate_steps,
- end: true,
- });
- }
- if (data.files) {
- updateLastMessage({
- end: true,
- files: data.files,
- });
- }
-
- setLockChat(false);
- isStream = false;
- }
- if (data.type === "stream" && isStream) {
- updateLastMessage({ str: data.message });
- }
- }
-
- function connectWS() {
- try {
- const urlWs = getWebSocketUrl(
- id.current,
- process.env.NODE_ENV === "development"
- );
- const newWs = new WebSocket(urlWs);
- newWs.onopen = () => {
- console.log("WebSocket connection established!");
- };
- newWs.onmessage = (event) => {
- const data = JSON.parse(event.data);
- console.log("Received data:", data);
- handleWsMessage(data);
- //get chat history
- };
- newWs.onclose = (event) => {
- handleOnClose(event);
- };
- newWs.onerror = (ev) => {
- console.log(ev, "error");
- if (flow.id === "") {
- connectWS();
- } else {
- setErrorData({
- title: "There was an error on web connection, please: ",
- list: [
- "Refresh the page",
- "Use a new flow tab",
- "Check if the backend is up",
- ],
- });
- }
- };
- ws.current = newWs;
- } catch (error) {
- if (flow.id === "") {
- connectWS();
- }
- console.log(error);
- }
- }
-
- useEffect(() => {
- connectWS();
- return () => {
- console.log("unmount");
- console.log(ws);
- if (ws.current) {
- ws.current.close();
- }
- };
- }, []);
-
- useEffect(() => {
- if (
- ws.current &&
- (ws.current.readyState === ws.current.CLOSED ||
- ws.current.readyState === ws.current.CLOSING)
- ) {
- connectWS();
- setLockChat(false);
- }
- }, [lockChat]);
-
- async function sendAll(data: sendAllProps) {
- try {
- if (ws) {
- ws.current.send(JSON.stringify(data));
- }
- } catch (error) {
- setErrorData({
- title: "There was an error sending the message",
- list: [error.message],
- });
- setChatValue(data.message);
- connectWS();
- }
- }
-
- useEffect(() => {
- if (ref.current) ref.current.scrollIntoView({ behavior: "smooth" });
- }, [chatHistory]);
-
- const ref = useRef(null);
-
- useEffect(() => {
- if (open && ref.current) {
- ref.current.focus();
- }
- }, [open]);
-
- function sendMessage() {
- if (chatValue !== "") {
- let nodeValidationErrors = validateNodes(reactFlowInstance);
- if (nodeValidationErrors.length === 0) {
- setLockChat(true);
- let message = chatValue;
- setChatValue("");
- addChatHistory(message, true);
- sendAll({
- ...reactFlowInstance.toObject(),
- message,
- chatHistory,
- name: flow.name,
- description: flow.description,
- });
- } else {
- setErrorData({
- title: "Oops! Looks like you missed some required information:",
- list: nodeValidationErrors,
- });
- }
- } else {
- setErrorData({
- title: "Error sending message",
- list: ["The message cannot be empty."],
- });
- }
- }
- function clearChat() {
- setChatHistory([]);
- ws.current.send(JSON.stringify({ clear_history: true }));
- if (lockChat) setLockChat(false);
- }
-
- function setModalOpen(x: boolean) {
- setOpen(x);
- }
- return (
-
-
-
- );
-}
diff --git a/src/frontend/src/modals/formModal/chatInput/index.tsx b/src/frontend/src/modals/formModal/chatInput/index.tsx
index c03ab2003..17a673d68 100644
--- a/src/frontend/src/modals/formModal/chatInput/index.tsx
+++ b/src/frontend/src/modals/formModal/chatInput/index.tsx
@@ -8,7 +8,6 @@ export default function ChatInput({
lockChat,
chatValue,
sendMessage,
- clearChat,
setChatValue,
inputRef,
}) {
@@ -59,19 +58,11 @@ export default function ChatInput({
)}
placeholder={"Send a message..."}
/>
-{/*
-
-
*/}
-