mirror of
https://github.com/langgenius/dify.git
synced 2026-09-09 13:52:42 +08:00
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
'use client'
|
|
|
|
import type { ReactNode } from 'react'
|
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
import { consoleQuery } from '@/service/console'
|
|
import { commonQueryKeys } from '@/service/use-common'
|
|
import { ProviderContext } from './provider-context'
|
|
|
|
type ProviderContextProviderProps = {
|
|
children: ReactNode
|
|
}
|
|
|
|
export const ProviderContextProvider = ({ children }: ProviderContextProviderProps) => {
|
|
const queryClient = useQueryClient()
|
|
const {
|
|
data: providersData,
|
|
isLoading: isLoadingModelProviders,
|
|
isSuccess: isSuccessModelProviders,
|
|
} = useQuery(consoleQuery.workspaces.current.modelProviders.summary.get.queryOptions())
|
|
|
|
const refreshModelProviders = () =>
|
|
Promise.all([
|
|
queryClient.invalidateQueries({
|
|
queryKey: consoleQuery.workspaces.current.modelProviders.summary.get.key(),
|
|
}),
|
|
queryClient.invalidateQueries({ queryKey: commonQueryKeys.modelProviderDetails }),
|
|
]).then(() => undefined)
|
|
|
|
return (
|
|
<ProviderContext.Provider
|
|
value={{
|
|
modelProviders: providersData?.data || [],
|
|
modelProviderPlugins: providersData?.plugins || {},
|
|
isLoadingModelProviders,
|
|
isSuccessModelProviders,
|
|
refreshModelProviders,
|
|
}}
|
|
>
|
|
{children}
|
|
</ProviderContext.Provider>
|
|
)
|
|
}
|