🧩 feat: OpenDocument Format File Upload and Native ODS Parsing (#11959)

*  feat: Add support for OpenDocument MIME types in file configuration

Updated the applicationMimeTypes regex to include support for OASIS OpenDocument formats, enhancing the file type recognition capabilities of the data provider.

* feat: document processing with OpenDocument support

Added support for OpenDocument Spreadsheet (ODS) MIME type in the file processing service and updated the document parser to handle ODS files. Included tests to verify correct parsing of ODS documents and updated file configuration to recognize OpenDocument formats.

* refactor: Enhance document processing to support additional Excel MIME types

Updated the document processing logic to utilize a regex for matching Excel MIME types, improving flexibility in handling various Excel file formats. Added tests to ensure correct parsing of new MIME types, including multiple Excel variants and OpenDocument formats. Adjusted file configuration to include these MIME types for better recognition in the file processing service.

* feat: Add support for additional OpenDocument MIME types in file processing

Enhanced the document processing service to support ODT, ODP, and ODG MIME types. Updated tests to verify correct routing through the OCR strategy for these new formats. Adjusted documentation to reflect changes in handled MIME types for improved clarity.
This commit is contained in:
Danny Avila 2026-02-26 14:39:49 -05:00 committed by GitHub
parent 3a079b980a
commit 046e92217f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 220 additions and 26 deletions

View file

@ -56,6 +56,50 @@ describe('Document Parser', () => {
});
});
test('parseDocument() parses text from ods', async () => {
const file = {
originalname: 'sample.ods',
path: path.join(__dirname, 'sample.ods'),
mimetype: 'application/vnd.oasis.opendocument.spreadsheet',
} as Express.Multer.File;
const document = await parseDocument({ file });
expect(document).toEqual({
bytes: 66,
filename: 'sample.ods',
filepath: 'document_parser',
images: [],
text: 'Sheet One:\nData,on,first,sheet\nSecond Sheet:\nData,On\nSecond,Sheet\n',
});
});
test.each([
'application/msexcel',
'application/x-msexcel',
'application/x-ms-excel',
'application/x-excel',
'application/x-dos_ms_excel',
'application/xls',
'application/x-xls',
])('parseDocument() parses xls with variant MIME type: %s', async (mimetype) => {
const file = {
originalname: 'sample.xls',
path: path.join(__dirname, 'sample.xls'),
mimetype,
} as Express.Multer.File;
const document = await parseDocument({ file });
expect(document).toEqual({
bytes: 31,
filename: 'sample.xls',
filepath: 'document_parser',
images: [],
text: 'Sheet One:\nData,on,first,sheet\n',
});
});
test('parseDocument() throws error for unhandled document type', async () => {
const file = {
originalname: 'nonexistent.file',

View file

@ -1,12 +1,13 @@
import * as fs from 'fs';
import { FileSources } from 'librechat-data-provider';
import { excelMimeTypes, FileSources } from 'librechat-data-provider';
import type { TextItem } from 'pdfjs-dist/types/src/display/api';
import type { MistralOCRUploadResult } from '~/types';
/**
* Parses an uploaded document and extracts its text content and metadata.
* Handled types must stay in sync with `documentParserMimeTypes` from data-provider.
*
* Throws an Error if it fails to parse or no text is found.
* @throws {Error} if `file.mimetype` is not handled or no text is found.
*/
export async function parseDocument({
file,
@ -14,19 +15,19 @@ export async function parseDocument({
file: Express.Multer.File;
}): Promise<MistralOCRUploadResult> {
let text: string;
switch (file.mimetype) {
case 'application/pdf':
text = await pdfToText(file);
break;
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
text = await wordDocToText(file);
break;
case 'application/vnd.ms-excel':
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
text = await excelSheetToText(file);
break;
default:
throw new Error(`Unsupported file type in document parser: ${file.mimetype}`);
if (file.mimetype === 'application/pdf') {
text = await pdfToText(file);
} else if (
file.mimetype === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
) {
text = await wordDocToText(file);
} else if (
excelMimeTypes.test(file.mimetype) ||
file.mimetype === 'application/vnd.oasis.opendocument.spreadsheet'
) {
text = await excelSheetToText(file);
} else {
throw new Error(`Unsupported file type in document parser: ${file.mimetype}`);
}
if (!text?.trim()) {

Binary file not shown.