feat: chatbot
This commit is contained in:
@@ -1426,3 +1426,33 @@ export function useScoreText() {
|
||||
api.post('/specialist-desks/score-text', body).then(r => r.data) as Promise<TextSentimentResult>,
|
||||
})
|
||||
}
|
||||
|
||||
// ── AI Chat widget — free-form, read-only, context-aware conversation ────────
|
||||
|
||||
export interface ChatMessage { role: 'user' | 'assistant'; content: string; created_at?: string }
|
||||
|
||||
export const useChatContextBlocks = () =>
|
||||
useQuery({
|
||||
queryKey: ['ai-chat-blocks'],
|
||||
queryFn: () => api.get('/ai-chat/blocks').then(r => r.data.blocks as string[]),
|
||||
staleTime: Infinity,
|
||||
})
|
||||
|
||||
export const useChatHistory = (sessionId: string) =>
|
||||
useQuery({
|
||||
queryKey: ['ai-chat-history', sessionId],
|
||||
queryFn: () => api.get('/ai-chat/history', { params: { session_id: sessionId } }).then(r => r.data.messages as ChatMessage[]),
|
||||
enabled: !!sessionId,
|
||||
staleTime: Infinity,
|
||||
})
|
||||
|
||||
export const useSendChatMessage = () =>
|
||||
useMutation({
|
||||
mutationFn: (body: { session_id: string; message: string; enabled_blocks?: string[]; refresh_context?: boolean }) =>
|
||||
api.post('/ai-chat/', body).then(r => r.data as { reply: string; blocks_included: string[] }),
|
||||
})
|
||||
|
||||
export const useClearChatSession = () =>
|
||||
useMutation({
|
||||
mutationFn: (sessionId: string) => api.post('/ai-chat/clear', { session_id: sessionId }).then(r => r.data),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user