From 25bde0b468b4f23e4eee70ab355c2e50a466c350 Mon Sep 17 00:00:00 2001 From: Innei Date: Tue, 23 Sep 2025 23:38:36 +0800 Subject: [PATCH] fix(ai-chat): update message container width for improved layout consistency - Adjusted the width calculations in multiple components to use `--ai-chat-message-container-width` instead of the previous layout width. This change ensures a more consistent and responsive design across the AI chat interface. - Updated components including `AIChainOfThought`, `AIDisplayFlowPart`, `AIReasoningPart`, and others to reflect this new width calculation, enhancing the overall user experience. These modifications aim to streamline the layout and improve visual coherence in the chat interface. Signed-off-by: Innei --- .../components/displays/AIChainOfThought.tsx | 4 ++-- .../components/displays/AIDisplayFlowPart.tsx | 2 +- .../components/displays/AIReasoningPart.tsx | 2 +- .../components/layouts/ChatInterface.tsx | 22 +++++++++++++++---- .../components/message/AIMarkdownMessage.tsx | 2 +- .../components/message/AIMessageParts.tsx | 2 +- .../message/ToolInvocationComponent.tsx | 2 +- .../components/message/UserChatMessage.tsx | 2 +- .../message/animated/AnimatedMarkdown.tsx | 1 - 9 files changed, 26 insertions(+), 13 deletions(-) diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/displays/AIChainOfThought.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/displays/AIChainOfThought.tsx index 372e9a9d4..8f73a0080 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/displays/AIChainOfThought.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/displays/AIChainOfThought.tsx @@ -33,7 +33,7 @@ export const AIChainOfThought: React.FC = React.memo( if (!groups || groups.length === 0) return null return ( -
+
= React.memo( collapseId={collapseId} defaultOpen={!currentChainReasoningIsFinished} title={ -
+
{!currentChainReasoningIsFinished ? ( diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/displays/AIDisplayFlowPart.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/displays/AIDisplayFlowPart.tsx index 1cdcbb4bb..135f8d940 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/displays/AIDisplayFlowPart.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/displays/AIDisplayFlowPart.tsx @@ -66,7 +66,7 @@ export const AIDisplayFlowPart = toolMemo(({ part }: { part: ToolWithState }, [nodes, edges, colorMode, present]) return ( -
+
= React.memo(({ tex return (
-
+
           {text}
diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatInterface.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatInterface.tsx
index b23766e0f..771c64227 100644
--- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatInterface.tsx
+++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatInterface.tsx
@@ -9,7 +9,7 @@ import { ErrorBoundary } from "@sentry/react"
 import type { EditorState, LexicalEditor } from "lexical"
 import { AnimatePresence } from "motion/react"
 import { nanoid } from "nanoid"
-import type { FC, Ref } from "react"
+import type { FC, RefObject } from "react"
 import { Suspense, use, useEffect, useLayoutEffect, useRef, useState } from "react"
 import { useEventCallback, useEventListener } from "usehooks-ts"
 
@@ -316,7 +316,7 @@ const ChatInterfaceContent = ({ centerInputOnEmpty }: ChatInterfaceProps) => {
                         : undefined,
                     }}
                   >
-                    
+                    } />
 
                     {(status === "submitted" || status === "streaming") && (
                       
@@ -385,11 +385,25 @@ export const ChatInterface = (props: ChatInterfaceProps) => (
   
 )
 
-const Messages: FC<{ contentRef?: Ref }> = ({ contentRef }) => {
+const Messages: FC<{ contentRef?: RefObject }> = ({ contentRef }) => {
   const messages = useMessages()
 
+  const [messageContainerWidth, setMessageContainerWidth] = useState(0)
+
+  useLayoutEffect(() => {
+    if (!contentRef) return
+    setMessageContainerWidth(contentRef.current?.clientWidth ?? 0)
+  }, [contentRef])
   return (
-    
+
{messages.map((message, index) => { const isLastMessage = index === messages.length - 1 return ( diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/AIMarkdownMessage.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/AIMarkdownMessage.tsx index 0030291cd..2b2958eeb 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/AIMarkdownMessage.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/AIMarkdownMessage.tsx @@ -17,7 +17,7 @@ export const AIMarkdownStreamingMessage = memo( const className = tw`prose max-w-full dark:prose-invert prose-sm prose-h1:text-2xl prose-h2:text-xl prose-h2:mt-2 prose-h3:text-lg prose-h4:text-base prose-h5:text-base prose-h6:text-sm prose-li:list-disc prose-li:marker:text-accent prose-hr:border-border prose-hr:mx-8 - w-[calc(var(--ai-chat-layout-width,65ch))] + w-[calc(var(--ai-chat-message-container-width,65ch))] prose-pre:text-base ` diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/AIMessageParts.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/AIMessageParts.tsx index ed11f5bb7..2ac82af46 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/AIMessageParts.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/AIMessageParts.tsx @@ -122,7 +122,7 @@ export const AIMessageParts: React.FC = React.memo( case "tool-displayFlowChart": { const loadingElement = ( -
+
diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/ToolInvocationComponent.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/ToolInvocationComponent.tsx index 95866898d..cd294a89e 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/ToolInvocationComponent.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/ToolInvocationComponent.tsx @@ -22,7 +22,7 @@ export const ToolInvocationComponent: React.FC = R
-
+
diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/UserChatMessage.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/UserChatMessage.tsx index 51b3b9e78..39c3fee40 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/UserChatMessage.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/UserChatMessage.tsx @@ -193,7 +193,7 @@ export const UserChatMessage: React.FC = React.memo(({ mes exit={{ opacity: 0, scale: 0.98 }} transition={{ duration: 0.15, ease: "easeOut" }} > -
+