Spaces:
Runtime error
Runtime error
Commit ·
ba93c86
1
Parent(s): 4b261d1
functioning frontend and docker
Browse filesFiles changed (10)
- .gitignore+53-9
- backend/routes/agent.py+2
- backend/session_manager.py+2-2
- backend/websocket.py+2-1
- eval/.amp_batch_solve.py.swpDeleted
- frontend/index.html+1-1
- frontend/src/components/Layout/AppLayout.tsx-5
- frontend/src/hooks/useAgentWebSocket.ts+50-30
- frontend/tsconfig.tsbuildinfoAdded+1
- frontend/vite.config.ts+2-2
4 unmodified lines5678910111213141516171819202122232425264 unmodified linesdist/wheels/*.egg-info# Virtual environments.venv.env.DS_Store.claude/*.jsonl*.csv/logshf-agent-leaderboard/.cursor/session_logs/skills/# Frontendfrontend/node_modules/frontend/dist/frontend/.cache/frontend/*.local4 unmodified lines56789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869704 unmodified linesdist/wheels/*.egg-info.pytest_cache/.mypy_cache/.tox/.coveragehtmlcov/.ipynb_checkpoints/# Virtual environments.venv/venv/ENV/env/# Environment and Secrets.env.env.local.env.*!.env.example*.localcredentials*.json# OS-specific.DS_StoreThumbs.db*.swp# IDE-specific.vscode/.idea/.cursor/.history/*.sublime-project*.sublime-workspace# Frontend (Node.js)frontend/node_modules/frontend/dist/frontend/.cache/frontend/*.localfrontend/.eslintcachefrontend/npm-debug.log*frontend/yarn-debug.log*frontend/yarn-error.log*# Docker.docker/# Project-specificsession_logs//logshf-agent-leaderboard/skills/.claude/*.jsonl*.csv# ML / Datadata/datasets/models/checkpoint-*/runs/wandb/
123 unmodified lines124125126127128129130131132123 unmodified lines@router.websocket("/ws/{session_id}")async def websocket_endpoint(websocket: WebSocket, session_id: str) -> None:"""WebSocket endpoint for real-time events."""# Verify session existsinfo = session_manager.get_session_info(session_id)if not info:await websocket.close(code=4004, reason="Session not found")return123 unmodified lines124125126127128129130131132133134123 unmodified lines@router.websocket("/ws/{session_id}")async def websocket_endpoint(websocket: WebSocket, session_id: str) -> None:"""WebSocket endpoint for real-time events."""logger.info(f"WebSocket connection request for session {session_id}")# Verify session existsinfo = session_manager.get_session_info(session_id)if not info:logger.warning(f"WebSocket connection rejected: Session {session_id} not found")await websocket.close(code=4004, reason="Session not found")return
67 unmodified lines68697071727374178 unmodified lines25325425525625725825967 unmodified linesevent_queue: asyncio.Queue = asyncio.Queue()# Create tool routertool_router = ToolRouter(config=self.config)# Create the agent sessionsession = Session(event_queue, config=self.config, tool_router=tool_router)178 unmodified lines"session_id": session_id,"created_at": agent_session.created_at.isoformat(),"is_active": agent_session.is_active,"message_count": len(agent_session.session.context_manager.messages),}def list_sessions(self) -> list[dict[str, Any]]:67 unmodified lines68697071727374178 unmodified lines25325425525625725825967 unmodified linesevent_queue: asyncio.Queue = asyncio.Queue()# Create tool routertool_router = ToolRouter(self.config.mcpServers)# Create the agent sessionsession = Session(event_queue, config=self.config, tool_router=tool_router)178 unmodified lines"session_id": session_id,"created_at": agent_session.created_at.isoformat(),"is_active": agent_session.is_active,"message_count": len(agent_session.session.context_manager.items),}def list_sessions(self) -> list[dict[str, Any]]:
19 unmodified lines2021222324252627282919 unmodified linesasync def connect(self, websocket: WebSocket, session_id: str) -> None:"""Accept a WebSocket connection and register it."""await websocket.accept()self.active_connections[session_id] = websocketself.message_queues[session_id] = asyncio.Queue()logger.info(f"WebSocket connected for session {session_id}")def disconnect(self, session_id: str) -> None:"""Remove a WebSocket connection."""19 unmodified lines202122232425262728293019 unmodified linesasync def connect(self, websocket: WebSocket, session_id: str) -> None:"""Accept a WebSocket connection and register it."""logger.info(f"Attempting to accept WebSocket for session {session_id}")await websocket.accept()self.active_connections[session_id] = websocketself.message_queues[session_id] = asyncio.Queue()logger.info(f"WebSocket connected and registered for session {session_id}")def disconnect(self, session_id: str) -> None:"""Remove a WebSocket connection."""
8 unmodified lines91011121314158 unmodified lines<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /><link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet" /></head><body><div id="root"></div><script type="module" src="/src/main.tsx"></script></body>8 unmodified lines91011121314158 unmodified lines<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /><link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet" /></head><body style="margin: 0; padding: 0; background-color: #0D1117; color: #E6EDF3;"><div id="root"></div><script type="module" src="/src/main.tsx"></script></body>
5 unmodified lines6789101112131412 unmodified lines27282930313233345 unmodified linesTypography,IconButton,Drawer,useMediaQuery,useTheme,Button,Chip,} from '@mui/material';import MenuIcon from '@mui/icons-material/Menu';12 unmodified linesconst DRAWER_WIDTH = 280;export default function AppLayout() {const theme = useTheme();const isMobile = useMediaQuery(theme.breakpoints.down('md'));const [mobileOpen, setMobileOpen] = useState(false);const { activeSessionId } = useSessionStore();5 unmodified lines6789101112 unmodified lines2425262728295 unmodified linesTypography,IconButton,Drawer,Chip,} from '@mui/material';import MenuIcon from '@mui/icons-material/Menu';12 unmodified linesconst DRAWER_WIDTH = 280;export default function AppLayout() {const [mobileOpen, setMobileOpen] = useState(false);const { activeSessionId } = useSessionStore();
1234523 unmodified lines2930313233342 unmodified lines37383940414293 unmodified lines13613713813914014114214314414514614714814915015115215315415515615715815916015 unmodified lines1761771781791801811821831841851861871881891901911921931941951961971981992005 unmodified lines2062072082092102112121 unmodified line214215216217218219220221222223224225226227228import { useCallback, useEffect, useRef } from 'react';import { useAgentStore } from '@/store/agentStore';import type { AgentEvent } from '@/types/events';import type { Message } from '@/types/agent';23 unmodified linessetError,} = useAgentStore();const handleEvent = useCallback((event: AgentEvent) => {if (!sessionId) return;2 unmodified linescase 'ready':setConnected(true);setProcessing(false);onReady?.();break;93 unmodified linesconsole.log('Unknown event:', event);}},[sessionId,addMessage,setProcessing,setConnected,setPendingApprovals,setError,onReady,onError,]);const connect = useCallback(() => {if (!sessionId || wsRef.current?.readyState === WebSocket.OPEN) return;const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';const host = window.location.host;const wsUrl = `${protocol}//${host}/api/ws/${sessionId}`;const ws = new WebSocket(wsUrl);ws.onopen = () => {15 unmodified linesconsole.error('WebSocket error:', error);};ws.onclose = () => {console.log('WebSocket closed');setConnected(false);// Attempt to reconnect with exponential backoffif (reconnectTimeoutRef.current) {clearTimeout(reconnectTimeoutRef.current);}reconnectTimeoutRef.current = window.setTimeout(() => {reconnectDelayRef.current = Math.min(reconnectDelayRef.current * 2,WS_MAX_RECONNECT_DELAY);connect();}, reconnectDelayRef.current);};wsRef.current = ws;}, [sessionId, handleEvent, setConnected]);const disconnect = useCallback(() => {if (reconnectTimeoutRef.current) {5 unmodified lineswsRef.current = null;}setConnected(false);}, [setConnected]);const sendPing = useCallback(() => {if (wsRef.current?.readyState === WebSocket.OPEN) {1 unmodified line}}, []);// Connect when sessionId changesuseEffect(() => {if (sessionId) {connect();}return () => {disconnect();};}, [sessionId, connect, disconnect]);// HeartbeatuseEffect(() => {12345623 unmodified lines30313233343536372 unmodified lines4041424344454693 unmodified lines14014114214314414514614714814915015115215315415515615715815916016116216316416516616716815 unmodified lines1841851861871881891901911921931941951961971981992002012022032042052062072082092102115 unmodified lines2172182192202212222231 unmodified line225226227228229230231232233234235236237238239240241242243244245246247248import { useCallback, useEffect, useRef } from 'react';import { useAgentStore } from '@/store/agentStore';import { useSessionStore } from '@/store/sessionStore';import type { AgentEvent } from '@/types/events';import type { Message } from '@/types/agent';23 unmodified linessetError,} = useAgentStore();const { setSessionActive } = useSessionStore();const handleEvent = useCallback((event: AgentEvent) => {if (!sessionId) return;2 unmodified linescase 'ready':setConnected(true);setProcessing(false);setSessionActive(sessionId, true);onReady?.();break;93 unmodified linesconsole.log('Unknown event:', event);}},// Zustand setters are stable, so we don't need them in deps// eslint-disable-next-line react-hooks/exhaustive-deps[sessionId, onReady, onError]);const connect = useCallback(() => {if (!sessionId) return;// Don't connect if already connected or connectingif (wsRef.current?.readyState === WebSocket.OPEN ||wsRef.current?.readyState === WebSocket.CONNECTING) {return;}// Connect directly to backend (Vite doesn't proxy WebSockets)const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';// In development, connect directly to backend port 7860// In production, use the same hostconst isDev = import.meta.env.DEV;const host = isDev ? '127.0.0.1:7860' : window.location.host;const wsUrl = `${protocol}//${host}/api/ws/${sessionId}`;console.log('Connecting to WebSocket:', wsUrl);const ws = new WebSocket(wsUrl);ws.onopen = () => {15 unmodified linesconsole.error('WebSocket error:', error);};ws.onclose = (event) => {console.log('WebSocket closed', event.code, event.reason);setConnected(false);// Only reconnect if it wasn't a normal closure and session still existsif (event.code !== 1000 && sessionId) {// Attempt to reconnect with exponential backoffif (reconnectTimeoutRef.current) {clearTimeout(reconnectTimeoutRef.current);}reconnectTimeoutRef.current = window.setTimeout(() => {reconnectDelayRef.current = Math.min(reconnectDelayRef.current * 2,WS_MAX_RECONNECT_DELAY);connect();}, reconnectDelayRef.current);}};wsRef.current = ws;}, [sessionId, handleEvent]);const disconnect = useCallback(() => {if (reconnectTimeoutRef.current) {5 unmodified lineswsRef.current = null;}setConnected(false);}, []);const sendPing = useCallback(() => {if (wsRef.current?.readyState === WebSocket.OPEN) {1 unmodified line}}, []);// Connect when sessionId changes (with a small delay to ensure session is ready)useEffect(() => {if (!sessionId) {disconnect();return;}// Small delay to ensure session is fully created on backendconst timeoutId = setTimeout(() => {connect();}, 100);return () => {clearTimeout(timeoutId);disconnect();};// eslint-disable-next-line react-hooks/exhaustive-deps}, [sessionId]);// HeartbeatuseEffect(() => {
1{"root":["./src/app.tsx","./src/main.tsx","./src/theme.ts","./src/vite-env.d.ts","./src/components/approvalmodal/approvalmodal.tsx","./src/components/chat/chatinput.tsx","./src/components/chat/messagebubble.tsx","./src/components/chat/messagelist.tsx","./src/components/layout/applayout.tsx","./src/components/sessionsidebar/sessionsidebar.tsx","./src/hooks/useagentwebsocket.ts","./src/store/agentstore.ts","./src/store/sessionstore.ts","./src/types/agent.ts","./src/types/events.ts"],"errors":true,"version":"5.6.3"}12 unmodified lines131415161718192021222312 unmodified linesport: 5173,proxy: {'/api': {target: 'http://localhost:8000',changeOrigin: true,},'/auth': {target: 'http://localhost:8000',changeOrigin: true,},},12 unmodified lines131415161718192021222312 unmodified linesport: 5173,proxy: {'/api': {target: 'http://localhost:7860',changeOrigin: true,},'/auth': {target: 'http://localhost:7860',changeOrigin: true,},},
.gitignore+53-9
backend/routes/agent.py+2
backend/session_manager.py+2-2
backend/websocket.py+2-1
eval/.amp_batch_solve.py.swpDeleted
frontend/index.html+1-1
frontend/src/components/Layout/AppLayout.tsx-5
frontend/src/hooks/useAgentWebSocket.ts+50-30
frontend/tsconfig.tsbuildinfoAdded+1
frontend/vite.config.ts+2-2