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' import type { CommonResponse } from '@/models/common' import type { AppMode, ModelConfig } from '@/types/app' 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, config }) => { return post('apps', { body: { name, icon, icon_background, mode, model_config: config } }) } 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 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 }) }