diff --git a/src/features/AgentSetting/AgentPlugin/LocalPluginItem.tsx b/src/features/AgentSetting/AgentPlugin/LocalPluginItem.tsx index fc196eb495c8..253a724d0a64 100644 --- a/src/features/AgentSetting/AgentPlugin/LocalPluginItem.tsx +++ b/src/features/AgentSetting/AgentPlugin/LocalPluginItem.tsx @@ -17,11 +17,13 @@ const MarketList = memo<{ id: string }>(({ id }) => { const updateConfig = useStore((s) => s.toggleAgentPlugin); const [plugins, hasPlugin] = useStore((s) => [s.config.plugins || [], !!s.config.plugins]); - const [useFetchPluginList, fetchPluginManifest, dispatchDevPluginList] = usePluginStore((s) => [ - s.useFetchPluginList, - s.fetchPluginManifest, - s.dispatchCustomPluginList, - ]); + const [useFetchPluginList, fetchPluginManifest, deleteCustomPlugin, updateCustomPlugin] = + usePluginStore((s) => [ + s.useFetchPluginList, + s.fetchPluginManifest, + s.deleteCustomPlugin, + s.updateCustomPlugin, + ]); const pluginManifestLoading = usePluginStore((s) => s.pluginManifestLoading, isEqual); const devPlugin = usePluginStore(pluginSelectors.getDevPluginById(id), isEqual); @@ -33,11 +35,11 @@ const MarketList = memo<{ id: string }>(({ id }) => { { - dispatchDevPluginList({ id, type: 'deleteItem' }); + deleteCustomPlugin(id); }} onOpenChange={setModal} onSave={(value) => { - dispatchDevPluginList({ id, plugin: value, type: 'updateItem' }); + updateCustomPlugin(id, value); }} open={showModal} value={devPlugin} diff --git a/src/features/AgentSetting/AgentPlugin/MarketList.tsx b/src/features/AgentSetting/AgentPlugin/MarketList.tsx index a85347eafb5b..f1dacc99db8b 100644 --- a/src/features/AgentSetting/AgentPlugin/MarketList.tsx +++ b/src/features/AgentSetting/AgentPlugin/MarketList.tsx @@ -52,14 +52,22 @@ const MarketList = memo(() => { s.useFetchPluginList, s.fetchPluginManifest, s.saveToCustomPluginList, - s.updateNewDevPlugin, + s.updateNewCustomPlugin, ]); const pluginManifestLoading = usePluginStore((s) => s.pluginManifestLoading, isEqual); const pluginList = usePluginStore((s) => s.pluginList, isEqual); - const devPluginList = usePluginStore((s) => s.customPluginList, isEqual); + const customPluginList = usePluginStore((s) => s.customPluginList, isEqual); useFetchPluginList(); + const togglePlugin = async (pluginId: string, fetchManifest?: boolean) => { + toggleAgentPlugin(pluginId); + if (fetchManifest) { + await fetchPluginManifest(pluginId); + } + }; + + // =========== Skeleton Loading =========== // const loadingItem = { avatar: ( { /> ), }; - const loadingList = [loadingItem, loadingItem, loadingItem]; const isEmpty = pluginList.length === 0; + // =========== Plugin List =========== // + const list = pluginList.map(({ identifier, meta }) => ({ avatar: , children: ( @@ -95,10 +104,7 @@ const MarketList = memo(() => { } loading={pluginManifestLoading[identifier]} onChange={(checked) => { - toggleAgentPlugin(identifier); - if (checked) { - fetchPluginManifest(identifier); - } + togglePlugin(identifier, checked); }} /> ), @@ -108,7 +114,9 @@ const MarketList = memo(() => { tag: identifier, })); - const devList = devPluginList.map(({ identifier, meta }) => ({ + // =========== Custom Plugin List =========== // + + const customList = customPluginList.map(({ identifier, meta }) => ({ avatar: , children: , desc: pluginHelpers.getPluginDesc(meta), @@ -128,11 +136,11 @@ const MarketList = memo(() => { <> { + onSave={async (devPlugin) => { // 先保存 saveToDevList(devPlugin); - // 再开启 - toggleAgentPlugin(devPlugin.identifier); + // 再开启插件 + await togglePlugin(devPlugin.identifier, true); }} onValueChange={updateNewDevPlugin} open={showModal} @@ -140,7 +148,7 @@ const MarketList = memo(() => {