90 lines
3.0 KiB
TypeScript
90 lines
3.0 KiB
TypeScript
/**
|
|
* features/chat/api/chat.api.ts
|
|
* 聊天域 HTTP API:会话、消息、源文件、附件上传。
|
|
*/
|
|
import { getAuthHeaders } from '@/shared/utils/auth';
|
|
import { requestJson } from '@/shared/api/client';
|
|
import type {
|
|
ChatCrossAgentHistoryItem,
|
|
ChatMessage,
|
|
ChatQueryPreviewPage,
|
|
ChatSessionItem,
|
|
ChatSourceFileResult,
|
|
ChatUploadResult,
|
|
OaEmployeesResponse,
|
|
} from '../types/chat.types';
|
|
|
|
const auth = () => ({ headers: getAuthHeaders() });
|
|
const jsonAuth = () => ({ headers: { 'Content-Type': 'application/json', ...getAuthHeaders() } });
|
|
|
|
export const listChatSessions = (agentId: number) =>
|
|
requestJson<ChatSessionItem[]>(`/api/chat/sessions?agent_id=${agentId}`, auth());
|
|
|
|
export const deleteAllChatSessions = (agentId: number) =>
|
|
requestJson(`/api/chat/sessions?agent_id=${agentId}`, { method: 'DELETE', ...auth() });
|
|
|
|
export const deleteChatSession = (conversationId: string, agentId: number) =>
|
|
requestJson(`/api/chat/sessions/${conversationId}?agent_id=${agentId}`, { method: 'DELETE', ...auth() });
|
|
|
|
export const listChatMessages = (conversationId: string, agentId: number) =>
|
|
requestJson<ChatMessage[]>(`/api/chat/messages?conversation_id=${conversationId}&agent_id=${agentId}`, auth());
|
|
|
|
export const saveLocalChatMessage = (payload: Record<string, unknown>) =>
|
|
requestJson<{ conversation_id?: string; chat_log_id?: number }>('/api/chat/messages/local', {
|
|
method: 'POST',
|
|
...jsonAuth(),
|
|
body: JSON.stringify(payload),
|
|
});
|
|
|
|
export const resolveChatSourceFile = (params: {
|
|
agent_id: number;
|
|
dataset_id: string;
|
|
remote_document_id: string;
|
|
}) => {
|
|
const qs = new URLSearchParams({
|
|
agent_id: String(params.agent_id),
|
|
dataset_id: params.dataset_id,
|
|
remote_document_id: params.remote_document_id,
|
|
});
|
|
return requestJson<ChatSourceFileResult>(`/api/chat/source-file?${qs.toString()}`, auth());
|
|
};
|
|
|
|
export const listOaEmployees = (
|
|
agentId: number,
|
|
query: { keyword?: string; page?: number; page_size?: number },
|
|
) => {
|
|
const qs = new URLSearchParams({
|
|
agent_id: String(agentId),
|
|
keyword: query.keyword || '',
|
|
page: String(query.page ?? 1),
|
|
page_size: String(query.page_size ?? 20),
|
|
});
|
|
return requestJson<OaEmployeesResponse>(`/api/chat/oa/employees?${qs.toString()}`, auth());
|
|
};
|
|
|
|
export const uploadChatFile = (agentId: number, file: File) => {
|
|
const qs = new URLSearchParams({ agent_id: String(agentId) });
|
|
const fd = new FormData();
|
|
fd.append('file', file);
|
|
return requestJson<ChatUploadResult>(`/api/chat/files/upload?${qs.toString()}`, {
|
|
method: 'POST',
|
|
body: fd,
|
|
headers: getAuthHeaders(),
|
|
});
|
|
};
|
|
|
|
export const getChatQueryPreviewPage = (
|
|
agentId: number,
|
|
chatLogId: number,
|
|
query: { page?: number; page_size?: number } = {},
|
|
) => {
|
|
const qs = new URLSearchParams({
|
|
agent_id: String(agentId),
|
|
page: String(query.page ?? 1),
|
|
page_size: String(query.page_size ?? 100),
|
|
});
|
|
return requestJson<ChatQueryPreviewPage>(`/api/chat/query-preview/${chatLogId}?${qs.toString()}`, auth());
|
|
};
|
|
|
|
export type { ChatSessionItem, ChatCrossAgentHistoryItem };
|