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/tools): get attachments by note
Elian Doran98c70e662dc0
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex b96718128f..392efae3e7 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2354,7 +2354,8 @@"get_subtree": "Get subtree","load_skill": "Load skill","web_search": "Web search",- "note_in_parent": "<Note/> in <Parent/>"+ "note_in_parent": "<Note/> in <Parent/>",+ "get_attachments": "Get attachments"}}}diff --git a/apps/server/src/services/llm/tools/attachment_tools.ts b/apps/server/src/services/llm/tools/attachment_tools.tsnew file mode 100644index 0000000000..c2043d5843--- /dev/null+++ b/apps/server/src/services/llm/tools/attachment_tools.ts@@ -0,0 +1,36 @@+/**+ * LLM tools for attachment operations.+ */++import { z } from "zod";++import becca from "../../../becca/becca.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.",+ 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" };+ }++ 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+ }));+ }+ }+});diff --git a/apps/server/src/services/llm/tools/index.ts b/apps/server/src/services/llm/tools/index.tsindex b4b10b4884..1af4e4bef5 100644--- a/apps/server/src/services/llm/tools/index.ts+++ b/apps/server/src/services/llm/tools/index.ts@@ -5,6 +5,7 @@export { noteTools } from "./note_tools.js";export { attributeTools } from "./attribute_tools.js";+export { attachmentTools } from "./attachment_tools.js";export { hierarchyTools } from "./hierarchy_tools.js";export { skillTools } from "../skills/index.js";export type { ToolDefinition } from "./tool_registry.js";@@ -12,6 +13,7 @@ export { ToolRegistry } from "./tool_registry.js";import { noteTools } from "./note_tools.js";import { attributeTools } from "./attribute_tools.js";+import { attachmentTools } from "./attachment_tools.js";import { hierarchyTools } from "./hierarchy_tools.js";import { skillTools } from "../skills/index.js";import type { ToolRegistry } from "./tool_registry.js";@@ -20,6 +22,7 @@ import type { ToolRegistry } from "./tool_registry.js";export const allToolRegistries: ToolRegistry[] = [noteTools,attributeTools,+ attachmentTools,hierarchyTools,skillTools];