From 3f0d49ceb3de99810274d6f037283182af4244bc Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 8 Dec 2025 13:53:37 -0600 Subject: [PATCH] Render image below tool --- src/components/AIMessageItem.tsx | 60 ++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/src/components/AIMessageItem.tsx b/src/components/AIMessageItem.tsx index 22ed0818..ffecef91 100644 --- a/src/components/AIMessageItem.tsx +++ b/src/components/AIMessageItem.tsx @@ -59,9 +59,8 @@ export const AIMessageItem = memo(({ isCurrentlyLoading = false, toolCall, }: AIMessageItemProps) => { - // Check if this is a generate_image tool to expand by default - const isGenerateImageTool = message.role === 'tool' && toolCall?.type === 'function' && toolCall.function.name === 'generate_image'; - const [isToolExpanded, setIsToolExpanded] = useState(isGenerateImageTool); + // All tools start collapsed by default + const [isToolExpanded, setIsToolExpanded] = useState(false); const [isReasoningExpanded, setIsReasoningExpanded] = useState(false); const [expandedImageUrl, setExpandedImageUrl] = useState(null); const { displayTheme } = useTheme(); @@ -300,26 +299,12 @@ export const AIMessageItem = memo(({ } if (toolName === 'generate_image') { - // Parse "Generated image: /tmp/filename.png" from content - const match = content.match(/Generated image:\s*(\/tmp\/[^\s\n]+)/); - if (match) { - const imagePath = match[1]; - const filename = imagePath.split('/').pop() || imagePath; - - return ( -
- setExpandedImageUrl(imagePath)} - /> -
- ); - } else { - // Image generation failed - show error in place - return ; - } + // For generate_image, when expanded show the full prompt + return ( +
+
{typeof toolArgs.prompt === 'string' ? toolArgs.prompt : 'No prompt provided'}
+
+ ); } // Default rendering for other tools @@ -332,6 +317,32 @@ export const AIMessageItem = memo(({ ); }; + // Special rendering for generate_image - always show image below the tool + const renderImageBelowTool = () => { + if (toolName !== 'generate_image') return null; + + // Parse "Generated image: /tmp/filename.png" from content + const match = content.match(/Generated image:\s*(\/tmp\/[^\s\n]+)/); + if (match) { + const imagePath = match[1]; + const filename = imagePath.split('/').pop() || imagePath; + + return ( +
+ setExpandedImageUrl(imagePath)} + /> +
+ ); + } else { + // Image generation failed - show error in place + return ; + } + }; + // Regular tool message rendering return (
{/* -mt-2 to make it snug with the previous assistant message */} @@ -349,6 +360,9 @@ export const AIMessageItem = memo(({ {isToolExpanded && renderSpecialContent()} + + {/* Always render image below for generate_image tool */} + {renderImageBelowTool()}
); }