Skip to content

Commit 0e35c18

Browse files
committed
🐛 fix: 修正删除插件时错误开启的问题
1 parent 27f8d6d commit 0e35c18

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/features/AgentSetting/AgentPlugin/LocalPluginItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const MarketList = memo<{ id: string }>(({ id }) => {
3636
mode={'edit'}
3737
onDelete={() => {
3838
deleteCustomPlugin(id);
39-
toggleAgentPlugin(id);
39+
toggleAgentPlugin(id, false);
4040
}}
4141
onOpenChange={setModal}
4242
onSave={(value) => {

src/features/AgentSetting/store/action.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface Action {
4848

4949
setAgentMeta: (meta: Partial<MetaData>) => void;
5050
streamUpdateMeta: (key: keyof MetaData) => any;
51-
toggleAgentPlugin: (pluginId: string) => void;
51+
toggleAgentPlugin: (pluginId: string, state?: boolean) => void;
5252
/**
5353
* 更新加载状态
5454
* @param key - SessionLoadingState 的键
@@ -198,8 +198,8 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
198198
};
199199
},
200200

201-
toggleAgentPlugin: (id) => {
202-
get().dispatchConfig({ pluginId: id, type: 'togglePlugin' });
201+
toggleAgentPlugin: (id, state) => {
202+
get().dispatchConfig({ pluginId: id, state, type: 'togglePlugin' });
203203
},
204204

205205
updateLoadingState: (key, value) => {

src/features/AgentSetting/store/reducers/config.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { merge } from '@/utils/merge';
66

77
export type ConfigDispatch =
88
| { config: Partial<any>; type: 'update' }
9-
| { pluginId: string; type: 'togglePlugin' }
9+
| { pluginId: string; state?: boolean; type: 'togglePlugin' }
1010
| { type: 'reset' };
1111

1212
export const configReducer = (state: LobeAgentConfig, payload: ConfigDispatch): LobeAgentConfig => {
@@ -19,15 +19,26 @@ export const configReducer = (state: LobeAgentConfig, payload: ConfigDispatch):
1919

2020
case 'togglePlugin': {
2121
return produce(state, (config) => {
22-
const { pluginId: id } = payload;
22+
const { pluginId: id, state } = payload;
2323
if (config.plugins === undefined) {
24-
config.plugins = [id];
25-
} else {
24+
config.plugins = [];
25+
}
26+
27+
if (typeof state === 'undefined') {
2628
if (config.plugins.includes(id)) {
2729
config.plugins.splice(config.plugins.indexOf(id), 1);
28-
} else {
29-
config.plugins.push(id);
30+
31+
return;
3032
}
33+
34+
config.plugins.push(id);
35+
return;
36+
}
37+
38+
if (!state) {
39+
config.plugins = config.plugins.filter((pluginId) => pluginId !== id);
40+
} else {
41+
config.plugins.push(id);
3142
}
3243
});
3344
}

0 commit comments

Comments
 (0)