feat: remove the initialization of tool policy with useEffect, use the defaultToolPolicy as a fallback if a value has not been set by the user in selectActiveTools.ts
This commit is contained in:
parent
f3b71a353c
commit
fb44d5bad6
3 changed files with 10 additions and 31 deletions
|
|
@ -48,7 +48,6 @@ 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 {
|
||||
|
|
@ -126,23 +125,6 @@ export function Chat() {
|
|||
return isJetBrains();
|
||||
}, []);
|
||||
|
||||
const availableTools = useAppSelector((state) => state.config.config.tools);
|
||||
// Mark if initialized
|
||||
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(() => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { createSelector } from "@reduxjs/toolkit";
|
||||
import { Tool } from "core";
|
||||
import { BUILT_IN_GROUP_NAME } from "core/tools/builtIn";
|
||||
import { DEFAULT_TOOL_SETTING } from "../slices/uiSlice";
|
||||
import { RootState } from "../store";
|
||||
|
||||
export const selectActiveTools = createSelector(
|
||||
|
|
@ -14,11 +15,15 @@ export const selectActiveTools = createSelector(
|
|||
if (mode === "chat") {
|
||||
return [];
|
||||
} else {
|
||||
const enabledTools = tools.filter(
|
||||
(tool) =>
|
||||
policies[tool.function.name] !== "disabled" &&
|
||||
groupPolicies[tool.group] !== "exclude",
|
||||
);
|
||||
const enabledTools = tools.filter((tool) => {
|
||||
const toolPolicy =
|
||||
policies[tool.function.name] ??
|
||||
tool.defaultToolPolicy ??
|
||||
DEFAULT_TOOL_SETTING;
|
||||
return (
|
||||
toolPolicy !== "disabled" && groupPolicies[tool.group] !== "exclude"
|
||||
);
|
||||
});
|
||||
if (mode === "plan") {
|
||||
return enabledTools.filter(
|
||||
(t) => t.group !== BUILT_IN_GROUP_NAME || t.readonly,
|
||||
|
|
|
|||
|
|
@ -73,13 +73,6 @@ 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.defaultToolPolicy ?? DEFAULT_TOOL_SETTING;
|
||||
}
|
||||
},
|
||||
// Tools
|
||||
addTool: (state, action: PayloadAction<Tool>) => {
|
||||
state.toolSettings[action.payload.function.name] =
|
||||
|
|
@ -159,7 +152,6 @@ export const {
|
|||
clearToolPolicy,
|
||||
toggleToolGroupSetting,
|
||||
addTool,
|
||||
initTool,
|
||||
addRule,
|
||||
toggleRuleSetting,
|
||||
setTTSActive,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue