Skip to content

Build your personal knowledge base with Trilium Notes

feat(llm): use a card selector for the Add AI provider screen

Elian Doran70a0a4e8693d
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 71d04992c1..e0e69908d7 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3073,6 +3073,11 @@
"no_providers_configured": "No providers configured yet.",
"provider_name": "Name",
"provider_type": "Provider",
+ "connection_details": "Connection",
+ "provider_desc_anthropic": "Claude models via the Anthropic API. Requires an API key.",
+ "provider_desc_claude_agent": "Uses your Claude Pro/Max subscription, no API key. Requires Claude Code on the Trilium server.",
+ "provider_desc_openai": "GPT models via the OpenAI API. Requires an API key.",
+ "provider_desc_google": "Gemini models via the Google API. Requires an API key.",
"actions": "Actions",
"delete_provider": "Delete",
"delete_provider_confirmation": "Are you sure you want to delete the provider \"{{name}}\"?",
diff --git a/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.css b/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.css
new file mode 100644
index 0000000000..7a8840df32
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.css
@@ -0,0 +1,15 @@
+.modal.add-provider-modal {
+ .tn-card {
+ margin-bottom: 1rem;
+ }
+
+ .tn-card:last-child {
+ margin-bottom: 0;
+ }
+
+ /* The connection card holds the form fields directly, so drop the FormGroup's
+ trailing margin on the last field to keep the card padding even. */
+ .tn-card-section .form-group:last-child {
+ margin-bottom: 0;
+ }
+}
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 7289adc135..4d0517b347 100644
--- a/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.tsx
+++ b/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.tsx
@@ -1,11 +1,18 @@
+import "./AddProviderModal.css";
+
import { createPortal } from "preact/compat";
import { useMemo, useRef, useState } from "preact/hooks";
import { t } from "../../../../services/i18n";
+import { Card, CardSection } from "../../../react/Card";
import FormGroup from "../../../react/FormGroup";
-import FormSelect from "../../../react/FormSelect";
import FormTextBox from "../../../react/FormTextBox";
import Modal from "../../../react/Modal";
+import SelectableCard, { SelectableCardGrid } from "../../../react/SelectableCard";
+import anthropicIcon from "./icons/anthropic.svg?url";
+import claudeAgentIcon from "./icons/claude-ai.svg?url";
+import geminiIcon from "./icons/gemini.svg?url";
+import openaiIcon from "./icons/openai.svg?url";
export interface LlmProviderConfig {
id: string;
@@ -19,16 +26,22 @@ export interface ProviderType {
id: string;
name: string;
defaultBaseUrl: string;
+ /** URL of the provider's logo (an imported `*.svg?url`), rendered monochrome via a CSS mask. */
+ iconUrl: string;
+ /** Short blurb shown under the provider name on its selectable card. */
+ description: string;
/** When false, the provider needs no API key or base URL (e.g. subscription-based auth). */
usesApiKey?: boolean;
}
+// The two Claude-powered providers lead the list so they sit together on the top row,
+// making the subscription-vs-API-key choice easy to spot.
export const PROVIDER_TYPES: ProviderType[] = [
- { id: "anthropic", name: "Anthropic", defaultBaseUrl: "https://api.anthropic.com/v1" },
- { id: "openai", name: "OpenAI", defaultBaseUrl: "https://api.openai.com/v1" },
- { id: "google", name: "Google Gemini", defaultBaseUrl: "https://generativelanguage.googleapis.com/v1beta" },
+ { id: "anthropic", name: "Anthropic", defaultBaseUrl: "https://api.anthropic.com/v1", iconUrl: anthropicIcon, description: t("llm.provider_desc_anthropic") },
// Uses the Claude Agent SDK on the server; auth belongs to Claude Code (`claude /login`).
- { id: "claude-agent", name: "Claude Code (Pro/Max subscription)", defaultBaseUrl: "", usesApiKey: false }
+ { id: "claude-agent", name: "Claude Code", defaultBaseUrl: "", iconUrl: claudeAgentIcon, description: t("llm.provider_desc_claude_agent"), usesApiKey: false },
+ { id: "openai", name: "OpenAI", defaultBaseUrl: "https://api.openai.com/v1", iconUrl: openaiIcon, description: t("llm.provider_desc_openai") },
+ { id: "google", name: "Google Gemini", defaultBaseUrl: "https://generativelanguage.googleapis.com/v1beta", iconUrl: geminiIcon, description: t("llm.provider_desc_google") }
];
function isValidBaseUrl(value: string): boolean {
@@ -102,6 +115,7 @@ export default function AddProviderModal({ show, onHidden, onSave }: AddProvider
title={t("llm.add_provider_title")}
className="add-provider-modal"
size="md"
+ maxWidth={600}
stackable
footer={
<>
@@ -114,48 +128,59 @@ export default function AddProviderModal({ show, onHidden, onSave }: AddProvider
</>
}
>
- <FormGroup name="provider-type" label={t("llm.provider_type")}>
- <FormSelect
- values={PROVIDER_TYPES}
- keyProperty="id"
- titleProperty="name"
- currentValue={selectedProvider}
- onChange={setSelectedProvider}
- />
- </FormGroup>
-
- {usesApiKey ? (
- <>
- <FormGroup
- name="base-url"
- label={t("llm.base_url")}
- description={
- !baseUrlIsValid
- ? <span className="text-danger">{t("llm.base_url_invalid")}</span>
- : t("llm.base_url_description")
- }
- >
- <FormTextBox
- type="text"
- currentValue={baseUrl}
- onChange={setBaseUrl}
- placeholder={providerType?.defaultBaseUrl}
- />
- </FormGroup>
-
- <FormGroup name="api-key" label={t("llm.api_key")}>
- <FormTextBox
- type="password"
- currentValue={apiKey}
- onChange={setApiKey}
- placeholder={t("llm.api_key_placeholder")}
- autoFocus
- />
- </FormGroup>
- </>
- ) : (
- <p>{t("llm.claude_agent_description")}</p>
- )}
+ <Card heading={t("llm.provider_type")}>
+ <CardSection>
+ <SelectableCardGrid columns={2}>
+ {PROVIDER_TYPES.map((provider) => (
+ <SelectableCard
+ key={provider.id}
+ iconUrl={provider.iconUrl}
+ title={provider.name}
+ description={provider.description}
+ selected={selectedProvider === provider.id}
+ onSelect={() => setSelectedProvider(provider.id)}
+ />
+ ))}
+ </SelectableCardGrid>
+ </CardSection>
+ </Card>
+
+ <Card heading={t("llm.connection_details")}>
+ <CardSection>
+ {usesApiKey ? (
+ <>
+ <FormGroup
+ name="base-url"
+ label={t("llm.base_url")}
+ description={
+ !baseUrlIsValid
+ ? <span className="text-danger">{t("llm.base_url_invalid")}</span>
+ : t("llm.base_url_description")
+ }
+ >
+ <FormTextBox
+ type="text"
+ currentValue={baseUrl}
+ onChange={setBaseUrl}
+ placeholder={providerType?.defaultBaseUrl}
+ />
+ </FormGroup>
+
+ <FormGroup name="api-key" label={t("llm.api_key")}>
+ <FormTextBox
+ type="password"
+ currentValue={apiKey}
+ onChange={setApiKey}
+ placeholder={t("llm.api_key_placeholder")}
+ autoFocus
+ />
+ </FormGroup>
+ </>
+ ) : (
+ <p>{t("llm.claude_agent_description")}</p>
+ )}
+ </CardSection>
+ </Card>
</Modal>,
document.body
);
diff --git a/apps/client/src/widgets/type_widgets/options/llm/icons/anthropic.svg b/apps/client/src/widgets/type_widgets/options/llm/icons/anthropic.svg
new file mode 100644
index 0000000000..1ad75502a4
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/options/llm/icons/anthropic.svg
@@ -0,0 +1 @@
+<svg width="24" height="24" fill="currentColor" viewBox="0 0 24 24" transform="" id="injected-svg" xmlns="http://www.w3.org/2000/svg"><!--Boxicons v3.0.8 https://boxicons.com | License https://docs.boxicons.com/free--><path d="M7.47 5.13 2 18.86h3.06l1.12-2.88h5.73l1.12 2.88h3.06L10.62 5.13H7.48Zm3.44 8.3H7.16L9.03 8.6l1.87 4.83Zm2.61-8.3L19 18.87h3L16.53 5.13z"></path></svg>
\ No newline at end of file
diff --git a/apps/client/src/widgets/type_widgets/options/llm/icons/claude-ai.svg b/apps/client/src/widgets/type_widgets/options/llm/icons/claude-ai.svg
new file mode 100644
index 0000000000..e37a6e5826
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/options/llm/icons/claude-ai.svg
@@ -0,0 +1 @@
+<svg width="24" height="24" fill="currentColor" viewBox="0 0 24 24" transform="" id="injected-svg" xmlns="http://www.w3.org/2000/svg"><!--Boxicons v3.0.8 https://boxicons.com | License https://docs.boxicons.com/free--><path d="m6.09 15.21 3.83-2.15.06-.19-.06-.1h-.19l-.64-.04-2.19-.06-1.9-.08-1.84-.1-.46-.1-.43-.57.04-.29.39-.26.56.05 1.23.08 1.85.13 1.34.08 1.99.21h.32l.04-.13-.11-.08-.08-.08-1.91-1.3-2.07-1.37-1.08-.79-.59-.4-.3-.37-.13-.82.53-.59.71.05.18.05.72.56 1.55 1.2 2.02 1.49.3.25.12-.08v-.06l-.12-.22-1.1-1.99L7.5 5.12l-.52-.84-.14-.5c-.05-.21-.08-.38-.08-.59l.61-.82.33-.11.81.11.34.3.5 1.15.81 1.81 1.26 2.46.37.73.2.68.07.21h.13v-.12l.1-1.38.19-1.7.19-2.19.06-.62.31-.74.61-.4.47.23.39.56-.05.36-.23 1.5-.45 2.36-.3 1.58h.17l.2-.2.8-1.06 1.34-1.68.59-.67.69-.73.44-.35h.84l.62.92-.28.95-.86 1.09-.71.93-1.02 1.38-.64 1.1.06.09h.15l2.32-.51 1.25-.23 1.49-.26.68.32.07.32-.27.66-1.6.39-1.87.37-2.79.66-.03.02.04.05 1.26.12.54.03h1.32l2.45.18.64.42.38.52-.06.39-.99.5-1.33-.32-3.1-.74-1.06-.27h-.15v.09l.89.87 1.63 1.47 2.04 1.89.1.47-.26.37-.28-.04-1.79-1.35-.69-.61-1.56-1.32h-.1v.14l.36.53 1.9 2.86.1.88-.14.29-.49.17-.54-.1-1.11-1.56-1.15-1.76-.93-1.58-.11.06-.55 5.89-.26.3-.59.23-.49-.37-.26-.61.26-1.2.32-1.56.26-1.24.23-1.54.14-.51v-.03l-.12.01-1.16 1.6-1.77 2.39-1.4 1.5-.34.13-.58-.3.05-.54.33-.48 1.94-2.46 1.17-1.53.75-.88v-.13h-.05l-5.14 3.34-.92.12-.39-.37.05-.61.19-.2 1.55-1.06Z"></path></svg>
\ No newline at end of file
diff --git a/apps/client/src/widgets/type_widgets/options/llm/icons/gemini.svg b/apps/client/src/widgets/type_widgets/options/llm/icons/gemini.svg
new file mode 100644
index 0000000000..0fec02f5bb
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/options/llm/icons/gemini.svg
@@ -0,0 +1 @@
+<svg width="24" height="24" fill="currentColor" viewBox="0 0 24 24" transform="" id="injected-svg" xmlns="http://www.w3.org/2000/svg"><!--Boxicons v3.0.8 https://boxicons.com | License https://docs.boxicons.com/free--><path d="M12 2c-.78 5.16-4.84 9.22-10 10 5.16.78 9.22 4.84 10 10 .78-5.16 4.84-9.22 10-10-5.16-.78-9.22-4.84-10-10"></path></svg>
\ No newline at end of file
diff --git a/apps/client/src/widgets/type_widgets/options/llm/icons/openai.svg b/apps/client/src/widgets/type_widgets/options/llm/icons/openai.svg
new file mode 100644
index 0000000000..d1c04f8026
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/options/llm/icons/openai.svg
@@ -0,0 +1 @@
+<svg width="24" height="24" fill="currentColor" viewBox="0 0 24 24" transform="" id="injected-svg" xmlns="http://www.w3.org/2000/svg"><!--Boxicons v3.0.8 https://boxicons.com | License https://docs.boxicons.com/free--><path d="M20.57 10.18c.45-1.36.3-2.85-.43-4.09a5.03 5.03 0 0 0-5.42-2.42 5.05 5.05 0 0 0-7.14-.38c-.66.59-1.15 1.35-1.43 2.19A4.98 4.98 0 0 0 2.82 7.9c-1.1 1.9-.85 4.29.62 5.91-.45 1.36-.3 2.85.43 4.09a5.045 5.045 0 0 0 5.43 2.42A5.03 5.03 0 0 0 13.06 22c2.19 0 4.14-1.41 4.81-3.5a4.98 4.98 0 0 0 3.33-2.42 5.04 5.04 0 0 0-.62-5.89Zm-7.52 10.51c-.88 0-1.72-.31-2.4-.87l.12-.07 3.98-2.3c.2-.12.33-.33.33-.57v-5.61l1.68.97s.03.02.03.04v4.65c0 2.07-1.68 3.74-3.75 3.75ZM5 17.25c-.44-.76-.6-1.65-.45-2.51l.12.07 3.99 2.3c.2.12.45.12.65 0l4.87-2.81v1.94s-.01.04-.03.05l-4.03 2.33A3.756 3.756 0 0 1 5 17.25M3.95 8.58a3.7 3.7 0 0 1 1.97-1.64v4.73c0 .23.12.45.32.56l4.85 2.8-1.68.97h-.06l-4.03-2.32a3.754 3.754 0 0 1-1.37-5.12zm13.83 3.21-4.86-2.82L14.6 8h.06l4.03 2.33a3.743 3.743 0 0 1 1.37 5.12 3.8 3.8 0 0 1-1.94 1.64v-4.73a.67.67 0 0 0-.34-.56Zm1.68-2.52-.12-.07-3.98-2.32a.63.63 0 0 0-.65 0L9.84 9.69V7.75s0-.04.02-.05l4.03-2.32a3.75 3.75 0 0 1 5.12 1.38c.44.76.59 1.64.45 2.51v.02ZM8.93 12.72l-1.68-.97s-.03-.03-.03-.05V7.06c0-2.07 1.68-3.75 3.75-3.74.87 0 1.72.31 2.39.87l-.12.07-3.98 2.3c-.2.12-.33.33-.33.57v5.6Zm.91-1.97 2.17-1.25 2.17 1.25v2.5l-2.16 1.25-2.17-1.25v-2.5Z"></path></svg>
\ No newline at end of file