diff --git a/src/components/AiChatWidget.tsx b/src/components/AiChatWidget.tsx index 06a7450..37fe9a4 100644 --- a/src/components/AiChatWidget.tsx +++ b/src/components/AiChatWidget.tsx @@ -17,6 +17,7 @@ interface ChatResponse { remaining_credits?: number; remaining_daily_actions?: number; credits_charged?: number; + message?: string; } interface UsageStatus { @@ -79,7 +80,7 @@ export function AiChatWidget() { setInput(""); try { - const res = await fetch(`${API}/api/ai/chat/message`, { + let res = await fetch(`${API}/api/ai/chat/ask`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ @@ -88,6 +89,17 @@ export function AiChatWidget() { }), }); + if (res.status === 401 || res.status === 403 || res.status === 404) { + res = await fetch(`${API}/api/ai/chat/message`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + message: text, + conversation_id: conversationId() || undefined, + }), + }); + } + if (!res.ok) throw new Error("AI request failed"); const data: ChatResponse = await res.json(); @@ -110,7 +122,7 @@ export function AiChatWidget() { const assistantMessage: ChatMessage = { role: "assistant", - content: data.reply, + content: data.message || data.reply, intent: data.intent, }; setMessages((prev) => [...prev, assistantMessage]);