From 6e3d42e80e9ccf4ee78e930315fc2770901d3dec Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 1 Jul 2025 01:57:41 -0700 Subject: [PATCH] update message cancelaltion and rejection logic --- gui/src/components/AcceptRejectDiffButtons.tsx | 15 ++++++++++++++- gui/src/components/mainInput/InputToolbar.tsx | 14 +------------- gui/src/hooks/ParallelListeners.tsx | 11 +++++------ gui/src/pages/gui/Chat.tsx | 2 +- .../pages/gui/ToolCallDiv/SimpleToolCallUI.tsx | 2 +- gui/src/redux/util/constructMessages.ts | 4 +++- 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/gui/src/components/AcceptRejectDiffButtons.tsx b/gui/src/components/AcceptRejectDiffButtons.tsx index a19b56068..9420fc551 100644 --- a/gui/src/components/AcceptRejectDiffButtons.tsx +++ b/gui/src/components/AcceptRejectDiffButtons.tsx @@ -2,6 +2,9 @@ import { CheckIcon, XMarkIcon } from "@heroicons/react/24/outline"; import { ApplyState } from "core"; import { useContext } from "react"; import { IdeMessengerContext } from "../context/IdeMessenger"; +import { useAppDispatch, useAppSelector } from "../redux/hooks"; +import { selectCurrentToolCallApplyState } from "../redux/selectors/selectCurrentToolCall"; +import { cancelToolCall } from "../redux/slices/sessionSlice"; import { getMetaKeyLabel } from "../util"; import { ToolTip } from "./gui/Tooltip"; @@ -20,8 +23,18 @@ export default function AcceptRejectAllButtons({ (state) => state.status === "done", ); const ideMessenger = useContext(IdeMessengerContext); - + const currentToolCallApplyState = useAppSelector( + selectCurrentToolCallApplyState, + ); + const dispatch = useAppDispatch(); async function handleAcceptOrReject(status: AcceptOrRejectOutcome) { + if (currentToolCallApplyState?.status === "done") { + dispatch( + cancelToolCall({ + toolCallId: currentToolCallApplyState.toolCallId!, + }), + ); + } for (const { filepath = "", streamId } of pendingApplyStates) { ideMessenger.post(status, { filepath, diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index 0dfbcd493..88d5a5c65 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -9,10 +9,6 @@ import { useContext, useRef } from "react"; import { IdeMessengerContext } from "../../context/IdeMessenger"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { selectUseActiveFile } from "../../redux/selectors"; -import { - selectCurrentToolCall, - selectCurrentToolCallApplyState, -} from "../../redux/selectors/selectCurrentToolCall"; import { selectSelectedChatModel } from "../../redux/slices/configSlice"; import { setHasReasoningEnabled } from "../../redux/slices/sessionSlice"; import { exitEdit } from "../../redux/thunks/edit"; @@ -53,20 +49,12 @@ function InputToolbar(props: InputToolbarProps) { const useActiveFile = useAppSelector(selectUseActiveFile); const isInEdit = useAppSelector((store) => store.session.isInEdit); const codeToEdit = useAppSelector((store) => store.editModeState.codeToEdit); - const toolCallState = useAppSelector(selectCurrentToolCall); - const currentToolCallApplyState = useAppSelector( - selectCurrentToolCallApplyState, - ); const hasReasoningEnabled = useAppSelector( (store) => store.session.hasReasoningEnabled, ); const isEnterDisabled = - props.disabled || - (isInEdit && codeToEdit.length === 0) || - toolCallState?.status === "generated" || - (currentToolCallApplyState && - currentToolCallApplyState.status !== "closed"); + props.disabled || (isInEdit && codeToEdit.length === 0); const toolsSupported = defaultModel && modelSupportsTools(defaultModel); diff --git a/gui/src/hooks/ParallelListeners.tsx b/gui/src/hooks/ParallelListeners.tsx index 693359a97..246e92ce6 100644 --- a/gui/src/hooks/ParallelListeners.tsx +++ b/gui/src/hooks/ParallelListeners.tsx @@ -268,7 +268,6 @@ function ParallelListeners() { currentToolCallApplyState.streamId === state.streamId ) { if (state.status === "done" && autoAcceptEditToolDiffs) { - console.log("AUTO ACCEPTED"); ideMessenger.post("acceptDiff", { streamId: state.streamId, filepath: state.filepath, @@ -281,6 +280,11 @@ function ParallelListeners() { toolCallId: currentToolCallApplyState.toolCallId!, }), ); + void dispatch( + streamResponseAfterToolCall({ + toolCallId: currentToolCallApplyState.toolCallId!, + }), + ); } // const output: ContextItem = { // name: "Edit tool output", @@ -288,11 +292,6 @@ function ParallelListeners() { // description: "", // }; // dispatch(setToolCallOutput([])); - void dispatch( - streamResponseAfterToolCall({ - toolCallId: currentToolCallApplyState.toolCallId!, - }), - ); } } } diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 126c4e894..a965f9559 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -319,7 +319,7 @@ export function Chat() { inputId={item.message.id} /> - ) : item.message.role === "tool" ? null : item.message.role === + ) : item.message.role === "tool" ? null : item.message.role === // /> // toolCallId={item.message.toolCallId} // contextItems={item.contextItems} // +