import type { AxiosProgressEvent, GenericAbortSignal } from 'axios' import { get, post } from '@/utils/request' import type { AuditConfig, CHATMODEL, ConfigState, KeyConfig, MailConfig, SiteConfig, Status, UserRole } from '@/components/common/Setting/model' import { useAuthStore, useSettingStore } from '@/store' export function fetchChatAPI( prompt: string, options?: { conversationId?: string; parentMessageId?: string }, signal?: GenericAbortSignal, ) { return post({ url: '/chat', data: { prompt, options }, signal, }) } export function fetchChatConfig() { return post({ url: '/config', }) } export function fetchChatAPIProcess( params: { roomId: number uuid: number regenerate?: boolean prompt: string options?: { conversationId?: string; parentMessageId?: string } signal?: GenericAbortSignal onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void }, ) { const settingStore = useSettingStore() const authStore = useAuthStore() let data: Record = { roomId: params.roomId, uuid: params.uuid, regenerate: params.regenerate || false, prompt: params.prompt, options: params.options, } if (authStore.isChatGPTAPI) { data = { ...data, systemMessage: settingStore.systemMessage, temperature: settingStore.temperature, top_p: settingStore.top_p, } } return post({ url: '/chat-process', data, signal: params.signal, onDownloadProgress: params.onDownloadProgress, }) } export function fetchChatStopResponding(text: string, messageId: string, conversationId: string) { return post({ url: '/chat-abort', data: { text, messageId, conversationId }, }) } export function fetchChatResponseoHistory(roomId: number, uuid: number, index: number) { return get({ url: '/chat-response-history', data: { roomId, uuid, index }, }) } export function fetchSession() { return post({ url: '/session', }) } export function fetchVerify(token: string) { return post({ url: '/verify', data: { token }, }) } export function fetchVerifyAdmin(token: string) { return post({ url: '/verifyadmin', data: { token }, }) } export function fetchLogin(username: string, password: string) { return post({ url: '/user-login', data: { username, password }, }) } export function fetchSendResetMail(username: string) { return post({ url: '/user-send-reset-mail', data: { username }, }) } export function fetchResetPassword(username: string, password: string, sign: string) { return post({ url: '/user-reset-password', data: { username, password, sign }, }) } export function fetchRegister(username: string, password: string) { return post({ url: '/user-register', data: { username, password }, }) } export function fetchUpdateUserInfo(name: string, avatar: string, description: string) { return post({ url: '/user-info', data: { name, avatar, description }, }) } export function fetchUpdateUserChatModel(chatModel: CHATMODEL) { return post({ url: '/user-chat-model', data: { chatModel }, }) } export function fetchGetUsers(page: number, size: number) { return get({ url: '/users', data: { page, size }, }) } export function fetchUpdateUserStatus(userId: string, status: Status) { return post({ url: '/user-status', data: { userId, status }, }) } export function fetchUpdateUserRole(userId: string, roles: UserRole[]) { return post({ url: '/user-role', data: { userId, roles }, }) } export function fetchGetChatRooms() { return get({ url: '/chatrooms', }) } export function fetchCreateChatRoom(title: string, roomId: number) { return post({ url: '/room-create', data: { title, roomId }, }) } export function fetchRenameChatRoom(title: string, roomId: number) { return post({ url: '/room-rename', data: { title, roomId }, }) } export function fetchUpdateChatRoomPrompt(prompt: string, roomId: number) { return post({ url: '/room-prompt', data: { prompt, roomId }, }) } export function fetchUpdateChatRoomUsingContext(using: boolean, roomId: number) { return post({ url: '/room-context', data: { using, roomId }, }) } export function fetchDeleteChatRoom(roomId: number) { return post({ url: '/room-delete', data: { roomId }, }) } export function fetchGetChatHistory(roomId: number, lastId?: number) { return get({ url: `/chat-history?roomId=${roomId}&lastId=${lastId}`, }) } export function fetchClearAllChat() { return post({ url: '/chat-clear-all', data: { }, }) } export function fetchClearChat(roomId: number) { return post({ url: '/chat-clear', data: { roomId }, }) } export function fetchDeleteChat(roomId: number, uuid: number, inversion?: boolean) { return post({ url: '/chat-delete', data: { roomId, uuid, inversion }, }) } export function fetchUpdateMail(mail: MailConfig) { return post({ url: '/setting-mail', data: mail, }) } export function fetchTestMail(mail: MailConfig) { return post({ url: '/mail-test', data: mail, }) } export function fetchUpdateAudit(audit: AuditConfig) { return post({ url: '/setting-audit', data: audit, }) } export function fetchTestAudit(text: string, audit: AuditConfig) { return post({ url: '/audit-test', data: { audit, text }, }) } export function fetchUpdateSite(config: SiteConfig) { return post({ url: '/setting-site', data: config, }) } export function fetchUpdateBaseSetting(config: ConfigState) { return post({ url: '/setting-base', data: config, }) } export function fetchUserStatistics(start: number, end: number) { return post({ url: '/statistics/by-day', data: { start, end }, }) } export function fetchGetKeys(page: number, size: number) { return get({ url: '/setting-keys', data: { page, size }, }) } export function fetchUpdateApiKeyStatus(id: string, status: Status) { return post({ url: '/setting-key-status', data: { id, status }, }) } export function fetchUpsertApiKey(keyConfig: KeyConfig) { return post({ url: '/setting-key-upsert', data: keyConfig, }) }