mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-10-03 20:22:22 +00:00
🐛 fix: Resolve agent provider for image upload delivery paths
processImageFile resolved llmDeliveryPath from the request endpoint (agents), ignoring metadata.agent_id, so provider-specific defaultLLMDeliveryPath and legacyFileUploadUX config never applied to images even though processAgentFileUpload already honored it. Both paths now share resolveUploadEndpoint; the raw endpoint still drives image resize/storage.
This commit is contained in:
parent
6a1a67242b
commit
106f8d7fcb
2 changed files with 52 additions and 11 deletions
|
|
@ -449,6 +449,16 @@ const processFileURL = async ({
|
|||
}
|
||||
};
|
||||
|
||||
/** Agent uploads carry endpoint=agents; resolve the file config from the agent's
|
||||
* own provider so provider-specific defaultLLMDeliveryPath overrides are honored. */
|
||||
const resolveUploadEndpoint = async ({ endpoint, agent_id }) => {
|
||||
if (!agent_id) {
|
||||
return endpoint;
|
||||
}
|
||||
const uploadAgent = await db.getAgent({ id: agent_id });
|
||||
return uploadAgent?.provider || endpoint;
|
||||
};
|
||||
|
||||
const resolveDefaultUploadLLMDeliveryPath = ({ file, endpointConfig, fileConfig }) => {
|
||||
const isLegacyFileUploadUX = endpointConfig?.legacyFileUploadUX === true;
|
||||
if (isLegacyFileUploadUX) {
|
||||
|
|
@ -479,9 +489,10 @@ const processImageFile = async ({ req, res, metadata, returnFile = false, sseStr
|
|||
const appConfig = req.config;
|
||||
const source = getFileStrategy(appConfig, { isImage: true });
|
||||
const { handleImageUpload } = getStrategyFunctions(source);
|
||||
const { file_id, temp_file_id, endpoint } = metadata;
|
||||
const { file_id, temp_file_id, endpoint, agent_id } = metadata;
|
||||
const fileConfig = mergeFileConfig(appConfig?.fileConfig);
|
||||
const endpointConfig = getEndpointFileConfig({ fileConfig, endpoint });
|
||||
const configEndpoint = await resolveUploadEndpoint({ endpoint, agent_id });
|
||||
const endpointConfig = getEndpointFileConfig({ fileConfig, endpoint: configEndpoint });
|
||||
const llmDeliveryPath = resolveDefaultUploadLLMDeliveryPath({ file, endpointConfig, fileConfig });
|
||||
|
||||
const { filepath, bytes, width, height, storageKey, storageRegion } = await handleImageUpload({
|
||||
|
|
@ -721,15 +732,7 @@ const processAgentFileUpload = async ({ req, res, metadata, sseStream }) => {
|
|||
tool_resource === EToolResources.ocr ? EToolResources.context : tool_resource;
|
||||
|
||||
const fileConfig = mergeFileConfig(appConfig?.fileConfig);
|
||||
// An agent upload carries endpoint=agents; resolve the file config from the agent's
|
||||
// own provider so provider-specific defaultLLMDeliveryPath overrides are honored.
|
||||
let endpoint = req.body?.endpoint;
|
||||
if (agent_id) {
|
||||
const uploadAgent = await db.getAgent({ id: agent_id });
|
||||
if (uploadAgent?.provider) {
|
||||
endpoint = uploadAgent.provider;
|
||||
}
|
||||
}
|
||||
const endpoint = await resolveUploadEndpoint({ endpoint: req.body?.endpoint, agent_id });
|
||||
const endpointConfig = getEndpointFileConfig({ fileConfig, endpoint });
|
||||
|
||||
if (agent_id && !tool_resource && !messageAttachment) {
|
||||
|
|
|
|||
|
|
@ -1809,6 +1809,44 @@ describe('processImageFile', () => {
|
|||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('resolves llmDeliveryPath from the agent provider config for agent image uploads', async () => {
|
||||
const { createFile, getAgent } = require('~/models');
|
||||
getAgent.mockResolvedValueOnce({ provider: 'Custom Provider' });
|
||||
const handleImageUpload = jest.fn().mockResolvedValue({
|
||||
filepath: '/images/user-123/image.webp',
|
||||
bytes: 256,
|
||||
width: 100,
|
||||
height: 80,
|
||||
});
|
||||
mergeFileConfig.mockReturnValue({
|
||||
...makeFileConfig(),
|
||||
endpoints: {
|
||||
'Custom Provider': { defaultLLMDeliveryPath: { overrides: { 'image/*': 'none' } } },
|
||||
},
|
||||
});
|
||||
getStrategyFunctions.mockReturnValue({ handleImageUpload });
|
||||
const req = makeReq({ mimetype: 'image/png', ocrConfig: null });
|
||||
|
||||
await processImageFile({
|
||||
req,
|
||||
res: mockRes,
|
||||
metadata: {
|
||||
file_id: 'image-file-id',
|
||||
agent_id: 'agent-abc',
|
||||
endpoint: EModelEndpoint.agents,
|
||||
},
|
||||
});
|
||||
|
||||
expect(getAgent).toHaveBeenCalledWith({ id: 'agent-abc' });
|
||||
expect(handleImageUpload).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ endpoint: EModelEndpoint.agents }),
|
||||
);
|
||||
expect(createFile).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ llmDeliveryPath: 'none' }),
|
||||
true,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('processFileURL', () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue