Add conversation history management and API endpoints

- Introduce new database models for conversation sessions, messages, and artifacts to support conversation history tracking.
- Implement API routes for listing conversations and retrieving detailed conversation data, enhancing user interaction with historical records.
- Add a conversation recorder service to persist conversation messages in real-time without disrupting ongoing calls.
- Update the frontend to display conversation history, including filtering and sorting options, improving user experience.
- Enhance the pipeline to integrate conversation history recording seamlessly during interactions.
This commit is contained in:
Xin Wang
2026-07-10 16:25:06 +08:00
parent 5705726cfb
commit 059ad8162e
13 changed files with 1096 additions and 43 deletions

View File

@@ -194,6 +194,63 @@ export const assistantsApi = {
request<{ ok: boolean }>(`/api/assistants/${id}`, { method: "DELETE" }),
};
// ---------- 对话历史 ----------
export type Conversation = {
id: string;
assistantId: string | null;
assistantName: string;
channel: string;
runtimeMode: string;
status: string;
messageCount: number;
startedAt: string;
endedAt: string | null;
};
export type ConversationMessage = {
id: string;
sequence: number;
role: "user" | "assistant";
contentType: string;
content: string;
occurredAt: string;
extra: { interrupted?: boolean; turn_id?: string };
};
export type ConversationDetail = Conversation & {
messages: ConversationMessage[];
};
export type ConversationList = {
items: Conversation[];
total: number;
page: number;
pageSize: number;
};
export const conversationsApi = {
list: (params: {
page?: number;
pageSize?: number;
search?: string;
channel?: string;
status?: string;
sortOrder?: "newest" | "oldest";
} = {}) => {
const query = new URLSearchParams({
page: String(params.page ?? 1),
page_size: String(params.pageSize ?? 20),
sort_order: params.sortOrder ?? "newest",
});
if (params.search) query.set("search", params.search);
if (params.channel) query.set("channel", params.channel);
if (params.status) query.set("status", params.status);
return request<ConversationList>(`/api/conversations?${query}`);
},
get: (id: string) =>
request<ConversationDetail>(`/api/conversations/${id}`),
};
// ---------- 工具 ----------
export type ToolStatus = "active" | "archived" | "draft";
export type ToolParameter = {