common.ts 8.0 KB

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