|
|
@@ -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);
|
|
|
});
|
|
|
}
|