@exulu/backend 5.21.0 → 5.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,55 @@
1
+ import * as fs from "fs";
2
+
3
+ jest.mock("@EE/entitlements", () => ({ checkLicense: () => ({ "advanced-document-processing": true }) }));
4
+ jest.mock("@SRC/utils/python-executor", () => ({ executePythonScript: jest.fn() }));
5
+ jest.mock("@SRC/exulu/resolve-ocr", () => ({ resolveOcr: jest.fn() }));
6
+ jest.mock("@SRC/exulu/resolve-model", () => ({ resolveModel: jest.fn(async () => ({ languageModel: {} })) }));
7
+ jest.mock("@llamaindex/liteparse", () => ({ LiteParse: jest.fn() }), { virtual: true });
8
+ jest.mock("ai", () => ({ generateText: jest.fn(), Output: { object: (x: unknown) => x } }));
9
+ jest.mock("@SRC/templates/tools/document-render-helpers", () => ({ convertOfficeToPdf: jest.fn() }));
10
+
11
+ import { documentProcessor } from "./doc_processor";
12
+
13
+ const { LiteParse } = require("@llamaindex/liteparse") as { LiteParse: jest.Mock };
14
+ const { convertOfficeToPdf } = require("@SRC/templates/tools/document-render-helpers") as { convertOfficeToPdf: jest.Mock };
15
+
16
+ const PDF = Buffer.from("%PDF-1.4 rendered deck");
17
+
18
+ beforeEach(() => {
19
+ jest.clearAllMocks();
20
+ jest.spyOn(console, "log").mockImplementation(() => undefined);
21
+ jest.spyOn(console, "error").mockImplementation(() => undefined);
22
+ convertOfficeToPdf.mockResolvedValue(PDF);
23
+ });
24
+ afterEach(() => jest.restoreAllMocks());
25
+
26
+ describe("presentations go through the PDF path", () => {
27
+ it.each(["pptx", "ppt", "pptm", "odp"])("renders a .%s to PDF and parses the PDF, not the upload", async (ext) => {
28
+ let parsed: { path: string; bytes: Buffer } | undefined;
29
+ LiteParse.mockImplementation(() => ({
30
+ parse: async (source: string) => {
31
+ parsed = { path: source, bytes: fs.readFileSync(source) };
32
+ return { pages: [{ pageNum: 1, text: "Folie eins" }, { pageNum: 2, text: "Folie zwei" }] };
33
+ },
34
+ screenshot: async () => [],
35
+ }));
36
+
37
+ const result = await documentProcessor({ file: Buffer.from("PK deck"), name: `Pitch.${ext}`, config: { processor: { name: "liteparse" } } });
38
+
39
+ expect(convertOfficeToPdf).toHaveBeenCalledWith(Buffer.from("PK deck"), `.${ext}`);
40
+ expect(parsed?.path.endsWith("converted.pdf")).toBe(true);
41
+ expect(parsed?.bytes.equals(PDF)).toBe(true);
42
+ expect(result?.map((p) => [p.page, p.content])).toEqual([[1, "Folie eins"], [2, "Folie zwei"]]);
43
+ });
44
+
45
+ it("accepts a presentation for the OCR processor instead of refusing the file type", async () => {
46
+ // The OCR path itself is covered elsewhere; here only: the type gate lets it through to the conversion.
47
+ convertOfficeToPdf.mockRejectedValue(new Error("stop after the gate"));
48
+ await expect(documentProcessor({ file: Buffer.from("PK"), name: "a.pptx", config: { processor: { name: "mistral", model: "vertex-ocr" } } })).rejects.toThrow("stop after the gate");
49
+ });
50
+
51
+ it("reports a failed conversion instead of returning an empty document", async () => {
52
+ convertOfficeToPdf.mockRejectedValue(new Error("LibreOffice could not convert"));
53
+ await expect(documentProcessor({ file: Buffer.from("PK"), name: "a.pptx", config: { processor: { name: "liteparse" } } })).rejects.toThrow("LibreOffice could not convert");
54
+ });
55
+ });
@@ -18,6 +18,7 @@ import type { ResolveOcrInput } from '@SRC/exulu/resolve-ocr';
18
18
  import { resolveModel } from '@SRC/exulu/resolve-model';
19
19
  import type { ProgressFn } from '@SRC/exulu/document-cache/progress';
20
20
  import { ocrConcurrency, type ProviderLimiters } from './limits';
21
+ import { convertOfficeToPdf } from '@SRC/templates/tools/document-render-helpers';
21
22
 
22
23
  export type DocumentProcessorConfig = {
23
24
  vlm?: {
@@ -796,6 +797,20 @@ async function processDocument(
796
797
  result = await processImage(buffer, paths, config, verbose, tolerateVisionFailures, onProgress, limiters);
797
798
  break;
798
799
 
800
+ // A presentation is rendered to PDF and then read like any PDF, with whatever
801
+ // processor is configured. The caller does not choose a parser by file type:
802
+ // slides keep their pictures, charts and screenshots through OCR and the vision pass.
803
+ case 'pptx':
804
+ case 'ppt':
805
+ case 'pptm':
806
+ case 'odp': {
807
+ const pdf = await convertOfficeToPdf(buffer, `.${stripped}`);
808
+ const pdfPath = path.join(tempDir, 'converted.pdf');
809
+ await fs.promises.writeFile(pdfPath, pdf);
810
+ result = await processPdf(pdf, { ...paths, source: pdfPath }, config, verbose, tolerateVisionFailures, onProgress, limiters);
811
+ break;
812
+ }
813
+
799
814
  // Todo other file types with docx and officeparser
800
815
  default:
801
816
  throw new Error(`[EXULU] Unsupported file type: ${fileType}`);
@@ -1182,13 +1197,13 @@ export async function documentProcessor({
1182
1197
  let supportedTypes: string[] = [];
1183
1198
  switch (config?.processor.name) {
1184
1199
  case "officeparser":
1185
- supportedTypes = ['docx', 'pptx', 'xlsx', 'odt', 'odp', 'ods', 'pdf', 'rtf', 'csv', 'md', 'html'];
1200
+ supportedTypes = ['docx', 'pptx', 'ppt', 'pptm', 'xlsx', 'odt', 'odp', 'ods', 'pdf', 'rtf', 'csv', 'md', 'html'];
1186
1201
  break;
1187
1202
  case "liteparse":
1188
1203
  supportedTypes = ['pdf', 'doc', 'docx', 'docm', 'odt', 'rtf', 'ppt', 'pptx', 'pptm', 'odp', 'xls', 'xlsx', 'xlsm', 'ods', 'csv', 'tsv'];
1189
1204
  break;
1190
1205
  case "mistral":
1191
- supportedTypes = ['pdf', 'docx', 'doc', 'txt', 'md', 'jpg', 'jpeg', 'png', 'gif', 'webp'];
1206
+ supportedTypes = ['pdf', 'docx', 'doc', 'pptx', 'ppt', 'pptm', 'odp', 'txt', 'md', 'jpg', 'jpeg', 'png', 'gif', 'webp'];
1192
1207
  break;
1193
1208
  }
1194
1209
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@exulu/backend",
3
3
  "author": "Qventu B.V.",
4
- "version": "5.21.0",
4
+ "version": "5.23.0",
5
5
  "main": "./dist/index.js",
6
6
  "private": false,
7
7
  "publishConfig": {