@lobehub/chat
Version:
Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.
57 lines (46 loc) • 1.32 kB
text/typescript
import { produce } from 'immer';
import { LobeToolCustomPlugin } from '@/types/tool/plugin';
export type DevListState = LobeToolCustomPlugin[];
export type AddPluginAction = {
plugin: LobeToolCustomPlugin;
type: 'addItem';
};
export type DeletePluginAction = {
id: string;
type: 'deleteItem';
};
export type UpdatePluginAction = {
id: string;
plugin: LobeToolCustomPlugin;
type: 'updateItem';
};
export type CustomPluginListDispatch = AddPluginAction | DeletePluginAction | UpdatePluginAction;
export const devPluginListReducer = (
state: DevListState,
payload: CustomPluginListDispatch,
): DevListState => {
switch (payload.type) {
case 'addItem': {
return [...state, payload.plugin];
}
case 'deleteItem': {
return produce(state, (draftState) => {
const deleteIndex = state.findIndex((plugin) => plugin.identifier === payload.id);
if (deleteIndex !== -1) {
draftState.splice(deleteIndex, 1);
}
});
}
case 'updateItem': {
return produce(state, (draftState) => {
const updateIndex = state.findIndex((plugin) => plugin.identifier === payload.id);
if (updateIndex !== -1) {
draftState[updateIndex] = payload.plugin;
}
});
}
default: {
return state;
}
}
};