Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(llm_chat): show the Tools menu toggle as a dropdown
Elian Doran12bb9963f6fa
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.css b/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.cssindex bd75f31b59..12df72dba4 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.css+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.css@@ -1,3 +1,11 @@+.llm-chat-tools-icon {+ line-height: inherit;++ &.llm-chat-tools-on {+ color: var(--link-color);+ }+}+.tn-dropdown-portal.llm-chat-tools {.dropdown-item .description {max-width: 18rem;diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.spec.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.spec.tsxindex 7179aa5a51..600a6db120 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.spec.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.spec.tsx@@ -4,13 +4,13 @@ import { afterEach, describe, expect, it, vi } from "vitest";vi.mock("../../../services/i18n.js", () => ({ t: (key: string) => key }));-// Renders the toggle's class and tooltip, and the menu, without the popup machinery.+// Renders the toggle's face, class and tooltip, and the menu, without the popup machinery.vi.mock("../../react/Dropdown.js", () => ({- default: ({ title, buttonClassName, children }: {- title?: string; buttonClassName?: string; children: ComponentChildren;+ default: ({ text, title, buttonClassName, children }: {+ text?: ComponentChildren; title?: string; buttonClassName?: string; children: ComponentChildren;}) => (<div className="dropdown-stub">- <button className={buttonClassName} title={title} />+ <button className={buttonClassName} title={title}>{text}</button><div className="menu">{children}</div></div>)@@ -43,8 +43,14 @@ function renderMenu(props: Partial<Parameters<typeof ChatToolsDropdown>[0]> = {}/>, target));const rows = [ ...target.querySelectorAll<HTMLElement>(".menu .dropdown-item") ];+ const toggle = target.querySelector<HTMLButtonElement>(".dropdown-stub > button");return {- toggle: target.querySelector<HTMLButtonElement>(".dropdown-stub > button"),+ toggle,+ isToggleOn: () => {+ const icon = toggle?.querySelector(".llm-chat-tools-icon");+ expect(icon).not.toBeNull();+ return icon?.classList.contains("llm-chat-tools-on");+ },noteRow: rows.find((row) => row.textContent?.includes("llm_chat.note_tools")),webRow: rows.find((row) => row.textContent?.includes("llm_chat.web_search")),onNoteToolsChange,@@ -55,15 +61,17 @@ function renderMenu(props: Partial<Parameters<typeof ChatToolsDropdown>[0]> = {}const isOn = (row: HTMLElement | undefined) => row?.querySelector<HTMLInputElement>("input[type='checkbox']")?.checked;describe("ChatToolsDropdown", () => {- it("shows a switch per tool group, and marks the toggle active while any is on", () => {+ it("shows a switch per tool group, and marks the toggle while any is on", () => {const off = renderMenu();expect(off.toggle?.title).toBe("llm_chat.tools");- expect(off.toggle?.classList.contains("active")).toBe(false);+ // The compact combo box of the model picker, which draws the dropdown caret.+ expect(off.toggle?.classList.contains("llm-chat-model-select")).toBe(true);+ expect(off.isToggleOn()).toBe(false);expect(isOn(off.noteRow)).toBe(false);expect(isOn(off.webRow)).toBe(false);const on = renderMenu({ enableWebSearch: true });- expect(on.toggle?.classList.contains("active")).toBe(true);+ expect(on.isToggleOn()).toBe(true);expect(isOn(on.noteRow)).toBe(false);expect(isOn(on.webRow)).toBe(true);});@@ -80,9 +88,9 @@ describe("ChatToolsDropdown", () => {});it("shows web search off and disabled, with the reason, when the model cannot combine it", async () => {- const { toggle, webRow, onWebSearchChange } = renderMenu({ enableWebSearch: true, webSearchUnavailableReason: "Not on Gemini" });+ const { isToggleOn, webRow, onWebSearchChange } = renderMenu({ enableWebSearch: true, webSearchUnavailableReason: "Not on Gemini" });- expect(toggle?.classList.contains("active")).toBe(false);+ expect(isToggleOn()).toBe(false);expect(isOn(webRow)).toBe(false);expect(webRow?.classList.contains("disabled")).toBe(true);expect(webRow?.querySelector(".description")?.textContent).toBe("Not on Gemini");diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.tsxindex 3a9a39ba7a..019550ea6d 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatToolsDropdown.tsx@@ -5,10 +5,12 @@ import clsx from "clsx";import { t } from "../../../services/i18n.js";import Dropdown from "../../react/Dropdown.js";import { FormListToggleableItem } from "../../react/FormList.js";+import Icon from "../../react/Icon.js";/*** The Tools menu of the chat input bar: one switch per group of tools the model can reach this- * turn. Each row stops its click, so the menu stays open while several are flipped.+ * turn. Each row stops its click, so the menu stays open while several are flipped. Its toggle+ * shares the compact combo box styling of the model picker beside it.*/export default function ChatToolsDropdown({ enableNoteTools, enableWebSearch, onNoteToolsChange, onWebSearchChange, webSearchUnavailableReason, disabled }: {enableNoteTools: boolean;@@ -24,14 +26,12 @@ export default function ChatToolsDropdown({ enableNoteTools, enableWebSearch, onreturn (<Dropdown- buttonClassName={clsx("bx bx-shield-quarter llm-chat-capability llm-chat-tools-button", anyActive && "active")}+ text={<Icon icon="bx bx-shield-quarter" className={clsx("llm-chat-tools-icon", anyActive && "llm-chat-tools-on")} />}+ buttonClassName="llm-chat-model-select llm-chat-tools-button"className="llm-chat-tools"title={t("llm_chat.tools")}titlePosition="top"placement="top-start"- iconAction- hideToggleArrow- noSelectButtonStyledisabled={disabled}><FormListToggleableItem