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>
|
</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
|
<div
|
||||||
key={message.id}
|
key={message.id}
|
||||||
className={cn(
|
className={cn(
|
||||||
@ -731,7 +758,7 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF
|
|||||||
|
|
||||||
{/* 消息内容 */}
|
{/* 消息内容 */}
|
||||||
<div className="whitespace-pre-wrap break-words leading-relaxed">
|
<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') {
|
if (part.type === 'text') {
|
||||||
// 提取并显示图片
|
// 提取并显示图片
|
||||||
const imageUrls = extractImageUrls(part.text || '');
|
const imageUrls = extractImageUrls(part.text || '');
|
||||||
@ -766,7 +793,8 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
{isLoading && (
|
{isLoading && (
|
||||||
<div className="flex gap-3">
|
<div className="flex gap-3">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user