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
feat(llm): space the final reply off the steps before it
Elian Doranb28abf3731c7
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.css b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.cssindex 5c39196ff0..ac8f75c7e7 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.css+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.css@@ -251,6 +251,11 @@ body.background-effects.theme-supports-background-effects .llm-chat-message-user}}+/* The text after the last thought or tool call, set apart from the steps that led to it. */+.llm-chat-reply {+ margin-top: 1rem;+}+/* Markdown styles */.llm-chat-markdown {line-height: 1.6;diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.spec.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.spec.tsxindex 14ea4dd392..0a7078987e 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.spec.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.spec.tsx@@ -145,4 +145,18 @@ describe("ChatMessage thinking", () => {expect(card?.querySelector(".expandable-section-label")?.textContent).toBe("Retrieving PC hostname with command");expect(card?.querySelector(".llm-chat-thinking-content .markdown-stub")?.textContent).toContain("<code>/etc/hostname</code>");});++ it("marks only the text after the last thought or tool call as the reply", () => {+ const target = renderMessage([+ { type: "thinking", content: "**Inspecting available tool names**" },+ { type: "text", content: "I'll add a French pangram." },+ { type: "tool_call", toolCall: { id: "c1", toolName: "create_note", input: {}, result: "{}" } },+ { type: "text", content: "Added the French pangram." }+ ]);+ const replies = [...target.querySelectorAll(".llm-chat-reply")];+ expect(replies.map(el => el.textContent)).toEqual([ "Added the French pangram." ]);++ const plain = renderMessage([{ type: "text", content: "Hello." }]);+ expect(plain.querySelector(".llm-chat-reply")).toBeNull();+ });});diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsxindex 4499a72b93..d9fcc77c32 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx@@ -335,11 +335,15 @@ function groupContentBlocks(blocks: ContentBlock[]): ContentGroup[] {}function renderContentBlocks(blocks: ContentBlock[], isStreaming?: boolean) {- return groupContentBlocks(blocks).map((group) => {+ const groups = groupContentBlocks(blocks);+ const lastStep = groups.findLastIndex(group => group.type === "thinking" || group.type === "tool_calls");+ const reply = lastStep >= 0 && groups[lastStep + 1]?.type === "text" ? groups[lastStep + 1] : undefined;++ return groups.map((group) => {const isLastBlock = group.index === blocks.length - 1;if (group.type === "text") {return (- <div key={group.index}>+ <div key={group.index} className={group === reply ? "llm-chat-reply" : undefined}><TextBlockContent content={group.block.content} isStreaming={isStreaming && isLastBlock} /></div>);