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
feat(llm): add button to toggle access to the note
Elian Doran261c95fb063f
diff --git a/apps/client/src/widgets/sidebar/SidebarChat.tsx b/apps/client/src/widgets/sidebar/SidebarChat.tsxindex de96367ca0..c83ba94447 100644--- a/apps/client/src/widgets/sidebar/SidebarChat.tsx+++ b/apps/client/src/widgets/sidebar/SidebarChat.tsx@@ -29,7 +29,7 @@ export default function SidebarChat() {const historyDropdownRef = useRef<BootstrapDropdown | null>(null);// Get the current active note context- const { noteId: activeNoteId } = useActiveNoteContext();+ const { noteId: activeNoteId, note: activeNote } = useActiveNoteContext();// Use shared chat hook with sidebar-specific optionsconst chat = useLlmChat(@@ -304,6 +304,8 @@ export default function SidebarChat() {<ChatInputBarchat={chat}rows={2}+ activeNoteId={activeNoteId ?? undefined}+ activeNoteTitle={activeNote?.title}onSubmit={handleSubmit}onKeyDown={handleKeyDown}/>diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsxindex bd2bc2a990..8fb81a7997 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx@@ -16,6 +16,10 @@ interface ChatInputBarProps {chat: UseLlmChatReturn;/** Number of rows for the textarea (default: 3) */rows?: number;+ /** Current active note ID (for note context toggle) */+ activeNoteId?: string;+ /** Current active note title (for note context toggle) */+ activeNoteTitle?: string;/** Custom submit handler (overrides chat.handleSubmit) */onSubmit?: (e: Event) => void;/** Custom key down handler (overrides chat.handleKeyDown) */@@ -33,6 +37,8 @@ interface ChatInputBarProps {export default function ChatInputBar({chat,rows = 3,+ activeNoteId,+ activeNoteTitle,onSubmit,onKeyDown,onWebSearchChange,@@ -63,6 +69,16 @@ export default function ChatInputBar({onModelChange?.(model);};+ const handleNoteContextToggle = () => {+ if (chat.contextNoteId) {+ chat.setContextNoteId(undefined);+ } else if (activeNoteId) {+ chat.setContextNoteId(activeNoteId);+ }+ };++ const isNoteContextEnabled = !!chat.contextNoteId && !!activeNoteId;+const currentModel = chat.availableModels.find(m => m.id === chat.selectedModel);const currentModels = chat.availableModels.filter(m => !m.isLegacy);const legacyModels = chat.availableModels.filter(m => m.isLegacy);@@ -143,6 +159,20 @@ export default function ChatInputBar({disabled={chat.isStreaming}/></Dropdown>+ {activeNoteId && activeNoteTitle && (+ <button+ type="button"+ className={`llm-chat-note-context ${isNoteContextEnabled ? "active" : ""}`}+ onClick={handleNoteContextToggle}+ disabled={chat.isStreaming}+ title={isNoteContextEnabled+ ? t("llm_chat.note_context_enabled", { title: activeNoteTitle })+ : t("llm_chat.note_context_disabled")}+ >+ <span className={`bx ${isNoteContextEnabled ? "bx-file" : "bx-file-blank"}`} />+ <span className="llm-chat-note-context-title">{activeNoteTitle}</span>+ </button>+ )}{chat.lastPromptTokens > 0 && (<divclassName="llm-chat-context-indicator"diff --git a/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.css b/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.cssindex 3060689c43..c1e63b6402 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.css+++ b/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.css@@ -310,6 +310,47 @@cursor: not-allowed;}+/* Note context toggle */+.llm-chat-note-context {+ display: flex;+ align-items: center;+ gap: 0.375rem;+ padding: 0.25rem 0.5rem;+ border: none;+ border-radius: 4px;+ background: transparent;+ color: var(--muted-text-color);+ font-family: inherit;+ font-size: 0.8rem;+ cursor: pointer;+ max-width: 150px;+ transition: all 0.15s ease;+}++.llm-chat-note-context:hover:not(:disabled) {+ color: var(--main-text-color);+}++.llm-chat-note-context.active {+ color: var(--main-text-color);+}++.llm-chat-note-context:disabled {+ opacity: 0.5;+ cursor: not-allowed;+}++.llm-chat-note-context .bx {+ font-size: 1rem;+ flex-shrink: 0;+}++.llm-chat-note-context-title {+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+}+/* Markdown styles */.llm-chat-markdown {line-height: 1.6;