Skip to content

Build your personal knowledge base with Trilium Notes

feat(llm_chat): merge web search and note access into a Tools menu

Elian Doran58262d76c566
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 0c68136dc2..66cd7ea102 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2720,7 +2720,10 @@
"attachment_model_cannot_read_image": "{{- model}} can't read images.",
"attachment_model_cannot_read_file": "{{- model}} can't read PDFs.",
"attachment_refused": "\"{{name}}\" wasn't attached. {{- reason}}",
- "remove_unreadable_attachments": "Remove the attachments {{- model}} can't read"
+ "remove_unreadable_attachments": "Remove the attachments {{- model}} can't read",
+ "tools": "Tools",
+ "note_tools_description": "Search, read and edit your notes",
+ "web_search_description": "Search the internet for current information"
},
"sidebar_chat": {
"title": "AI Chat",
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.css b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.css
index 481b3dc648..d343489522 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.css
+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.css
@@ -235,10 +235,6 @@
flex-shrink: 0;
}
-.llm-chat-capability-unavailable {
- display: inline-flex;
-}
-
.llm-chat-input-form .llm-chat-capability.icon-action {
--icon-button-size: 24px;
--icon-button-icon-ratio: 0.65;
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx
index ebb9c1d9b3..c9bcd58bfb 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx
+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx
@@ -23,6 +23,7 @@ import { computeContextUsage } from "./chat_context_usage.js";
import { insertNewBlock as insertNewBlockCommand, isSelectionInCodeBlock, outdentListItemAtStart } from "./chat_input_editing.js";
import { editorHtmlToMarkdown } from "./chat_input_markdown.js";
import { shortModelName } from "./model_name.js";
+import ChatToolsDropdown from "./ChatToolsDropdown.js";
import ReasoningEffortDropdown from "./ReasoningEffortDropdown.js";
import { SafeImage } from "./retry_image.js";
import { getAttachmentLightbox, getUnreadableReasons, useChatAttachments } from "./useChatAttachments.js";
@@ -460,24 +461,15 @@ export default function ChatInputBar({
/>
) : null}
</div>
- {/* What the model can reach this turn. Lifted out of the model dropdown so
- their state reads at a glance and flipping one is a single click — the
- system prompt currently has to tell the user where these live, which is
- a fair sign a menu was the wrong home. Grouped so they stay together. */}
+ {/* What the model can reach this turn (the Tools menu) and how it answers
+ (extended thinking), grouped so they stay together. */}
<div className="llm-chat-capabilities">
- <CapabilityToggle
- icon="bx bx-globe"
- label={t("llm_chat.web_search")}
- active={chat.enableWebSearch && !webSearchUnavailable}
- onToggle={handleWebSearchToggle}
- disabled={chat.isStreaming}
- unavailableReason={webSearchUnavailable ? t("llm_chat.web_search_unavailable_gemini") : undefined}
- />
- <CapabilityToggle
- icon="bx bx-note"
- label={t("llm_chat.note_tools")}
- active={chat.enableNoteTools}
- onToggle={handleNoteToolsToggle}
+ <ChatToolsDropdown
+ enableNoteTools={chat.enableNoteTools}
+ enableWebSearch={chat.enableWebSearch}
+ onNoteToolsChange={handleNoteToolsToggle}
+ onWebSearchChange={handleWebSearchToggle}
+ webSearchUnavailableReason={webSearchUnavailable ? t("llm_chat.web_search_unavailable_gemini") : undefined}
disabled={chat.isStreaming}
/>
{!currentModel?.reasoningEfforts?.length && (
@@ -616,31 +608,22 @@ function AttachmentChipPreview({ att }: { att: AttachmentBlock }) {
* One of the model's per-conversation capability switches, as an icon toggle whose state
* reads without opening anything. The label is the tooltip.
*/
-function CapabilityToggle({ icon, label, active, onToggle, disabled, unavailableReason }: {
+function CapabilityToggle({ icon, label, active, onToggle, disabled }: {
icon: string;
label: string;
active: boolean;
onToggle: (newValue: boolean) => void;
disabled?: boolean;
- /** Why this capability can't be used with the current model, if it can't. */
- unavailableReason?: string;
}) {
- const button = (
+ return (
<ActionButton
icon={icon}
- text={unavailableReason ?? label}
+ text={label}
active={active}
- disabled={disabled || !!unavailableReason}
+ disabled={disabled}
onClick={() => onToggle(!active)}
className="llm-chat-capability"
/>
);
-
- // A disabled <button> receives no mouse events, so its own tooltip never fires — which is
- // why the dropdown this replaced had to put the explanation on a separate info icon. The
- // wrapper carries it instead, and only exists when there is something to explain.
- return unavailableReason
- ? <span className="llm-chat-capability-unavailable" title={unavailableReason}>{button}</span>
- : button;
}
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.css b/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.css
new file mode 100644
index 0000000000..bd75f31b59
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.css
@@ -0,0 +1,6 @@
+.tn-dropdown-portal.llm-chat-tools {
+ .dropdown-item .description {
+ max-width: 18rem;
+ white-space: normal;
+ }
+}
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.spec.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.spec.tsx
new file mode 100644
index 0000000000..7179aa5a51
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.spec.tsx
@@ -0,0 +1,93 @@
+import { type ComponentChildren, render } from "preact";
+import { act } from "preact/test-utils";
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+vi.mock("../../../services/i18n.js", () => ({ t: (key: string) => key }));
+
+// Renders the toggle's class and tooltip, and the menu, without the popup machinery.
+vi.mock("../../react/Dropdown.js", () => ({
+ default: ({ title, buttonClassName, children }: {
+ title?: string; buttonClassName?: string; children: ComponentChildren;
+ }) => (
+ <div className="dropdown-stub">
+ <button className={buttonClassName} title={title} />
+ <div className="menu">{children}</div>
+ </div>
+ )
+}));
+
+import ChatToolsDropdown from "./ChatToolsDropdown.js";
+
+let host: HTMLElement | undefined;
+
+afterEach(() => {
+ if (host) {
+ render(null, host);
+ host.remove();
+ host = undefined;
+ }
+});
+
+function renderMenu(props: Partial<Parameters<typeof ChatToolsDropdown>[0]> = {}) {
+ const onNoteToolsChange = vi.fn();
+ const onWebSearchChange = vi.fn();
+ host = document.body.appendChild(document.createElement("div"));
+ const target = host;
+ act(() => render(
+ <ChatToolsDropdown
+ enableNoteTools={false}
+ enableWebSearch={false}
+ onNoteToolsChange={onNoteToolsChange}
+ onWebSearchChange={onWebSearchChange}
+ {...props}
+ />, target));
+
+ const rows = [ ...target.querySelectorAll<HTMLElement>(".menu .dropdown-item") ];
+ return {
+ toggle: target.querySelector<HTMLButtonElement>(".dropdown-stub > button"),
+ noteRow: rows.find((row) => row.textContent?.includes("llm_chat.note_tools")),
+ webRow: rows.find((row) => row.textContent?.includes("llm_chat.web_search")),
+ onNoteToolsChange,
+ onWebSearchChange
+ };
+}
+
+const isOn = (row: HTMLElement | undefined) => row?.querySelector<HTMLInputElement>("input[type='checkbox']")?.checked;
+
+describe("ChatToolsDropdown", () => {
+ it("shows a switch per tool group, and marks the toggle active while any is on", () => {
+ const off = renderMenu();
+ expect(off.toggle?.title).toBe("llm_chat.tools");
+ expect(off.toggle?.classList.contains("active")).toBe(false);
+ expect(isOn(off.noteRow)).toBe(false);
+ expect(isOn(off.webRow)).toBe(false);
+
+ const on = renderMenu({ enableWebSearch: true });
+ expect(on.toggle?.classList.contains("active")).toBe(true);
+ expect(isOn(on.noteRow)).toBe(false);
+ expect(isOn(on.webRow)).toBe(true);
+ });
+
+ it("flips the group whose row is pressed", async () => {
+ const { noteRow, webRow, onNoteToolsChange, onWebSearchChange } = renderMenu({ enableNoteTools: true });
+ expect(noteRow).toBeDefined();
+ expect(webRow).toBeDefined();
+
+ await act(async () => noteRow?.click());
+ expect(onNoteToolsChange).toHaveBeenCalledExactlyOnceWith(false);
+ await act(async () => webRow?.click());
+ expect(onWebSearchChange).toHaveBeenCalledExactlyOnceWith(true);
+ });
+
+ it("shows web search off and disabled, with the reason, when the model cannot combine it", async () => {
+ const { toggle, webRow, onWebSearchChange } = renderMenu({ enableWebSearch: true, webSearchUnavailableReason: "Not on Gemini" });
+
+ expect(toggle?.classList.contains("active")).toBe(false);
+ expect(isOn(webRow)).toBe(false);
+ expect(webRow?.classList.contains("disabled")).toBe(true);
+ expect(webRow?.querySelector(".description")?.textContent).toBe("Not on Gemini");
+
+ await act(async () => webRow?.click());
+ expect(onWebSearchChange).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.tsx
new file mode 100644
index 0000000000..3a9a39ba7a
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.tsx
@@ -0,0 +1,54 @@
+import "./ChatToolsDropdown.css";
+
+import clsx from "clsx";
+
+import { t } from "../../../services/i18n.js";
+import Dropdown from "../../react/Dropdown.js";
+import { FormListToggleableItem } from "../../react/FormList.js";
+
+/**
+ * The Tools menu of the chat input bar: one switch per group of tools the model can reach this
+ * turn. Each row stops its click, so the menu stays open while several are flipped.
+ */
+export default function ChatToolsDropdown({ enableNoteTools, enableWebSearch, onNoteToolsChange, onWebSearchChange, webSearchUnavailableReason, disabled }: {
+ enableNoteTools: boolean;
+ enableWebSearch: boolean;
+ onNoteToolsChange: (newValue: boolean) => void;
+ onWebSearchChange: (newValue: boolean) => void;
+ /** Why web search can't be used with the current model and settings, if it can't. */
+ webSearchUnavailableReason?: string;
+ disabled?: boolean;
+}) {
+ const webSearchActive = enableWebSearch && !webSearchUnavailableReason;
+ const anyActive = enableNoteTools || webSearchActive;
+
+ return (
+ <Dropdown
+ buttonClassName={clsx("bx bx-shield-quarter llm-chat-capability llm-chat-tools-button", anyActive && "active")}
+ className="llm-chat-tools"
+ title={t("llm_chat.tools")}
+ titlePosition="top"
+ placement="top-start"
+ iconAction
+ hideToggleArrow
+ noSelectButtonStyle
+ disabled={disabled}
+ >
+ <FormListToggleableItem
+ icon="bx bx-note"
+ title={t("llm_chat.note_tools")}
+ description={t("llm_chat.note_tools_description")}
+ currentValue={enableNoteTools}
+ onChange={onNoteToolsChange}
+ />
+ <FormListToggleableItem
+ icon="bx bx-globe"
+ title={t("llm_chat.web_search")}
+ description={webSearchUnavailableReason ?? t("llm_chat.web_search_description")}
+ currentValue={webSearchActive}
+ onChange={onWebSearchChange}
+ disabled={!!webSearchUnavailableReason}
+ />
+ </Dropdown>
+ );
+}
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI.html
index 11ab371b80..9cff809212 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI.html
@@ -112,8 +112,8 @@
<h3>Web search</h3>
<p>The AI can optionally search the web to find more information about a
specific topic.&nbsp;</p>
-<p>This feature is on by default but it can easily be disabled by clicking
- on the model selector at the bottom of the chat and unchecking <em>Web search</em>.</p>
+<p>This feature is on by default. To turn it off, press the <span class="tn-icon bx bx-shield-quarter"></span> <em>Tools</em> button
+ next to the model selector at the bottom of the chat and switch off <em>Web search</em>.</p>
<aside
class="admonition note">
<p>Currently only the search native to the LLM provider is used. External
@@ -128,7 +128,8 @@ class="admonition note">
<p>How much a model thinks is set per chat, in one of two ways depending
on the model:</p>
<ul>
- <li>Most models have an <em>Extended thinking</em> switch, next to <em>Web search</em>.</li>
+ <li>Most models have an <span class="tn-icon bx bx-brain"></span> <em>Extended thinking</em> button,
+ next to the <span class="tn-icon bx bx-shield-quarter"></span> <em>Tools</em> button.</li>
<li>Models that offer several levels of reasoning (DeepSeek V4, OpenAI Codex,
Antigravity) have a <span class="tn-icon bx bx-brain"></span> reasoning effort
dropdown next to the model selector instead. <em>None</em>, where offered,
@@ -143,8 +144,10 @@ class="admonition note">
<h3>Note access (tools)</h3>
<p>Tools allow the agentic AI to understand and operate on notes directly
within your Trilium instance.</p>
-<p>This feature is on by default but it can easily be disabled by clicking
- on the model selector at the bottom of the chat and unchecking <em>Note access</em>.</p>
+<p>This feature is on by default. To turn it off, press the <span class="tn-icon bx bx-shield-quarter"></span> <em>Tools</em> button
+ next to the model selector at the bottom of the chat and switch off <em>Note access</em>.
+ The <em>Tools</em> button is highlighted while note access or web search
+ is on.</p>
<p>Here are a few tools that Trilium provides for the LLM:</p>
<ul>
<li>At note level:
@@ -238,7 +241,8 @@ class="admonition note">
</aside>
<aside class="admonition note">
<p>Gemini has a special case in which <em>Note access</em> and <em>Web search</em> can't
- be both enabled at the same time.</p>
+ be both enabled at the same time. While note access is on, the <em>Web search</em> switch
+ in the <em>Tools</em> menu is disabled and says why.</p>
</aside>
<h3>Attachments</h3>
<p>Since Trilium v0.140.0,&nbsp;<a class="reference-link" href="#root/_help_0vhv7lsOLy82">Attachments</a>&nbsp;allow
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI/Privacy.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI/Privacy.html
index 75a796f379..b8dbedb8d2 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI/Privacy.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI/Privacy.html
@@ -112,11 +112,11 @@
<ul>
<li><strong>Which provider</strong>: the single decision that determines whether
anything leaves your machine at all.</li>
- <li><strong>Note access</strong>: turn tools off from the model selector at
- the bottom of the chat, and the model can read nothing beyond what you
+ <li><strong>Note access</strong>: turn it off in the <span class="tn-icon bx bx-shield-quarter"></span> <em>Tools</em> menu
+ at the bottom of the chat, and the model can read nothing beyond what you
type.</li>
<li><strong>The current note:</strong> the file icon in the sidebar chat.</li>
- <li><strong>Web search:</strong> also in the model selector.</li>
+ <li><strong>Web search:</strong> also in the <em>Tools</em> menu.</li>
<li><strong>The editor assistant</strong>: it has no per-run toggles. What
you control is whether you run it, what you select before you do and which
model answers.</li>
diff --git a/docs/User Guide/User Guide/AI.md b/docs/User Guide/User Guide/AI.md
index a843b0aea3..ed6a6674d2 100644
--- a/docs/User Guide/User Guide/AI.md
+++ b/docs/User Guide/User Guide/AI.md
@@ -85,7 +85,7 @@ Pricing information is displayed for known models. The pricing information (pric
The AI can optionally search the web to find more information about a specific topic. 
-This feature is on by default but it can easily be disabled by clicking on the model selector at the bottom of the chat and unchecking _Web search_.
+This feature is on by default. To turn it off, press the <span class="tn-icon bx bx-shield-quarter"></span> _Tools_ button next to the model selector at the bottom of the chat and switch off _Web search_.
> [!NOTE]
> Currently only the search native to the LLM provider is used. External search providers (Brave Search, Tavily, Exa and SearXNG) can already be added in the _Search Providers_ section of the AI settings, but the chat does not use them yet.
@@ -96,7 +96,7 @@ Some models reason before they answer. While the model is thinking, its reasonin
How much a model thinks is set per chat, in one of two ways depending on the model:
-* Most models have an _Extended thinking_ switch, next to _Web search_.
+* Most models have an <span class="tn-icon bx bx-brain"></span> _Extended thinking_ button, next to the <span class="tn-icon bx bx-shield-quarter"></span> _Tools_ button.
* Models that offer several levels of reasoning (DeepSeek V4, OpenAI Codex, Antigravity) have a <span class="tn-icon bx bx-brain"></span> reasoning effort dropdown next to the model selector instead. _None_, where offered, turns thinking off; higher levels give better answers to hard questions, but take longer and cost more.
> [!NOTE]
@@ -106,7 +106,7 @@ How much a model thinks is set per chat, in one of two ways depending on the mod
Tools allow the agentic AI to understand and operate on notes directly within your Trilium instance.
-This feature is on by default but it can easily be disabled by clicking on the model selector at the bottom of the chat and unchecking _Note access_.
+This feature is on by default. To turn it off, press the <span class="tn-icon bx bx-shield-quarter"></span> _Tools_ button next to the model selector at the bottom of the chat and switch off _Note access_. The _Tools_ button is highlighted while note access or web search is on.
Here are a few tools that Trilium provides for the LLM:
@@ -142,7 +142,7 @@ When the reply stops moving for a couple of seconds while the AI is still at wor
> Currently there is **no permission management** implemented for note tools, meaning that the LLM could potentially remove existing notes or clutter the tree with notes. Generally most actions are easily reversible (deleting the notes, restoring deleted notes, reverting modifications to a note), but there are some that are harder to revert (e.g. setting an attribute because there is no attribute history).
> [!NOTE]
-> Gemini has a special case in which _Note access_ and _Web search_ can't be both enabled at the same time.
+> Gemini has a special case in which _Note access_ and _Web search_ can't be both enabled at the same time. While note access is on, the _Web search_ switch in the _Tools_ menu is disabled and says why.
### Attachments
diff --git a/docs/User Guide/User Guide/AI/Privacy.md b/docs/User Guide/User Guide/AI/Privacy.md
index 0022c215e9..f88249982e 100644
--- a/docs/User Guide/User Guide/AI/Privacy.md
+++ b/docs/User Guide/User Guide/AI/Privacy.md
@@ -53,9 +53,9 @@ The same applies to the <a class="reference-link" href="../Note%20Types/Text/In
## What you control
* **Which provider**: the single decision that determines whether anything leaves your machine at all.
-* **Note access**: turn tools off from the model selector at the bottom of the chat, and the model can read nothing beyond what you type.
+* **Note access**: turn it off in the <span class="tn-icon bx bx-shield-quarter"></span> _Tools_ menu at the bottom of the chat, and the model can read nothing beyond what you type.
* **The current note:** the file icon in the sidebar chat.
-* **Web search:** also in the model selector.
+* **Web search:** also in the _Tools_ menu.
* **The editor assistant**: it has no per-run toggles. What you control is whether you run it, what you select before you do and which model answers.
With note access and note context both off, the provider receives only the words you typed.
diff --git a/packages/trilium-core/src/services/llm/system_prompt.spec.ts b/packages/trilium-core/src/services/llm/system_prompt.spec.ts
index 6e0d680927..4a0d871e4c 100644
--- a/packages/trilium-core/src/services/llm/system_prompt.spec.ts
+++ b/packages/trilium-core/src/services/llm/system_prompt.spec.ts
@@ -44,11 +44,12 @@ describe("buildSystemPrompt", () => {
expect(prompt).toContain("do not have access to web search");
});
- it("points the user at the toggle that turns a missing capability on", () => {
+ it("points the user at the switch in the Tools menu that turns a missing capability on", () => {
const prompt = buildSystemPrompt([], {}) ?? "";
- // The toggles' own icons, as ChatInputBar draws them, for the model to show the user.
- expect(prompt).toContain(`<span class="tn-icon bx bx-globe"></span> "Web search" toggle`);
- expect(prompt).toContain(`<span class="tn-icon bx bx-note"></span> "Note access" toggle`);
+ // The menu's own icon, as ChatToolsDropdown draws it, for the model to show the user.
+ const menu = `<span class="tn-icon bx bx-shield-quarter"></span> "Tools" menu`;
+ expect(prompt).toContain(`turn it on with the "Web search" switch in the ${menu}`);
+ expect(prompt).toContain(`turn it on with the "Note access" switch in the ${menu}`);
expect(prompt).not.toContain("model name dropdown");
});
diff --git a/packages/trilium-core/src/services/llm/system_prompt.ts b/packages/trilium-core/src/services/llm/system_prompt.ts
index 76937628c7..9c8a208008 100644
--- a/packages/trilium-core/src/services/llm/system_prompt.ts
+++ b/packages/trilium-core/src/services/llm/system_prompt.ts
@@ -139,12 +139,12 @@ function buildTaskListHint(): string {
}
/**
- * Where the user turns a capability on: the icon toggles beside the model
- * selector in `ChatInputBar`. The icon classes must match the toggles' own.
+ * Where the user turns a capability on: a switch in the Tools menu beside the model selector in
+ * `ChatInputBar`. The icon class must match the toggle button of `ChatToolsDropdown`.
*/
-const NOTE_ACCESS_TOGGLE = describeToggle("bx bx-note", "Note access");
-const WEB_SEARCH_TOGGLE = describeToggle("bx bx-globe", "Web search");
+const NOTE_ACCESS_TOGGLE = describeToggle("Note access");
+const WEB_SEARCH_TOGGLE = describeToggle("Web search");
-function describeToggle(iconClass: string, label: string): string {
- return `the <span class="tn-icon ${iconClass}"></span> "${label}" toggle next to the model selector, below the message box (include the icon exactly as written, so the user sees the same icon)`;
+function describeToggle(label: string): string {
+ return `the "${label}" switch in the <span class="tn-icon bx bx-shield-quarter"></span> "Tools" menu next to the model selector, below the message box (include the icon exactly as written, so the user sees the same icon)`;
}