Skip to content

Build your personal knowledge base with Trilium Notes

client/AI chat: handle multiple files in a single messages without text in ToC

Adorian Doran10aa9733c9a4
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/chat_toc.spec.ts b/apps/client/src/widgets/type_widgets/llm_chat/chat_toc.spec.ts
index 67edf478a0..3e23c169ed 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/chat_toc.spec.ts
+++ b/apps/client/src/widgets/type_widgets/llm_chat/chat_toc.spec.ts
@@ -162,6 +162,16 @@ describe("buildChatHeadings", () => {
const [heading] = buildChatHeadings([userMessage("u1", content)]);
expect(heading.text).toBe("File: notes.md");
});
+
+ it("comma-joins the titles when a message carries multiple files", () => {
+ const content: ContentBlock[] = [
+ { type: "image", attachmentId: "att1", mime: "image/png", title: "diagram.png", url: "/x" },
+ { type: "file", attachmentId: "att2", mime: "application/pdf", title: "report.pdf", url: "/y" },
+ { type: "text_file", attachmentId: "att3", mime: "text/markdown", title: "notes.md", url: "/z" }
+ ];
+ const [heading] = buildChatHeadings([userMessage("u1", content)]);
+ expect(heading.text).toBe("File: diagram.png, report.pdf, notes.md");
+ });
});
describe("pickActiveHeadingId", () => {
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/chat_toc.ts b/apps/client/src/widgets/type_widgets/llm_chat/chat_toc.ts
index 4d552b93fa..d55726581b 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/chat_toc.ts
+++ b/apps/client/src/widgets/type_widgets/llm_chat/chat_toc.ts
@@ -129,13 +129,15 @@ function getMessagePreviewText(content: string | ContentBlock[]): string {
const text = getMessageText(content);
if (text.trim()) return text;
if (Array.isArray(content)) {
+ // Attachment-only messages get a localized "File: " prefix so a bare filename in
+ // the list isn't mistaken for the message's prose; multiple files are comma-joined.
+ const titles: string[] = [];
for (const block of content) {
- // Attachment-only messages get a localized "File: " prefix so a bare filename
- // in the list isn't mistaken for the message's prose.
if ((block.type === "image" || block.type === "file" || block.type === "text_file") && block.title) {
- return t("llm_chat.toc_file", { name: block.title });
+ titles.push(block.title);
}
}
+ if (titles.length > 0) return t("llm_chat.toc_file", { name: titles.join(", ") });
}
return "";
}