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
refactor(llm): share the disclosure line between thoughts and tool calls
Elian Doran14a3d230f710
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.css b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.cssindex 87f7f915de..5c39196ff0 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.css+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.css@@ -200,44 +200,9 @@ body.background-effects.theme-supports-background-effects .llm-chat-message-usermargin-top: 0.75rem;}+/* The disclosure line itself is `.expandable-line` in ExpandableCard.css. */.llm-chat-thinking {margin: 0.25rem 0;- font-size: 0.85rem;- color: var(--muted-text-color);-- /* Top alignment with a shared line height keeps the icons on the first line of the label,- whether it wraps or not. */- .expandable-section-summary,- .llm-chat-thinking-header {- display: flex;- align-items: flex-start;- gap: 0.4rem;- width: fit-content;- max-width: 100%;- padding: 0.15rem 0;- font-weight: normal;- line-height: 1.4rem;-- > .bx {- font-size: 1rem;- line-height: inherit;- margin-right: 0;- }-- /* The brain and the live spinner share a size, so a thought keeps its place when it stops streaming. */- > .bx-brain,- > .bx-loader {- font-size: 0.9rem;- }- }-- .expandable-section-summary:hover {- color: var(--main-text-color);- }-- .expandable-section-chevron {- margin-left: 0;- }/* `text-overflow` needs a block container: as a flex container the label never shows the ellipsis. */.expandable-section-label {@@ -273,13 +238,6 @@ body.background-effects.theme-supports-background-effects .llm-chat-message-userwhite-space: nowrap;}-/* The left margin centers the rule under the 0.9rem icon of the line above. */-.llm-chat-thinking-content {- margin: 0.15rem 0 0.25rem 0.45rem;- padding-left: 0.85rem;- border-left: 2px solid var(--main-border-color);-}-/* Aligning the content to the end clips the overflow at the top, keeping the newest lines in view. */.llm-chat-thinking-live .llm-chat-thinking-content {display: flex;diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsxindex faee0d206d..4499a72b93 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx@@ -130,12 +130,12 @@ function CitationsSection({ citations }: { citations: LlmCitation[] }) {function ThinkingCard({ content, isLive }: { content: string; isLive?: boolean }) {if (isLive) {return (- <div className="llm-chat-thinking llm-chat-thinking-live">- <div className="llm-chat-thinking-header">+ <div className="expandable-line llm-chat-thinking llm-chat-thinking-live">+ <div className="expandable-line-header"><LoadingSpinner /><span className="llm-chat-thinking-title">{latestThinkingTitle(content) ?? t("llm_chat.thinking")}</span></div>- <div className="llm-chat-thinking-content">+ <div className="expandable-line-body llm-chat-thinking-content"><TextBlockContent content={content} /></div></div>@@ -148,7 +148,7 @@ function ThinkingCard({ content, isLive }: { content: string; isLive?: boolean }}return (- <ExpandableSection className="llm-chat-thinking" icon="bx bx-brain" label={label || t("llm_chat.thought_process")}>+ <ExpandableSection variant="line" className="llm-chat-thinking" icon="bx bx-brain" label={label || t("llm_chat.thought_process")}><div className="llm-chat-thinking-content"><TextBlockContent content={body} /></div>@@ -174,6 +174,7 @@ function ThinkingLine({ label }: { label: string }) {return (<ExpandableSection+ variant="line"className={`llm-chat-thinking ${fits ? "llm-chat-thinking-fits" : ""}`}icon="bx bx-brain"label={<span ref={labelRef} className="llm-chat-thinking-label">{label}</span>}diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ExpandableCard.css b/apps/client/src/widgets/type_widgets/llm_chat/ExpandableCard.cssindex e237bd2244..51c534dafe 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ExpandableCard.css+++ b/apps/client/src/widgets/type_widgets/llm_chat/ExpandableCard.css@@ -9,7 +9,7 @@}/* Expandable section — collapsible details within a card */-.expandable-section + .expandable-section {+.expandable-card .expandable-section + .expandable-section {border-top: 1px solid var(--main-border-color);}@@ -55,3 +55,48 @@.expandable-section-body {padding: 0;}++/* Disclosure line — a bare muted section. `.expandable-line-header` and `.expandable-line-body`+ give the same shape to a line that does not fold, such as the thought being streamed. */+.expandable-line {+ font-size: 0.85rem;+ color: var(--muted-text-color);+}++/* Top alignment with a shared line height keeps the icons on the first line of the label,+ whether it wraps or not. */+.expandable-line > .expandable-section-summary,+.expandable-line-header {+ display: flex;+ align-items: flex-start;+ gap: 0.4rem;+ width: fit-content;+ max-width: 100%;+ padding: 0.15rem 0;+ font-weight: normal;+ line-height: 1.4rem;++ > .bx {+ font-size: 0.9rem;+ line-height: inherit;+ margin-right: 0;+ }++ > .expandable-section-chevron {+ font-size: 1rem;+ margin-left: 0;+ }+}++/* `:where()` keeps the hover below a variant's own color, such as an errored tool call's. */+.expandable-line > .expandable-section-summary:where(:hover) {+ color: var(--main-text-color);+}++/* The left margin centers the rule under the 0.9rem icon of the line above. */+.expandable-line > .expandable-section-body,+.expandable-line-body {+ margin: 0.15rem 0 0.25rem 0.45rem;+ padding-left: 0.85rem;+ border-left: 2px solid var(--main-border-color);+}diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ExpandableCard.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ExpandableCard.tsxindex fb6976ad66..d0c5739299 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ExpandableCard.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ExpandableCard.tsx@@ -9,12 +9,17 @@ interface ExpandableSectionProps {/** Whether the section is expanded on initial render. */open?: boolean;children?: ComponentChildren;+ /**+ * `card` is a row of an ExpandableCard; `line` is a bare muted line whose body hangs off a rule+ * under the icon, as used by thoughts and tool calls.+ */+ variant?: "card" | "line";}-/** A collapsible section within an ExpandableCard. */-export function ExpandableSection({ icon, label, className, open, children }: ExpandableSectionProps) {+/** A collapsible section, either a row of an ExpandableCard or a standalone disclosure line. */+export function ExpandableSection({ icon, label, className, open, children, variant = "card" }: ExpandableSectionProps) {return (- <details className={`expandable-section ${className ?? ""}`} open={open}>+ <details className={`expandable-section ${variant === "line" ? "expandable-line" : ""} ${className ?? ""}`} open={open}><summary className="expandable-section-summary"><span className={icon} /><span className="expandable-section-label">{label}</span>diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.css b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.cssindex 6be85f85be..dd3b6191f8 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.css+++ b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.css@@ -1,44 +1,6 @@-/* Tool calls share the thought's disclosure line (`.llm-chat-thinking` in ChatMessage.css). */+/* Each call is an `.expandable-line` (ExpandableCard.css). */.llm-chat-tool-calls {margin: 0.25rem 0;- font-size: 0.85rem;- color: var(--muted-text-color);-}--.llm-chat-tool-call {- & + & {- border-top: none;- }-- > .expandable-section-summary {- width: fit-content;- max-width: 100%;- padding: 0.15rem 0;- gap: 0.4rem;- font-weight: normal;- line-height: 1.4rem;-- > .bx {- font-size: 0.9rem;- line-height: inherit;- margin-right: 0;- }-- > .expandable-section-chevron {- margin-left: 0;- }-- &:hover {- color: var(--main-text-color);- }- }-- /* The left margin centers the rule under the 0.9rem icon of the line above. */- > .expandable-section-body {- margin: 0.15rem 0 0.25rem 0.45rem;- padding-left: 0.85rem;- border-left: 2px solid var(--main-border-color);- }}.llm-chat-tool-call-detail {diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsxindex 507dd3cd54..72be3254fa 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsx@@ -198,6 +198,7 @@ function ToolCallSection({ toolCall }: { toolCall: ToolCall }) {<ExpandableSectionicon={toolCallIcon(toolCall)}label={<ToolCallLabel toolCall={toolCall} />}+ variant="line"className={`llm-chat-tool-call ${hasError ? "llm-chat-tool-call-error" : ""}`}open={noteContentEdits ? isSmallEdit(noteContentEdits) : isStreamingInput || undefined}>@@ -243,7 +244,7 @@ function ToolCallGroupSection({ toolCalls }: { toolCalls: ToolCall[] }) {);return (- <ExpandableSection icon={icon} label={label} className="llm-chat-tool-call llm-chat-tool-call-group">+ <ExpandableSection variant="line" icon={icon} label={label} className="llm-chat-tool-call llm-chat-tool-call-group">{toolCalls.map((tc, idx) => (<ToolCallSection key={tc.id ?? idx} toolCall={tc} />))}