2023-05-15 08:51:32 +08:00
|
|
|
import type { Fetcher } from 'swr'
|
2023-06-16 21:47:51 +08:00
|
|
|
import { del, get, patch, post, put } from './base'
|
2023-05-15 08:51:32 +08:00
|
|
|
import type {
|
2023-06-16 21:47:51 +08:00
|
|
|
AccountIntegrate, CommonResponse, DataSourceNotion,
|
2023-08-28 10:53:45 +08:00
|
|
|
DocumentsLimitResponse,
|
2023-08-16 23:14:27 +08:00
|
|
|
FileUploadConfigResponse,
|
2023-08-15 13:35:47 +08:00
|
|
|
ICurrentWorkspace,
|
2023-08-31 01:18:31 +08:00
|
|
|
IWorkspace, InvitationResponse, LangGeniusVersionResponse, Member,
|
2023-08-07 13:19:47 +08:00
|
|
|
OauthResponse, PluginProvider, Provider, ProviderAnthropicToken, ProviderAzureToken,
|
2023-08-22 16:59:57 +08:00
|
|
|
SetupStatusResponse, UserProfileOriginResponse,
|
2023-05-15 08:51:32 +08:00
|
|
|
} from '@/models/common'
|
|
|
|
import type {
|
2023-06-06 11:22:00 +08:00
|
|
|
UpdateOpenAIKeyResponse,
|
2023-05-15 08:51:32 +08:00
|
|
|
ValidateOpenAIKeyResponse,
|
|
|
|
} from '@/models/app'
|
2023-08-12 00:57:13 +08:00
|
|
|
import type { BackendModel, ProviderMap } from '@/app/components/header/account-setting/model-page/declarations'
|
2023-05-15 08:51:32 +08:00
|
|
|
|
2023-09-25 12:49:16 +08:00
|
|
|
export const login: Fetcher<CommonResponse & { data: string }, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
|
|
|
return post(url, { body }) as Promise<CommonResponse & { data: string }>
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const setup: Fetcher<CommonResponse, { body: Record<string, any> }> = ({ body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse>('/setup', { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
2023-08-07 13:19:47 +08:00
|
|
|
export const fetchSetupStatus = () => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<SetupStatusResponse>('/setup')
|
2023-08-07 13:19:47 +08:00
|
|
|
}
|
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
export const fetchUserProfile: Fetcher<UserProfileOriginResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<UserProfileOriginResponse>(url, params, { needAllResponseContent: true })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const updateUserProfile: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const logout: Fetcher<CommonResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<CommonResponse>(url, params)
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchLanggeniusVersion: Fetcher<LangGeniusVersionResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<LangGeniusVersionResponse>(url, { params })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const oauth: Fetcher<OauthResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<OauthResponse>(url, { params })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const oneMoreStep: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchMembers: Fetcher<{ accounts: Member[] | null }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<{ accounts: Member[] | null }>(url, { params })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchProviders: Fetcher<Provider[] | null, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<Provider[] | null>(url, { params })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const validateProviderKey: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: { token: string } }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<ValidateOpenAIKeyResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
2023-07-17 00:14:32 +08:00
|
|
|
export const updateProviderAIKey: Fetcher<UpdateOpenAIKeyResponse, { url: string; body: { token: string | ProviderAzureToken | ProviderAnthropicToken } }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<UpdateOpenAIKeyResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchAccountIntegrates: Fetcher<{ data: AccountIntegrate[] | null }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<{ data: AccountIntegrate[] | null }>(url, { params })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
2023-08-31 01:18:31 +08:00
|
|
|
export const inviteMember: Fetcher<InvitationResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<InvitationResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const updateMemberRole: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return put<CommonResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
2023-06-06 11:22:00 +08:00
|
|
|
export const deleteMemberOrCancelInvitation: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return del<CommonResponse>(url)
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchFilePreview: Fetcher<{ content: string }, { fileID: string }> = ({ fileID }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<{ content: string }>(`/files/${fileID}/preview`)
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
2023-08-15 13:35:47 +08:00
|
|
|
export const fetchCurrentWorkspace: Fetcher<ICurrentWorkspace, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<ICurrentWorkspace>(url, { params })
|
2023-08-15 13:35:47 +08:00
|
|
|
}
|
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
export const fetchWorkspaces: Fetcher<{ workspaces: IWorkspace[] }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<{ workspaces: IWorkspace[] }>(url, { params })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const switchWorkspace: Fetcher<CommonResponse & { new_tenant: IWorkspace }, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse & { new_tenant: IWorkspace }>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
2023-06-16 21:47:51 +08:00
|
|
|
|
|
|
|
export const fetchDataSource: Fetcher<{ data: DataSourceNotion[] }, { url: string }> = ({ url }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<{ data: DataSourceNotion[] }>(url)
|
2023-06-16 21:47:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const syncDataSourceNotion: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<CommonResponse>(url)
|
2023-06-16 21:47:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const updateDataSourceNotionAction: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return patch<CommonResponse>(url)
|
2023-06-16 21:47:51 +08:00
|
|
|
}
|
2023-07-14 11:19:26 +08:00
|
|
|
|
2023-07-27 13:27:34 +08:00
|
|
|
export const fetchPluginProviders: Fetcher<PluginProvider[] | null, string> = (url) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<PluginProvider[] | null>(url)
|
2023-07-27 13:27:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const validatePluginProviderKey: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: { credentials: any } }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<ValidateOpenAIKeyResponse>(url, { body })
|
2023-07-27 13:27:34 +08:00
|
|
|
}
|
|
|
|
export const updatePluginProviderAIKey: Fetcher<UpdateOpenAIKeyResponse, { url: string; body: { credentials: any } }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<UpdateOpenAIKeyResponse>(url, { body })
|
2023-07-27 13:27:34 +08:00
|
|
|
}
|
|
|
|
|
2023-07-14 11:19:26 +08:00
|
|
|
export const invitationCheck: Fetcher<CommonResponse & { is_valid: boolean; workspace_name: string }, { url: string; params: { workspace_id: string; email: string; token: string } }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<CommonResponse & { is_valid: boolean; workspace_name: string }>(url, { params })
|
2023-07-14 11:19:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const activateMember: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse>(url, { body })
|
2023-07-14 11:19:26 +08:00
|
|
|
}
|
2023-08-12 00:57:13 +08:00
|
|
|
|
|
|
|
export const fetchModelProviders: Fetcher<ProviderMap, string> = (url) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<ProviderMap>(url)
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchModelList: Fetcher<BackendModel[], string> = (url) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<BackendModel[]>(url)
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const validateModelProvider: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: any }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<ValidateOpenAIKeyResponse>(url, { body })
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const setModelProvider: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse>(url, { body })
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const deleteModelProvider: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return del<CommonResponse>(url)
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const changeModelProviderPriority: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse>(url, { body })
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const setModelProviderModel: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse>(url, { body })
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const deleteModelProviderModel: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return del<CommonResponse>(url)
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const getPayUrl: Fetcher<{ url: string }, string> = (url) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<{ url: string }>(url)
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchDefaultModal: Fetcher<BackendModel, string> = (url) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<BackendModel>(url)
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const updateDefaultModel: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse>(url, { body })
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
2023-08-14 12:46:28 +08:00
|
|
|
|
|
|
|
export const submitFreeQuota: Fetcher<{ type: string; redirect_url?: string; result?: string }, string> = (url) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<{ type: string; redirect_url?: string; result?: string }>(url)
|
2023-08-14 12:46:28 +08:00
|
|
|
}
|
2023-08-16 23:14:27 +08:00
|
|
|
|
|
|
|
export const fetchFileUploadConfig: Fetcher<FileUploadConfigResponse, { url: string }> = ({ url }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<FileUploadConfigResponse>(url)
|
2023-08-16 23:14:27 +08:00
|
|
|
}
|
2023-08-28 10:53:45 +08:00
|
|
|
|
|
|
|
export const fetchDocumentsLimit: Fetcher<DocumentsLimitResponse, string> = (url) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<DocumentsLimitResponse>(url)
|
2023-08-28 10:53:45 +08:00
|
|
|
}
|
2023-09-11 17:30:54 +08:00
|
|
|
|
2023-09-18 18:02:05 +08:00
|
|
|
export const fetchFreeQuotaVerify: Fetcher<{ result: string; flag: boolean; reason: string }, string> = (url) => {
|
2023-09-11 17:30:54 +08:00
|
|
|
return get(url) as Promise<{ result: string; flag: boolean; reason: string }>
|
|
|
|
}
|
2023-09-28 14:39:13 +08:00
|
|
|
|
|
|
|
export const fetchNotionConnection: Fetcher<{ data: string }, string> = (url) => {
|
|
|
|
return get(url) as Promise<{ data: string }>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchDataSourceNotionBinding: Fetcher<{ result: string }, string> = (url) => {
|
|
|
|
return get(url) as Promise<{ result: string }>
|
|
|
|
}
|