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, AppStatisticsResponse, AppTemplatesResponse, AppTokenCostsResponse, CreateApiKeyResponse, GenerationIntroductionResponse, UpdateAppModelConfigResponse, 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. export const updateAppSiteStatus: Fetcher<AppDetailResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  22. return post(url, { body }) as Promise<AppDetailResponse>
  23. }
  24. export const updateAppApiStatus: Fetcher<AppDetailResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  25. return post(url, { body }) as Promise<AppDetailResponse>
  26. }
  27. // path: /apps/{appId}/rate-limit
  28. export const updateAppRateLimit: Fetcher<AppDetailResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  29. return post(url, { body }) as Promise<AppDetailResponse>
  30. }
  31. export const updateAppSiteAccessToken: Fetcher<UpdateAppSiteCodeResponse, { url: string }> = ({ url }) => {
  32. return post(url) as Promise<UpdateAppSiteCodeResponse>
  33. }
  34. export const updateAppSiteConfig: Fetcher<AppDetailResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  35. return post(url, { body }) as Promise<AppDetailResponse>
  36. }
  37. export const getAppDailyConversations: Fetcher<AppDailyConversationsResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  38. return get(url, { params }) as Promise<AppDailyConversationsResponse>
  39. }
  40. export const getAppStatistics: Fetcher<AppStatisticsResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  41. return get(url, { params }) as Promise<AppStatisticsResponse>
  42. }
  43. export const getAppDailyEndUsers: Fetcher<AppDailyEndUsersResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  44. return get(url, { params }) as Promise<AppDailyEndUsersResponse>
  45. }
  46. export const getAppTokenCosts: Fetcher<AppTokenCostsResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  47. return get(url, { params }) as Promise<AppTokenCostsResponse>
  48. }
  49. export const updateAppModelConfig: Fetcher<UpdateAppModelConfigResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  50. return post(url, { body }) as Promise<UpdateAppModelConfigResponse>
  51. }
  52. // For temp testing
  53. export const fetchAppListNoMock: Fetcher<AppListResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  54. return get(url, params) as Promise<AppListResponse>
  55. }
  56. export const fetchApiKeysList: Fetcher<ApikeysListResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  57. return get(url, params) as Promise<ApikeysListResponse>
  58. }
  59. export const delApikey: Fetcher<CommonResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  60. return del(url, params) as Promise<CommonResponse>
  61. }
  62. export const createApikey: Fetcher<CreateApiKeyResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  63. return post(url, body) as Promise<CreateApiKeyResponse>
  64. }
  65. export const validateOpenAIKey: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: { token: string } }> = ({ url, body }) => {
  66. return post(url, { body }) as Promise<ValidateOpenAIKeyResponse>
  67. }
  68. export const updateOpenAIKey: Fetcher<UpdateOpenAIKeyResponse, { url: string; body: { token: string } }> = ({ url, body }) => {
  69. return post(url, { body }) as Promise<UpdateOpenAIKeyResponse>
  70. }
  71. export const generationIntroduction: Fetcher<GenerationIntroductionResponse, { url: string; body: { prompt_template: string } }> = ({ url, body }) => {
  72. return post(url, { body }) as Promise<GenerationIntroductionResponse>
  73. }