Skip to content

Build your personal knowledge base with Trilium Notes

feat(llm): support SVG attachments

Elian Doran3fd179b451b7
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/useChatAttachments.ts b/apps/client/src/widgets/type_widgets/llm_chat/useChatAttachments.ts
index 6b2b5493e1..95d72f6170 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/useChatAttachments.ts
+++ b/apps/client/src/widgets/type_widgets/llm_chat/useChatAttachments.ts
@@ -7,8 +7,14 @@ import toast from "../../../services/toast.js";
import type { FileBlock, ImageBlock, TextFileBlock } from "./llm_chat_types.js";
import type { AttachmentBlock, UseLlmChatReturn } from "./useLlmChat.js";
-/** MIME types we accept for image upload — must match what the providers support as vision input. */
-const ACCEPTED_IMAGE_TYPES = ["image/png", "image/jpeg", "image/jpg", "image/gif", "image/webp"];
+/**
+ * MIME types we accept as image attachments. The first four are what every
+ * major provider supports natively as vision input. SVG is treated as an image
+ * here — the chip and message bubble render it inline — but the server detects
+ * the SVG mime and sends the XML source as a text part, since no provider
+ * accepts SVG as a vision input.
+ */
+const ACCEPTED_IMAGE_TYPES = ["image/png", "image/jpeg", "image/jpg", "image/gif", "image/webp", "image/svg+xml"];
/** Binary file MIME types we accept (provider-side handling). PDFs are supported by Anthropic, OpenAI, Google. */
const ACCEPTED_BINARY_FILE_TYPES = ["application/pdf"];
/**
diff --git a/apps/server/src/services/llm/providers/base_provider.ts b/apps/server/src/services/llm/providers/base_provider.ts
index 6dadd203c2..cbac4f220e 100644
--- a/apps/server/src/services/llm/providers/base_provider.ts
+++ b/apps/server/src/services/llm/providers/base_provider.ts
@@ -72,10 +72,22 @@ function resolveMessagePart(part: LlmMessagePart): TextPart | ImagePart | FilePa
return null;
}
if (part.type === "image") {
+ const mime = part.mime || attachment.mime;
+ // SVG isn't accepted by any major provider's vision input, but every
+ // LLM is fluent in SVG markup — send the XML source as a text part so
+ // the model can actually read and reason about it.
+ if (mime === "image/svg+xml") {
+ const filename = attachment.title || "image.svg";
+ const text = decodeUtf8(attachment.getContent());
+ return {
+ type: "text",
+ text: `<file name="${filename}">\n${text}\n</file>`
+ };
+ }
return {
type: "image",
image: attachment.getContent(),
- mediaType: part.mime || attachment.mime
+ mediaType: mime
};
}
if (part.type === "file") {