diff --git a/react/src/App.tsx b/react/src/App.tsx index 2eead08..460bd3b 100644 --- a/react/src/App.tsx +++ b/react/src/App.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, useState } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; import "./App.css"; import { Button } from "./components/ui/button"; import { @@ -86,13 +86,21 @@ function Home() { )}
- {!!curPath && } + {!!curPath && < + PostEditor + curPath={curPath} + setCurPath={setCurPath} + editorContent={editorContent} + setEditorContent={setEditorContent} + setEditorContentWrapper={setEditorContentWrapper} + />}
{ setSessionId(nanoid()); }} diff --git a/react/src/Chat.tsx b/react/src/Chat.tsx index c901e22..e4406eb 100644 --- a/react/src/Chat.tsx +++ b/react/src/Chat.tsx @@ -46,12 +46,15 @@ const ChatInterface = ({ onClickNewChat, editorContent, editorTitle, + setEditorContentWrapper, }: { sessionId: string; editorTitle: string; editorContent: string; onClickNewChat: () => void; + setEditorContentWrapper: (value: string) => void; }) => { + const [buttonClicked, setButtonClicked] = useState(true); const [messages, setMessages] = useState([]); const [prompt, setPrompt] = useState(""); const [disableStop, setDisableStop] = useState(false); @@ -125,6 +128,7 @@ const ChatInterface = ({ console.log(event.data); try { const data = JSON.parse(event.data); + console.log("👇data", data); if (data.type == "log") { console.log(data); } @@ -139,6 +143,7 @@ const ChatInterface = ({ }); } else if (data.type == "done") { setPending(false); + setButtonClicked(false); } else if (data.type == "info") { toast.info(data.info, { closeButton: true, @@ -236,6 +241,10 @@ const ChatInterface = ({ if (pending) { return; } + if (!buttonClicked) { + toast.error("Please approve/decline the previous AI suggestion first."); + return; + } if (!model) { toast.error( "Please select a model! Go to Settings to set your API keys if you haven't done so." @@ -253,7 +262,12 @@ const ChatInterface = ({ const newMessages = messages.concat([ { role: "user", - content: promptStr + "\n\n # " + editorTitle + "\n\n" + editorContent, + //content: promptStr + "\n\n # " + editorTitle + "\n\n" + editorContent, + content: + "Based on the following prompt, generate a revised version of the editorContent: \n\n" + + "Prompt: " + promptStr + "\n\n" + + "Original editorContent: " + editorContent + "\n\n" + + "Please respond **only** with the updated version of the editorContent. Do not include any explanations, comments, or extra text.", }, ]); setMessages(newMessages); @@ -411,8 +425,59 @@ const ChatInterface = ({ {/* Messages */} {messages.map((message, idx) => (
- {/* Regular message content */} - {typeof message.content == "string" && + {/* User message */} + {typeof message.content == "string" &&message.role === "user" && ( +
+ {message.content} +
+ )} + {/* Assistant message */} + { typeof message.content == "string" && message.role === "assistant" && ( +
+ {/* Message body */} + {message.content} + + {/* Buttons appear only on hover, after response is done */} + {!pending && messages.at(-1) === message && ( +
+ + +
+ )} +
+ )} + + {/* {typeof message.content == "string" && message.role !== "tool" && (
{message.content}
- )} + )} */} + {typeof message.content == "string" && message.role == "tool" && expandingToolCalls.includes(message.tool_call_id) && ( @@ -498,7 +564,8 @@ const ChatInterface = ({