88e8ab0792
Frontend interface expected 'message' and 'response' but API returns 'user_message' and 'assistant_message'. Field name mismatch caused undefined access and page crash. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import api from './client'
|
|
|
|
export interface ChatMessage {
|
|
id: string
|
|
role: 'user' | 'assistant' | 'system'
|
|
content: string
|
|
created_at: string
|
|
}
|
|
|
|
export interface ChatSession {
|
|
session_id: string
|
|
last_message: string
|
|
message_count: number
|
|
created_at: string
|
|
}
|
|
|
|
export interface ChatResponse {
|
|
session_id: string
|
|
user_message: ChatMessage
|
|
assistant_message: ChatMessage
|
|
}
|
|
|
|
export async function sendChatMessage(
|
|
message: string,
|
|
sessionId?: string,
|
|
contextType?: string,
|
|
contextId?: string,
|
|
): Promise<ChatResponse> {
|
|
const res = await api.post<ChatResponse>('/chat/messages', {
|
|
message,
|
|
session_id: sessionId || undefined,
|
|
context_type: contextType || undefined,
|
|
context_id: contextId || undefined,
|
|
})
|
|
return res.data
|
|
}
|
|
|
|
export async function getChatSessions(): Promise<ChatSession[]> {
|
|
const res = await api.get<ChatSession[]>('/chat/sessions')
|
|
return res.data
|
|
}
|
|
|
|
export async function getSessionMessages(sessionId: string): Promise<ChatMessage[]> {
|
|
const res = await api.get<ChatMessage[]>(`/chat/sessions/${sessionId}/messages`)
|
|
return res.data
|
|
}
|
|
|
|
export async function deleteChatSession(sessionId: string): Promise<void> {
|
|
await api.delete(`/chat/sessions/${sessionId}`)
|
|
}
|