feat: Add conversation ID support to custom endpoint headers

- Add LIBRECHAT_CONVERSATION_ID to customUserVars when provided
- Pass conversation ID to header resolution for dynamic headers
- Add comprehensive test coverage

Enables custom endpoints to access conversation context using {{LIBRECHAT_CONVERSATION_ID}} placeholder.
This commit is contained in:
Gopal Sharma 2025-07-22 20:32:05 +05:30 committed by Gopal Sharma
parent da3730b7d6
commit a8babbcebf
2 changed files with 18 additions and 1 deletions

View file

@ -64,6 +64,20 @@ describe('custom/initializeClient', () => {
jest.clearAllMocks();
});
it('calls resolveHeaders with conversation ID when provided', async () => {
const { resolveHeaders } = require('@librechat/api');
const requestWithConversationId = {
...mockRequest,
body: { ...mockRequest.body, conversationId: 'existing-conversation-123' },
};
await initializeClient({ req: requestWithConversationId, res: mockResponse, optionsOnly: true });
expect(resolveHeaders).toHaveBeenCalledWith(
{ 'x-user': '{{LIBRECHAT_USER_ID}}', 'x-email': '{{LIBRECHAT_USER_EMAIL}}' },
{ id: 'user-123', email: 'test@example.com' },
{ LIBRECHAT_CONVERSATION_ID: 'existing-conversation-123' },
);
});
it('calls resolveHeaders with headers and user', async () => {
const { resolveHeaders } = require('@librechat/api');
await initializeClient({ req: mockRequest, res: mockResponse, optionsOnly: true });