feat: Add the initialization uiSlice.toolSettings logic.
fix: attempt pass GUI.test.ts
This commit is contained in:
parent
8ad03dc4e5
commit
d1b7b2df59
3 changed files with 29 additions and 3 deletions
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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(() => {
|
||||
|
|
|
|||
|
|
@ -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<Tool>) => {
|
||||
if (!state.toolSettings[action.payload.function.name]) {
|
||||
state.toolSettings[action.payload.function.name] =
|
||||
action.payload.toolPolicy ?? DEFAULT_TOOL_SETTING;
|
||||
}
|
||||
},
|
||||
// Tools
|
||||
addTool: (state, action: PayloadAction<Tool>) => {
|
||||
state.toolSettings[action.payload.function.name] =
|
||||
|
|
@ -166,6 +173,7 @@ export const {
|
|||
clearToolPolicy,
|
||||
toggleToolGroupSetting,
|
||||
addTool,
|
||||
initTool,
|
||||
addRule,
|
||||
toggleRuleSetting,
|
||||
setTTSActive,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue