From a482aaaad64d9570cf0a5ab37687c5adef3df032 Mon Sep 17 00:00:00 2001 From: sepehr Date: Thu, 30 Apr 2026 19:10:20 +0200 Subject: [PATCH] fix: AI assistant in note-input still searches other notes when scoped to "this note" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When chatScope is "this note", the AI had access to note_search and note_read tools which let it pull content from any note. Now these tools are excluded via a webOnly flag in buildToolsForChat — only web_search/web_scrape remain if the user toggled web search. Co-Authored-By: Claude Opus 4.7 --- memento-note/app/api/chat/route.ts | 6 +++++- memento-note/lib/ai/tools/registry.ts | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/memento-note/app/api/chat/route.ts b/memento-note/app/api/chat/route.ts index bc6afdc..00dd784 100644 --- a/memento-note/app/api/chat/route.ts +++ b/memento-note/app/api/chat/route.ts @@ -419,7 +419,11 @@ Never switch to another language. Even if the user writes in a different languag webSearch: !!webSearch, config, } - const chatTools = toolRegistry.buildToolsForChat(chatToolContext) + // When scoped to "this note", only provide web tools — no note_search/note_read + // to prevent the AI from pulling information from other notes + const chatTools = noteContext + ? toolRegistry.buildToolsForChat({ ...chatToolContext, webOnly: true }) + : toolRegistry.buildToolsForChat(chatToolContext) // 8. Save user message to DB before streaming if (isNewMessage && lastIncoming) { diff --git a/memento-note/lib/ai/tools/registry.ts b/memento-note/lib/ai/tools/registry.ts index 262b621..e1eb75a 100644 --- a/memento-note/lib/ai/tools/registry.ts +++ b/memento-note/lib/ai/tools/registry.ts @@ -49,9 +49,10 @@ class ToolRegistry { /** * Build tools for the chat endpoint. * Includes internal tools (note_search, note_read) and web tools when configured. + * When webOnly is true, only web tools are included (no note access). */ - buildToolsForChat(ctx: ToolContext): Record { - const toolNames: string[] = ['note_search', 'note_read'] + buildToolsForChat(ctx: ToolContext & { webOnly?: boolean }): Record { + const toolNames: string[] = ctx.webOnly ? [] : ['note_search', 'note_read'] // Add web tools only when user toggled web search AND config is present if (ctx.webSearch) {