import React, { useState } from 'react'; import { Search, History, Bot, Sparkles, Database, Layers, FileText, ChevronRight, ChevronLeft, Cpu, Target, Zap, CheckCircle, } from 'lucide-react'; import { useTheme } from '../../contexts/ThemeContext'; import { PageType } from '../../components/Sidebar'; import { ChatMessage, EmptyChatState, QAComposer, TypingIndicator } from './QACommon'; interface Agent { id: string; name: string; category: string; tags: string[]; description: string; skills: string[]; dataSources: string[]; functions: string[]; outputFields: string[]; } interface Message { id: string; role: 'user' | 'assistant'; content: string; timestamp: Date; agentName?: string; skills?: string[]; dataSources?: string[]; functions?: string[]; structuredOutput?: Record; } /** * 智能体问答组件 * 基于特定智能体的专业能力进行问答,支持选择不同领域的智能体 * @param onNavigate - 页面导航函数 */ const AgentQA: React.FC<{ onNavigate: (page: PageType) => void }> = ({ onNavigate }) => { const { theme } = useTheme(); const isDark = theme === 'dark'; // 模拟智能体列表 const agents: Agent[] = [ { id: 'audience-agent', name: 'AudienceAgent', category: '受众分析', tags: ['受众分层', '画像抽取', '行为预测'], description: '专业的受众分析智能体,能够识别目标受众特征并生成画像', skills: ['受众分层', '核心受众识别', '画像抽取', '行为预测'], dataSources: ['知识库', 'Y系统', 'A系统'], functions: ['信息抽取器', '标签聚类器', '结构化输出器'], outputFields: ['core_audience', 'key_traits', 'barriers', 'opportunities'], }, { id: 'brand-agent', name: 'BrandAgent', category: '品牌分析', tags: ['品牌定位', '传播策略', '调性分析'], description: '专注品牌建设与传播策略的智能体', skills: ['品牌定位分析', '传播路径规划', '品牌调性设计'], dataSources: ['知识库', '行业数据库'], functions: ['品牌诊断器', '策略生成器'], outputFields: ['brand_position', 'communication_path', 'tone_guide'], }, { id: 'content-agent', name: 'ContentAgent', category: '内容创作', tags: ['文案撰写', '创意生成', '多形式内容'], description: '智能内容创作助手,支持多种形式的内容生成', skills: ['文案撰写', '创意生成', '多形式内容', 'A/B测试文案'], dataSources: ['知识库', '优秀案例库'], functions: ['文案生成器', '风格适配器', '质量评估器'], outputFields: ['headlines', 'body_copy', 'call_to_action', 'variants'], }, { id: 'channel-agent', name: 'ChannelAgent', category: '渠道规划', tags: ['渠道选择', '投放策略', '效果评估'], description: '专业的渠道分析与规划智能体', skills: ['渠道选择', '投放策略规划', '效果评估', '预算分配'], dataSources: ['Y系统', 'A系统', '行业数据'], functions: ['渠道分析器', '投放优化器', 'ROI预测器'], outputFields: ['recommended_channels', 'budget_allocation', 'expected_roi'], }, ]; // 状态管理 // 当前选中的智能体 const [selectedAgent, setSelectedAgent] = useState(agents[0]); // 智能体搜索关键词 const [searchQuery, setSearchQuery] = useState(''); // 聊天消息列表 const [messages, setMessages] = useState([]); // 输入框内容 const [inputValue, setInputValue] = useState(''); // 加载状态 const [isLoading, setIsLoading] = useState(false); // 左侧侧边栏折叠状态 const [isLeftSidebarCollapsed, setIsLeftSidebarCollapsed] = useState(false); // 过滤智能体 const filteredAgents = agents.filter(agent => agent.name.toLowerCase().includes(searchQuery.toLowerCase()) || agent.category.toLowerCase().includes(searchQuery.toLowerCase()) || agent.tags.some(tag => tag.toLowerCase().includes(searchQuery.toLowerCase())) ); /** * 处理发送消息 * 发送用户消息并模拟智能体响应 */ const handleSend = () => { if (!inputValue.trim()) return; setIsLoading(true); const userMessage: Message = { id: Date.now().toString(), role: 'user', content: inputValue, timestamp: new Date(), }; setMessages([...messages, userMessage]); setInputValue(''); // 模拟AI响应 setTimeout(() => { const response: Message = { id: (Date.now() + 1).toString(), role: 'assistant', content: `基于${selectedAgent.name}的专业能力,我来为您分析:\n\n根据您的问题,我识别到核心受众特征如下:\n\n**核心受众识别**:\n- 主要年龄段:25-35岁\n- 职业特征:都市白领\n- 消费能力:中高端\n- 关注点:品质生活、个人成长\n\n**关键特质**:\n1. 追求个性化表达\n2. 注重社交认同\n3. 愿意为品质付费\n\n**可能存在的阻力**:\n- 价格敏感度较高\n- 对品牌忠诚度有限\n\n以上分析是否满足您的需求?如需调整维度,请继续补充信息。`, timestamp: new Date(), agentName: selectedAgent.name, skills: selectedAgent.skills, dataSources: selectedAgent.dataSources, functions: selectedAgent.functions, structuredOutput: { core_audience: '25-35岁都市白领', key_traits: ['追求个性化', '注重社交认同', '品质导向'], barriers: ['价格敏感', '品牌忠诚度有限'], opportunities: ['社交媒体影响大', '口碑传播效果好'], }, }; setMessages(prev => [...prev, response]); setIsLoading(false); }, 1500); }; /** * 处理停止操作 * 停止当前正在进行的智能体响应 */ const handleStop = () => { setIsLoading(false); }; /** * 处理键盘事件 * 按Enter键发送消息(不按Shift) */ const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSend(); } }; /** * 保存问答记录 */ const handleSaveRecord = () => { alert('问答记录已保存'); }; /** * 收藏当前对话 */ const handleCollect = () => { alert('已添加到收藏'); }; return (
{/* 顶部工具栏 */}

智能体问答

当前智能体: {selectedAgent.name}
{/* 主体内容区 */}
{/* 左侧智能体区 */}
{!isLeftSidebarCollapsed && ( 智能体配置 )}
{!isLeftSidebarCollapsed && (<> {/* 智能体搜索 */}
setSearchQuery(e.target.value)} placeholder="搜索智能体..." className={`w-full pl-10 pr-4 py-2 rounded-lg text-sm focus:outline-none ${ isDark ? 'bg-transparent text-white placeholder-slate-500' : 'bg-transparent text-gray-800 placeholder-gray-400' }`} />
{/* 智能体列表 */}

智能体列表

{filteredAgents.map((agent) => ( ))}
{/* 当前智能体能力摘要 */}

能力摘要

{/* 核心职责 */}
核心职责

{selectedAgent.description}

{/* 已启用技能 */}
已启用技能
{selectedAgent.skills.map((skill, idx) => ( {skill} ))}
{/* 可访问数据源 */}
可访问数据源
{selectedAgent.dataSources.map((source, idx) => ( {source} ))}
{/* 可调用功能 */}
可调用功能
{selectedAgent.functions.map((func, idx) => ( {func} ))}
)}
{/* 中间对话区 */}
{/* 消息列表 */}
{messages.length === 0 ? ( } title={`开始与${selectedAgent.name}对话`} description="基于智能体专业能力获取精准回答" /> ) : ( messages.map((msg) => ( (

本轮启用技能

{assistantMessage.skills?.map((skill, idx) => ( {skill} ))}

本轮访问数据源

{assistantMessage.dataSources?.map((source, idx) => ( {source} ))}

本轮调用功能

{assistantMessage.functions?.map((func, idx) => ( {func} ))}
{assistantMessage.structuredOutput && (

结构化输出

{Object.entries(assistantMessage.structuredOutput).map(([key, value]) => (
{key}: {Array.isArray(value) ? value.join(', ') : String(value)}
))}
)}
)} /> )) )} {isLoading && }
{/* 底部输入区 */}
{/* 右侧执行详情区 */}

执行详情

{/* 本轮启用技能 */}
本轮启用技能
{selectedAgent.skills.map((skill, idx) => (
{skill}
))}
{/* 本轮访问数据源 */}
本轮访问数据源
{selectedAgent.dataSources.map((source, idx) => (
{source}
))}
{/* 本轮调用功能 */}
本轮调用功能
{selectedAgent.functions.map((func, idx) => (
{func}
))}
{/* 结构化输出字段 */}
输出字段
{selectedAgent.outputFields.map((field, idx) => (
{field}
))}
); }; export default AgentQA;