From 1069565dbd1f56ef7166053377147752d2f5d0c8 Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Mon, 23 Nov 2026 18:08:06 +0000 Subject: [PATCH] fix(server): XLSX files whose workbook is not xl/workbook.xml reach the agent --- .../server/src/provider/documentTextWorker.ts | 25 ++++++++++++------- .../src/provider/userInputAttachments.test.ts | 21 ++++++++++++++++ 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/apps/server/src/provider/documentTextWorker.ts b/apps/server/src/provider/documentTextWorker.ts index 3fe14f40ddbf..2f5a05f22cde 100644 --- a/apps/server/src/provider/documentTextWorker.ts +++ b/apps/server/src/provider/documentTextWorker.ts @@ -665,8 +665,8 @@ async function* document(path: string, extension: string): AsyncGenerator rel.attrs.TargetMode !== "External") .map((rel) => [rel.attrs.Id, rel.attrs]), ); - if (extension === ".docx") { - // The package relationship names the main part; Word for the web saves word/document2.xml. + // The package relationship names the main part; Word for the web saves word/document2.xml. + const mainPart = (fallback: string) => { const target = has("_rels/.rels") ? [...all(read("_rels/.rels"), "Relationship")].find( (rel) => @@ -674,7 +674,10 @@ async function* document(path: string, extension: string): AsyncGenerator + NodePath.posix.resolve(`/${workbookDir}`, target).slice(1); + const workbook = read(workbookPath); + const rels = relations( + NodePath.posix.join(workbookDir, "_rels", `${NodePath.posix.basename(workbookPath)}.rels`), + ); const workbookRelations = [...rels.values()]; const workbookPartPath = (part: string) => { const target = workbookRelations.find((rel) => rel.Type?.endsWith(`/${part}`))?.Target; - return target ? NodePath.posix.resolve("/xl", target).slice(1) : `xl/${part}.xml`; + return resolveWorkbookPart(target || `${part}.xml`); }; const dateSystem = ["1", "true"].includes( all(workbook, "workbookPr").next().value?.attrs.date1904 ?? "", @@ -731,9 +740,7 @@ async function* document(path: string, extension: string): AsyncGenerator { const value = all(cell, "v").next().value; if (cell.attrs.t === "s") { diff --git a/apps/server/src/provider/userInputAttachments.test.ts b/apps/server/src/provider/userInputAttachments.test.ts index 7d0e75d7384c..6192a0f645e2 100644 --- a/apps/server/src/provider/userInputAttachments.test.ts +++ b/apps/server/src/provider/userInputAttachments.test.ts @@ -1010,6 +1010,27 @@ describe("question answer paths", () => { "45293 [Excel numFmtId=164; format=yyyy-mm-dd; date system 1900]", ], }, + { + ext: "xlsx", + bounded: true, + parts: { + "_rels/.rels": + '', + "docs/book.xml": '', + "docs/_rels/book.xml.rels": + '', + "docs/strings.xml": "Harbor", + "docs/styles.xml": + '', + "docs/sheets/data.xml": + '045293', + }, + expected: [ + "## Sheet: Data", + "Harbor\t45293 [Excel numFmtId=164; format=yyyy-mm-dd; date system 1900]", + ], + absent: ["[Skipped document part"], + }, { ext: "xlsx", bounded: true,