File size: 8,260 Bytes
348eedc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { Center, Loader } from '@mantine/core';
import { lazy, Suspense, type ReactNode } from 'react';
import { Navigate, Route, Routes, useLocation, useSearchParams } from 'react-router-dom';
import { AssistantPage } from './pages/insights/AssistantPage';
import { AuthProvider, useAuth } from './auth/AuthContext';
import { Layout } from './components/Layout';
import { AdminOnly } from './components/AdminOnly';
import { NotFoundPage } from './components/ErrorPages';
import { PodsPage } from './pages/setup/PodsPage';
import { ReadinessPage } from './pages/home/ReadinessPage';
import { TicketsPage } from './pages/insights/QueuesPages';
import { RunWorkspace } from './pages/run/RunWorkspace';
import { RunsPage } from './pages/runs/RunsPage';

// Pages opened less often load on demand, so the first visit downloads less (Home, test runs, environments and defects
// stay in the main bundle: they are the daily path).
const named = <T extends Record<string, unknown>>(load: () => Promise<T>, name: keyof T) =>
  lazy(() => load().then((m) => ({ default: m[name] as React.ComponentType })));
const AgentTeamPage = named(() => import('./pages/insights/AgentTeamPage'), 'AgentTeamPage');
const SettingsPage = named(() => import('./pages/setup/SettingsPage'), 'SettingsPage');
const AutonomyPage = named(() => import('./pages/setup/AdminPages'), 'AutonomyPage');
const KillSwitchPage = named(() => import('./pages/setup/AdminPages'), 'KillSwitchPage');
const SchedulerPage = named(() => import('./pages/setup/AdminPages'), 'SchedulerPage');
const UsersPage = named(() => import('./pages/setup/AdminPages'), 'UsersPage');
const AuditPage = named(() => import('./pages/insights/InsightPages'), 'AuditPage');
const LearnerPage = named(() => import('./pages/insights/InsightPages'), 'LearnerPage');
const ReportsPage = named(() => import('./pages/library/LibraryPages'), 'ReportsPage');
const ScenarioDetailPage = named(() => import('./pages/library/LibraryPages'), 'ScenarioDetailPage');
const ScenariosLibraryPage = named(() => import('./pages/library/LibraryPages'), 'ScenariosLibraryPage');
const HealPage = named(() => import('./pages/insights/QueuesPages'), 'HealPage');
const ScriptsPage = named(() => import('./pages/insights/QueuesPages'), 'ScriptsPage');
const AccountPage = named(() => import('./pages/account/AccountPage'), 'AccountPage');
const IntegrationsPage = named(() => import('./pages/setup/IntegrationsPage'), 'IntegrationsPage');
const LeftOnPodPage = named(() => import('./pages/setup/LeftOnPodPage'), 'LeftOnPodPage');
const AgentStudioPage = named(() => import('./pages/setup/AgentStudioPage'), 'AgentStudioPage');
const AiMonitoringPage = named(() => import('./pages/setup/AiMonitoringPage'), 'AiMonitoringPage');
const ImportCasesPage = named(() => import('./pages/library/ImportCasesPage'), 'ImportCasesPage');
// the sign-in page carries the beUI animation library: only people who sign in download it
const LoginPage = named(() => import('./pages/auth/LoginPage'), 'LoginPage');
const RegisterPage = named(() => import('./pages/auth/RegisterPage'), 'RegisterPage');
const ForgotPage = named(() => import('./pages/auth/PasswordPages'), 'ForgotPage');
const ResetPage = named(() => import('./pages/auth/PasswordPages'), 'ResetPage');

// Dev-only fixture screens for design review; the branch is removed from the production build.
const DevFixtures = import.meta.env.DEV ? lazy(() => import('./pages/dev/DevFixtures').then((m) => ({ default: m.DevFixtures }))) : null;
const DevApprovalFixtures = import.meta.env.DEV ? lazy(() => import('./pages/dev/DevFixtures').then((m) => ({ default: m.DevApprovalFixtures }))) : null;
/** The fixture routes this build registers (none outside dev builds). */
export const DEV_FIXTURE_PATHS: string[] = import.meta.env.DEV ? ['/dev/board-fixture', '/dev/approval-fixture'] : [];

/** The account pages (sign in, register, forgot, reset) load on demand: they carry the beUI and 3D libraries. */
function SignInRoute({ children }: { children: ReactNode }) {
  return <Suspense fallback={<Center h="100vh" bg="#0a0a0c"><Loader color="gray" aria-label="Loading" /></Center>}>{children}</Suspense>;
}

