Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(llm): get_attachment + get_note_attachments
Elian Doran4a0d45ad7db6
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 97c8e27aae..1eb35e1314 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2355,7 +2355,8 @@"load_skill": "Load skill","web_search": "Web search","note_in_parent": "<Note/> in <Parent/>",- "get_attachments": "Get attachments"+ "get_note_attachments": "Get note attachments",+ "get_attachment": "Get attachment"}}}diff --git a/apps/server/src/services/llm/tools/attachment_tools.ts b/apps/server/src/services/llm/tools/attachment_tools.tsindex c2043d5843..4d369b4798 100644--- a/apps/server/src/services/llm/tools/attachment_tools.ts+++ b/apps/server/src/services/llm/tools/attachment_tools.ts@@ -5,32 +5,22 @@import { z } from "zod";import becca from "../../../becca/becca.js";+import mappers from "../../../etapi/mappers.js";import { defineTools } from "./tool_registry.js";export const attachmentTools = defineTools({- get_attachments: {- description: "List all attachments of a note. Returns metadata such as title, MIME type, role, size, and attachment ID for each attachment.",+ get_attachment: {+ description: "Get metadata for a single attachment by its ID.",inputSchema: z.object({- noteId: z.string().describe("The ID of the note whose attachments to list")+ attachmentId: z.string().describe("The ID of the attachment to retrieve")}),- execute: async ({ noteId }) => {- const note = becca.getNote(noteId);- if (!note) {- return { error: "Note not found" };+ execute: async ({ attachmentId }) => {+ const attachment = becca.getAttachment(attachmentId);+ if (!attachment) {+ return { error: "Attachment not found" };}- const attachments = note.getAttachments();-- return attachments.map((att) => ({- attachmentId: att.attachmentId,- title: att.title,- role: att.role,- mime: att.mime,- contentLength: att.contentLength,- position: att.position,- isProtected: !!att.isProtected,- utcDateModified: att.utcDateModified- }));+ return mappers.mapAttachmentToPojo(attachment);}}});diff --git a/apps/server/src/services/llm/tools/note_tools.ts b/apps/server/src/services/llm/tools/note_tools.tsindex 080ad490f7..827be8427c 100644--- a/apps/server/src/services/llm/tools/note_tools.ts+++ b/apps/server/src/services/llm/tools/note_tools.ts@@ -273,5 +273,20 @@ export const noteTools = defineTools({return { error: err instanceof Error ? err.message : "Failed to create note" };}}+ },++ get_note_attachments: {+ description: "List all attachments of a note by its ID. Returns metadata for each attachment.",+ inputSchema: z.object({+ noteId: z.string().describe("The ID of the note whose attachments to list")+ }),+ execute: async ({ noteId }) => {+ const note = becca.getNote(noteId);+ if (!note) {+ return { error: "Note not found" };+ }++ return note.getAttachments().map((att) => mappers.mapAttachmentToPojo(att));+ }}});