From 447dfd982bb6a18fd6e3dc3b4e220b746cb4e7d4 Mon Sep 17 00:00:00 2001 From: LE Quoc Dat Date: Mon, 21 Apr 2025 18:30:08 +0100 Subject: [PATCH] fix x2 attachments --- .../(dashboard)/agents/[threadId]/page.tsx | 155 +++++++----------- 1 file changed, 61 insertions(+), 94 deletions(-) diff --git a/frontend/src/app/(dashboard)/agents/[threadId]/page.tsx b/frontend/src/app/(dashboard)/agents/[threadId]/page.tsx index cdb4e316..693d887e 100644 --- a/frontend/src/app/(dashboard)/agents/[threadId]/page.tsx +++ b/frontend/src/app/(dashboard)/agents/[threadId]/page.tsx @@ -103,70 +103,26 @@ function renderMarkdownContent(content: string, handleToolClick: (assistantMessa if (toolName === 'ask') { // Extract attachments from the XML attributes const attachmentsMatch = rawXml.match(/attachments=["']([^"']*)["']/i); - const attachments = attachmentsMatch + const attachments = attachmentsMatch ? attachmentsMatch[1].split(',').map(a => a.trim()) : []; - + // Extract content from the ask tag const contentMatch = rawXml.match(/]*>([\s\S]*?)<\/ask>/i); const askContent = contentMatch ? contentMatch[1] : ''; - // Render tag content with attachment UI + // Render tag content with attachment UI (using the helper) contentParts.push(
{askContent} - - {attachments.length > 0 && ( -
-
- {attachments.map((attachment, idx) => { - const extension = attachment.split('.').pop()?.toLowerCase(); - const filename = attachment.split('/').pop() || 'file'; - - // Define file size (in a real app, this would come from the backend) - const fileSize = - extension === 'html' ? '52.68 KB' : - attachment.includes('itinerary') ? '4.14 KB' : - attachment.includes('proposal') ? '6.20 KB' : - attachment.includes('todo') ? '1.89 KB' : - attachment.includes('research') ? '3.75 KB' : - `${(Math.random() * 5 + 1).toFixed(2)} KB`; - - // Get file type display - const fileType = extension === 'html' ? 'Code' : 'Text'; - - return ( - - ); - })} -
-
- )} + {renderAttachments(attachments, fileViewerHandler)}
); } else { // Render tool button as a clickable element contentParts.push( - + ); + })} + + + ); +} + export default function ThreadPage({ params }: { params: Promise }) { const unwrappedParams = React.use(params); const threadId = unwrappedParams.threadId; @@ -1353,50 +1362,8 @@ export default function ThreadPage({ params }: { params: Promise } {cleanContent} )} - {attachments.length > 0 && ( -
-
- {attachments.map((attachment, idx) => { - const extension = attachment.split('.').pop()?.toLowerCase(); - const filename = attachment.split('/').pop() || 'file'; - - // Define file size (in a real app, this would come from the backend) - const fileSize = - extension === 'html' ? '52.68 KB' : - attachment.includes('itinerary') ? '4.14 KB' : - attachment.includes('proposal') ? '6.20 KB' : - attachment.includes('todo') ? '1.89 KB' : - attachment.includes('research') ? '3.75 KB' : - `${(Math.random() * 5 + 1).toFixed(2)} KB`; - - // Get file type display - const fileType = extension === 'html' ? 'Code' : 'Text'; - - return ( - - ); - })} -
-
- )} + {/* Use the helper function to render user attachments */} + {renderAttachments(attachments as string[], handleOpenFileViewer)}