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
refactor(llm): don't rely on ETAPI mappers
Elian Dorandd5979aec805
diff --git a/apps/server/src/services/llm/tools/attachment_tools.ts b/apps/server/src/services/llm/tools/attachment_tools.tsindex 4d369b4798..43b5860a86 100644--- a/apps/server/src/services/llm/tools/attachment_tools.ts+++ b/apps/server/src/services/llm/tools/attachment_tools.ts@@ -5,7 +5,6 @@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({@@ -20,7 +19,19 @@ export const attachmentTools = defineTools({return { error: "Attachment not found" };}- return mappers.mapAttachmentToPojo(attachment);+ return {+ attachmentId: attachment.attachmentId,+ ownerId: attachment.ownerId,+ role: attachment.role,+ mime: attachment.mime,+ title: attachment.title,+ position: attachment.position,+ blobId: attachment.blobId,+ dateModified: attachment.dateModified,+ utcDateModified: attachment.utcDateModified,+ utcDateScheduledForErasureSince: attachment.utcDateScheduledForErasureSince,+ contentLength: attachment.contentLength+ };}}});diff --git a/apps/server/src/services/llm/tools/note_tools.ts b/apps/server/src/services/llm/tools/note_tools.tsindex 0eb4f1fda5..59d85a55ba 100644--- a/apps/server/src/services/llm/tools/note_tools.ts+++ b/apps/server/src/services/llm/tools/note_tools.ts@@ -6,7 +6,6 @@ import { z } from "zod";import type BNote from "../../../becca/entities/bnote.js";import becca from "../../../becca/becca.js";-import mappers from "../../../etapi/mappers.js";import markdownExport from "../../export/markdown.js";import markdownImport from "../../import/markdown.js";import noteService from "../../notes.js";@@ -39,12 +38,35 @@ export function getContentPreview(note: { type: string; blobId?: string; getCont}/**- * Build the full metadata object for a note, matching ETAPI's format plus a- * short content preview. Used by both the `get_note` tool and the system prompt.+ * Build the full metadata object for a note. Used by both the `get_note` tool+ * and the system prompt.*/export function getNoteMeta(note: BNote) {return {- ...mappers.mapNoteToPojo(note),+ noteId: note.noteId,+ isProtected: note.isProtected,+ title: note.title,+ type: note.type,+ mime: note.mime,+ blobId: note.blobId,+ dateCreated: note.dateCreated,+ dateModified: note.dateModified,+ utcDateCreated: note.utcDateCreated,+ utcDateModified: note.utcDateModified,+ parentNoteIds: note.getParentNotes().map((p) => p.noteId),+ childNoteIds: note.getChildNotes().map((ch) => ch.noteId),+ parentBranchIds: note.getParentBranches().map((p) => p.branchId),+ childBranchIds: note.getChildBranches().map((ch) => ch.branchId),+ attributes: note.getAttributes().map((attr) => ({+ attributeId: attr.attributeId,+ noteId: attr.noteId,+ type: attr.type,+ name: attr.name,+ value: attr.value,+ position: attr.position,+ isInheritable: attr.isInheritable,+ utcDateModified: attr.utcDateModified+ })),contentPreview: getContentPreview(note)};}@@ -295,7 +317,19 @@ export const noteTools = defineTools({return { error: "Note not found" };}- return note.getAttachments().map((att) => mappers.mapAttachmentToPojo(att));+ return note.getAttachments().map((att) => ({+ attachmentId: att.attachmentId,+ ownerId: att.ownerId,+ role: att.role,+ mime: att.mime,+ title: att.title,+ position: att.position,+ blobId: att.blobId,+ dateModified: att.dateModified,+ utcDateModified: att.utcDateModified,+ utcDateScheduledForErasureSince: att.utcDateScheduledForErasureSince,+ contentLength: att.contentLength+ }));}}});