diff --git a/src/components/AIMessageItem.tsx b/src/components/AIMessageItem.tsx index ecc64720..f850d900 100644 --- a/src/components/AIMessageItem.tsx +++ b/src/components/AIMessageItem.tsx @@ -184,6 +184,75 @@ export const AIMessageItem = memo(({ const toolInfo = getToolInfo(); const IconComponent = toolInfo.icon; + // Get tool call arguments for special rendering + let toolArgs: Record = {}; + let toolName = ''; + if (toolCall?.type === 'function') { + toolName = toolCall.function.name; + try { + toolArgs = JSON.parse(toolCall.function.arguments); + } catch { + toolArgs = {}; + } + } + + // Special rendering for tools + const renderSpecialContent = () => { + if (toolName === 'text_editor_write' && toolArgs.file_text) { + return ( +
+
+ {toolArgs.file_text as string} +
+
+ ); + } + + if (toolName === 'text_editor_str_replace' && toolArgs.old_str && toolArgs.new_str) { + const oldLines = (toolArgs.old_str as string).split('\n'); + const newLines = (toolArgs.new_str as string).split('\n'); + + return ( +
+
+ {/* Old content (removed) */} +
+ {oldLines.map((line, index) => ( +
+ - + + {line} + +
+ ))} +
+ + {/* New content (added) */} +
+ {newLines.map((line, index) => ( +
+ + + + {line} + +
+ ))} +
+
+
+ ); + } + + // Default rendering for other tools + return ( +
+
+ {content} +
+
+ ); + }; + // Regular tool message rendering return (
{/* -mt-2 to make it snug with the previous assistant message */} @@ -200,13 +269,7 @@ export const AIMessageItem = memo(({ - {isToolExpanded && ( -
-
- {content} -
-
- )} + {isToolExpanded && renderSpecialContent()}
); }