File size: 2,170 Bytes
65d68f5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | import { apiDelete, apiGet, apiPost } from "@/lib/api/client";
import type {
StudyChatAcademicContext,
StudyChatEvidence,
StudyChatMode,
WebSource,
} from "@/lib/api/chat";
export type ChatSessionOut = {
id: string;
source_id: string | null;
subject: string;
title: string;
context_data: StudyChatAcademicContext | null;
active_source_ids: string[];
mode: StudyChatMode;
message_count: number;
created_at: string;
updated_at: string;
};
export type ChatMessageOut = {
id: string;
role: "user" | "assistant";
content: string;
intent: string | null;
evidence_label?: string | null;
client_turn_id?: string | null;
web_sources?: WebSource[];
evidence?: StudyChatEvidence | null;
created_at: string;
};
export type ChatSessionDetail = {
id: string;
source_id: string | null;
subject: string;
title: string;
context_data: StudyChatAcademicContext | null;
active_source_ids: string[];
mode: StudyChatMode;
messages: ChatMessageOut[];
created_at: string;
updated_at: string;
};
export function listChatSessions(sourceId?: string | null) {
const query = sourceId ? `?source_id=${encodeURIComponent(sourceId)}` : "";
return apiGet<ChatSessionOut[]>(`/chat/sessions${query}`);
}
export function getChatSession(sessionId: string) {
return apiGet<ChatSessionDetail>(`/chat/sessions/${sessionId}`);
}
export function createChatSession(body: {
source_id?: string | null;
subject?: string;
title?: string;
context_data?: StudyChatAcademicContext | null;
active_source_ids?: string[];
mode?: StudyChatMode;
}) {
return apiPost<ChatSessionOut, typeof body>("/chat/sessions", body);
}
export function appendChatMessages(
sessionId: string,
body: {
user_content: string;
assistant_content: string;
client_turn_id?: string;
intent?: string;
evidence_label?: string | null;
web_sources?: WebSource[];
evidence?: StudyChatEvidence | null;
},
) {
return apiPost<ChatMessageOut[], typeof body>(
`/chat/sessions/${sessionId}/messages`,
body,
);
}
export function deleteChatSession(sessionId: string) {
return apiDelete(`/chat/sessions/${sessionId}`);
}
|