common.ts 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import type { Fetcher } from 'swr'
  2. import { del, get, patch, post, put } from './base'
  3. import type {
  4. AccountIntegrate, CommonResponse, DataSourceNotion,
  5. DocumentsLimitResponse,
  6. FileUploadConfigResponse,
  7. ICurrentWorkspace,
  8. IWorkspace, InvitationResponse, LangGeniusVersionResponse, Member,
  9. OauthResponse, PluginProvider, Provider, ProviderAnthropicToken, ProviderAzureToken,
  10. SetupStatusResponse, UserProfileOriginResponse,
  11. } from '@/models/common'
  12. import type {
  13. UpdateOpenAIKeyResponse,
  14. ValidateOpenAIKeyResponse,
  15. } from '@/models/app'
  16. import type { BackendModel, ProviderMap } from '@/app/components/header/account-setting/model-page/declarations'
  17. export const login: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  18. return post(url, { body }) as Promise<CommonResponse>
  19. }
  20. export const setup: Fetcher<CommonResponse, { body: Record<string, any> }> = ({ body }) => {
  21. return post('/setup', { body }) as Promise<CommonResponse>
  22. }
  23. export const fetchSetupStatus = () => {
  24. return get('/setup') as Promise<SetupStatusResponse>
  25. }
  26. export const fetchUserProfile: Fetcher<UserProfileOriginResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  27. return get(url, params, { needAllResponseContent: true }) as Promise<UserProfileOriginResponse>
  28. }
  29. export const updateUserProfile: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  30. return post(url, { body }) as Promise<CommonResponse>
  31. }
  32. export const logout: Fetcher<CommonResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  33. return get(url, params) as Promise<CommonResponse>
  34. }
  35. export const fetchLanggeniusVersion: Fetcher<LangGeniusVersionResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  36. return get(url, { params }) as Promise<LangGeniusVersionResponse>
  37. }
  38. export const oauth: Fetcher<OauthResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  39. return get(url, { params }) as Promise<OauthResponse>
  40. }
  41. export const oneMoreStep: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  42. return post(url, { body }) as Promise<CommonResponse>
  43. }
  44. export const fetchMembers: Fetcher<{ accounts: Member[] | null }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  45. return get(url, { params }) as Promise<{ accounts: Member[] | null }>
  46. }
  47. export const fetchProviders: Fetcher<Provider[] | null, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  48. return get(url, { params }) as Promise<Provider[] | null>
  49. }
  50. export const validateProviderKey: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: { token: string } }> = ({ url, body }) => {
  51. return post(url, { body }) as Promise<ValidateOpenAIKeyResponse>
  52. }
  53. export const updateProviderAIKey: Fetcher<UpdateOpenAIKeyResponse, { url: string; body: { token: string | ProviderAzureToken | ProviderAnthropicToken } }> = ({ url, body }) => {
  54. return post(url, { body }) as Promise<UpdateOpenAIKeyResponse>
  55. }
  56. export const fetchAccountIntegrates: Fetcher<{ data: AccountIntegrate[] | null }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  57. return get(url, { params }) as Promise<{ data: AccountIntegrate[] | null }>
  58. }
  59. export const inviteMember: Fetcher<InvitationResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  60. return post(url, { body }) as Promise<InvitationResponse>
  61. }
  62. export const updateMemberRole: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  63. return put(url, { body }) as Promise<CommonResponse>
  64. }
  65. export const deleteMemberOrCancelInvitation: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
  66. return del(url) as Promise<CommonResponse>
  67. }
  68. export const fetchFilePreview: Fetcher<{ content: string }, { fileID: string }> = ({ fileID }) => {
  69. return get(`/files/${fileID}/preview`) as Promise<{ content: string }>
  70. }
  71. export const fetchCurrentWorkspace: Fetcher<ICurrentWorkspace, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  72. return get(url, { params }) as Promise<ICurrentWorkspace>
  73. }
  74. export const fetchWorkspaces: Fetcher<{ workspaces: IWorkspace[] }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  75. return get(url, { params }) as Promise<{ workspaces: IWorkspace[] }>
  76. }
  77. export const switchWorkspace: Fetcher<CommonResponse & { new_tenant: IWorkspace }, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  78. return post(url, { body }) as Promise<CommonResponse & { new_tenant: IWorkspace }>
  79. }
  80. export const fetchDataSource: Fetcher<{ data: DataSourceNotion[] }, { url: string }> = ({ url }) => {
  81. return get(url) as Promise<{ data: DataSourceNotion[] }>
  82. }
  83. export const syncDataSourceNotion: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
  84. return get(url) as Promise<CommonResponse>
  85. }
  86. export const updateDataSourceNotionAction: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
  87. return patch(url) as Promise<CommonResponse>
  88. }
  89. export const fetchPluginProviders: Fetcher<PluginProvider[] | null, string> = (url) => {
  90. return get(url) as Promise<PluginProvider[] | null>
  91. }
  92. export const validatePluginProviderKey: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: { credentials: any } }> = ({ url, body }) => {
  93. return post(url, { body }) as Promise<ValidateOpenAIKeyResponse>
  94. }
  95. export const updatePluginProviderAIKey: Fetcher<UpdateOpenAIKeyResponse, { url: string; body: { credentials: any } }> = ({ url, body }) => {
  96. return post(url, { body }) as Promise<UpdateOpenAIKeyResponse>
  97. }
  98. export const invitationCheck: Fetcher<CommonResponse & { is_valid: boolean; workspace_name: string }, { url: string; params: { workspace_id: string; email: string; token: string } }> = ({ url, params }) => {
  99. return get(url, { params }) as Promise<CommonResponse & { is_valid: boolean; workspace_name: string }>
  100. }
  101. export const activateMember: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
  102. return post(url, { body }) as Promise<CommonResponse>
  103. }
  104. export const fetchModelProviders: Fetcher<ProviderMap, string> = (url) => {
  105. return get(url) as Promise<ProviderMap>
  106. }
  107. export const fetchModelList: Fetcher<BackendModel[], string> = (url) => {
  108. return get(url) as Promise<BackendModel[]>
  109. }
  110. export const validateModelProvider: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: any }> = ({ url, body }) => {
  111. return post(url, { body }) as Promise<ValidateOpenAIKeyResponse>
  112. }
  113. export const setModelProvider: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
  114. return post(url, { body }) as Promise<CommonResponse>
  115. }
  116. export const deleteModelProvider: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
  117. return del(url) as Promise<CommonResponse>
  118. }
  119. export const changeModelProviderPriority: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
  120. return post(url, { body }) as Promise<CommonResponse>
  121. }
  122. export const setModelProviderModel: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
  123. return post(url, { body }) as Promise<CommonResponse>
  124. }
  125. export const deleteModelProviderModel: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
  126. return del(url) as Promise<CommonResponse>
  127. }
  128. export const getPayUrl: Fetcher<{ url: string }, string> = (url) => {
  129. return get(url) as Promise<{ url: string }>
  130. }
  131. export const fetchDefaultModal: Fetcher<BackendModel, string> = (url) => {
  132. return get(url) as Promise<BackendModel>
  133. }
  134. export const updateDefaultModel: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
  135. return post(url, { body }) as Promise<CommonResponse>
  136. }
  137. export const submitFreeQuota: Fetcher<{ type: string; redirect_url?: string; result?: string }, string> = (url) => {
  138. return post(url) as Promise<{ type: string; redirect_url?: string; result?: string }>
  139. }
  140. export const fetchFileUploadConfig: Fetcher<FileUploadConfigResponse, { url: string }> = ({ url }) => {
  141. return get(url) as Promise<FileUploadConfigResponse>
  142. }
  143. export const fetchDocumentsLimit: Fetcher<DocumentsLimitResponse, string> = (url) => {
  144. return get(url) as Promise<DocumentsLimitResponse>
  145. }