-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ refactor(plugin): 重构 plugin Store 组织结构,便于开发与迭代维护
- Loading branch information
Showing
17 changed files
with
142 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,9 @@ | ||
import { LobeChatPluginManifest, LobeChatPluginMeta } from '@lobehub/chat-plugin-sdk'; | ||
import { CustomPluginState, initialCustomPluginState } from './slices/customPlugin'; | ||
import { PluginState, initialPluginState } from './slices/plugin'; | ||
|
||
import { PluginManifestMap } from '@/types/plugin'; | ||
|
||
export type PluginManifestLoadingState = Record<string, boolean>; | ||
export type PluginsSettings = Record<string, any>; | ||
|
||
export interface DevPlugin extends LobeChatPluginMeta { | ||
apiMode: 'openapi' | 'simple'; | ||
enableSettings: boolean; | ||
manifestConfig?: LobeChatPluginManifest; | ||
manifestMode: 'local' | 'url'; | ||
} | ||
|
||
export interface PluginStoreState { | ||
devPluginList: DevPlugin[]; | ||
manifestPrepared: boolean; | ||
newDevPlugin: Partial<DevPlugin>; | ||
pluginList: LobeChatPluginMeta[]; | ||
pluginManifestLoading: PluginManifestLoadingState; | ||
pluginManifestMap: PluginManifestMap; | ||
pluginsSettings: PluginsSettings; | ||
} | ||
export const defaultDevPlugin: Partial<DevPlugin> = { | ||
apiMode: 'simple', | ||
enableSettings: false, | ||
manifestMode: 'url', | ||
}; | ||
export type PluginStoreState = PluginState & CustomPluginState; | ||
|
||
export const initialState: PluginStoreState = { | ||
devPluginList: [], | ||
manifestPrepared: false, | ||
newDevPlugin: defaultDevPlugin, | ||
pluginList: [], | ||
pluginManifestLoading: {}, | ||
pluginManifestMap: {}, | ||
pluginsSettings: {}, | ||
...initialPluginState, | ||
...initialCustomPluginState, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { merge } from 'lodash-es'; | ||
import { StateCreator } from 'zustand/vanilla'; | ||
|
||
import { CustomPlugin } from '@/types/plugin'; | ||
import { setNamespace } from '@/utils/storeDebug'; | ||
|
||
import { PluginStore } from '../../store'; | ||
import { defaultCustomPlugin } from './initialState'; | ||
import { CustomPluginListDispatch, devPluginListReducer } from './reducers/customPluginList'; | ||
|
||
const t = setNamespace('customPlugin'); | ||
|
||
/** | ||
* 代理行为接口 | ||
*/ | ||
export interface CustomPluginAction { | ||
dispatchCustomPluginList: (payload: CustomPluginListDispatch) => void; | ||
saveToCustomPluginList: (value: CustomPlugin) => void; | ||
updateNewDevPlugin: (value: Partial<CustomPlugin>) => void; | ||
} | ||
|
||
export const createCustomPluginSlice: StateCreator< | ||
PluginStore, | ||
[['zustand/devtools', never]], | ||
[], | ||
CustomPluginAction | ||
> = (set, get) => ({ | ||
dispatchCustomPluginList: (payload) => { | ||
const { customPluginList } = get(); | ||
|
||
const nextList = devPluginListReducer(customPluginList, payload); | ||
set({ customPluginList: nextList }, false, t('dispatchDevList', payload)); | ||
}, | ||
saveToCustomPluginList: (value) => { | ||
get().dispatchCustomPluginList({ plugin: value, type: 'addItem' }); | ||
set({ newCustomPlugin: defaultCustomPlugin }, false, t('saveToDevList')); | ||
}, | ||
|
||
updateNewDevPlugin: (newCustomPlugin) => { | ||
set( | ||
{ newCustomPlugin: merge({}, get().newCustomPlugin, newCustomPlugin) }, | ||
false, | ||
t('updateNewDevPlugin'), | ||
); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './action'; | ||
export * from './initialState'; | ||
// export * from './selectors'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { CustomPlugin } from '@/types/plugin'; | ||
|
||
export interface CustomPluginState { | ||
customPluginList: CustomPlugin[]; | ||
newCustomPlugin: Partial<CustomPlugin>; | ||
} | ||
export const defaultCustomPlugin: Partial<CustomPlugin> = { | ||
apiMode: 'simple', | ||
enableSettings: false, | ||
manifestMode: 'url', | ||
}; | ||
|
||
export const initialCustomPluginState: CustomPluginState = { | ||
customPluginList: [], | ||
newCustomPlugin: defaultCustomPlugin, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './action'; | ||
export * from './initialState'; | ||
// export * from './selectors'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { LobeChatPluginMeta } from '@lobehub/chat-plugin-sdk'; | ||
|
||
import { PluginManifestMap } from '@/types/plugin'; | ||
|
||
export type PluginManifestLoadingState = Record<string, boolean>; | ||
export type PluginsSettings = Record<string, any>; | ||
|
||
export interface PluginState { | ||
manifestPrepared: boolean; | ||
pluginList: LobeChatPluginMeta[]; | ||
pluginManifestLoading: PluginManifestLoadingState; | ||
pluginManifestMap: PluginManifestMap; | ||
pluginsSettings: PluginsSettings; | ||
} | ||
|
||
export const initialPluginState: PluginState = { | ||
manifestPrepared: false, | ||
pluginList: [], | ||
pluginManifestLoading: {}, | ||
pluginManifestMap: {}, | ||
pluginsSettings: {}, | ||
}; |
File renamed without changes.
Oops, something went wrong.