🎞️ feat: OpenRouter Audio/Video File Upload Support (#11070)
Some checks are pending
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Waiting to run
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Waiting to run

* Added video upload support for OpenRouter

- Added VIDEO_URL content type to support video_url message format
- Implemented OpenRouter video encoding using base64 data URLs
- Extended encodeAndFormatVideos() to handle OpenRouter provider
- Updated UI to accept video uploads for OpenRouter (mp4, webm, mpeg, mov)
- Fixed case-sensitivity in provider detection for agents
- Made isDocumentSupportedProvider() and isOpenAILikeProvider() case-insensitive

Videos are now converted to data:video/mp4;base64,... format compatible
with OpenRouter's API requirements per their documentation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* refactor: change multimodal and google_multimodal to more transparent variable names of image_document and image_document_video_audio

(also google_multimodal doesn't apply as much since we are adding support for video and audio uploads for open router)

* fix: revert .toLowerCase change to isOpenAILikeProvider and isDocumentSupportedProvider which broke upload to provider detection for openAI endpoints

* wip: add audio support to openrouter

* fix: filetypes now properly parsed and sent rather than destructured mimetypes for openrouter

* refactor: Omit to Exclude for ESLint

* feat: update DragDropModal for new openrouter support

* fix: special case openrouter for lower case provider

(currently getting issues with the provider coming in as 'OpenRouter' and our enum being 'openrouter') This will probably require a larger refactor later to handle case insensitivity for all providers, but that will have to be thoroughly tested in its own isolated PR

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Dustin Healy <54083382+dustinhealy@users.noreply.github.com>
This commit is contained in:
papasaidfine 2025-12-25 13:23:29 -05:00 committed by GitHub
parent 5caa008432
commit 4fe223eedd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 113 additions and 29 deletions

View file

@ -9,6 +9,7 @@ import {
TerminalSquareIcon,
} from 'lucide-react';
import {
Providers,
EToolResources,
EModelEndpoint,
defaultAgentCapabilities,
@ -36,6 +37,8 @@ import { ephemeralAgentByConvoId } from '~/store';
import { MenuItemProps } from '~/common';
import { cn } from '~/utils';
type FileUploadType = 'image' | 'document' | 'image_document' | 'image_document_video_audio';
interface AttachFileMenuProps {
agentId?: string | null;
endpoint?: string | null;
@ -83,9 +86,7 @@ const AttachFileMenu = ({
ephemeralAgent,
);
const handleUploadClick = (
fileType?: 'image' | 'document' | 'multimodal' | 'google_multimodal',
) => {
const handleUploadClick = (fileType?: FileUploadType) => {
if (!inputRef.current) {
return;
}
@ -94,9 +95,9 @@ const AttachFileMenu = ({
inputRef.current.accept = 'image/*';
} else if (fileType === 'document') {
inputRef.current.accept = '.pdf,application/pdf';
} else if (fileType === 'multimodal') {
} else if (fileType === 'image_document') {
inputRef.current.accept = 'image/*,.pdf,application/pdf';
} else if (fileType === 'google_multimodal') {
} else if (fileType === 'image_document_video_audio') {
inputRef.current.accept = 'image/*,.pdf,application/pdf,video/*,audio/*';
} else {
inputRef.current.accept = '';
@ -106,12 +107,16 @@ const AttachFileMenu = ({
};
const dropdownItems = useMemo(() => {
const createMenuItems = (
onAction: (fileType?: 'image' | 'document' | 'multimodal' | 'google_multimodal') => void,
) => {
const createMenuItems = (onAction: (fileType?: FileUploadType) => void) => {
const items: MenuItemProps[] = [];
const currentProvider = provider || endpoint;
let currentProvider = provider || endpoint;
// This will be removed in a future PR to formally normalize Providers comparisons to be case insensitive
if (currentProvider?.toLowerCase() === Providers.OPENROUTER) {
currentProvider = Providers.OPENROUTER;
}
if (
isDocumentSupportedProvider(endpointType) ||
isDocumentSupportedProvider(currentProvider)
@ -120,9 +125,11 @@ const AttachFileMenu = ({
label: localize('com_ui_upload_provider'),
onClick: () => {
setToolResource(undefined);
onAction(
(provider || endpoint) === EModelEndpoint.google ? 'google_multimodal' : 'multimodal',
);
let fileType: Exclude<FileUploadType, 'image' | 'document'> = 'image_document';
if (currentProvider === Providers.GOOGLE || currentProvider === Providers.OPENROUTER) {
fileType = 'image_document_video_audio';
}
onAction(fileType);
},
icon: <FileImageIcon className="icon-md" />,
});

View file

@ -2,6 +2,7 @@ import React, { useMemo } from 'react';
import { useRecoilValue } from 'recoil';
import { OGDialog, OGDialogTemplate } from '@librechat/client';
import {
Providers,
inferMimeType,
EToolResources,
EModelEndpoint,
@ -55,15 +56,21 @@ const DragDropModal = ({ onOptionSelect, setShowModal, files, isVisible }: DragD
const options = useMemo(() => {
const _options: FileOption[] = [];
const currentProvider = provider || endpoint;
let currentProvider = provider || endpoint;
// This will be removed in a future PR to formally normalize Providers comparisons to be case insensitive
if (currentProvider?.toLowerCase() === Providers.OPENROUTER) {
currentProvider = Providers.OPENROUTER;
}
/** Helper to get inferred MIME type for a file */
const getFileType = (file: File) => inferMimeType(file.name, file.type);
// Check if provider supports document upload
if (isDocumentSupportedProvider(endpointType) || isDocumentSupportedProvider(currentProvider)) {
const isGoogleProvider = currentProvider === EModelEndpoint.google;
const validFileTypes = isGoogleProvider
const supportsImageDocVideoAudio =
currentProvider === EModelEndpoint.google || currentProvider === Providers.OPENROUTER;
const validFileTypes = supportsImageDocVideoAudio
? files.every((file) => {
const type = getFileType(file);
return (

View file

@ -512,7 +512,7 @@ describe('AttachFileMenu', () => {
});
describe('Google Provider Special Case', () => {
it('should use google_multimodal file type for Google provider', () => {
it('should use image_document_video_audio file type for Google provider', () => {
mockUseAgentToolPermissions.mockReturnValue({
fileSearchAllowedByAgent: false,
codeAllowedByAgent: false,
@ -536,7 +536,7 @@ describe('AttachFileMenu', () => {
// The file input should have been clicked (indirectly tested through the implementation)
});
it('should use multimodal file type for non-Google providers', () => {
it('should use image_document file type for non-Google providers', () => {
mockUseAgentToolPermissions.mockReturnValue({
fileSearchAllowedByAgent: false,
codeAllowedByAgent: false,
@ -555,7 +555,7 @@ describe('AttachFileMenu', () => {
expect(uploadProviderButton).toBeInTheDocument();
fireEvent.click(uploadProviderButton);
// Implementation detail - multimodal type is used
// Implementation detail - image_document type is used
});
});