fix: 画布聊天面板过滤空消息
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
2a14ae8445
commit
96e4c8ebe0
@ -675,7 +675,34 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF
|
||||
</div>
|
||||
)}
|
||||
|
||||
{messages.map((message) => (
|
||||
{messages.map((message) => {
|
||||
// 🆕 清理消息中的内部标记并检查是否有实际内容
|
||||
const cleanedParts = message.parts?.map((part: any) => {
|
||||
if (part.type === 'text' && part.text) {
|
||||
return {
|
||||
...part,
|
||||
text: part.text.replace(/\n*<!-- GENERATING_IMAGE -->\n*/g, '').trim()
|
||||
};
|
||||
}
|
||||
return part;
|
||||
});
|
||||
|
||||
// 检查清理后是否有内容
|
||||
const hasContent = cleanedParts?.some((part: any) => {
|
||||
if (part.type === 'text') return part.text && part.text.trim().length > 0;
|
||||
if (part.type === 'file' || part.type === 'image') return part.url;
|
||||
return true;
|
||||
});
|
||||
|
||||
// 没有内容则不渲染
|
||||
if (!hasContent && cleanedParts?.length > 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 使用清理后的消息
|
||||
const cleanedMessage = { ...message, parts: cleanedParts };
|
||||
|
||||
return (
|
||||
<div
|
||||
key={message.id}
|
||||
className={cn(
|
||||
@ -731,7 +758,7 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF
|
||||
|
||||
{/* 消息内容 */}
|
||||
<div className="whitespace-pre-wrap break-words leading-relaxed">
|
||||
{message.parts?.map((part: any, i: number) => {
|
||||
{cleanedMessage.parts?.map((part: any, i: number) => {
|
||||
if (part.type === 'text') {
|
||||
// 提取并显示图片
|
||||
const imageUrls = extractImageUrls(part.text || '');
|
||||
@ -766,7 +793,8 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
);
|
||||
})}
|
||||
|
||||
{isLoading && (
|
||||
<div className="flex gap-3">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user