common.ts 8.0 KB

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