Skip to content

Build your personal knowledge base with Trilium Notes

feat(llm): let the web search switch alone allow web searches

Elian Doran235fa28f9fdf
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 56e0252d02..c198b5f604 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
@@ -285,8 +285,7 @@
class="tn-icon bx bx-shield-quarter"></span> <em>Tools</em> menu under <em>Permissions</em>:</p>
<ul>
<li><em>Always ask</em>: every call asks, including the ones that only read
- (searching notes, reading a note or an attachment, and reading a web page
- through a search provider).</li>
+ (searching notes, or reading a note or an attachment).</li>
<li><em>Ask before changes</em>: the calls that only read run on their own,
and the ones that change your notes (creating, editing, renaming, moving
or deleting a note, and setting or deleting an attribute) ask.</li>
@@ -298,8 +297,10 @@
<p>A tool allowed for the chat runs without asking in every mode. So does
looking something up in what ships with Trilium (its User Guide, the skill
sheets that teach the AI Trilium's search syntax and note types, and the
- icons), since it reads none of your notes. A model's built-in web search
- runs on the provider's side and never asks.</p>
+ icons), since it reads none of your notes. Searching the web and reading
+ a web page never ask either: turning on web search in the <em>Tools</em> menu
+ is what allows them, whether the model searches on its own or through a
+ search provider.</p>
<aside class="admonition important">
<p>Among the <a class="reference-link" href="#root/_help_eFhxp9laTW1S">Subscription-based providers</a>,
Claude Code, Google Antigravity and OpenAI Codex ask like any other provider.
diff --git a/docs/User Guide/User Guide/AI.md b/docs/User Guide/User Guide/AI.md
index 7f22395119..13da2c1199 100644
--- a/docs/User Guide/User Guide/AI.md
+++ b/docs/User Guide/User Guide/AI.md
@@ -169,13 +169,13 @@ To make a chat ask about a tool again, open the <span class="tn-icon bx bx-shiel
Which calls ask depends on the chat's permission mode, chosen in the <span class="tn-icon bx bx-shield-quarter"></span> _Tools_ menu under _Permissions_:
-* _Always ask_: every call asks, including the ones that only read (searching notes, reading a note or an attachment, and reading a web page through a search provider).
+* _Always ask_: every call asks, including the ones that only read (searching notes, or reading a note or an attachment).
* _Ask before changes_: the calls that only read run on their own, and the ones that change your notes (creating, editing, renaming, moving or deleting a note, and setting or deleting an attribute) ask.
* _Don't ask_: every call runs without asking, changes included.
A new chat starts in the mode you picked last, in any chat, or in _Ask before changes_ until you pick one. Picking _Don't ask_ therefore carries over to the next chat too.
-A tool allowed for the chat runs without asking in every mode. So does looking something up in what ships with Trilium (its User Guide, the skill sheets that teach the AI Trilium's search syntax and note types, and the icons), since it reads none of your notes. A model's built-in web search runs on the provider's side and never asks.
+A tool allowed for the chat runs without asking in every mode. So does looking something up in what ships with Trilium (its User Guide, the skill sheets that teach the AI Trilium's search syntax and note types, and the icons), since it reads none of your notes. Searching the web and reading a web page never ask either: turning on web search in the _Tools_ menu is what allows them, whether the model searches on its own or through a search provider.
> [!IMPORTANT]
> Among the <a class="reference-link" href="AI/Providers/Subscription-based%20providers.md">Subscription-based providers</a>, Claude Code, Google Antigravity and OpenAI Codex ask like any other provider. GitHub Copilot doesn't ask yet: its tool calls run without approval.
diff --git a/packages/trilium-core/src/services/llm/tool_approval.spec.ts b/packages/trilium-core/src/services/llm/tool_approval.spec.ts
index 5cbc01a788..754546447f 100644
--- a/packages/trilium-core/src/services/llm/tool_approval.spec.ts
+++ b/packages/trilium-core/src/services/llm/tool_approval.spec.ts
@@ -168,21 +168,23 @@ describe("ToolApprovals allowed for the chat", () => {
describe("ToolApprovals permission modes", () => {
const kindOf = (toolName: string): ToolKind => {
if (toolName === "load_skill") return "app_content";
+ if (toolName === "read_web_page") return "web";
return toolName === "get_note" ? "read" : "change";
};
- /** Which of a lookup in Trilium's own content, a read and a change ask in `mode`. */
+ /** Which of a lookup in Trilium's own content, a web page read, a read and a change ask in `mode`. */
function asked(mode: "always_ask" | "ask_before_changes" | "dont_ask") {
const approvals = new ToolApprovals(undefined, { mode, kindOf });
const requests: string[] = [];
approvals.onRequest = (request) => requests.push(request.toolName);
void approvals.request({ toolCallId: "c0", toolName: "load_skill", toolInput: {} });
+ void approvals.request({ toolCallId: "c3", toolName: "read_web_page", toolInput: {} });
void approvals.request({ toolCallId: "c1", toolName: "get_note", toolInput: {} });
void approvals.request({ toolCallId: "c2", toolName: "delete_note", toolInput: {} });
approvals.declineAll();
return requests;
}
- it("asks about every call, only about changes, or about none, and never about Trilium's own content", async () => {
+ it("asks about every call, only about changes, or about none, and never about Trilium's own content or the web", async () => {
expect(asked("always_ask")).toEqual([ "get_note", "delete_note" ]);
expect(asked("ask_before_changes")).toEqual([ "delete_note" ]);
expect(asked("dont_ask")).toEqual([]);
@@ -191,9 +193,10 @@ describe("ToolApprovals permission modes", () => {
await expect(approvals.request({ toolCallId: "c1", toolName: "load_skill", toolInput: {} })).resolves.toBe(true);
});
- it("tells Trilium's own content, reads and changes apart, and counts anything unknown as a change", () => {
+ it("tells Trilium's own content, the web, reads and changes apart, and counts anything unknown as a change", () => {
expect([ "load_skill", "search_icons" ].map(toolKind)).toEqual([ "app_content", "app_content" ]);
- expect([ "get_note", "search_notes", "web_search", "read_web_page" ].map(toolKind)).toEqual([ "read", "read", "read", "read" ]);
+ expect([ "get_note", "search_notes" ].map(toolKind)).toEqual([ "read", "read" ]);
+ expect([ "web_search", "read_web_page" ].map(toolKind)).toEqual([ "web", "web" ]);
expect([ "create_note", "delete_attribute", "some_mcp_tool" ].map(toolKind)).toEqual([ "change", "change", "change" ]);
});
});
diff --git a/packages/trilium-core/src/services/llm/tool_approval.ts b/packages/trilium-core/src/services/llm/tool_approval.ts
index d686eab910..5caba97ecd 100644
--- a/packages/trilium-core/src/services/llm/tool_approval.ts
+++ b/packages/trilium-core/src/services/llm/tool_approval.ts
@@ -23,8 +23,8 @@ export interface ToolApprovalPolicy {
/** Absent means `"always_ask"`. */
mode?: LlmPermissionMode;
/**
- * What a tool's calls touch. `"app_content"` never asks, and `"ask_before_changes"` lets
- * `"read"` run too. Absent, every tool counts as a change.
+ * What a tool's calls touch. `"app_content"` and `"web"` never ask, and `"ask_before_changes"`
+ * lets `"read"` run too. Absent, every tool counts as a change.
*/
kindOf?: (toolName: string) => ToolKind;
}
@@ -98,7 +98,8 @@ export class ToolApprovals {
return true;
}
const kind = this.kindOf(toolName);
- return kind === "app_content" || (kind === "read" && this.mode === "ask_before_changes");
+ return kind === "app_content" || kind === "web"
+ || (kind === "read" && this.mode === "ask_before_changes");
}
/** Decline every call that still waits. */
diff --git a/packages/trilium-core/src/services/llm/tools/index.ts b/packages/trilium-core/src/services/llm/tools/index.ts
index 4ed7e40e98..62806715c1 100644
--- a/packages/trilium-core/src/services/llm/tools/index.ts
+++ b/packages/trilium-core/src/services/llm/tools/index.ts
@@ -96,23 +96,23 @@ export function resolveToolRegistries(): Promise<void> {
return inFlightResolve;
}
-/** The web search tools that run in place of a model's built-in search, which only read. */
-const WEB_READ_TOOLS = new Set([ "web_search", "read_web_page" ]);
+/** The web search tools that run in place of a model's built-in search. */
+const WEB_TOOLS = new Set([ "web_search", "read_web_page" ]);
/**
* What a tool's calls touch, which decides when they wait for approval: only what ships with Trilium
- * (`"app_content"`), the user's data without changing it (`"read"`), or the user's data to change
- * it (`"change"`).
+ * (`"app_content"`), the web, which the chat's web search switch already allows (`"web"`), the
+ * user's data without changing it (`"read"`), or the user's data to change it (`"change"`).
*/
-export type ToolKind = "app_content" | "read" | "change";
+export type ToolKind = "app_content" | "web" | "read" | "change";
/**
- * The {@link ToolKind} of a tool, from its registry definition; the web search tools are reads. A tool
- * none of them names, such as one a future integration adds, counts as a change.
+ * The {@link ToolKind} of a tool, from its registry definition or as one of the web search
+ * tools. A tool none of them names, such as one a future integration adds, counts as a change.
*/
export function toolKind(toolName: string): ToolKind {
- if (WEB_READ_TOOLS.has(toolName)) {
- return "read";
+ if (WEB_TOOLS.has(toolName)) {
+ return "web";
}
for (const registry of allToolRegistries) {
for (const [ name, definition ] of registry) {