import type { Fetcher } from 'swr' import { del, get, patch, post, put } from './base' import type { ApikeysListResponse, AppDailyConversationsResponse, AppDailyEndUsersResponse, AppDetailResponse, AppListResponse, AppStatisticsResponse, AppTemplatesResponse, AppTokenCostsResponse, AppVoicesListResponse, CreateApiKeyResponse, GenerationIntroductionResponse, TracingConfig, TracingStatus, UpdateAppModelConfigResponse, UpdateAppSiteCodeResponse, UpdateOpenAIKeyResponse, ValidateOpenAIKeyResponse, WorkflowDailyConversationsResponse } from '@/models/app' import type { CommonResponse } from '@/models/common' import type { AppMode, ModelConfig } from '@/types/app' import type { TracingProvider } from '@/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/tracing/type' export const fetchAppList: Fetcher }> = ({ url, params }) => { return get(url, { params }) } export const fetchAppDetail = ({ url, id }: { url: string; id: string }) => { return get(`${url}/${id}`) } export const fetchAppTemplates: Fetcher = ({ url }) => { return get(url) } export const createApp: Fetcher = ({ name, icon, icon_background, mode, description, config }) => { return post('apps', { body: { name, icon, icon_background, mode, description, model_config: config } }) } export const updateAppInfo: Fetcher = ({ appID, name, icon, icon_background, description }) => { return put(`apps/${appID}`, { body: { name, icon, icon_background, description } }) } export const copyApp: Fetcher = ({ appID, name, icon, icon_background, mode, description }) => { return post(`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 = ({ data, name, description, icon, icon_background }) => { return post('apps/import', { body: { data, name, description, icon, icon_background } }) } export const importAppFromUrl: Fetcher = ({ url, name, description, icon, icon_background }) => { return post('apps/import/url', { body: { url, 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 } }) } export const deleteApp: Fetcher = (appID) => { return del(`apps/${appID}`) } export const updateAppSiteStatus: Fetcher }> = ({ url, body }) => { return post(url, { body }) } export const updateAppApiStatus: Fetcher }> = ({ url, body }) => { return post(url, { body }) } // path: /apps/{appId}/rate-limit export const updateAppRateLimit: Fetcher }> = ({ url, body }) => { return post(url, { body }) } export const updateAppSiteAccessToken: Fetcher = ({ url }) => { return post(url) } export const updateAppSiteConfig = ({ url, body }: { url: string; body: Record }) => { return post(url, { body }) } export const getAppDailyConversations: Fetcher }> = ({ url, params }) => { return get(url, { params }) } export const getWorkflowDailyConversations: Fetcher }> = ({ url, params }) => { return get(url, { params }) } export const getAppStatistics: Fetcher }> = ({ url, params }) => { return get(url, { params }) } export const getAppDailyEndUsers: Fetcher }> = ({ url, params }) => { return get(url, { params }) } export const getAppTokenCosts: Fetcher }> = ({ url, params }) => { return get(url, { params }) } export const updateAppModelConfig: Fetcher }> = ({ url, body }) => { return post(url, { body }) } // For temp testing export const fetchAppListNoMock: Fetcher }> = ({ url, params }) => { return get(url, params) } export const fetchApiKeysList: Fetcher }> = ({ url, params }) => { return get(url, params) } export const delApikey: Fetcher }> = ({ url, params }) => { return del(url, params) } export const createApikey: Fetcher }> = ({ url, body }) => { return post(url, body) } export const validateOpenAIKey: Fetcher = ({ url, body }) => { return post(url, { body }) } export const updateOpenAIKey: Fetcher = ({ url, body }) => { return post(url, { body }) } export const generationIntroduction: Fetcher = ({ url, body }) => { return post(url, { body }) } export const fetchAppVoices: Fetcher = ({ appId, language }) => { language = language || 'en-US' return get(`apps/${appId}/text-to-audio/voices?language=${language}`) } // Tracing export const fetchTracingStatus: Fetcher = ({ appId }) => { return get(`/apps/${appId}/trace`) } export const updateTracingStatus: Fetcher }> = ({ appId, body }) => { return post(`/apps/${appId}/trace`, { body }) } export const fetchTracingConfig: Fetcher = ({ appId, provider }) => { return get(`/apps/${appId}/trace-config`, { params: { tracing_provider: provider, }, }) } export const addTracingConfig: Fetcher = ({ appId, body }) => { return post(`/apps/${appId}/trace-config`, { body }) } export const updateTracingConfig: Fetcher = ({ appId, body }) => { return patch(`/apps/${appId}/trace-config`, { body }) } export const removeTracingConfig: Fetcher = ({ appId, provider }) => { return del(`/apps/${appId}/trace-config?tracing_provider=${provider}`) }