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): let Antigravity search the web when the chat allows it
Elian Doran546942a85fe5
diff --git a/apps/server/src/services/llm/providers/acp_agent.ts b/apps/server/src/services/llm/providers/acp_agent.tsindex 6311570348..f6199c3da6 100644--- a/apps/server/src/services/llm/providers/acp_agent.ts+++ b/apps/server/src/services/llm/providers/acp_agent.ts@@ -185,8 +185,10 @@ export abstract class AcpAgentProvider implements LlmProvider {/*** Permission policy. The default denies every request; a subclass whose* agent asks before running Trilium's own note tools approves those.+ * `config` is the chat turn's configuration, and absent outside a chat+ * turn (the model probe, the title).*/- protected decidePermission(request: AcpPermissionRequest): AcpPermissionOutcome {+ protected decidePermission(request: AcpPermissionRequest, _config?: LlmProviderConfig): AcpPermissionOutcome {return denyPermission(request, this.logLabel);}@@ -338,7 +340,7 @@ export abstract class AcpAgentProvider implements LlmProvider {let assistantText = "";try {- client = await this.startClient(collector.onNotification);+ client = await this.startClient(collector.onNotification, config);const mcpServers = noteToolsEnabled ? await buildMcpServersConfig() : [];@@ -520,8 +522,11 @@ export abstract class AcpAgentProvider implements LlmProvider {}}- /** Spawn the agent and run the ACP initialize handshake. */- protected async startClient(onNotification: (method: string, params: unknown) => void): Promise<AcpClient> {+ /**+ * Spawn the agent and run the ACP initialize handshake. `config` is the chat+ * turn's configuration, which the permission policy reads.+ */+ protected async startClient(onNotification: (method: string, params: unknown) => void, config?: LlmProviderConfig): Promise<AcpClient> {const launch = await this.launchSpec();const client = AcpClient.start(launch.binary, {cwd: this.agentCwd(),@@ -529,7 +534,7 @@ export abstract class AcpAgentProvider implements LlmProvider {args: launch.args,env: launch.env,onNotification,- onAgentRequest: (method, params) => this.handleAgentRequest(method, params)+ onAgentRequest: (method, params) => this.handleAgentRequest(method, params, config)});try {await client.request(@@ -554,9 +559,9 @@ export abstract class AcpAgentProvider implements LlmProvider {* Handle agent→client requests. Only the permission callback is supported;* everything else (fs, terminal) was never advertised and is refused.*/- private handleAgentRequest(method: string, params: unknown): unknown {+ private handleAgentRequest(method: string, params: unknown, config: LlmProviderConfig | undefined): unknown {if (method === "session/request_permission") {- return this.decidePermission(params as AcpPermissionRequest);+ return this.decidePermission(params as AcpPermissionRequest, config);}throw new Error(`Trilium does not support "${method}".`);}diff --git a/apps/server/src/services/llm/providers/antigravity_agent.spec.ts b/apps/server/src/services/llm/providers/antigravity_agent.spec.tsindex 63d9c3e028..1c3e05fbba 100644--- a/apps/server/src/services/llm/providers/antigravity_agent.spec.ts+++ b/apps/server/src/services/llm/providers/antigravity_agent.spec.ts@@ -164,6 +164,26 @@ describe("decideAntigravityPermission", () => {options: [PERMISSION_OPTIONS[0], PERMISSION_OPTIONS[2]]}, "test")).toEqual(denied);});++ // Shape captured from agy_acp_server 1.2.1.+ const SEARCH_WEB = { toolCallId: "7bba", kind: "search", status: "pending", title: "Run search_web?", rawInput: { query: "weather Sibiu today" } };++ it("approves a web search once only in a chat with web search on", () => {+ const allowed = { outcome: { outcome: "selected", optionId: "allow" } };+ const denied = { outcome: { outcome: "selected", optionId: "deny" } };+ expect(decideAntigravityPermission({ toolCall: SEARCH_WEB, options: PERMISSION_OPTIONS }, "test", { webSearch: true })).toEqual(allowed);+ expect(decideAntigravityPermission({ toolCall: SEARCH_WEB, options: PERMISSION_OPTIONS }, "test", { webSearch: false })).toEqual(denied);+ expect(decideAntigravityPermission({ toolCall: SEARCH_WEB, options: PERMISSION_OPTIONS }, "test")).toEqual(denied);+ // A shell command the model titled like a search, and another search-kind tool.+ expect(decideAntigravityPermission({+ toolCall: { kind: "execute", title: "Run search_web?", rawInput: { CommandLine: "Run search_web?" } },+ options: PERMISSION_OPTIONS+ }, "test", { webSearch: true })).toEqual(denied);+ expect(decideAntigravityPermission({+ toolCall: { ...SEARCH_WEB, title: "Run read_url_content?" },+ options: PERMISSION_OPTIONS+ }, "test", { webSearch: true })).toEqual(denied);+ });});describe("AntigravityAgentProvider", () => {@@ -204,6 +224,18 @@ describe("AntigravityAgentProvider", () => {.toEqual({ decision: "allow" });});+ it("lets the agent search the web only when the chat allows it", async () => {+ const request = { toolCall: { kind: "search", title: "Run search_web?", rawInput: { query: "x" } }, options: PERMISSION_OPTIONS };++ await collect(new AntigravityAgentProvider().chatChunks([{ role: "user", content: "hi" }], { enableWebSearch: true }));+ expect(FakeAcpClient.current?.onAgentRequest?.("session/request_permission", request))+ .toEqual({ outcome: { outcome: "selected", optionId: "allow" } });++ await collect(new AntigravityAgentProvider().chatChunks([{ role: "user", content: "hi" }], {}));+ expect(FakeAcpClient.current?.onAgentRequest?.("session/request_permission", request))+ .toEqual({ outcome: { outcome: "selected", optionId: "deny" } });+ });+it("signs in during the model probe, but reports a missing sign-in in the chat instead", async () => {FakeAcpClient.signedIn = false;const chunks = await collect(new AntigravityAgentProvider().chatChunks([{ role: "user", content: "hi" }], {}));diff --git a/apps/server/src/services/llm/providers/antigravity_agent.ts b/apps/server/src/services/llm/providers/antigravity_agent.tsindex c4bc26a07c..5737b48475 100644--- a/apps/server/src/services/llm/providers/antigravity_agent.ts+++ b/apps/server/src/services/llm/providers/antigravity_agent.ts@@ -133,8 +133,8 @@ export class AntigravityAgentProvider extends AcpAgentProvider {return buildAntigravityModelList(remote);}- protected decidePermission(request: AcpPermissionRequest): AcpPermissionOutcome {- return decideAntigravityPermission(request, this.logLabel);+ protected decidePermission(request: AcpPermissionRequest, config?: LlmProviderConfig): AcpPermissionOutcome {+ return decideAntigravityPermission(request, this.logLabel, { webSearch: config?.enableWebSearch === true });}/** Answer the file-access hook for one tool call, logging each denial. */@@ -197,21 +197,32 @@ export class AntigravityAgentProvider extends AcpAgentProvider {}/**- * Approve Trilium's own note tools and deny everything else.+ * Approve Trilium's own note tools, and the web search in a chat that allows+ * it; deny everything else.** The server asks before every MCP tool call, including those of the note-tools* server Trilium hands it. It marks those requests in `toolCall._meta` — the* MCP server's name and `is_mcp_tool_call` — which the server sets itself, so* the model cannot forge them the way it controls a tool call's title and- * arguments. Built-in tools (shell, file edits, URL fetch, web search) carry no- * such marker and are denied.+ * arguments. Other built-in tools (shell, file edits, URL fetch) carry no such+ * marker and are denied.+ *+ * The web search is recognized by its kind and title together. The server+ * titles it from a template, and the one tool whose title the model writes, the+ * shell, has the kind `execute`.*/-export function decideAntigravityPermission(request: AcpPermissionRequest, logLabel: string): AcpPermissionOutcome {- const meta = request.toolCall?._meta;+export function decideAntigravityPermission(+ request: AcpPermissionRequest,+ logLabel: string,+ { webSearch = false }: { webSearch?: boolean } = {}+): AcpPermissionOutcome {+ const toolCall = request.toolCall;+ const meta = toolCall?._meta;const mcp = meta?.mcp as { server?: unknown } | undefined;const isNoteTool = meta?.is_mcp_tool_call === true && mcp?.server === NOTE_TOOLS_MCP_SERVER_NAME;+ const isWebSearch = toolCall?.kind === "search" && toolCall.title === "Run search_web?";const allowOnce = request.options?.find(o => o.kind === "allow_once");- if (isNoteTool && allowOnce) {+ if ((isNoteTool || (webSearch && isWebSearch)) && allowOnce) {return { outcome: { outcome: "selected", optionId: allowOnce.optionId } };}return denyPermission(request, logLabel);