refactor(chat + workspace): chat和workspace重构,子路由、懒加载等

This commit is contained in:
sophie committed 2026-06-10 16:39:05 +08:00
1 parent 0a647a0b79
commit 1f1f7236b0
57 files changed
+4356 -3798

No files matched your search

@@ -0,0 +1,75 @@
/**
* features/chat/api/chat.api.ts
* 聊天域 HTTP API:会话、消息、源文件、附件上传。
*/
import { getAuthHeaders } from '@/utils/auth';
import { requestJson } from '@/api/client';
import type {
ChatCrossAgentHistoryItem,
ChatMessage,
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 type { ChatSessionItem, ChatCrossAgentHistoryItem };