feat: 添加会话历史管理功能
- 在 AI 教练聊天界面中新增会话历史查看和选择功能,用户可以查看和选择之前的会话记录 - 实现会话删除功能,用户可以删除不需要的会话记录 - 优化历史会话的加载和展示,提升用户体验 - 更新相关样式以适应新功能的展示和交互
This commit is contained in:
38
services/aiCoach.ts
Normal file
38
services/aiCoach.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { api } from '@/services/api';
|
||||
|
||||
export type AiConversationListItem = {
|
||||
conversationId: string;
|
||||
title?: string | null;
|
||||
lastMessageAt?: string | null;
|
||||
createdAt?: string | null;
|
||||
};
|
||||
|
||||
export type AiConversationListResponse = {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
total: number;
|
||||
items: AiConversationListItem[];
|
||||
};
|
||||
|
||||
export type AiConversationDetail = {
|
||||
conversationId: string;
|
||||
title?: string | null;
|
||||
lastMessageAt?: string | null;
|
||||
createdAt?: string | null;
|
||||
messages: Array<{ role: 'user' | 'assistant' | 'system'; content: string; createdAt?: string | null }>;
|
||||
};
|
||||
|
||||
export async function listConversations(page = 1, pageSize = 20): Promise<AiConversationListResponse> {
|
||||
const qs = `?page=${encodeURIComponent(page)}&pageSize=${encodeURIComponent(pageSize)}`;
|
||||
return api.get<AiConversationListResponse>(`/api/ai-coach/conversations${qs}`);
|
||||
}
|
||||
|
||||
export async function getConversationDetail(conversationId: string): Promise<AiConversationDetail> {
|
||||
return api.get<AiConversationDetail>(`/api/ai-coach/conversations/${encodeURIComponent(conversationId)}`);
|
||||
}
|
||||
|
||||
export async function deleteConversation(conversationId: string): Promise<{ success: boolean }> {
|
||||
return api.delete<{ success: boolean }>(`/api/ai-coach/conversations/${encodeURIComponent(conversationId)}`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user