From 994da4b58de9fdced22d8b576a08c915a9de43cf Mon Sep 17 00:00:00 2001 From: yiling Date: Thu, 21 May 2026 15:53:35 +0800 Subject: [PATCH] feat(chat): remove nested cards in session logs dialog & separate contents with a horizontal separator --- src/ui/components/chat/message-card.tsx | 183 +++++++++++++----------- 1 file changed, 97 insertions(+), 86 deletions(-) diff --git a/src/ui/components/chat/message-card.tsx b/src/ui/components/chat/message-card.tsx index c2ef7d57..5845d6b6 100644 --- a/src/ui/components/chat/message-card.tsx +++ b/src/ui/components/chat/message-card.tsx @@ -9,6 +9,7 @@ import { DialogHeader, DialogTitle, } from '@/ui/components/ui/dialog' +import { Separator } from '@/ui/components/ui/separator' import { useQuery } from '@tanstack/react-query' import { Download, File, Terminal } from 'lucide-react' import React from 'react' @@ -372,94 +373,104 @@ export const MessageCard: React.FC = ({ } if (Array.isArray(content)) { + const renderedBlocks: React.ReactNode[] = [] + + content.forEach((item, idx) => { + if (!item) return + + if (typeof item === 'string') { + if (!item.trim()) return + renderedBlocks.push( +
+ {item} +
, + ) + return + } + + if (typeof item === 'object') { + const itemObj = item as Record + const type = itemObj.type + if (type === 'text') { + const text = itemObj.text + if (typeof text !== 'string' || !text.trim()) return + renderedBlocks.push( +
+ {text} +
, + ) + return + } + + if (type === 'toolCall') { + const toolName = String( + itemObj.name || itemObj.toolName || 'Unknown', + ) + const toolArgs = itemObj.arguments || itemObj.args + renderedBlocks.push( +
+
+ + Calling Tool:{' '} + + {toolName} + +
+ {!!toolArgs && ( +
+
+ Arguments +
+ {renderToolCallArguments(toolArgs)} +
+ )} +
, + ) + return + } + + if (type === 'image') { + renderedBlocks.push( +
+ [Image Object] +
, + ) + return + } + + // Fallback for other object types + const stringified = JSON.stringify(item, null, 2) + if (stringified === '{}') return + renderedBlocks.push( +
+                                  {stringified}
+                                
, + ) + } + }) + + if (renderedBlocks.length === 0) return null + return (
- {content.map((item, idx) => { - if (!item) return null - - if (typeof item === 'string') { - if (!item.trim()) return null - return ( -
- {item} -
- ) - } - - if (typeof item === 'object') { - const itemObj = item as Record - const type = itemObj.type - if (type === 'text') { - const text = itemObj.text - if (typeof text !== 'string' || !text.trim()) return null - return ( -
- {text} -
- ) - } - - if (type === 'toolCall') { - const toolName = String( - itemObj.name || itemObj.toolName || 'Unknown', - ) - const toolArgs = itemObj.arguments || itemObj.args - return ( -
-
- - Calling Tool:{' '} - - {toolName} - -
- {!!toolArgs && ( -
-
- Arguments -
- {renderToolCallArguments(toolArgs)} -
- )} -
- ) - } - - if (type === 'image') { - return ( -
- [Image Object] -
- ) - } - - // Fallback for other object types - const stringified = JSON.stringify(item, null, 2) - if (stringified === '{}') return null - return ( -
-                                      {stringified}
-                                    
- ) - } - - return null - })} + {renderedBlocks.map((block, index) => ( + + {index > 0 && } + {block} + + ))}
) }