Skip to content

Build your personal knowledge base with Trilium Notes

feat(llm): draw the icons an icon search found

Elian Dorana54ca48dbf46
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 8ec0a65bdf..f46982750c 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2677,7 +2677,9 @@
"attachment_count_one": "{{count}} attachment",
"attachment_count_other": "{{count}} attachments",
"attribute_count_one": "({{count}} attribute)",
- "attribute_count_other": "({{count}} attributes)"
+ "attribute_count_other": "({{count}} attributes)",
+ "search_icons_count_one": "({{count}} icon)",
+ "search_icons_count_other": "({{count}} icons)"
},
"sidebar_chat": {
"title": "AI Chat",
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.spec.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.spec.tsx
index 07ee4e3a7b..186cb1de9d 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.spec.tsx
@@ -576,4 +576,26 @@ describe("ToolCallCard", () => {
expect(pills(deleted)).toEqual([ "#temp=1" ]);
expect(deleted?.querySelector(".llm-chat-attribute")?.classList.contains("llm-chat-attribute-deleted")).toBe(true);
});
+
+ it("shows the icons an icon search found, and how many it left out", () => {
+ const target = renderCard([ {
+ id: "1",
+ toolName: "search_icons",
+ input: { query: "rocket", limit: 2 },
+ result: JSON.stringify({
+ totalResults: 5,
+ results: [
+ { iconClass: "bx bx-rocket", terms: [ "rocket", "launch" ] },
+ { iconClass: "bx bxs-rocket", terms: [ "rocket" ] }
+ ]
+ })
+ } ]);
+ const line = target.querySelector("details.llm-chat-tool-call");
+ expect(line?.querySelector(".llm-chat-tool-call-result-count")?.textContent)
+ .toBe("llm_chat.search_icons_count{\"count\":5}");
+ const icons = [ ...(line?.querySelectorAll(".llm-chat-icon-results .tn-icon") ?? []) ];
+ expect(icons.map(icon => [ ...icon.classList ].filter(c => c.startsWith("bx")).join(" "))).toEqual([ "bx bx-rocket", "bx bxs-rocket" ]);
+ expect(line?.querySelector(".llm-chat-note-results-more")?.textContent)
+ .toBe("llm_chat.search_notes_limited{\"count\":5,\"limit\":2}");
+ });
});
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallViews.css b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallViews.css
index 423ee75f9f..eee9b9c8ef 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallViews.css
+++ b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallViews.css
@@ -148,3 +148,26 @@
.expandable-section-label > .llm-chat-attribute {
font-size: 0.75rem;
}
+
+/* The icons a `search_icons` call found. */
+.llm-chat-icon-grid {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 0.25rem;
+ padding: 0.2rem 0;
+
+ > .tn-icon {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 2rem;
+ height: 2rem;
+ border-radius: 6px;
+ font-size: 1.3rem;
+ color: var(--main-text-color);
+
+ &:hover {
+ background: var(--hover-item-background-color);
+ }
+ }
+}
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallViews.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallViews.tsx
index 7c0b6f162b..5eb5a87e19 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallViews.tsx
+++ b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallViews.tsx
@@ -10,6 +10,7 @@ import { NOTE_TYPES } from "../../../services/note_types.js";
import { openInAppHelpFromUrl } from "../../../services/utils.js";
import CodeBlock from "../../react/CodeBlock.js";
import { useNote } from "../../react/hooks.js";
+import { TooltipIcon } from "../../react/Icon.js";
import { NewNoteLink } from "../../react/NoteLink.js";
import { ReadOnlyTextContent } from "../text/ReadOnlyText.js";
import { renderMarkdown } from "./chat_markdown.js";
@@ -105,6 +106,17 @@ export function getToolCallView(toolCall: ToolCall): ToolCallView | null {
body: search.results.length > 0 ? <NoteSearchResults {...search} /> : undefined
};
}
+ case "search_icons": {
+ const result = parseIconSearchResult(toolCall.result);
+ if (!result) return null;
+ const { limit } = toolCall.input;
+ return {
+ summary: t("llm_chat.search_icons_count", { count: result.totalResults }),
+ body: result.icons.length > 0
+ ? <IconSearchResults {...result} limit={typeof limit === "number" ? limit : result.icons.length} />
+ : undefined
+ };
+ }
case "get_child_notes": {
const children = parseChildNotesResult(toolCall.result);
if (!children) return null;
@@ -201,6 +213,36 @@ function NoteSearchResults({ totalResults, results, ancestorNoteId, limit, isHel
);
}
+interface IconSearchResult {
+ totalResults: number;
+ icons: string[];
+}
+
+/** The icons a `search_icons` call found, drawn rather than named, with each class as its tooltip. */
+function IconSearchResults({ totalResults, icons, limit }: IconSearchResult & { limit: number }) {
+ return (
+ <div className="llm-chat-icon-results">
+ <div className="llm-chat-icon-grid">
+ {icons.map((iconClass) => <TooltipIcon key={iconClass} icon={iconClass} tooltip={iconClass} />)}
+ </div>
+ {totalResults > icons.length && (
+ <div className="llm-chat-note-results-more">
+ {t("llm_chat.search_notes_limited", { count: totalResults, limit })}
+ </div>
+ )}
+ </div>
+ );
+}
+
+function parseIconSearchResult(result: string): IconSearchResult | null {
+ const parsed = parseJson(result);
+ if (!isRecord(parsed) || typeof parsed.totalResults !== "number" || !Array.isArray(parsed.results)) return null;
+ const icons = parsed.results
+ .map((item) => (isRecord(item) && typeof item.iconClass === "string" ? item.iconClass : null))
+ .filter((iconClass): iconClass is string => !!iconClass);
+ return { totalResults: parsed.totalResults, icons };
+}
+
function ChildNoteList({ notes }: { notes: ChildNote[] }) {
return (
<div className="llm-chat-note-results">
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 df90b9875c..6ae10be7d0 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
@@ -196,17 +196,17 @@ class="admonition note">
title struck through, a deleted note its title struck through, a moved
note where it was moved from and to, and an attribute the AI read, set
or deleted as a pill (struck through once deleted). A line folds open only
- when there is something to read inline: the notes a search found, the type,
- attributes or start of the content of a note the AI read, all the attributes
- of a note, the User Guide pages the AI looked up (which open in the help
- panel), the children or the whole subtree of a note, what the AI wrote
- into a note it created, rewrote or added to, the changes of an edit, or
- the reason a tool failed. A search also shows how many notes it found,
- the part of the tree it was confined to, if any, and how many of the matches
- the AI asked for; each note it lists opens with a click. To see exactly
- what the AI sent to a tool and what it got back, hover the line and press
- the <span class="tn-icon bx bx-code-alt"></span> button next to it; on touch
- screens the button is always shown.</p>
+ when there is something to read inline: the notes a search found, the icons
+ an icon search found, the type, attributes or start of the content of a
+ note the AI read, all the attributes of a note, the User Guide pages the
+ AI looked up (which open in the help panel), the children or the whole
+ subtree of a note, what the AI wrote into a note it created, rewrote or
+ added to, the changes of an edit, or the reason a tool failed. A search
+ also shows how many notes it found, the part of the tree it was confined
+ to, if any, and how many of the matches the AI asked for; each note it
+ lists opens with a click. To see exactly what the AI sent to a tool and
+ what it got back, hover the line and press the <span class="tn-icon bx bx-code-alt"></span> button
+ next to it; on touch screens the button is always shown.</p>
<aside class="admonition warning">
<p>Currently there is <strong>no permission management</strong> implemented
for note tools, meaning that the LLM could potentially remove existing
diff --git a/docs/User Guide/User Guide/AI.md b/docs/User Guide/User Guide/AI.md
index a199ac9d54..8db0d34b97 100644
--- a/docs/User Guide/User Guide/AI.md
+++ b/docs/User Guide/User Guide/AI.md
@@ -133,7 +133,7 @@ Here are a few tools that Trilium provides for the LLM:
* Get the content of an attachment.
* Skills (see the dedicated section).
-Each tool the AI uses appears in the chat as a single line naming the tool and the note or query it worked on; a renamed note shows its previous title struck through, a deleted note its title struck through, a moved note where it was moved from and to, and an attribute the AI read, set or deleted as a pill (struck through once deleted). A line folds open only when there is something to read inline: the notes a search found, the type, attributes or start of the content of a note the AI read, all the attributes of a note, the User Guide pages the AI looked up (which open in the help panel), the children or the whole subtree of a note, what the AI wrote into a note it created, rewrote or added to, the changes of an edit, or the reason a tool failed. A search also shows how many notes it found, the part of the tree it was confined to, if any, and how many of the matches the AI asked for; each note it lists opens with a click. To see exactly what the AI sent to a tool and what it got back, hover the line and press the <span class="tn-icon bx bx-code-alt"></span> button next to it; on touch screens the button is always shown.
+Each tool the AI uses appears in the chat as a single line naming the tool and the note or query it worked on; a renamed note shows its previous title struck through, a deleted note its title struck through, a moved note where it was moved from and to, and an attribute the AI read, set or deleted as a pill (struck through once deleted). A line folds open only when there is something to read inline: the notes a search found, the icons an icon search found, the type, attributes or start of the content of a note the AI read, all the attributes of a note, the User Guide pages the AI looked up (which open in the help panel), the children or the whole subtree of a note, what the AI wrote into a note it created, rewrote or added to, the changes of an edit, or the reason a tool failed. A search also shows how many notes it found, the part of the tree it was confined to, if any, and how many of the matches the AI asked for; each note it lists opens with a click. To see exactly what the AI sent to a tool and what it got back, hover the line and press the <span class="tn-icon bx bx-code-alt"></span> button next to it; on touch screens the button is always shown.
> [!WARNING]
> Currently there is **no permission management** implemented for note tools, meaning that the LLM could potentially remove existing notes or clutter the tree with notes. Generally most actions are easily reversible (deleting the notes, restoring deleted notes, reverting modifications to a note), but there are some that are harder to revert (e.g. setting an attribute because there is no attribute history).