// The route tree, shared by the server and the browser. Each side builds its // own router instance from it: the server a per-request memory-history router // (see router.server.ts), the browser a singleton (see router.client.ts). import { createRootRoute, createRoute, createRouter, redirect, type RouterHistory, } from "@octanejs/tanstack-router"; /** Key under which the server middleware stores the loaded router in request state. */ export const ROUTER_STATE_KEY = "tanstack.router"; const rootRoute = createRootRoute().lazy(() => import("./routes/RootLayout.lazy.tsx").then((module) => module.Route), ); const indexRoute = createRoute({ getParentRoute: () => rootRoute, path: "/", }).lazy(() => import("./routes/Home.lazy.tsx").then((module) => module.Route)); const conversationRoute = createRoute({ getParentRoute: () => rootRoute, path: "conversations/$id", }).lazy(() => import("./routes/Conversation.lazy.tsx").then((module) => module.Route), ); const tasksRoute = createRoute({ getParentRoute: () => rootRoute, path: "tasks", }).lazy(() => import("./routes/Tasks.lazy.tsx").then((module) => module.Route)); const taskRoute = createRoute({ getParentRoute: () => rootRoute, path: "tasks/$id", }).lazy(() => import("./routes/Tasks.lazy.tsx").then((module) => module.TaskRoute), ); // Preserve the old personal-agent entry point without retaining starter content. const agentsRoute = createRoute({ getParentRoute: () => rootRoute, path: "agents", beforeLoad: () => { throw redirect({ to: "/" }); }, }); const settingsRoute = createRoute({ getParentRoute: () => rootRoute, path: "settings", beforeLoad: ({ location }) => { if ( location.hash.replace(/^#/, "") === "extensions-settings" || new URLSearchParams(location.searchStr).has("mcpAuth") ) { throw redirect({ href: `/extensions${location.searchStr}#mcp-settings`, replace: true, }); } }, }).lazy(() => import("./routes/Settings.lazy.tsx").then((module) => module.Route), ); const extensionsRoute = createRoute({ getParentRoute: () => rootRoute, path: "extensions", }).lazy(() => import("./routes/Extensions.lazy.tsx").then((module) => module.Route), ); const routeTree = rootRoute.addChildren([ indexRoute, conversationRoute, tasksRoute, taskRoute, agentsRoute, settingsRoute, extensionsRoute, ]); export interface RouterEnv { /** Memory history on the server; omitted in the browser (browser history). */ history?: RouterHistory; /** Use the non-reactive server store factory. */ isServer?: boolean; /** Request origin. Required on the server, where router-core would otherwise read `window`. */ origin?: string; } export function createAppRouter(env: RouterEnv = {}) { return createRouter({ routeTree, history: env.history, isServer: env.isServer, origin: env.origin, defaultPreload: "intent", scrollRestoration: true, }); } export type AppRouter = ReturnType; declare module "@octanejs/tanstack-router" { interface Register { router: AppRouter; } }