The best way to control Claude Code, Codex and more from any computer or phone
fix(server): count only actual slides in PowerPoint attachment text (#38377)
Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com>
Simone committed
Nov 18, 2026 at 01:31 UTC
959c4c1ecf0dac0e6a1ebc83336113ecf91a585d
2 files changed
+21
-9
apps/server/src/provider/documentTextWorker.ts
+5
-3
@@ -133,8 +133,8 @@ function xml(source: string, extension: string): XmlNode {
133
return root;
134
}
135
136
-const children = (node: XmlNode) =>
137
- node.children.filter((child): child is XmlNode => typeof child !== "string");
136
+const children = (node: XmlNode | undefined) =>
137
+ node?.children.filter((child): child is XmlNode => typeof child !== "string") ?? [];
138
function* all(node: XmlNode, name: string | readonly string[]): Generator<XmlNode, void> {
139
for (const child of children(node)) {
140
if (typeof name === "string" ? child.name === name : name.includes(child.name)) yield child;
@@ -630,8 +630,10 @@ async function* document(path: string, extension: string): AsyncGenerator<TextPa
630
}
631
} else if (extension === ".pptx") {
632
const rels = relations("ppt/_rels/presentation.xml.rels");
633
+ const [presentation] = children(read("ppt/presentation.xml"));
634
+ const slideList = children(presentation).find((node) => node.name === "sldIdLst");
635
let index = 0;
634
- for (const slide of all(read("ppt/presentation.xml"), "sldId")) {
636
+ for (const slide of children(slideList).filter((node) => node.name === "sldId")) {
637
yield `\n\n## Slide ${++index}\n`;
638
const target = rels.get(slide.attrs["r:id"] ?? slide.attrs.id);
639
if (!target) {
apps/server/src/provider/userInputAttachments.test.ts
+16
-6
@@ -685,7 +685,7 @@ describe("question answer paths", () => {
685
ext === "pptx"
686
? {
687
"ppt/presentation.xml":
688
- '<presentation><sldId r:id="bad"/><sldId r:id="good"/></presentation>',
688
+ '<presentation><sldIdLst><sldId r:id="bad"/><sldId r:id="good"/></sldIdLst></presentation>',
689
"ppt/_rels/presentation.xml.rels":
690
'<Relationships><Relationship Id="bad" Target="bad.xml"/><Relationship Id="good" Target="good.xml"/></Relationships>',
691
"ppt/bad.xml": "<slide><p>Discard</slide>",
@@ -912,8 +912,16 @@ describe("question answer paths", () => {
912
ext: "pptx",
913
bounded: true,
914
parts: {
915
- "ppt/presentation.xml":
916
- '<p:presentation><p:sldIdLst><p:sldId id="1" r:id="b"/><p:sldId id="2" r:id="a"/></p:sldIdLst></p:presentation>',
915
+ "ppt/presentation.xml": `<p:presentation xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"
916
+ xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
917
+ xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main">
918
+ <p:sldIdLst><p:sldId id="256" r:id="b"/><p:sldId id="257" r:id="a"/></p:sldIdLst>
919
+ <p:extLst><p:ext uri="{521415D9-36F7-43E2-AB2F-B90AF26B5E84}"><p14:sectionLst>
920
+ <p14:section name="Schedule" id="{01F07B81-39E6-4BBB-9B89-66EA253FBD29}">
921
+ <p14:sldIdLst><p14:sldId id="256"/><p14:sldId id="257"/></p14:sldIdLst>
922
+ </p14:section>
923
+ </p14:sectionLst></p:ext></p:extLst>
924
+ </p:presentation>`,
925
"ppt/_rels/presentation.xml.rels":
926
'<Relationships><Relationship Id="a" Target="slides/slide1.xml"/><Relationship Id="b" Target="slides/slide2.xml"/></Relationships>',
927
"ppt/slides/slide1.xml": "<p:sld><a:p><a:r><a:t>Departure</a:t></a:r></a:p></p:sld>",
@@ -934,13 +942,15 @@ describe("question answer paths", () => {
942
"## Slide 2",
943
"Departure\nNotes:\nBoard at gate 4",
944
],
945
+ occurrences: { text: "## Slide ", count: 2 },
946
absent: ["Unrelated notes", "[Skipped document part", "[Extracted text truncated"],
947
},
948
...[false, true].map((missing) => ({
949
ext: "pptx",
950
bounded: true,
951
parts: {
943
- "ppt/presentation.xml": '<presentation><sldId r:id="a"/></presentation>',
952
+ "ppt/presentation.xml":
953
+ '<presentation><sldIdLst><sldId r:id="a"/></sldIdLst></presentation>',
954
"ppt/_rels/presentation.xml.rels":
955
'<Relationships><Relationship Id="a" Target="slides/a.xml"/></Relationships>',
956
"ppt/slides/a.xml": "<slide><p>Slide text</p></slide>",
@@ -958,7 +968,7 @@ describe("question answer paths", () => {
968
bounded: true,
969
parts: {
970
"ppt/presentation.xml":
961
- '<presentation><sldId r:id="a"/><sldId r:id="b"/></presentation>',
971
+ '<presentation><sldIdLst><sldId r:id="a"/><sldId r:id="b"/></sldIdLst></presentation>',
972
"ppt/_rels/presentation.xml.rels":
973
'<Relationships><Relationship Id="a" Target="slides/a.xml"/><Relationship Id="b" Target="slides/b.xml"/></Relationships>',
974
"ppt/slides/a.xml": `<slide><p>${"A".repeat(600_000)}</p></slide>`,
@@ -1092,7 +1102,7 @@ describe("question answer paths", () => {
1102
bounded: true,
1103
parts: {
1104
"ppt/presentation.xml":
1095
- '<p:presentation><p:sldId r:id="a"/><p:sldId r:id="missing"/></p:presentation>',
1105
+ '<p:presentation><p:sldIdLst><p:sldId r:id="a"/><p:sldId r:id="missing"/></p:sldIdLst></p:presentation>',
1106
"ppt/_rels/presentation.xml.rels":
1107
'<Relationships><Relationship Id="a" Target="slides/slide.xml"/></Relationships>',
1108
"ppt/slides/slide.xml": `<p:sld><a:p><a:t>${"A".repeat(1_000_100)}</a:t></a:p></p:sld>`,