Skip to content

Build your personal knowledge base with Trilium Notes

feat(llm): show tool calls as disclosure lines like thoughts

Elian Doran99b5ae9d93dc
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.css b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.css
index 2ae5770ec2..6be85f85be 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.css
+++ b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.css
@@ -1,26 +1,43 @@
-/* Tool call specific styles (card/section structure is in ExpandableCard.css) */
+/* Tool calls share the thought's disclosure line (`.llm-chat-thinking` in ChatMessage.css). */
+.llm-chat-tool-calls {
+ margin: 0.25rem 0;
+ font-size: 0.85rem;
+ color: var(--muted-text-color);
+}
-.expandable-card.llm-chat-tool-call-card {
- border-radius: 6px;
+.llm-chat-tool-call {
+ & + & {
+ border-top: none;
+ }
- .expandable-section-summary {
- padding: 0.25rem 0.6rem;
+ > .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;
- margin-right: 0.1rem;
- color: var(--muted-text-color);
+ line-height: inherit;
+ margin-right: 0;
+ }
+
+ > .expandable-section-chevron {
+ margin-left: 0;
}
&:hover {
- background: var(--hover-item-background-color);
+ color: var(--main-text-color);
}
}
- .expandable-section-body {
- border-top: 1px solid var(--main-border-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);
}
}
@@ -43,15 +60,11 @@
/* Section body (input + result) */
.llm-chat-tool-call-input,
.llm-chat-tool-call-result {
- padding: 0.4rem 0.6rem;
+ padding: 0.25rem 0;
max-height: 300px;
overflow: auto;
}
-.llm-chat-tool-call-result {
- border-top: 1px solid var(--main-border-color);
-}
-
.expandable-section-body pre {
margin: 0;
padding: 0;
@@ -116,8 +129,8 @@
}
/* Tool call error styling */
-.llm-chat-tool-call-error > .expandable-section-summary,
-.expandable-card.llm-chat-tool-call-card .llm-chat-tool-call-error > .expandable-section-summary > .bx {
+/* Outranks the summary's hover color, so an errored call stays red. */
+.llm-chat-tool-call.llm-chat-tool-call-error > .expandable-section-summary {
color: var(--danger-color, #dc3545);
}
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 6d0d5b8d45..f718c19398 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
@@ -39,4 +39,17 @@ describe("ToolCallCard", () => {
expect([ ...card.querySelectorAll(".llm-chat-tool-call-detail") ].map(detail => detail.textContent))
.toEqual([ "rocket", "weather Sibiu", "https://triliumnotes.org" ]);
});
+
+ it("lists the calls as bare disclosure lines rather than in a card", () => {
+ const target = renderCard([
+ { id: "1", toolName: "get_note", input: { noteId: "a" }, result: "{}" },
+ { id: "2", toolName: "get_note", input: { noteId: "b" }, result: "{}" },
+ { id: "3", toolName: "web_search", input: { query: "rocket" }, result: "Sunny" }
+ ]);
+ expect(target.querySelector(".expandable-card")).toBeNull();
+ const lines = [ ...(target.querySelector(".llm-chat-tool-calls")?.children ?? []) ];
+ expect(lines.map(line => line instanceof HTMLDetailsElement && line.classList.contains("llm-chat-tool-call")))
+ .toEqual([ true, true ]);
+ expect(lines[0]?.querySelectorAll(".expandable-section-body > details.llm-chat-tool-call")).toHaveLength(2);
+ });
});
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsx
index 44e7cff695..507dd3cd54 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsx
+++ b/apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsx
@@ -5,7 +5,7 @@ import { Trans } from "react-i18next";
import { t } from "../../../services/i18n.js";
import { NewNoteLink } from "../../react/NoteLink.js";
import { EditNoteContentDiff, isSmallEdit, parseNoteContentEdits } from "./EditNoteContentDiff.js";
-import { ExpandableCard, ExpandableSection } from "./ExpandableCard.js";
+import { ExpandableSection } from "./ExpandableCard.js";
import type { ToolCall } from "./llm_chat_types.js";
interface ToolCallContext {
@@ -198,7 +198,7 @@ function ToolCallSection({ toolCall }: { toolCall: ToolCall }) {
<ExpandableSection
icon={toolCallIcon(toolCall)}
label={<ToolCallLabel toolCall={toolCall} />}
- className={hasError ? "llm-chat-tool-call-error" : ""}
+ className={`llm-chat-tool-call ${hasError ? "llm-chat-tool-call-error" : ""}`}
open={noteContentEdits ? isSmallEdit(noteContentEdits) : isStreamingInput || undefined}
>
<div className={`llm-chat-tool-call-input ${isStreamingInput ? "llm-chat-tool-call-input-streaming" : ""}`}>
@@ -243,7 +243,7 @@ function ToolCallGroupSection({ toolCalls }: { toolCalls: ToolCall[] }) {
);
return (
- <ExpandableSection icon={icon} label={label} className="llm-chat-tool-call-group">
+ <ExpandableSection 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} />
))}
@@ -267,16 +267,16 @@ function groupByToolName(toolCalls: ToolCall[]): Array<ToolCall | ToolCall[]> {
return groups;
}
-/** A card that groups one or more sequential tool calls together. */
+/** One or more sequential tool calls, each a disclosure line like a thought. */
export default function ToolCallCard({ toolCalls }: { toolCalls: ToolCall[] }) {
const groups = groupByToolName(toolCalls);
return (
- <ExpandableCard className="llm-chat-tool-call-card">
+ <div className="llm-chat-tool-calls">
{groups.map((group, idx) => (
Array.isArray(group)
? <ToolCallGroupSection key={idx} toolCalls={group} />
: <ToolCallSection key={group.id ?? idx} toolCall={group} />
))}
- </ExpandableCard>
+ </div>
);
}