import React from 'react'; import { Clock, Plus, PanelLeftClose, Search, X, MessageSquare, BookOpen, Trash2, Loader, } from 'lucide-react'; import type { SessionSummary, SearchResult, } from '../../hooks/useResearchAgent'; interface AgentSessionSidebarProps { sessions: SessionSummary[]; currentSessionId: string | null; setCurrentSessionId: (id: string | null) => void; loadingSessions: boolean; searchQuery: string; setSearchQuery: (val: string) => void; searchScopeOnlyCurrent: boolean; setSearchScopeOnlyCurrent: (val: boolean) => void; searchResults: SearchResult[]; loadingSearch: boolean; collapsed: boolean; onToggleCollapse: (val: boolean) => void; onNewSession: () => void; onDeleteSession: (sessionId: string, e: React.MouseEvent) => void; } export function AgentSessionSidebar({ sessions, currentSessionId, setCurrentSessionId, loadingSessions, searchQuery, setSearchQuery, searchScopeOnlyCurrent, setSearchScopeOnlyCurrent, searchResults, loadingSearch, collapsed, onToggleCollapse, onNewSession, onDeleteSession, }: AgentSessionSidebarProps) { const handleSelectSession = (id: string | null) => { setCurrentSessionId(id); if (typeof window !== 'undefined' && window.innerWidth < 1024) { onToggleCollapse(true); } }; const handleCreateNewSession = () => { onNewSession(); if (typeof window !== 'undefined' && window.innerWidth < 1024) { onToggleCollapse(true); } }; return ( <> {/* 移动端背景遮罩层 */} {!collapsed && ( {/* 搜索框区域 */}
setSearchQuery(e.target.value)} placeholder="搜索历史会话或消息内容..." className="w-full pl-8 pr-7 py-1.5 rounded-md bg-slate-50 border border-slate-200 text-slate-800 placeholder-slate-400 focus:outline-none focus:border-blueprint focus:bg-white transition-all text-[11px] font-medium" />
{searchQuery && ( )}
{currentSessionId && ( )}
{searchQuery.trim() ? ( loadingSearch ? (
检索历史记录中...
) : searchResults.length === 0 ? (
未找到匹配的历史记录
) : ( searchResults.map((result, idx) => { const isActive = result.session_id === currentSessionId; const isMessage = result.result_type.startsWith('message/'); const role = isMessage ? result.result_type.split('/')[1] : null; return ( ); }) ) ) : // 正常的会话列表渲染 loadingSessions ? (
加载历史会话中...
) : sessions.length === 0 ? (
暂无历史会话记录
) : ( sessions.map((session) => { const isActive = session.session_id === currentSessionId; return ( ); }) )}
); }