function RequireAuth({ children }: { children: ReactNode }) {
  const { user, loading } = useAuth();
  const loc = useLocation();
  if (loading) return <Center h="100vh"><Loader aria-label="loading" /></Center>;
  if (!user) return <Navigate to="/login" replace state={{ from: loc.pathname }} />;
  return <>{children}</>;
}

/** The old "new test run" page is now the Start sheet over the home page. */
function NewRunRedirect() {
  const [p] = useSearchParams();
  const area = p.get('area');
  return <Navigate to={`/?new=1${area ? `&area=${encodeURIComponent(area)}` : ''}`} replace />;
}

export function AppRoutes() {
  return (
    <Routes>
      <Route path="/login" element={<SignInRoute><LoginPage /></SignInRoute>} />
      <Route path="/register" element={<SignInRoute><RegisterPage /></SignInRoute>} />
      <Route path="/forgot" element={<SignInRoute><ForgotPage /></SignInRoute>} />
      <Route path="/reset" element={<SignInRoute><ResetPage /></SignInRoute>} />
      <Route element={<RequireAuth><Layout /></RequireAuth>}>
        <Route index element={<ReadinessPage />} />
        <Route path="/runs" element={<RunsPage />} />
        <Route path="/runs/new" element={<NewRunRedirect />} />
        <Route path="/runs/:id" element={<RunWorkspace />} />
        <Route path="/runs/:id/:tab" element={<RunWorkspace />} />
        <Route path="/assistant" element={<AssistantPage />} />
        <Route path="/assistant/:id" element={<AssistantPage />} />
        <Route path="/scenarios" element={<ScenariosLibraryPage />} />
        <Route path="/scenarios/import" element={<ImportCasesPage />} />
        <Route path="/scenarios/:id" element={<ScenarioDetailPage />} />
        <Route path="/tickets" element={<TicketsPage />} />
        <Route path="/pods" element={<PodsPage />} />
        <Route path="/pods/left" element={<LeftOnPodPage />} />
        <Route path="/reports" element={<ReportsPage />} />
        <Route path="/account" element={<AccountPage />} />
        {/* Admin & under the hood (engineering views) */}
        <Route path="/admin" element={<AdminOnly><SettingsPage /></AdminOnly>} />
        <Route path="/agents" element={<AdminOnly title="Agent team"><AgentTeamPage /></AdminOnly>} />
        <Route path="/heal" element={<AdminOnly title="Self-heal review"><HealPage /></AdminOnly>} />
        <Route path="/scripts" element={<AdminOnly title="Scripts and drafts"><ScriptsPage /></AdminOnly>} />
        <Route path="/learner" element={<AdminOnly title="Learner"><LearnerPage /></AdminOnly>} />
        <Route path="/audit" element={<AdminOnly title="Audit log"><AuditPage /></AdminOnly>} />
        <Route path="/admin/kill-switch" element={<AdminOnly title="Emergency stop"><KillSwitchPage /></AdminOnly>} />
        <Route path="/admin/autonomy" element={<AdminOnly title="Automatic approval"><AutonomyPage /></AdminOnly>} />
        <Route path="/admin/scheduler" element={<AdminOnly title="Scheduled runs"><SchedulerPage /></AdminOnly>} />
        <Route path="/schedules" element={<AdminOnly title="Scheduled runs"><SchedulerPage /></AdminOnly>} />
        <Route path="/admin/users" element={<AdminOnly title="Users"><UsersPage /></AdminOnly>} />
        <Route path="/integrations" element={<AdminOnly title="Integrations"><IntegrationsPage /></AdminOnly>} />
        <Route path="/agent-studio" element={<AdminOnly title="Oracle AI Agent Studio"><AgentStudioPage /></AdminOnly>} />
        <Route path="/ai-monitoring" element={<AdminOnly title="AI monitoring"><AiMonitoringPage /></AdminOnly>} />
        {DevFixtures && DEV_FIXTURE_PATHS.includes('/dev/board-fixture') && <Route path="/dev/board-fixture" element={<Suspense fallback={null}><DevFixtures /></Suspense>} />}
        {DevApprovalFixtures && DEV_FIXTURE_PATHS.includes('/dev/approval-fixture') && <Route path="/dev/approval-fixture" element={<Suspense fallback={null}><DevApprovalFixtures /></Suspense>} />}
        <Route path="*" element={<NotFoundPage />} />
      </Route>
    </Routes>
  );
}

export function App() {
  return <AuthProvider><AppRoutes /></AuthProvider>;
}