mirror of
https://github.com/zadam/trilium.git
synced 2026-07-16 07:24:00 +02:00
feat(llm): get_attachment + get_note_attachments
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user