Skip to content

Fix chat endpoint #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/components/ChatContainer/ChatContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
};

loadTools();
}, [getAccessTokenSilently]);

Check warning on line 78 in src/components/ChatContainer/ChatContainer.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'handleError'. Either include it or remove the dependency array


useEffect(() => {
Expand Down Expand Up @@ -164,6 +164,11 @@
})
};

if (chatUuid) {
payload.chat_uuid = chatUuid;
}


if (config.streamResponse) {
await handleStreamingResponse(chatService, payload);
} else {
Expand Down Expand Up @@ -209,6 +214,11 @@
return newMessages;
});
}
},
(headerChatUuid) => {
if (headerChatUuid && !chatUuid) {
setChatUuid(headerChatUuid);
}
}
);
};
Expand Down
6 changes: 5 additions & 1 deletion src/services/APIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ export class APIClient {
): Promise<Response> {
const response = await fetch(`${this.baseUrl}${endpoint}`, {
...options,
headers: this.getHeaders(),
headers: {
...this.getHeaders(),
...options.headers
},
mode: 'cors',
});

if (!response.ok) {
Expand Down
20 changes: 18 additions & 2 deletions src/services/ChatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class ChatService extends APIClient {
}

async sendMessage(payload: ChatPayload): Promise<APIResponse<ChatResponse>> {
return this.fetchWithError<ChatResponse>('/ask', {
return this.fetchWithError<ChatResponse>('/api/v1/chats', {
method: 'POST',
body: JSON.stringify(payload),
});
Expand All @@ -52,14 +52,30 @@ export class ChatService extends APIClient {

async sendStreamMessage(
payload: ChatPayload,
onChunk: (chunk: StreamChunk) => void
onChunk: (chunk: StreamChunk) => void,
onHeaderChatUuid?: (chatUuid: string) => void
): Promise<void> {
try {
const response = await this.fetchStream('/api/v1/chats/stream', {
method: 'POST',
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');
Expand Down
Loading