- Add OpenClawProcessOwner class to manage the lifecycle of the OpenClaw process. - Introduce utility functions for managing OpenClaw runtime paths. - Update session store to normalize agent session keys and migrate existing keys. - Refactor main process to handle local provider API routing through a new dispatch function. - Enhance token usage writer to utilize a new session key parsing function. - Create agents management store to handle agent data and interactions. - Update chat store to integrate agent selection and session management. - Introduce AgentsSection component for displaying agent information in the UI. - Refactor HomePage to support agent selection and display current agent. - Update routing to reflect new agents page structure.
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { Navigate, Route, Routes, useLocation, useNavigate } from 'react-router-dom';
|
|
import MainLayout from '../components/layout/MainLayout';
|
|
import HomePage from '../pages/Home';
|
|
import LoginPage from '../pages/Login';
|
|
import AgentsPage from '../pages/agents';
|
|
import SkillsPage from '../pages/Skills';
|
|
import CronPage from '../pages/Cron';
|
|
import ScriptsPage from '../pages/Scripts';
|
|
import SettingPage from '../pages/Setting';
|
|
import KnowledgePage from '../pages/Knowledge';
|
|
import { DEFAULT_PATH } from './routes';
|
|
import { RedirectAuthenticated, RequireAuth, isAuthenticated } from './auth';
|
|
import { onAuthLogout } from './auth-session';
|
|
|
|
function AuthLogoutRedirector() {
|
|
const location = useLocation();
|
|
const navigate = useNavigate();
|
|
|
|
useEffect(() => {
|
|
return onAuthLogout(({ from }) => {
|
|
const currentPath = location.pathname === '/login' ? undefined : location.pathname;
|
|
navigate('/login', {
|
|
replace: true,
|
|
state: { from: from ?? currentPath },
|
|
});
|
|
});
|
|
}, [location.pathname, navigate]);
|
|
|
|
return null;
|
|
}
|
|
|
|
export function AppRouter() {
|
|
const initialPath = isAuthenticated() ? DEFAULT_PATH : '/login';
|
|
|
|
return (
|
|
<>
|
|
<AuthLogoutRedirector />
|
|
<Routes>
|
|
<Route path="/" element={<Navigate to={initialPath} replace />} />
|
|
<Route element={<RedirectAuthenticated />}>
|
|
<Route path="/login" element={<LoginPage />} />
|
|
</Route>
|
|
|
|
<Route element={<RequireAuth />}>
|
|
<Route element={<MainLayout />}>
|
|
<Route path="/home" element={<HomePage />} />
|
|
<Route path="/agents" element={<AgentsPage />} />
|
|
<Route path="/skills" element={<SkillsPage />} />
|
|
<Route path="/cron" element={<CronPage />} />
|
|
<Route path="/scripts" element={<ScriptsPage />} />
|
|
<Route path="/setting" element={<SettingPage />} />
|
|
<Route path="/knowledge" element={<KnowledgePage />} />
|
|
</Route>
|
|
</Route>
|
|
|
|
<Route path="*" element={<Navigate to={initialPath} replace />} />
|
|
</Routes>
|
|
</>
|
|
);
|
|
}
|