Merge branch 'feat/plugins' into dev/plugin-deploy
This commit is contained in:
commit
1272cf8fe7
@ -28,11 +28,12 @@ import {
|
|||||||
} from '@/service/common'
|
} from '@/service/common'
|
||||||
import { useProviderContext } from '@/context/provider-context'
|
import { useProviderContext } from '@/context/provider-context'
|
||||||
import {
|
import {
|
||||||
useMarketplaceCollectionsAndPlugins,
|
|
||||||
useMarketplacePlugins,
|
useMarketplacePlugins,
|
||||||
} from '@/app/components/plugins/marketplace/hooks'
|
} from '@/app/components/plugins/marketplace/hooks'
|
||||||
|
import type { Plugin } from '@/app/components/plugins/types'
|
||||||
import { PluginType } from '@/app/components/plugins/types'
|
import { PluginType } from '@/app/components/plugins/types'
|
||||||
import { getMarketplaceListCondition } from '@/app/components/plugins/marketplace/utils'
|
// import { getMarketplacePluginsByCollectionId } from '@/app/components/plugins/marketplace/utils'
|
||||||
|
import type { MarketplaceCollection } from '@/app/components/plugins/marketplace/types'
|
||||||
|
|
||||||
type UseDefaultModelAndModelList = (
|
type UseDefaultModelAndModelList = (
|
||||||
defaultModel: DefaultModelResponse | undefined,
|
defaultModel: DefaultModelResponse | undefined,
|
||||||
@ -241,21 +242,40 @@ export const useUpdateModelProviders = () => {
|
|||||||
return updateModelProviders
|
return updateModelProviders
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useMarketplace = (providers: ModelProvider[], searchText: string) => {
|
export const useMarketplace = () => {
|
||||||
const exclude = useMemo(() => {
|
const [marketplaceCollections] = useState<MarketplaceCollection[]>([])
|
||||||
return providers.map(provider => provider.provider.replace(/(.+)\/([^/]+)$/, '$1'))
|
const [marketplaceCollectionPluginsMap] = useState<Record<string, Plugin[]>>()
|
||||||
}, [providers])
|
const [isLoading] = useState(false)
|
||||||
const {
|
|
||||||
|
// const getCollectionPlugins = useCallback(async () => {
|
||||||
|
// setIsLoading(true)
|
||||||
|
// const collectionPlugins = await getMarketplacePluginsByCollectionId('')
|
||||||
|
// setIsLoading(false)
|
||||||
|
|
||||||
|
// setCollectionPlugins(collectionPlugins)
|
||||||
|
// }, [])
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// getCollectionPlugins()
|
||||||
|
// }, [getCollectionPlugins])
|
||||||
|
|
||||||
|
return {
|
||||||
isLoading,
|
isLoading,
|
||||||
marketplaceCollections,
|
marketplaceCollections,
|
||||||
marketplaceCollectionPluginsMap,
|
marketplaceCollectionPluginsMap,
|
||||||
queryMarketplaceCollectionsAndPlugins,
|
}
|
||||||
} = useMarketplaceCollectionsAndPlugins()
|
}
|
||||||
|
|
||||||
|
export const useMarketplaceAllPlugins = (providers: ModelProvider[], searchText: string) => {
|
||||||
|
const exclude = useMemo(() => {
|
||||||
|
return providers.map(provider => provider.provider.replace(/(.+)\/([^/]+)$/, '$1'))
|
||||||
|
}, [providers])
|
||||||
|
|
||||||
const {
|
const {
|
||||||
plugins,
|
plugins,
|
||||||
resetPlugins,
|
queryPlugins,
|
||||||
queryPluginsWithDebounced,
|
queryPluginsWithDebounced,
|
||||||
isLoading: isPluginsLoading,
|
isLoading,
|
||||||
} = useMarketplacePlugins()
|
} = useMarketplacePlugins()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -268,39 +288,15 @@ export const useMarketplace = (providers: ModelProvider[], searchText: string) =
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
queryMarketplaceCollectionsAndPlugins({
|
queryPlugins({
|
||||||
|
query: '',
|
||||||
category: PluginType.model,
|
category: PluginType.model,
|
||||||
condition: getMarketplaceListCondition(PluginType.model),
|
|
||||||
exclude,
|
|
||||||
type: 'plugin',
|
type: 'plugin',
|
||||||
|
pageSize: 1000,
|
||||||
|
exclude,
|
||||||
})
|
})
|
||||||
resetPlugins()
|
|
||||||
}
|
}
|
||||||
}, [searchText, queryMarketplaceCollectionsAndPlugins, queryPluginsWithDebounced, resetPlugins, exclude])
|
}, [queryPlugins, queryPluginsWithDebounced, searchText, exclude])
|
||||||
|
|
||||||
return {
|
|
||||||
isLoading: isLoading || isPluginsLoading,
|
|
||||||
marketplaceCollections,
|
|
||||||
marketplaceCollectionPluginsMap,
|
|
||||||
plugins: plugins?.filter(plugin => plugin.type !== 'bundle'),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useMarketplaceAllPlugins = () => {
|
|
||||||
const {
|
|
||||||
plugins,
|
|
||||||
queryPlugins,
|
|
||||||
isLoading,
|
|
||||||
} = useMarketplacePlugins()
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
queryPlugins({
|
|
||||||
query: '',
|
|
||||||
category: PluginType.model,
|
|
||||||
type: 'plugin',
|
|
||||||
pageSize: 1000,
|
|
||||||
})
|
|
||||||
}, [queryPlugins])
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
plugins: plugins?.filter(plugin => plugin.type !== 'bundle'),
|
plugins: plugins?.filter(plugin => plugin.type !== 'bundle'),
|
||||||
|
@ -122,15 +122,14 @@ const ModelProviderPage = ({ searchText }: Props) => {
|
|||||||
const [collapse, setCollapse] = useState(false)
|
const [collapse, setCollapse] = useState(false)
|
||||||
const locale = getLocaleOnClient()
|
const locale = getLocaleOnClient()
|
||||||
const {
|
const {
|
||||||
plugins,
|
|
||||||
marketplaceCollections,
|
marketplaceCollections,
|
||||||
marketplaceCollectionPluginsMap,
|
marketplaceCollectionPluginsMap,
|
||||||
isLoading: isPluginsLoading,
|
isLoading: isPluginsLoading,
|
||||||
} = useMarketplace(providers, searchText)
|
} = useMarketplace()
|
||||||
const {
|
const {
|
||||||
plugins: allPlugins,
|
plugins: allPlugins,
|
||||||
isLoading: isAllPluginsLoading,
|
isLoading: isAllPluginsLoading,
|
||||||
} = useMarketplaceAllPlugins()
|
} = useMarketplaceAllPlugins(providers, searchText)
|
||||||
|
|
||||||
const cardRender = useCallback((plugin: Plugin) => {
|
const cardRender = useCallback((plugin: Plugin) => {
|
||||||
if (plugin.type === 'bundle')
|
if (plugin.type === 'bundle')
|
||||||
@ -220,7 +219,7 @@ const ModelProviderPage = ({ searchText }: Props) => {
|
|||||||
<List
|
<List
|
||||||
marketplaceCollections={marketplaceCollections || []}
|
marketplaceCollections={marketplaceCollections || []}
|
||||||
marketplaceCollectionPluginsMap={marketplaceCollectionPluginsMap || {}}
|
marketplaceCollectionPluginsMap={marketplaceCollectionPluginsMap || {}}
|
||||||
plugins={plugins}
|
plugins={undefined}
|
||||||
showInstallButton
|
showInstallButton
|
||||||
locale={locale}
|
locale={locale}
|
||||||
cardContainerClassName='grid grid-cols-2 gap-2'
|
cardContainerClassName='grid grid-cols-2 gap-2'
|
||||||
|
@ -37,6 +37,36 @@ export const getPluginLinkInMarketplace = (plugin: Plugin) => {
|
|||||||
return `${MARKETPLACE_URL_PREFIX}/plugins/${plugin.org}/${plugin.name}`
|
return `${MARKETPLACE_URL_PREFIX}/plugins/${plugin.org}/${plugin.name}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getMarketplacePluginsByCollectionId = async (collectionId: string, query?: CollectionsAndPluginsSearchParams) => {
|
||||||
|
let plugins = [] as Plugin[]
|
||||||
|
|
||||||
|
try {
|
||||||
|
const url = `${MARKETPLACE_API_PREFIX}/collections/${collectionId}/plugins`
|
||||||
|
const marketplaceCollectionPluginsData = await globalThis.fetch(
|
||||||
|
url,
|
||||||
|
{
|
||||||
|
cache: 'no-store',
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
category: query?.category,
|
||||||
|
exclude: query?.exclude,
|
||||||
|
type: query?.type,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
const marketplaceCollectionPluginsDataJson = await marketplaceCollectionPluginsData.json()
|
||||||
|
plugins = marketplaceCollectionPluginsDataJson.data.plugins.map((plugin: Plugin) => {
|
||||||
|
return getFormattedPlugin(plugin)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line unused-imports/no-unused-vars
|
||||||
|
catch (e) {
|
||||||
|
plugins = []
|
||||||
|
}
|
||||||
|
|
||||||
|
return plugins
|
||||||
|
}
|
||||||
|
|
||||||
export const getMarketplaceCollectionsAndPlugins = async (query?: CollectionsAndPluginsSearchParams) => {
|
export const getMarketplaceCollectionsAndPlugins = async (query?: CollectionsAndPluginsSearchParams) => {
|
||||||
let marketplaceCollections = [] as MarketplaceCollection[]
|
let marketplaceCollections = [] as MarketplaceCollection[]
|
||||||
let marketplaceCollectionPluginsMap = {} as Record<string, Plugin[]>
|
let marketplaceCollectionPluginsMap = {} as Record<string, Plugin[]>
|
||||||
@ -50,23 +80,7 @@ export const getMarketplaceCollectionsAndPlugins = async (query?: CollectionsAnd
|
|||||||
const marketplaceCollectionsDataJson = await marketplaceCollectionsData.json()
|
const marketplaceCollectionsDataJson = await marketplaceCollectionsData.json()
|
||||||
marketplaceCollections = marketplaceCollectionsDataJson.data.collections
|
marketplaceCollections = marketplaceCollectionsDataJson.data.collections
|
||||||
await Promise.all(marketplaceCollections.map(async (collection: MarketplaceCollection) => {
|
await Promise.all(marketplaceCollections.map(async (collection: MarketplaceCollection) => {
|
||||||
const url = `${MARKETPLACE_API_PREFIX}/collections/${collection.name}/plugins`
|
const plugins = await getMarketplacePluginsByCollectionId(collection.name, query)
|
||||||
const marketplaceCollectionPluginsData = await globalThis.fetch(
|
|
||||||
url,
|
|
||||||
{
|
|
||||||
cache: 'no-store',
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify({
|
|
||||||
category: query?.category,
|
|
||||||
exclude: query?.exclude,
|
|
||||||
type: query?.type,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
const marketplaceCollectionPluginsDataJson = await marketplaceCollectionPluginsData.json()
|
|
||||||
const plugins = marketplaceCollectionPluginsDataJson.data.plugins.map((plugin: Plugin) => {
|
|
||||||
return getFormattedPlugin(plugin)
|
|
||||||
})
|
|
||||||
|
|
||||||
marketplaceCollectionPluginsMap[collection.name] = plugins
|
marketplaceCollectionPluginsMap[collection.name] = plugins
|
||||||
}))
|
}))
|
||||||
|
Loading…
Reference in New Issue
Block a user