Menu
popagent
publicLatest change ac1b32888da9db0a129d0e91ff5cb4dac22c12f0 - Add workspace documentation RAG by AkurAI Build
export const SETTINGS_SECTIONS = ["appearance", "agents", "browser", "memory", "runtime", "tasks", "observability"] as const;
export type SettingsSection = (typeof SETTINGS_SECTIONS)[number];
export type AppRoute =
| { page: "overview" }
| { page: "workspace"; workspaceId: string }
| { page: "documentation"; workspaceId: string; path?: string }
| { page: "chat"; sessionId: string }
| { page: "settings"; section: SettingsSection };
function decoded(segment: string): string | undefined {
try {
return decodeURIComponent(segment);
} catch {
return undefined;
}
}
export function parseAppRoute(pathname: string): AppRoute {
const parts = pathname.split("/").filter(Boolean);
if (!parts.length) return { page: "overview" };
if (parts[0] === "settings" && parts.length <= 2) {
const section = parts[1] ?? "agents";
if (SETTINGS_SECTIONS.includes(section as SettingsSection)) {
return { page: "settings", section: section as SettingsSection };
}
}
if (parts[0] === "workspaces" && parts[2] === "docs" && parts.length >= 3) {
const workspaceId = decoded(parts[1]!);
const pathParts = parts.slice(3).map(decoded);
if (workspaceId && pathParts.every(Boolean)) {
const path = pathParts.length ? pathParts.join("/") : undefined;
return { page: "documentation", workspaceId, ...(path ? { path } : {}) };
}
}
if (parts.length === 2 && parts[0] === "workspaces") {
const workspaceId = decoded(parts[1]!);
if (workspaceId) return { page: "workspace", workspaceId };
}
if (parts.length === 2 && parts[0] === "chats") {
const sessionId = decoded(parts[1]!);
if (sessionId) return { page: "chat", sessionId };
}
return { page: "overview" };
}
export function appRoutePath(route: AppRoute): string {
switch (route.page) {
case "overview": return "/";
case "workspace": return `/workspaces/${encodeURIComponent(route.workspaceId)}`;
case "documentation": return `/workspaces/${encodeURIComponent(route.workspaceId)}/docs${route.path ? `/${route.path.split("/").map(encodeURIComponent).join("/")}` : ""}`;
case "chat": return `/chats/${encodeURIComponent(route.sessionId)}`;
case "settings": return `/settings/${route.section}`;
}
}