dify/web/service/apps.ts

96 lines
4.5 KiB
TypeScript
Raw Normal View History

2023-05-15 08:51:32 +08:00
import type { Fetcher } from 'swr'
import { del, get, post } from './base'
import type { ApikeysListResponse, AppDailyConversationsResponse, AppDailyEndUsersResponse, AppDetailResponse, AppListResponse, AppStatisticsResponse, AppTemplatesResponse, AppTokenCostsResponse, CreateApiKeyResponse, GenerationIntroductionResponse, UpdateAppModelConfigResponse, UpdateAppSiteCodeResponse, UpdateOpenAIKeyResponse, ValidateOpenAIKeyResponse } from '@/models/app'
2023-05-15 08:51:32 +08:00
import type { CommonResponse } from '@/models/common'
import type { AppMode, ModelConfig } from '@/types/app'
export const fetchAppList: Fetcher<AppListResponse, { url: string; params?: Record<string, any> }> = ({ url, params }) => {
return get<AppListResponse>(url, { params })
2023-05-15 08:51:32 +08:00
}
export const fetchAppDetail = ({ url, id }: { url: string; id: string }) => {
return get<AppDetailResponse>(`${url}/${id}`)
2023-05-15 08:51:32 +08:00
}
export const fetchAppTemplates: Fetcher<AppTemplatesResponse, { url: string }> = ({ url }) => {
return get<AppTemplatesResponse>(url)
2023-05-15 08:51:32 +08:00
}
2023-05-31 11:21:30 +08:00
export const createApp: Fetcher<AppDetailResponse, { name: string; icon: string; icon_background: string; mode: AppMode; config?: ModelConfig }> = ({ name, icon, icon_background, mode, config }) => {
return post<AppDetailResponse>('apps', { body: { name, icon, icon_background, mode, model_config: config } })
2023-05-15 08:51:32 +08:00
}
export const deleteApp: Fetcher<CommonResponse, string> = (appID) => {
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 }) => {
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 }) => {
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 }) => {
return post<AppDetailResponse>(url, { body })
2023-05-15 08:51:32 +08:00
}
export const updateAppSiteAccessToken: Fetcher<UpdateAppSiteCodeResponse, { url: string }> = ({ url }) => {
return post<UpdateAppSiteCodeResponse>(url)
2023-05-15 08:51:32 +08:00
}
export const updateAppSiteConfig = ({ url, body }: { url: string; body: Record<string, any> }) => {
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 }) => {
return get<AppDailyConversationsResponse>(url, { params })
2023-05-15 08:51:32 +08:00
}
2023-05-31 11:21:30 +08:00
export const getAppStatistics: Fetcher<AppStatisticsResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
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 }) => {
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 }) => {
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 }) => {
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 }) => {
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 }) => {
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 }) => {
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 }) => {
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 }) => {
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 }) => {
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 }) => {
return post<GenerationIntroductionResponse>(url, { body })
2023-05-15 08:51:32 +08:00
}