import type { Fetcher } from 'swr' import { del, get, post } from './base' import type { ApikeysListResponse, AppDailyConversationsResponse, AppDailyEndUsersResponse, AppDetailResponse, AppListResponse, AppStatisticsResponse, AppTemplatesResponse, AppTokenCostsResponse, CreateApiKeyResponse, GenerationIntroductionResponse, UpdateAppModelConfigResponse, UpdateAppNameResponse, UpdateAppSiteCodeResponse, UpdateOpenAIKeyResponse, ValidateOpenAIKeyResponse } from '@/models/app' import type { CommonResponse } from '@/models/common' import type { AppMode, ModelConfig } from '@/types/app' export const fetchAppList: Fetcher }> = ({ url, params }) => { return get(url, { params }) as Promise } export const fetchAppDetail: Fetcher = ({ url, id }) => { return get(`${url}/${id}`) as Promise } export const fetchAppTemplates: Fetcher = ({ url }) => { return get(url) as Promise } export const createApp: Fetcher = ({ name, icon, icon_background, mode, config }) => { return post('apps', { body: { name, icon, icon_background, mode, model_config: config } }) as Promise } export const deleteApp: Fetcher = (appID) => { return del(`apps/${appID}`) as Promise } // path: /apps/{appId}/name export const updateAppName: Fetcher }> = ({ url, body }) => { return post(url, { body }) as Promise } export const updateAppSiteStatus: Fetcher }> = ({ url, body }) => { return post(url, { body }) as Promise } export const updateAppApiStatus: Fetcher }> = ({ url, body }) => { return post(url, { body }) as Promise } // path: /apps/{appId}/rate-limit export const updateAppRateLimit: Fetcher }> = ({ url, body }) => { return post(url, { body }) as Promise } export const updateAppSiteAccessToken: Fetcher = ({ url }) => { return post(url) as Promise } export const updateAppSiteConfig: Fetcher }> = ({ url, body }) => { return post(url, { body }) as Promise } export const getAppDailyConversations: Fetcher }> = ({ url, params }) => { return get(url, { params }) as Promise } export const getAppStatistics: Fetcher }> = ({ url, params }) => { return get(url, { params }) as Promise } export const getAppDailyEndUsers: Fetcher }> = ({ url, params }) => { return get(url, { params }) as Promise } export const getAppTokenCosts: Fetcher }> = ({ url, params }) => { return get(url, { params }) as Promise } export const updateAppModelConfig: Fetcher }> = ({ url, body }) => { return post(url, { body }) as Promise } // For temp testing export const fetchAppListNoMock: Fetcher }> = ({ url, params }) => { return get(url, params) as Promise } export const fetchApiKeysList: Fetcher }> = ({ url, params }) => { return get(url, params) as Promise } export const delApikey: Fetcher }> = ({ url, params }) => { return del(url, params) as Promise } export const createApikey: Fetcher }> = ({ url, body }) => { return post(url, body) as Promise } export const validateOpenAIKey: Fetcher = ({ url, body }) => { return post(url, { body }) as Promise } export const updateOpenAIKey: Fetcher = ({ url, body }) => { return post(url, { body }) as Promise } export const generationIntroduction: Fetcher = ({ url, body }) => { return post(url, { body }) as Promise }