From d1b7b2df59b24a2f7b8b9bd8ee89830d4a729aa3 Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Wed, 23 Jul 2025 13:32:51 +0800 Subject: [PATCH] feat: Add the initialization uiSlice.toolSettings logic. fix: attempt pass GUI.test.ts --- extensions/vscode/e2e/tests/GUI.test.ts | 6 +++--- gui/src/pages/gui/Chat.tsx | 18 ++++++++++++++++++ gui/src/redux/slices/uiSlice.ts | 8 ++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index 41b3befbf..2c1be987e 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -288,7 +288,7 @@ describe("GUI Test", () => { it("should render tool call", async () => { // all tool's toolSettings here defaults to ? - await GUIActions.toggleToolPolicy(view, "view_diff", 2); + // await GUIActions.toggleToolPolicy(view, "view_diff", 0); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); @@ -308,7 +308,7 @@ describe("GUI Test", () => { it("should call tool after approval", async () => { // all tool's toolSettings here defaults to ? - await GUIActions.toggleToolPolicy(view, "view_diff", 2); + // await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); @@ -330,7 +330,7 @@ describe("GUI Test", () => { it("should cancel tool", async () => { // all tool's toolSettings here defaults to ? - // await GUIActions.toggleToolPolicy(view, "view_diff", 1); + await GUIActions.toggleToolPolicy(view, "view_diff", 2); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 7b05087d8..ab1ab53b0 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -48,6 +48,7 @@ import { cancelStream } from "../../redux/thunks/cancelStream"; import { EmptyChatBody } from "./EmptyChatBody"; import { ExploreDialogWatcher } from "./ExploreDialogWatcher"; import { useAutoScroll } from "./useAutoScroll"; +import { initTool } from "../../redux/slices/uiSlice"; // Helper function to find the index of the latest conversation summary function findLatestSummaryIndex(history: ChatHistoryItem[]): number { @@ -125,6 +126,23 @@ export function Chat() { return isJetBrains(); }, []); + const availableTools = useAppSelector((state) => state.config.config.tools); + // 标记是否已初始化 + const [toolSettingsInitialized, setToolSettingsInitialized] = useState(false); + + useEffect(() => { + if ( + !toolSettingsInitialized && + Array.isArray(availableTools) && + availableTools.length > 0 + ) { + for (const tool of availableTools) { + dispatch(initTool(tool)); + } + setToolSettingsInitialized(true); + } + }, [availableTools, toolSettingsInitialized, dispatch]); + useAutoScroll(stepsDivRef, history); useEffect(() => { diff --git a/gui/src/redux/slices/uiSlice.ts b/gui/src/redux/slices/uiSlice.ts index 4f9c10e95..cbce3134a 100644 --- a/gui/src/redux/slices/uiSlice.ts +++ b/gui/src/redux/slices/uiSlice.ts @@ -87,6 +87,13 @@ export const uiSlice = createSlice({ ) => { state.isExploreDialogOpen = action.payload; }, + // Initialize when there is no toolSetting data in the cache + initTool: (state, action: PayloadAction) => { + if (!state.toolSettings[action.payload.function.name]) { + state.toolSettings[action.payload.function.name] = + action.payload.toolPolicy ?? DEFAULT_TOOL_SETTING; + } + }, // Tools addTool: (state, action: PayloadAction) => { state.toolSettings[action.payload.function.name] = @@ -166,6 +173,7 @@ export const { clearToolPolicy, toggleToolGroupSetting, addTool, + initTool, addRule, toggleRuleSetting, setTTSActive,