From c43d992f2b7054810b7752bc49c2646a7be5ed67 Mon Sep 17 00:00:00 2001 From: Joel Date: Wed, 25 Jun 2025 18:40:12 +0800 Subject: [PATCH] feat: fetch plugin list --- .../auto-update-setting/tool-picker.tsx | 16 ++++++++- web/service/use-plugins.ts | 33 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/web/app/components/plugins/reference-setting-modal/auto-update-setting/tool-picker.tsx b/web/app/components/plugins/reference-setting-modal/auto-update-setting/tool-picker.tsx index 5bcadcc3d4..9f96e4a7aa 100644 --- a/web/app/components/plugins/reference-setting-modal/auto-update-setting/tool-picker.tsx +++ b/web/app/components/plugins/reference-setting-modal/auto-update-setting/tool-picker.tsx @@ -1,11 +1,13 @@ 'use client' import type { FC } from 'react' -import React, { useCallback } from 'react' +import React, { useCallback, useState } from 'react' import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger, } from '@/app/components/base/portal-to-follow-elem' +import { useFetchPluginListOrBundleList } from '@/service/use-plugins' +import { PLUGIN_TYPE_SEARCH_MAP } from '../../marketplace/plugin-type-switch' type Props = { trigger: React.ReactNode @@ -16,6 +18,8 @@ type Props = { } +const allPluginTypes = [PLUGIN_TYPE_SEARCH_MAP.all, PLUGIN_TYPE_SEARCH_MAP.model, PLUGIN_TYPE_SEARCH_MAP.tool, PLUGIN_TYPE_SEARCH_MAP.agent, PLUGIN_TYPE_SEARCH_MAP.extension, PLUGIN_TYPE_SEARCH_MAP.bundle] + const ToolPicker: FC = ({ trigger, value, @@ -26,6 +30,16 @@ const ToolPicker: FC = ({ const toggleShowPopup = useCallback(() => { onShowChange(!isShow) }, [onShowChange, isShow]) + + const [pluginType, setPluginType] = useState(PLUGIN_TYPE_SEARCH_MAP.all) + const [query, setQuery] = useState('') + const { data } = useFetchPluginListOrBundleList({ + query, + category: pluginType, + }) + const isBundle = pluginType === PLUGIN_TYPE_SEARCH_MAP.bundle + const list = (isBundle ? data?.data?.bundles : data?.data?.plugins) || [] + console.log(list) return ( { + return useQuery({ + queryKey: [NAME_SPACE, 'fetchPluginListOrBundleList', pluginsSearchParams], + queryFn: () => { + const { + query, + sortBy, + sortOrder, + category, + tags, + exclude, + type, + page = 1, + pageSize = 40, + } = pluginsSearchParams + const pluginOrBundle = type === 'bundle' ? 'bundles' : 'plugins' + return postMarketplace<{ data: PluginsFromMarketplaceResponse }>(`/${pluginOrBundle}/search/advanced`, { + body: { + page, + page_size: pageSize, + query, + sort_by: sortBy, + sort_order: sortOrder, + category: category !== 'all' ? category : '', + tags, + exclude, + type, + }, + }) + }, + }) +} + export const useFetchPluginsInMarketPlaceByInfo = (infos: Record[]) => { return useQuery({ queryKey: [NAME_SPACE, 'fetchPluginsInMarketPlaceByInfo', infos],