mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-20 15:02:02 +00:00
🚚 feat: Route Attachments and Provision Tools Lazily (#15763)
This commit is contained in:
parent
e6376f6df4
commit
ec15075dc8
112 changed files with 12570 additions and 478 deletions
25
client/src/utils/__tests__/unifiedUploadMode.spec.ts
Normal file
25
client/src/utils/__tests__/unifiedUploadMode.spec.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { isUnifiedUploadMode } from '../files';
|
||||
|
||||
describe('isUnifiedUploadMode', () => {
|
||||
it('withholds unified mode until the config actually resolves', () => {
|
||||
/* An unresolved config falls back to the built-in defaults, where the absent
|
||||
* legacyFileUploadUX reads as unified. Trusting it shows the unified uploader on a
|
||||
* legacy deployment, and an upload made in that window carries no tool resource
|
||||
* while the server still applies legacy rules. A failed or paused fetch is as
|
||||
* unresolved as an in-flight one, which is why the flag is "resolved" and not
|
||||
* "settled". */
|
||||
expect(isUnifiedUploadMode(undefined, false)).toBe(false);
|
||||
expect(isUnifiedUploadMode({}, false)).toBe(false);
|
||||
expect(isUnifiedUploadMode({ legacyFileUploadUX: false }, false)).toBe(false);
|
||||
});
|
||||
|
||||
it('is unified once the config lands and does not opt out', () => {
|
||||
expect(isUnifiedUploadMode({}, true)).toBe(true);
|
||||
expect(isUnifiedUploadMode({ legacyFileUploadUX: false }, true)).toBe(true);
|
||||
expect(isUnifiedUploadMode(undefined, true)).toBe(true);
|
||||
});
|
||||
|
||||
it('honors an explicit legacy opt-out', () => {
|
||||
expect(isUnifiedUploadMode({ legacyFileUploadUX: true }, true)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
@ -57,6 +57,42 @@ describe('validateFiles', () => {
|
|||
expect(setError).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects a type outside a restricted endpoint allowlist in unified mode', () => {
|
||||
endpointFileConfig = makeEndpointConfig({
|
||||
supportedMimeTypes: [/^image\/(jpeg|png)$/],
|
||||
});
|
||||
const fileList = [makeFile('notes.txt', 'text/plain', 1024)];
|
||||
|
||||
const result = validateFiles({
|
||||
files,
|
||||
fileList,
|
||||
setError,
|
||||
endpointFileConfig,
|
||||
fileConfig: defaultFileConfig,
|
||||
});
|
||||
|
||||
expect(result).toBe(false);
|
||||
expect(setError).toHaveBeenCalledWith('Unsupported file type: text/plain');
|
||||
});
|
||||
|
||||
it('accepts a type the restricted endpoint allowlist permits in unified mode', () => {
|
||||
endpointFileConfig = makeEndpointConfig({
|
||||
supportedMimeTypes: [/^image\/(jpeg|png)$/],
|
||||
});
|
||||
const fileList = [makeFile('shot.png', 'image/png', 1024)];
|
||||
|
||||
const result = validateFiles({
|
||||
files,
|
||||
fileList,
|
||||
setError,
|
||||
endpointFileConfig,
|
||||
fileConfig: defaultFileConfig,
|
||||
});
|
||||
|
||||
expect(result).toBe(true);
|
||||
expect(setError).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects when endpoint is disabled', () => {
|
||||
endpointFileConfig = makeEndpointConfig({ disabled: true });
|
||||
const fileList = [makeFile('doc.pdf', 'application/pdf', 1024)];
|
||||
|
|
|
|||
|
|
@ -460,6 +460,10 @@ export const validateFiles = ({
|
|||
fileList[i] = newFile;
|
||||
}
|
||||
|
||||
/* Unified mode routes by MIME type but does not widen what may be uploaded: the
|
||||
* endpoint allowlist is the same ceiling the server enforces in `filterFile`, so
|
||||
* accepting extraction-capable types beyond it only turns a preflight message into
|
||||
* a failed request. */
|
||||
let mimeTypesToCheck = supportedMimeTypes;
|
||||
if (toolResource === EToolResources.context) {
|
||||
mimeTypesToCheck = [
|
||||
|
|
@ -556,6 +560,19 @@ const isContextType = (type: string, fileConfig: FileConfig | null): boolean =>
|
|||
* Each option requires every file to be valid for it, so the caller can decide between
|
||||
* auto-routing (one option), prompting (multiple), or rejecting (none).
|
||||
*/
|
||||
/**
|
||||
* Whether uploads route from the file itself rather than through the destination chooser.
|
||||
* Answering it needs a config the server actually returned: without one the built-in
|
||||
* defaults apply, and their absent `legacyFileUploadUX` reads as unified, which is the
|
||||
* wrong uploader on a legacy deployment. A failed or paused query is as unresolved as a
|
||||
* pending one, so the caller passes whether the fetch succeeded rather than whether it
|
||||
* has stopped.
|
||||
*/
|
||||
export const isUnifiedUploadMode = (
|
||||
endpointFileConfig: EndpointFileConfig | undefined,
|
||||
isConfigResolved: boolean,
|
||||
): boolean => isConfigResolved && endpointFileConfig?.legacyFileUploadUX !== true;
|
||||
|
||||
export const getViableUploadOptions = (
|
||||
fileList: File[],
|
||||
ctx: UploadOptionContext,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue