🤷♂️
diff --git a/web/app/signin/invite-settings/page.tsx b/web/app/signin/invite-settings/page.tsx
index cbd37f51f6..de8d6c60ea 100644
--- a/web/app/signin/invite-settings/page.tsx
+++ b/web/app/signin/invite-settings/page.tsx
@@ -5,7 +5,6 @@ import { useCallback, useState } from 'react'
import Link from 'next/link'
import { useContext } from 'use-context-selector'
import { useRouter, useSearchParams } from 'next/navigation'
-import useSWR from 'swr'
import { RiAccountCircleLine } from '@remixicon/react'
import Input from '@/app/components/base/input'
import { SimpleSelect } from '@/app/components/base/select'
@@ -13,12 +12,13 @@ import Button from '@/app/components/base/button'
import { timezones } from '@/utils/timezone'
import { LanguagesSupported, languages } from '@/i18n-config/language'
import I18n from '@/context/i18n'
-import { activateMember, invitationCheck } from '@/service/common'
+import { activateMember } from '@/service/common'
import Loading from '@/app/components/base/loading'
import Toast from '@/app/components/base/toast'
import { noop } from 'lodash-es'
import { useGlobalPublicStore } from '@/context/global-public-context'
import { resolvePostLoginRedirect } from '../utils/post-login-redirect'
+import { useInvitationCheck } from '@/service/use-common'
export default function InviteSettingsPage() {
const { t } = useTranslation()
@@ -38,9 +38,7 @@ export default function InviteSettingsPage() {
token,
},
}
- const { data: checkRes, mutate: recheck } = useSWR(checkParams, invitationCheck, {
- revalidateOnFocus: false,
- })
+ const { data: checkRes, refetch: recheck } = useInvitationCheck(checkParams.params, !!token)
const handleActivate = useCallback(async () => {
try {
diff --git a/web/app/signin/one-more-step.tsx b/web/app/signin/one-more-step.tsx
index 3293caa8f5..4b20f85681 100644
--- a/web/app/signin/one-more-step.tsx
+++ b/web/app/signin/one-more-step.tsx
@@ -1,8 +1,7 @@
'use client'
-import React, { type Reducer, useEffect, useReducer } from 'react'
+import React, { type Reducer, useReducer } from 'react'
import { useTranslation } from 'react-i18next'
import Link from 'next/link'
-import useSWR from 'swr'
import { useRouter, useSearchParams } from 'next/navigation'
import Input from '../components/base/input'
import Button from '@/app/components/base/button'
@@ -10,12 +9,11 @@ import Tooltip from '@/app/components/base/tooltip'
import { SimpleSelect } from '@/app/components/base/select'
import { timezones } from '@/utils/timezone'
import { LanguagesSupported, languages } from '@/i18n-config/language'
-import { oneMoreStep } from '@/service/common'
import Toast from '@/app/components/base/toast'
import { useDocLink } from '@/context/i18n'
+import { useOneMoreStep } from '@/service/use-common'
type IState = {
- formState: 'processing' | 'error' | 'success' | 'initial'
invitation_code: string
interface_language: string
timezone: string
@@ -26,7 +24,6 @@ type IAction
| { type: 'invitation_code', value: string }
| { type: 'interface_language', value: string }
| { type: 'timezone', value: string }
- | { type: 'formState', value: 'processing' }
const reducer: Reducer
= (state: IState, action: IAction) => {
switch (action.type) {
@@ -36,11 +33,8 @@ const reducer: Reducer = (state: IState, action: IAction) => {
return { ...state, interface_language: action.value }
case 'timezone':
return { ...state, timezone: action.value }
- case 'formState':
- return { ...state, formState: action.value }
case 'failed':
return {
- formState: 'initial',
invitation_code: '',
interface_language: 'en-US',
timezone: 'Asia/Shanghai',
@@ -57,30 +51,29 @@ const OneMoreStep = () => {
const searchParams = useSearchParams()
const [state, dispatch] = useReducer(reducer, {
- formState: 'initial',
invitation_code: searchParams.get('invitation_code') || '',
interface_language: 'en-US',
timezone: 'Asia/Shanghai',
})
- const { data, error } = useSWR(state.formState === 'processing'
- ? {
- url: '/account/init',
- body: {
+ const { mutateAsync: submitOneMoreStep, isPending } = useOneMoreStep()
+
+ const handleSubmit = async () => {
+ if (isPending)
+ return
+ try {
+ await submitOneMoreStep({
invitation_code: state.invitation_code,
interface_language: state.interface_language,
timezone: state.timezone,
- },
+ })
+ router.push('/apps')
}
- : null, oneMoreStep)
-
- useEffect(() => {
- if (error && error.status === 400) {
- Toast.notify({ type: 'error', message: t('login.invalidInvitationCode') })
+ catch (error: any) {
+ if (error && error.status === 400)
+ Toast.notify({ type: 'error', message: t('login.invalidInvitationCode') })
dispatch({ type: 'failed', payload: null })
}
- if (data)
- router.push('/apps')
- }, [data, error])
+ }
return (
<>
@@ -151,10 +144,8 @@ const OneMoreStep = () => {
diff --git a/web/context/app-context.tsx b/web/context/app-context.tsx
index 426ef2217e..48d67c3611 100644
--- a/web/context/app-context.tsx
+++ b/web/context/app-context.tsx
@@ -1,10 +1,14 @@
'use client'
-import { useCallback, useEffect, useMemo, useState } from 'react'
-import useSWR from 'swr'
+import { useCallback, useEffect, useMemo } from 'react'
import { createContext, useContext, useContextSelector } from 'use-context-selector'
import type { FC, ReactNode } from 'react'
-import { fetchCurrentWorkspace, fetchLangGeniusVersion, fetchUserProfile } from '@/service/common'
+import { useQueryClient } from '@tanstack/react-query'
+import {
+ useCurrentWorkspace,
+ useLangGeniusVersion,
+ useUserProfile,
+} from '@/service/use-common'
import type { ICurrentWorkspace, LangGeniusVersionResponse, UserProfileResponse } from '@/models/common'
import MaintenanceNotice from '@/app/components/header/maintenance-notice'
import { noop } from 'lodash-es'
@@ -79,48 +83,44 @@ export type AppContextProviderProps = {
}
export const AppContextProvider: FC = ({ children }) => {
+ const queryClient = useQueryClient()
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
- const { data: userProfileResponse, mutate: mutateUserProfile, error: userProfileError } = useSWR({ url: '/account/profile', params: {} }, fetchUserProfile)
- const { data: currentWorkspaceResponse, mutate: mutateCurrentWorkspace, isLoading: isLoadingCurrentWorkspace } = useSWR({ url: '/workspaces/current', params: {} }, fetchCurrentWorkspace)
+ const { data: userProfileResp } = useUserProfile()
+ const { data: currentWorkspaceResp, isPending: isLoadingCurrentWorkspace } = useCurrentWorkspace()
+ const langGeniusVersionQuery = useLangGeniusVersion(
+ userProfileResp?.meta.currentVersion,
+ !systemFeatures.branding.enabled,
+ )
+
+ const userProfile = useMemo(() => userProfileResp?.profile || userProfilePlaceholder, [userProfileResp?.profile])
+ const currentWorkspace = useMemo(() => currentWorkspaceResp || initialWorkspaceInfo, [currentWorkspaceResp])
+ const langGeniusVersionInfo = useMemo(() => {
+ if (!userProfileResp?.meta?.currentVersion || !langGeniusVersionQuery.data)
+ return initialLangGeniusVersionInfo
+
+ const current_version = userProfileResp.meta.currentVersion
+ const current_env = userProfileResp.meta.currentEnv || ''
+ const versionData = langGeniusVersionQuery.data
+ return {
+ ...versionData,
+ current_version,
+ latest_version: versionData.version,
+ current_env,
+ }
+ }, [langGeniusVersionQuery.data, userProfileResp?.meta])
- const [userProfile, setUserProfile] = useState(userProfilePlaceholder)
- const [langGeniusVersionInfo, setLangGeniusVersionInfo] = useState(initialLangGeniusVersionInfo)
- const [currentWorkspace, setCurrentWorkspace] = useState(initialWorkspaceInfo)
const isCurrentWorkspaceManager = useMemo(() => ['owner', 'admin'].includes(currentWorkspace.role), [currentWorkspace.role])
const isCurrentWorkspaceOwner = useMemo(() => currentWorkspace.role === 'owner', [currentWorkspace.role])
const isCurrentWorkspaceEditor = useMemo(() => ['owner', 'admin', 'editor'].includes(currentWorkspace.role), [currentWorkspace.role])
const isCurrentWorkspaceDatasetOperator = useMemo(() => currentWorkspace.role === 'dataset_operator', [currentWorkspace.role])
- const updateUserProfileAndVersion = useCallback(async () => {
- if (userProfileResponse && !userProfileResponse.bodyUsed) {
- try {
- const result = await userProfileResponse.json()
- setUserProfile(result)
- if (!systemFeatures.branding.enabled) {
- const current_version = userProfileResponse.headers.get('x-version')
- const current_env = process.env.NODE_ENV === 'development' ? 'DEVELOPMENT' : userProfileResponse.headers.get('x-env')
- const versionData = await fetchLangGeniusVersion({ url: '/version', params: { current_version } })
- setLangGeniusVersionInfo({ ...versionData, current_version, latest_version: versionData.version, current_env })
- }
- }
- catch (error) {
- console.error('Failed to update user profile:', error)
- if (userProfile.id === '')
- setUserProfile(userProfilePlaceholder)
- }
- }
- else if (userProfileError && userProfile.id === '') {
- setUserProfile(userProfilePlaceholder)
- }
- }, [userProfileResponse, userProfileError, userProfile.id])
- useEffect(() => {
- updateUserProfileAndVersion()
- }, [updateUserProfileAndVersion, userProfileResponse])
+ const mutateUserProfile = useCallback(() => {
+ queryClient.invalidateQueries({ queryKey: ['common', 'user-profile'] })
+ }, [queryClient])
- useEffect(() => {
- if (currentWorkspaceResponse)
- setCurrentWorkspace(currentWorkspaceResponse)
- }, [currentWorkspaceResponse])
+ const mutateCurrentWorkspace = useCallback(() => {
+ queryClient.invalidateQueries({ queryKey: ['common', 'current-workspace'] })
+ }, [queryClient])
// #region Zendesk conversation fields
useEffect(() => {
diff --git a/web/context/provider-context.tsx b/web/context/provider-context.tsx
index 70944d85f1..e1739853c6 100644
--- a/web/context/provider-context.tsx
+++ b/web/context/provider-context.tsx
@@ -1,15 +1,15 @@
'use client'
import { createContext, useContext, useContextSelector } from 'use-context-selector'
-import useSWR from 'swr'
import { useEffect, useState } from 'react'
import dayjs from 'dayjs'
import { useTranslation } from 'react-i18next'
+import { useQueryClient } from '@tanstack/react-query'
import {
- fetchModelList,
- fetchModelProviders,
- fetchSupportRetrievalMethods,
-} from '@/service/common'
+ useModelListByType,
+ useModelProviders,
+ useSupportRetrievalMethods,
+} from '@/service/use-common'
import {
CurrentSystemQuotaTypeEnum,
ModelStatusEnum,
@@ -114,10 +114,10 @@ type ProviderContextProviderProps = {
export const ProviderContextProvider = ({
children,
}: ProviderContextProviderProps) => {
- const { data: providersData, mutate: refreshModelProviders } = useSWR('/workspaces/current/model-providers', fetchModelProviders)
- const fetchModelListUrlPrefix = '/workspaces/current/models/model-types/'
- const { data: textGenerationModelList } = useSWR(`${fetchModelListUrlPrefix}${ModelTypeEnum.textGeneration}`, fetchModelList)
- const { data: supportRetrievalMethods } = useSWR('/datasets/retrieval-setting', fetchSupportRetrievalMethods)
+ const queryClient = useQueryClient()
+ const { data: providersData } = useModelProviders()
+ const { data: textGenerationModelList } = useModelListByType(ModelTypeEnum.textGeneration)
+ const { data: supportRetrievalMethods } = useSupportRetrievalMethods()
const [plan, setPlan] = useState(defaultPlan)
const [isFetchedPlan, setIsFetchedPlan] = useState(false)
@@ -139,6 +139,10 @@ export const ProviderContextProvider = ({
const [isAllowTransferWorkspace, setIsAllowTransferWorkspace] = useState(false)
const [isAllowPublishAsCustomKnowledgePipelineTemplate, setIsAllowPublishAsCustomKnowledgePipelineTemplate] = useState(false)
+ const refreshModelProviders = () => {
+ queryClient.invalidateQueries({ queryKey: ['common', 'model-providers'] })
+ }
+
const fetchPlan = async () => {
try {
const data = await fetchCurrentPlanInfo()
@@ -226,7 +230,7 @@ export const ProviderContextProvider = ({
modelProviders: providersData?.data || [],
refreshModelProviders,
textGenerationModelList: textGenerationModelList?.data || [],
- isAPIKeySet: !!textGenerationModelList?.data.some(model => model.status === ModelStatusEnum.active),
+ isAPIKeySet: !!textGenerationModelList?.data?.some(model => model.status === ModelStatusEnum.active),
supportRetrievalMethods: supportRetrievalMethods?.retrieval_method || [],
plan,
isFetchedPlan,
diff --git a/web/context/workspace-context.tsx b/web/context/workspace-context.tsx
index 9350a959b4..da7dcf5a50 100644
--- a/web/context/workspace-context.tsx
+++ b/web/context/workspace-context.tsx
@@ -1,8 +1,7 @@
'use client'
import { createContext, useContext } from 'use-context-selector'
-import useSWR from 'swr'
-import { fetchWorkspaces } from '@/service/common'
+import { useWorkspaces } from '@/service/use-common'
import type { IWorkspace } from '@/models/common'
export type WorkspacesContextValue = {
@@ -20,7 +19,7 @@ type IWorkspaceProviderProps = {
export const WorkspaceProvider = ({
children,
}: IWorkspaceProviderProps) => {
- const { data } = useSWR({ url: '/workspaces' }, fetchWorkspaces)
+ const { data } = useWorkspaces()
return (
@@ -58,12 +55,7 @@ export const useCheckNotion = () => {
const type = searchParams.get('type')
const notionCode = searchParams.get('code')
const notionError = searchParams.get('error')
- const { data } = useSWR(
- (canBinding && notionCode)
- ? `/oauth/data-source/binding/notion?code=${notionCode}`
- : null,
- fetchDataSourceNotionBinding,
- )
+ const { data } = useNotionBinding(notionCode, canBinding)
useEffect(() => {
if (data)
diff --git a/web/service/common.ts b/web/service/common.ts
index 7a092a6a24..1793675bc5 100644
--- a/web/service/common.ts
+++ b/web/service/common.ts
@@ -1,4 +1,3 @@
-import type { Fetcher } from 'swr'
import { del, get, patch, post, put } from './base'
import type {
AccountIntegrate,
@@ -49,145 +48,145 @@ type LoginFail = {
message: string
}
type LoginResponse = LoginSuccess | LoginFail
-export const login: Fetcher }> = ({ url, body }) => {
- return post(url, { body }) as Promise
+export const login = ({ url, body }: { url: string; body: Record }): Promise => {
+ return post(url, { body })
}
-export const webAppLogin: Fetcher }> = ({ url, body }) => {
- return post(url, { body }, { isPublicAPI: true }) as Promise
+export const webAppLogin = ({ url, body }: { url: string; body: Record }): Promise => {
+ return post(url, { body }, { isPublicAPI: true })
}
-export const setup: Fetcher }> = ({ body }) => {
+export const setup = ({ body }: { body: Record }): Promise => {
return post('/setup', { body })
}
-export const initValidate: Fetcher }> = ({ body }) => {
+export const initValidate = ({ body }: { body: Record }): Promise => {
return post('/init', { body })
}
-export const fetchInitValidateStatus = () => {
+export const fetchInitValidateStatus = (): Promise => {
return get('/init')
}
-export const fetchSetupStatus = () => {
+export const fetchSetupStatus = (): Promise => {
return get('/setup')
}
-export const fetchUserProfile: Fetcher }> = ({ url, params }) => {
+export const fetchUserProfile = ({ url, params }: { url: string; params: Record }): Promise => {
return get(url, params, { needAllResponseContent: true })
}
-export const updateUserProfile: Fetcher }> = ({ url, body }) => {
+export const updateUserProfile = ({ url, body }: { url: string; body: Record }): Promise => {
return post(url, { body })
}
-export const fetchLangGeniusVersion: Fetcher }> = ({ url, params }) => {
+export const fetchLangGeniusVersion = ({ url, params }: { url: string; params: Record }): Promise => {
return get(url, { params })
}
-export const oauth: Fetcher }> = ({ url, params }) => {
+export const oauth = ({ url, params }: { url: string; params: Record }): Promise => {
return get(url, { params })
}
-export const oneMoreStep: Fetcher }> = ({ url, body }) => {
+export const oneMoreStep = ({ url, body }: { url: string; body: Record }): Promise => {
return post(url, { body })
}
-export const fetchMembers: Fetcher<{ accounts: Member[] | null }, { url: string; params: Record }> = ({ url, params }) => {
+export const fetchMembers = ({ url, params }: { url: string; params: Record }): Promise<{ accounts: Member[] | null }> => {
return get<{ accounts: Member[] | null }>(url, { params })
}
-export const fetchProviders: Fetcher }> = ({ url, params }) => {
+export const fetchProviders = ({ url, params }: { url: string; params: Record }): Promise => {
return get(url, { params })
}
-export const validateProviderKey: Fetcher = ({ url, body }) => {
+export const validateProviderKey = ({ url, body }: { url: string; body: { token: string } }): Promise => {
return post(url, { body })
}
-export const updateProviderAIKey: Fetcher = ({ url, body }) => {
+export const updateProviderAIKey = ({ url, body }: { url: string; body: { token: string | ProviderAzureToken | ProviderAnthropicToken } }): Promise => {
return post(url, { body })
}
-export const fetchAccountIntegrates: Fetcher<{ data: AccountIntegrate[] | null }, { url: string; params: Record }> = ({ url, params }) => {
+export const fetchAccountIntegrates = ({ url, params }: { url: string; params: Record }): Promise<{ data: AccountIntegrate[] | null }> => {
return get<{ data: AccountIntegrate[] | null }>(url, { params })
}
-export const inviteMember: Fetcher }> = ({ url, body }) => {
+export const inviteMember = ({ url, body }: { url: string; body: Record }): Promise => {
return post(url, { body })
}
-export const updateMemberRole: Fetcher }> = ({ url, body }) => {
+export const updateMemberRole = ({ url, body }: { url: string; body: Record }): Promise => {
return put(url, { body })
}
-export const deleteMemberOrCancelInvitation: Fetcher = ({ url }) => {
+export const deleteMemberOrCancelInvitation = ({ url }: { url: string }): Promise => {
return del(url)
}
-export const sendOwnerEmail = (body: { language?: string }) =>
+export const sendOwnerEmail = (body: { language?: string }): Promise =>
post('/workspaces/current/members/send-owner-transfer-confirm-email', { body })
-export const verifyOwnerEmail = (body: { code: string; token: string }) =>
+export const verifyOwnerEmail = (body: { code: string; token: string }): Promise =>
post('/workspaces/current/members/owner-transfer-check', { body })
-export const ownershipTransfer = (memberID: string, body: { token: string }) =>
+export const ownershipTransfer = (memberID: string, body: { token: string }): Promise =>
post(`/workspaces/current/members/${memberID}/owner-transfer`, { body })
-export const fetchFilePreview: Fetcher<{ content: string }, { fileID: string }> = ({ fileID }) => {
+export const fetchFilePreview = ({ fileID }: { fileID: string }): Promise<{ content: string }> => {
return get<{ content: string }>(`/files/${fileID}/preview`)
}
-export const fetchCurrentWorkspace: Fetcher }> = ({ url, params }) => {
+export const fetchCurrentWorkspace = ({ url, params }: { url: string; params: Record }): Promise => {
return post(url, { body: params })
}
-export const updateCurrentWorkspace: Fetcher }> = ({ url, body }) => {
+export const updateCurrentWorkspace = ({ url, body }: { url: string; body: Record }): Promise => {
return post(url, { body })
}
-export const fetchWorkspaces: Fetcher<{ workspaces: IWorkspace[] }, { url: string; params: Record }> = ({ url, params }) => {
+export const fetchWorkspaces = ({ url, params }: { url: string; params: Record }): Promise<{ workspaces: IWorkspace[] }> => {
return get<{ workspaces: IWorkspace[] }>(url, { params })
}
-export const switchWorkspace: Fetcher }> = ({ url, body }) => {
+export const switchWorkspace = ({ url, body }: { url: string; body: Record }): Promise => {
return post(url, { body })
}
-export const updateWorkspaceInfo: Fetcher }> = ({ url, body }) => {
+export const updateWorkspaceInfo = ({ url, body }: { url: string; body: Record }): Promise => {
return post(url, { body })
}
-export const fetchDataSource: Fetcher<{ data: DataSourceNotion[] }, { url: string }> = ({ url }) => {
+export const fetchDataSource = ({ url }: { url: string }): Promise<{ data: DataSourceNotion[] }> => {
return get<{ data: DataSourceNotion[] }>(url)
}
-export const syncDataSourceNotion: Fetcher = ({ url }) => {
+export const syncDataSourceNotion = ({ url }: { url: string }): Promise => {
return get(url)
}
-export const updateDataSourceNotionAction: Fetcher = ({ url }) => {
+export const updateDataSourceNotionAction = ({ url }: { url: string }): Promise => {
return patch(url)
}
-export const fetchPluginProviders: Fetcher = (url) => {
+export const fetchPluginProviders = (url: string): Promise => {
return get(url)
}
-export const validatePluginProviderKey: Fetcher = ({ url, body }) => {
+export const validatePluginProviderKey = ({ url, body }: { url: string; body: { credentials: any } }): Promise => {
return post(url, { body })
}
-export const updatePluginProviderAIKey: Fetcher = ({ url, body }) => {
+export const updatePluginProviderAIKey = ({ url, body }: { url: string; body: { credentials: any } }): Promise => {
return post(url, { body })
}
-export const invitationCheck: Fetcher = ({ url, params }) => {
+export const invitationCheck = ({ url, params }: { url: string; params: { workspace_id?: string; email?: string; token: string } }): Promise => {
return get(url, { params })
}
-export const activateMember: Fetcher = ({ url, body }) => {
+export const activateMember = ({ url, body }: { url: string; body: any }): Promise => {
return post(url, { body })
}
-export const fetchModelProviders: Fetcher<{ data: ModelProvider[] }, string> = (url) => {
+export const fetchModelProviders = (url: string): Promise<{ data: ModelProvider[] }> => {
return get<{ data: ModelProvider[] }>(url)
}
@@ -195,197 +194,197 @@ export type ModelProviderCredentials = {
credentials?: Record
load_balancing: ModelLoadBalancingConfig
}
-export const fetchModelProviderCredentials: Fetcher = (url) => {
+export const fetchModelProviderCredentials = (url: string): Promise => {
return get(url)
}
-export const fetchModelLoadBalancingConfig: Fetcher<{
+export const fetchModelLoadBalancingConfig = (url: string): Promise<{
credentials?: Record
load_balancing: ModelLoadBalancingConfig
-}, string> = (url) => {
+}> => {
return get<{
credentials?: Record
load_balancing: ModelLoadBalancingConfig
}>(url)
}
-export const fetchModelProviderModelList: Fetcher<{ data: ModelItem[] }, string> = (url) => {
+export const fetchModelProviderModelList = (url: string): Promise<{ data: ModelItem[] }> => {
return get<{ data: ModelItem[] }>(url)
}
-export const fetchModelList: Fetcher<{ data: Model[] }, string> = (url) => {
+export const fetchModelList = (url: string): Promise<{ data: Model[] }> => {
return get<{ data: Model[] }>(url)
}
-export const validateModelProvider: Fetcher = ({ url, body }) => {
+export const validateModelProvider = ({ url, body }: { url: string; body: any }): Promise => {
return post(url, { body })
}
-export const validateModelLoadBalancingCredentials: Fetcher = ({ url, body }) => {
+export const validateModelLoadBalancingCredentials = ({ url, body }: { url: string; body: any }): Promise => {
return post(url, { body })
}
-export const setModelProvider: Fetcher = ({ url, body }) => {
+export const setModelProvider = ({ url, body }: { url: string; body: any }): Promise => {
return post(url, { body })
}
-export const deleteModelProvider: Fetcher = ({ url, body }) => {
+export const deleteModelProvider = ({ url, body }: { url: string; body?: any }): Promise => {
return del(url, { body })
}
-export const changeModelProviderPriority: Fetcher = ({ url, body }) => {
+export const changeModelProviderPriority = ({ url, body }: { url: string; body: any }): Promise => {
return post(url, { body })
}
-export const setModelProviderModel: Fetcher = ({ url, body }) => {
+export const setModelProviderModel = ({ url, body }: { url: string; body: any }): Promise => {
return post(url, { body })
}
-export const deleteModelProviderModel: Fetcher = ({ url }) => {
+export const deleteModelProviderModel = ({ url }: { url: string }): Promise => {
return del(url)
}
-export const getPayUrl: Fetcher<{ url: string }, string> = (url) => {
+export const getPayUrl = (url: string): Promise<{ url: string }> => {
return get<{ url: string }>(url)
}
-export const fetchDefaultModal: Fetcher<{ data: DefaultModelResponse }, string> = (url) => {
+export const fetchDefaultModal = (url: string): Promise<{ data: DefaultModelResponse }> => {
return get<{ data: DefaultModelResponse }>(url)
}
-export const updateDefaultModel: Fetcher = ({ url, body }) => {
+export const updateDefaultModel = ({ url, body }: { url: string; body: any }): Promise => {
return post(url, { body })
}
-export const fetchModelParameterRules: Fetcher<{ data: ModelParameterRule[] }, string> = (url) => {
+export const fetchModelParameterRules = (url: string): Promise<{ data: ModelParameterRule[] }> => {
return get<{ data: ModelParameterRule[] }>(url)
}
-export const fetchFileUploadConfig: Fetcher = ({ url }) => {
+export const fetchFileUploadConfig = ({ url }: { url: string }): Promise => {
return get(url)
}
-export const fetchNotionConnection: Fetcher<{ data: string }, string> = (url) => {
- return get(url) as Promise<{ data: string }>
+export const fetchNotionConnection = (url: string): Promise<{ data: string }> => {
+ return get<{ data: string }>(url)
}
-export const fetchDataSourceNotionBinding: Fetcher<{ result: string }, string> = (url) => {
- return get(url) as Promise<{ result: string }>
+export const fetchDataSourceNotionBinding = (url: string): Promise<{ result: string }> => {
+ return get<{ result: string }>(url)
}
-export const fetchApiBasedExtensionList: Fetcher = (url) => {
- return get(url) as Promise
+export const fetchApiBasedExtensionList = (url: string): Promise => {
+ return get(url)
}
-export const fetchApiBasedExtensionDetail: Fetcher = (url) => {
- return get(url) as Promise
+export const fetchApiBasedExtensionDetail = (url: string): Promise => {
+ return get(url)
}
-export const addApiBasedExtension: Fetcher = ({ url, body }) => {
- return post(url, { body }) as Promise
+export const addApiBasedExtension = ({ url, body }: { url: string; body: ApiBasedExtension }): Promise => {
+ return post(url, { body })
}
-export const updateApiBasedExtension: Fetcher = ({ url, body }) => {
- return post(url, { body }) as Promise
+export const updateApiBasedExtension = ({ url, body }: { url: string; body: ApiBasedExtension }): Promise => {
+ return post(url, { body })
}
-export const deleteApiBasedExtension: Fetcher<{ result: string }, string> = (url) => {
- return del(url) as Promise<{ result: string }>
+export const deleteApiBasedExtension = (url: string): Promise<{ result: string }> => {
+ return del<{ result: string }>(url)
}
-export const fetchCodeBasedExtensionList: Fetcher = (url) => {
- return get(url) as Promise
+export const fetchCodeBasedExtensionList = (url: string): Promise => {
+ return get(url)
}
-export const moderate = (url: string, body: { app_id: string; text: string }) => {
- return post(url, { body }) as Promise
+export const moderate = (url: string, body: { app_id: string; text: string }): Promise => {
+ return post(url, { body })
}
type RetrievalMethodsRes = {
retrieval_method: RETRIEVE_METHOD[]
}
-export const fetchSupportRetrievalMethods: Fetcher = (url) => {
+export const fetchSupportRetrievalMethods = (url: string): Promise => {
return get(url)
}
-export const getSystemFeatures = () => {
+export const getSystemFeatures = (): Promise => {
return get('/system-features')
}
-export const enableModel = (url: string, body: { model: string; model_type: ModelTypeEnum }) =>
+export const enableModel = (url: string, body: { model: string; model_type: ModelTypeEnum }): Promise =>
patch(url, { body })
-export const disableModel = (url: string, body: { model: string; model_type: ModelTypeEnum }) =>
+export const disableModel = (url: string, body: { model: string; model_type: ModelTypeEnum }): Promise =>
patch(url, { body })
-export const sendForgotPasswordEmail: Fetcher = ({ url, body }) =>
+export const sendForgotPasswordEmail = ({ url, body }: { url: string; body: { email: string } }): Promise =>
post(url, { body })
-export const verifyForgotPasswordToken: Fetcher = ({ url, body }) => {
- return post(url, { body }) as Promise
+export const verifyForgotPasswordToken = ({ url, body }: { url: string; body: { token: string } }): Promise => {
+ return post(url, { body })
}
-export const changePasswordWithToken: Fetcher = ({ url, body }) =>
+export const changePasswordWithToken = ({ url, body }: { url: string; body: { token: string; new_password: string; password_confirm: string } }): Promise =>
post(url, { body })
-export const sendWebAppForgotPasswordEmail: Fetcher = ({ url, body }) =>
+export const sendWebAppForgotPasswordEmail = ({ url, body }: { url: string; body: { email: string } }): Promise =>
post