2023-05-15 08:51:32 +08:00
|
|
|
import type { Fetcher } from 'swr'
|
2024-04-08 18:51:46 +08:00
|
|
|
import { del, get, post, put } from './base'
|
|
|
|
import type { ApikeysListResponse, AppDailyConversationsResponse, AppDailyEndUsersResponse, AppDetailResponse, AppListResponse, AppStatisticsResponse, AppTemplatesResponse, AppTokenCostsResponse, AppVoicesListResponse, CreateApiKeyResponse, GenerationIntroductionResponse, UpdateAppModelConfigResponse, UpdateAppSiteCodeResponse, UpdateOpenAIKeyResponse, ValidateOpenAIKeyResponse, WorkflowDailyConversationsResponse } from '@/models/app'
|
2023-05-15 08:51:32 +08:00
|
|
|
import type { CommonResponse } from '@/models/common'
|
|
|
|
import type { AppMode, ModelConfig } from '@/types/app'
|
|
|
|
|
2023-05-20 21:55:47 +08:00
|
|
|
export const fetchAppList: Fetcher<AppListResponse, { url: string; params?: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<AppListResponse>(url, { params })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
2023-09-27 08:54:52 +08:00
|
|
|
export const fetchAppDetail = ({ url, id }: { url: string; id: string }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<AppDetailResponse>(`${url}/${id}`)
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchAppTemplates: Fetcher<AppTemplatesResponse, { url: string }> = ({ url }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<AppTemplatesResponse>(url)
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
2024-04-08 18:51:46 +08:00
|
|
|
export const createApp: Fetcher<AppDetailResponse, { name: string; icon: string; icon_background: string; mode: AppMode; description?: string; config?: ModelConfig }> = ({ name, icon, icon_background, mode, description, config }) => {
|
|
|
|
return post<AppDetailResponse>('apps', { body: { name, icon, icon_background, mode, description, model_config: config } })
|
|
|
|
}
|
|
|
|
|
|
|
|
export const updateAppInfo: Fetcher<AppDetailResponse, { appID: string; name: string; icon: string; icon_background: string; description: string }> = ({ appID, name, icon, icon_background, description }) => {
|
|
|
|
return put<AppDetailResponse>(`apps/${appID}`, { body: { name, icon, icon_background, description } })
|
|
|
|
}
|
|
|
|
|
|
|
|
export const copyApp: Fetcher<AppDetailResponse, { appID: string; name: string; icon: string; icon_background: string; mode: AppMode; description?: string }> = ({ appID, name, icon, icon_background, mode, description }) => {
|
|
|
|
return post<AppDetailResponse>(`apps/${appID}/copy`, { body: { name, icon, icon_background, mode, description } })
|
|
|
|
}
|
|
|
|
|
|
|
|
export const exportAppConfig: Fetcher<{ data: string }, string> = (appID) => {
|
|
|
|
return get<{ data: string }>(`apps/${appID}/export`)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const importApp: Fetcher<AppDetailResponse, { data: string; name?: string; description?: string; icon?: string; icon_background?: string }> = ({ data, name, description, icon, icon_background }) => {
|
|
|
|
return post<AppDetailResponse>('apps/import', { body: { data, name, description, icon, icon_background } })
|
|
|
|
}
|
|
|
|
|
|
|
|
export const switchApp: Fetcher<{ new_app_id: string }, { appID: string; name: string; icon: string; icon_background: string }> = ({ appID, name, icon, icon_background }) => {
|
|
|
|
return post<{ new_app_id: string }>(`apps/${appID}/convert-to-workflow`, { body: { name, icon, icon_background } })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const deleteApp: Fetcher<CommonResponse, string> = (appID) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return del<CommonResponse>(`apps/${appID}`)
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const updateAppSiteStatus: Fetcher<AppDetailResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<AppDetailResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const updateAppApiStatus: Fetcher<AppDetailResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<AppDetailResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// path: /apps/{appId}/rate-limit
|
|
|
|
export const updateAppRateLimit: Fetcher<AppDetailResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<AppDetailResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const updateAppSiteAccessToken: Fetcher<UpdateAppSiteCodeResponse, { url: string }> = ({ url }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<UpdateAppSiteCodeResponse>(url)
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
2023-09-27 08:54:52 +08:00
|
|
|
export const updateAppSiteConfig = ({ url, body }: { url: string; body: Record<string, any> }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<AppDetailResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const getAppDailyConversations: Fetcher<AppDailyConversationsResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<AppDailyConversationsResponse>(url, { params })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
2024-04-08 18:51:46 +08:00
|
|
|
export const getWorkflowDailyConversations: Fetcher<WorkflowDailyConversationsResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
|
|
|
return get<WorkflowDailyConversationsResponse>(url, { params })
|
|
|
|
}
|
|
|
|
|
2023-05-31 11:21:30 +08:00
|
|
|
export const getAppStatistics: Fetcher<AppStatisticsResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<AppStatisticsResponse>(url, { params })
|
2023-05-31 11:21:30 +08:00
|
|
|
}
|
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
export const getAppDailyEndUsers: Fetcher<AppDailyEndUsersResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<AppDailyEndUsersResponse>(url, { params })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const getAppTokenCosts: Fetcher<AppTokenCostsResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<AppTokenCostsResponse>(url, { params })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const updateAppModelConfig: Fetcher<UpdateAppModelConfigResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<UpdateAppModelConfigResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// For temp testing
|
|
|
|
export const fetchAppListNoMock: Fetcher<AppListResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<AppListResponse>(url, params)
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchApiKeysList: Fetcher<ApikeysListResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<ApikeysListResponse>(url, params)
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const delApikey: Fetcher<CommonResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return del<CommonResponse>(url, params)
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const createApikey: Fetcher<CreateApiKeyResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CreateApiKeyResponse>(url, body)
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const validateOpenAIKey: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: { token: string } }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<ValidateOpenAIKeyResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const updateOpenAIKey: Fetcher<UpdateOpenAIKeyResponse, { url: string; body: { token: string } }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<UpdateOpenAIKeyResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const generationIntroduction: Fetcher<GenerationIntroductionResponse, { url: string; body: { prompt_template: string } }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<GenerationIntroductionResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
2024-02-15 22:41:18 +08:00
|
|
|
|
2024-02-18 15:39:25 +08:00
|
|
|
export const fetchAppVoices: Fetcher<AppVoicesListResponse, { appId: string; language?: string }> = ({ appId, language }) => {
|
|
|
|
return get<AppVoicesListResponse>(`apps/${appId}/text-to-audio/voices?language=${language}`)
|
2024-02-15 22:41:18 +08:00
|
|
|
}
|