fix: production CSRF, ProxyFix, and SSE streaming issues

This commit is contained in:
Your Name
2026-03-18 11:21:42 +02:00
parent 88cc92c252
commit aed02e36e5
10 changed files with 773 additions and 22 deletions

View File

@@ -412,13 +412,25 @@ export async function streamAssistantChat(
payload: AssistantChatRequest,
handlers: AssistantStreamHandlers = {}
): Promise<AssistantChatResponse> {
// Ensure a CSRF token cookie exists before streaming
let csrfToken = getCookieValue(CSRF_COOKIE_NAME);
if (!csrfToken) {
await csrfBootstrapClient.get('/auth/csrf');
csrfToken = getCookieValue(CSRF_COOKIE_NAME);
}
const streamHeaders: Record<string, string> = {
'Content-Type': 'application/json',
Accept: 'text/event-stream',
};
if (csrfToken) {
streamHeaders[CSRF_HEADER_NAME] = csrfToken;
}
const response = await fetch('/api/assistant/chat/stream', {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
Accept: 'text/event-stream',
},
headers: streamHeaders,
body: JSON.stringify(payload),
});