Skip to content

Build your personal knowledge base with Trilium Notes

fix(llm): disable search services the browser version can't reach

Elian Dorane3604ed8c4fd
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 5818b9d257..683a809b30 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -4267,7 +4267,8 @@
"model_providers": "Model Providers",
"add_model_provider": "Add Model Provider",
"no_model_providers_configured": "No model providers configured yet.",
- "provider_no_models": "No models selected, so it isn't offered in the chat."
+ "provider_no_models": "No models selected, so it isn't offered in the chat.",
+ "search_provider_unavailable_standalone": "Unavailable in the browser version: this service refuses requests made from a web page, so it can only be used from the desktop or server version."
},
"common": {
"save": "Save",
diff --git a/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.tsx b/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.tsx
index aba668cac8..78c1408309 100644
--- a/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.tsx
+++ b/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.tsx
@@ -72,6 +72,12 @@ export interface ProviderType {
* that silently omits it leaves them hunting.
*/
needsHostProcess?: boolean;
+ /**
+ * The service's API refuses the CORS preflight of a request made from a web page, so the
+ * standalone build, which calls it with the page's own `fetch`, cannot reach it. Shown disabled
+ * there, as {@link needsHostProcess} is.
+ */
+ refusesBrowserRequests?: boolean;
/**
* How the provider authenticates: a key it requires (vendor APIs), one it may
* take (self-hosted endpoints that sit behind a proxy or gateway), or none at
@@ -164,11 +170,11 @@ export const PROVIDER_TYPES: ProviderType[] = [
/** Web search services, configured in the same `llmProviders` option with `kind: "search"`. */
export const SEARCH_PROVIDER_TYPES: ProviderType[] = [
- { id: "brave", name: "Brave Search", group: "search-cloud", defaultBaseUrl: "https://api.search.brave.com/res/v1", iconUrl: PROVIDER_ICONS.brave },
+ { id: "brave", name: "Brave Search", group: "search-cloud", defaultBaseUrl: "https://api.search.brave.com/res/v1", iconUrl: PROVIDER_ICONS.brave, refusesBrowserRequests: true },
{ id: "tavily", name: "Tavily", group: "search-cloud", defaultBaseUrl: "https://api.tavily.com", iconUrl: PROVIDER_ICONS.tavily },
- { id: "exa", name: "Exa", group: "search-cloud", defaultBaseUrl: "https://api.exa.ai", iconUrl: PROVIDER_ICONS.exa },
+ { id: "exa", name: "Exa", group: "search-cloud", defaultBaseUrl: "https://api.exa.ai", iconUrl: PROVIDER_ICONS.exa, refusesBrowserRequests: true },
{ id: "serper", name: "Serper", group: "search-cloud", defaultBaseUrl: "https://google.serper.dev", iconUrl: PROVIDER_ICONS.serper },
- { id: "perplexity", name: "Perplexity", group: "search-cloud", defaultBaseUrl: "https://api.perplexity.ai", iconUrl: PROVIDER_ICONS.perplexity },
+ { id: "perplexity", name: "Perplexity", group: "search-cloud", defaultBaseUrl: "https://api.perplexity.ai", iconUrl: PROVIDER_ICONS.perplexity, refusesBrowserRequests: true },
{
id: "searxng", name: "SearXNG", group: "search-local", defaultBaseUrl: "http://localhost:8888", prefillBaseUrl: true,
iconUrl: PROVIDER_ICONS.searxng,
@@ -512,9 +518,7 @@ function ProviderGroup({ heading, description, columns, providers, selectedProvi
// A provider this build can't run keeps its place in the list but
// states why in place of its blurb — the blurb describes a setup
// that isn't on offer here, so it would only mislead.
- const unavailableReason = provider.needsHostProcess && isStandalone
- ? t("llm.provider_unavailable_standalone")
- : undefined;
+ const unavailableReason = standaloneUnavailableReason(provider);
return (
<SelectableCard
key={provider.id}
@@ -535,6 +539,20 @@ function ProviderGroup({ heading, description, columns, providers, selectedProvi
);
}
+/** Why the standalone build cannot use `provider`, or `undefined` where it can or this is not that build. */
+function standaloneUnavailableReason(provider: ProviderType): string | undefined {
+ if (!isStandalone) {
+ return undefined;
+ }
+ if (provider.needsHostProcess) {
+ return t("llm.provider_unavailable_standalone");
+ }
+ if (provider.refusesBrowserRequests) {
+ return t("llm.search_provider_unavailable_standalone");
+ }
+ return undefined;
+}
+
/**
* The endpoint a freshly picked provider starts with. Only self-hosted providers
* prefill: their port is the one thing the user must get right and it differs per
diff --git a/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.wizard.spec.tsx b/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.wizard.spec.tsx
index 5774f74f49..bc99ae26e0 100644
--- a/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.wizard.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.wizard.spec.tsx
@@ -7,11 +7,20 @@ const mocks = vi.hoisted(() => ({
onSave: vi.fn(),
onHidden: vi.fn(),
/** The Antigravity download found for the device running Trilium. */
- antigravityDownload: {} as { version?: string; url?: string }
+ antigravityDownload: {} as { version?: string; url?: string },
+ standalone: false
}));
vi.mock("./antigravity_download", () => ({ useAntigravityDownload: () => mocks.antigravityDownload }));
+// `isStandalone` is a const in the target, read here through a getter so a case can flip it.
+vi.mock("../../../../services/utils", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("../../../../services/utils")>()),
+ get isStandalone() {
+ return mocks.standalone;
+ }
+}));
+
/** Messages whose text a case depends on; every other key renders as itself. */
const MESSAGES = vi.hoisted<Record<string, string>>(() => ({
"llm.antigravity_agent_description": "Uses your Google account.\n\nDownload the server.\n\nSign in once."
@@ -79,6 +88,7 @@ afterEach(() => {
document.body.innerHTML = "";
vi.clearAllMocks();
mocks.antigravityDownload = {};
+ mocks.standalone = false;
});
function open(existingProvider?: LlmProviderConfig, kind?: LlmProviderKind) {
@@ -284,6 +294,21 @@ describe("what gets saved", () => {
expect(step).not.toContain("llm.base_url_description");
});
+ it("disables, with the reason, the search services that refuse requests from a web page in the browser version", () => {
+ const cards = () => Object.fromEntries([ "Brave Search", "Tavily", "Exa", "Serper", "Perplexity", "SearXNG" ]
+ .map((name) => [ name, providerCard(name) ]));
+ open(undefined, "search");
+ expect(Object.values(cards()).every((card) => card && !(card as HTMLButtonElement).disabled)).toBe(true);
+
+ mocks.standalone = true;
+ open(undefined, "search");
+ const disabled = Object.entries(cards())
+ .filter(([ , card ]) => (card as HTMLButtonElement | undefined)?.disabled)
+ .map(([ name ]) => name);
+ expect(disabled).toEqual([ "Brave Search", "Exa", "Perplexity" ]);
+ expect(providerCard("Exa")?.textContent).toContain("llm.search_provider_unavailable_standalone");
+ });
+
it("keeps the kind of the search provider being edited", () => {
open({ id: "brave_1", name: "Brave Search", provider: "brave", kind: "search", apiKey: "old" });
type(textBoxes()[0], "new");
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 5ef29483f2..706a2a52fc 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
@@ -126,7 +126,9 @@
searches through that service instead, whichever model is answering. Search
providers are added in the <em>Search Providers</em> section of the AI settings,
which the <span class="tn-icon bx bx-cog"></span> button beside the <em>Web search</em> heading
- in the menu opens.</li>
+ in the menu opens. The browser version can't use Brave Search, Exa or Perplexity,
+ whose services refuse requests made from a web page, so they're shown disabled
+ there.</li>
</ul>
<p>Whether web search is on is kept per chat; the search source is shared
by all chats. A choice the current model can't use stays in the menu, disabled;
diff --git a/docs/User Guide/User Guide/AI.md b/docs/User Guide/User Guide/AI.md
index 12058d0bb6..f630748111 100644
--- a/docs/User Guide/User Guide/AI.md
+++ b/docs/User Guide/User Guide/AI.md
@@ -89,7 +89,7 @@ Where the search comes from is chosen under _Web search_ in the <span class="tn-
* _Disabled_ turns web search off for this chat.
* _Use the model's built-in search_, the default, lets the model search with its provider's own search. Anthropic, OpenAI and Google Gemini models have one, as do Claude Code, Google Antigravity and OpenAI Codex. DeepSeek, Ollama, LM Studio and custom endpoints don't, so this choice is disabled for their models.
-* A search provider (Brave Search, Tavily, Exa, Serper, Perplexity or SearXNG) searches through that service instead, whichever model is answering. Search providers are added in the _Search Providers_ section of the AI settings, which the <span class="tn-icon bx bx-cog"></span> button beside the _Web search_ heading in the menu opens.
+* A search provider (Brave Search, Tavily, Exa, Serper, Perplexity or SearXNG) searches through that service instead, whichever model is answering. Search providers are added in the _Search Providers_ section of the AI settings, which the <span class="tn-icon bx bx-cog"></span> button beside the _Web search_ heading in the menu opens. The browser version can't use Brave Search, Exa or Perplexity, whose services refuse requests made from a web page, so they're shown disabled there.
Whether web search is on is kept per chat; the search source is shared by all chats. A choice the current model can't use stays in the menu, disabled; hover the <span class="tn-icon bx bx-info-circle"></span> icon next to it to see why. Claude Code, GitHub Copilot, Google Antigravity and OpenAI Codex run their own tools, so they can't use a search provider.