From 027280954a5fc25445bd07f8bbb48428d522a52e Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 4 Apr 2026 09:59:00 +0300 Subject: [PATCH] chore(llm): remove some lesser used fields from LLM response --- .../services/llm/tools/attachment_tools.ts | 4 --- .../src/services/llm/tools/attribute_tools.ts | 5 ++-- apps/server/src/services/llm/tools/helpers.ts | 28 ++++++++----------- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/apps/server/src/services/llm/tools/attachment_tools.ts b/apps/server/src/services/llm/tools/attachment_tools.ts index 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.ts index 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.ts index 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)