feat(web): Day 9 — Web ChatPage + 会话 API 前端
- ChatPage 组件: 左侧会话列表(260px) + 右侧聊天区 + RichMessage 富消息 - 新建/选择/重命名/关闭会话,session_id 模式消息持久化 - aiChatApi 新增 createSession/listSessions/renameSession/closeSession - 路由 /ai/chat 注册,支持 display_hints 富消息渲染 - App.tsx 路由权限校验覆盖
This commit is contained in:
@@ -54,17 +54,55 @@ export interface ChatResponse {
|
||||
display_hints?: DisplayHint[];
|
||||
}
|
||||
|
||||
export interface ChatSession {
|
||||
id: string;
|
||||
title: string | null;
|
||||
patient_id: string | null;
|
||||
status: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export const aiChatApi = {
|
||||
sendMessage: async (
|
||||
message: string,
|
||||
history: ChatHistoryItem[],
|
||||
patientId?: string
|
||||
patientId?: string,
|
||||
sessionId?: string
|
||||
): Promise<ChatResponse> => {
|
||||
const resp = await client.post('/ai/chat', {
|
||||
message,
|
||||
history,
|
||||
...(patientId ? { patient_id: patientId } : {}),
|
||||
...(sessionId ? { session_id: sessionId } : {}),
|
||||
});
|
||||
return resp.data.data as ChatResponse;
|
||||
},
|
||||
|
||||
createSession: async (
|
||||
patientId?: string,
|
||||
title?: string
|
||||
): Promise<ChatSession> => {
|
||||
const resp = await client.post('/ai/chat/sessions', {
|
||||
...(patientId ? { patient_id: patientId } : {}),
|
||||
...(title ? { title } : {}),
|
||||
});
|
||||
return resp.data.data as ChatSession;
|
||||
},
|
||||
|
||||
listSessions: async (): Promise<ChatSession[]> => {
|
||||
const resp = await client.get('/ai/chat/sessions');
|
||||
return resp.data.data as ChatSession[];
|
||||
},
|
||||
|
||||
renameSession: async (
|
||||
sessionId: string,
|
||||
title: string
|
||||
): Promise<void> => {
|
||||
await client.put(`/ai/chat/sessions/${sessionId}/rename`, { title });
|
||||
},
|
||||
|
||||
closeSession: async (sessionId: string): Promise<void> => {
|
||||
await client.post(`/ai/chat/sessions/${sessionId}/close`);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user