import type { Fetcher } from 'swr' import { del, get, patch, post, put } from './base' import type { AccountIntegrate, CommonResponse, DataSourceNotion, IWorkspace, LangGeniusVersionResponse, Member, OauthResponse, PluginProvider, Provider, ProviderAnthropicToken, ProviderAzureToken, SetupStatusResponse, TenantInfoResponse, UserProfileOriginResponse, } from '@/models/common' import type { UpdateOpenAIKeyResponse, ValidateOpenAIKeyResponse, } from '@/models/app' import type { BackendModel, ProviderMap } from '@/app/components/header/account-setting/model-page/declarations' export const login: Fetcher }> = ({ url, body }) => { return post(url, { body }) as Promise } export const setup: Fetcher }> = ({ body }) => { return post('/setup', { body }) as Promise } export const fetchSetupStatus = () => { return get('/setup') as Promise } export const fetchUserProfile: Fetcher }> = ({ url, params }) => { return get(url, params, { needAllResponseContent: true }) as Promise } export const updateUserProfile: Fetcher }> = ({ url, body }) => { return post(url, { body }) as Promise } export const fetchTenantInfo: Fetcher = ({ url }) => { return get(url) as Promise } export const logout: Fetcher }> = ({ url, params }) => { return get(url, params) as Promise } export const fetchLanggeniusVersion: Fetcher }> = ({ url, params }) => { return get(url, { params }) as Promise } export const oauth: Fetcher }> = ({ url, params }) => { return get(url, { params }) as Promise } export const oneMoreStep: Fetcher }> = ({ url, body }) => { return post(url, { body }) as Promise } export const fetchMembers: Fetcher<{ accounts: Member[] | null }, { url: string; params: Record }> = ({ url, params }) => { return get(url, { params }) as Promise<{ accounts: Member[] | null }> } export const fetchProviders: Fetcher }> = ({ url, params }) => { return get(url, { params }) as Promise } export const validateProviderKey: Fetcher = ({ url, body }) => { return post(url, { body }) as Promise } export const updateProviderAIKey: Fetcher = ({ url, body }) => { return post(url, { body }) as Promise } export const fetchAccountIntegrates: Fetcher<{ data: AccountIntegrate[] | null }, { url: string; params: Record }> = ({ url, params }) => { return get(url, { params }) as Promise<{ data: AccountIntegrate[] | null }> } export const inviteMember: Fetcher }> = ({ url, body }) => { return post(url, { body }) as Promise } export const updateMemberRole: Fetcher }> = ({ url, body }) => { return put(url, { body }) as Promise } export const deleteMemberOrCancelInvitation: Fetcher = ({ url }) => { return del(url) as Promise } export const fetchFilePreview: Fetcher<{ content: string }, { fileID: string }> = ({ fileID }) => { return get(`/files/${fileID}/preview`) as Promise<{ content: string }> } export const fetchWorkspaces: Fetcher<{ workspaces: IWorkspace[] }, { url: string; params: Record }> = ({ url, params }) => { return get(url, { params }) as Promise<{ workspaces: IWorkspace[] }> } export const switchWorkspace: Fetcher }> = ({ url, body }) => { return post(url, { body }) as Promise } export const fetchDataSource: Fetcher<{ data: DataSourceNotion[] }, { url: string }> = ({ url }) => { return get(url) as Promise<{ data: DataSourceNotion[] }> } export const syncDataSourceNotion: Fetcher = ({ url }) => { return get(url) as Promise } export const updateDataSourceNotionAction: Fetcher = ({ url }) => { return patch(url) as Promise } export const fetchPluginProviders: Fetcher = (url) => { return get(url) as Promise } export const validatePluginProviderKey: Fetcher = ({ url, body }) => { return post(url, { body }) as Promise } export const updatePluginProviderAIKey: Fetcher = ({ url, body }) => { return post(url, { body }) as Promise } export const invitationCheck: Fetcher = ({ url, params }) => { return get(url, { params }) as Promise } export const activateMember: Fetcher = ({ url, body }) => { return post(url, { body }) as Promise } export const fetchModelProviders: Fetcher = (url) => { return get(url) as Promise } export const fetchModelList: Fetcher = (url) => { return get(url) as Promise } export const validateModelProvider: Fetcher = ({ url, body }) => { return post(url, { body }) as Promise } export const setModelProvider: Fetcher = ({ url, body }) => { return post(url, { body }) as Promise } export const deleteModelProvider: Fetcher = ({ url }) => { return del(url) as Promise } export const changeModelProviderPriority: Fetcher = ({ url, body }) => { return post(url, { body }) as Promise } export const setModelProviderModel: Fetcher = ({ url, body }) => { return post(url, { body }) as Promise } export const deleteModelProviderModel: Fetcher = ({ url }) => { return del(url) as Promise } export const getPayUrl: Fetcher<{ url: string }, string> = (url) => { return get(url) as Promise<{ url: string }> } export const fetchDefaultModal: Fetcher = (url) => { return get(url) as Promise } export const updateDefaultModel: Fetcher = ({ url, body }) => { return post(url, { body }) as Promise } export const submitFreeQuota: Fetcher<{ type: string; redirect_url?: string; result?: string }, string> = (url) => { return post(url) as Promise<{ type: string; redirect_url?: string; result?: string }> }