From 9e28c7a4eb3d863ad52b52a2da88c76dfc67ade2 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 22 Aug 2025 09:14:23 +0530 Subject: [PATCH] feat: continue tool calls after rejection --- core/config/sharedConfig.ts | 6 +++ core/index.d.ts | 1 + gui/src/pages/config/UserSettingsForm.tsx | 12 +++++ gui/src/redux/thunks/cancelToolCall.ts | 45 ++++++++++++++++++- .../thunks/streamResponseAfterToolCall.ts | 13 +++++- 5 files changed, 74 insertions(+), 3 deletions(-) diff --git a/core/config/sharedConfig.ts b/core/config/sharedConfig.ts index 85a0c084a..52b96061a 100644 --- a/core/config/sharedConfig.ts +++ b/core/config/sharedConfig.ts @@ -32,6 +32,7 @@ export const sharedConfigSchema = z displayRawMarkdown: z.boolean(), showChatScrollbar: z.boolean(), autoAcceptEditToolDiffs: z.boolean(), + continueAfterToolRejection: z.boolean(), // `tabAutocompleteOptions` in `ContinueConfig` useAutocompleteCache: z.boolean(), @@ -158,6 +159,11 @@ export function modifyAnyConfigWithSharedConfig< configCopy.ui.showSessionTabs = sharedConfig.showSessionTabs; } + if (sharedConfig.continueAfterToolRejection !== undefined) { + configCopy.ui.continueAfterToolRejection = + sharedConfig.continueAfterToolRejection; + } + configCopy.experimental = { ...configCopy.experimental, }; diff --git a/core/index.d.ts b/core/index.d.ts index 90039f025..033a51542 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1343,6 +1343,7 @@ export interface ContinueUIConfig { codeWrap?: boolean; showSessionTabs?: boolean; autoAcceptEditToolDiffs?: boolean; + continueAfterToolRejection?: boolean; } export interface ContextMenuConfig { diff --git a/gui/src/pages/config/UserSettingsForm.tsx b/gui/src/pages/config/UserSettingsForm.tsx index a27e58230..bbff49f6a 100644 --- a/gui/src/pages/config/UserSettingsForm.tsx +++ b/gui/src/pages/config/UserSettingsForm.tsx @@ -82,6 +82,8 @@ export function UserSettingsForm() { // TODO defaults are in multiple places, should be consolidated and probably not explicit here const showSessionTabs = config.ui?.showSessionTabs ?? false; + const continueAfterToolRejection = + config.ui?.continueAfterToolRejection ?? false; const codeWrap = config.ui?.codeWrap ?? false; const showChatScrollbar = config.ui?.showChatScrollbar ?? false; const readResponseTTS = config.experimental?.readResponseTTS ?? false; @@ -449,6 +451,16 @@ export function UserSettingsForm() { text="@Codebase: use tool calling only" /> + + handleUpdate({ + continueAfterToolRejection: !continueAfterToolRejection, + }) + } + text="Stream after tool rejection" + /> + {hasContinueEmail && ( ("chat/cancelToolCall", async ({ toolCallId }, { dispatch, getState }) => { const state = getState(); + const continueAfterToolRejection = + state.config.config.ui?.continueAfterToolRejection ?? false; const toolCallState = findToolCallById(state.session.history, toolCallId); if (toolCallState) { @@ -21,6 +34,36 @@ export const cancelToolCallThunk = createAsyncThunk< }); } + if (continueAfterToolRejection) { + // Update tool call output with rejection message + dispatch( + updateToolCallOutput({ + toolCallId, + contextItems: [ + { + icon: "problems", + name: "Tool Call Rejected", + description: "User skipped the tool call", + content: DEFAULT_USER_REJECTION_MESSAGE, + hidden: false, + }, + ], + }), + ); + } + // Dispatch the actual cancel action dispatch(cancelToolCallAction({ toolCallId })); + + if (continueAfterToolRejection) { + const rejectionMessage: ChatMessage = { + role: "tool", + content: "User skipped the tool call", + toolCallId, + }; + dispatch(streamUpdate([rejectionMessage])); + + // Continue the conversation by triggering a new LLM response + void dispatch(streamNormalInput({})); + } }); diff --git a/gui/src/redux/thunks/streamResponseAfterToolCall.ts b/gui/src/redux/thunks/streamResponseAfterToolCall.ts index fd04fc1e1..5b5cf2b43 100644 --- a/gui/src/redux/thunks/streamResponseAfterToolCall.ts +++ b/gui/src/redux/thunks/streamResponseAfterToolCall.ts @@ -16,6 +16,7 @@ import { streamThunkWrapper } from "./streamThunkWrapper"; */ function areAllToolsDoneStreaming( assistantMessage: ChatHistoryItemWithMessageId | undefined, + continueAfterToolRejection: boolean, ): boolean { // This might occur because of race conditions, if so, the tools are completed if (!assistantMessage?.toolCallStates) { @@ -24,7 +25,10 @@ function areAllToolsDoneStreaming( // Only continue if all tool calls are complete const completedToolCalls = assistantMessage.toolCallStates.filter( - (tc) => tc.status === "done" || tc.status === "errored", + (tc) => + tc.status === "done" || + tc.status === "errored" || + (continueAfterToolRejection && tc.status === "canceled"), ); return completedToolCalls.length === assistantMessage.toolCallStates.length; @@ -71,7 +75,12 @@ export const streamResponseAfterToolCall = createAsyncThunk< item.toolCallStates?.some((tc) => tc.toolCallId === toolCallId), ); - if (areAllToolsDoneStreaming(assistantMessage)) { + if ( + areAllToolsDoneStreaming( + assistantMessage, + state.config.config.ui?.continueAfterToolRejection ?? false, + ) + ) { unwrapResult(await dispatch(streamNormalInput({}))); } }),