wepee's picture
add: sse integration
69f44ef
Raw
History Blame Contribute Delete
1.44 kB
export type CourseResponse = {
id: number | string;
title: string;
description?: string;
};
export type DocumentSource = {
document_id: string;
filename: string;
excerpt: string;
};
export type ChatMessageResponse = {
uuid_id: string;
role: string;
content: string;
sources?: DocumentSource[];
created_at: string;
};
export type ChatSessionResponse = {
uuid_id: string;
user_id: string;
user_name?: string;
course_id: string;
course_name?: string;
title: string;
message_count: number;
last_message_at?: string;
created_at: string;
updated_at: string;
};
function createLocalMessageId(prefix: string): string {
if (typeof crypto !== 'undefined' && 'randomUUID' in crypto) {
return `${prefix}-${crypto.randomUUID()}`;
}
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
}
export function createLocalUserMessage(content: string): ChatMessageResponse {
return {
content,
created_at: new Date().toISOString(),
role: 'user',
sources: [],
uuid_id: createLocalMessageId('local'),
};
}
export function createLocalAssistantMessage(
content = '',
): ChatMessageResponse {
return {
content,
created_at: new Date().toISOString(),
role: 'assistant',
sources: [],
uuid_id: createLocalMessageId('local-assistant'),
};
}