import type { Fetcher } from 'swr' import { del, get, patch, post, put } from './base' import type { AccountIntegrate, ApiBasedExtension, CodeBasedExtension, CommonResponse, DataSourceNotion, FileUploadConfigResponse, ICurrentWorkspace, IWorkspace, InvitationResponse, LangGeniusVersionResponse, Member, ModerateResponse, OauthResponse, PluginProvider, Provider, ProviderAnthropicToken, ProviderAzureToken, SetupStatusResponse, UserProfileOriginResponse, } from '@/models/common' import type { UpdateOpenAIKeyResponse, ValidateOpenAIKeyResponse, } from '@/models/app' import type { DefaultModelResponse, Model, ModelItem, ModelParameterRule, ModelProvider, } from '@/app/components/header/account-setting/model-provider-page/declarations' import type { RETRIEVE_METHOD } from '@/types/app' export const login: Fetcher }> = ({ url, body }) => { return post(url, { body }) as Promise } export const setup: Fetcher }> = ({ body }) => { return post('/setup', { body }) } export const fetchSetupStatus = () => { return get('/setup') } export const fetchUserProfile: Fetcher }> = ({ url, params }) => { return get(url, params, { needAllResponseContent: true }) } export const updateUserProfile: Fetcher }> = ({ url, body }) => { return post(url, { body }) } export const logout: Fetcher }> = ({ url, params }) => { return get(url, params) } export const fetchLanggeniusVersion: Fetcher }> = ({ url, params }) => { return get(url, { params }) } export const oauth: Fetcher }> = ({ url, params }) => { return get(url, { params }) } export const oneMoreStep: Fetcher }> = ({ url, body }) => { return post(url, { body }) } export const fetchMembers: Fetcher<{ accounts: Member[] | null }, { url: string; params: Record }> = ({ url, params }) => { return get<{ accounts: Member[] | null }>(url, { params }) } export const fetchProviders: Fetcher }> = ({ url, params }) => { return get(url, { params }) } export const validateProviderKey: Fetcher = ({ url, body }) => { return post(url, { body }) } export const updateProviderAIKey: Fetcher = ({ url, body }) => { return post(url, { body }) } export const fetchAccountIntegrates: Fetcher<{ data: AccountIntegrate[] | null }, { url: string; params: Record }> = ({ url, params }) => { return get<{ data: AccountIntegrate[] | null }>(url, { params }) } export const inviteMember: Fetcher }> = ({ url, body }) => { return post(url, { body }) } export const updateMemberRole: Fetcher }> = ({ url, body }) => { return put(url, { body }) } export const deleteMemberOrCancelInvitation: Fetcher = ({ url }) => { return del(url) } export const fetchFilePreview: Fetcher<{ content: string }, { fileID: string }> = ({ fileID }) => { return get<{ content: string }>(`/files/${fileID}/preview`) } export const fetchCurrentWorkspace: Fetcher }> = ({ url, params }) => { return get(url, { params }) } export const updateCurrentWorkspace: Fetcher }> = ({ url, body }) => { return post(url, { body }) } export const fetchWorkspaces: Fetcher<{ workspaces: IWorkspace[] }, { url: string; params: Record }> = ({ url, params }) => { return get<{ workspaces: IWorkspace[] }>(url, { params }) } export const switchWorkspace: Fetcher }> = ({ url, body }) => { return post(url, { body }) } export const fetchDataSource: Fetcher<{ data: DataSourceNotion[] }, { url: string }> = ({ url }) => { return get<{ data: DataSourceNotion[] }>(url) } export const syncDataSourceNotion: Fetcher = ({ url }) => { return get(url) } export const updateDataSourceNotionAction: Fetcher = ({ url }) => { return patch(url) } export const fetchPluginProviders: Fetcher = (url) => { return get(url) } export const validatePluginProviderKey: Fetcher = ({ url, body }) => { return post(url, { body }) } export const updatePluginProviderAIKey: Fetcher = ({ url, body }) => { return post(url, { body }) } export const invitationCheck: Fetcher = ({ url, params }) => { return get(url, { params }) } export const activateMember: Fetcher = ({ url, body }) => { return post(url, { body }) } export const fetchModelProviders: Fetcher<{ data: ModelProvider[] }, string> = (url) => { return get<{ data: ModelProvider[] }>(url) } export const fetchModelProviderCredentials: Fetcher<{ credentials?: Record }, string> = (url) => { return get<{ credentials?: Record }>(url) } export const fetchModelProviderModelList: Fetcher<{ data: ModelItem[] }, string> = (url) => { return get<{ data: ModelItem[] }>(url) } export const fetchModelList: Fetcher<{ data: Model[] }, string> = (url) => { return get<{ data: Model[] }>(url) } export const validateModelProvider: Fetcher = ({ url, body }) => { return post(url, { body }) } export const setModelProvider: Fetcher = ({ url, body }) => { return post(url, { body }) } export const deleteModelProvider: Fetcher = ({ url, body }) => { return del(url, { body }) } export const changeModelProviderPriority: Fetcher = ({ url, body }) => { return post(url, { body }) } export const setModelProviderModel: Fetcher = ({ url, body }) => { return post(url, { body }) } export const deleteModelProviderModel: Fetcher = ({ url }) => { return del(url) } export const getPayUrl: Fetcher<{ url: string }, string> = (url) => { return get<{ url: string }>(url) } export const fetchDefaultModal: Fetcher<{ data: DefaultModelResponse }, string> = (url) => { return get<{ data: DefaultModelResponse }>(url) } export const updateDefaultModel: Fetcher = ({ url, body }) => { return post(url, { body }) } export const fetchModelParameterRules: Fetcher<{ data: ModelParameterRule[] }, string> = (url) => { return get<{ data: ModelParameterRule[] }>(url) } export const submitFreeQuota: Fetcher<{ type: string; redirect_url?: string; result?: string }, string> = (url) => { return post<{ type: string; redirect_url?: string; result?: string }>(url) } export const fetchFileUploadConfig: Fetcher = ({ url }) => { return get(url) } export const fetchFreeQuotaVerify: Fetcher<{ result: string; flag: boolean; reason: string }, string> = (url) => { return get(url) as Promise<{ result: string; flag: boolean; reason: string }> } 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 }> } export const fetchApiBasedExtensionList: Fetcher = (url) => { return get(url) as Promise } export const fetchApiBasedExtensionDetail: Fetcher = (url) => { return get(url) as Promise } export const addApiBasedExtension: Fetcher = ({ url, body }) => { return post(url, { body }) as Promise } export const updateApiBasedExtension: Fetcher = ({ url, body }) => { return post(url, { body }) as Promise } export const deleteApiBasedExtension: Fetcher<{ result: string }, string> = (url) => { return del(url) as Promise<{ result: string }> } export const fetchCodeBasedExtensionList: Fetcher = (url) => { return get(url) as Promise } export const moderate = (url: string, body: { app_id: string; text: string }) => { return post(url, { body }) as Promise } type RetrievalMethodsRes = { 'retrieval_method': RETRIEVE_METHOD[] } export const fetchSupportRetrievalMethods: Fetcher = (url) => { return get(url) }