Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const MAX_EDIT_STACK_SIZE = 100;

export default function PromptInput({
submit,
onChange,
isStreaming,
sendCommand,
attachments = [],
Expand All @@ -51,7 +50,6 @@ export default function PromptInput({

// Synchronizes prompt input value with localStorage, scoped to the current thread.
usePromptInputStorage({
onChange,
promptInput,
setPromptInput,
});
Expand Down Expand Up @@ -228,7 +226,6 @@ export default function PromptInput({
pasteText +
promptInput.substring(end);
setPromptInput(newPromptInput);
onChange({ target: { value: newPromptInput } });

// Set the cursor position after the pasted text
// we need to use setTimeout to prevent the cursor from being set to the end of the text
Expand All @@ -243,7 +240,6 @@ export default function PromptInput({

function handleChange(e) {
debouncedSaveState(-1);
onChange(e);
watchForSlash(e);
watchForAt(e);
adjustTextArea(e);
Expand Down
20 changes: 6 additions & 14 deletions frontend/src/components/WorkspaceChat/ChatContainer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,13 @@ import useChatContainerQuickScroll from "@/hooks/useChatContainerQuickScroll";

export default function ChatContainer({ workspace, knownHistory = [] }) {
const { threadSlug = null } = useParams();
const [message, setMessage] = useState("");
const [loadingResponse, setLoadingResponse] = useState(false);
const [chatHistory, setChatHistory] = useState(knownHistory);
const [socketId, setSocketId] = useState(null);
const [websocket, setWebsocket] = useState(null);
const { files, parseAttachments } = useContext(DndUploaderContext);
const { chatHistoryRef } = useChatContainerQuickScroll();

// Maintain state of message from whatever is in PromptInput
const handleMessageChange = (event) => {
setMessage(event.target.value);
};

const { listening, resetTranscript } = useSpeechRecognition({
clearTranscriptOnListen: true,
});
Expand All @@ -50,10 +44,6 @@ export default function ChatContainer({ workspace, knownHistory = [] }) {
* @param {'replace' | 'append'} writeMode - Replace current text or append to existing text (default: replace)
*/
function setMessageEmit(messageContent = "", writeMode = "replace") {
if (writeMode === "append") setMessage((prev) => prev + messageContent);
else setMessage(messageContent ?? "");

// Push the update to the PromptInput component (same logic as above to keep in sync)
window.dispatchEvent(
new CustomEvent(PROMPT_INPUT_EVENT, {
detail: { messageContent, writeMode },
Expand All @@ -63,19 +53,22 @@ export default function ChatContainer({ workspace, knownHistory = [] }) {

const handleSubmit = async (event) => {
event.preventDefault();
if (!message || message === "") return false;
const currentMessage =
document.getElementById(PROMPT_INPUT_ID)?.value || "";
if (!currentMessage) return false;

const prevChatHistory = [
...chatHistory,
{
content: message,
content: currentMessage,
role: "user",
attachments: parseAttachments(),
},
{
content: "",
role: "assistant",
pending: true,
userMessage: message,
userMessage: currentMessage,
animate: true,
},
];
Expand Down Expand Up @@ -321,7 +314,6 @@ export default function ChatContainer({ workspace, knownHistory = [] }) {
</MetricsProvider>
<PromptInput
submit={handleSubmit}
onChange={handleMessageChange}
isStreaming={loadingResponse}
sendCommand={sendCommand}
attachments={files}
Expand Down
9 changes: 1 addition & 8 deletions frontend/src/hooks/usePromptInputStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,11 @@ import { safeJsonParse } from "@/utils/request";
* ```
*
* @param {Object} props
* @param {Function} props.onChange - Callback invoked when restoring saved value, receives `{ target: { value: string } }`
* @param {string} props.promptInput - Current prompt input value to sync
* @param {Function} props.setPromptInput - State setter function for prompt input
* @returns {void}
*/
export default function usePromptInputStorage({
onChange,
promptInput,
setPromptInput,
}) {
export default function usePromptInputStorage({ promptInput, setPromptInput }) {
const { threadSlug = null, slug: workspaceSlug } = useParams();
useEffect(() => {
const serializedPromptInputMap =
Expand All @@ -40,8 +35,6 @@ export default function usePromptInputStorage({
const userPromptInputValue = promptInputMap[threadSlug ?? workspaceSlug];
if (userPromptInputValue) {
setPromptInput(userPromptInputValue);
// Notify parent component so message state is synchronized
onChange({ target: { value: userPromptInputValue } });
}
}, []);

Expand Down