fix: render all pending apply states
This commit is contained in:
parent
70a5365dfc
commit
cd6ceebcbf
8 changed files with 72 additions and 86 deletions
12
core/index.d.ts
vendored
12
core/index.d.ts
vendored
|
|
@ -432,12 +432,12 @@ export interface PromptLog {
|
|||
export type MessageModes = "chat" | "agent" | "plan";
|
||||
|
||||
export type ToolStatus =
|
||||
| "generating"
|
||||
| "generated"
|
||||
| "calling"
|
||||
| "errored"
|
||||
| "done"
|
||||
| "canceled";
|
||||
| "generating" // Tool call arguments are being streamed from the LLM
|
||||
| "generated" // Tool call is complete and ready for execution (awaiting approval)
|
||||
| "calling" // Tool is actively being executed
|
||||
| "errored" // Tool execution failed with an error
|
||||
| "done" // Tool execution completed successfully
|
||||
| "canceled"; // Tool call was canceled by user or system
|
||||
|
||||
// Will exist only on "assistant" messages with tool calls
|
||||
interface ToolCallState {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ 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/selectToolCalls";
|
||||
import { useAppDispatch } from "../redux/hooks";
|
||||
import { cancelToolCall } from "../redux/slices/sessionSlice";
|
||||
import { getMetaKeyLabel } from "../util";
|
||||
import { ToolTip } from "./gui/Tooltip";
|
||||
|
|
@ -23,21 +22,22 @@ 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 (
|
||||
status === "rejectDiff" &&
|
||||
currentToolCallApplyState?.status === "done"
|
||||
) {
|
||||
dispatch(
|
||||
cancelToolCall({
|
||||
toolCallId: currentToolCallApplyState.toolCallId!,
|
||||
}),
|
||||
);
|
||||
// For reject operations, cancel all tool calls associated with pending apply states
|
||||
if (status === "rejectDiff") {
|
||||
for (const applyState of pendingApplyStates) {
|
||||
if (applyState.toolCallId && applyState.status === "done") {
|
||||
dispatch(
|
||||
cancelToolCall({
|
||||
toolCallId: applyState.toolCallId,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process all pending apply states
|
||||
for (const { filepath = "", streamId } of pendingApplyStates) {
|
||||
ideMessenger.post(status, {
|
||||
filepath,
|
||||
|
|
|
|||
|
|
@ -8,11 +8,8 @@ export function GeneratingIndicator({
|
|||
testId?: string;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className="text-description flex items-center text-xs"
|
||||
data-testid={testId}
|
||||
>
|
||||
<span>{text}</span>
|
||||
<div className="flex items-center" data-testid={testId}>
|
||||
<span className="text-description text-xs">{text}</span>
|
||||
<AnimatedEllipsis />
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ import { useSelector } from "react-redux";
|
|||
import { IdeMessengerContext } from "../../../../context/IdeMessenger";
|
||||
import { useAppDispatch, useAppSelector } from "../../../../redux/hooks";
|
||||
import {
|
||||
selectCurrentToolCall,
|
||||
selectFirstPendingToolCall,
|
||||
selectPendingToolCalls,
|
||||
} from "../../../../redux/selectors/selectToolCalls";
|
||||
import { cancelToolCall } from "../../../../redux/slices/sessionSlice";
|
||||
import { callToolById } from "../../../../redux/thunks/callToolById";
|
||||
|
|
@ -42,7 +42,7 @@ export function LumpToolbar() {
|
|||
const isStreaming = useAppSelector((state) => state.session.isStreaming);
|
||||
const isInEdit = useAppSelector((state) => state.session.isInEdit);
|
||||
const jetbrains = isJetBrains();
|
||||
const toolCallState = useSelector(selectCurrentToolCall);
|
||||
const pendingToolCalls = useAppSelector(selectPendingToolCalls);
|
||||
const firstPendingToolCall = useAppSelector(selectFirstPendingToolCall);
|
||||
const editApplyState = useAppSelector(
|
||||
(state) => state.editModeState.applyState,
|
||||
|
|
@ -107,7 +107,7 @@ export function LumpToolbar() {
|
|||
return <StreamingToolbar />;
|
||||
}
|
||||
|
||||
if (toolCallState?.status === "generated") {
|
||||
if (pendingToolCalls.length > 0) {
|
||||
return <PendingToolCallToolbar />;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,6 @@ import { IdeMessengerContext } from "../context/IdeMessenger";
|
|||
import { EDIT_MODE_STREAM_ID } from "core/edit/constants";
|
||||
import { FromCoreProtocol } from "core/protocol";
|
||||
import { useAppDispatch, useAppSelector } from "../redux/hooks";
|
||||
import {
|
||||
selectCurrentToolCall,
|
||||
selectCurrentToolCallApplyState,
|
||||
} from "../redux/selectors/selectToolCalls";
|
||||
import { setConfigLoading, setConfigResult } from "../redux/slices/configSlice";
|
||||
import {
|
||||
setLastNonEditSessionEmpty,
|
||||
|
|
@ -55,13 +51,9 @@ function ParallelListeners() {
|
|||
(store) => store.profiles.selectedProfileId,
|
||||
);
|
||||
const hasDoneInitialConfigLoad = useRef(false);
|
||||
const currentToolCallApplyState = useAppSelector(
|
||||
selectCurrentToolCallApplyState,
|
||||
);
|
||||
const autoAcceptEditToolDiffs = useAppSelector(
|
||||
(store) => store.config.config.ui?.autoAcceptEditToolDiffs,
|
||||
);
|
||||
const currentToolCall = useAppSelector(selectCurrentToolCall);
|
||||
// Load symbols for chat on any session change
|
||||
const sessionId = useAppSelector((state) => state.session.id);
|
||||
|
||||
|
|
@ -274,11 +266,8 @@ function ParallelListeners() {
|
|||
// chat or agent
|
||||
dispatch(updateApplyState(state));
|
||||
|
||||
// Handle apply status updates that are associated with current tool call
|
||||
if (
|
||||
currentToolCallApplyState &&
|
||||
currentToolCallApplyState.streamId === state.streamId
|
||||
) {
|
||||
// Handle apply status updates - use toolCallId from event payload
|
||||
if (state.toolCallId) {
|
||||
if (state.status === "done" && autoAcceptEditToolDiffs) {
|
||||
ideMessenger.post("acceptDiff", {
|
||||
streamId: state.streamId,
|
||||
|
|
@ -286,15 +275,20 @@ function ParallelListeners() {
|
|||
});
|
||||
}
|
||||
if (state.status === "closed") {
|
||||
if (currentToolCall?.status !== "canceled") {
|
||||
// Find the tool call to check if it was canceled
|
||||
const toolCallState = findToolCallById(
|
||||
store.getState().session.history,
|
||||
state.toolCallId,
|
||||
);
|
||||
if (toolCallState && toolCallState.status !== "canceled") {
|
||||
dispatch(
|
||||
acceptToolCall({
|
||||
toolCallId: currentToolCallApplyState.toolCallId!,
|
||||
toolCallId: state.toolCallId,
|
||||
}),
|
||||
);
|
||||
void dispatch(
|
||||
streamResponseAfterToolCall({
|
||||
toolCallId: currentToolCallApplyState.toolCallId!,
|
||||
toolCallId: state.toolCallId,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
@ -308,12 +302,7 @@ function ParallelListeners() {
|
|||
}
|
||||
}
|
||||
},
|
||||
[
|
||||
currentToolCall,
|
||||
currentToolCallApplyState,
|
||||
autoAcceptEditToolDiffs,
|
||||
ideMessenger,
|
||||
],
|
||||
[autoAcceptEditToolDiffs, ideMessenger],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@ import { IdeMessengerContext } from "../../context/IdeMessenger";
|
|||
import { useWebviewListener } from "../../hooks/useWebviewListener";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import {
|
||||
selectCurrentToolCall,
|
||||
selectCurrentToolCallApplyState,
|
||||
selectPendingToolCalls,
|
||||
} from "../../redux/selectors/selectToolCalls";
|
||||
import {
|
||||
cancelToolCall,
|
||||
|
|
@ -141,9 +140,11 @@ export function Chat() {
|
|||
isStreaming,
|
||||
);
|
||||
|
||||
const currentToolCallState = useAppSelector(selectCurrentToolCall);
|
||||
const currentToolCallApplyState = useAppSelector(
|
||||
selectCurrentToolCallApplyState,
|
||||
const pendingToolCalls = useAppSelector(selectPendingToolCalls);
|
||||
const pendingApplyStates = useAppSelector(
|
||||
(state) => state.session.codeBlockApplyStates.states.filter(
|
||||
(applyState) => applyState.status === "done"
|
||||
)
|
||||
);
|
||||
|
||||
const sendInput = useCallback(
|
||||
|
|
@ -153,19 +154,21 @@ export function Chat() {
|
|||
index?: number,
|
||||
editorToClearOnSend?: Editor,
|
||||
) => {
|
||||
if (currentToolCallState) {
|
||||
// Cancel all pending tool calls
|
||||
pendingToolCalls.forEach((toolCallState) => {
|
||||
dispatch(
|
||||
cancelToolCall({
|
||||
toolCallId: currentToolCallState.toolCallId,
|
||||
toolCallId: toolCallState.toolCallId,
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (
|
||||
currentToolCallApplyState &&
|
||||
currentToolCallApplyState.status !== "closed"
|
||||
) {
|
||||
ideMessenger.post("rejectDiff", currentToolCallApplyState);
|
||||
}
|
||||
});
|
||||
|
||||
// Reject all pending apply states
|
||||
pendingApplyStates.forEach((applyState) => {
|
||||
if (applyState.status !== "closed") {
|
||||
ideMessenger.post("rejectDiff", applyState);
|
||||
}
|
||||
});
|
||||
const model = isInEdit
|
||||
? (selectedModels?.edit ?? selectedModels?.chat)
|
||||
: selectedModels?.chat;
|
||||
|
|
@ -222,8 +225,8 @@ export function Chat() {
|
|||
mode,
|
||||
isInEdit,
|
||||
codeToEdit,
|
||||
currentToolCallState,
|
||||
currentToolCallApplyState,
|
||||
pendingToolCalls,
|
||||
pendingApplyStates,
|
||||
],
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { RootState } from "../store";
|
|||
import {
|
||||
findAllCurToolCalls,
|
||||
findAllCurToolCallsByStatus,
|
||||
findToolCallById,
|
||||
hasCurrentToolCalls,
|
||||
} from "../util";
|
||||
|
||||
|
|
@ -26,12 +27,6 @@ export const selectToolCallsByStatus = createSelector(
|
|||
(history, status) => findAllCurToolCallsByStatus(history, status),
|
||||
);
|
||||
|
||||
// Convenience selectors for single tool calls
|
||||
export const selectCurrentToolCall = createSelector(
|
||||
selectCurrentToolCalls,
|
||||
(toolCalls) => toolCalls[0] || undefined,
|
||||
);
|
||||
|
||||
export const selectFirstPendingToolCall = createSelector(
|
||||
(store: RootState) => store.session.history,
|
||||
(history) => {
|
||||
|
|
@ -40,20 +35,22 @@ export const selectFirstPendingToolCall = createSelector(
|
|||
},
|
||||
);
|
||||
|
||||
// Apply state selectors
|
||||
export const selectCurrentToolCallApplyState = createSelector(
|
||||
// ID-based selectors for specific tool calls
|
||||
export const selectToolCallById = createSelector(
|
||||
[
|
||||
selectCurrentToolCalls,
|
||||
(store: RootState) => store.session.codeBlockApplyStates,
|
||||
(store: RootState) => store.session.history,
|
||||
(_store: RootState, toolCallId: string) => toolCallId,
|
||||
],
|
||||
(toolCalls, applyStates) => {
|
||||
if (toolCalls.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
const firstToolCall = toolCalls[0];
|
||||
return applyStates.states.find(
|
||||
(state) => state.toolCallId === firstToolCall.toolCallId,
|
||||
);
|
||||
(history, toolCallId) => findToolCallById(history, toolCallId),
|
||||
);
|
||||
|
||||
export const selectApplyStateByToolCallId = createSelector(
|
||||
[
|
||||
(store: RootState) => store.session.codeBlockApplyStates,
|
||||
(_store: RootState, toolCallId: string) => toolCallId,
|
||||
],
|
||||
(applyStates, toolCallId) => {
|
||||
return applyStates.states.find((state) => state.toolCallId === toolCallId);
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -35,10 +35,10 @@ async function handleToolCallExecution(
|
|||
const newState = getState();
|
||||
const toolSettings = newState.ui.toolSettings;
|
||||
const allToolCallStates = selectCurrentToolCalls(newState);
|
||||
|
||||
|
||||
// Only process tool calls that are in "generating" status (newly created during this streaming session)
|
||||
const toolCallStates = allToolCallStates.filter(
|
||||
(toolCallState) => toolCallState.status === "generating"
|
||||
(toolCallState) => toolCallState.status === "generating",
|
||||
);
|
||||
|
||||
// If no generating tool calls, nothing to process
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue