update message cancelaltion and rejection logic

This commit is contained in:
Dallin Romney 2025-07-01 01:57:41 -07:00
parent 401b3bbf50
commit 6e3d42e80e
6 changed files with 25 additions and 23 deletions

View file

@ -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,

View file

@ -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);

View file

@ -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!,
}),
);
}
}
}

View file

@ -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} // <ToolOutput
"assistant" &&
item.message.toolCalls &&
item.toolCallState ? (

View file

@ -73,7 +73,7 @@ export function SimpleToolCallUI({
}
return (
<div className="flex flex-col pl-5 pr-2 pt-4">
<div className="flex flex-col py-4 pl-5 pr-2">
<div className="flex min-w-0 flex-row items-center justify-between gap-2">
<div
className={`text-description flex min-w-0 flex-row items-center justify-between gap-1.5 text-xs transition-colors duration-200 ease-in-out ${

View file

@ -114,7 +114,9 @@ export function constructMessages(
for (const toolCall of item.message.toolCalls) {
let content: string = "No tool output";
// TODO toolCallState only supports one tool call per message for now
if (
if (item.toolCallState?.status === "canceled") {
content = "The user cancelled this tool call.";
} else if (
item.toolCallState?.toolCallId === toolCall.id &&
item.toolCallState?.output
) {