diff --git a/components/canvas/CanvasChatPanel.tsx b/components/canvas/CanvasChatPanel.tsx index 126c343..1b0a95a 100644 --- a/components/canvas/CanvasChatPanel.tsx +++ b/components/canvas/CanvasChatPanel.tsx @@ -857,55 +857,53 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF message.role === 'user' ? "items-end" : "items-start" )}> {message.role === 'user' ? ( - // 🆕 用户消息:使用图片标签样式(类似输入框) + // 🆕 用户消息:使用图片标签样式(类似竞品,按 parts 原始顺序渲染)
- {/* 渲染图片标签和文字混合 */} - {(() => { - const msgAttachments = (message as any).attachments || []; - const fileParts = cleanedMessage.parts?.filter((p: any) => p.type === 'file' && p.url) || []; - const textParts = cleanedMessage.parts?.filter((p: any) => p.type === 'text' && p.text) || []; - - // 合并所有图片 - const allImages = [ - ...msgAttachments.map((att: any) => ({ url: att.url, name: att.name || 'Image' })), - ...fileParts.map((p: any) => ({ url: p.url, name: p.name || 'Image' })) - ]; - - // 获取纯文字内容(去掉标注提示前缀) - let textContent = textParts.map((p: any) => p.text).join(' ').trim(); - // 移除标注提示前缀(这是后台处理用的,不需要显示给用户) - textContent = textContent.replace(/【注意:图片中有标注(箭头、圆圈、文字等)标记的区域是需要重点关注或修改的部分,请根据标注进行处理】\n?/g, ''); - - // 解析文字中的图片名称引用,构建混合显示 - const elements: React.ReactNode[] = []; - - // 先添加图片标签 - allImages.forEach((img, idx) => { - elements.push( + {/* 按 parts 原始顺序渲染图片标签和文字 */} + {cleanedMessage.parts?.map((part: any, idx: number) => { + if (part.type === 'file' && part.url) { + // 图片标签 + return ( - {img.name} + {part.name || 'Image'} ); - }); - - // 添加文字内容 - if (textContent) { - elements.push( - {textContent} + } + if (part.type === 'text' && part.text) { + // 文字(去掉标注提示前缀) + let text = part.text.replace(/【注意:图片中有标注(箭头、圆圈、文字等)标记的区域是需要重点关注或修改的部分,请根据标注进行处理】\n?/g, '').trim(); + if (!text) return null; + return ( + {text} ); } - - return elements; - })()} + return null; + })} + {/* 如果有 attachments 但没有 file parts,也显示 */} + {(!cleanedMessage.parts?.some((p: any) => p.type === 'file') && (message as any).attachments?.length > 0) && + (message as any).attachments.map((att: any, idx: number) => ( + + + {att.name || 'Image'} + + )) + }
) : (