File size: 1,520 Bytes
11f4e50 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 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;
// The browser connects to the /browser namespace to listen to the agent
const socket = io('http://localhost:5000/browser', {
auth: { token },
});
// When the CLI agent wants to guide the user's view:
socket.on('agent:navigate', (path: string) => {
console.log(`[Agent Orchestrator] Navigating to ${path}`);
navigate(path);
});
// When the CLI agent creates a project, we should refresh our state so the UI updates
socket.on('agent:project_created', () => {
console.log(`[Agent Orchestrator] Agent created a project, refreshing list`);
dispatch(fetchProjects());
});
// You could add logic here for 'agent:video_draft_updated'
// to fill out the form fields in VideoCreate automatically.
return () => {
socket.disconnect();
};
}, [token, navigate, dispatch]);
}
|