From 3928c1d5517f962aac5744e6b5ad875654547b31 Mon Sep 17 00:00:00 2001 From: Xichen Gao Date: Sun, 25 May 2025 23:19:51 -0700 Subject: [PATCH 1/2] added the functionalities to let the user choose whether to overwrite the original editorContent or not and to overwrite that if the user wants overwriting to happen --- react/src/App.tsx | 12 ++- react/src/Chat.tsx | 99 +++++++++++++++---- react/src/PostEditor.tsx | 23 ++++- server/localmanus/routers/agent.py | 146 +++++++++++++++++------------ 4 files changed, 196 insertions(+), 84 deletions(-) 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..5d05ff4 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,16 +241,20 @@ const ChatInterface = ({ if (pending) { return; } - if (!model) { - toast.error( - "Please select a model! Go to Settings to set your API keys if you haven't done so." - ); - return; - } - if (!model.url || model.url == "") { - toast.error("Please set the model URL in Settings"); + 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." + // ); + // return; + // } + // if (!model.url || model.url == "") { + // toast.error("Please set the model URL in Settings"); + // return; + // } if (!promptStr || promptStr == "") { return; } @@ -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); @@ -267,9 +281,9 @@ const ChatInterface = ({ body: JSON.stringify({ messages: newMessages, session_id: sessionIdRef.current, - model: model.model, - provider: model.provider, - url: model.url, + // model: model.model, + // provider: model.provider, + // url: model.url, }), }).then((resp) => resp.json()); }; @@ -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 = ({