/**
* 教师端 - 创建Agent页面
* 对应原始 index.html 的 create-agent section (4步向导)
* 复用原始HTML的4步表单逻辑
*/
import { useState, useEffect } from 'react';
import { Steps, Card, Form, Input, Select, Button, Space, Checkbox, message, Row, Col, Modal } from 'antd';
import {
InfoCircleOutlined,
AppstoreOutlined,
DatabaseOutlined,
BranchesOutlined,
ArrowLeftOutlined,
ArrowRightOutlined,
CheckOutlined,
} from '@ant-design/icons';
import { motion } from 'framer-motion';
import knowledgeService from '../../services/knowledgeService';
import agentService from '../../services/agentService';
import WorkflowEditor from '../../components/WorkflowEditor';
const { TextArea } = Input;
const CreateAgent = () => {
const [form] = Form.useForm();
const [currentStep, setCurrentStep] = useState(0);
const [submitting, setSubmitting] = useState(false); // 创建Agent的loading
const [aiGenerating, setAiGenerating] = useState(false); // AI生成工作流的loading
const [selectedPlugins, setSelectedPlugins] = useState([]);
const [selectedKnowledgeBases, setSelectedKnowledgeBases] = useState([]);
const [knowledgeBases, setKnowledgeBases] = useState([]);
const [workflow, setWorkflow] = useState(null);
const [showWorkflowEditor, setShowWorkflowEditor] = useState(false);
// 检查是否是编辑模式
const urlParams = new URLSearchParams(window.location.search);
const isEditMode = urlParams.get('mode') === 'edit';
const [editingAgentId, setEditingAgentId] = useState(null);
// 保存每个步骤的数据
const [formData, setFormData] = useState({
name: '',
description: '',
subject: '',
instructor: '',
type: 'general',
});
// 加载知识库列表和编辑数据
useEffect(() => {
loadKnowledgeBases();
// 如果是编辑模式,加载agent数据
if (isEditMode) {
const editingAgentStr = localStorage.getItem('editingAgent');
if (editingAgentStr) {
try {
const editingAgent = JSON.parse(editingAgentStr);
setEditingAgentId(editingAgent.id);
// 设置表单数据
setFormData({
name: editingAgent.name || '',
description: editingAgent.description || '',
subject: editingAgent.subject || '',
instructor: editingAgent.instructor || '',
type: editingAgent.type || 'general',
});
// 设置表单初始值
form.setFieldsValue({
name: editingAgent.name || '',
description: editingAgent.description || '',
subject: editingAgent.subject || '',
instructor: editingAgent.instructor || '',
type: editingAgent.type || 'general',
});
// 设置其他数据
setSelectedPlugins(editingAgent.plugins || []);
setSelectedKnowledgeBases(editingAgent.knowledgeBases || []);
setWorkflow(editingAgent.workflow || null);
// 清除localStorage
localStorage.removeItem('editingAgent');
} catch (error) {
console.error('加载编辑数据失败:', error);
}
}
}
}, [isEditMode]);
const loadKnowledgeBases = async () => {
try {
const res = await knowledgeService.getKnowledgeBases();
setKnowledgeBases(res.data || []);
} catch (error) {
console.error('加载知识库失败:', error);
}
};
// 可用插件列表(对应原始HTML的插件选项)
const availablePlugins = [
{
id: 'code',
name: '代码执行',
icon: '💻',
description: '允许学生编写和执行Python代码,实时获取结果',
color: '#10b981',
},
{
id: 'visualization',
name: '3D可视化',
icon: '📊',
description: '生成交互式3D图形,帮助学生理解数学概念',
color: '#f97316',
},
{
id: 'mindmap',
name: '思维导图',
icon: '🗺️',
description: '创建结构化的思维导图,帮助学生梳理知识点',
color: '#8b5cf6',
},
];
// Agent类型选项
const agentTypes = [
{ value: 'educational', label: '教育辅导' },
{ value: 'programming', label: '编程辅助' },
{ value: 'math', label: '数学辅导' },
{ value: 'general', label: '通用助手' },
];
// 步骤配置
const steps = [
{
title: '基本信息',
icon:
这些插件将增强Agent的能力,帮助学生更好地学习
选择与此Agent相关的知识库,Agent将基于这些知识回答问题
定义Agent如何处理学生的问题和请求
让AI根据您选择的插件和知识库自动生成最优工作流
暂时不配置工作流,后续可以在Agent详情中进行配置
使用可视化编辑器自定义工作流
选择Agent可以使用的插件
选择关联的知识库
工作流设计
AI自动设计(推荐)
跳过工作流配置
手动设计(高级)
{isEditMode ? '修改您的AI教学助手' : '按照步骤创建您的AI教学助手'}