import { Download, Eraser, FileText, Plus } from 'lucide-react' import { useStore, useActiveConversation } from '../../store/useStore' import { Btn, Field, Section, inputCls, download, stamp } from '../ui' import ModelPicker from './ModelPicker' function toMarkdown(conv, agents) { const lines = [`# ${conv.title}`, '', `> 匯出於 ${new Date().toLocaleString()} · 模型 ${conv.model}`, ''] for (const m of conv.messages) { if (m.role === 'user') lines.push('## 🧑 使用者', '', m.content, '') else if (m.role === 'assistant') { const a = agents.find((x) => x.id === m.agentId) if (m.content) lines.push(`## ${a?.icon || '🤖'} ${a?.name || 'Assistant'}`, '', m.content, '') for (const c of m.tool_calls || []) lines.push(`> 🔧 呼叫 \`${c.function?.name}\` ${c.function?.arguments || ''}`, '') } else if (m.role === 'tool') { lines.push(`
🔧 ${m.name} 結果`, '', '```', String(m.content), '```', '
', '') } } return lines.join('\n') } export default function ConversationPanel({ onDone }) { const conv = useActiveConversation() const agents = useStore((s) => s.agents) const running = useStore((s) => (conv ? s.running[conv.id] : 0)) const st = useStore.getState() if (!conv) { return (

目前沒有開啟的對話。

st.createConversation()}> 新對話
) } const agent = agents.find((a) => a.id === conv.agentId) const up = (patch) => st.updateConversation(conv.id, patch) return (
up({ title: e.target.value })} /> up({ providerId, model })} />

對話途中可以隨時換模型或 Agent,下一輪就會生效。

{agents.map((a) => ( ))}
{agent && (

啟用工具:{agent.tools?.length ? agent.tools.join('、') : '無'}(到「Agent」頁可修改)

)}
download(`chat-${conv.title}-${stamp()}.json`, JSON.stringify(st.exportData('conversation', { id: conv.id }), null, 2))}> JSON download(`chat-${conv.title}-${stamp()}.md`, toMarkdown(conv, agents), 'text/markdown')}> Markdown confirm('清空這個對話的所有訊息?') && st.clearConversation(conv.id)}> 清空訊息
) }