import { createRouter } from "@openclaw/uirouter"; import type { PageDefinition, Router, RouterHistory } from "@openclaw/uirouter"; import { routeIdFromPath, type RouteId } from "./app-route-paths.ts"; import type { ApplicationContext } from "./app/context.ts"; import { page as activityPage } from "./pages/activity/route.ts"; import { page as agentsPage } from "./pages/agents/route.ts"; import { page as channelsPage } from "./pages/channels/route.ts"; import { page as chatPage } from "./pages/chat/route.ts"; import { pages as configPages } from "./pages/config/route.ts"; import { page as cronPage } from "./pages/cron/route.ts"; import { page as debugPage } from "./pages/debug/route.ts"; import { page as dreamsPage } from "./pages/dreams/route.ts"; import { page as instancesPage } from "./pages/instances/route.ts"; import { page as logsPage } from "./pages/logs/route.ts"; import { page as nodesPage } from "./pages/nodes/route.ts"; import { page as overviewPage } from "./pages/overview/route.ts"; import { page as sessionsPage } from "./pages/sessions/route.ts"; import { page as skillWorkshopPage } from "./pages/skill-workshop/route.ts"; import { page as skillsPage } from "./pages/skills/route.ts"; import { page as usagePage } from "./pages/usage/route.ts"; import { page as workboardPage } from "./pages/workboard/route.ts"; export type AppRouteModule = { render: (data: unknown) => unknown; }; export type ApplicationRouter = Router< RouteId, ApplicationContext, AppRouteModule, unknown >; export type AppRoute = PageDefinition, AppRouteModule>; export const APP_ROUTE_TREE = [ chatPage, overviewPage, activityPage, agentsPage, channelsPage, ...configPages, workboardPage, instancesPage, sessionsPage, usagePage, debugPage, logsPage, skillWorkshopPage, skillsPage, cronPage, nodesPage, dreamsPage, ] as const; const appRoutes = APP_ROUTE_TREE as readonly AppRoute[]; export function createApplicationRouter(): ApplicationRouter { return createRouter, AppRouteModule>({ routes: appRoutes, }); } export async function startApplicationRouter( router: ApplicationRouter, history: RouterHistory, basePath: string, context: ApplicationContext, ): Promise { const location = history.location(); if (routeIdFromPath(location.pathname, basePath) === null) { history.replace({ ...location, pathname: router.pathForRoute("chat", basePath), }); } await router.start(history, basePath, context); } export function startAppRouter( router: ApplicationRouter, history: RouterHistory, basePath: string, context: ApplicationContext, ): Promise { return startApplicationRouter(router, history, basePath, context); } export { APP_ROUTE_DEFINITIONS, APP_ROUTE_IDS, inferBasePathFromPathname, isRouteId, locationForRoute, normalizeBasePath, normalizePath, pathForRoute, routeIdFromPath, type RouteId, } from "./app-route-paths.ts";