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
chore(llm): remove some lesser used fields from LLM response
Elian Doran027280954a5f
diff --git a/apps/server/src/services/llm/tools/attachment_tools.ts b/apps/server/src/services/llm/tools/attachment_tools.tsindex cd568e3fbc..0f050f32a7 100644--- a/apps/server/src/services/llm/tools/attachment_tools.ts+++ b/apps/server/src/services/llm/tools/attachment_tools.ts@@ -25,11 +25,7 @@ export const attachmentTools = defineTools({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/attribute_tools.ts b/apps/server/src/services/llm/tools/attribute_tools.tsindex 46446698f5..f17799f7b2 100644--- a/apps/server/src/services/llm/tools/attribute_tools.ts+++ b/apps/server/src/services/llm/tools/attribute_tools.ts@@ -6,6 +6,7 @@ import { z } from "zod";import becca from "../../../becca/becca.js";import attributeService from "../../attributes.js";+import { flag } from "./helpers.js";import { defineTools } from "./tool_registry.js";export const attributeTools = defineTools({@@ -27,7 +28,7 @@ export const attributeTools = defineTools({type: attr.type,name: attr.name,value: attr.value,- isInheritable: attr.isInheritable+ isInheritable: flag(attr.isInheritable)}));}},@@ -49,7 +50,7 @@ export const attributeTools = defineTools({type: attribute.type,name: attribute.name,value: attribute.value,- isInheritable: attribute.isInheritable+ isInheritable: flag(attribute.isInheritable)};}},diff --git a/apps/server/src/services/llm/tools/helpers.ts b/apps/server/src/services/llm/tools/helpers.tsindex 3043ddeee6..381461f4c8 100644--- a/apps/server/src/services/llm/tools/helpers.ts+++ b/apps/server/src/services/llm/tools/helpers.ts@@ -11,6 +11,16 @@ import markdownImport from "../../import/markdown.js";const CONTENT_PREVIEW_MAX_LENGTH = 500;const ATTACHMENT_PREVIEW_MAX_LENGTH = 200;+/**+ * Return `true` if the value is truthy, otherwise `undefined`.+ * Since `undefined` values are omitted from JSON serialization,+ * this effectively includes the field only when true.+ * Usage: `{ isInheritable: flag(attr.isInheritable) }`+ */+export function flag(value: boolean | undefined): true | undefined {+ return value ? true : undefined;+}+/*** Convert note content to a format suitable for LLM consumption.* Text notes are converted from HTML to Markdown to reduce token usage.@@ -139,45 +149,31 @@ export function getNoteMeta(note: BNote, limits: NoteMetaLimits) {const allAttributes = 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+ isInheritable: flag(attr.isInheritable)}));const allAttachments = 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,contentPreview: getAttachmentContentPreview(att)}));return {noteId: note.noteId,- isProtected: note.isProtected,+ isProtected: flag(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),childNotes: truncated(allChildNotes, limits.childNotes),- parentBranchIds: note.getParentBranches().map((p) => p.branchId),- childBranchIds: note.getChildBranches().map((ch) => ch.branchId),attributes: truncated(allAttributes, limits.attributes),contentPreview: getContentPreview(note),attachments: truncated(allAttachments, limits.attachments)