| import { useEffect } from 'react';
|
| import { useNavigate } from 'react-router-dom';
|
| import { useSelector, useDispatch } from 'react-redux';
|
| import { io } from 'socket.io-client';
|
| import { RootState, AppDispatch } from '../store';
|
| import { fetchProjects } from '../store/projectsSlice';
|
|
|
| export function useAgentOrchestrator() {
|
| const navigate = useNavigate();
|
| const dispatch = useDispatch<AppDispatch>();
|
| const { token } = useSelector((state: RootState) => state.auth);
|
|
|
| useEffect(() => {
|
| if (!token) return;
|
|
|
|
|
| const socket = io('http://localhost:5000/browser', {
|
| auth: { token },
|
| });
|
|
|
|
|
| socket.on('agent:navigate', (path: string) => {
|
| console.log(`[Agent Orchestrator] Navigating to ${path}`);
|
| navigate(path);
|
| });
|
|
|
|
|
| socket.on('agent:project_created', () => {
|
| console.log(`[Agent Orchestrator] Agent created a project, refreshing list`);
|
| dispatch(fetchProjects());
|
| });
|
|
|
|
|
|
|
|
|
| return () => {
|
| socket.disconnect();
|
| };
|
| }, [token, navigate, dispatch]);
|
| }
|
|
|