/** * Agent 管理组件 */ app.component('agents-page', { props: ['agents'], emits: ['refresh'], setup(props, { emit }) { const { ref, reactive, computed } = Vue; // 对话框状态 const dialogVisible = ref(false); const dialogTitle = ref('新建 Agent'); const editingId = ref(null); // 表单数据 const form = reactive({ id: '', name: '', workspace_path: '~/.config/minenasai/workspace', model: 'claude-sonnet-4-20250514', temperature: 0.7, tools_allow: [], tools_deny: [], sandbox_mode: 'workspace' }); // 可用工具列表 const availableTools = [ { value: 'read', label: '读取文件' }, { value: 'write', label: '写入文件' }, { value: 'python', label: 'Python 执行' }, { value: 'exec', label: '执行命令' }, { value: 'web_search', label: '网页搜索' }, { value: 'delete', label: '删除文件' }, { value: 'docker', label: 'Docker 操作' }, { value: 'system_config', label: '系统配置' } ]; // 模型列表 const models = [ 'claude-sonnet-4-20250514', 'claude-3-5-sonnet-20241022', 'gpt-4o', 'deepseek-chat', 'glm-4-flash', 'moonshot-v1-8k' ]; // 沙箱模式 const sandboxModes = [ { value: 'workspace', label: '工作目录限制' }, { value: 'docker', label: 'Docker 容器' }, { value: 'none', label: '无限制(危险)' } ]; // 打开新建对话框 function handleAdd() { editingId.value = null; dialogTitle.value = '新建 Agent'; Object.assign(form, { id: '', name: '', workspace_path: '~/.config/minenasai/workspace', model: 'claude-sonnet-4-20250514', temperature: 0.7, tools_allow: ['read', 'write', 'python'], tools_deny: ['delete', 'system_config'], sandbox_mode: 'workspace' }); dialogVisible.value = true; } // 打开编辑对话框 function handleEdit(agent) { editingId.value = agent.id; dialogTitle.value = '编辑 Agent'; Object.assign(form, { id: agent.id, name: agent.name, workspace_path: agent.workspace_path || '~/.config/minenasai/workspace', model: agent.model || 'claude-sonnet-4-20250514', temperature: agent.temperature || 0.7, tools_allow: agent.tools?.allow || [], tools_deny: agent.tools?.deny || [], sandbox_mode: agent.sandbox?.mode || 'workspace' }); dialogVisible.value = true; } // 删除 Agent async function handleDelete(agent) { try { await ElementPlus.ElMessageBox.confirm( `确定要删除 Agent "${agent.name}" 吗?`, '删除确认', { type: 'warning' } ); await fetch(`/api/agents/${agent.id}`, { method: 'DELETE' }); ElementPlus.ElMessage.success('删除成功'); emit('refresh'); } catch (e) { if (e !== 'cancel') { ElementPlus.ElMessage.error('删除失败: ' + e.message); } } } // 保存 Agent async function handleSave() { try { const data = { id: form.id, name: form.name, workspace_path: form.workspace_path, model: form.model, temperature: form.temperature, tools: { allow: form.tools_allow, deny: form.tools_deny }, sandbox: { mode: form.sandbox_mode } }; if (editingId.value) { await fetch(`/api/agents/${editingId.value}`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); } else { await fetch('/api/agents', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); } dialogVisible.value = false; ElementPlus.ElMessage.success('保存成功'); emit('refresh'); } catch (e) { ElementPlus.ElMessage.error('保存失败: ' + e.message); } } return { dialogVisible, dialogTitle, form, availableTools, models, sandboxModes, handleAdd, handleEdit, handleDelete, handleSave }; }, template: `