From 526f5847c6a4dce8609a8e98db913d0292b593c6 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 27 Jun 2023 20:54:00 -0300 Subject: [PATCH 01/21] =?UTF-8?q?=F0=9F=90=9B=20fix(validate.py):=20remove?= =?UTF-8?q?=20unused=20variables=20from=20prompt.frontend=5Fnode.template?= =?UTF-8?q?=20=E2=9C=A8=20feat(validate.py):=20add=20support=20for=20dynam?= =?UTF-8?q?ic=20template=20fields=20in=20prompt=20validation=20The=20chang?= =?UTF-8?q?es=20in=20this=20commit=20remove=20unused=20variables=20from=20?= =?UTF-8?q?the=20prompt.frontend=5Fnode.template.=20The=20commit=20also=20?= =?UTF-8?q?adds=20support=20for=20dynamic=20template=20fields=20in=20promp?= =?UTF-8?q?t=20validation.=20The=20new=20variables=20are=20added=20to=20th?= =?UTF-8?q?e=20template=20and=20the=20custom=5Ffields=20list.=20The=20old?= =?UTF-8?q?=20custom=5Ffields=20list=20is=20copied=20and=20then=20updated?= =?UTF-8?q?=20with=20the=20new=20variables.=20The=20variables=20that=20are?= =?UTF-8?q?=20not=20in=20the=20template=20anymore=20are=20removed=20from?= =?UTF-8?q?=20the=20prompt.frontend=5Fnode.template.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/validate.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/backend/langflow/api/v1/validate.py b/src/backend/langflow/api/v1/validate.py index 802ee3e3d..431945602 100644 --- a/src/backend/langflow/api/v1/validate.py +++ b/src/backend/langflow/api/v1/validate.py @@ -31,6 +31,10 @@ def post_validate_code(code: Code): def post_validate_prompt(prompt: ValidatePromptRequest): try: input_variables = validate_prompt(prompt.template) + # Reinitialize custom_fields + old_custom_fields = prompt.frontend_node.custom_fields.copy() + prompt.frontend_node.custom_fields = [] + # Add new variables to the template for variable in input_variables: try: template_field = TemplateField( @@ -39,13 +43,20 @@ def post_validate_prompt(prompt: ValidatePromptRequest): prompt.frontend_node.template[variable] = template_field.to_dict() prompt.frontend_node.custom_fields.append(variable) - for key in prompt.frontend_node.template: - if key not in input_variables: - prompt.frontend_node.template.pop(key, None) + except Exception as exc: logger.exception(exc) raise HTTPException(status_code=500, detail=str(exc)) from exc + # Remove variables that are not in the template anymore + for variable in old_custom_fields: + if variable not in input_variables: + try: + prompt.frontend_node.template.pop(variable, None) + except Exception as exc: + logger.exception(exc) + raise HTTPException(status_code=500, detail=str(exc)) from exc + return PromptValidationResponse( input_variables=input_variables, frontend_node=prompt.frontend_node, From 355b846be435bae8ce5f38f87fe9d93dc3dd5610 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Tue, 27 Jun 2023 20:54:24 -0300 Subject: [PATCH 02/21] =?UTF-8?q?=F0=9F=8E=A8=20style(constants.tsx):=20ad?= =?UTF-8?q?d=20CHAT=5FFORM=5FDIALOG=5FSUBTITLE=20constant=20to=20improve?= =?UTF-8?q?=20code=20readability=20=E2=9C=A8=20feat(formModal):=20add=20In?= =?UTF-8?q?put=20Variables=20section=20to=20Chat=20Form=20modal=20to=20all?= =?UTF-8?q?ow=20users=20to=20input=20variables=20=F0=9F=8E=A8=20style(form?= =?UTF-8?q?Modal):=20adjust=20width=20of=20Chat=20Form=20modal=20and=20Inp?= =?UTF-8?q?ut=20Variables=20section=20to=20improve=20UI=20=F0=9F=8E=A8=20s?= =?UTF-8?q?tyle(formModal):=20adjust=20layout=20of=20Input=20Variables=20s?= =?UTF-8?q?ection=20to=20improve=20UI=20=F0=9F=8E=A8=20style(formModal):?= =?UTF-8?q?=20adjust=20layout=20of=20From=20Chat=20switch=20to=20improve?= =?UTF-8?q?=20UI=20=F0=9F=90=9B=20fix(formModal):=20replace=20Switch=20com?= =?UTF-8?q?ponent=20with=20custom=20ToggleShadComponent=20to=20fix=20styli?= =?UTF-8?q?ng=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/constants.tsx | 7 ++++++ src/frontend/src/modals/formModal/index.tsx | 26 ++++++++++++++++----- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/frontend/src/constants.tsx b/src/frontend/src/constants.tsx index f569046ea..d87008971 100644 --- a/src/frontend/src/constants.tsx +++ b/src/frontend/src/constants.tsx @@ -22,6 +22,13 @@ export const SETTINGS_DIALOG_SUBTITLE = "Edit details about your project."; export const CODE_DIALOG_SUBTITLE = "Export your flow to use it with this code."; +/** + * The base text for subtitle of Chat Form + * @constant + */ +export const CHAT_FORM_DIALOG_SUBTITLE = + "Export your flow to use it with this code."; + /** * The base text for subtitle of Edit Node Dialog * @constant diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index e1d2e1067..0d139a2d6 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -5,7 +5,7 @@ import { alertContext } from "../../contexts/alertContext"; import { validateNodes } from "../../utils"; import { typesContext } from "../../contexts/typesContext"; import ChatMessage from "./chatMessage"; -import { X, MessagesSquare, Eraser, TerminalSquare, MessageCircle, MessageSquareDashed, MessageSquare } from "lucide-react"; +import { X, MessagesSquare, Eraser, TerminalSquare, MessageCircle, MessageSquareDashed, MessageSquare, Variable } from "lucide-react"; import { sendAllProps } from "../../types/api"; import { ChatMessageType } from "../../types/chat"; import ChatInput from "./chatInput"; @@ -21,7 +21,7 @@ import { DialogTrigger, } from "../../components/ui/dialog"; import { dark } from "@mui/material/styles/createPalette"; -import { CODE_PROMPT_DIALOG_SUBTITLE } from "../../constants"; +import { CHAT_FORM_DIALOG_SUBTITLE } from "../../constants"; import { postValidateCode } from "../../controllers/API"; import { Button } from "../../components/ui/button"; import { Input } from "../../components/ui/input"; @@ -38,6 +38,8 @@ import { Textarea } from "../../components/ui/textarea"; import { Badge } from "../../components/ui/badge"; import { Separator } from "../../components/ui/separator"; import { Switch } from "../../components/ui/switch"; +import { CardTitle } from "../../components/ui/card"; +import ToggleShadComponent from "../../components/toggleShadComponent"; export default function FormModal({ flow, @@ -359,19 +361,26 @@ export default function FormModal({ return ( - + - Chat Form + Chat + {CHAT_FORM_DIALOG_SUBTITLE}
-
+
+
+ + + Input Variables + +
{tabsState[id.current].formKeysData.input_keys.map((i, k) => ( @@ -379,8 +388,13 @@ export default function FormModal({
- handleOnCheckedChange(value, k)}/> + handleOnCheckedChange(value, k)} + size="small" + disabled={false} + />
From 8c721b0b8e930e53dfcfb27315e6a1c33549c90f Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Tue, 27 Jun 2023 20:58:01 -0300 Subject: [PATCH 03/21] =?UTF-8?q?=F0=9F=90=9B=20fix(formModal):=20fix=20ke?= =?UTF-8?q?ysValue=20state=20initialization=20to=20prevent=20undefined=20e?= =?UTF-8?q?rror=20=E2=9C=A8=20feat(formModal):=20add=20support=20for=20mem?= =?UTF-8?q?ory=5Fkeys=20in=20input=20variables=20accordion=20to=20display?= =?UTF-8?q?=20memory=20keys=20in=20chat=20form=20modal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/modals/formModal/index.tsx | 224 +++++++++++--------- 1 file changed, 123 insertions(+), 101 deletions(-) diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index 0d139a2d6..b0cdaf484 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -5,7 +5,16 @@ import { alertContext } from "../../contexts/alertContext"; import { validateNodes } from "../../utils"; import { typesContext } from "../../contexts/typesContext"; import ChatMessage from "./chatMessage"; -import { X, MessagesSquare, Eraser, TerminalSquare, MessageCircle, MessageSquareDashed, MessageSquare, Variable } from "lucide-react"; +import { + X, + MessagesSquare, + Eraser, + TerminalSquare, + MessageCircle, + MessageSquareDashed, + MessageSquare, + Variable, +} from "lucide-react"; import { sendAllProps } from "../../types/api"; import { ChatMessageType } from "../../types/chat"; import ChatInput from "./chatInput"; @@ -74,8 +83,10 @@ export default function FormModal({ }, [open]); useEffect(() => { id.current = flow.id; - setKeysValue(Array(tabsState[flow.id].formKeysData.input_keys.length).fill("")); - }, [flow.id]); + setKeysValue( + Array(tabsState[flow.id].formKeysData.input_keys.length).fill("") + ); + }, [flow.id, tabsState[flow.id], tabsState[flow.id].formKeysData]); var isStream = false; @@ -316,7 +327,7 @@ export default function FormModal({ setLockChat(true); // Message variable makes a object with the keys being the names from tabsState[flow.id].formKeysData.input_keys and the values being the keysValue of the correspondent index let keys = tabsState[flow.id].formKeysData.input_keys; // array of keys - let values = keysValue.map((k, i) => i == chatKey ? chatValue : k); // array of values + let values = keysValue.map((k, i) => (i == chatKey ? chatValue : k)); // array of values let message = keys.reduce((object, key, index) => { object[key] = values[index]; return object; @@ -354,115 +365,126 @@ export default function FormModal({ } function handleOnCheckedChange(checked: boolean, index: number) { - if(checked === true){ + if (checked === true) { setChatKey(index); } } return ( - - - - Chat - - {CHAT_FORM_DIALOG_SUBTITLE} - + {tabsState[flow.id].formKeysData && ( + + + + Chat + + {CHAT_FORM_DIALOG_SUBTITLE} + -
-
-
- - - Input Variables - -
- - {tabsState[id.current].formKeysData.input_keys.map((i, k) => ( - - {i} - -
-
- - handleOnCheckedChange(value, k)} - size="small" - disabled={false} - /> -
- -
-
-
- ))} - {tabsState[id.current].formKeysData.memory_keys.map((i, k) => ( - -
-
{i}
- Memory Key -
-
- ))} -
-
-
-
-
- {chatHistory.length > 0 ? ( - chatHistory.map((c, i) => ( - - )) - ) : ( -
- - πŸ‘‹{" "} - - LangFlow Chat - - -
-
- - Start a conversation and click the agent's thoughts{" "} - - - {" "} - to inspect the chaining process. - -
-
- )} -
+
+
+
+ + + Input Variables +
-
-
- + + {tabsState[id.current].formKeysData.input_keys.map((i, k) => ( + + {i} + +
+
+ + + handleOnCheckedChange(value, k) + } + size="small" + disabled={false} + /> +
+ +
+
+
+ ))} + {tabsState[id.current].formKeysData.memory_keys.map((i, k) => ( + +
+
{i}
+ Memory Key +
+
+ ))} +
+
+
+
+
+ {chatHistory.length > 0 ? ( + chatHistory.map((c, i) => ( + + )) + ) : ( +
+ + πŸ‘‹{" "} + + LangFlow Chat + + +
+
+ + Start a conversation and click the agent's thoughts{" "} + + + {" "} + to inspect the chaining process. + +
+
+ )} +
+
+
+
+ +
-
- + + )}
); } From a4101dac536b61fcbc877c3f7c193c1fa62f708a Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 27 Jun 2023 21:31:47 -0300 Subject: [PATCH 04/21] =?UTF-8?q?=F0=9F=94=A5=20refactor(formModal):=20rem?= =?UTF-8?q?ove=20unused=20imports=20and=20variables=20=E2=9C=A8=20feat(for?= =?UTF-8?q?mModal):=20add=20function=20to=20format=20message=20inputs=20in?= =?UTF-8?q?to=20a=20string=20This=20commit=20removes=20unused=20imports=20?= =?UTF-8?q?and=20variables=20from=20the=20file.=20A=20new=20function=20was?= =?UTF-8?q?=20added=20to=20format=20the=20message=20inputs=20into=20a=20st?= =?UTF-8?q?ring,=20which=20is=20used=20to=20display=20the=20message=20in?= =?UTF-8?q?=20the=20chat.=20This=20improves=20the=20readability=20of=20the?= =?UTF-8?q?=20code=20and=20makes=20it=20easier=20to=20understand=20how=20t?= =?UTF-8?q?he=20message=20is=20being=20constructed.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/modals/formModal/index.tsx | 57 +++++++++++---------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index b0cdaf484..f0e5e0f5c 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -1,20 +1,10 @@ -import { Transition } from "@headlessui/react"; -import { Fragment, useContext, useEffect, useRef, useState } from "react"; +import { 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, - TerminalSquare, - MessageCircle, - MessageSquareDashed, - MessageSquare, - Variable, -} from "lucide-react"; +import { TerminalSquare, MessageSquare, Variable } from "lucide-react"; import { sendAllProps } from "../../types/api"; import { ChatMessageType } from "../../types/chat"; import ChatInput from "./chatInput"; @@ -24,16 +14,11 @@ import { Dialog, DialogContent, DialogDescription, - DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "../../components/ui/dialog"; -import { dark } from "@mui/material/styles/createPalette"; import { CHAT_FORM_DIALOG_SUBTITLE } from "../../constants"; -import { postValidateCode } from "../../controllers/API"; -import { Button } from "../../components/ui/button"; -import { Input } from "../../components/ui/input"; import { Label } from "../../components/ui/label"; import { TabsContext } from "../../contexts/tabsContext"; import { @@ -42,12 +27,8 @@ import { AccordionItem, AccordionTrigger, } from "../../components/ui/accordion"; -import { AccordionHeader } from "@radix-ui/react-accordion"; import { Textarea } from "../../components/ui/textarea"; import { Badge } from "../../components/ui/badge"; -import { Separator } from "../../components/ui/separator"; -import { Switch } from "../../components/ui/switch"; -import { CardTitle } from "../../components/ui/card"; import ToggleShadComponent from "../../components/toggleShadComponent"; export default function FormModal({ @@ -83,9 +64,12 @@ export default function FormModal({ }, [open]); useEffect(() => { id.current = flow.id; - setKeysValue( - Array(tabsState[flow.id].formKeysData.input_keys.length).fill("") - ); + + if (tabsState[flow.id].formKeysData) { + setKeysValue( + Array(tabsState[flow.id].formKeysData.input_keys.length).fill("") + ); + } }, [flow.id, tabsState[flow.id], tabsState[flow.id].formKeysData]); var isStream = false; @@ -303,7 +287,7 @@ export default function FormModal({ title: "There was an error sending the message", list: [error.message], }); - setChatValue(data.message); + setChatValue(data.inputs); connectWS(); } } @@ -319,6 +303,22 @@ export default function FormModal({ ref.current.focus(); } }, [open]); + function formatMessage(inputs: any): string { + if (inputs) { + // inputs is a object with the keys and values being input_keys and keysValue + // so the formated message is a string with the keys and values separated by ": " + let message = ""; + for (const [key, value] of Object.entries(inputs)) { + // make key bold + // dangerouslySetInnerHTML={{ + // __html: message.replace(/\n/g, "
"), + // }} + message += `${key}: ${value}\n`; + } + return message; + } + return ""; + } function sendMessage() { if (chatValue !== "") { @@ -328,15 +328,16 @@ export default function FormModal({ // Message variable makes a object with the keys being the names from tabsState[flow.id].formKeysData.input_keys and the values being the keysValue of the correspondent index let keys = tabsState[flow.id].formKeysData.input_keys; // array of keys let values = keysValue.map((k, i) => (i == chatKey ? chatValue : k)); // array of values - let message = keys.reduce((object, key, index) => { + let inputs = keys.reduce((object, key, index) => { object[key] = values[index]; return object; }, {}); setChatValue(""); - addChatHistory(message.toString(), true); + const message = formatMessage(inputs); + addChatHistory(message, true); sendAll({ ...reactFlowInstance.toObject(), - message, + inputs: inputs, chatHistory, name: flow.name, description: flow.description, From 5a9c1ae1b71244741c7067c1fd2dc0c8571d5a62 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 27 Jun 2023 21:32:09 -0300 Subject: [PATCH 05/21] =?UTF-8?q?=F0=9F=94=80=20chore(schemas.py):=20add?= =?UTF-8?q?=20support=20for=20dict=20type=20in=20message=20field=20of=20Ch?= =?UTF-8?q?atMessage=20schema=20The=20message=20field=20of=20the=20ChatMes?= =?UTF-8?q?sage=20schema=20now=20supports=20a=20dictionary=20type=20in=20a?= =?UTF-8?q?ddition=20to=20the=20previous=20string=20and=20None=20types.=20?= =?UTF-8?q?This=20change=20was=20made=20to=20allow=20for=20more=20complex?= =?UTF-8?q?=20messages=20to=20be=20sent=20and=20received=20in=20the=20chat?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/schemas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/langflow/api/v1/schemas.py b/src/backend/langflow/api/v1/schemas.py index ed5bf8b3b..1739310e9 100644 --- a/src/backend/langflow/api/v1/schemas.py +++ b/src/backend/langflow/api/v1/schemas.py @@ -43,7 +43,7 @@ class ChatMessage(BaseModel): """Chat message schema.""" is_bot: bool = False - message: Union[str, None] = None + message: Union[str, None, dict] = None type: str = "human" From c39e94d584522188d6e54f80c3510de9e3d392ab Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 27 Jun 2023 21:32:46 -0300 Subject: [PATCH 06/21] =?UTF-8?q?=F0=9F=94=A8=20refactor(base.py):=20chang?= =?UTF-8?q?e=20message=20parameter=20to=20inputs=20parameter=20to=20improv?= =?UTF-8?q?e=20semantics=20The=20message=20parameter=20was=20not=20being?= =?UTF-8?q?=20used=20in=20the=20function,=20so=20it=20was=20changed=20to?= =?UTF-8?q?=20inputs=20to=20better=20reflect=20the=20purpose=20of=20the=20?= =?UTF-8?q?parameter.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/processing/base.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/backend/langflow/processing/base.py b/src/backend/langflow/processing/base.py index 97b0d5be0..ca86d1a83 100644 --- a/src/backend/langflow/processing/base.py +++ b/src/backend/langflow/processing/base.py @@ -6,23 +6,12 @@ from langflow.processing.process import fix_memory_inputs, format_actions from langflow.utils.logger import logger -async def get_result_and_steps(langchain_object, message: str, **kwargs): +async def get_result_and_steps(langchain_object, inputs: dict, **kwargs): """Get result and thought from extracted json""" try: if hasattr(langchain_object, "verbose"): langchain_object.verbose = True - chat_input = None - memory_key = "" - if hasattr(langchain_object, "memory") and langchain_object.memory is not None: - memory_key = langchain_object.memory.memory_key - - if hasattr(langchain_object, "input_keys"): - for key in langchain_object.input_keys: - if key not in [memory_key, "chat_history"]: - chat_input = {key: message} - else: - chat_input = message # type: ignore if hasattr(langchain_object, "return_intermediate_steps"): # https://github.com/hwchase17/langchain/issues/2068 @@ -33,12 +22,12 @@ async def get_result_and_steps(langchain_object, message: str, **kwargs): fix_memory_inputs(langchain_object) try: async_callbacks = [AsyncStreamingLLMCallbackHandler(**kwargs)] - output = await langchain_object.acall(chat_input, callbacks=async_callbacks) + output = await langchain_object.acall(inputs, callbacks=async_callbacks) except Exception as exc: # make the error message more informative logger.debug(f"Error: {str(exc)}") sync_callbacks = [StreamingLLMCallbackHandler(**kwargs)] - output = langchain_object(chat_input, callbacks=sync_callbacks) + output = langchain_object(inputs, callbacks=sync_callbacks) intermediate_steps = ( output.get("intermediate_steps", []) if isinstance(output, dict) else [] From 2e09d7026b1d3b21f4d527b8417382e352b0e91c Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 27 Jun 2023 21:33:06 -0300 Subject: [PATCH 07/21] =?UTF-8?q?=F0=9F=94=80=20chore(api):=20rename=20mes?= =?UTF-8?q?sage=20property=20to=20inputs=20in=20sendAllProps=20type=20The?= =?UTF-8?q?=20message=20property=20in=20the=20sendAllProps=20type=20has=20?= =?UTF-8?q?been=20renamed=20to=20inputs=20to=20better=20reflect=20its=20pu?= =?UTF-8?q?rpose.=20This=20change=20improves=20the=20semantics=20of=20the?= =?UTF-8?q?=20code=20and=20makes=20it=20easier=20to=20understand=20the=20p?= =?UTF-8?q?urpose=20of=20the=20property.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/types/api/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/src/types/api/index.ts b/src/frontend/src/types/api/index.ts index d47663d18..7fc10f309 100644 --- a/src/frontend/src/types/api/index.ts +++ b/src/frontend/src/types/api/index.ts @@ -31,7 +31,7 @@ export type sendAllProps = { name: string; description: string; viewport: Viewport; - message: any; + inputs: any; chatHistory: { message: string; isSend: boolean }[]; }; From d59b648b75e3ea1790869ba3c5da86362154a067 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Wed, 28 Jun 2023 00:38:21 -0300 Subject: [PATCH 08/21] =?UTF-8?q?=F0=9F=94=A5=20refactor(formTrigger):=20r?= =?UTF-8?q?emove=20unused=20FormTrigger=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit πŸ”₯ refactor(chatComponent): remove import and usage of FormTrigger component πŸ”₯ refactor(ui/badge): remove unused size variant in Badge component πŸ”₯ refactor(formModal/chatInput): remove unused Eraser icon import and clearChat function πŸ”₯ refactor(formModal/chatMessage): remove unused classNames import and remove dark mode classes πŸ”₯ refactor(formModal): remove unused Eraser icon import and clearChat function --- .../chatComponent/formTrigger/index.tsx | 51 ------------------- .../src/components/chatComponent/index.tsx | 9 ++-- src/frontend/src/components/ui/badge.tsx | 13 +++-- .../src/modals/formModal/chatInput/index.tsx | 21 +++++--- .../modals/formModal/chatMessage/index.tsx | 4 +- src/frontend/src/modals/formModal/index.tsx | 26 +++++++--- 6 files changed, 48 insertions(+), 76 deletions(-) delete mode 100644 src/frontend/src/components/chatComponent/formTrigger/index.tsx diff --git a/src/frontend/src/components/chatComponent/formTrigger/index.tsx b/src/frontend/src/components/chatComponent/formTrigger/index.tsx deleted file mode 100644 index c281a92e3..000000000 --- a/src/frontend/src/components/chatComponent/formTrigger/index.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import { Transition } from "@headlessui/react"; -import { FormInput, MessagesSquare } from "lucide-react"; - -import { alertContext } from "../../../contexts/alertContext"; -import { useContext } from "react"; - -export default function FormTrigger({ open, setOpen, isBuilt }) { - const { setErrorData } = useContext(alertContext); - - function handleClick() { - if (isBuilt) { - setOpen(true); - } else { - setErrorData({ - title: "Flow not built", - list: ["Please build the flow before chatting"], - }); - } - } - - return ( - -
-
- -
-
-
- ); -} diff --git a/src/frontend/src/components/chatComponent/index.tsx b/src/frontend/src/components/chatComponent/index.tsx index 741cf4ec8..eaf0ba4ef 100644 --- a/src/frontend/src/components/chatComponent/index.tsx +++ b/src/frontend/src/components/chatComponent/index.tsx @@ -7,7 +7,6 @@ import ChatModal from "../../modals/chatModal"; import { getBuildStatus } from "../../controllers/API"; import { NodeType } from "../../types/flow"; -import FormTrigger from "./formTrigger"; import FormModal from "../../modals/formModal"; export default function Chat({ flow }: ChatType) { @@ -66,15 +65,13 @@ export default function Chat({ flow }: ChatType) { {isBuilt ? (
- - - - + +
) : ( , VariantProps {} -function Badge({ className, variant, ...props }: BadgeProps) { +function Badge({ className, variant, size, ...props }: BadgeProps) { return ( -
+
); } diff --git a/src/frontend/src/modals/formModal/chatInput/index.tsx b/src/frontend/src/modals/formModal/chatInput/index.tsx index cb77cd277..c03ab2003 100644 --- a/src/frontend/src/modals/formModal/chatInput/index.tsx +++ b/src/frontend/src/modals/formModal/chatInput/index.tsx @@ -2,12 +2,13 @@ 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"; +import { Eraser, Lock, LucideSend, Send } from "lucide-react"; export default function ChatInput({ lockChat, chatValue, sendMessage, + clearChat, setChatValue, inputRef, }) { @@ -58,16 +59,24 @@ export default function ChatInput({ )} placeholder={"Send a message..."} /> -
- +
*/} +
+ +
Date: Wed, 28 Jun 2023 00:44:48 -0300 Subject: [PATCH 09/21] Deleted chat modal and changed disposition of clearChat button --- .../src/modals/chatModal/chatInput/index.tsx | 78 ---- .../chatModal/chatMessage/codeBlock/index.tsx | 82 ---- .../modals/chatModal/chatMessage/index.tsx | 166 ------- .../modals/chatModal/fileComponent/index.tsx | 79 ---- src/frontend/src/modals/chatModal/index.tsx | 415 ------------------ .../src/modals/formModal/chatInput/index.tsx | 13 +- .../modals/formModal/chatMessage/index.tsx | 2 +- src/frontend/src/modals/formModal/index.tsx | 6 +- 8 files changed, 5 insertions(+), 836 deletions(-) delete mode 100644 src/frontend/src/modals/chatModal/chatInput/index.tsx delete mode 100644 src/frontend/src/modals/chatModal/chatMessage/codeBlock/index.tsx delete mode 100644 src/frontend/src/modals/chatModal/chatMessage/index.tsx delete mode 100644 src/frontend/src/modals/chatModal/fileComponent/index.tsx delete mode 100644 src/frontend/src/modals/chatModal/index.tsx 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 ( -
-