import { useState } from 'react' import { X, Download } from 'lucide-react' import { useAgentStore } from '../store/agentStore' export default function ExportDialog({ onClose }) { const [includeErrors, setIncludeErrors] = useState(true) const messages = useAgentStore((state) => state.messages) const handleExport = () => { const rows = messages .filter((m) => includeErrors || !(typeof m.content === 'string' && m.content.startsWith('⚠️'))) .map((m) => { const row = { role: m.role, content: m.content || '' } if (m.tool_call_id) row.tool_call_id = m.tool_call_id if (m.name) row.name = m.name if (m.tool_calls?.length) { row.tool_calls = m.tool_calls.map((c) => ({ id: c.id, type: c.type, function: { name: c.function?.name, arguments: c.function?.arguments }, })) } return row }) const dataStr = JSON.stringify( { timestamp: new Date().toISOString(), source: 'Agent Studio (Agent 頁)', messages: rows, }, null, 2, ) const blob = new Blob([dataStr], { type: 'application/json' }) const url = URL.createObjectURL(blob) const a = document.createElement('a') a.href = url a.download = `agent-conversation-${new Date().toISOString().slice(0, 10)}.json` a.click() URL.revokeObjectURL(url) onClose() } const isEmpty = messages.length === 0 return (
共 {messages.length} 則訊息(只匯出 Agent 頁,聊天頁是獨立對話)。