Merge pull request #7022 from xiaohuanxiong3/fix-tool-execute-abnormal-when-there-is-no-tool-policy-data-in-the-local-cache

fix: fix tool execute abnormal when there is no tool policy data in the local cache
This commit is contained in:
Dallin Romney 2025-08-06 21:01:39 -07:00 • committed by GitHub
commit 162d7ddf20
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 15 deletions

View file

@ -287,7 +287,6 @@ describe("GUI Test", () => {
}).timeout(DEFAULT_TIMEOUT.MD);
it("should render tool call", async () => {
await GUIActions.toggleToolPolicy(view, "view_diff", 0);
const [messageInput] = await GUISelectors.getMessageInputFields(view);
await messageInput.sendKeys("Hello");
await messageInput.sendKeys(Key.ENTER);

View file

@ -14,6 +14,7 @@ import {
import { ThunkApiType } from "../store";
import { findToolCallById, logToolUsage } from "../util";
import { streamResponseAfterToolCall } from "./streamResponseAfterToolCall";
import { DEFAULT_TOOL_SETTING } from "../slices/uiSlice";
export const callToolById = createAsyncThunk<
void,
@ -36,9 +37,11 @@ export const callToolById = createAsyncThunk<
// Check if this is an auto-approved tool
const toolSettings = state.ui.toolSettings;
const isAutoApproved =
toolSettings[toolCallState.toolCall.function.name] ===
"allowedWithoutPermission";
const toolPolicy =
toolSettings[toolCallState.toolCall.function.name] ??
toolCallState.tool?.defaultToolPolicy ??
DEFAULT_TOOL_SETTING;
const isAutoApproved = toolPolicy === "allowedWithoutPermission";
posthog.capture("gui_tool_call_decision", {
decision: isAutoApproved ? "auto_accept" : "accept",

View file

@ -29,6 +29,7 @@ import { SystemMessageToolCodeblocksFramework } from "core/tools/systemMessageTo
import { selectCurrentToolCalls } from "../selectors/selectToolCalls";
import { getBaseSystemMessage } from "../util/getBaseSystemMessage";
import { callToolById } from "./callToolById";
import { DEFAULT_TOOL_SETTING } from "../slices/uiSlice";
/**
* Handles the execution of tool calls that may be automatically accepted.
* Sets all tools as generated first, then executes auto-approved tool calls.
@ -36,6 +37,7 @@ import { callToolById } from "./callToolById";
async function handleToolCallExecution(
dispatch: AppThunkDispatch,
getState: () => RootState,
activeTools: Tool[],
): Promise<void> {
const newState = getState();
const toolSettings = newState.ui.toolSettings;
@ -52,11 +54,15 @@ async function handleToolCallExecution(
}
// Check if ALL tool calls are auto-approved - if not, wait for user approval
const allAutoApproved = toolCallStates.every(
(toolCallState) =>
toolSettings[toolCallState.toolCall.function.name] ===
"allowedWithoutPermission",
);
const allAutoApproved = toolCallStates.every((toolCallState) => {
const toolPolicy =
toolSettings[toolCallState.toolCall.function.name] ??
activeTools.find(
(tool) => tool.function.name === toolCallState.toolCall.function.name,
)?.defaultToolPolicy ??
DEFAULT_TOOL_SETTING;
return toolPolicy == "allowedWithoutPermission";
});
// Set all tools as generated first
toolCallStates.forEach((toolCallState) => {
@ -298,11 +304,16 @@ export const streamNormalInput = createAsyncThunk<
// Check if ALL generating tool calls are auto-approved
const allAutoApproved =
generatingToolCalls.length > 0 &&
generatingToolCalls.every(
(toolCallState) =>
toolSettings[toolCallState.toolCall.function.name] ===
"allowedWithoutPermission",
);
generatingToolCalls.every((toolCallState) => {
const toolPolicy =
toolSettings[toolCallState.toolCall.function.name] ??
activeTools.find(
(tool) =>
tool.function.name === toolCallState.toolCall.function.name,
)?.defaultToolPolicy ??
DEFAULT_TOOL_SETTING;
return toolPolicy == "allowedWithoutPermission";
});
// Only set inactive if:
// 1. There are no tool calls, OR
@ -312,6 +323,6 @@ export const streamNormalInput = createAsyncThunk<
dispatch(setInactive());
}
await handleToolCallExecution(dispatch, getState);
await handleToolCallExecution(dispatch, getState, activeTools);
},
);