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