diff --git a/src/components/ChatContainer/ChatContainer.tsx b/src/components/ChatContainer/ChatContainer.tsx index 816c0e3..831aa67 100644 --- a/src/components/ChatContainer/ChatContainer.tsx +++ b/src/components/ChatContainer/ChatContainer.tsx @@ -164,6 +164,11 @@ export const ChatContainer: React.FC = ({ }) }; + if (chatUuid) { + payload.chat_uuid = chatUuid; + } + + if (config.streamResponse) { await handleStreamingResponse(chatService, payload); } else { @@ -209,6 +214,11 @@ export const ChatContainer: React.FC = ({ return newMessages; }); } + }, + (headerChatUuid) => { + if (headerChatUuid && !chatUuid) { + setChatUuid(headerChatUuid); + } } ); }; diff --git a/src/services/APIClient.ts b/src/services/APIClient.ts index 265c4dc..0843b53 100644 --- a/src/services/APIClient.ts +++ b/src/services/APIClient.ts @@ -54,7 +54,11 @@ export class APIClient { ): Promise { const response = await fetch(`${this.baseUrl}${endpoint}`, { ...options, - headers: this.getHeaders(), + headers: { + ...this.getHeaders(), + ...options.headers + }, + mode: 'cors', }); if (!response.ok) { diff --git a/src/services/ChatService.ts b/src/services/ChatService.ts index 88039b1..8760b74 100644 --- a/src/services/ChatService.ts +++ b/src/services/ChatService.ts @@ -40,7 +40,7 @@ export class ChatService extends APIClient { } async sendMessage(payload: ChatPayload): Promise> { - return this.fetchWithError('/ask', { + return this.fetchWithError('/api/v1/chats', { method: 'POST', body: JSON.stringify(payload), }); @@ -52,7 +52,8 @@ export class ChatService extends APIClient { async sendStreamMessage( payload: ChatPayload, - onChunk: (chunk: StreamChunk) => void + onChunk: (chunk: StreamChunk) => void, + onHeaderChatUuid?: (chatUuid: string) => void ): Promise { try { const response = await this.fetchStream('/api/v1/chats/stream', { @@ -60,6 +61,21 @@ export class ChatService extends APIClient { body: JSON.stringify(payload), }); + //const chatUuid = response.headers.get('X-Chat-Uuid'); + // Debug: Log all available headers + console.log('All response headers:'); + response.headers.forEach((value, name) => { + console.log(`${name}: ${value}`); + }); + + // Try both casing variants + const chatUuid = response.headers.get('X-MKit-Chat-UUID'); + + if (chatUuid && onHeaderChatUuid) { + onHeaderChatUuid(chatUuid); + } + + const reader = response.body?.getReader(); if (!reader) { throw new Error('Response body is not readable');