| 
									
										
										
										
											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-11-06 19:36:32 +08:00
										 |  |  |   AccountIntegrate, | 
					
						
							|  |  |  |   ApiBasedExtension, | 
					
						
							|  |  |  |   CodeBasedExtension, | 
					
						
							|  |  |  |   CommonResponse, | 
					
						
							|  |  |  |   DataSourceNotion, | 
					
						
							| 
									
										
										
										
											2023-08-16 23:14:27 +08:00
										 |  |  |   FileUploadConfigResponse, | 
					
						
							| 
									
										
										
										
											2023-08-15 13:35:47 +08:00
										 |  |  |   ICurrentWorkspace, | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |   IWorkspace, | 
					
						
							| 
									
										
										
										
											2024-02-01 15:03:56 +08:00
										 |  |  |   InitValidateStatusResponse, | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |   InvitationResponse, | 
					
						
							|  |  |  |   LangGeniusVersionResponse, | 
					
						
							|  |  |  |   Member, | 
					
						
							|  |  |  |   ModerateResponse, | 
					
						
							|  |  |  |   OauthResponse, | 
					
						
							|  |  |  |   PluginProvider, | 
					
						
							|  |  |  |   Provider, | 
					
						
							|  |  |  |   ProviderAnthropicToken, | 
					
						
							|  |  |  |   ProviderAzureToken, | 
					
						
							|  |  |  |   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' | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | import type { | 
					
						
							|  |  |  |   DefaultModelResponse, | 
					
						
							|  |  |  |   Model, | 
					
						
							|  |  |  |   ModelItem, | 
					
						
							| 
									
										
										
										
											2024-06-05 00:13:29 +08:00
										 |  |  |   ModelLoadBalancingConfig, | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  |   ModelParameterRule, | 
					
						
							|  |  |  |   ModelProvider, | 
					
						
							| 
									
										
										
										
											2024-06-05 00:13:29 +08:00
										 |  |  |   ModelTypeEnum, | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | } from '@/app/components/header/account-setting/model-provider-page/declarations' | 
					
						
							| 
									
										
										
										
											2023-11-18 11:53:35 +08:00
										 |  |  | import type { RETRIEVE_METHOD } from '@/types/app' | 
					
						
							| 
									
										
										
										
											2024-05-15 16:14:49 +08:00
										 |  |  | import type { SystemFeatures } from '@/types/feature' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-12 23:40:38 +08:00
										 |  |  | type LoginSuccess = { | 
					
						
							|  |  |  |   result: 'success' | 
					
						
							| 
									
										
										
										
											2025-03-06 10:25:18 +08:00
										 |  |  |   data: { access_token: string; refresh_token: string } | 
					
						
							| 
									
										
										
										
											2024-10-12 23:40:38 +08:00
										 |  |  | } | 
					
						
							|  |  |  | type LoginFail = { | 
					
						
							|  |  |  |   result: 'fail' | 
					
						
							|  |  |  |   data: string | 
					
						
							| 
									
										
										
										
											2024-10-21 09:23:20 +08:00
										 |  |  |   code: string | 
					
						
							|  |  |  |   message: string | 
					
						
							| 
									
										
										
										
											2024-10-12 23:40:38 +08:00
										 |  |  | } | 
					
						
							|  |  |  | type LoginResponse = LoginSuccess | LoginFail | 
					
						
							|  |  |  | export const login: Fetcher<LoginResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => { | 
					
						
							|  |  |  |   return post(url, { body }) as Promise<LoginResponse> | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-06-05 10:55:17 +08:00
										 |  |  | export const webAppLogin: Fetcher<LoginResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => { | 
					
						
							|  |  |  |   return post(url, { body }, { isPublicAPI: true }) as Promise<LoginResponse> | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-10-12 23:40:38 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export const fetchNewToken: Fetcher<CommonResponse & { data: { access_token: string; refresh_token: string } }, { body: Record<string, any> }> = ({ body }) => { | 
					
						
							|  |  |  |   return post('/refresh-token', { body }) as Promise<CommonResponse & { data: { access_token: string; refresh_token: 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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-01 15:03:56 +08:00
										 |  |  | export const initValidate: Fetcher<CommonResponse, { body: Record<string, any> }> = ({ body }) => { | 
					
						
							|  |  |  |   return post<CommonResponse>('/init', { body }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const fetchInitValidateStatus = () => { | 
					
						
							|  |  |  |   return get<InitValidateStatusResponse>('/init') | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-12-18 16:25:37 +08:00
										 |  |  | export const updateCurrentWorkspace: Fetcher<ICurrentWorkspace, { url: string; body: Record<string, any> }> = ({ url, body }) => { | 
					
						
							|  |  |  |   return post<ICurrentWorkspace>(url, { body }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-03 16:05:55 +08:00
										 |  |  | export const updateWorkspaceInfo: Fetcher<ICurrentWorkspace, { url: string; body: Record<string, any> }> = ({ url, body }) => { | 
					
						
							|  |  |  |   return post<ICurrentWorkspace>(url, { body }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-21 09:23:20 +08:00
										 |  |  | export const invitationCheck: Fetcher<CommonResponse & { is_valid: boolean; data: { workspace_name: string; email: string; workspace_id: string } }, { url: string; params: { workspace_id?: string; email?: string; token: string } }> = ({ url, params }) => { | 
					
						
							|  |  |  |   return get<CommonResponse & { is_valid: boolean; data: { workspace_name: string; email: string; workspace_id: string } }>(url, { params }) | 
					
						
							| 
									
										
										
										
											2023-07-14 11:19:26 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-21 09:23:20 +08:00
										 |  |  | export const activateMember: Fetcher<LoginResponse, { url: string; body: any }> = ({ url, body }) => { | 
					
						
							|  |  |  |   return post<LoginResponse>(url, { body }) | 
					
						
							| 
									
										
										
										
											2023-07-14 11:19:26 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-08-12 00:57:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | export const fetchModelProviders: Fetcher<{ data: ModelProvider[] }, string> = (url) => { | 
					
						
							|  |  |  |   return get<{ data: ModelProvider[] }>(url) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 00:13:29 +08:00
										 |  |  | export type ModelProviderCredentials = { | 
					
						
							|  |  |  |   credentials?: Record<string, string | undefined | boolean> | 
					
						
							|  |  |  |   load_balancing: ModelLoadBalancingConfig | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | export const fetchModelProviderCredentials: Fetcher<ModelProviderCredentials, string> = (url) => { | 
					
						
							|  |  |  |   return get<ModelProviderCredentials>(url) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const fetchModelLoadBalancingConfig: Fetcher<{ | 
					
						
							|  |  |  |   credentials?: Record<string, string | undefined | boolean> | 
					
						
							|  |  |  |   load_balancing: ModelLoadBalancingConfig | 
					
						
							|  |  |  | }, string> = (url) => { | 
					
						
							|  |  |  |   return get<{ | 
					
						
							|  |  |  |     credentials?: Record<string, string | undefined | boolean> | 
					
						
							|  |  |  |     load_balancing: ModelLoadBalancingConfig | 
					
						
							|  |  |  |   }>(url) | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const fetchModelProviderModelList: Fetcher<{ data: ModelItem[] }, string> = (url) => { | 
					
						
							|  |  |  |   return get<{ data: ModelItem[] }>(url) | 
					
						
							| 
									
										
										
										
											2023-08-12 00:57:13 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | export const fetchModelList: Fetcher<{ data: Model[] }, string> = (url) => { | 
					
						
							|  |  |  |   return get<{ data: Model[] }>(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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 00:13:29 +08:00
										 |  |  | export const validateModelLoadBalancingCredentials: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: any }> = ({ url, body }) => { | 
					
						
							|  |  |  |   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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | export const deleteModelProvider: Fetcher<CommonResponse, { url: string; body?: any }> = ({ url, body }) => { | 
					
						
							|  |  |  |   return del<CommonResponse>(url, { body }) | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | export const fetchDefaultModal: Fetcher<{ data: DefaultModelResponse }, string> = (url) => { | 
					
						
							|  |  |  |   return get<{ data: DefaultModelResponse }>(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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | export const fetchModelParameterRules: Fetcher<{ data: ModelParameterRule[] }, string> = (url) => { | 
					
						
							|  |  |  |   return get<{ data: ModelParameterRule[] }>(url) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 }> | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export const fetchApiBasedExtensionList: Fetcher<ApiBasedExtension[], string> = (url) => { | 
					
						
							|  |  |  |   return get(url) as Promise<ApiBasedExtension[]> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const fetchApiBasedExtensionDetail: Fetcher<ApiBasedExtension, string> = (url) => { | 
					
						
							|  |  |  |   return get(url) as Promise<ApiBasedExtension> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const addApiBasedExtension: Fetcher<ApiBasedExtension, { url: string; body: ApiBasedExtension }> = ({ url, body }) => { | 
					
						
							|  |  |  |   return post(url, { body }) as Promise<ApiBasedExtension> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const updateApiBasedExtension: Fetcher<ApiBasedExtension, { url: string; body: ApiBasedExtension }> = ({ url, body }) => { | 
					
						
							|  |  |  |   return post(url, { body }) as Promise<ApiBasedExtension> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const deleteApiBasedExtension: Fetcher<{ result: string }, string> = (url) => { | 
					
						
							|  |  |  |   return del(url) as Promise<{ result: string }> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const fetchCodeBasedExtensionList: Fetcher<CodeBasedExtension, string> = (url) => { | 
					
						
							|  |  |  |   return get(url) as Promise<CodeBasedExtension> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const moderate = (url: string, body: { app_id: string; text: string }) => { | 
					
						
							|  |  |  |   return post(url, { body }) as Promise<ModerateResponse> | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-11-18 11:53:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | type RetrievalMethodsRes = { | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |   retrieval_method: RETRIEVE_METHOD[] | 
					
						
							| 
									
										
										
										
											2023-11-18 11:53:35 +08:00
										 |  |  | } | 
					
						
							|  |  |  | export const fetchSupportRetrievalMethods: Fetcher<RetrievalMethodsRes, string> = (url) => { | 
					
						
							|  |  |  |   return get<RetrievalMethodsRes>(url) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-05-15 16:14:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export const getSystemFeatures = () => { | 
					
						
							|  |  |  |   return get<SystemFeatures>('/system-features') | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-06-05 00:13:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export const enableModel = (url: string, body: { model: string; model_type: ModelTypeEnum }) => | 
					
						
							|  |  |  |   patch<CommonResponse>(url, { body }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const disableModel = (url: string, body: { model: string; model_type: ModelTypeEnum }) => | 
					
						
							|  |  |  |   patch<CommonResponse>(url, { body }) | 
					
						
							| 
									
										
										
										
											2024-07-05 13:38:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-21 09:23:20 +08:00
										 |  |  | export const sendForgotPasswordEmail: Fetcher<CommonResponse & { data: string }, { url: string; body: { email: string } }> = ({ url, body }) => | 
					
						
							|  |  |  |   post<CommonResponse & { data: string }>(url, { body }) | 
					
						
							| 
									
										
										
										
											2024-07-05 13:38:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export const verifyForgotPasswordToken: Fetcher<CommonResponse & { is_valid: boolean; email: string }, { url: string; body: { token: string } }> = ({ url, body }) => { | 
					
						
							|  |  |  |   return post(url, { body }) as Promise<CommonResponse & { is_valid: boolean; email: string }> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const changePasswordWithToken: Fetcher<CommonResponse, { url: string; body: { token: string; new_password: string; password_confirm: string } }> = ({ url, body }) => | 
					
						
							|  |  |  |   post<CommonResponse>(url, { body }) | 
					
						
							| 
									
										
										
										
											2024-10-21 09:23:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-05 10:55:17 +08:00
										 |  |  | export const sendWebAppForgotPasswordEmail: Fetcher<CommonResponse & { data: string }, { url: string; body: { email: string } }> = ({ url, body }) => | 
					
						
							|  |  |  |   post<CommonResponse & { data: string }>(url, { body }, { isPublicAPI: true }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const verifyWebAppForgotPasswordToken: Fetcher<CommonResponse & { is_valid: boolean; email: string }, { url: string; body: { token: string } }> = ({ url, body }) => { | 
					
						
							|  |  |  |   return post(url, { body }, { isPublicAPI: true }) as Promise<CommonResponse & { is_valid: boolean; email: string }> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const changeWebAppPasswordWithToken: Fetcher<CommonResponse, { url: string; body: { token: string; new_password: string; password_confirm: string } }> = ({ url, body }) => | 
					
						
							|  |  |  |   post<CommonResponse>(url, { body }, { isPublicAPI: true }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-02 17:03:14 +08:00
										 |  |  | export const uploadRemoteFileInfo = (url: string, isPublic?: boolean) => { | 
					
						
							|  |  |  |   return post<{ id: string; name: string; size: number; mime_type: string; url: string }>('/remote-files/upload', { body: { url } }, { isPublicAPI: isPublic }) | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2024-11-01 15:45:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-21 09:23:20 +08:00
										 |  |  | export const sendEMailLoginCode = (email: string, language = 'en-US') => | 
					
						
							|  |  |  |   post<CommonResponse & { data: string }>('/email-code-login', { body: { email, language } }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-06 10:25:18 +08:00
										 |  |  | export const emailLoginWithCode = (data: { email: string; code: string; token: string }) => | 
					
						
							| 
									
										
										
										
											2024-10-21 09:23:20 +08:00
										 |  |  |   post<LoginResponse>('/email-code-login/validity', { body: data }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const sendResetPasswordCode = (email: string, language = 'en-US') => | 
					
						
							| 
									
										
										
										
											2025-03-06 10:25:18 +08:00
										 |  |  |   post<CommonResponse & { data: string; message?: string; code?: string }>('/forgot-password', { body: { email, language } }) | 
					
						
							| 
									
										
										
										
											2024-10-21 09:23:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-06 10:25:18 +08:00
										 |  |  | export const verifyResetPasswordCode = (body: { email: string; code: string; token: string }) => | 
					
						
							| 
									
										
										
										
											2025-04-18 17:14:51 +08:00
										 |  |  |   post<CommonResponse & { is_valid: boolean; token: string }>('/forgot-password/validity', { body }) | 
					
						
							| 
									
										
										
										
											2024-12-30 13:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-05 10:55:17 +08:00
										 |  |  | export const sendWebAppEMailLoginCode = (email: string, language = 'en-US') => | 
					
						
							|  |  |  |   post<CommonResponse & { data: string }>('/email-code-login', { body: { email, language } }, { isPublicAPI: true }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const webAppEmailLoginWithCode = (data: { email: string; code: string; token: string }) => | 
					
						
							|  |  |  |   post<LoginResponse>('/email-code-login/validity', { body: data }, { isPublicAPI: true }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const sendWebAppResetPasswordCode = (email: string, language = 'en-US') => | 
					
						
							|  |  |  |   post<CommonResponse & { data: string; message?: string; code?: string }>('/forgot-password', { body: { email, language } }, { isPublicAPI: true }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const verifyWebAppResetPasswordCode = (body: { email: string; code: string; token: string }) => | 
					
						
							|  |  |  |   post<CommonResponse & { is_valid: boolean; token: string }>('/forgot-password/validity', { body }, { isPublicAPI: true }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-30 13:39:26 +08:00
										 |  |  | export const sendDeleteAccountCode = () => | 
					
						
							|  |  |  |   get<CommonResponse & { data: string }>('/account/delete/verify') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-06 10:25:18 +08:00
										 |  |  | export const verifyDeleteAccountCode = (body: { code: string; token: string }) => | 
					
						
							| 
									
										
										
										
											2024-12-30 13:39:26 +08:00
										 |  |  |   post<CommonResponse & { is_valid: boolean }>('/account/delete', { body }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-06 10:25:18 +08:00
										 |  |  | export const submitDeleteAccountFeedback = (body: { feedback: string; email: string }) => | 
					
						
							| 
									
										
										
										
											2024-12-30 13:39:26 +08:00
										 |  |  |   post<CommonResponse>('/account/delete/feedback', { body }) | 
					
						
							| 
									
										
										
										
											2025-03-06 10:25:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export const getDocDownloadUrl = (doc_name: string) => | 
					
						
							|  |  |  |   get<{ url: string }>('/compliance/download', { params: { doc_name } }, { silent: true }) |