common.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import type { Fetcher } from 'swr'
  2. import { del, get, patch, post, put } from './base'
  3. import type {
  4. AccountIntegrate, CommonResponse, DataSourceNotion,
  5. IWorkspace, LangGeniusVersionResponse, Member,
  6. OauthResponse, PluginProvider, Provider, ProviderAnthropicToken, ProviderAzureToken,
  7. SetupStatusResponse, TenantInfoResponse, UserProfileOriginResponse,
  8. } from '@/models/common'
  9. import type {
  10. UpdateOpenAIKeyResponse,
  11. ValidateOpenAIKeyResponse,
  12. } from '@/models/app'
  13. export const login: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  14. return post(url, { body }) as Promise<CommonResponse>
  15. }
  16. export const setup: Fetcher<CommonResponse, { body: Record<string, any> }> = ({ body }) => {
  17. return post('/setup', { body }) as Promise<CommonResponse>
  18. }
  19. export const fetchSetupStatus = () => {
  20. return get('/setup') as Promise<SetupStatusResponse>
  21. }
  22. export const fetchUserProfile: Fetcher<UserProfileOriginResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  23. return get(url, params, { needAllResponseContent: true }) as Promise<UserProfileOriginResponse>
  24. }
  25. export const updateUserProfile: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  26. return post(url, { body }) as Promise<CommonResponse>
  27. }
  28. export const fetchTenantInfo: Fetcher<TenantInfoResponse, { url: string }> = ({ url }) => {
  29. return get(url) as Promise<TenantInfoResponse>
  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 fetchWorkspaces: Fetcher<{ workspaces: IWorkspace[] }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  71. return get(url, { params }) as Promise<{ workspaces: IWorkspace[] }>
  72. }
  73. export const switchWorkspace: Fetcher<CommonResponse & { new_tenant: IWorkspace }, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  74. return post(url, { body }) as Promise<CommonResponse & { new_tenant: IWorkspace }>
  75. }
  76. export const fetchDataSource: Fetcher<{ data: DataSourceNotion[] }, { url: string }> = ({ url }) => {
  77. return get(url) as Promise<{ data: DataSourceNotion[] }>
  78. }
  79. export const syncDataSourceNotion: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
  80. return get(url) as Promise<CommonResponse>
  81. }
  82. export const updateDataSourceNotionAction: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
  83. return patch(url) as Promise<CommonResponse>
  84. }
  85. export const fetchPluginProviders: Fetcher<PluginProvider[] | null, string> = (url) => {
  86. return get(url) as Promise<PluginProvider[] | null>
  87. }
  88. export const validatePluginProviderKey: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: { credentials: any } }> = ({ url, body }) => {
  89. return post(url, { body }) as Promise<ValidateOpenAIKeyResponse>
  90. }
  91. export const updatePluginProviderAIKey: Fetcher<UpdateOpenAIKeyResponse, { url: string; body: { credentials: any } }> = ({ url, body }) => {
  92. return post(url, { body }) as Promise<UpdateOpenAIKeyResponse>
  93. }
  94. export const invitationCheck: Fetcher<CommonResponse & { is_valid: boolean; workspace_name: string }, { url: string; params: { workspace_id: string; email: string; token: string } }> = ({ url, params }) => {
  95. return get(url, { params }) as Promise<CommonResponse & { is_valid: boolean; workspace_name: string }>
  96. }
  97. export const activateMember: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
  98. return post(url, { body }) as Promise<CommonResponse>
  99. }