Skip to content

Build your personal knowledge base with Trilium Notes

feat(llm): list the attachment kinds each model reads natively

Elian Doran8c76fe54fb38
diff --git a/apps/server/src/services/llm/providers/acp_agent.ts b/apps/server/src/services/llm/providers/acp_agent.ts
index dab1e7d2e4..ec47932709 100644
--- a/apps/server/src/services/llm/providers/acp_agent.ts
+++ b/apps/server/src/services/llm/providers/acp_agent.ts
@@ -19,7 +19,7 @@
* permission policy; the protocol handling lives here.
*/
-import { LLM_REASONING_EFFORTS, type LlmMessage, type LlmMessagePart, type LlmReasoningEffort, type LlmStreamChunk } from "@triliumnext/commons";
+import { LLM_REASONING_EFFORTS, type LlmAttachmentKind, type LlmMessage, type LlmMessagePart, type LlmReasoningEffort, type LlmStreamChunk } from "@triliumnext/commons";
import { getLog } from "@triliumnext/core";
import { attachmentPlaceholder, resolveAttachmentPart } from "@triliumnext/core/src/services/llm/attachment_content.js";
import { buildNoteHint } from "@triliumnext/core/src/services/llm/note_hint.js";
@@ -97,6 +97,9 @@ type AcpMcpServer = { name: string; type: "http"; url: string; headers: never[]
/** Image media types the ACP prompt accepts as a base64 image block. */
const SUPPORTED_IMAGE_MIMES = new Set<string>(["image/png", "image/jpeg", "image/gif", "image/webp"]);
+/** What {@link buildPromptBlocks} sends natively: images, while a PDF becomes a placeholder. */
+const ACP_ATTACHMENT_KINDS: LlmAttachmentKind[] = [ "image" ];
+
/**
* How long a probed catalog is reused. The line-up changes with the vendor's
* releases and the user's plan, neither of which moves within an editing
@@ -383,7 +386,7 @@ export abstract class AcpAgentProvider implements LlmProvider {
}
getAvailableModels(): ModelInfo[] {
- return this.fallbackModels;
+ return withAcpAttachmentKinds(this.fallbackModels);
}
/**
@@ -423,7 +426,7 @@ export abstract class AcpAgentProvider implements LlmProvider {
try {
client = await this.startClient(() => {});
const created = await this.createSession(client, { cwd: this.agentCwd(), mcpServers: [] }, true, MODEL_PROBE_TIMEOUT_MS);
- const models = this.buildModelList(created.models ?? {});
+ const models = withAcpAttachmentKinds(this.buildModelList(created.models ?? {}));
this.state().modelCatalogCache = { models, fetchedAt: Date.now() };
return models;
} catch (err) {
@@ -1022,6 +1025,11 @@ export function buildPromptBlocks(content: string | LlmMessagePart[], prefix: st
return blocks;
}
+/** Declares {@link ACP_ATTACHMENT_KINDS} on each model. */
+function withAcpAttachmentKinds(models: ModelInfo[]): ModelInfo[] {
+ return models.map(model => ({ ...model, attachmentKinds: ACP_ATTACHMENT_KINDS }));
+}
+
export function describeError(error: unknown): string {
return error instanceof Error ? error.message : String(error);
}
diff --git a/apps/server/src/services/llm/providers/antigravity_agent.spec.ts b/apps/server/src/services/llm/providers/antigravity_agent.spec.ts
index 7ca487904e..8c4b4bde5f 100644
--- a/apps/server/src/services/llm/providers/antigravity_agent.spec.ts
+++ b/apps/server/src/services/llm/providers/antigravity_agent.spec.ts
@@ -351,6 +351,8 @@ describe("AntigravityAgentProvider", () => {
expect(FakeAcpClient.current?.methods()).toEqual(["initialize", "session/new", "authenticate", "session/new"]);
expect(FakeAcpClient.current?.requests[2].params).toEqual({ methodId: "oauth-personal" });
expect(models.map(m => m.id)).toEqual(["default", "gemini-3.8-flash", "gemini-3.7-flash", "gemini-3.6-flash", "gemini-3.1-pro"]);
+ // The ACP prompt carries images but no PDFs, which become placeholders.
+ expect(models.map(m => m.attachmentKinds)).toEqual(models.map(() => ["image"]));
});
it("leaves the default model to the server, selects any other, and titles on the newest Flash Low", async () => {
diff --git a/packages/commons/src/lib/llm_api.ts b/packages/commons/src/lib/llm_api.ts
index 0661882772..5382bfc0b4 100644
--- a/packages/commons/src/lib/llm_api.ts
+++ b/packages/commons/src/lib/llm_api.ts
@@ -158,8 +158,18 @@ export interface LlmModelInfo {
reasoningEfforts?: LlmReasoningEffort[];
/** The effort used when a chat has not chosen one. One of {@link reasoningEfforts}. */
defaultReasoningEffort?: LlmReasoningEffort;
+ /**
+ * The attachment kinds the model reads natively. Absent means every kind; text attachments
+ * are inlined as text for every model and never listed.
+ */
+ attachmentKinds?: LlmAttachmentKind[];
}
+/** An attachment a model reads natively: an image, or a file such as a PDF. */
+export const LLM_ATTACHMENT_KINDS = [ "image", "file" ] as const;
+
+export type LlmAttachmentKind = (typeof LLM_ATTACHMENT_KINDS)[number];
+
/**
* Token usage information from the LLM response.
*/
diff --git a/packages/trilium-core/src/services/llm/providers/base_provider.spec.ts b/packages/trilium-core/src/services/llm/providers/base_provider.spec.ts
index e7e2ccc53a..c1856a15f3 100644
--- a/packages/trilium-core/src/services/llm/providers/base_provider.spec.ts
+++ b/packages/trilium-core/src/services/llm/providers/base_provider.spec.ts
@@ -249,6 +249,22 @@ describe("listModels", () => {
expect(models.map((m) => m.id)).toEqual(["cheap", "mid", "spendy"]);
});
+ it("lists attachmentKinds only on models that don't read every kind", async () => {
+ class NoPdfProvider extends TestProvider {
+ protected override acceptsAttachment(kind: "image" | "file", modelId: string) {
+ return kind === "image" || modelId === "spendy";
+ }
+ }
+ const fromTable = await new NoPdfProvider().listModels();
+ expect(fromTable.map(m => m.attachmentKinds)).toEqual([["image"], ["image"], undefined]);
+
+ const listed = new NoPdfProvider();
+ listed.fetchRemoteModelsMock.mockResolvedValue([{ id: "mid" }, { id: "brand-new" }]);
+ expect((await listed.listModels()).map(m => m.attachmentKinds)).toEqual([["image"], ["image"]]);
+
+ expect((await new TestProvider().listModels()).some(m => "attachmentKinds" in m)).toBe(false);
+ });
+
it("merges the remote list with price-table metadata and caches the result", async () => {
const provider = new TestProvider();
provider.fetchRemoteModelsMock.mockResolvedValue([{ id: "mid" }, { id: "brand-new" }]);
diff --git a/packages/trilium-core/src/services/llm/providers/base_provider.ts b/packages/trilium-core/src/services/llm/providers/base_provider.ts
index 94b4c44131..91dbcc6309 100644
--- a/packages/trilium-core/src/services/llm/providers/base_provider.ts
+++ b/packages/trilium-core/src/services/llm/providers/base_provider.ts
@@ -3,7 +3,7 @@
* tool assembly, model pricing, and title generation.
*/
-import { type LlmMessage, type LlmMessagePart } from "@triliumnext/commons";
+import { LLM_ATTACHMENT_KINDS, type LlmAttachmentKind, type LlmMessage, type LlmMessagePart } from "@triliumnext/commons";
import { type FilePart, generateText, type ImagePart, type LanguageModel, type ModelMessage, stepCountIs, streamText, type SystemModelMessage, type TextPart, type ToolSet } from "ai";
import { getLog } from "../../log.js";
@@ -114,7 +114,7 @@ function resolveMessagePart(part: LlmMessagePart, accepts: AttachmentFilter): Te
}
/** Whether a model reads an attachment of this kind natively. Text attachments are always inlined. */
-export type AttachmentFilter = (kind: "image" | "file") => boolean;
+export type AttachmentFilter = (kind: LlmAttachmentKind) => boolean;
/**
* Build a single ModelMessage from an LlmMessage. Plain string content stays
@@ -301,13 +301,21 @@ export abstract class BaseProvider implements LlmProvider {
if (!remote || remote.length === 0) {
// The provider doesn't support dynamic listing, or the endpoint
// returned nothing — the price-table catalog is the answer, not an error.
- return this.getAvailableModels();
+ return this.withAttachmentKinds(this.getAvailableModels());
}
- const merged = mergeModelLists(this.getAvailableModels(), remote);
+ const merged = this.withAttachmentKinds(mergeModelLists(this.getAvailableModels(), remote));
this.modelListCache = { models: merged, fetchedAt: Date.now() };
return merged;
}
+ /** Lists {@link ModelInfo.attachmentKinds} on the models {@link acceptsAttachment} limits. */
+ private withAttachmentKinds(models: ModelInfo[]): ModelInfo[] {
+ return models.map(model => {
+ const kinds = LLM_ATTACHMENT_KINDS.filter(kind => this.acceptsAttachment(kind, model.id));
+ return kinds.length === LLM_ATTACHMENT_KINDS.length ? model : { ...model, attachmentKinds: kinds };
+ });
+ }
+
/**
* Build the system prompt. Delegates to the shared `system_prompt` module;
* kept as an overridable method so providers can post-process the result
@@ -332,7 +340,7 @@ export abstract class BaseProvider implements LlmProvider {
* Whether `modelId` reads an image or file attachment natively. One it doesn't is sent as an
* `[attached …]` placeholder, so the model knows something was attached instead of never seeing it.
*/
- protected acceptsAttachment(_kind: "image" | "file", _modelId: string): boolean {
+ protected acceptsAttachment(_kind: LlmAttachmentKind, _modelId: string): boolean {
return true;
}
diff --git a/packages/trilium-core/src/services/llm/providers/deepseek.spec.ts b/packages/trilium-core/src/services/llm/providers/deepseek.spec.ts
index fa58a02354..d25ebab37a 100644
--- a/packages/trilium-core/src/services/llm/providers/deepseek.spec.ts
+++ b/packages/trilium-core/src/services/llm/providers/deepseek.spec.ts
@@ -330,6 +330,14 @@ describe("DeepSeekProvider attachments", () => {
expect(content).toContain("[attached file: report.pdf]");
});
+ it("lists what each model reads natively", async () => {
+ const okJson = (body: unknown) => ({ ok: true, json: async () => body });
+ fetchMock.mockResolvedValue(okJson({ data: [{ id: "deepseek-v4-pro" }, { id: "deepseek-v4-flash-vision-exp" }] }));
+ const models = await new DeepSeekProvider("sk-deep").listModels();
+ expect(models.find(m => m.id === "deepseek-v4-pro")?.attachmentKinds).toEqual([]);
+ expect(models.find(m => m.id === "deepseek-v4-flash-vision-exp")?.attachmentKinds).toEqual(["image"]);
+ });
+
it("sends images to the vision model, and names the PDF it cannot read", async () => {
const content = await sentUserContent("deepseek-v4-flash-vision-exp");
expect(content).toEqual(expect.arrayContaining([
diff --git a/packages/trilium-core/src/services/llm/providers/deepseek.ts b/packages/trilium-core/src/services/llm/providers/deepseek.ts
index e53fb4f48a..4262af2fd8 100644
--- a/packages/trilium-core/src/services/llm/providers/deepseek.ts
+++ b/packages/trilium-core/src/services/llm/providers/deepseek.ts
@@ -1,5 +1,5 @@
import { createDeepSeek, type DeepSeekLanguageModelChatOptions, type DeepSeekProvider as DeepSeekSDKProvider } from "@ai-sdk/deepseek";
-import type { LlmReasoningEffort } from "@triliumnext/commons";
+import type { LlmAttachmentKind, LlmReasoningEffort } from "@triliumnext/commons";
import type { LlmProviderConfig, ModelInfo } from "../types.js";
import { BaseProvider, type RemoteModel } from "./base_provider.js";
@@ -78,7 +78,7 @@ export class DeepSeekProvider extends BaseProvider {
}
/** DeepSeek reads no PDFs, and images only on its vision models (`deepseek-v4-flash-vision-exp`). */
- protected override acceptsAttachment(kind: "image" | "file", modelId: string): boolean {
+ protected override acceptsAttachment(kind: LlmAttachmentKind, modelId: string): boolean {
return kind === "image" && modelId.includes("vision");
}
diff --git a/packages/trilium-core/src/services/llm/types.ts b/packages/trilium-core/src/services/llm/types.ts
index 0514bec083..eacdce520c 100644
--- a/packages/trilium-core/src/services/llm/types.ts
+++ b/packages/trilium-core/src/services/llm/types.ts
@@ -4,7 +4,7 @@
* should be imported from @triliumnext/commons.
*/
-import type { LlmChatConfig, LlmMessage, LlmReasoningEffort, LlmStreamChunk } from "@triliumnext/commons";
+import type { LlmAttachmentKind, LlmChatConfig, LlmMessage, LlmReasoningEffort, LlmStreamChunk } from "@triliumnext/commons";
import type { streamText } from "ai";
/**
@@ -60,6 +60,8 @@ export interface ModelInfo {
reasoningEfforts?: LlmReasoningEffort[];
/** The effort used when a chat has not chosen one. */
defaultReasoningEffort?: LlmReasoningEffort;
+ /** The attachment kinds the model reads natively; see `LlmModelInfo`. */
+ attachmentKinds?: LlmAttachmentKind[];
}
export interface LlmProvider {