feat: chat in explore support agent (#647)
Co-authored-by: StyleZhang <jasonapring2015@outlook.com>
This commit is contained in:
35
web/context/provider-context.tsx
Normal file
35
web/context/provider-context.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
'use client'
|
||||
|
||||
import { createContext, useContext } from 'use-context-selector'
|
||||
import useSWR from 'swr'
|
||||
import { fetchTenantInfo } from '@/service/common'
|
||||
|
||||
const ProviderContext = createContext<{ currentProvider: {
|
||||
provider: string
|
||||
provider_name: string
|
||||
token_is_set: boolean
|
||||
is_valid: boolean
|
||||
token_is_valid: boolean
|
||||
} | null | undefined }>({
|
||||
currentProvider: null,
|
||||
})
|
||||
|
||||
export const useProviderContext = () => useContext(ProviderContext)
|
||||
|
||||
type ProviderContextProviderProps = {
|
||||
children: React.ReactNode
|
||||
}
|
||||
export const ProviderContextProvider = ({
|
||||
children,
|
||||
}: ProviderContextProviderProps) => {
|
||||
const { data: userInfo } = useSWR({ url: '/info' }, fetchTenantInfo)
|
||||
const currentProvider = userInfo?.providers?.find(({ token_is_set, is_valid }) => token_is_set && is_valid)
|
||||
|
||||
return (
|
||||
<ProviderContext.Provider value={{ currentProvider }}>
|
||||
{children}
|
||||
</ProviderContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export default ProviderContext
|
Reference in New Issue
Block a user