mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-23 20:00:15 +01:00
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:
parent
da3730b7d6
commit
a8babbcebf
2 changed files with 18 additions and 1 deletions
|
|
@ -28,7 +28,10 @@ const initializeClient = async ({ req, res, endpointOption, optionsOnly, overrid
|
||||||
const CUSTOM_API_KEY = extractEnvVariable(endpointConfig.apiKey);
|
const CUSTOM_API_KEY = extractEnvVariable(endpointConfig.apiKey);
|
||||||
const CUSTOM_BASE_URL = extractEnvVariable(endpointConfig.baseURL);
|
const CUSTOM_BASE_URL = extractEnvVariable(endpointConfig.baseURL);
|
||||||
|
|
||||||
let resolvedHeaders = resolveHeaders(endpointConfig.headers, req.user);
|
const customUserVars = {};
|
||||||
|
customUserVars.LIBRECHAT_CONVERSATION_ID = req.body.conversationId;
|
||||||
|
|
||||||
|
let resolvedHeaders = resolveHeaders(endpointConfig.headers, req.user, customUserVars);
|
||||||
|
|
||||||
if (CUSTOM_API_KEY.match(envVarRegex)) {
|
if (CUSTOM_API_KEY.match(envVarRegex)) {
|
||||||
throw new Error(`Missing API Key for ${endpoint}.`);
|
throw new Error(`Missing API Key for ${endpoint}.`);
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,20 @@ describe('custom/initializeClient', () => {
|
||||||
jest.clearAllMocks();
|
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 () => {
|
it('calls resolveHeaders with headers and user', async () => {
|
||||||
const { resolveHeaders } = require('@librechat/api');
|
const { resolveHeaders } = require('@librechat/api');
|
||||||
await initializeClient({ req: mockRequest, res: mockResponse, optionsOnly: true });
|
await initializeClient({ req: mockRequest, res: mockResponse, optionsOnly: true });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue