Skip to content

Build your personal knowledge base with Trilium Notes

feat(llm): show provider logos in the configured providers list

Elian Doran5c13232f0566
diff --git a/apps/client/src/widgets/react/MaskedIcon.css b/apps/client/src/widgets/react/MaskedIcon.css
new file mode 100644
index 0000000000..4ca1d8f410
--- /dev/null
+++ b/apps/client/src/widgets/react/MaskedIcon.css
@@ -0,0 +1,9 @@
+.masked-icon {
+ display: inline-block;
+ flex-shrink: 0;
+ width: var(--masked-icon-size, 1.5em);
+ height: var(--masked-icon-size, 1.5em);
+ background-color: currentColor;
+ -webkit-mask: var(--masked-icon-url) center / contain no-repeat;
+ mask: var(--masked-icon-url) center / contain no-repeat;
+}
diff --git a/apps/client/src/widgets/react/MaskedIcon.tsx b/apps/client/src/widgets/react/MaskedIcon.tsx
new file mode 100644
index 0000000000..e228ec0e04
--- /dev/null
+++ b/apps/client/src/widgets/react/MaskedIcon.tsx
@@ -0,0 +1,12 @@
+import "./MaskedIcon.css";
+
+interface MaskedIconProps {
+ /** URL of an SVG (e.g. an imported `*.svg?url`) rendered monochrome via a CSS mask. */
+ url: string;
+ className?: string;
+}
+
+/** A monochrome icon rendered from an SVG URL via a CSS mask, tinted with `currentColor`. */
+export default function MaskedIcon({ url, className }: MaskedIconProps) {
+ return <span className={`masked-icon ${className ?? ""}`} style={{ "--masked-icon-url": `url("${url}")` }} />;
+}
diff --git a/apps/client/src/widgets/react/SelectableCard.css b/apps/client/src/widgets/react/SelectableCard.css
index 5dc781d6f0..ada9bc222a 100644
--- a/apps/client/src/widgets/react/SelectableCard.css
+++ b/apps/client/src/widgets/react/SelectableCard.css
@@ -32,15 +32,6 @@ body.mobile .selectable-card-grid {
color: var(--active-item-text-color);
}
-.selectable-card-icon {
- flex-shrink: 0;
- width: 1.5em;
- height: 1.5em;
- background-color: currentColor;
- -webkit-mask: var(--card-mask) center / contain no-repeat;
- mask: var(--card-mask) center / contain no-repeat;
-}
-
/* Boxicons-based card icon (used when `icon` is supplied instead of `iconUrl`). */
.selectable-card-bxicon {
flex-shrink: 0;
diff --git a/apps/client/src/widgets/react/SelectableCard.tsx b/apps/client/src/widgets/react/SelectableCard.tsx
index ccd82509da..94be321dd4 100644
--- a/apps/client/src/widgets/react/SelectableCard.tsx
+++ b/apps/client/src/widgets/react/SelectableCard.tsx
@@ -2,6 +2,8 @@ import "./SelectableCard.css";
import type { ComponentChildren } from "preact";
+import MaskedIcon from "./MaskedIcon";
+
export interface SelectableCardProps {
title: ComponentChildren;
description?: ComponentChildren;
@@ -23,7 +25,7 @@ export default function SelectableCard({ title, description, iconUrl, icon, sele
return (
<button type="button" className={`selectable-card ${selected ? "selected" : ""} ${className ?? ""}`} onClick={onSelect}>
{iconUrl
- ? <span className="selectable-card-icon" style={{ "--card-mask": `url("${iconUrl}")` }} />
+ ? <MaskedIcon url={iconUrl} />
: icon ? <span className={`selectable-card-bxicon ${icon}`} /> : null}
<span className="selectable-card-text">
<span className="selectable-card-name">{title}</span>
diff --git a/apps/client/src/widgets/type_widgets/options/llm.css b/apps/client/src/widgets/type_widgets/options/llm.css
new file mode 100644
index 0000000000..70857b61df
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/options/llm.css
@@ -0,0 +1,10 @@
+.llm-provider-name {
+ display: inline-flex;
+ align-items: center;
+ gap: 0.5em;
+}
+
+/* Scale the provider logo down to sit inline with the row label text. */
+.llm-provider-name .masked-icon {
+ --masked-icon-size: 1.2em;
+}
diff --git a/apps/client/src/widgets/type_widgets/options/llm.tsx b/apps/client/src/widgets/type_widgets/options/llm.tsx
index 6b4fe38e2d..749ef4544a 100644
--- a/apps/client/src/widgets/type_widgets/options/llm.tsx
+++ b/apps/client/src/widgets/type_widgets/options/llm.tsx
@@ -1,3 +1,5 @@
+import "./llm.css";
+
import { useCallback, useMemo, useState } from "preact/hooks";
import dialog from "../../../services/dialog";
@@ -8,6 +10,7 @@ import Button from "../../react/Button";
import FormTextBox from "../../react/FormTextBox";
import FormToggle from "../../react/FormToggle";
import { useTriliumOption, useTriliumOptionBool } from "../../react/hooks";
+import MaskedIcon from "../../react/MaskedIcon";
import NoItems from "../../react/NoItems";
import OptionsPageHeader from "./components/OptionsPageHeader";
import OptionsRow, { OptionsRowWithToggle } from "./components/OptionsRow";
@@ -162,7 +165,12 @@ function ProviderList({ providers, onDelete }: ProviderListProps) {
<OptionsRow
key={provider.id}
name="llm-provider"
- label={provider.name}
+ label={
+ <span className="llm-provider-name">
+ {providerType?.iconUrl && <MaskedIcon url={providerType.iconUrl} />}
+ {provider.name}
+ </span>
+ }
description={providerType?.name || provider.provider}
>
<ActionButton