apps.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import type { Fetcher } from 'swr'
  2. import { del, get, post } from './base'
  3. import type { ApikeysListResponse, AppDailyConversationsResponse, AppDailyEndUsersResponse, AppDetailResponse, AppListResponse, AppTemplatesResponse, AppTokenCostsResponse, CreateApiKeyResponse, GenerationIntroductionResponse, UpdateAppModelConfigResponse, UpdateAppNameResponse, UpdateAppSiteCodeResponse, UpdateOpenAIKeyResponse, ValidateOpenAIKeyResponse } from '@/models/app'
  4. import type { CommonResponse } from '@/models/common'
  5. import type { AppMode, ModelConfig } from '@/types/app'
  6. export const fetchAppList: Fetcher<AppListResponse, { url: string; params?: Record<string, any> }> = ({ url, params }) => {
  7. return get(url, { params }) as Promise<AppListResponse>
  8. }
  9. export const fetchAppDetail: Fetcher<AppDetailResponse, { url: string; id: string }> = ({ url, id }) => {
  10. return get(`${url}/${id}`) as Promise<AppDetailResponse>
  11. }
  12. export const fetchAppTemplates: Fetcher<AppTemplatesResponse, { url: string }> = ({ url }) => {
  13. return get(url) as Promise<AppTemplatesResponse>
  14. }
  15. export const createApp: Fetcher<AppDetailResponse, { name: string; icon: string, icon_background: string, mode: AppMode; config?: ModelConfig }> = ({ name, icon, icon_background, mode, config }) => {
  16. return post('apps', { body: { name, icon, icon_background, mode, model_config: config } }) as Promise<AppDetailResponse>
  17. }
  18. export const deleteApp: Fetcher<CommonResponse, string> = (appID) => {
  19. return del(`apps/${appID}`) as Promise<CommonResponse>
  20. }
  21. // path: /apps/{appId}/name
  22. export const updateAppName: Fetcher<UpdateAppNameResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  23. return post(url, { body }) as Promise<UpdateAppNameResponse>
  24. }
  25. export const updateAppSiteStatus: Fetcher<AppDetailResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  26. return post(url, { body }) as Promise<AppDetailResponse>
  27. }
  28. export const updateAppApiStatus: Fetcher<AppDetailResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  29. return post(url, { body }) as Promise<AppDetailResponse>
  30. }
  31. // path: /apps/{appId}/rate-limit
  32. export const updateAppRateLimit: Fetcher<AppDetailResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  33. return post(url, { body }) as Promise<AppDetailResponse>
  34. }
  35. export const updateAppSiteAccessToken: Fetcher<UpdateAppSiteCodeResponse, { url: string }> = ({ url }) => {
  36. return post(url) as Promise<UpdateAppSiteCodeResponse>
  37. }
  38. export const updateAppSiteConfig: Fetcher<AppDetailResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  39. return post(url, { body }) as Promise<AppDetailResponse>
  40. }
  41. export const getAppDailyConversations: Fetcher<AppDailyConversationsResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  42. return get(url, { params }) as Promise<AppDailyConversationsResponse>
  43. }
  44. export const getAppDailyEndUsers: Fetcher<AppDailyEndUsersResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  45. return get(url, { params }) as Promise<AppDailyEndUsersResponse>
  46. }
  47. export const getAppTokenCosts: Fetcher<AppTokenCostsResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  48. return get(url, { params }) as Promise<AppTokenCostsResponse>
  49. }
  50. export const updateAppModelConfig: Fetcher<UpdateAppModelConfigResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  51. return post(url, { body }) as Promise<UpdateAppModelConfigResponse>
  52. }
  53. // For temp testing
  54. export const fetchAppListNoMock: Fetcher<AppListResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  55. return get(url, params) as Promise<AppListResponse>
  56. }
  57. export const fetchApiKeysList: Fetcher<ApikeysListResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  58. return get(url, params) as Promise<ApikeysListResponse>
  59. }
  60. export const delApikey: Fetcher<CommonResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  61. return del(url, params) as Promise<CommonResponse>
  62. }
  63. export const createApikey: Fetcher<CreateApiKeyResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  64. return post(url, body) as Promise<CreateApiKeyResponse>
  65. }
  66. export const validateOpenAIKey: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: { token: string } }> = ({ url, body }) => {
  67. return post(url, { body }) as Promise<ValidateOpenAIKeyResponse>
  68. }
  69. export const updateOpenAIKey: Fetcher<UpdateOpenAIKeyResponse, { url: string; body: { token: string } }> = ({ url, body }) => {
  70. return post(url, { body }) as Promise<UpdateOpenAIKeyResponse>
  71. }
  72. export const generationIntroduction: Fetcher<GenerationIntroductionResponse, { url: string; body: { prompt_template: string } }> = ({ url, body }) => {
  73. return post(url, { body }) as Promise<GenerationIntroductionResponse>
  74. }