Skip to content

Build your personal knowledge base with Trilium Notes

feat(llm): configure search providers in the AI settings

Elian Doran928d89cdfc12
diff --git a/apps/client/src/services/llm_providers.spec.ts b/apps/client/src/services/llm_providers.spec.ts
index 9668348031..61b3c673f3 100644
--- a/apps/client/src/services/llm_providers.spec.ts
+++ b/apps/client/src/services/llm_providers.spec.ts
@@ -1,7 +1,11 @@
import type { LlmModelInfo } from "@triliumnext/commons";
-import { describe, expect, it } from "vitest";
+import { describe, expect, it, vi } from "vitest";
-import { readsAttachmentKind, unreadableAttachments } from "./llm_providers.js";
+const mocks = vi.hoisted(() => ({ stored: [] as unknown[] }));
+
+vi.mock("./options.js", () => ({ default: { getJson: () => mocks.stored } }));
+
+import { readSelectedModels, readsAttachmentKind, unreadableAttachments } from "./llm_providers.js";
const textOnly: LlmModelInfo = { id: "deepseek-v4-pro", name: "DeepSeek V4 Pro", attachmentKinds: [] };
const imagesOnly: LlmModelInfo = { id: "codex", name: "Codex", attachmentKinds: [ "image" ] };
@@ -29,3 +33,19 @@ describe("attachment support", () => {
expect(readsAttachmentKind(everything, "file")).toBe(true);
});
});
+
+describe("readSelectedModels", () => {
+ it("lists chat providers only, leaving search providers out", () => {
+ mocks.stored = [
+ { id: "o1", name: "OpenAI", provider: "openai", selectedModels: [ { id: "gpt", name: "GPT" } ] },
+ { id: "s1", name: "Brave Search", provider: "brave", kind: "search" }
+ ];
+ const { groups, models, hasProvider } = readSelectedModels();
+ expect(groups.map(group => group.id)).toEqual([ "o1" ]);
+ expect(models.map(model => model.id)).toEqual([ "gpt" ]);
+ expect(hasProvider).toBe(true);
+
+ mocks.stored = [ { id: "s1", name: "Brave Search", provider: "brave", kind: "search" } ];
+ expect(readSelectedModels().hasProvider).toBe(false);
+ });
+});
diff --git a/apps/client/src/services/llm_providers.ts b/apps/client/src/services/llm_providers.ts
index 1303364a8c..01857c247e 100644
--- a/apps/client/src/services/llm_providers.ts
+++ b/apps/client/src/services/llm_providers.ts
@@ -1,4 +1,4 @@
-import type { LlmAttachmentKind, LlmModelInfo } from "@triliumnext/commons";
+import { isProviderOfKind, type LlmAttachmentKind, type LlmModelInfo, type LlmProviderKind } from "@triliumnext/commons";
import { formatModelCost } from "./llm_model_cost.js";
import options from "./options.js";
@@ -32,7 +32,8 @@ export interface ModelProviderGroup {
* chat's picker, the text editor's assistant — lists the same thing without a round-trip.
*/
export function readSelectedModels(): { models: ModelOption[]; groups: ModelProviderGroup[]; hasProvider: boolean } {
- const configs = (options.getJson("llmProviders") as StoredProviderConfig[] | null) ?? [];
+ const configs = ((options.getJson("llmProviders") as StoredProviderConfig[] | null) ?? [])
+ .filter(config => isProviderOfKind(config, "llm"));
const groups: ModelProviderGroup[] = configs.map(config => ({
id: config.id,
name: config.name,
@@ -99,5 +100,6 @@ interface StoredProviderConfig {
id: string;
name: string;
provider: string;
+ kind?: LlmProviderKind;
selectedModels?: LlmModelInfo[];
}
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 348d39e613..0c68136dc2 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -4251,7 +4251,15 @@
"note_moved_from": "<Note/> from <From/> to <To/>",
"note_moved": "<Note/> to <To/>",
"attachment_in_note": "<Title/> in <Note/>"
- }
+ },
+ "search_providers": "Search Providers",
+ "no_search_providers_configured": "No search providers configured yet.",
+ "add_search_provider": "Add Search Provider",
+ "search_provider_group_cloud": "Search APIs",
+ "search_provider_group_cloud_description": "Uses an API key, with a free monthly allowance or billed per search depending on the service. Your searches are sent to the provider's servers.",
+ "search_provider_group_local": "Self-hosted",
+ "search_provider_group_local_description": "Your own metasearch instance. Searches reach only that instance and the search engines it queries.",
+ "setup_hint_searxng": "The address of your SearXNG instance. Its <Code>settings.yml</Code> must list <Code>json</Code> under <Code>search.formats</Code>."
},
"common": {
"save": "Save",
diff --git a/apps/client/src/widgets/type_widgets/options/llm.spec.tsx b/apps/client/src/widgets/type_widgets/options/llm.spec.tsx
index 738509e289..2197e26c88 100644
--- a/apps/client/src/widgets/type_widgets/options/llm.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/options/llm.spec.tsx
@@ -51,7 +51,7 @@ vi.mock("./components/OptionsPageHeader", () => ({
default: ({ below }: { below?: preact.ComponentChildren }) => <div className="header-stub">{below}</div>
}));
// Carries a bootstrap modal into the tree, and the MCP card below it is what is being read here.
-vi.mock("./llm/AddProviderModal", () => ({ default: () => null, PROVIDER_TYPES: [] }));
+vi.mock("./llm/AddProviderModal", () => ({ default: () => null, findProviderType: () => undefined }));
import LlmSettings, { buildMcpClientConfig, buildMcpClientCommand } from "./llm";
@@ -204,7 +204,7 @@ describe("the configured providers", () => {
const providers = () => [ ...host.querySelectorAll(".tn-card-option") ]
.filter((option) => option.querySelector(".llm-provider-name"));
- function withProviders(configured: { id: string; name: string; provider: string; apiKey: string; selectedModels?: unknown[] }[]) {
+ function withProviders(configured: { id: string; name: string; provider: string; kind?: string; apiKey: string; selectedModels?: unknown[] }[]) {
mocks.stored = { ...mocks.stored, llmProviders: JSON.stringify(configured) };
}
@@ -261,6 +261,27 @@ describe("the configured providers", () => {
expect(mocks.saved.some(([ name ]) => name === "llmProviders")).toBe(false);
});
+
+ it("lists search providers in a card of their own, and deleting one keeps the chat providers", async () => {
+ withProviders([
+ { id: "a", name: "My OpenAI", provider: "openai", apiKey: "sk" },
+ { id: "s", name: "Brave Search", provider: "brave", kind: "search", apiKey: "bk" }
+ ]);
+ open();
+
+ const card = (heading: string) => [ ...host.querySelectorAll(".tn-card") ]
+ .find((c) => c.querySelector(".tn-card-heading")?.textContent === heading);
+ const names = (heading: string) => [ ...card(heading)?.querySelectorAll(".llm-provider-name") ?? [] ]
+ .map((name) => name.textContent);
+ expect(names("llm.configured_providers")).toEqual([ "My OpenAI" ]);
+ expect(names("llm.search_providers")).toEqual([ "Brave Search" ]);
+
+ const remove = card("llm.search_providers")?.querySelectorAll(".tn-card-option-actions button")[1];
+ expect(remove).toBeDefined();
+ await act(async () => (remove as HTMLButtonElement).click());
+ const written = mocks.saved.find(([ name ]) => name === "llmProviders");
+ expect(JSON.parse(written?.[1] ?? "[]").map((provider: { id: string }) => provider.id)).toEqual([ "a" ]);
+ });
});
describe("MCP client configuration samples", () => {
diff --git a/apps/client/src/widgets/type_widgets/options/llm.tsx b/apps/client/src/widgets/type_widgets/options/llm.tsx
index 92d01f60d8..24ee8c3050 100644
--- a/apps/client/src/widgets/type_widgets/options/llm.tsx
+++ b/apps/client/src/widgets/type_widgets/options/llm.tsx
@@ -1,6 +1,6 @@
import "./llm.css";
-import type { NetworkAddressesResponse } from "@triliumnext/commons";
+import { isProviderOfKind, type LlmProviderKind, type NetworkAddressesResponse } from "@triliumnext/commons";
import { useCallback, useEffect, useMemo, useState } from "preact/hooks";
import dialog from "../../../services/dialog";
@@ -18,7 +18,7 @@ import { useTriliumOption, useTriliumOptionBool } from "../../react/hooks";
import MaskedIcon from "../../react/MaskedIcon";
import NoItems from "../../react/NoItems";
import OptionsPageHeader from "./components/OptionsPageHeader";
-import AddProviderModal, { type LlmProviderConfig, PROVIDER_TYPES } from "./llm/AddProviderModal";
+import AddProviderModal, { findProviderType, type LlmProviderConfig } from "./llm/AddProviderModal";
export default function LlmSettings() {
const [aiEnabled, setAiEnabled] = useTriliumOptionBool("aiEnabled");
@@ -43,7 +43,8 @@ export default function LlmSettings() {
{aiEnabled && (
<>
- <ProviderSettings />
+ <ProviderSettings kind="llm" />
+ <ProviderSettings kind="search" />
<McpSettings />
</>
)}
@@ -51,16 +52,18 @@ export default function LlmSettings() {
);
}
-function ProviderSettings() {
+/** The configured providers of one kind. Both kinds are stored in the `llmProviders` option. */
+function ProviderSettings({ kind }: { kind: LlmProviderKind }) {
const [providersJson, setProvidersJson] = useTriliumOption("llmProviders");
- const providers = useMemo<LlmProviderConfig[]>(() => {
+ const allProviders = useMemo<LlmProviderConfig[]>(() => {
try {
return providersJson ? JSON.parse(providersJson) : [];
} catch {
return [];
}
}, [providersJson]);
- const setProviders = useCallback((newProviders: LlmProviderConfig[]) => {
+ const providers = useMemo(() => allProviders.filter(p => isProviderOfKind(p, kind)), [allProviders, kind]);
+ const setAllProviders = useCallback((newProviders: LlmProviderConfig[]) => {
setProvidersJson(JSON.stringify(newProviders));
}, [setProvidersJson]);
// `undefined` while closed; the edited provider (or a fresh marker) while open.
@@ -77,31 +80,35 @@ function ProviderSettings() {
// Upsert: editing replaces the config with the matching id, adding appends.
const handleSaveProvider = useCallback((saved: LlmProviderConfig) => {
- setProviders(providers.some(p => p.id === saved.id)
- ? providers.map(p => (p.id === saved.id ? saved : p))
- : [...providers, saved]);
- }, [providers, setProviders]);
+ setAllProviders(allProviders.some(p => p.id === saved.id)
+ ? allProviders.map(p => (p.id === saved.id ? saved : p))
+ : [...allProviders, saved]);
+ }, [allProviders, setAllProviders]);
const handleDeleteProvider = useCallback(async (providerId: string, providerName: string) => {
if (!(await dialog.confirm(t("llm.delete_provider_confirmation", { name: providerName })))) {
return;
}
- setProviders(providers.filter(p => p.id !== providerId));
- }, [providers, setProviders]);
+ setAllProviders(allProviders.filter(p => p.id !== providerId));
+ }, [allProviders, setAllProviders]);
+
+ const isSearch = kind === "search";
return (<>
- <Card heading={t("llm.configured_providers")}>
+ <Card heading={isSearch ? t("llm.search_providers") : t("llm.configured_providers")}>
<ProviderList
providers={providers}
+ emptyIcon={isSearch ? "bx bx-search" : "bx bx-bot"}
+ emptyText={isSearch ? t("llm.no_search_providers_configured") : t("llm.no_providers_configured")}
onEdit={openModal}
onDelete={handleDeleteProvider}
/>
<CardSection className="llm-add-provider">
<Button
- name="add-llm-provider-button"
+ name={isSearch ? "add-search-provider-button" : "add-llm-provider-button"}
size="micro" icon="bx-plus"
- text={t("llm.add_provider")}
+ text={isSearch ? t("llm.add_search_provider") : t("llm.add_provider")}
onClick={() => openModal()}
/>
</CardSection>
@@ -111,6 +118,7 @@ function ProviderSettings() {
key={openToken}
show={modalOpen}
existingProvider={modalProvider}
+ kind={kind}
onHidden={() => setModalOpen(false)}
onSave={handleSaveProvider}
/>
@@ -260,22 +268,24 @@ function getMcpEndpointUrl() {
interface ProviderListProps {
providers: LlmProviderConfig[];
+ emptyIcon: string;
+ emptyText: string;
onEdit: (provider: LlmProviderConfig) => void;
onDelete: (providerId: string, providerName: string) => Promise<void>;
}
-function ProviderList({ providers, onEdit, onDelete }: ProviderListProps) {
+function ProviderList({ providers, emptyIcon, emptyText, onEdit, onDelete }: ProviderListProps) {
if (!providers.length) {
return (
<CardSection>
- <NoItems icon="bx bx-bot" text={t("llm.no_providers_configured")} />
+ <NoItems icon={emptyIcon} text={emptyText} />
</CardSection>
);
}
return <>
{providers.map((provider) => {
- const providerType = PROVIDER_TYPES.find(p => p.id === provider.provider);
+ const providerType = findProviderType(provider.provider);
const modelCount = provider.selectedModels?.length ?? 0;
return (
<OptionCardSection
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 3b03ea3e89..24b5fd468d 100644
--- a/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.tsx
+++ b/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.tsx
@@ -1,6 +1,6 @@
import "./AddProviderModal.css";
-import type { LlmModelInfo } from "@triliumnext/commons";
+import type { LlmModelInfo, LlmProviderKind } from "@triliumnext/commons";
import { createPortal } from "preact";
import { useMemo, useState } from "preact/hooks";
import { Trans } from "react-i18next";
@@ -16,12 +16,14 @@ import WizardModal, { type WizardStep } from "../../../react/WizardModal";
import OptionsRow from "../components/OptionsRow";
import { useAntigravityDownload } from "./antigravity_download";
import ModelSelection from "./ModelSelection";
-import { PROVIDER_ICONS } from "./provider_icons.js";
+import { PROVIDER_ICONS, SEARCH_PROVIDER_ICON } from "./provider_icons.js";
export interface LlmProviderConfig {
id: string;
name: string;
provider: string;
+ /** Absent in configurations saved before search providers existed, all of which are `"llm"`. */
+ kind?: LlmProviderKind;
apiKey: string;
baseURL?: string;
/** Models the user selected for this provider, with full metadata for offline rendering. */
@@ -111,7 +113,12 @@ const PROVIDER_GROUPS = [
{ id: "custom", columns: 1, headingKey: "llm.provider_group_custom", descriptionKey: "llm.provider_group_custom_description" }
] as const;
-type ProviderGroupId = (typeof PROVIDER_GROUPS)[number]["id"];
+const SEARCH_PROVIDER_GROUPS = [
+ { id: "search-cloud", columns: 2, headingKey: "llm.search_provider_group_cloud", descriptionKey: "llm.search_provider_group_cloud_description" },
+ { id: "search-local", columns: 1, headingKey: "llm.search_provider_group_local", descriptionKey: "llm.search_provider_group_local_description" }
+] as const;
+
+type ProviderGroupId = (typeof PROVIDER_GROUPS)[number]["id"] | (typeof SEARCH_PROVIDER_GROUPS)[number]["id"];
export const PROVIDER_TYPES: ProviderType[] = [
{ id: "anthropic", name: "Anthropic", group: "cloud", defaultBaseUrl: "https://api.anthropic.com/v1", iconUrl: PROVIDER_ICONS.anthropic },
@@ -155,6 +162,23 @@ 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: SEARCH_PROVIDER_ICON },
+ { id: "tavily", name: "Tavily", group: "search-cloud", defaultBaseUrl: "https://api.tavily.com", iconUrl: SEARCH_PROVIDER_ICON },
+ { id: "exa", name: "Exa", group: "search-cloud", defaultBaseUrl: "https://api.exa.ai", iconUrl: SEARCH_PROVIDER_ICON },
+ {
+ id: "searxng", name: "SearXNG", group: "search-local", defaultBaseUrl: "http://localhost:8888", prefillBaseUrl: true,
+ iconUrl: SEARCH_PROVIDER_ICON,
+ setupHintKey: "llm.setup_hint_searxng", apiKey: "optional", baseUrl: "required"
+ }
+];
+
+/** The provider type with `providerId`, of either kind. */
+export function findProviderType(providerId: string | undefined): ProviderType | undefined {
+ return PROVIDER_TYPES.find(p => p.id === providerId) ?? SEARCH_PROVIDER_TYPES.find(p => p.id === providerId);
+}
+
/**
* Whether an endpoint is one the app could actually reach. An empty field is not invalid — it means
* the provider's own default stands — so it is only the shape of what was typed that is judged here.
@@ -209,26 +233,29 @@ interface AddProviderModalProps {
existingProvider?: LlmProviderConfig;
/** Step to open on. Pass "models" to jump straight to model selection (e.g. editing from the chat picker). */
initialStep?: ProviderStep;
+ /** Which kind of provider to add. When editing, the kind of {@link existingProvider} applies instead. */
+ kind?: LlmProviderKind;
}
-export default function AddProviderModal({ show, onHidden, onSave, existingProvider, initialStep }: AddProviderModalProps) {
+export default function AddProviderModal({ show, onHidden, onSave, existingProvider, initialStep, kind: kindToAdd = "llm" }: AddProviderModalProps) {
const isEdit = !!existingProvider;
+ const kind = existingProvider ? (existingProvider.kind ?? "llm") : kindToAdd;
+ const isSearch = kind === "search";
+ const providerTypes = isSearch ? SEARCH_PROVIDER_TYPES : PROVIDER_TYPES;
+ const providerGroups = isSearch ? SEARCH_PROVIDER_GROUPS : PROVIDER_GROUPS;
const firstStep = initialStep ?? (isEdit ? "connection" : "provider");
const [step, setStep] = useState<ProviderStep>(firstStep);
- const [selectedProvider, setSelectedProvider] = useState(existingProvider?.provider ?? PROVIDER_TYPES[0].id);
+ const [selectedProvider, setSelectedProvider] = useState(existingProvider?.provider ?? providerTypes[0].id);
// Whether the user has actually picked a provider. `selectedProvider` always
// holds one so the connection step has something to work with, but on a fresh
// add nothing should *look* chosen — clicking a card is the choice, and it
// moves on immediately, so a pre-highlighted card would be a lie.
const [providerChosen, setProviderChosen] = useState(firstStep !== "provider");
const [apiKey, setApiKey] = useState(existingProvider?.apiKey ?? "");
- const [baseUrl, setBaseUrl] = useState(existingProvider?.baseURL ?? prefilledBaseUrl(existingProvider?.provider ?? PROVIDER_TYPES[0].id));
+ const [baseUrl, setBaseUrl] = useState(existingProvider?.baseURL ?? prefilledBaseUrl(existingProvider?.provider ?? providerTypes[0].id));
const [selectedModels, setSelectedModels] = useState<LlmModelInfo[]>(existingProvider?.selectedModels ?? []);
- const providerType = useMemo(
- () => PROVIDER_TYPES.find(p => p.id === selectedProvider),
- [selectedProvider]
- );
+ const providerType = useMemo(() => findProviderType(selectedProvider), [selectedProvider]);
const apiKeyMode = providerType?.apiKey ?? "required";
// Self-hosted providers show the endpoint as their primary connection detail;
// vendor providers keep it tucked away as an advanced override.
@@ -289,7 +316,7 @@ export default function AddProviderModal({ show, onHidden, onSave, existingProvi
const seedDefaultModels = !existingProvider?.selectedModels;
function reset() {
- const initialProvider = existingProvider?.provider ?? PROVIDER_TYPES[0].id;
+ const initialProvider = existingProvider?.provider ?? providerTypes[0].id;
setStep(firstStep);
setSelectedProvider(initialProvider);
setProviderChosen(firstStep !== "provider");
@@ -308,9 +335,10 @@ export default function AddProviderModal({ show, onHidden, onSave, existingProvi
id: existingProvider?.id ?? `${selectedProvider}_${Date.now()}`,
name: providerType?.name || selectedProvider,
provider: selectedProvider,
+ ...(isSearch && { kind }),
apiKey: usesApiKey ? trimmedApiKey : "",
...(baseUrlMode !== "none" && trimmedBaseUrl && { baseURL: trimmedBaseUrl }),
- selectedModels
+ ...(!isSearch && { selectedModels })
};
onSave(saved);
@@ -324,10 +352,10 @@ export default function AddProviderModal({ show, onHidden, onSave, existingProvi
? t("llm.edit_provider_title", { name: existingProvider?.name ?? providerType?.name ?? selectedProvider })
: t("llm.add_provider_title_named", { name: providerType?.name ?? selectedProvider });
- const steps: WizardStep<ProviderStep>[] = [
+ const allSteps: WizardStep<ProviderStep>[] = [
{
id: "provider",
- title: t("llm.add_provider_title"),
+ title: isSearch ? t("llm.add_search_provider") : t("llm.add_provider_title"),
// Choosing a card advances on its own, so the step needs no primary action —
// but Enter must still not advance with whichever provider happens to be
// first in the list, hence the guard.
@@ -337,13 +365,13 @@ export default function AddProviderModal({ show, onHidden, onSave, existingProvi
// One card per group rather than one "Provider" card holding them all:
// the groups are the step's structure, so each gets the heading and the
// enclosure, and the choices below it are only the ones it describes.
- PROVIDER_GROUPS.map(group => (
+ providerGroups.map(group => (
<ProviderGroup
key={group.id}
heading={t(group.headingKey)}
description={t(group.descriptionKey)}
columns={group.columns}
- providers={PROVIDER_TYPES.filter(p => p.group === group.id)}
+ providers={providerTypes.filter(p => p.group === group.id)}
selectedProvider={providerChosen ? selectedProvider : undefined}
onSelect={selectProviderType}
/>
@@ -413,6 +441,8 @@ export default function AddProviderModal({ show, onHidden, onSave, existingProvi
)
}
];
+ // Search providers have no models to choose, so their wizard ends at the connection step.
+ const steps = isSearch ? allSteps.filter(s => s.id !== "models") : allSteps;
return createPortal(
<WizardModal
@@ -510,7 +540,7 @@ function ProviderGroup({ heading, description, columns, providers, selectedProvi
* unedited field must not store a redundant override).
*/
export function prefilledBaseUrl(providerId: string): string {
- const providerType = PROVIDER_TYPES.find(p => p.id === providerId);
+ const providerType = findProviderType(providerId);
return providerType?.prefillBaseUrl ? providerType.defaultBaseUrl : "";
}
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 c305626c21..56b6191a60 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
@@ -1,4 +1,4 @@
-import type { LlmModelInfo } from "@triliumnext/commons";
+import type { LlmModelInfo, LlmProviderKind } from "@triliumnext/commons";
import { render } from "preact";
import { act } from "preact/test-utils";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
@@ -81,7 +81,7 @@ afterEach(() => {
mocks.antigravityDownload = {};
});
-function open(existingProvider?: LlmProviderConfig) {
+function open(existingProvider?: LlmProviderConfig, kind?: LlmProviderKind) {
act(() => {
render(null, host);
render(
@@ -90,6 +90,7 @@ function open(existingProvider?: LlmProviderConfig) {
onHidden={mocks.onHidden}
onSave={mocks.onSave}
existingProvider={existingProvider}
+ kind={kind}
/>,
host
);
@@ -261,6 +262,28 @@ describe("what gets saved", () => {
expect(saved.selectedModels).toEqual(existing.selectedModels);
});
+ it("offers search services for a search provider, and saves one at the connection step", () => {
+ open(undefined, "search");
+ expect(providerCard("OpenAI")).toBeUndefined();
+ act(() => providerCard("SearXNG")?.click());
+ expect(textBoxes()[0]?.value).toBe("http://localhost:8888");
+ act(() => void nextButton()?.click());
+
+ expect(document.querySelector(".model-selection-stub")).toBeNull();
+ const [ saved ] = mocks.onSave.mock.calls[0] as [ LlmProviderConfig ];
+ expect(saved).toMatchObject({ provider: "searxng", name: "SearXNG", kind: "search", baseURL: "http://localhost:8888" });
+ expect(saved).not.toHaveProperty("selectedModels");
+ });
+
+ 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");
+ act(() => void nextButton()?.click());
+
+ const [ saved ] = mocks.onSave.mock.calls[0] as [ LlmProviderConfig ];
+ expect(saved).toMatchObject({ id: "brave_1", kind: "search", apiKey: "new" });
+ });
+
it("puts the dialog away once it has saved", () => {
open();
act(() => providerCard("Claude Code")?.click());
diff --git a/apps/client/src/widgets/type_widgets/options/llm/icons/search.svg b/apps/client/src/widgets/type_widgets/options/llm/icons/search.svg
new file mode 100644
index 0000000000..de93f3ff21
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/options/llm/icons/search.svg
@@ -0,0 +1 @@
+<svg width="24" height="24" fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M10 2a8 8 0 0 1 6.32 12.9l5.39 5.39-1.42 1.42-5.39-5.39A8 8 0 1 1 10 2m0 2a6 6 0 1 0 0 12 6 6 0 0 0 0-12"/></svg>
diff --git a/apps/client/src/widgets/type_widgets/options/llm/provider_icons.ts b/apps/client/src/widgets/type_widgets/options/llm/provider_icons.ts
index ad5a47f3d1..eb94def88a 100644
--- a/apps/client/src/widgets/type_widgets/options/llm/provider_icons.ts
+++ b/apps/client/src/widgets/type_widgets/options/llm/provider_icons.ts
@@ -21,6 +21,7 @@ import lmStudioIcon from "./icons/lmstudio.svg?url";
import ollamaIcon from "./icons/ollama.svg?url";
import openaiIcon from "./icons/openai.svg?url";
import openAiCompatibleIcon from "./icons/robot.svg?url";
+import searchIcon from "./icons/search.svg?url";
export const PROVIDER_ICONS: Record<string, string> = {
anthropic: anthropicIcon,
@@ -36,6 +37,9 @@ export const PROVIDER_ICONS: Record<string, string> = {
"openai-compatible": openAiCompatibleIcon
};
+/** The mark every search provider card shows. */
+export const SEARCH_PROVIDER_ICON = searchIcon;
+
/**
* The mark for a provider type, falling back to the generic one so a provider added later —
* or a configuration restored from a newer version — still gets a glyph rather than a gap
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 230cab1447..11ab371b80 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
@@ -116,8 +116,10 @@
on the model selector at the bottom of the chat and unchecking <em>Web search</em>.</p>
<aside
class="admonition note">
- <p>Currently only the search native to the LLM provider is supported. External
- search providers such as Exa, Tavily &amp; SearXNG are not yet supported.</p>
+ <p>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 <em>Search Providers</em> section of the AI settings, but the
+ chat does not use them yet.</p>
</aside>
<h3>Thinking</h3>
<p>Some models reason before they answer. While the model is thinking, its
diff --git a/docs/User Guide/User Guide/AI.md b/docs/User Guide/User Guide/AI.md
index 54138ba64b..a843b0aea3 100644
--- a/docs/User Guide/User Guide/AI.md
+++ b/docs/User Guide/User Guide/AI.md
@@ -88,7 +88,7 @@ The AI can optionally search the web to find more information about a specific t
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_.
> [!NOTE]
-> Currently only the search native to the LLM provider is supported. External search providers such as Exa, Tavily & SearXNG are not yet supported.
+> 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.
### Thinking
diff --git a/packages/commons/src/lib/llm_api.ts b/packages/commons/src/lib/llm_api.ts
index 5382bfc0b4..5ee5f6d9e6 100644
--- a/packages/commons/src/lib/llm_api.ts
+++ b/packages/commons/src/lib/llm_api.ts
@@ -125,6 +125,17 @@ export interface LlmModelPricing {
output: number;
}
+/**
+ * What a configuration in the `llmProviders` option provides: chat models (`"llm"`) or web
+ * search (`"search"`). A configuration without a `kind` is `"llm"`.
+ */
+export type LlmProviderKind = "llm" | "search";
+
+/** Whether a stored provider configuration is of `kind`, treating a missing `kind` as `"llm"`. */
+export function isProviderOfKind(config: { kind?: LlmProviderKind }, kind: LlmProviderKind): boolean {
+ return (config.kind ?? "llm") === kind;
+}
+
/**
* Information about an available LLM model.
*/
diff --git a/packages/trilium-core/src/services/llm/index.spec.ts b/packages/trilium-core/src/services/llm/index.spec.ts
index 3673bcf514..de9b295f8e 100644
--- a/packages/trilium-core/src/services/llm/index.spec.ts
+++ b/packages/trilium-core/src/services/llm/index.spec.ts
@@ -200,6 +200,17 @@ describe("llm/index provider registry", () => {
setProviders(TWO);
expect(hasConfiguredProviders()).toBe(true);
});
+
+ it("leaves search providers out of the chat providers", async () => {
+ const search = { id: "s1", name: "Brave Search", provider: "brave", kind: "search", apiKey: "k" };
+ setProviders([ search ]);
+ expect(hasConfiguredProviders()).toBe(false);
+
+ setProviders([ search, ...TWO ]);
+ const first = await getProvider();
+ expect((first.constructor as any).lastArgs).toEqual(["k1", "https://proxy"]);
+ await expect(getProvider("s1")).rejects.toThrow("LLM provider not found: s1");
+ });
});
describe("getProviderByType", () => {
diff --git a/packages/trilium-core/src/services/llm/index.ts b/packages/trilium-core/src/services/llm/index.ts
index 7f50e83e3e..4dde717079 100644
--- a/packages/trilium-core/src/services/llm/index.ts
+++ b/packages/trilium-core/src/services/llm/index.ts
@@ -1,3 +1,5 @@
+import { isProviderOfKind, type LlmProviderKind } from "@triliumnext/commons";
+
import { getLog } from "../../services/log.js";
import optionService from "../../services/options.js";
@@ -14,6 +16,8 @@ export interface LlmProviderSetup {
id: string;
name: string;
provider: string;
+ /** Absent in configurations saved before search providers existed, all of which are `"llm"`. */
+ kind?: LlmProviderKind;
apiKey: string;
/** Optional override for the SDK's default API endpoint (e.g. for self-hosted Ollama, vLLM, or proxies). */
baseURL?: string;
@@ -92,7 +96,8 @@ let cachedProviders: Record<string, LlmProvider> = {};
let cachedProvidersSource: string | null = null;
/**
- * Get configured providers from the options.
+ * Get the configured chat providers from the options. Search providers share the option and are
+ * left out, so none of them is ever picked to answer a chat.
*/
function getConfiguredProviders(): LlmProviderSetup[] {
try {
@@ -104,7 +109,7 @@ function getConfiguredProviders(): LlmProviderSetup[] {
if (!providersJson) {
return [];
}
- return JSON.parse(providersJson) as LlmProviderSetup[];
+ return (JSON.parse(providersJson) as LlmProviderSetup[]).filter(c => isProviderOfKind(c, "llm"));
} catch (e) {
getLog().error(`Failed to parse llmProviders option: ${e}`);
return [];