fix(ai): use authenticated ask ash chat path
This commit is contained in:
parent
b5d286ada3
commit
5f535cba59
1 changed files with 14 additions and 2 deletions
|
|
@ -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]);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue