leonardo 2 hónapja
szülő
commit
04bc9d7329
4 módosított fájl, 22 hozzáadás és 11 törlés
  1. 2 2
      dist/index.html
  2. 4 6
      src/api/chat.js
  3. 6 0
      src/api/client.js
  4. 10 3
      src/composables/useChat.js

+ 2 - 2
dist/index.html

@@ -6,8 +6,8 @@
     <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1" />
     <link rel="icon" type="image/x-icon" href="/favicon.ico?v=2" />
     <title>ORÁCULO</title>
-    <script type="module" crossorigin src="/assets/index-CrCOIjew.js"></script>
-    <link rel="stylesheet" crossorigin href="/assets/index-DObT3dAY.css">
+    <script type="module" crossorigin src="/assets/index-YT22NH87.js"></script>
+    <link rel="stylesheet" crossorigin href="/assets/index-BkzxuOwG.css">
   </head>
   <body class="bg-background">
     <noscript>

+ 4 - 6
src/api/chat.js

@@ -1,4 +1,4 @@
-import { apiBaseUrl, apiFetch, getAccessToken } from "./client.js";
+import { apiBaseUrl, apiFetch, buildAuthHeaders } from "./client.js";
 
 export async function sendChat(message, { conversationId } = {}) {
   return apiFetch("/api/chat", {
@@ -8,9 +8,7 @@ export async function sendChat(message, { conversationId } = {}) {
 }
 
 export async function sendChatStream(message, { conversationId, onChunk, onSources, onStatus, onDone, onError, signal } = {}) {
-  const token = getAccessToken();
-  const headers = { "content-type": "application/json" };
-  if (token) headers["Authorization"] = `Bearer ${token}`;
+  const headers = buildAuthHeaders();
 
   let res;
   try {
@@ -99,8 +97,8 @@ export function ingestFile(file, { source, onProgress } = {}) {
     xhr.ontimeout = () => reject(new Error("timeout"));
 
     xhr.open("POST", `${apiBaseUrl}/api/ingest/file`);
-    const token = getAccessToken();
-    if (token) xhr.setRequestHeader("Authorization", `Bearer ${token}`);
+    const authHeaders = buildAuthHeaders();
+    if (authHeaders["Authorization"]) xhr.setRequestHeader("Authorization", authHeaders["Authorization"]);
     xhr.send(form);
   });
 }

+ 6 - 0
src/api/client.js

@@ -28,6 +28,12 @@ export function getAccessToken() {
   return _accessToken;
 }
 
+export function buildAuthHeaders(extra = {}) {
+  const headers = { "content-type": "application/json", ...extra };
+  if (_accessToken) headers["Authorization"] = `Bearer ${_accessToken}`;
+  return headers;
+}
+
 export async function apiFetch(path, { method = "GET", body } = {}) {
   const headers = { "content-type": "application/json" };
   if (_accessToken) headers["Authorization"] = `Bearer ${_accessToken}`;

+ 10 - 3
src/composables/useChat.js

@@ -105,8 +105,11 @@ export function useChat() {
       conversations.value = [...conversations.value, ...items.map(normalizeConversation)];
       conversationsHasMore.value = items.length >= CONV_PAGE_SIZE;
       conversationsOffset.value += items.length;
-    } catch {
-      // keep existing conversations on error
+    } catch (err) {
+      if (err?.message !== "session_expired") {
+        toast.erro("Não foi possível carregar mais conversas.");
+        console.warn("[useChat] loadMoreConversations:", err);
+      }
     } finally {
       conversationsLoading.value = false;
     }
@@ -123,8 +126,12 @@ export function useChat() {
       const data = await getConversationMessages(numId);
       const normalized = normalizeApiMessages(data?.items);
       messages.value = normalized.length ? normalized : [...defaultMessages];
-    } catch {
+    } catch (err) {
       messages.value = [...defaultMessages];
+      if (err?.message !== "session_expired") {
+        conversationsError.value = "Erro ao carregar mensagens da conversa.";
+        console.warn("[useChat] setActiveConversation:", err);
+      }
     }
   }