import type { DefaultModelResponse, Model, ModelItem, ModelLoadBalancingConfig, ModelParameterRule, ModelProvider, ModelTypeEnum, } from '@/app/components/header/account-setting/model-provider-page/declarations' import type { UpdateOpenAIKeyResponse, ValidateOpenAIKeyResponse, } from '@/models/app' import type { AccountIntegrate, ApiBasedExtension, CodeBasedExtension, CommonResponse, DataSourceNotion, FileUploadConfigResponse, ICurrentWorkspace, InitValidateStatusResponse, InvitationResponse, IWorkspace, LangGeniusVersionResponse, Member, ModerateResponse, OauthResponse, PluginProvider, Provider, ProviderAnthropicToken, ProviderAzureToken, SetupStatusResponse, UserProfileOriginResponse, } from '@/models/common' import type { RETRIEVE_METHOD } from '@/types/app' import type { SystemFeatures } from '@/types/feature' import { del, get, patch, post, put } from './base' type LoginSuccess = { result: 'success' data: { access_token: string } } type LoginFail = { result: 'fail' data: string code: string message: string } type LoginResponse = LoginSuccess | LoginFail export const login = ({ url, body }: { url: string, body: Record }): Promise => { return post(url, { body }) } export const webAppLogin = ({ url, body }: { url: string, body: Record }): Promise => { return post(url, { body }, { isPublicAPI: true }) } export const setup = ({ body }: { body: Record }): Promise => { return post('/setup', { body }) } export const initValidate = ({ body }: { body: Record }): Promise => { return post('/init', { body }) } export const fetchInitValidateStatus = (): Promise => { return get('/init') } export const fetchSetupStatus = (): Promise => { return get('/setup') } export const fetchUserProfile = ({ url, params }: { url: string, params: Record }): Promise => { return get(url, params, { needAllResponseContent: true }) } export const updateUserProfile = ({ url, body }: { url: string, body: Record }): Promise => { return post(url, { body }) } export const fetchLangGeniusVersion = ({ url, params }: { url: string, params: Record }): Promise => { return get(url, { params }) } export const oauth = ({ url, params }: { url: string, params: Record }): Promise => { return get(url, { params }) } export const oneMoreStep = ({ url, body }: { url: string, body: Record }): Promise => { return post(url, { body }) } export const fetchMembers = ({ url, params }: { url: string, params: Record }): Promise<{ accounts: Member[] | null }> => { return get<{ accounts: Member[] | null }>(url, { params }) } export const fetchProviders = ({ url, params }: { url: string, params: Record }): Promise => { return get(url, { params }) } export const validateProviderKey = ({ url, body }: { url: string, body: { token: string } }): Promise => { return post(url, { body }) } export const updateProviderAIKey = ({ url, body }: { url: string, body: { token: string | ProviderAzureToken | ProviderAnthropicToken } }): Promise => { return post(url, { body }) } export const fetchAccountIntegrates = ({ url, params }: { url: string, params: Record }): Promise<{ data: AccountIntegrate[] | null }> => { return get<{ data: AccountIntegrate[] | null }>(url, { params }) } export const inviteMember = ({ url, body }: { url: string, body: Record }): Promise => { return post(url, { body }) } export const updateMemberRole = ({ url, body }: { url: string, body: Record }): Promise => { return put(url, { body }) } export const deleteMemberOrCancelInvitation = ({ url }: { url: string }): Promise => { return del(url) } 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 }): Promise => post('/workspaces/current/members/owner-transfer-check', { body }) export const ownershipTransfer = (memberID: string, body: { token: string }): Promise => post(`/workspaces/current/members/${memberID}/owner-transfer`, { body }) export const fetchFilePreview = ({ fileID }: { fileID: string }): Promise<{ content: string }> => { return get<{ content: string }>(`/files/${fileID}/preview`) } export const fetchCurrentWorkspace = ({ url, params }: { url: string, params: Record }): Promise => { return post(url, { body: params }) } export const updateCurrentWorkspace = ({ url, body }: { url: string, body: Record }): Promise => { return post(url, { body }) } export const fetchWorkspaces = ({ url, params }: { url: string, params: Record }): Promise<{ workspaces: IWorkspace[] }> => { return get<{ workspaces: IWorkspace[] }>(url, { params }) } export const switchWorkspace = ({ url, body }: { url: string, body: Record }): Promise => { return post(url, { body }) } export const updateWorkspaceInfo = ({ url, body }: { url: string, body: Record }): Promise => { return post(url, { body }) } export const fetchDataSource = ({ url }: { url: string }): Promise<{ data: DataSourceNotion[] }> => { return get<{ data: DataSourceNotion[] }>(url) } export const syncDataSourceNotion = ({ url }: { url: string }): Promise => { return get(url) } export const updateDataSourceNotionAction = ({ url }: { url: string }): Promise => { return patch(url) } export const fetchPluginProviders = (url: string): Promise => { return get(url) } export const validatePluginProviderKey = ({ url, body }: { url: string, body: { credentials: any } }): Promise => { return post(url, { body }) } export const updatePluginProviderAIKey = ({ url, body }: { url: string, body: { credentials: any } }): Promise => { return post(url, { body }) } export const invitationCheck = ({ url, params }: { url: string, params: { workspace_id?: string, email?: string, token: string } }): Promise => { return get(url, { params }) } export const activateMember = ({ url, body }: { url: string, body: any }): Promise => { return post(url, { body }) } export const fetchModelProviders = (url: string): Promise<{ data: ModelProvider[] }> => { return get<{ data: ModelProvider[] }>(url) } export type ModelProviderCredentials = { credentials?: Record load_balancing: ModelLoadBalancingConfig } export const fetchModelProviderCredentials = (url: string): Promise => { return get(url) } export const fetchModelLoadBalancingConfig = (url: string): Promise<{ credentials?: Record load_balancing: ModelLoadBalancingConfig }> => { return get<{ credentials?: Record load_balancing: ModelLoadBalancingConfig }>(url) } export const fetchModelProviderModelList = (url: string): Promise<{ data: ModelItem[] }> => { return get<{ data: ModelItem[] }>(url) } export const fetchModelList = (url: string): Promise<{ data: Model[] }> => { return get<{ data: Model[] }>(url) } export const validateModelProvider = ({ url, body }: { url: string, body: any }): Promise => { return post(url, { body }) } export const validateModelLoadBalancingCredentials = ({ url, body }: { url: string, body: any }): Promise => { return post(url, { body }) } export const setModelProvider = ({ url, body }: { url: string, body: any }): Promise => { return post(url, { body }) } export const deleteModelProvider = ({ url, body }: { url: string, body?: any }): Promise => { return del(url, { body }) } export const changeModelProviderPriority = ({ url, body }: { url: string, body: any }): Promise => { return post(url, { body }) } export const setModelProviderModel = ({ url, body }: { url: string, body: any }): Promise => { return post(url, { body }) } export const deleteModelProviderModel = ({ url }: { url: string }): Promise => { return del(url) } export const getPayUrl = (url: string): Promise<{ url: string }> => { return get<{ url: string }>(url) } export const fetchDefaultModal = (url: string): Promise<{ data: DefaultModelResponse }> => { return get<{ data: DefaultModelResponse }>(url) } export const updateDefaultModel = ({ url, body }: { url: string, body: any }): Promise => { return post(url, { body }) } export const fetchModelParameterRules = (url: string): Promise<{ data: ModelParameterRule[] }> => { return get<{ data: ModelParameterRule[] }>(url) } export const fetchFileUploadConfig = ({ url }: { url: string }): Promise => { return get(url) } export const fetchNotionConnection = (url: string): Promise<{ data: string }> => { return get<{ data: string }>(url) } export const fetchDataSourceNotionBinding = (url: string): Promise<{ result: string }> => { return get<{ result: string }>(url) } export const fetchApiBasedExtensionList = (url: string): Promise => { return get(url) } export const fetchApiBasedExtensionDetail = (url: string): Promise => { return get(url) } export const addApiBasedExtension = ({ url, body }: { url: string, body: ApiBasedExtension }): Promise => { return post(url, { body }) } export const updateApiBasedExtension = ({ url, body }: { url: string, body: ApiBasedExtension }): Promise => { return post(url, { body }) } export const deleteApiBasedExtension = (url: string): Promise<{ result: string }> => { return del<{ result: string }>(url) } export const fetchCodeBasedExtensionList = (url: string): Promise => { return get(url) } 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 = (url: string): Promise => { return get(url) } export const getSystemFeatures = (): Promise => { return get('/system-features') } 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 }): Promise => patch(url, { body }) export const sendForgotPasswordEmail = ({ url, body }: { url: string, body: { email: string } }): Promise => post(url, { body }) export const verifyForgotPasswordToken = ({ url, body }: { url: string, body: { token: string } }): Promise => { return post(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 = ({ url, body }: { url: string, body: { email: string } }): Promise => post(url, { body }, { isPublicAPI: true }) export const verifyWebAppForgotPasswordToken = ({ url, body }: { url: string, body: { token: string } }): Promise => { return post(url, { body }, { isPublicAPI: true }) } export const changeWebAppPasswordWithToken = ({ url, body }: { url: string, body: { token: string, new_password: string, password_confirm: string } }): Promise => post(url, { body }, { isPublicAPI: true }) export const uploadRemoteFileInfo = (url: string, isPublic?: boolean, silent?: boolean): Promise<{ id: string, name: string, size: number, mime_type: string, url: string }> => { return post<{ id: string, name: string, size: number, mime_type: string, url: string }>('/remote-files/upload', { body: { url } }, { isPublicAPI: isPublic, silent }) } export const sendEMailLoginCode = (email: string, language = 'en-US'): Promise => post('/email-code-login', { body: { email, language } }) export const emailLoginWithCode = (data: { email: string, code: string, token: string, language: string }): Promise => post('/email-code-login/validity', { body: data }) export const sendResetPasswordCode = (email: string, language = 'en-US'): Promise => post('/forgot-password', { body: { email, language } }) export const verifyResetPasswordCode = (body: { email: string, code: string, token: string }): Promise => post('/forgot-password/validity', { body }) export const sendWebAppEMailLoginCode = (email: string, language = 'en-US'): Promise => post('/email-code-login', { body: { email, language } }, { isPublicAPI: true }) export const webAppEmailLoginWithCode = (data: { email: string, code: string, token: string }): Promise => post('/email-code-login/validity', { body: data }, { isPublicAPI: true }) export const sendWebAppResetPasswordCode = (email: string, language = 'en-US'): Promise => post('/forgot-password', { body: { email, language } }, { isPublicAPI: true }) export const verifyWebAppResetPasswordCode = (body: { email: string, code: string, token: string }): Promise => post('/forgot-password/validity', { body }, { isPublicAPI: true }) export const sendDeleteAccountCode = (): Promise => get('/account/delete/verify') export const verifyDeleteAccountCode = (body: { code: string, token: string }): Promise => post('/account/delete', { body }) export const submitDeleteAccountFeedback = (body: { feedback: string, email: string }): Promise => post('/account/delete/feedback', { body }) export const getDocDownloadUrl = (doc_name: string): Promise<{ url: string }> => get<{ url: string }>('/compliance/download', { params: { doc_name } }, { silent: true }) export const sendVerifyCode = (body: { email: string, phase: string, token?: string }): Promise => post('/account/change-email', { body }) export const verifyEmail = (body: { email: string, code: string, token: string }): Promise => post('/account/change-email/validity', { body }) export const resetEmail = (body: { new_email: string, token: string }): Promise => post('/account/change-email/reset', { body }) export const checkEmailExisted = (body: { email: string }): Promise => post('/account/change-email/check-email-unique', { body }, { silent: true })