import type { DefaultModelResponse, Model, ModelItem, ModelParameterRule, ModelTypeEnum, } from '@/app/components/header/account-setting/model-provider-page/declarations' import type { CommonResponse, ICurrentWorkspace, InitValidateStatusResponse, InvitationResponse, SetupStatusResponse, } from '@/models/common' import { del, get, patch, post } 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 updateUserProfile = ({ url, body }: { url: string, body: Record }): Promise => { return post(url, { body }) } export const inviteMember = ({ url, body }: { url: string, body: Record }): Promise => { return post(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 updateCurrentWorkspace = ({ 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 }) } type InvitationCheckData = { workspace_name: string email: string workspace_id: string account_status?: string requires_setup?: boolean } type ActivateMemberBody = { token: string name?: string interface_language?: string timezone?: string } 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: ActivateMemberBody }): Promise => { return post(url, { body }) } 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 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 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 changePasswordWithToken = ({ url, body }: { url: string, body: { token: string, new_password: string, password_confirm: string } }): Promise => post(url, { body }) 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 timezone?: 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 }) export const getAvatar = async ({ avatar }: { avatar: string }): Promise<{ avatar_url: string }> => { const { consoleClient } = await import('./client') return consoleClient.account.avatar.get({ query: { avatar } }) }