Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: keep speaker notes when a PowerPoint file is attached in chat (#17258)

Nilay5180805451a2
diff --git a/studio/frontend/src/components/file-viewer/office.ts b/studio/frontend/src/components/file-viewer/office.ts
index 81abf07129c..c24f5a6259b 100644
--- a/studio/frontend/src/components/file-viewer/office.ts
+++ b/studio/frontend/src/components/file-viewer/office.ts
@@ -1249,6 +1249,7 @@ export interface SlideBox {
export interface Slide {
boxes: SlideBox[];
+ notes?: string[];
}
export interface Deck {
@@ -1510,7 +1511,10 @@ function degrees(xfrm: Element | undefined): number {
return Number(xfrm?.getAttribute("rot")) / 60000 || 0;
}
-export function readPptx(bytes: Uint8Array, { images = true, maxSlides = MAX_SLIDES } = {}): Deck {
+export function readPptx(
+ bytes: Uint8Array,
+ { images = true, maxSlides = MAX_SLIDES, notes = false } = {},
+): Deck {
const read = archive(bytes);
const main = mainPart(read, "ppt/presentation.xml");
if ((read.size(main) ?? 0) > MAX_XML_PART_BYTES) throw new Error("File is too large to preview.");
@@ -1680,8 +1684,20 @@ export function readPptx(bytes: Uint8Array, { images = true, maxSlides = MAX_SLI
};
const tree = first(doc, "spTree");
if (tree) walk(tree);
+ const notesPath = notes ? slideRelList.find((rel) => rel.type.endsWith("/notesSlide"))?.path : undefined;
+ const notesDoc = notesPath ? partDoc(notesPath) : null;
+ const slideNumber = new Set(
+ (notesDoc ? all(notesDoc, "sp") : [])
+ .filter((sp) => first(sp, "ph")?.getAttribute("type") === "sldNum")
+ .flatMap((sp) => all(sp, "p")),
+ );
+ const noteLines = (notesDoc ? all(notesDoc, "p") : [])
+ .filter((p) => !slideNumber.has(p))
+ .map(paragraphText)
+ .filter((text) => text.trim());
+ textLeft -= noteLines.reduce((n, text) => n + text.length, 0);
if (cut) boxes.push({ paragraphs: [{ text: "…" }] });
- slides.push({ boxes });
+ slides.push(noteLines.length ? { boxes, notes: noteLines } : { boxes });
if (textLeft <= 0) {
truncated = index < slidePaths.length - 1;
break;
diff --git a/studio/frontend/src/features/chat/attachment-content.ts b/studio/frontend/src/features/chat/attachment-content.ts
index 03d2f8249c5..4f86c8c3640 100644
--- a/studio/frontend/src/features/chat/attachment-content.ts
+++ b/studio/frontend/src/features/chat/attachment-content.ts
@@ -1789,7 +1789,7 @@ export async function extractOfficeAttachmentText(
const budget = textBudget(MAX_OFFICE_TEXT_BYTES);
const parts: string[] = [];
if (label === "PPTX") {
- const deck = readPptx(bytes, { images: false });
+ const deck = readPptx(bytes, { images: false, notes: true });
for (const [index, slide] of deck.slides.entries()) {
if (budget.cut) break;
const lines = [budget.take(`Slide ${index + 1}`)];
@@ -1798,6 +1798,7 @@ export async function extractOfficeAttachmentText(
if (box.caption) lines.push(budget.take(box.caption));
for (const row of box.table ?? []) lines.push(row.map((cell) => budget.take(cell)).join("\t"));
}
+ if (slide.notes) lines.push(budget.take("Notes:"), ...slide.notes.map((text) => budget.take(text)));
parts.push(lines.join("\n"));
}
if (deck.truncated && !budget.cut) {
diff --git a/studio/frontend/tests/file-viewer-office.test.ts b/studio/frontend/tests/file-viewer-office.test.ts
index f3de416a60e..10920366d94 100644
--- a/studio/frontend/tests/file-viewer-office.test.ts
+++ b/studio/frontend/tests/file-viewer-office.test.ts
@@ -8,6 +8,9 @@ import { DOMParser } from "@xmldom/xmldom";
import { strToU8, zipSync } from "fflate";
import { formatNumber, readDelimited, readPptx, readXlsx } from "../src/components/file-viewer/office.ts";
+import { registerBundlerResolver } from "./helpers/kit.ts";
+
+registerBundlerResolver();
{
const proto = Object.getPrototypeOf(new DOMParser().parseFromString("<a/>", "application/xml").documentElement);
@@ -269,6 +272,42 @@ test("pptx: maxSlides stops reading after that many slides", () => {
assert.equal(first.slides[0]!.boxes[0]?.paragraphs?.[0]?.text, "one");
});
+test("pptx attachments keep speaker notes without the slide number", async () => {
+ const { extractOfficeAttachmentText } = await import("../src/features/chat/attachment-content.ts");
+ const P = "http://schemas.openxmlformats.org/presentationml/2006/main";
+ const A = "http://schemas.openxmlformats.org/drawingml/2006/main";
+ const sp = (ph: string, body: string) =>
+ `<p:sp><p:nvSpPr><p:nvPr><p:ph type="${ph}"/></p:nvPr></p:nvSpPr><p:txBody>${body}</p:txBody></p:sp>`;
+ const zip = zipSync({
+ "ppt/presentation.xml": strToU8(
+ `<p:presentation xmlns:p="${P}" xmlns:r="${REL}"><p:sldIdLst><p:sldId id="256" r:id="rId1"/></p:sldIdLst></p:presentation>`,
+ ),
+ "ppt/_rels/presentation.xml.rels": rels(`<Relationship Id="rId1" Type="${REL}/slide" Target="slides/slide1.xml"/>`),
+ "ppt/slides/slide1.xml": strToU8(
+ `<p:sld xmlns:p="${P}" xmlns:a="${A}"><p:cSld><p:spTree>${sp("title", "<a:p><a:r><a:t>Quarterly plan</a:t></a:r></a:p>")}</p:spTree></p:cSld></p:sld>`,
+ ),
+ "ppt/slides/_rels/slide1.xml.rels": rels(
+ `<Relationship Id="rId2" Type="${REL}/notesSlide" Target="../notesSlides/notesSlide1.xml"/>`,
+ ),
+ "ppt/notesSlides/notesSlide1.xml": strToU8(
+ `<p:notes xmlns:p="${P}" xmlns:a="${A}"><p:cSld><p:spTree>` +
+ sp("sldImg", "") +
+ sp("body", "<a:p><a:r><a:t>Budget is 42 dollars</a:t></a:r></a:p><a:p><a:r><a:t>Ask about Q3</a:t></a:r></a:p>") +
+ sp("sldNum", '<a:p><a:fld type="slidenum"><a:t>1</a:t></a:fld></a:p>') +
+ `</p:spTree></p:cSld></p:notes>`,
+ ),
+ });
+ const file = new File([zip], "deck.pptx");
+ assert.equal(
+ await extractOfficeAttachmentText(file, "PPTX"),
+ "Slide 1\nQuarterly plan\nNotes:\nBudget is 42 dollars\nAsk about Q3",
+ );
+ assert.deepEqual(
+ readPptx(zip).slides[0]?.boxes.flatMap((box) => box.paragraphs?.map((p) => p.text) ?? []),
+ ["Quarterly plan"],
+ );
+});
+
test("sheet limits cap rows, columns and parsed sheets", () => {
const cells = (r: number) => Array.from({ length: 5 }, (_, c) => `<c r="${"ABCDE"[c]}${r}"><v>${r}</v></c>`).join("");
const rows = Array.from({ length: 10 }, (_, i) => `<row r="${i + 1}">${cells(i + 1)}</row>`).join("");